11.07.2015 Views

POSIX-Compatible Application-Defined Scheduling in MaRTE OS

POSIX-Compatible Application-Defined Scheduling in MaRTE OS

POSIX-Compatible Application-Defined Scheduling in MaRTE OS

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

A different approach is followed <strong>in</strong> the CPU Inheritance<strong>Schedul<strong>in</strong>g</strong> [9], <strong>in</strong> which the kernel only implements threadblock<strong>in</strong>g, unblock<strong>in</strong>g and CPU donation, and the applicationdef<strong>in</strong>ed schedulers are threads which donate the CPUto other threads. In this approach the only method used toavoid priority <strong>in</strong>version is the priority <strong>in</strong>heritance.Although other synchronization policies could be implemented,the lack of an <strong>in</strong>terface to trigger schedul<strong>in</strong>g decisionsby the use of mutexes makes it difficult or impossibleto implement general synchronization protocols, whichmay be a limitation for special application-def<strong>in</strong>ed policies.In addition although this approach supports multiprocessorschedulers, it is not possible to have one s<strong>in</strong>gle-threadedscheduler to schedule threads <strong>in</strong> other processors. Somemultiprocessor architectures, for example us<strong>in</strong>g one general-purposeprocessor runn<strong>in</strong>g the scheduler and an arrayof digital signal processors runn<strong>in</strong>g the scheduled threads,may require that capability.Another common solution is to implement the applicationschedul<strong>in</strong>g algorithms as modules to be <strong>in</strong>cluded orl<strong>in</strong>ked with the kernel (S.Ha.R.K [10], RT-L<strong>in</strong>ux [12], Vassal[13]). With this mechanism the functions exported bythe modules are <strong>in</strong>voked from the kernel at every schedul<strong>in</strong>gpo<strong>in</strong>t. This is a very efficient and general method but asa drawback, the application schedul<strong>in</strong>g algorithms can neitherbe isolated from each other nor from the kernel itself,so, a bug <strong>in</strong> one of them could affect the whole system.In our approach the application scheduler is <strong>in</strong>voked atevery schedul<strong>in</strong>g po<strong>in</strong>t like with the kernel modules, so thescheduler can have complete control over its scheduledthreads. But <strong>in</strong> addition, our application schedul<strong>in</strong>g algorithmis executed by a user thread. This fact implies twoimportant advantages from our po<strong>in</strong>t of view:a) The system reliability can be improved by protect<strong>in</strong>gthe system from the actions of an erroneous applicationscheduler. For efficiency, our <strong>in</strong>terface allowsexecution of the application-def<strong>in</strong>ed scheduler <strong>in</strong> anexecution environment different than that of regularapplication thread, for example <strong>in</strong>side the kernel. Butalternatively, the <strong>in</strong>terface allows the implementation toexecute the scheduler <strong>in</strong> the environment of theapplication, to isolate it from the kernel. In this way,high priority threads that are critical cannot be affectedby a faulty scheduler execut<strong>in</strong>g at a lower priority level.b) The application schedul<strong>in</strong>g code can use standard<strong>in</strong>terfaces like those def<strong>in</strong>ed <strong>in</strong> the <strong>P<strong>OS</strong>IX</strong> standard. Insome systems part of these <strong>in</strong>terfaces might not beaccessible for <strong>in</strong>vocation from <strong>in</strong>side the kernel.We have designed our <strong>in</strong>terface so that several application-def<strong>in</strong>edschedulers can be def<strong>in</strong>ed, and so that theyhave a behavior compatible with other exist<strong>in</strong>g schedul<strong>in</strong>gpolicies <strong>in</strong> <strong>P<strong>OS</strong>IX</strong>, both on s<strong>in</strong>gle processor and multiprocessorplatforms. In addition, the <strong>in</strong>terface needs to take<strong>in</strong>to account the implementation of application-def<strong>in</strong>edsynchronization protocols.The dynamic schedul<strong>in</strong>g mechanism proposed for Real-Time CORBA 2.0 [11] represents an object-oriented <strong>in</strong>terfaceto application-def<strong>in</strong>ed schedulers, but it does notattempt to def<strong>in</strong>e how that <strong>in</strong>terface communicates with theoperat<strong>in</strong>g system. The <strong>in</strong>terface presented <strong>in</strong> this paper isthe <strong>OS</strong> low-level <strong>in</strong>terface, and thus an RT CORBA implementationcould use it to support the proposed dynamicschedul<strong>in</strong>g <strong>in</strong>terface.In summary, the motivation for this work is to providedevelopers of applications runn<strong>in</strong>g on top of standard operat<strong>in</strong>gsystems (<strong>P<strong>OS</strong>IX</strong>) with a flexible schedul<strong>in</strong>g mechanism,handl<strong>in</strong>g both thread schedul<strong>in</strong>g andsynchronization, that enables them to schedule dynamicapplications that would not meet their requirements us<strong>in</strong>gthe more rigid fixed-priority schedul<strong>in</strong>g provided <strong>in</strong> thoseoperat<strong>in</strong>g systems. This mechanism allows isolation of thekernel from misbehaved application schedulers. In addition,we wish to provide this mechanism both for applicationsdeveloped <strong>in</strong> C or Ada.3. Model for <strong>Application</strong>-<strong>Def<strong>in</strong>ed</strong><strong>Schedul<strong>in</strong>g</strong>Figure 1 shows the proposed approach for applicationdef<strong>in</strong>edschedul<strong>in</strong>g. Each application scheduler is a specialk<strong>in</strong>d of thread, that is responsible of schedul<strong>in</strong>g a set ofthreads that have been attached to it. This leads to twoclasses of threads <strong>in</strong> this context:•<strong>Application</strong> scheduler threads: special threads used torun application schedulers.•Regular threads: regular application threadsThe application schedulers can run <strong>in</strong> the context of thekernel or <strong>in</strong> the context of the application. This allowsimplementations <strong>in</strong> which application threads are nottrusted, and therefore their schedulers run <strong>in</strong> the context ofSystem-scheduledTasksSystemSchedulerUser Space<strong>Application</strong>Scheduler<strong>Application</strong>SchedulerScheduler Space<strong>Application</strong> scheduler tasksApp. ScheduledTasksRegular TasksApp. ScheduledTasksFigure 1. Model for <strong>Application</strong> <strong>Schedul<strong>in</strong>g</strong>


