sched: KIST schedule() bad cast on monotime_diff_msec()
This code snippet creates a cast "overflow" from 64 bit to 32 bit:
diff = (int32_t) monotime_diff_msec(&scheduler_last_run, &now);
Because at boot time, scheduler_last_run
is set to 0 (static value), the diff that comes out is simply bigger than int32_t
everytime leading to a diff value that is negative.
And then we would add the next run to libevent with a humongeous usec value (and remember that diff
is big negative number):
next_run.tv_usec = (sched_run_interval - diff) * 1000;
Leading to libevent to fail to add the event and thus the scheduler never runs.
The fix here is to use int64_t
and BUG()
the event_add/active()
so we can catch such issue in the future.