From 2c272f99a3fac49d8acd4b49a1aa3302225f17b8 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Mon, 7 Aug 2017 12:33:08 -0400 Subject: sched: Implement generic sleep mechanism based on tasks pending Track when tasks are pending and spin in irq_wait() when no tasks are pending. This improves the mechanism for sleeping the processor - it's simpler for the board specific code and it reduces the possibility of the processor sleeping when tasks are busy. Signed-off-by: Kevin O'Connor --- src/basecmd.c | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) (limited to 'src/basecmd.c') diff --git a/src/basecmd.c b/src/basecmd.c index da21fad0..831b12e4 100644 --- a/src/basecmd.c +++ b/src/basecmd.c @@ -228,7 +228,6 @@ command_get_status(uint32_t *args) DECL_COMMAND_FLAGS(command_get_status, HF_IN_SHUTDOWN, "get_status"); static uint32_t stats_send_time, stats_send_time_high; -static uint32_t stats_last_time, stats_sleep_time; void command_get_uptime(uint32_t *args) @@ -239,24 +238,16 @@ command_get_uptime(uint32_t *args) } DECL_COMMAND_FLAGS(command_get_uptime, HF_IN_SHUTDOWN, "get_uptime"); -void -stats_note_sleep(uint32_t sleep_time) -{ - stats_sleep_time += sleep_time; - stats_last_time += sleep_time; -} - #define SUMSQ_BASE 256 DECL_CONSTANT(STATS_SUMSQ_BASE, SUMSQ_BASE); void -stats_task(void) +stats_update(uint32_t start, uint32_t cur) { - static uint32_t count, sumsq; - uint32_t cur = timer_read_time(); - uint32_t diff = cur - stats_last_time; - stats_last_time = cur; + static uint32_t count, sum, sumsq; + uint32_t diff = cur - start; count++; + sum += diff; // Calculate sum of diff^2 - be careful of integer overflow uint32_t nextsumsq; if (diff <= 0xffff) { @@ -272,15 +263,12 @@ stats_task(void) if (timer_is_before(cur, stats_send_time + timer_from_us(5000000))) return; - sendf("stats count=%u sum=%u sumsq=%u" - , count, cur - stats_send_time - stats_sleep_time, sumsq); + sendf("stats count=%u sum=%u sumsq=%u", count, sum, sumsq); if (cur < stats_send_time) stats_send_time_high++; stats_send_time = cur; - stats_sleep_time = 0; - count = sumsq = 0; + count = sum = sumsq = 0; } -DECL_TASK(stats_task); /**************************************************************** -- cgit v1.2.3-70-g09d2