Subversion Repositories shark

Compare Revisions

Ignore whitespace Rev 948 → Rev 949

/shark/trunk/ports/first/fsf_include/tests/synch_obj_test/fsf_synch_obj_test.c
0,0 → 1,410
#include <stdio.h>
#include <unistd.h>
#include <time.h>
#include <errno.h>
 
#include <pthread.h>
#include <sched.h>
#include <fsf.h>
#include "timespec_operations.h"
#include "fsf_os_compatibility.h"
 
 
/*
 
* This is part of the common tests:
** Test of the synchronization object primitives
 
- Create two servers, server A and server B. Each with 5 seconds budget
and 20 seconds period (minimum values equal to the maximum ones),
preemption levels for A = 4 and for B = 3, A is INDETERMINATE workload
and B is BOUNDED workload. Deadline is 19.9 seconds for A and it is
equal to the period for B. Server A is bound to the main thread with
fsf_negotiate_contract_for_myself, server B is created with
fsf_negotiate_contract_for_new_thread.
- Once the main program becomes server A, it creates a Synch_object
and stores its reference in the global variable SO1_handle, then it
creates server B for a new thread and releases
the CPU for 0.5 second. The new thread in server B after starting,
just waits for SO1 to be signaled, after that it executes during 1 second,
then it waits for the the synchronization object SO1_handle to be signaled
again, and finally ends.
- After the first release of the CPU, the main thread in server A
signals SO1_handle and then releases the CPU for 0.5 second again,
after that it signals SO1_handle a second time and releases the CPU for 2 seconds.
Finally it destroy the synchronization object OS1 and ends.
*/
 
#define LOCAL_ERROR(nn,ss) {if(errno==0) errno=(nn); perror(ss); return (nn);}
//#define ERROR(nn,ss) {if(errno==0) errno=(nn); perror(ss); exit (nn);}
#define FSF_MAX_N_TIME_VALUES 1000
 
struct timespec instant_zero = {0,0};
int main_priority = 4;
struct timespec last_time = {0,0};
fsf_server_id_t server_A = 0;
fsf_server_id_t server_B = 0;
fsf_synch_obj_handle_t SO1_handle;
 
extern int cal_cycles;
extern int calibrate_cycle(void);
extern void eat(TIME wait);
 
struct pseudo_printed_results {
char *s;
struct timespec t;
} res[FSF_MAX_N_TIME_VALUES];
volatile int res_index = 0;
 
//reports the real-time it is
//with a comment and the difference to the last reported time
int
put_time(const struct timespec *time, char *s)
{
struct timespec now = {0,0};
int terror;
 
// if(time == (struct timespec *)NULL) {
if ((terror=clock_gettime(CLOCK_REALTIME,&now)))
ERROR(terror,"clock_gettime failed");
// }
// else {
// now = *time;
// }
 
res[res_index].s = s;
res[res_index].t = now;
 
// printf("(%2d)", res_index+1);
// printf("%-60s", s);
// printf(" %2d %9d\n", now.tv_sec,now.tv_nsec);
 
if (res_index < FSF_MAX_N_TIME_VALUES) res_index++;
return 0;
} /* End of put_time */
 
 
int
print_time_results()
{
struct timespec now = {0,0};
struct timespec diff = {0,0};
char *s = NULL;
int i;
 
printf("\n");
for (i=0;i<res_index;i++)
{
now = res[i].t;
s = res[i].s;
if (s==NULL) s = " - timestamp - ";
diff = now;
decr_timespec(&diff, &last_time);
last_time = now;
printf("(%2d)", i+1);
printf("%-60s", s);
printf(" %2d %9d", now.tv_sec,now.tv_nsec);
printf(" [diff=%13.9f]\n", (double)diff.tv_sec+((double)diff.tv_nsec/(double)1000000000));
}
 
return 0;
} /* End of print_time_results */
 
 
 
int
fsf_priority_map (unsigned long plevel)
{
return plevel;
}
 
 
void * fsf_bounded_server_B (void * arg)
{
//fsf_server_id_t in = *((fsf_server_id_t *)arg);
int terror=0;
 
//fsf_server_id_t server;
 
//struct timespec next_activation_time = in.offset;
struct timespec next_budget;
struct timespec next_period;
bool was_deadline_missed = 0;
bool was_budget_overran = 0;
 
//executes for 0.1 second
 
put_time(NULL, "B start one tenth of second execution ");
eat(100000);
put_time(NULL, "B complete one tenth of second execution");
 
//wait for the the synchronization object SO1_handle to be signaled
 
put_time(NULL, "B called first fsf_schedule_triggered_job ");
 
if ((terror=fsf_schedule_triggered_job (
SO1_handle,
&next_budget,
&next_period,
&was_deadline_missed,
&was_budget_overran)))
{
ERROR(terror,"fsf_bounded_server: first call to fsf_schedule_triggered_job failed");
}
put_time(NULL, "B returned from first fsf_schedule_triggered_job");
 
 
 
//executes for 1 second
 
put_time(NULL, "B start 1 second execution ");
eat(1000000);
put_time(NULL, "B complete the 1 second execution");
 
//wait for the the synchronization object SO1_handle to be signaled again
put_time(NULL, "B called fsf_schedule_triggered_job");
terror=fsf_schedule_triggered_job (
SO1_handle,
&next_budget,
&next_period,
&was_deadline_missed,
&was_budget_overran);
put_time(NULL, "B returned from fsf_schedule_triggered_job");
if (terror)
{
ERROR(terror,"fsf_bounded_server: second call to fsf_schedule_triggered_job failed");
}
 
 
//end
put_time(NULL, "B ends");
 
return 0;
 
} /* End of fsf_bounded_server_B */
 
 
 
