Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1673 tullio 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 "edf/edf/edf.h"
41
#include "cbs/cbs/cbs.h"
42
 
43
#include "pthread.h"
44
#include "posix/posix/posix.h"
45
 
46
#include "fsf.h"
47
#include "fsf_server.h"
48
#include "dummy/dummy/dummy.h"
49
 
50
#include "sem/sem/sem.h"
51
#include "pi/pi/pi.h"
52
#include "pc/pc/pc.h"
53
 
54
#include "hartport/hartport/hartport.h"
55
#include "cabs/cabs/cabs.h"
56
 
57
#include "drivers/keyb.h"
58
#include <stdlib.h>
59
 
60
// --------------------------------------------------
61
// --------------------------------------------------
62
// Init Part
63
// --------------------------------------------------
64
// --------------------------------------------------
65
 
66
/*+ sysyem tick in us +*/
67
#define TICK 0
68
 
69
/*+ RR tick in us +*/
70
#define RRTICK 10000
71
 
72
int grubstar_level;
73
int posix_level;
74
 
75
 
76
TIME __kernel_register_levels__(void *arg)
77
{
78
  struct multiboot_info *mb = (struct multiboot_info *)arg;
79
 
80
  EDF_register_level(EDF_ENABLE_ALL);
81
  posix_level=POSIX_register_level(RRTICK, 1, mb, 32);
82
  grubstar_level = GRUBSTAR_register_level(5, 0);
83
  FSF_register_module(posix_level,grubstar_level, (int)(MAX_BANDWIDTH * 0.9));
84
  dummy_register_level();
85
 
86
  // for the keyboard...
87
  CBS_register_level(CBS_ENABLE_ALL, 0);
88
 
89
  PI_register_module();
90
  PC_register_module();
91
 
92
  SEM_register_module();
93
 
94
  PTHREAD_register_module(1, 0, 1);
95
 
96
  return TICK;
97
 
98
}
99
 
100
 
101
TASK __init__(void *arg)
102
{
103
  struct multiboot_info *mb = (struct multiboot_info *)arg;
104
 
105
  HARTPORT_init();
106
 
107
  KEYB_init(NULL);
108
 
109
  __call_main__(mb);
110
 
111
  return (void *)0;
112
 
113
}
114
 
115
// --------------------------------------------------
116
// --------------------------------------------------
117
// The Test
118
// --------------------------------------------------
119
// --------------------------------------------------
120
 
121
pthread_t j1 = -1;
122
pthread_t j2 = -1;
123
pthread_t j3 = -1;
124
pthread_t j4 = -1;
125
fsf_server_id_t server1 = -1;
126
fsf_server_id_t server2 = -1;
127
fsf_server_id_t server3 = -1;
128
fsf_server_id_t server4 = -1;
129
fsf_contract_parameters_t contract1, contract2;
130
 
131
 
132
#define TASK_PERIOD 1000000
133
 
134
void *periodic_star(void *arg)
135
{
136
  struct timespec actual,end,next_time;
137
  int actpersecond,act,cycle;
138
  int mean,nmean;
139
  bool was_deadline_missed, was_budget_overran;
140
 
141
  act = 0;
142
  actpersecond = 0;
143
  mean = 0;
144
  nmean = 0;
145
  cycle = 0;
146
  for (;;) {
147
 
148
    kern_gettime(&actual);
149
    cycle++;
150
 
151
    if (act == 0) {
152
      TIMESPEC_ASSIGN(&end,&actual);
153
      end.tv_sec++;
154
    }
155
 
156
    if (TIMESPEC_A_LT_B(&actual,&end)) {
157
      act++;
158
    } else {
159
      actpersecond = act;
160
      act = 0;
161
      mean = (mean * nmean + actpersecond) / (nmean+1);
162
      nmean++;
163
    }
164
 
165
      printf_xy(0,exec_shadow,WHITE,"Thread %3d Act_per_Second = %8d Mean = %8d Cycle = %8d",
166
                                        exec_shadow,actpersecond,mean,cycle);
167
    kern_gettime(&next_time);
168
    ADDUSEC2TIMESPEC(TASK_PERIOD, &next_time);
169
    fsf_schedule_timed_job(&next_time, NULL, NULL, &was_deadline_missed, &was_budget_overran);
170
 
171
  }
172
 
173
  return NULL;
174
 
175
}
176
 
177
void *star(void *arg)
178
{
179
  struct timespec actual,end;
180
  int actpersecond,act;
181
  int mean,nmean,cycle;
182
 
183
  act = 0;
184
  actpersecond = 0;
185
  mean = 0;
186
  nmean = 0;
187
  cycle = 0;
188
  for (;;) {
189
 
190
    cycle++;
191
    kern_gettime(&actual);
192
 
193
    if (act == 0) {
194
      TIMESPEC_ASSIGN(&end,&actual);
195
      end.tv_sec++;
196
    }
197
 
198
    if (TIMESPEC_A_LT_B(&actual,&end)) {
199
      act++;
200
    } else {
201
      actpersecond = act;
202
      act = 0;
203
      mean = (mean * nmean + actpersecond) / (nmean+1);
204
      nmean++;
205
    }
206
 
207
      printf_xy(0,exec_shadow,WHITE,"Thread %3d Act_per_Second = %8d Mean = %8d Cycle = %8d",
208
                                    exec_shadow,actpersecond,mean,cycle);
209
 
210
  }
211
 
212
  return NULL;
213
 
214
}
215
 
