Subversion Repositories shark

Rev

Rev 1655 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1655 giacomo 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
 ------------
21
 CVS :        $Id: static.c,v 1.1.1.1 2004-05-24 18:03:47 giacomo Exp $
22
 
23
 File:        $File$
24
 Revision:    $Revision: 1.1.1.1 $
25
 Last update: $Date: 2004-05-24 18:03:47 $
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
 
70
  IQUEUE mytable;
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
 
89
  //  STATIC_printf("(o p%d t%d)", p, (int)proc_table[p].timespec_priority.tv_sec);
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
 
99
  for (my_table_index = iq_query_first(&lev->mytable);
100
       my_table_index != NIL;
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);
103
    kern_event_post(&x, STATIC_offset_activate,(void *)my_table_index);
104
 
105
    STATIC_printf("|p%d t%d ",
106
                  my_table_index,
107
                  (int)iq_query_timespec(my_table_index, &lev->mytable)->tv_sec);
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 */
133
static PID STATIC_public_scheduler(LEVEL l)
134
{
135
  STATIC_level_des *lev = (STATIC_level_des *)(level_table[l]);
136
 
137
  return lev->currenttask;
138
}
139
 
140
static int STATIC_public_create(LEVEL l, PID p, TASK_MODEL *m)
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
 
149
  if (m->pclass != STATIC_PCLASS) return -1;
150
  if (m->level != 0 && m->level != l) return -1;
151
 
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);
155
 
156
  return 0; /* OK, also if the task cannot be guaranteed... */
157
}
158
 
159
static void STATIC_public_dispatch(LEVEL l, PID p, int nostop)
160
{
161
}
162
 
163
static void STATIC_public_epilogue(LEVEL l, PID p)
164
{
165
}
166
 
167
static void STATIC_public_activate(LEVEL l, PID p)
168
{
169
}
170
 
171
static void STATIC_public_unblock(LEVEL l, PID p)
172
{
173
}
174
 
175
static void STATIC_public_block(LEVEL l, PID p)
176
{
177
}
178
 
179
static int STATIC_public_message(LEVEL l, PID p, void *m)
180
{
181
  STATIC_level_des *lev = (STATIC_level_des *)(level_table[l]);
182
 
183
  lev->currenttask = NIL;
184
 
185
  jet_update_endcycle(); /* Update the Jet data... */
186
 
187
  return 0;
188
}
189
 
190
static void STATIC_public_end(LEVEL l, PID p)
191
{
192
  STATIC_level_des *lev = (STATIC_level_des *)(level_table[l]);
193
 
194
  lev->currenttask = NIL;
195
 
196
  iq_extract(p,&lev->mytable);
197
 
198
  /* we finally put the task in the ready queue */
199
  proc_table[p].status = FREE;
200
  iq_insertfirst(p,&freedesc);
201
}
202
 
203
/* Registration functions */
204
 
205
/*+ Registration function:
206
    int flags                 the init flags ... see STATIC.h +*/
207
LEVEL STATIC_register_level()
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 */
215
  l = level_alloc_descriptor(sizeof(STATIC_level_des));
216
 
217
  lev = (STATIC_level_des *)level_table[l];
218
 
219
  printk("    lev=%d\n",(int)lev);
220
 
221
  /* fill the standard descriptor */
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;
231
 
232
  /* fill the STATIC descriptor part */
233
 
234
  iq_init(&lev->mytable, &freedesc, 0);
235
  lev->currenttask = NIL;
236
 
237
  NULL_TIMESPEC(&lev->hp);
238
  NULL_TIMESPEC(&lev->ref);
239
 
240
  return l;
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();
249
  kern_gettime(&x);
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