Subversion Repositories shark

Compare Revisions

Ignore whitespace Rev 404 → Rev 405

/shark/trunk/ports/first/first-server.c
11,6 → 11,8
// S.Ha.R.K. Implementation
//=====================================================================
 
#include "ll/i386/64bit.h"
 
#include "fsf_contract.h"
#include "fsf_server.h"
 
17,15 → 19,18
#include <pthread.h>
#include <stdlib.h>
 
//#define FSF_DEBUG
 
#define FSF_DEBUG
int current=0;
server_elem server_list[MAX_PROC];
bandwidth_t min_bandwidth=0;
int fsf_server_level;
 
int FSF_register_module(int server_level)
{
 
printk("FSF Module\n");
 
current=0;
fsf_server_level = server_level;
 
return 0;
56,7 → 61,7
local_scheduler_level = MPEGSTAR_register_level(fsf_server_level);
break;
}
 
*budget = SERVER_setbudget(fsf_server_level,
TIMESPEC2USEC(&(contract->budget_min)),
TIMESPEC2USEC(&(contract->period_max)),
66,14 → 71,14
 
}
 
int adjust_SERVER_budget_from_contract
(const fsf_contract_parameters_t *contract,
int budget)
int adjust_SERVER_budget
(int budget, const TIME budget_actual,
const TIME period_actual)
{
 
SERVER_adjust_budget(fsf_server_level,
TIMESPEC2USEC(&(contract->budget_min)),
TIMESPEC2USEC(&(contract->period_max)),
budget_actual,
period_actual,
budget);
 
return 0;
83,7 → 88,6
/* Admission Test function */
int add_contract(const fsf_contract_parameters_t *contract)
{
 
return 0;
 
}
91,7 → 95,38
int link_contract_to_server(const fsf_contract_parameters_t *contract,
fsf_server_id_t server)
{
TIME T,Q;
int temp;
#ifdef FSF_DEBUG
kern_printf("(Link Server %d)",server);
#endif
server_list[current].server=server;
server_list[current].Qs=1;
T=TIMESPEC2USEC(&contract->period_min);
Q=TIMESPEC2USEC(&contract->budget_max);
mul32div32to32(MAX_BANDWIDTH,Q,T,server_list[current].Umax);
T=TIMESPEC2USEC(&contract->period_max);
server_list[current].Tmax=T;
Q=TIMESPEC2USEC(&contract->budget_min);
server_list[current].Cmin=Q;
mul32div32to32(MAX_BANDWIDTH,Q,T,server_list[current].Umin);
min_bandwidth+=server_list[current].Umin;
server_list[current].U=server_list[current].Umax;
 
#ifdef FSF_DEBUG
mul32div32to32(server_list[current].Umax,100, MAX_BANDWIDTH, temp);
kern_printf("(Umax %d)",temp);
mul32div32to32(server_list[current].Umin,100, MAX_BANDWIDTH, temp);
kern_printf("(Umin %d)",temp);
#endif
current++;
return 0;
 
}
98,7 → 133,29
 
int remove_contract(fsf_server_id_t server)
{
int i=0;
// find the contract
while(i<current) {
if (server_list[i].server==server) break;
i++;
}
 
// compress the array;
while (i<(current-1)) {
server_list[i].server=server_list[i+1].server;
TIMESPEC_ASSIGN(&(server_list[i+1].budget_actual), &(server_list[i].budget_actual));
TIMESPEC_ASSIGN(&(server_list[i+1].period_actual), &(server_list[i].period_actual));
server_list[i].Umin=server_list[i+1].Umin;
server_list[i].U=server_list[i+1].U;
server_list[i].Umax=server_list[i+1].Umax;
server_list[i].Cmin=server_list[i+1].Cmin;
server_list[i].Tmax=server_list[i+1].Tmax;
server_list[i].Qs=server_list[i+1].Qs;
i++;
}
current--;
 
 
return 0;
 
}
108,7 → 165,10
(const fsf_contract_parameters_t *contract,
fsf_server_id_t *server)
{
SYS_FLAGS f;
int i=0;
TIME T;
TIME Q;
/* Check if contract is initialized */
if (!contract) return FSF_ERR_NOT_INITIALIZED;
 
116,6 → 176,7
if (FSF_ADMISSION_TEST_IS_ENABLED)
if (add_contract(contract))
return FSF_ERR_CONTRACT_REJECTED;
f = kern_fsave();
 
/* SERVER => BUDGET */
set_SERVER_budget_from_contract(contract,server);
124,11 → 185,38
kern_printf("(New Server %d)",*server);
#endif
 
if (*server >= 0)
if (*server >= 0) {
link_contract_to_server(contract,*server);
else
if (recalculate_contract(MAX_BANDWIDTH)==-1) {
kern_frestore(f);
return FSF_ERR_CREATE_SERVER;
}
#ifdef FSF_DEBUG
kern_printf("(Adjust budget)");
#endif
for (i=0; i<current; 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)
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
adjust_SERVER_budget(server_list[i].server,Q, server_list[i].Tmax);
}
 
}
}
else {
kern_frestore(f);
return FSF_ERR_CREATE_SERVER;
 
}
kern_frestore(f);
return 0;
 
}
303,9 → 391,11
SERVER_removebudget(fsf_server_level,*server);
 
