Rev 892 | Rev 897 | 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 | * |
||
893 | trimarchi | 37 | * CVS : $Id: server-task.c,v 1.11 2004-11-24 09:06:36 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; |
||
880 | trimarchi | 58 | struct timespec next_act; |
59 | struct timespec period; |
||
60 | struct timespec act_time; |
||
679 | trimarchi | 61 | PORT rec,tra; |
868 | trimarchi | 62 | |
679 | trimarchi | 63 | rec = port_connect("CHANW",sizeof(struct mess),STREAM,READ); |
668 | trimarchi | 64 | |
679 | trimarchi | 65 | tra = port_connect("CHANR",sizeof(struct mess),STREAM,WRITE); |
668 | trimarchi | 66 | |
67 | while(1) { |
||
868 | trimarchi | 68 | // wait for operation |
69 | if (wait_renegotiation) { |
||
70 | if (!fsf_get_renegotiation_status(msg.server,&status)) { |
||
71 | if (status==FSF_ADMITTED) { |
||
72 | // send response server is -1 if the operation fail |
||
73 | #ifdef FSF_DEBUG |
||
74 | kern_printf("ADM"); |
||
75 | #endif |
||
76 | wait_renegotiation=0; |
||
77 | port_send(tra,&msg,BLOCK); |
||
880 | trimarchi | 78 | //kern_gettime(&act_time); |
79 | //fsf_get_budget_and_period(service_server,NULL,&period); |
||
80 | //ADDTIMESPEC(&act_time, &period, &next_act); |
||
81 | //fsf_schedule_next_timed_job(&next_act,NULL,NULL,NULL,NULL); |
||
868 | trimarchi | 82 | continue; |
83 | } else |
||
84 | #ifdef FSF_DEBUG |
||
85 | kern_printf("WAIT") |
||
86 | #endif |
||
87 | ; |
||
88 | } |
||
89 | } else { |
||
90 | port_receive(rec,&msg,BLOCK); |
||
877 | trimarchi | 91 | #ifdef FSF_DEBUG |
868 | trimarchi | 92 | kern_printf("Message "); |
877 | trimarchi | 93 | #endif |
868 | trimarchi | 94 | switch (msg.type) { |
95 | |||
96 | case NEGOTIATE_CONTRACT: |
||
97 | if (negotiate_contract(&msg.contract, &msg.server)==FSF_ERR_CONTRACT_REJECTED) |
||
98 | msg.server=-1; |
||
880 | trimarchi | 99 | else { |
100 | wait_renegotiation=1; |
||
101 | //task_endcycle(); |
||
102 | continue; |
||
103 | } |
||
104 | break; |
||
868 | trimarchi | 105 | |
106 | case REQUEST_RENEGOTIATE_CONTRACT: |
||
107 | if (renegotiate_contract(&msg.contract, msg.server)==FSF_ERR_CONTRACT_REJECTED) |
||
108 | msg.server=-1; |
||
109 | break; |
||
110 | |||
111 | case RENEGOTIATE_CONTRACT: |
||
112 | if (renegotiate_contract(&msg.contract, msg.server)==FSF_ERR_CONTRACT_REJECTED) |
||
113 | msg.server=-1; |
||
114 | else { |
||
115 | wait_renegotiation=1; |
||
116 | //task_endcycle(); |
||
117 | continue; |
||
118 | } |
||
119 | break; |
||
893 | trimarchi | 120 | case CHANGE_PARAMETER: |
121 | // this CASE change the quality and importance |
||
122 | break; |
||
123 | |||
868 | trimarchi | 124 | default : |
125 | break; |
||
126 | |||
127 | } |
||
128 | // send response server is -1 if the operation fail |
||
129 | port_send(tra,&msg,BLOCK); |
||
880 | trimarchi | 130 | //kern_gettime(&act_time); |
131 | //fsf_get_budget_and_period(service_server,NULL,&period); |
||
132 | //ADDTIMESPEC(&act_time, &period, &next_act); |
||
133 | //fsf_schedule_next_timed_job(&next_act,NULL,NULL,NULL,NULL); |
||
868 | trimarchi | 134 | //task_endcycle(); |
880 | trimarchi | 135 | //kern_printf("(ES)"); |
668 | trimarchi | 136 | } |
137 | } |
||
138 | } |
||
139 | |||
688 | trimarchi | 140 | |
141 | static __inline void set_contract_parameter(void) { |
||
142 | |||
143 | int i=0; |
||
679 | trimarchi | 144 | TIME T,Q; |
868 | trimarchi | 145 | |
146 | for (i=0; i<current_server; i++) { |
||
679 | trimarchi | 147 | mul32div32to32(MAX_BANDWIDTH,server_list[i].Cmin,server_list[i].U,T); |
148 | if (T > server_list[i].Tmin ) { |
||
149 | server_list[i].actual_budget = server_list[i].Cmin; |
||
150 | server_list[i].actual_period = T; |
||
151 | #ifdef FSF_DEBUG |
||
152 | kern_printf("(1 - Q %ld T %ld)", server_list[i].actual_budget, server_list[i].actual_period); |
||
153 | #endif |
||
892 | trimarchi | 154 | if (server_list[i].d_equals_t == true) |
679 | trimarchi | 155 | adjust_SERVER_budget(server_list[i].server,server_list[i].Cmin, T, T); |
156 | else |
||
157 | adjust_SERVER_budget(server_list[i].server,server_list[i].Cmin, T, server_list[i].deadline); |
||
158 | |||
159 | } else { |
||
160 | mul32div32to32(server_list[i].Tmin,server_list[i].U,MAX_BANDWIDTH,Q); |
||
161 | server_list[i].actual_budget = Q; |
||
162 | server_list[i].actual_period = server_list[i].Tmin; |
||
163 | #ifdef FSF_DEBUG |
||
164 | kern_printf("(2 - Q %ld T %ld)", server_list[i].actual_budget, server_list[i].actual_period); |
||
165 | #endif |
||
166 | |||
892 | trimarchi | 167 | if (server_list[i].d_equals_t == true) |
679 | trimarchi | 168 | adjust_SERVER_budget(server_list[i].server,server_list[i].Cmin, server_list[i].Tmin, server_list[i].Tmin); |
169 | else |
||
170 | adjust_SERVER_budget(server_list[i].server,server_list[i].Cmin, server_list[i].Tmin, server_list[i].deadline); |
||
171 | } |
||
172 | |||
173 | server_list[i].U=server_list[i].Umin; |
||
174 | } |
||
175 | |||
688 | trimarchi | 176 | } |
177 | |||
178 | |||
179 | int renegotiate_contract |
||
180 | (const fsf_contract_parameters_t *new_contract, |
||
181 | fsf_server_id_t server) |
||
182 | { |
||
183 | |||
184 | #ifdef FSF_DEBUG |
||
185 | kern_printf("(Renegotiate for server %d)",server); |
||
186 | #endif |
||
187 | |||
188 | if (!new_contract) |
||
868 | trimarchi | 189 | return FSF_ERR_BAD_ARGUMENT; |
688 | trimarchi | 190 | |
191 | if (server < 0) |
||
875 | trimarchi | 192 | return FSF_ERR_BAD_ARGUMENT; |
688 | trimarchi | 193 | |
194 | // change the parameter |
||
195 | relink_contract_to_server(new_contract, server); |
||
196 | if (recalculate_contract(fsf_max_bw)==-1) { |
||
875 | trimarchi | 197 | return FSF_ERR_CONTRACT_REJECTED; |
688 | trimarchi | 198 | } |
199 | |||
200 | set_contract_parameter(); |
||
201 | |||
679 | trimarchi | 202 | return 0; |
203 | } |
||
204 | |||
668 | trimarchi | 205 | int negotiate_contract |
679 | trimarchi | 206 | (const fsf_contract_parameters_t *contract, |
207 | fsf_server_id_t *server) |
||
668 | trimarchi | 208 | { |
209 | /* Check if contract is initialized */ |
||
868 | trimarchi | 210 | if (!contract) return FSF_ERR_BAD_ARGUMENT; |
668 | trimarchi | 211 | |
212 | /* Admission Test */ |
||
213 | if (FSF_ADMISSION_TEST_IS_ENABLED) |
||
214 | if (add_contract(contract)) |
||
215 | return FSF_ERR_CONTRACT_REJECTED; |
||
216 | |||
679 | trimarchi | 217 | /* SERVER => BUDGET */ |
218 | set_SERVER_budget_from_contract(contract,server); |
||
668 | trimarchi | 219 | |
688 | trimarchi | 220 | #ifdef FSF_DEBUG |
221 | kern_printf("(New Server %d)",*server); |
||
222 | #endif |
||
679 | trimarchi | 223 | |
224 | if (*server >= 0) { |
||
225 | link_contract_to_server(contract,*server); |
||
226 | if (recalculate_contract(fsf_max_bw)==-1) { |
||
868 | trimarchi | 227 | remove_contract(server); |
875 | trimarchi | 228 | return FSF_ERR_CONTRACT_REJECTED; |
679 | trimarchi | 229 | } |
688 | trimarchi | 230 | set_contract_parameter(); |
679 | trimarchi | 231 | #ifdef FSF_DEBUG |
232 | kern_printf("(Adjust budget)"); |
||
233 | #endif |
||
688 | trimarchi | 234 | |
679 | trimarchi | 235 | } |
236 | else { |
||
875 | trimarchi | 237 | return FSF_ERR_CONTRACT_REJECTED; |
679 | trimarchi | 238 | } |
880 | trimarchi | 239 | //kern_printf("(ENCR)"); |
679 | trimarchi | 240 | return 0; |
241 | |||
668 | trimarchi | 242 | } |
243 |