Skip to content

Commit 263d7ea

Browse files
crwood-rhrostedt
authored andcommitted
tools/rtla: Create common_apply_config()
Merge the common bits of osnoise_apply_config() and timerlat_apply_config(). Put the result in a new common.c, and move enough things to common.h so that common.c does not need to include osnoise.h. Cc: John Kacur <[email protected]> Cc: Costa Shulyupin <[email protected]> Link: https://lore.kernel.org/[email protected] Reviewed-by: Tomas Glozar <[email protected]> Signed-off-by: Crystal Wood <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 5742bf6 commit 263d7ea

File tree

9 files changed

+142
-150
lines changed

9 files changed

+142
-150
lines changed

tools/tracing/rtla/src/Build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
rtla-y += trace.o
22
rtla-y += utils.o
33
rtla-y += actions.o
4+
rtla-y += common.o
45
rtla-y += osnoise.o
56
rtla-y += osnoise_top.o
67
rtla-y += osnoise_hist.o

tools/tracing/rtla/src/common.c

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
#define _GNU_SOURCE
3+
4+
#include <unistd.h>
5+
#include "common.h"
6+
7+
/*
8+
* common_apply_config - apply common configs to the initialized tool
9+
*/
10+
int
11+
common_apply_config(struct osnoise_tool *tool, struct common_params *params)
12+
{
13+
int retval, i;
14+
15+
if (!params->sleep_time)
16+
params->sleep_time = 1;
17+
18+
retval = osnoise_set_cpus(tool->context, params->cpus ? params->cpus : "all");
19+
if (retval) {
20+
err_msg("Failed to apply CPUs config\n");
21+
goto out_err;
22+
}
23+
24+
if (!params->cpus) {
25+
for (i = 0; i < sysconf(_SC_NPROCESSORS_CONF); i++)
26+
CPU_SET(i, &params->monitored_cpus);
27+
}
28+
29+
if (params->hk_cpus) {
30+
retval = sched_setaffinity(getpid(), sizeof(params->hk_cpu_set),
31+
&params->hk_cpu_set);
32+
if (retval == -1) {
33+
err_msg("Failed to set rtla to the house keeping CPUs\n");
34+
goto out_err;
35+
}
36+
} else if (params->cpus) {
37+
/*
38+
* Even if the user do not set a house-keeping CPU, try to
39+
* move rtla to a CPU set different to the one where the user
40+
* set the workload to run.
41+
*
42+
* No need to check results as this is an automatic attempt.
43+
*/
44+
auto_house_keeping(&params->monitored_cpus);
45+
}
46+
47+
/*
48+
* Set workload according to type of thread if the kernel supports it.
49+
* On kernels without support, user threads will have already failed
50+
* on missing fd, and kernel threads do not need it.
51+
*/
52+
retval = osnoise_set_workload(tool->context, params->kernel_workload);
53+
if (retval < -1) {
54+
err_msg("Failed to set OSNOISE_WORKLOAD option\n");
55+
goto out_err;
56+
}
57+
58+
return 0;
59+
60+
out_err:
61+
return -1;
62+
}
63+

tools/tracing/rtla/src/common.h

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,67 @@
11
/* SPDX-License-Identifier: GPL-2.0 */
22
#pragma once
33

4+
#include "trace.h"
45
#include "utils.h"
56

7+
/*
8+
* osnoise_context - read, store, write, restore osnoise configs.
9+
*/
10+
struct osnoise_context {
11+
int flags;
12+
int ref;
13+
14+
char *curr_cpus;
15+
char *orig_cpus;
16+
17+
/* 0 as init value */
18+
unsigned long long orig_runtime_us;
19+
unsigned long long runtime_us;
20+
21+
/* 0 as init value */
22+
unsigned long long orig_period_us;
23+
unsigned long long period_us;
24+
25+
/* 0 as init value */
26+
long long orig_timerlat_period_us;
27+
long long timerlat_period_us;
28+
29+
/* 0 as init value */
30+
long long orig_tracing_thresh;
31+
long long tracing_thresh;
32+
33+
/* -1 as init value because 0 is disabled */
34+
long long orig_stop_us;
35+
long long stop_us;
36+
37+
/* -1 as init value because 0 is disabled */
38+
long long orig_stop_total_us;
39+
long long stop_total_us;
40+
41+
/* -1 as init value because 0 is disabled */
42+
long long orig_print_stack;
43+
long long print_stack;
44+
45+
/* -1 as init value because 0 is off */
46+
int orig_opt_irq_disable;
47+
int opt_irq_disable;
48+
49+
/* -1 as init value because 0 is off */
50+
int orig_opt_workload;
51+
int opt_workload;
52+
};
53+
54+
/*
55+
* osnoise_tool - osnoise based tool definition.
56+
*/
57+
struct osnoise_tool {
58+
struct trace_instance trace;
59+
struct osnoise_context *context;
60+
void *data;
61+
void *params;
62+
time_t start_time;
63+
};
64+
665
struct hist_params {
766
char no_irq;
867
char no_thread;
@@ -44,4 +103,12 @@ struct common_params {
44103
int output_divisor;
45104
int pretty_output;
46105
int quiet;
106+
int kernel_workload;
47107
};
108+
109+
int osnoise_set_cpus(struct osnoise_context *context, char *cpus);
110+
void osnoise_restore_cpus(struct osnoise_context *context);
111+
112+
int osnoise_set_workload(struct osnoise_context *context, bool onoff);
113+
114+
int common_apply_config(struct osnoise_tool *tool, struct common_params *params);

tools/tracing/rtla/src/osnoise.c

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,21 +1120,14 @@ osnoise_report_missed_events(struct osnoise_tool *tool)
11201120
}
11211121

