All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] perf tools: Show better error message in case we fail to open counters due to EBUSY error
@ 2014-08-01 15:46 Jiri Olsa
  2014-08-02 17:58 ` Yann Droneaud
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Jiri Olsa @ 2014-08-01 15:46 UTC (permalink / raw)
  To: linux-kernel
  Cc: Jiri Olsa, Adrian Hunter, Arnaldo Carvalho de Melo, David Ahern,
	Frederic Weisbecker, Namhyung Kim, Paul Mackerras,
	Peter Zijlstra, Stephane Eranian, William Cohen, Yann Droneaud

Showing better error message in case we fail to open
counters due to the EBUSY error. If we detect oprofile
daemon process running, we now display following message
for EBUSY error:

  $ perf record ls
  Error:
  The PMU counters are busy/taken by another profiler.
  We found oprofile daemon running, please stop it and try again.

In case oprofiled was not detected the current error
message stays:

  $ perf record ls
  Error:
  The sys_perf_event_open() syscall returned with 16 (Device or resource busy) for event (cycles).
  /bin/dmesg may provide additional information.
  No CONFIG_PERF_EVENTS=y kernel support configured?

Also changing PERF_FLAG_FD_CLOEXEC detection code not to display
error in case of EBUSY error, as it currently does:

  $ perf record ls
  Error:
  perf_event_open(..., PERF_FLAG_FD_CLOEXEC) failed with unexpected error 16 (Device or resource busy)
  perf_event_open(..., 0) failed unexpectedly with error 16 (Device or resource busy)
  The PMU counters are busy/taken by another profiler.
  We found oprofile daemon running, please stop it and try again.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: William Cohen <wcohen@redhat.com>
Cc: Yann Droneaud <ydroneaud@opteya.com>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/util/cloexec.c |  4 ++--
 tools/perf/util/evsel.c   |  6 ++++++
 tools/perf/util/util.c    | 36 ++++++++++++++++++++++++++++++++++++
 tools/perf/util/util.h    |  1 +
 4 files changed, 45 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/cloexec.c b/tools/perf/util/cloexec.c
index c5d05ec17220..dede0c388ed4 100644
--- a/tools/perf/util/cloexec.c
+++ b/tools/perf/util/cloexec.c
@@ -25,7 +25,7 @@ static int perf_flag_probe(void)
 		return 1;
 	}
 
-	WARN_ONCE(err != EINVAL,
+	WARN_ONCE(err != EINVAL && err != EBUSY,
 		  "perf_event_open(..., PERF_FLAG_FD_CLOEXEC) failed with unexpected error %d (%s)\n",
 		  err, strerror(err));
 
@@ -33,7 +33,7 @@ static int perf_flag_probe(void)
 	fd = sys_perf_event_open(&attr, 0, -1, -1, 0);
 	err = errno;
 
-	if (WARN_ONCE(fd < 0,
+	if (WARN_ONCE(fd < 0 && err != EBUSY,
 		      "perf_event_open(..., 0) failed unexpectedly with error %d (%s)\n",
 		      err, strerror(err)))
 		return -1;
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 21a373ebea22..180ce82d79ea 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -2036,6 +2036,12 @@ int perf_evsel__open_strerror(struct perf_evsel *evsel, struct target *target,
 	"No APIC? If so then you can boot the kernel with the \"lapic\" boot parameter to force-enable it.");
 #endif
 		break;
+	case EBUSY:
+		if (find_process("oprofiled"))
+			return scnprintf(msg, size,
+	"The PMU counters are busy/taken by another profiler.\n"
+	"We found oprofile daemon running, please stop it and try again.");
+		break;
 	default:
 		break;
 	}
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c
index e52e7461911b..b82a93cb1694 100644
--- a/tools/perf/util/util.c
+++ b/tools/perf/util/util.c
@@ -536,3 +536,39 @@ void mem_bswap_64(void *src, int byte_size)
 		++m;
 	}
 }
+
+bool find_process(const char *name)
+{
+	size_t len = strlen(name);
+	DIR *dir;
+	struct dirent *d;
+	int ret = -1;
+
+	dir = opendir(procfs__mountpoint());
+	if (!dir)
+		return -1;
+
+	/* Walk through the directory. */
+	while (ret && (d = readdir(dir)) != NULL) {
+		char path[PATH_MAX];
+		char *data;
+		size_t size;
+
+		if ((d->d_type != DT_DIR) ||
+		     !strcmp(".", d->d_name) ||
+		     !strcmp("..", d->d_name))
+			continue;
+
+		scnprintf(path, sizeof(path), "%s/%s/comm",
+			  procfs__mountpoint(), d->d_name);
+
+		if (filename__read_str(path, &data, &size))
+			continue;
+
+		ret = strncmp(name, data, len);
+		free(data);
+	}
+
+	closedir(dir);
+	return ret ? false : true;
+}
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index 66864364ccb4..11d977db58a7 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -330,4 +330,5 @@ void mem_bswap_64(void *src, int byte_size);
 void mem_bswap_32(void *src, int byte_size);
 
 const char *get_filename_for_perf_kvm(void);
+bool find_process(const char *name);
 #endif /* GIT_COMPAT_UTIL_H */
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] perf tools: Show better error message in case we fail to open counters due to EBUSY error
  2014-08-01 15:46 [PATCH] perf tools: Show better error message in case we fail to open counters due to EBUSY error Jiri Olsa
@ 2014-08-02 17:58 ` Yann Droneaud
  2014-08-03 12:10   ` [PATCH] perf tools: Fix PERF_FLAG_FD_CLOEXEC flag probing event type " Jiri Olsa
  2014-08-02 18:13 ` [PATCH] perf tools: report PERF_FLAG_FD_CLOEXEC probing error once Yann Droneaud
  2014-08-13  5:17 ` [tip:perf/core] perf tools: Show better error message in case we fail to open counters due to EBUSY error tip-bot for Jiri Olsa
  2 siblings, 1 reply; 8+ messages in thread
From: Yann Droneaud @ 2014-08-02 17:58 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: linux-kernel, Adrian Hunter, Arnaldo Carvalho de Melo,
	David Ahern, Frederic Weisbecker, Namhyung Kim, Paul Mackerras,
	Peter Zijlstra, Stephane Eranian, William Cohen, ydroneaud

Hi Jiri,

Le vendredi 01 août 2014 à 17:46 +0200, Jiri Olsa a écrit :
> Showing better error message in case we fail to open
> counters due to the EBUSY error. If we detect oprofile
> daemon process running, we now display following message
> for EBUSY error:
> 
>   $ perf record ls
>   Error:
>   The PMU counters are busy/taken by another profiler.
>   We found oprofile daemon running, please stop it and try again.
> 
> In case oprofiled was not detected the current error
> message stays:
> 
>   $ perf record ls
>   Error:
>   The sys_perf_event_open() syscall returned with 16 (Device or resource busy) for event (cycles).
>   /bin/dmesg may provide additional information.
>   No CONFIG_PERF_EVENTS=y kernel support configured?
> 
> Also changing PERF_FLAG_FD_CLOEXEC detection code not to display
> error in case of EBUSY error, as it currently does:
> 
>   $ perf record ls
>   Error:
>   perf_event_open(..., PERF_FLAG_FD_CLOEXEC) failed with unexpected error 16 (Device or resource busy)
>   perf_event_open(..., 0) failed unexpectedly with error 16 (Device or resource busy)
>   The PMU counters are busy/taken by another profiler.
>   We found oprofile daemon running, please stop it and try again.
> 
> Cc: Adrian Hunter <adrian.hunter@intel.com>
> Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
> Cc: David Ahern <dsahern@gmail.com>
> Cc: Frederic Weisbecker <fweisbec@gmail.com>
> Cc: Namhyung Kim <namhyung@gmail.com>
> Cc: Paul Mackerras <paulus@samba.org>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Stephane Eranian <eranian@google.com>
> Cc: William Cohen <wcohen@redhat.com>
> Cc: Yann Droneaud <ydroneaud@opteya.com>
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> ---
>  tools/perf/util/cloexec.c |  4 ++--
>  tools/perf/util/evsel.c   |  6 ++++++
>  tools/perf/util/util.c    | 36 ++++++++++++++++++++++++++++++++++++
>  tools/perf/util/util.h    |  1 +
>  4 files changed, 45 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/perf/util/cloexec.c b/tools/perf/util/cloexec.c
> index c5d05ec17220..dede0c388ed4 100644
> --- a/tools/perf/util/cloexec.c
> +++ b/tools/perf/util/cloexec.c
> @@ -25,7 +25,7 @@ static int perf_flag_probe(void)
>  		return 1;
>  	}
>  
> -	WARN_ONCE(err != EINVAL,
> +	WARN_ONCE(err != EINVAL && err != EBUSY,
>  		  "perf_event_open(..., PERF_FLAG_FD_CLOEXEC) failed with unexpected error %d (%s)\n",
>  		  err, strerror(err));
>  
> @@ -33,7 +33,7 @@ static int perf_flag_probe(void)
>  	fd = sys_perf_event_open(&attr, 0, -1, -1, 0);
>  	err = errno;
>  
> -	if (WARN_ONCE(fd < 0,
> +	if (WARN_ONCE(fd < 0 && err != EBUSY,
>  		      "perf_event_open(..., 0) failed unexpectedly with error %d (%s)\n",
>  		      err, strerror(err)))
>  		return -1;

It's definitely possible to shortcut the function if EBUSY is returned
by first call to perf_event_open().

diff --git a/tools/perf/util/cloexec.c b/tools/perf/util/cloexec.c
index dc360ebde745..d5c626d5432a 100644
--- a/tools/perf/util/cloexec.c
+++ b/tools/perf/util/cloexec.c
@@ -25,6 +25,9 @@ static int perf_flag_probe(void)
 		return 1;
 	}
 
+	if (err == EBUSY)
+		return -1;
+
 	WARN_ONCE(err != EINVAL,
 		  "perf_event_open(..., PERF_FLAG_FD_CLOEXEC) failed with unexpected error %d (%s)\n",
 		  err, strerror(err));


BTW, I'm going to submit a patch to make the function report such 
warning only once.

Regards.

-- 
Yann Droneaud
OPTEYA



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH] perf tools: report PERF_FLAG_FD_CLOEXEC probing error once
  2014-08-01 15:46 [PATCH] perf tools: Show better error message in case we fail to open counters due to EBUSY error Jiri Olsa
  2014-08-02 17:58 ` Yann Droneaud
