Skip to content

Commit fb9e90a

Browse files
author
Daniel Bristot de Oliveira
committed
rtla/timerlat: Make user-space threads the default
After ther -u addition, most of the known users are setting it. And it makes sense, as it adds more information, and inherits the default setup for the threads - e.g., cgroups configs. Thus, if the user-space interface is available, enable -u. Otherwise, use the in-kernel thread. Add the -k option to allow the user to request kernel-threads. Link: https://lkml.kernel.org/r/9241d3089de4091b124f780ed832a0e6646cadaa.1713968967.git.bristot@kernel.org Cc: Jonathan Corbet <[email protected]> Cc: Juri Lelli <[email protected]> Signed-off-by: Daniel Bristot de Oliveira <[email protected]>
1 parent cdbf719 commit fb9e90a

File tree

3 files changed

+61
-7
lines changed

3 files changed

+61
-7
lines changed

Documentation/tools/rtla/common_timerlat_options.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,16 @@
2727
*cyclictest* sets this value to *0* by default, use **--dma-latency** *0* to have
2828
similar results.
2929

30+
**-k**, **--kernel-threads**
31+
32+
Use timerlat kernel-space threads, in contrast of **-u**.
33+
3034
**-u**, **--user-threads**
3135

3236
Set timerlat to run without a workload, and then dispatches user-space workloads
3337
to wait on the timerlat_fd. Once the workload is awakes, it goes to sleep again
3438
adding so the measurement for the kernel-to-user and user-to-kernel to the tracer
35-
output.
39+
output. **--user-threads** will be used unless the user specify **-k**.
3640

3741
**-U**, **--user-load**
3842

tools/tracing/rtla/src/timerlat_hist.c

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ struct timerlat_hist_params {
4040
int no_aa;
4141
int dump_tasks;
4242
int user_workload;
43+
int kernel_workload;
4344
int user_hist;
4445
cpu_set_t hk_cpu_set;
4546
struct sched_attr sched_param;
@@ -628,7 +629,7 @@ static void timerlat_hist_usage(char *usage)
628629
" usage: [rtla] timerlat hist [-h] [-q] [-d s] [-D] [-n] [-a us] [-p us] [-i us] [-T us] [-s us] \\",
629630
" [-t[=file]] [-e sys[:event]] [--filter <filter>] [--trigger <trigger>] [-c cpu-list] [-H cpu-list]\\",
630631
" [-P priority] [-E N] [-b N] [--no-irq] [--no-thread] [--no-header] [--no-summary] \\",
631-
" [--no-index] [--with-zeros] [--dma-latency us] [-C[=cgroup_name]] [--no-aa] [--dump-task] [-u]",
632+
" [--no-index] [--with-zeros] [--dma-latency us] [-C[=cgroup_name]] [--no-aa] [--dump-task] [-u|-k]",
632633
" [--warm-up s]",
633634
"",
634635
" -h/--help: print this menu",
@@ -664,7 +665,8 @@ static void timerlat_hist_usage(char *usage)
664665
" f:prio - use SCHED_FIFO with prio",
665666
" d:runtime[us|ms|s]:period[us|ms|s] - use SCHED_DEADLINE with runtime and period",
666667
" in nanoseconds",
667-
" -u/--user-threads: use rtla user-space threads instead of in-kernel timerlat threads",
668+
" -u/--user-threads: use rtla user-space threads instead of kernel-space timerlat threads",
669+
" -k/--kernel-threads: use timerlat kernel-space threads instead of rtla user-space threads",
668670
" -U/--user-load: enable timerlat for user-defined user-space workload",
669671
" --warm-up s: let the workload run for s seconds before collecting data",
670672
NULL,
@@ -728,6 +730,7 @@ static struct timerlat_hist_params
728730
{"thread", required_argument, 0, 'T'},
729731
{"trace", optional_argument, 0, 't'},
730732
{"user-threads", no_argument, 0, 'u'},
733+
{"kernel-threads", no_argument, 0, 'k'},
731734
{"user-load", no_argument, 0, 'U'},
732735
{"event", required_argument, 0, 'e'},
733736
{"no-irq", no_argument, 0, '0'},
@@ -748,7 +751,7 @@ static struct timerlat_hist_params
748751
/* getopt_long stores the option index here. */
749752
int option_index = 0;
750753

751-
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:",
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:",
752755
long_options, &option_index);
753756

754757
/* detect the end of the options. */
@@ -831,6 +834,9 @@ static struct timerlat_hist_params
831834
case 'i':
832835
params->stop_us = get_llong_from_str(optarg);
833836
break;
837+
case 'k':
838+
params->kernel_workload = 1;
839+
break;
834840
case 'n':
835841
params->output_divisor = 1;
836842
break;
@@ -942,6 +948,9 @@ static struct timerlat_hist_params
942948
if (!params->stop_us && !params->stop_total_us)
943949
params->no_aa = 1;
944950

951+
if (params->kernel_workload && params->user_workload)
952+
timerlat_hist_usage("--kernel-threads and --user-threads are mutually exclusive!");
953+
945954
return params;
946955
}
947956

@@ -1017,6 +1026,22 @@ timerlat_hist_apply_config(struct osnoise_tool *tool, struct timerlat_hist_param
10171026
auto_house_keeping(&params->monitored_cpus);
10181027
}
10191028

