Subversion Repositories shark

Rev

Rev 1625 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1624 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
 *   Giacomo Guidi       <giacomo@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
 * Copyright (C) 2002 Paolo Gai
21
 *
22
 * This program is free software; you can redistribute it and/or modify
23
 * it under the terms of the GNU General Public License as published by
24
 * the Free Software Foundation; either version 2 of the License, or
25
 * (at your option) any later version.
26
 *
27
 * This program is distributed in the hope that it will be useful,
28
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
30
 * GNU General Public License for more details.
31
 *
32
 * You should have received a copy of the GNU General Public License
33
 * along with this program; if not, write to the Free Software
34
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
35
 *
36
 */
37
 
38
#include "kernel/kern.h"
39
 
40
#include "modules/edf.h"
41
#include "modules/cbs.h"
42
 
43
#include "pthread.h"
44
#include "modules/posix.h"
45
 
46
#include "fsf_contract.h"
47
#include "fsf_server.h"
48
 
49
#include "modules/dummy.h"
50
 
51
#include "modules/sem.h"
52
#include "modules/pi.h"
53
#include "modules/pc.h"
54
 
55
#include "modules/hartport.h"
56
#include "modules/cabs.h"
57
 
58
#include "drivers/keyb.h"
59
#include <stdlib.h>
60
 
61
// --------------------------------------------------
62
// --------------------------------------------------
63
// Init Part
64
// --------------------------------------------------
65
// --------------------------------------------------
66
 
67
/*+ sysyem tick in us +*/
68
#define TICK 0
69
 
70
/*+ RR tick in us +*/
71
#define RRTICK 10000
72
 
73
int grubstar_level;
74
 
75
TIME __kernel_register_levels__(void *arg)
76
{
77
  struct multiboot_info *mb = (struct multiboot_info *)arg;
78
 
79
  EDF_register_level(EDF_ENABLE_ALL);
80
  POSIX_register_level(RRTICK, 1, mb, 32);
81
  grubstar_level = GRUBSTAR_register_level(5, 0);
82
  FSF_register_module(grubstar_level, (int)(MAX_BANDWIDTH * 0.9));
83
  dummy_register_level();
84
 
85
  // for the keyboard...
86
  CBS_register_level(CBS_ENABLE_ALL, 0);
87
 
88
  PI_register_module();
89
  PC_register_module();
90
 
91
  SEM_register_module();
92
 
93
  PTHREAD_register_module(1, 0, 1);
94
 
95
  return TICK;
96
}
97
 
98
 
99
TASK __init__(void *arg)
100
{
101
  struct multiboot_info *mb = (struct multiboot_info *)arg;
102
 
103
  HARTPORT_init();
104
 
105
  KEYB_init(NULL);
106
 
107
  __call_main__(mb);
108
 
109
  return (void *)0;
110
 
111
}
112
 
113
// --------------------------------------------------
114
// --------------------------------------------------
115
// The Test
116
// --------------------------------------------------
117
// --------------------------------------------------
118
 
119
pthread_t jposix = -1;
120
pthread_t j1 = -1;
121
pthread_t j2 = -1;
122
pthread_t j3 = -1;
123
pthread_t j4 = -1;
124
fsf_server_id_t server1 = -1;
125
fsf_server_id_t server2 = -1;
126
fsf_server_id_t server3 = -1;
127
fsf_server_id_t server4 = -1;
128
fsf_contract_parameters_t contract;
129
 
130
pthread_mutex_t mux;
131
 
132
void *posix(void *arg)
133
{
134
  struct timespec actual,end;
135
  int actpersecond,act;
136
  int cycle;
137
 
138
  act = 0;
139
  actpersecond = 0;
140
  cycle = 0;
141
  for (;;) {
142
 
143
    cycle++;
144
    kern_gettime(&actual);
145
 
146
    if (act == 0) {
147
      TIMESPEC_ASSIGN(&end,&actual);
148
      end.tv_sec++;
149
    }
150
 
151
    if (TIMESPEC_A_LT_B(&actual,&end)) {
152
      act++;
153
    } else {
154
      actpersecond = act;
155
      act = 0;
156
    }
157
 
158
    pthread_mutex_lock(&mux);
159
      printf_xy(0,exec_shadow,GREEN,"Thread %3d Act_per_Second = %8d cycle = %8d",
160
                                    exec_shadow,actpersecond,cycle);
161
    pthread_mutex_unlock(&mux);
162
 
163
  }
164
 
165
  return NULL;
166
 
167
}
168
 