@ 2014-08-02 18:13 ` Yann Droneaud
  2014-08-03 12:12   ` Jiri Olsa
  2014-08-13  5:17 ` [tip:perf/core] perf tools: Show better error message in case we fail to open counters due to EBUSY error tip-bot for Jiri Olsa
  2 siblings, 1 reply; 8+ messages in thread
From: Yann Droneaud @ 2014-08-02 18:13 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Yann Droneaud, linux-kernel, Andi Kleen,
	Arnaldo Carvalho de Melo, Ingo Molnar, Peter Zijlstra,
	Paul Mackerras, Adrian Hunter, David Ahern, Frederic Weisbecker,
	Namhyung Kim, Stephane Eranian, William Cohen

In case of failure, unrelated to PERF_FLAG_FD_CLOEXEC,
perf_flag_probe() reports the error twice. For example:

  $ perf record ls
  Error:
  perf_event_open(..., PERF_FLAG_FD_CLOEXEC) failed with unexpected error 16 (Device or resource busy)
  perf_event_open(..., 0) failed unexpectedly with error 16 (Device or resource busy)
  The PMU counters are busy/taken by another profiler.
  We found oprofile daemon running, please stop it and try again.

This patch changes the function to only report a second
error message when the two calls to perf_even_open(2)
fail with different error codes.

Cc: Andi Kleen <ak@linux.intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: William Cohen <wcohen@redhat.com>
Link: http://lkml.kernel.org/r/1406908014-8312-1-git-send-email-jolsa@kernel.org
Reported-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Yann Droneaud <ydroneaud@opteya.com>
---
 tools/perf/util/cloexec.c | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/tools/perf/util/cloexec.c b/tools/perf/util/cloexec.c
index c5d05ec17220..dc360ebde745 100644
--- a/tools/perf/util/cloexec.c
+++ b/tools/perf/util/cloexec.c
@@ -13,34 +13,36 @@ static int perf_flag_probe(void)
 		.config = PERF_COUNT_SW_CPU_CLOCK,
 	};
 	int fd;
-	int err;
+	int err0, err1;
 
 	/* check cloexec flag */
 	fd = sys_perf_event_open(&attr, 0, -1, -1,
 				 PERF_FLAG_FD_CLOEXEC);
-	err = errno;
+	err0 = errno;
 
 	if (fd >= 0) {
 		close(fd);
 		return 1;
 	}
 
-	WARN_ONCE(err != EINVAL,
+	WARN_ONCE(err0 != EINVAL,
 		  "perf_event_open(..., PERF_FLAG_FD_CLOEXEC) failed with unexpected error %d (%s)\n",
-		  err, strerror(err));
+		  err0, strerror(err0));
 
 	/* not supported, confirm error related to PERF_FLAG_FD_CLOEXEC */
 	fd = sys_perf_event_open(&attr, 0, -1, -1, 0);
-	err = errno;
+	err1 = errno;
 
-	if (WARN_ONCE(fd < 0,
-		      "perf_event_open(..., 0) failed unexpectedly with error %d (%s)\n",
-		      err, strerror(err)))
-		return -1;
+	if (fd >= 0) {
+		close(fd);
+		return 0;
+	}
 
-	close(fd);
+	WARN_ONCE(err0 != err1,
+		  "perf_event_open(..., 0) failed unexpectedly with error %d (%s)\n",
+		  err1, strerror(err1));
 
-	return 0;
+	return -1;
 }
 
 unsigned long perf_event_open_cloexec_flag(void)
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH] perf tools: Fix PERF_FLAG_FD_CLOEXEC flag probing event type open counters due to EBUSY error
  2014-08-02 17:58 ` Yann Droneaud
