Skip to content

Commit 0122938

Browse files
lenticularis39rostedt
authored andcommitted
rtla: Always set all tracer options
rtla currently only sets tracer options that are explicitly set by the user, with the exception of OSNOISE_WORKLOAD. This leads to improper behavior in case rtla is run with those options not set to the default value. rtla does reset them to the original value upon exiting, but that does not protect it from starting with non-default values set either by an improperly exited rtla or by another user of the tracers. For example, after running this command: $ echo 1 > /sys/kernel/tracing/osnoise/stop_tracing_us all runs of rtla will stop at the 1us threshold, even if not requested by the user: $ rtla osnoise hist Index CPU-000 CPU-001 1 8 5 2 5 9 3 1 2 4 6 1 5 2 1 6 0 1 8 1 1 12 0 1 14 1 0 15 1 0 over: 0 0 count: 25 21 min: 1 1 avg: 3.68 3.05 max: 15 12 rtla osnoise hit stop tracing Fix the problem by setting the default value for all tracer options if the user has not provided their own value. For most of the options, it's enough to just drop the if clause checking for the value being set. For cpus, "all" is used as the default value, and for osnoise default period and runtime, default values of the osnoise_data variable in trace_osnoise.c are used. Cc: Luis Goncalves <lgoncalv@redhat.com> Link: https://lore.kernel.org/20250320092500.101385-5-tglozar@redhat.com Fixes: 1eceb2f ("rtla/osnoise: Add osnoise top mode") Fixes: 829a6c0 ("rtla/osnoise: Add the hist mode") Fixes: a828cd1 ("rtla: Add timerlat tool and timelart top mode") Fixes: 1eeb632 ("rtla/timerlat: Add timerlat hist mode") Signed-off-by: Tomas Glozar <tglozar@redhat.com> Reviewed-by: John Kacur <jkacur@redhat.com> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 parent a8122a6 commit 0122938

File tree

2 files changed

+56
-59
lines changed

2 files changed

+56
-59
lines changed

tools/tracing/rtla/src/osnoise.c

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717

1818
#include "osnoise.h"
1919

20+
#define DEFAULT_SAMPLE_PERIOD 1000000 /* 1s */
21+
#define DEFAULT_SAMPLE_RUNTIME 1000000 /* 1s */
22+
2023
/*
2124
* osnoise_get_cpus - return the original "osnoise/cpus" content
2225
*
@@ -1127,46 +1130,43 @@ osnoise_apply_config(struct osnoise_tool *tool, struct osnoise_params *params)
11271130
if (!params->sleep_time)
11281131
params->sleep_time = 1;
11291132

1130-
if (params->cpus) {
1131-
retval = osnoise_set_cpus(tool->context, params->cpus);
1132-
if (retval) {
1133-
err_msg("Failed to apply CPUs config\n");
1134-
goto out_err;
1135-
}
1133+
retval = osnoise_set_cpus(tool->context, params->cpus ? params->cpus : "all");
1134+
if (retval) {
1135+
err_msg("Failed to apply CPUs config\n");
1136+
goto out_err;
11361137
}
11371138

11381139
if (params->runtime || params->period) {
11391140
retval = osnoise_set_runtime_period(tool->context,
11401141
params->runtime,
11411142
params->period);
1142-
if (retval) {
1143-
err_msg("Failed to set runtime and/or period\n");
1144-
goto out_err;
1145-
}
1143+
} else {
1144+
retval = osnoise_set_runtime_period(tool->context,
1145+
DEFAULT_SAMPLE_PERIOD,
1146+
DEFAULT_SAMPLE_RUNTIME);
11461147
}
11471148

1148-
if (params->stop_us) {
1149-
retval = osnoise_set_stop_us(tool->context, params->stop_us);
1150-
if (retval) {
1151-
err_msg("Failed to set stop us\n");
1152-
goto out_err;
1153-
}
1149+
if (retval) {
1150+
err_msg("Failed to set runtime and/or period\n");
1151+
goto out_err;
11541152
}
11551153

1156-
if (params->stop_total_us) {
1157-
retval = osnoise_set_stop_total_us(tool->context, params->stop_total_us);
1158-
if (retval) {
1159-
err_msg("Failed to set stop total us\n");
1160-
goto out_err;
1161-
}
1154+
retval = osnoise_set_stop_us(tool->context, params->stop_us);
1155+
if (retval) {
1156+
err_msg("Failed to set stop us\n");
1157+
goto out_err;
11621158
}
11631159

1164-
if (params->threshold) {
1165-
retval = osnoise_set_tracing_thresh(tool->context, params->threshold);
1166-
if (retval) {
1167-
err_msg("Failed to set tracing_thresh\n");
1168-
goto out_err;
1169-
}
1160+
retval = osnoise_set_stop_total_us(tool->context, params->stop_total_us);
1161+
if (retval) {
1162+
err_msg("Failed to set stop total us\n");
1163+
goto out_err;
1164+
}
1165+
1166+
retval = osnoise_set_tracing_thresh(tool->context, params->threshold);
1167+
if (retval) {
1168+
err_msg("Failed to set tracing_thresh\n");
1169+
goto out_err;
11701170
}
11711171

11721172
if (params->hk_cpus) {

tools/tracing/rtla/src/timerlat.c

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
#include "timerlat.h"
1818

19+
#define DEFAULT_TIMERLAT_PERIOD 1000 /* 1ms */
20+
1921
/*
2022
* timerlat_apply_config - apply common configs to the initialized tool
2123
*/
@@ -27,49 +29,44 @@ timerlat_apply_config(struct osnoise_tool *tool, struct timerlat_params *params)
2729
if (!params->sleep_time)
2830
params->sleep_time = 1;
2931

