2012-05-02 16:27:27

by Arnaldo Carvalho de Melo

[permalink] [raw]
Subject: [GIT PULL 0/2] perf/urgent fixes

Hi Ingo,

Please consider pulling,

- Arnaldo

The following changes since commit 33ff581eddf744ea91a50d46c2f0961b375a9595:

perf symbols: Read plt symbols from proper symtab_type binary (2012-04-20 13:34:49 -0300)

are available in the git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux tags/perf-urgent-for-mingo

for you to fetch changes up to 5622c07b4741e0afd7607bce6e850b76eeb23210:

perf stat: Fix case where guest/host monitoring is not supported by kernel (2012-05-01 14:20:00 -0300)

----------------------------------------------------------------
Fixes for perf/urgent:

. Add fallback in 'perf stat' for kernels that don't support
perf_event_attr.exclude_guest, from Stephane Eranian.

. Fix build id cache add routine to take the size of the buffer and not of a
pointer, from Namhyung Kim.

Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>

----------------------------------------------------------------
Namhyung Kim (1):
perf build-id: Fix filename size calculation

Stephane Eranian (1):
perf stat: Fix case where guest/host monitoring is not supported by kernel

tools/perf/builtin-stat.c | 33 +++++++++++++++++++++++++++++----
tools/perf/util/header.c | 2 +-
2 files changed, 30 insertions(+), 5 deletions(-)


2012-05-02 16:27:23

by Arnaldo Carvalho de Melo

[permalink] [raw]
Subject: [PATCH 1/2] perf build-id: Fix filename size calculation

From: Namhyung Kim <[email protected]>

The filename is a pointer variable so the sizeof(filename) will return
length of a pointer. Fix it by using 'size'.

Signed-off-by: Namhyung Kim <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
---
tools/perf/util/header.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 4c7c2d7..c0b70c6 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -296,7 +296,7 @@ int build_id_cache__add_s(const char *sbuild_id, const char *debugdir,
if (mkdir_p(filename, 0755))
goto out_free;

- snprintf(filename + len, sizeof(filename) - len, "/%s", sbuild_id);
+ snprintf(filename + len, size - len, "/%s", sbuild_id);

if (access(filename, F_OK)) {
if (is_kallsyms) {
--
1.7.9.2.358.g22243

2012-05-02 16:27:25

by Arnaldo Carvalho de Melo

[permalink] [raw]
Subject: [PATCH 2/2] perf stat: Fix case where guest/host monitoring is not supported by kernel

From: Stephane Eranian <[email protected]>

By default, perf stat sets exclude_guest = 1. But when you run perf on a
kernel which does not support host/guest filtering, then you get an
error saying the event in unsupported. This comes from the fact that
when the perf_event_attr struct passed by the user is larger than the
one known to the kernel there is safety check which ensures that all
unknown bits are zero. But here, exclude_guest is 1 (part of the unknown
bits) and thus the perf_event_open() syscall return EINVAL.

To my surprise, running perf record on the same kernel did not exhibit
the problem. The reason is that perf record handles the problem by
catching the error and retrying with guest/host excludes set to zero.
For some reason, this was not done with perf stat. This patch fixes this
problem.

Signed-off-by: Stephane Eranian <[email protected]>
Cc: Gleb Natapov <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Joerg Roedel <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Robert Richter <[email protected]>
Link: http://lkml.kernel.org/r/20120427124538.GA7230@quad
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
---
tools/perf/builtin-stat.c | 33 +++++++++++++++++++++++++++++----
1 file changed, 29 insertions(+), 4 deletions(-)

diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index c941bb6..4532a78 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -283,6 +283,8 @@ static int create_perf_stat_counter(struct perf_evsel *evsel,
{
struct perf_event_attr *attr = &evsel->attr;
struct xyarray *group_fd = NULL;
+ bool exclude_guest_missing = false;
+ int ret;

if (group && evsel != first)
group_fd = first->fd;
@@ -293,16 +295,39 @@ static int create_perf_stat_counter(struct perf_evsel *evsel,

attr->inherit = !no_inherit;

- if (system_wide)
- return perf_evsel__open_per_cpu(evsel, evsel_list->cpus,
+retry:
+ if (exclude_guest_missing)
+ evsel->attr.exclude_guest = evsel->attr.exclude_host = 0;
+
+ if (system_wide) {
+ ret = perf_evsel__open_per_cpu(evsel, evsel_list->cpus,
group, group_fd);
+ if (ret)
+ goto check_ret;
+ return 0;
+ }
+
if (!target_pid && !target_tid && (!group || evsel == first)) {
attr->disabled = 1;
attr->enable_on_exec = 1;
}

- return perf_evsel__open_per_thread(evsel, evsel_list->threads,
- group, group_fd);
+ ret = perf_evsel__open_per_thread(evsel, evsel_list->threads,
+ group, group_fd);
+ if (!ret)
+ return 0;
+ /* fall through */
+check_ret:
+ if (ret && errno == EINVAL) {
+ if (!exclude_guest_missing &&
+ (evsel->attr.exclude_guest || evsel->attr.exclude_host)) {
+ pr_debug("Old kernel, cannot exclude "
+ "guest or host samples.\n");
+ exclude_guest_missing = true;
+ goto retry;
+ }
+ }
+ return ret;
}

/*
--
1.7.9.2.358.g22243

2012-05-02 17:34:53

by Ingo Molnar

[permalink] [raw]
Subject: Re: [GIT PULL 0/2] perf/urgent fixes


* Arnaldo Carvalho de Melo <[email protected]> wrote:

> Hi Ingo,
>
> Please consider pulling,
>
> - Arnaldo
>
> The following changes since commit 33ff581eddf744ea91a50d46c2f0961b375a9595:
>
> perf symbols: Read plt symbols from proper symtab_type binary (2012-04-20 13:34:49 -0300)
>
> are available in the git repository at:
>
> git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux tags/perf-urgent-for-mingo
>
> for you to fetch changes up to 5622c07b4741e0afd7607bce6e850b76eeb23210:
>
> perf stat: Fix case where guest/host monitoring is not supported by kernel (2012-05-01 14:20:00 -0300)
>
> ----------------------------------------------------------------
> Fixes for perf/urgent:
>
> . Add fallback in 'perf stat' for kernels that don't support
> perf_event_attr.exclude_guest, from Stephane Eranian.
>
> . Fix build id cache add routine to take the size of the buffer and not of a
> pointer, from Namhyung Kim.
>
> Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
>
> ----------------------------------------------------------------
> Namhyung Kim (1):
> perf build-id: Fix filename size calculation
>
> Stephane Eranian (1):
> perf stat: Fix case where guest/host monitoring is not supported by kernel
>
> tools/perf/builtin-stat.c | 33 +++++++++++++++++++++++++++++----
> tools/perf/util/header.c | 2 +-
> 2 files changed, 30 insertions(+), 5 deletions(-)

Pulled, thanks Arnaldo!

Ingo