@ 2014-08-03 12:10   ` Jiri Olsa
  2014-08-06 10:00     ` Yann Droneaud
  2014-08-13  5:19     ` [tip:perf/core] " tip-bot for Jiri Olsa
  0 siblings, 2 replies; 8+ messages in thread
From: Jiri Olsa @ 2014-08-03 12:10 UTC (permalink / raw)
  To: Yann Droneaud
  Cc: Jiri Olsa, linux-kernel, Adrian Hunter, Arnaldo Carvalho de Melo,
	David Ahern, Frederic Weisbecker, Namhyung Kim, Paul Mackerras,
	Peter Zijlstra, Stephane Eranian, William Cohen

On Sat, Aug 02, 2014 at 07:58:25PM +0200, Yann Droneaud wrote:
> Hi Jiri,

SNIP

> >  	err = errno;
> >  
> > -	if (WARN_ONCE(fd < 0,
> > +	if (WARN_ONCE(fd < 0 && err != EBUSY,
> >  		      "perf_event_open(..., 0) failed unexpectedly with error %d (%s)\n",
> >  		      err, strerror(err)))
> >  		return -1;
> 
> It's definitely possible to shortcut the function if EBUSY is returned
> by first call to perf_event_open().
> 
> diff --git a/tools/perf/util/cloexec.c b/tools/perf/util/cloexec.c
> index dc360ebde745..d5c626d5432a 100644
> --- a/tools/perf/util/cloexec.c
> +++ b/tools/perf/util/cloexec.c
> @@ -25,6 +25,9 @@ static int perf_flag_probe(void)
>  		return 1;
>  	}
>  
> +	if (err == EBUSY)
> +		return -1;
> +
>  	WARN_ONCE(err != EINVAL,
>  		  "perf_event_open(..., PERF_FLAG_FD_CLOEXEC) failed with unexpected error %d (%s)\n",
>  		  err, strerror(err));

heh, I haven't realized that your probing event was
PERF_COUNT_SW_CPU_CLOCK, which could never be busy
and found following bug ;-)

jirka


---
We were using PERF_COUNT_SW_CPU_CLOCK as an probing event type.
Using expected PERF_TYPE_SOFTWARE type instead.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: William Cohen <wcohen@redhat.com>
Cc: Yann Droneaud <ydroneaud@opteya.com>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/util/cloexec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/util/cloexec.c b/tools/perf/util/cloexec.c
index dc360ebde745..0f7eb0a53d4b 100644
--- a/tools/perf/util/cloexec.c
+++ b/tools/perf/util/cloexec.c
@@ -9,7 +9,7 @@ static int perf_flag_probe(void)
 {
 	/* use 'safest' configuration as used in perf_evsel__fallback() */
 	struct perf_event_attr attr = {
-		.type = PERF_COUNT_SW_CPU_CLOCK,
+		.type = PERF_TYPE_SOFTWARE,
 		.config = PERF_COUNT_SW_CPU_CLOCK,
 	};
 	int fd;
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] perf tools: report PERF_FLAG_FD_CLOEXEC probing error once
  2014-08-02 18:13 ` [PATCH] perf tools: report PERF_FLAG_FD_CLOEXEC probing error once Yann Droneaud
