Does SuperCore use heap ?

Joel Sherrill joel at OARcorp.com
Thu Jan 15 15:43:37 UTC 2004


Stan wrote:
> ----- Original Message ----- 
> From: "Joel Sherrill" <joel.sherrill at OARcorp.com>
> To: "Stan" <zylog at club-internet.fr>
> Cc: "rtems-users" <rtems-users at rtems.com>
> Sent: Tuesday, January 13, 2004 5:50 PM
> Subject: Re: Does SuperCore use heap ?
> 
> 
> 
>>Stan wrote:
>>
>>
>>>Hi,
>>>
>>>I thought SuperCore doesn't use heap, only libc does it ( when routine
> 
> like
> 
>>>open, read, write or malloc are called).
>>
>>  Thus, Workspace is the memory used by RTEMS to allocate objects like
>>>tasks and semaphores etc...
>>>But nevertheless, it seems to me that rtems_task_start allocates memory
>>> from heap.
>>
>>The workspace is another instance of a super core heap.  There are two
>>score heaps in a system -- the C program heap and the workspace.
>>
> 
> 
> If I don't need to use memory "malloc'ed " from C program,
> can I declare the _HeapSize with minimal value  ?
> ( because the memory is small )

As a general rule yes.  But some libraries and support
functions do malloc.  For example, newlib mallocs buffers
and file descriptors.  So you may have implicit malloc's you
aren't aware of.

If your application allocates everything up front, then
you can do a malloc_freespace and see how much is left.
That would be a nice guideline for reducing it.

>>Yes if you did not reserve enough memory in the workspace.
>>
> 
> 
> I think to have reserved enough memory ( the define CONFIGURE_MAXIMUM_TASKS,
> etc. are right ).
> 
> Here is my system.h file :
> ----------------------------------------------------------------------------
> -----------------------------
> #include <rtems.h>
> #include <bsp.h>
> 
> /* functions */
> rtems_task Init(
>   rtems_task_argument argument
> );
> 
> /* configuration information */
> 
> 
> #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
> #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
> 
> 
> #define CONFIGURE_MICROSECONDS_PER_TICK  10000
> 
> #define CONFIGURE_MAXIMUM_TASKS   20
> #define CONFIGURE_MAXIMUM_SEMAPHORES         0
> #define CONFIGURE_MAXIMUM_MESSAGE_QUEUES     0
> #define CONFIGURE_MAXIMUM_TIMERS             0
> 
> #define CONFIGURE_MEMORY_OVERHEAD     0
> 
> 
> #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
> 
> #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 6
> 
> 
> #define CONFIGURE_EXTRA_TASK_STACKS         ( 0 )
> 
> 
> 
> #define CONFIGURE_INIT_TASK_STACKS_SIZE   ( RTEMS_MINIMUM_STACK_SIZE )
> #define CONFIGURE_INIT_TASK_PRIORITY   10
> #define CONFIGURE_INIT_TASK_INITIAL_MODES (RTEMS_PREEMPT | \
>                                            RTEMS_NO_TIMESLICE | \
>                                            RTEMS_NO_ASR | \
>                                            RTEMS_INTERRUPT_LEVEL(0))
> 
> 
> #define CONFIGURE_INIT_TASK_NAME rtems_build_name('M','O','N',' ')
> 
> #include <confdefs.h>
> 
> ----------------------------------------------------------------------------
> -----------------------------
> Here is init.c file :
> ----------------------------------------------------------------------------
> -----------------------------
>  /*
>  * Init
>  */
> #define CONFIGURE_INIT
> 
> #include "system.h"
> 
> #include <stdio.h>
> #include <stdlib.h>
> #include <fcntl.h>
> #include <termios.h>
> #include <unistd.h>
> #include <string.h>
> 
> #define VERSION     "*** TEST V24 V1.07 ***"
> 
> 
> #define MAXIMUM_TASKS (18)
> 
> rtems_task test(
>   rtems_task_argument argument
> )
> {
>  while(1){
>   rtems_task_wake_after( 100 );
>  }
> 
>     rtems_task_delete( RTEMS_SELF );
> }
> 
> 
> rtems_task Init(
>   rtems_task_argument argument
> )
> {
> rtems_name name[MAXIMUM_TASKS];
> rtems_mode mode[MAXIMUM_TASKS];
> rtems_id task_id[MAXIMUM_TASKS];
> rtems_task_priority pri[MAXIMUM_TASKS];;
> 
> rtems_status_code status;
> rtems_task_priority old_priority;
> 
> int count;
> char str_name[30];
> 
>     puts(VERSION);
>     CPU_usage_Dump();
> 
> 
> 
>  for(count=0; count < MAXIMUM_TASKS; count++){
>   sprintf( str_name, "%03d", count);
>   printf("Build name (%s).\r\n", str_name);
>   name[count] = rtems_build_name('T', str_name[0], str_name[1],
> str_name[2]);
>  }
> 
>     for(count=0; count< MAXIMUM_TASKS; count++){
>         mode[count] = RTEMS_INTERRUPT_LEVEL(0) | RTEMS_NO_ASR;
>         mode[count] |= RTEMS_PREEMPT;
>         mode[count] |= RTEMS_TIMESLICE;
>         pri[count] = 20;
> 
>         status = rtems_task_create(name[count], pri[count], 1024,
>            mode[count], RTEMS_DEFAULT_ATTRIBUTES, &task_id[count]);
>         if (status != RTEMS_SUCCESSFUL) {
>             printf("Error create task no %d\r\n", count);
>         }else printf("Creation task no %d\r\n", count);
>     }
> 
>  /* ------------------- START TASK --------------------*/
>  for(count=0; count < MAXIMUM_TASKS; count++){
>   status = rtems_task_start(task_id[count], test, count);
>         if (status != RTEMS_SUCCESSFUL) {
>             printf("Error start task no %d\r\n", count);
>         }else printf("Start task no %d\r\n", count);
>  }
> 
> 
>  while(1){
>   rtems_task_wake_after( 200 );
>   CPU_usage_Dump();
>  }
>     status = rtems_task_delete( RTEMS_SELF );
> }
> 
> ----------------------------------------------------------------------------
> -----------------------------
> 
>>>Why the memory isn't allocated from the workspace ?
>>
>>It was until it ran out. :)
>>
> 
> 
> The memory workspace is calculate by confdefs.h ?
> Why is its size is not sufficient ?