int main()
{
struct sched_param param;
struct timespec half_second= {0,500000000};
struct timespec tmp = {0,0};
int terror = 0;
 
fsf_contract_parameters_t contract;
struct timespec budget_min = {7,0};
struct timespec period_max = {20,0};
struct timespec budget_max = {7,0};
struct timespec period_min = {20,0};
fsf_workload_t workload = FSF_INDETERMINATE;
 
bool d_equals_t = false;
struct timespec deadline = {19,900000000};
int budget_overrun_sig_notify = FSF_NULL_SIGNAL; // 0
union sigval budget_overrun_sig_value = {0};
int deadline_miss_sig_notify = FSF_NULL_SIGNAL; // 0
union sigval deadline_miss_sig_value = {0};
 
fsf_granularity_t granularity = FSF_DEFAULT_GRANULARITY; // CONTINUOUS
fsf_utilization_set_t *utilization_set = FSF_NULL_UTILIZATION_SET; // NULL
int quality = 1;
int importance = FSF_DEFAULT_IMPORTANCE; // 1
 
fsf_preemption_level_t preemption_level;
fsf_critical_sections_t *critical_sections = NULL;
 
pthread_t task_in_b;
 
calibrate_cycle();
fsf_init();
SERIAL_CONSOLE_INIT;
param.sched_priority = main_priority;
if ((terror=pthread_setschedparam(pthread_self(), SCHED_FIFO, &param)))
ERROR(terror,"pthread_setschedparam");
 
instant_zero.tv_sec = 10000000;
instant_zero.tv_nsec = 10000000;
clock_settime(CLOCK_REALTIME,&instant_zero);
clock_gettime(CLOCK_REALTIME,&instant_zero);
last_time = instant_zero;
put_time(&instant_zero, "instant_zero");
put_time(NULL, "printing point 1");
put_time(NULL, "printing point 2");
 
if ((terror=fsf_initialize_contract(&contract)))
{
printf(" Initialize fail for server A\n");
ERROR(terror,"fsf_initialize_contract failed");
}
 
if ((terror=fsf_set_contract_basic_parameters (&contract,
&budget_min,
&period_max,
workload)))
{
printf("Set_Basic_Parameters failed for server A\n");
ERROR(terror,"set_contract_basic_parameters failed");
}
 
if ((terror=fsf_set_contract_timing_requirements (&contract,
d_equals_t,
(d_equals_t?NULL:&deadline),
budget_overrun_sig_notify,
budget_overrun_sig_value,
deadline_miss_sig_notify,
deadline_miss_sig_value)))
{
printf("Set_Timing_Requirements failed for server A\n");
ERROR(terror,"fsf_set_contract_timing_requirements failed");
}
 
if ((terror=fsf_set_contract_reclamation_parameters (&contract,
&budget_max,
&period_min,
granularity,
utilization_set,
quality,
importance)))
{
printf("Set_Reclamation_Parameters failed for server A\n");
ERROR(terror,"fsf_set_contract_reclamation_parameters failed");
}
 
preemption_level = (fsf_preemption_level_t) param.sched_priority;
if ((terror=fsf_set_contract_synchronization_parameters (&contract,
critical_sections)))
{
printf("Set_Synchronization_Parameters failed for server A\n");
ERROR(terror,"fsf_set_contract_synchronization_parameters failed");
}
 
 
put_time(NULL, "A start first server contract negotiation");
terror = fsf_negotiate_contract_for_myself (&contract, &server_A);
put_time(NULL, "A end first server contract negotiation");
if (terror)
{
printf("Negotiate_Contract failed for server A\n");
ERROR(terror,"fsf_negotiate_contract_for_myself failed");
}
 
//creation of the synchronization object
put_time(NULL, "A start creating synchronization object");
terror=fsf_create_synch_obj(&SO1_handle);
put_time(NULL, "A end creating synchronization object");
if (terror)
{
ERROR(terror,"fsf_signal_synchobject failed");
}
 
 
//preparation of server B
workload = FSF_BOUNDED;
d_equals_t = true;
//deadline.tv_sec = deadline.tv_nsec = 0;
 
if ((terror=fsf_set_contract_basic_parameters (&contract,
&budget_min,
&period_max,
workload)))
{
printf("Set_Basic_Parameters failed for server B\n");
ERROR(terror,"set_contract_basic_parameters failed");
}
 
if ((terror=fsf_set_contract_timing_requirements (&contract,
d_equals_t,
(d_equals_t?NULL:&deadline),
budget_overrun_sig_notify,
budget_overrun_sig_value,
deadline_miss_sig_notify,
deadline_miss_sig_value)))
{
printf("Set_Timing_Requirements failed for server B\n");
ERROR(terror,"fsf_set_contract_timing_requirements failed");
}
 
preemption_level--;
if ((terror=fsf_set_contract_synchronization_parameters (&contract,
critical_sections)))
{
printf("Set_Synchronization_Parameters failed for server B\n");
ERROR(terror,"fsf_set_contract_synchronization_parameters failed");
}
 
put_time(NULL, "A starts server B contract negotiation");
terror=fsf_negotiate_contract_for_new_thread (&contract, &server_B, &task_in_b, NULL, fsf_bounded_server_B, NULL);
put_time(NULL, "A ends server B contract negotiation");
if (terror)
{
printf("Negotiate_Contract failed for server B\n");
ERROR(terror,"fsf_negotiate_contract_for_new_thread failed");
}
 
if(!server_B) ERROR((-1), "Contract B not accepted");
put_time(NULL, "A starts a half second nanosleep");
if ((terror=nanosleep(&half_second,NULL)))
ERROR(terror, "nanosleep 1 failed");
put_time(NULL, "A completes the half second nanosleep");
put_time(NULL, "A starts post-signaling synchronization object");
terror=fsf_signal_synch_obj(SO1_handle);
put_time(NULL, "A ends post-signaling synchronization object");
if (terror)
{
ERROR(terror,"fsf_signal_synchobject failed");
}
half_second.tv_sec = 3;
half_second.tv_nsec = 0;
put_time(NULL, "A starts another 3s nanosleep");
if ((terror=nanosleep(&half_second,NULL)))
ERROR(terror, "nanosleep 2 failed");
put_time(NULL, "A completes the other half second nanosleep");
put_time(NULL, "A starts pre-signaling synchronization object");
terror=fsf_signal_synch_obj(SO1_handle);
put_time(NULL, "A ends pre-signaling synchronization object");
if (terror)
{
ERROR(terror,"fsf_signal_synchobject failed");
}
tmp.tv_sec = 2;
tmp.tv_nsec = 0;
put_time(NULL, "A starts a final 2 seconds nanosleep");
if ((terror=nanosleep(&tmp,NULL)))
ERROR(terror, "third nanosleep failed");
put_time(NULL, "A ends the final 2 seconds nanosleep");
put_time(NULL, "A starts destroying synchronization object");
terror=fsf_destroy_synch_obj(SO1_handle);
put_time(NULL, "A ends destroying synchronization object");
if (terror)
{
ERROR(terror,"fsf_destroy_synchobject failed");
}
 
print_time_results();
STANDARD_CONSOLE_INIT; //marte1.26i+
 
//print_time_results();
 
printf("\nThe End.\n");
 
//stop_scheduler = 1;
 
exit(0);
return 0;
} /* End of main */
/shark/trunk/ports/first/fsf_include/tests/synch_obj_test/makefile
0,0 → 1,19
#
#
ifeq ($(OS), S)
BASE=../../../../..
OSNAME = shark_glue
export BASE
 
