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.c
48 //==============================================
49 // ******** ****** ******** **********
50 // **///// /** ** **////// /** /**
51 // ** /** ** /** /** /**
52 // ******* /** ** /********* /**********
53 // **//// /** ** ////////** /**//////**
54 // ** /** ** /** /** /**
55 // ** /** ** ******** /** /**
56 // // /******/ //////// // //
58 // FOSA(Frescor Operating System Adaptation layer)
59 //================================================
63 //#include <rtl_sched.h>
64 #include <rtl_malloc.h>
66 /********************************
67 * Application-defined scheduling
68 ********************************/
71 extern fosa_ads_scheduler_ops_t fosa_scheduler_operations; // See rtl_appsched.c
72 extern void *fosa_scheduler_loop(void *arg); // See rtl_appsched.c
73 extern void *fosa_scheduler_args;
74 extern int fosa_scheduler_args_size;
77 int fosa_ads_scheduler_create (const fosa_ads_scheduler_ops_t * scheduler_ops,
78 size_t scheduler_data_size,
80 size_t init_args_size){
81 struct sched_param sched_param;
85 // There will be only ONE single ADS scheduler facility in the system
86 fosa_scheduler_args_size=init_args_size;
87 fosa_scheduler_args=rtl_malloc(init_args_size);
88 if (!fosa_scheduler_args) {
89 rtl_printf("ERROR: fosa_ads_scheduler_create, rtl_mallox failed\n");
92 memcpy((unsigned char *)fosa_scheduler_args,
93 (unsigned char *)init_args, init_args_size);
95 fosa_scheduler_operations = *scheduler_ops;
97 pthread_attr_init (&attr);
98 sched_param.sched_priority=100; // Only one priority will be
99 // used in the system.
100 pthread_attr_setappschedulerstate(&attr, PTHREAD_APPSCHEDULER);
101 pthread_attr_setschedparam (&attr, &sched_param);
103 ret=pthread_create(&fosa_scheduler_thread, &attr,
104 fosa_scheduler_loop, NULL);
110 int fosa_thread_attr_set_appscheduled (frsh_thread_attr_t *attr,
114 attr->policy=SCHED_APP;
116 attr->policy=SCHED_FIFO;
122 int fosa_thread_attr_get_appscheduled (const frsh_thread_attr_t *attr,
125 if (attr->policy==SCHED_APP)
134 int fosa_thread_attr_set_appsched_params (frsh_thread_attr_t *attr,
137 return pthread_attr_setappschedparam(attr, (void *)param, paramsize);
140 int fosa_thread_attr_get_appsched_params (const frsh_thread_attr_t *attr,
143 return pthread_attr_getappschedparam((frsh_thread_attr_t *)attr, param, paramsize);
146 int fosa_ads_set_appscheduled (frsh_thread_id_t thread,
148 pthread_t sched=(appscheduled)?fosa_scheduler_thread:0;
150 return (!pthread_setappscheduler(thread, sched))?0:EINVAL;
153 int fosa_ads_get_appscheduled (frsh_thread_id_t thread,
156 *appscheduled=(appscheduler(thread))?1:0;
162 int fosa_ads_set_appschedparam (frsh_thread_id_t thread,
165 return (!pthread_setappschedparam(thread, (void *)param, paramsize))?0:EINVAL;
168 int fosa_ads_get_appsched_params (frsh_thread_id_t thread,
171 return (!pthread_getappschedparam(thread, param, paramsize))?0:EINVAL;
174 int fosa_ads_set_appsched_params (frsh_thread_id_t thread,
177 return (!pthread_setappschedparam(thread, (void *)param, paramsize))?0:EINVAL;
180 /*********************************
183 * A scheduling actions object is used to specify a series of actions
184 * to be performed by the system at the end of a scheduler primitive
185 * operation. The order of the actions added to the object shall be
188 *********************************/
190 int fosa_adsactions_add_reject(fosa_ads_actions_t *sched_actions,
191 frsh_thread_id_t thread){
192 return posix_appsched_actions_addreject(sched_actions, thread);
195 int fosa_adsactions_add_activate(fosa_ads_actions_t *sched_actions,
196 frsh_thread_id_t thread,
197 fosa_ads_urgency_t urgency){
198 RTL_PRIO(thread)=set_urgency(thread, urgency);
199 return posix_appsched_actions_addactivate(sched_actions, thread);
202 int fosa_adsactions_add_suspend(fosa_ads_actions_t *sched_actions,
203 frsh_thread_id_t thread){
204 return posix_appsched_actions_addsuspend (sched_actions, thread);
207 extern timer_t fosa_timeout_timer; // defined in rtl_fosa.c
208 int fosa_adsactions_add_timeout(fosa_ads_actions_t *sched_actions,
209 fosa_clock_id_t clock_id,
210 const struct timespec *at_time){
211 struct sigevent signal;
212 struct itimerspec at_itimer= (struct itimerspec)
213 {.it_interval=(struct timespec){0,0},
216 if (fosa_timeout_timer)
219 signal.sigev_signo=0;
220 signal.sigev_notify=SIGEV_NONE;
222 timer_create(clock_id, &signal, &fosa_timeout_timer);
223 timer_settime(fosa_timeout_timer, 0, &at_itimer, 0);
228 int fosa_adsactions_add_thread_notification(fosa_ads_actions_t *sched_actions,
229 frsh_thread_id_t thread,
230 fosa_clock_id_t clock_id,
231 const struct timespec *at_time){
232 struct sigevent signal;
233 struct itimerspec at_itimer= (struct itimerspec)
234 {.it_interval=(struct timespec){0,0},
237 if (fosa_timeout_timer)
240 signal.sigev_value.sival_ptr=(void *)clock_id;
241 signal.sigev_signo=(int)thread;
242 signal.sigev_notify=SIGEV_NONE;
244 timer_create(clock_id, &signal, &fosa_timeout_timer);
245 timer_settime(fosa_timeout_timer, 0, &at_itimer, 0);
248 extern rtl_sigset_t fosa_scheduler_signal_bitmap; // as declared in rtl_fosa.c
250 int fosa_ads_set_handled_signal_set(frsh_signal_t set[], int size){
253 rtl_sigemptyset(&fosa_scheduler_signal_bitmap);
254 for (x=0; x<size; x++)
255 rtl_sigaddset(&fosa_scheduler_signal_bitmap, set[x]);
260 int fosa_ads_invoke_withdata (const void *msg, size_t msg_size,
261 void *reply, size_t *reply_size){
262 return posix_appsched_invoke_withdata((void *)msg, msg_size, reply, reply_size);