Skip to content

Commit 003010d

Browse files
committed
MCS: Add periodic drift test
If this test fails, TIMER_OVERHEAD_TICKS may not be set correctly for the platform. Needs seL4 pull #847 applied to pass. Signed-off-by: Indan Zupancic <Indan.Zupancic@mep-info.com>
1 parent ecaf208 commit 003010d

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

apps/sel4test-tests/src/tests/scheduler.c

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1697,3 +1697,65 @@ static int test_changing_affinity(struct env *env)
16971697
}
16981698
DEFINE_TEST(SCHED0022, "test changing a helper threads core", test_changing_affinity,
16991699
(config_set(CONFIG_KERNEL_MCS) &&(CONFIG_MAX_NUM_NODES > 1)));
1700+
1701+
static void yielding_thread(int id, volatile unsigned long *counters)
1702+
{
1703+
counters[id] = 0;
1704+
while (1) {
1705+
counters[id]++;
1706+
seL4_Yield();
1707+
}
1708+
}
1709+
1710+
#define M (200) // Minimum budget
1711+
#define P (2 * M)
1712+
#define N (US_IN_S / P)
1713+
1714+
static int run_test_period_drift(env_t env, int num_threads)
1715+
{
1716+
int error;
1717+
helper_thread_t t[num_threads];
1718+
volatile unsigned long counters[num_threads];
1719+
1720+
/* Create tasks with lower priority: */
1721+
for (int i = 0; i < num_threads; i++) {
1722+
create_helper_thread(env, &t[i]);
1723+
set_helper_priority(env, &t[i], env->priority - 1);
1724+
}
1725+
error = api_sched_ctrl_configure(simple_get_sched_ctrl(&env->simple, 0), // Core 0
1726+
t[0].thread.sched_context.cptr, P / 2, P, 0, 0);
1727+
test_error_eq(error, seL4_NoError);
1728+
if (num_threads > 1) {
1729+
error = api_sched_ctrl_configure(simple_get_sched_ctrl(&env->simple, 1), // Core 1
1730+
t[1].thread.sched_context.cptr, M, M, 0, 0);
1731+
test_error_eq(error, seL4_NoError);
1732+
}
1733+
1734+
/* Periodic task */
1735+
start_helper(env, &t[0], (helper_fn_t)yielding_thread, 0, (seL4_Word)counters, 0, 0);
1736+
if (num_threads > 1) {
1737+
/* Introduce lock contention with round-robin task on other core */
1738+
start_helper(env, &t[1], (helper_fn_t)yielding_thread, 1, (seL4_Word)counters, 0, 0);
1739+
}
1740+
1741+
/* Measure with P/2 margin: */
1742+
sel4test_sleep(env, 1 * NS_IN_S - P / 2 * 1000);
1743+
1744+
test_eq(counters[0], N);
1745+
1746+
return sel4test_get_result();
1747+
}
1748+
1749+
int test_period_drift(env_t env)
1750+
{
1751+
return run_test_period_drift(env, 1);
1752+
}
1753+
DEFINE_TEST(SCHED0023, "Test period drift", test_period_drift,
1754+
config_set(CONFIG_KERNEL_MCS) &&config_set(CONFIG_HAVE_TIMER))
1755+
1756+
int test_period_drift_smp(env_t env)
1757+
{
1758+
return run_test_period_drift(env, 2);
1759+
}
1760+
DEFINE_TEST(SCHED0024, "Test period drift SMP", test_period_drift_smp,
1761+
config_set(CONFIG_KERNEL_MCS) &&config_set(CONFIG_HAVE_TIMER) &&CONFIG_MAX_NUM_NODES > 1)

0 commit comments

Comments
 (0)