30-
if (params->cpus) {
31-
retval = osnoise_set_cpus(tool->context, params->cpus);
32-
if (retval) {
33-
err_msg("Failed to apply CPUs config\n");
34-
goto out_err;
35-
}
36-
} else {
32+
retval = osnoise_set_cpus(tool->context, params->cpus ? params->cpus : "all");
33+
if (retval) {
34+
err_msg("Failed to apply CPUs config\n");
35+
goto out_err;
36+
}
37+
38+
if (!params->cpus) {
3739
for (i = 0; i < sysconf(_SC_NPROCESSORS_CONF); i++)
3840
CPU_SET(i, &params->monitored_cpus);
3941
}
4042

41-
if (params->stop_us) {
42-
retval = osnoise_set_stop_us(tool->context, params->stop_us);
43-
if (retval) {
44-
err_msg("Failed to set stop us\n");
45-
goto out_err;
46-
}
43+
retval = osnoise_set_stop_us(tool->context, params->stop_us);
44+
if (retval) {
45+
err_msg("Failed to set stop us\n");
46+
goto out_err;
4747
}
4848

49-
if (params->stop_total_us) {
50-
retval = osnoise_set_stop_total_us(tool->context, params->stop_total_us);
51-
if (retval) {
52-
err_msg("Failed to set stop total us\n");
53-
goto out_err;
54-
}
49+
retval = osnoise_set_stop_total_us(tool->context, params->stop_total_us);
50+
if (retval) {
51+
err_msg("Failed to set stop total us\n");
52+
goto out_err;
5553
}
5654

5755

58-
if (params->timerlat_period_us) {
59-
retval = osnoise_set_timerlat_period_us(tool->context, params->timerlat_period_us);
60-
if (retval) {
61-
err_msg("Failed to set timerlat period\n");
62-
goto out_err;
63-
}
56+
retval = osnoise_set_timerlat_period_us(tool->context,
57+
params->timerlat_period_us ?
58+
params->timerlat_period_us :
59+
DEFAULT_TIMERLAT_PERIOD);
60+
if (retval) {
61+
err_msg("Failed to set timerlat period\n");
62+
goto out_err;
6463
}
6564

6665

67-
if (params->print_stack) {
68-
retval = osnoise_set_print_stack(tool->context, params->print_stack);
69-
if (retval) {
70-
err_msg("Failed to set print stack\n");
71-
goto out_err;
72-
}
66+
retval = osnoise_set_print_stack(tool->context, params->print_stack);
67+
if (retval) {
68+
err_msg("Failed to set print stack\n");
69+
goto out_err;
7370
}
7471

7572
if (params->hk_cpus) {

0 commit comments

Comments
 (0)