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 // -----------------------------------------------------------------------
48 //==============================================
49 // ******** ****** ******** **********
50 // **///// /** ** **////// /** /**
51 // ** /** ** /** /** /**
52 // ******* /** ** /********* /**********
53 // **//// /** ** ////////** /**//////**
54 // ** /** ** /** /** /**
55 // ** /** ** ******** /** /**
56 // // /******/ //////// // //
58 // FOSA(Frescor Operating System Adaptation layer)
59 //================================================
62 #ifndef _FOSA_TYPES_H_
63 #define _FOSA_TYPES_H_
65 #include "fosa_opaque_types.h"
68 * @addtogroup clocksandtimers
72 // identifier of a clock
73 // either a real-time clock or a cpu-time clock
74 typedef FOSA_CLOCK_ID_T_OPAQUE fosa_clock_id_t;
76 // identifier of a one-shot timer
77 typedef FOSA_TIMER_ID_T_OPAQUE fosa_timer_id_t;
82 * @addtrogroup mutexesandcondvars
86 // a condition variable
87 typedef FOSA_COND_T_OPAQUE fosa_cond_t;
91 * @addtogroup appdefsched
103 * This type is used to represent a list of scheduling actions that the
104 * scheduler will later request to be executed by the system. The pos-
105 * sible actions are of the following kinds:
106 * - reject a thread that has requested attachment to this scheduler
107 * - activate an application-scheduled thread with the desired value
109 * - suspend an application-scheduled thread
110 * - program a timeout
111 * - program a timed notification associated to a particular
112 * application-scheduled thread.
114 * No comparison or assignment operators are defined for this type
116 typedef FOSA_ADS_ACTIONS_T_OPAQUE fosa_ads_actions_t;
120 * Causes of error in the appsched_error primitive operation
122 typedef enum {FOSA_ADS_THREAD_NOT_ATTACHED, FOSA_ADS_INVALID_ACTION}
123 fosa_ads_error_cause_t;
127 * The urgency used to orde the threads of the same priority in the
128 * underlying scheduler. Support for urgency scheduling is required
129 * for supporting the hierarchhical scheduling module
131 typedef int fosa_ads_urgency_t;
135 * Scheduler primitive operations
137 * This structure is used to create application schedulers. It
138 * contains pointers to the primitive operations that are invoked by
139 * the system when a scheduling event occurs:
141 * - The \b init() primitive operation is invoked by the system just after
142 * the scheduler has been created using fosa_ads_scheduler_create().
144 * - The \b new_thread() primitive operation is invoked by the system when
145 * a thread has requested attachment to this scheduler; this can be a
146 * newly created thread (via fosa_thread_create()), or an existing thread
147 * that was not running under ads scheduler (via
148 * fosa_ads_set_appscheduled()).\n \n
150 * The thread can be rejected by the scheduler adding a
151 * reject-thread action to the actions parameter using
152 * fosa_ads_actions_add_reject(). If no reject-thread action is
153 * added, the thread is accepted.\n \n
155 * Newly created threads shall be activated by the system after the
156 * execution of the new_thread() primitive operation. The urgency of
157 * an accepted thread (either newly created or existing) shall be set
158 * to a value of zero, unless an activate-thread action with a
159 * different value of urgency is added via
160 * fosa_ads_actions_add_activate().\n \n
162 * If a request to attach a thread to this scheduler was made via
163 * fosa_ads_set_appscheduled(), at the finalization of the new_thread()
164 * primitive operation if the newly attached thread is blocked by the
165 * system (not by the scheduler itself via a suspend scheduling
166 * action), a thread-block event shall be generated for the scheduler
167 * immediately and, consequently, the thread_block() primitive
168 * operation shall be invoked by the system.
170 * - The \b thread_terminate() primitive operation is invoked by the system
171 * when a thread attached to this scheduler is terminating (via an
172 * explicit or implicit thread termination, or cancellation, or when
173 * it is no longer sceduled by the ads scheduler (via
174 * fosa_ads_setappscheduled()). \n\n
176 * Before the thread_terminate() primitive operation is invoked by
177 * the system, all the thread-notification events programmed for that
178 * thread are cancelled. \n\n
180 * In the case of a thread that is terminating, the
181 * thread_terminate() primitive operation is executed before the
182 * execution of the cleanup handlers and of the thread-specific data
183 * destructor functions. In that way, the thread parameter corresponds
184 * to a valid thread Id and the thread-specific data is valid and can
185 * be accessed from the thread_terminate() primitive operation. \n\n
187 * Also for terminating threads, after the thread_terminate() primitive
188 * operation finishes, the system shall lower the urgency of the
189 * thread identified by thread to a value of zero, and shall deattach
190 * it from the ads scheduler. Then, the thread shall execute the
191 * cleanup handlers and the thread-specific data destructor functions
192 * outside the management of its former scheduler. Notice that in a
193 * multiprocessor system this may imply the suspension of the thread
194 * identified by parameter thread during the execution of the
195 * thread_terminate() primitive operation.
197 * - The \b thread_ready() primitive operation is invoked by the system
198 * when a thread attached to this scheduler that was blocked has
199 * become unblocked by the system.
201 * - The \b thread_block() primitive operation is invoked by the system
202 * when a thread attached to this scheduler has blocked.
204 * - The \b change_sched_param_thread() primitive operation is invoked by
205 * the system when the scheduling parameters of a thread attached to
206 * this scheduler have been changed, but the thread continues to run
207 * under this scheduler. The change includes either the regular
208 * scheduling parameters (fosa_thread_set_prio() or the application-
209 * defined scheduling parameters, via fosa_ads_set_appsched_param().
211 * - The \b explicit_call_with_data() primitive operation is invoked by the
212 * system when a thread (identified by the thread parameter) has
213 * explicitly invoked the scheduler with a message containing
214 * scheduling information, and possibly requesting a reply message,
215 * via fosa_ads_invoke_withdata().
217 * - The \b notification_for_thread() primitive operation is invoked by the
218 * system when the time for a thread-notification previously programed
219 * by the scheduler via fosa_ads_actions_add_thread_notification()
220 * is reached. Parameter clock identifies the clock for which the
221 * thread-notification was programmed.
223 * - The \b timeout() primitive operation is invoked by the system when a
224 * timeout requested by the scheduler (via
225 * fosa_ads_actions_add_timeout()) has expired.
227 * - The \b signal() primitive operation is invoked by the system when a
228 * signal belonging to the set of signals for which the scheduler is
229 * waiting (via fosa_ads_set_handled_signal_set()) has been
232 * The signal number and its associated information (if any) are
233 * passed in the arguments signal and siginfo.\n\n
235 * The signal is consumed with the invocation of this primitive
236 * operation, which implies that it will not cause the execution of
237 * any signal handler, nor it may be accepted by any thread waiting
238 * for this signal number.
240 * - The \b appsched_error() primitive operation is invoked by the system
241 * when an error in the scheduling actions list specified in a
242 * previous primitive operation is detected. The cause of the error is
243 * notified in the parameter cause. The defined causes of error are
244 * described fosa_ads_error_cause_tappdefsched
246 * Every primitive operation receives the argument sched_data. It is a
247 * pointer to a memory area containing information shared by all the
248 * scheduler operations. It can be used to store the data structures
249 * required by the scheduler (for example, a ready queue and a delay
250 * queue). Scheduler operations should not use any other global data out
251 * of this memory area.
253 * The actions argument is used by the scheduler to request the operating
254 * system to execute a set of scheduling actions at the end of the
255 * primitive operation. It is passed empty by the system, and the
256 * scheduler may add multiple scheduling actions.
258 * The current_time argument contains the system time
259 * measured immediately before the invocation of the primitive operation
260 * using the FOSA_CLOCK_REALTIME clock
262 * In addition to these common parameters, most of the primitive
263 * operations receive a thread argument. This argument allows the
264 * primitive operations to know which is the thread that has produced or
265 * is related to the event.
268 void (*init) (void * sched_data, void * arg);
269 void (*new_thread) (void * sched_data,
270 frsh_thread_id_t thread,
271 fosa_ads_actions_t * actions,
272 struct timespec *current_time);
273 void (*thread_terminate) (void * sched_data,
274 frsh_thread_id_t thread,
275 fosa_ads_actions_t * actions,
276 struct timespec *current_time);
277 void (*thread_ready) (void * sched_data,
278 frsh_thread_id_t thread,
279 fosa_ads_actions_t * actions,
280 struct timespec *current_time);
281 void (*thread_block) (void * sched_data,
282 frsh_thread_id_t thread,
283 fosa_ads_actions_t * actions,
284 struct timespec *current_time);
285 //void (*thread_yield) (void * sched_data,
286 // frsh_thread_id_t thread,
287 // fosa_ads_actions_t * actions,
288 // struct timespec *current_time);
289 void (*change_sched_param_thread) (void * sched_data,
290 frsh_thread_id_t thread,
291 fosa_ads_actions_t * actions,
292 struct timespec *current_time);
293 //void msg_from_scheduler(void * sched_data,
294 // fosa_ads_scheduler_id_t scheduler_id,
295 // const void * msg, size_t msg_size,
296 // fosa_ads_actions_t * actions,
297 // struct timespec *current_time);
298 //void (*explicit_call) (void * sched_data,
299 // frsh_thread_id_t thread,
300 // int user_event_code,
301 // fosa_ads_actions_t * actions,
302 // struct timespec *current_time);
303 void (*explicit_call_with_data) (void * sched_data,
304 frsh_thread_id_t thread,
305 const void * msg, size_t msg_size,
306 void **reply, size_t *reply_size,
307 fosa_ads_actions_t * actions,
308 struct timespec *current_time);
309 void (*notification_for_thread) (void * sched_data,
310 frsh_thread_id_t thread,
311 fosa_clock_id_t clock,
312 fosa_ads_actions_t * actions,
313 struct timespec *current_time);
314 void (*timeout) (void * sched_data,
315 fosa_ads_actions_t * actions,
316 struct timespec *current_time);
317 void (*signal) (void * sched_data,
318 frsh_signal_t signal,
319 frsh_signal_info_t siginfo,
320 fosa_ads_actions_t * actions,
321 struct timespec *current_time);
322 //void (*priority_inherit) (void * sched_data,
323 // frsh_thread_id_t thread,
324 // int sched_priority,
325 // fosa_ads_actions_t * actions,
326 // struct timespec *current_time);
327 //void (*priority_uninherit) (void * sched_data,
328 // frsh_thread_id_t thread,
329 // int sched_priority,
330 // fosa_ads_actions_t * actions,
331 // struct timespec *current_time);
332 void (*appshed_error) (void * sched_data,
333 frsh_thread_id_t thread,
334 fosa_ads_error_cause_t cause,
335 fosa_ads_actions_t * actions);
336 } fosa_ads_scheduler_ops_t;
341 #endif // _FOSA_TYPES_H_