# HG changeset patch # User Alexis Jeandet # Date 2018-08-27 16:21:27 # Node ID a9b894b0ab6a8fa48f50ce3dd7200406b83e2a62 # Parent ba339e088c78fd67b777c91a740ab3e66067e542 Fixed again CPU usage measurement Previous fix was still wrong, now we call all the time rtems_cpu_usage_reset to only get stats since last measurement. All previous versions were also wrong since they use to send cpu usage with 100=100% instead of 255=100%. diff --git a/header/lfr_cpu_usage_report.h b/header/lfr_cpu_usage_report.h --- a/header/lfr_cpu_usage_report.h +++ b/header/lfr_cpu_usage_report.h @@ -29,7 +29,9 @@ unsigned char lfr_rtems_cpu_usage_report( void ); +#define CONST_10 10 #define CONST_100 100 +#define CONST_255 255 #define CONST_1000 1000 #define CONST_100000 100000 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -64,7 +64,7 @@ option(FSW_debug_tch "?" OFF) set(SW_VERSION_N1 "3" CACHE STRING "Choose N1 FSW Version." FORCE) set(SW_VERSION_N2 "2" CACHE STRING "Choose N2 FSW Version." FORCE) set(SW_VERSION_N3 "0" CACHE STRING "Choose N3 FSW Version." FORCE) -set(SW_VERSION_N4 "18" CACHE STRING "Choose N4 FSW Version." FORCE) +set(SW_VERSION_N4 "19" CACHE STRING "Choose N4 FSW Version." FORCE) if(FSW_verbose) add_definitions(-DPRINT_MESSAGES_ON_CONSOLE) diff --git a/src/fsw_misc.c b/src/fsw_misc.c --- a/src/fsw_misc.c +++ b/src/fsw_misc.c @@ -816,7 +816,7 @@ void get_cpu_load( unsigned char *resour old_avg_pos %= LOAD_AVG_SIZE; // CPU_LOAD_AVE resource_statistics[BYTE_2] = (unsigned char)(cpu_load_avg / LOAD_AVG_SIZE); - +// this will change the way LFR compute usage #ifndef PRINT_TASK_STATISTICS rtems_cpu_usage_reset(); #endif diff --git a/src/lfr_cpu_usage_report.c b/src/lfr_cpu_usage_report.c --- a/src/lfr_cpu_usage_report.c +++ b/src/lfr_cpu_usage_report.c @@ -28,11 +28,7 @@ unsigned char lfr_rtems_cpu_usage_report Timestamp_Control uptime; Timestamp_Control total; Timestamp_Control ran; - Timestamp_Control abs_total; - Timestamp_Control abs_ran; - static Timestamp_Control last_total={0,0}; - static Timestamp_Control last_ran={0,0}; #else #error "Can't compute CPU usage using ticks on LFR" #endif @@ -42,8 +38,6 @@ unsigned char lfr_rtems_cpu_usage_report ival = 0; cpu_load = 0; - _TOD_Get_uptime( &uptime ); - _Timestamp_Subtract( &CPU_usage_Uptime_at_last_reset, &uptime, &abs_total ); for ( api_index = 1 ; api_index <= OBJECTS_APIS_LAST ; api_index++ ) { if ( !_Objects_Information_table[ api_index ] ) { } @@ -59,30 +53,11 @@ unsigned char lfr_rtems_cpu_usage_report if ( the_thread == NULL) { } else if(the_thread->Object.id == Task_id[TASKID_SCRB]) // Only measure scrubbing task load, CPU load is 100%-Scrubbing { - /* - * If this is the currently executing thread, account for time - * since the last context switch. - */ - abs_ran = the_thread->cpu_time_used; - if ( _Thread_Executing->Object.id == the_thread->Object.id ) - { - Timestamp_Control used; - _Timestamp_Subtract( - &_Thread_Time_of_last_context_switch, &uptime, &used - ); - _Timestamp_Add_to( &abs_ran, &used ); - } - /* - * Only consider the time since last call - */ - _Timespec_Subtract(&last_ran, &abs_ran, &ran); - _Timespec_Subtract(&last_total, &abs_total, &total); - - last_ran = abs_ran; - last_total = abs_total; - + _TOD_Get_uptime( &uptime ); + _Timestamp_Subtract( &CPU_usage_Uptime_at_last_reset, &uptime, &total ); + ran = the_thread->cpu_time_used; _Timestamp_Divide( &ran, &total, &ival, &fval); - cpu_load = (unsigned char)(CONST_100 - ival); + cpu_load = (unsigned char)(CONST_255 - ((ival*CONST_10+fval/CONST_100)*CONST_256/CONST_1000)); } } }