Skip to content

Commit 272ced2

Browse files
Daniel Bristot de Oliveirarostedt
authored andcommitted
rtla: Add --house-keeping option
To avoid having rtla interfering with the measurement threads, add an option for the user to set the CPUs in which rtla should run. For instance: # rtla timerlat top -H 0 -c 1-7 Will place rtla in the CPU 0, while running the measurement threads in the CPU 1-7. Link: https://lkml.kernel.org/r/6a6c78a579a96ba8b02ae67ee1e0ba2cb5e03c4a.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> Suggested-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 a957cbc commit 272ced2

7 files changed

Lines changed: 166 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
@@ -2,6 +2,10 @@
22

33
Set the osnoise tracer to run the sample threads in the cpu-list.
44

5+
**-H**, **--house-keeping** *cpu-list*
6+
7+
Run rtla control threads only on the given cpu-list.
8+
59
**-d**, **--duration** *time[s|m|h|d]*
610

711
Set the duration of the session.

tools/tracing/rtla/src/osnoise_hist.c

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright (C) 2021 Red Hat Inc, Daniel Bristot de Oliveira <bristot@kernel.org>
44
*/
55

6+
#define _GNU_SOURCE
67
#include <getopt.h>
78
#include <stdlib.h>
89
#include <string.h>
@@ -11,6 +12,7 @@
1112
#include <errno.h>
1213
#include <stdio.h>
1314
#include <time.h>
15+
#include <sched.h>
1416

1517
#include "utils.h"
1618
#include "osnoise.h"
@@ -30,6 +32,8 @@ struct osnoise_hist_params {
3032
int set_sched;
3133
int output_divisor;
3234
int cgroup;
35+
int hk_cpus;
36+
cpu_set_t hk_cpu_set;
3337
struct sched_attr sched_param;
3438
struct trace_events *events;
3539

@@ -434,8 +438,8 @@ static void osnoise_hist_usage(char *usage)
434438
"",
435439
" usage: rtla osnoise hist [-h] [-D] [-d s] [-a us] [-p us] [-r us] [-s us] [-S us] \\",
436440
" [-T us] [-t[=file]] [-e sys[:event]] [--filter <filter>] [--trigger <trigger>] \\",
437-
" [-c cpu-list] [-P priority] [-b N] [-E N] [--no-header] [--no-summary] [--no-index] \\",
438-
" [--with-zeros] [-C[=cgroup_name]]",
441+
" [-c cpu-list] [-H cpu-list] [-P priority] [-b N] [-E N] [--no-header] [--no-summary] \\",
442+
" [--no-index] [--with-zeros] [-C[=cgroup_name]]",
439443
"",
440444
" -h/--help: print this menu",
441445
" -a/--auto: set automatic trace mode, stopping the session if argument in us sample is hit",
@@ -445,6 +449,7 @@ static void osnoise_hist_usage(char *usage)
445449
" -S/--stop-total us: stop trace if the total sample is higher than the argument in us",
446450
" -T/--threshold us: the minimum delta to be considered a noise",
447451
" -c/--cpus cpu-list: list of cpus to run osnoise threads",
452+
" -H/--house-keeping cpus: run rtla control threads only on the given cpus",
448453
" -C/--cgroup[=cgroup_name]: set cgroup, if no cgroup_name is passed, the rtla's cgroup will be inherited",
449454
" -d/--duration time[s|m|h|d]: duration of the session",
450455
" -D/--debug: print debug info",
@@ -507,6 +512,7 @@ static struct osnoise_hist_params
507512
{"cgroup", optional_argument, 0, 'C'},
508513
{"debug", no_argument, 0, 'D'},
509514
{"duration", required_argument, 0, 'd'},
515+
{"house-keeping", required_argument, 0, 'H'},
510516
{"help", no_argument, 0, 'h'},
511517
{"period", required_argument, 0, 'p'},
512518
{"priority", required_argument, 0, 'P'},
@@ -528,7 +534,7 @@ static struct osnoise_hist_params
528534
/* getopt_long stores the option index here. */
529535
int option_index = 0;
530536

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

534540
/* detect the end of the options. */
@@ -597,6 +603,14 @@ static struct osnoise_hist_params
597603
case '?':
598604
osnoise_hist_usage(NULL);
599605
break;
606+
case 'H':
607+
params->hk_cpus = 1;
608+
retval = parse_cpu_set(optarg, &params->hk_cpu_set);
609+
if (retval) {
610+
err_msg("Error parsing house keeping CPUs\n");
611+
exit(EXIT_FAILURE);
612+
}
613+
break;
600614
case 'p':
601615
params->period = get_llong_from_str(optarg);
602616
if (params->period > 10000000)
@@ -732,6 +746,15 @@ osnoise_hist_apply_config(struct osnoise_tool *tool, struct osnoise_hist_params
732746
}
733747
}
734748

