Line data Source code
1 : /* 2 : * CPU Usage Reporter 3 : * 4 : * COPYRIGHT (c) 1989-2009 5 : * On-Line Applications Research Corporation (OAR). 6 : * 7 : * The license and distribution terms for this file may be 8 : * found in the file LICENSE in this distribution or at 9 : * http://www.rtems.com/license/LICENSE. 10 : * 11 : * $Id$ 12 : */ 13 : 14 : #include "lfr_cpu_usage_report.h" 15 : #include "fsw_globals.h" 16 : #include "fsw_params.h" 17 : 18 11 : unsigned char lfr_rtems_cpu_usage_report(void) 19 : { 20 : const Thread_Control* the_thread; 21 : const Objects_Information* information; 22 : uint32_t ival; 23 : uint32_t fval; 24 : #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__ 25 : Timestamp_Control uptime; 26 : Timestamp_Control total; 27 : Timestamp_Control ran; 28 : 29 : #else 30 : #error "Can't compute CPU usage using ticks on LFR" 31 : #endif 32 : 33 : unsigned char cpu_load; 34 : 35 11 : ival = 0; 36 11 : cpu_load = 0; 37 : 38 55 : for (uint32_t api_index = 1; api_index <= OBJECTS_APIS_LAST; api_index++) 39 : { 40 44 : if (_Objects_Information_table[api_index]!=NULL) 41 : { 42 33 : information = _Objects_Information_table[api_index][1]; 43 33 : if (information != NULL) 44 : { 45 330 : for (uint32_t information_index = 1; information_index <= information->maximum; 46 264 : information_index++) 47 : { 48 264 : the_thread = (Thread_Control*)information->local_table[information_index]; 49 : 50 : // Only measure scrubbing task load, CPU load is 100%-Scrubbing 51 264 : if (the_thread != NULL && the_thread->Object.id == Task_id[TASKID_SCRB]) 52 : { 53 11 : _TOD_Get_uptime(&uptime); 54 11 : _Timestamp_Subtract(&CPU_usage_Uptime_at_last_reset, &uptime, &total); 55 11 : ran = the_thread->cpu_time_used; 56 11 : _Timestamp_Divide(&ran, &total, &ival, &fval); 57 11 : cpu_load = (unsigned char)(CONST_255 58 11 : - ((((ival * CONST_10) + (fval / CONST_100)) * CONST_256) 59 : / CONST_1000)); 60 : } 61 : } 62 : } 63 : } 64 : } 65 11 : return cpu_load; 66 : }