Skip to content

Commit 8f17fcc

Browse files
committed
rtla: Add --trace-buffer-size option
JIRA: https://issues.redhat.com/browse/RHEL-58061 Conflicts: RHEL-9.x does not have commit fb9e90a ("rtla/timerlat: Make user-space threads the default) and that leads to a small merge conflict. commit e9a4062 Author: Daniel Bristot de Oliveira <bristot@kernel.org> Date: Thu May 16 16:15:22 2024 +0200 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 <corbet@lwn.net> Cc: Juri Lelli <juri.lelli@redhat.com> Cc: John Kacur <jkacur@redhat.com> Signed-off-by: Daniel Bristot de Oliveira <bristot@kernel.org> Signed-off-by: Luis Claudio R. Goncalves <lgoncalv@redhat.com>
1 parent 64f189a commit 8f17fcc

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ DOCSRC = $(SRCTREE)/../../../Documentation/tools/rtla/
6464
endif
6565

6666
LIBTRACEEVENT_MIN_VERSION = 1.5
67-
LIBTRACEFS_MIN_VERSION = 1.3
67+
LIBTRACEFS_MIN_VERSION = 1.6
6868

6969
.PHONY: all warnings show_warnings
7070
all: warnings rtla

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 {
@@ -484,6 +485,7 @@ static void osnoise_hist_usage(char *usage)
484485
" d:runtime[us|ms|s]:period[us|ms|s] - use SCHED_DEADLINE with runtime and period",
485486
" in nanoseconds",
486487
" --warm-up: let the workload run for s seconds before collecting data",
488+
" --trace-buffer-size kB: set the per-cpu trace buffer size in kB",
487489
NULL,
488490
};
489491

@@ -548,13 +550,14 @@ static struct osnoise_hist_params
548550
{"trigger", required_argument, 0, '4'},
549551
{"filter", required_argument, 0, '5'},
550552
{"warm-up", required_argument, 0, '6'},
553+
{"trace-buffer-size", required_argument, 0, '7'},
551554
{0, 0, 0, 0}
552555
};
553556

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

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

560563
/* detect the end of the options. */
@@ -704,6 +707,9 @@ static struct osnoise_hist_params
704707
case '6':
705708
params->warmup = get_llong_from_str(optarg);
706709
break;
710+
case '7':
711+
params->buffer_size = get_llong_from_str(optarg);
712+
break;
707713
default:
708714
osnoise_hist_usage("Invalid option");
709715
}
@@ -910,6 +916,11 @@ int osnoise_hist_main(int argc, char *argv[])
910916
goto out_hist;
911917
}
912918

919+
if (params->buffer_size > 0) {
920+
retval = trace_set_buffer_size(&record->trace, params->buffer_size);
921+
if (retval)
922+
goto out_hist;
923+
}
913924
}
914925

915926
/*

tools/tracing/rtla/src/osnoise_top.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ struct osnoise_top_params {
4242
int hk_cpus;
4343
int warmup;
4444
int pretty_output;
45+
int buffer_size;
4546
cpu_set_t hk_cpu_set;
4647
struct sched_attr sched_param;
4748
struct trace_events *events;
@@ -317,6 +318,7 @@ static void osnoise_top_usage(struct osnoise_top_params *params, char *usage)
317318
" d:runtime[us|ms|s]:period[us|ms|s] - use SCHED_DEADLINE with runtime and period",
318319
" in nanoseconds",
319320
" --warm-up s: let the workload run for s seconds before collecting data",
321+
" --trace-buffer-size kB: set the per-cpu trace buffer size in kB",
320322
NULL,
321323
};
322324

@@ -392,13 +394,14 @@ struct osnoise_top_params *osnoise_top_parse_args(int argc, char **argv)
392394
{"trigger", required_argument, 0, '0'},
393395
{"filter", required_argument, 0, '1'},
394396
{"warm-up", required_argument, 0, '2'},
397+
{"trace-buffer-size", required_argument, 0, '3'},
395398
{0, 0, 0, 0}
396399
};
397400

398401
/* getopt_long stores the option index here. */
399402
int option_index = 0;
400403

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

404407
/* Detect the end of the options. */
@@ -529,6 +532,9 @@ struct osnoise_top_params *osnoise_top_parse_args(int argc, char **argv)
529532
case '2':
530533
params->warmup = get_llong_from_str(optarg);
531534
break;
535+
case '3':
536+
params->buffer_size = get_llong_from_str(optarg);
537+
break;
532538
default:
533539
osnoise_top_usage(params, "Invalid option");
534540
}
@@ -740,6 +746,12 @@ int osnoise_top_main(int argc, char **argv)
740746
if (retval)
741747
goto out_top;
742748
}
749+
750+
if (params->buffer_size > 0) {
751+
retval = trace_set_buffer_size(&record->trace, params->buffer_size);
752+
if (retval)
753+
goto out_top;
754+
}
743755
}
744756