include $(BASE)/config/config.mk
endif
 
PROGS= $(OS)_$(WL)_synch_test
 
ifeq ($(OS), S)
include $(BASE)/config/example.mk
endif
 
$(OS)_$(WL)_synch_test:
make -f $(SUBMAKE) APPNAME=$(PROGS) APP=fsf_synch_obj_test INIT= OTHEROBJS="../$(OSNAME)/initfile.o ../$(OSNAME)/shark.o" OTHERINCL="-I../common" SHARKOPT="__INPUT__ __FIRST__ __NEW_TRACER__ __LINUXC26__ __PCI__ __NET__ __GRX__"
 
/shark/trunk/ports/first/fsf_include/tests/fsf_negotiation_test/makefile
0,0 → 1,19
#
#
ifeq ($(OS), S)
BASE=../../../../..
OSNAME = shark_glue
export BASE
 
include $(BASE)/config/config.mk
endif
 
PROGS= $(OS)_$(WL)_negotiation_test
 
ifeq ($(OS), S)
include $(BASE)/config/example.mk
endif
 
$(OS)_$(WL)_negotiation_test:
make -f $(SUBMAKE) APPNAME=$(PROGS) APP=fsf_negotiation_test INIT= OTHEROBJS="../$(OSNAME)/initfile.o ../$(OSNAME)/shark.o" OTHERINCL="-I../common" SHARKOPT="__INPUT__ __FIRST__ __NEW_TRACER__ __LINUXC26__ __PCI__ __NET__ __GRX__"
 
