Subversion Repositories shark

Rev

Rev 1108 | 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
 ------------
1123 pj 21
 CVS :        $Id: static.c,v 1.4 2003-01-07 17:10:18 pj Exp $
1085 pj 22
 
23
 File:        $File$
1123 pj 24
 Revision:    $Revision: 1.4 $
25
 Last update: $Date: 2003-01-07 17:10:18 $
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
#include <kernel/trace.h>
56
 
57
#define STATIC_printf kern_printf
58
//#define STATIC_printf printk
59
 
60
/*+ Status used in the level +*/
61
#define STATIC_READY         MODULE_STATUS_BASE    /*+ - Ready status        +*/
62
#define STATIC_IDLE          MODULE_STATUS_BASE+4  /*+ to wait the deadline  +*/
63
 
64
/*+ flags +*/
65
#define STATIC_FLAG_NORAISEEXC  2
66
 
67
/*+ the level redefinition for the Earliest Deadline First level +*/
68
typedef struct {
69
  level_des l;     /*+ the standard level descriptor          +*/
70
 
1108 pj 71
  IQUEUE mytable;
1085 pj 72
 
73
  PID currenttask;
74
 
75
  struct timespec hp;
76
  struct timespec ref;
77
 
78
} STATIC_level_des;
79
 
80
static void STATIC_offset_activate(void *par)
81
{
82
  PID p = (PID) par;
83
  STATIC_level_des *lev;
84
 
85
  lev = (STATIC_level_des *)level_table[proc_table[p].task_level];
86
 
87
  lev->currenttask = p;
88
  event_need_reschedule();
89
 
1108 pj 90
  //  STATIC_printf("(o p%d t%d)", p, (int)proc_table[p].timespec_priority.tv_sec);
1085 pj 91
}
92
 
93
static void STATIC_activateall(STATIC_level_des *lev)
94
{
95
  PID my_table_index;
96
  struct timespec x;
97
 
98
  STATIC_printf("(A ");
99
 
1108 pj 100
  for (my_table_index = iq_query_first(&lev->mytable);
1085 pj 101
       my_table_index != NIL;
1108 pj 102
       my_table_index = iq_query_next(my_table_index, &lev->mytable)) {
103
    ADDTIMESPEC(&lev->ref,iq_query_timespec(my_table_index, &lev->mytable),&x);
1085 pj 104
    kern_event_post(&x, STATIC_offset_activate,(void *)my_table_index);
105
 
106
    STATIC_printf("|p%d t%d ",
107
                  my_table_index,
1108 pj 108
                  (int)iq_query_timespec(my_table_index, &lev->mytable)->tv_sec);
1085 pj 109
  }
110
 
111
  STATIC_printf(")");
112
 
113
}
114
 
115
static void STATIC_hyperperiod(void *par)
116
{
117
  STATIC_level_des *lev;
118
  struct timespec x;
119
 
120
  lev = (STATIC_level_des *)level_table[(LEVEL)par];
121
 
122
  STATIC_printf("(hp %d)", (int)lev->ref.tv_sec);
123
 
124
  STATIC_activateall(lev);
125
 
126
  ADDTIMESPEC(&lev->ref, &lev->hp, &x);
127
  lev->ref = x;
128
 
129
  kern_event_post(&x, STATIC_hyperperiod, par);
130
}
131
 
132
 
133
/* The scheduler only gets the first task in the queue */
1123 pj 134
static PID STATIC_public_scheduler(LEVEL l)
1085 pj 135
{
136
  STATIC_level_des *lev = (STATIC_level_des *)(level_table[l]);
137
 
138
  return lev->currenttask;
139
}
140
 
1123 pj 141
static int STATIC_public_create(LEVEL l, PID p, TASK_MODEL *m)
1085 pj 142
{
143
  STATIC_level_des *lev = (STATIC_level_des *)(level_table[l]);
144
 
145
  /* if the STATIC_task_create is called, then the pclass must be a
146
     valid pclass. */
147
 
148
  STATIC_TASK_MODEL *h = (STATIC_TASK_MODEL *)m;
149
 
1123 pj 150
  if (m->pclass != STATIC_PCLASS) return -1;
151
  if (m->level != 0 && m->level != l) return -1;
152
 
1108 pj 153
  iq_query_timespec(p, &lev->mytable)->tv_sec = h->offset.tv_sec;
154
  iq_query_timespec(p, &lev->mytable)->tv_nsec = h->offset.tv_nsec;
155
  iq_timespec_insert(p,&lev->mytable);
1085 pj 156
 
157
  return 0; /* OK, also if the task cannot be guaranteed... */
158
}
159
 
