Rev 897 | Rev 909 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
668 | 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 | * Trimarchi Michael <trimarchi@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) 2000 Giorgio Buttazzo, 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 | * |
||
908 | trimarchi | 37 | * CVS : $Id: server-task.c,v 1.13 2004-12-09 10:27:08 trimarchi Exp $ |
668 | trimarchi | 38 | */ |
39 | |||
679 | trimarchi | 40 | #include "ll/i386/64bit.h" |
868 | trimarchi | 41 | #include "fsf_configuration_parameters.h" |
880 | trimarchi | 42 | #include "fsf.h" |
868 | trimarchi | 43 | #include "fsf_service_task.h" |
44 | #include "message.h" |
||
668 | trimarchi | 45 | #include <kernel/kern.h> |
679 | trimarchi | 46 | #include <modules/sem.h> |
47 | #include <modules/hartport.h> |
||
668 | trimarchi | 48 | #include <modules/cabs.h> |
49 | |||
868 | trimarchi | 50 | //#define FSF_DEBUG |
880 | trimarchi | 51 | extern fsf_server_id_t service_server; |
868 | trimarchi | 52 | |
53 | TASK service_task(void) { |
||
679 | trimarchi | 54 | |
868 | trimarchi | 55 | struct mess msg; |
56 | fsf_renegotiation_status_t status; |
||
57 | int wait_renegotiation=0; |
||
908 | trimarchi | 58 | /* |
880 | trimarchi | 59 | struct timespec next_act; |
60 | struct timespec period; |
||
61 | struct timespec act_time; |
||
908 | trimarchi | 62 | */ |
679 | trimarchi | 63 | PORT rec,tra; |
868 | trimarchi | 64 | |
679 | trimarchi | 65 | rec = port_connect("CHANW",sizeof(struct mess),STREAM,READ); |
668 | trimarchi | 66 | |
679 | trimarchi | 67 | tra = port_connect("CHANR",sizeof(struct mess),STREAM,WRITE); |
668 | trimarchi | 68 | |
69 | while(1) { |
||
868 | trimarchi | 70 | // wait for operation |
71 | if (wait_renegotiation) { |
||
72 | if (!fsf_get_renegotiation_status(msg.server,&status)) { |
||
73 | if (status==FSF_ADMITTED) { |
||
74 | // send response server is -1 if the operation fail |
||
75 | #ifdef FSF_DEBUG |
||
76 | kern_printf("ADM"); |
||
77 | #endif |
||
78 | wait_renegotiation=0; |
||
908 | trimarchi | 79 | //kern_printf("(REN %d)", msg.server); |
868 | trimarchi | 80 | port_send(tra,&msg,BLOCK); |
880 | trimarchi | 81 | //kern_gettime(&act_time); |
82 | //fsf_get_budget_and_period(service_server,NULL,&period); |
||
83 | //ADDTIMESPEC(&act_time, &period, &next_act); |
||
84 | //fsf_schedule_next_timed_job(&next_act,NULL,NULL,NULL,NULL); |
||
868 | trimarchi | 85 | continue; |
86 | } else |
||
87 | #ifdef FSF_DEBUG |
||
88 | kern_printf("WAIT") |
||
89 | #endif |
||
90 | ; |
||
91 | } |
||
92 | } else { |
||
93 | port_receive(rec,&msg,BLOCK); |
||
877 | trimarchi | 94 | #ifdef FSF_DEBUG |
868 | trimarchi | 95 | kern_printf("Message "); |
877 | trimarchi | 96 | #endif |
868 | trimarchi | 97 | switch (msg.type) { |
98 | |||
99 | case NEGOTIATE_CONTRACT: |
||
100 | if (negotiate_contract(&msg.contract, &msg.server)==FSF_ERR_CONTRACT_REJECTED) |
||
101 | msg.server=-1; |
||
880 | trimarchi | 102 | else { |
103 | wait_renegotiation=1; |
||
104 | //task_endcycle(); |
||
105 | continue; |
||
106 | } |
||
107 | break; |
||
868 | trimarchi | 108 | |
109 | case REQUEST_RENEGOTIATE_CONTRACT: |
||
110 | if (renegotiate_contract(&msg.contract, msg.server)==FSF_ERR_CONTRACT_REJECTED) |
||
111 | msg.server=-1; |
||
112 | break; |
||
113 | |||
114 | case RENEGOTIATE_CONTRACT: |
||
115 | if (renegotiate_contract(&msg.contract, msg.server)==FSF_ERR_CONTRACT_REJECTED) |
||
116 | msg.server=-1; |
||
117 | else { |
||
118 | wait_renegotiation=1; |
||
119 | //task_endcycle(); |
||
120 | continue; |
||
121 | } |
||
122 | break; |
||
908 | trimarchi | 123 | case CHANGE_PARAMETER: |
124 | { |
||
125 | fsf_contract_parameters_t new_contract; |
||
126 | struct timespec period; |
||
127 | struct timespec budget; |
||
128 | int i=0; |
||
129 | // this CASE change the quality and importance |
||
130 | //fsf_initialize_contract(&new_contract); |
||
131 | // find contract |
||
132 | while(i<current_server) { |
||
133 | if (server_list[i].server==msg.server) break; |
||
134 | i++; |
||
135 | } |
||
136 | //kern_printf("(RCQI)"); |
||
137 | NULL_TIMESPEC(&period); |
||
138 | ADDUSEC2TIMESPEC(server_list[i].Tmax, &period); |
||
139 | NULL_TIMESPEC(&budget); |
||
140 | ADDUSEC2TIMESPEC(server_list[i].Cmin, &budget); |
||
141 | |||
142 | fsf_set_contract_basic_parameters(&new_contract,&budget,&period,FSF_DEFAULT_WORKLOAD); |
||
143 | NULL_TIMESPEC(&period); |
||
144 | ADDUSEC2TIMESPEC(server_list[i].Tmin, &period); |
||
145 | NULL_TIMESPEC(&budget); |
||
146 | ADDUSEC2TIMESPEC(server_list[i].Cmax, &budget); |
||
147 | |||
148 | fsf_set_contract_reclamation_parameters(&new_contract, &budget, &period, FSF_DEFAULT_GRANULARITY,NULL, |
||
149 | msg.qi.quality,msg.qi.importance); |
||
150 | |||
151 | if (server_list[i].d_equals_t == true) { |
||
152 | NULL_TIMESPEC(&new_contract.deadline); |
||
153 | new_contract.d_equals_t = true; |
||
154 | } else { |
||
155 | NULL_TIMESPEC(&period); |
||
156 | ADDUSEC2TIMESPEC(server_list[i].deadline, &period); |
||
157 | TIMESPEC_ASSIGN(&new_contract.deadline, &period); |
||
158 | new_contract.d_equals_t = false; |
||
159 | } |
||
160 | if (renegotiate_contract(&new_contract, msg.server)==FSF_ERR_CONTRACT_REJECTED) |
||
161 | msg.server=-1; |
||
162 | } |
||
893 | trimarchi | 163 | break; |
164 | |||
868 | trimarchi | 165 | default : |
166 | break; |
||
167 | |||
168 | } |
||
169 | // send response server is -1 if the operation fail |
||
908 | trimarchi | 170 | //kern_printf("(msg server %d)", msg.server); |
868 | trimarchi | 171 | port_send(tra,&msg,BLOCK); |
880 | trimarchi | 172 | //kern_gettime(&act_time); |
173 | //fsf_get_budget_and_period(service_server,NULL,&period); |
||
174 | //ADDTIMESPEC(&act_time, &period, &next_act); |
||
175 | //fsf_schedule_next_timed_job(&next_act,NULL,NULL,NULL,NULL); |
||
868 | trimarchi | 176 | //task_endcycle(); |
880 | trimarchi | 177 | //kern_printf("(ES)"); |
668 | trimarchi | 178 | } |
179 | } |
||
180 | } |
||
181 | |||
688 | trimarchi | 182 | |
183 | static __inline void set_contract_parameter(void) { |
||
184 | |||
185 | int i=0; |
||
679 | trimarchi | 186 | TIME T,Q; |
868 | trimarchi | 187 | |
188 | for (i=0; i<current_server; i++) { |
||
679 | trimarchi | 189 | mul32div32to32(MAX_BANDWIDTH,server_list[i].Cmin,server_list[i].U,T); |
190 | if (T > server_list[i].Tmin ) { |
||
191 | server_list[i].actual_budget = server_list[i].Cmin; |
||
192 | server_list[i].actual_period = T; |
||
193 | #ifdef FSF_DEBUG |
||
194 | kern_printf("(1 - Q %ld T %ld)", server_list[i].actual_budget, server_list[i].actual_period); |
||
195 | #endif |
||
908 | trimarchi | 196 | if (server_list[i].d_equals_t == true) |
679 | trimarchi | 197 | adjust_SERVER_budget(server_list[i].server,server_list[i].Cmin, T, T); |
198 | else |
||
199 | adjust_SERVER_budget(server_list[i].server,server_list[i].Cmin, T, server_list[i].deadline); |
||
200 | |||
201 | } else { |
||
202 | mul32div32to32(server_list[i].Tmin,server_list[i].U,MAX_BANDWIDTH,Q); |
||
203 | server_list[i].actual_budget = Q; |
||
204 | server_list[i].actual_period = server_list[i].Tmin; |
||
205 | #ifdef FSF_DEBUG |
||
206 | kern_printf("(2 - Q %ld T %ld)", server_list[i].actual_budget, server_list[i].actual_period); |
||
207 | #endif |
||
208 | |||
908 | trimarchi | 209 | if (server_list[i].d_equals_t == true) |
679 | trimarchi | 210 | adjust_SERVER_budget(server_list[i].server,server_list[i].Cmin, server_list[i].Tmin, server_list[i].Tmin); |
211 | else |
||
212 | adjust_SERVER_budget(server_list[i].server,server_list[i].Cmin, server_list[i].Tmin, server_list[i].deadline); |
||
213 | } |
||
214 | |||
215 | server_list[i].U=server_list[i].Umin; |
||
216 | } |
||
217 | |||
688 | trimarchi | 218 | } |
219 | |||
220 | |||
221 | int renegotiate_contract |
||
222 | (const fsf_contract_parameters_t *new_contract, |
||
223 | fsf_server_id_t server) |
||
224 | { |
||
225 | |||
226 | #ifdef FSF_DEBUG |
||
227 | kern_printf("(Renegotiate for server %d)",server); |
||
228 | #endif |
||
229 | |||
230 | if (!new_contract) |
||
868 | trimarchi | 231 | return FSF_ERR_BAD_ARGUMENT; |
688 | trimarchi | 232 | |
233 | if (server < 0) |
||
875 | trimarchi | 234 | return FSF_ERR_BAD_ARGUMENT; |
688 | trimarchi | 235 | |
236 | // change the parameter |
||
237 | relink_contract_to_server(new_contract, server); |
||
238 | if (recalculate_contract(fsf_max_bw)==-1) { |
||
875 | trimarchi | 239 | return FSF_ERR_CONTRACT_REJECTED; |
688 | trimarchi | 240 | } |
241 | |||
242 | set_contract_parameter(); |
||
243 | |||
679 | trimarchi | 244 | return 0; |
245 | } |
||
246 | |||
668 | trimarchi | 247 | int negotiate_contract |
679 | trimarchi | 248 | (const fsf_contract_parameters_t *contract, |
249 | fsf_server_id_t *server) |
||
668 | trimarchi | 250 | { |
251 | /* Check if contract is initialized */ |
||
868 | trimarchi | 252 | if (!contract) return FSF_ERR_BAD_ARGUMENT; |
668 | trimarchi | 253 | |
254 | /* Admission Test */ |
||
255 | if (FSF_ADMISSION_TEST_IS_ENABLED) |
||
256 | if (add_contract(contract)) |
||
257 | return FSF_ERR_CONTRACT_REJECTED; |
||
258 | |||
679 | trimarchi | 259 | /* SERVER => BUDGET */ |
260 | set_SERVER_budget_from_contract(contract,server); |
||
668 | trimarchi | 261 | |
688 | trimarchi | 262 | #ifdef FSF_DEBUG |
263 | kern_printf("(New Server %d)",*server); |
||
264 | #endif |
||
679 | trimarchi | 265 | |
266 | if (*server >= 0) { |
||
267 | link_contract_to_server(contract,*server); |
||
268 | if (recalculate_contract(fsf_max_bw)==-1) { |
||
868 | trimarchi | 269 | remove_contract(server); |
875 | trimarchi | 270 | return FSF_ERR_CONTRACT_REJECTED; |
679 | trimarchi | 271 | } |
688 | trimarchi | 272 | set_contract_parameter(); |
679 | trimarchi | 273 | #ifdef FSF_DEBUG |
274 | kern_printf("(Adjust budget)"); |
||
275 | #endif |
||
688 | trimarchi | 276 | |
679 | trimarchi | 277 | } |
278 | else { |
||
875 | trimarchi | 279 | return FSF_ERR_CONTRACT_REJECTED; |
679 | trimarchi | 280 | } |
880 | trimarchi | 281 | //kern_printf("(ENCR)"); |
679 | trimarchi | 282 | return 0; |
283 | |||
668 | trimarchi | 284 | } |
285 |