Skip to content

Commit 8c25c44

Browse files
committed
Merge tag 'perf-tools-fixes-for-v5.14-2021-07-18' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux
Pull perf tools fixes from Arnaldo Carvalho de Melo: - Skip invalid hybrid PMU on hybrid systems when the atom (little) CPUs are offlined. - Fix 'perf test' problems related to the recently added hybrid (BIG/little) code. - Split ARM's coresight (hw tracing) decode by aux records to avoid fatal decoding errors. - Fix add event failure in 'perf probe' when running 32-bit perf in a 64-bit kernel. - Fix 'perf sched record' failure when CONFIG_SCHEDSTATS is not set. - Fix memory and refcount leaks detected by ASAn when running 'perf test', should be clean of warnings now. - Remove broken definition of __LITTLE_ENDIAN from tools' linux/kconfig.h, which was breaking the build in some systems. - Cast PTHREAD_STACK_MIN to int as it may turn into 'long sysconf(__SC_THREAD_STACK_MIN_VALUE), breaking the build in some systems. - Fix libperf build error with LIBPFM4=1. - Sync UAPI files changed by the memfd_secret new syscall. * tag 'perf-tools-fixes-for-v5.14-2021-07-18' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux: (35 commits) perf sched: Fix record failure when CONFIG_SCHEDSTATS is not set perf probe: Fix add event failure when running 32-bit perf in a 64-bit kernel perf data: Close all files in close_dir() perf probe-file: Delete namelist in del_events() on the error path perf test bpf: Free obj_buf perf trace: Free strings in trace__parse_events_option() perf trace: Free syscall tp fields in evsel->priv perf trace: Free syscall->arg_fmt perf trace: Free malloc'd trace fields on exit perf lzma: Close lzma stream on exit perf script: Fix memory 'threads' and 'cpus' leaks on exit perf script: Release zstd data perf session: Cleanup trace_event perf inject: Close inject.output on exit perf report: Free generated help strings for sort option perf env: Fix memory leak of cpu_pmu_caps perf test maps__merge_in: Fix memory leak of maps perf dso: Fix memory leak in dso__new_map() perf test event_update: Fix memory leak of unit perf test event_update: Fix memory leak of evlist ...
2 parents f0eb870 + b0f0085 commit 8c25c44

36 files changed

+391
-98
lines changed

tools/arch/arm64/include/uapi/asm/unistd.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@
2020
#define __ARCH_WANT_SET_GET_RLIMIT
2121
#define __ARCH_WANT_TIME32_SYSCALLS
2222
#define __ARCH_WANT_SYS_CLONE3
23+
#define __ARCH_WANT_MEMFD_SECRET
2324

2425
#include <asm-generic/unistd.h>

tools/include/linux/kconfig.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@
44

55
/* CONFIG_CC_VERSION_TEXT (Do not delete this comment. See help in Kconfig) */
66

7-
#ifdef CONFIG_CPU_BIG_ENDIAN
8-
#define __BIG_ENDIAN 4321
9-
#else
10-
#define __LITTLE_ENDIAN 1234
11-
#endif
12-
137
#define __ARG_PLACEHOLDER_1 0,
148
#define __take_second_arg(__ignored, val, ...) val
159

tools/include/uapi/asm-generic/unistd.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -873,8 +873,13 @@ __SYSCALL(__NR_landlock_add_rule, sys_landlock_add_rule)
873873
#define __NR_landlock_restrict_self 446
874874
__SYSCALL(__NR_landlock_restrict_self, sys_landlock_restrict_self)
875875

876+
#ifdef __ARCH_WANT_MEMFD_SECRET
877+
#define __NR_memfd_secret 447
878+
__SYSCALL(__NR_memfd_secret, sys_memfd_secret)
879+
#endif
880+
876881
#undef __NR_syscalls
877-
#define __NR_syscalls 447
882+
#define __NR_syscalls 448
878883

