]> rtime.felk.cvut.cz Git - frescor/fosa.git/blob - src_rtlinux/fosa_app_def_sched.c
FOSA ADS timeout and notification events implemented
[frescor/fosa.git] / src_rtlinux / fosa_app_def_sched.c
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.c
48 //==============================================
49 //  ********  ******    ********  **********
50 //  **///// /**    **  **//////  /**     /**
51 //  **      /**    ** /**        /**     /**
52 //  ******* /**    ** /********* /**********
53 //  **////  /**    ** ////////** /**//////**
54 //  **      /**    **        /** /**     /**
55 //  **      /**    **  ********  /**     /**
56 //  //       /******/  ////////   //      // 
57 //
58 // FOSA(Frescor Operating System Adaptation layer)
59 //================================================
60
61
62 // MISSED: HEADERS
63
64 /********************************
65  * Application-defined scheduling
66  ********************************/
67
68
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;
73
74
75 int fosa_ads_scheduler_create (const fosa_ads_scheduler_ops_t * scheduler_ops, 
76                                size_t scheduler_data_size,
77                                void * init_args, 
78                                size_t init_args_size){
79
80     pthread_attr_t  attr; 
81     int ret;
82
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");
88         return -1;
89     }
90     memcpy((unsigned char *)fosa_scheduler_args, 
91            (unsigned char *)init_args, init_args_size);
92
93     fosa_scheduler_operations = *scheduler_ops;
94
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);
100     
101     ret=pthread_create(&fosa_scheduler_thread, &attr, 
102                        fosa_scheduler_loop, NULL);
103     return ret;
104 }
105
106
107
108 int fosa_thread_attr_set_appscheduled (frsh_thread_attr_t *attr,
109                                        bool appscheduled){
110      if (attr){
111           if (appscheduled)
112                attr->policy=SCHED_APP;
113           else
114                attr->policy=SCHED_FIFO;
115           return 0;
116      } 
117      else return EINVAL;
118 }
119
120 int fosa_thread_attr_get_appscheduled (const frsh_thread_attr_t *attr,
121                                        bool *appscheduled){
122         if (attr){
123              if (attr->policy==SCHED_APP)
124                   *appscheduled=true;
125              else
126                   *appscheduled=false;
127              return 0;
128         }
129         else return EINVAL;
130 }
131
132 int fosa_thread_attr_set_appsched_params (frsh_thread_attr_t *attr,
133                                                  const void *param,
134                                                  int paramsize){
135      return pthread_attr_setappschedparam(attr, param, paramsize);
136 }
137
138 int fosa_thread_attr_get_appsched_params (const frsh_thread_attr_t *attr,
139                                           void *param,
140                                           size_t *paramsize){
141      return pthread_attr_getappschedparam(attr, param, paramsize);      
142 }
143
144 int fosa_ads_set_appscheduled (frsh_thread_id_t thread,
145                                bool appscheduled){
146      pthread_t sched=(appscheduled)?fosa_scheduler_thread:0;
147      
148      return (!pthread_setappscheduler(thread, sched))?0:EINVAL;
149 }
150
151 int fosa_ads_get_appscheduled (frsh_thread_id_t thread,
152                                bool *appscheduled){
153      if (thread) {
154           *appscheduled=(appscheduler(thread))?1:0;
155           return 0;
156      }
157      return EINVAL;
158 }
159
160 int fosa_ads_set_appschedparam (frsh_thread_id_t thread,
161                                 const void *param,
162                                 size_t paramsize){
163      return (!pthread_setappschedparam(thread, param, paramsize))?0:EINVAL;
164 }
165
166 int fosa_ads_get_appsched_params (frsh_thread_id_t thread,
167                                          void *param,
168                                          int *paramsize){
169      return (!pthread_getappschedparam(thread, param, paramsize))?0:EINVAL;
170 }
171
172 /*********************************
173  * ADS actions
174  *
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
178  * preserved.
179  *
180  *********************************/
181
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);
185 }
186
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);
192 }
193
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);
197 }
198
199
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)
205           return EINVAL;
206
207      signal.sigev_signo=0;
208      signal.sigev_notify=SIGEV_NONE;
209
210      timer_create(clock_id, signal, &fosa_timeout_timer);
211      timer_settime(fosa_timeout_timer, int flags, at_time, 0);
212 }
213
214
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){
219      struct sigevent signal;
220      if (fosa_timeout_timer)
221           return EINVAL;
222
223      signal.sigev_value.sival_ptr=(void *)clock_id;
224      signal.sigev_signo=(int)thread;
225      signal.sigev_notify=SIGEV_NONE;
226
227      timer_create(clock_id, signal, &fosa_timeout_timer);
228      timer_settime(fosa_timeout_timer, int flags, at_time, 0);
229 }
230
231
232
233 int fosa_ads_set_handled_signal_set(frsh_signal_t set[]){
234      
235 }
236
237
238 int fosa_ads_invoke_withdata (const void *msg, 
239                                      size_t msg_size, 
240                                      void *reply, 
241                                      size_t *reply_size){
242         posix_appsched_invoke_withdata(msg, msg_size, reply, reply_size);
243 }