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
 *
11
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
12
 *
13
 * http://www.sssup.it
14
 * http://retis.sssup.it
15
 * http://shark.sssup.it
16
 */
17
 
18
/*
19
 * Copyright (C) 2000 Paolo Gai
20
 *
21
 * This program is free software; you can redistribute it and/or modify
22
 * it under the terms of the GNU General Public License as published by
23
 * the Free Software Foundation; either version 2 of the License, or
24
 * (at your option) any later version.
25
 *
26
 * This program is distributed in the hope that it will be useful,
27
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
29
 * GNU General Public License for more details.
30
 *
31
 * You should have received a copy of the GNU General Public License
32
 * along with this program; if not, write to the Free Software
33
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
34
 */
35
 
36
#include "kernel/kern.h"
37
 
38
#include "fsf.h"
39
#include "fsf_server.h"
40
 
41
#include "stdlib.h"
42
#include "unistd.h"
43
#include "string.h"
44
#include "pistar.h"
45
 
46
#include "pthread.h"
47
 
48
#include "drivers/glib.h"
49
 
50
#include <tracer.h>
51
 
52
#include "FTrace_udp.h"
53
#include "FTrace_chunk.h"
54
 
55
#include <drivers/shark_keyb26.h>
56
 
57
#define TEST_PERIOD 50000
58
 
59
mutex_t mux;
60
int main_chunk;
61
 
62
TASK finish_task() {
63
 
64
  #ifdef __NEW_TRACER__
65
 group_kill(1);
66
  group_kill(2);
67
 
68
  FTrace_OSD_init_udp(1,"192.168.82.43","192.168.82.41");
69
 
70
  FTrace_send_chunk(main_chunk, 0, FTRACE_CHUNK_FLAG_FREE | FTRACE_CHUNK_FLAG_CYC);
71
 
72
  exit(0);
73
 
74
  #else
75
 
76
  exit(0);
77
 
78
  #endif
79
 
80
  return NULL;
81
 
82
}
83
 
84
void print_timer(int x, int y)
85
{
86
 
87
  long nsec,sec,min,hrs,day;
88
  struct timespec actual_timer;
89
  char tmp[100];
90
 
91
  sys_gettime(&actual_timer);
92
 
93
  nsec = actual_timer.tv_nsec;
94
  sec = actual_timer.tv_sec;
95
  min = sec / 60;
96
  sec %= 60;
97
  hrs = min / 60;
98
  min %= 60;
99
  day = hrs / 24;
100
  hrs %= 24;
101
 
102
  sprintf(tmp,"Time: %2ld d %2ld h %2ld m %2ld s %12ld ns",day,hrs,min,sec,(long)nsec);
103
  mutex_lock(&mux);
104
    grx_text(tmp,x,y,rgb16(255,255,255),0);
105
  mutex_unlock(&mux);
106
 
107
}
108
 
109
#define LOAD_VARIATION 10
110
 
111
#define MAX_V_QOS 30
112
#define MIN_V_QOS 2
113
 
114
void *test_task_variable(void *arg) {
115
 
116
  struct timespec next_time;
117
  bool was_deadline_missed = false, was_budget_overran = false;
118
 
119
  char tmp[100];
120
 
121
  long long i;
122
  int task_qos;
123
  int var_load, rd_per;
124
 
125
  TIME exectime;
126
 
127
  task_qos = 7;
128
  var_load = 5;
129
  rd_per = 0;
130
 
131
  while(1) {
132
 
133
    print_timer(307,10+30*exec_shadow);
134
    sprintf(tmp,"Test Thread V QOS = %5d PID = %3d VLOAD = %3d",task_qos,exec_shadow,var_load);
135
 
136
    mutex_lock(&mux);
137
      if (!was_deadline_missed)
138
        grx_text(tmp,307,20+30*exec_shadow,rgb16(255,255,255),0);
139
      else
140
        grx_text(tmp,307,20+30*exec_shadow,rgb16(255,0,0),0);
141
    mutex_unlock(&mux);
142
 
143
    //jet_gettable(exec_shadow, &exectime, 1);
144
    //sprintf(tmp,"Thread Exec Timer = %10d us",(int)exectime);
145
    //grx_text(tmp,307,30+30*exec_shadow,rgb16(255,255,255),0);    
146
 
147
    if (rd_per > LOAD_VARIATION) {
148
        var_load += rand()%3-1;
149
        if (var_load > 20) var_load = 20;
150
        if (var_load < 0) var_load = 0;
151
        rd_per = 0;
152
    } else {
153
        rd_per++;
154
    }
155
 
156
    for(i = 0; i < 10000*(task_qos+var_load); i++);
157
 
158
  }
159
 
160
  return NULL;
161
 
162
}
163
 
