From: Crystal Wood <crwood@redhat.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Tomas Glozar <tglozar@redhat.com>, John Kacur <jkacur@redhat.com>,
linux-trace-kernel@vger.kernel.org,
Crystal Wood <crwood@redhat.com>
Subject: [PATCH v7 01/10] tracing/osnoise: Variable cleanup
Date: Fri, 13 Nov 2026 00:40:54 -0600 [thread overview]
Message-ID: <20261113064103.3041704-2-crwood@redhat.com> (raw)
In-Reply-To: <20261113064103.3041704-1-crwood@redhat.com>
Add cpu_osn_var/cpu_tmr_var() accessors and use them.
Timerlat threads aren't always kthreads, so rename the variable to just
"thread".
rel_period isn't used at all, so remove it.
Signed-off-by: Crystal Wood <crwood@redhat.com>
---
v7: Add osn variable to start_kthread(), replacing individual calls to
cpu_osn_var(), which previously happened later in the patch set.
This avoids a temporary build break in the next patch.
---
kernel/trace/trace_osnoise.c | 54 +++++++++++++++++++++---------------
1 file changed, 32 insertions(+), 22 deletions(-)
diff --git a/kernel/trace/trace_osnoise.c b/kernel/trace/trace_osnoise.c
index 995da9e0b548..2f3cbe71d313 100644
--- a/kernel/trace/trace_osnoise.c
+++ b/kernel/trace/trace_osnoise.c
@@ -251,6 +251,11 @@ static inline struct osnoise_variables *this_cpu_osn_var(void)
return this_cpu_ptr(&per_cpu_osnoise_var);
}
+static inline struct osnoise_variables *cpu_osn_var(int cpu)
+{
+ return per_cpu_ptr(&per_cpu_osnoise_var, cpu);
+}
+
/*
* Protect the interface.
*/
@@ -261,9 +266,8 @@ static struct mutex interface_lock;
* Runtime information for the timer mode.
*/
struct timerlat_variables {
- struct task_struct *kthread;
+ struct task_struct *thread;
struct hrtimer timer;
- u64 rel_period;
u64 abs_period;
bool tracing_thread;
u64 count;
@@ -285,6 +289,11 @@ static inline struct timerlat_variables *this_cpu_tmr_var(void)
return this_cpu_ptr(&per_cpu_timerlat_var);
}
+static inline struct timerlat_variables *cpu_tmr_var(int cpu)
+{
+ return per_cpu_ptr(&per_cpu_timerlat_var, cpu);
+}
+
/*
* tlat_var_reset - Reset the values of the given timerlat_variables
*/
@@ -301,8 +310,8 @@ static inline void tlat_var_reset(void)
* zeroing the structure is perfect.
*/
for_each_online_cpu(cpu) {
- tlat_var = per_cpu_ptr(&per_cpu_timerlat_var, cpu);
- if (tlat_var->kthread)
+ tlat_var = cpu_tmr_var(cpu);
+ if (tlat_var->thread)
hrtimer_cancel(&tlat_var->timer);
memset(tlat_var, 0, sizeof(*tlat_var));
}
@@ -331,7 +340,7 @@ static inline void osn_var_reset(void)
* zeroing the structure is perfect.
*/
for_each_online_cpu(cpu) {
- osn_var = per_cpu_ptr(&per_cpu_osnoise_var, cpu);
+ osn_var = cpu_osn_var(cpu);
memset(osn_var, 0, sizeof(*osn_var));
}
}
@@ -1227,9 +1236,9 @@ static void trace_sched_migrate_callback(void *data, struct task_struct *p, int
struct osnoise_variables *osn_var;
long cpu = task_cpu(p);
- osn_var = per_cpu_ptr(&per_cpu_osnoise_var, cpu);
+ osn_var = cpu_osn_var(cpu);
if (osn_var->pid == p->pid && dest_cpu != cpu) {
- per_cpu_ptr(&per_cpu_timerlat_var, cpu)->uthread_migrate = 1;
+ cpu_tmr_var(cpu)->uthread_migrate = 1;
osnoise_taint("timerlat user-thread migrated\n");
osnoise_stop_exception("timerlat user-thread migrated", cpu);
}
@@ -1827,13 +1836,13 @@ static enum hrtimer_restart timerlat_irq(struct hrtimer *timer)
osnoise_stop_tracing();
notify_new_max_latency(diff);
- wake_up_process(tlat->kthread);
+ wake_up_process(tlat->thread);
return HRTIMER_NORESTART;
}
}
- wake_up_process(tlat->kthread);
+ wake_up_process(tlat->thread);
if (osnoise_data.print_stack)
timerlat_save_stack(0);
@@ -1926,7 +1935,7 @@ static int timerlat_main(void *data)
tlat->tracing_thread = false;
hrtimer_setup(&tlat->timer, timerlat_irq, CLOCK_MONOTONIC, HRTIMER_MODE_ABS_PINNED_HARD);
- tlat->kthread = current;
+ tlat->thread = current;
osn_var->pid = current->pid;
/*
* Annotate the arrival time.
@@ -1981,7 +1990,7 @@ static void stop_kthread(unsigned int cpu)
{
struct task_struct *kthread;
- kthread = xchg_relaxed(&(per_cpu(per_cpu_osnoise_var, cpu).kthread), NULL);
+ kthread = xchg_relaxed(&cpu_osn_var(cpu)->kthread, NULL);
if (kthread) {
if (cpumask_test_and_clear_cpu(cpu, &kthread_cpumask) &&
!WARN_ON(!test_bit(OSN_WORKLOAD, &osnoise_options))) {
@@ -2001,7 +2010,7 @@ static void stop_kthread(unsigned int cpu)
/*
* This is set in the osnoise tracer case.
*/
- per_cpu(per_cpu_osnoise_var, cpu).sampling = false;
+ cpu_osn_var(cpu)->sampling = false;
barrier();
}
}
@@ -2030,12 +2039,13 @@ static void stop_per_cpu_kthreads(void)
*/
static int start_kthread(unsigned int cpu)
{
+ struct osnoise_variables *osn = cpu_osn_var(cpu);
struct task_struct *kthread;
void *main = osnoise_main;
char comm[24];
/* Do not start a new thread if it is already running */
- if (per_cpu(per_cpu_osnoise_var, cpu).kthread)
+ if (osn->kthread)
return 0;
if (timerlat_enabled()) {
@@ -2044,7 +2054,7 @@ static int start_kthread(unsigned int cpu)
} else {
/* if no workload, just return */
if (!test_bit(OSN_WORKLOAD, &osnoise_options)) {
- per_cpu(per_cpu_osnoise_var, cpu).sampling = true;
+ osn->sampling = true;
barrier();
return 0;
}
@@ -2058,7 +2068,7 @@ static int start_kthread(unsigned int cpu)
return -ENOMEM;
}
- per_cpu(per_cpu_osnoise_var, cpu).kthread = kthread;
+ osn->kthread = kthread;
cpumask_set_cpu(cpu, &kthread_cpumask);
return 0;
@@ -2091,7 +2101,7 @@ static int start_per_cpu_kthreads(void)
if (cpumask_test_and_clear_cpu(cpu, &kthread_cpumask)) {
struct task_struct *kthread;
- kthread = xchg_relaxed(&(per_cpu(per_cpu_osnoise_var, cpu).kthread), NULL);
+ kthread = xchg_relaxed(&cpu_osn_var(cpu)->kthread, NULL);
if (!WARN_ON(!kthread))
kthread_stop(kthread);
}
@@ -2520,7 +2530,7 @@ timerlat_fd_read(struct file *file, char __user *ubuf, size_t count,
return -EINVAL;
}
} else {
- per_cpu_ptr(&per_cpu_timerlat_var, cpu)->uthread_migrate = 1;
+ cpu_tmr_var(cpu)->uthread_migrate = 1;
osnoise_taint("timerlat user thread migrate\n");
osnoise_stop_tracing();
migrate_enable();
@@ -2564,7 +2574,7 @@ timerlat_fd_read(struct file *file, char __user *ubuf, size_t count,
}
} else {
tlat->tracing_thread = false;
- tlat->kthread = current;
+ tlat->thread = current;
/* Annotate now to drift new period */
tlat->abs_period = hrtimer_cb_get_time(&tlat->timer);
@@ -2613,10 +2623,10 @@ static int timerlat_fd_release(struct inode *inode, struct file *file)
migrate_disable();
mutex_lock(&interface_lock);
- osn_var = per_cpu_ptr(&per_cpu_osnoise_var, cpu);
- tlat_var = per_cpu_ptr(&per_cpu_timerlat_var, cpu);
+ osn_var = cpu_osn_var(cpu);
+ tlat_var = cpu_tmr_var(cpu);
- if (tlat_var->kthread)
+ if (tlat_var->thread)
hrtimer_cancel(&tlat_var->timer);
memset(tlat_var, 0, sizeof(*tlat_var));
@@ -3096,7 +3106,7 @@ static void timerlat_tracer_stop(struct trace_array *tr)
*/
if (!osnoise_has_registered_instances()) {
for_each_online_cpu(cpu)
- per_cpu(per_cpu_osnoise_var, cpu).sampling = 0;
+ cpu_osn_var(cpu)->sampling = 0;
}
osnoise_workload_stop();
--
2.56.0
next prev parent reply other threads:[~2026-11-13 6:41 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-13 6:40 [PATCH v7 00/10] tracing/osnoise: Synchronization fixes Crystal Wood
2026-11-13 6:40 ` Crystal Wood [this message]
2026-11-13 6:40 ` [PATCH v7 02/10] tracing/osnoise: start_kthread: Always check OSN_WORKLOAD Crystal Wood
2026-11-13 6:40 ` [PATCH v7 03/10] tracing/osnoise: Start all eligible cpus from hotplug workfn Crystal Wood
2026-11-13 6:51 ` sashiko-bot
2026-11-13 6:40 ` [PATCH v7 04/10] tracing/osnoise: Hold a ref on osn->kthread Crystal Wood
2026-11-13 6:40 ` [PATCH v7 05/10] tracing/osnoise: Per-cpu mutexes and fd detachment Crystal Wood
2026-11-13 6:40 ` [PATCH v7 06/10] tracing/osnoise: Reset cleanup Crystal Wood
2026-11-13 6:41 ` [PATCH v7 07/10] tracing/osnoise: kthreads: Verify CPU after migrate_disable() Crystal Wood
2026-11-13 6:41 ` [PATCH v7 08/10] tracing/osnoise: Take trace_types_lock in timerlat_fd_open Crystal Wood
2026-11-13 6:41 ` [PATCH v7 09/10] tracing/osnoise: Print taint message for timerlat Crystal Wood
2026-11-13 6:41 ` [PATCH v7 10/10] tracing/osnoise: Refuse timerlat fd open if tracer inactive Crystal Wood
2026-11-13 6:55 ` sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261113064103.3041704-2-crwood@redhat.com \
--to=crwood@redhat.com \
--cc=jkacur@redhat.com \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=rostedt@goodmis.org \
--cc=tglozar@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox