Skip to content

Commit ccb6754

Browse files
Daniel Bristot de Oliveirarostedt
authored andcommitted
tracing/osnoise: Remove TIMERLAT ifdefs from inside functions
Remove CONFIG_TIMERLAT_TRACER from inside functions, avoiding compilation problems in the future. Link: https://lkml.kernel.org/r/8245abb5a112d249f5da6c1df499244ad9e647bc.1635702894.git.bristot@kernel.org Cc: Ingo Molnar <[email protected]> Cc: Tom Zanussi <[email protected]> Cc: Masami Hiramatsu <[email protected]> Cc: Juri Lelli <[email protected]> Cc: Clark Williams <[email protected]> Cc: John Kacur <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Sebastian Andrzej Siewior <[email protected]> Cc: Daniel Bristot de Oliveira <[email protected]> Cc: [email protected] Cc: [email protected] Cc: [email protected] Suggested-by: Steven Rostedt <[email protected]> Signed-off-by: Daniel Bristot de Oliveira <[email protected]> Signed-off-by: Steven Rostedt (VMware) <[email protected]>
1 parent dae1813 commit ccb6754

File tree

1 file changed

+106
-44
lines changed

1 file changed

+106
-44
lines changed

kernel/trace/trace_osnoise.c

Lines changed: 106 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,57 @@ static struct osnoise_data {
321321
#endif
322322
};
323323

324+
#ifdef CONFIG_TIMERLAT_TRACER
325+
static inline bool timerlat_enabled(void)
326+
{
327+
return osnoise_data.timerlat_tracer;
328+
}
329+
330+
static inline int timerlat_softirq_exit(struct osnoise_variables *osn_var)
331+
{
332+
struct timerlat_variables *tlat_var = this_cpu_tmr_var();
333+
/*
334+
* If the timerlat is enabled, but the irq handler did
335+
* not run yet enabling timerlat_tracer, do not trace.
336+
*/
337+
if (!tlat_var->tracing_thread) {
338+
osn_var->softirq.arrival_time = 0;
339+
osn_var->softirq.delta_start = 0;
340+
return 0;
341+
}
342+
return 1;
343+
}
344+
345+
static inline int timerlat_thread_exit(struct osnoise_variables *osn_var)
346+
{
347+
struct timerlat_variables *tlat_var = this_cpu_tmr_var();
348+
/*
349+
* If the timerlat is enabled, but the irq handler did
350+
* not run yet enabling timerlat_tracer, do not trace.
351+
*/
352+
if (!tlat_var->tracing_thread) {
353+
osn_var->thread.delta_start = 0;
354+
osn_var->thread.arrival_time = 0;
355+
return 0;
356+
}
357+
return 1;
358+
}
359+
#else /* CONFIG_TIMERLAT_TRACER */
360+
static inline bool timerlat_enabled(void)
361+
{
362+
return false;
363+
}
364+
365+
static inline int timerlat_softirq_exit(struct osnoise_variables *osn_var)
366+
{
367+
return 1;
368+
}
369+
static inline int timerlat_thread_exit(struct osnoise_variables *osn_var)
370+
{
371+
return 1;
372+
}
373+
#endif
374+
324375
#ifdef CONFIG_PREEMPT_RT
325376
/*
326377
* Print the osnoise header info.
@@ -978,21 +1029,9 @@ static void trace_softirq_exit_callback(void *data, unsigned int vec_nr)
9781029
if (!osn_var->sampling)
9791030
return;
9801031

981-
#ifdef CONFIG_TIMERLAT_TRACER
982-
/*
983-
* If the timerlat is enabled, but the irq handler did
984-
* not run yet enabling timerlat_tracer, do not trace.
985-
*/
986-
if (unlikely(osnoise_data.timerlat_tracer)) {
987-
struct timerlat_variables *tlat_var;
988-
tlat_var = this_cpu_tmr_var();
989-
if (!tlat_var->tracing_thread) {
990-
osn_var->softirq.arrival_time = 0;
991-
osn_var->softirq.delta_start = 0;
1032+
if (unlikely(timerlat_enabled()))
1033+
if (!timerlat_softirq_exit(osn_var))
9921034
return;
993-
}
994-
}
995-
#endif
9961035

9971036
duration = get_int_safe_duration(osn_var, &osn_var->softirq.delta_start);
9981037
trace_softirq_noise(vec_nr, osn_var->softirq.arrival_time, duration);
@@ -1086,17 +1125,9 @@ thread_exit(struct osnoise_variables *osn_var, struct task_struct *t)
10861125
if (!osn_var->sampling)
10871126
return;
10881127

1089-
#ifdef CONFIG_TIMERLAT_TRACER
1090-
if (osnoise_data.timerlat_tracer) {
1091-
struct timerlat_variables *tlat_var;
1092-
tlat_var = this_cpu_tmr_var();
1093-
if (!tlat_var->tracing_thread) {
1094-
osn_var->thread.delta_start = 0;
1095-
osn_var->thread.arrival_time = 0;
1128+
if (unlikely(timerlat_enabled()))
1129+
if (!timerlat_thread_exit(osn_var))
10961130
return;
1097-
}
1098-
}
1099-
#endif
11001131

