Skip to content

Commit a957cbc

Browse files
Daniel Bristot de Oliveirarostedt
authored andcommitted
rtla: Add -C cgroup support
The -C option sets a cgroup to the tracer's threads. If the -C option is passed without arguments, the tracer's thread will inherit rtla's cgroup. Otherwise, the threads will be placed on the cgroup passed to the option. Link: https://lkml.kernel.org/r/cb051477331d292f17c08bf1d66f0e0384bbe5a5.1686066600.git.bristot@kernel.org Cc: William White <chwhite@redhat.com> Cc: Jonathan Corbet <corbet@lwn.net> Tested-by: Juri Lelli <juri.lelli@redhat.com> Signed-off-by: Daniel Bristot de Oliveira <bristot@kernel.org> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 parent 9561de3 commit a957cbc

7 files changed

Lines changed: 286 additions & 9 deletions

File tree

Documentation/tools/rtla/common_options.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@
4242
- *f:prio* - use SCHED_FIFO with *prio*;
4343
- *d:runtime[us|ms|s]:period[us|ms|s]* - use SCHED_DEADLINE with *runtime* and *period* in nanoseconds.
4444

45+
**-C**, **--cgroup**\[*=cgroup*]
46+
47+
Set a *cgroup* to the tracer's threads. If the **-C** option is passed without arguments, the tracer's thread will inherit **rtla**'s *cgroup*. Otherwise, the threads will be placed on the *cgroup* passed to the option.
48+
4549
**-h**, **--help**
4650

4751
Print help menu.

