Skip to content

Commit

Permalink
Merge tag 'perf-tools-fixes-for-v5.9-2020-09-16' 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:

 - Set PERF_SAMPLE_PERIOD if attr->freq is set.

 - Remove trailing commas from AMD JSON vendor event files.

 - Don't clear event's period if set by a event definition term.

 - Leader sampling shouldn't clear sample period in 'perf test'.

 - Fix the "signal" test inline assembly when built with DEBUG=1.

 - Fix memory leaks detected by ASAN, some in normal paths, some in
   error paths.

 - Fix 2 memory sanitizer warnings in 'perf bench'.

 - Fix the ratio comments of miss-events in 'perf stat'.

 - Prevent override of attr->sample_period for libpfm4 events.

 - Sync kvm.h and in.h headers with the kernel sources.

* tag 'perf-tools-fixes-for-v5.9-2020-09-16' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux:
  perf stat: Fix the ratio comments of miss-events
  perf test: Free formats for perf pmu parse test
  perf metric: Do not free metric when failed to resolve
  perf metric: Free metric when it failed to resolve
  perf metric: Release expr_parse_ctx after testing
  perf test: Fix memory leaks in parse-metric test
  perf parse-event: Fix memory leak in evsel->unit
  perf evlist: Fix cpu/thread map leak
  perf metric: Fix some memory leaks - part 2
  perf metric: Fix some memory leaks
  perf test: Free aliases for PMU event map aliases test
  perf vendor events amd: Remove trailing commas
  perf test: Leader sampling shouldn't clear sample period
  perf record: Don't clear event's period if set by a term
  tools headers UAPI: update linux/in.h copy
  tools headers UAPI: Sync kvm.h headers with the kernel sources
  perf record: Prevent override of attr->sample_period for libpfm4 events
  perf record: Set PERF_RECORD_PERIOD if attr->freq is set.
  perf bench: Fix 2 memory sanitizer warnings
  perf test: Fix the "signal" test inline assembly
  • Loading branch information
