Subversion Repositories shark

Rev

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