Subversion Repositories shark

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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