Subversion Repositories shark

Rev

Details | 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
TIME __kernel_register_levels__(void *arg)
74
{
75
  struct multiboot_info *mb = (struct multiboot_info *)arg;
76
  int grubstar_level;
77
 
78
  EDF_register_level(EDF_ENABLE_ALL);
79
  POSIX_register_level(RRTICK, 1, mb, 32);
80
  grubstar_level = GRUBSTAR_register_level(4, 0);
81
  FSF_register_module(grubstar_level, (int)(MAX_BANDWIDTH * 0.9));
82
  dummy_register_level();
83
 
84
  // for the keyboard...
85
  CBS_register_level(CBS_ENABLE_ALL, 0);
86
 
87
  PI_register_module();
88
  PC_register_module();
89
 
90
  SEM_register_module();
91
 
92
  PTHREAD_register_module(1, 0, 1);
93
 
94
  return TICK;
95
}
96
 
97
 
98
TASK __init__(void *arg)
99
{
100
  struct multiboot_info *mb = (struct multiboot_info *)arg;
101
 
102
  HARTPORT_init();
103
 
104
  KEYB_init(NULL);
105
 
106
  __call_main__(mb);
107
 
108
  return (void *)0;
109
 
110
}
111
 
112
// --------------------------------------------------
113
// --------------------------------------------------
114
// The Test
115
// --------------------------------------------------
116
// --------------------------------------------------
117
 
118
pthread_t j1 = -1;
119
pthread_t j2 = -1;
120
pthread_t j3 = -1;
121
pthread_t j4 = -1;
122
fsf_server_id_t server1 = -1;
123
fsf_server_id_t server2 = -1;
124
fsf_server_id_t server3 = -1;
125
fsf_server_id_t server4 = -1;
126
fsf_contract_parameters_t contract1, contract2;
127
 
128
pthread_mutex_t mux;
129
 
130
#define TASK_PERIOD 1000000
131
 
132
void *periodic_star(void *arg)
133
{
134
  struct timespec actual,end,next_time;
135
  int actpersecond,act,cycle;
136
  int mean,nmean;
137
  bool was_deadline_missed, was_budget_overran;
138
 
139
  act = 0;
140
  actpersecond = 0;
141
  mean = 0;
142
  nmean = 0;
143
  cycle = 0;
144
  for (;;) {
145
 
146
    kern_gettime(&actual);
147
    cycle++;
148
 
149
    if (act == 0) {
150
      TIMESPEC_ASSIGN(&end,&actual);
151
      end.tv_sec++;
152
    }
153
 
154
    if (TIMESPEC_A_LT_B(&actual,&end)) {
155
      act++;
156
    } else {
157
      actpersecond = act;
158
      act = 0;
159
      mean = (mean * nmean + actpersecond) / (nmean+1);
160
      nmean++;
161
    }
162
 
163
    //pthread_mutex_lock(&mux);
164
      printf_xy(0,exec_shadow,WHITE,"Thread %3d Act_per_Second = %8d Mean = %8d Cycle = %8d",
165
                                        exec_shadow,actpersecond,mean,cycle);
166
    //pthread_mutex_unlock(&mux);
167
 
168
    kern_gettime(&next_time);
169
    ADDUSEC2TIMESPEC(TASK_PERIOD, &next_time);
170
    fsf_schedule_next_timed_job(NULL, NULL, NULL, &was_deadline_missed, &was_budget_overran);
171
 
172
  }
173
 
174
  return NULL;
175
 
176
}
177
 
178
void *star(void *arg)
179
{
180
  struct timespec actual,end;
181
  int actpersecond,act;
182
  int mean,nmean,cycle;
183
 
184
  act = 0;
185
  actpersecond = 0;
186
  mean = 0;
187
  nmean = 0;
188
  cycle = 0;
189
  for (;;) {
190
 
191
    cycle++;
192
    kern_gettime(&actual);
193
 
194
    if (act == 0) {
195
      TIMESPEC_ASSIGN(&end,&actual);
196
      end.tv_sec++;
197
    }
198
 
199
    if (TIMESPEC_A_LT_B(&actual,&end)) {
200
      act++;
201
    } else {
202
      actpersecond = act;
203
      act = 0;
204
      mean = (mean * nmean + actpersecond) / (nmean+1);
205
      nmean++;
206
    }
207
 
208
    //pthread_mutex_lock(&mux);
209
      printf_xy(0,exec_shadow,WHITE,"Thread %3d Act_per_Second = %8d Mean = %8d Cycle = %8d",
210
                                    exec_shadow,actpersecond,mean,cycle);
211
    //pthread_mutex_unlock(&mux);
212
 
213
  }
214
 
215
  return NULL;
216
 
217
}
218
 
