Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests/kernel/sched/schedule_api: Restore spinning for timer alignment #13916

Merged
merged 1 commit into from
Feb 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions tests/kernel/sched/schedule_api/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,28 @@
K_THREAD_STACK_DEFINE(tstack, STACK_SIZE);
K_THREAD_STACK_ARRAY_DEFINE(tstacks, MAX_NUM_THREAD, STACK_SIZE);

void spin_for_ms(int ms)
{
#if defined(CONFIG_X86_64) && defined(CONFIG_QEMU_TARGET)
/* qemu-system-x86_64 has a known bug with the hpet device
* where it will drop interrupts if you try to spin on the
* counter.
*/
k_busy_wait(ms * 1000);
#else
u32_t t32 = k_uptime_get_32();

while (k_uptime_get_32() - t32 < ms) {
/* In the posix arch, a busy loop takes no time, so
* let's make it take some
*/
if (IS_ENABLED(CONFIG_ARCH_POSIX)) {
k_busy_wait(50);
}
}
#endif
}

/**
* @brief Test scheduling
*
Expand Down
2 changes: 2 additions & 0 deletions tests/kernel/sched/schedule_api/src/test_sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ struct thread_data {
int executed;
};

void spin_for_ms(int ticks);

void test_priority_cooperative(void);
void test_priority_preemptible(void);
void test_yield_cooperative(void);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ static void thread_tslice(void *p1, void *p2, void *p3)
/* Keep the current thread busy for more than one slice, even though,
* when timeslice used up the next thread should be scheduled in.
*/
k_busy_wait(1000 * BUSY_MS);
spin_for_ms(BUSY_MS);
k_sem_give(&sema);
}

Expand Down
4 changes: 2 additions & 2 deletions tests/kernel/sched/schedule_api/src/test_slice_scheduling.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ static void thread_tslice(void *p1, void *p2, void *p3)
* even though, when timeslice used up the next thread
* should be scheduled in.
*/
k_busy_wait(1000 * BUSY_MS);
spin_for_ms(BUSY_MS);
k_sem_give(&sema1);
}

Expand Down Expand Up @@ -102,7 +102,7 @@ void test_slice_scheduling(void)
* even though, when timeslice used up the next thread
* should be scheduled in.
*/
k_busy_wait(1000 * BUSY_MS);
spin_for_ms(BUSY_MS);

/* relinquish CPU and wait for each thread to complete*/
for (int i = 0; i < NUM_THREAD; i++) {
Expand Down