169
void *star(void *arg)
170
{
171
  struct timespec actual,end;
172
  int actpersecond,act;
173
  int cycle,rec;
174
 
175
  act = 0;
176
  actpersecond = 0;
177
  cycle = 0;
178
  rec = 0;
179
  for (;;) {
180
 
181
    cycle++;
182
    kern_gettime(&actual);
183
    rec = SERVER_get_last_reclaiming(grubstar_level,exec_shadow);
184
 
185
    if (act == 0) {
186
      TIMESPEC_ASSIGN(&end,&actual);
187
      end.tv_sec++;
188
    }
189
 
190
    if (TIMESPEC_A_LT_B(&actual,&end)) {
191
      act++;
192
    } else {
193
      actpersecond = act;
194
      act = 0;
195
    }
196
 
197
    pthread_mutex_lock(&mux);
198
      printf_xy(0,exec_shadow,WHITE,"Thread %3d Act_per_Second = %8d cycle = %8d rec = %8d",
199
                                    exec_shadow,actpersecond,cycle,rec);
200
    pthread_mutex_unlock(&mux);
201
 
202
  }
203
 
204
  return NULL;
205
 
206
}
207
 
208
void *periodic_star(void *arg)
209
{
210
  struct timespec actual,end;
211
  int actpersecond,act;
212
  int cycle,rec;
213
 
214
  act = 0;
215
  actpersecond = 0;
216
  cycle = 0;
217
  rec = 0;
218
  for (;;) {
219
 
220
    cycle++;
221
    kern_gettime(&actual);
222
    rec = SERVER_get_last_reclaiming(grubstar_level,exec_shadow);
223
 
224
    if (act == 0) {
225
      TIMESPEC_ASSIGN(&end,&actual);
226
      end.tv_sec++;
227
    }
228
 
229
    if (TIMESPEC_A_LT_B(&actual,&end)) {
230
      act++;
231
    } else {
232
      actpersecond = act;
233
      act = 0;
234
    }
235
 
236
    pthread_mutex_lock(&mux);
237
      printf_xy(0,exec_shadow,RED,"Thread %3d Act_per_Second = %8d cycle = %8d rec = %8d",
238
                                    exec_shadow,actpersecond,cycle,rec);
239
    pthread_mutex_unlock(&mux);
240
 
241
    task_endcycle();
242
 
243
  }
244
 
245
  return NULL;
246
 
247
}
248
 
249
int keyinc = 5;
250
 
251
void *edftask(void *arg)
252
{
253
  long long j;
254
  while(1) {
255
    for (j=0; j<10000*keyinc; j++);
256
    task_endcycle();
257
  }
258
 
259
  return NULL;
260
}
261
 
262
 
