Skip to content

Commit 894c29c

Browse files
Daniel Bristot de Oliveirarostedt
authored andcommitted
rtla: Change monitored_cpus from char * to cpu_set_t
Use a cpumask instead of a char *, reducing memory footprint and code. No functional change, and in preparation for auto house-keeping. Link: https://lkml.kernel.org/r/54c46293261d13cb1042d0314486539eeb45fe5d.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 272ced2 commit 894c29c

5 files changed

Lines changed: 24 additions & 87 deletions

File tree

tools/tracing/rtla/src/osnoise_hist.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
struct osnoise_hist_params {
2121
char *cpus;
22-
char *monitored_cpus;
22+
cpu_set_t monitored_cpus;
2323
char *trace_output;
2424
char *cgroup_name;
2525
unsigned long long runtime;
@@ -274,7 +274,7 @@ static void osnoise_hist_header(struct osnoise_tool *tool)
274274
trace_seq_printf(s, "Index");
275275

276276
for (cpu = 0; cpu < data->nr_cpus; cpu++) {
277-
if (params->cpus && !params->monitored_cpus[cpu])
277+
if (params->cpus && !CPU_ISSET(cpu, &params->monitored_cpus))
278278
continue;
279279

280280
if (!data->hist[cpu].count)
@@ -305,7 +305,7 @@ osnoise_print_summary(struct osnoise_hist_params *params,
305305
trace_seq_printf(trace->seq, "count:");
306306

307307
for (cpu = 0; cpu < data->nr_cpus; cpu++) {
308-
if (params->cpus && !params->monitored_cpus[cpu])
308+
if (params->cpus && !CPU_ISSET(cpu, &params->monitored_cpus))
309309
continue;
310310

311311
if (!data->hist[cpu].count)
@@ -319,7 +319,7 @@ osnoise_print_summary(struct osnoise_hist_params *params,
319319
trace_seq_printf(trace->seq, "min: ");
320320

321321
for (cpu = 0; cpu < data->nr_cpus; cpu++) {
322-
if (params->cpus && !params->monitored_cpus[cpu])
322+
if (params->cpus && !CPU_ISSET(cpu, &params->monitored_cpus))
323323
continue;
324324

325325
if (!data->hist[cpu].count)
@@ -334,7 +334,7 @@ osnoise_print_summary(struct osnoise_hist_params *params,
334334
trace_seq_printf(trace->seq, "avg: ");
335335

336336
for (cpu = 0; cpu < data->nr_cpus; cpu++) {
337-
if (params->cpus && !params->monitored_cpus[cpu])
337+
if (params->cpus && !CPU_ISSET(cpu, &params->monitored_cpus))
338338
continue;
339339

340340
if (!data->hist[cpu].count)
@@ -352,7 +352,7 @@ osnoise_print_summary(struct osnoise_hist_params *params,
352352
trace_seq_printf(trace->seq, "max: ");
353353

354354
for (cpu = 0; cpu < data->nr_cpus; cpu++) {
355-
if (params->cpus && !params->monitored_cpus[cpu])
355+
if (params->cpus && !CPU_ISSET(cpu, &params->monitored_cpus))
356356
continue;
357357

358358
if (!data->hist[cpu].count)
@@ -387,7 +387,7 @@ osnoise_print_stats(struct osnoise_hist_params *params, struct osnoise_tool *too
387387
bucket * data->bucket_size);
388388

389389
for (cpu = 0; cpu < data->nr_cpus; cpu++) {
390-
if (params->cpus && !params->monitored_cpus[cpu])
390+
if (params->cpus && !CPU_ISSET(cpu, &params->monitored_cpus))
391391
continue;
392392

393393
if (!data->hist[cpu].count)
@@ -411,7 +411,7 @@ osnoise_print_stats(struct osnoise_hist_params *params, struct osnoise_tool *too
411411
trace_seq_printf(trace->seq, "over: ");
412412

413413
for (cpu = 0; cpu < data->nr_cpus; cpu++) {
414-
if (params->cpus && !params->monitored_cpus[cpu])
414+
if (params->cpus && !CPU_ISSET(cpu, &params->monitored_cpus))
415415
continue;
416416

417417
if (!data->hist[cpu].count)
@@ -559,7 +559,7 @@ static struct osnoise_hist_params
559559
osnoise_hist_usage("Bucket size needs to be > 0 and <= 1000000\n");
560560
break;
561561
case 'c':
562-
retval = parse_cpu_list(optarg, &params->monitored_cpus);
562+
retval = parse_cpu_set(optarg, &params->monitored_cpus);
563563
if (retval)
564564
osnoise_hist_usage("\nInvalid -c cpu list\n");
565565
params->cpus = optarg;

tools/tracing/rtla/src/osnoise_top.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ enum osnoise_mode {
2626
*/
2727
struct osnoise_top_params {
2828
char *cpus;
29-
char *monitored_cpus;
29+
cpu_set_t monitored_cpus;
3030
char *trace_output;
3131
char *cgroup_name;
3232
unsigned long long runtime;
@@ -263,7 +263,7 @@ osnoise_print_stats(struct osnoise_top_params *params, struct osnoise_tool *top)
263263
osnoise_top_header(top);
264264

265265
for (i = 0; i < nr_cpus; i++) {
266-
if (params->cpus && !params->monitored_cpus[i])
266+
if (params->cpus && !CPU_ISSET(i, &params->monitored_cpus))
267267
continue;
268268
osnoise_top_print(top, i);
269269
}
@@ -397,7 +397,7 @@ struct osnoise_top_params *osnoise_top_parse_args(int argc, char **argv)
397397

398398
break;
399399
case 'c':
400-
retval = parse_cpu_list(optarg, &params->monitored_cpus);
400+
retval = parse_cpu_set(optarg, &params->monitored_cpus);
401401
if (retval)
402402
osnoise_top_usage(params, "\nInvalid -c cpu list\n");
403403
params->cpus = optarg;

tools/tracing/rtla/src/timerlat_hist.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
struct timerlat_hist_params {
2121
char *cpus;
22-
char *monitored_cpus;
22+
cpu_set_t monitored_cpus;
2323
char *trace_output;
2424
char *cgroup_name;
2525
unsigned long long runtime;
@@ -227,7 +227,7 @@ static void timerlat_hist_header(struct osnoise_tool *tool)
227227
trace_seq_printf(s, "Index");
228228

229229
for (cpu = 0; cpu < data->nr_cpus; cpu++) {
230-
if (params->cpus && !params->monitored_cpus[cpu])
230+
if (params->cpus && !CPU_ISSET(cpu, &params->monitored_cpus))
231231
continue;
232232

233233
if (!data->hist[cpu].irq_count && !data->hist[cpu].thread_count)
@@ -263,7 +263,7 @@ timerlat_print_summary(struct timerlat_hist_params *params,
263263
trace_seq_printf(trace->seq, "count:");
264264

265265
for (cpu = 0; cpu < data->nr_cpus; cpu++) {
266-
if (params->cpus && !params->monitored_cpus[cpu])
266+
if (params->cpus && !CPU_ISSET(cpu, &params->monitored_cpus))
267267
continue;
268268

269269
if (!data->hist[cpu].irq_count && !data->hist[cpu].thread_count)
@@ -283,7 +283,7 @@ timerlat_print_summary(struct timerlat_hist_params *params,
283283
trace_seq_printf(trace->seq, "min: ");
284284

285285
for (cpu = 0; cpu < data->nr_cpus; cpu++) {
286-
if (params->cpus && !params->monitored_cpus[cpu])
286+
if (params->cpus && !CPU_ISSET(cpu, &params->monitored_cpus))
287287
continue;
288288

289289
if (!data->hist[cpu].irq_count && !data->hist[cpu].thread_count)
@@ -303,7 +303,7 @@ timerlat_print_summary(struct timerlat_hist_params *params,
303303
trace_seq_printf(trace->seq, "avg: ");
304304

305305
for (cpu = 0; cpu < data->nr_cpus; cpu++) {
306-
if (params->cpus && !params->monitored_cpus[cpu])
306+
if (params->cpus && !CPU_ISSET(cpu, &params->monitored_cpus))
307307
continue;
308308

309309
if (!data->hist[cpu].irq_count && !data->hist[cpu].thread_count)
@@ -331,7 +331,7 @@ timerlat_print_summary(struct timerlat_hist_params *params,
331331
trace_seq_printf(trace->seq, "max: ");
332332

333333
for (cpu = 0; cpu < data->nr_cpus; cpu++) {
334-
if (params->cpus && !params->monitored_cpus[cpu])
334+
if (params->cpus && !CPU_ISSET(cpu, &params->monitored_cpus))
335335
continue;
336336

337337
if (!data->hist[cpu].irq_count && !data->hist[cpu].thread_count)
@@ -371,7 +371,7 @@ timerlat_print_stats(struct timerlat_hist_params *params, struct osnoise_tool *t
371371
bucket * data->bucket_size);
372372

373373
for (cpu = 0; cpu < data->nr_cpus; cpu++) {
374-
if (params->cpus && !params->monitored_cpus[cpu])
374+
if (params->cpus && !CPU_ISSET(cpu, &params->monitored_cpus))
375375
continue;
376376

377377
if (!data->hist[cpu].irq_count && !data->hist[cpu].thread_count)
@@ -405,7 +405,7 @@ timerlat_print_stats(struct timerlat_hist_params *params, struct osnoise_tool *t
405405
trace_seq_printf(trace->seq, "over: ");
406406

407407
for (cpu = 0; cpu < data->nr_cpus; cpu++) {
408-
if (params->cpus && !params->monitored_cpus[cpu])
408+
if (params->cpus && !CPU_ISSET(cpu, &params->monitored_cpus))
409409
continue;
410410

411411
if (!data->hist[cpu].irq_count && !data->hist[cpu].thread_count)
@@ -565,7 +565,7 @@ static struct timerlat_hist_params
565565

566566
break;
567567
case 'c':
568-
retval = parse_cpu_list(optarg, &params->monitored_cpus);
568+
retval = parse_cpu_set(optarg, &params->monitored_cpus);
569569
if (retval)
570570
timerlat_hist_usage("\nInvalid -c cpu list\n");
571571
params->cpus = optarg;

tools/tracing/rtla/src/timerlat_top.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
struct timerlat_top_params {
2323
char *cpus;
24-
char *monitored_cpus;
24+
cpu_set_t monitored_cpus;
2525
char *trace_output;
2626
char *cgroup_name;
2727
unsigned long long runtime;
@@ -271,7 +271,7 @@ timerlat_print_stats(struct timerlat_top_params *params, struct osnoise_tool *to
271271
timerlat_top_header(top);
272272

273273
for (i = 0; i < nr_cpus; i++) {
274-
if (params->cpus && !params->monitored_cpus[i])
274+
if (params->cpus && !CPU_ISSET(i, &params->monitored_cpus))
275275
continue;
276276
timerlat_top_print(top, i);
277277
}
@@ -422,7 +422,7 @@ static struct timerlat_top_params
422422
params->aa_only = 1;
423423
break;
424424
case 'c':
425-
retval = parse_cpu_list(optarg, &params->monitored_cpus);
425+
retval = parse_cpu_set(optarg, &params->monitored_cpus);
426426
if (retval)
427427
timerlat_top_usage("\nInvalid -c cpu list\n");
428428
params->cpus = optarg;

tools/tracing/rtla/src/utils.c

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -88,69 +88,6 @@ void get_duration(time_t start_time, char *output, int output_size)
8888
tm_info->tm_sec);
8989
}
9090

91-
/*
92-
* parse_cpu_list - parse a cpu_list filling a char vector with cpus set
93-
*
94-
* Receives a cpu list, like 1-3,5 (cpus 1, 2, 3, 5), and then set the char
95-
* in the monitored_cpus.
96-
*
97-
* XXX: convert to a bitmask.
98-
*/
99-
int parse_cpu_list(char *cpu_list, char **monitored_cpus)
100-
{
101-
char *mon_cpus;
102-
const char *p;
103-
int end_cpu;
104-
int nr_cpus;
105-
int cpu;
106-
int i;
107-
108-
nr_cpus = sysconf(_SC_NPROCESSORS_CONF);
109-
110-
mon_cpus = calloc(nr_cpus, sizeof(char));
111-
if (!mon_cpus)
112-
goto err;
113-
114-
for (p = cpu_list; *p; ) {
115-
cpu = atoi(p);
116-
if (cpu < 0 || (!cpu && *p != '0') || cpu >= nr_cpus)
117-
goto err;
118-
119-
while (isdigit(*p))
120-
p++;
121-
if (*p == '-') {
122-
p++;
123-
end_cpu = atoi(p);
124-
if (end_cpu < cpu || (!end_cpu && *p != '0') || end_cpu >= nr_cpus)
125-
goto err;
126-
while (isdigit(*p))
127-
p++;
128-
} else
129-
end_cpu = cpu;
130-
131-
if (cpu == end_cpu) {
132-
debug_msg("cpu_list: adding cpu %d\n", cpu);
133-
mon_cpus[cpu] = 1;
134-
} else {
135-
for (i = cpu; i <= end_cpu; i++) {
136-
debug_msg("cpu_list: adding cpu %d\n", i);
137-
mon_cpus[i] = 1;
138-
}
139-
}
140-
141-
if (*p == ',')
142-
p++;
143-
}
144-
145-
*monitored_cpus = mon_cpus;
146-
147-
return 0;
148-
149-
err:
150-
debug_msg("Error parsing the cpu list %s", cpu_list);
151-
return 1;
152-
}
153-
15491
/*
15592
* parse_cpu_set - parse a cpu_list filling cpu_set_t argument
15693
*

0 commit comments

Comments
 (0)