Rev 681 | Rev 868 | 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 | * |
||
688 | trimarchi | 37 | * CVS : $Id: server-task.c,v 1.4 2004-05-26 13:44:55 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 | tra = port_connect("CHANR",sizeof(struct mess),STREAM,WRITE); |
668 | trimarchi | 59 | |
60 | while(1) { |
||
679 | trimarchi | 61 | // wait for renegotiation |
681 | trimarchi | 62 | port_receive(rec,&message,BLOCK); |
668 | trimarchi | 63 | switch (message.type) { |
64 | |||
65 | case NEGOTIATE_CONTRACT: |
||
679 | trimarchi | 66 | if (negotiate_contract(&message.contract, &message.server)==FSF_ERR_CONTRACT_REJECTED) |
67 | message.server=-1; |
||
668 | trimarchi | 68 | |
69 | break; |
||
70 | case RENEGOTIATE_CONTRACT: |
||
679 | trimarchi | 71 | if (renegotiate_contract(&message.contract, message.server)==FSF_ERR_CONTRACT_REJECTED) |
72 | message.server=-1; |
||
668 | trimarchi | 73 | break; |
74 | |||
75 | default : |
||
76 | break; |
||
77 | |||
78 | } |
||
679 | trimarchi | 79 | // send response server is -1 if the operation fail |
681 | trimarchi | 80 | port_send(tra,&message,BLOCK); |
668 | trimarchi | 81 | |
82 | task_endcycle(); |
||
83 | |||
84 | } |
||
85 | } |
||
86 | |||
688 | trimarchi | 87 | |
88 | static __inline void set_contract_parameter(void) { |
||
89 | |||
90 | int i=0; |
||
679 | trimarchi | 91 | TIME T,Q; |
92 | |||
93 | for (i=0; i<current_server; i++) { |
||
94 | mul32div32to32(MAX_BANDWIDTH,server_list[i].Cmin,server_list[i].U,T); |
||
95 | if (T > server_list[i].Tmin ) { |
||
96 | server_list[i].actual_budget = server_list[i].Cmin; |
||
97 | server_list[i].actual_period = T; |
||
98 | #ifdef FSF_DEBUG |
||
99 | kern_printf("(1 - Q %ld T %ld)", server_list[i].actual_budget, server_list[i].actual_period); |
||
100 | #endif |
||
101 | if (server_list[i].d_equals_t == TRUE) |
||
102 | adjust_SERVER_budget(server_list[i].server,server_list[i].Cmin, T, T); |
||
103 | else |
||
104 | adjust_SERVER_budget(server_list[i].server,server_list[i].Cmin, T, server_list[i].deadline); |
||
105 | |||
106 | } else { |
||
107 | mul32div32to32(server_list[i].Tmin,server_list[i].U,MAX_BANDWIDTH,Q); |
||
108 | server_list[i].actual_budget = Q; |
||
109 | server_list[i].actual_period = server_list[i].Tmin; |
||
110 | #ifdef FSF_DEBUG |
||
111 | kern_printf("(2 - Q %ld T %ld)", server_list[i].actual_budget, server_list[i].actual_period); |
||
112 | #endif |
||
113 | |||
114 | if (server_list[i].d_equals_t == TRUE) |
||
115 | adjust_SERVER_budget(server_list[i].server,server_list[i].Cmin, server_list[i].Tmin, server_list[i].Tmin); |
||
116 | else |
||
117 | adjust_SERVER_budget(server_list[i].server,server_list[i].Cmin, server_list[i].Tmin, server_list[i].deadline); |
||
118 | } |
||
119 | |||
120 | server_list[i].U=server_list[i].Umin; |
||
121 | } |
||
122 | |||
688 | trimarchi | 123 | } |
124 | |||
125 | |||
126 | int renegotiate_contract |
||
127 | (const fsf_contract_parameters_t *new_contract, |
||
128 | fsf_server_id_t server) |
||
129 | { |
||
130 | |||
131 | #ifdef FSF_DEBUG |
||
132 | kern_printf("(Renegotiate for server %d)",server); |
||
133 | #endif |
||
134 | |||
135 | if (!new_contract) |
||
136 | return FSF_ERR_NOT_INITIALIZED; |
||
137 | |||
138 | if (server < 0) |
||
139 | return FSF_ERR_INVALID_SERVER; |
||
140 | |||
141 | // change the parameter |
||
142 | relink_contract_to_server(new_contract, server); |
||
143 | if (recalculate_contract(fsf_max_bw)==-1) { |
||
144 | return FSF_ERR_CREATE_SERVER; |
||
145 | } |
||
146 | |||
147 | set_contract_parameter(); |
||
148 | |||
679 | trimarchi | 149 | return 0; |
150 | } |
||
151 | |||
668 | trimarchi | 152 | int negotiate_contract |
679 | trimarchi | 153 | (const fsf_contract_parameters_t *contract, |
154 | fsf_server_id_t *server) |
||
668 | trimarchi | 155 | { |
156 | /* Check if contract is initialized */ |
||
157 | if (!contract) return FSF_ERR_NOT_INITIALIZED; |
||
158 | |||
159 | /* Admission Test */ |
||
160 | if (FSF_ADMISSION_TEST_IS_ENABLED) |
||
161 | if (add_contract(contract)) |
||
162 | return FSF_ERR_CONTRACT_REJECTED; |
||
163 | |||
679 | trimarchi | 164 | /* SERVER => BUDGET */ |
165 | set_SERVER_budget_from_contract(contract,server); |
||
668 | trimarchi | 166 | |
688 | trimarchi | 167 | #ifdef FSF_DEBUG |
168 | kern_printf("(New Server %d)",*server); |
||
169 | #endif |
||
679 | trimarchi | 170 | |
171 | if (*server >= 0) { |
||
172 | link_contract_to_server(contract,*server); |
||
173 | if (recalculate_contract(fsf_max_bw)==-1) { |
||
688 | trimarchi | 174 | return FSF_ERR_CREATE_SERVER; |
679 | trimarchi | 175 | } |
688 | trimarchi | 176 | set_contract_parameter(); |
679 | trimarchi | 177 | #ifdef FSF_DEBUG |
178 | kern_printf("(Adjust budget)"); |
||
179 | #endif |
||
688 | trimarchi | 180 | |
679 | trimarchi | 181 | } |
182 | else { |
||
183 | return FSF_ERR_CREATE_SERVER; |
||
184 | } |
||
688 | trimarchi | 185 | |
679 | trimarchi | 186 | return 0; |
187 | |||
668 | trimarchi | 188 | } |
189 | |||
190 | |||
679 | trimarchi | 191 | #if defined MICHAEL |
668 | trimarchi | 192 | int recalculate_contract(bandwidth_t U) { |
193 | bandwidth_t current_bandwidth; |
||
194 | unsigned int temp_U; |
||
195 | int Qt; |
||
196 | int isok=0; |
||
197 | int i=0; |
||
198 | |||
199 | #ifdef FSF_DEBUG |
||
200 | int temp; |
||
201 | |||
202 | kern_printf("(Recalculate contract)"); |
||
203 | #endif |
||
204 | |||
205 | /* The current bandwidth is the min bandwidth */ |
||
206 | //current_bandwidth=SERVER_return_bandwidth(fsf_server_level); |
||
207 | #ifdef FSF_DEBUG |
||
208 | kern_printf("(nserver %d)", current_server); |
||
209 | #endif |
||
210 | |||
211 | do { |
||
212 | current_bandwidth=0; |
||
213 | Qt=0; |
||
214 | for (i=0; i<current_server; i++) { |
||
215 | if (server_list[i].Qs!=0 && server_list[i].U<server_list[i].Umax) |
||
216 | Qt+=server_list[i].Qs; |
||
217 | current_bandwidth+=server_list[i].U; |
||
218 | } |
||
219 | |||
220 | #ifdef FSF_DEBUG |
||
221 | kern_printf("(Total Quality %d)", Qt); |
||
222 | #endif |
||
223 | isok=1; |
||
224 | for (i=0; i<current_server; i++) { |
||
225 | if (server_list[i].Qs!=0 && server_list[i].U<server_list[i].Umax) { |
||
226 | temp_U=server_list[i].U; |
||
227 | server_list[i].U=U-current_bandwidth; |
||
228 | mul32div32to32(server_list[i].U, server_list[i].Qs, Qt, server_list[i].U); |
||
229 | temp_U+=server_list[i].U; |
||
230 | |||
231 | if (temp_U<=server_list[i].Umin) { |
||
232 | server_list[i].U=server_list[i].Umin; |
||
233 | } else if (temp_U>server_list[i].Umax) { |
||
234 | server_list[i].U=server_list[i].Umax; |
||
235 | isok=0; |
||
236 | } else server_list[i].U=temp_U; |
||
237 | |||
238 | #ifdef FSF_DEBUG |
||
239 | mul32div32to32(server_list[i].U,100, MAX_BANDWIDTH, temp); |
||
240 | kern_printf("(Server %d bw %d)", server_list[i].server, temp); |
||
241 | #endif |
||
242 | } |
||
243 | } |
||
244 | |||
245 | } while (!isok); |
||
246 | |||
247 | return 0; |
||
248 | } |
||
679 | trimarchi | 249 | #endif |