Subversion Repositories shark

Rev

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

Rev Author Line No. Line
1182 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
 *
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_contract.h"
39
 
40
#include "stdlib.h"
41
#include "unistd.h"
42
#include "string.h"
43
 
44
#include "pthread.h"
45
 
46
#include "drivers/keyb.h"
47
#include "drivers/glib.h"
48
 
49
#define TEST_PERIOD 50000
50
 
51
mutex_t mux;
52
 
53
void program_key_end(KEY_EVT *k)
54
{
55
 
56
  sys_end();
57
 
58
}
59
 
60
void print_timer(int x, int y)
61
{
62
 
63
  long nsec,sec,min,hrs,day;
64
  struct timespec actual_timer;
65
  char tmp[100];
66
 
67
  sys_gettime(&actual_timer);
68
 
69
  nsec = actual_timer.tv_nsec;
70
  sec = actual_timer.tv_sec;
71
  min = sec / 60;
72
  sec %= 60;
73
  hrs = min / 60;
74
  min %= 60;
75
  day = hrs / 24;
76
  hrs %= 24;
77
 
78
  sprintf(tmp,"Time: %2ld d %2ld h %2ld m %2ld s %12ld ns",day,hrs,min,sec,(long)nsec);
79
  //mutex_lock(&mux);
80
    grx_text(tmp,x,y,rgb16(255,255,255),0);
81
  //mutex_unlock(&mux);
82
 
83
}
84
 
85
#define LOAD_VARIATION 10
86
 
87
#define MAX_V_QOS 30
88
#define MIN_V_QOS 2
89
 
90
void *test_task_variable(void *arg) {
91
 
92
  struct timespec next_time;
93
  bool was_deadline_missed = false, was_budget_overran = false;
94
 
95
  char tmp[100];
96
 
97
  long long i;
98
  int task_qos;
99
  int var_load, rd_per;
100
 
101
  TIME exectime;
102
 
103
  task_qos = 7;
104
  var_load = 5;
105
  rd_per = 0;
106
 
107
  while(1) {
108
 
109
    print_timer(307,10+30*exec_shadow);
110
    sprintf(tmp,"Test Thread V QOS = %5d PID = %3d VLOAD = %3d",task_qos,exec_shadow,var_load);
111
 
112
    //mutex_lock(&mux);
113
      if (!was_deadline_missed)
114
        grx_text(tmp,307,20+30*exec_shadow,rgb16(255,255,255),0);
115
      else
116
        grx_text(tmp,307,20+30*exec_shadow,rgb16(255,0,0),0);
117
    //mutex_unlock(&mux);
118
 
119
    jet_gettable(exec_shadow, &exectime, 1);
120
    sprintf(tmp,"Thread Exec Timer = %10d us",(int)exectime);
121
    grx_text(tmp,307,30+30*exec_shadow,rgb16(255,255,255),0);    
122
 
123
    if (rd_per > LOAD_VARIATION) {
124
        var_load += rand()%3-1;
125
        if (var_load > 20) var_load = 20;
126
        if (var_load < 0) var_load = 0;
127
        rd_per = 0;
128
    } else {
129
        rd_per++;
130
    }
131
 
132
    for(i = 0; i < 10000*(task_qos+var_load); i++);
133
 
134
  }
135
 
136
  return NULL;
137
 
138
}
139
 
140
#define MAX_C_QOS 30
141
#define MIN_C_QOS 2
142
 
143
void *test_task_constant(void *arg) {
144
 
145
  struct timespec next_time;
146
  bool was_deadline_missed = false, was_budget_overran = false;
147
 
148
  char tmp[100];
149
 
150
  long long i;
151
  int task_qos;
152
 
153
  task_qos = 7;
154
 
155
  while(1) {
156
 
157
    print_timer(307,10+20*exec_shadow);
158
    sprintf(tmp,"Test Task C QOS = %5d PID = %3d",task_qos,exec_shadow);
159
    //mutex_lock(&mux);
160
      if (!was_deadline_missed)
161
        grx_text(tmp,307,20+20*exec_shadow,rgb16(255,255,255),0);
162
      else
163
        grx_text(tmp,307,20+20*exec_shadow,rgb16(255,0,0),0);
164
    //mutex_unlock(&mux);
165
 
166
    for(i = 0; i < 10000*task_qos; i++);
167
 
168
  }
169
 
170
  return NULL;
171
 
172
}
173
 
174
void draw_box(int x1, int y1, int x2, int y2)
175
{
176
 
177
  grx_rect(x1,y1,x2,y2,rgb16(160,160,160));
178
  grx_rect(x1+2,y1+2,x2-2,y2-2,rgb16(210,210,210));
179
 
180
}
181
 
