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_params.h" |
16 |
|
|
|
17 |
|
|
extern rtems_id Task_id[]; |
18 |
|
|
|
19 |
|
151 |
unsigned char lfr_rtems_cpu_usage_report( void ) |
20 |
|
|
{ |
21 |
|
|
uint32_t api_index; |
22 |
|
|
uint32_t information_index; |
23 |
|
|
Thread_Control *the_thread; |
24 |
|
|
Objects_Information *information; |
25 |
|
|
uint32_t ival; |
26 |
|
|
uint32_t fval; |
27 |
|
|
#ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__ |
28 |
|
|
Timestamp_Control uptime; |
29 |
|
|
Timestamp_Control total; |
30 |
|
|
Timestamp_Control ran; |
31 |
|
|
|
32 |
|
|
#else |
33 |
|
|
#error "Can't compute CPU usage using ticks on LFR" |
34 |
|
|
#endif |
35 |
|
|
|
36 |
|
|
unsigned char cpu_load; |
37 |
|
|
|
38 |
|
151 |
ival = 0; |
39 |
|
151 |
cpu_load = 0; |
40 |
|
|
|
41 |
✓✓ |
755 |
for ( api_index = 1 ; api_index <= OBJECTS_APIS_LAST ; api_index++ ) |
42 |
|
|
{ |
43 |
✓✓ |
604 |
if ( !_Objects_Information_table[ api_index ] ) { } |
44 |
|
|
else |
45 |
|
|
{ |
46 |
|
453 |
information = _Objects_Information_table[ api_index ][ 1 ]; |
47 |
✓✗ |
453 |
if ( information != NULL ) |
48 |
|
|
{ |
49 |
✓✓ |
4077 |
for(information_index=1;information_index<=information->maximum;information_index++) |
50 |
|
|
{ |
51 |
|
3624 |
the_thread = (Thread_Control *)information->local_table[ information_index ]; |
52 |
|
|
|
53 |
✓✓ |
3624 |
if ( the_thread == NULL) { } |
54 |
✓✓ |
3473 |
else if(the_thread->Object.id == Task_id[TASKID_SCRB]) // Only measure scrubbing task load, CPU load is 100%-Scrubbing |
55 |
|
|
{ |
56 |
|
151 |
_TOD_Get_uptime( &uptime ); |
57 |
|
151 |
_Timestamp_Subtract( &CPU_usage_Uptime_at_last_reset, &uptime, &total ); |
58 |
|
151 |
ran = the_thread->cpu_time_used; |
59 |
|
151 |
_Timestamp_Divide( &ran, &total, &ival, &fval); |
60 |
|
151 |
cpu_load = (unsigned char) (CONST_255 - ((((ival*CONST_10) + (fval/CONST_100))*CONST_256)/CONST_1000)); |
61 |
|
|
} |
62 |
|
|
} |
63 |
|
|
} |
64 |
|
|
} |
65 |
|
|
} |
66 |
|
151 |
return cpu_load; |
67 |
|
|
} |
68 |
|
|
|
69 |
|
|
|