RTEMS
threadgetcputimeused.c
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 #ifdef HAVE_CONFIG_H
16 #include "config.h"
17 #endif
18 
19 #include <rtems/score/threadimpl.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 
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 }
void _Thread_Get_CPU_time_used(Thread_Control *the_thread, Timestamp_Control *cpu_time_used)
Gets the used cpu time of the thread and stores it in the given Timestamp_Control.
Timestamp_Control cpu_time_used
Definition: thread.h:820
int64_t Timestamp_Control
Definition: timestamp.h:57
static __inline__ void _Scheduler_Acquire_critical(const Scheduler_Control *scheduler, ISR_lock_Context *lock_context)
Acquires the scheduler instance inside a critical section (interrupts disabled).
static __inline__ const Scheduler_Control * _Thread_Scheduler_get_home(const Thread_Control *the_thread)
Gets the home scheduler of the thread.
Definition: threadimpl.h:1419
Inlined Routines Associated with the Manipulation of the Scheduler.
This thread is scheduled with respect to the scheduler.
Definition: thread.h:229
Thread_Scheduler_control Scheduler
Scheduler related control.
Definition: thread.h:764
static __inline__ void _Thread_State_release(Thread_Control *the_thread, ISR_lock_Context *lock_context)
Releases the lock context and enables interrupts.
Definition: threadimpl.h:592
static __inline__ void _Scheduler_Release_critical(const Scheduler_Control *scheduler, ISR_lock_Context *lock_context)
Releases the scheduler instance inside a critical section (interrupts disabled).
Thread_Scheduler_state state
The current scheduler state of this thread.
Definition: thread.h:253
static __inline__ bool _Thread_Is_executing(const Thread_Control *the_thread)
Checks if the thread is the currently executing thread.
Definition: threadimpl.h:910
static __inline__ Per_CPU_Control * _Thread_Get_CPU(const Thread_Control *thread)
Gets the cpu of the thread&#39;s scheduler.
Definition: threadimpl.h:867
Scheduler control.
Definition: scheduler.h:264
Inlined Routines from the Thread Handler.
Local ISR lock context for acquire and release pairs.
Definition: isrlock.h:65
static __inline__ void _Thread_State_acquire(Thread_Control *the_thread, ISR_lock_Context *lock_context)
Disables interrupts and acquires the lock_context.
Definition: threadimpl.h:542
static __inline__ void _Thread_Update_CPU_time_used(Thread_Control *the_thread, Per_CPU_Control *cpu)
Updates the cpu time used of the thread.
Definition: threadimpl.h:1155