Skip to content

Commit cb7ca87

Browse files
Daniel Bristot de Oliveirarostedt
authored andcommitted
tracing/osnoise: Skip running osnoise if all instances are off
In the case of all tracing instances being off, sleep for the entire period. Q: Why not kill all threads so? A: It is valid and useful to start the threads with tracing off. For example, rtla disables tracing, starts the tracer, applies the scheduling setup to the threads, e.g., sched priority and cgroup, and then begin tracing with all set. Skipping the period helps to speed up rtla setup and save the trace after a stop tracing. Link: https://lkml.kernel.org/r/aa4dd9b7e76fcb63901fe5407e15ec002b318599.1686063934.git.bristot@kernel.org Cc: Juri Lelli <[email protected]> Cc: William White <[email protected]> Cc: Daniel Bristot de Oliveira <[email protected]> Cc: Masami Hiramatsu <[email protected]> Cc: Jonathan Corbet <[email protected]> Signed-off-by: Daniel Bristot de Oliveira <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 4998e7f commit cb7ca87

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

kernel/trace/trace_osnoise.c

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,6 +1285,22 @@ static __always_inline void osnoise_stop_tracing(void)
12851285
rcu_read_unlock();
12861286
}
12871287

1288+
/*
1289+
* osnoise_has_tracing_on - Check if there is at least one instance on
1290+
*/
1291+
static __always_inline int osnoise_has_tracing_on(void)
1292+
{
1293+
struct osnoise_instance *inst;
1294+
int trace_is_on = 0;
1295+
1296+
rcu_read_lock();
1297+
list_for_each_entry_rcu(inst, &osnoise_instances, list)
1298+
trace_is_on += tracer_tracing_is_on(inst->tr);
1299+
rcu_read_unlock();
1300+
1301+
return trace_is_on;
1302+
}
1303+
12881304
/*
12891305
* notify_new_max_latency - Notify a new max latency via fsnotify interface.
12901306
*/
@@ -1517,13 +1533,16 @@ static struct cpumask save_cpumask;
15171533
/*
15181534
* osnoise_sleep - sleep until the next period
15191535
*/
1520-
static void osnoise_sleep(void)
1536+
static void osnoise_sleep(bool skip_period)
15211537
{
15221538
u64 interval;
15231539
ktime_t wake_time;
15241540

15251541
mutex_lock(&interface_lock);
1526-
interval = osnoise_data.sample_period - osnoise_data.sample_runtime;
1542+
if (skip_period)
1543+
interval = osnoise_data.sample_period;
1544+
else
1545+
interval = osnoise_data.sample_period - osnoise_data.sample_runtime;
15271546
mutex_unlock(&interface_lock);
15281547

15291548
/*
@@ -1604,8 +1623,14 @@ static int osnoise_main(void *data)
16041623
if (osnoise_migration_pending())
16051624
break;
16061625

1626+
/* skip a period if tracing is off on all instances */
1627+
if (!osnoise_has_tracing_on()) {
1628+
osnoise_sleep(true);
1629+
continue;
1630+
}
1631+
16071632
run_osnoise();
1608-
osnoise_sleep();
1633+
osnoise_sleep(false);
16091634
}
16101635

16111636
migrate_enable();

0 commit comments

Comments
 (0)