Skip to content

Commit

Permalink
tracing: Fix wakeup_rt self test on virtual machines
Browse files Browse the repository at this point in the history
The warkeup_rt self test used msleep() calls to wait for real time
tasks to wake up and run. On bare-metal hardware, this was enough as
the scheduler should let the RT task run way before the non-RT task
wakes up from the msleep(). If it did not, then that would mean the
scheduler was broken.

But when dealing with virtual machines, this is a different story.
If the RT task wakes up on a VCPU, it's up to the host to decide when
that task gets to schedule, which can be far behind the time that the
non-RT task wakes up. In this case, the test would fail incorrectly.

As we are not testing the scheduler, but instead the wake up tracing,
we can use completions to wait and not depend on scheduler timings
to see if events happen on time.

Link: http://lkml.kernel.org/r/1343663105.3847.7.camel@fedora

Reported-by: Fengguang Wu <[email protected]>
Tested-by: Fengguang Wu <[email protected]>
Signed-off-by: Steven Rostedt <[email protected]>
  • Loading branch information
Steven Rostedt authored and rostedt committed Aug 7, 2012
1 parent e525389 commit 3c18c10
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions kernel/trace/trace_selftest.c
Original file line number Diff line number Diff line change
Expand Up @@ -1041,6 +1041,8 @@ static int trace_wakeup_test_thread(void *data)
set_current_state(TASK_INTERRUPTIBLE);
schedule();

complete(x);

/* we are awake, now wait to disappear */
while (!kthread_should_stop()) {
/*
Expand Down Expand Up @@ -1084,24 +1086,21 @@ trace_selftest_startup_wakeup(struct tracer *trace, struct trace_array *tr)
/* reset the max latency */
tracing_max_latency = 0;

/* sleep to let the RT thread sleep too */
msleep(100);
while (p->on_rq) {
/*
* Sleep to make sure the RT thread is asleep too.
* On virtual machines we can't rely on timings,
* but we want to make sure this test still works.
*/
msleep(100);
}

/*
* Yes this is slightly racy. It is possible that for some
* strange reason that the RT thread we created, did not
* call schedule for 100ms after doing the completion,
* and we do a wakeup on a task that already is awake.
* But that is extremely unlikely, and the worst thing that
* happens in such a case, is that we disable tracing.
* Honestly, if this race does happen something is horrible
* wrong with the system.
*/
init_completion(&isrt);

wake_up_process(p);

/* give a little time to let the thread wake up */
msleep(100);
/* Wait for the task to wake up */
wait_for_completion(&isrt);

/* stop the tracing. */
tracing_stop();
Expand Down

0 comments on commit 3c18c10

Please sign in to comment.