the application, as well as implementations for trustedapplication schedulers, which can run more efficiently<strong>in</strong>side the kernel. Because of this duality we will model thescheduler threads as if they run <strong>in</strong> a separate context, whichwe call the scheduler space. The ma<strong>in</strong> implication of thisseparate space is that for portability purposes the applicationschedulers cannot directly share <strong>in</strong>formation with thekernel, nor with regular threads, except by us<strong>in</strong>g the<strong>P<strong>OS</strong>IX</strong> shared memory objects, which is the mechanismfor shar<strong>in</strong>g memory among entities with different addressspaces.Accord<strong>in</strong>g to the way a thread is scheduled, we can categorizethe threads as:•System-scheduled threads: these threads are scheduleddirectly by the operat<strong>in</strong>g system, without <strong>in</strong>tervention ofa scheduler thread.•<strong>Application</strong>-scheduled threads: these threads are alsoscheduled by the operat<strong>in</strong>g system, but before they canbe scheduled, they need to be activated by their application-def<strong>in</strong>edscheduler.Although an application scheduler thread can itself beapplication scheduled, implementations should not berequired to support this feature, because usually thesethreads will be system scheduled.Because the use of mutexes may cause priority <strong>in</strong>versionsor similar delay effects, it is necessary that the schedulerthread knows about their use, to establish its ownprotocols adapted to the particular thread schedul<strong>in</strong>g policy.As we show <strong>in</strong> Figure 2, two k<strong>in</strong>ds of mutexes will beconsidered:•System-scheduled mutexes. Those created with the current<strong>P<strong>OS</strong>IX</strong> protocols: no priority <strong>in</strong>heritance(PTHREAD_PRIO_NONE), immediate priority ceil<strong>in</strong>g(PTHREAD_PRIO_PROTECT), or basic priority <strong>in</strong>heritance(PTHREAD_PRIO_INHERIT). They can be used toaccess resources shared between application schedulers,between sets of application-scheduled threads attached todifferent schedulers, or even between an applicationSystem-scheduledTasksRegularMutex or PORegularMutex or PO<strong>Application</strong>Scheduler<strong>Application</strong>SchedulerApp. ScheduledTasksRegularMutex or POApp. ScheduledTasksFigure 2. Model for <strong>Application</strong>-<strong>Def<strong>in</strong>ed</strong>SynchronizationApp. Sched.MutexApp. Sched.Mutexscheduler and its scheduled threads (<strong>in</strong> this case themutex and its protected state must be placed <strong>in</strong> a <strong>P<strong>OS</strong>IX</strong>shared memory object).•<strong>Application</strong>-scheduled mutexes: Those created withPTHREAD_APPSCHED_PROTOCOL. The behavior of theprotocol itself is def<strong>in</strong>ed by the application scheduler.The kernel notifies the scheduler about the request tolock one such mutex, the execution of an unlock operation,or when a thread blocks on one of these mutexes.After the lock request operation the application schedulercan chose to grant or not the mutex to the request<strong>in</strong>gthread. The block event might not be necessary <strong>in</strong> someschedulers that implement non-block<strong>in</strong>g synchronizationprotocols.3.1. Relations with Other ThreadsEach thread <strong>in</strong> the system, whether application- or system-scheduled,has a system priority:•For system-scheduled threads, the system priority is thepriority def<strong>in</strong>ed <strong>in</strong> its schedul<strong>in</strong>g parameters(sched_priority field of its sched_param structure),possibly modified by the <strong>in</strong>heritance of other prioritiesthrough the use of mutexes.•For application-scheduled threads, the system priority islower than or equal to the system priority of their schedulerthread. The system priority of an application-scheduledthread may change because of the <strong>in</strong>heritance ofother system priorities through the use of mutexes. Inthat case, its scheduler also <strong>in</strong>herits the same system priority(but this priority is not <strong>in</strong>herited by the rest of thethreads scheduled by that scheduler). In addition to thesystem priority, application-scheduled threads haveapplication schedul<strong>in</strong>g parameters that are used toschedule that thread contend<strong>in</strong>g with the other threadsattached to the same application scheduler. The systempriority always takes precedence over any applicationschedul<strong>in</strong>g parameters. Therefore, application-scheduledthreads and their scheduler take precedence overthreads with lower system priority, and they are alwayspreempted by threads with higher system priority thatbecome ready. The scheduler always takes precedenceover its scheduled threads.If application-scheduled threads coexist at the same prioritylevel with other system-scheduled threads, then<strong>P<strong>OS</strong>IX</strong> schedul<strong>in</strong>g rules apply as if the application-scheduledthreads were scheduled under the FIFO with<strong>in</strong> prioritiespolicy (SCHED_FIFO); so a thread runs untilcompletion, until blocked, or until preempted, whateverhappens earlier. A thread runn<strong>in</strong>g under the round-rob<strong>in</strong>with<strong>in</strong> priorities policy (SCHED_RR) runs until completion,until blocked, until preempted, or until its round rob<strong>in</strong>quantum has been consumed, whatever happens earlier. Of