216
void *edftask(void *arg)
217
{
218
  int i,j;
219
  while(1) {
220
  for (i=0;i<5; i++) {
221
    for (j=0; j<10; j++);
222
    //cputc('#');
223
    //cputs((char *)(arg));
224
  }
225
 
226
  task_endcycle();
227
  }
228
 
229
  return NULL;
230
}
231
 
232
 
233
void create()
234
{
235
  HARD_TASK_MODEL mhard;
236
 
237
  struct timespec period1 = {0,100000000};
238
  struct timespec period2 = {0,100000000};
239
  struct timespec budget1 = {0,30000000};
240
  struct timespec budget2 = {0,30000000};
241
 
242
  PID t1, t2;
243
  int err;
244
 
245
  FSF_start_service_task();
246
 
247
  kern_printf("(Start Create)");
248
 
249
  hard_task_default_model(mhard);
250
  hard_task_def_ctrl_jet(mhard);
251
  hard_task_def_mit(mhard,32000);
252
  hard_task_def_wcet(mhard,3000);
253
  hard_task_def_arg(mhard,(void *)"X");
254
  hard_task_def_group(mhard,1);
255
  hard_task_def_periodic(mhard);
256
 
257
  //t1 = task_create("X", edftask, &mhard, NULL);
258
  //if (t1 == NIL) {
259
  //  perror("Could not create task X ...");
260
  //  exit(1);
261
  //}
262
 
263
  hard_task_def_mit(mhard,32000);
264
  hard_task_def_wcet(mhard,3000);
265
  hard_task_def_arg(mhard,(void *)"Y");
266
  //t2 = task_create("Y", edftask, &mhard, NULL);
267
  //if (t2 == NIL) {
268
  //  perror("Could not create task Y ...");
269
  //  exit(1);
270
  //}
271
 
272
  //group_activate(1);
273
 
274
  err = pthread_create(&j1, NULL, star, (void *)"A");
275
  if (err) {
276
    perror("Could not create task A ...");
277
    exit(1);
278
  }
279
 
280
  err = pthread_create(&j2, NULL, periodic_star, (void *)"B");
281
  if (err) {
282
    perror("Could not create task B ...");
283
    exit(1);
284
  }
285
 
286
  err = pthread_create(&j3, NULL, star, (void *)"C");
287
  if (err) {
288
    perror("Could not create task C ...");
289
    exit(1);
290
  }
291
 
292
  err = pthread_create(&j4, NULL, periodic_star, (void *)"D");
293
  if (err) {
294
    perror("Could not create task D ...");
295
    exit(1);
296
  }
297
 
298
  fsf_initialize_contract(&contract1);
299
  fsf_set_contract_basic_parameters(&contract1,&budget1,&period1,FSF_DEFAULT_WORKLOAD);
300
  fsf_initialize_contract(&contract2);
301
  fsf_set_contract_basic_parameters(&contract2,&budget2,&period2,FSF_DEFAULT_WORKLOAD);
302
 
303
  kern_printf("(End Create)");
304
 
305
}
306
 
307
int main(int argc, char **argv)
308
{
309
 
310
  char ch = 0;
311
  int err;
312
 
313
  create();
314
 
315
  do {
316
    ch = keyb_getch(BLOCK);
317
 
318
    switch(ch) {
319
      case '1':
320
        err = fsf_bind_thread_to_server(server1,j1);
321
        kern_printf("(%d)",err);
322
        break;
323
      case '2':
324
        err = fsf_bind_thread_to_server(server2,j2);
325
        kern_printf("(%d)",err);
326
        break;
327
      case '3':
328
        err = fsf_bind_thread_to_server(server1,j3);
329
        kern_printf("(%d)",err);
330
        break;
331
      case '4':
332
        err = fsf_bind_thread_to_server(server2,j4);
333
        kern_printf("(%d)",err);
334
        break;
335
      case '5':
336
        err = fsf_unbind_thread_from_server(j1);
337
        kern_printf("(%d)",err);
338
        break;
339
      case '6':
340
        err = fsf_unbind_thread_from_server(j2);
341
        kern_printf("(%d)",err);
342
        break;
343
      case '7':
344
        err = fsf_unbind_thread_from_server(j3);
345
        kern_printf("(%d)",err);
346
        break;
347
      case '8':
348
        err = fsf_unbind_thread_from_server(j4);
349
        kern_printf("(%d)",err);
350
        break;
351
      case 'q':
352
        err = fsf_negotiate_contract(&contract1,&server1);
353
        cprintf("(%d)",err);
354
        break;
355
      case 'w':
356
        err = fsf_negotiate_contract(&contract2,&server2);
357
        kern_printf("(%d)",err);
358
        break;
359
      case 'e':
360
        err = fsf_negotiate_contract(&contract1,&server3);
361
        kern_printf("(%d)",err);
362
        break;
363
      case 'r':
364
        err = fsf_cancel_contract(server1);
365
        kern_printf("(%d)",err);
366
        break;
367
      case 't':
368
        err = fsf_cancel_contract(server2);
369
        kern_printf("(%d)",err);
370
        break;
371
      case 'y':
372
        err = fsf_cancel_contract(server3);
373
        kern_printf("(%d)",err);
374
        break;
375
 
376
    }
377
 
378
  } while(ch != ESC);
379
 
380
  exit(1);
381
 
382
  return 0;
383
 
384
}
385