Skip to content

Commit

Permalink
Merge tag 'perf-tools-fixes-for-v5.14-2021-07-18' of git://git.kernel…
Browse files Browse the repository at this point in the history
….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
  ...
  • Loading branch information
torvalds committed Jul 18, 2021
2 parents f0eb870 + b0f0085 commit 8c25c44
Show file tree
Hide file tree
Showing 36 changed files with 391 additions and 98 deletions.
1 change: 1 addition & 0 deletions tools/arch/arm64/include/uapi/asm/unistd.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@
#define __ARCH_WANT_SET_GET_RLIMIT
#define __ARCH_WANT_TIME32_SYSCALLS
#define __ARCH_WANT_SYS_CLONE3
#define __ARCH_WANT_MEMFD_SECRET

#include <asm-generic/unistd.h>
6 changes: 0 additions & 6 deletions tools/include/linux/kconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@

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

#ifdef CONFIG_CPU_BIG_ENDIAN
#define __BIG_ENDIAN 4321
#else
#define __LITTLE_ENDIAN 1234
#endif

#define __ARG_PLACEHOLDER_1 0,
#define __take_second_arg(__ignored, val, ...) val

Expand Down
7 changes: 6 additions & 1 deletion tools/include/uapi/asm-generic/unistd.h
Original file line number Diff line number Diff line change
Expand Up @@ -873,8 +873,13 @@ __SYSCALL(__NR_landlock_add_rule, sys_landlock_add_rule)
#define __NR_landlock_restrict_self 446
__SYSCALL(__NR_landlock_restrict_self, sys_landlock_restrict_self)

#ifdef __ARCH_WANT_MEMFD_SECRET
#define __NR_memfd_secret 447
__SYSCALL(__NR_memfd_secret, sys_memfd_secret)
#endif

#undef __NR_syscalls
#define __NR_syscalls 447
#define __NR_syscalls 448

