Rev 1223 | 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; |
1224 | giacomo | 100 | struct timespec current; |
1218 | giacomo | 101 | |
1219 | giacomo | 102 | while(1) { |
1218 | giacomo | 103 | |
1219 | giacomo | 104 | cprintf("Decoder Start %d Frame %d\n",exec_shadow,darg->frame_number); |
1218 | giacomo | 105 | |
1224 | giacomo | 106 | for (i=0;i<100;i++) { |
107 | if (MPEGSTAR_is_frame_skipped(darg->server_id)) { |
||
108 | kern_printf("Skipping this frame\n"); |
||
109 | break; |
||
110 | } |
||
111 | kern_gettime(¤t); |
||
112 | } |
||
1218 | giacomo | 113 | |
1223 | giacomo | 114 | Q = MPEGSTAR_get_remain_capacity(darg->server_id); |
1224 | giacomo | 115 | R = MPEGSTAR_get_last_reclaiming(darg->server_id); |
1223 | giacomo | 116 | printf_xy(55,10+exec_shadow,WHITE,"[S%02d:Q%06d:R%06d]",darg->server_id,Q,R); |
117 | |||
1219 | giacomo | 118 | cprintf("Decoder End %d\n",exec_shadow); |
1218 | giacomo | 119 | |
1219 | giacomo | 120 | task_endcycle(); |
121 | |||
122 | } |
||
123 | |||
1218 | giacomo | 124 | return NULL; |
125 | |||
126 | } |
||
127 | |||
128 | int init_mpeg_server() { |
||
129 | |||
130 | int err; |
||
131 | HARD_TASK_MODEL ht; |
||
132 | |||
133 | fsf_initialize_contract(&contract_I); |
||
134 | fsf_set_contract_basic_parameters(&contract_I,&server_I_budget,&server_I_period,NULL,NULL,FSF_DEFAULT_WORKLOAD); |
||
135 | fsf_set_local_scheduler_parameter(&contract_I, FSF_SCHEDULER_MPEG); |
||
136 | |||
137 | fsf_initialize_contract(&contract_P); |
||
138 | fsf_set_contract_basic_parameters(&contract_P,&server_P_budget,&server_P_period,NULL,NULL,FSF_DEFAULT_WORKLOAD); |
||
139 | fsf_set_local_scheduler_parameter(&contract_P, FSF_SCHEDULER_MPEG); |
||
140 | |||
141 | fsf_initialize_contract(&contract_B); |
||
142 | fsf_set_contract_basic_parameters(&contract_B,&server_B_budget,&server_B_period,NULL,NULL,FSF_DEFAULT_WORKLOAD); |
||
143 | fsf_set_local_scheduler_parameter(&contract_B, FSF_SCHEDULER_MPEG); |
||
144 | |||
145 | err = fsf_negotiate_contract(&contract_I,&server_I); |
||
146 | if (err) cprintf("(FSF ERROR %d)",err); |
||
147 | err = fsf_negotiate_contract(&contract_P,&server_P); |
||
148 | if (err) cprintf("(FSF ERROR %d)",err); |
||
149 | err = fsf_negotiate_contract(&contract_B,&server_B); |
||
150 | if (err) cprintf("(FSF ERROR %d)",err); |
||
151 | |||
152 | hard_task_default_model(ht); |
||
153 | |||
1219 | giacomo | 154 | decoder_arg_table[server_I] = (decoder_arg_ptr)malloc(sizeof(struct decoder_arg)); |
155 | decoder_arg_table[server_I]->server_id = server_I; |
||
156 | fsf_create_thread(server_I, &pI, NULL, decoder, decoder_arg_table[server_I], &ht); |
||
157 | cprintf("Decoder I PID %d\n",pI); |
||
1218 | giacomo | 158 | |
1219 | giacomo | 159 | decoder_arg_table[server_P] = (decoder_arg_ptr)malloc(sizeof(struct decoder_arg)); |
160 | decoder_arg_table[server_P]->server_id = server_P; |
||
161 | fsf_create_thread(server_P, &pP, NULL, decoder, decoder_arg_table[server_P], &ht); |
||
162 | cprintf("Decoder P PID %d\n",pP); |
||
163 | |||
164 | decoder_arg_table[server_B] = (decoder_arg_ptr)malloc(sizeof(struct decoder_arg)); |
||
165 | decoder_arg_table[server_B]->server_id = server_B; |
||
166 | fsf_create_thread(server_B, &pB, NULL, decoder, decoder_arg_table[server_B], &ht); |
||
167 | cprintf("Decoder B PID %d\n",pB); |
||
1218 | giacomo | 168 | |
169 | return 0; |
||
170 | |||
171 | } |
||
172 | |||
1219 | giacomo | 173 | /* Decoder Manager TASK */ |
174 | TASK decoder_manager(void *arg) { |
||
1218 | giacomo | 175 | |
176 | TIME T,Q; |
||
177 | |||
1219 | giacomo | 178 | T = 50000; |
1218 | giacomo | 179 | Q = 10000; |
180 | MPEGSTAR_rescale(server_I,Q,T); |
||
1219 | giacomo | 181 | decoder_arg_table[server_I]->frame_number = 0; |
182 | decoder_arg_table[server_I]->frame_type = FRAME_I; |
||
1218 | giacomo | 183 | task_activate(pI); |
1219 | giacomo | 184 | |
1224 | giacomo | 185 | T = 150000; |
1218 | giacomo | 186 | Q = 10000; |
187 | MPEGSTAR_rescale(server_P,Q,T); |
||
1224 | giacomo | 188 | decoder_arg_table[server_P]->frame_number = 2; |
1219 | giacomo | 189 | decoder_arg_table[server_P]->frame_type = FRAME_P; |
1218 | giacomo | 190 | task_activate(pP); |
1219 | giacomo | 191 | |
1224 | giacomo | 192 | T = 100000; |
1219 | giacomo | 193 | Q = 10000; |
1218 | giacomo | 194 | MPEGSTAR_rescale(server_B,Q,T); |
1224 | giacomo | 195 | decoder_arg_table[server_B]->frame_number = 1; |
1219 | giacomo | 196 | decoder_arg_table[server_B]->frame_type = FRAME_B; |
1218 | giacomo | 197 | task_activate(pB); |
1219 | giacomo | 198 | |
199 | return 0; |
||
200 | |||
201 | } |
||
202 | |||
203 | int main () { |
||
204 | |||
205 | HARD_TASK_MODEL ht_manager; |
||
206 | PID dm; |
||
207 | |||
208 | init_mpeg_server(); |
||
209 | |||
210 | hard_task_default_model(ht_manager); |
||
211 | hard_task_def_mit(ht_manager,10000); |
||
212 | hard_task_def_wcet(ht_manager,5000); |
||
213 | hard_task_def_arg(ht_manager,NULL); |
||
214 | |||
215 | dm = task_create("Manager", decoder_manager, &ht_manager, NULL); |
||
216 | if (dm == NIL) { |
||
217 | cprintf("Error creating decoder manager\n"); |
||
218 | sys_end(); |
||
219 | } |
||
220 | |||
1222 | giacomo | 221 | cprintf("Control-C to exit\n"); |
222 | |||
1219 | giacomo | 223 | task_activate(dm); |
224 | |||
1218 | giacomo | 225 | while(1); |
1219 | giacomo | 226 | |
1218 | giacomo | 227 | return 0; |
228 | |||
229 | } |