1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief CPU Usage Reset |
---|
5 | * @ingroup libmisc_cpuuse CPU Usage |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * COPYRIGHT (c) 1989-2009 |
---|
10 | * On-Line Applications Research Corporation (OAR). |
---|
11 | * |
---|
12 | * The license and distribution terms for this file may be |
---|
13 | * found in the file LICENSE in this distribution or at |
---|
14 | * http://www.rtems.org/license/LICENSE. |
---|
15 | */ |
---|
16 | |
---|
17 | #ifdef HAVE_CONFIG_H |
---|
18 | #include "config.h" |
---|
19 | #endif |
---|
20 | |
---|
21 | #include <rtems/cpuuse.h> |
---|
22 | #include <rtems/score/percpu.h> |
---|
23 | #include <rtems/score/todimpl.h> |
---|
24 | #include <rtems/score/schedulerimpl.h> |
---|
25 | #include <rtems/score/watchdogimpl.h> |
---|
26 | |
---|
27 | #include "cpuuseimpl.h" |
---|
28 | |
---|
29 | static bool CPU_usage_Per_thread_handler( |
---|
30 | Thread_Control *the_thread, |
---|
31 | void *arg |
---|
32 | ) |
---|
33 | { |
---|
34 | const Scheduler_Control *scheduler; |
---|
35 | ISR_lock_Context state_lock_context; |
---|
36 | ISR_lock_Context scheduler_lock_context; |
---|
37 | |
---|
38 | _Thread_State_acquire( the_thread, &state_lock_context ); |
---|
39 | scheduler = _Thread_Scheduler_get_home( the_thread ); |
---|
40 | _Scheduler_Acquire_critical( scheduler, &scheduler_lock_context ); |
---|
41 | |
---|
42 | _Timestamp_Set_to_zero( &the_thread->cpu_time_used ); |
---|
43 | |
---|
44 | _Scheduler_Release_critical( scheduler, &scheduler_lock_context ); |
---|
45 | _Thread_State_release( the_thread, &state_lock_context ); |
---|
46 | return false; |
---|
47 | } |
---|
48 | |
---|
49 | /* |
---|
50 | * rtems_cpu_usage_reset |
---|
51 | */ |
---|
52 | void rtems_cpu_usage_reset( void ) |
---|
53 | { |
---|
54 | uint32_t cpu_count; |
---|
55 | uint32_t cpu_index; |
---|
56 | |
---|
57 | _TOD_Get_uptime( &CPU_usage_Uptime_at_last_reset ); |
---|
58 | |
---|
59 | cpu_count = rtems_scheduler_get_processor_maximum(); |
---|
60 | for ( cpu_index = 0 ; cpu_index < cpu_count ; ++cpu_index ) { |
---|
61 | Per_CPU_Control *cpu = _Per_CPU_Get_by_index( cpu_index ); |
---|
62 | |
---|
63 | cpu->cpu_usage_timestamp = CPU_usage_Uptime_at_last_reset; |
---|
64 | } |
---|
65 | |
---|
66 | rtems_task_iterate(CPU_usage_Per_thread_handler, NULL); |
---|
67 | } |
---|