Subversion Repositories shark

Rev

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

Rev Author Line No. Line
1191 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
 *   (see the web pages for full authors list)
11
 *
12
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
13
 *
14
 * http://www.sssup.it
15
 * http://retis.sssup.it
16
 * http://shark.sssup.it
17
 */
18
 
19
/*
20
 * Copyright (C) 2002 Paolo Gai
21
 *
22
 * This program is free software; you can redistribute it and/or modify
23
 * it under the terms of the GNU General Public License as published by
24
 * the Free Software Foundation; either version 2 of the License, or
25
 * (at your option) any later version.
26
 *
27
 * This program is distributed in the hope that it will be useful,
28
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
30
 * GNU General Public License for more details.
31
 *
32
 * You should have received a copy of the GNU General Public License
33
 * along with this program; if not, write to the Free Software
34
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
35
 *
36
 */
37
 
38
#include "kernel/kern.h"
39
 
40
#include "modules/edf.h"
41
#include "modules/cbs.h"
42
 
43
#include "pthread.h"
44
#include "modules/posix.h"
45
 
46
#include "fsf_contract.h"
47
#include "fsf_server.h"
48
 
49
#include "modules/dummy.h"
50
 
51
#include "modules/sem.h"
52
#include "modules/pi.h"
53
#include "modules/pc.h"
54
 
55
#include "modules/hartport.h"
56
#include "modules/cabs.h"
57
 
58
#include "drivers/keyb.h"
59
#include <stdlib.h>
60
 
61
// --------------------------------------------------
62
// --------------------------------------------------
63
// Init Part
64
// --------------------------------------------------
65
// --------------------------------------------------
66
 
67
/*+ sysyem tick in us +*/
68
#define TICK 0
69
 
70
/*+ RR tick in us +*/
71
#define RRTICK 10000
72
 
73
int grubstar_level;
74
 
75
TIME __kernel_register_levels__(void *arg)
76
{
77
  struct multiboot_info *mb = (struct multiboot_info *)arg;
78
 
79
  EDF_register_level(EDF_ENABLE_ALL);
80
  POSIX_register_level(RRTICK, 1, mb, 32);
81
  grubstar_level = GRUBSTAR_register_level(5, 0);
82
  FSF_register_module(grubstar_level);
83
  dummy_register_level();
84
 
85
  // for the keyboard...
86
  CBS_register_level(CBS_ENABLE_ALL, 0);
87
 
88
  PI_register_module();
89
  PC_register_module();
90
 
91
  SEM_register_module();
92
 
93
  PTHREAD_register_module(1, 0, 1);
94
 
95
  return TICK;
96
}
97
 
98
 
99
TASK __init__(void *arg)
100
{
101
  struct multiboot_info *mb = (struct multiboot_info *)arg;
102
 
103
  HARTPORT_init();
104
 
105
  KEYB_init(NULL);
106
 
107
  __call_main__(mb);
108
 
109
  return (void *)0;
110
 
111
}
112
 
113
// --------------------------------------------------
114
// --------------------------------------------------
115
// The Test
116
// --------------------------------------------------
117
// --------------------------------------------------
118
 
119
pthread_t j1 = -1;
120
pthread_t j2 = -1;
121
pthread_t j3 = -1;
122
pthread_t j4 = -1;
123
fsf_server_id_t server1 = -1;
124
fsf_server_id_t server2 = -1;
125
fsf_server_id_t server3 = -1;
126
fsf_server_id_t server4 = -1;
127
fsf_contract_parameters_t contract;
128
 
129
pthread_mutex_t mux;
130
 
131
void *star(void *arg)
132
{
133
  struct timespec actual,end;
134
  int actpersecond,act;
135
  int cycle,rec;
136
 
137
  act = 0;
138
  actpersecond = 0;
139
  cycle = 0;
140
  rec = 0;
141
  for (;;) {
142
 
143
    cycle++;
144
    kern_gettime(&actual);
145
    rec = GRUBSTAR_get_last_reclaiming(grubstar_level);
146
 
147
    if (act == 0) {
148
      TIMESPEC_ASSIGN(&end,&actual);
149
      end.tv_sec++;
150
    }
151
 
152
    if (TIMESPEC_A_LT_B(&actual,&end)) {
153
      act++;
154
    } else {
155
      actpersecond = act;
156
      act = 0;
157
    }
158
 
159
    //pthread_mutex_lock(&mux);
160
      printf_xy(0,exec_shadow,WHITE,"Thread %3d Act_per_Second = %8d cycle = %8d rec = %8d",
161
                                    exec_shadow,actpersecond,cycle,rec);
162
    //pthread_mutex_unlock(&mux);
163
 
164
  }
165
 
166
  return NULL;
167
 
168
}
169
 
