Subversion Repositories shark

Rev

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

Rev Author Line No. Line
1191 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);
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
 
1192 giacomo 119
pthread_t jposix = -1;
1191 giacomo 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
 
1192 giacomo 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
 
1191 giacomo 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);
1195 giacomo 183
    rec = SERVER_get_last_reclaiming(grubstar_level,exec_shadow);
1191 giacomo 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
 
1192 giacomo 197
    pthread_mutex_lock(&mux);
1191 giacomo 198
      printf_xy(0,exec_shadow,WHITE,"Thread %3d Act_per_Second = %8d cycle = %8d rec = %8d",
199
                                    exec_shadow,actpersecond,cycle,rec);
1192 giacomo 200
    pthread_mutex_unlock(&mux);
1191 giacomo 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);
1195 giacomo 222
    rec = SERVER_get_last_reclaiming(grubstar_level,exec_shadow);
1191 giacomo 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
 
1192 giacomo 236
    pthread_mutex_lock(&mux);
1191 giacomo 237
      printf_xy(0,exec_shadow,RED,"Thread %3d Act_per_Second = %8d cycle = %8d rec = %8d",
238
                                    exec_shadow,actpersecond,cycle,rec);
1192 giacomo 239
    pthread_mutex_unlock(&mux);
1191 giacomo 240
 
241
    task_endcycle();
242
 
243
  }
244
 
245
  return NULL;
246
 
247
}
248
 
1192 giacomo 249
int keyinc = 5;
250
 
1191 giacomo 251
void *edftask(void *arg)
252
{
1192 giacomo 253
  long long j;
1191 giacomo 254
  while(1) {
1192 giacomo 255
    for (j=0; j<10000*keyinc; j++);
256
    task_endcycle();
1191 giacomo 257
  }
258
 
259
  return NULL;
260
}
261
 
262
 
263
void create()
264
{
265
  HARD_TASK_MODEL mhard;
1192 giacomo 266
  int err;
1191 giacomo 267
 
1192 giacomo 268
  struct timespec period1 = {0,90000000};   //30%
269
  struct timespec period2 = {0,300000000};  //20%
1191 giacomo 270
  struct timespec period3 = {0,300000000};  //10%
271
  struct timespec budget1 = {0,30000000};
1192 giacomo 272
  struct timespec budget2 = {0,60000000};
1191 giacomo 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);
1192 giacomo 281
  hard_task_def_mit(mhard,30000); //5%
282
  hard_task_def_wcet(mhard,1500);
1191 giacomo 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 ...");
291
    sys_end();
292
  }
293
 
1192 giacomo 294
  hard_task_def_mit(mhard,30000); //5%
295
  hard_task_def_wcet(mhard,1500);
1191 giacomo 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 ...");
300
    sys_end();
301
  }
302
 
1192 giacomo 303
  group_activate(1);
1191 giacomo 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
 
1192 giacomo 316
  fsf_set_contract_basic_parameters(&contract,&budget2,&period2,NULL,NULL,FSF_DEFAULT_WORKLOAD);
1191 giacomo 317
  fsf_set_local_scheduler_parameter(&contract, FSF_SCHEDULER_EDF);
318
  fsf_negotiate_contract(&contract,&server4);
319
 
1192 giacomo 320
  err = pthread_create(&jposix, NULL, posix, NULL);
321
  if (err) kern_printf("(Error creating posix task)");
322
 
1191 giacomo 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;
1210 giacomo 332
  NRT_TASK_MODEL nrt;
1192 giacomo 333
  struct timespec endtimer;
1191 giacomo 334
 
335
  pthread_mutex_init(&mux,NULL);
336
 
1192 giacomo 337
  srand(kern_gettime(NULL));
1191 giacomo 338
  create();
1210 giacomo 339
 
340
  nrt_task_default_model(nrt);
1192 giacomo 341
 
342
  kern_gettime(&endtimer);
343
  endtimer.tv_sec += 20;
344
  kern_event_post(&endtimer, (void (*)(void *))(sys_end), NULL);
1191 giacomo 345
 
1210 giacomo 346
  err = fsf_create_thread(server1,&j1,NULL,star,NULL,&nrt);
1192 giacomo 347
  kern_printf("(%d)",err);
348
 
1210 giacomo 349
  err = fsf_create_thread(server2,&j2,NULL,star,NULL,&nrt);
1192 giacomo 350
  kern_printf("(%d)",err);
351
 
1210 giacomo 352
  err = fsf_create_thread(server3,&j3,NULL,star,NULL,&nrt);
1192 giacomo 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);
1191 giacomo 360
 
1192 giacomo 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
*/
1210 giacomo 367
  err = fsf_create_thread(server1,&j1,NULL,star,NULL,&nrt);
1192 giacomo 368
  kern_printf("(%d)",err);
369
 
1210 giacomo 370
  err = fsf_create_thread(server2,&j2,NULL,star,NULL,&nrt);
1192 giacomo 371
  kern_printf("(%d)",err);
372
 
1210 giacomo 373
  err = fsf_create_thread(server3,&j3,NULL,star,NULL,&nrt);
1192 giacomo 374
  kern_printf("(%d)",err);
1191 giacomo 375
 
376
  return 0;
377
 
378
}
379