From ffd8088d1dc2d539b590baaebc9da72ec3b7595c Mon Sep 17 00:00:00 2001 From: Ludwig Ortmann Date: Sat, 16 Nov 2013 19:26:02 +0100 Subject: [PATCH 1/2] proper inttype runtime, declare to import define runtime long as hwtimer_now() uses long import hwtimer.h instead of declaring hwtimer_now() --- core/include/sched.h | 2 +- core/sched.c | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/core/include/sched.h b/core/include/sched.h index 4ca62ff7f7..db3654a634 100644 --- a/core/include/sched.h +++ b/core/include/sched.h @@ -90,7 +90,7 @@ typedef struct { unsigned int laststart; /*< Time stamp of the last time this thread was scheduled to run */ unsigned int schedules; /*< How often the thread was scheduled to run */ - unsigned int runtime; /*< The total runtime of this thread */ + unsigned long runtime; /*< The total runtime of this thread */ } schedstat; /** diff --git a/core/sched.c b/core/sched.c index 85c67a81d6..7c33d81f79 100644 --- a/core/sched.c +++ b/core/sched.c @@ -7,6 +7,8 @@ * Public License. See the file LICENSE in the top level directory for more * details. * + * TODO: setup dependency from SCHEDSTATISTICS to MODULE_HWTIMER + * * @ingroup kernel * @{ * @file @@ -21,6 +23,10 @@ #include #include +#if SCHEDSTATISTICS +#include "hwtimer.h" +#endif + #define ENABLE_DEBUG (0) #include @@ -87,10 +93,8 @@ void sched_run() } -#if SCHEDSTATISTICS - /* TODO: setup dependency from SCHEDSTATISTICS to MODULE_HWTIMER */ - extern unsigned long hwtimer_now(void); - unsigned int time = hwtimer_now(); +#ifdef SCHEDSTATISTICS + unsigned long time = hwtimer_now(); if (my_active_thread && (pidlist[my_active_thread->pid].laststart)) { pidlist[my_active_thread->pid].runtime += time - pidlist[my_active_thread->pid].laststart; From d06e0d8717440e1fbea225697f017e1e1ec0618b Mon Sep 17 00:00:00 2001 From: Ludwig Ortmann Date: Mon, 18 Nov 2013 12:14:43 +0100 Subject: [PATCH 2/2] rename runtime to reflect the unit of measurement --- core/include/sched.h | 2 +- core/sched.c | 4 ++-- sys/ps/ps.c | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core/include/sched.h b/core/include/sched.h index db3654a634..1249bc81b2 100644 --- a/core/include/sched.h +++ b/core/include/sched.h @@ -90,7 +90,7 @@ typedef struct { unsigned int laststart; /*< Time stamp of the last time this thread was scheduled to run */ unsigned int schedules; /*< How often the thread was scheduled to run */ - unsigned long runtime; /*< The total runtime of this thread */ + unsigned long runtime_ticks; /*< The total runtime of this thread in ticks */ } schedstat; /** diff --git a/core/sched.c b/core/sched.c index 7c33d81f79..9a3de8b451 100644 --- a/core/sched.c +++ b/core/sched.c @@ -57,7 +57,7 @@ void sched_init() sched_threads[i] = NULL; #if SCHEDSTATISTICS pidlist[i].laststart = 0; - pidlist[i].runtime = 0; + pidlist[i].runtime_ticks = 0; pidlist[i].schedules = 0; #endif } @@ -97,7 +97,7 @@ void sched_run() unsigned long time = hwtimer_now(); if (my_active_thread && (pidlist[my_active_thread->pid].laststart)) { - pidlist[my_active_thread->pid].runtime += time - pidlist[my_active_thread->pid].laststart; + pidlist[my_active_thread->pid].runtime_ticks += time - pidlist[my_active_thread->pid].laststart; } #endif diff --git a/sys/ps/ps.c b/sys/ps/ps.c index 600dad0cbb..719eef75b7 100644 --- a/sys/ps/ps.c +++ b/sys/ps/ps.c @@ -54,16 +54,16 @@ void thread_print_all(void) const char *sname = state_names[statebit]; // get state name const char *queued = queued_name + (state & BIT0); // get queued flag int stacksz = p->stack_size; // get max used stack - double runtime = 0 / 0.0; + double runtime_ticks = 0 / 0.0; int switches = -1; #if SCHEDSTATISTICS - runtime = pidlist[i].runtime / (double) hwtimer_now() * 100; + runtime_ticks = pidlist[i].runtime_ticks / (double) hwtimer_now() * 100; switches = pidlist[i].schedules; #endif overall_stacksz += stacksz; stacksz -= thread_measure_stack_usage(p->stack_start); printf("\t%3u | %-21s| %-8s %.1s | %3i | %5i (%5i) %p | %6.3f%% | ", - p->pid, p->name, sname, queued, p->priority, p->stack_size, stacksz, p->stack_start, runtime); + p->pid, p->name, sname, queued, p->priority, p->stack_size, stacksz, p->stack_start, runtime_ticks); printf(" %8u\n", switches); } }