11011132
duration = get_int_safe_duration(osn_var, &osn_var->thread.delta_start);
11021133

@@ -1600,6 +1631,11 @@ static int timerlat_main(void *data)
16001631
hrtimer_cancel(&tlat->timer);
16011632
return 0;
16021633
}
1634+
#else /* CONFIG_TIMERLAT_TRACER */
1635+
static int timerlat_main(void *data)
1636+
{
1637+
return 0;
1638+
}
16031639
#endif /* CONFIG_TIMERLAT_TRACER */
16041640

16051641
/*
@@ -1642,16 +1678,13 @@ static int start_kthread(unsigned int cpu)
16421678
void *main = osnoise_main;
16431679
char comm[24];
16441680

1645-
#ifdef CONFIG_TIMERLAT_TRACER
1646-
if (osnoise_data.timerlat_tracer) {
1681+
if (timerlat_enabled()) {
16471682
snprintf(comm, 24, "timerlat/%d", cpu);
16481683
main = timerlat_main;
16491684
} else {
16501685
snprintf(comm, 24, "osnoise/%d", cpu);
16511686
}
1652-
#else
1653-
snprintf(comm, 24, "osnoise/%d", cpu);
1654-
#endif
1687+
16551688
kthread = kthread_create_on_cpu(main, NULL, cpu, comm);
16561689

16571690
if (IS_ERR(kthread)) {
@@ -1945,6 +1978,35 @@ static const struct file_operations cpus_fops = {
19451978
.llseek = generic_file_llseek,
19461979
};
19471980

1981+
#ifdef CONFIG_TIMERLAT_TRACER
1982+
/*
1983+
* init_timerlat_tracefs - A function to initialize the timerlat interface files
1984+
*/
1985+
static int init_timerlat_tracefs(struct dentry *top_dir)
1986+
{
1987+
struct dentry *tmp;
1988+
1989+
#ifdef CONFIG_STACKTRACE
1990+
tmp = tracefs_create_file("print_stack", TRACE_MODE_WRITE, top_dir,
1991+
&osnoise_print_stack, &trace_min_max_fops);
1992+
if (!tmp)
1993+
return -ENOMEM;
1994+
#endif
1995+
1996+
tmp = tracefs_create_file("timerlat_period_us", TRACE_MODE_WRITE, top_dir,
1997+
&timerlat_period, &trace_min_max_fops);
1998+
if (!tmp)
1999+
return -ENOMEM;
2000+
2001+
return 0;
2002+
}
2003+
#else /* CONFIG_TIMERLAT_TRACER */
2004+
static int init_timerlat_tracefs(struct dentry *top_dir)
2005+
{
2006+
return 0;
2007+
}
2008+
#endif /* CONFIG_TIMERLAT_TRACER */
2009+
19482010
/*
19492011
* init_tracefs - A function to initialize the tracefs interface files
19502012
*
@@ -1989,19 +2051,10 @@ static int init_tracefs(void)
19892051
tmp = trace_create_file("cpus", TRACE_MODE_WRITE, top_dir, NULL, &cpus_fops);
19902052
if (!tmp)
19912053
goto err;
1992-
#ifdef CONFIG_TIMERLAT_TRACER
1993-
#ifdef CONFIG_STACKTRACE
1994-
tmp = tracefs_create_file("print_stack", TRACE_MODE_WRITE, top_dir,
1995-
&osnoise_print_stack, &trace_min_max_fops);
1996-
if (!tmp)
1997-
goto err;
1998-
#endif
19992054

2000-
tmp = tracefs_create_file("timerlat_period_us", TRACE_MODE_WRITE, top_dir,
2001-
&timerlat_period, &trace_min_max_fops);
2002-
if (!tmp)
2055+
ret = init_timerlat_tracefs(top_dir);
2056+
if (ret)
20032057
goto err;
2004-
#endif
20052058

20062059
return 0;
20072060

@@ -2207,6 +2260,16 @@ static struct tracer timerlat_tracer __read_mostly = {
22072260
.print_header = print_timerlat_headers,
22082261
.allow_instances = true,
22092262
};
2263+
2264+
__init static int init_timerlat_tracer(void)
2265+
{
2266+
return register_tracer(&timerlat_tracer);
2267+
}
2268+
#else /* CONFIG_TIMERLAT_TRACER */
2269+
__init static int init_timerlat_tracer(void)
2270+
{
2271+
return 0;
2272+
}
22102273
#endif /* CONFIG_TIMERLAT_TRACER */
22112274

22122275
__init static int init_osnoise_tracer(void)
@@ -2223,13 +2286,12 @@ __init static int init_osnoise_tracer(void)
22232286
return ret;
22242287
}
22252288

2226-
#ifdef CONFIG_TIMERLAT_TRACER
2227-
ret = register_tracer(&timerlat_tracer);
2289+
ret = init_timerlat_tracer();
22282290
if (ret) {
2229-
pr_err(BANNER "Error registering timerlat\n");
2291+
pr_err(BANNER "Error registering timerlat!\n");
22302292
return ret;
22312293
}
2232-
#endif
2294+
22332295
osnoise_init_hotplug_support();
22342296

22352297
INIT_LIST_HEAD_RCU(&osnoise_instances);

0 commit comments

Comments
 (0)