@@ -793,6 +793,10 void get_v_e1_e2_f3( unsigned char *spac | |||
|
793 | 793 | |
|
794 | 794 | void get_cpu_load( unsigned char *resource_statistics ) |
|
795 | 795 | { |
|
796 | #define LOAD_AVG_SIZE 60 | |
|
797 | static unsigned char cpu_load_hist[LOAD_AVG_SIZE]={0}; | |
|
798 | static char old_avg_pos=0; | |
|
799 | static unsigned int cpu_load_avg; | |
|
796 | 800 | unsigned char cpu_load; |
|
797 | 801 | |
|
798 | 802 | cpu_load = lfr_rtems_cpu_usage_report(); |
@@ -806,8 +810,12 void get_cpu_load( unsigned char *resour | |||
|
806 | 810 | resource_statistics[1] = cpu_load; |
|
807 | 811 | } |
|
808 | 812 | |
|
813 | cpu_load_avg = cpu_load_avg - (unsigned int)cpu_load_hist[(int)old_avg_pos] + (unsigned int)cpu_load; | |
|
814 | cpu_load_hist[(int)old_avg_pos] = cpu_load; | |
|
815 | old_avg_pos += 1; | |
|
816 | old_avg_pos %= LOAD_AVG_SIZE; | |
|
809 | 817 | // CPU_LOAD_AVE |
|
810 |
resource_statistics[BYTE_2] = |
|
|
818 | resource_statistics[BYTE_2] = (unsigned char)(cpu_load_avg / LOAD_AVG_SIZE); | |
|
811 | 819 | |
|
812 | 820 | #ifndef PRINT_TASK_STATISTICS |
|
813 | 821 | rtems_cpu_usage_reset(); |
@@ -12,10 +12,14 | |||
|
12 | 12 | */ |
|
13 | 13 | |
|
14 | 14 | #include "lfr_cpu_usage_report.h" |
|
15 | #include "fsw_params.h" | |
|
16 | ||
|
17 | extern rtems_id Task_id[]; | |
|
15 | 18 | |
|
16 | 19 | unsigned char lfr_rtems_cpu_usage_report( void ) |
|
17 | 20 | { |
|
18 | 21 | uint32_t api_index; |
|
22 | uint32_t information_index; | |
|
19 | 23 | Thread_Control *the_thread; |
|
20 | 24 | Objects_Information *information; |
|
21 | 25 | uint32_t ival; |
@@ -24,8 +28,13 unsigned char lfr_rtems_cpu_usage_report | |||
|
24 | 28 | Timestamp_Control uptime; |
|
25 | 29 | Timestamp_Control total; |
|
26 | 30 | Timestamp_Control ran; |
|
31 | Timestamp_Control abs_total; | |
|
32 | Timestamp_Control abs_ran; | |
|
33 | ||
|
34 | static Timestamp_Control last_total={0,0}; | |
|
35 | static Timestamp_Control last_ran={0,0}; | |
|
27 | 36 | #else |
|
28 | uint32_t total_units = 0; | |
|
37 | #error "Can't compute CPU usage using ticks on LFR" | |
|
29 | 38 | #endif |
|
30 | 39 | |
|
31 | 40 | unsigned char cpu_load; |
@@ -33,33 +42,8 unsigned char lfr_rtems_cpu_usage_report | |||
|
33 | 42 | ival = 0; |
|
34 | 43 | cpu_load = 0; |
|
35 | 44 | |
|
36 | /* | |
|
37 | * When not using nanosecond CPU usage resolution, we have to count | |
|
38 | * the number of "ticks" we gave credit for to give the user a rough | |
|
39 | * guideline as to what each number means proportionally. | |
|
40 | */ | |
|
41 | #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__ | |
|
42 | 45 | _TOD_Get_uptime( &uptime ); |
|
43 | _Timestamp_Subtract( &CPU_usage_Uptime_at_last_reset, &uptime, &total ); | |
|
44 | #else | |
|
45 | for ( api_index = 1 ; api_index <= OBJECTS_APIS_LAST ; api_index++ ) { | |
|
46 | if ( !_Objects_Information_table[ api_index ] ) { } | |
|
47 | else | |
|
48 | { | |
|
49 | information = _Objects_Information_table[ api_index ][ 1 ]; | |
|
50 | if ( information != NULL ) | |
|
51 | { | |
|
52 | for ( i=1 ; i <= information->maximum ; i++ ) { | |
|
53 | the_thread = (Thread_Control *)information->local_table[ i ]; | |
|
54 | ||
|
55 | if ( the_thread != NULL ) { | |
|
56 | total_units += the_thread->cpu_time_used; } | |
|
57 | } | |
|
58 | } | |
|
59 | } | |
|
60 | } | |
|
61 | #endif | |
|
62 | ||
|
46 | _Timestamp_Subtract( &CPU_usage_Uptime_at_last_reset, &uptime, &abs_total ); | |
|
63 | 47 | for ( api_index = 1 ; api_index <= OBJECTS_APIS_LAST ; api_index++ ) |
|
64 | 48 | { |
|
65 | 49 | if ( !_Objects_Information_table[ api_index ] ) { } |
@@ -68,50 +52,42 unsigned char lfr_rtems_cpu_usage_report | |||
|
68 | 52 | information = _Objects_Information_table[ api_index ][ 1 ]; |
|
69 | 53 | if ( information != NULL ) |
|
70 | 54 | { |
|
71 | the_thread = (Thread_Control *)information->local_table[ 1 ]; | |
|
72 | ||
|
73 | if ( the_thread == NULL ) { } | |
|
74 | else | |
|
55 | for(information_index=1;information_index<=information->maximum;information_index++) | |
|
75 | 56 | { |
|
76 | #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__ | |
|
77 | /* | |
|
78 | * If this is the currently executing thread, account for time | |
|
79 | * since the last context switch. | |
|
80 | */ | |
|
81 | ran = the_thread->cpu_time_used; | |
|
82 | if ( _Thread_Executing->Object.id == the_thread->Object.id ) | |
|
57 | the_thread = (Thread_Control *)information->local_table[ information_index ]; | |
|
58 | ||
|
59 | if ( the_thread == NULL) { } | |
|
60 | else if(the_thread->Object.id == Task_id[TASKID_SCRB]) // Only measure scrubbing task load, CPU load is 100%-Scrubbing | |
|
83 | 61 | { |
|
84 |
|
|
|
85 | _Timestamp_Subtract( | |
|
86 |
|
|
|
87 |
|
|
|
88 | _Timestamp_Add_to( &ran, &used ); | |
|
62 | /* | |
|
63 | * If this is the currently executing thread, account for time | |
|
64 | * since the last context switch. | |
|
65 | */ | |
|
66 | abs_ran = the_thread->cpu_time_used; | |
|
67 | if ( _Thread_Executing->Object.id == the_thread->Object.id ) | |
|
68 | { | |
|
69 | Timestamp_Control used; | |
|
70 | _Timestamp_Subtract( | |
|
71 | &_Thread_Time_of_last_context_switch, &uptime, &used | |
|
72 | ); | |
|
73 | _Timestamp_Add_to( &abs_ran, &used ); | |
|
74 | } | |
|
75 | /* | |
|
76 | * Only consider the time since last call | |
|
77 | */ | |
|
78 | _Timespec_Subtract(&last_ran, &abs_ran, &ran); | |
|
79 | _Timespec_Subtract(&last_total, &abs_total, &total); | |
|
80 | ||
|
81 | last_ran = abs_ran; | |
|
82 | last_total = abs_total; | |
|
83 | ||
|
84 | _Timestamp_Divide( &ran, &total, &ival, &fval); | |
|
85 | cpu_load = (unsigned char)(CONST_100 - ival); | |
|
89 | 86 | } |
|
90 | _Timestamp_Divide( &ran, &total, &ival, &fval ); | |
|
91 | ||
|
92 | #else | |
|
93 | if (total_units != 0) | |
|
94 | { | |
|
95 | uint64_t ival_64; | |
|
96 | ||
|
97 | ival_64 = the_thread->cpu_time_used; | |
|
98 | ival_64 *= CONST_100000; | |
|
99 | ival = ival_64 / total_units; | |
|
100 | } | |
|
101 | else | |
|
102 | { | |
|
103 | ival = 0; | |
|
104 | } | |
|
105 | ||
|
106 | fval = ival % CONST_1000; | |
|
107 | ival /= CONST_1000; | |
|
108 | #endif | |
|
109 | 87 | } |
|
110 | 88 | } |
|
111 | 89 | } |
|
112 | 90 | } |
|
113 | cpu_load = (unsigned char) (CONST_100 - ival); | |
|
114 | ||
|
115 | 91 | return cpu_load; |
|
116 | 92 | } |
|
117 | 93 |
General Comments 0
You need to be logged in to leave comments.
Login now