Skip to content

Commit e25e43a

Browse files
mhiramatrostedt
authored andcommitted
tracing: Fix complicated dependency of CONFIG_TRACER_MAX_TRACE
Both CONFIG_OSNOISE_TRACER and CONFIG_HWLAT_TRACER partially enables the CONFIG_TRACER_MAX_TRACE code, but that is complicated and has introduced a bug; It declares tracing_max_lat_fops data structure outside of #ifdefs, but since it is defined only when CONFIG_TRACER_MAX_TRACE=y or CONFIG_HWLAT_TRACER=y, if only CONFIG_OSNOISE_TRACER=y, that declaration comes to a definition(!). To fix this issue, and do not repeat the similar problem, makes CONFIG_OSNOISE_TRACER and CONFIG_HWLAT_TRACER enables the CONFIG_TRACER_MAX_TRACE always. It has there benefits; - Fix the tracing_max_lat_fops bug - Simplify the #ifdefs - CONFIG_TRACER_MAX_TRACE code is fully enabled, or not. Link: https://lore.kernel.org/linux-trace-kernel/167033628155.4111793.12185405690820208159.stgit@devnote3 Fixes: 424b650 ("tracing: Fix missing osnoise tracer on max_latency") Cc: Daniel Bristot de Oliveira <[email protected]> Cc: [email protected] Reported-by: David Howells <[email protected]> Reported-by: kernel test robot <[email protected]> Signed-off-by: Masami Hiramatsu (Google) <[email protected]> Link: https://lore.kernel.org/all/166992525941.1716618.13740663757583361463.stgit@warthog.procyon.org.uk/ (original thread and v1) Link: https://lore.kernel.org/all/[email protected]/T/#u (v1 error report) Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 575b76c commit e25e43a

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

kernel/trace/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,7 @@ config SCHED_TRACER
375375
config HWLAT_TRACER
376376
bool "Tracer to detect hardware latencies (like SMIs)"
377377
select GENERIC_TRACER
378+
select TRACER_MAX_TRACE
378379
help
379380
This tracer, when enabled will create one or more kernel threads,
380381
depending on what the cpumask file is set to, which each thread
@@ -410,6 +411,7 @@ config HWLAT_TRACER
410411
config OSNOISE_TRACER
411412
bool "OS Noise tracer"
412413
select GENERIC_TRACER
414+
select TRACER_MAX_TRACE
413415
help
414416
In the context of high-performance computing (HPC), the Operating
415417
System Noise (osnoise) refers to the interference experienced by an

kernel/trace/trace.c

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,6 +1421,7 @@ int tracing_snapshot_cond_disable(struct trace_array *tr)
14211421
return false;
14221422
}
14231423
EXPORT_SYMBOL_GPL(tracing_snapshot_cond_disable);
1424+
#define free_snapshot(tr) do { } while (0)
14241425
#endif /* CONFIG_TRACER_SNAPSHOT */
14251426

14261427
void tracer_tracing_off(struct trace_array *tr)
@@ -1692,6 +1693,8 @@ static ssize_t trace_seq_to_buffer(struct trace_seq *s, void *buf, size_t cnt)
16921693
}
16931694

16941695
unsigned long __read_mostly tracing_thresh;
1696+
1697+
#ifdef CONFIG_TRACER_MAX_TRACE
16951698
static const struct file_operations tracing_max_lat_fops;
16961699

16971700
#ifdef LATENCY_FS_NOTIFY
@@ -1748,18 +1751,14 @@ void latency_fsnotify(struct trace_array *tr)
17481751
irq_work_queue(&tr->fsnotify_irqwork);
17491752
}
17501753

1751-
#elif defined(CONFIG_TRACER_MAX_TRACE) || defined(CONFIG_HWLAT_TRACER) \
1752-
|| defined(CONFIG_OSNOISE_TRACER)
1754+
#else /* !LATENCY_FS_NOTIFY */
17531755

17541756
#define trace_create_maxlat_file(tr, d_tracer) \
17551757
trace_create_file("tracing_max_latency", TRACE_MODE_WRITE, \
17561758
d_tracer, &tr->max_latency, &tracing_max_lat_fops)
17571759

1758-
#else
1759-
#define trace_create_maxlat_file(tr, d_tracer) do { } while (0)
17601760
#endif
17611761