@ 2014-08-03 12:12   ` Jiri Olsa
  0 siblings, 0 replies; 8+ messages in thread
From: Jiri Olsa @ 2014-08-03 12:12 UTC (permalink / raw)
  To: Yann Droneaud
  Cc: Jiri Olsa, linux-kernel, Andi Kleen, Arnaldo Carvalho de Melo,
	Ingo Molnar, Peter Zijlstra, Paul Mackerras, Adrian Hunter,
	David Ahern, Frederic Weisbecker, Namhyung Kim, Stephane Eranian,
	William Cohen

On Sat, Aug 02, 2014 at 08:13:22PM +0200, Yann Droneaud wrote:
> In case of failure, unrelated to PERF_FLAG_FD_CLOEXEC,
> perf_flag_probe() reports the error twice. For example:
> 
>   $ perf record ls
>   Error:
>   perf_event_open(..., PERF_FLAG_FD_CLOEXEC) failed with unexpected error 16 (Device or resource busy)
>   perf_event_open(..., 0) failed unexpectedly with error 16 (Device or resource busy)

seems ok,
but since your patch is not based on my other patch,
please provide the changelog perf out without it

---
>   The PMU counters are busy/taken by another profiler.
>   We found oprofile daemon running, please stop it and try again.
---

also, please provide both before and after outputs
I'll queue it up with those other 2 patches

thanks,
jirka

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] perf tools: Fix PERF_FLAG_FD_CLOEXEC flag probing event type open counters due to EBUSY error
  2014-08-03 12:10   ` [PATCH] perf tools: Fix PERF_FLAG_FD_CLOEXEC flag probing event type " Jiri Olsa