/shark/trunk/ports/first/fsf_include/tests/fsf_negotiation_test/fsf_negotiation_test.c
0,0 → 1,484
//=====================================================================
// FFFFFFIII RRRRR SSTTTTTTT
// FF IIR RR SS
// FF IR SS
// FFFFFF RRRR SSSSST
// FF FI RRR SS
// FF II RRR SS
// FF IIIIIR RS
//
// FIRST Scheduling Framework
//
//=====================================================================
 
 
 
#include <stdio.h>
#include <unistd.h>
#include <time.h>
#include <errno.h>
#include <pthread.h>
#include <sched.h>
#include <fsf.h>
 
#include "timespec_operations.h"
#include "fsf_os_compatibility.h"
 
//#include <debug_marte.h>
 
/*
 
* This is part of the common tests:
** Test to get the time it takes the negotiation of contracts and
the maximum reacheable utilization
- Prepare the configuration files to accept up to 100 servers,
enable the acceptance test, set the service thread with 100s period
and 1s budget, and the scheduler priority to be 102
 
- Fill a contract with the values: Cmin 1s, Cmax 50s, Tmax 100s,
Tmin 50s, INDETERMINATE workload, and the preemptibility level equal
to 101 minus the number of already accepted servers. Create a server
with that contract, and bound it to the main thread using the
fsf_negotiate_contract_for_myself primitive.
- then as a servered task, negotiates as much of the prepared contracts
as possible, taking the utilization given to each of the contracts
after each new contract is accepted and the time it took the
negotiation.
** Test to get the time it takes re-negotiation of contracts and
the change of quality and importance
- change the last parragraph of the test above, so that contracts are
negotiated and bound at the same time to the ever running threads,
and also after each succesful negotiation, the contracts are
re-negotiated, and its quality and importance changed to the same
values. They are taken the utilization given to each server and the
time it took each operation.
 
*/
 
 
#define FSF_MAX_N_TIME_VALUES 1000
 
#define N_SERVERS 10
 
struct timespec instant_zero = {0,0};
int main_priority = N_SERVERS+1;
struct timespec last_time = {0,0};
fsf_server_id_t server[N_SERVERS];
struct server_res_t {
struct timespec negotiation;
struct timespec renegotiation;
struct timespec change_q_and_i;
struct timespec cancellation;
double min_u, max_u, tot_u;
} server_res[N_SERVERS];
int n_servers = 0;
pthread_t task[N_SERVERS];
 
 
 
struct pseudo_printed_results {
char *s;
struct timespec t;
} res[FSF_MAX_N_TIME_VALUES];
int res_index = 0;
 
 
extern int cal_cycles;
extern int calibrate_cycle(void);
extern void eat(TIME wait);
 
//put_time has been reduced in this experiment
//so that it just reports the real-time it is
struct timespec
put_time(const struct timespec *time, char *s)
{
struct timespec now = {0,0};
int terror;
 
if ((terror=clock_gettime(CLOCK_REALTIME,&now)))
ERROR(terror,"clock_gettime failed");
return now;
} /* End of put_time */
 
/*
int
print_time_results()
{
struct timespec now = {0,0};
struct timespec diff = {0,0};
char *s = NULL;
int i;
 
printf("\n");
for (i=0;i<res_index;i++)
{
now = res[i].t;
s = res[i].s;
if (s==NULL) s = " - timestamp - ";
diff = now;
decr_timespec(&diff, &last_time);
last_time = now;
printf("%-60s", s);
printf(" %2d %9d", now.tv_sec,now.tv_nsec);
printf(" [diff=%13.9f]\n", (double)diff.tv_sec+((double)diff.tv_nsec/(double)1000000000));
}
 
return 0;
} / * End of print_time_results * /
*/
/*
int
fsf_priority_map (unsigned long plevel)
{
return plevel;
}
*/
 
void * fsf_indeterminate_server (void * arg)
{
 
//executes for ever
while (1) eat(1000000);
 
} /* End of fsf_indeterminate_server */
 
 
 