1123 pj 160
static void STATIC_public_dispatch(LEVEL l, PID p, int nostop)
1085 pj 161
{
162
}
163
 
1123 pj 164
static void STATIC_public_epilogue(LEVEL l, PID p)
1085 pj 165
{
166
}
167
 
1123 pj 168
static void STATIC_public_activate(LEVEL l, PID p)
1085 pj 169
{
170
}
171
 
1123 pj 172
static void STATIC_public_unblock(LEVEL l, PID p)
1085 pj 173
{
174
}
175
 
1123 pj 176
static void STATIC_public_block(LEVEL l, PID p)
1085 pj 177
{
178
}
179
 
1123 pj 180
static int STATIC_public_message(LEVEL l, PID p, void *m)
1085 pj 181
{
1123 pj 182
  STATIC_level_des *lev = (STATIC_level_des *)(level_table[l]);
1085 pj 183
 
1123 pj 184
  lev->currenttask = NIL;
1085 pj 185
 
1123 pj 186
  jet_update_endcycle(); /* Update the Jet data... */
187
  trc_logevent(TRC_ENDCYCLE,&exec_shadow); /* tracer stuff */
1085 pj 188
 
1123 pj 189
  return 0;
1085 pj 190
}
191
 
1123 pj 192
static void STATIC_public_end(LEVEL l, PID p)
1085 pj 193
{
194
  STATIC_level_des *lev = (STATIC_level_des *)(level_table[l]);
195
 
196
  lev->currenttask = NIL;
197
 
1108 pj 198
  iq_extract(p,&lev->mytable);
1085 pj 199
 
200
  /* we finally put the task in the ready queue */
201
  proc_table[p].status = FREE;
1108 pj 202
  iq_insertfirst(p,&freedesc);
1085 pj 203
}
204
 
205
/* Registration functions */
206
 
207
/*+ Registration function:
208
    int flags                 the init flags ... see STATIC.h +*/
1123 pj 209
LEVEL STATIC_register_level()
1085 pj 210
{
211
  LEVEL l;            /* the level that we register */
212
  STATIC_level_des *lev;  /* for readableness only */
213
 
214
  printk("STATIC_register_level\n");
215
 
216
  /* request an entry in the level_table */
1123 pj 217
  l = level_alloc_descriptor(sizeof(STATIC_level_des));
1085 pj 218
 
1123 pj 219
  lev = (STATIC_level_des *)level_table[l];
1085 pj 220
 
221
  printk("    lev=%d\n",(int)lev);
222
 
223
  /* fill the standard descriptor */
1123 pj 224
  lev->l.public_scheduler = STATIC_public_scheduler;
225
  lev->l.public_create    = STATIC_public_create;
226
  lev->l.public_end       = STATIC_public_end;
227
  lev->l.public_dispatch  = STATIC_public_dispatch;
228
  lev->l.public_epilogue  = STATIC_public_epilogue;
229
  lev->l.public_activate  = STATIC_public_activate;
230
  lev->l.public_unblock   = STATIC_public_unblock;
231
  lev->l.public_block     = STATIC_public_block;
232
  lev->l.public_message   = STATIC_public_message;
1085 pj 233
 
234
  /* fill the STATIC descriptor part */
235
 
1108 pj 236
  iq_init(&lev->mytable, &freedesc, 0);
1085 pj 237
  lev->currenttask = NIL;
238
 
239
  NULL_TIMESPEC(&lev->hp);
240
  NULL_TIMESPEC(&lev->ref);
1123 pj 241
 
242
  return l;
1085 pj 243
}
244
 
245
void STATIC_start(LEVEL l, struct timespec *h, struct timespec *o)
246
{
247
  STATIC_level_des *lev = (STATIC_level_des *)(level_table[l]);
248
  struct timespec x;
249
 
250
  kern_cli();
1123 pj 251
  kern_gettime(&x);
1085 pj 252
  lev->hp = *h;
253
 
254
  ADDTIMESPEC(&x,o,&lev->ref);
255
  STATIC_printf("(ST: ref:%d.%d x:%d.%d)\n",
256
                (int)lev->ref.tv_sec, (int)lev->ref.tv_nsec,
257
                (int)x.tv_sec, (int)x.tv_nsec);
258
 
259
  kern_event_post(&x, STATIC_hyperperiod,(void *)l);
260
 
261
  kern_sti();
262
}
263
 
264