1762-
#ifdef CONFIG_TRACER_MAX_TRACE
17631762
/*
17641763
* Copy the new maximum trace into the separate maximum-trace
17651764
* structure. (this way the maximum trace is permanently saved,
@@ -1834,14 +1833,15 @@ update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu,
18341833
ring_buffer_record_off(tr->max_buffer.buffer);
18351834

18361835
#ifdef CONFIG_TRACER_SNAPSHOT
1837-
if (tr->cond_snapshot && !tr->cond_snapshot->update(tr, cond_data))
1838-
goto out_unlock;
1836+
if (tr->cond_snapshot && !tr->cond_snapshot->update(tr, cond_data)) {
1837+
arch_spin_unlock(&tr->max_lock);
1838+
return;
1839+
}
18391840
#endif
18401841
swap(tr->array_buffer.buffer, tr->max_buffer.buffer);
18411842

18421843
__update_max_tr(tr, tsk, cpu);
18431844

1844-
out_unlock:
18451845
arch_spin_unlock(&tr->max_lock);
18461846
}
18471847

@@ -1888,6 +1888,7 @@ update_max_tr_single(struct trace_array *tr, struct task_struct *tsk, int cpu)
18881888
__update_max_tr(tr, tsk, cpu);
18891889
arch_spin_unlock(&tr->max_lock);
18901890
}
1891+
18911892
#endif /* CONFIG_TRACER_MAX_TRACE */
18921893

18931894
static int wait_on_pipe(struct trace_iterator *iter, int full)
@@ -6577,7 +6578,7 @@ tracing_thresh_write(struct file *filp, const char __user *ubuf,
65776578
return ret;
65786579
}
65796580

6580-
#if defined(CONFIG_TRACER_MAX_TRACE) || defined(CONFIG_HWLAT_TRACER)
6581+
#ifdef CONFIG_TRACER_MAX_TRACE
65816582

65826583
static ssize_t
65836584
tracing_max_lat_read(struct file *filp, char __user *ubuf,
@@ -7592,7 +7593,7 @@ static const struct file_operations tracing_thresh_fops = {
75927593
.llseek = generic_file_llseek,
75937594
};
75947595

7595-
#if defined(CONFIG_TRACER_MAX_TRACE) || defined(CONFIG_HWLAT_TRACER)
7596+
#ifdef CONFIG_TRACER_MAX_TRACE
75967597
static const struct file_operations tracing_max_lat_fops = {
75977598
.open = tracing_open_generic,
75987599
.read = tracing_max_lat_read,
@@ -9606,7 +9607,9 @@ init_tracer_tracefs(struct trace_array *tr, struct dentry *d_tracer)
96069607

96079608
create_trace_options_dir(tr);
96089609

9610+
#ifdef CONFIG_TRACER_MAX_TRACE
96099611
trace_create_maxlat_file(tr, d_tracer);
9612+
#endif
96109613

96119614
if (ftrace_create_function_files(tr, d_tracer))
96129615
MEM_FAIL(1, "Could not allocate function filter files");

kernel/trace/trace.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,7 @@ struct trace_array {
308308
struct array_buffer max_buffer;
309309
bool allocated_snapshot;
310310
#endif
311-
#if defined(CONFIG_TRACER_MAX_TRACE) || defined(CONFIG_HWLAT_TRACER) \
312-
|| defined(CONFIG_OSNOISE_TRACER)
311+
#ifdef CONFIG_TRACER_MAX_TRACE
313312
unsigned long max_latency;
314313
#ifdef CONFIG_FSNOTIFY
315314
struct dentry *d_max_latency;
@@ -688,12 +687,11 @@ void update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu,
688687
void *cond_data);
689688
void update_max_tr_single(struct trace_array *tr,
690689
struct task_struct *tsk, int cpu);
691-
#endif /* CONFIG_TRACER_MAX_TRACE */
692690

693-
#if (defined(CONFIG_TRACER_MAX_TRACE) || defined(CONFIG_HWLAT_TRACER) \
694-
|| defined(CONFIG_OSNOISE_TRACER)) && defined(CONFIG_FSNOTIFY)
691+
#ifdef CONFIG_FSNOTIFY
695692
#define LATENCY_FS_NOTIFY
696693
#endif
694+
#endif /* CONFIG_TRACER_MAX_TRACE */
697695

698696
#ifdef LATENCY_FS_NOTIFY
699697
void latency_fsnotify(struct trace_array *tr);

0 commit comments

Comments
 (0)