level_free_descriptor(local_scheduler_level);
 
remove_contract(*server);
 
recalculate_contract(MAX_BANDWIDTH);
 
*server = -1;
 
return 0;
312,11 → 402,73
 
}
 
int recalculate_contract(bandwidth_t U) {
long int current_bandwidth,temp_U;
int Qt;
int isok=0;
int i=0;
int temp;
#ifdef FSF_DEBUG
kern_printf("(Recalculate contract)");
#endif
 
/* The current bandwidth is the min bandwidth */
//current_bandwidth=SERVER_return_bandwidth(fsf_server_level);
#ifdef FSF_DEBUG
kern_printf("(nserver %d)", current);
#endif
do {
current_bandwidth=0;
Qt=0;
for (i=0; i<current; i++) {
if (server_list[i].U>server_list[i].Umin
&& server_list[i].Qs!=0)
Qt+=server_list[i].Qs;
current_bandwidth+=server_list[i].U;
}
#ifdef FSF_DEBUG
kern_printf("(Total Quality %d)", Qt);
#endif
isok=1;
for (i=0; i<current; i++) {
if (server_list[i].U>server_list[i].Umin &&
server_list[i].Qs!=0) {
temp_U=server_list[i].U;
temp_U=temp_U-(current_bandwidth-U)*server_list[i].Qs/Qt;
#ifdef FSF_DEBUG
mul32div32to32(temp_U,100, MAX_BANDWIDTH, temp);
kern_printf("(Server %d bw %d)", server_list[i].server, temp);
#endif
 
if (temp_U<server_list[i].Umin) {
server_list[i].U=server_list[i].Umin;
isok=0;
} else if (temp_U>=server_list[i].Umax) {
server_list[i].U=server_list[i].Umax;
} else server_list[i].U=temp_U;
#ifdef FSF_DEBUG
mul32div32to32(server_list[i].U,100, MAX_BANDWIDTH, temp);
kern_printf("(Server %d bw %d)", server_list[i].server, temp);
#endif
}
}
 
} while (!isok);
return 0;
}
 
int fsf_renegotiate_contract
(const fsf_contract_parameters_t *new_contract,
fsf_server_id_t server)
{
 
SYS_FLAGS f;
int i=0;
#ifdef FSF_DEBUG
kern_printf("(Renegotiate for server %d)",server);
#endif
326,8 → 478,18
 
if (server < 0)
return FSF_ERR_INVALID_SERVER;
 
return adjust_SERVER_budget_from_contract(new_contract,server);
 
// compute the new value
//
f = kern_fsave();
if (recalculate_contract(MAX_BANDWIDTH)==-1) {
kern_frestore(f);
return FSF_ERR_CREATE_SERVER;
}
/*
for (i=0; i<current; i++)
adjust_SERVER_budget(server_list[i].server,server_list[i].budget_actual, server_list[i].period_actual);
*/
kern_frestore(f);
return 0;
}