/*
* 32 bit systems traditionally used different
Expand Down
1 change: 1 addition & 0 deletions tools/perf/arch/x86/entry/syscalls/syscall_64.tbl
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@
444 common landlock_create_ruleset sys_landlock_create_ruleset
445 common landlock_add_rule sys_landlock_add_rule
446 common landlock_restrict_self sys_landlock_restrict_self
447 common memfd_secret sys_memfd_secret

#
# Due to a historical design error, certain syscalls are numbered differently
Expand Down
13 changes: 9 additions & 4 deletions tools/perf/builtin-inject.c
Original file line number Diff line number Diff line change
Expand Up @@ -361,9 +361,10 @@ static struct dso *findnew_dso(int pid, int tid, const char *filename,
dso = machine__findnew_dso_id(machine, filename, id);
}

if (dso)
if (dso) {
nsinfo__put(dso->nsinfo);
dso->nsinfo = nsi;
else
} else
nsinfo__put(nsi);

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

data.path = inject.input_name;
inject.session = perf_session__new(&data, inject.output.is_pipe, &inject.tool);
if (IS_ERR(inject.session))
return PTR_ERR(inject.session);
if (IS_ERR(inject.session)) {
ret = PTR_ERR(inject.session);
goto out_close_output;
}

if (zstd_init(&(inject.session->zstd_data), 0) < 0)
pr_warning("Decompression initialization failed.\n");
Expand Down Expand Up @@ -1035,6 +1038,8 @@ int cmd_inject(int argc, const char **argv)
out_delete:
zstd_fini(&(inject.session->zstd_data));
perf_session__delete(inject.session);
out_close_output:
perf_data__close(&inject.output);
free(inject.itrace_synth_opts.vm_tm_corr_args);
return ret;
}
33 changes: 22 additions & 11 deletions tools/perf/builtin-report.c
Original file line number Diff line number Diff line change
Expand Up @@ -1175,6 +1175,8 @@ int cmd_report(int argc, const char **argv)
.annotation_opts = annotation__default_options,
.skip_empty = true,
};
char *sort_order_help = sort_help("sort by key(s):");
char *field_order_help = sort_help("output field(s): overhead period sample ");
const struct option options[] = {
OPT_STRING('i', "input", &input_name, "file",
"input file name"),
Expand Down Expand Up @@ -1209,9 +1211,9 @@ int cmd_report(int argc, const char **argv)
OPT_BOOLEAN(0, "header-only", &report.header_only,
"Show only data header."),
OPT_STRING('s', "sort", &sort_order, "key[,key2...]",
sort_help("sort by key(s):")),
sort_order_help),
OPT_STRING('F', "fields", &field_order, "key[,keys...]",
sort_help("output field(s): overhead period sample ")),
field_order_help),
OPT_BOOLEAN(0, "show-cpu-utilization", &symbol_conf.show_cpu_utilization,
"Show sample percentage for different cpu modes"),
OPT_BOOLEAN_FLAG(0, "showcpuutilization", &symbol_conf.show_cpu_utilization,
Expand Down Expand Up @@ -1344,11 +1346,11 @@ int cmd_report(int argc, const char **argv)
char sort_tmp[128];

if (ret < 0)
return ret;
goto exit;

ret = perf_config(report__config, &report);
if (ret)
return ret;
goto exit;

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

if (annotate_check_args(&report.annotation_opts) < 0)
return -EINVAL;
if (annotate_check_args(&report.annotation_opts) < 0) {
ret = -EINVAL;
goto exit;
}

if (report.mmaps_mode)
report.tasks_mode = true;
Expand All @@ -1377,12 +1381,14 @@ int cmd_report(int argc, const char **argv)
if (symbol_conf.vmlinux_name &&
access(symbol_conf.vmlinux_name, R_OK)) {
pr_err("Invalid file: %s\n", symbol_conf.vmlinux_name);
return -EINVAL;
ret = -EINVAL;
goto exit;
}
if (symbol_conf.kallsyms_name &&
access(symbol_conf.kallsyms_name, R_OK)) {
pr_err("Invalid file: %s\n", symbol_conf.kallsyms_name);
return -EINVAL;
ret = -EINVAL;
goto exit;
}

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

repeat:
session = perf_session__new(&data, false, &report.tool);
if (IS_ERR(session))
return PTR_ERR(session);
if (IS_ERR(session)) {
ret = PTR_ERR(session);
goto exit;
}

ret = evswitch__init(&report.evswitch, session->evlist, stderr);
if (ret)
return ret;
goto exit;

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

zstd_fini(&(session->zstd_data));
perf_session__delete(session);
exit:
free(sort_order_help);
free(field_order_help);
return ret;
}
35 changes: 30 additions & 5 deletions tools/perf/builtin-sched.c
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ static void create_tasks(struct perf_sched *sched)
err = pthread_attr_init(&attr);
BUG_ON(err);
err = pthread_attr_setstacksize(&attr,
(size_t) max(16 * 1024, PTHREAD_STACK_MIN));
(size_t) max(16 * 1024, (int)PTHREAD_STACK_MIN));
BUG_ON(err);
err = pthread_mutex_lock(&sched->start_work_mutex);
BUG_ON(err);
Expand Down Expand Up @@ -3335,6 +3335,16 @@ static void setup_sorting(struct perf_sched *sched, const struct option *options
sort_dimension__add("pid", &sched->cmp_pid);
}

static bool schedstat_events_exposed(void)
{
/*
* Select "sched:sched_stat_wait" event to check
* whether schedstat tracepoints are exposed.
*/
return IS_ERR(trace_event__tp_format("sched", "sched_stat_wait")) ?
false : true;
}

static int __cmd_record(int argc, const char **argv)
{
unsigned int rec_argc, i, j;
Expand All @@ -3346,21 +3356,33 @@ static int __cmd_record(int argc, const char **argv)
"-m", "1024",
"-c", "1",
"-e", "sched:sched_switch",
"-e", "sched:sched_stat_wait",
"-e", "sched:sched_stat_sleep",
"-e", "sched:sched_stat_iowait",
"-e", "sched:sched_stat_runtime",
"-e", "sched:sched_process_fork",
"-e", "sched:sched_wakeup_new",
"-e", "sched:sched_migrate_task",
};

/*
* The tracepoints trace_sched_stat_{wait, sleep, iowait}
* are not exposed to user if CONFIG_SCHEDSTATS is not set,
* to prevent "perf sched record" execution failure, determine
* whether to record schedstat events according to actual situation.
*/
const char * const schedstat_args[] = {
"-e", "sched:sched_stat_wait",
"-e", "sched:sched_stat_sleep",
"-e", "sched:sched_stat_iowait",
};
unsigned int schedstat_argc = schedstat_events_exposed() ?
ARRAY_SIZE(schedstat_args) : 0;

struct tep_event *waking_event;

/*
* +2 for either "-e", "sched:sched_wakeup" or
* "-e", "sched:sched_waking"
*/
rec_argc = ARRAY_SIZE(record_args) + 2 + argc - 1;
rec_argc = ARRAY_SIZE(record_args) + 2 + schedstat_argc + argc - 1;
rec_argv = calloc(rec_argc + 1, sizeof(char *));

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

