Skip to content

Commit 5742bf6

Browse files
crwood-rhrostedt
authored andcommitted
tools/rtla: Move top/hist params into common struct
The hist members were very similar between timerlat and top, so just use one common hist struct. output_divisor, quiet, and pretty printing are pretty generic concepts that can go in the main struct even if not every specific tool (currently) uses them. 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 3448238 commit 5742bf6

File tree

8 files changed

+152
-163
lines changed

8 files changed

+152
-163
lines changed

tools/tracing/rtla/src/common.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@
33

44
#include "utils.h"
55

6+
struct hist_params {
7+
char no_irq;
8+
char no_thread;
9+
char no_header;
10+
char no_summary;
11+
char no_index;
12+
char with_zeros;
13+
int bucket_size;
14+
int entries;
15+
};
16+
617
/*
718
* common_params - Parameters shared between timerlat_params and osnoise_params
819
*/
@@ -27,4 +38,10 @@ struct common_params {
2738
char *cgroup_name;
2839
int hk_cpus;
2940
cpu_set_t hk_cpu_set;
41+
42+
/* Other parameters */
43+
struct hist_params hist;
44+
int output_divisor;
45+
int pretty_output;
46+
int quiet;
3047
};

tools/tracing/rtla/src/osnoise.h

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,7 @@ struct osnoise_params {
1515
unsigned long long runtime;
1616
unsigned long long period;
1717
long long threshold;
18-
union {
19-
struct {
20-
/* top only */
21-
int quiet;
22-
int pretty_output;
23-
enum osnoise_mode mode;
24-
};
25-
struct {
26-
/* hist only */
27-
int output_divisor;
28-
char no_header;
29-
char no_summary;
30-
char no_index;
31-
char with_zeros;
32-
int bucket_size;
33-
int entries;
34-
};
35-
};
18+
enum osnoise_mode mode;
3619
};
3720

3821
/*

tools/tracing/rtla/src/osnoise_hist.c

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ static void osnoise_hist_update_multiple(struct osnoise_tool *tool, int cpu,
102102
int bucket;
103103
int *hist;
104104

105-
if (params->output_divisor)
106-
duration = duration / params->output_divisor;
105+
if (params->common.output_divisor)
106+
duration = duration / params->common.output_divisor;
107107

108108
bucket = duration / data->bucket_size;
109109

@@ -146,7 +146,7 @@ static int osnoise_init_trace_hist(struct osnoise_tool *tool)
146146
/*
147147
* Set the size of the bucket.
148148
*/
149-
bucket_size = params->output_divisor * params->bucket_size;
149+
bucket_size = params->common.output_divisor * params->common.hist.bucket_size;
150150
snprintf(buff, sizeof(buff), "duration.buckets=%d", bucket_size);
151151

152152
data->trace_hist = tracefs_hist_alloc(tool->trace.tep, "osnoise", "sample_threshold",
@@ -228,18 +228,18 @@ static void osnoise_hist_header(struct osnoise_tool *tool)
228228
char duration[26];
229229
int cpu;
230230

231-
if (params->no_header)
231+
if (params->common.hist.no_header)
232232
return;
233233

234234
get_duration(tool->start_time, duration, sizeof(duration));
235235
trace_seq_printf(s, "# RTLA osnoise histogram\n");
236236
trace_seq_printf(s, "# Time unit is %s (%s)\n",
237-
params->output_divisor == 1 ? "nanoseconds" : "microseconds",
238-
params->output_divisor == 1 ? "ns" : "us");
237+
params->common.output_divisor == 1 ? "nanoseconds" : "microseconds",
238+
params->common.output_divisor == 1 ? "ns" : "us");
239239

240240
trace_seq_printf(s, "# Duration: %s\n", duration);
241241

242-
if (!params->no_index)
242+
if (!params->common.hist.no_index)
243243
trace_seq_printf(s, "Index");
244244