Table 1: <strong>Schedul<strong>in</strong>g</strong> EventsEvent CodeDescriptionAdditional<strong>in</strong>formation<strong>P<strong>OS</strong>IX</strong>_APPSCHED_NEW A new thread has requested attachment to the scheduler none<strong>P<strong>OS</strong>IX</strong>_APPSCHED_TERMINATE A thread has been term<strong>in</strong>ated none<strong>P<strong>OS</strong>IX</strong>_APPSCHED_READY A thread has become unblocked by the system none<strong>P<strong>OS</strong>IX</strong>_APPSCHED_BLOCK A thread has blocked none<strong>P<strong>OS</strong>IX</strong>_APPSCHED_YIELD A thread yields the CPU none<strong>P<strong>OS</strong>IX</strong>_APPSCHED_SIGNALA signal belong<strong>in</strong>g to the requested set has beenaccepted by the scheduler thread.Signal-related<strong>in</strong>formation<strong>P<strong>OS</strong>IX</strong>_APPSCHED_CHANGE_SCHED_PARAM A thread has changed its schedul<strong>in</strong>g parameters none<strong>P<strong>OS</strong>IX</strong>_APPSCHED_EXPLICIT_CALL A thread has explicitly <strong>in</strong>voked the scheduler <strong>Application</strong>message<strong>P<strong>OS</strong>IX</strong>_APPSCHED_TIMEOUT A timeout has expired none<strong>P<strong>OS</strong>IX</strong>_APPSCHED_PRIORITY_INHERINTA thread has <strong>in</strong>herited a new system priority due to theuse of system mutexesInherited systempriority<strong>P<strong>OS</strong>IX</strong>_APPSCHED_PRIORITY_UNINHERIT A thread has f<strong>in</strong>ished the <strong>in</strong>heritance of a system priority Un<strong>in</strong>heritedsystem priority<strong>P<strong>OS</strong>IX</strong>_APPSCHED_INIT_MUTEXA thread has requested <strong>in</strong>itialization of an applicationscheduledmutexPo<strong>in</strong>ter to themutex<strong>P<strong>OS</strong>IX</strong>_APPSCHED_DESTROY_MUTEX A thread has destroyed an application-scheduled mutex Po<strong>in</strong>ter to themutex<strong>P<strong>OS</strong>IX</strong>_APPSCHED_LOCK_MUTEXA thread has <strong>in</strong>voked a “lock” operation on an availableapplication- scheduled mutexPo<strong>in</strong>ter to themutex<strong>P<strong>OS</strong>IX</strong>_APPSCHED_TRY_LOCK_MUTEXA thread has <strong>in</strong>voked a “try lock” operation on anavailable application- scheduled mutexPo<strong>in</strong>ter to themutex<strong>P<strong>OS</strong>IX</strong>_APPSCHED_UNLOCK_MUTEXA thread has released the lock of an applicationscheduledmutexPo<strong>in</strong>ter to themutex<strong>P<strong>OS</strong>IX</strong>_APPSCHED_BLOCK_AT_MUTEX A thread has blocked at an application-scheduled mutex Po<strong>in</strong>ter to themutex<strong>P<strong>OS</strong>IX</strong>_APPSCHED_CHANGE_MUTEX_SCHED_PARAMA thread has changed the schedul<strong>in</strong>g parameters of anapplication-scheduled mutexPo<strong>in</strong>ter to themutex•Accept or reject a thread that has requested attachment tothis scheduler•Activate or suspend an application scheduled thread•Accept or reject <strong>in</strong>itialization of an application-scheduledmutex•Grant the lock of an application-scheduled mutexThe list of actions will be prepared by the schedulerthread and reported to the system via a call to theposix_appsched_execute_actions() function. Thisfunction is the ma<strong>in</strong> operation <strong>in</strong> our <strong>in</strong>terface. It allows theapplication scheduler to execute a list of schedul<strong>in</strong>g actionsand then it suspends wait<strong>in</strong>g for the next schedul<strong>in</strong>g eventto be reported by the system. If desired, a timeout can beset as an additional return condition which will occur whenthere is no schedul<strong>in</strong>g event available but the timeoutexpires. The system time measured immediately before thefunction returns can be requested if it is relevant for thealgorithm.The posix_appsched_execute_actions() functioncan also be programmed to return when a <strong>P<strong>OS</strong>IX</strong> signalis generated for the thread. This possibility eases theuse of <strong>P<strong>OS</strong>IX</strong> timers, <strong>in</strong>clud<strong>in</strong>g CPU-time timers, assources of schedul<strong>in</strong>g events for our scheduler threads. Theprototype of this function is:<strong>in</strong>t posix_appsched_execute_actions(const posix_appsched_actions_t *sched_actions,const sigset_t *set,const struct timespec *timeout,struct timespec *current_time,struct posix_appsched_event *event);


