Skip to content

Commit e9a4062

Browse files
author
Daniel Bristot de Oliveira
committed
rtla: Add --trace-buffer-size option
Add the option allow the users to set a different buffer size for the trace. For example, in large systems, the user might be interested on reducing the trace buffer to avoid large tracing files. The buffer size is specified in kB, and it is only affecting the tracing instance. The function trace_set_buffer_size() appears on libtracefs v1.6, so increase the minimum required version on Makefile.config. Link: https://lkml.kernel.org/r/e7c9ca5b3865f28e131a49ec3b984fadf2d056c6.1715860611.git.bristot@kernel.org Cc: Jonathan Corbet <[email protected]> Cc: Juri Lelli <[email protected]> Cc: John Kacur <[email protected]> Signed-off-by: Daniel Bristot de Oliveira <[email protected]>
1 parent fb9e90a commit e9a4062

File tree

8 files changed

+71
-5
lines changed

8 files changed

+71
-5
lines changed

Documentation/tools/rtla/common_options.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@
5454

5555
After starting the workload, let it run for *s* seconds before starting collecting the data, allowing the system to warm-up. Statistical data generated during warm-up is discarded.
5656

57+
**--trace-buffer-size** *kB*
58+
Set the per-cpu trace buffer size in kB for the tracing output.
59+
5760
**-h**, **--help**
5861

5962
Print help menu.

tools/tracing/rtla/Makefile.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
STOP_ERROR :=
44

55
LIBTRACEEVENT_MIN_VERSION = 1.5
6-
LIBTRACEFS_MIN_VERSION = 1.3
6+
LIBTRACEFS_MIN_VERSION = 1.6
77

88
define lib_setup
99
$(eval LIB_INCLUDES += $(shell sh -c "$(PKG_CONFIG) --cflags lib$(1)"))

tools/tracing/rtla/src/osnoise_hist.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ struct osnoise_hist_params {
4343
int bucket_size;
4444
int entries;
4545
int warmup;
46+
int buffer_size;
4647
};
4748

4849
struct osnoise_hist_cpu {
@@ -469,6 +470,7 @@ static void osnoise_hist_usage(char *usage)
469470
" d:runtime[us|ms|s]:period[us|ms|s] - use SCHED_DEADLINE with runtime and period",
470471
" in nanoseconds",
471472
" --warm-up: let the workload run for s seconds before collecting data",
473+
" --trace-buffer-size kB: set the per-cpu trace buffer size in kB",
472474
NULL,
473475
};
474476

@@ -533,13 +535,14 @@ static struct osnoise_hist_params
533535
{"trigger", required_argument, 0, '4'},
534536
{"filter", required_argument, 0, '5'},
535537
{"warm-up", required_argument, 0, '6'},
538+
{"trace-buffer-size", required_argument, 0, '7'},
536539
{0, 0, 0, 0}
537540
};
538541

539542
/* getopt_long stores the option index here. */
540543
int option_index = 0;
541544

542-
c = getopt_long(argc, argv, "a:c:C::b:d:e:E:DhH:p:P:r:s:S:t::T:01234:5:6:",
545+
c = getopt_long(argc, argv, "a:c:C::b:d:e:E:DhH:p:P:r:s:S:t::T:01234:5:6:7:",
543546
long_options, &option_index);
544547

545548
/* detect the end of the options. */
@@ -685,6 +688,9 @@ static struct osnoise_hist_params
685688
case '6':
686689
params->warmup = get_llong_from_str(optarg);
687690
break;
691+
case '7':
692+
params->buffer_size = get_llong_from_str(optarg);
693+
break;
688694
default:
689695
osnoise_hist_usage("Invalid option");
690696
}
@@ -891,6 +897,11 @@ int osnoise_hist_main(int argc, char *argv[])
891897
goto out_hist;
892898
}
893899

900+
if (params->buffer_size > 0) {
901+
retval = trace_set_buffer_size(&record->trace, params->buffer_size);
902+
if (retval)
903+
goto out_hist;
904+
}
894905
}
895906

