Subversion Repositories shark

Rev

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

Rev Author Line No. Line
1562 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
 *   (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_basic_types.h"
47
#include "fsf_core.h"
48
#include "fsf_hierarchical.h"
49
#include "fsf_spare_capacity.h"
50
 
51
#include "fsf_server.h"
52
 
53
#include "modules/dummy.h"
54
 
55
#include "modules/sem.h"
56
#include "modules/pi.h"
57
#include "modules/pc.h"
58
 
59
#include "modules/hartport.h"
60
#include "modules/cabs.h"
61
 
62
#include "drivers/keyb.h"
63
#include <stdlib.h>
64
#include "fsf_server.h"
65
#include "fsf_basic_types.h"
66
#include "fsf_core.h"
67
// --------------------------------------------------
68
// --------------------------------------------------
69
// Init Part
70
// --------------------------------------------------
71
// --------------------------------------------------
72
 
73
/*+ sysyem tick in us +*/
74
#define TICK 0
75
 
76
/*+ RR tick in us +*/
77
#define RRTICK 10000
78
 
79
int grubstar_level;
80
int posix_level;
81
 
82
 
83
//fsf_shared_object_t obj;
84
//fsf_shared_operation_t op;
85
 
86
TIME __kernel_register_levels__(void *arg)
87
{
88
  struct multiboot_info *mb = (struct multiboot_info *)arg;
89
 
90
  EDF_register_level(EDF_ENABLE_ALL);
91
  posix_level=POSIX_register_level(RRTICK, 1, mb, 32);
92
  grubstar_level = GRUBSTAR_register_level(5, 0);
93
  FSF_register_module(posix_level,grubstar_level, (int)(MAX_BANDWIDTH * 0.9));
94
  dummy_register_level();
95
 
96
  // for the keyboard...
97
  CBS_register_level(CBS_ENABLE_ALL, 0);
98
 
99
  PI_register_module();
100
  PC_register_module();
101
 
102
  SEM_register_module();
103
 
104
  PTHREAD_register_module(1, 0, 1);
105
 
106
  return TICK;
107
}
108
 
109
 
110
TASK __init__(void *arg)
111
{
112
  struct multiboot_info *mb = (struct multiboot_info *)arg;
113
 
114
  HARTPORT_init();
115
 
116
  KEYB_init(NULL);
117
 
118
  __call_main__(mb);
119
 
120
  return (void *)0;
121
 
122
}
123
 
124
// --------------------------------------------------
125
// --------------------------------------------------
126
// The Test
127
// --------------------------------------------------
128
// --------------------------------------------------
129
 
130
pthread_t jposix = -1;
131
pthread_t j1 = -1;
132
pthread_t j2 = -1;
133
fsf_server_id_t server1 = -1;
134
fsf_server_id_t server2 = -1;
135
fsf_contract_parameters_t contract;
136
 
137
void *star(void *arg)
138
{
139
  struct timespec actual,end;
140
  int actpersecond,act;
141
  int cycle,rec;
142
 
143
  act = 0;
144
  actpersecond = 0;
145
  cycle = 0;
146
  rec = 0;
147
  for (;;) {
148
 
149
    cycle++;
150
    kern_gettime(&actual);
151
    rec = SERVER_get_last_reclaiming(grubstar_level,exec_shadow);
152
 
153
    if (act == 0) {
154
      TIMESPEC_ASSIGN(&end,&actual);
155
      end.tv_sec++;
156
    }
157
 
158
    if (TIMESPEC_A_LT_B(&actual,&end)) {
159
      act++;
160
    } else {
161
      actpersecond = act;
162
      act = 0;
163
    }
164
 
165
    //pthread_mutex_lock(&mux);
166
      printf_xy(0,exec_shadow,WHITE,"Thread %3d Act_per_Second = %8d cycle = %8d rec = %8d",
167
                                    exec_shadow,actpersecond,cycle,rec);
168
    //pthread_mutex_unlock(&mux);
169
 
170
  }
171
 
172
  return NULL;
173
 
174
}
175
 
176
void *periodic_star(void *arg)
177
{
178
  struct timespec actual,end;
179
  int actpersecond,act;
180
  int cycle,rec;
181
 
182
  act = 0;
183
  actpersecond = 0;
184
  cycle = 0;
185
  rec = 0;
186
  for (;;) {
187
 
188
    cycle++;
189
    kern_gettime(&actual);
190
    rec = SERVER_get_last_reclaiming(grubstar_level,exec_shadow);
191
 
192
    if (act == 0) {
193
      TIMESPEC_ASSIGN(&end,&actual);
194
      end.tv_sec++;
195
    }
196
 
197
    if (TIMESPEC_A_LT_B(&actual,&end)) {
198
      act++;
199
    } else {
200
      actpersecond = act;
201
      act = 0;
202
    }
203
 
204
    //fsf_lock_object(&op);
205
      printf_xy(0,exec_shadow,RED,"Thread %3d Act_per_Second = %8d cycle = %8d rec = %8d",
206
                                    exec_shadow,actpersecond,cycle,rec);
207
    //fsf_unlock_object(&op);    
208
 
209
    task_endcycle();
210
 
211
  }
212
 
213
  return NULL;
214
 
215
}
216
 
217
int keyinc = 5;
218
 
219
void *edftask(void *arg)
220
{
221
  long long j;
222
  while(1) {
223
    for (j=0; j<10000*keyinc; j++);
224
    task_endcycle();
225
  }
226
 
227
  return NULL;
228
}
229
 
230
 
231
void create()
232
{
233
  struct timespec period1 = {0,90000000};   //30%
234
  struct timespec period2 = {0,75000000};  //80%
235
  struct timespec budget1 = {0,30000000};
236
  struct timespec budget2 = {0,60000000};
237
 
238
  FSF_start_service_task();
239
 
240
 
241
  kern_printf("(Start Create)");
242
 
243
  fsf_initialize_contract(&contract);
244
 
245
  fsf_set_contract_basic_parameters(&contract,&budget1,&period1,FSF_DEFAULT_WORKLOAD);
246
  fsf_set_contract_scheduling_policy(&contract, FSF_EDF);
247
  fsf_set_contract_reclamation_parameters(&contract,&budget2, &period2, FSF_DEFAULT_GRANULARITY, NULL, 1, 0);
248
  fsf_negotiate_contract(&contract,&server1);
249
 
250
 
251
  fsf_set_contract_basic_parameters(&contract,&budget1,&period1,FSF_DEFAULT_WORKLOAD);
252
  fsf_set_contract_scheduling_policy(&contract, FSF_EDF);
253
  fsf_set_contract_reclamation_parameters(&contract,&budget2, &period2,FSF_DEFAULT_GRANULARITY, NULL, 1, 1);
254
 
255
  fsf_negotiate_contract(&contract,&server2);
256
 
257
  kern_printf("(End Create)");
258
 
259
 
260
}
261
 
262
void renegotiate(void) {  
263
  struct timespec period2 = {0,75000000};
264
  struct timespec budget2 = {0,60000000};
265
  struct timespec budget1 = {0,60000000};
266
  union sigval sval;
267
  for (;;) {
268
    fsf_set_contract_basic_parameters(&contract,&budget2,&period2,FSF_DEFAULT_WORKLOAD);
269
    fsf_set_contract_reclamation_parameters(&contract,&budget1, &period2,FSF_DEFAULT_GRANULARITY, NULL, 20, 0);
270
 
271
    //fsf_request_contract_renegotiation(&contract,server2, 0, sval);
272
 
273
    fsf_renegotiate_contract(&contract, server2);
274
    budget2.tv_nsec -=60000;
275
 
276
    task_endcycle();
277
  }
278
 
279
}
280
 
281
 
282
int main(int argc, char **argv)
283
{
284
 
285
  int err;
286
  HARD_TASK_MODEL ht;
287
  struct timespec endtimer;
288
 
289
  //fsf_init_shared_object(&obj,1); 
290
 
291
  //op.op_id=1;
292
  //op.wcet.tv_sec=0;
293
  //op.wcet.tv_nsec=100000;
294
  //fsf_declare_shared_object_operation(&obj, &op);  
295
 
296
  srand(kern_gettime(NULL));
297
  create();
298
 
299
  kern_gettime(&endtimer);
300
  endtimer.tv_sec += 20;
301
  kern_event_post(&endtimer, (void (*)(void *))(sys_end), NULL);  
302
 
303
  hard_task_default_model(ht);
304
  hard_task_def_mit(ht,200000);
305
  hard_task_def_wcet(ht,5000);
306
  err = fsf_create_thread(server1,&j1,NULL,periodic_star,NULL,&ht);
307
  kern_printf("(%d)",err);
308
  task_activate(j1);
309
 
310
  hard_task_default_model(ht);
311
  hard_task_def_mit(ht,1000000);
312
  hard_task_def_wcet(ht,50000);
313
  err = fsf_create_thread(server1,&j1,NULL,renegotiate,NULL,&ht);
314
  kern_printf("(%d)",err);
315
  task_activate(j1);
316
 
317
  hard_task_default_model(ht);
318
  hard_task_def_mit(ht,159000);
319
  hard_task_def_wcet(ht,5000);
320
  err = fsf_create_thread(server2,&j2,NULL,periodic_star,NULL,&ht);
321
  kern_printf("(%d)",err);
322
  task_activate(j2);
323
 
324
  hard_task_default_model(ht);
325
  hard_task_def_mit(ht,159000);
326
  hard_task_def_wcet(ht,5000);
327
  err = fsf_create_thread(server2,&j2,NULL,periodic_star,NULL,&ht);
328
  kern_printf("(%d)",err);
329
  task_activate(j2);
330
 
331
 return 0;
332
 
333
}
334