Subversion Repositories shark

Rev

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
  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
  pthread_t j = -1;
200
 
1188 giacomo 201
  fsf_create_thread(server, &j, NULL, test_task_variable, NULL, NULL);
1182 giacomo 202
 
203
}
204
 
205
void add_edfstar_thread(fsf_server_id_t server)
206
{
207
 
208
  pthread_t j = -1;
209
  HARD_TASK_MODEL ht;
210
 
211
  hard_task_default_model(ht);
212
  hard_task_def_mit(ht,100000);
213
  hard_task_def_wcet(ht,90000);
214
 
1188 giacomo 215
  fsf_create_thread(server, &j, NULL, mpeg2decoder, NULL, &ht);
1182 giacomo 216
 
217
}
218
 
219
int main(int argc, char **argv)
220
{
221
 
222
  char ch;
223
  int err;
224
 
225
  KEY_EVT k;
226
 
227
  PI_mutexattr_t a;
228
 
229
  struct timespec period1 = {0,10000000};
230
  struct timespec period2 = {0,10000000};
1183 giacomo 231
  struct timespec budget1 = {0,4000000};
232
  struct timespec budget2 = {0,4000000};
1182 giacomo 233
 
234
  fsf_server_id_t server1, server2;
235
  fsf_contract_parameters_t contract1, contract2;
236
 
237
  sys_atrunlevel(program_end, NULL, RUNLEVEL_BEFORE_EXIT);
238
 
239
  k.flag = ALTL_BIT;
240
  k.scan = KEY_C;
241
  k.ascii = 'c';
242
  keyb_hook(k,program_key_end);
243
 
244
  srand(sys_gettime(NULL));
245
 
246
  // graphic card Initialization
247
  if (grx_init() < 1) {
248
     sys_end();
249
  }
250
 
251
  if (grx_open(800, 600, 16) < 0) {
252
    cprintf("GRX Err\n");
253
    sys_end();
254
  }
255
 
256
  layout_screen();
257
 
258
  PI_mutexattr_default(a);
259
 
260
  mutex_init(&mux,&a);
261
 
262
  fsf_initialize_contract(&contract1);
263
  fsf_set_contract_basic_parameters(&contract1,&budget1,&period1,NULL,NULL,FSF_DEFAULT_WORKLOAD);
264
  fsf_initialize_contract(&contract2);
265
  fsf_set_contract_basic_parameters(&contract2,&budget2,&period2,NULL,NULL,FSF_DEFAULT_WORKLOAD);
266
  fsf_set_local_scheduler_parameter(&contract2, FSF_SCHEDULER_EDF);
267
 
268
  err = fsf_negotiate_contract(&contract1,&server1);
269
  if (err) cprintf("(FSF ERROR %d)",err);
270
  err = fsf_negotiate_contract(&contract2,&server2);
271
  if (err) cprintf("(FSF ERROR %d)",err);
272
 
273
  ch = keyb_getch(BLOCK);
274
 
275
  while(ch != ESC) {
276
 
277
          switch (ch) {
278
 
279
            case '1':
280
                add_posixstar_thread(server1);
281
                break;
282
            case '2':
283
                add_edfstar_thread(server2);
284
                break;
285
            case '3':
286
                break;
287
            case '4':
288
                break;
289
            case '5':
290
                break;
291
          }
292
 
293
    ch = keyb_getch(BLOCK);
294
 
295
  }
296
 
297
  sys_end();
298
 
299
  return 0;
300
 
301
}