1 | /* SPDX-License-Identifier: BSD-2-Clause */ |
---|
2 | |
---|
3 | /** |
---|
4 | * @file |
---|
5 | * |
---|
6 | * @ingroup RTEMSImplCPUUsageReporting |
---|
7 | * |
---|
8 | * @brief This source file contains the definition of |
---|
9 | * rtems_cpu_usage_reset(). |
---|
10 | */ |
---|
11 | |
---|
12 | /* |
---|
13 | * COPYRIGHT (c) 1989-2009 |
---|
14 | * On-Line Applications Research Corporation (OAR). |
---|
15 | * |
---|
16 | * Redistribution and use in source and binary forms, with or without |
---|
17 | * modification, are permitted provided that the following conditions |
---|
18 | * are met: |
---|
19 | * 1. Redistributions of source code must retain the above copyright |
---|
20 | * notice, this list of conditions and the following disclaimer. |
---|
21 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
22 | * notice, this list of conditions and the following disclaimer in the |
---|
23 | * documentation and/or other materials provided with the distribution. |
---|
24 | * |
---|
25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
28 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
---|
29 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
30 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
31 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
33 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
34 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
35 | * POSSIBILITY OF SUCH DAMAGE. |
---|
36 | */ |
---|
37 | |
---|
38 | #ifdef HAVE_CONFIG_H |
---|
39 | #include "config.h" |
---|
40 | #endif |
---|
41 | |
---|
42 | #include <rtems/cpuuse.h> |
---|
43 | #include <rtems/rtems/scheduler.h> |
---|
44 | #include <rtems/score/percpu.h> |
---|
45 | #include <rtems/score/todimpl.h> |
---|
46 | #include <rtems/score/schedulerimpl.h> |
---|
47 | #include <rtems/score/watchdogimpl.h> |
---|
48 | |
---|
49 | #include "cpuuseimpl.h" |
---|
50 | |
---|
51 | static bool CPU_usage_Per_thread_handler( |
---|
52 | Thread_Control *the_thread, |
---|
53 | void *arg |
---|
54 | ) |
---|
55 | { |
---|
56 | const Scheduler_Control *scheduler; |
---|
57 | ISR_lock_Context state_lock_context; |
---|
58 | ISR_lock_Context scheduler_lock_context; |
---|
59 | |
---|
60 | _Thread_State_acquire( the_thread, &state_lock_context ); |
---|
61 | scheduler = _Thread_Scheduler_get_home( the_thread ); |
---|
62 | _Scheduler_Acquire_critical( scheduler, &scheduler_lock_context ); |
---|
63 | |
---|
64 | the_thread->cpu_time_used_at_last_reset = |
---|
65 | _Thread_Get_CPU_time_used_locked( the_thread ); |
---|
66 | |
---|
67 | _Scheduler_Release_critical( scheduler, &scheduler_lock_context ); |
---|
68 | _Thread_State_release( the_thread, &state_lock_context ); |
---|
69 | return false; |
---|
70 | } |
---|
71 | |
---|
72 | /* |
---|
73 | * rtems_cpu_usage_reset |
---|
74 | */ |
---|
75 | void rtems_cpu_usage_reset( void ) |
---|
76 | { |
---|
77 | uint32_t cpu_count; |
---|
78 | uint32_t cpu_index; |
---|
79 | |
---|
80 | _TOD_Get_uptime( &CPU_usage_Uptime_at_last_reset ); |
---|
81 | |
---|
82 | cpu_count = rtems_scheduler_get_processor_maximum(); |
---|
83 | for ( cpu_index = 0 ; cpu_index < cpu_count ; ++cpu_index ) { |
---|
84 | Per_CPU_Control *cpu = _Per_CPU_Get_by_index( cpu_index ); |
---|
85 | |
---|
86 | cpu->cpu_usage_timestamp = CPU_usage_Uptime_at_last_reset; |
---|
87 | } |
---|
88 | |
---|
89 | rtems_task_iterate(CPU_usage_Per_thread_handler, NULL); |
---|
90 | } |
---|