Thread question

Kenneth Peters Kenneth.J.Peters at jpl.nasa.gov
Mon Dec 13 16:45:33 UTC 2004


At 10:23 AM 12/13/2004 -0600, Joel Sherrill <joel at OARcorp.com> wrote:
>Steve Holle wrote:
>>At 05:05 PM 12/10/2004, Angelo Fraietta wrote:
>>
>>>Steve Holle wrote:
>>>
>>>>If I disable task 1A, 1B keeps running even with the streaming audio 
>>>>running.
>>>>
>>>>I assumes that since 1A and 1B where set up to timeslice that whatever 
>>>>time was left 1A and 1B would get serviced.  That is obviously a false 
>>>>assumption.
>>>
>>>
>>>I am pretty sure that if a higher priority thread takes control at any 
>>>stage, the thread that was switched out will get switched back in; 
>>>however, it's timeslices will start again at zero. It is possible in 
>>>that case for one thread to get starved because the thread of equal 
>>>priority keeps getting switched back with it's timeslice count set back 
>>>to the start
>>
>>I'm not sure I understand this.  Why should it's timeslice restart?
>>That seems counter-intuitive.  That would explain the symptoms we are 
>>seeing but I'm not sure I understand the purpose and how to use 
>>timeslicing if this is the case.
>
>THe way timeslicing is defined in the Classic API, it is just a limit on
>how long a thread can run without giving up the processor.  If it ever
>gives up the CPU, it will have its timeslice reset when it runs again.
>
>POSIX has a slightly different definition of timeslice quantum
>handling.  It is not reset until it is actually exhausted.
>
>A quick hack to try the POSIX version is to change the taskcreate.c
>call to _Thread_initialize to use EXHAUST_TIMESLICE not RESET_TIMESLICE.
>There has been a wishlist for a while to be able to specify which
>algorithm to use.  Maybe you have finally got a case where it matters. :)
>
>--joel

FYI, I've been using a hacked version of rtems_task_mode() to set these 
parameters after creating classic tasks (but before starting them 
executing). It has worked fine for me. See diffs against 4.5.0 taskmode.c 
below.

I did it this way because I did not want to hack the OS itself (for 
administrative reasons we need to use an "oficial release" as much as 
possible), so I made my own copy of taskmode.c to build into my own code 
and changed the name to reveal the guilty.

Ken Peters

12c12
<  *  $Id: taskmode.c,v 1.2 1999/11/17 17:50:27 joel Exp $
---
 >  *  $Id: electra_rtems_taskmode.c,v 1.3 2004/09/16 18:06:06 kenp Exp $
30a31,32
 > #include "../include/electra_task_control.h"
 >
32a35,43
 >  *  electra_rtems_task_mode
 >  *    Copied from rtems-4.5.0 "taskmode.c" and modified by Ken Peters 03 
Oct 2003
 >  *    to allow changing a task's budget_algorithm for timeslicing to
 >  *    not reset the task's timeslice every time the task is dispatched.
 >  *    That functionality is supported by the RTEMS POSIX interface, but not
 >  *    the classic interface.
 >  *    Also set the task's "Start.budget_algorithm", so if the task is 
restarted
 >  *    it keeps the selected timeslicing method.
 >  *
48c59
< rtems_status_code rtems_task_mode(
---
 > rtems_status_code electra_rtems_task_mode(
51c62,64
<   rtems_mode *previous_mode_set
---
 >   rtems_mode *previous_mode_set,
 >   boolean     use_timeslice_exhaustion,
 >   boolean     *previous_use_timeslice_exhaustion
76a90,94
 >   if ( executing->budget_algorithm == 
THREAD_CPU_BUDGET_ALGORITHM_EXHAUST_TIMESLICE )
 >     *previous_use_timeslice_exhaustion = TRUE;
 >   else
 >     *previous_use_timeslice_exhaustion = FALSE;
 >
85,87c103,115
<     if ( _Modes_Is_timeslice(mode_set) )
<       executing->budget_algorithm = 
THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE;
<     else
---
 >     if ( _Modes_Is_timeslice(mode_set) ) {
 >         if ( use_timeslice_exhaustion ) {
 >         executing->budget_algorithm
 >                 = THREAD_CPU_BUDGET_ALGORITHM_EXHAUST_TIMESLICE;
 >               executing->Start.budget_algorithm
 >                 = THREAD_CPU_BUDGET_ALGORITHM_EXHAUST_TIMESLICE;
 >         } else {
 >         executing->budget_algorithm
 >                 = THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE;
 >               executing->Start.budget_algorithm
 >                 = THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE;
 >         }
 >     } else {
88a117
 >       }





More information about the users mailing list