879884
/*
880885
* 32 bit systems traditionally used different

tools/perf/arch/x86/entry/syscalls/syscall_64.tbl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@
368368
444 common landlock_create_ruleset sys_landlock_create_ruleset
369369
445 common landlock_add_rule sys_landlock_add_rule
370370
446 common landlock_restrict_self sys_landlock_restrict_self
371+
447 common memfd_secret sys_memfd_secret
371372

372373
#
373374
# Due to a historical design error, certain syscalls are numbered differently

tools/perf/builtin-inject.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -361,9 +361,10 @@ static struct dso *findnew_dso(int pid, int tid, const char *filename,
361361
dso = machine__findnew_dso_id(machine, filename, id);
362362
}
363363

364-
if (dso)
364+
if (dso) {
365+
nsinfo__put(dso->nsinfo);
365366
dso->nsinfo = nsi;
366-
else
367+
} else
367368
nsinfo__put(nsi);
368369

369370
thread__put(thread);
@@ -992,8 +993,10 @@ int cmd_inject(int argc, const char **argv)
992993

993994
data.path = inject.input_name;
994995
inject.session = perf_session__new(&data, inject.output.is_pipe, &inject.tool);
995-
if (IS_ERR(inject.session))
996-
return PTR_ERR(inject.session);
996+
if (IS_ERR(inject.session)) {
997+
ret = PTR_ERR(inject.session);
998+
goto out_close_output;
999+
}
9971000

9981001
if (zstd_init(&(inject.session->zstd_data), 0) < 0)
9991002
pr_warning("Decompression initialization failed.\n");
@@ -1035,6 +1038,8 @@ int cmd_inject(int argc, const char **argv)
10351038
out_delete:
10361039
zstd_fini(&(inject.session->zstd_data));
10371040
perf_session__delete(inject.session);
1041+
out_close_output:
1042+
perf_data__close(&inject.output);
10381043
free(inject.itrace_synth_opts.vm_tm_corr_args);
10391044
return ret;
10401045
}

tools/perf/builtin-report.c

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,6 +1175,8 @@ int cmd_report(int argc, const char **argv)
11751175
.annotation_opts = annotation__default_options,
11761176
.skip_empty = true,
11771177
};
1178+
char *sort_order_help = sort_help("sort by key(s):");
1179+
char *field_order_help = sort_help("output field(s): overhead period sample ");
11781180
const struct option options[] = {
11791181
OPT_STRING('i', "input", &input_name, "file",
11801182
"input file name"),
@@ -1209,9 +1211,9 @@ int cmd_report(int argc, const char **argv)
12091211
OPT_BOOLEAN(0, "header-only", &report.header_only,
12101212
"Show only data header."),
12111213
OPT_STRING('s', "sort", &sort_order, "key[,key2...]",
1212-
sort_help("sort by key(s):")),
1214+
sort_order_help),
12131215
OPT_STRING('F', "fields", &field_order, "key[,keys...]",
1214-
sort_help("output field(s): overhead period sample ")),
1216+
field_order_help),
12151217
OPT_BOOLEAN(0, "show-cpu-utilization", &symbol_conf.show_cpu_utilization,
12161218
"Show sample percentage for different cpu modes"),
12171219
OPT_BOOLEAN_FLAG(0, "showcpuutilization", &symbol_conf.show_cpu_utilization,
@@ -1344,11 +1346,11 @@ int cmd_report(int argc, const char **argv)
13441346
char sort_tmp[128];
13451347

13461348
if (ret < 0)
1347-
return ret;
1349+
goto exit;
13481350

13491351
ret = perf_config(report__config, &report);
13501352
if (ret)
1351-
return ret;
1353+
goto exit;
13521354

13531355
argc = parse_options(argc, argv, options, report_usage, 0);
13541356
if (argc) {
@@ -1362,8 +1364,10 @@ int cmd_report(int argc, const char **argv)
13621364
report.symbol_filter_str = argv[0];
13631365
}
13641366

1365-
if (annotate_check_args(&report.annotation_opts) < 0)
1366-
return -EINVAL;
1367+
if (annotate_check_args(&report.annotation_opts) < 0) {
1368+
ret = -EINVAL;
1369+
goto exit;
1370+
}
13671371

13681372
if (report.mmaps_mode)
13691373
report.tasks_mode = true;
@@ -1377,12 +1381,14 @@ int cmd_report(int argc, const char **argv)
13771381
if (symbol_conf.vmlinux_name &&
13781382
access(symbol_conf.vmlinux_name, R_OK)) {
13791383
pr_err("Invalid file: %s\n", symbol_conf.vmlinux_name);
1380-
return -EINVAL;
1384+
ret = -EINVAL;
1385+
goto exit;
13811386
}
13821387
if (symbol_conf.kallsyms_name &&
13831388
access(symbol_conf.kallsyms_name, R_OK)) {
13841389
pr_err("Invalid file: %s\n", symbol_conf.kallsyms_name);
1385-
return -EINVAL;
1390+
ret = -EINVAL;
1391+
goto exit;
13861392
}
13871393

13881394
if (report.inverted_callchain)
@@ -1406,12 +1412,14 @@ int cmd_report(int argc, const char **argv)
14061412

14071413
repeat:
14081414
session = perf_session__new(&data, false, &report.tool);
1409-
if (IS_ERR(session))
1410-
return PTR_ERR(session);
1415+
if (IS_ERR(session)) {
1416+
ret = PTR_ERR(session);
1417+
goto exit;
1418+
}
14111419

14121420
ret = evswitch__init(&report.evswitch, session->evlist, stderr);
14131421
if (ret)
1414-
return ret;
1422+
goto exit;
14151423

14161424
if (zstd_init(&(session->zstd_data), 0) < 0)
14171425
pr_warning("Decompression initialization failed. Reported data may be incomplete.\n");
@@ -1646,5 +1654,8 @@ int cmd_report(int argc, const char **argv)
16461654

16471655
zstd_fini(&(session->zstd_data));
16481656
perf_session__delete(session);
1657+
exit:
1658+
free(sort_order_help);
1659+
free(field_order_help);
16491660
return ret;
16501661
}

tools/perf/builtin-sched.c

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ static void create_tasks(struct perf_sched *sched)
670670
err = pthread_attr_init(&attr);
671671
BUG_ON(err);
672672
err = pthread_attr_setstacksize(&attr,
673-
(size_t) max(16 * 1024, PTHREAD_STACK_MIN));
673+
(size_t) max(16 * 1024, (int)PTHREAD_STACK_MIN));
674674
BUG_ON(err);
675675
err = pthread_mutex_lock(&sched->start_work_mutex);
676676
BUG_ON(err);
@@ -3335,6 +3335,16 @@ static void setup_sorting(struct perf_sched *sched, const struct option *options
33353335
sort_dimension__add("pid", &sched->cmp_pid);
33363336
}
33373337

3338+
static bool schedstat_events_exposed(void)
3339+
{
3340+
/*
3341+
* Select "sched:sched_stat_wait" event to check
3342+
* whether schedstat tracepoints are exposed.
3343+
*/
3344+
return IS_ERR(trace_event__tp_format("sched", "sched_stat_wait")) ?
3345+
false : true;
3346+
}
3347+
33383348
static int __cmd_record(int argc, const char **argv)
33393349
{
33403350
unsigned int rec_argc, i, j;
@@ -3346,21 +3356,33 @@ static int __cmd_record(int argc, const char **argv)
33463356
"-m", "1024",
33473357
"-c", "1",
33483358
"-e", "sched:sched_switch",
3349-
"-e", "sched:sched_stat_wait",
3350-
"-e", "sched:sched_stat_sleep",
3351-
"-e", "sched:sched_stat_iowait",
33523359
"-e", "sched:sched_stat_runtime",
33533360
"-e", "sched:sched_process_fork",
33543361
"-e", "sched:sched_wakeup_new",
33553362
"-e", "sched:sched_migrate_task",
33563363
};
3364+
3365+
/*
3366+
* The tracepoints trace_sched_stat_{wait, sleep, iowait}
3367+
* are not exposed to user if CONFIG_SCHEDSTATS is not set,
3368+
* to prevent "perf sched record" execution failure, determine
3369+
* whether to record schedstat events according to actual situation.
3370+
*/
3371+
const char * const schedstat_args[] = {
3372+
"-e", "sched:sched_stat_wait",
3373+
"-e", "sched:sched_stat_sleep",
3374+
"-e", "sched:sched_stat_iowait",
3375+
};
3376+
unsigned int schedstat_argc = schedstat_events_exposed() ?
3377+
ARRAY_SIZE(schedstat_args) : 0;
3378+
33573379
struct tep_event *waking_event;
33583380

