3 bugs found related with RTEMS POSIX API(?)

Alex kbyte at iol.pt
Mon Apr 19 09:09:05 UTC 2004


(Env: RTEMS v4.6, Target=i386, Bsp=pc686)

Hi,
I think it is clear now for me that there is 3 bugs related with RTEMS POSIX API.
The first and second ones are related with getting rtems memory to handle POSIX timers. The third one prevents anyone from create more than 11 timers.

First and Second bugs:
At some days ago I tried to create some POSIX timers but the app always died at the start up. I search for possible problems but as I am beginner in this kernell I decided to put the question to the list. The question had the subject: “How many Timers Can I create?”
Soon, Dr Joel and also Kamen pointed me to the bug: 
Well, the app died because it run out of space during the preallocation of memory to handle the specified number of objects, in this case, timers.
File: .../rtems-4.6/tools/rtems-4.6.0pre5/cpukit/sapi/include/confdefs.h

The next macro 
#define CONFIGURE_MEMORY_FOR_POSIX_TIMERS(_timers) \
  ((_timers) * \
   ( 0 ) )

must be replaced by
#define CONFIGURE_MEMORY_FOR_POSIX_TIMERS(_timers)  \
  ((_timers) * sizeof(POSIX_Timer_Control))

As can be seen,first version of the macro multiplies the defined posix timers by zero!

Also, the macro:
#define CONFIGURE_MEMORY_FOR_POSIX \
  ( \
    CONFIGURE_MEMORY_FOR_POSIX_MUTEXES( CONFIGURE_MAXIMUM_POSIX_MUTEXES ) + \
    CONFIGURE_MEMORY_FOR_POSIX_CONDITION_VARIABLES( \
        CONFIGURE_MAXIMUM_POSIX_CONDITION_VARIABLES ) + \
    CONFIGURE_MEMORY_FOR_POSIX_KEYS( CONFIGURE_MAXIMUM_POSIX_KEYS ) + \
    CONFIGURE_MEMORY_FOR_POSIX_QUEUED_SIGNALS( \
        CONFIGURE_MAXIMUM_POSIX_QUEUED_SIGNALS ) + \
    CONFIGURE_MEMORY_FOR_POSIX_MESSAGE_QUEUES( \
        CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUES ) + \
    CONFIGURE_MEMORY_FOR_POSIX_SEMAPHORES( \
        CONFIGURE_MAXIMUM_POSIX_SEMAPHORES ) + \
    (CONFIGURE_POSIX_INIT_THREAD_STACK_SIZE) \
   )
does not take in account the memory for posix timers. So a new line of source code must be added, because, later this macro is called by the CONFIGURE_EXECUTIVE_RAM_SIZE macro in order to get the total ram size. The fixed version of the  CONFIGURE_MEMORY_FOR_POSIX macro is presented next.  

#define CONFIGURE_MEMORY_FOR_POSIX \
  ( \
    CONFIGURE_MEMORY_FOR_POSIX_TIMERS(CONFIGURE_MAXIMUM_POSIX_TIMERS) + \
    CONFIGURE_MEMORY_FOR_POSIX_MUTEXES( CONFIGURE_MAXIMUM_POSIX_MUTEXES ) + \
    CONFIGURE_MEMORY_FOR_POSIX_CONDITION_VARIABLES( \
        CONFIGURE_MAXIMUM_POSIX_CONDITION_VARIABLES ) + \
    CONFIGURE_MEMORY_FOR_POSIX_KEYS( CONFIGURE_MAXIMUM_POSIX_KEYS ) + \
    CONFIGURE_MEMORY_FOR_POSIX_QUEUED_SIGNALS( \
        CONFIGURE_MAXIMUM_POSIX_QUEUED_SIGNALS ) + \
    CONFIGURE_MEMORY_FOR_POSIX_MESSAGE_QUEUES( \
        CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUES ) + \
    CONFIGURE_MEMORY_FOR_POSIX_SEMAPHORES( \
        CONFIGURE_MAXIMUM_POSIX_SEMAPHORES ) + \
    (CONFIGURE_POSIX_INIT_THREAD_STACK_SIZE) \
   )

Once more again, special thanks to Dr Joel and to Kamen for pointing me to the probably error in source code.
After changing the erronious source code, I tested it creating timers and everything worked fine.


Third bug:
Continuing with my tests, then, I tried to create 150 POSIX timers. When the 12th timer was created the POSIX function timer_create() always returned -1. Looking to the last error, I saw the EAGAIN value. Studing the source code that creates a POSIX timer I realized that this error could only come from 2 different situations:

1.There is not position for another timers in the timer_struct array
2.There has been created too much timers for the same process

The second reason is not accepted because I configuread POSIX_TIMERS and standard TIMERS to 150. So only the first reason could be accepted. 
Using some “trace” operations I realized that the  timer_struct  array had 150 elements elements at the begining and at the end of the program. So everything looked fine...

Looking for the  FIRST_FREE_POSITION_F() and for the timer_create() both in the ptimer1.c, I realized that there is only a chance to justify the failling of the timer_create() call:

The defined constant NO_MORE_TIMERS_C used to validate the answer of the FIRST_FREE_POSITION_F() function has a value that is to low and prevents one person from create more than “NO_MORE_TIMERS_C” timers (starting from zero). If we look to the timer.h we see:

...
#define NO_MORE_TIMERS_C      	11 /* There is not available timers          */
#define BAD_TIMER_C           	11 /* The timer does not exist in the table  */
...

So, to fix this problem giving the chance to the programmer to create as much timers as he or she needs, this constant must be assigned to negative values, because this constant is only used to justify the leak of free array positions. The same is applied to the  BAD_TIMER_C constant.

So, I propose to define these constants in the 
.../rtems-4.6.0pre5/cpukit/posix/include/rtems/posix/timer.h as

 ...
#define NO_MORE_TIMERS_C      	-1 /* There is not available timers          */
#define BAD_TIMER_C           	-1 /* The timer does not exist in the table  */
...

I already made the modification. I compiled again the kernell and now I have no problems, but it is usefull to receive comments to other people, like making a “code inspection” where all of us are present.

Thank you for your attention...

Alex

PS: Now, I can create 20.000 timers and even more without any problems! :-)



___________________________________________________________________________________________
IOL Flash. A net normal em versao acelerada.
Promocao: Ligue-se a Internet pelo IOL Flash e ganhe um Vale de €10 da Galp!
Saiba como: http://www.iol.pt/central_utilizador/iol_flash/promocao.php




More information about the users mailing list