Bug in rtems_task_set_priority()

Thomas Rauscher trauscher at loytec.com
Tue Dec 23 17:21:07 UTC 2003


Hi,

we've discovered a bug in rtems_task_set_priority() in RTEMS-4.5.0.
The problem seems to be in the mainline too, but I cannot test this.

It occurs if a task owning a non-priority discipline semaphore
lowers its priority or gets its priority lowered by another task.
Its priority is not lowered then at all.

The problem is that for a task owning only fifo and/or priority
semaphores,
the task priority is not changed immediately or at least when the
'resource_count' in the thread control structure is decremented back to
zero.

The patch in the attachment is a first attempt to address this problem.
Feel free to comment it.

It creates a 'priority_resource_count' variable
in the thread control structure which is incremented only for
priority-discipline semaphores. All priority changing code uses the
'priority_resource_count' instead of 'resource_count' then.

As far as I can tell, 'resource_count' is only used for priority
inheritance/ceiling,
so the second variable is not strictly necessary. If the patch is OK so
far,
only one counter for priority-discipline semaphores is required.

I've also attached a testcase demonstrating the problem.

Best regards,
Thomas Rauscher

-- 
Thomas Rauscher
LOYTEC electronics GmbH
Stolzenthalergasse 24/3
A-1080 Wien
Austria/Europe
trauscher at loytec.com
www.loytec.com
Phone: +43-1-4020805-15
FAX:   +43-1-4020805-99

-------------- next part --------------
A non-text attachment was scrubbed...
Name: settaskpri.c
Type: text/x-csrc
Size: 1553 bytes
Desc: 
URL: <http://lists.rtems.org/pipermail/users/attachments/20031223/a673a0c4/attachment.bin>
-------------- next part --------------
Index: itron/src/chg_pri.c
===================================================================
RCS file: /data/prj_sw/cvs/rtems/c/src/exec/itron/src/chg_pri.c,v
retrieving revision 1.1.1.1
diff -r1.1.1.1 chg_pri.c
56c56
<       if ( the_thread->resource_count == 0 ||
---
>       if ( the_thread->priority_resource_count == 0 ||
Index: posix/src/pthread.c
===================================================================
RCS file: /data/prj_sw/cvs/rtems/c/src/exec/posix/src/pthread.c,v
retrieving revision 1.1.1.2
diff -r1.1.1.2 pthread.c
79c79
<   if ( the_thread->resource_count == 0 ||
---
>   if ( the_thread->priority_resource_count == 0 ||
116c116
<  if ( the_thread->resource_count == 0 ||
---
>  if ( the_thread->priority_resource_count == 0 ||
Index: rtems/src/tasksetpriority.c
===================================================================
RCS file: /data/prj_sw/cvs/rtems/c/src/exec/rtems/src/tasksetpriority.c,v
retrieving revision 1.1.1.1
diff -r1.1.1.1 tasksetpriority.c
89c89
<         if ( the_thread->resource_count == 0 ||
---
>         if ( the_thread->priority_resource_count == 0 ||
Index: score/include/rtems/score/thread.h
===================================================================
RCS file: /data/prj_sw/cvs/rtems/c/src/exec/score/include/rtems/score/thread.h,v
retrieving revision 1.2
diff -r1.2 thread.h
163a164
>   unsigned32               priority_resource_count;
196a198
>   unsigned32                            priority_resource_count;
Index: score/src/coremutex.c
===================================================================
RCS file: /data/prj_sw/cvs/rtems/c/src/exec/score/src/coremutex.c,v
retrieving revision 1.1.1.2
diff -r1.1.1.2 coremutex.c
75a76,84
>     switch ( the_mutex->Attributes.discipline ) {
>       case CORE_MUTEX_DISCIPLINES_FIFO:
>       case CORE_MUTEX_DISCIPLINES_PRIORITY:
>         break;
>       case CORE_MUTEX_DISCIPLINES_PRIORITY_CEILING:  
>       case CORE_MUTEX_DISCIPLINES_PRIORITY_INHERIT: 
> 	_Thread_Executing->priority_resource_count++;
>         break;    
>     }     
Index: score/src/coremutexseize.c
===================================================================
RCS file: /data/prj_sw/cvs/rtems/c/src/exec/score/src/coremutexseize.c,v
retrieving revision 1.1.1.1
diff -r1.1.1.1 coremutexseize.c
75a76,84
>     switch ( the_mutex->Attributes.discipline ) {
>       case CORE_MUTEX_DISCIPLINES_FIFO:
>       case CORE_MUTEX_DISCIPLINES_PRIORITY:
>         break;
>       case CORE_MUTEX_DISCIPLINES_PRIORITY_CEILING:  
>       case CORE_MUTEX_DISCIPLINES_PRIORITY_INHERIT: 
> 	_Thread_Executing->priority_resource_count++;
>         break;    
>     }     
Index: score/src/coremutexsurrender.c
===================================================================
RCS file: /data/prj_sw/cvs/rtems/c/src/exec/score/src/coremutexsurrender.c,v
retrieving revision 1.1.1.1
diff -r1.1.1.1 coremutexsurrender.c
105c105,110
<       if ( holder->resource_count == 0 && 
---
>       _Thread_Executing->priority_resource_count--;
>       /* !!TR: Fix docu on priority inheritance 8.2.3 3rd paragraph:
>        * Use "binary semaphore using priority inheritance" instead 
>        * of "binary semaphore".
>        */
>       if ( holder->priority_resource_count == 0 && 
130a136,144
>       switch ( the_mutex->Attributes.discipline ) {
>         case CORE_MUTEX_DISCIPLINES_FIFO:
>         case CORE_MUTEX_DISCIPLINES_PRIORITY:
>           break;
>         case CORE_MUTEX_DISCIPLINES_PRIORITY_CEILING:  
>         case CORE_MUTEX_DISCIPLINES_PRIORITY_INHERIT: 
> 	  the_thread->priority_resource_count++;
>           break;    
>       }     
Index: score/src/threadinitialize.c
===================================================================
RCS file: /data/prj_sw/cvs/rtems/c/src/exec/score/src/threadinitialize.c,v
retrieving revision 1.2
diff -r1.2 threadinitialize.c
159a160
>   the_thread->priority_resource_count= 0;
Index: score/src/threadreset.c
===================================================================
RCS file: /data/prj_sw/cvs/rtems/c/src/exec/score/src/threadreset.c,v
retrieving revision 1.1.1.1
diff -r1.1.1.1 threadreset.c
45a46
>   the_thread->priority_resource_count = 0;


More information about the users mailing list