Skip to content

Commit

Permalink
tracing/osnoise: Make osnoise_main to sleep for microseconds
Browse files Browse the repository at this point in the history
osnoise's runtime and period are in the microseconds scale, but it is
currently sleeping in the millisecond's scale. This behavior roots in the
usage of hwlat as the skeleton for osnoise.

Make osnoise to sleep in the microseconds scale. Also, move the sleep to
a specialized function.

Link: https://lkml.kernel.org/r/302aa6c7bdf2d131719b22901905e9da122a11b2.1645197336.git.bristot@kernel.org

Cc: Ingo Molnar <mingo@redhat.com>
Signed-off-by: Daniel Bristot de Oliveira <bristot@kernel.org>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
  • Loading branch information
Daniel Bristot de Oliveira authored and Steven Rostedt (Google) committed Feb 25, 2022
1 parent ab2f993 commit dd99035
Showing 1 changed file with 32 additions and 21 deletions.
53 changes: 32 additions & 21 deletions kernel/trace/trace_osnoise.c
Original file line number Diff line number Diff line change
Expand Up @@ -1436,6 +1436,37 @@ static int run_osnoise(void)
static struct cpumask osnoise_cpumask;
static struct cpumask save_cpumask;

/*
* osnoise_sleep - sleep until the next period
*/
static void osnoise_sleep(void)
{
u64 interval;
ktime_t wake_time;

mutex_lock(&interface_lock);
interval = osnoise_data.sample_period - osnoise_data.sample_runtime;
mutex_unlock(&interface_lock);

/*
* differently from hwlat_detector, the osnoise tracer can run
* without a pause because preemption is on.
*/
if (!interval) {
/* Let synchronize_rcu_tasks() make progress */
cond_resched_tasks_rcu_qs();
return;
}

wake_time = ktime_add_us(ktime_get(), interval);
__set_current_state(TASK_INTERRUPTIBLE);

while (schedule_hrtimeout_range(&wake_time, 0, HRTIMER_MODE_ABS)) {
if (kthread_should_stop())
break;
}
}

/*
* osnoise_main - The osnoise detection kernel thread
*
Expand All @@ -1444,30 +1475,10 @@ static struct cpumask save_cpumask;
*/
static int osnoise_main(void *data)
{
u64 interval;

while (!kthread_should_stop()) {

run_osnoise();

mutex_lock(&interface_lock);
interval = osnoise_data.sample_period - osnoise_data.sample_runtime;
mutex_unlock(&interface_lock);

do_div(interval, USEC_PER_MSEC);

/*
* differently from hwlat_detector, the osnoise tracer can run
* without a pause because preemption is on.
*/
if (interval < 1) {
/* Let synchronize_rcu_tasks() make progress */
cond_resched_tasks_rcu_qs();
continue;
}

if (msleep_interruptible(interval))
break;
osnoise_sleep();
}

return 0;
Expand Down

0 comments on commit dd99035

Please sign in to comment.