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>
This commit is contained in:
Kevin O'Connor 2017-08-07 12:33:08 -04:00
parent a9982beacf
commit 2c272f99a3
9 changed files with 60 additions and 80 deletions

View file

@ -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);
/****************************************************************