245245
for (cpu = 0; cpu < data->nr_cpus; cpu++) {
@@ -267,10 +267,10 @@ osnoise_print_summary(struct osnoise_params *params,
267267
{
268268
int cpu;
269269

270-
if (params->no_summary)
270+
if (params->common.hist.no_summary)
271271
return;
272272

273-
if (!params->no_index)
273+
if (!params->common.hist.no_index)
274274
trace_seq_printf(trace->seq, "count:");
275275

276276
for (cpu = 0; cpu < data->nr_cpus; cpu++) {
@@ -284,7 +284,7 @@ osnoise_print_summary(struct osnoise_params *params,
284284
}
285285
trace_seq_printf(trace->seq, "\n");
286286

287-
if (!params->no_index)
287+
if (!params->common.hist.no_index)
288288
trace_seq_printf(trace->seq, "min: ");
289289

290290
for (cpu = 0; cpu < data->nr_cpus; cpu++) {
@@ -299,7 +299,7 @@ osnoise_print_summary(struct osnoise_params *params,
299299
}
300300
trace_seq_printf(trace->seq, "\n");
301301

302-
if (!params->no_index)
302+
if (!params->common.hist.no_index)
303303
trace_seq_printf(trace->seq, "avg: ");
304304

305305
for (cpu = 0; cpu < data->nr_cpus; cpu++) {
@@ -317,7 +317,7 @@ osnoise_print_summary(struct osnoise_params *params,
317317
}
318318
trace_seq_printf(trace->seq, "\n");
319319

320-
if (!params->no_index)
320+
if (!params->common.hist.no_index)
321321
trace_seq_printf(trace->seq, "max: ");
322322

323323
for (cpu = 0; cpu < data->nr_cpus; cpu++) {
@@ -352,7 +352,7 @@ osnoise_print_stats(struct osnoise_params *params, struct osnoise_tool *tool)
352352
for (bucket = 0; bucket < data->entries; bucket++) {
353353
total = 0;
354354

355-
if (!params->no_index)
355+
if (!params->common.hist.no_index)
356356
trace_seq_printf(trace->seq, "%-6d",
357357
bucket * data->bucket_size);
358358

@@ -367,7 +367,7 @@ osnoise_print_stats(struct osnoise_params *params, struct osnoise_tool *tool)
367367
trace_seq_printf(trace->seq, "%9d ", data->hist[cpu].samples[bucket]);
368368
}
369369

370-
if (total == 0 && !params->with_zeros) {
370+
if (total == 0 && !params->common.hist.with_zeros) {
371371
trace_seq_reset(trace->seq);
372372
continue;
373373
}
@@ -391,7 +391,7 @@ osnoise_print_stats(struct osnoise_params *params, struct osnoise_tool *tool)
391391
return;
392392
}
393393

394-
if (!params->no_index)
394+
if (!params->common.hist.no_index)
395395
trace_seq_printf(trace->seq, "over: ");
396396

397397
for (cpu = 0; cpu < data->nr_cpus; cpu++) {
@@ -490,9 +490,9 @@ static struct osnoise_params
490490
exit(1);
491491

492492
/* display data in microseconds */
493-
params->output_divisor = 1000;
494-
params->bucket_size = 1;
495-
params->entries = 256;
493+
params->common.output_divisor = 1000;
494+
params->common.hist.bucket_size = 1;
495+
params->common.hist.entries = 256;
496496

497497
while (1) {
498498
static struct option long_options[] = {
@@ -547,8 +547,9 @@ static struct osnoise_params
547547

548548
break;
549549
case 'b':
550-
params->bucket_size = get_llong_from_str(optarg);
551-
if ((params->bucket_size == 0) || (params->bucket_size >= 1000000))
550+
params->common.hist.bucket_size = get_llong_from_str(optarg);
551+
if (params->common.hist.bucket_size == 0 ||
552+
params->common.hist.bucket_size >= 1000000)
552553
osnoise_hist_usage("Bucket size needs to be > 0 and <= 1000000\n");
553554
break;
554555
case 'c':
@@ -588,8 +589,9 @@ static struct osnoise_params
588589
params->common.events = tevent;
589590
break;
590591
case 'E':
591-
params->entries = get_llong_from_str(optarg);
592-
if ((params->entries < 10) || (params->entries > 9999999))
592+
params->common.hist.entries = get_llong_from_str(optarg);
593+
if (params->common.hist.entries < 10 ||
594+
params->common.hist.entries > 9999999)
593595
osnoise_hist_usage("Entries must be > 10 and < 9999999\n");
594596
break;
595597
case 'h':
@@ -641,16 +643,16 @@ static struct osnoise_params
641643
params->trace_output = "osnoise_trace.txt";
642644
break;
643645
case '0': /* no header */
644-
params->no_header = 1;
646+
params->common.hist.no_header = 1;
645647
break;
646648
case '1': /* no summary */
647-
params->no_summary = 1;
649+
params->common.hist.no_summary = 1;
648650
break;
649651
case '2': /* no index */
650-
params->no_index = 1;
652+
params->common.hist.no_index = 1;
651653
break;
652654
case '3': /* with zeros */
653-
params->with_zeros = 1;
655+
params->common.hist.with_zeros = 1;
654656
break;
655657
case '4': /* trigger */
656658
if (params->common.events) {
@@ -690,7 +692,7 @@ static struct osnoise_params
690692
exit(EXIT_FAILURE);
691693
}
692694

693-
if (params->no_index && !params->with_zeros)
695+
if (params->common.hist.no_index && !params->common.hist.with_zeros)
694696
osnoise_hist_usage("no-index set and with-zeros not set - it does not make sense");
695697

696698
return params;
@@ -729,7 +731,8 @@ static struct osnoise_tool
729731
if (!tool)
730732
return NULL;
731733

732-
tool->data = osnoise_alloc_histogram(nr_cpus, params->entries, params->bucket_size);
734+
tool->data = osnoise_alloc_histogram(nr_cpus, params->common.hist.entries,
735+
params->common.hist.bucket_size);
733736
if (!tool->data)
734737
goto out_err;
735738

tools/tracing/rtla/src/osnoise_top.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,12 @@ static void osnoise_top_header(struct osnoise_tool *top)
125125
{
126126
struct osnoise_params *params = top->params;
127127
struct trace_seq *s = top->trace.seq;
128+
bool pretty = params->common.pretty_output;
128129
char duration[26];
129130

130131
get_duration(top->start_time, duration, sizeof(duration));
131132

132-
if (params->pretty_output)
133+
if (pretty)
133134
trace_seq_printf(s, "\033[2;37;40m");
134135

135136
trace_seq_printf(s, " ");
@@ -143,13 +144,13 @@ static void osnoise_top_header(struct osnoise_tool *top)
143144

144145
trace_seq_printf(s, " ");
145146

146-
if (params->pretty_output)
147+
if (pretty)
147148
trace_seq_printf(s, "\033[0;0;0m");
148149
trace_seq_printf(s, "\n");
149150

150151
trace_seq_printf(s, "duration: %9s | time is in us\n", duration);
151152

152-
if (params->pretty_output)
153+
if (pretty)
153154
trace_seq_printf(s, "\033[2;30;47m");
154155

155156
trace_seq_printf(s, "CPU Period Runtime ");
@@ -164,7 +165,7 @@ static void osnoise_top_header(struct osnoise_tool *top)
164165
trace_seq_printf(s, " IRQ Softirq Thread");
165166

166167
eol:
167-
if (params->pretty_output)
168+
if (pretty)
168169
trace_seq_printf(s, "\033[0;0;0m");
169170
trace_seq_printf(s, "\n");
170171
}
@@ -232,7 +233,7 @@ osnoise_print_stats(struct osnoise_params *params, struct osnoise_tool *top)
232233
if (nr_cpus == -1)
233234
nr_cpus = sysconf(_SC_NPROCESSORS_CONF);
234235

235-
if (!params->quiet)
236+
if (!params->common.quiet)
236237
clear_terminal(trace->seq);
237238

238239
osnoise_top_header(top);
@@ -446,7 +447,7 @@ struct osnoise_params *osnoise_top_parse_args(int argc, char **argv)
446447
params->common.set_sched = 1;
447448
break;
448449
case 'q':
449-
params->quiet = 1;
450+
params->common.quiet = 1;
450451
break;
451452
case 'r':
452453
params->runtime = get_llong_from_str(optarg);
@@ -534,8 +535,8 @@ osnoise_top_apply_config(struct osnoise_tool *tool, struct osnoise_params *param
534535
}
535536
}
536537

537-
if (isatty(STDOUT_FILENO) && !params->quiet)
538-
params->pretty_output = 1;
538+
if (isatty(STDOUT_FILENO) && !params->common.quiet)
539+
params->common.pretty_output = 1;
539540

540541
return 0;
541542

@@ -705,7 +706,7 @@ int osnoise_top_main(int argc, char **argv)
705706
goto out_top;
706707
}
707708

708-
if (!params->quiet)
709+
if (!params->common.quiet)
709710
osnoise_print_stats(params, tool);
710711

711712
if (osnoise_trace_is_off(tool, record))

tools/tracing/rtla/src/timerlat.h

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,38 +23,18 @@ struct timerlat_params {
2323
struct common_params common;
2424
long long timerlat_period_us;
2525
long long print_stack;
26-
int output_divisor;
2726
int dma_latency;
2827
int no_aa;
2928
int dump_tasks;
3029
int user_workload;
3130
int kernel_workload;
3231
int user_data;
3332
int deepest_idle_state;
33+
int aa_only;
3434
enum timerlat_tracing_mode mode;
3535

3636
struct actions threshold_actions;
3737
struct actions end_actions;
38-
39-
union {
40-
struct {
41-
/* top only */
42-
int quiet;
43-
int aa_only;
44-
int pretty_output;
45-
};
46-
struct {
47-
/* hist only */
48-
char no_irq;
49-
char no_thread;
50-
char no_header;
51-
char no_summary;
52-
char no_index;
53-
char with_zeros;
54-
int bucket_size;
55-
int entries;
56-
};
57-
};
5838
};
5939

6040
int timerlat_apply_config(struct osnoise_tool *tool, struct timerlat_params *params);

tools/tracing/rtla/src/timerlat_bpf.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,20 @@ int timerlat_bpf_init(struct timerlat_params *params)
2121
return 1;
2222

2323
/* Pass common options */
24-
bpf->rodata->output_divisor = params->output_divisor;
25-
bpf->rodata->entries = params->entries;
24+
bpf->rodata->output_divisor = params->common.output_divisor;
25+
bpf->rodata->entries = params->common.hist.entries;
2626
bpf->rodata->irq_threshold = params->common.stop_us;
2727
bpf->rodata->thread_threshold = params->common.stop_total_us;
2828
bpf->rodata->aa_only = params->aa_only;
2929

30-
if (params->entries != 0) {
30+
if (params->common.hist.entries != 0) {
3131
/* Pass histogram options */
32-
bpf->rodata->bucket_size = params->bucket_size;
32+
bpf->rodata->bucket_size = params->common.hist.bucket_size;
3333

3434
/* Set histogram array sizes */
35-
bpf_map__set_max_entries(bpf->maps.hist_irq, params->entries);
36-
bpf_map__set_max_entries(bpf->maps.hist_thread, params->entries);
37-
bpf_map__set_max_entries(bpf->maps.hist_user, params->entries);
35+
bpf_map__set_max_entries(bpf->maps.hist_irq, params->common.hist.entries);
36+
bpf_map__set_max_entries(bpf->maps.hist_thread, params->common.hist.entries);
37+
bpf_map__set_max_entries(bpf->maps.hist_user, params->common.hist.entries);
3838
} else {
3939
/* No entries, disable histogram */
4040
bpf_map__set_autocreate(bpf->maps.hist_irq, false);

0 commit comments

Comments
 (0)