Subversion Repositories shark

Rev

Rev 877 | Rev 892 | 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
 *
880 trimarchi 37
 * CVS :        $Id: server-task.c,v 1.9 2004-11-16 09:24:45 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;                   
120
 
121
      default :
122
        break;
123
 
124
      }
125
      // send response server is -1 if the operation fail
126
      port_send(tra,&msg,BLOCK);
880 trimarchi 127
      //kern_gettime(&act_time);
128
      //fsf_get_budget_and_period(service_server,NULL,&period);
129
      //ADDTIMESPEC(&act_time, &period, &next_act);
130
      //fsf_schedule_next_timed_job(&next_act,NULL,NULL,NULL,NULL);
868 trimarchi 131
      //task_endcycle();
880 trimarchi 132
      //kern_printf("(ES)");
668 trimarchi 133
    }
134
  }
135
}
136
 
688 trimarchi 137
 
138
static __inline void set_contract_parameter(void) {
139
 
140
  int i=0;
679 trimarchi 141
  TIME T,Q;
868 trimarchi 142
 
143
  for (i=0; i<current_server; i++) {
679 trimarchi 144
      mul32div32to32(MAX_BANDWIDTH,server_list[i].Cmin,server_list[i].U,T);
145
      if (T > server_list[i].Tmin ) {
146
         server_list[i].actual_budget = server_list[i].Cmin;
147
         server_list[i].actual_period = T;
148
      #ifdef FSF_DEBUG
149
         kern_printf("(1 - Q %ld T %ld)", server_list[i].actual_budget, server_list[i].actual_period);
150
      #endif
151
         if (server_list[i].d_equals_t == TRUE)
152
           adjust_SERVER_budget(server_list[i].server,server_list[i].Cmin, T, T);
153
         else
154
           adjust_SERVER_budget(server_list[i].server,server_list[i].Cmin, T, server_list[i].deadline);
155
 
156
      } else {
157
        mul32div32to32(server_list[i].Tmin,server_list[i].U,MAX_BANDWIDTH,Q);
158
        server_list[i].actual_budget = Q;
159
        server_list[i].actual_period = server_list[i].Tmin;
160
      #ifdef FSF_DEBUG
161
         kern_printf("(2 - Q %ld T %ld)", server_list[i].actual_budget, server_list[i].actual_period);
162
      #endif
163
 
164
         if (server_list[i].d_equals_t == TRUE)
165
           adjust_SERVER_budget(server_list[i].server,server_list[i].Cmin, server_list[i].Tmin, server_list[i].Tmin);
166
         else
167
           adjust_SERVER_budget(server_list[i].server,server_list[i].Cmin, server_list[i].Tmin, server_list[i].deadline);                                                                                                        
168
     }
169
 
170
     server_list[i].U=server_list[i].Umin;
171
   }
172
 
688 trimarchi 173
}
174
 
175
 
176
int renegotiate_contract
177
  (const fsf_contract_parameters_t *new_contract,
178
   fsf_server_id_t                 server)
179
{
180
 
181
  #ifdef FSF_DEBUG
182
    kern_printf("(Renegotiate for server %d)",server);
183
  #endif
184
 
185
  if (!new_contract)
868 trimarchi 186
    return  FSF_ERR_BAD_ARGUMENT;
688 trimarchi 187
 
188
  if (server < 0)
875 trimarchi 189
    return  FSF_ERR_BAD_ARGUMENT;
688 trimarchi 190
 
191
   // change the parameter
192
   relink_contract_to_server(new_contract, server);
193
   if (recalculate_contract(fsf_max_bw)==-1)  {
875 trimarchi 194
       return  FSF_ERR_CONTRACT_REJECTED;
688 trimarchi 195
   }
196
 
197
   set_contract_parameter();
198
 
679 trimarchi 199
   return 0;
200
}
201
 
668 trimarchi 202
int negotiate_contract
679 trimarchi 203
  (const fsf_contract_parameters_t *contract,
204
   fsf_server_id_t                 *server)
668 trimarchi 205
{
206
  /* Check if contract is initialized */
868 trimarchi 207
  if (!contract) return  FSF_ERR_BAD_ARGUMENT;
668 trimarchi 208
 
209
  /* Admission Test */
210
  if (FSF_ADMISSION_TEST_IS_ENABLED)
211
    if (add_contract(contract))
212
      return FSF_ERR_CONTRACT_REJECTED;
213
 
679 trimarchi 214
  /* SERVER => BUDGET */    
215
  set_SERVER_budget_from_contract(contract,server);
668 trimarchi 216
 
688 trimarchi 217
#ifdef FSF_DEBUG
218
  kern_printf("(New Server %d)",*server);
219
#endif
679 trimarchi 220
 
221
  if (*server >= 0) {
222
    link_contract_to_server(contract,*server);
223
    if (recalculate_contract(fsf_max_bw)==-1)  {
868 trimarchi 224
      remove_contract(server);
875 trimarchi 225
      return  FSF_ERR_CONTRACT_REJECTED;
679 trimarchi 226
    }
688 trimarchi 227
    set_contract_parameter();
679 trimarchi 228
#ifdef  FSF_DEBUG
229
    kern_printf("(Adjust budget)");
230
#endif    
688 trimarchi 231
 
679 trimarchi 232
  }
233
  else  {
875 trimarchi 234
    return  FSF_ERR_CONTRACT_REJECTED;
679 trimarchi 235
  }
880 trimarchi 236
  //kern_printf("(ENCR)"); 
679 trimarchi 237
  return 0;
238
 
668 trimarchi 239
}
240