summaryrefslogtreecommitdiffstats
path: root/cpukit/libmisc/cpuuse/cpuusagetop.c
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2016-03-03 07:02:03 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2016-03-17 08:27:47 +0100
commitd37adfe5dd82cc3c933eb521b8f800c342af0e52 (patch)
tree5f4a77976b9ae35594d00b0bb58e18bb62a9b541 /cpukit/libmisc/cpuuse/cpuusagetop.c
parentbsp/realview_pbx_a9_qemu: Fix compiler flags (diff)
downloadrtems-d37adfe5dd82cc3c933eb521b8f800c342af0e52.tar.bz2
score: Fix CPU time used by executing threads
The CPU time used of a thread was previously maintained per-processor mostly during _Thread_Dispatch(). However, on SMP configurations the actual processor of a thread is difficult to figure out since thread dispatching is a highly asynchronous process (e.g. via inter-processor interrupts). Only the intended processor of a thread is known to the scheduler easily. Do the CPU usage accounting during thread heir updates in the context of the scheduler operations. Provide the function _Thread_Get_CPU_time_used() to get the CPU usage of a thread using proper locks to get a consistent value. Close #2627.
Diffstat (limited to 'cpukit/libmisc/cpuuse/cpuusagetop.c')
-rw-r--r--cpukit/libmisc/cpuuse/cpuusagetop.c23
1 files changed, 3 insertions, 20 deletions
diff --git a/cpukit/libmisc/cpuuse/cpuusagetop.c b/cpukit/libmisc/cpuuse/cpuusagetop.c
index 6355e4e636..9b928588c7 100644
--- a/cpukit/libmisc/cpuuse/cpuusagetop.c
+++ b/cpukit/libmisc/cpuuse/cpuusagetop.c
@@ -218,12 +218,14 @@ static void
task_usage(Thread_Control* thread, void* arg)
{
rtems_cpu_usage_data* data = (rtems_cpu_usage_data*) arg;
- Timestamp_Control usage = thread->cpu_time_used;
+ Timestamp_Control usage;
Timestamp_Control current = data->zero;
int j;
data->stack_size += thread->Start.Initial_stack.size;
+ _Thread_Get_CPU_time_used(thread, &usage);
+
for (j = 0; j < data->last_task_count; j++)
{
if (thread == data->last_tasks[j])
@@ -497,25 +499,6 @@ rtems_cpuusage_top_thread (rtems_task_argument arg)
current_usage = data->current_usage[i];
/*
- * If this is the currently executing thread, account for time since
- * the last context switch.
- */
- if (_Thread_Get_time_of_last_context_switch(thread, &last))
- {
- Timestamp_Control used;
- Timestamp_Control now;
-
- /*
- * Get the current uptime and assume we are not pre-empted to
- * measure the time from the last switch this thread and now.
- */
- _TOD_Get_uptime(&now);
- _Timestamp_Subtract(&last, &now, &used);
- _Timestamp_Add_to(&usage, &used);
- _Timestamp_Add_to(&current_usage, &used);
- }
-
- /*
* Print the information
*/
print_time(data, &usage, 19);