1 | /* |
---|
2 | * Copyright (c) 2016 embedded brains GmbH. All rights reserved. |
---|
3 | * |
---|
4 | * embedded brains GmbH |
---|
5 | * Dornierstr. 4 |
---|
6 | * 82178 Puchheim |
---|
7 | * Germany |
---|
8 | * <rtems@embedded-brains.de> |
---|
9 | * |
---|
10 | * The license and distribution terms for this file may be |
---|
11 | * found in the file LICENSE in this distribution or at |
---|
12 | * http://www.rtems.org/license/LICENSE. |
---|
13 | */ |
---|
14 | |
---|
15 | #if HAVE_CONFIG_H |
---|
16 | #include "config.h" |
---|
17 | #endif |
---|
18 | |
---|
19 | #include <rtems/score/threadimpl.h> |
---|
20 | #include <rtems/score/schedulerimpl.h> |
---|
21 | |
---|
22 | static bool _Thread_Is_scheduled( const Thread_Control *the_thread ) |
---|
23 | { |
---|
24 | #if defined(RTEMS_SMP) |
---|
25 | return the_thread->Scheduler.state == THREAD_SCHEDULER_SCHEDULED; |
---|
26 | #else |
---|
27 | return _Thread_Is_executing( the_thread ); |
---|
28 | #endif |
---|
29 | } |
---|
30 | |
---|
31 | void _Thread_Get_CPU_time_used( |
---|
32 | Thread_Control *the_thread, |
---|
33 | Timestamp_Control *cpu_time_used |
---|
34 | ) |
---|
35 | { |
---|
36 | const Scheduler_Control *scheduler; |
---|
37 | ISR_lock_Context state_lock_context; |
---|
38 | ISR_lock_Context scheduler_lock_context; |
---|
39 | |
---|
40 | _Thread_State_acquire( the_thread, &state_lock_context ); |
---|
41 | scheduler = _Thread_Scheduler_get_home( the_thread ); |
---|
42 | _Scheduler_Acquire_critical( scheduler, &scheduler_lock_context ); |
---|
43 | |
---|
44 | if ( _Thread_Is_scheduled( the_thread ) ) { |
---|
45 | _Thread_Update_CPU_time_used( the_thread, _Thread_Get_CPU( the_thread ) ); |
---|
46 | } |
---|
47 | |
---|
48 | *cpu_time_used = the_thread->cpu_time_used; |
---|
49 | |
---|
50 | _Scheduler_Release_critical( scheduler, &scheduler_lock_context ); |
---|
51 | _Thread_State_release( the_thread, &state_lock_context ); |
---|
52 | } |
---|