Subversion Repositories shark

Compare Revisions

Ignore whitespace Rev 409 → Rev 410

/shark/trunk/ports/first/first-server.c
21,7 → 21,7
 
//#define FSF_DEBUG
 
int current=0;
int current_server=0;
server_elem server_list[FSF_MAX_N_SERVERS];
bandwidth_t fsf_max_bw = 0;
30,7 → 30,7
int FSF_register_module(int server_level, bandwidth_t max_bw)
{
printk("FSF Module\n");
current=0;
current_server=0;
fsf_server_level = server_level;
fsf_max_bw = max_bw;
 
93,6 → 93,48
 
}
 
int relink_contract_to_server(const fsf_contract_parameters_t *contract,
fsf_server_id_t server)
{
TIME T,Q;
int i=0;
#ifdef FSF_DEBUG
int temp;
kern_printf("(Relink Server %d)",server);
#endif
// find contract
while(i<current_server) {
if (server_list[i].server==server) break;
i++;
}
 
server_list[i].server=server;
server_list[i].Qs=1;
T=TIMESPEC2USEC(&contract->period_min);
Q=TIMESPEC2USEC(&contract->budget_max);
mul32div32to32(MAX_BANDWIDTH,Q,T,server_list[current_server].Umax);
T=TIMESPEC2USEC(&contract->period_max);
server_list[i].Tmax=T;
Q=TIMESPEC2USEC(&contract->budget_min);
server_list[i].Cmin=Q;
mul32div32to32(MAX_BANDWIDTH,Q,T,server_list[i].Umin);
server_list[i].U=server_list[i].Umax;
#ifdef FSF_DEBUG
mul32div32to32(server_list[i].Umax,100, MAX_BANDWIDTH, temp);
kern_printf("(Umax %d)",temp);
mul32div32to32(server_list[i].Umin,100, MAX_BANDWIDTH, temp);
kern_printf("(Umin %d)",temp);
#endif
 
return 0;
}
 
int link_contract_to_server(const fsf_contract_parameters_t *contract,
fsf_server_id_t server)
{
103,31 → 145,31
kern_printf("(Link Server %d)",server);
#endif
server_list[current].server=server;
server_list[current].Qs=1;
server_list[current_server].server=server;
server_list[current_server].Qs=1;
T=TIMESPEC2USEC(&contract->period_min);
Q=TIMESPEC2USEC(&contract->budget_max);
mul32div32to32(MAX_BANDWIDTH,Q,T,server_list[current].Umax);
mul32div32to32(MAX_BANDWIDTH,Q,T,server_list[current_server].Umax);
T=TIMESPEC2USEC(&contract->period_max);
server_list[current].Tmax=T;
server_list[current_server].Tmax=T;
Q=TIMESPEC2USEC(&contract->budget_min);
server_list[current].Cmin=Q;
server_list[current_server].Cmin=Q;
mul32div32to32(MAX_BANDWIDTH,Q,T,server_list[current].Umin);
server_list[current].U=server_list[current].Umax;
mul32div32to32(MAX_BANDWIDTH,Q,T,server_list[current_server].Umin);
server_list[current_server].U=server_list[current_server].Umax;
 
#ifdef FSF_DEBUG
mul32div32to32(server_list[current].Umax,100, MAX_BANDWIDTH, temp);
mul32div32to32(server_list[current_server].Umax,100, MAX_BANDWIDTH, temp);
kern_printf("(Umax %d)",temp);
mul32div32to32(server_list[current].Umin,100, MAX_BANDWIDTH, temp);
mul32div32to32(server_list[current_server].Umin,100, MAX_BANDWIDTH, temp);
kern_printf("(Umin %d)",temp);
#endif
current++;
current_server++;
return 0;
 
}
136,13 → 178,13
{
int i=0;
// find the contract
while(i<current) {
while(i<current_server) {
if (server_list[i].server==server) break;
i++;
}
 
// compress the array;
while (i<(current-1)) {
while (i<(current_server-1)) {
server_list[i].server=server_list[i+1].server;
server_list[i].Umin=server_list[i+1].Umin;
server_list[i].U=server_list[i+1].Umax;
152,7 → 194,7
server_list[i].Qs=server_list[i+1].Qs;
i++;
}
current--;
current_server--;
 
 
return 0;
193,7 → 235,7
#ifdef FSF_DEBUG
kern_printf("(Adjust budget)");
#endif
for (i=0; i<current; i++) {
for (i=0; i<current_server; i++) {
mul32div32to32(MAX_BANDWIDTH,server_list[i].Cmin,server_list[i].U,T);
#ifdef FSF_DEBUG
kern_printf("(T %ld)", T);
421,13 → 463,13
/* The current bandwidth is the min bandwidth */
//current_bandwidth=SERVER_return_bandwidth(fsf_server_level);
#ifdef FSF_DEBUG
kern_printf("(nserver %d)", current);
kern_printf("(nserver %d)", current_server);
#endif
do {
current_bandwidth=0;
Qt=0;
for (i=0; i<current; i++) {
for (i=0; i<current_server; i++) {
if (server_list[i].Qs!=0 && server_list[i].U>server_list[i].Umin)
Qt+=server_list[i].Qs;
current_bandwidth+=server_list[i].U;
437,7 → 479,7
kern_printf("(Total Quality %d)", Qt);
#endif
isok=1;
for (i=0; i<current; i++) {
for (i=0; i<current_server; i++) {
if (server_list[i].Qs!=0 && server_list[i].U>server_list[i].Umin) {
temp_U=server_list[i].U;
temp_U=temp_U-(current_bandwidth-U)*server_list[i].Qs/Qt;
466,7 → 508,10
(const fsf_contract_parameters_t *new_contract,
fsf_server_id_t server)
{
SYS_FLAGS f;
SYS_FLAGS f;
TIME T,Q;
int i;
#ifdef FSF_DEBUG
kern_printf("(Renegotiate for server %d)",server);
#endif
477,13 → 522,34
if (server < 0)
return FSF_ERR_INVALID_SERVER;
// compute the new value
//
f = kern_fsave();
// change the parameter
relink_contract_to_server(new_contract, server);
if (recalculate_contract(fsf_max_bw)==-1) {
kern_frestore(f);
return FSF_ERR_CREATE_SERVER;
}
for (i=0; i<current_server; i++) {
mul32div32to32(MAX_BANDWIDTH,server_list[i].Cmin,server_list[i].U,T);
#ifdef FSF_DEBUG
kern_printf("(T %ld)", T);
#endif
if (T<=server_list[i].Tmax) {
server_list[i].actual_budget = server_list[i].Cmin;
server_list[i].actual_period = T;
adjust_SERVER_budget(server_list[i].server,server_list[i].Cmin, T);
} else {
mul32div32to32(server_list[i].Tmax,server_list[i].U,MAX_BANDWIDTH,Q);
#ifdef FSF_DEBUG
kern_printf("(Q %ld)", Q);
#endif
server_list[i].actual_budget = Q;
server_list[i].actual_period = server_list[i].Tmax;
adjust_SERVER_budget(server_list[i].server,Q, server_list[i].Tmax);
}
server_list[i].U=server_list[i].Umax;
}
kern_frestore(f);
return 0;
}
495,7 → 561,7
kern_printf("Server List\n");
for(i=0;i<current;i++) {
for(i=0;i<current_server;i++) {
 
kern_printf("[%d] Q:%d T:%d\n",server_list[i].server,(int)server_list[i].actual_budget,(int)server_list[i].actual_period);