Skip to content

Commit eb67bb0

Browse files
tests: kernel: workq: work_queue: use k_busy_wait to sim work
System workqueue items must not use blocking APIs, like k_msleep(). Replace k_msleep() with k_busy_wait() to both adhere to this rule, and to better emulate more realistic work being done by system workqueue. Signed-off-by: Bjarki Arge Andreasen <[email protected]>
1 parent bb1e9f9 commit eb67bb0

File tree

1 file changed

+9
-2
lines changed
  • tests/kernel/workq/work_queue/src

1 file changed

+9
-2
lines changed

tests/kernel/workq/work_queue/src/main.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ LOG_MODULE_REGISTER(test);
3232
#define WORK_ITEM_WAIT_ALIGNED \
3333
k_ticks_to_ms_floor64(k_ms_to_ticks_ceil32(WORK_ITEM_WAIT) + _TICK_ALIGN)
3434

35+
/*
36+
* System work queue is not allowed to unready threads. k_busy_wait() is
37+
* used to simulate work. It is higly inprecise, use way lower wait to
38+
* account for this.
39+
*/
40+
#define WORK_ITEM_BUSY_WAIT ((WORK_ITEM_WAIT * USEC_PER_MSEC) / 4)
41+
3542
/*
3643
* Wait 50ms between work submissions, to ensure co-op and prempt
3744
* preempt thread submit alternatively.
@@ -97,7 +104,7 @@ static void work_handler(struct k_work *work)
97104
CONTAINER_OF(dwork, struct delayed_test_item, work);
98105

99106
LOG_DBG(" - Running test item %d", ti->key);
100-
k_msleep(WORK_ITEM_WAIT);
107+
k_busy_wait(WORK_ITEM_BUSY_WAIT);
101108

102109
results[num_results++] = ti->key;
103110
}
@@ -211,7 +218,7 @@ static void resubmit_work_handler(struct k_work *work)
211218
struct delayed_test_item *ti =
212219
CONTAINER_OF(dwork, struct delayed_test_item, work);
213220

214-
k_msleep(WORK_ITEM_WAIT);
221+
k_busy_wait(WORK_ITEM_BUSY_WAIT);
215222

216223
results[num_results++] = ti->key;
217224

0 commit comments

Comments
 (0)