Linus Torvalds committed Sep 16, 2020
2 parents 05da40e + ce9c13f commit 5925fa6
Show file tree
Hide file tree
Showing 19 changed files with 154 additions and 52 deletions.
2 changes: 1 addition & 1 deletion tools/include/uapi/linux/in.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ struct in_addr {
* this socket to prevent accepting spoofed ones.
*/
#define IP_PMTUDISC_INTERFACE 4
/* weaker version of IP_PMTUDISC_INTERFACE, which allos packets to get
/* weaker version of IP_PMTUDISC_INTERFACE, which allows packets to get
* fragmented if they exeed the interface mtu
*/
#define IP_PMTUDISC_OMIT 5
Expand Down
6 changes: 4 additions & 2 deletions tools/include/uapi/linux/kvm.h
Original file line number Diff line number Diff line change
Expand Up @@ -790,9 +790,10 @@ struct kvm_ppc_resize_hpt {
#define KVM_VM_PPC_HV 1
#define KVM_VM_PPC_PR 2

/* on MIPS, 0 forces trap & emulate, 1 forces VZ ASE */
#define KVM_VM_MIPS_TE 0
/* on MIPS, 0 indicates auto, 1 forces VZ ASE, 2 forces trap & emulate */
#define KVM_VM_MIPS_AUTO 0
#define KVM_VM_MIPS_VZ 1
#define KVM_VM_MIPS_TE 2

#define KVM_S390_SIE_PAGE_OFFSET 1

Expand Down Expand Up @@ -1035,6 +1036,7 @@ struct kvm_ppc_resize_hpt {
#define KVM_CAP_LAST_CPU 184
#define KVM_CAP_SMALLER_MAXPHYADDR 185
#define KVM_CAP_S390_DIAG318 186
#define KVM_CAP_STEAL_TIME 187

#ifdef KVM_CAP_IRQ_ROUTING

Expand Down
4 changes: 2 additions & 2 deletions tools/perf/bench/sched-messaging.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,10 @@ static void fdpair(int fds[2])
/* Block until we're ready to go */
static void ready(int ready_out, int wakefd)
{
char dummy;
struct pollfd pollfd = { .fd = wakefd, .events = POLLIN };

/* Tell them we're ready. */
if (write(ready_out, &dummy, 1) != 1)
if (write(ready_out, "R", 1) != 1)
err(EXIT_FAILURE, "CLIENT: ready write");

/* Wait for "GO" signal */
Expand All @@ -85,6 +84,7 @@ static void *sender(struct sender_context *ctx)
unsigned int i, j;

ready(ctx->ready_out, ctx->wakefd);
memset(data, 'S', sizeof(data));

/* Now pump to every receiver. */
for (i = 0; i < nr_loops; i++) {
Expand Down
2 changes: 1 addition & 1 deletion tools/perf/pmu-events/arch/x86/amdzen1/core.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
{
"EventName": "ex_ret_brn_ind_misp",
"EventCode": "0xca",
"BriefDescription": "Retired Indirect Branch Instructions Mispredicted.",
"BriefDescription": "Retired Indirect Branch Instructions Mispredicted."
},
{
"EventName": "ex_ret_mmx_fp_instr.sse_instr",
Expand Down
2 changes: 1 addition & 1 deletion tools/perf/pmu-events/arch/x86/amdzen2/core.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,6 @@
{
"EventName": "ex_ret_fus_brnch_inst",
"EventCode": "0x1d0",
"BriefDescription": "Retired Fused Instructions. The number of fuse-branch instructions retired per cycle. The number of events logged per cycle can vary from 0-8.",
"BriefDescription": "Retired Fused Instructions. The number of fuse-branch instructions retired per cycle. The number of events logged per cycle can vary from 0-8."
}
]
1 change: 1 addition & 0 deletions tools/perf/tests/attr/README
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Following tests are defined (with perf commands):
perf record --call-graph fp kill (test-record-graph-fp)
perf record --group -e cycles,instructions kill (test-record-group)
perf record -e '{cycles,instructions}' kill (test-record-group1)
perf record -e '{cycles/period=1/,instructions/period=2/}:S' kill (test-record-group2)
perf record -D kill (test-record-no-delay)
perf record -i kill (test-record-no-inherit)
perf record -n kill (test-record-no-samples)
Expand Down
29 changes: 29 additions & 0 deletions tools/perf/tests/attr/test-record-group2
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[config]
command = record
args = --no-bpf-event -e '{cycles/period=1234000/,instructions/period=6789000/}:S' kill >/dev/null 2>&1
ret = 1

[event-1:base-record]
fd=1
group_fd=-1
config=0|1
sample_period=1234000
sample_type=87
read_format=12
inherit=0
freq=0

[event-2:base-record]
fd=2
group_fd=1
config=0|1
sample_period=6789000
sample_type=87
read_format=12
disabled=0
inherit=0
mmap=0
comm=0
freq=0
enable_on_exec=0
task=0
5 changes: 4 additions & 1 deletion tools/perf/tests/bp_signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,13 @@ volatile long the_var;
#if defined (__x86_64__)
extern void __test_function(volatile long *ptr);
asm (
".pushsection .text;"
".globl __test_function\n"
".type __test_function, @function;"
"__test_function:\n"
"incq (%rdi)\n"
"ret\n");
"ret\n"
".popsection\n");
#else
static void __test_function(volatile long *ptr)
{
Expand Down
14 changes: 9 additions & 5 deletions tools/perf/tests/parse-metric.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,10 @@ static int __compute_metric(const char *name, struct value *vals,
return -ENOMEM;

cpus = perf_cpu_map__new("0");
if (!cpus)
if (!cpus) {
evlist__delete(evlist);
return -ENOMEM;
}

perf_evlist__set_maps(&evlist->core, cpus, NULL);

Expand All @@ -163,10 +165,11 @@ static int __compute_metric(const char *name, struct value *vals,
false, false,
&metric_events);
if (err)
return err;
goto out;

if (perf_evlist__alloc_stats(evlist, false))
return -1;
err = perf_evlist__alloc_stats(evlist, false);
if (err)
goto out;

/* Load the runtime stats with given numbers for events. */
runtime_stat__init(&st);
Expand All @@ -178,13 +181,14 @@ static int __compute_metric(const char *name, struct value *vals,
if (name2 && ratio2)
*ratio2 = compute_single(&metric_events, evlist, &st, name2);

out:
/* ... clenup. */
metricgroup__rblist_exit(&metric_events);
runtime_stat__exit(&st);
perf_evlist__free_stats(evlist);
perf_cpu_map__put(cpus);
evlist__delete(evlist);
return 0;
return err;
}

static int compute_metric(const char *name, struct value *vals, double *ratio)
Expand Down
5 changes: 5 additions & 0 deletions tools/perf/tests/pmu-events.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ static int __test__pmu_event_aliases(char *pmu_name, int *count)
int res = 0;
bool use_uncore_table;
struct pmu_events_map *map = __test_pmu_get_events_map();
struct perf_pmu_alias *a, *tmp;

if (!map)
return -1;
Expand Down Expand Up @@ -347,6 +348,10 @@ static int __test__pmu_event_aliases(char *pmu_name, int *count)
pmu_name, alias->name);
}

list_for_each_entry_safe(a, tmp, &aliases, list) {
list_del(&a->list);
perf_pmu_free_alias(a);
}
free(pmu);
return res;
}
Expand Down
1 change: 1 addition & 0 deletions tools/perf/tests/pmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ int test__pmu(struct test *test __maybe_unused, int subtest __maybe_unused)
ret = 0;
} while (0);

perf_pmu__del_formats(&formats);
test_format_dir_put(format);
return ret;
}
11 changes: 8 additions & 3 deletions tools/perf/util/evlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,10 @@ int perf_evlist__create_maps(struct evlist *evlist, struct target *target)

perf_evlist__set_maps(&evlist->core, cpus, threads);

/* as evlist now has references, put count here */
perf_cpu_map__put(cpus);
perf_thread_map__put(threads);

return 0;

out_delete_threads:
Expand Down Expand Up @@ -1273,11 +1277,12 @@ static int perf_evlist__create_syswide_maps(struct evlist *evlist)
goto out_put;

perf_evlist__set_maps(&evlist->core, cpus, threads);
out:
return err;

perf_thread_map__put(threads);
out_put:
perf_cpu_map__put(cpus);
goto out;
out:
return err;
}