I don't know.  You have a hard-coded 1024 stack size
and depending on the port that may be more than the minimum
stack size.  So confdefs.h may be missing that.  Try
it with the minimum stack constant.

It is always possible confdefs.h is not accounting for
something.

>>>Where is my error ? ;)
>>
>>I don't see the task create calls but it is possible that you aren't
>>accounting for all the stack memory you are allocating.  Are they
>>minimum size or larger?
> 
> 
> They have minimum size.

They have 1024 which may or may not be the minimum.

>>If they are larger than minimum then you have to account for such.
> 
> 
> In my case, CONFIGURE_EXTRA_TASK_STACK  can be initialize with zero.
> Tell me if I  make a mistake ;)
> 
> I have other questions :
> 
> Why this problem cause rtems_fatal_error_occurred instead of  returning
> with code RTEMS_NO_MEMORY ?

Break there and see what code it is.  RTEMS internally doesn't
fatal error for memory being allocated.  So it might be an
extension or some library routine.

> Between rtems-4.0.6pre4  and rtems-ss-20030703, are they some differences
> for memory management ?
> Because, it seems to me that behaviour is not same.
> Before, on my old bsp based upon efi68k, I worked with minimum heap ( with
> HeapSize= 0x1000) because
> no memory  is "malloc'ed" by  the C program.
> With this size, four tasks were successfully launched but not with my new
> bsp based upon mcf5206elite ...
> An idea ?

Some support library or routine is allocating memory that is
not being accounted for.

> Thanks again...
> 
> 
> Stan.
> 


-- 
Joel Sherrill, Ph.D.             Director of Research & Development
joel at OARcorp.com                 On-Line Applications Research
Ask me about RTEMS: a free RTOS  Huntsville AL 35805
Support Available                (256) 722-9985




More information about the users mailing list