896907
/*

tools/tracing/rtla/src/osnoise_top.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ struct osnoise_top_params {
4141
int cgroup;
4242
int hk_cpus;
4343
int warmup;
44+
int buffer_size;
4445
cpu_set_t hk_cpu_set;
4546
struct sched_attr sched_param;
4647
struct trace_events *events;
@@ -309,6 +310,7 @@ static void osnoise_top_usage(struct osnoise_top_params *params, char *usage)
309310
" d:runtime[us|ms|s]:period[us|ms|s] - use SCHED_DEADLINE with runtime and period",
310311
" in nanoseconds",
311312
" --warm-up s: let the workload run for s seconds before collecting data",
313+
" --trace-buffer-size kB: set the per-cpu trace buffer size in kB",
312314
NULL,
313315
};
314316

@@ -384,13 +386,14 @@ struct osnoise_top_params *osnoise_top_parse_args(int argc, char **argv)
384386
{"trigger", required_argument, 0, '0'},
385387
{"filter", required_argument, 0, '1'},
386388
{"warm-up", required_argument, 0, '2'},
389+
{"trace-buffer-size", required_argument, 0, '3'},
387390
{0, 0, 0, 0}
388391
};
389392

390393
/* getopt_long stores the option index here. */
391394
int option_index = 0;
392395

393-
c = getopt_long(argc, argv, "a:c:C::d:De:hH:p:P:qr:s:S:t::T:0:1:2:",
396+
c = getopt_long(argc, argv, "a:c:C::d:De:hH:p:P:qr:s:S:t::T:0:1:2:3:",
394397
long_options, &option_index);
395398

396399
/* Detect the end of the options. */
@@ -517,6 +520,9 @@ struct osnoise_top_params *osnoise_top_parse_args(int argc, char **argv)
517520
case '2':
518521
params->warmup = get_llong_from_str(optarg);
519522
break;
523+
case '3':
524+
params->buffer_size = get_llong_from_str(optarg);
525+
break;
520526
default:
521527
osnoise_top_usage(params, "Invalid option");
522528
}
@@ -725,6 +731,12 @@ int osnoise_top_main(int argc, char **argv)
725731
if (retval)
726732
goto out_top;
727733
}
734+
735+
if (params->buffer_size > 0) {
736+
retval = trace_set_buffer_size(&record->trace, params->buffer_size);
737+
if (retval)
738+
goto out_top;
739+
}
728740
}
729741

730742
/*

tools/tracing/rtla/src/timerlat_hist.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ struct timerlat_hist_params {
5454
int bucket_size;
5555
int entries;
5656
int warmup;
57+
int buffer_size;
5758
};
5859

5960
struct timerlat_hist_cpu {
@@ -669,6 +670,7 @@ static void timerlat_hist_usage(char *usage)
669670
" -k/--kernel-threads: use timerlat kernel-space threads instead of rtla user-space threads",
670671
" -U/--user-load: enable timerlat for user-defined user-space workload",
671672
" --warm-up s: let the workload run for s seconds before collecting data",
673+
" --trace-buffer-size kB: set the per-cpu trace buffer size in kB",
672674
NULL,
673675
};
674676

@@ -745,13 +747,14 @@ static struct timerlat_hist_params
745747
{"no-aa", no_argument, 0, '9'},
746748
{"dump-task", no_argument, 0, '\1'},
747749
{"warm-up", required_argument, 0, '\2'},
750+
{"trace-buffer-size", required_argument, 0, '\3'},
748751
{0, 0, 0, 0}
749752
};
750753

751754
/* getopt_long stores the option index here. */
752755
int option_index = 0;
753756

754-
c = getopt_long(argc, argv, "a:c:C::b:d:e:E:DhH:i:knp:P:s:t::T:uU0123456:7:8:9\1\2:",
757+
c = getopt_long(argc, argv, "a:c:C::b:d:e:E:DhH:i:knp:P:s:t::T:uU0123456:7:8:9\1\2:\3",
755758
long_options, &option_index);
756759

757760
/* detect the end of the options. */
@@ -926,6 +929,9 @@ static struct timerlat_hist_params
926929
case '\2':
927930
params->warmup = get_llong_from_str(optarg);
928931
break;
932+
case '\3':
933+
params->buffer_size = get_llong_from_str(optarg);
934+
break;
929935
default:
930936
timerlat_hist_usage("Invalid option");
931937
}
@@ -1179,6 +1185,12 @@ int timerlat_hist_main(int argc, char *argv[])
11791185
if (retval)
11801186
goto out_hist;
11811187
}
1188+
1189+
if (params->buffer_size > 0) {
1190+
retval = trace_set_buffer_size(&record->trace, params->buffer_size);
1191+
if (retval)
1192+
goto out_hist;
1193+
}
11821194
}
11831195

