diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2017-08-07 12:33:08 -0400 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2017-08-08 00:27:28 -0400 |
commit | 2c272f99a3fac49d8acd4b49a1aa3302225f17b8 (patch) | |
tree | 07998c722ed20fa812de26e1941daf57a030271f /src/basecmd.c | |
parent | a9982beacf184ccdc4bf1221852c900b0809537d (diff) | |
download | kutter-2c272f99a3fac49d8acd4b49a1aa3302225f17b8.tar.gz kutter-2c272f99a3fac49d8acd4b49a1aa3302225f17b8.tar.xz kutter-2c272f99a3fac49d8acd4b49a1aa3302225f17b8.zip |
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 <kevin@koconnor.net>
Diffstat (limited to 'src/basecmd.c')
-rw-r--r-- | src/basecmd.c | 24 |
1 files changed, 6 insertions, 18 deletions
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); /**************************************************************** |