tools/tracing/rtla/src/osnoise_hist.c

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ struct osnoise_hist_params {
1919
char *cpus;
2020
char *monitored_cpus;
2121
char *trace_output;
22+
char *cgroup_name;
2223
unsigned long long runtime;
2324
unsigned long long period;
2425
long long threshold;
@@ -28,6 +29,7 @@ struct osnoise_hist_params {
2829
int duration;
2930
int set_sched;
3031
int output_divisor;
32+
int cgroup;
3133
struct sched_attr sched_param;
3234
struct trace_events *events;
3335

@@ -433,7 +435,7 @@ static void osnoise_hist_usage(char *usage)
433435
" usage: rtla osnoise hist [-h] [-D] [-d s] [-a us] [-p us] [-r us] [-s us] [-S us] \\",
434436
" [-T us] [-t[=file]] [-e sys[:event]] [--filter <filter>] [--trigger <trigger>] \\",
435437
" [-c cpu-list] [-P priority] [-b N] [-E N] [--no-header] [--no-summary] [--no-index] \\",
436-
" [--with-zeros]",
438+
" [--with-zeros] [-C[=cgroup_name]]",
437439
"",
438440
" -h/--help: print this menu",
439441
" -a/--auto: set automatic trace mode, stopping the session if argument in us sample is hit",
@@ -443,6 +445,7 @@ static void osnoise_hist_usage(char *usage)
443445
" -S/--stop-total us: stop trace if the total sample is higher than the argument in us",
444446
" -T/--threshold us: the minimum delta to be considered a noise",
445447
" -c/--cpus cpu-list: list of cpus to run osnoise threads",
448+
" -C/--cgroup[=cgroup_name]: set cgroup, if no cgroup_name is passed, the rtla's cgroup will be inherited",
446449
" -d/--duration time[s|m|h|d]: duration of the session",
447450
" -D/--debug: print debug info",
448451
" -t/--trace[=file]: save the stopped trace to [file|osnoise_trace.txt]",
@@ -501,6 +504,7 @@ static struct osnoise_hist_params
501504
{"bucket-size", required_argument, 0, 'b'},
502505
{"entries", required_argument, 0, 'E'},
503506
{"cpus", required_argument, 0, 'c'},
507+
{"cgroup", optional_argument, 0, 'C'},
504508
{"debug", no_argument, 0, 'D'},
505509
{"duration", required_argument, 0, 'd'},
506510
{"help", no_argument, 0, 'h'},
@@ -524,7 +528,7 @@ static struct osnoise_hist_params
524528
/* getopt_long stores the option index here. */
525529
int option_index = 0;
526530

527-
c = getopt_long(argc, argv, "a:c:b:d:e:E:Dhp:P:r:s:S:t::T:01234:5:",
531+
c = getopt_long(argc, argv, "a:c:C::b:d:e:E:Dhp:P:r:s:S:t::T:01234:5:",
528532
long_options, &option_index);
529533

530534
/* detect the end of the options. */
@@ -554,6 +558,16 @@ static struct osnoise_hist_params
554558
osnoise_hist_usage("\nInvalid -c cpu list\n");
555559
params->cpus = optarg;
556560
break;
561+
case 'C':
562+
params->cgroup = 1;
563+
if (!optarg) {
564+
/* will inherit this cgroup */
565+
params->cgroup_name = NULL;
566+
} else if (*optarg == '=') {
567+
/* skip the = */
568+
params->cgroup_name = ++optarg;
569+
}
570+
break;
557571
case 'D':
558572
config_debug = 1;
559573
break;
@@ -816,6 +830,14 @@ int osnoise_hist_main(int argc, char *argv[])
816830
}
817831
}
818832

833+
if (params->cgroup) {
834+
retval = set_comm_cgroup("timerlat/", params->cgroup_name);
835+
if (!retval) {
836+
err_msg("Failed to move threads to cgroup\n");
837+
goto out_free;
838+
}
839+
}
840+
819841
trace_instance_start(trace);
820842

821843
if (params->trace_output) {

tools/tracing/rtla/src/osnoise_top.c

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ struct osnoise_top_params {
2626
char *cpus;
2727
char *monitored_cpus;
2828
char *trace_output;
29+
char *cgroup_name;
2930
unsigned long long runtime;
3031
unsigned long long period;
3132
long long threshold;
@@ -35,6 +36,7 @@ struct osnoise_top_params {
3536
int duration;
3637
int quiet;
3738
int set_sched;
39+
int cgroup;
3840
struct sched_attr sched_param;
3941
struct trace_events *events;
4042
enum osnoise_mode mode;
@@ -276,7 +278,7 @@ static void osnoise_top_usage(struct osnoise_top_params *params, char *usage)
276278
static const char * const msg[] = {
277279
" [-h] [-q] [-D] [-d s] [-a us] [-p us] [-r us] [-s us] [-S us] \\",
278280
" [-T us] [-t[=file]] [-e sys[:event]] [--filter <filter>] [--trigger <trigger>] \\",
279-
" [-c cpu-list] [-P priority]",
281+
" [-c cpu-list] [-P priority] [-C[=cgroup_name]]",
280282
"",
281283
" -h/--help: print this menu",
282284
" -a/--auto: set automatic trace mode, stopping the session if argument in us sample is hit",
@@ -286,6 +288,7 @@ static void osnoise_top_usage(struct osnoise_top_params *params, char *usage)
286288
" -S/--stop-total us: stop trace if the total sample is higher than the argument in us",
287289
" -T/--threshold us: the minimum delta to be considered a noise",
288290
" -c/--cpus cpu-list: list of cpus to run osnoise threads",
291+
" -C/--cgroup[=cgroup_name]: set cgroup, if no cgroup_name is passed, the rtla's cgroup will be inherited",
289292
" -d/--duration time[s|m|h|d]: duration of the session",
290293
" -D/--debug: print debug info",
291294
" -t/--trace[=file]: save the stopped trace to [file|osnoise_trace.txt]",
@@ -347,6 +350,7 @@ struct osnoise_top_params *osnoise_top_parse_args(int argc, char **argv)
347350
static struct option long_options[] = {
348351
{"auto", required_argument, 0, 'a'},
349352
{"cpus", required_argument, 0, 'c'},
353+
{"cgroup", optional_argument, 0, 'C'},
350354
{"debug", no_argument, 0, 'D'},
351355
{"duration", required_argument, 0, 'd'},
352356
{"event", required_argument, 0, 'e'},
@@ -367,7 +371,7 @@ struct osnoise_top_params *osnoise_top_parse_args(int argc, char **argv)
367371
/* getopt_long stores the option index here. */
368372
int option_index = 0;
369373

370-
c = getopt_long(argc, argv, "a:c:d:De:hp:P:qr:s:S:t::T:0:1:",
374+
c = getopt_long(argc, argv, "a:c:C::d:De:hp:P:qr:s:S:t::T:0:1:",
371375
long_options, &option_index);
372376

373377
/* Detect the end of the options. */
@@ -392,6 +396,16 @@ struct osnoise_top_params *osnoise_top_parse_args(int argc, char **argv)
392396
osnoise_top_usage(params, "\nInvalid -c cpu list\n");
393397
params->cpus = optarg;
394398
break;
399+
case 'C':
400+
params->cgroup = 1;
401+
if (!optarg) {
402+
/* will inherit this cgroup */
403+
params->cgroup_name = NULL;
404+
} else if (*optarg == '=') {
405+
/* skip the = */
406+
params->cgroup_name = ++optarg;
407+
}
408+
break;
395409
case 'D':
396410
config_debug = 1;
397411
break;
@@ -643,6 +657,14 @@ int osnoise_top_main(int argc, char **argv)
643657
}
644658
}
645659

660+
if (params->cgroup) {
661+
retval = set_comm_cgroup("osnoise/", params->cgroup_name);
662+
if (!retval) {
663+
err_msg("Failed to move threads to cgroup\n");
664+
goto out_free;
665+
}
666+
}
667+
646668
trace_instance_start(trace);
647669

648670
if (params->trace_output) {

tools/tracing/rtla/src/timerlat_hist.c

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ struct timerlat_hist_params {
1919
char *cpus;
2020
char *monitored_cpus;
2121
char *trace_output;
22+
char *cgroup_name;
2223
unsigned long long runtime;
2324
long long stop_us;
2425
long long stop_total_us;
@@ -29,9 +30,9 @@ struct timerlat_hist_params {
2930
int duration;
3031
int set_sched;
3132
int dma_latency;
33+
int cgroup;
3234
struct sched_attr sched_param;
3335
struct trace_events *events;
34-
3536
char no_irq;
3637
char no_thread;
3738
char no_header;
@@ -433,7 +434,7 @@ static void timerlat_hist_usage(char *usage)
433434
" usage: [rtla] timerlat hist [-h] [-q] [-d s] [-D] [-n] [-a us] [-p us] [-i us] [-T us] [-s us] \\",
434435
" [-t[=file]] [-e sys[:event]] [--filter <filter>] [--trigger <trigger>] [-c cpu-list] \\",
435436
" [-P priority] [-E N] [-b N] [--no-irq] [--no-thread] [--no-header] [--no-summary] \\",
436-
" [--no-index] [--with-zeros] [--dma-latency us]",
437+
" [--no-index] [--with-zeros] [--dma-latency us] [-C[=cgroup_name]]",
437438
"",
438439
" -h/--help: print this menu",
439440
" -a/--auto: set automatic trace mode, stopping the session if argument in us latency is hit",
@@ -442,6 +443,7 @@ static void timerlat_hist_usage(char *usage)
442443
" -T/--thread us: stop trace if the thread latency is higher than the argument in us",
443444
" -s/--stack us: save the stack trace at the IRQ if a thread latency is higher than the argument in us",
444445
" -c/--cpus cpus: run the tracer only on the given cpus",
446+
" -C/--cgroup[=cgroup_name]: set cgroup, if no cgroup_name is passed, the rtla's cgroup will be inherited",
445447
" -d/--duration time[m|h|d]: duration of the session in seconds",
446448
" -D/--debug: print debug info",
447449
" -t/--trace[=file]: save the stopped trace to [file|timerlat_trace.txt]",
@@ -506,6 +508,7 @@ static struct timerlat_hist_params
506508
static struct option long_options[] = {
507509
{"auto", required_argument, 0, 'a'},
508510
{"cpus", required_argument, 0, 'c'},
511+
{"cgroup", optional_argument, 0, 'C'},
509512
{"bucket-size", required_argument, 0, 'b'},
510513
{"debug", no_argument, 0, 'D'},
511514
{"entries", required_argument, 0, 'E'},
@@ -534,7 +537,7 @@ static struct timerlat_hist_params
534537
/* getopt_long stores the option index here. */
535538
int option_index = 0;
536539

537-
c = getopt_long(argc, argv, "a:c:b:d:e:E:Dhi:np:P:s:t::T:0123456:7:8:",
540+
c = getopt_long(argc, argv, "a:c:C::b:d:e:E:Dhi:np:P:s:t::T:0123456:7:8:",
538541
long_options, &option_index);
539542

540543
/* detect the end of the options. */
@@ -561,6 +564,16 @@ static struct timerlat_hist_params
561564
timerlat_hist_usage("\nInvalid -c cpu list\n");
562565
params->cpus = optarg;
563566
break;
567+
case 'C':
568+
params->cgroup = 1;
569+
if (!optarg) {
570+
/* will inherit this cgroup */
571+
params->cgroup_name = NULL;
572+
} else if (*optarg == '=') {
573+
/* skip the = */
574+
params->cgroup_name = ++optarg;
575+
}
576+
break;
564577
case 'b':
565578
params->bucket_size = get_llong_from_str(optarg);
566579
if ((params->bucket_size == 0) || (params->bucket_size >= 1000000))
@@ -840,6 +853,14 @@ int timerlat_hist_main(int argc, char *argv[])
840853
}
841854
}
842855

856+
if (params->cgroup) {
857+
retval = set_comm_cgroup("timerlat/", params->cgroup_name);
858+
if (!retval) {
859+
err_msg("Failed to move threads to cgroup\n");
860+
goto out_free;
861+
}
862+
}
863+
843864
if (params->dma_latency >= 0) {
844865
dma_latency_fd = set_cpu_dma_latency(params->dma_latency);
845866
if (dma_latency_fd < 0) {

tools/tracing/rtla/src/timerlat_top.c

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ struct timerlat_top_params {
2121
char *cpus;
2222
char *monitored_cpus;
2323
char *trace_output;
24+
char *cgroup_name;
2425
unsigned long long runtime;
2526
long long stop_us;
2627
long long stop_total_us;
@@ -35,6 +36,7 @@ struct timerlat_top_params {
3536
int no_aa;
3637
int aa_only;
3738
int dump_tasks;
39+
int cgroup;
3840
struct sched_attr sched_param;
3941
struct trace_events *events;
4042
};
@@ -285,7 +287,7 @@ static void timerlat_top_usage(char *usage)
285287
"",
286288
" usage: rtla timerlat [top] [-h] [-q] [-a us] [-d s] [-D] [-n] [-p us] [-i us] [-T us] [-s us] \\",
287289
" [[-t[=file]] [-e sys[:event]] [--filter <filter>] [--trigger <trigger>] [-c cpu-list] \\",
288-
" [-P priority] [--dma-latency us] [--aa-only us]",
290+
" [-P priority] [--dma-latency us] [--aa-only us] [-C[=cgroup_name]]",
289291
"",
290292
" -h/--help: print this menu",
291293
" -a/--auto: set automatic trace mode, stopping the session if argument in us latency is hit",
@@ -295,6 +297,7 @@ static void timerlat_top_usage(char *usage)
295297
" -T/--thread us: stop trace if the thread latency is higher than the argument in us",
296298
" -s/--stack us: save the stack trace at the IRQ if a thread latency is higher than the argument in us",
297299
" -c/--cpus cpus: run the tracer only on the given cpus",
300+
" -C/--cgroup[=cgroup_name]: set cgroup, if no cgroup_name is passed, the rtla's cgroup will be inherited",
298301
" -d/--duration time[m|h|d]: duration of the session in seconds",
299302
" -D/--debug: print debug info",
300303
" --dump-tasks: prints the task running on all CPUs if stop conditions are met (depends on !--no-aa)",
@@ -352,6 +355,7 @@ static struct timerlat_top_params
352355
static struct option long_options[] = {
353356
{"auto", required_argument, 0, 'a'},
354357
{"cpus", required_argument, 0, 'c'},
358+
{"cgroup", optional_argument, 0, 'C'},
355359
{"debug", no_argument, 0, 'D'},
356360
{"duration", required_argument, 0, 'd'},
357361
{"event", required_argument, 0, 'e'},
@@ -376,7 +380,7 @@ static struct timerlat_top_params
376380
/* getopt_long stores the option index here. */
377381
int option_index = 0;
378382

379-
c = getopt_long(argc, argv, "a:c:d:De:hi:np:P:qs:t::T:0:1:2:345:",
383+
c = getopt_long(argc, argv, "a:c:C::d:De:hi:np:P:qs:t::T:0:1:2:345:",
380384
long_options, &option_index);
381385

382386
/* detect the end of the options. */
@@ -417,6 +421,16 @@ static struct timerlat_top_params
417421
timerlat_top_usage("\nInvalid -c cpu list\n");
418422
params->cpus = optarg;
419423
break;
424+
case 'C':
425+
params->cgroup = 1;
426+
if (!optarg) {
427+
/* will inherit this cgroup */
428+
params->cgroup_name = NULL;
429+
} else if (*optarg == '=') {
430+
/* skip the = */
431+
params->cgroup_name = ++optarg;
432+
}
433+
break;
420434
case 'D':
421435
config_debug = 1;
422436
break;
@@ -694,6 +708,14 @@ int timerlat_top_main(int argc, char *argv[])
694708
}
695709
}
696710

711+
if (params->cgroup) {
712+
retval = set_comm_cgroup("timerlat/", params->cgroup_name);
713+
if (!retval) {
714+
err_msg("Failed to move threads to cgroup\n");
715+
goto out_free;
716+
}
717+
}
718+
697719
if (params->dma_latency >= 0) {
698720
dma_latency_fd = set_cpu_dma_latency(params->dma_latency);
699721
if (dma_latency_fd < 0) {

0 commit comments

Comments
 (0)