int evlist__open(struct evlist *evlist)
Expand Down
10 changes: 7 additions & 3 deletions tools/perf/util/evsel.c
Original file line number Diff line number Diff line change
Expand Up @@ -976,16 +976,20 @@ void evsel__config(struct evsel *evsel, struct record_opts *opts,
* We default some events to have a default interval. But keep
* it a weak assumption overridable by the user.
*/
if (!attr->sample_period || (opts->user_freq != UINT_MAX ||
opts->user_interval != ULLONG_MAX)) {
if (!attr->sample_period) {
if (opts->freq) {
evsel__set_sample_bit(evsel, PERIOD);
attr->freq = 1;
attr->sample_freq = opts->freq;
} else {
attr->sample_period = opts->default_interval;
}
}
/*
* If attr->freq was set (here or earlier), ask for period
* to be sampled.
*/
if (attr->freq)
evsel__set_sample_bit(evsel, PERIOD);

if (opts->no_samples)
attr->sample_freq = 0;
Expand Down
35 changes: 25 additions & 10 deletions tools/perf/util/metricgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ static void metric_event_delete(struct rblist *rblist __maybe_unused,

list_for_each_entry_safe(expr, tmp, &me->head, nd) {
free(expr->metric_refs);
free(expr->metric_events);
free(expr);
}

Expand Down Expand Up @@ -316,6 +317,7 @@ static int metricgroup__setup_events(struct list_head *groups,
if (!metric_refs) {
ret = -ENOMEM;
free(metric_events);
free(expr);
break;
}

Expand Down Expand Up @@ -530,6 +532,9 @@ void metricgroup__print(bool metrics, bool metricgroups, char *filter,
continue;
strlist__add(me->metrics, s);
}

if (!raw)
free(s);
}
free(omg);
}
Expand Down Expand Up @@ -667,7 +672,6 @@ static int __add_metric(struct list_head *metric_list,
m->has_constraint = metric_no_group || metricgroup__has_constraint(pe);
INIT_LIST_HEAD(&m->metric_refs);
m->metric_refs_cnt = 0;
*mp = m;

parent = expr_ids__alloc(ids);
if (!parent) {
Expand All @@ -680,6 +684,7 @@ static int __add_metric(struct list_head *metric_list,
free(m);
return -ENOMEM;
}
*mp = m;
} else {
/*
* We got here for the referenced metric, via the
Expand Down Expand Up @@ -714,8 +719,11 @@ static int __add_metric(struct list_head *metric_list,
* all the metric's IDs and add it to the parent context.
*/
if (expr__find_other(pe->metric_expr, NULL, &m->pctx, runtime) < 0) {
expr__ctx_clear(&m->pctx);
free(m);
if (m->metric_refs_cnt == 0) {
expr__ctx_clear(&m->pctx);
free(m);
*mp = NULL;
}
return -EINVAL;
}

Expand Down Expand Up @@ -934,7 +942,7 @@ static int metricgroup__add_metric(const char *metric, bool metric_no_group,

ret = add_metric(&list, pe, metric_no_group, &m, NULL, &ids);
if (ret)
return ret;
goto out;

/*
* Process any possible referenced metrics
Expand All @@ -943,12 +951,14 @@ static int metricgroup__add_metric(const char *metric, bool metric_no_group,
ret = resolve_metric(metric_no_group,
&list, map, &ids);
if (ret)
return ret;
goto out;
}

/* End of pmu events. */
if (!has_match)
return -EINVAL;
if (!has_match) {
ret = -EINVAL;
goto out;
}

list_for_each_entry(m, &list, nd) {
if (events->len > 0)
Expand All @@ -963,9 +973,14 @@ static int metricgroup__add_metric(const char *metric, bool metric_no_group,
}
}

out:
/*
* add to metric_list so that they can be released
* even if it's failed
*/
list_splice(&list, metric_list);
expr_ids__exit(&ids);
return 0;
return ret;
}

static int metricgroup__add_metric_list(const char *list, bool metric_no_group,
Expand Down Expand Up @@ -1040,19 +1055,19 @@ static int parse_groups(struct evlist *perf_evlist, const char *str,
ret = metricgroup__add_metric_list(str, metric_no_group,
&extra_events, &metric_list, map);
if (ret)
return ret;
goto out;
pr_debug("adding %s\n", extra_events.buf);
bzero(&parse_error, sizeof(parse_error));
ret = __parse_events(perf_evlist, extra_events.buf, &parse_error, fake_pmu);
if (ret) {
parse_events_print_error(&parse_error, extra_events.buf);
goto out;
}
strbuf_release(&extra_events);
ret = metricgroup__setup_events(&metric_list, metric_no_merge,
perf_evlist, metric_events);
out:
metricgroup__free_metrics(&metric_list);
strbuf_release(&extra_events);
return ret;
}

Expand Down
2 changes: 1 addition & 1 deletion tools/perf/util/parse-events.c
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ static int add_event_tool(struct list_head *list, int *idx,
return -ENOMEM;
evsel->tool_event = tool_event;
if (tool_event == PERF_TOOL_DURATION_TIME)
evsel->unit = strdup("ns");
evsel->unit = "ns";
return 0;
}

Expand Down
13 changes: 12 additions & 1 deletion tools/perf/util/pmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ static void perf_pmu_update_alias(struct perf_pmu_alias *old,
}

/* Delete an alias entry. */
static void perf_pmu_free_alias(struct perf_pmu_alias *newalias)
void perf_pmu_free_alias(struct perf_pmu_alias *newalias)
{
zfree(&newalias->name);
zfree(&newalias->desc);
Expand Down Expand Up @@ -1354,6 +1354,17 @@ void perf_pmu__set_format(unsigned long *bits, long from, long to)
set_bit(b, bits);
}

void perf_pmu__del_formats(struct list_head *formats)
{
struct perf_pmu_format *fmt, *tmp;

list_for_each_entry_safe(fmt, tmp, formats, list) {
list_del(&fmt->list);
free(fmt->name);
free(fmt);
}
}

static int sub_non_neg(int a, int b)
{
if (b > a)
Expand Down
Loading

0 comments on commit 5925fa6

Please sign in to comment.