4.1.3. Scheduled Thread-Specific DataWhen a scheduler is process<strong>in</strong>g an event, the schedul<strong>in</strong>gactions to execute will depend on the current schedul<strong>in</strong>gstatus of its scheduled threads and particularly on the statusof the thread which caused that event. It would be very<strong>in</strong>terest<strong>in</strong>g to have a mechanism for obta<strong>in</strong><strong>in</strong>g that <strong>in</strong>formation<strong>in</strong> a straightforward and efficient way. Because the<strong>P<strong>OS</strong>IX</strong> thread identification type, pthread_t, is opaque,it is not possible to build a portable hash<strong>in</strong>g function at theapplication level, and thus a list <strong>in</strong>dexed by thread idswould be <strong>in</strong>efficient.Consequently, our <strong>in</strong>terface extends the <strong>P<strong>OS</strong>IX</strong> “threadspecificdata” functionality. Two new functions are def<strong>in</strong>ed(pthread_getspecific_thread()andpthread_setspecific_thread()) that permit sett<strong>in</strong>gand gett<strong>in</strong>g thread-specific data from a thread differentfrom the owner. The scheduler thread can use those functionsfor attach<strong>in</strong>g and retriev<strong>in</strong>g the schedul<strong>in</strong>g status ofits scheduled threads.4.2. Create scheduler and scheduled threadsIn our <strong>in</strong>terface a scheduler thread is created as such. Ascheduled thread can be created attached to a particularthread. For these purposes our <strong>in</strong>terface extends the threadcreation attributes, the schedul<strong>in</strong>g policies, and schedul<strong>in</strong>gparameters def<strong>in</strong>ed <strong>in</strong> the <strong>P<strong>OS</strong>IX</strong> standard.A new policy “<strong>Application</strong>-def<strong>in</strong>ed <strong>Schedul<strong>in</strong>g</strong> Policy”(SCHED_APP) is def<strong>in</strong>ed to dist<strong>in</strong>guish between systemscheduledand application-scheduled threads. For a threadto be created with this policy it is necessary to def<strong>in</strong>e whichthread is go<strong>in</strong>g to act as its application scheduler and,optionally, an application-def<strong>in</strong>ed schedul<strong>in</strong>g parametersobject to be <strong>in</strong>terpreted by this scheduler thread. Both, thescheduler and the application-def<strong>in</strong>ed parameters are<strong>in</strong>cluded as new members of the <strong>P<strong>OS</strong>IX</strong> schedul<strong>in</strong>g parametersstructure (sched_param).Whether a thread is an application scheduler or not isdeterm<strong>in</strong>ed by the value of its appscheduler attribute.After its creation, an application scheduler thread can setsome of its properties through different functions def<strong>in</strong>ed<strong>in</strong> the <strong>in</strong>terface. The properties are the k<strong>in</strong>d of timeout thatis supported (relative or absolute), the clock used to determ<strong>in</strong>ewhen the timeout expires, and the event mask thatallows schedul<strong>in</strong>g events to be filtered out by the system,and thus are not reported to the application scheduler.4.3. Explicit Scheduler InvocationExplicit scheduler <strong>in</strong>vocation from the scheduled threadcould be necessary <strong>in</strong> some schedul<strong>in</strong>g algoritms (forexample as a mechanism to <strong>in</strong>form the scheduler a threadhas f<strong>in</strong>ish its work for the current activation). For this purpose,our <strong>in</strong>terface def<strong>in</strong>es the posix_appsched_-<strong>in</strong>voke_scheduler() function. Call<strong>in</strong>g this functionwill cause a schedul<strong>in</strong>g event of type<strong>P<strong>OS</strong>IX</strong>_APPSCHED_EXPLICIT_CALL to be generated forthe scheduler. Optionally, a message can be attached to theevent.4.4. <strong>Application</strong>-Scheduled MutexesAs expla<strong>in</strong>ed above, our <strong>in</strong>terface allows creat<strong>in</strong>gmutexes whose synchronization protocol is def<strong>in</strong>ed by theapplication scheduler. These special mutexes are createdlike any other <strong>P<strong>OS</strong>IX</strong> mutex but specify<strong>in</strong>g the valuePTHREAD_APPSCHED_PROTOCOL for they protocolattribute. For this k<strong>in</strong>d of mutexes two new attributes havebeen def<strong>in</strong>ed: the appscheduler attribute and the appschedparamattribute. The appscheduler attribute identifiesthe scheduler thread the mutex is attached to. Theoptional appschedparam attribute can be used for pass<strong>in</strong>gapplication-def<strong>in</strong>ed mutex schedul<strong>in</strong>g attributes to thescheduler.As for the application-scheduled threads, it is alsoimportant for the scheduler to have a simple mechanism toattach and retrieve the schedul<strong>in</strong>g specific data associatedwith an application-scheduled mutex. With this purposeour <strong>in</strong>terface <strong>in</strong>troduces a new functionality not def<strong>in</strong>ed <strong>in</strong><strong>P<strong>OS</strong>IX</strong>: the mutex-specific data, and two functions:posix_appsched_mutex_setspecific() andposix_appsched_mutex_getspecific(), to get andset the value currently bound to a mutex.5. Example of an <strong>Application</strong>-<strong>Def<strong>in</strong>ed</strong>Policy: EDF with CBSThe follow<strong>in</strong>g example shows the pseudocode of anapplication scheduler that implements the Earliest Deadl<strong>in</strong>eFirst (EDF) schedul<strong>in</strong>g policy along with the ConstantBandwidth Server (CBS) [2] schedul<strong>in</strong>g policy. The latterpolicy allows schedul<strong>in</strong>g soft real-time tasks without jeopardiz<strong>in</strong>gthe priority guarantee of hard real-time activities.The CBS assigns each soft task a maximum bandwidth andassures that it is not overcome even <strong>in</strong> the presence of overloads.In our example the asynchronous arrival of a new jobfor a CBS thread causes the generation of a signal(NEW_JOB_SIGNAL) to be caught by the schedulerthread.In order to assure that a CBS thread does not overcomeits assigned bandwidth its execution time must be limited.To achieve that, a <strong>P<strong>OS</strong>IX</strong> CPU-time timer is associatedwith each CBS thread, and the signal generated by thetimer expiration is caught by the scheduler thread to performthe appropriate schedul<strong>in</strong>g actions.The EDF/CBS scheduler has a list of threads that areregistered for be<strong>in</strong>g scheduled under it, either as EDF or