1029+
/*
1030+
* If the user did not specify a type of thread, try user-threads first.
1031+
* Fall back to kernel threads otherwise.
1032+
*/
1033+
if (!params->kernel_workload && !params->user_workload) {
1034+
retval = tracefs_file_exists(NULL, "osnoise/per_cpu/cpu0/timerlat_fd");
1035+
if (retval) {
1036+
debug_msg("User-space interface detected, setting user-threads\n");
1037+
params->user_workload = 1;
1038+
params->user_hist = 1;
1039+
} else {
1040+
debug_msg("User-space interface not detected, setting kernel-threads\n");
1041+
params->kernel_workload = 1;
1042+
}
1043+
}
1044+
10201045
if (params->user_hist) {
10211046
retval = osnoise_set_workload(tool->context, 0);
10221047
if (retval) {

tools/tracing/rtla/src/timerlat_top.c

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ struct timerlat_top_params {
4444
int hk_cpus;
4545
int user_top;
4646
int user_workload;
47+
int kernel_workload;
4748
int pretty_output;
4849
int warmup;
4950
cpu_set_t hk_cpu_set;
@@ -445,7 +446,7 @@ static void timerlat_top_usage(char *usage)
445446
"",
446447
" usage: rtla timerlat [top] [-h] [-q] [-a us] [-d s] [-D] [-n] [-p us] [-i us] [-T us] [-s us] \\",
447448
" [[-t[=file]] [-e sys[:event]] [--filter <filter>] [--trigger <trigger>] [-c cpu-list] [-H cpu-list]\\",
448-
" [-P priority] [--dma-latency us] [--aa-only us] [-C[=cgroup_name]] [-u] [--warm-up s]",
449+
" [-P priority] [--dma-latency us] [--aa-only us] [-C[=cgroup_name]] [-u|-k] [--warm-up s]",
449450
"",
450451
" -h/--help: print this menu",
451452
" -a/--auto: set automatic trace mode, stopping the session if argument in us latency is hit",
@@ -474,7 +475,8 @@ static void timerlat_top_usage(char *usage)
474475
" f:prio - use SCHED_FIFO with prio",
475476
" d:runtime[us|ms|s]:period[us|ms|s] - use SCHED_DEADLINE with runtime and period",
476477
" in nanoseconds",
477-
" -u/--user-threads: use rtla user-space threads instead of in-kernel timerlat threads",
478+
" -u/--user-threads: use rtla user-space threads instead of kernel-space timerlat threads",
479+
" -k/--kernel-threads: use timerlat kernel-space threads instead of rtla user-space threads",
478480
" -U/--user-load: enable timerlat for user-defined user-space workload",
479481
" --warm-up s: let the workload run for s seconds before collecting data",
480482
NULL,
@@ -536,6 +538,7 @@ static struct timerlat_top_params
536538
{"thread", required_argument, 0, 'T'},
537539
{"trace", optional_argument, 0, 't'},
538540
{"user-threads", no_argument, 0, 'u'},
541+
{"kernel-threads", no_argument, 0, 'k'},
539542
{"user-load", no_argument, 0, 'U'},
540543
{"trigger", required_argument, 0, '0'},
541544
{"filter", required_argument, 0, '1'},
@@ -550,7 +553,7 @@ static struct timerlat_top_params
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:knp:P:qs:t::T:uU0:1:2:345:6:",
554557
long_options, &option_index);
555558

556559
/* detect the end of the options. */
@@ -635,6 +638,9 @@ static struct timerlat_top_params
635638
case 'i':
636639
params->stop_us = get_llong_from_str(optarg);
637640
break;
641+
case 'k':
642+
params->kernel_workload = true;
643+
break;
638644
case 'n':
639645
params->output_divisor = 1;
640646
break;
@@ -729,6 +735,9 @@ static struct timerlat_top_params
729735
if (params->no_aa && params->aa_only)
730736
timerlat_top_usage("--no-aa and --aa-only are mutually exclusive!");
731737

738+
if (params->kernel_workload && params->user_workload)
739+
timerlat_top_usage("--kernel-threads and --user-threads are mutually exclusive!");
740+
732741
return params;
733742
}
734743

@@ -807,6 +816,22 @@ timerlat_top_apply_config(struct osnoise_tool *top, struct timerlat_top_params *
807816
auto_house_keeping(&params->monitored_cpus);
808817
}
809818

819+
/*
820+
* If the user did not specify a type of thread, try user-threads first.
821+
* Fall back to kernel threads otherwise.
822+
*/
823+
if (!params->kernel_workload && !params->user_workload) {
824+
retval = tracefs_file_exists(NULL, "osnoise/per_cpu/cpu0/timerlat_fd");
825+
if (retval) {
826+
debug_msg("User-space interface detected, setting user-threads\n");
827+
params->user_workload = 1;
828+
params->user_top = 1;
829+
} else {
830+
debug_msg("User-space interface not detected, setting kernel-threads\n");
831+
params->kernel_workload = 1;
832+
}
833+
}
834+
810835
if (params->user_top) {
811836
retval = osnoise_set_workload(top->context, 0);
812837
if (retval) {

0 commit comments

Comments
 (0)