182
void layout_screen()
183
{
184
 
185
  draw_box(0,0,300,500);
186
  grx_text("Application Task List",5,5,rgb16(255,255,255),0);
187
 
188
  draw_box(303,0,799,500);
189
  grx_text("Task Output",305,5,rgb16(255,255,255),0);
190
 
191
  draw_box(0,503,799,599);
192
  grx_line(140,505,140,597,rgb16(255,255,255));
193
  grx_line(140,583,797,583,rgb16(255,255,255));
194
 
195
  grx_text("Application Statistics",142,507,rgb16(255,255,255),0);
196
 
197
}
198
 
199
void program_end()
200
{
201
 
202
  grx_close();
203
 
204
}
205
 
206
void *mpeg2decoder(void *arg);
207
 
208
void add_posixstar_thread(fsf_server_id_t server)
209
{
210
 
211
  int err;
212
  pthread_t j = -1;
213
  NRT_TASK_MODEL nrt;
214
 
215
  nrt_task_default_model(nrt);
216
  nrt_task_def_save_arrivals(nrt);
217
 
218
  err = pthread_create(&j, NULL, test_task_variable, NULL);
219
  if (err) {
220
    perror("Could not create task...");
221
    sys_end();
222
  }
223
 
224
  fsf_bind_thread_to_server(server, j, &nrt);
225
 
226
}
227
 
228
void add_edfstar_thread(fsf_server_id_t server)
229
{
230
 
231
  int err;
232
  pthread_t j = -1;
233
  HARD_TASK_MODEL ht;
234
 
235
  hard_task_default_model(ht);
236
  hard_task_def_mit(ht,100000);
237
  hard_task_def_wcet(ht,90000);
238
 
239
  err = pthread_create(&j, NULL, mpeg2decoder, NULL);
240
  if (err) {
241
    perror("Could not create task...");
242
    sys_end();
243
  }
244
 
1183 giacomo 245
  fsf_bind_thread_to_server(server, j, &ht);
1182 giacomo 246
 
247
}
248
 
249
int main(int argc, char **argv)
250
{
251
 
252
  char ch;
253
  int err;
254
 
255
  KEY_EVT k;
256
 
257
  PI_mutexattr_t a;
258
 
259
  struct timespec period1 = {0,10000000};
260
  struct timespec period2 = {0,10000000};
1183 giacomo 261
  struct timespec budget1 = {0,4000000};
262
  struct timespec budget2 = {0,4000000};
1182 giacomo 263
 
264
  fsf_server_id_t server1, server2;
265
  fsf_contract_parameters_t contract1, contract2;
266
 
267
  sys_atrunlevel(program_end, NULL, RUNLEVEL_BEFORE_EXIT);
268
 
269
  k.flag = ALTL_BIT;
270
  k.scan = KEY_C;
271
  k.ascii = 'c';
272
  keyb_hook(k,program_key_end);
273
 
274
  srand(sys_gettime(NULL));
275
 
276
  // graphic card Initialization
277
  if (grx_init() < 1) {
278
     sys_end();
279
  }
280
 
281
  if (grx_open(800, 600, 16) < 0) {
282
    cprintf("GRX Err\n");
283
    sys_end();
284
  }
285
 
286
  layout_screen();
287
 
288
  PI_mutexattr_default(a);
289
 
290
  mutex_init(&mux,&a);
291
 
292
  fsf_initialize_contract(&contract1);
293
  fsf_set_contract_basic_parameters(&contract1,&budget1,&period1,NULL,NULL,FSF_DEFAULT_WORKLOAD);
294
  fsf_initialize_contract(&contract2);
295
  fsf_set_contract_basic_parameters(&contract2,&budget2,&period2,NULL,NULL,FSF_DEFAULT_WORKLOAD);
296
  fsf_set_local_scheduler_parameter(&contract2, FSF_SCHEDULER_EDF);
297
 
298
  err = fsf_negotiate_contract(&contract1,&server1);
299
  if (err) cprintf("(FSF ERROR %d)",err);
300
  err = fsf_negotiate_contract(&contract2,&server2);
301
  if (err) cprintf("(FSF ERROR %d)",err);
302
 
303
  ch = keyb_getch(BLOCK);
304
 
305
  while(ch != ESC) {
306
 
307
          switch (ch) {
308
 
309
            case '1':
310
                add_posixstar_thread(server1);
311
                break;
312
            case '2':
313
                add_edfstar_thread(server2);
314
                break;
315
            case '3':
316
                break;
317
            case '4':
318
                break;
319
            case '5':
320
                break;
321
          }
322
 
323
    ch = keyb_getch(BLOCK);
324
 
325
  }
326
 
327
  sys_end();
328
 
329
  return 0;
330
 
331
}