11841196
if (!params->no_aa) {

tools/tracing/rtla/src/timerlat_top.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ struct timerlat_top_params {
4747
int kernel_workload;
4848
int pretty_output;
4949
int warmup;
50+
int buffer_size;
5051
cpu_set_t hk_cpu_set;
5152
struct sched_attr sched_param;
5253
struct trace_events *events;
@@ -479,6 +480,7 @@ static void timerlat_top_usage(char *usage)
479480
" -k/--kernel-threads: use timerlat kernel-space threads instead of rtla user-space threads",
480481
" -U/--user-load: enable timerlat for user-defined user-space workload",
481482
" --warm-up s: let the workload run for s seconds before collecting data",
483+
" --trace-buffer-size kB: set the per-cpu trace buffer size in kB",
482484
NULL,
483485
};
484486

@@ -547,13 +549,14 @@ static struct timerlat_top_params
547549
{"dump-tasks", no_argument, 0, '4'},
548550
{"aa-only", required_argument, 0, '5'},
549551
{"warm-up", required_argument, 0, '6'},
552+
{"trace-buffer-size", required_argument, 0, '7'},
550553
{0, 0, 0, 0}
551554
};
552555

553556
/* getopt_long stores the option index here. */
554557
int option_index = 0;
555558

556-
c = getopt_long(argc, argv, "a:c:C::d:De:hH:i:knp:P:qs:t::T:uU0:1:2:345:6:",
559+
c = getopt_long(argc, argv, "a:c:C::d:De:hH:i:knp:P:qs:t::T:uU0:1:2:345:6:7:",
557560
long_options, &option_index);
558561

559562
/* detect the end of the options. */
@@ -716,6 +719,9 @@ static struct timerlat_top_params
716719
case '6':
717720
params->warmup = get_llong_from_str(optarg);
718721
break;
722+
case '7':
723+
params->buffer_size = get_llong_from_str(optarg);
724+
break;
719725
default:
720726
timerlat_top_usage("Invalid option");
721727
}
@@ -973,6 +979,12 @@ int timerlat_top_main(int argc, char *argv[])
973979
if (retval)
974980
goto out_top;
975981
}
982+
983+
if (params->buffer_size > 0) {
984+
retval = trace_set_buffer_size(&record->trace, params->buffer_size);
985+
if (retval)
986+
goto out_top;
987+
}
976988
}
977989

978990
if (!params->no_aa) {

tools/tracing/rtla/src/trace.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,3 +540,18 @@ int trace_is_off(struct trace_instance *tool, struct trace_instance *trace)
540540

541541
return 0;
542542
}
543+
544+
/*
545+
* trace_set_buffer_size - set the per-cpu tracing buffer size.
546+
*/
547+
int trace_set_buffer_size(struct trace_instance *trace, int size)
548+
{
549+
int retval;
550+
551+
debug_msg("Setting trace buffer size to %d Kb\n", size);
552+
retval = tracefs_instance_set_buffer_size(trace->inst, size, -1);
553+
if (retval)
554+
err_msg("Error setting trace buffer size\n");
555+
556+
return retval;
557+
}

tools/tracing/rtla/src/trace.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,4 @@ int trace_events_enable(struct trace_instance *instance,
4848
int trace_event_add_filter(struct trace_events *event, char *filter);
4949
int trace_event_add_trigger(struct trace_events *event, char *trigger);
5050
int trace_is_off(struct trace_instance *tool, struct trace_instance *trace);
51+
int trace_set_buffer_size(struct trace_instance *trace, int size);

0 commit comments

Comments
 (0)