Rev 1123 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1085 | pj | 1 | /* |
2 | * Project: S.Ha.R.K. |
||
3 | * |
||
4 | * Coordinators: |
||
5 | * Giorgio Buttazzo <giorgio@sssup.it> |
||
6 | * Paolo Gai <pj@gandalf.sssup.it> |
||
7 | * |
||
8 | * Authors : |
||
9 | * Paolo Gai <pj@gandalf.sssup.it> |
||
10 | * (see the web pages for full authors list) |
||
11 | * |
||
12 | * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
||
13 | * |
||
14 | * http://www.sssup.it |
||
15 | * http://retis.sssup.it |
||
16 | * http://shark.sssup.it |
||
17 | */ |
||
18 | |||
19 | /** |
||
20 | ------------ |
||
1287 | giacomo | 21 | CVS : $Id: static.c,v 1.5 2003-12-17 13:52:47 giacomo Exp $ |
1085 | pj | 22 | |
23 | File: $File$ |
||
1287 | giacomo | 24 | Revision: $Revision: 1.5 $ |
25 | Last update: $Date: 2003-12-17 13:52:47 $ |
||
1085 | pj | 26 | ------------ |
27 | **/ |
||
28 | |||
29 | /* |
||
30 | * Copyright (C) 2001 Paolo Gai |
||
31 | * |
||
32 | * This program is free software; you can redistribute it and/or modify |
||
33 | * it under the terms of the GNU General Public License as published by |
||
34 | * the Free Software Foundation; either version 2 of the License, or |
||
35 | * (at your option) any later version. |
||
36 | * |
||
37 | * This program is distributed in the hope that it will be useful, |
||
38 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
39 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
40 | * GNU General Public License for more details. |
||
41 | * |
||
42 | * You should have received a copy of the GNU General Public License |
||
43 | * along with this program; if not, write to the Free Software |
||
44 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
45 | * |
||
46 | */ |
||
47 | |||
48 | #include "static.h" |
||
49 | #include <ll/stdio.h> |
||
50 | #include <ll/string.h> |
||
51 | #include <kernel/model.h> |
||
52 | #include <kernel/descr.h> |
||
53 | #include <kernel/var.h> |
||
54 | #include <kernel/func.h> |
||
55 | |||
56 | #define STATIC_printf kern_printf |
||
57 | //#define STATIC_printf printk |
||
58 | |||
59 | /*+ Status used in the level +*/ |
||
60 | #define STATIC_READY MODULE_STATUS_BASE /*+ - Ready status +*/ |
||
61 | #define STATIC_IDLE MODULE_STATUS_BASE+4 /*+ to wait the deadline +*/ |
||
62 | |||
63 | /*+ flags +*/ |
||
64 | #define STATIC_FLAG_NORAISEEXC 2 |
||
65 | |||
66 | /*+ the level redefinition for the Earliest Deadline First level +*/ |
||
67 | typedef struct { |
||
68 | level_des l; /*+ the standard level descriptor +*/ |
||
69 | |||
1108 | pj | 70 | IQUEUE mytable; |
1085 | pj | 71 | |
72 | PID currenttask; |
||
73 | |||
74 | struct timespec hp; |
||
75 | struct timespec ref; |
||
76 | |||
77 | } STATIC_level_des; |
||
78 | |||
79 | static void STATIC_offset_activate(void *par) |
||
80 | { |
||
81 | PID p = (PID) par; |
||
82 | STATIC_level_des *lev; |
||
83 | |||
84 | lev = (STATIC_level_des *)level_table[proc_table[p].task_level]; |
||
85 | |||
86 | lev->currenttask = p; |
||
87 | event_need_reschedule(); |
||
88 | |||
1108 | pj | 89 | // STATIC_printf("(o p%d t%d)", p, (int)proc_table[p].timespec_priority.tv_sec); |
1085 | pj | 90 | } |
91 | |||
92 | static void STATIC_activateall(STATIC_level_des *lev) |
||
93 | { |
||
94 | PID my_table_index; |
||
95 | struct timespec x; |
||
96 | |||
97 | STATIC_printf("(A "); |
||
98 | |||
1108 | pj | 99 | for (my_table_index = iq_query_first(&lev->mytable); |
1085 | pj | 100 | my_table_index != NIL; |
1108 | pj | 101 | my_table_index = iq_query_next(my_table_index, &lev->mytable)) { |
102 | ADDTIMESPEC(&lev->ref,iq_query_timespec(my_table_index, &lev->mytable),&x); |
||
1085 | pj | 103 | kern_event_post(&x, STATIC_offset_activate,(void *)my_table_index); |
104 | |||
105 | STATIC_printf("|p%d t%d ", |
||
106 | my_table_index, |
||
1108 | pj | 107 | (int)iq_query_timespec(my_table_index, &lev->mytable)->tv_sec); |
1085 | pj | 108 | } |
109 | |||
110 | STATIC_printf(")"); |
||
111 | |||
112 | } |
||
113 | |||
114 | static void STATIC_hyperperiod(void *par) |
||
115 | { |
||
116 | STATIC_level_des *lev; |
||
117 | struct timespec x; |
||
118 | |||
119 | lev = (STATIC_level_des *)level_table[(LEVEL)par]; |
||
120 | |||
121 | STATIC_printf("(hp %d)", (int)lev->ref.tv_sec); |
||
122 | |||
123 | STATIC_activateall(lev); |
||
124 | |||
125 | ADDTIMESPEC(&lev->ref, &lev->hp, &x); |
||
126 | lev->ref = x; |
||
127 | |||
128 | kern_event_post(&x, STATIC_hyperperiod, par); |
||
129 | } |
||
130 | |||
131 | |||
132 | /* The scheduler only gets the first task in the queue */ |
||
1123 | pj | 133 | static PID STATIC_public_scheduler(LEVEL l) |
1085 | pj | 134 | { |
135 | STATIC_level_des *lev = (STATIC_level_des *)(level_table[l]); |
||
136 | |||
137 | return lev->currenttask; |
||
138 | } |
||
139 | |||
1123 | pj | 140 | static int STATIC_public_create(LEVEL l, PID p, TASK_MODEL *m) |
1085 | pj | 141 | { |
142 | STATIC_level_des *lev = (STATIC_level_des *)(level_table[l]); |
||
143 | |||
144 | /* if the STATIC_task_create is called, then the pclass must be a |
||
145 | valid pclass. */ |
||
146 | |||
147 | STATIC_TASK_MODEL *h = (STATIC_TASK_MODEL *)m; |
||
148 | |||
1123 | pj | 149 | if (m->pclass != STATIC_PCLASS) return -1; |
150 | if (m->level != 0 && m->level != l) return -1; |
||
151 | |||
1108 | pj | 152 | iq_query_timespec(p, &lev->mytable)->tv_sec = h->offset.tv_sec; |
153 | iq_query_timespec(p, &lev->mytable)->tv_nsec = h->offset.tv_nsec; |
||
154 | iq_timespec_insert(p,&lev->mytable); |
||
1085 | pj | 155 | |
156 | return 0; /* OK, also if the task cannot be guaranteed... */ |
||
157 | } |
||
158 | |||
1123 | pj | 159 | static void STATIC_public_dispatch(LEVEL l, PID p, int nostop) |
1085 | pj | 160 | { |
161 | } |
||
162 | |||
1123 | pj | 163 | static void STATIC_public_epilogue(LEVEL l, PID p) |
1085 | pj | 164 | { |
165 | } |
||
166 | |||
1123 | pj | 167 | static void STATIC_public_activate(LEVEL l, PID p) |
1085 | pj | 168 | { |
169 | } |
||
170 | |||
1123 | pj | 171 | static void STATIC_public_unblock(LEVEL l, PID p) |
1085 | pj | 172 | { |
173 | } |
||
174 | |||
1123 | pj | 175 | static void STATIC_public_block(LEVEL l, PID p) |
1085 | pj | 176 | { |
177 | } |
||
178 | |||
1123 | pj | 179 | static int STATIC_public_message(LEVEL l, PID p, void *m) |
1085 | pj | 180 | { |
1123 | pj | 181 | STATIC_level_des *lev = (STATIC_level_des *)(level_table[l]); |
1085 | pj | 182 | |
1123 | pj | 183 | lev->currenttask = NIL; |
1085 | pj | 184 | |
1123 | pj | 185 | jet_update_endcycle(); /* Update the Jet data... */ |
1085 | pj | 186 | |
1123 | pj | 187 | return 0; |
1085 | pj | 188 | } |
189 | |||
1123 | pj | 190 | static void STATIC_public_end(LEVEL l, PID p) |
1085 | pj | 191 | { |
192 | STATIC_level_des *lev = (STATIC_level_des *)(level_table[l]); |
||
193 | |||
194 | lev->currenttask = NIL; |
||
195 | |||
1108 | pj | 196 | iq_extract(p,&lev->mytable); |
1085 | pj | 197 | |
198 | /* we finally put the task in the ready queue */ |
||
199 | proc_table[p].status = FREE; |
||
1108 | pj | 200 | iq_insertfirst(p,&freedesc); |
1085 | pj | 201 | } |
202 | |||
203 | /* Registration functions */ |
||
204 | |||
205 | /*+ Registration function: |
||
206 | int flags the init flags ... see STATIC.h +*/ |
||
1123 | pj | 207 | LEVEL STATIC_register_level() |
1085 | pj | 208 | { |
209 | LEVEL l; /* the level that we register */ |
||
210 | STATIC_level_des *lev; /* for readableness only */ |
||
211 | |||
212 | printk("STATIC_register_level\n"); |
||
213 | |||
214 | /* request an entry in the level_table */ |
||
1123 | pj | 215 | l = level_alloc_descriptor(sizeof(STATIC_level_des)); |
1085 | pj | 216 | |
1123 | pj | 217 | lev = (STATIC_level_des *)level_table[l]; |
1085 | pj | 218 | |
219 | printk(" lev=%d\n",(int)lev); |
||
220 | |||
221 | /* fill the standard descriptor */ |
||
1123 | pj | 222 | lev->l.public_scheduler = STATIC_public_scheduler; |
223 | lev->l.public_create = STATIC_public_create; |
||
224 | lev->l.public_end = STATIC_public_end; |
||
225 | lev->l.public_dispatch = STATIC_public_dispatch; |
||
226 | lev->l.public_epilogue = STATIC_public_epilogue; |
||
227 | lev->l.public_activate = STATIC_public_activate; |
||
228 | lev->l.public_unblock = STATIC_public_unblock; |
||
229 | lev->l.public_block = STATIC_public_block; |
||
230 | lev->l.public_message = STATIC_public_message; |
||
1085 | pj | 231 | |
232 | /* fill the STATIC descriptor part */ |
||
233 | |||
1108 | pj | 234 | iq_init(&lev->mytable, &freedesc, 0); |
1085 | pj | 235 | lev->currenttask = NIL; |
236 | |||
237 | NULL_TIMESPEC(&lev->hp); |
||
238 | NULL_TIMESPEC(&lev->ref); |
||
1123 | pj | 239 | |
240 | return l; |
||
1085 | pj | 241 | } |
242 | |||
243 | void STATIC_start(LEVEL l, struct timespec *h, struct timespec *o) |
||
244 | { |
||
245 | STATIC_level_des *lev = (STATIC_level_des *)(level_table[l]); |
||
246 | struct timespec x; |
||
247 | |||
248 | kern_cli(); |
||
1123 | pj | 249 | kern_gettime(&x); |
1085 | pj | 250 | lev->hp = *h; |
251 | |||
252 | ADDTIMESPEC(&x,o,&lev->ref); |
||
253 | STATIC_printf("(ST: ref:%d.%d x:%d.%d)\n", |
||
254 | (int)lev->ref.tv_sec, (int)lev->ref.tv_nsec, |
||
255 | (int)x.tv_sec, (int)x.tv_nsec); |
||
256 | |||
257 | kern_event_post(&x, STATIC_hyperperiod,(void *)l); |
||
258 | |||
259 | kern_sti(); |
||
260 | } |
||
261 | |||
262 |