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_
65 #include "fosa_types.h"
68 * @defgroup appdefsched Application Defined Scheduling
71 * This module defines the function and types for an abstraction of
72 * the Application Defined Scheduling.
79 /********************************
80 * Application-defined scheduling
81 ********************************/
84 * We make the following ASSUMPTIONS:
86 * - The ADS always executes in the user memory space, so we don't
87 * need to manage the memory space translation.
89 * - Only one application scheduler exists, so we don't need an
94 * fosa_ads_scheduler_create()
96 * Create the application defined scheduler
98 * The application defined scheduler is created with the primitive
99 * operations specified in the object pointed to by scheduler_ops.
101 * The clock used to read the time immediately before the invocation
102 * of each primitive operation, to be reported to the scheduler via
103 * the current_time parameter of each primitive operation is the
104 * FOSA_CLOCK_REALTIME clock.
106 * The scheduler_data_size parameter is used to request that a memory
107 * area of this size must be created and reserved for the scheduler to
108 * store its state. A pointer to this area is passed to the scheduler
109 * operations in the sched_data parameter.
111 * Parameter init_arg points to an area that contains configuration
112 * information for the scheduler. The function creates a memory area
113 * of init_arg_size bytes and copies into it the area pointed by
114 * arg. A pointer to this new created area will be passed to the
115 * primitive operation init() in its arg parameter.
117 * This function must be called before any other function in this
120 * In addition it must be called at a priority level no greater than
121 * the priority at which the scheduler operations execute. This
122 * priority is defined as the maximum SCHED_FIFO priority in the
123 * system minus the configuration parameter FOSA_ADS_SCHEDULER_PRIO_DIFF.
125 * Returns 0 if successful; otherwise it returns an error code:
127 * FOSA_EINVAL: The value of scheduler_ops was invalid \n
128 * FOSA_EAGAIN: The system lacks enough resources to create the
131 * Alternatively, in case of error the implementation is allowed to
132 * notify it to the system console and then terminate the FRSH
133 * implementation and dependant applications
135 int fosa_ads_scheduler_create
136 (const fosa_ads_scheduler_ops_t * scheduler_ops,
137 size_t scheduler_data_size,
139 size_t init_args_size);
142 * fosa_thread_attr_set_appscheduled()
144 * Set the appscheduled attribute of a thread attributes object
146 * This function is used to set the appscheduled attribute in the
147 * object pointed to by attr. This attribute controls the kind of
148 * scheduling used for threads created with it. If true, the thread is
149 * scheduled by the application scheduler. If not, it is scheduled by
150 * the system under a fixed priority scheduler
152 * Returns 0 if successful; otherwise it returns an error code:
154 * FOSA_EINVAL: The value of attr is invalid
156 * Alternatively, in case of error the implementation is allowed to
157 * notify it to the system console and then terminate the FRSH
158 * implementation and dependant applications
160 int fosa_thread_attr_set_appscheduled
161 (frsh_thread_attr_t *attr,
165 * fosa_thread_attr_get_appscheduled()
167 * Get the appscheduled attribute of a thread attributes object
169 * This function is used to get the appscheduled attribute in the
170 * object pointed to by attr. This attribute controls the kind of
171 * scheduling used for threads created with it. If true, the thread is
172 * scheduled by the application scheduler. If not, it is scheduled by
173 * the system under a fixed priority scheduler.
175 * Returns 0 if successful; otherwise it returns an error code:
177 * FOSA_EINVAL: The value of attr is invalid
179 * Alternatively, in case of error the implementation is allowed to
180 * notify it to the system console and then terminate the FRSH
181 * implementation and dependant applications
183 int fosa_thread_attr_get_appscheduled
184 (const frsh_thread_attr_t *attr,
188 * fosa_thread_attr_set_appsched_params()
190 * Set the appsched_param attribute of a thread attributes object
192 * This function is used to set the appsched_param attribute in the
193 * object pointed to by attr. For those threads with appscheduled set
194 * to true, this attribute represents the application-specific
195 * scheduling parameters. If successful, the function shall set the
196 * size of the appsched_param attribute to the value specified by
197 * paramsize, and shall copy the scheduling parameters occupying
198 * paramsize bytes and pointed to by param into that attribute
200 * Returns 0 if successful; otherwise it returns an error code:
202 * FOSA_EINVAL: The value of attr is invalid, or paramsize is less than
203 * zero or larger than FOSA_ADS_SCHEDPARAM_MAX
205 * Alternatively, in case of error the implementation is allowed to
206 * notify it to the system console and then terminate the FRSH
207 * implementation and dependant applications
209 int fosa_thread_attr_set_appsched_params
210 (frsh_thread_attr_t *attr,
215 * fosa_thread_attr_get_appsched_params()
217 * Get the appsched_param attribute of a thread attributes object
219 * This function is used to get the appsched_param attribute from the
220 * object pointed to by attr. For those threads with appscheduled set
221 * to true, this attribute represents the application-specific
222 * scheduling parameters. If successful, the function shall set the
223 * value pointed to by paramsize to the size of the appsched_param
224 * attribute, and shall copy the scheduling parameters occupying
225 * paramsize bytes into the variable pointed to by param. This
226 * variable should be capable of storing a number of bytes equal to
229 * Returns 0 if successful; otherwise it returns an error code:
231 * FOSA_EINVAL: The value of attr is invalid
233 * Alternatively, in case of error the implementation is allowed to
234 * notify it to the system console and then terminate the FRSH
235 * implementation and dependant applications
237 int fosa_thread_attr_get_appsched_params
238 (const frsh_thread_attr_t *attr,
243 * fosa_ads_set_appscheduled()
245 * Dynamically set the appscheduled attribute of a thread
247 * This function is used to dynamically set the appscheduled attribute
248 * of the thread identified by thread. This attribute controls the
249 * kind of scheduling used for threads created with it. If true, the
250 * thread is scheduled by the application scheduler. If not, it is
251 * scheduled by the system under a fixed priority scheduler.
253 * Returns 0 if successful; otherwise it returns an error code:
255 * FOSA_EINVAL: The value of thread is invalid
257 * FOSA_EREJECT: the attachment of the thread to the frsh schehduler
258 * was rejected by the frsh scheduler possibly because of
259 * incorrect attributes, or because the requested minimum
260 * capacity cannot be guaranteed
262 * Alternatively, in case of error the implementation is allowed to
263 * notify it to the system console and then terminate the FRSH
264 * implementation and dependant applications
266 int fosa_ads_set_appscheduled
267 (frsh_thread_id_t thread,
271 * fosa_ads_getappscheduled()
273 * Dynamically get the appscheduled attribute of a thread
275 * This function is used to dynamically get the appscheduled attribute
276 * of the thread identified by thread. This attribute controls the
277 * kind of scheduling used for threads created with it. If true, the
278 * thread is scheduled by the application scheduler. If not, it is
279 * scheduled by the system under a fixed priority scheduler
281 * Returns 0 if successful; otherwise it returns an error code:
283 * FOSA_EINVAL: The value of thread is invalid
285 * Alternatively, in case of error the implementation is allowed to
286 * notify it to the system console and then terminate the FRSH
287 * implementation and dependant applications
289 int fosa_ads_get_appscheduled
290 (frsh_thread_id_t thread,
295 * fosa_ads_setappschedparam()
297 * Dynamically set the appsched_param attribute of a thread
299 * This function is used to dynamically set the appsched_param
300 * attribute of the thread identified by thread. For those threads
301 * with appscheduled set to true, this attribute represents the
302 * application-specific scheduling parameters. If successful, the
303 * function shall set the size of the appsched_param attribute to the
304 * value specified by paramsize, and shall copy the scheduling
305 * parameters occupying paramsize bytes and pointed to by param into
308 * Returns 0 if successful; otherwise it returns an error code:
310 * FOSA_EINVAL: The value of thread is invalid, or paramsize is less than
311 * zero or larger than FOSA_ADS_SCHEDPARAM_MAX
313 * Alternatively, in case of error the implementation is allowed to
314 * notify it to the system console and then terminate the FRSH
315 * implementation and dependant applications
317 int fosa_ads_set_appsched_params
318 (frsh_thread_id_t thread,
323 * fosa_ads_get_appsched_params()
325 * Dynamically get the appsched_param attribute of a thread
327 * This function is used to dynamically get the appsched_param
328 * attribute of the thread identified by thread. For those threads
329 * with appscheduled set to true, this attribute represents the
330 * application-specific scheduling parameters. If successful, the
331 * function shall set the variable pointed to by paramsize to the size
332 * of the appsched_param attribute, and shall copy the scheduling
333 * parameters occupying paramsize bytes into the variable pointed to
334 * by param. This variable should be capable of storing a number of
335 * bytes equal to paramsize.
337 * Returns 0 if successful; otherwise it returns an error code:
339 * FOSA_EINVAL: The value of thread is invalid, or paramsize is less than
340 * zero or larger than FOSA_ADS_SCHEDPARAM_MAX
342 * Alternatively, in case of error the implementation is allowed to
343 * notify it to the system console and then terminate the FRSH
344 * implementation and dependant applications.
346 int fosa_ads_get_appsched_params
347 (frsh_thread_id_t thread,
352 /*********************************
355 * A scheduling actions object is used to specify a series of actions
356 * to be performed by the system at the end of a scheduler primitive
357 * operation. The order of the actions added to the object shall be
360 *********************************/
363 * fosa_adsactions_add_reject()
365 * Add a reject-thread action
367 * This function adds a thread-reject action to the object referenced
368 * by sched_actions, that will serve to notify that the thread
369 * identified by thread has not been accepted by the scheduler to be
370 * scheduled by it, possibly because the thread contained invalid
371 * application scheduling attributes, or because there are not enough
372 * resources for the new thread. At the end of the new_thread()
373 * scheduler primitive operation, the parent of the rejected thread
374 * waiting on a fosa_thread_create() or the rejected thread itself
375 * waiting on a fosa_ads_set_appscheduled() function shall complete the
376 * function with an error code of FOSA_EREJECT. If no reject-thread action
377 * is added during the new_thread() scheduler primitive operation, the
378 * thread is accepted to be scheduled by the scheduler and the
379 * associated fosa_thread_create() or the fosa_ads_set_appscheduled()
380 * function shall be completed without error. For the function to
381 * succeed, it has to be called from the new_thread() primitive
382 * operation and for the thread that is requesting attachment to the
385 * Returns 0 if successful; otherwise it returns an error code:
387 * FOSA_ENOMEM: There is insufficient memory to add this action \n
388 * FOSA_EPOLICY: The thread specified by thread is not the one requesting
389 * attachment to the scheduler, or the function is not being
390 * called from the new_thread primitive operation \n
391 * FOSA_EINVAL: The value specified by sched_actions is invalid \n
393 * Alternatively, in case of error the implementation is allowed to
394 * notify it to the system console and then terminate the FRSH
395 * implementation and dependant applications
397 int fosa_adsactions_add_reject(
398 fosa_ads_actions_t *sched_actions,
399 frsh_thread_id_t thread);
402 * fosa_adsactions_add_activate()
404 * Add a thread-activate action
406 * This function adds a thread-activate action to the object
407 * referenced by sched_actions. In case the thread had been previously
408 * suspended via posix_appsched_actions_addsuspend(), it will be
409 * activated at the end of the primitive operation.
411 * In those implementations that do not support urgency scheduling,
412 * the urgencu value is ignored. These implementations cannot support
413 * the frsh hierarchical scheduling module.
415 * In those implementations supporting urgency-scheduling, the action
416 * will cause the change of the urgency of the thread to the value
417 * specified in the urgency argument. Besides, if the thread was
418 * already active at the time the thread-activate action is executed,
419 * the change or urgency will imply a reordering of the thread in its
420 * priority queue, so that for threads of the same priority, those
421 * with more urgency will be scheduled before those of less urgency.
423 * Returns 0 if successful; otherwise it returns an error code:
425 * FOSA_ENOMEM: There is insufficient memory to add this action \n
426 * FOSA_EPOLICY: The thread specified by thread has its appscheduled
427 * attribute set to false \n
428 * FOSA_EINVAL: The value specified by sched_actions is invalid \n
430 * Alternatively, in case of error the implementation is allowed to
431 * notify it to the system console and then terminate the FRSH
432 * implementation and dependant applications
434 int fosa_adsactions_add_activate(
435 fosa_ads_actions_t *sched_actions,
436 frsh_thread_id_t thread,
437 fosa_ads_urgency_t urgency);
440 * fosa_adsactions_add_suspend()
442 * Add a thread-suspend action
444 * This function adds a thread-suspend action to the object referenced
445 * by sched_actions, that will cause the thread identified by thread
446 * to be suspended waiting for a thread-activate action at the end of
447 * the scheduler operation. If the thread was already waiting for a
448 * thread-activate action the thread-suspend action has no effect. It
449 * is an error trying to suspend a thread that is blocked by the
452 * Returns 0 if successful; otherwise it returns an error code:
454 * FOSA_ENOMEM: There is insufficient memory to add this action \n
455 * FOSA_EPOLICY: The thread specified by thread has its appscheduled
456 * attribute set to false \n
457 * FOSA_EINVAL: The value specified by sched_actions is invalid \n
459 * Alternatively, in case of error the implementation is allowed to
460 * notify it to the system console and then terminate the FRSH
461 * implementation and dependant applications
463 int fosa_adsactions_add_suspend(
464 fosa_ads_actions_t *sched_actions,
465 frsh_thread_id_t thread);
468 * fosa_adsactions_add_timeout()
470 * Add a timeout action
472 * This function adds a timeout action to the object referenced by
473 * sched_actions, that will cause the timeout() scheduler operation to
474 * be invoked if no other scheduler operation is invoked before
475 * timeout expires. The timeout shall expire when the clock specified by
476 * clock_id reaches the absolute time specified by the at_time
479 * Returns 0 if successful; otherwise it returns an error code:
481 * FOSA_ENOMEM: There is insufficient memory to add this action \n
482 * FOSA_EINVAL: The value specified by sched_actions is invalid \n
484 * Alternatively, in case of error the implementation is allowed to
485 * notify it to the system console and then terminate the FRSH
486 * implementation and dependant applications
488 int fosa_adsactions_add_timeout(
489 fosa_ads_actions_t *sched_actions,
490 fosa_clock_id_t clock_id,
491 const struct timespec *at_time);
494 * fosa_adsactions_add_thread_notification()
496 * Add a timed-thread-notification action
498 * This function adds a thread-notification action associated with the
499 * thread specified in the thread argument that will cause the
500 * notification_for_thread() scheduler operation to be invoked at the
501 * time specified by at_time. This operation shall be invoked when the
502 * clock specified by clock_id reaches the absolute time specified by
503 * the at_time argument. In particular, a cpu-time clock may be used
504 * for parameter clock_id.Only one thread-notification can be active
505 * for each thread and clock. Calling the function shall remove the
506 * former thread-notification, if any, that had been programmed for
507 * the same thread and clock. A value of NULL for parameter at_time is
508 * used to cancel a previous thread-notification, if any, for the
509 * thread specified by thread and the clock specified by clock_id.
511 * Returns 0 if successful; otherwise it returns an error code:
513 * FOSA_ENOMEM: There is insufficient memory to add this action \n
514 * FOSA_EPOLICY: The thread specified by thread has its appscheduled
515 * attribute set to false \n
516 * FOSA_EINVAL: The value specified by sched_actions is invalid \n
518 * Alternatively, in case of error the implementation is allowed to
519 * notify it to the system console and then terminate the FRSH
520 * implementation and dependant applications
522 int fosa_adsactions_add_thread_notification(
523 fosa_ads_actions_t *sched_actions,
524 frsh_thread_id_t thread,
525 fosa_clock_id_t clock_id,
526 const struct timespec *at_time);
530 * fosa_ads_set_handled_signal_set()
532 * Specifiy the set of signals that will be handled by the application
535 * This function is used to dynamically set the set of signals that
536 * are handled by the application scheduler. When a signal included
537 * in this set is generated, the signal() primitive operation of the
538 * application scheduler shall be executed. When a signal in tis set
539 * is generated, it shall always imply the execution of the signal()
540 * primitive operation, regardless of whether that signal could be
541 * accepted by some other thread. Once the signal() primitive
542 * operation is executed the signal is consumed, so no signal handlers
543 * shall be executed and no threads using a sigwait operation shall
544 * return for that particular signal instance. For this function to
545 * succeed, it has to be called from a primitive operation of a
548 * The size of the array is specified by argument size.
550 * Returns 0 if successful; otherwise it returns an error code:
552 * FOSA_EPOLICY: The function has not been called from a scheduler
553 * primitive operation \n
554 * FOSA_EINVAL: The value specified by set is invalid \n
556 * Alternatively, in case of error the implementation is allowed to
557 * notify it to the system console and then terminate the FRSH
558 * implementation and dependant applications
560 int fosa_ads_set_handled_signal_set(frsh_signal_t set[], int size);
564 * fosa_signal_queue_scheduler()
566 * Queue a signal destinated to the scheduler
568 * This is a special case of fosa_signal_queue() in which the
569 * destinator is the scheduler itself. It is needed by the service
570 * thread to notify the results to the scheduler.
572 * The problem with this case is that, depending on the implementation,
573 * this call would be translated to a true signal or to a scheduler
574 * notification message.
576 * Besides for the scheduler we don't have always a destinator
577 * thread_id needed in frsh_signal_queue for OSE.
579 * So the fosa implementation will solve this issue internally.
581 * Returns 0 if successful; otherwise it returns an error code:
582 * FOSA_EINVAL: the signal specified by signal is not
583 * between FOSA_SIGNAL_MIN and FOSA_SIGNAL_MAX
585 * FOSA_EAGAIN: no resources are available to queue the signal; the
586 * maximum number of queued signals has been reached, or a
587 * systemwide resource limit has been exceeded
589 * Alternatively, in case of error the implementation is allowed to
590 * notify it to the system console and then terminate the FRSH
591 * implementation and dependant applications
593 int fosa_signal_queue_scheduler(frsh_signal_t signal, frsh_signal_info_t info);
597 * fosa_ads_invoke_withdata()
599 * Explicitly invoke the scheduler, with data
601 * This function can be used by any thread in the process to invoke
602 * the ads scheduler or to share data with it.
604 * If successful, the function shall cause the execution of the
605 * primitive operation explicit_call_with_data() of the ads scheduler
606 * with its thread parameter equal to the thread ID of the calling
607 * thread, and its msg_size parameter equal to msg_size. In addition,
608 * if msg_size is larger than zero, the function shall make available
609 * to the scheduler a memory area whose contents are identical to the
610 * memory area pointed to by msg in the msg parameter of the
611 * explicit_call_with_data() primitive operation (note that copying
612 * the information is not needed).
614 * The function shall not return until the system has finished
615 * execution of the explicit_call_with_data() primitive operation. If
616 * the reply argument is non NULL, the memory area pointed to by the
617 * reply parameter of explicit_call_with_data() primitive operation is
618 * copied into the memory area pointed to by reply, and its size is
619 * copied into the variable pointed to by reply_size. The size of the
620 * reply information is limited to the value FOSA_ADS_SCHEDINFO_MAX.
622 * The function shall fail if the size specified by msg_size is larger
623 * than FOSA_ADS_SCHEDINFO_MAX. The function shall fail if primitive
624 * operation explicit_call_with_data() is set to NULL for the ads
627 * Returns 0 if successful; otherwise it returns an error code:
629 * FOSA_EPOLICY: The function been called from inside a scheduler
630 * primitive operation \n
631 * FOSA_EINVAL: The value of msg_size is less than zero or larger than
632 * FOSA_ADS_SCHEDINFO_MAX \n
633 * FOSA_EMASKED: The operation cannot be executed because the primitive
634 * operation explicit_call_with_data() is set to NULL \n
636 * Alternatively, in case of error the implementation is allowed to
637 * notify it to the system console and then terminate the FRSH
638 * implementation and dependant applications
640 int fosa_ads_invoke_withdata
641 (const void *msg, size_t msg_size, void *reply, size_t *reply_size);
646 #endif /* !FOSA_APP_DEF_SCHED_H_ */