263
void create()
264
{
265
  HARD_TASK_MODEL mhard;
266
  int err;
267
 
268
  struct timespec period1 = {0,90000000};   //30%
269
  struct timespec period2 = {0,300000000};  //20%
270
  struct timespec period3 = {0,300000000};  //10%
271
  struct timespec budget1 = {0,30000000};
272
  struct timespec budget2 = {0,60000000};
273
  struct timespec budget3 = {0,30000000};
274
 
275
  PID t1, t2;
276
 
277
  kern_printf("(Start Create)");
278
 
279
  hard_task_default_model(mhard);
280
  hard_task_def_ctrl_jet(mhard);
281
  hard_task_def_mit(mhard,30000); //5%
282
  hard_task_def_wcet(mhard,1500);
283
  hard_task_def_arg(mhard,(void *)"X");
284
  hard_task_def_group(mhard,1);
285
  hard_task_def_periodic(mhard);
286
  hard_task_def_level(mhard,0);
287
 
288
  t1 = task_create("X", edftask, &mhard, NULL);
289
  if (t1 == NIL) {
290
    perror("Could not create task X ...");
1650 pj 291
    exit(1);
1624 giacomo 292
  }
293
 
294
  hard_task_def_mit(mhard,30000); //5%
295
  hard_task_def_wcet(mhard,1500);
296
  hard_task_def_arg(mhard,(void *)"Y");
297
  t2 = task_create("Y", edftask, &mhard, NULL);
298
  if (t2 == NIL) {
299
    perror("Could not create task Y ...");
1650 pj 300
    exit(1);
1624 giacomo 301
  }
302
 
303
  group_activate(1);
304
 
305
  fsf_initialize_contract(&contract);
306
 
307
  fsf_set_contract_basic_parameters(&contract,&budget1,&period1,NULL,NULL,FSF_DEFAULT_WORKLOAD);
308
  fsf_negotiate_contract(&contract,&server1);
309
 
310
  fsf_set_contract_basic_parameters(&contract,&budget2,&period2,NULL,NULL,FSF_DEFAULT_WORKLOAD);
311
  fsf_negotiate_contract(&contract,&server2);
312
 
313
  fsf_set_contract_basic_parameters(&contract,&budget3,&period3,NULL,NULL,FSF_DEFAULT_WORKLOAD);  
314
  fsf_negotiate_contract(&contract,&server3);
315
 
316
  fsf_set_contract_basic_parameters(&contract,&budget2,&period2,NULL,NULL,FSF_DEFAULT_WORKLOAD);
317
  fsf_set_local_scheduler_parameter(&contract, FSF_SCHEDULER_EDF);
318
  fsf_negotiate_contract(&contract,&server4);
319
 
320
  err = pthread_create(&jposix, NULL, posix, NULL);
321
  if (err) kern_printf("(Error creating posix task)");
322
 
323
  kern_printf("(End Create)");
324
 
325
}
326
 
327
int main(int argc, char **argv)
328
{
329
 
330
  int err;
331
  HARD_TASK_MODEL ht;
332
  NRT_TASK_MODEL nrt;
333
  struct timespec endtimer;
334
 
335
  pthread_mutex_init(&mux,NULL);
336
 
337
  srand(kern_gettime(NULL));
338
  create();
339
 
340
  nrt_task_default_model(nrt);
341
 
342
  kern_gettime(&endtimer);
343
  endtimer.tv_sec += 20;
1650 pj 344
  kern_event_post(&endtimer, (void (*)(void *))(exit), NULL);
1624 giacomo 345
 
346
  err = fsf_create_thread(server1,&j1,NULL,star,NULL,&nrt);
347
  kern_printf("(%d)",err);
348
 
349
  err = fsf_create_thread(server2,&j2,NULL,star,NULL,&nrt);
350
  kern_printf("(%d)",err);
351
 
352
  err = fsf_create_thread(server3,&j3,NULL,star,NULL,&nrt);
353
  kern_printf("(%d)",err);
354
 
355
  hard_task_default_model(ht);
356
  hard_task_def_mit(ht,200000);
357
  hard_task_def_wcet(ht,50000);
358
  err = fsf_create_thread(server4,&j4,NULL,periodic_star,NULL,&ht);
359
  kern_printf("(%d)",err);
360
 
361
/*  hard_task_default_model(ht);
362
  hard_task_def_mit(ht,159000);
363
  hard_task_def_wcet(ht,50000);
364
  err = fsf_create_thread(server4,&j4,NULL,periodic_star,NULL,&ht);
365
  kern_printf("(%d)",err);
366
*/
367
  err = fsf_create_thread(server1,&j1,NULL,star,NULL,&nrt);
368
  kern_printf("(%d)",err);
369
 
370
  err = fsf_create_thread(server2,&j2,NULL,star,NULL,&nrt);
371
  kern_printf("(%d)",err);
372
 
373
  err = fsf_create_thread(server3,&j3,NULL,star,NULL,&nrt);
374
  kern_printf("(%d)",err);
375
 
376
  return 0;
377
 
378
}
379