Rev 668 | Rev 681 | 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 | * |
||
679 | trimarchi | 37 | * CVS : $Id: server-task.c,v 1.2 2004-05-25 12:38:05 trimarchi Exp $ |
668 | trimarchi | 38 | */ |
39 | |||
679 | trimarchi | 40 | #include "ll/i386/64bit.h" |
668 | trimarchi | 41 | #include <kernel/kern.h> |
679 | trimarchi | 42 | #include <modules/sem.h> |
43 | #include <modules/hartport.h> |
||
668 | trimarchi | 44 | #include <modules/cabs.h> |
45 | #include <string.h> |
||
679 | trimarchi | 46 | #include "fsf_contract.h" |
47 | #include "fsf_server.h" |
||
48 | #include "fsf_service_task.h" |
||
668 | trimarchi | 49 | #include "message.h" |
50 | |||
679 | trimarchi | 51 | TASK service_task() { |
52 | |||
53 | struct mess message; |
||
54 | PORT rec,tra; |
||
668 | trimarchi | 55 | |
679 | trimarchi | 56 | rec = port_connect("CHANW",sizeof(struct mess),STREAM,READ); |
668 | trimarchi | 57 | |
679 | trimarchi | 58 | cprintf("task start\n", rec); |
59 | tra = port_connect("CHANR",sizeof(struct mess),STREAM,WRITE); |
||
60 | cprintf("task start\n", tra); |
||
668 | trimarchi | 61 | |
679 | trimarchi | 62 | cprintf("Fine connect %d\n", rec); |
63 | |||
668 | trimarchi | 64 | while(1) { |
679 | trimarchi | 65 | // wait for renegotiation |
66 | cprintf("(pr_t %d)",port_receive(rec,&message,BLOCK)); |
||
668 | trimarchi | 67 | switch (message.type) { |
68 | |||
69 | case NEGOTIATE_CONTRACT: |
||
679 | trimarchi | 70 | if (negotiate_contract(&message.contract, &message.server)==FSF_ERR_CONTRACT_REJECTED) |
71 | message.server=-1; |
||
668 | trimarchi | 72 | |
73 | break; |
||
74 | case RENEGOTIATE_CONTRACT: |
||
679 | trimarchi | 75 | if (renegotiate_contract(&message.contract, message.server)==FSF_ERR_CONTRACT_REJECTED) |
76 | message.server=-1; |
||
668 | trimarchi | 77 | break; |
78 | |||
79 | default : |
||
80 | break; |
||
81 | |||
82 | } |
||
679 | trimarchi | 83 | // send response server is -1 if the operation fail |
84 | cprintf("(ps_t %d)",port_send(tra,&message,BLOCK)); |
||
668 | trimarchi | 85 | |
86 | task_endcycle(); |
||
87 | |||
88 | } |
||
89 | } |
||
90 | |||
679 | trimarchi | 91 | int renegotiate_contract |
92 | (const fsf_contract_parameters_t *new_contract, |
||
93 | fsf_server_id_t server) |
||
94 | { |
||
95 | TIME T,Q; |
||
96 | int i; |
||
97 | |||
98 | #ifdef FSF_DEBUG |
||
99 | kern_printf("(Renegotiate for server %d)",server); |
||
100 | #endif |
||
101 | |||
102 | if (!new_contract) |
||
103 | return FSF_ERR_NOT_INITIALIZED; |
||
104 | |||
105 | if (server < 0) |
||
106 | return FSF_ERR_INVALID_SERVER; |
||
107 | |||
108 | // change the parameter |
||
109 | relink_contract_to_server(new_contract, server); |
||
110 | if (recalculate_contract(fsf_max_bw)==-1) { |
||
111 | return FSF_ERR_CREATE_SERVER; |
||
112 | } |
||
113 | |||
114 | for (i=0; i<current_server; i++) { |
||
115 | mul32div32to32(MAX_BANDWIDTH,server_list[i].Cmin,server_list[i].U,T); |
||
116 | if (T > server_list[i].Tmin ) { |
||
117 | server_list[i].actual_budget = server_list[i].Cmin; |
||
118 | server_list[i].actual_period = T; |
||
119 | #ifdef FSF_DEBUG |
||
120 | kern_printf("(1 - Q %ld T %ld)", server_list[i].actual_budget, server_list[i].actual_period); |
||
121 | #endif |
||
122 | if (server_list[i].d_equals_t == TRUE) |
||
123 | adjust_SERVER_budget(server_list[i].server,server_list[i].Cmin, T, T); |
||
124 | else |
||
125 | adjust_SERVER_budget(server_list[i].server,server_list[i].Cmin, T, server_list[i].deadline); |
||
126 | |||
127 | } else { |
||
128 | mul32div32to32(server_list[i].Tmin,server_list[i].U,MAX_BANDWIDTH,Q); |
||
129 | server_list[i].actual_budget = Q; |
||
130 | server_list[i].actual_period = server_list[i].Tmin; |
||
131 | #ifdef FSF_DEBUG |
||
132 | kern_printf("(2 - Q %ld T %ld)", server_list[i].actual_budget, server_list[i].actual_period); |
||
133 | #endif |
||
134 | |||
135 | if (server_list[i].d_equals_t == TRUE) |
||
136 | adjust_SERVER_budget(server_list[i].server,server_list[i].Cmin, server_list[i].Tmin, server_list[i].Tmin); |
||
137 | else |
||
138 | adjust_SERVER_budget(server_list[i].server,server_list[i].Cmin, server_list[i].Tmin, server_list[i].deadline); |
||
139 | } |
||
140 | |||
141 | server_list[i].U=server_list[i].Umin; |
||
142 | } |
||
143 | |||
144 | return 0; |
||
145 | } |
||
146 | |||
668 | trimarchi | 147 | int negotiate_contract |
679 | trimarchi | 148 | (const fsf_contract_parameters_t *contract, |
149 | fsf_server_id_t *server) |
||
668 | trimarchi | 150 | { |
679 | trimarchi | 151 | int i=0; |
668 | trimarchi | 152 | TIME T; |
153 | TIME Q; |
||
154 | /* Check if contract is initialized */ |
||
155 | if (!contract) return FSF_ERR_NOT_INITIALIZED; |
||
156 | |||
157 | /* Admission Test */ |
||
158 | if (FSF_ADMISSION_TEST_IS_ENABLED) |
||
159 | if (add_contract(contract)) |
||
160 | return FSF_ERR_CONTRACT_REJECTED; |
||
161 | |||
679 | trimarchi | 162 | /* SERVER => BUDGET */ |
163 | set_SERVER_budget_from_contract(contract,server); |
||
668 | trimarchi | 164 | |
679 | trimarchi | 165 | #ifdef FSF_DEBUG |
166 | kern_printf("(New Server %d)",*server); |
||
167 | #endif |
||
168 | |||
169 | if (*server >= 0) { |
||
170 | link_contract_to_server(contract,*server); |
||
171 | if (recalculate_contract(fsf_max_bw)==-1) { |
||
172 | return FSF_ERR_CREATE_SERVER; |
||
173 | } |
||
174 | #ifdef FSF_DEBUG |
||
175 | kern_printf("(Adjust budget)"); |
||
176 | #endif |
||
177 | for (i=0; i<current_server; i++) { |
||
178 | mul32div32to32(MAX_BANDWIDTH,server_list[i].Cmin,server_list[i].U,T); |
||
179 | if (T > server_list[i].Tmin ) { |
||
180 | server_list[i].actual_budget = server_list[i].Cmin; |
||
181 | server_list[i].actual_period = T; |
||
182 | #ifdef FSF_DEBUG |
||
183 | kern_printf("(1 - Q %ld T %ld)", server_list[i].actual_budget, server_list[i].actual_period); |
||
184 | #endif |
||
185 | |||
186 | if (server_list[i].d_equals_t == TRUE) |
||
187 | adjust_SERVER_budget(server_list[i].server,server_list[i].Cmin, T , T); |
||
188 | else |
||
189 | adjust_SERVER_budget(server_list[i].server,server_list[i].Cmin, T , server_list[i].deadline); |
||
190 | |||
191 | } else { |
||
192 | mul32div32to32(server_list[i].Tmin,server_list[i].U,MAX_BANDWIDTH,Q); |
||
193 | server_list[i].actual_budget = Q; |
||
194 | server_list[i].actual_period = server_list[i].Tmin; |
||
195 | #ifdef FSF_DEBUG |
||
196 | kern_printf("(2 - Q %ld T %ld)", server_list[i].actual_budget, server_list[i].actual_period); |
||
197 | #endif |
||
198 | |||
199 | if (server_list[i].d_equals_t == TRUE) |
||
200 | adjust_SERVER_budget(server_list[i].server,Q, server_list[i].Tmin , server_list[i].Tmin); |
||
201 | else |
||
202 | adjust_SERVER_budget(server_list[i].server,Q, server_list[i].Tmin , server_list[i].deadline); |
||
203 | |||
204 | } |
||
205 | |||
206 | |||
207 | server_list[i].U=server_list[i].Umin; |
||
208 | |||
209 | } |
||
210 | } |
||
211 | else { |
||
212 | return FSF_ERR_CREATE_SERVER; |
||
213 | } |
||
214 | |||
215 | return 0; |
||
216 | |||
668 | trimarchi | 217 | } |
218 | |||
219 | |||
679 | trimarchi | 220 | #if defined MICHAEL |
668 | trimarchi | 221 | int recalculate_contract(bandwidth_t U) { |
222 | bandwidth_t current_bandwidth; |
||
223 | unsigned int temp_U; |
||
224 | int Qt; |
||
225 | int isok=0; |
||
226 | int i=0; |
||
227 | |||
228 | #ifdef FSF_DEBUG |
||
229 | int temp; |
||
230 | |||
231 | kern_printf("(Recalculate contract)"); |
||
232 | #endif |
||
233 | |||
234 | /* The current bandwidth is the min bandwidth */ |
||
235 | //current_bandwidth=SERVER_return_bandwidth(fsf_server_level); |
||
236 | #ifdef FSF_DEBUG |
||
237 | kern_printf("(nserver %d)", current_server); |
||
238 | #endif |
||
239 | |||
240 | do { |
||
241 | current_bandwidth=0; |
||
242 | Qt=0; |
||
243 | for (i=0; i<current_server; i++) { |
||
244 | if (server_list[i].Qs!=0 && server_list[i].U<server_list[i].Umax) |
||
245 | Qt+=server_list[i].Qs; |
||
246 | current_bandwidth+=server_list[i].U; |
||
247 | } |
||
248 | |||
249 | #ifdef FSF_DEBUG |
||
250 | kern_printf("(Total Quality %d)", Qt); |
||
251 | #endif |
||
252 | isok=1; |
||
253 | for (i=0; i<current_server; i++) { |
||
254 | if (server_list[i].Qs!=0 && server_list[i].U<server_list[i].Umax) { |
||
255 | temp_U=server_list[i].U; |
||
256 | server_list[i].U=U-current_bandwidth; |
||
257 | mul32div32to32(server_list[i].U, server_list[i].Qs, Qt, server_list[i].U); |
||
258 | temp_U+=server_list[i].U; |
||
259 | |||
260 | if (temp_U<=server_list[i].Umin) { |
||
261 | server_list[i].U=server_list[i].Umin; |
||
262 | } else if (temp_U>server_list[i].Umax) { |
||
263 | server_list[i].U=server_list[i].Umax; |
||
264 | isok=0; |
||
265 | } else server_list[i].U=temp_U; |
||
266 | |||
267 | #ifdef FSF_DEBUG |
||
268 | mul32div32to32(server_list[i].U,100, MAX_BANDWIDTH, temp); |
||
269 | kern_printf("(Server %d bw %d)", server_list[i].server, temp); |
||
270 | #endif |
||
271 | } |
||
272 | } |
||
273 | |||
274 | } while (!isok); |
||
275 | |||
276 | return 0; |
||
277 | } |
||
679 | trimarchi | 278 | #endif |