Subject: [PATCH V2 0/3] osnoise/timerlat improvements

These three patches are improvements for the osnoise/timerlat tracers,
mainly to support rtla. The first one is a dependency for the -C <cgroup>
command line option to be added to rtla. It is essential to allow
timerlat/osnoise to measure the latencies from the container/cgroup
point of view. The second improves rtla time for saving tracing after
a stop tracing condition on osnoise/hwnoise.

The third patch adds the osnoise/per_cpu/cpu$id/timerlat_fd file
where timerlat expects a pinned user thread to open and read from it.
When the thread reads it, it actually activates timerlat latency
measurement mechanism, so timerlat can be activated from an user-space
thread. Timerlat is also expanded to report the return from user-space
latency when read is called after the first call, so adding another
metric to timerlat, that can either represent the kernel-to-user and
user-to-kernel overhead, or to measure the execution time of any
workload. Details are added to the kernel documentation.

Changes from V1:
- Added the user-space interface patch
- Link: https://lore.kernel.org/lkml/[email protected]/

Daniel Bristot de Oliveira (3):
tracing/osnoise: Switch from PF_NO_SETAFFINITY to migrate_disable
tracing/osnoise: Skip running osnoise if all instances are off
tracing/timerlat: Add user-space interface

Documentation/trace/timerlat-tracer.rst | 78 +++++
kernel/trace/trace_osnoise.c | 411 +++++++++++++++++++++++-
kernel/trace/trace_output.c | 4 +-
3 files changed, 487 insertions(+), 6 deletions(-)

--
2.38.1



Subject: [PATCH V2 2/3] 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.

Cc: Steven Rostedt <[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]>
---
kernel/trace/trace_osnoise.c | 31 ++++++++++++++++++++++++++++---
1 file changed, 28 insertions(+), 3 deletions(-)

diff --git a/kernel/trace/trace_osnoise.c b/kernel/trace/trace_osnoise.c
index c265ec5f1726..220172cb874d 100644
--- a/kernel/trace/trace_osnoise.c
+++ b/kernel/trace/trace_osnoise.c
@@ -1285,6 +1285,22 @@ static __always_inline void osnoise_stop_tracing(void)
rcu_read_unlock();
}

+/*
+ * osnoise_has_tracing_on - Check if there is at least one instance on
+ */
+static __always_inline int osnoise_has_tracing_on(void)
+{
+ struct osnoise_instance *inst;
+ int trace_is_on = 0;
+
+ rcu_read_lock();
+ list_for_each_entry_rcu(inst, &osnoise_instances, list)
+ trace_is_on += tracer_tracing_is_on(inst->tr);
+ rcu_read_unlock();
+
+ return trace_is_on;
+}
+
/*
* notify_new_max_latency - Notify a new max latency via fsnotify interface.
*/
@@ -1517,13 +1533,16 @@ static struct cpumask save_cpumask;
/*
* osnoise_sleep - sleep until the next period
*/
-static void osnoise_sleep(void)
+static void osnoise_sleep(bool skip_period)
{
u64 interval;
ktime_t wake_time;

mutex_lock(&interface_lock);
- interval = osnoise_data.sample_period - osnoise_data.sample_runtime;
+ if (skip_period)
+ interval = osnoise_data.sample_period;
+ else
+ interval = osnoise_data.sample_period - osnoise_data.sample_runtime;
mutex_unlock(&interface_lock);

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

+ /* skip a period if tracing is off on all instances */
+ if (!osnoise_has_tracing_on()) {
+ osnoise_sleep(true);
+ continue;
+ }
+
run_osnoise();
- osnoise_sleep();
+ osnoise_sleep(false);
}

migrate_enable();
--
2.38.1