int main()
{
struct sched_param param;
//struct timespec half_second={0,500000000};
struct timespec tmp = {0,0};
int terror = 0;
 
fsf_contract_parameters_t contract;
struct timespec budget_min = {1,0}; //{20,710678118};
// struct timespec budget_min = {21,210678118};
struct timespec period_max = {100,0};
struct timespec budget_max = {50,0}; //{20,710678118};
struct timespec period_min = {50,0};
fsf_workload_t workload = FSF_INDETERMINATE; //FSF_BOUNDED;
 
bool d_equals_t = true;
struct timespec deadline = {0,0};
int budget_overrun_sig_notify = FSF_NULL_SIGNAL; // 0
union sigval budget_overrun_sig_value = {0};
int deadline_miss_sig_notify = FSF_NULL_SIGNAL; // 0
union sigval deadline_miss_sig_value = {0};
 
fsf_granularity_t granularity = FSF_DEFAULT_GRANULARITY; // CONTINUOUS
fsf_utilization_set_t *utilization_set = FSF_NULL_UTILIZATION_SET; // NULL
int quality = 1;
int importance = FSF_DEFAULT_IMPORTANCE; // 1
 
fsf_preemption_level_t preemption_level;
fsf_critical_sections_t *critical_sections = NULL;
 
struct timespec budget = {0,0};
struct timespec period = {0,0};
struct timespec start, end;
int i;
double u;
 
INITIALIZATION_CODE;
 
param.sched_priority = main_priority;
if ((terror=pthread_setschedparam (pthread_self(), SCHED_FIFO, &param)))
ERROR(terror,"pthread_setschedparam");
 
instant_zero.tv_sec = 10000000;
instant_zero.tv_nsec = 10000000;
clock_settime(CLOCK_REALTIME,&instant_zero);
clock_gettime(CLOCK_REALTIME,&instant_zero);
last_time = instant_zero;
put_time(&instant_zero, "instant_zero");
put_time(NULL, "printing point 1");
put_time(NULL, "printing point 2");
 
 
 
if ((terror=fsf_initialize_contract(&contract)))
{
printf(" Initialize fail for server A\n");
ERROR(terror,"fsf_initialize_contract failed");
}
 
if ((terror=fsf_set_contract_basic_parameters (&contract,
&budget_min,
&period_max,
workload)))
{
printf("Set_Basic_Parameters failed for server A\n");
ERROR(terror,"set_contract_basic_parameters failed");
}
 
if ((terror=fsf_set_contract_timing_requirements (&contract,
d_equals_t,
(d_equals_t?NULL:&deadline),
budget_overrun_sig_notify,
budget_overrun_sig_value,
deadline_miss_sig_notify,
deadline_miss_sig_value)))
{
printf("Set_Timing_Requirements failed for server A\n");
ERROR(terror,"fsf_set_contract_timing_requirements failed");
}
 
if ((terror=fsf_set_contract_reclamation_parameters (&contract,
&budget_max,
&period_min,
granularity,
utilization_set,
quality,
importance)))
{
printf("Set_Reclamation_Parameters failed for server A\n");
ERROR(terror,"fsf_set_contract_reclamation_parameters failed");
}
 
preemption_level = (fsf_preemption_level_t) param.sched_priority;
if ((terror=fsf_set_contract_synchronization_parameters (&contract,
critical_sections)))
{
printf("Set_Synchronization_Parameters failed for server A\n");
ERROR(terror,"fsf_set_contract_synchronization_parameters failed");
}
 
start = put_time(NULL, "start first server contract negotiation");
terror = fsf_negotiate_contract_for_myself (&contract, &server[0]);
end = put_time(NULL, " end first server contract negotiation");
if (terror)
{
printf("Negotiate_Contract failed for server 0\n");
ERROR(terror,"fsf_negotiate_contract_for_myself failed");
}
decr_timespec(&end, &start);
server_res[0].negotiation = end;
start = put_time(NULL, "start first server contract renegotiation");
terror = fsf_renegotiate_contract (&contract, server[0]);
end = put_time(NULL, " end first server contract renegotiation");
if (terror)
{
printf("ReNegotiate_Contract failed for server 0\n");
ERROR(terror,"fsf_renegotiate_contract failed");
}
decr_timespec(&end, &start);
server_res[0].renegotiation = end;
start = put_time(NULL, "start first server change quality and importance");
terror = fsf_request_change_quality_and_importance(server[0],1,1);
end = put_time(NULL, " end first server change quality and importance");
if (terror)
{
printf("Change quality and importancet failed for server 0\n");
ERROR(terror,"fsf_renegotiate_contract failed");
}
decr_timespec(&end, &start);
server_res[0].change_q_and_i = end;
 
tmp = server_res[0].renegotiation;
incr_timespec(&tmp, &server_res[0].negotiation);
//release the CPU for a while to get the quality change done
if ((terror=nanosleep(&tmp,NULL)))
ERROR(terror, "nanosleep failed");
 
//set_break_point_here;
 
//ask for the utilization actually gotten
terror = fsf_get_budget_and_period (server[0], &budget, &period);
if (terror)
{
printf("fsf_get_budget_and_period failed for server 0\n");
ERROR(terror,"fsf_get_budget_and_period failed");
}
// put_time(&budget,"the budget gotten is: ");
// put_time(&period,"the period gotten is: ");
server_res[0].min_u = server_res[0].max_u = server_res[0].tot_u = t2d(budget) / t2d(period);
/*
budget_min.tv_sec = 1;
budget_min.tv_nsec = 0;
// budget_max = budget_min;
if ((terror=fsf_set_contract_basic_parameters (&contract,
&budget_min,
&period_max,
&budget_max,
&period_min,
workload)))
{
printf("Set_Basic_Parameters failed for a server \n");
}
*/
while(++n_servers < N_SERVERS) {
 
//preparation of the rest of the servers
////if (n_servers==27) set_break_point_here;
preemption_level = main_priority - n_servers;
if ((terror=fsf_set_contract_synchronization_parameters (&contract,
critical_sections)))
{
printf("Set_Synchronization_Parameters failed for server %d\n", n_servers);
ERROR(terror,"fsf_set_contract_synchronization_parameters failed");
}
start = put_time(NULL, "start server contract negotiation");
//terror=fsf_negotiate_contract_for_new_thread (&contract, &server[n_servers], &task[n_servers], NULL, fsf_indeterminate_server, NULL);
terror=fsf_negotiate_contract(&contract, &server[n_servers]);
end = put_time(NULL, " end server contract negotiation");
if (terror)
{
printf("Negotiate_Contract failed for server %d\n", n_servers);
ERROR(terror,"fsf_negotiate_contract failed");
}
if (!server[n_servers]) {
printf("The negotiation for the server number %d was not succesful!! (n_servers=%d)\n",n_servers+1, n_servers);
break;
}
////set_break_point_here;
decr_timespec(&end, &start);
server_res[n_servers].negotiation = end;
start = put_time(NULL, "start server contract renegotiation");
terror = fsf_renegotiate_contract (&contract, server[n_servers]);
end = put_time(NULL, " end server contract renegotiation");
if (terror)
{
printf("ReNegotiate_Contract failed for server %d\n", n_servers);
ERROR(terror,"fsf_renegotiate_contract failed");
}
decr_timespec(&end, &start);
server_res[n_servers].renegotiation = end;
start = put_time(NULL, "start first server change quality and importance");
terror = fsf_request_change_quality_and_importance(server[n_servers],1,1);
end = put_time(NULL, " end first server change quality and importance");
if (terror)
{
printf("Change quality and importancet failed for server %d\n", n_servers);
ERROR(terror,"fsf_request_change_quality_and_importance failed");
}
decr_timespec(&end, &start);
server_res[n_servers].change_q_and_i = end;
tmp = server_res[n_servers].renegotiation;
incr_timespec(&tmp, &server_res[n_servers].negotiation);
//release the CPU for a while long enough to get the change done
if ((terror=nanosleep(&tmp,NULL)))
ERROR(terror, "nanosleep failed");
////set_break_point_here;
//ask for the utilization actually gotten
terror = fsf_get_budget_and_period (server[0], &budget, &period);
if (terror)
{
printf("fsf_get_budget_and_period failed for server 0\n");
ERROR(terror,"fsf_get_budget_and_period failed");
}
if (period.tv_sec==0 && period.tv_nsec==0) {
printf("while processing server %d, the period gotten for server %d is cero!!\n", n_servers, 0);
exit(-1);
}
u = t2d(budget) / t2d(period);
server_res[n_servers].min_u = server_res[n_servers].max_u = server_res[n_servers].tot_u = u;
//get statistics for the utilization of all the accepted contracts up to the current one
for (i=1;i<=n_servers;i++){
terror = fsf_get_budget_and_period (server[i], &budget, &period);
if (terror)
{
printf("fsf_get_budget_and_period failed for server %d\n", n_servers);
ERROR(terror,"fsf_get_budget_and_period failed");
}
if (period.tv_sec==0 && period.tv_nsec==0) {
printf("while processing server %d, the period gotten for server %d is cero!!\n", n_servers, i);
exit(-1);
}
u = t2d(budget) / t2d(period);
server_res[n_servers].tot_u += u;
if (u > server_res[n_servers].max_u) server_res[n_servers].max_u = u;
if (u < server_res[n_servers].min_u) server_res[n_servers].min_u = u;
}
//printf(" %d", n_servers);
} /* End of the while */
//cancellation of contracts
for (i=n_servers-1; i>0;i--) {
start = put_time(NULL, "start server contract cancellation");
terror=fsf_cancel_contract(server[i]);
end = put_time(NULL, " end server contract cancellation");
if (terror)
{
printf("Cancel_Contract failed for server %d\n", i);
ERROR(terror,"fsf_cancel_contract failed");
}
decr_timespec(&end, &start);
server_res[i].cancellation = end;
}
printf("\n");
printf("The number of accepted servers was: %d \n", n_servers);
printf("==================================\n\n");
printf("server negotiation renegotiation qualityChange cancellation max_utilizati min_utilizati total_utilization\n\n");
for (i=0;i<n_servers;i++){
printf(" %2d ", i+1);
printf(" %13.9f ", t2d(server_res[i].negotiation));
printf(" %13.9f ", t2d(server_res[i].renegotiation));
printf(" %13.9f ", t2d(server_res[i].change_q_and_i));
printf(" %13.9f ", t2d(server_res[i].cancellation));
printf(" %13.9f ", server_res[i].max_u);
printf(" %13.9f ", server_res[i].min_u);
printf(" %13.9f ", server_res[i].tot_u);
printf("\n");
}
STANDARD_CONSOLE_INIT; //marte1.26i+
printf("\n");
printf("The number of accepted servers was: %d \n", n_servers);
printf("==================================\n\n");
printf("server negotiation renegotiation qualityChange cancellation max_utilizati min_utilizati total_utilization\n\n");
for (i=0;i<n_servers;i++){
printf(" %2d ", i+1);
printf(" %13.9f ", t2d(server_res[i].negotiation));
printf(" %13.9f ", t2d(server_res[i].renegotiation));
printf(" %13.9f ", t2d(server_res[i].change_q_and_i));
printf(" %13.9f ", t2d(server_res[i].cancellation));
printf(" %13.9f ", server_res[i].max_u);
printf(" %13.9f ", server_res[i].min_u);
printf(" %13.9f ", server_res[i].tot_u);
printf("\n");
}
printf("\nThe end.\n");
//....
exit(-1);
return 0;
} /* End of main */
/shark/trunk/ports/first/fsf_include/tests/fsf_jitter_test/jitter_test.c
0,0 → 1,234
#include <stdio.h>
#include <unistd.h>
 