170
void *periodic_star(void *arg)
171
{
172
  struct timespec actual,end;
173
  int actpersecond,act;
174
  int cycle,rec;
175
 
176
  act = 0;
177
  actpersecond = 0;
178
  cycle = 0;
179
  rec = 0;
180
  for (;;) {
181
 
182
    cycle++;
183
    kern_gettime(&actual);
184
    rec = GRUBSTAR_get_last_reclaiming(grubstar_level);
185
 
186
    if (act == 0) {
187
      TIMESPEC_ASSIGN(&end,&actual);
188
      end.tv_sec++;
189
    }
190
 
191
    if (TIMESPEC_A_LT_B(&actual,&end)) {
192
      act++;
193
    } else {
194
      actpersecond = act;
195
      act = 0;
196
    }
197
 
198
    //pthread_mutex_lock(&mux);
199
      printf_xy(0,exec_shadow,RED,"Thread %3d Act_per_Second = %8d cycle = %8d rec = %8d",
200
                                    exec_shadow,actpersecond,cycle,rec);
201
    //pthread_mutex_unlock(&mux);
202
 
203
    task_endcycle();
204
 
205
  }
206
 
207
  return NULL;
208
 
209
}
210
 
211
void *edftask(void *arg)
212
{
213
  int i,j;
214
  while(1) {
215
  for (i=0;i<5; i++) {
216
    for (j=0; j<10; j++);
217
    //cputc('#');
218
    //cputs((char *)(arg));
219
  }
220
 
221
  task_endcycle();
222
  }
223
 
224
  return NULL;
225
}
226
 
227
 
228
void create()
229
{
230
  HARD_TASK_MODEL mhard;
231
 
232
  struct timespec period1 = {0,100000000};  //30%
233
  struct timespec period2 = {0,200000000};  //15%
234
  struct timespec period3 = {0,300000000};  //10%
235
  struct timespec budget1 = {0,30000000};
236
  struct timespec budget2 = {0,30000000};
237
  struct timespec budget3 = {0,30000000};
238
 
239
  PID t1, t2;
240
 
241
  kern_printf("(Start Create)");
242
 
243
  hard_task_default_model(mhard);
244
  hard_task_def_ctrl_jet(mhard);
245
  hard_task_def_mit(mhard,30000);
246
  hard_task_def_wcet(mhard,3000);
247
  hard_task_def_arg(mhard,(void *)"X");
248
  hard_task_def_group(mhard,1);
249
  hard_task_def_periodic(mhard);
250
  hard_task_def_level(mhard,0);
251
 
252
  t1 = task_create("X", edftask, &mhard, NULL);
253
  if (t1 == NIL) {
254
    perror("Could not create task X ...");
255
    sys_end();
256
  }
257
 
258
  hard_task_def_mit(mhard,30000);
259
  hard_task_def_wcet(mhard,3000);
260
  hard_task_def_arg(mhard,(void *)"Y");
261
  t2 = task_create("Y", edftask, &mhard, NULL);
262
  if (t2 == NIL) {
263
    perror("Could not create task Y ...");
264
    sys_end();
265
  }
266
 
267
  //group_activate(1);
268
 
269
  fsf_initialize_contract(&contract);
270
 
271
  fsf_set_contract_basic_parameters(&contract,&budget1,&period1,NULL,NULL,FSF_DEFAULT_WORKLOAD);
272
  fsf_negotiate_contract(&contract,&server1);
273
 
274
  fsf_set_contract_basic_parameters(&contract,&budget2,&period2,NULL,NULL,FSF_DEFAULT_WORKLOAD);
275
  fsf_negotiate_contract(&contract,&server2);
276
 
277
  fsf_set_contract_basic_parameters(&contract,&budget3,&period3,NULL,NULL,FSF_DEFAULT_WORKLOAD);  
278
  fsf_negotiate_contract(&contract,&server3);
279
 
280
  fsf_set_contract_basic_parameters(&contract,&budget1,&period1,NULL,NULL,FSF_DEFAULT_WORKLOAD);
281
  fsf_set_local_scheduler_parameter(&contract, FSF_SCHEDULER_EDF);
282
  fsf_negotiate_contract(&contract,&server4);
283
 
284
  kern_printf("(End Create)");
285
 
286
}
287
 
288
int main(int argc, char **argv)
289
{
290
 
291
  char ch = 0;
292
  int err;
293
  HARD_TASK_MODEL ht;
294
 
295
  pthread_mutex_init(&mux,NULL);
296
 
297
  create();
298
 
299
  do {
300
    ch = keyb_getch(BLOCK);
301
 
302
    switch(ch) {
303
      case '1':
304
        err = fsf_create_thread(server1,&j1,NULL,star,NULL,NULL);
305
        kern_printf("(%d)",err);
306
        break;
307
      case '2':
308
        err = fsf_create_thread(server2,&j2,NULL,star,NULL,NULL);
309
        kern_printf("(%d)",err);
310
        break;
311
      case '3':
312
        err = fsf_create_thread(server3,&j3,NULL,star,NULL,NULL);
313
        kern_printf("(%d)",err);
314
        break;
315
      case '4':
316
        hard_task_default_model(ht);
317
        hard_task_def_mit(ht,200000);
318
        hard_task_def_wcet(ht,100000);
319
        err = fsf_create_thread(server4,&j4,NULL,periodic_star,NULL,&ht);
320
        kern_printf("(%d)",err);
321
        break;
322
    }
323
 
324
  } while(ch != ESC);
325
 
326
  sys_end();
327
 
328
  return 0;
329
 
330
}
331