164
#define MAX_C_QOS 30
165
#define MIN_C_QOS 2
166
 
167
void *test_task_constant(void *arg) {
168
 
169
  struct timespec next_time;
170
  bool was_deadline_missed = false, was_budget_overran = false;
171
 
172
  char tmp[100];
173
 
174
  long long i;
175
  int task_qos;
176
 
177
  task_qos = 7;
178
 
179
  while(1) {
180
 
181
    print_timer(307,10+20*exec_shadow);
182
    sprintf(tmp,"Test Task C QOS = %5d PID = %3d",task_qos,exec_shadow);
183
    mutex_lock(&mux);
184
      if (!was_deadline_missed)
185
        grx_text(tmp,307,20+20*exec_shadow,rgb16(255,255,255),0);
186
      else
187
        grx_text(tmp,307,20+20*exec_shadow,rgb16(255,0,0),0);
188
    mutex_unlock(&mux);
189
 
190
    for(i = 0; i < 10000*task_qos; i++);
191
 
192
  }
193
 
194
  return NULL;
195
 
196
}
197
 
198
void draw_box(int x1, int y1, int x2, int y2)
199
{
200
 
201
  grx_rect(x1,y1,x2,y2,rgb16(160,160,160));
202
  grx_rect(x1+2,y1+2,x2-2,y2-2,rgb16(210,210,210));
203
 
204
}
205
 
206
void layout_screen()
207
{
208
 
209
  draw_box(0,0,300,500);
210
  grx_text("Application Task List",5,5,rgb16(255,255,255),0);
211
 
212
  draw_box(303,0,799,500);
213
  grx_text("Task Output",305,5,rgb16(255,255,255),0);
214
 
215
  draw_box(0,503,799,599);
216
  grx_line(140,505,140,597,rgb16(255,255,255));
217
  grx_line(140,583,797,583,rgb16(255,255,255));
218
 
219
  grx_text("Application Statistics",142,507,rgb16(255,255,255),0);
220
 
221
}
222
 
223
void program_end()
224
{
225
 
226
  grx_close();
227
 
228
}
229
 
230
void *mpeg2decoder(void *arg);
231
 
232
void add_posixstar_thread(fsf_server_id_t server)
233
{
234
 
235
  int err;
236
  pthread_t j = -1;
237
  static fsf_sched_params_t pr;
238
  NRT_TASK_MODEL nrt;
239
 
240
  pr.policy=FSF_RR;
241
  pr.params=&nrt;
242
 
243
  nrt_task_default_model(nrt);
244
  nrt_task_def_save_arrivals(nrt);
245
  nrt_task_def_group(nrt,1);
246
 
247
  err = pthread_create(&j, NULL, test_task_variable, NULL);
248
  if (err) {
249
    perror("Could not create task...");
250
    exit(1);
251
  }
252
 
253
  err=fsf_bind_local_thread_to_server(server, j, (fsf_sched_params_t *)(&pr));
254
  if (err) {
255
    grx_close();
256
    kern_printf("Could not bind task.. %d", err);
257
    exit(1);
258
 
259
  }
260
 
261
 
262
}
263
 
264
void add_edfstar_thread(fsf_server_id_t server)
265
{
266
 
267
  int err;
268
  pthread_t j = -1;
269
  HARD_TASK_MODEL ht;
270
  static fsf_sched_params_t pr;
271
 
272
 
273
  pr.policy=FSF_EDF;
274
  pr.params=&ht;
275
 
276
 
277
  hard_task_default_model(ht);
278
  hard_task_def_mit(ht,100000);
279
  hard_task_def_wcet(ht,90000);
280
  nrt_task_def_group(ht,2);
281
 
282
 
283
  err = pthread_create(&j, NULL, mpeg2decoder, NULL);
284
  if (err) {  
285
    grx_close();
286
    perror("Could not create task...");
287
    exit(1);
288
  }
289
 
290
 err=fsf_bind_local_thread_to_server(server, j,(fsf_sched_params_t *)(&pr));
291
 if (err) {
292
   grx_close();
293
   perror("Could not bind task..");
294
   exit(1);
295
 
296
 }
297
 
298
 
299
}
300
 