#include <time.h>
#include <errno.h>
 
#include <pthread.h>
#include <sched.h>
//#include <tefses_stats.h>
 
#include "fsf.h"
#include "timespec_operations.h"
#include "fsf_os_compatibility.h"
 
 
/*
 
* This is part of the common tests:
** Test for the calculus of the jitter
 
- Create a BOUNDED workload server, with 40ms minimum budget and 50ms
as maximum and minimum period and also 50ms maximum budget,
preemption level 4 and deadline equal to period. The server is
bound to the main thread with fsf_negotiate_contract_for_myself.
- The test consist of a periodic activation at absolutes points in time,
the first instruction after each activation is the measurement of the
absolute real-time of activation. Minimum, maximum and average
differences are stored. The test runs 500 times.
*/
 
#define LOCAL_ERROR(nn,ss) {if(errno==0) errno=(nn); perror(ss); return (nn);}
//#define ERROR(nn,ss) {if(errno==0) errno=(nn); perror(ss); exit (nn);}
 
struct timespec instant_zero = {0,0};
int main_priority = 4;
struct timespec last_time = {0,0};
fsf_server_id_t server_A = 0;
 
extern int cal_cycles;
extern int calibrate_cycle(void);
extern void eat(TIME wait);
 
 
int
fsf_priority_map (unsigned long plevel)
{
return plevel;
}
 
 
int main()
{
struct sched_param param;
//struct timespec half_second={0,500000000};
struct timespec tmp = {0,0};
int terror = 0;
 
fsf_contract_parameters_t contract;
struct timespec budget_min = {0,30000000};
struct timespec period_max = {0,50000000};
struct timespec budget_max = {0,50000000};
struct timespec period_min = {0,50000000};
fsf_workload_t workload = FSF_BOUNDED;
 
bool d_equals_t = true;
struct timespec deadline = {0,50000000};
int budget_overrun_sig_notify = FSF_NULL_SIGNAL; // 0
union sigval budget_overrun_sig_value = {0};
int deadline_miss_sig_notify = FSF_NULL_SIGNAL; // 0
union sigval deadline_miss_sig_value = {0};
 
fsf_granularity_t granularity = FSF_DEFAULT_GRANULARITY; // CONTINUOUS
fsf_utilization_set_t *utilization_set = FSF_NULL_UTILIZATION_SET; // NULL
int quality = 1;
int importance = FSF_DEFAULT_IMPORTANCE; // 1
 
fsf_preemption_level_t preemption_level = (fsf_preemption_level_t) main_priority;
fsf_critical_sections_t *critical_sections = NULL;
struct timespec max_jitter={0,0};
struct timespec min_jitter={100000000,0};
struct timespec avg_jitter={0,0};
int my_counter = 0;
/*
struct timespec next_budget;
struct timespec next_period;
bool was_deadline_missed = 0;
bool was_budget_overran = 0;
*/
//pthread_t task_in_b;
calibrate_cycle();
fsf_init();
SERIAL_CONSOLE_INIT; //marte1.26i+
 
param.sched_priority = main_priority;
if ((terror=pthread_setschedparam (pthread_self (), SCHED_FIFO, &param)))
LOCAL_ERROR(terror,"pthread_setschedparam");
 
instant_zero.tv_sec = 10000000;
instant_zero.tv_nsec = 10000000;
clock_settime(CLOCK_REALTIME,&instant_zero);
clock_gettime(CLOCK_REALTIME,&instant_zero);
last_time = instant_zero;
// put_time(&instant_zero, "instant_zero");
// put_time(NULL, "printing point 1");
// put_time(NULL, "printing point 2");
 
// Adjust the time eater (in load.c)
//adjust ();
 
if ((terror=fsf_initialize_contract(&contract)))
{
printf(" Initialize fail for server A\n");
LOCAL_ERROR(terror,"fsf_initialize_contract failed");
}
 
if ((terror=fsf_set_contract_basic_parameters (&contract,
&budget_min,
&period_max,
workload)))
{
printf("Set_Basic_Parameters failed for server A\n");
LOCAL_ERROR(terror,"set_contract_basic_parameters failed");
}
 
if ((terror=fsf_set_contract_timing_requirements (&contract,
d_equals_t,
(d_equals_t?NULL:&deadline),
budget_overrun_sig_notify,
budget_overrun_sig_value,
deadline_miss_sig_notify,
deadline_miss_sig_value)))
{
printf("Set_Timing_Requirements failed for server A\n");
LOCAL_ERROR(terror,"fsf_set_contract_timing_requirements failed");
}
 
if ((terror=fsf_set_contract_reclamation_parameters (&contract,
&budget_max,
&period_min,
granularity,
utilization_set,
quality,
importance)))
{
printf("Set_Reclamation_Parameters failed for server A\n");
LOCAL_ERROR(terror,"fsf_set_contract_reclamation_parameters failed");
}
 
//preemption_level = (fsf_preemption_level_t) param.sched_priority;
if ((terror=fsf_set_contract_synchronization_parameters (&contract,
critical_sections)))
{
printf("Set_Synchronization_Parameters failed for server A\n");
LOCAL_ERROR(terror,"fsf_set_contract_synchronization_parameters failed");
}
 
terror = fsf_negotiate_contract_for_myself(&contract, &server_A);
if (terror)
{
printf("Negotiate_Contract failed for server A\n");
ERROR(terror,"fsf_negotiate_contract_for_myself failed");
}
 
{ /* Bounded workload task block */
struct timespec next_budget;
struct timespec next_period;
bool was_deadline_missed = 0;
bool was_budget_overran = 0;
struct timespec at_absolute_time;
struct timespec my_period = {0,53000000}; // 53 miliseconds
struct timespec ahora;
int i;
 
if ((terror=clock_gettime(CLOCK_REALTIME,&at_absolute_time)))
LOCAL_ERROR(terror,"clock_gettime failed");
for (i=0;i<500;i++) {
 
incr_timespec(&at_absolute_time, &my_period);
if ((terror=fsf_schedule_timed_job (
&at_absolute_time,
&next_budget,
&next_period,
&was_deadline_missed,
&was_budget_overran)))
{
ERROR(terror,"fsf_bounded_server: a call to fsf_schedule_next_timed_job failed");
}
//printf("\ndebug: now es-> (%d,%d)\n", now.tv_sec, now.tv_nsec);
if ((terror=clock_gettime(CLOCK_REALTIME,&ahora)))
LOCAL_ERROR(terror,"ahora clock_gettime failed");
//printf("\ndebug: y ahora es-> (%d,%d)\n", ahora.tv_sec, ahora.tv_nsec);
decr_timespec(&ahora, &at_absolute_time);
 
if ( smaller_timespec(&ahora, &min_jitter) )
min_jitter = ahora;
if ( smaller_timespec(&max_jitter, &ahora) )
max_jitter = ahora;
incr_timespec(&avg_jitter, &ahora);
my_counter++;
}
printf("\n\n minimum jitter is: %8d\n", min_jitter.tv_nsec+ min_jitter.tv_sec*1000000000);
printf(" maximum jitter is: %8d\n", max_jitter.tv_nsec+ max_jitter.tv_sec*1000000000);
printf(" average jitter is: %8d\n\n", (avg_jitter.tv_nsec+ avg_jitter.tv_sec*1000000000)/my_counter);
 
} /* End of bounded workload task block */
 
STANDARD_CONSOLE_INIT; //marte1.26i+
 
printf("\n\n minimum jitter is: %8d\n", min_jitter.tv_nsec+ min_jitter.tv_sec*1000000000);
printf(" maximum jitter is: %8d\n", max_jitter.tv_nsec+ max_jitter.tv_sec*1000000000);
printf(" average jitter is: %8d\n\n", (avg_jitter.tv_nsec+ avg_jitter.tv_sec*1000000000)/my_counter);
 
//printf("\nThe end.\n");
 
//stop_scheduler = 1;
exit(0);
return 0;
} /* End of main */
/shark/trunk/ports/first/fsf_include/tests/fsf_jitter_test/makefile
0,0 → 1,19
#
#
ifeq ($(OS), S)
BASE=../../../../..
OSNAME = shark_glue
export BASE
 
include $(BASE)/config/config.mk
endif
 
PROGS= $(OS)_$(WL)_jitter_test
 
ifeq ($(OS), S)
include $(BASE)/config/example.mk
endif
 
$(OS)_$(WL)_jitter_test:
make -f $(SUBMAKE) APPNAME=$(PROGS) APP=jitter_test INIT= OTHEROBJS="../$(OSNAME)/initfile.o ../$(OSNAME)/shark.o" OTHERINCL="-I../common" SHARKOPT="__INPUT__ __FIRST__ __NEW_TRACER__ __LINUXC26__ __PCI__ __NET__ __GRX__"