Some problems in the implement of the supercore:

Sergei Organov osv at topconrd.ru
Mon Dec 29 15:53:06 UTC 2003


"Bert"<doclzs at 21cn.com> writes:
> Hi,here are some problems in the implement of the supercore.
> i am urgent for your advice.
> Thanks a lot in advance!
> 
> (1)the file "chain.inl"
[...]
>    return (Chain_Node *) the_chain;
> i think it should be:
[...]
>    return (Chain_Node *) the_chain->first;

You are wrong.

> 
> one of my colleagues think it should be:
>    return (Chain_Node *) &the_chain->first;

He is right, but this is the same as initial implementation, as
&the_chain->first==the_chain due to the fact that 'first' is the first field
in the Chain_Node structure.

> who is right?

Your colleagues' implementation and the initial implementation are both
correct, youth is wrong.

> after all, the variable "first" is already a pointer to a Chain_Node.

Yes, it is, but Chain_Head *is not* the first element in the free chain list,
it points to the first element through its 'first' field.

[...]

> (3)the file "heap.inl"
> 
> RTEMS_INLINE_ROUTINE Heap_Block *_Heap_User_block_at(
>   void       *base
> )
> {
>   unsigned32         offset;
>  
>   offset = *(((unsigned32 *) base) - 1);
>   return _Heap_Block_at( base, -offset + -HEAP_BLOCK_USED_OVERHEAD);
> }
> 
> what is the function of this? 
> why "offset=*(((unsigned32 *) base) - 1)"?

The heap manager stores the offset just before the address where 'base' points
to. See _Heap_Allocate() for details.

> what is meaning of the value "-offset + -HEAP_BLOCK_USED_OVERHEAD"?

The offset from the pointer that has been returned to the user to the
beginning of the allocated block.

> 
> (4)the file "heapallocate.c"
> 
> void *_Heap_Allocate(
>   Heap_Control        *the_heap,
>   unsigned32           size
> )
> {
> ......
> 
>   if ( size >= (-1 - HEAP_BLOCK_USED_OVERHEAD) )
>     return( NULL );
> 
>   excess   = size % the_heap->page_size;
>   the_size = size + the_heap->page_size + HEAP_BLOCK_USED_OVERHEAD;
> 
> ......
> }
> 
> It is sure that "size >= (-1 - HEAP_BLOCK_USED_OVERHEAD)", right?
> what is meaning of the value "-1 - HEAP_BLOCK_USED_OVERHEAD"?
> Is it necessary of the code
> "the_size = size + the_heap->page_size + HEAP_BLOCK_USED_OVERHEAD;" ?

For the current implementation it is. For better implementation,
'the_heap->page_size' is not necessary. I've posted new implementation of the
heap manager to the rtems-users mailing list a few days ago, refer to

<http://www.rtems.com/ml/rtems-users/2003/december/msg00170.html>

and to PR 536 in RTEMS bugs database for details.

> what is meaning of the value "the_heap->page_size +
> HEAP_BLOCK_USED_OVERHEAD"?

That's how much memory the manager will spend in addition to the user requested
size for bookkeeping purposes.

-- 
Sergei.




More information about the users mailing list