301
void ending_system(KEY_EVT *e) {
302
 
303
  grx_close();
304
 
305
#ifdef __NEW_TRACER__
306
 
307
  NRT_TASK_MODEL nrt;
308
 
309
  TRACER_LOGEVENT(FTrace_EVT_trace_stop,0,0);
310
 
311
  FTrace_disable();
312
 
313
  //group_kill(l->group);
314
 
315
  nrt_task_default_model(nrt);
316
 
317
  task_activate(task_create("Finish",finish_task,&nrt,NULL));
318
 
319
#else
320
 
321
  exit(0);
322
 
323
#endif
324
}
325
 
326
 
327
int main(int argc, char **argv)
328
{
329
 
330
  char ch;
331
  int err;
332
 
333
  //KEY_EVT k;
334
 
335
  PI_mutexattr_t a;
336
  KEY_EVT ev;
337
 
338
  union sigval no_sigval = {0};
339
 
340
  struct timespec period = {0,10000000};
341
  struct timespec budget = {0,1000000};
342
  struct timespec period1 = {0,10000000};
343
  struct timespec period2 = {0,10000000};
344
  struct timespec budget1 = {0,3000000};
345
  struct timespec budget2 = {0,3000000};
346
 
347
  fsf_server_id_t server1, server2;
348
  fsf_contract_parameters_t contract1, contract2;
349
  union sigval sval;
350
 
351
 
352
  ev.ascii = 'c';
353
  ev.scan  = KEY_C;
354
  ev.status = KEY_PRESSED;
355
  ev.flag = CNTR_BIT;
356
  keyb_hook(ev, ending_system, FALSE);
357
 
358
#ifdef __NEW_TRACER__
359
 
360
  main_chunk = FTrace_chunk_create(10000000, 1000, FTRACE_CHUNK_FLAG_FREE | FTRACE_CHUNK_FLAG_CYC);
361
 
362
  FTrace_actual_chunk_select(main_chunk);
363
 
364
  FTrace_enable();  
365
 
366
#endif
367
 
368
  TRACER_LOGEVENT(FTrace_EVT_trace_start,0,0);
369
 
370
  PI_mutexattr_default(a);
371
  FSF_start_service_task();
372
 
373
  mutex_init(&mux,&a);
374
 
375
  fsf_initialize_contract(&contract1);
376
  fsf_set_contract_basic_parameters(&contract1,&budget1,&period1,FSF_DEFAULT_WORKLOAD);
377
  fsf_set_contract_timing_requirements(&contract1,true,NULL,0,no_sigval,0,no_sigval);
378
  fsf_initialize_contract(&contract2);
379
  fsf_set_contract_scheduling_policy(&contract1, FSF_RR);
380
  fsf_set_contract_basic_parameters(&contract2,&budget2,&period2,FSF_DEFAULT_WORKLOAD);
381
  fsf_set_contract_timing_requirements(&contract2,true,NULL,0,no_sigval,0,no_sigval);
382
  fsf_set_contract_scheduling_policy(&contract2, FSF_EDF);
383
 
384
  err = fsf_negotiate_contract(&contract1,&server1);
385
  if (err) cprintf("(FSF ERROR %d)",err);
386
  err = fsf_negotiate_contract(&contract2,&server2);
387
  if (err) cprintf("(FSF ERROR %d)",err);
388
  //graphic card Initialization
389
  if (grx_init() < 1) {
390
    exit(1);
391
  }
392
 
393
  if (grx_open(800, 600, 16) < 0) {
394
    cprintf("GRX Err\n");
395
    exit(0);
396
  }
397
 
398
  layout_screen();
399
 
400
  ch = keyb_getch(BLOCK);
401
 
402
  while(ch != ESC) {
403
 
404
      switch (ch) {
405
 
406
            case '1':
407
                add_posixstar_thread(server1);
408
            break;
409
            case '2':
410
                add_edfstar_thread(server2);
411
            break;
412
            case '3':        
413
              fsf_set_contract_basic_parameters(&contract2,&budget,&period,FSF_DEFAULT_WORKLOAD);
414
              fsf_request_contract_renegotiation(&contract2,server2, 0, sval);                           
415
              break;
416
            case '4':
417
              ending_system(NULL);
418
                break;
419
            case '5':
420
                break;
421
          }
422
 
423
    ch = keyb_getch(BLOCK);
424
 
425
  }
426
 
427
  ending_system(NULL);
428
 
429
 return 0;
430
 
431
}