Subversion Repositories shark

Rev

Rev 1222 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1218 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"
1219 giacomo 39
#include "fsf_server.h"
1218 giacomo 40
 
41
#include "stdlib.h"
42
#include "unistd.h"
43
#include "string.h"
44
 
45
#include "pthread.h"
46
 
47
#include "drivers/keyb.h"
48
#include "drivers/glib.h"
49
 
1219 giacomo 50
/*Init Server Parameters */
51
#define SERVER_I_PERIOD 50000
1218 giacomo 52
#define SERVER_I_BUDGET 10000
1219 giacomo 53
#define SERVER_P_PERIOD 50000
1218 giacomo 54
#define SERVER_P_BUDGET 10000
1219 giacomo 55
#define SERVER_B_PERIOD 50000
56
#define SERVER_B_BUDGET 10000
1218 giacomo 57
 
58
struct timespec server_I_period = {0,SERVER_I_PERIOD*1000};
59
struct timespec server_I_budget = {0,SERVER_I_BUDGET*1000};
60
struct timespec server_P_period = {0,SERVER_P_PERIOD*1000};
61
struct timespec server_P_budget = {0,SERVER_P_BUDGET*1000};
62
struct timespec server_B_period = {0,SERVER_B_PERIOD*1000};
63
struct timespec server_B_budget = {0,SERVER_B_BUDGET*1000};
64
 
65
fsf_server_id_t server_I, server_P, server_B;
66
fsf_contract_parameters_t contract_I, contract_P, contract_B;
67
 
1219 giacomo 68
/* Decoder PID */
1218 giacomo 69
pthread_t pI,pP,pB;
70
 
1219 giacomo 71
#define FRAME_I 0
72
#define FRAME_P 1
73
#define FRAME_B 2
74
 
75
struct decoder_arg {
76
 
77
   int frame_number;
78
   int frame_type;
1222 giacomo 79
   int fx,fy,fd;
1220 giacomo 80
   void *input_buffer_newdata;
81
   void *input_buffer_pastframe;
82
   void *output_buffer_newframe;
1219 giacomo 83
   int server_id;
84
 
85
};
86
 
87
typedef struct decoder_arg *decoder_arg_ptr;
88
 
89
#define MAX_DECODER_NUMBER 10
90
 
91
/* Table of pointer to decoder_ard struct */
92
decoder_arg_ptr decoder_arg_table[MAX_DECODER_NUMBER];
93
 
94
/* Decoder TASK */
1218 giacomo 95
TASK decoder(void *arg)
96
{
97
 
1219 giacomo 98
  decoder_arg_ptr darg = (decoder_arg_ptr)(arg);
1222 giacomo 99
  int i,Q,R;
1218 giacomo 100
 
1219 giacomo 101
  while(1) {
1218 giacomo 102
 
1219 giacomo 103
    cprintf("Decoder Start %d Frame %d\n",exec_shadow,darg->frame_number);
1218 giacomo 104
 
1223 giacomo 105
    for (i=0;i<100;i++);
1218 giacomo 106
 
1223 giacomo 107
    Q = MPEGSTAR_get_remain_capacity(darg->server_id);
108
    R = MPEGSTAR_get_last_reclaiming();
109
    printf_xy(55,10+exec_shadow,WHITE,"[S%02d:Q%06d:R%06d]",darg->server_id,Q,R);
110
 
1219 giacomo 111
    cprintf("Decoder End %d\n",exec_shadow);
1218 giacomo 112
 
1219 giacomo 113
    task_endcycle();
114
 
115
  }
116
 
1218 giacomo 117
  return NULL;
118
 
119
}
120
 