for (j = 0; j < schedstat_argc; j++)
rec_argv[i++] = strdup(schedstat_args[j]);

for (j = 1; j < (unsigned int)argc; j++, i++)
rec_argv[i] = argv[j];

Expand Down
8 changes: 8 additions & 0 deletions tools/perf/builtin-script.c
Original file line number Diff line number Diff line change
Expand Up @@ -2601,6 +2601,12 @@ static void perf_script__exit_per_event_dump_stats(struct perf_script *script)
}
}

static void perf_script__exit(struct perf_script *script)
{
perf_thread_map__put(script->threads);
perf_cpu_map__put(script->cpus);
}

static int __cmd_script(struct perf_script *script)
{
int ret;
Expand Down Expand Up @@ -4143,8 +4149,10 @@ int cmd_script(int argc, const char **argv)
zfree(&script.ptime_range);
}

zstd_fini(&(session->zstd_data));
evlist__free_stats(session->evlist);
perf_session__delete(session);
perf_script__exit(&script);

if (script_started)
cleanup_scripting();
Expand Down
3 changes: 0 additions & 3 deletions tools/perf/builtin-stat.c
Original file line number Diff line number Diff line change
Expand Up @@ -2445,9 +2445,6 @@ int cmd_stat(int argc, const char **argv)

evlist__check_cpu_maps(evsel_list);

if (perf_pmu__has_hybrid())
stat_config.no_merge = true;

/*
* Initialize thread_map with comm names,
* so we could print it out on output.
Expand Down
45 changes: 43 additions & 2 deletions tools/perf/builtin-trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -2266,6 +2266,14 @@ static void *syscall__augmented_args(struct syscall *sc, struct perf_sample *sam
return augmented_args;
}

static void syscall__exit(struct syscall *sc)
{
if (!sc)
return;

free(sc->arg_fmt);
}

static int trace__sys_enter(struct trace *trace, struct evsel *evsel,
union perf_event *event __maybe_unused,
struct perf_sample *sample)
Expand Down Expand Up @@ -3095,6 +3103,21 @@ static struct evsel *evsel__new_pgfault(u64 config)
return evsel;
}

static void evlist__free_syscall_tp_fields(struct evlist *evlist)
{
struct evsel *evsel;

evlist__for_each_entry(evlist, evsel) {
struct evsel_trace *et = evsel->priv;

if (!et || !evsel->tp_format || strcmp(evsel->tp_format->system, "syscalls"))
continue;

free(et->fmt);
free(et);
}
}

static void trace__handle_event(struct trace *trace, union perf_event *event, struct perf_sample *sample)
{
const u32 type = event->header.type;
Expand Down Expand Up @@ -4130,7 +4153,7 @@ static int trace__run(struct trace *trace, int argc, const char **argv)

out_delete_evlist:
trace__symbols__exit(trace);

evlist__free_syscall_tp_fields(evlist);
evlist__delete(evlist);
cgroup__put(trace->cgroup);
trace->evlist = NULL;
Expand Down Expand Up @@ -4636,6 +4659,9 @@ static int trace__parse_events_option(const struct option *opt, const char *str,
err = parse_events_option(&o, lists[0], 0);
}
out:
free(strace_groups_dir);
free(lists[0]);
free(lists[1]);
if (sep)
*sep = ',';

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

static void trace__exit(struct trace *trace)
{
int i;

strlist__delete(trace->ev_qualifier);
free(trace->ev_qualifier_ids.entries);
if (trace->syscalls.table) {
for (i = 0; i <= trace->sctbl->syscalls.max_id; i++)
syscall__exit(&trace->syscalls.table[i]);
free(trace->syscalls.table);
}
syscalltbl__delete(trace->sctbl);
zfree(&trace->perfconfig_events);
}

int cmd_trace(int argc, const char **argv)
{
const char *trace_usage[] = {
Expand Down Expand Up @@ -5135,6 +5176,6 @@ int cmd_trace(int argc, const char **argv)
if (output_name != NULL)
fclose(trace.output);
out:
zfree(&trace.perfconfig_events);
trace__exit(&trace);
return err;
}
2 changes: 2 additions & 0 deletions tools/perf/tests/bpf.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/epoll.h>
#include <sys/types.h>
#include <sys/stat.h>
Expand Down Expand Up @@ -276,6 +277,7 @@ static int __test__bpf(int idx)
}

out:
free(obj_buf);
bpf__clear();
return ret;
}
Expand Down
Loading

0 comments on commit 8c25c44

Please sign in to comment.