CBS threads. The state of each EDF thread can be active ortimed (when it has f<strong>in</strong>ished its current execution and iswait<strong>in</strong>g for its next period), while the CBS threads can beactive or idle (a CBS thread with not pend<strong>in</strong>g jobs).The schedule_next() function <strong>in</strong>voked by the schedulerupdates the list of registered threads based upon thecurrent time. It switches <strong>in</strong>to the active state those timedthreads whose activation time has been reached, and thencalculates the next thread to be executed and the earlieststart time of the new set of timed threads.The pseudocode of the scheduler is the follow<strong>in</strong>g:void *edf_scheduler (void *arg){...;while (1) {schedule_next (&next_thread, &earliest_start,&now);/* Thread activation and suspension actions*/if (next_thread != NULL)posix_appsched_actions_addactivate(&actions, next_thread);if (current_thread != NULL)posix_appsched_actions_addsuspend(&actions, current_thread);current_thread = next_thread;/* Execute schedul<strong>in</strong>g actions */posix_appsched_execute_actions(&actions, &awaited_signal_set,&earliest_start, &now, &sched_event);/* Process schedul<strong>in</strong>g events */switch (sched_event.event_code) {case <strong>P<strong>OS</strong>IX</strong>_APPSCHED_NEW :Get thread EDF/CBS specific sched param;if (CBS thread) { Create CPU-time timer; }Add thread to list of scheduled threads;break;case <strong>P<strong>OS</strong>IX</strong>_APPSCHED_TERMINATE :if (CBS thread) { Delete CPU-time timer; }Remove thread from scheduled threads list;break;case <strong>P<strong>OS</strong>IX</strong>_APPSCHED_EXPLICIT_CALL :if (CBS thread) {thread.number_of_pend<strong>in</strong>g_jobs--;if (thread.number_of_pend<strong>in</strong>g_jobs == 0)thread.state=CBS_IDLE;} else { // is EDFthread.state=TIMED;Obta<strong>in</strong> next deadl<strong>in</strong>e & activation time;} break;case <strong>P<strong>OS</strong>IX</strong>_APPSCHED_SIGNAL :switch (received signal) {case END_OF_BUDGET_SIGNAL :thread.deadl<strong>in</strong>e += thread.period;thread.budget = thread.max_budget;Arm CPU-timer for 'thread.budget' secs;break;case NEW_JOB_SIGNAL :thread.number_of_pend<strong>in</strong>g_jobs++;if (thread.state==CBS_IDLE) {thread.state=ACTIVE;if (not enough time until deadl<strong>in</strong>e) {thread.deadl<strong>in</strong>e += thread.period;thread.budget = thread.max_budget;Arm CPU-timer for'thread.budget' secs;}}}break;case <strong>P<strong>OS</strong>IX</strong>_APPSCHED_TIMEOUT :break; // threads will be rescheduled} // switch} // while (1)}The pseudocode of one of the application-scheduledthreads is the follow<strong>in</strong>g:void * edf_or_cbs_thread (void * arg){while (1) {// do useful work...// tell the scheduler that the// current job has f<strong>in</strong>ishedpthread_appsched_<strong>in</strong>voke_scheduler ();}}The scheduler needs to know the period and the deadl<strong>in</strong>eof the EDF periodic threads and the maximum budget ofthe CBS threads. To store that <strong>in</strong>formation, theedf_cbs_parameters_t type is created:typedef struct {<strong>in</strong>t cbs_thread;struct timespec deadl<strong>in</strong>e, period, max_budget;} edf_cbs_parameters_t;The posix_appsched_param field of thesched_param structure assigned to an EDF or CBS threadwill po<strong>in</strong>t to an object of this type. Us<strong>in</strong>g the <strong>P<strong>OS</strong>IX</strong> functionpthread_getschedparam() the scheduler will beable to get the schedul<strong>in</strong>g parameters of its attachedthreads.F<strong>in</strong>ally, the pseudocode of a thread that creates thescheduler, a periodic EDF thread and a CBS thread is:<strong>in</strong>t ma<strong>in</strong> (){...;// Set attr object for the scheduler threadSet policy to FIFO;Set the thread type to “application scheduler”;// Create scheduler threadpthread_create (attr object, edf_scheduler);// Set the attributes object for an EDF threadSet policy to application-def<strong>in</strong>ed;Set the thread type to “regular”;Set edf_scheduler as its application scheduler;Set period and deadl<strong>in</strong>e <strong>in</strong> the applicationdef<strong>in</strong>ed schedul<strong>in</strong>g parameters;// Create EDF threadpthread_create (attributes object, edf_thread);


}// Set the attributes object for a CBS threadSet policy to application-def<strong>in</strong>ed;Set the thread type to “regular”;Set edf_scheduler as its application scheduler;Set period, deadl<strong>in</strong>e and max_budget <strong>in</strong> theapplication def<strong>in</strong>ed schedul<strong>in</strong>g parameters;// Create CBS threadpthread_create (attributes object, cbs_thread);6. Performance MetricsTable 2 shows some performance metrics measured on a1.1 GHz Pentium III, relative to a context switch between aCBS thread that consumes its execution time budget, andan EDF thread that becomes active. The first three entries<strong>in</strong> the table show the execution times of different parts ofthis context switch. The total is 4.1 µs, which represents anoverhead of 0.82% for a 1KHz periodic thread, assum<strong>in</strong>gtwo context switches per execution. Of course, this overheadwould be lower for lower frequency threads. As acomparison, the last entry <strong>in</strong> the table shows the contextswitch time associated with a timer expiration, us<strong>in</strong>g thekernel-level fixed-priority scheduler. This time (1.1 µs)must be compared with the time needed to activate thescheduler (1.8 µs) and to activate a new thread (1.0 µs) todeterm<strong>in</strong>e the overhead of the application-def<strong>in</strong>ed schedul<strong>in</strong>gmechanism. We can see that this overhead is around2.54 times the overhead of the <strong>in</strong>ternal kernel scheduler. Inour op<strong>in</strong>ion, this penalty is small compared to the benefitsof be<strong>in</strong>g able to def<strong>in</strong>e application schedulers <strong>in</strong> a flexibleand portable way.Table 2. Performance on a 1.1 GHz Pentium IIIDescriptionTime (µs)Scheduler activation after CPU-timer expiration 1.8<strong>Schedul<strong>in</strong>g</strong> algorithm time 1.3EDF thread activation 1.0Total context switch time 4.1Context switch after timer expiration 1.17. Conclusions and Further WorkWe have def<strong>in</strong>ed a new API for application-def<strong>in</strong>edschedul<strong>in</strong>g. There are two versions of the API, one <strong>in</strong> Cand the other one <strong>in</strong> Ada. Both are designed <strong>in</strong> the contextof a <strong>P<strong>OS</strong>IX</strong> operat<strong>in</strong>g system. The ma<strong>in</strong> design requirementshave been to have a compatible behavior with otherexist<strong>in</strong>g <strong>P<strong>OS</strong>IX</strong> fixed priority schedul<strong>in</strong>g policy, to be ableto isolate the scheduler from the kernel and from otherapplication schedulers, to be able to run both on s<strong>in</strong>gle processorand multiprocessor systems, and to be able todescribe application-def<strong>in</strong>ed synchronization protocols.The proposed API has been implemented <strong>in</strong> <strong>MaRTE</strong> <strong>OS</strong>,which is a free software implementation of the <strong>P<strong>OS</strong>IX</strong> m<strong>in</strong>imalreal-time operat<strong>in</strong>g system, <strong>in</strong>tended for small embeddedsystems. It is written <strong>in</strong> Ada but provides both the<strong>P<strong>OS</strong>IX</strong> Ada and the C <strong>in</strong>terfaces. Us<strong>in</strong>g this implementationwe have programmed and tested several schedul<strong>in</strong>gpolicies, such as a priority-based round rob<strong>in</strong> scheduler,EDF, and more complex dynamic schedul<strong>in</strong>g policies. Wehave also tested some application-def<strong>in</strong>ed synchronizationprotocols, such as the full Priority Ceil<strong>in</strong>g Protocol. Prelim<strong>in</strong>aryperformance data show a good level of efficiency.<strong>MaRTE</strong> <strong>OS</strong>, <strong>in</strong>clud<strong>in</strong>g the application-def<strong>in</strong>ed schedul<strong>in</strong>gservices def<strong>in</strong>ed <strong>in</strong> this paper can be found at:http://marte.unican.esReferences[1] ISO/IEC 9945-1 (1996). ISO/IEC Standard 9945-1:1996.Information Technology -Portable Operat<strong>in</strong>g System Interface(<strong>P<strong>OS</strong>IX</strong>)- Part 1: System <strong>Application</strong> Program Interface (API)[C Language]. Institute of Electrical and electronicEng<strong>in</strong>eers.[2] L. Abeni and G. Buttazzo. “Integrat<strong>in</strong>g Multimedia<strong>Application</strong>s <strong>in</strong> Hard Real-Time Systems”. Proceed<strong>in</strong>gs of theIEEE Real-Time Systems Symposium, Madrid, Spa<strong>in</strong>,December 1998[3] M. Aldea Rivas and M. González Harbour. “<strong>P<strong>OS</strong>IX</strong>-<strong>Compatible</strong> <strong>Application</strong>-<strong>Def<strong>in</strong>ed</strong> <strong>Schedul<strong>in</strong>g</strong> <strong>in</strong> <strong>MaRTE</strong> <strong>OS</strong>”.Proceed<strong>in</strong>gs of the Work <strong>in</strong> Progress Session, 13th EuromicroConference on Real-Time Systems, Delft, The Netherlands,June 2001.[4] M. Aldea and M. González. “<strong>MaRTE</strong> <strong>OS</strong>: An Ada Kernel forReal-Time Embedded <strong>Application</strong>s”. Proceed<strong>in</strong>gs of theInternational Conference on Reliable Software Technologies,Ada-Europe-2001, Leuven, Belgium, Lecture Notes <strong>in</strong>Computer Science, LNCS 2043, May, 2001.[5] <strong>P<strong>OS</strong>IX</strong>.1d (1999). IEEE Std. 1003.d-1999. InformationTechnology -Portable Operat<strong>in</strong>g System Interface (<strong>P<strong>OS</strong>IX</strong>)-Part 1: System <strong>Application</strong> Program Interface (API)Amendment: Additional Realtime Extensions [C Language].The Institute of Electrical and Electronics Eng<strong>in</strong>eers.[6] <strong>P<strong>OS</strong>IX</strong>.13 (1998). IEEE Std. 1003.13-1998. InformationTechnology -Standardized <strong>Application</strong> Environment Profile-<strong>P<strong>OS</strong>IX</strong> Realtime <strong>Application</strong> Support (AEP). The Institute ofElectrical and Electronics Eng<strong>in</strong>eers.[7] <strong>P<strong>OS</strong>IX</strong>.5b (1996). IEEE Std 1003.5b-1996, InformationTechnology—<strong>P<strong>OS</strong>IX</strong> Ada Language Interfaces—Part 1:B<strong>in</strong>d<strong>in</strong>g for System <strong>Application</strong> Program Interface (API)—Amendment 1: Realtime Extensions. The Institute ofElectrical and Eng<strong>in</strong>eer<strong>in</strong>g Electronics.[8] Y.C. Wang and K.J. L<strong>in</strong>, “Implement<strong>in</strong>g a general real-timeschedul<strong>in</strong>g framework <strong>in</strong> the red-l<strong>in</strong>ux real-time kernel”.Proceed<strong>in</strong>gs of IEEE Real-Time Systems Symposium,Phoenix, December 1999.


[9] Bryan Ford and Sai Susarla, “CPU Inheritance <strong>Schedul<strong>in</strong>g</strong>”.Proceed<strong>in</strong>gs of <strong>OS</strong>DI, October 1996.[10]P. Gai, L. Abeni, M. Giorgi, G. Buttazzo, "A New KernelApproach for Modular Real-Time Systems Development",IEEE Proceed<strong>in</strong>gs of the 13th Euromicro Conference on Real-Time Systems, Delft, The Netherlands, June 2001.[11]OMG. Real-Time CORBA 2.0: Dynamic <strong>Schedul<strong>in</strong>g</strong>, Jo<strong>in</strong>tF<strong>in</strong>al Submission. OMG Document orbos/2001-06-09, June2001.[12]Yodaiken V., “An RT-L<strong>in</strong>ux Manifesto”. Proceed<strong>in</strong>gs of the5th L<strong>in</strong>ux Expo, Raleigh, North Carol<strong>in</strong>a, USA, May 1999.[13]George M. Candea and Michael B. Jones, “Vassal: LoadableScheduler Support for Multi-Policy <strong>Schedul<strong>in</strong>g</strong>”. Proceed<strong>in</strong>gsof the Second USENIX W<strong>in</strong>dows NT Symposium, Seattle,Wash<strong>in</strong>gton, August 1998.[14]F. Mueller, V. Rustagi, and T.P. Baker. “MiTh<strong>OS</strong> - A Real-Time Micro-Kernel Threads Operat<strong>in</strong>g System”. Proceed<strong>in</strong>gsof the IEEE Real-Time Systems Symposium, December1995.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!