Skip to content

Commit b91cfd9

Browse files
makelinuxrostedt
authored andcommitted
tools/rtla: Add osnoise_trace_is_off()
All of the users of trace_is_off() passes in &record->trace as the second parameter, where record is a pointer to a struct osnoise_tool. This record could be NULL and there is a hidden dependency that the trace field is the first field to allow &record->trace to work with a NULL record pointer. In order to make this code a bit more robust, as record shouldn't be dereferenced if it is NULL, even if the code does work, create a new function called osnoise_trace_is_off() that takes the pointer to a struct osnoise_tool as its second parameter. This way it can properly test if it is NULL before it dereferences it. The old function trace_is_off() is removed and the function osnoise_trace_is_off() is added into osnoise.c which is what the struct osnoise_tool is associated with. Cc: John Kacur <[email protected]> Cc: "Luis Claudio R. Goncalves" <[email protected]> Cc: Eder Zulian <[email protected]> Cc: Dan Carpenter <[email protected]> Cc: Tomas Glozar <[email protected]> Cc: Gabriele Monaco <[email protected]> Link: https://lore.kernel.org/[email protected] Signed-off-by: Costa Shulyupin <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 217f0b1 commit b91cfd9

File tree

8 files changed

+26
-29
lines changed

8 files changed

+26
-29
lines changed

tools/tracing/rtla/src/osnoise.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,6 +1079,22 @@ struct osnoise_tool *osnoise_init_trace_tool(char *tracer)
10791079
return NULL;
10801080
}
10811081

1082+
bool osnoise_trace_is_off(struct osnoise_tool *tool, struct osnoise_tool *record)
1083+
{
1084+
/*
1085+
* The tool instance is always present, it is the one used to collect
1086+
* data.
1087+
*/
1088+
if (!tracefs_trace_is_on(tool->trace.inst))
1089+
return true;
1090+
1091+
/*
1092+
* The trace record instance is only enabled when -t is set. IOW, when the system
1093+
* is tracing.
1094+
*/
1095+
return record && !tracefs_trace_is_on(record->trace.inst);
1096+
}
1097+
10821098
static void osnoise_usage(int err)
10831099
{
10841100
int i;

tools/tracing/rtla/src/osnoise.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ struct osnoise_tool {
104104
void osnoise_destroy_tool(struct osnoise_tool *top);
105105
struct osnoise_tool *osnoise_init_tool(char *tool_name);
106106
struct osnoise_tool *osnoise_init_trace_tool(char *tracer);
107+
bool osnoise_trace_is_off(struct osnoise_tool *tool, struct osnoise_tool *record);
107108

108109
int osnoise_hist_main(int argc, char *argv[]);
109110
int osnoise_top_main(int argc, char **argv);

tools/tracing/rtla/src/osnoise_hist.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -970,7 +970,7 @@ int osnoise_hist_main(int argc, char *argv[])
970970
goto out_hist;
971971
}
972972

973-
if (trace_is_off(&tool->trace, &record->trace))
973+
if (osnoise_trace_is_off(tool, record))
974974
break;
975975
}
976976

@@ -980,7 +980,7 @@ int osnoise_hist_main(int argc, char *argv[])
980980

981981
return_value = 0;
982982