@ 2014-08-06 10:00     ` Yann Droneaud
  2014-08-13  5:19     ` [tip:perf/core] " tip-bot for Jiri Olsa
  1 sibling, 0 replies; 8+ messages in thread
From: Yann Droneaud @ 2014-08-06 10:00 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Jiri Olsa, linux-kernel, Adrian Hunter, Arnaldo Carvalho de Melo,
	David Ahern, Frederic Weisbecker, Namhyung Kim, Paul Mackerras,
	Peter Zijlstra, Stephane Eranian, William Cohen, Yann Droneaud

Hi,

Le dimanche 03 août 2014 à 14:10 +0200, Jiri Olsa a écrit :
> On Sat, Aug 02, 2014 at 07:58:25PM +0200, Yann Droneaud wrote:

> heh, I haven't realized that your probing event was
> PERF_COUNT_SW_CPU_CLOCK, which could never be busy
> and found following bug ;-)
> 
> jirka
> 
> 
> ---
> We were using PERF_COUNT_SW_CPU_CLOCK as an probing event type.
> Using expected PERF_TYPE_SOFTWARE type instead.
> 
> Cc: Adrian Hunter <adrian.hunter@intel.com>
> Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
> Cc: David Ahern <dsahern@gmail.com>
> Cc: Frederic Weisbecker <fweisbec@gmail.com>
> Cc: Namhyung Kim <namhyung@gmail.com>
> Cc: Paul Mackerras <paulus@samba.org>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Stephane Eranian <eranian@google.com>
> Cc: William Cohen <wcohen@redhat.com>
> Cc: Yann Droneaud <ydroneaud@opteya.com>
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> ---
>  tools/perf/util/cloexec.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tools/perf/util/cloexec.c b/tools/perf/util/cloexec.c
> index dc360ebde745..0f7eb0a53d4b 100644
> --- a/tools/perf/util/cloexec.c
> +++ b/tools/perf/util/cloexec.c
> @@ -9,7 +9,7 @@ static int perf_flag_probe(void)
>  {
>  	/* use 'safest' configuration as used in perf_evsel__fallback() */
>  	struct perf_event_attr attr = {
> -		.type = PERF_COUNT_SW_CPU_CLOCK,
> +		.type = PERF_TYPE_SOFTWARE,
>  		.config = PERF_COUNT_SW_CPU_CLOCK,

erf ... I was even not able to copy paste correctly the configuration
used in perf_evsel__fallback(), my bad.

Thanks for the fix.

Regards.

-- 
Yann Droneaud
OPTEYA




^ permalink raw reply	[flat|nested] 8+ messages in thread

* [tip:perf/core] perf tools: Show better error message in case we fail to open counters due to EBUSY error
  2014-08-01 15:46 [PATCH] perf tools: Show better error message in case we fail to open counters due to EBUSY error Jiri Olsa
  2014-08-02 17:58 ` Yann Droneaud
  2014-08-02 18:13 ` [PATCH] perf tools: report PERF_FLAG_FD_CLOEXEC probing error once Yann Droneaud
@ 2014-08-13  5:17 ` tip-bot for Jiri Olsa
  2 siblings, 0 replies; 8+ messages in thread
From: tip-bot for Jiri Olsa @ 2014-08-13  5:17 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: acme, linux-kernel, eranian, paulus, hpa, mingo, jolsa, peterz,
	ydroneaud, namhyung, wcohen, fweisbec, adrian.hunter, dsahern,
	tglx

Commit-ID:  63914aca8f7e7a75d0ee027af7b1755c69cc1e2c
Gitweb:     http://git.kernel.org/tip/63914aca8f7e7a75d0ee027af7b1755c69cc1e2c
Author:     Jiri Olsa <jolsa@kernel.org>
AuthorDate: Fri, 1 Aug 2014 17:46:54 +0200
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Tue, 12 Aug 2014 12:03:02 -0300

perf tools: Show better error message in case we fail to open counters due to EBUSY error

Showing better error message in case we fail to open counters due to the
EBUSY error. If we detect oprofile daemon process running, we now
display following message for EBUSY error:

  $ perf record ls
  Error:
  The PMU counters are busy/taken by another profiler.
  We found oprofile daemon running, please stop it and try again.

In case oprofiled was not detected the current error message stays:

  $ perf record ls
  Error:
  The sys_perf_event_open() syscall returned with 16 (Device or resource busy) for event (cycles).
  /bin/dmesg may provide additional information.
  No CONFIG_PERF_EVENTS=y kernel support configured?

Also changing PERF_FLAG_FD_CLOEXEC detection code not to display error
in case of EBUSY error, as it currently does:

  $ perf record ls
  Error:
  perf_event_open(..., PERF_FLAG_FD_CLOEXEC) failed with unexpected error 16 (Device or resource busy)
  perf_event_open(..., 0) failed unexpectedly with error 16 (Device or resource busy)
  The PMU counters are busy/taken by another profiler.
  We found oprofile daemon running, please stop it and try again.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: William Cohen <wcohen@redhat.com>
Cc: Yann Droneaud <ydroneaud@opteya.com>
Link: http://lkml.kernel.org/r/1406908014-8312-1-git-send-email-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/cloexec.c |  4 ++--
 tools/perf/util/evsel.c   |  6 ++++++
 tools/perf/util/util.c    | 36 ++++++++++++++++++++++++++++++++++++
 tools/perf/util/util.h    |  1 +
 4 files changed, 45 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/cloexec.c b/tools/perf/util/cloexec.c
index c5d05ec..dede0c3 100644
--- a/tools/perf/util/cloexec.c
+++ b/tools/perf/util/cloexec.c
@@ -25,7 +25,7 @@ static int perf_flag_probe(void)
 		return 1;
 	}
 
-	WARN_ONCE(err != EINVAL,
+	WARN_ONCE(err != EINVAL && err != EBUSY,
 		  "perf_event_open(..., PERF_FLAG_FD_CLOEXEC) failed with unexpected error %d (%s)\n",
 		  err, strerror(err));
 
@@ -33,7 +33,7 @@ static int perf_flag_probe(void)
 	fd = sys_perf_event_open(&attr, 0, -1, -1, 0);
 	err = errno;
 
-	if (WARN_ONCE(fd < 0,
+	if (WARN_ONCE(fd < 0 && err != EBUSY,
 		      "perf_event_open(..., 0) failed unexpectedly with error %d (%s)\n",
 		      err, strerror(err)))
 		return -1;
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 92e5235..0c8919d 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -2039,6 +2039,12 @@ int perf_evsel__open_strerror(struct perf_evsel *evsel, struct target *target,
 	"No APIC? If so then you can boot the kernel with the \"lapic\" boot parameter to force-enable it.");
 #endif
 		break;
+	case EBUSY:
+		if (find_process("oprofiled"))
+			return scnprintf(msg, size,
+	"The PMU counters are busy/taken by another profiler.\n"
+	"We found oprofile daemon running, please stop it and try again.");
+		break;
 	default:
 		break;
 	}
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c
index e52e746..b82a93c 100644
--- a/tools/perf/util/util.c
+++ b/tools/perf/util/util.c
@@ -536,3 +536,39 @@ void mem_bswap_64(void *src, int byte_size)
 		++m;
 	}
 }
+
+bool find_process(const char *name)
+{
+	size_t len = strlen(name);
+	DIR *dir;
+	struct dirent *d;
+	int ret = -1;
+
+	dir = opendir(procfs__mountpoint());
+	if (!dir)
+		return -1;
+
+	/* Walk through the directory. */
+	while (ret && (d = readdir(dir)) != NULL) {
+		char path[PATH_MAX];
+		char *data;
+		size_t size;
+
+		if ((d->d_type != DT_DIR) ||
+		     !strcmp(".", d->d_name) ||
+		     !strcmp("..", d->d_name))
+			continue;
+
+		scnprintf(path, sizeof(path), "%s/%s/comm",
+			  procfs__mountpoint(), d->d_name);
+
+		if (filename__read_str(path, &data, &size))
+			continue;
+
+		ret = strncmp(name, data, len);
+		free(data);
+	}
+
+	closedir(dir);
+	return ret ? false : true;
+}
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index 38af775..03a1ea2 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -346,4 +346,5 @@ void mem_bswap_64(void *src, int byte_size);
 void mem_bswap_32(void *src, int byte_size);
 
 const char *get_filename_for_perf_kvm(void);
+bool find_process(const char *name);
 #endif /* GIT_COMPAT_UTIL_H */

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [tip:perf/core] perf tools: Fix PERF_FLAG_FD_CLOEXEC flag probing event type open counters due to EBUSY error
  2014-08-03 12:10   ` [PATCH] perf tools: Fix PERF_FLAG_FD_CLOEXEC flag probing event type " Jiri Olsa
  2014-08-06 10:00     ` Yann Droneaud
@ 2014-08-13  5:19     ` tip-bot for Jiri Olsa
  1 sibling, 0 replies; 8+ messages in thread
From: tip-bot for Jiri Olsa @ 2014-08-13  5:19 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: acme, eranian, mingo, jolsa, peterz, ydroneaud, wcohen, jolsa,
	fweisbec, dsahern, tglx, hpa, paulus, linux-kernel, namhyung,
	adrian.hunter

Commit-ID:  038fa0b9739d7f375f3f61a2ce4f78ad44329f66
Gitweb:     http://git.kernel.org/tip/038fa0b9739d7f375f3f61a2ce4f78ad44329f66
Author:     Jiri Olsa <jolsa@redhat.com>
AuthorDate: Sun, 3 Aug 2014 14:10:36 +0200
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Tue, 12 Aug 2014 12:03:08 -0300

perf tools: Fix PERF_FLAG_FD_CLOEXEC flag probing event type open counters due to EBUSY error

We were using PERF_COUNT_SW_CPU_CLOCK as an probing event type.  Using
expected PERF_TYPE_SOFTWARE type instead.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: William Cohen <wcohen@redhat.com>
Cc: Yann Droneaud <ydroneaud@opteya.com>
Link: http://lkml.kernel.org/r/20140803121036.GA1181@krava.brq.redhat.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/cloexec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/util/cloexec.c b/tools/perf/util/cloexec.c
index dede0c3..5073c01 100644
--- a/tools/perf/util/cloexec.c
+++ b/tools/perf/util/cloexec.c
@@ -9,7 +9,7 @@ static int perf_flag_probe(void)
 {
 	/* use 'safest' configuration as used in perf_evsel__fallback() */
 	struct perf_event_attr attr = {
-		.type = PERF_COUNT_SW_CPU_CLOCK,
+		.type = PERF_TYPE_SOFTWARE,
 		.config = PERF_COUNT_SW_CPU_CLOCK,
 	};
 	int fd;

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2014-08-13  5:20 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-01 15:46 [PATCH] perf tools: Show better error message in case we fail to open counters due to EBUSY error Jiri Olsa
2014-08-02 17:58 ` Yann Droneaud
2014-08-03 12:10   ` [PATCH] perf tools: Fix PERF_FLAG_FD_CLOEXEC flag probing event type " Jiri Olsa
2014-08-06 10:00     ` Yann Droneaud
2014-08-13  5:19     ` [tip:perf/core] " tip-bot for Jiri Olsa
2014-08-02 18:13 ` [PATCH] perf tools: report PERF_FLAG_FD_CLOEXEC probing error once Yann Droneaud
2014-08-03 12:12   ` Jiri Olsa
2014-08-13  5:17 ` [tip:perf/core] perf tools: Show better error message in case we fail to open counters due to EBUSY error tip-bot for Jiri Olsa

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.