33593381
/*
33603382
* +2 for either "-e", "sched:sched_wakeup" or
33613383
* "-e", "sched:sched_waking"
33623384
*/
3363-
rec_argc = ARRAY_SIZE(record_args) + 2 + argc - 1;
3385+
rec_argc = ARRAY_SIZE(record_args) + 2 + schedstat_argc + argc - 1;
33643386
rec_argv = calloc(rec_argc + 1, sizeof(char *));
33653387

33663388
if (rec_argv == NULL)
@@ -3376,6 +3398,9 @@ static int __cmd_record(int argc, const char **argv)
33763398
else
33773399
rec_argv[i++] = strdup("sched:sched_wakeup");
33783400

3401+
for (j = 0; j < schedstat_argc; j++)
3402+
rec_argv[i++] = strdup(schedstat_args[j]);
3403+
33793404
for (j = 1; j < (unsigned int)argc; j++, i++)
33803405
rec_argv[i] = argv[j];
33813406

tools/perf/builtin-script.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2601,6 +2601,12 @@ static void perf_script__exit_per_event_dump_stats(struct perf_script *script)
26012601
}
26022602
}
26032603

2604+
static void perf_script__exit(struct perf_script *script)
2605+
{
2606+
perf_thread_map__put(script->threads);
2607+
perf_cpu_map__put(script->cpus);
2608+
}
2609+
26042610
static int __cmd_script(struct perf_script *script)
26052611
{
26062612
int ret;
@@ -4143,8 +4149,10 @@ int cmd_script(int argc, const char **argv)
41434149
zfree(&script.ptime_range);
41444150
}
41454151