219
void *edftask(void *arg)
220
{
221
  int i,j;
222
  while(1) {
223
  for (i=0;i<5; i++) {
224
    for (j=0; j<10; j++);
225
    //cputc('#');
226
    //cputs((char *)(arg));
227
  }
228
 
229
  task_endcycle();
230
  }
231
 
232
  return NULL;
233
}
234
 
235
 
236
void create()
237
{
238
  HARD_TASK_MODEL mhard;
239
 
240
  struct timespec period1 = {0,100000000};
241
  struct timespec period2 = {0,100000000};
242
  struct timespec budget1 = {0,30000000};
243
  struct timespec budget2 = {0,30000000};
244
 
245
  PID t1, t2;
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
    sys_end();
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
    sys_end();
270
  }
271
 
272
  group_activate(1);
273
 
274
  fsf_initialize_contract(&contract1);
275
  fsf_set_contract_basic_parameters(&contract1,&budget1,&period1,NULL,NULL,FSF_DEFAULT_WORKLOAD);
276
  fsf_initialize_contract(&contract2);
277
  fsf_set_contract_basic_parameters(&contract2,&budget2,&period2,NULL,NULL,FSF_DEFAULT_WORKLOAD);
278
 
279
  kern_printf("(End Create)");
280
 
281
}
282
 
283
int main(int argc, char **argv)
284
{
285
 
286
  NRT_TASK_MODEL nrt;
287
  char ch = 0;
288
  int err;
289
 
290
  pthread_mutex_init(&mux,NULL);
291
 
292
  create();
293
 
294
  nrt_task_default_model(nrt);
295
  nrt_task_def_save_arrivals(nrt);
296
  nrt_task_def_ctrl_jet(nrt);
297
 
298
  do {
299
    ch = keyb_getch(BLOCK);
300
 
301
    switch(ch) {
302
      case '1':
303
        err = fsf_create_thread(server1,&j1,NULL,star,NULL,&nrt);
304
        kern_printf("(%d)",err);
305
        break;
306
      case '2':
307
        err = fsf_create_thread(server2,&j2,NULL,star,NULL,&nrt);
308
        kern_printf("(%d)",err);
309
        break;
310
      case '3':
311
        err = fsf_create_thread(server1,&j3,NULL,star,NULL,&nrt);
312
        kern_printf("(%d)",err);
313
        break;
314
      case '4':
315
        err = fsf_create_thread(server2,&j4,NULL,star,NULL,&nrt);
316
        kern_printf("(%d)",err);
317
        break;
318
      case 'q':
319
        err = fsf_negotiate_contract(&contract1,&server1);
320
        cprintf("(%d)",err);
321
        break;
322
      case 'w':
323
        err = fsf_negotiate_contract(&contract2,&server2);
324
        kern_printf("(%d)",err);
325
        break;
326
      case 'e':
327
        err = fsf_negotiate_contract(&contract1,&server3);
328
        kern_printf("(%d)",err);
329
        break;
330
      case 'r':
331
        err = fsf_cancel_contract(&server1);
332
        kern_printf("(%d)",err);
333
        break;
334
      case 't':
335
        err = fsf_cancel_contract(&server2);
336
        kern_printf("(%d)",err);
337
        break;
338
      case 'y':
339
        err = fsf_cancel_contract(&server3);
340
        kern_printf("(%d)",err);
341
        break;
342
 
343
    }
344
 
345
  } while(ch != ESC);
346
 
347
  sys_end();
348
 
349
  return 0;
350
 
351
}
352