11221122
/*
1123-
* osnoise_apply_config - apply common configs to the initialized tool
1123+
* osnoise_apply_config - apply osnoise configs to the initialized tool
11241124
*/
11251125
int
11261126
osnoise_apply_config(struct osnoise_tool *tool, struct osnoise_params *params)
11271127
{
11281128
int retval;
11291129

1130-
if (!params->common.sleep_time)
1131-
params->common.sleep_time = 1;
1132-
1133-
retval = osnoise_set_cpus(tool->context, params->common.cpus ? params->common.cpus : "all");
1134-
if (retval) {
1135-
err_msg("Failed to apply CPUs config\n");
1136-
goto out_err;
1137-
}
1130+
params->common.kernel_workload = true;
11381131

11391132
if (params->runtime || params->period) {
11401133
retval = osnoise_set_runtime_period(tool->context,
@@ -1169,31 +1162,7 @@ osnoise_apply_config(struct osnoise_tool *tool, struct osnoise_params *params)
11691162
goto out_err;
11701163
}
11711164

1172-
if (params->common.hk_cpus) {
1173-
retval = sched_setaffinity(getpid(), sizeof(params->common.hk_cpu_set),
1174-
&params->common.hk_cpu_set);
1175-
if (retval == -1) {
1176-
err_msg("Failed to set rtla to the house keeping CPUs\n");
1177-
goto out_err;
1178-
}
1179-
} else if (params->common.cpus) {
1180-
/*
1181-
* Even if the user do not set a house-keeping CPU, try to
1182-
* move rtla to a CPU set different to the one where the user
1183-
* set the workload to run.
1184-
*
1185-
* No need to check results as this is an automatic attempt.
1186-
*/
1187-
auto_house_keeping(&params->common.monitored_cpus);
1188-
}
1189-
1190-
retval = osnoise_set_workload(tool->context, true);
1191-
if (retval < -1) {
1192-
err_msg("Failed to set OSNOISE_WORKLOAD option\n");
1193-
goto out_err;
1194-
}
1195-
1196-
return 0;
1165+
return common_apply_config(tool, &params->common);
11971166

11981167
out_err:
11991168
return -1;

tools/tracing/rtla/src/osnoise.h

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#pragma once
33

44
#include "common.h"
5-
#include "trace.h"
65

76
enum osnoise_mode {
87
MODE_OSNOISE = 0,
@@ -18,53 +17,6 @@ struct osnoise_params {
1817
enum osnoise_mode mode;
1918
};
2019

21-
/*
22-
* osnoise_context - read, store, write, restore osnoise configs.
23-
*/
24-
struct osnoise_context {
25-
int flags;
26-
int ref;
27-
28-
char *curr_cpus;
29-
char *orig_cpus;
30-
31-
/* 0 as init value */
32-
unsigned long long orig_runtime_us;
33-
unsigned long long runtime_us;
34-
35-
/* 0 as init value */
36-
unsigned long long orig_period_us;
37-
unsigned long long period_us;
38-
39-
/* 0 as init value */
40-
long long orig_timerlat_period_us;
41-
long long timerlat_period_us;
42-
43-
/* 0 as init value */
44-
long long orig_tracing_thresh;
45-
long long tracing_thresh;
46-
47-
/* -1 as init value because 0 is disabled */
48-
long long orig_stop_us;
49-
long long stop_us;
50-
51-
/* -1 as init value because 0 is disabled */
52-
long long orig_stop_total_us;
53-
long long stop_total_us;
54-
55-
/* -1 as init value because 0 is disabled */
56-
long long orig_print_stack;
57-
long long print_stack;
58-
59-
/* -1 as init value because 0 is off */
60-
int orig_opt_irq_disable;
61-
int opt_irq_disable;
62-
63-
/* -1 as init value because 0 is off */
64-
int orig_opt_workload;
65-
int opt_workload;
66-
};
67-
6820
/*
6921
* *_INIT_VALs are also invalid values, they are used to
7022
* communicate errors.
@@ -76,9 +28,6 @@ struct osnoise_context *osnoise_context_alloc(void);
7628
int osnoise_get_context(struct osnoise_context *context);
7729
void osnoise_put_context(struct osnoise_context *context);
7830

79-
int osnoise_set_cpus(struct osnoise_context *context, char *cpus);
80-
void osnoise_restore_cpus(struct osnoise_context *context);
81-
8231
int osnoise_set_runtime_period(struct osnoise_context *context,
8332
unsigned long long runtime,
8433
unsigned long long period);
@@ -105,19 +54,6 @@ int osnoise_set_print_stack(struct osnoise_context *context,
10554
long long print_stack);
10655

10756
int osnoise_set_irq_disable(struct osnoise_context *context, bool onoff);
108-
int osnoise_set_workload(struct osnoise_context *context, bool onoff);
109-
110-
/*
111-
* osnoise_tool - osnoise based tool definition.
112-
*/
113-
struct osnoise_tool {
114-
struct trace_instance trace;
115-
struct osnoise_context *context;
116-
void *data;
117-
void *params;
118-
time_t start_time;
119-
};
120-
12157
void osnoise_destroy_tool(struct osnoise_tool *top);
12258
struct osnoise_tool *osnoise_init_tool(char *tool_name);
12359
struct osnoise_tool *osnoise_init_trace_tool(char *tracer);

tools/tracing/rtla/src/timerlat.c

Lines changed: 4 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,7 @@
2424
int
2525
timerlat_apply_config(struct osnoise_tool *tool, struct timerlat_params *params)
2626
{
27-
int retval, i;
28-
29-
if (!params->common.sleep_time)
30-
params->common.sleep_time = 1;
31-
32-
retval = osnoise_set_cpus(tool->context, params->common.cpus ? params->common.cpus : "all");
33-
if (retval) {
34-
err_msg("Failed to apply CPUs config\n");
35-
goto out_err;
36-
}
37-
38-
if (!params->common.cpus) {
39-
for (i = 0; i < sysconf(_SC_NPROCESSORS_CONF); i++)
40-
CPU_SET(i, &params->common.monitored_cpus);
41-
}
27+
int retval;
4228

4329
if (params->mode != TRACING_MODE_BPF) {
4430
/*
@@ -75,52 +61,23 @@ timerlat_apply_config(struct osnoise_tool *tool, struct timerlat_params *params)
7561
goto out_err;
7662
}
7763

78-
if (params->common.hk_cpus) {
79-
retval = sched_setaffinity(getpid(), sizeof(params->common.hk_cpu_set),
80-
&params->common.hk_cpu_set);
81-
if (retval == -1) {
82-
err_msg("Failed to set rtla to the house keeping CPUs\n");
83-
goto out_err;
84-
}
85-
} else if (params->common.cpus) {
86-
/*
87-
* Even if the user do not set a house-keeping CPU, try to
88-
* move rtla to a CPU set different to the one where the user
89-
* set the workload to run.
90-
*
91-
* No need to check results as this is an automatic attempt.
92-
*/
93-
auto_house_keeping(&params->common.monitored_cpus);
94-
}
95-
9664
/*
9765
* If the user did not specify a type of thread, try user-threads first.
9866
* Fall back to kernel threads otherwise.
9967
*/
100-
if (!params->kernel_workload && !params->user_data) {
68+
if (!params->common.kernel_workload && !params->user_data) {
10169
retval = tracefs_file_exists(NULL, "osnoise/per_cpu/cpu0/timerlat_fd");
10270
if (retval) {
10371
debug_msg("User-space interface detected, setting user-threads\n");
10472
params->user_workload = 1;
10573
params->user_data = 1;
10674
} else {
10775
debug_msg("User-space interface not detected, setting kernel-threads\n");
108-
params->kernel_workload = 1;
76+
params->common.kernel_workload = 1;
10977
}
11078
}
11179

112-
/*
113-
* Set workload according to type of thread if the kernel supports it.
114-
* On kernels without support, user threads will have already failed
115-
* on missing timerlat_fd, and kernel threads do not need it.
116-
*/
117-
retval = osnoise_set_workload(tool->context, params->kernel_workload);
118-
if (retval < -1) {
119-
err_msg("Failed to set OSNOISE_WORKLOAD option\n");
120-
goto out_err;
121-
}
122-
123-
return 0;
80+
return common_apply_config(tool, &params->common);
12481

12582
out_err:
12683
return -1;

tools/tracing/rtla/src/timerlat.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ struct timerlat_params {
2727
int no_aa;
2828
int dump_tasks;
2929
int user_workload;
30-
int kernel_workload;
3130
int user_data;
3231
int deepest_idle_state;
3332
int aa_only;

0 commit comments

Comments
 (0)