1 // -----------------------------------------------------------------------
2 // Copyright (C) 2006 - 2007 FRESCOR consortium partners:
4 // Universidad de Cantabria, SPAIN
5 // University of York, UK
6 // Scuola Superiore Sant'Anna, ITALY
7 // Kaiserslautern University, GERMANY
8 // Univ. Politecnica Valencia, SPAIN
9 // Czech Technical University in Prague, CZECH REPUBLIC
11 // Thales Communication S.A. FRANCE
12 // Visual Tools S.A. SPAIN
13 // Rapita Systems Ltd UK
16 // See http://www.frescor.org for a link to partners' websites
18 // FRESCOR project (FP6/2005/IST/5-034026) is funded
19 // in part by the European Union Sixth Framework Programme
20 // The European Union is not liable of any use that may be
23 // This file is part of the FRSH implementation
25 // FRSH is free software; you can redistribute it and/or modify
26 // it under the terms of the GNU General Public License as published by
27 // the Free Software Foundation; either version 2, or (at your option)
30 // FRSH is distributed in the hope that it will be useful, but
31 // WITHOUT ANY WARRANTY; without even the implied warranty of
32 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
33 // General Public License for more details.
35 // You should have received a copy of the GNU General Public License
36 // distributed with FRSH; see file COPYING. If not, write to the
37 // Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
40 // As a special exception, if you include this header file into source
41 // files to be compiled, this header file does not by itself cause
42 // the resulting executable to be covered by the GNU General Public
43 // License. This exception does not however invalidate any other
44 // reasons why the executable file might be covered by the GNU General
46 // -----------------------------------------------------------------------
47 //fosa_app_def_sched.h
48 //==============================================
49 // ******** ****** ******** **********
50 // **///// /** ** **////// /** /**
51 // ** /** ** /** /** /**
52 // ******* /** ** /********* /**********
53 // **//// /** ** ////////** /**//////**
54 // ** /** ** /** /** /**
55 // ** /** ** ******** /** /**
56 // // /******/ //////// // //
58 // FOSA(Frescor Operating System Adaptation layer)
59 //================================================
62 #ifndef FOSA_APP_DEF_SCHED_H_
63 #define FOSA_APP_DEF_SCHED_H_
66 * @defgroup appdefsched Application Defined Scheduling
69 * This module defines the function and types for an abstraction of
70 * the Application Defined Scheduling.
77 /********************************
78 * Application-defined scheduling
79 ********************************/
82 * We make the following ASSUMPTIONS:
84 * - The ADS always executes in the user memory space, so we don't
85 * need to manage the memory space translation.
87 * - Only one application scheduler exists, so we don't need an
92 * fosa_ads_scheduler_create()
94 * Create the application defined scheduler
96 * The application defined scheduler is created with the primitive
97 * operations specified in the object pointed to by scheduler_ops.
99 * The clock used to read the time immediately before the invocation
100 * of each primitive operation, to be reported to the scheduler via
101 * the current_time parameter of each primitive operation is the
102 * FOSA_CLOCK_REALTIME clock.
104 * The scheduler_data_size parameter is used to request that a memory
105 * area of this size must be created and reserved for the scheduler to
106 * store its state. A pointer to this area is passed to the scheduler
107 * operations in the sched_data parameter.
109 * Parameter init_arg points to an area that contains configuration
110 * information for the scheduler. The function creates a memory area
111 * of init_arg_size bytes and copies into it the area pointed by
112 * arg. A pointer to this new created area will be passed to the
113 * primitive operation init() in its arg parameter.
115 * Returns 0 if successful; otherwise it returns an error code:
116 * EINVAL: The value of scheduler_ops was invalid
117 * EAGAIN: The system lacks enough resources to create the scheduler
119 * Alternatively, in case of error the implementation is allowed to
120 * notify it to the system console and then terminate the FRSH
121 * implementation and dependant applications
123 int fosa_ads_scheduler_create
124 (const fosa_ads_scheduler_ops_t * scheduler_ops,
125 size_t scheduler_data_size,
127 size_t init_args_size);
130 * fosa_thread_attr_set_appscheduled()
132 * Set the appscheduled attribute of a thread attributes object
134 * This function is used to set the appscheduled attribute in the
135 * object pointed to by attr. This attribute controls the kind of
136 * scheduling used for threads created with it. If true, the thread is
137 * scheduled by the application scheduler. If not, it is scheduled by
138 * the system under a fixed priority scheduler
140 * Returns 0 if successful; otherwise it returns an error code:
141 * EINVAL: The value of attr is invalid
143 * Alternatively, in case of error the implementation is allowed to
144 * notify it to the system console and then terminate the FRSH
145 * implementation and dependant applications
147 int fosa_thread_attr_set_appscheduled
148 (frsh_thread_attr_t *attr,
152 * fosa_thread_attr_get_appscheduled()
154 * Get the appscheduled attribute of a thread attributes object
156 * This function is used to get the appscheduled attribute in the
157 * object pointed to by attr. This attribute controls the kind of
158 * scheduling used for threads created with it. If true, the thread is
159 * scheduled by the application scheduler. If not, it is scheduled by
160 * the system under a fixed priority scheduler.
162 * Returns 0 if successful; otherwise it returns an error code:
163 * EINVAL: The value of attr is invalid
165 * Alternatively, in case of error the implementation is allowed to
166 * notify it to the system console and then terminate the FRSH
167 * implementation and dependant applications
169 int fosa_thread_attr_get_appscheduled
170 (const frsh_thread_attr_t *attr,
174 * fosa_thread_attr_set_appsched_params()
176 * Set the appsched_param attribute of a thread attributes object
178 * This function is used to set the appsched_param attribute in the
179 * object pointed to by attr. For those threads with appscheduled set
180 * to true, this attribute represents the application-specific
181 * scheduling parameters. If successful, the function shall set the
182 * size of the appsched_param attribute to the value specified by
183 * paramsize, and shall copy the scheduling parameters occupying
184 * paramsize bytes and pointed to by param into that attribute
186 * Returns 0 if successful; otherwise it returns an error code:
187 * EINVAL: The value of attr is invalid, or paramsize is less than
188 * zero or larger than FOSA_ADS_SCHEDPARAM_MAX
190 * Alternatively, in case of error the implementation is allowed to
191 * notify it to the system console and then terminate the FRSH
192 * implementation and dependant applications
194 //int fosa_thread_attr_set_appsched_params
195 // (frsh_thread_attr_t *attr,
196 // const void *param,
197 // size_t paramsize);
198 inline int fosa_thread_attr_set_appsched_params (frsh_thread_attr_t *attr,
201 pthread_attr_setappschedparam(attr, param, paramsize);
204 * fosa_thread_attr_get_appsched_params()
206 * Get the appsched_param attribute of a thread attributes object
208 * This function is used to get the appsched_param attribute from the
209 * object pointed to by attr. For those threads with appscheduled set
210 * to true, this attribute represents the application-specific
211 * scheduling parameters. If successful, the function shall set the
212 * value pointed to by paramsize to the size of the appsched_param
213 * attribute, and shall copy the scheduling parameters occupying
214 * paramsize bytes into the variable pointed to by param. This
215 * variable should be capable of storing a number of bytes equal to
218 * Returns 0 if successful; otherwise it returns an error code:
219 * EINVAL: The value of attr is invalid
221 * Alternatively, in case of error the implementation is allowed to
222 * notify it to the system console and then terminate the FRSH
223 * implementation and dependant applications
225 int fosa_thread_attr_get_appsched_params
226 (const frsh_thread_attr_t *attr,
231 * fosa_ads_set_appscheduled()
233 * Dynamically set the appscheduled attribute of a thread
235 * This function is used to dynamically set the appscheduled attribute
236 * of the thread identified by thread. This attribute controls the
237 * kind of scheduling used for threads created with it. If true, the
238 * thread is scheduled by the application scheduler. If not, it is
239 * scheduled by the system under a fixed priority scheduler.
241 * Returns 0 if successful; otherwise it returns an error code:
242 * EINVAL: The value of thread is invalid
244 * EREJECT: the attachment of the thread to the frsh schehduler
245 * was rejected by the frsh scheduler possibly because of
246 * incorrect attributes, or because the requested minimum
247 * capacity cannot be guaranteed
249 * Alternatively, in case of error the implementation is allowed to
250 * notify it to the system console and then terminate the FRSH
251 * implementation and dependant applications
253 int fosa_ads_set_appscheduled
254 (frsh_thread_id_t thread,
258 * fosa_ads_getappscheduled()
260 * Dynamically get the appscheduled attribute of a thread
262 * This function is used to dynamically get the appscheduled attribute
263 * of the thread identified by thread. This attribute controls the
264 * kind of scheduling used for threads created with it. If true, the
265 * thread is scheduled by the application scheduler. If not, it is
266 * scheduled by the system under a fixed priority scheduler
268 * Returns 0 if successful; otherwise it returns an error code:
269 * EINVAL: The value of thread is invalid
271 * Alternatively, in case of error the implementation is allowed to
272 * notify it to the system console and then terminate the FRSH
273 * implementation and dependant applications
275 int fosa_ads_get_appscheduled
276 (frsh_thread_id_t thread,
281 * fosa_ads_setappschedparam()
283 * Dynamically set the appsched_param attribute of a thread
285 * This function is used to dynamically set the appsched_param
286 * attribute of the thread identified by thread. For those threads
287 * with appscheduled set to true, this attribute represents the
288 * application-specific scheduling parameters. If successful, the
289 * function shall set the size of the appsched_param attribute to the
290 * value specified by paramsize, and shall copy the scheduling
291 * parameters occupying paramsize bytes and pointed to by param into
294 * Returns 0 if successful; otherwise it returns an error code:
295 * EINVAL: The value of thread is invalid, or paramsize is less than
296 * zero or larger than FOSA_ADS_SCHEDPARAM_MAX
298 * Alternatively, in case of error the implementation is allowed to
299 * notify it to the system console and then terminate the FRSH
300 * implementation and dependant applications
302 //int fosa_ads_set_appschedparam
303 // (frsh_thread_id_t thread,
304 // const void *param,
305 // size_t paramsize);
306 inline int fosa_ads_set_appschedparam (frsh_thread_id_t thread,
309 pthread_setappschedparam(thread, param, paramsize);
313 * fosa_ads_get_appsched_params()
315 * Dynamically get the appsched_param attribute of a thread
317 * This function is used to dynamically get the appsched_param
318 * attribute of the thread identified by thread. For those threads
319 * with appscheduled set to true, this attribute represents the
320 * application-specific scheduling parameters. If successful, the
321 * function shall set the variable pointed to by paramsize to the size
322 * of the appsched_param attribute, and shall copy the scheduling
323 * parameters occupying paramsize bytes into the variable pointed to
324 * by param. This variable should be capable of storing a number of
325 * bytes equal to paramsize.
327 * Returns 0 if successful; otherwise it returns an error code:
328 * EINVAL: The value of thread is invalid, or paramsize is less than
329 * zero or larger than FOSA_ADS_SCHEDPARAM_MAX
331 * Alternatively, in case of error the implementation is allowed to
332 * notify it to the system console and then terminate the FRSH
333 * implementation and dependant applications.
335 //int fosa_ads_get_appsched_params
336 // (frsh_thread_id_t thread,
338 // size_t *paramsize);
339 inline int fosa_ads_get_appsched_params (frsh_thread_id_t thread,
342 pthread_getappschedparam(thread, param, paramsize);
345 /*********************************
348 * A scheduling actions object is used to specify a series of actions
349 * to be performed by the system at the end of a scheduler primitive
350 * operation. The order of the actions added to the object shall be
353 *********************************/
356 * fosa_adsactions_add_reject()
358 * Add a reject-thread action
360 * This function adds a thread-reject action to the object referenced
361 * by sched_actions, that will serve to notify that the thread
362 * identified by thread has not been accepted by the scheduler to be
363 * scheduled by it, possibly because the thread contained invalid
364 * application scheduling attributes, or because there are not enough
365 * resources for the new thread. At the end of the new_thread()
366 * scheduler primitive operation, the parent of the rejected thread
367 * waiting on a fosa_thread_create() or the rejected thread itself
368 * waiting on a fosa_ads_set_appscheduled() function shall complete the
369 * function with an error code of EREJECT. If no reject-thread action
370 * is added during the new_thread() scheduler primitive operation, the
371 * thread is accepted to be scheduled by the scheduler and the
372 * associated fosa_thread_create() or the fosa_ads_set_appscheduled()
373 * function shall be completed without error. For the function to
374 * succeed, it has to be called from the new_thread() primitive
375 * operation and for the thread that is requesting attachment to the
378 * Returns 0 if successful; otherwise it returns an error code:
379 * ENOMEM: There is insufficient memory to add this action
380 * EPOLICY: The thread specified by thread is not the one requesting
381 * attachment to the scheduler, or the function is not being
382 * called from the new_thread primitive operation
383 * EINVAL: The value specified by sched_actions is invalid
385 * Alternatively, in case of error the implementation is allowed to
386 * notify it to the system console and then terminate the FRSH
387 * implementation and dependant applications
389 // int fosa_adsactions_add_reject(
390 // fosa_ads_actions_t *sched_actions,
391 // frsh_thread_id_t thread);
392 inline int fosa_adsactions_add_reject(fosa_ads_actions_t *sched_actions,
393 frsh_thread_id_t thread){
394 posix_appsched_actions_addreject(sched_actions, thread);
397 * fosa_adsactions_add_activate()
399 * Add a thread-activate action
401 * This function adds a thread-activate action to the object
402 * referenced by sched_actions. In case the thread had been previously
403 * suspended via posix_appsched_actions_addsuspend(), it will be
404 * activated at the end of the primitive operation.
406 * In those implementations that do not support urgency scheduling,
407 * the urgencu value is ignored. These implementations cannot support
408 * the frsh hierarchical scheduling module.
410 * In those implementations supporting urgency-scheduling, the action
411 * will cause the change of the urgency of the thread to the value
412 * specified in the urgency argument. Besides, if the thread was
413 * already active at the time the thread-activate action is executed,
414 * the change or urgency will imply a reordering of the thread in its
415 * priority queue, so that for threads of the same priority, those
416 * with more urgency will be scheduled before those of less urgency.
418 * Returns 0 if successful; otherwise it returns an error code:
419 * ENOMEM: There is insufficient memory to add this action
420 * EPOLICY: The thread specified by thread has its appscheduled
421 * attribute set to false,
422 * EINVAL: The value specified by sched_actions is invalid
424 * Alternatively, in case of error the implementation is allowed to
425 * notify it to the system console and then terminate the FRSH
426 * implementation and dependant applications
428 // int fosa_adsactions_add_activate(
429 // fosa_ads_actions_t *sched_actions,
430 // frsh_thread_id_t thread,
431 // fosa_ads_urgency_t urgency);
432 inline int fosa_adsactions_add_activate(
433 fosa_ads_actions_t *sched_actions,
434 frsh_thread_id_t thread/*,
435 fosa_ads_urgency_t urgency*/){
436 posix_appsched_actions_addactivate(sched_actions, thread);
439 * fosa_adsactions_add_suspend()
441 * Add a thread-suspend action
443 * This function adds a thread-suspend action to the object referenced
444 * by sched_actions, that will cause the thread identified by thread
445 * to be suspended waiting for a thread-activate action at the end of
446 * the scheduler operation. If the thread was already waiting for a
447 * thread-activate action the thread-suspend action has no effect. It
448 * is an error trying to suspend a thread that is blocked by the
451 * Returns 0 if successful; otherwise it returns an error code:
452 * ENOMEM: There is insufficient memory to add this action
453 * EPOLICY: The thread specified by thread has its appscheduled
454 * attribute set to false,
455 * EINVAL: The value specified by sched_actions is invalid
457 * Alternatively, in case of error the implementation is allowed to
458 * notify it to the system console and then terminate the FRSH
459 * implementation and dependant applications
461 // int fosa_adsactions_add_suspend(
462 // fosa_ads_actions_t *sched_actions,
463 // frsh_thread_id_t thread);
464 inline int fosa_adsactions_add_suspend(fosa_ads_actions_t *sched_actions,
465 frsh_thread_id_t thread){
466 posix_appsched_actions_addsuspend (sched_actions, thread);
469 * fosa_adsactions_add_timeout()
471 * Add a timeout action
473 * This function adds a timeout action to the object referenced by
474 * sched_actions, that will cause the timeout() scheduler operation to
475 * be invoked if no other scheduler operation is invoked before
476 * timeout expires. The timeout shall expire when the clock specified by
477 * clock_id reaches the absolute time specified by the at_time
480 * Returns 0 if successful; otherwise it returns an error code:
481 * ENOMEM: There is insufficient memory to add this action
482 * EPOLICY: The thread specified by thread has its appscheduled
483 * attribute set to false,
484 * EINVAL: The value specified by sched_actions is invalid
486 * Alternatively, in case of error the implementation is allowed to
487 * notify it to the system console and then terminate the FRSH
488 * implementation and dependant applications
490 int fosa_adsactions_add_timeout(
491 fosa_ads_actions_t *sched_actions,
492 fosa_clock_id_t clock_id,
493 const struct timespec *at_time);
496 * fosa_adsactions_add_thread_notification()
498 * Add a timed-thread-notification action
500 * This function adds a thread-notification action associated with the
501 * thread specified in the thread argument that will cause the
502 * notification_for_thread() scheduler operation to be invoked at the
503 * time specified by at_time. This operation shall be invoked when the
504 * clock specified by clock_id reaches the absolute time specified by
505 * the at_time argument. In particular, a cpu-time clock may be used
506 * for parameter clock_id.Only one thread-notification can be active
507 * for each thread and clock. Calling the function shall remove the
508 * former thread-notification, if any, that had been programmed for
509 * the same thread and clock. A value of NULL for parameter at_time is
510 * used to cancel a previous thread-notification, if any, for the
511 * thread specified by thread and the clock specified by clock_id.
513 * Returns 0 if successful; otherwise it returns an error code:
514 * ENOMEM: There is insufficient memory to add this action
515 * EPOLICY: The thread specified by thread has its appscheduled
516 * attribute set to false,
517 * EINVAL: The value specified by sched_actions is invalid
519 * Alternatively, in case of error the implementation is allowed to
520 * notify it to the system console and then terminate the FRSH
521 * implementation and dependant applications
523 int fosa_adsactions_add_thread_notification(
524 fosa_ads_actions_t *sched_actions,
525 frsh_thread_id_t thread,
526 fosa_clock_id_t clock_id,
527 const struct timespec *at_time);
531 * fosa_ads_set_handled_signal_set()
533 * Specifiy the set of signals that will be handled by the application
536 * This function is used to dynamically set the set of signals that
537 * are handled by the application scheduler. When a signal included
538 * in this set is generated, the signal() primitive operation of the
539 * application scheduler shall be executed. When a signal in tis set
540 * is generated, it shall always imply the execution of the signal()
541 * primitive operation, regardless of whether that signal could be
542 * accepted by some other thread. Once the signal() primitive
543 * operation is executed the signal is consumed, so no signal handlers
544 * shall be executed and no threads using a sigwait operation shall
545 * return for that particular signal instance. For this function to
546 * succeed, it has to be called from a primitive operation of a
549 * Returns 0 if successful; otherwise it returns an error code:
550 * EPOLICY: The function has not been called from a scheduler
551 * primitive operation
552 * EINVAL: The value specified by set is invalid
554 * Alternatively, in case of error the implementation is allowed to
555 * notify it to the system console and then terminate the FRSH
556 * implementation and dependant applications
558 int fosa_ads_set_handled_signal_set(frsh_signal_t set[]);
562 * fosa_ads_invoke_withdata()
564 * Explicitly invoke the scheduler, with data
566 * This function can be used by any thread in the process to invoke
567 * the ads scheduler or to share data with it.
569 * If successful, the function shall cause the execution of the
570 * primitive operation explicit_call_with_data() of the ads scheduler
571 * with its thread parameter equal to the thread ID of the calling
572 * thread, and its msg_size parameter equal to msg_size. In addition,
573 * if msg_size is larger than zero, the function shall make available
574 * to the scheduler a memory area whose contents are identical to the
575 * memory area pointed to by msg in the msg parameter of the
576 * explicit_call_with_data() primitive operation (note that copying
577 * the information is not needed).
579 * The function shall not return until the system has finished
580 * execution of the explicit_call_with_data() primitive operation. If
581 * the reply argument is non NULL, the memory area pointed to by the
582 * reply parameter of explicit_call_with_data() primitive operation is
583 * copied into the memory area pointed to by reply, and its size is
584 * copied into the variable pointed to by reply_size. The size of the
585 * reply information is limited to the value FOSA_ADS_SCHEDINFO_MAX.
587 * The function shall fail if the size specified by msg_size is larger
588 * than FOSA_ADS_SCHEDINFO_MAX. The function shall fail if primitive
589 * operation explicit_call_with_data() is set to NULL for the ads
592 * Returns 0 if successful; otherwise it returns an error code:
593 * EPOLICY: The function been called from inside a scheduler
594 * primitive operation
595 * EINVAL: The value of msg_size is less than zero or larger than
596 * FOSA_ADS_SCHEDINFO_MAX
597 * EMASKED: The operation cannot be executed because the primitive
598 * operation explicit_call_with_data() is set to NULL
600 * Alternatively, in case of error the implementation is allowed to
601 * notify it to the system console and then terminate the FRSH
602 * implementation and dependant applications
604 int fosa_ads_invoke_withdata
605 (const void *msg, size_t msg_size, void *reply, size_t *reply_size);
610 #endif /* !FOSA_APP_DEF_SCHED_H_ */