summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Boichat <drinkcat@chromium.org>2019-05-22 13:16:42 +0800
committerchrome-bot <chrome-bot@chromium.org>2019-05-24 05:57:40 -0700
commit78ec9d739a404a64b03d50d5b83c0520b790f7a6 (patch)
treef07d87c3efa18f9e04eb9d8afc61405629eb0350
parent99900cae2fa4e17b6c1433111f4c142ebf27c024 (diff)
downloadchrome-ec-78ec9d739a404a64b03d50d5b83c0520b790f7a6.tar.gz
core/host/task: Add OS sleeps instead of busy-looping
When running on a busy builder, fuzzing tests often time out. I suspect this is due to the fact that one of the thread is busy looping, and for some reason, does not give enough time for other threads to run. Fix the issue by using nanosleep OS call (avoiding namespace clash with msleep/usleep that are implemented differently). From the builder stack traces, we know these tests often fail in 2 busy-loops, so fix those. BRANCH=none BUG=chromium:963768 TEST=Emulate busy system with 4 cores only: taskset 0xf yes > /dev/null & (about ten times) Then run tests: while taskset 0xf build/host/usb_pd_fuzz/usb_pd_fuzz.exe \ -runs=1; do :; done => No failures after 30 minutes. Change-Id: I458ff783d166e27fb38dc33853f08e5b3acba980 Signed-off-by: Nicolas Boichat <drinkcat@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1623050 Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Manoj Gupta <manojgupta@chromium.org>
-rw-r--r--core/host/task.c24
1 files changed, 22 insertions, 2 deletions
diff --git a/core/host/task.c b/core/host/task.c
index 5ec77d689e..3a2ff8974c 100644
--- a/core/host/task.c
+++ b/core/host/task.c
@@ -65,6 +65,23 @@ CONFIG_TEST_TASK_LIST
CONFIG_CTS_TASK_LIST
#undef TASK
+/* usleep that uses OS functions, instead of emulated timer. */
+void _usleep(int usec)
+{
+ struct timespec req;
+
+ req.tv_sec = usec / 1000000;
+ req.tv_nsec = (usec % 1000000) * 1000;
+
+ nanosleep(&req, NULL);
+}
+
+/* msleep that uses OS functions, instead of emulated timer. */
+void _msleep(int msec)
+{
+ _usleep(1000 * msec);
+}
+
/* Idle task */
void __idle(void *d)
{
@@ -156,7 +173,7 @@ void task_trigger_test_interrupt(void (*isr)(void))
/* Wait for ISR to complete */
sem_wait(&interrupt_sem);
while (in_interrupt)
- ;
+ _usleep(10);
pending_isr = NULL;
pthread_mutex_unlock(&interrupt_lock);
@@ -285,13 +302,16 @@ static void _wait_for_task_started(int can_sleep)
while (1) {
ok = 1;
- for (i = 0; i < TASK_ID_COUNT - 1; ++i)
+ for (i = 0; i < TASK_ID_COUNT - 1; ++i) {
if (!tasks[i].started) {
if (can_sleep)
msleep(10);
+ else
+ _msleep(10);
ok = 0;
break;
}
+ }
if (ok)
return;
}