745757
/*

tools/tracing/rtla/src/timerlat_hist.c

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

5859
struct timerlat_hist_cpu {
@@ -691,6 +692,7 @@ static void timerlat_hist_usage(char *usage)
691692
" -u/--user-threads: use rtla user-space threads instead of in-kernel timerlat threads",
692693
" -U/--user-load: enable timerlat for user-defined user-space workload",
693694
" --warm-up s: let the workload run for s seconds before collecting data",
695+
" --trace-buffer-size kB: set the per-cpu trace buffer size in kB",
694696
NULL,
695697
};
696698

@@ -766,13 +768,14 @@ static struct timerlat_hist_params
766768
{"no-aa", no_argument, 0, '9'},
767769
{"dump-task", no_argument, 0, '\1'},
768770
{"warm-up", required_argument, 0, '\2'},
771+
{"trace-buffer-size", required_argument, 0, '\3'},
769772
{0, 0, 0, 0}
770773
};
771774

772775
/* getopt_long stores the option index here. */
773776
int option_index = 0;
774777

775-
c = getopt_long(argc, argv, "a:c:C::b:d:e:E:DhH:i:np:P:s:t::T:uU0123456:7:8:9\1\2:",
778+
c = getopt_long(argc, argv, "a:c:C::b:d:e:E:DhH:i:np:P:s:t::T:uU0123456:7:8:9\1\2:\3",
776779
long_options, &option_index);
777780

778781
/* detect the end of the options. */
@@ -948,6 +951,9 @@ static struct timerlat_hist_params
948951
case '\2':
949952
params->warmup = get_llong_from_str(optarg);
950953
break;
954+
case '\3':
955+
params->buffer_size = get_llong_from_str(optarg);
956+
break;
951957
default:
952958
timerlat_hist_usage("Invalid option");
953959
}
@@ -1182,6 +1188,12 @@ int timerlat_hist_main(int argc, char *argv[])
11821188
if (retval)
11831189
goto out_hist;
11841190
}
1191+
1192+
if (params->buffer_size > 0) {
1193+
retval = trace_set_buffer_size(&record->trace, params->buffer_size);
1194+
if (retval)
1195+
goto out_hist;
1196+
}
11851197
}
11861198

11871199
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
@@ -46,6 +46,7 @@ struct timerlat_top_params {
4646
int user_workload;
4747
int pretty_output;
4848
int warmup;
49+
int buffer_size;
4950
cpu_set_t hk_cpu_set;
5051
struct sched_attr sched_param;
5152
struct trace_events *events;
@@ -477,6 +478,7 @@ static void timerlat_top_usage(char *usage)
477478
" -u/--user-threads: use rtla user-space threads instead of in-kernel timerlat threads",
478479
" -U/--user-load: enable timerlat for user-defined user-space workload",
479480
" --warm-up s: let the workload run for s seconds before collecting data",
481+
" --trace-buffer-size kB: set the per-cpu trace buffer size in kB",
480482
NULL,
481483
};
482484

@@ -544,13 +546,14 @@ static struct timerlat_top_params
544546
{"dump-tasks", no_argument, 0, '4'},
545547
{"aa-only", required_argument, 0, '5'},
546548
{"warm-up", required_argument, 0, '6'},
549+
{"trace-buffer-size", required_argument, 0, '7'},
547550
{0, 0, 0, 0}
548551
};
549552

550553
/* getopt_long stores the option index here. */
551554
int option_index = 0;
552555

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

556559
/* detect the end of the options. */
@@ -714,6 +717,9 @@ static struct timerlat_top_params
714717
case '6':
715718
params->warmup = get_llong_from_str(optarg);
716719
break;
720+
case '7':
721+
params->buffer_size = get_llong_from_str(optarg);
722+
break;
717723
default:
718724
timerlat_top_usage("Invalid option");
719725
}
@@ -952,6 +958,12 @@ int timerlat_top_main(int argc, char *argv[])
952958
if (retval)
953959
goto out_top;
954960
}
961+
962+
if (params->buffer_size > 0) {
963+
retval = trace_set_buffer_size(&record->trace, params->buffer_size);
964+
if (retval)
965+
goto out_top;
966+
}
955967
}
956968

957969
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)