121
int init_mpeg_server() {
122
 
123
  int err;
124
  HARD_TASK_MODEL ht;
125
 
126
  fsf_initialize_contract(&contract_I);
127
  fsf_set_contract_basic_parameters(&contract_I,&server_I_budget,&server_I_period,NULL,NULL,FSF_DEFAULT_WORKLOAD);
128
  fsf_set_local_scheduler_parameter(&contract_I, FSF_SCHEDULER_MPEG);
129
 
130
  fsf_initialize_contract(&contract_P);
131
  fsf_set_contract_basic_parameters(&contract_P,&server_P_budget,&server_P_period,NULL,NULL,FSF_DEFAULT_WORKLOAD);
132
  fsf_set_local_scheduler_parameter(&contract_P, FSF_SCHEDULER_MPEG);
133
 
134
  fsf_initialize_contract(&contract_B);
135
  fsf_set_contract_basic_parameters(&contract_B,&server_B_budget,&server_B_period,NULL,NULL,FSF_DEFAULT_WORKLOAD);
136
  fsf_set_local_scheduler_parameter(&contract_B, FSF_SCHEDULER_MPEG);
137
 
138
  err = fsf_negotiate_contract(&contract_I,&server_I);
139
  if (err) cprintf("(FSF ERROR %d)",err);
140
  err = fsf_negotiate_contract(&contract_P,&server_P);
141
  if (err) cprintf("(FSF ERROR %d)",err);
142
  err = fsf_negotiate_contract(&contract_B,&server_B);
143
  if (err) cprintf("(FSF ERROR %d)",err);
144
 
145
  hard_task_default_model(ht);
146
 
1219 giacomo 147
  decoder_arg_table[server_I] = (decoder_arg_ptr)malloc(sizeof(struct decoder_arg));
148
  decoder_arg_table[server_I]->server_id = server_I;
149
  fsf_create_thread(server_I, &pI, NULL, decoder, decoder_arg_table[server_I], &ht);
150
  cprintf("Decoder I PID %d\n",pI);
1218 giacomo 151
 
1219 giacomo 152
  decoder_arg_table[server_P] = (decoder_arg_ptr)malloc(sizeof(struct decoder_arg));
153
  decoder_arg_table[server_P]->server_id = server_P;
154
  fsf_create_thread(server_P, &pP, NULL, decoder, decoder_arg_table[server_P], &ht);
155
  cprintf("Decoder P PID %d\n",pP);
156
 
157
  decoder_arg_table[server_B] = (decoder_arg_ptr)malloc(sizeof(struct decoder_arg));
158
  decoder_arg_table[server_B]->server_id = server_B;
159
  fsf_create_thread(server_B, &pB, NULL, decoder, decoder_arg_table[server_B], &ht);
160
  cprintf("Decoder B PID %d\n",pB);
1218 giacomo 161
 
162
  return 0;
163
 
164
}
165
 
1219 giacomo 166
/* Decoder Manager TASK */
167
TASK decoder_manager(void *arg) {
1218 giacomo 168
 
169
  TIME T,Q;
170
 
1219 giacomo 171
  T = 50000;
1218 giacomo 172
  Q = 10000;
173
  MPEGSTAR_rescale(server_I,Q,T);
1219 giacomo 174
  decoder_arg_table[server_I]->frame_number = 0;
175
  decoder_arg_table[server_I]->frame_type = FRAME_I;
1218 giacomo 176
  task_activate(pI);
1219 giacomo 177
 
178
  T = 100000;
1218 giacomo 179
  Q = 10000;
180
  MPEGSTAR_rescale(server_P,Q,T);
1219 giacomo 181
  decoder_arg_table[server_P]->frame_number = 1;
182
  decoder_arg_table[server_P]->frame_type = FRAME_P;
1218 giacomo 183
  task_activate(pP);
1219 giacomo 184
 
185
  T = 150000;
186
  Q = 10000;
1218 giacomo 187
  MPEGSTAR_rescale(server_B,Q,T);
1219 giacomo 188
  decoder_arg_table[server_B]->frame_number = 2;
189
  decoder_arg_table[server_B]->frame_type = FRAME_B;
1218 giacomo 190
  task_activate(pB);
1219 giacomo 191
 
192
  return 0;
193
 
194
}
195
 
196
int main () {
197
 
198
  HARD_TASK_MODEL ht_manager;
199
  PID dm;
200
 
201
  init_mpeg_server();
202
 
203
  hard_task_default_model(ht_manager);
204
  hard_task_def_mit(ht_manager,10000);
205
  hard_task_def_wcet(ht_manager,5000);
206
  hard_task_def_arg(ht_manager,NULL);
207
 
208
  dm = task_create("Manager", decoder_manager, &ht_manager, NULL);
209
  if (dm == NIL) {
210
    cprintf("Error creating decoder manager\n");
211
    sys_end();
212
  }
213
 
1222 giacomo 214
  cprintf("Control-C to exit\n");
215
 
1219 giacomo 216
  task_activate(dm);
217
 
1218 giacomo 218
  while(1);
1219 giacomo 219
 
1218 giacomo 220
  return 0;
221
 
222
}