cortex-m: disallow rescheduling if task_start() has not yet run

Most GPIO/peripheral interrupts are enabled in HOOK_INIT or some other
*_init() functions that are called before task_start(). Quite a lot of
these IRQ handler wake some task to process the interrupt, and this
causes a race condition. If the interrupt is triggered before
task_start() is called, the system may crash/hang/whatever.

Fix this by only allowing rescheduling tasks if task_start() is called.
This is basically the cortex-m version of commit e541eeb2.

BRANCH=Ryu
BUG=None
TEST=Without this fix, my Ryu P3 always crashes when cold resetting from
bootloader mode. After applying this fix, it doesn't anymore.

Change-Id: I0f81e90482ff97469c4f0423d6aa060f2ac76f74
Signed-off-by: Vic Yang <victoryang@google.com>
Reviewed-on: https://chromium-review.googlesource.com/243626
Tested-by: Vic Yang <victoryang@chromium.org>
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Commit-Queue: Vic Yang <victoryang@chromium.org>
This commit is contained in:
Vic Yang
2015-01-27 14:18:23 -08:00
committed by ChromeOS Commit Bot
parent 7aa976d3a4
commit 3a1b5ec3dd

View File

@@ -359,7 +359,8 @@ uint32_t task_set_event(task_id_t tskid, uint32_t event, int wait)
/* The receiver might run again */
atomic_or(&tasks_ready, 1 << tskid);
#ifndef CONFIG_TASK_PROFILING
need_resched_or_profiling = 1;
if (start_called)
need_resched_or_profiling = 1;
#endif
} else {
if (wait)