From: telleriam Date: Fri, 30 Nov 2007 12:59:14 +0000 (+0000) Subject: Adding mutex_lock and unlock to calibration example X-Git-Url: https://rtime.felk.cvut.cz/gitweb/frescor/fosa.git/commitdiff_plain/78791a77557ba9b65e5aa368d975d5e1074e8eba Adding mutex_lock and unlock to calibration example git-svn-id: http://www.frescor.org/private/svn/frescor/fosa/trunk@916 35b4ef3e-fd22-0410-ab77-dab3279adceb --- diff --git a/src_marte/tests/test_non_local_jump/fosa_long_jump_calibrate.c b/src_marte/tests/test_non_local_jump/fosa_long_jump_calibrate.c index e905db9..bd900a8 100644 --- a/src_marte/tests/test_non_local_jump/fosa_long_jump_calibrate.c +++ b/src_marte/tests/test_non_local_jump/fosa_long_jump_calibrate.c @@ -44,7 +44,7 @@ /*************************/ /* D E F I N I T I O N S */ /*************************/ -#define NUMBER_OF_TESTS 100 +#define NUMBER_OF_TESTS 1000 static struct timespec minimum_budget_for_timer = {0, 100000}; // 100 us @@ -53,11 +53,13 @@ static struct timespec minimum_budget_for_timer = {0, 100000}; // 100 us #define CALIBRATE_THREAD_PRIORITY (fosa_get_priority_min() + 4) #define MAIN_THREAD_PRIORITY (fosa_get_priority_min() + 3) +#define MUTEX_CEILING (fosa_get_priority_min() + 10) #define MINIMUM_BUDGET_FOR_TIMER_USECS 100 #define SIGNAL_CALIBRATE_FINISHED (FRSH_SIGNAL_MIN + 6) + typedef struct _individual_results_t { int first_time_passed; @@ -100,16 +102,13 @@ static int frsh_sharedobj_calibrate(individual_results_t *fixed_abort_ovhd, individual_results_t *fixed_memory_copy_ovhd, individual_results_t *memory_copy_per_byte_ovhd); - -static void *calibrate_thread_code(void *thread_arg); +static void *fixed_abort_ovhd_thread_code(void *thread_arg); static void process_result(individual_results_t *results, struct timespec interval); static void print_results(individual_results_t results); static struct timespec timespec_divide_by_int(struct timespec numerator, long int denominator); - - int main() { @@ -179,6 +178,9 @@ static int frsh_sharedobj_calibrate(individual_results_t *fixed_abort_ovhd, PRW( fosa_set_accepted_signals(signal_set, 1) ); PRW( fosa_thread_set_prio(fosa_thread_self(), MAIN_THREAD_PRIORITY) ); + /* We get our CPU clock */ + PRW( fosa_thread_get_cputime_clock( fosa_thread_self(), &cpu_clock) ); + /* We measure the fixed_abort_ovhd */ /***********************************/ thread_data.results = fixed_abort_ovhd; @@ -186,23 +188,21 @@ static int frsh_sharedobj_calibrate(individual_results_t *fixed_abort_ovhd, PRW( frsh_thread_attr_init(&calibrate_thread_attr) ); PRW( fosa_thread_attr_set_prio(&calibrate_thread_attr, CALIBRATE_THREAD_PRIORITY) ); - PRW( fosa_thread_create(&calibrate_tid, &calibrate_thread_attr, calibrate_thread_code, + + PRW( fosa_thread_create(&calibrate_tid, &calibrate_thread_attr, fixed_abort_ovhd_thread_code, &thread_data ) ); - printf("Main waits for the calibrate code to finish...\n"); + /* We wait for the signal to arrive */ PRW( fosa_signal_wait(signal_set, 1, &signal_received, &signal_info_received) ); /* We measure fixed_memory_copy_ovhd */ /*************************************/ - PRW( fosa_thread_get_cputime_clock( fosa_thread_self(), &cpu_clock) ); - - for(i = 0 ; i < NUMBER_OF_TESTS ; i++) { - fosa_clock_get_time(FOSA_CLOCK_REALTIME, &initial_time); + fosa_clock_get_time(FOSA_CLOCK_REALTIME, &initial_time); // Start measurement memcpy(memory_region_destination, memory_region_source, 0); - fosa_clock_get_time(FOSA_CLOCK_REALTIME, &final_time); + fosa_clock_get_time(FOSA_CLOCK_REALTIME, &final_time); // End measurement decr_timespec(&final_time, &initial_time); @@ -222,6 +222,7 @@ static int frsh_sharedobj_calibrate(individual_results_t *fixed_abort_ovhd, fosa_clock_get_time(cpu_clock, &final_time); // End measurement decr_timespec(&final_time, &initial_time); + final_time = timespec_divide_by_int(final_time, NUMBER_OF_BYTES_TO_SIMULATE / 1024); process_result(memory_copy_per_byte_ovhd, final_time); @@ -249,7 +250,7 @@ typedef struct _protection_parameters // ------------------------------------------------------------------------ -static void *calibrate_thread_code(void *thread_arg) +static void *fixed_abort_ovhd_thread_code(void *thread_arg) { int terror = -1; @@ -259,14 +260,17 @@ static void *calibrate_thread_code(void *thread_arg) protection_parameters_t protection_parameters; frsh_signal_info_t signal_info_to_send; + frsh_mutex_t mutex; memset(&protection_parameters, 0, sizeof(protection_parameters) ); memset(&signal_info_to_send, 0, sizeof(signal_info_to_send) ); - + memset(&mutex, 0, sizeof(mutex) ); thread_data = (thread_data_t *) thread_arg; results = thread_data->results; + PXW( fosa_mutex_init(&mutex, MUTEX_CEILING) ); + /* Periodic loop */ /*****************/ @@ -315,8 +319,10 @@ static void *calibrate_thread_code(void *thread_arg) protection_parameters.initialised = true; } + PXW( fosa_mutex_lock(&mutex) ); + /* We arm the jump_timer */ - fosa_timer_arm(protection_parameters.jump_timer, false, &budget); + PXW( fosa_timer_arm(protection_parameters.jump_timer, false, &budget) ); /* This is the point where the jump returns */ fosa_long_jump_save_context(&context); @@ -327,14 +333,18 @@ static void *calibrate_thread_code(void *thread_arg) { /* HERE COMES THE WORK THAT CAN BE INTERRUPTED */ work_under_a_interruptible_budget(); + PXW( fosa_timer_disarm(protection_parameters.jump_timer, NULL) ); + PXW( fosa_mutex_unlock(&mutex) ); PERROR_AND_EXIT(FRSH_ERR_INTERNAL_ERROR, "The jump should always prevent us from arriving here\n"); } + + PXW( fosa_mutex_unlock(&mutex) ); + /* E N D O F M E A S U R I N G H E R E */ /***************************************************/ fosa_clock_get_time(FOSA_CLOCK_REALTIME, &after_timestamp); - results->number_of_tries++; decr_timespec(&after_timestamp, &before_timestamp); decr_timespec(&after_timestamp, &minimum_budget_for_timer); @@ -399,6 +409,7 @@ static void process_result(individual_results_t *results, struct timespec interv incr_timespec(&results->total_interval, &interval); } + } // ------------------------------------------------------------------------------ @@ -421,7 +432,6 @@ static void print_results(individual_results_t results) results.average_interval.tv_nsec, results.number_of_tries); } - // ------------------------------------------------------------------------------ static struct timespec timespec_divide_by_int(struct timespec numerator, long int denominator)