trace/osnoise: Add trace events for samples
Subsystems (2)
PATCH v2 1/1 trace/osnoise: Add trace events for samples
Add trace events that fire at osnoise and timerlat sample generation, in addition to the already existing noise and threshold events.
This allows processing the samples directly in the kernel, either with ftrace triggers or with BPF.
---
A proof-of-concept bpftrace script using this feature:
https://gitlab.com/-/snippets/4801190
v2:
- Move "#ifndef _OSNOISE_TRACE_H" before "#define _OSNOISE_TRACE_H" to fix build. (Sorry about that, it was Friday.)
include/trace/events/osnoise.h | 96 ++++++++++++++++++++++++++++++++++ kernel/trace/trace_osnoise.c | 55 ++++++------------- 2 files changed, 112 insertions(+), 39 deletions(-)
include/trace/events/osnoise.h +96 -0
@@ -3,9 +3,105 @@#define TRACE_SYSTEM osnoise#if !defined(_OSNOISE_TRACE_H) || defined(TRACE_HEADER_MULTI_READ ) + +#ifndef _OSNOISE_TRACE_H#define _OSNOISE_TRACE_H +/* +* osnoise sample structure definition. Used to store the statistics of a +* sample run. +*/ +struct osnoise_sample { +u64 runtime;/* runtime */ +u64 noise;/* noise */ +u64 max_sample;/* max single noise sample */ +int hw_count;/* # HW (incl. hypervisor) interference */ +int nmi_count;/* # NMIs during this sample */ +int irq_count;/* # IRQs during this sample */ +int softirq_count;/* # softirqs during this sample */ +int thread_count;/* # threads during this sample */ +}; + +#ifdef CONFIG_TIMERLAT_TRACER +/* +* timerlat sample structure definition. Used to store the statistics of +* a sample run. +*/ +struct timerlat_sample { +u64 timer_latency;/* timer_latency */ +unsigned int seqnum;/* unique sequence */ +int context;/* timer context */ +}; +#endif // CONFIG_TIMERLAT_TRACER +#endif // _OSNOISE_TRACE_H #include <linux/tracepoint.h> +TRACE_EVENT (osnoise_sample, + + TP_PROTO(struct osnoise_sample *s), + +TP_ARGS (s), + +TP_STRUCT__entry ( + __field( u64, runtime ) + __field( u64, noise ) + __field( u64, max_sample ) + __field( int, hw_count ) + __field( int, irq_count ) + __field( int, nmi_count ) + __field( int, softirq_count ) +__field ( int, thread_count ) + ), + +TP_fast_assign ( + __entry->runtime = s->runtime; + __entry->noise = s->noise; + __entry->max_sample = s->max_sample; + __entry->hw_count = s->hw_count; + __entry->irq_count = s->irq_count; + __entry->nmi_count = s->nmi_count; + __entry->softirq_count = s->softirq_count; + __entry->thread_count = s->thread_count; + ), + +TP_printk ("runtime=%llu noise=%llu max_sample=%llu hw_count=%d" +" irq_count=%d nmi_count=%d softirq_count=%d" +" thread_count=%d" , + __entry->runtime, + __entry->noise, + __entry->max_sample, + __entry->hw_count, + __entry->irq_count, + __entry->nmi_count, + __entry->softirq_count, + __entry->thread_count) +); + +#ifdef CONFIG_TIMERLAT_TRACER +TRACE_EVENT (timerlat_sample, + + TP_PROTO(struct timerlat_sample *s), + +TP_ARGS (s), + +TP_STRUCT__entry ( + __field( u64, timer_latency ) + __field( unsigned int, seqnum ) +__field ( int, context ) + ), + +TP_fast_assign ( + __entry->timer_latency = s->timer_latency; + __entry->seqnum = s->seqnum; + __entry->context = s->context; + ), + +TP_printk ("timer_latency=%llu seqnum=%u context=%d" , + __entry->timer_latency, + __entry->seqnum, + __entry->context) +); +#endif // CONFIG_TIMERLAT_TRACER + TRACE_EVENT(thread_noise, TP_PROTO(struct task_struct *t, u64 start, u64 duration),
kernel/trace/trace_osnoise.c +16 -39
130 lines not on this page · raw message
Signature · 1 line
2.48.1
po 3. 2. 2025 v 10:04 odesílatel Tomas Glozar <[email protected]> napsal:
Quoted 3 lines
A proof-of-concept bpftrace script using this feature:
https://gitlab.com/-/snippets/4801190
I added another PoC using event histograms to the snippet. That one captures data from all CPUs, and thus can be used for testing on machines with a high number of CPUs where rtla cannot keep up with timerlat samples (in our measurements, >100).
There seems to be an issue with division where most values are rounded up, e.g.:
max: 135 timer_latency: 134657
This also affects the main histogram and seems to be specific to the event histogram PoC. The bpftrace one shows exactly the same results as rtla when run concurrently with it. Another difference compared to the bpftrace PoC is that you have to calculate averages manually from the latency sum and the sample count.
Tomas
Gabriele Monaco
Tested-byQuoted 15 lines · Tomas Glozar
po 3. 2. 2025 v 10:04 odesílatel Tomas Glozar <[email protected]> napsal:
Quoted 3 lines
A proof-of-concept bpftrace script using this feature:
https://gitlab.com/-/snippets/4801190I added another PoC using event histograms to the snippet. That one captures data from all CPUs, and thus can be used for testing on machines with a high number of CPUs where rtla cannot keep up with timerlat samples (in our measurements, >100).
There seems to be an issue with division where most values are rounded up, e.g.:
max: 135 timer_latency: 134657
Quoted 8 lines
This also affects the main histogram and seems to be specific to the event histogram PoC. The bpftrace one shows exactly the same results as rtla when run concurrently with it. Another difference compared to the bpftrace PoC is that you have to calculate averages manually from the latency sum and the sample count.
Tomas
The patch and scripts using the new tracepoints produce reasonable results on a large arm64 machine (128 cores).
Thanks,
Gabriele