749+
if (params->hk_cpus) {
750+
retval = sched_setaffinity(getpid(), sizeof(params->hk_cpu_set),
751+
&params->hk_cpu_set);
752+
if (retval == -1) {
753+
err_msg("Failed to set rtla to the house keeping CPUs\n");
754+
goto out_err;
755+
}
756+
}
757+
735758
return 0;
736759

737760
out_err:

tools/tracing/rtla/src/osnoise_top.c

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
* Copyright (C) 2021 Red Hat Inc, Daniel Bristot de Oliveira <bristot@kernel.org>
44
*/
55

6+
#define _GNU_SOURCE
67
#include <getopt.h>
78
#include <stdlib.h>
89
#include <string.h>
910
#include <signal.h>
1011
#include <unistd.h>
1112
#include <stdio.h>
1213
#include <time.h>
14+
#include <sched.h>
1315

1416
#include "osnoise.h"
1517
#include "utils.h"
@@ -37,6 +39,8 @@ struct osnoise_top_params {
3739
int quiet;
3840
int set_sched;
3941
int cgroup;
42+
int hk_cpus;
43+
cpu_set_t hk_cpu_set;
4044
struct sched_attr sched_param;
4145
struct trace_events *events;
4246
enum osnoise_mode mode;
@@ -278,7 +282,7 @@ static void osnoise_top_usage(struct osnoise_top_params *params, char *usage)
278282
static const char * const msg[] = {
279283
" [-h] [-q] [-D] [-d s] [-a us] [-p us] [-r us] [-s us] [-S us] \\",
280284
" [-T us] [-t[=file]] [-e sys[:event]] [--filter <filter>] [--trigger <trigger>] \\",
281-
" [-c cpu-list] [-P priority] [-C[=cgroup_name]]",
285+
" [-c cpu-list] [-H cpu-list] [-P priority] [-C[=cgroup_name]]",
282286
"",
283287
" -h/--help: print this menu",
284288
" -a/--auto: set automatic trace mode, stopping the session if argument in us sample is hit",
@@ -288,6 +292,7 @@ static void osnoise_top_usage(struct osnoise_top_params *params, char *usage)
288292
" -S/--stop-total us: stop trace if the total sample is higher than the argument in us",
289293
" -T/--threshold us: the minimum delta to be considered a noise",
290294
" -c/--cpus cpu-list: list of cpus to run osnoise threads",
295+
" -H/--house-keeping cpus: run rtla control threads only on the given cpus",
291296
" -C/--cgroup[=cgroup_name]: set cgroup, if no cgroup_name is passed, the rtla's cgroup will be inherited",
292297
" -d/--duration time[s|m|h|d]: duration of the session",
293298
" -D/--debug: print debug info",
@@ -354,6 +359,7 @@ struct osnoise_top_params *osnoise_top_parse_args(int argc, char **argv)
354359
{"debug", no_argument, 0, 'D'},
355360
{"duration", required_argument, 0, 'd'},
356361
{"event", required_argument, 0, 'e'},
362+
{"house-keeping", required_argument, 0, 'H'},
357363
{"help", no_argument, 0, 'h'},
358364
{"period", required_argument, 0, 'p'},
359365
{"priority", required_argument, 0, 'P'},
@@ -371,7 +377,7 @@ struct osnoise_top_params *osnoise_top_parse_args(int argc, char **argv)
371377
/* getopt_long stores the option index here. */
372378
int option_index = 0;
373379

374-
c = getopt_long(argc, argv, "a:c:C::d:De:hp:P:qr:s:S:t::T:0:1:",
380+
c = getopt_long(argc, argv, "a:c:C::d:De:hH:p:P:qr:s:S:t::T:0:1:",
375381
long_options, &option_index);
376382

377383
/* Detect the end of the options. */
@@ -430,6 +436,14 @@ struct osnoise_top_params *osnoise_top_parse_args(int argc, char **argv)
430436
case '?':
431437
osnoise_top_usage(params, NULL);
432438
break;
439+
case 'H':
440+
params->hk_cpus = 1;
441+
retval = parse_cpu_set(optarg, &params->hk_cpu_set);
442+
if (retval) {
443+
err_msg("Error parsing house keeping CPUs\n");
444+
exit(EXIT_FAILURE);
445+
}
446+
break;
433447
case 'p':
434448
params->period = get_llong_from_str(optarg);
435449
if (params->period > 10000000)
@@ -561,6 +575,15 @@ osnoise_top_apply_config(struct osnoise_tool *tool, struct osnoise_top_params *p
561575
}
562576
}
563577

578+
if (params->hk_cpus) {
579+
retval = sched_setaffinity(getpid(), sizeof(params->hk_cpu_set),
580+
&params->hk_cpu_set);
581+
if (retval == -1) {
582+
err_msg("Failed to set rtla to the house keeping CPUs\n");
583+
goto out_err;
584+
}
585+
}
586+
564587
return 0;
565588

566589
out_err:

tools/tracing/rtla/src/timerlat_hist.c

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
* Copyright (C) 2021 Red Hat Inc, Daniel Bristot de Oliveira <bristot@kernel.org>
44
*/
55

6+
#define _GNU_SOURCE
67
#include <getopt.h>
78
#include <stdlib.h>
89
#include <string.h>
910
#include <signal.h>
1011
#include <unistd.h>
1112
#include <stdio.h>
1213
#include <time.h>
14+
#include <sched.h>
1315

1416
#include "utils.h"
1517
#include "osnoise.h"
@@ -31,6 +33,8 @@ struct timerlat_hist_params {
3133
int set_sched;
3234
int dma_latency;
3335
int cgroup;
36+
int hk_cpus;
37+
cpu_set_t hk_cpu_set;
3438
struct sched_attr sched_param;
3539
struct trace_events *events;
3640
char no_irq;
@@ -432,7 +436,7 @@ static void timerlat_hist_usage(char *usage)
432436
char *msg[] = {
433437
"",
434438
" usage: [rtla] timerlat hist [-h] [-q] [-d s] [-D] [-n] [-a us] [-p us] [-i us] [-T us] [-s us] \\",
435-
" [-t[=file]] [-e sys[:event]] [--filter <filter>] [--trigger <trigger>] [-c cpu-list] \\",
439+
" [-t[=file]] [-e sys[:event]] [--filter <filter>] [--trigger <trigger>] [-c cpu-list] [-H cpu-list]\\",
436440
" [-P priority] [-E N] [-b N] [--no-irq] [--no-thread] [--no-header] [--no-summary] \\",
437441
" [--no-index] [--with-zeros] [--dma-latency us] [-C[=cgroup_name]]",
438442
"",
@@ -443,6 +447,7 @@ static void timerlat_hist_usage(char *usage)
443447
" -T/--thread us: stop trace if the thread latency is higher than the argument in us",
444448
" -s/--stack us: save the stack trace at the IRQ if a thread latency is higher than the argument in us",
445449
" -c/--cpus cpus: run the tracer only on the given cpus",
450+
" -H/--house-keeping cpus: run rtla control threads only on the given cpus",
446451
" -C/--cgroup[=cgroup_name]: set cgroup, if no cgroup_name is passed, the rtla's cgroup will be inherited",
447452
" -d/--duration time[m|h|d]: duration of the session in seconds",
448453
" -D/--debug: print debug info",
@@ -513,6 +518,7 @@ static struct timerlat_hist_params
513518
{"debug", no_argument, 0, 'D'},
514519
{"entries", required_argument, 0, 'E'},
515520
{"duration", required_argument, 0, 'd'},
521+
{"house-keeping", required_argument, 0, 'H'},
516522
{"help", no_argument, 0, 'h'},
517523
{"irq", required_argument, 0, 'i'},
518524
{"nano", no_argument, 0, 'n'},
@@ -537,7 +543,7 @@ static struct timerlat_hist_params
537543
/* getopt_long stores the option index here. */
538544
int option_index = 0;
539545

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

543549
/* detect the end of the options. */
@@ -608,6 +614,14 @@ static struct timerlat_hist_params
608614
case '?':
609615
timerlat_hist_usage(NULL);
610616
break;
617+
case 'H':
618+
params->hk_cpus = 1;
619+
retval = parse_cpu_set(optarg, &params->hk_cpu_set);
620+
if (retval) {
621+
err_msg("Error parsing house keeping CPUs\n");
622+
exit(EXIT_FAILURE);
623+
}
624+
break;
611625
case 'i':
612626
params->stop_us = get_llong_from_str(optarg);
613627
break;
@@ -755,6 +769,15 @@ timerlat_hist_apply_config(struct osnoise_tool *tool, struct timerlat_hist_param
755769
}
756770
}
757771

772+
if (params->hk_cpus) {
773+
retval = sched_setaffinity(getpid(), sizeof(params->hk_cpu_set),
774+
&params->hk_cpu_set);
775+
if (retval == -1) {
776+
err_msg("Failed to set rtla to the house keeping CPUs\n");
777+
goto out_err;
778+
}
779+
}
780+
758781
return 0;
759782

760783
out_err:

tools/tracing/rtla/src/timerlat_top.c

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright (C) 2021 Red Hat Inc, Daniel Bristot de Oliveira <bristot@kernel.org>
44
*/
55

6+
#define _GNU_SOURCE
67
#include <getopt.h>
78
#include <stdlib.h>
89
#include <string.h>
@@ -11,6 +12,7 @@
1112
#include <stdio.h>
1213
#include <time.h>
1314
#include <errno.h>
15+
#include <sched.h>
1416

1517
#include "utils.h"
1618
#include "osnoise.h"
@@ -37,6 +39,8 @@ struct timerlat_top_params {
3739
int aa_only;
3840
int dump_tasks;
3941
int cgroup;
42+
int hk_cpus;
43+
cpu_set_t hk_cpu_set;
4044
struct sched_attr sched_param;
4145
struct trace_events *events;
4246
};
@@ -286,7 +290,7 @@ static void timerlat_top_usage(char *usage)
286290
static const char *const msg[] = {
287291
"",
288292
" usage: rtla timerlat [top] [-h] [-q] [-a us] [-d s] [-D] [-n] [-p us] [-i us] [-T us] [-s us] \\",
289-
" [[-t[=file]] [-e sys[:event]] [--filter <filter>] [--trigger <trigger>] [-c cpu-list] \\",
293+
" [[-t[=file]] [-e sys[:event]] [--filter <filter>] [--trigger <trigger>] [-c cpu-list] [-H cpu-list]\\",
290294
" [-P priority] [--dma-latency us] [--aa-only us] [-C[=cgroup_name]]",
291295
"",
292296
" -h/--help: print this menu",
@@ -297,6 +301,7 @@ static void timerlat_top_usage(char *usage)
297301
" -T/--thread us: stop trace if the thread latency is higher than the argument in us",
298302
" -s/--stack us: save the stack trace at the IRQ if a thread latency is higher than the argument in us",
299303
" -c/--cpus cpus: run the tracer only on the given cpus",
304+
" -H/--house-keeping cpus: run rtla control threads only on the given cpus",
300305
" -C/--cgroup[=cgroup_name]: set cgroup, if no cgroup_name is passed, the rtla's cgroup will be inherited",
301306
" -d/--duration time[m|h|d]: duration of the session in seconds",
302307
" -D/--debug: print debug info",
@@ -360,6 +365,7 @@ static struct timerlat_top_params
360365
{"duration", required_argument, 0, 'd'},
361366
{"event", required_argument, 0, 'e'},
362367
{"help", no_argument, 0, 'h'},
368+
{"house-keeping", required_argument, 0, 'H'},
363369
{"irq", required_argument, 0, 'i'},
364370
{"nano", no_argument, 0, 'n'},
365371
{"period", required_argument, 0, 'p'},
@@ -380,7 +386,7 @@ static struct timerlat_top_params
380386
/* getopt_long stores the option index here. */
381387
int option_index = 0;
382388

383-
c = getopt_long(argc, argv, "a:c:C::d:De:hi:np:P:qs:t::T:0:1:2:345:",
389+
c = getopt_long(argc, argv, "a:c:C::d:De:hH:i:np:P:qs:t::T:0:1:2:345:",
384390
long_options, &option_index);
385391

386392
/* detect the end of the options. */
@@ -454,6 +460,14 @@ static struct timerlat_top_params
454460
case '?':
455461
timerlat_top_usage(NULL);
456462
break;
463+
case 'H':
464+
params->hk_cpus = 1;
465+
retval = parse_cpu_set(optarg, &params->hk_cpu_set);
466+
if (retval) {
467+
err_msg("Error parsing house keeping CPUs\n");
468+
exit(EXIT_FAILURE);
469+
}
470+
break;
457471
case 'i':
458472
params->stop_us = get_llong_from_str(optarg);
459473
break;
@@ -598,6 +612,15 @@ timerlat_top_apply_config(struct osnoise_tool *top, struct timerlat_top_params *
598612
}
599613
}
600614

615+
if (params->hk_cpus) {
616+
retval = sched_setaffinity(getpid(), sizeof(params->hk_cpu_set),
617+
&params->hk_cpu_set);
618+
if (retval == -1) {
619+
err_msg("Failed to set rtla to the house keeping CPUs\n");
620+
goto out_err;
621+
}
622+
}
623+
601624
return 0;
602625

603626
out_err:

0 commit comments

Comments
 (0)