]> rtime.felk.cvut.cz Git - frescor/fosa.git/blob - src_rtlinux/fosa_app_def_sched.h
'fosa_app_def_sched' and 'fosa_mutexes_and_condvars' partial RTLinux adaptation
[frescor/fosa.git] / src_rtlinux / fosa_app_def_sched.h
1 // -----------------------------------------------------------------------
2 //  Copyright (C) 2006 - 2007 FRESCOR consortium partners:
3 //
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
10 //    ENEA                                   SWEDEN
11 //    Thales Communication S.A.              FRANCE
12 //    Visual Tools S.A.                      SPAIN
13 //    Rapita Systems Ltd                     UK
14 //    Evidence                               ITALY
15 //    
16 //    See http://www.frescor.org for a link to partners' websites
17 //
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
21 //        made of this code.
22 //
23 //  This file is part of the FRSH implementation
24 //
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)
28 //  any later version.
29 //
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.
34 //
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
38 //  02111-1307, USA.
39 //
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
45 //  Public License.
46 // -----------------------------------------------------------------------
47 //fosa_app_def_sched.h
48 //==============================================
49 //  ********  ******    ********  **********
50 //  **///// /**    **  **//////  /**     /**
51 //  **      /**    ** /**        /**     /**
52 //  ******* /**    ** /********* /**********
53 //  **////  /**    ** ////////** /**//////**
54 //  **      /**    **        /** /**     /**
55 //  **      /**    **  ********  /**     /**
56 //  //       /******/  ////////   //      // 
57 //
58 // FOSA(Frescor Operating System Adaptation layer)
59 //================================================
60
61
62 #ifndef         FOSA_APP_DEF_SCHED_H_
63 #define         FOSA_APP_DEF_SCHED_H_
64
65 /**
66  * @defgroup appdefsched Application Defined Scheduling
67  * @ingroup fosa
68  *
69  * This module defines the function and types for an abstraction of
70  * the Application Defined Scheduling.
71  *
72  * @{
73  **/
74
75
76
77 /********************************
78  * Application-defined scheduling
79  ********************************/
80
81 /**
82  * We make the following ASSUMPTIONS:
83  *
84  * - The ADS always executes in the user memory space, so we don't
85  *   need to manage the memory space translation. 
86  *
87  * - Only one application scheduler exists, so we don't need an
88  *   scheduler_id.
89  **/
90
91 /**
92  * fosa_ads_scheduler_create()
93  *
94  * Create the application defined scheduler
95  *
96  * The application defined scheduler is created with the primitive
97  * operations specified in the object pointed to by scheduler_ops.
98  * 
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.
103  *
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. 
108  *
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.
114  *
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
118  *
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
122  **/
123 int fosa_ads_scheduler_create
124      (const fosa_ads_scheduler_ops_t * scheduler_ops, 
125       size_t scheduler_data_size,
126       void * init_args, 
127       size_t init_args_size);
128
129 /**
130  * fosa_thread_attr_set_appscheduled()
131  *
132  * Set the appscheduled attribute of a thread attributes object
133  *
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
139  *
140  * Returns 0 if successful; otherwise it returns an error code:
141  *     EINVAL: The value of attr is invalid
142  *
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
146  **/
147 int fosa_thread_attr_set_appscheduled
148         (frsh_thread_attr_t *attr,
149          bool appscheduled);
150
151 /**
152  * fosa_thread_attr_get_appscheduled()
153  *
154  * Get the appscheduled attribute of a thread attributes object
155  *
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.
161  * 
162  * Returns 0 if successful; otherwise it returns an error code:
163  *    EINVAL: The value of attr is invalid
164  *
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
168  **/
169 int fosa_thread_attr_get_appscheduled
170         (const frsh_thread_attr_t *attr,
171          bool *appscheduled);
172
173 /**
174  * fosa_thread_attr_set_appsched_params()
175  *
176  * Set the appsched_param attribute of a thread attributes object
177  *
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
185  *
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
189  *
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
193  **/
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,
199                                                  const void *param,
200                                                  int paramsize){
201         pthread_attr_setappschedparam(attr, param, paramsize);
202 }
203 /**
204  * fosa_thread_attr_get_appsched_params()
205  *
206  * Get the appsched_param attribute of a thread attributes object
207  *
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
216  * paramsize.
217  *
218  * Returns 0 if successful; otherwise it returns an error code:
219  *     EINVAL: The value of attr is invalid
220  *
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
224  **/
225 int fosa_thread_attr_get_appsched_params
226         (const frsh_thread_attr_t *attr,
227          void *param,
228          size_t *paramsize);
229
230 /**
231  * fosa_ads_set_appscheduled()
232  *
233  * Dynamically set the appscheduled attribute of a thread
234  * 
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.
240  *
241  * Returns 0 if successful; otherwise it returns an error code:
242  *     EINVAL: The value of thread is invalid
243  *
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
248  *
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
252  **/
253 int fosa_ads_set_appscheduled
254         (frsh_thread_id_t thread,
255          bool appscheduled);
256
257 /**
258  * fosa_ads_getappscheduled()
259  *
260  * Dynamically get the appscheduled attribute of a thread
261  * 
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
267  *
268  * Returns 0 if successful; otherwise it returns an error code:
269  *     EINVAL: The value of thread is invalid
270  *
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
274  **/
275 int fosa_ads_get_appscheduled
276         (frsh_thread_id_t thread,
277          bool *appscheduled);
278
279
280 /**
281  * fosa_ads_setappschedparam()
282  *
283  * Dynamically set the appsched_param attribute of a thread
284  *
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
292  * that attribute
293  *
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
297  *
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
301  **/
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,
307                                 const void *param,
308                                 size_t paramsize){
309         pthread_setappschedparam(thread, param, paramsize);
310 }
311
312 /**
313  * fosa_ads_get_appsched_params()
314  *
315  * Dynamically get the appsched_param attribute of a thread
316  *
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.
326  *
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
330  *
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.
334  **/
335 //int fosa_ads_get_appsched_params
336 //        (frsh_thread_id_t thread,
337 //         void *param,
338 //         size_t *paramsize);
339 inline int fosa_ads_get_appsched_params (frsh_thread_id_t thread,
340                                          void *param,
341                                          int *paramsize){
342         pthread_getappschedparam(thread, param, paramsize);
343 }
344
345 /*********************************
346  * ADS actions
347  *
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
351  * preserved.
352  *
353  *********************************/
354
355 /**
356  * fosa_adsactions_add_reject()
357  *
358  * Add a reject-thread action
359  *
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
376  * scheduler.
377  *
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
384  *
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
388  **/
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);
395 }
396 /**
397  * fosa_adsactions_add_activate()
398  *
399  * Add a thread-activate action 
400  *
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.
405  *
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.
409  *
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.
417  *
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
423  *
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
427  **/
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);
437 }
438 /**
439  * fosa_adsactions_add_suspend()
440  *
441  * Add a thread-suspend action
442  *
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
449  * operating system.
450  * 
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
456  *
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
460  **/
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);
467 }
468 /**
469  * fosa_adsactions_add_timeout()
470  *
471  * Add a timeout action
472  *
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
478  * argument.
479  *
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
485  *
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
489  **/
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);
494
495 /**
496  * fosa_adsactions_add_thread_notification()
497  *
498  * Add a timed-thread-notification action
499  *
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.
512  * 
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
518  *
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
522  **/
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);
528
529
530 /**
531  * fosa_ads_set_handled_signal_set()
532  *
533  * Specifiy the set of signals that will be handled by the application
534  * scheduler
535  *
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
547  * scheduler.
548  *
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
553  *
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
557  **/
558 int fosa_ads_set_handled_signal_set(frsh_signal_t set[]);
559
560
561 /**
562  * fosa_ads_invoke_withdata()
563  *
564  * Explicitly invoke the scheduler, with data  
565  *
566  * This function can be used by any thread in the process to invoke
567  * the ads scheduler or to share data with it.
568  *
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). 
578  *
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. 
586  * 
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
590  * scheduler.
591  *
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
599  *
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
603  **/
604 int fosa_ads_invoke_withdata
605    (const void *msg, size_t msg_size, void *reply, size_t *reply_size);
606
607 /*}*/
608
609
610 #endif      /* !FOSA_APP_DEF_SCHED_H_ */