Subversion Repositories shark

Rev

Rev 843 | Rev 875 | 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
 *
868 trimarchi 37
 * CVS :        $Id: server-task.c,v 1.6 2004-10-25 14:40:58 trimarchi Exp $
668 trimarchi 38
 */
39
 
679 trimarchi 40
#include "ll/i386/64bit.h"
868 trimarchi 41
#include "fsf_configuration_parameters.h"
42
#include "fsf_core.h"
43
#include "fsf_server.h"
44
#include "fsf_service_task.h"
45
#include "message.h"
668 trimarchi 46
#include <kernel/kern.h>
679 trimarchi 47
#include <modules/sem.h>
48
#include <modules/hartport.h>
668 trimarchi 49
#include <modules/cabs.h>
50
 
868 trimarchi 51
//#define FSF_DEBUG
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;
679 trimarchi 58
  PORT rec,tra;
868 trimarchi 59
 
679 trimarchi 60
  rec = port_connect("CHANW",sizeof(struct mess),STREAM,READ);
668 trimarchi 61
 
679 trimarchi 62
  tra = port_connect("CHANR",sizeof(struct mess),STREAM,WRITE);
668 trimarchi 63
 
64
  while(1) {
868 trimarchi 65
    // wait for operation
66
    if (wait_renegotiation) {
67
      if (!fsf_get_renegotiation_status(msg.server,&status)) {
68
        if (status==FSF_ADMITTED) {
69
          // send response server is -1 if the operation fail
70
#ifdef FSF_DEBUG
71
          kern_printf("ADM");
72
#endif
73
          wait_renegotiation=0;
74
          port_send(tra,&msg,BLOCK);
75
          //task_endcycle();
76
          continue;
77
        } else
78
#ifdef FSF_DEBUG
79
          kern_printf("WAIT")
80
#endif
81
;
82
      }
83
    } else {
84
      port_receive(rec,&msg,BLOCK);
85
      kern_printf("Message ");
86
      switch (msg.type) {
87
 
88
      case NEGOTIATE_CONTRACT:
89
        if (negotiate_contract(&msg.contract, &msg.server)==FSF_ERR_CONTRACT_REJECTED)
90
          msg.server=-1;       
91
        break;
92
 
93
      case REQUEST_RENEGOTIATE_CONTRACT:
94
        if (renegotiate_contract(&msg.contract, msg.server)==FSF_ERR_CONTRACT_REJECTED)
95
          msg.server=-1;
96
        break;
97
 
98
      case RENEGOTIATE_CONTRACT:
99
        if (renegotiate_contract(&msg.contract, msg.server)==FSF_ERR_CONTRACT_REJECTED)
100
          msg.server=-1;
101
        else {
102
          wait_renegotiation=1;
103
          //task_endcycle();
104
          continue;
105
        }
106
        break;                   
107
 
108
      default :
109
        break;
110
 
111
      }
112
      // send response server is -1 if the operation fail
113
      port_send(tra,&msg,BLOCK);
114
      //task_endcycle();
668 trimarchi 115
 
116
    }
117
  }
118
}
119
 
688 trimarchi 120
 
121
static __inline void set_contract_parameter(void) {
122
 
123
  int i=0;
679 trimarchi 124
  TIME T,Q;
868 trimarchi 125
 
126
  for (i=0; i<current_server; i++) {
679 trimarchi 127
      mul32div32to32(MAX_BANDWIDTH,server_list[i].Cmin,server_list[i].U,T);
128
      if (T > server_list[i].Tmin ) {
129
         server_list[i].actual_budget = server_list[i].Cmin;
130
         server_list[i].actual_period = T;
131
      #ifdef FSF_DEBUG
132
         kern_printf("(1 - Q %ld T %ld)", server_list[i].actual_budget, server_list[i].actual_period);
133
      #endif
134
         if (server_list[i].d_equals_t == TRUE)
135
           adjust_SERVER_budget(server_list[i].server,server_list[i].Cmin, T, T);
136
         else
137
           adjust_SERVER_budget(server_list[i].server,server_list[i].Cmin, T, server_list[i].deadline);
138
 
139
      } else {
140
        mul32div32to32(server_list[i].Tmin,server_list[i].U,MAX_BANDWIDTH,Q);
141
        server_list[i].actual_budget = Q;
142
        server_list[i].actual_period = server_list[i].Tmin;
143
      #ifdef FSF_DEBUG
144
         kern_printf("(2 - Q %ld T %ld)", server_list[i].actual_budget, server_list[i].actual_period);
145
      #endif
146
 
147
         if (server_list[i].d_equals_t == TRUE)
148
           adjust_SERVER_budget(server_list[i].server,server_list[i].Cmin, server_list[i].Tmin, server_list[i].Tmin);
149
         else
150
           adjust_SERVER_budget(server_list[i].server,server_list[i].Cmin, server_list[i].Tmin, server_list[i].deadline);                                                                                                        
151
     }
152
 
153
     server_list[i].U=server_list[i].Umin;
154
   }
155
 
688 trimarchi 156
}
157
 
158
 
159
int renegotiate_contract
160
  (const fsf_contract_parameters_t *new_contract,
161
   fsf_server_id_t                 server)
162
{
163
 
164
  #ifdef FSF_DEBUG
165
    kern_printf("(Renegotiate for server %d)",server);
166
  #endif
167
 
168
  if (!new_contract)
868 trimarchi 169
    return  FSF_ERR_BAD_ARGUMENT;
688 trimarchi 170
 
171
  if (server < 0)
172
    return FSF_ERR_INVALID_SERVER;
173
 
174
   // change the parameter
175
   relink_contract_to_server(new_contract, server);
176
   if (recalculate_contract(fsf_max_bw)==-1)  {
177
       return FSF_ERR_CREATE_SERVER;
178
   }
179
 
180
   set_contract_parameter();
181
 
679 trimarchi 182
   return 0;
183
}
184
 
668 trimarchi 185
int negotiate_contract
679 trimarchi 186
  (const fsf_contract_parameters_t *contract,
187
   fsf_server_id_t                 *server)
668 trimarchi 188
{
189
  /* Check if contract is initialized */
868 trimarchi 190
  if (!contract) return  FSF_ERR_BAD_ARGUMENT;
668 trimarchi 191
 
192
  /* Admission Test */
193
  if (FSF_ADMISSION_TEST_IS_ENABLED)
194
    if (add_contract(contract))
195
      return FSF_ERR_CONTRACT_REJECTED;
196
 
679 trimarchi 197
  /* SERVER => BUDGET */    
198
  set_SERVER_budget_from_contract(contract,server);
668 trimarchi 199
 
688 trimarchi 200
#ifdef FSF_DEBUG
201
  kern_printf("(New Server %d)",*server);
202
#endif
679 trimarchi 203
 
204
  if (*server >= 0) {
205
    link_contract_to_server(contract,*server);
206
    if (recalculate_contract(fsf_max_bw)==-1)  {
868 trimarchi 207
      remove_contract(server);
688 trimarchi 208
      return FSF_ERR_CREATE_SERVER;
679 trimarchi 209
    }
688 trimarchi 210
    set_contract_parameter();
679 trimarchi 211
#ifdef  FSF_DEBUG
212
    kern_printf("(Adjust budget)");
213
#endif    
688 trimarchi 214
 
679 trimarchi 215
  }
216
  else  {
217
    return FSF_ERR_CREATE_SERVER;
218
  }
688 trimarchi 219
 
679 trimarchi 220
  return 0;
221
 
668 trimarchi 222
}
223