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 //================================================
64 /********************************
65 * Application-defined scheduling
66 ********************************/
69 extern fosa_ads_scheduler_ops_t fosa_scheduler_operations; // See rtl_appsched.c
70 extern void *fosa_scheduler_loop(void *arg); // See rtl_appsched.c
71 extern void *fosa_scheduler_args;
72 extern int fosa_scheduler_args_size;
75 int fosa_ads_scheduler_create (const fosa_ads_scheduler_ops_t * scheduler_ops,
76 size_t scheduler_data_size,
78 size_t init_args_size){
83 // There will be only ONE single ADS scheduler facility in the system
84 fosa_scheduler_args_size=init_args_size;
85 fosa_scheduler_args=rtl_malloc(init_args_size);
86 if (!fosa_scheduler_args) {
87 rtl_printf("ERROR: fosa_ads_scheduler_create, rtl_mallox failed\n");
90 memcpy((unsigned char *)fosa_scheduler_args,
91 (unsigned char *)init_args, init_args_size);
93 fosa_scheduler_operations = *scheduler_ops;
95 pthread_attr_init (&attr);
96 sched_param.sched_priority=100; // Only one priority will be
97 // used in the system.
98 pthread_attr_setappschedulerstate(&attr, PTHREAD_APPSCHEDULER);
99 pthread_attr_setschedparam (&attr, &sched_param);
101 ret=pthread_create(&fosa_scheduler_thread, &attr,
102 fosa_scheduler_loop, NULL);
108 int fosa_thread_attr_set_appscheduled (frsh_thread_attr_t *attr,
112 attr->policy=SCHED_APP;
114 attr->policy=SCHED_FIFO;
120 int fosa_thread_attr_get_appscheduled (const frsh_thread_attr_t *attr,
123 if (attr->policy==SCHED_APP)
132 int fosa_thread_attr_set_appsched_params (frsh_thread_attr_t *attr,
135 return pthread_attr_setappschedparam(attr, param, paramsize);
138 int fosa_thread_attr_get_appsched_params (const frsh_thread_attr_t *attr,
141 return pthread_attr_getappschedparam(attr, param, paramsize);
144 int fosa_ads_set_appscheduled (frsh_thread_id_t thread,
146 pthread_t sched=(appscheduled)?fosa_scheduler_thread:0;
148 return (!pthread_setappscheduler(thread, sched))?0:EINVAL;
151 int fosa_ads_get_appscheduled (frsh_thread_id_t thread,
154 *appscheduled=(appscheduler(thread))?1:0;
160 int fosa_ads_set_appschedparam (frsh_thread_id_t thread,
163 return (!pthread_setappschedparam(thread, param, paramsize))?0:EINVAL;
166 int fosa_ads_get_appsched_params (frsh_thread_id_t thread,
169 return (!pthread_getappschedparam(thread, param, paramsize))?0:EINVAL;
172 /*********************************
175 * A scheduling actions object is used to specify a series of actions
176 * to be performed by the system at the end of a scheduler primitive
177 * operation. The order of the actions added to the object shall be
180 *********************************/
182 int fosa_adsactions_add_reject(fosa_ads_actions_t *sched_actions,
183 frsh_thread_id_t thread){
184 return posix_appsched_actions_addreject(sched_actions, thread);
187 int fosa_adsactions_add_activate(fosa_ads_actions_t *sched_actions,
188 frsh_thread_id_t thread,
189 fosa_ads_urgency_t urgency){
190 RTL_PRIO(&thread)=set_urgency(urgency, (&thread));
191 return posix_appsched_actions_addactivate(sched_actions, thread);
194 int fosa_adsactions_add_suspend(fosa_ads_actions_t *sched_actions,
195 frsh_thread_id_t thread){
196 return posix_appsched_actions_addsuspend (sched_actions, thread);
200 int fosa_adsactions_add_timeout(fosa_ads_actions_t *sched_actions,
201 fosa_clock_id_t clock_id,
202 const struct timespec *at_time){
203 struct sigevent signal;
204 if (fosa_timeout_timer)
207 signal.sigev_signo=0;
208 signal.sigev_notify=SIGEV_NONE;
210 timer_create(clock_id, signal, &fosa_timeout_timer);
211 timer_settime(fosa_timeout_timer, int flags, at_time, 0);
215 int fosa_adsactions_add_thread_notification(fosa_ads_actions_t *sched_actions,
216 frsh_thread_id_t thread,
217 fosa_clock_id_t clock_id,
218 const struct timespec *at_time){
225 int fosa_ads_set_handled_signal_set(frsh_signal_t set[]){
230 int fosa_ads_invoke_withdata (const void *msg,
234 posix_appsched_invoke_withdata(msg, msg_size, reply, reply_size);