4152+
zstd_fini(&(session->zstd_data));
41464153
evlist__free_stats(session->evlist);
41474154
perf_session__delete(session);
4155+
perf_script__exit(&script);
41484156

41494157
if (script_started)
41504158
cleanup_scripting();

tools/perf/builtin-stat.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2445,9 +2445,6 @@ int cmd_stat(int argc, const char **argv)
24452445

24462446
evlist__check_cpu_maps(evsel_list);
24472447

2448-
if (perf_pmu__has_hybrid())
2449-
stat_config.no_merge = true;
2450-
24512448
/*
24522449
* Initialize thread_map with comm names,
24532450
* so we could print it out on output.

tools/perf/builtin-trace.c

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2266,6 +2266,14 @@ static void *syscall__augmented_args(struct syscall *sc, struct perf_sample *sam
22662266
return augmented_args;
22672267
}
22682268

2269+
static void syscall__exit(struct syscall *sc)
2270+
{
2271+
if (!sc)
2272+
return;
2273+
2274+
free(sc->arg_fmt);
2275+
}
2276+
22692277
static int trace__sys_enter(struct trace *trace, struct evsel *evsel,
22702278
union perf_event *event __maybe_unused,
22712279
struct perf_sample *sample)
@@ -3095,6 +3103,21 @@ static struct evsel *evsel__new_pgfault(u64 config)
30953103
return evsel;
30963104
}
30973105

3106+
static void evlist__free_syscall_tp_fields(struct evlist *evlist)
3107+
{
3108+
struct evsel *evsel;
3109+
3110+
evlist__for_each_entry(evlist, evsel) {
3111+
struct evsel_trace *et = evsel->priv;
3112+
3113+
if (!et || !evsel->tp_format || strcmp(evsel->tp_format->system, "syscalls"))
3114+
continue;
3115+
3116+
free(et->fmt);
3117+
free(et);
3118+
}
3119+
}
3120+
30983121
static void trace__handle_event(struct trace *trace, union perf_event *event, struct perf_sample *sample)
30993122
{
31003123
const u32 type = event->header.type;
@@ -4130,7 +4153,7 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
41304153

41314154
out_delete_evlist:
41324155
trace__symbols__exit(trace);
4133-
4156+
evlist__free_syscall_tp_fields(evlist);
41344157
evlist__delete(evlist);
41354158
cgroup__put(trace->cgroup);
41364159
trace->evlist = NULL;
@@ -4636,6 +4659,9 @@ static int trace__parse_events_option(const struct option *opt, const char *str,
46364659
err = parse_events_option(&o, lists[0], 0);
46374660
}
46384661
out:
4662+
free(strace_groups_dir);
4663+
free(lists[0]);
4664+
free(lists[1]);
46394665
if (sep)
46404666
*sep = ',';
46414667

@@ -4701,6 +4727,21 @@ static int trace__config(const char *var, const char *value, void *arg)
47014727
return err;
47024728
}
47034729

4730+
static void trace__exit(struct trace *trace)
4731+
{
4732+
int i;
4733+
4734+
strlist__delete(trace->ev_qualifier);
4735+
free(trace->ev_qualifier_ids.entries);
4736+
if (trace->syscalls.table) {
4737+
for (i = 0; i <= trace->sctbl->syscalls.max_id; i++)
4738+
syscall__exit(&trace->syscalls.table[i]);
4739+
free(trace->syscalls.table);
4740+
}
4741+
syscalltbl__delete(trace->sctbl);
4742+
zfree(&trace->perfconfig_events);
4743+
}
4744+
47044745
int cmd_trace(int argc, const char **argv)
47054746
{
47064747
const char *trace_usage[] = {
@@ -5135,6 +5176,6 @@ int cmd_trace(int argc, const char **argv)
51355176
if (output_name != NULL)
51365177
fclose(trace.output);
51375178
out:
5138-
zfree(&trace.perfconfig_events);
5179+
trace__exit(&trace);
51395180
return err;
51405181
}

tools/perf/tests/bpf.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// SPDX-License-Identifier: GPL-2.0
22
#include <errno.h>
33
#include <stdio.h>
4+
#include <stdlib.h>
45
#include <sys/epoll.h>
56
#include <sys/types.h>
67
#include <sys/stat.h>
@@ -276,6 +277,7 @@ static int __test__bpf(int idx)
276277
}
277278

278279
out:
280+
free(obj_buf);
279281
bpf__clear();
280282
return ret;
281283
}

0 commit comments

Comments
 (0)