983-
if (trace_is_off(&tool->trace, &record->trace)) {
983+
if (osnoise_trace_is_off(tool, record)) {
984984
printf("rtla osnoise hit stop tracing\n");
985985
if (params->trace_output) {
986986
printf(" Saving trace to %s\n", params->trace_output);

tools/tracing/rtla/src/osnoise_top.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ int osnoise_top_main(int argc, char **argv)
801801
if (!params->quiet)
802802
osnoise_print_stats(params, tool);
803803

804-
if (trace_is_off(&tool->trace, &record->trace))
804+
if (osnoise_trace_is_off(tool, record))
805805
break;
806806

807807
}
@@ -810,7 +810,7 @@ int osnoise_top_main(int argc, char **argv)
810810

811811
return_value = 0;
812812

813-
if (trace_is_off(&tool->trace, &record->trace)) {
813+
if (osnoise_trace_is_off(tool, record)) {
814814
printf("osnoise hit stop tracing\n");
815815
if (params->trace_output) {
816816
printf(" Saving trace to %s\n", params->trace_output);

tools/tracing/rtla/src/timerlat_hist.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,7 +1347,7 @@ int timerlat_hist_main(int argc, char *argv[])
13471347
goto out_hist;
13481348
}
13491349

1350-
if (trace_is_off(&tool->trace, &record->trace))
1350+
if (osnoise_trace_is_off(tool, record))
13511351
break;
13521352

13531353
/* is there still any user-threads ? */
@@ -1368,7 +1368,7 @@ int timerlat_hist_main(int argc, char *argv[])
13681368

13691369
return_value = 0;
13701370

1371-
if (trace_is_off(&tool->trace, &record->trace) && !stop_tracing) {
1371+
if (osnoise_trace_is_off(tool, record) && !stop_tracing) {
13721372
printf("rtla timerlat hit stop tracing\n");
13731373

13741374
if (!params->no_aa)

tools/tracing/rtla/src/timerlat_top.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,7 +1114,7 @@ int timerlat_top_main(int argc, char *argv[])
11141114
while (!stop_tracing) {
11151115
sleep(params->sleep_time);
11161116

1117-
if (params->aa_only && !trace_is_off(&top->trace, &record->trace))
1117+
if (params->aa_only && !osnoise_trace_is_off(top, record))
11181118
continue;
11191119

11201120
retval = tracefs_iterate_raw_events(trace->tep,
@@ -1131,7 +1131,7 @@ int timerlat_top_main(int argc, char *argv[])
11311131
if (!params->quiet)
11321132
timerlat_print_stats(params, top);
11331133

1134-
if (trace_is_off(&top->trace, &record->trace))
1134+
if (osnoise_trace_is_off(top, record))
11351135
break;
11361136

11371137
/* is there still any user-threads ? */
@@ -1152,7 +1152,7 @@ int timerlat_top_main(int argc, char *argv[])
11521152

11531153
return_value = 0;
11541154

1155-
if (trace_is_off(&top->trace, &record->trace) && !stop_tracing) {
1155+
if (osnoise_trace_is_off(top, record) && !stop_tracing) {
11561156
printf("rtla timerlat hit stop tracing\n");
11571157

11581158
if (!params->no_aa)

tools/tracing/rtla/src/trace.c

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -530,25 +530,6 @@ void trace_events_destroy(struct trace_instance *instance,
530530
trace_events_free(events);
531531
}
532532

533-
int trace_is_off(struct trace_instance *tool, struct trace_instance *trace)
534-
{
535-
/*
536-
* The tool instance is always present, it is the one used to collect
537-
* data.
538-
*/
539-
if (!tracefs_trace_is_on(tool->inst))
540-
return 1;
541-
542-
/*
543-
* The trace instance is only enabled when -t is set. IOW, when the system
544-
* is tracing.
545-
*/
546-
if (trace && !tracefs_trace_is_on(trace->inst))
547-
return 1;
548-
549-
return 0;
550-
}
551-
552533
/*
553534
* trace_set_buffer_size - set the per-cpu tracing buffer size.
554535
*/

tools/tracing/rtla/src/trace.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,4 @@ int trace_events_enable(struct trace_instance *instance,
4848

4949
int trace_event_add_filter(struct trace_events *event, char *filter);
5050
int trace_event_add_trigger(struct trace_events *event, char *trigger);
51-
int trace_is_off(struct trace_instance *tool, struct trace_instance *trace);
5251
int trace_set_buffer_size(struct trace_instance *trace, int size);

0 commit comments

Comments
 (0)