From 5c20b2176cdfc588773913aa5606efa4276039ca Mon Sep 17 00:00:00 2001 From: Maurus Cuelenaere Date: Mon, 5 Apr 2010 19:36:34 +0200 Subject: [PATCH] Add simple per-thread runtime variable and make it accessible through the debug menu. Signed-off-by: Maurus Cuelenaere --- apps/debug_menu.c | 4 ++-- firmware/export/thread.h | 1 + firmware/thread.c | 4 ++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/apps/debug_menu.c b/apps/debug_menu.c index fbaae57..73f8669 100644 --- a/apps/debug_menu.c +++ b/apps/debug_menu.c @@ -175,7 +175,7 @@ static const char* threads_getname(int selected_item, void *data, thread_get_name(name, 32, thread); snprintf(buffer, buffer_len, - "%2d: " IF_COP("(%d) ") "%c%c " IF_PRIO("%d %d ") "%2d%% %s", + "%2d: " IF_COP("(%d) ") "%c%c " IF_PRIO("%d %d ") "%2d%% %s %ld.%02ld", selected_item, IF_COP(thread->core,) #ifdef HAVE_SCHEDULER_BOOSTCTRL @@ -184,7 +184,7 @@ static const char* threads_getname(int selected_item, void *data, ((thread->state == STATE_RUNNING) ? '*' : ' '), thread_status_char(thread->state), IF_PRIO(thread->base_priority, thread->priority, ) - thread_stack_usage(thread), name); + thread_stack_usage(thread), name, thread->runtime / HZ, thread->runtime % HZ); return buffer; } diff --git a/firmware/export/thread.h b/firmware/export/thread.h index a75981d..7928ce9 100644 --- a/firmware/export/thread.h +++ b/firmware/export/thread.h @@ -300,6 +300,7 @@ struct thread_entry #ifdef HAVE_IO_PRIORITY unsigned char io_priority; #endif + long runtime; /* Thread runtime in ticks */ }; /*** Macros for internal use ***/ diff --git a/firmware/thread.c b/firmware/thread.c index 81ef42a..3cf89c9 100644 --- a/firmware/thread.c +++ b/firmware/thread.c @@ -1970,6 +1970,7 @@ void switch_thread(void) const unsigned int core = CURRENT_CORE; struct thread_entry *block = cores[core].block_task; struct thread_entry *thread = cores[core].running; + static long last_tick = 0; /* Get context to save - next thread to run is unknown until all wakeups * are evaluated */ @@ -1997,6 +1998,8 @@ void switch_thread(void) profile_thread_stopped(thread->id & THREAD_ID_SLOT_MASK); #endif + thread->runtime += current_tick - last_tick; + /* Begin task switching by saving our current context so that we can * restore the state of the current thread later to the point prior * to this call. */ @@ -2102,6 +2105,7 @@ void switch_thread(void) profile_thread_started(thread->id & THREAD_ID_SLOT_MASK); #endif + last_tick = current_tick; } /*--------------------------------------------------------------------------- -- 1.7.0.3