All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/6 v2] perf: Have perf become tracefs aware
@ 2015-02-02 19:35 Steven Rostedt
  2015-02-02 19:35 ` [PATCH 1/6 v2] perf: Do not check debugfs MAGIC for tracing files Steven Rostedt
                   ` (5 more replies)
  0 siblings, 6 replies; 18+ messages in thread
From: Steven Rostedt @ 2015-02-02 19:35 UTC (permalink / raw)
  To: linux-kernel
  Cc: Ingo Molnar, Andrew Morton, Jiri Olsa, Arnaldo Carvalho de Melo,
	Masami Hiramatsu, Namhyung Kim


As I'm trying to move the tracing directory from debugfs, perf needs to
be aware of this as system admins will now be able to mount the tracing
directory without needing to mount debugfs. This patch series addresses
this and makes perf aware of tracefs.

I based this series on a recent tip branch: perf/core.

You can also get this series from my repo as stated below.

Changes since v1:

 o Added a patch to nuke the debugfs_valid_mountpoint.
   Well, it doesn't totally nuke it. It still uses that function
   (static though) to test if the "default" debugfs locations may
   already contain a debugfs file system. I also have tracefs do the same.

 o Fixed setting of debugfs_found and tracefs_found

 o Moved STR macro and PATH_MAX macros from debugfs.h to findfs.h

 o Changed debugfs_configured() and tracefs_configured() to use
   find_mountpoint() to see if they are configured.

 o Fixed directory name (debugfs before "/tracing").

Internal SHA1: 42b3093519e049d12dfa02c230c10bfee14712b0


Steven Rostedt (Red Hat) (6):
      perf: Do not check debugfs MAGIC for tracing files
      tools lib fs: Add helper to find mounted file systems
      tools lib api fs: Add tracefs mount helper functions
      tools lib api fs: Add DEBUGFS_DEFAULT_PATH macro
      tools lib api fs: Add {tracefs,debugfs}_configured() functions
      perf: Make perf aware of tracefs

----
 tools/lib/api/Makefile                   |  4 ++
 tools/lib/api/fs/debugfs.c               | 69 +++++++++-------------------
 tools/lib/api/fs/debugfs.h               | 13 +-----
 tools/lib/api/fs/findfs.c                | 63 ++++++++++++++++++++++++++
 tools/lib/api/fs/findfs.h                | 23 ++++++++++
 tools/lib/api/fs/tracefs.c               | 78 ++++++++++++++++++++++++++++++++
 tools/lib/api/fs/tracefs.h               | 21 +++++++++
 tools/perf/tests/open-syscall-all-cpus.c |  7 ++-
 tools/perf/tests/open-syscall.c          |  7 ++-
 tools/perf/tests/parse-events.c          | 13 +++++-
 tools/perf/util/cache.h                  |  1 +
 tools/perf/util/evlist.c                 |  1 -
 tools/perf/util/parse-events.c           | 19 --------
 tools/perf/util/parse-events.h           |  2 +-
 tools/perf/util/probe-event.c            | 24 ++++++----
 tools/perf/util/util.c                   | 60 +++++++++++++++++++-----
 tools/perf/util/util.h                   |  1 +
 17 files changed, 304 insertions(+), 102 deletions(-)

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

* [PATCH 1/6 v2] perf: Do not check debugfs MAGIC for tracing files
  2015-02-02 19:35 [PATCH 0/6 v2] perf: Have perf become tracefs aware Steven Rostedt
@ 2015-02-02 19:35 ` Steven Rostedt
  2015-02-18 18:27   ` [tip:perf/core] perf tools: " tip-bot for Steven Rostedt (Red Hat)
  2015-02-02 19:35 ` [PATCH 2/6 v2] tools lib fs: Add helper to find mounted file systems Steven Rostedt
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 18+ messages in thread
From: Steven Rostedt @ 2015-02-02 19:35 UTC (permalink / raw)
  To: linux-kernel
  Cc: Ingo Molnar, Andrew Morton, Jiri Olsa, Arnaldo Carvalho de Melo,
	Masami Hiramatsu, Namhyung Kim

[-- Attachment #1: 0001-perf-Do-not-check-debugfs-MAGIC-for-tracing-files.patch --]
[-- Type: text/plain, Size: 3864 bytes --]

From: "Steven Rostedt (Red Hat)" <rostedt@goodmis.org>

It's rather strange to be checking the debugfs MAGIC number for the
tracing directory. A system admin may want to have a custom set of events
to trace and it should be allowed to let the admin make a temp file
(even for tracing virtual boxes, this is useful).

Also with the coming tracefs, the files may not even be under debugfs,
so checking the debugfs MAGIC number is pointless.

Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
 tools/lib/api/fs/debugfs.c     | 28 ++++++++++++++--------------
 tools/lib/api/fs/debugfs.h     |  1 -
 tools/perf/util/parse-events.c | 19 -------------------
 3 files changed, 14 insertions(+), 34 deletions(-)

diff --git a/tools/lib/api/fs/debugfs.c b/tools/lib/api/fs/debugfs.c
index d2b18e887071..d21d4d6b4fd2 100644
--- a/tools/lib/api/fs/debugfs.c
+++ b/tools/lib/api/fs/debugfs.c
@@ -20,6 +20,20 @@ static const char * const debugfs_known_mountpoints[] = {
 
 static bool debugfs_found;
 
+/* verify that a mountpoint is actually a debugfs instance */
+
+static int debugfs_valid_mountpoint(const char *debugfs)
+{
+	struct statfs st_fs;
+
+	if (statfs(debugfs, &st_fs) < 0)
+		return -ENOENT;
+	else if ((long)st_fs.f_type != (long)DEBUGFS_MAGIC)
+		return -ENOENT;
+
+	return 0;
+}
+
 /* find the path to the mounted debugfs */
 const char *debugfs_find_mountpoint(void)
 {
@@ -60,20 +74,6 @@ const char *debugfs_find_mountpoint(void)
 	return debugfs_mountpoint;
 }
 
-/* verify that a mountpoint is actually a debugfs instance */
-
-int debugfs_valid_mountpoint(const char *debugfs)
-{
-	struct statfs st_fs;
-
-	if (statfs(debugfs, &st_fs) < 0)
-		return -ENOENT;
-	else if ((long)st_fs.f_type != (long)DEBUGFS_MAGIC)
-		return -ENOENT;
-
-	return 0;
-}
-
 /* mount the debugfs somewhere if it's not mounted */
 char *debugfs_mount(const char *mountpoint)
 {
diff --git a/tools/lib/api/fs/debugfs.h b/tools/lib/api/fs/debugfs.h
index 0739881a9897..77bb36a95b07 100644
--- a/tools/lib/api/fs/debugfs.h
+++ b/tools/lib/api/fs/debugfs.h
@@ -21,7 +21,6 @@
 #endif
 
 const char *debugfs_find_mountpoint(void);
-int debugfs_valid_mountpoint(const char *debugfs);
 char *debugfs_mount(const char *mountpoint);
 
 extern char debugfs_mountpoint[];
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 7f8ec6ce2823..ecf069b1661f 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -175,9 +175,6 @@ struct tracepoint_path *tracepoint_id_to_path(u64 config)
 	char evt_path[MAXPATHLEN];
 	char dir_path[MAXPATHLEN];
 
-	if (debugfs_valid_mountpoint(tracing_events_path))
-		return NULL;
-
 	sys_dir = opendir(tracing_events_path);
 	if (!sys_dir)
 		return NULL;
@@ -473,12 +470,6 @@ static int add_tracepoint_multi_sys(struct list_head *list, int *idx,
 int parse_events_add_tracepoint(struct list_head *list, int *idx,
 				char *sys, char *event)
 {
-	int ret;
-
-	ret = debugfs_valid_mountpoint(tracing_events_path);
-	if (ret)
-		return ret;
-
 	if (strpbrk(sys, "*?"))
 		return add_tracepoint_multi_sys(list, idx, sys, event);
 	else
@@ -1109,13 +1100,6 @@ void print_tracepoint_events(const char *subsys_glob, const char *event_glob,
 	struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent;
 	char evt_path[MAXPATHLEN];
 	char dir_path[MAXPATHLEN];
-	char sbuf[STRERR_BUFSIZE];
-
-	if (debugfs_valid_mountpoint(tracing_events_path)) {
-		printf("  [ Tracepoints not available: %s ]\n",
-			strerror_r(errno, sbuf, sizeof(sbuf)));
-		return;
-	}
 
 	sys_dir = opendir(tracing_events_path);
 	if (!sys_dir)
@@ -1163,9 +1147,6 @@ int is_valid_tracepoint(const char *event_string)
 	char evt_path[MAXPATHLEN];
 	char dir_path[MAXPATHLEN];
 
-	if (debugfs_valid_mountpoint(tracing_events_path))
-		return 0;
-
 	sys_dir = opendir(tracing_events_path);
 	if (!sys_dir)
 		return 0;
-- 
2.1.4



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

* [PATCH 2/6 v2] tools lib fs: Add helper to find mounted file systems
  2015-02-02 19:35 [PATCH 0/6 v2] perf: Have perf become tracefs aware Steven Rostedt
  2015-02-02 19:35 ` [PATCH 1/6 v2] perf: Do not check debugfs MAGIC for tracing files Steven Rostedt
@ 2015-02-02 19:35 ` Steven Rostedt
  2015-02-18 18:28   ` [tip:perf/core] " tip-bot for Steven Rostedt (Red Hat)
  2015-02-02 19:35 ` [PATCH 3/6 v2] tools lib api fs: Add tracefs mount helper functions Steven Rostedt
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 18+ messages in thread
From: Steven Rostedt @ 2015-02-02 19:35 UTC (permalink / raw)
  To: linux-kernel
  Cc: Ingo Molnar, Andrew Morton, Jiri Olsa, Arnaldo Carvalho de Melo,
	Masami Hiramatsu, Namhyung Kim

[-- Attachment #1: 0002-tools-lib-fs-Add-helper-to-find-mounted-file-systems.patch --]
[-- Type: text/plain, Size: 5702 bytes --]

From: "Steven Rostedt (Red Hat)" <rostedt@goodmis.org>

In preparation for adding tracefs for perf to use, create a findfs
helper utility that find_debugfs uses instead of hard coding the search
in the code. This will allow for a find_tracefs to be used as well.

Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
 tools/lib/api/Makefile     |  2 ++
 tools/lib/api/fs/debugfs.c | 51 ++++++-------------------------------
 tools/lib/api/fs/debugfs.h | 11 +-------
 tools/lib/api/fs/findfs.c  | 63 ++++++++++++++++++++++++++++++++++++++++++++++
 tools/lib/api/fs/findfs.h  | 21 ++++++++++++++++
 5 files changed, 94 insertions(+), 54 deletions(-)
 create mode 100644 tools/lib/api/fs/findfs.c
 create mode 100644 tools/lib/api/fs/findfs.h

diff --git a/tools/lib/api/Makefile b/tools/lib/api/Makefile
index 36c08b1f4afb..22b2f15d7255 100644
--- a/tools/lib/api/Makefile
+++ b/tools/lib/api/Makefile
@@ -9,11 +9,13 @@ LIB_H=
 LIB_OBJS=
 
 LIB_H += fs/debugfs.h
+LIB_H += fs/findfs.h
 LIB_H += fs/fs.h
 # See comment below about piggybacking...
 LIB_H += fd/array.h
 
 LIB_OBJS += $(OUTPUT)fs/debugfs.o
+LIB_OBJS += $(OUTPUT)fs/findfs.o
 LIB_OBJS += $(OUTPUT)fs/fs.o
 # XXX piggybacking here, need to introduce libapikfd, or rename this
 # to plain libapik.a and make it have it all api goodies
diff --git a/tools/lib/api/fs/debugfs.c b/tools/lib/api/fs/debugfs.c
index d21d4d6b4fd2..91e1668348ce 100644
--- a/tools/lib/api/fs/debugfs.c
+++ b/tools/lib/api/fs/debugfs.c
@@ -20,58 +20,21 @@ static const char * const debugfs_known_mountpoints[] = {
 
 static bool debugfs_found;
 
-/* verify that a mountpoint is actually a debugfs instance */
-
-static int debugfs_valid_mountpoint(const char *debugfs)
-{
-	struct statfs st_fs;
-
-	if (statfs(debugfs, &st_fs) < 0)
-		return -ENOENT;
-	else if ((long)st_fs.f_type != (long)DEBUGFS_MAGIC)
-		return -ENOENT;
-
-	return 0;
-}
-
 /* find the path to the mounted debugfs */
 const char *debugfs_find_mountpoint(void)
 {
-	const char * const *ptr;
-	char type[100];
-	FILE *fp;
+	const char *ret;
 
 	if (debugfs_found)
 		return (const char *)debugfs_mountpoint;
 
-	ptr = debugfs_known_mountpoints;
-	while (*ptr) {
-		if (debugfs_valid_mountpoint(*ptr) == 0) {
-			debugfs_found = true;
-			strcpy(debugfs_mountpoint, *ptr);
-			return debugfs_mountpoint;
-		}
-		ptr++;
-	}
+	ret = find_mountpoint("debugfs", (long) DEBUGFS_MAGIC,
+			      debugfs_mountpoint, PATH_MAX + 1,
+			      debugfs_known_mountpoints);
+	if (ret)
+		debugfs_found = true;
 
-	/* give up and parse /proc/mounts */
-	fp = fopen("/proc/mounts", "r");
-	if (fp == NULL)
-		return NULL;
-
-	while (fscanf(fp, "%*s %" STR(PATH_MAX) "s %99s %*s %*d %*d\n",
-		      debugfs_mountpoint, type) == 2) {
-		if (strcmp(type, "debugfs") == 0)
-			break;
-	}
-	fclose(fp);
-
-	if (strcmp(type, "debugfs") != 0)
-		return NULL;
-
-	debugfs_found = true;
-
-	return debugfs_mountpoint;
+	return ret;
 }
 
 /* mount the debugfs somewhere if it's not mounted */
diff --git a/tools/lib/api/fs/debugfs.h b/tools/lib/api/fs/debugfs.h
index 77bb36a95b07..1074ac81358e 100644
--- a/tools/lib/api/fs/debugfs.h
+++ b/tools/lib/api/fs/debugfs.h
@@ -1,16 +1,7 @@
 #ifndef __API_DEBUGFS_H__
 #define __API_DEBUGFS_H__
 
-#define _STR(x) #x
-#define STR(x) _STR(x)
-
-/*
- * On most systems <limits.h> would have given us this, but  not on some systems
- * (e.g. GNU/Hurd).
- */
-#ifndef PATH_MAX
-#define PATH_MAX 4096
-#endif
+#include "findfs.h"
 
 #ifndef DEBUGFS_MAGIC
 #define DEBUGFS_MAGIC          0x64626720
diff --git a/tools/lib/api/fs/findfs.c b/tools/lib/api/fs/findfs.c
new file mode 100644
index 000000000000..49946cb6d7af
--- /dev/null
+++ b/tools/lib/api/fs/findfs.c
@@ -0,0 +1,63 @@
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdbool.h>
+#include <sys/vfs.h>
+
+#include "findfs.h"
+
+/* verify that a mountpoint is actually the type we want */
+
+int valid_mountpoint(const char *mount, long magic)
+{
+	struct statfs st_fs;
+
+	if (statfs(mount, &st_fs) < 0)
+		return -ENOENT;
+	else if ((long)st_fs.f_type != magic)
+		return -ENOENT;
+
+	return 0;
+}
+
+/* find the path to a mounted file system */
+const char *find_mountpoint(const char *fstype, long magic,
+			    char *mountpoint, int len,
+			    const char * const *known_mountpoints)
+{
+	const char * const *ptr;
+	char format[128];
+	char type[100];
+	FILE *fp;
+
+	if (known_mountpoints) {
+		ptr = known_mountpoints;
+		while (*ptr) {
+			if (valid_mountpoint(*ptr, magic) == 0) {
+				strncpy(mountpoint, *ptr, len - 1);
+				mountpoint[len-1] = 0;
+				return mountpoint;
+			}
+			ptr++;
+		}
+	}
+
+	/* give up and parse /proc/mounts */
+	fp = fopen("/proc/mounts", "r");
+	if (fp == NULL)
+		return NULL;
+
+	snprintf(format, 128, "%%*s %%%ds %%99s %%*s %%*d %%*d\n", len);
+
+	while (fscanf(fp, format, mountpoint, type) == 2) {
+		if (strcmp(type, fstype) == 0)
+			break;
+	}
+	fclose(fp);
+
+	if (strcmp(type, fstype) != 0)
+		return NULL;
+
+	return mountpoint;
+}
diff --git a/tools/lib/api/fs/findfs.h b/tools/lib/api/fs/findfs.h
new file mode 100644
index 000000000000..9e7d876791e1
--- /dev/null
+++ b/tools/lib/api/fs/findfs.h
@@ -0,0 +1,21 @@
+#ifndef __API_FINDFS_H__
+#define __API_FINDFS_H__
+
+#define _STR(x) #x
+#define STR(x) _STR(x)
+
+/*
+ * On most systems <limits.h> would have given us this, but  not on some systems
+ * (e.g. GNU/Hurd).
+ */
+#ifndef PATH_MAX
+#define PATH_MAX 4096
+#endif
+
+const char *find_mountpoint(const char *fstype, long magic,
+			    char *mountpoint, int len,
+			    const char * const *known_mountpoints);
+
+int valid_mountpoint(const char *mount, long magic);
+
+#endif /* __API_FINDFS_H__ */
-- 
2.1.4



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

* [PATCH 3/6 v2] tools lib api fs: Add tracefs mount helper functions
  2015-02-02 19:35 [PATCH 0/6 v2] perf: Have perf become tracefs aware Steven Rostedt
  2015-02-02 19:35 ` [PATCH 1/6 v2] perf: Do not check debugfs MAGIC for tracing files Steven Rostedt
  2015-02-02 19:35 ` [PATCH 2/6 v2] tools lib fs: Add helper to find mounted file systems Steven Rostedt
@ 2015-02-02 19:35 ` Steven Rostedt
  2015-02-18 18:28   ` [tip:perf/core] " tip-bot for Steven Rostedt (Red Hat)
  2015-02-02 19:35 ` [PATCH 4/6 v2] tools lib api fs: Add DEBUGFS_DEFAULT_PATH macro Steven Rostedt
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 18+ messages in thread
From: Steven Rostedt @ 2015-02-02 19:35 UTC (permalink / raw)
  To: linux-kernel
  Cc: Ingo Molnar, Andrew Morton, Jiri Olsa, Arnaldo Carvalho de Melo,
	Masami Hiramatsu, Namhyung Kim

[-- Attachment #1: 0003-tools-lib-api-fs-Add-tracefs-mount-helper-functions.patch --]
[-- Type: text/plain, Size: 3791 bytes --]

From: "Steven Rostedt (Red Hat)" <rostedt@goodmis.org>

Since tracefs will now hold the event directory for perf, and
even though by default, debugfs still mounts tracefs on the
debugfs/tracing directory, the system admin may now choose to not
mount debugfs and instead just mount tracefs instead.

Having tracefs helper functions will facilitate having perf look
for tracefs first, and then try debugfs as a fallback.

Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
 tools/lib/api/Makefile     |  2 ++
 tools/lib/api/fs/tracefs.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++
 tools/lib/api/fs/tracefs.h | 20 +++++++++++++
 3 files changed, 92 insertions(+)
 create mode 100644 tools/lib/api/fs/tracefs.c
 create mode 100644 tools/lib/api/fs/tracefs.h

diff --git a/tools/lib/api/Makefile b/tools/lib/api/Makefile
index 22b2f15d7255..212aa4fd65a0 100644
--- a/tools/lib/api/Makefile
+++ b/tools/lib/api/Makefile
@@ -9,12 +9,14 @@ LIB_H=
 LIB_OBJS=
 
 LIB_H += fs/debugfs.h
+LIB_H += fs/tracefs.h
 LIB_H += fs/findfs.h
 LIB_H += fs/fs.h
 # See comment below about piggybacking...
 LIB_H += fd/array.h
 
 LIB_OBJS += $(OUTPUT)fs/debugfs.o
+LIB_OBJS += $(OUTPUT)fs/tracefs.o
 LIB_OBJS += $(OUTPUT)fs/findfs.o
 LIB_OBJS += $(OUTPUT)fs/fs.o
 # XXX piggybacking here, need to introduce libapikfd, or rename this
diff --git a/tools/lib/api/fs/tracefs.c b/tools/lib/api/fs/tracefs.c
new file mode 100644
index 000000000000..ef40d15821e9
--- /dev/null
+++ b/tools/lib/api/fs/tracefs.c
@@ -0,0 +1,70 @@
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdbool.h>
+#include <sys/vfs.h>
+#include <sys/mount.h>
+#include <linux/kernel.h>
+
+#include "tracefs.h"
+
+#ifndef TRACEFS_DEFAULT_PATH
+#define TRACEFS_DEFAULT_PATH		"/sys/kernel/tracing"
+#endif
+
+char tracefs_mountpoint[PATH_MAX + 1] = TRACEFS_DEFAULT_PATH;
+
+static const char * const tracefs_known_mountpoints[] = {
+	TRACEFS_DEFAULT_PATH,
+	"/sys/kernel/debug/tracing",
+	"/tracing",
+	"/trace",
+	0,
+};
+
+static bool tracefs_found;
+
+/* find the path to the mounted tracefs */
+const char *tracefs_find_mountpoint(void)
+{
+	const char *ret;
+
+	if (tracefs_found)
+		return (const char *)tracefs_mountpoint;
+
+	ret = find_mountpoint("tracefs", (long) TRACEFS_MAGIC,
+			      tracefs_mountpoint, PATH_MAX + 1,
+			      tracefs_known_mountpoints);
+
+	if (ret)
+		tracefs_found = true;
+
+	return ret;
+}
+
+/* mount the tracefs somewhere if it's not mounted */
+char *tracefs_mount(const char *mountpoint)
+{
+	/* see if it's already mounted */
+	if (tracefs_find_mountpoint())
+		goto out;
+
+	/* if not mounted and no argument */
+	if (mountpoint == NULL) {
+		/* see if environment variable set */
+		mountpoint = getenv(PERF_TRACEFS_ENVIRONMENT);
+		/* if no environment variable, use default */
+		if (mountpoint == NULL)
+			mountpoint = TRACEFS_DEFAULT_PATH;
+	}
+
+	if (mount(NULL, mountpoint, "tracefs", 0, NULL) < 0)
+		return NULL;
+
+	/* save the mountpoint */
+	tracefs_found = true;
+	strncpy(tracefs_mountpoint, mountpoint, sizeof(tracefs_mountpoint));
+out:
+	return tracefs_mountpoint;
+}
diff --git a/tools/lib/api/fs/tracefs.h b/tools/lib/api/fs/tracefs.h
new file mode 100644
index 000000000000..e6f7f5183c87
--- /dev/null
+++ b/tools/lib/api/fs/tracefs.h
@@ -0,0 +1,20 @@
+#ifndef __API_TRACEFS_H__
+#define __API_TRACEFS_H__
+
+#include "findfs.h"
+
+#ifndef TRACEFS_MAGIC
+#define TRACEFS_MAGIC          0x74726163
+#endif
+
+#ifndef PERF_TRACEFS_ENVIRONMENT
+#define PERF_TRACEFS_ENVIRONMENT "PERF_TRACEFS_DIR"
+#endif
+
+const char *tracefs_find_mountpoint(void);
+int tracefs_valid_mountpoint(const char *debugfs);
+char *tracefs_mount(const char *mountpoint);
+
+extern char tracefs_mountpoint[];
+
+#endif /* __API_DEBUGFS_H__ */
-- 
2.1.4



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

* [PATCH 4/6 v2] tools lib api fs: Add DEBUGFS_DEFAULT_PATH macro
  2015-02-02 19:35 [PATCH 0/6 v2] perf: Have perf become tracefs aware Steven Rostedt
                   ` (2 preceding siblings ...)
  2015-02-02 19:35 ` [PATCH 3/6 v2] tools lib api fs: Add tracefs mount helper functions Steven Rostedt
@ 2015-02-02 19:35 ` Steven Rostedt
  2015-02-18 18:28   ` [tip:perf/core] tools lib api debugfs: " tip-bot for Steven Rostedt (Red Hat)
  2015-02-02 19:35 ` [PATCH 5/6 v2] tools lib api fs: Add {tracefs,debugfs}_configured() functions Steven Rostedt
  2015-02-02 19:35 ` [PATCH 6/6 v2] perf: Make perf aware of tracefs Steven Rostedt
  5 siblings, 1 reply; 18+ messages in thread
From: Steven Rostedt @ 2015-02-02 19:35 UTC (permalink / raw)
  To: linux-kernel
  Cc: Ingo Molnar, Andrew Morton, Jiri Olsa, Arnaldo Carvalho de Melo,
	Masami Hiramatsu, Namhyung Kim

[-- Attachment #1: 0004-tools-lib-api-fs-Add-DEBUGFS_DEFAULT_PATH-macro.patch --]
[-- Type: text/plain, Size: 1220 bytes --]

From: "Steven Rostedt (Red Hat)" <rostedt@goodmis.org>

Instead of hard coding "/sys/kernel/debug" everywhere, create
a macro to hold where the default path exists.

Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
 tools/lib/api/fs/debugfs.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/tools/lib/api/fs/debugfs.c b/tools/lib/api/fs/debugfs.c
index 91e1668348ce..07d74b03d828 100644
--- a/tools/lib/api/fs/debugfs.c
+++ b/tools/lib/api/fs/debugfs.c
@@ -10,10 +10,14 @@
 
 #include "debugfs.h"
 
-char debugfs_mountpoint[PATH_MAX + 1] = "/sys/kernel/debug";
+#ifndef DEBUGFS_DEFAULT_PATH
+#define DEBUGFS_DEFAULT_PATH		"/sys/kernel/debug"
+#endif
+
+char debugfs_mountpoint[PATH_MAX + 1] = DEBUGFS_DEFAULT_PATH;
 
 static const char * const debugfs_known_mountpoints[] = {
-	"/sys/kernel/debug",
+	DEBUGFS_DEFAULT_PATH,
 	"/debug",
 	0,
 };
@@ -50,7 +54,7 @@ char *debugfs_mount(const char *mountpoint)
 		mountpoint = getenv(PERF_DEBUGFS_ENVIRONMENT);
 		/* if no environment variable, use default */
 		if (mountpoint == NULL)
-			mountpoint = "/sys/kernel/debug";
+			mountpoint = DEBUGFS_DEFAULT_PATH;
 	}
 
 	if (mount(NULL, mountpoint, "debugfs", 0, NULL) < 0)
-- 
2.1.4



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

* [PATCH 5/6 v2] tools lib api fs: Add {tracefs,debugfs}_configured() functions
  2015-02-02 19:35 [PATCH 0/6 v2] perf: Have perf become tracefs aware Steven Rostedt
                   ` (3 preceding siblings ...)
  2015-02-02 19:35 ` [PATCH 4/6 v2] tools lib api fs: Add DEBUGFS_DEFAULT_PATH macro Steven Rostedt
@ 2015-02-02 19:35 ` Steven Rostedt
  2015-02-18 18:29   ` [tip:perf/core] tools lib api fs: Add {tracefs, debugfs}_configured() functions tip-bot for Steven Rostedt (Red Hat)
  2015-02-02 19:35 ` [PATCH 6/6 v2] perf: Make perf aware of tracefs Steven Rostedt
  5 siblings, 1 reply; 18+ messages in thread
From: Steven Rostedt @ 2015-02-02 19:35 UTC (permalink / raw)
  To: linux-kernel
  Cc: Ingo Molnar, Andrew Morton, Jiri Olsa, Arnaldo Carvalho de Melo,
	Masami Hiramatsu, Namhyung Kim

[-- Attachment #1: 0005-tools-lib-api-fs-Add-tracefs-debugfs-_configured-fun.patch --]
[-- Type: text/plain, Size: 3068 bytes --]

From: "Steven Rostedt (Red Hat)" <rostedt@goodmis.org>

Add tracefs_configured() to return true if tracefs is configured in the
kernel (succeeds to find tracefs), and debugfs_configured() if debugfs is
configured in the kernel (succeeds to find debugfs).

Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
 tools/lib/api/fs/debugfs.c | 8 ++++++++
 tools/lib/api/fs/debugfs.h | 1 +
 tools/lib/api/fs/findfs.h  | 2 ++
 tools/lib/api/fs/tracefs.c | 8 ++++++++
 tools/lib/api/fs/tracefs.h | 1 +
 5 files changed, 20 insertions(+)

diff --git a/tools/lib/api/fs/debugfs.c b/tools/lib/api/fs/debugfs.c
index 07d74b03d828..8305b3e9d48e 100644
--- a/tools/lib/api/fs/debugfs.c
+++ b/tools/lib/api/fs/debugfs.c
@@ -3,8 +3,11 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <unistd.h>
 #include <stdbool.h>
 #include <sys/vfs.h>
+#include <sys/types.h>
+#include <sys/stat.h>
 #include <sys/mount.h>
 #include <linux/kernel.h>
 
@@ -24,6 +27,11 @@ static const char * const debugfs_known_mountpoints[] = {
 
 static bool debugfs_found;
 
+bool debugfs_configured(void)
+{
+	return debugfs_find_mountpoint() != NULL;
+}
+
 /* find the path to the mounted debugfs */
 const char *debugfs_find_mountpoint(void)
 {
diff --git a/tools/lib/api/fs/debugfs.h b/tools/lib/api/fs/debugfs.h
index 1074ac81358e..455023698d2b 100644
--- a/tools/lib/api/fs/debugfs.h
+++ b/tools/lib/api/fs/debugfs.h
@@ -11,6 +11,7 @@
 #define PERF_DEBUGFS_ENVIRONMENT "PERF_DEBUGFS_DIR"
 #endif
 
+bool debugfs_configured(void);
 const char *debugfs_find_mountpoint(void);
 char *debugfs_mount(const char *mountpoint);
 
diff --git a/tools/lib/api/fs/findfs.h b/tools/lib/api/fs/findfs.h
index 9e7d876791e1..b6f5d05acc42 100644
--- a/tools/lib/api/fs/findfs.h
+++ b/tools/lib/api/fs/findfs.h
@@ -1,6 +1,8 @@
 #ifndef __API_FINDFS_H__
 #define __API_FINDFS_H__
 
+#include <stdbool.h>
+
 #define _STR(x) #x
 #define STR(x) _STR(x)
 
diff --git a/tools/lib/api/fs/tracefs.c b/tools/lib/api/fs/tracefs.c
index ef40d15821e9..e4aa9688b71e 100644
--- a/tools/lib/api/fs/tracefs.c
+++ b/tools/lib/api/fs/tracefs.c
@@ -2,8 +2,11 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <unistd.h>
 #include <stdbool.h>
 #include <sys/vfs.h>
+#include <sys/types.h>
+#include <sys/stat.h>
 #include <sys/mount.h>
 #include <linux/kernel.h>
 
@@ -25,6 +28,11 @@ static const char * const tracefs_known_mountpoints[] = {
 
 static bool tracefs_found;
 
+bool tracefs_configured(void)
+{
+	return tracefs_find_mountpoint() != NULL;
+}
+
 /* find the path to the mounted tracefs */
 const char *tracefs_find_mountpoint(void)
 {
diff --git a/tools/lib/api/fs/tracefs.h b/tools/lib/api/fs/tracefs.h
index e6f7f5183c87..da780ac49acb 100644
--- a/tools/lib/api/fs/tracefs.h
+++ b/tools/lib/api/fs/tracefs.h
@@ -11,6 +11,7 @@
 #define PERF_TRACEFS_ENVIRONMENT "PERF_TRACEFS_DIR"
 #endif
 
+bool tracefs_configured(void);
 const char *tracefs_find_mountpoint(void);
 int tracefs_valid_mountpoint(const char *debugfs);
 char *tracefs_mount(const char *mountpoint);
-- 
2.1.4



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

* [PATCH 6/6 v2] perf: Make perf aware of tracefs
  2015-02-02 19:35 [PATCH 0/6 v2] perf: Have perf become tracefs aware Steven Rostedt
                   ` (4 preceding siblings ...)
  2015-02-02 19:35 ` [PATCH 5/6 v2] tools lib api fs: Add {tracefs,debugfs}_configured() functions Steven Rostedt
@ 2015-02-02 19:35 ` Steven Rostedt
  2015-02-03 14:16   ` Jiri Olsa
                     ` (2 more replies)
  5 siblings, 3 replies; 18+ messages in thread
From: Steven Rostedt @ 2015-02-02 19:35 UTC (permalink / raw)
  To: linux-kernel
  Cc: Ingo Molnar, Andrew Morton, Jiri Olsa, Arnaldo Carvalho de Melo,
	Masami Hiramatsu, Namhyung Kim

[-- Attachment #1: 0006-perf-Make-perf-aware-of-tracefs.patch --]
[-- Type: text/plain, Size: 10186 bytes --]

From: "Steven Rostedt (Red Hat)" <rostedt@goodmis.org>

As tracefs may be mounted instead of debugfs to get to the event directories,
have perf know about tracefs, and use that file system over debugfs if it
is present.

Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
 tools/perf/tests/open-syscall-all-cpus.c |  7 +++-
 tools/perf/tests/open-syscall.c          |  7 +++-
 tools/perf/tests/parse-events.c          | 13 +++++--
 tools/perf/util/cache.h                  |  1 +
 tools/perf/util/evlist.c                 |  1 -
 tools/perf/util/parse-events.h           |  2 +-
 tools/perf/util/probe-event.c            | 24 ++++++++-----
 tools/perf/util/util.c                   | 60 ++++++++++++++++++++++++++------
 tools/perf/util/util.h                   |  1 +
 9 files changed, 91 insertions(+), 25 deletions(-)

diff --git a/tools/perf/tests/open-syscall-all-cpus.c b/tools/perf/tests/open-syscall-all-cpus.c
index 8fa82d1700c7..21969e99ea46 100644
--- a/tools/perf/tests/open-syscall-all-cpus.c
+++ b/tools/perf/tests/open-syscall-all-cpus.c
@@ -29,7 +29,12 @@ int test__open_syscall_event_on_all_cpus(void)
 
 	evsel = perf_evsel__newtp("syscalls", "sys_enter_open");
 	if (evsel == NULL) {
-		pr_debug("is debugfs mounted on /sys/kernel/debug?\n");
+		if (tracefs_configured())
+			pr_debug("is tracefs mounted on /sys/kernel/debug?\n");
+		else if (debugfs_configured())
+			pr_debug("is debugfs mounted on /sys/kernel/debug?\n");
+		else
+			pr_debug("Neither tracefs or debugfs is enabled in this kernel\n");
 		goto out_thread_map_delete;
 	}
 
diff --git a/tools/perf/tests/open-syscall.c b/tools/perf/tests/open-syscall.c
index a33b2daae40f..4250e40234d2 100644
--- a/tools/perf/tests/open-syscall.c
+++ b/tools/perf/tests/open-syscall.c
@@ -18,7 +18,12 @@ int test__open_syscall_event(void)
 
 	evsel = perf_evsel__newtp("syscalls", "sys_enter_open");
 	if (evsel == NULL) {
-		pr_debug("is debugfs mounted on /sys/kernel/debug?\n");
+		if (tracefs_configured())
+			pr_debug("is tracefs mounted on /sys/kernel/debug?\n");
+		else if (debugfs_configured())
+			pr_debug("is debugfs mounted on /sys/kernel/debug?\n");
+		else
+			pr_debug("Neither tracefs or debugfs is enabled in this kernel\n");
 		goto out_thread_map_delete;
 	}
 
diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-events.c
index 1cdab0ce00e2..ac243ebcb20a 100644
--- a/tools/perf/tests/parse-events.c
+++ b/tools/perf/tests/parse-events.c
@@ -3,6 +3,7 @@
 #include "evsel.h"
 #include "evlist.h"
 #include <api/fs/fs.h>
+#include <api/fs/tracefs.h>
 #include <api/fs/debugfs.h>
 #include "tests.h"
 #include "debug.h"
@@ -1192,11 +1193,19 @@ static int count_tracepoints(void)
 {
 	char events_path[PATH_MAX];
 	struct dirent *events_ent;
+	const char *mountpoint;
 	DIR *events_dir;
 	int cnt = 0;
 
-	scnprintf(events_path, PATH_MAX, "%s/tracing/events",
-		  debugfs_find_mountpoint());
+	mountpoint = tracefs_find_mountpoint();
+	if (mountpoint) {
+		scnprintf(events_path, PATH_MAX, "%s/events",
+			  mountpoint);
+	} else {
+		mountpoint = debugfs_find_mountpoint();
+		scnprintf(events_path, PATH_MAX, "%s/tracing/events",
+			  mountpoint);
+	}
 
 	events_dir = opendir(events_path);
 
diff --git a/tools/perf/util/cache.h b/tools/perf/util/cache.h
index d04d770d90f6..fbcca21d66ab 100644
--- a/tools/perf/util/cache.h
+++ b/tools/perf/util/cache.h
@@ -17,6 +17,7 @@
 #define EXEC_PATH_ENVIRONMENT "PERF_EXEC_PATH"
 #define DEFAULT_PERF_DIR_ENVIRONMENT ".perf"
 #define PERF_DEBUGFS_ENVIRONMENT "PERF_DEBUGFS_DIR"
+#define PERF_TRACEFS_ENVIRONMENT "PERF_TRACEFS_DIR"
 
 typedef int (*config_fn_t)(const char *, const char *, void *);
 extern int perf_default_config(const char *, const char *, void *);
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 28b8ce86bf12..42f1a2dfead3 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -7,7 +7,6 @@
  * Released under the GPL v2. (and only v2, not any later version)
  */
 #include "util.h"
-#include <api/fs/debugfs.h>
 #include <api/fs/fs.h>
 #include <poll.h>
 #include "cpumap.h"
diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h
index ff6e1fa4111e..39c3b57965d1 100644
--- a/tools/perf/util/parse-events.h
+++ b/tools/perf/util/parse-events.h
@@ -122,6 +122,6 @@ void print_tracepoint_events(const char *subsys_glob, const char *event_glob,
 int print_hwcache_events(const char *event_glob, bool name_only);
 extern int is_valid_tracepoint(const char *event_string);
 
-extern int valid_debugfs_mount(const char *debugfs);
+int valid_event_mount(const char *eventfs);
 
 #endif /* __PERF_PARSE_EVENTS_H */
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 919937eb0be2..9dfbed96bf39 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -41,6 +41,7 @@
 #include "symbol.h"
 #include "thread.h"
 #include <api/fs/debugfs.h>
+#include <api/fs/tracefs.h>
 #include "trace-event.h"	/* For __maybe_unused */
 #include "probe-event.h"
 #include "probe-finder.h"
@@ -1805,7 +1806,7 @@ static void print_open_warning(int err, bool is_kprobe)
 			   " - please rebuild kernel with %s.\n",
 			   is_kprobe ? 'k' : 'u', config);
 	} else if (err == -ENOTSUP)
-		pr_warning("Debugfs is not mounted.\n");
+		pr_warning("Tracefs or debugfs is not mounted.\n");
 	else
 		pr_warning("Failed to open %cprobe_events: %s\n",
 			   is_kprobe ? 'k' : 'u',
@@ -1816,7 +1817,7 @@ static void print_both_open_warning(int kerr, int uerr)
 {
 	/* Both kprobes and uprobes are disabled, warn it. */
 	if (kerr == -ENOTSUP && uerr == -ENOTSUP)
-		pr_warning("Debugfs is not mounted.\n");
+		pr_warning("Tracefs or debugfs is not mounted.\n");
 	else if (kerr == -ENOENT && uerr == -ENOENT)
 		pr_warning("Please rebuild kernel with CONFIG_KPROBE_EVENTS "
 			   "or/and CONFIG_UPROBE_EVENTS.\n");
@@ -1833,13 +1834,20 @@ static int open_probe_events(const char *trace_file, bool readwrite)
 {
 	char buf[PATH_MAX];
 	const char *__debugfs;
+	const char *tracing_dir = "";
 	int ret;
 
-	__debugfs = debugfs_find_mountpoint();
-	if (__debugfs == NULL)
-		return -ENOTSUP;
+	__debugfs = tracefs_find_mountpoint();
+	if (__debugfs == NULL) {
+		tracing_dir = "tracing/";
 
-	ret = e_snprintf(buf, PATH_MAX, "%s/%s", __debugfs, trace_file);
+		__debugfs = debugfs_find_mountpoint();
+		if (__debugfs == NULL)
+			return -ENOTSUP;
+	}
+
+	ret = e_snprintf(buf, PATH_MAX, "%s/%s%s",
+			 __debugfs, tracing_dir, trace_file);
 	if (ret >= 0) {
 		pr_debug("Opening %s write=%d\n", buf, readwrite);
 		if (readwrite && !probe_event_dry_run)
@@ -1855,12 +1863,12 @@ static int open_probe_events(const char *trace_file, bool readwrite)
 
 static int open_kprobe_events(bool readwrite)
 {
-	return open_probe_events("tracing/kprobe_events", readwrite);
+	return open_probe_events("kprobe_events", readwrite);
 }
 
 static int open_uprobe_events(bool readwrite)
 {
-	return open_probe_events("tracing/uprobe_events", readwrite);
+	return open_probe_events("uprobe_events", readwrite);
 }
 
 /* Get raw string list of current kprobe_events  or uprobe_events */
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c
index b86744f29eef..92db3f156b63 100644
--- a/tools/perf/util/util.c
+++ b/tools/perf/util/util.c
@@ -303,13 +303,26 @@ void set_term_quiet_input(struct termios *old)
 	tcsetattr(0, TCSANOW, &tc);
 }
 
-static void set_tracing_events_path(const char *mountpoint)
+static void set_tracing_events_path(const char *tracing, const char *mountpoint)
 {
-	snprintf(tracing_events_path, sizeof(tracing_events_path), "%s/%s",
-		 mountpoint, "tracing/events");
+	snprintf(tracing_events_path, sizeof(tracing_events_path), "%s/%s%s",
+		 mountpoint, tracing, "events");
 }
 
-const char *perf_debugfs_mount(const char *mountpoint)
+static const char *__perf_tracefs_mount(const char *mountpoint)
+{
+	const char *mnt;
+
+	mnt = tracefs_mount(mountpoint);
+	if (!mnt)
+		return NULL;
+
+	set_tracing_events_path("", mnt);
+
+	return mnt;
+}
+
+static const char *__perf_debugfs_mount(const char *mountpoint)
 {
 	const char *mnt;
 
@@ -317,7 +330,20 @@ const char *perf_debugfs_mount(const char *mountpoint)
 	if (!mnt)
 		return NULL;
 
-	set_tracing_events_path(mnt);
+	set_tracing_events_path("tracing/", mnt);
+
+	return mnt;
+}
+
+const char *perf_debugfs_mount(const char *mountpoint)
+{
+	const char *mnt;
+
+	mnt = __perf_tracefs_mount(mountpoint);
+	if (mnt)
+		return mnt;
+
+	mnt = __perf_debugfs_mount(mountpoint);
 
 	return mnt;
 }
@@ -325,12 +351,19 @@ const char *perf_debugfs_mount(const char *mountpoint)
 void perf_debugfs_set_path(const char *mntpt)
 {
 	snprintf(debugfs_mountpoint, strlen(debugfs_mountpoint), "%s", mntpt);
-	set_tracing_events_path(mntpt);
+	set_tracing_events_path("tracing/", mntpt);
+}
+
+static const char *find_tracefs(void)
+{
+	const char *path = __perf_tracefs_mount(NULL);
+
+	return path;
 }
 
 static const char *find_debugfs(void)
 {
-	const char *path = perf_debugfs_mount(NULL);
+	const char *path = __perf_debugfs_mount(NULL);
 
 	if (!path)
 		fprintf(stderr, "Your kernel does not support the debugfs filesystem");
@@ -344,6 +377,7 @@ static const char *find_debugfs(void)
  */
 const char *find_tracing_dir(void)
 {
+	const char *tracing_dir = "";
 	static char *tracing;
 	static int tracing_found;
 	const char *debugfs;
@@ -351,11 +385,15 @@ const char *find_tracing_dir(void)
 	if (tracing_found)
 		return tracing;
 
-	debugfs = find_debugfs();
-	if (!debugfs)
-		return NULL;
+	debugfs = find_tracefs();
+	if (!debugfs) {
+		tracing_dir = "/tracing";
+		debugfs = find_debugfs();
+		if (!debugfs)
+			return NULL;
+	}
 
-	if (asprintf(&tracing, "%s/tracing", debugfs) < 0)
+	if (asprintf(&tracing, "%s%s", debugfs, tracing_dir) < 0)
 		return NULL;
 
 	tracing_found = 1;
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index 027a5153495c..73c2f8e557ab 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -75,6 +75,7 @@
 #include <linux/types.h>
 #include <sys/ttydefaults.h>
 #include <api/fs/debugfs.h>
+#include <api/fs/tracefs.h>
 #include <termios.h>
 #include <linux/bitops.h>
 #include <termios.h>
-- 
2.1.4



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

* Re: [PATCH 6/6 v2] perf: Make perf aware of tracefs
  2015-02-02 19:35 ` [PATCH 6/6 v2] perf: Make perf aware of tracefs Steven Rostedt
@ 2015-02-03 14:16   ` Jiri Olsa
  2015-02-03 16:45     ` Steven Rostedt
  2015-02-08 14:12   ` Namhyung Kim
  2015-02-18 18:29   ` [tip:perf/core] perf tools: " tip-bot for Steven Rostedt (Red Hat)
  2 siblings, 1 reply; 18+ messages in thread
From: Jiri Olsa @ 2015-02-03 14:16 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: linux-kernel, Ingo Molnar, Andrew Morton, Jiri Olsa,
	Arnaldo Carvalho de Melo, Masami Hiramatsu, Namhyung Kim

On Mon, Feb 02, 2015 at 02:35:07PM -0500, Steven Rostedt wrote:

SNIP

>  }
> @@ -325,12 +351,19 @@ const char *perf_debugfs_mount(const char *mountpoint)
>  void perf_debugfs_set_path(const char *mntpt)
>  {
>  	snprintf(debugfs_mountpoint, strlen(debugfs_mountpoint), "%s", mntpt);
> -	set_tracing_events_path(mntpt);
> +	set_tracing_events_path("tracing/", mntpt);
> +}
> +
> +static const char *find_tracefs(void)
> +{
> +	const char *path = __perf_tracefs_mount(NULL);
> +
> +	return path;

I guess you ommited the fprint(stderr... ) warning on purpose
(like in find_debugfs), because the tracefs is not upstream yet, right?

maybe we want at least pr_debug warning here..
anyway, other than that the patchset looks ok to me:

Acked-by: Jiri Olsa <jolsa@kernel.org>

thanks,
jirka

>  }
>  
>  static const char *find_debugfs(void)
>  {
> -	const char *path = perf_debugfs_mount(NULL);
> +	const char *path = __perf_debugfs_mount(NULL);
>  
>  	if (!path)
>  		fprintf(stderr, "Your kernel does not support the debugfs filesystem");
> @@ -344,6 +377,7 @@ static const char *find_debugfs(void)
>   */

SNIP


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

* Re: [PATCH 6/6 v2] perf: Make perf aware of tracefs
  2015-02-03 14:16   ` Jiri Olsa
@ 2015-02-03 16:45     ` Steven Rostedt
  2015-02-06  8:35       ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 18+ messages in thread
From: Steven Rostedt @ 2015-02-03 16:45 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: linux-kernel, Ingo Molnar, Andrew Morton, Jiri Olsa,
	Arnaldo Carvalho de Melo, Masami Hiramatsu, Namhyung Kim

On Tue, 3 Feb 2015 15:16:25 +0100
Jiri Olsa <jolsa@redhat.com> wrote:

> On Mon, Feb 02, 2015 at 02:35:07PM -0500, Steven Rostedt wrote:
> 
> SNIP
> 
> >  }
> > @@ -325,12 +351,19 @@ const char *perf_debugfs_mount(const char *mountpoint)
> >  void perf_debugfs_set_path(const char *mntpt)
> >  {
> >  	snprintf(debugfs_mountpoint, strlen(debugfs_mountpoint), "%s", mntpt);
> > -	set_tracing_events_path(mntpt);
> > +	set_tracing_events_path("tracing/", mntpt);
> > +}
> > +
> > +static const char *find_tracefs(void)
> > +{
> > +	const char *path = __perf_tracefs_mount(NULL);
> > +
> > +	return path;
> 
> I guess you ommited the fprint(stderr... ) warning on purpose
> (like in find_debugfs), because the tracefs is not upstream yet, right?

Right, because I didn't want people complaining about using a new perf
with an old kernel, and suddenly get warnings.

> 
> maybe we want at least pr_debug warning here..
> anyway, other than that the patchset looks ok to me:

I was thinking that we could add one later, when tracefs is more common.

> 
> Acked-by: Jiri Olsa <jolsa@kernel.org>

Thanks!

Arnaldo, do you want to pick this up?

-- Steve

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

* Re: [PATCH 6/6 v2] perf: Make perf aware of tracefs
  2015-02-03 16:45     ` Steven Rostedt
@ 2015-02-06  8:35       ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 18+ messages in thread
From: Arnaldo Carvalho de Melo @ 2015-02-06  8:35 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: Jiri Olsa, linux-kernel, Ingo Molnar, Andrew Morton, Jiri Olsa,
	Masami Hiramatsu, Namhyung Kim

Em Tue, Feb 03, 2015 at 11:45:50AM -0500, Steven Rostedt escreveu:
> On Tue, 3 Feb 2015 15:16:25 +0100
> Jiri Olsa <jolsa@redhat.com> wrote:
> > I guess you ommited the fprint(stderr... ) warning on purpose
> > (like in find_debugfs), because the tracefs is not upstream yet, right?
 
> Right, because I didn't want people complaining about using a new perf
> with an old kernel, and suddenly get warnings.
 
> > maybe we want at least pr_debug warning here..
> > anyway, other than that the patchset looks ok to me:
 
> I was thinking that we could add one later, when tracefs is more common.
 
> > Acked-by: Jiri Olsa <jolsa@kernel.org>
 
> Arnaldo, do you want to pick this up?

I will, but traveling now, as soon as I can I'll look at it and put it
in my perf/core branch.

- Arnaldo

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

* Re: [PATCH 6/6 v2] perf: Make perf aware of tracefs
  2015-02-02 19:35 ` [PATCH 6/6 v2] perf: Make perf aware of tracefs Steven Rostedt
  2015-02-03 14:16   ` Jiri Olsa
@ 2015-02-08 14:12   ` Namhyung Kim
  2015-02-09 15:24     ` Steven Rostedt
  2015-02-18 18:29   ` [tip:perf/core] perf tools: " tip-bot for Steven Rostedt (Red Hat)
  2 siblings, 1 reply; 18+ messages in thread
From: Namhyung Kim @ 2015-02-08 14:12 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: linux-kernel, Ingo Molnar, Andrew Morton, Jiri Olsa,
	Arnaldo Carvalho de Melo, Masami Hiramatsu

Hi Steve,

On Mon, Feb 02, 2015 at 02:35:07PM -0500, Steven Rostedt wrote:
> From: "Steven Rostedt (Red Hat)" <rostedt@goodmis.org>
> 
> As tracefs may be mounted instead of debugfs to get to the event directories,
> have perf know about tracefs, and use that file system over debugfs if it
> is present.
> 
> Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
> ---
>  tools/perf/tests/open-syscall-all-cpus.c |  7 +++-
>  tools/perf/tests/open-syscall.c          |  7 +++-
>  tools/perf/tests/parse-events.c          | 13 +++++--
>  tools/perf/util/cache.h                  |  1 +
>  tools/perf/util/evlist.c                 |  1 -
>  tools/perf/util/parse-events.h           |  2 +-
>  tools/perf/util/probe-event.c            | 24 ++++++++-----
>  tools/perf/util/util.c                   | 60 ++++++++++++++++++++++++++------
>  tools/perf/util/util.h                   |  1 +
>  9 files changed, 91 insertions(+), 25 deletions(-)
> 
> diff --git a/tools/perf/tests/open-syscall-all-cpus.c b/tools/perf/tests/open-syscall-all-cpus.c
> index 8fa82d1700c7..21969e99ea46 100644
> --- a/tools/perf/tests/open-syscall-all-cpus.c
> +++ b/tools/perf/tests/open-syscall-all-cpus.c
> @@ -29,7 +29,12 @@ int test__open_syscall_event_on_all_cpus(void)
>  
>  	evsel = perf_evsel__newtp("syscalls", "sys_enter_open");
>  	if (evsel == NULL) {
> -		pr_debug("is debugfs mounted on /sys/kernel/debug?\n");
> +		if (tracefs_configured())
> +			pr_debug("is tracefs mounted on /sys/kernel/debug?\n");

Shouldn't it be /sys/kernel/tracing/ ?


> +		else if (debugfs_configured())
> +			pr_debug("is debugfs mounted on /sys/kernel/debug?\n");
> +		else
> +			pr_debug("Neither tracefs or debugfs is enabled in this kernel\n");
>  		goto out_thread_map_delete;
>  	}
>  
> diff --git a/tools/perf/tests/open-syscall.c b/tools/perf/tests/open-syscall.c
> index a33b2daae40f..4250e40234d2 100644
> --- a/tools/perf/tests/open-syscall.c
> +++ b/tools/perf/tests/open-syscall.c
> @@ -18,7 +18,12 @@ int test__open_syscall_event(void)
>  
>  	evsel = perf_evsel__newtp("syscalls", "sys_enter_open");
>  	if (evsel == NULL) {
> -		pr_debug("is debugfs mounted on /sys/kernel/debug?\n");
> +		if (tracefs_configured())
> +			pr_debug("is tracefs mounted on /sys/kernel/debug?\n");

Ditto.

Thanks,
Namhyung


> +		else if (debugfs_configured())
> +			pr_debug("is debugfs mounted on /sys/kernel/debug?\n");
> +		else
> +			pr_debug("Neither tracefs or debugfs is enabled in this kernel\n");
>  		goto out_thread_map_delete;
>  	}

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

* Re: [PATCH 6/6 v2] perf: Make perf aware of tracefs
  2015-02-08 14:12   ` Namhyung Kim
@ 2015-02-09 15:24     ` Steven Rostedt
  0 siblings, 0 replies; 18+ messages in thread
From: Steven Rostedt @ 2015-02-09 15:24 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: linux-kernel, Ingo Molnar, Andrew Morton, Jiri Olsa,
	Arnaldo Carvalho de Melo, Masami Hiramatsu

On Sun, 8 Feb 2015 23:12:46 +0900
Namhyung Kim <namhyung@kernel.org> wrote:
 
> Shouldn't it be /sys/kernel/tracing/ ?

> >  	if (evsel == NULL) {
> > -		pr_debug("is debugfs mounted on /sys/kernel/debug?\n");
> > +		if (tracefs_configured())
> > +			pr_debug("is tracefs mounted on /sys/kernel/debug?\n");
> 
> Ditto.

Fixing, thanks!

-- Steve

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

* [tip:perf/core] perf tools: Do not check debugfs MAGIC for tracing files
  2015-02-02 19:35 ` [PATCH 1/6 v2] perf: Do not check debugfs MAGIC for tracing files Steven Rostedt
@ 2015-02-18 18:27   ` tip-bot for Steven Rostedt (Red Hat)
  0 siblings, 0 replies; 18+ messages in thread
From: tip-bot for Steven Rostedt (Red Hat) @ 2015-02-18 18:27 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: akpm, jolsa, linux-kernel, hpa, masami.hiramatsu.pt, acme, mingo,
	tglx, namhyung, rostedt

Commit-ID:  5693c92660970851e95f769ff27397f5098a6296
Gitweb:     http://git.kernel.org/tip/5693c92660970851e95f769ff27397f5098a6296
Author:     Steven Rostedt (Red Hat) <rostedt@goodmis.org>
AuthorDate: Mon, 2 Feb 2015 14:35:02 -0500
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Sat, 7 Feb 2015 13:51:30 +0100

perf tools: Do not check debugfs MAGIC for tracing files

It's rather strange to be checking the debugfs MAGIC number for the
tracing directory. A system admin may want to have a custom set of
events to trace and it should be allowed to let the admin make a temp
file (even for tracing virtual boxes, this is useful).

Also with the coming tracefs, the files may not even be under debugfs,
so checking the debugfs MAGIC number is pointless.

Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: http://lkml.kernel.org/r/20150202193552.546175764@goodmis.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/lib/api/fs/debugfs.c     | 28 ++++++++++++++--------------
 tools/lib/api/fs/debugfs.h     |  1 -
 tools/perf/util/parse-events.c | 19 -------------------
 3 files changed, 14 insertions(+), 34 deletions(-)

diff --git a/tools/lib/api/fs/debugfs.c b/tools/lib/api/fs/debugfs.c
index d2b18e8..d21d4d6 100644
--- a/tools/lib/api/fs/debugfs.c
+++ b/tools/lib/api/fs/debugfs.c
@@ -20,6 +20,20 @@ static const char * const debugfs_known_mountpoints[] = {
 
 static bool debugfs_found;
 
+/* verify that a mountpoint is actually a debugfs instance */
+
+static int debugfs_valid_mountpoint(const char *debugfs)
+{
+	struct statfs st_fs;
+
+	if (statfs(debugfs, &st_fs) < 0)
+		return -ENOENT;
+	else if ((long)st_fs.f_type != (long)DEBUGFS_MAGIC)
+		return -ENOENT;
+
+	return 0;
+}
+
 /* find the path to the mounted debugfs */
 const char *debugfs_find_mountpoint(void)
 {
@@ -60,20 +74,6 @@ const char *debugfs_find_mountpoint(void)
 	return debugfs_mountpoint;
 }
 
-/* verify that a mountpoint is actually a debugfs instance */
-
-int debugfs_valid_mountpoint(const char *debugfs)
-{
-	struct statfs st_fs;
-
-	if (statfs(debugfs, &st_fs) < 0)
-		return -ENOENT;
-	else if ((long)st_fs.f_type != (long)DEBUGFS_MAGIC)
-		return -ENOENT;
-
-	return 0;
-}
-
 /* mount the debugfs somewhere if it's not mounted */
 char *debugfs_mount(const char *mountpoint)
 {
diff --git a/tools/lib/api/fs/debugfs.h b/tools/lib/api/fs/debugfs.h
index 0739881..77bb36a 100644
--- a/tools/lib/api/fs/debugfs.h
+++ b/tools/lib/api/fs/debugfs.h
@@ -21,7 +21,6 @@
 #endif
 
 const char *debugfs_find_mountpoint(void);
-int debugfs_valid_mountpoint(const char *debugfs);
 char *debugfs_mount(const char *mountpoint);
 
 extern char debugfs_mountpoint[];
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 7f8ec6c..ecf069b 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -175,9 +175,6 @@ struct tracepoint_path *tracepoint_id_to_path(u64 config)
 	char evt_path[MAXPATHLEN];
 	char dir_path[MAXPATHLEN];
 
-	if (debugfs_valid_mountpoint(tracing_events_path))
-		return NULL;
-
 	sys_dir = opendir(tracing_events_path);
 	if (!sys_dir)
 		return NULL;
@@ -473,12 +470,6 @@ static int add_tracepoint_multi_sys(struct list_head *list, int *idx,
 int parse_events_add_tracepoint(struct list_head *list, int *idx,
 				char *sys, char *event)
 {
-	int ret;
-
-	ret = debugfs_valid_mountpoint(tracing_events_path);
-	if (ret)
-		return ret;
-
 	if (strpbrk(sys, "*?"))
 		return add_tracepoint_multi_sys(list, idx, sys, event);
 	else
@@ -1109,13 +1100,6 @@ void print_tracepoint_events(const char *subsys_glob, const char *event_glob,
 	struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent;
 	char evt_path[MAXPATHLEN];
 	char dir_path[MAXPATHLEN];
-	char sbuf[STRERR_BUFSIZE];
-
-	if (debugfs_valid_mountpoint(tracing_events_path)) {
-		printf("  [ Tracepoints not available: %s ]\n",
-			strerror_r(errno, sbuf, sizeof(sbuf)));
-		return;
-	}
 
 	sys_dir = opendir(tracing_events_path);
 	if (!sys_dir)
@@ -1163,9 +1147,6 @@ int is_valid_tracepoint(const char *event_string)
 	char evt_path[MAXPATHLEN];
 	char dir_path[MAXPATHLEN];
 
-	if (debugfs_valid_mountpoint(tracing_events_path))
-		return 0;
-
 	sys_dir = opendir(tracing_events_path);
 	if (!sys_dir)
 		return 0;

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

* [tip:perf/core] tools lib fs: Add helper to find mounted file systems
  2015-02-02 19:35 ` [PATCH 2/6 v2] tools lib fs: Add helper to find mounted file systems Steven Rostedt
@ 2015-02-18 18:28   ` tip-bot for Steven Rostedt (Red Hat)
  0 siblings, 0 replies; 18+ messages in thread
From: tip-bot for Steven Rostedt (Red Hat) @ 2015-02-18 18:28 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: hpa, acme, mingo, namhyung, akpm, jolsa, linux-kernel,
	masami.hiramatsu.pt, rostedt, tglx

Commit-ID:  cde164aee9e0343831467035eb96dd5506742648
Gitweb:     http://git.kernel.org/tip/cde164aee9e0343831467035eb96dd5506742648
Author:     Steven Rostedt (Red Hat) <rostedt@goodmis.org>
AuthorDate: Mon, 2 Feb 2015 14:35:03 -0500
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Sat, 7 Feb 2015 13:51:34 +0100

tools lib fs: Add helper to find mounted file systems

In preparation for adding tracefs for perf to use, create a findfs
helper utility that find_debugfs uses instead of hard coding the search
in the code. This will allow for a find_tracefs to be used as well.

Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: http://lkml.kernel.org/r/20150202193552.735023362@goodmis.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/lib/api/Makefile     |  2 ++
 tools/lib/api/fs/debugfs.c | 51 ++++++-------------------------------
 tools/lib/api/fs/debugfs.h | 11 +-------
 tools/lib/api/fs/findfs.c  | 63 ++++++++++++++++++++++++++++++++++++++++++++++
 tools/lib/api/fs/findfs.h  | 21 ++++++++++++++++
 5 files changed, 94 insertions(+), 54 deletions(-)

diff --git a/tools/lib/api/Makefile b/tools/lib/api/Makefile
index 36c08b1..22b2f15 100644
--- a/tools/lib/api/Makefile
+++ b/tools/lib/api/Makefile
@@ -9,11 +9,13 @@ LIB_H=
 LIB_OBJS=
 
 LIB_H += fs/debugfs.h
+LIB_H += fs/findfs.h
 LIB_H += fs/fs.h
 # See comment below about piggybacking...
 LIB_H += fd/array.h
 
 LIB_OBJS += $(OUTPUT)fs/debugfs.o
+LIB_OBJS += $(OUTPUT)fs/findfs.o
 LIB_OBJS += $(OUTPUT)fs/fs.o
 # XXX piggybacking here, need to introduce libapikfd, or rename this
 # to plain libapik.a and make it have it all api goodies
diff --git a/tools/lib/api/fs/debugfs.c b/tools/lib/api/fs/debugfs.c
index d21d4d6..91e1668 100644
--- a/tools/lib/api/fs/debugfs.c
+++ b/tools/lib/api/fs/debugfs.c
@@ -20,58 +20,21 @@ static const char * const debugfs_known_mountpoints[] = {
 
 static bool debugfs_found;
 
-/* verify that a mountpoint is actually a debugfs instance */
-
-static int debugfs_valid_mountpoint(const char *debugfs)
-{
-	struct statfs st_fs;
-
-	if (statfs(debugfs, &st_fs) < 0)
-		return -ENOENT;
-	else if ((long)st_fs.f_type != (long)DEBUGFS_MAGIC)
-		return -ENOENT;
-
-	return 0;
-}
-
 /* find the path to the mounted debugfs */
 const char *debugfs_find_mountpoint(void)
 {
-	const char * const *ptr;
-	char type[100];
-	FILE *fp;
+	const char *ret;
 
 	if (debugfs_found)
 		return (const char *)debugfs_mountpoint;
 
-	ptr = debugfs_known_mountpoints;
-	while (*ptr) {
-		if (debugfs_valid_mountpoint(*ptr) == 0) {
-			debugfs_found = true;
-			strcpy(debugfs_mountpoint, *ptr);
-			return debugfs_mountpoint;
-		}
-		ptr++;
-	}
+	ret = find_mountpoint("debugfs", (long) DEBUGFS_MAGIC,
+			      debugfs_mountpoint, PATH_MAX + 1,
+			      debugfs_known_mountpoints);
+	if (ret)
+		debugfs_found = true;
 
-	/* give up and parse /proc/mounts */
-	fp = fopen("/proc/mounts", "r");
-	if (fp == NULL)
-		return NULL;
-
-	while (fscanf(fp, "%*s %" STR(PATH_MAX) "s %99s %*s %*d %*d\n",
-		      debugfs_mountpoint, type) == 2) {
-		if (strcmp(type, "debugfs") == 0)
-			break;
-	}
-	fclose(fp);
-
-	if (strcmp(type, "debugfs") != 0)
-		return NULL;
-
-	debugfs_found = true;
-
-	return debugfs_mountpoint;
+	return ret;
 }
 
 /* mount the debugfs somewhere if it's not mounted */
diff --git a/tools/lib/api/fs/debugfs.h b/tools/lib/api/fs/debugfs.h
index 77bb36a..1074ac8 100644
--- a/tools/lib/api/fs/debugfs.h
+++ b/tools/lib/api/fs/debugfs.h
@@ -1,16 +1,7 @@
 #ifndef __API_DEBUGFS_H__
 #define __API_DEBUGFS_H__
 
-#define _STR(x) #x
-#define STR(x) _STR(x)
-
-/*
- * On most systems <limits.h> would have given us this, but  not on some systems
- * (e.g. GNU/Hurd).
- */
-#ifndef PATH_MAX
-#define PATH_MAX 4096
-#endif
+#include "findfs.h"
 
 #ifndef DEBUGFS_MAGIC
 #define DEBUGFS_MAGIC          0x64626720
diff --git a/tools/lib/api/fs/findfs.c b/tools/lib/api/fs/findfs.c
new file mode 100644
index 0000000..49946cb
--- /dev/null
+++ b/tools/lib/api/fs/findfs.c
@@ -0,0 +1,63 @@
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdbool.h>
+#include <sys/vfs.h>
+
+#include "findfs.h"
+
+/* verify that a mountpoint is actually the type we want */
+
+int valid_mountpoint(const char *mount, long magic)
+{
+	struct statfs st_fs;
+
+	if (statfs(mount, &st_fs) < 0)
+		return -ENOENT;
+	else if ((long)st_fs.f_type != magic)
+		return -ENOENT;
+
+	return 0;
+}
+
+/* find the path to a mounted file system */
+const char *find_mountpoint(const char *fstype, long magic,
+			    char *mountpoint, int len,
+			    const char * const *known_mountpoints)
+{
+	const char * const *ptr;
+	char format[128];
+	char type[100];
+	FILE *fp;
+
+	if (known_mountpoints) {
+		ptr = known_mountpoints;
+		while (*ptr) {
+			if (valid_mountpoint(*ptr, magic) == 0) {
+				strncpy(mountpoint, *ptr, len - 1);
+				mountpoint[len-1] = 0;
+				return mountpoint;
+			}
+			ptr++;
+		}
+	}
+
+	/* give up and parse /proc/mounts */
+	fp = fopen("/proc/mounts", "r");
+	if (fp == NULL)
+		return NULL;
+
+	snprintf(format, 128, "%%*s %%%ds %%99s %%*s %%*d %%*d\n", len);
+
+	while (fscanf(fp, format, mountpoint, type) == 2) {
+		if (strcmp(type, fstype) == 0)
+			break;
+	}
+	fclose(fp);
+
+	if (strcmp(type, fstype) != 0)
+		return NULL;
+
+	return mountpoint;
+}
diff --git a/tools/lib/api/fs/findfs.h b/tools/lib/api/fs/findfs.h
new file mode 100644
index 0000000..9e7d876
--- /dev/null
+++ b/tools/lib/api/fs/findfs.h
@@ -0,0 +1,21 @@
+#ifndef __API_FINDFS_H__
+#define __API_FINDFS_H__
+
+#define _STR(x) #x
+#define STR(x) _STR(x)
+
+/*
+ * On most systems <limits.h> would have given us this, but  not on some systems
+ * (e.g. GNU/Hurd).
+ */
+#ifndef PATH_MAX
+#define PATH_MAX 4096
+#endif
+
+const char *find_mountpoint(const char *fstype, long magic,
+			    char *mountpoint, int len,
+			    const char * const *known_mountpoints);
+
+int valid_mountpoint(const char *mount, long magic);
+
+#endif /* __API_FINDFS_H__ */

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

* [tip:perf/core] tools lib api fs: Add tracefs mount helper functions
  2015-02-02 19:35 ` [PATCH 3/6 v2] tools lib api fs: Add tracefs mount helper functions Steven Rostedt
@ 2015-02-18 18:28   ` tip-bot for Steven Rostedt (Red Hat)
  0 siblings, 0 replies; 18+ messages in thread
From: tip-bot for Steven Rostedt (Red Hat) @ 2015-02-18 18:28 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: rostedt, masami.hiramatsu.pt, akpm, hpa, tglx, namhyung, mingo,
	linux-kernel, acme, jolsa

Commit-ID:  4ef92c2ecd96ebad171e554020c83ce9fdb343ae
Gitweb:     http://git.kernel.org/tip/4ef92c2ecd96ebad171e554020c83ce9fdb343ae
Author:     Steven Rostedt (Red Hat) <rostedt@goodmis.org>
AuthorDate: Mon, 2 Feb 2015 14:35:04 -0500
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Sat, 7 Feb 2015 13:55:20 +0100

tools lib api fs: Add tracefs mount helper functions

Since tracefs will now hold the event directory for perf, and even
though by default, debugfs still mounts tracefs on the debugfs/tracing
directory, the system admin may now choose to not mount debugfs and
instead just mount tracefs instead.

Having tracefs helper functions will facilitate having perf look for
tracefs first, and then try debugfs as a fallback.

Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: http://lkml.kernel.org/r/20150202193552.898934751@goodmis.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/lib/api/Makefile     |  2 ++
 tools/lib/api/fs/tracefs.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++
 tools/lib/api/fs/tracefs.h | 20 +++++++++++++
 3 files changed, 92 insertions(+)

diff --git a/tools/lib/api/Makefile b/tools/lib/api/Makefile
index 22b2f15..212aa4f 100644
--- a/tools/lib/api/Makefile
+++ b/tools/lib/api/Makefile
@@ -9,12 +9,14 @@ LIB_H=
 LIB_OBJS=
 
 LIB_H += fs/debugfs.h
+LIB_H += fs/tracefs.h
 LIB_H += fs/findfs.h
 LIB_H += fs/fs.h
 # See comment below about piggybacking...
 LIB_H += fd/array.h
 
 LIB_OBJS += $(OUTPUT)fs/debugfs.o
+LIB_OBJS += $(OUTPUT)fs/tracefs.o
 LIB_OBJS += $(OUTPUT)fs/findfs.o
 LIB_OBJS += $(OUTPUT)fs/fs.o
 # XXX piggybacking here, need to introduce libapikfd, or rename this
diff --git a/tools/lib/api/fs/tracefs.c b/tools/lib/api/fs/tracefs.c
new file mode 100644
index 0000000..ef40d15
--- /dev/null
+++ b/tools/lib/api/fs/tracefs.c
@@ -0,0 +1,70 @@
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdbool.h>
+#include <sys/vfs.h>
+#include <sys/mount.h>
+#include <linux/kernel.h>
+
+#include "tracefs.h"
+
+#ifndef TRACEFS_DEFAULT_PATH
+#define TRACEFS_DEFAULT_PATH		"/sys/kernel/tracing"
+#endif
+
+char tracefs_mountpoint[PATH_MAX + 1] = TRACEFS_DEFAULT_PATH;
+
+static const char * const tracefs_known_mountpoints[] = {
+	TRACEFS_DEFAULT_PATH,
+	"/sys/kernel/debug/tracing",
+	"/tracing",
+	"/trace",
+	0,
+};
+
+static bool tracefs_found;
+
+/* find the path to the mounted tracefs */
+const char *tracefs_find_mountpoint(void)
+{
+	const char *ret;
+
+	if (tracefs_found)
+		return (const char *)tracefs_mountpoint;
+
+	ret = find_mountpoint("tracefs", (long) TRACEFS_MAGIC,
+			      tracefs_mountpoint, PATH_MAX + 1,
+			      tracefs_known_mountpoints);
+
+	if (ret)
+		tracefs_found = true;
+
+	return ret;
+}
+
+/* mount the tracefs somewhere if it's not mounted */
+char *tracefs_mount(const char *mountpoint)
+{
+	/* see if it's already mounted */
+	if (tracefs_find_mountpoint())
+		goto out;
+
+	/* if not mounted and no argument */
+	if (mountpoint == NULL) {
+		/* see if environment variable set */
+		mountpoint = getenv(PERF_TRACEFS_ENVIRONMENT);
+		/* if no environment variable, use default */
+		if (mountpoint == NULL)
+			mountpoint = TRACEFS_DEFAULT_PATH;
+	}
+
+	if (mount(NULL, mountpoint, "tracefs", 0, NULL) < 0)
+		return NULL;
+
+	/* save the mountpoint */
+	tracefs_found = true;
+	strncpy(tracefs_mountpoint, mountpoint, sizeof(tracefs_mountpoint));
+out:
+	return tracefs_mountpoint;
+}
diff --git a/tools/lib/api/fs/tracefs.h b/tools/lib/api/fs/tracefs.h
new file mode 100644
index 0000000..e6f7f51
--- /dev/null
+++ b/tools/lib/api/fs/tracefs.h
@@ -0,0 +1,20 @@
+#ifndef __API_TRACEFS_H__
+#define __API_TRACEFS_H__
+
+#include "findfs.h"
+
+#ifndef TRACEFS_MAGIC
+#define TRACEFS_MAGIC          0x74726163
+#endif
+
+#ifndef PERF_TRACEFS_ENVIRONMENT
+#define PERF_TRACEFS_ENVIRONMENT "PERF_TRACEFS_DIR"
+#endif
+
+const char *tracefs_find_mountpoint(void);
+int tracefs_valid_mountpoint(const char *debugfs);
+char *tracefs_mount(const char *mountpoint);
+
+extern char tracefs_mountpoint[];
+
+#endif /* __API_DEBUGFS_H__ */

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

* [tip:perf/core] tools lib api debugfs: Add DEBUGFS_DEFAULT_PATH macro
  2015-02-02 19:35 ` [PATCH 4/6 v2] tools lib api fs: Add DEBUGFS_DEFAULT_PATH macro Steven Rostedt
@ 2015-02-18 18:28   ` tip-bot for Steven Rostedt (Red Hat)
  0 siblings, 0 replies; 18+ messages in thread
From: tip-bot for Steven Rostedt (Red Hat) @ 2015-02-18 18:28 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: acme, tglx, masami.hiramatsu.pt, namhyung, jolsa, mingo, akpm,
	hpa, linux-kernel, rostedt

Commit-ID:  a9edf60749a9483341facfa7c28bcf8afb3c8311
Gitweb:     http://git.kernel.org/tip/a9edf60749a9483341facfa7c28bcf8afb3c8311
Author:     Steven Rostedt (Red Hat) <rostedt@goodmis.org>
AuthorDate: Mon, 2 Feb 2015 14:35:05 -0500
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Sat, 7 Feb 2015 13:56:32 +0100

tools lib api debugfs: Add DEBUGFS_DEFAULT_PATH macro

Instead of hard coding "/sys/kernel/debug" everywhere, create a macro to
hold where the default path exists.

Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: http://lkml.kernel.org/r/20150202193553.032117017@goodmis.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/lib/api/fs/debugfs.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/tools/lib/api/fs/debugfs.c b/tools/lib/api/fs/debugfs.c
index 91e1668..07d74b0 100644
--- a/tools/lib/api/fs/debugfs.c
+++ b/tools/lib/api/fs/debugfs.c
@@ -10,10 +10,14 @@
 
 #include "debugfs.h"
 
-char debugfs_mountpoint[PATH_MAX + 1] = "/sys/kernel/debug";
+#ifndef DEBUGFS_DEFAULT_PATH
+#define DEBUGFS_DEFAULT_PATH		"/sys/kernel/debug"
+#endif
+
+char debugfs_mountpoint[PATH_MAX + 1] = DEBUGFS_DEFAULT_PATH;
 
 static const char * const debugfs_known_mountpoints[] = {
-	"/sys/kernel/debug",
+	DEBUGFS_DEFAULT_PATH,
 	"/debug",
 	0,
 };
@@ -50,7 +54,7 @@ char *debugfs_mount(const char *mountpoint)
 		mountpoint = getenv(PERF_DEBUGFS_ENVIRONMENT);
 		/* if no environment variable, use default */
 		if (mountpoint == NULL)
-			mountpoint = "/sys/kernel/debug";
+			mountpoint = DEBUGFS_DEFAULT_PATH;
 	}
 
 	if (mount(NULL, mountpoint, "debugfs", 0, NULL) < 0)

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

* [tip:perf/core] tools lib api fs: Add {tracefs, debugfs}_configured() functions
  2015-02-02 19:35 ` [PATCH 5/6 v2] tools lib api fs: Add {tracefs,debugfs}_configured() functions Steven Rostedt
@ 2015-02-18 18:29   ` tip-bot for Steven Rostedt (Red Hat)
  0 siblings, 0 replies; 18+ messages in thread
From: tip-bot for Steven Rostedt (Red Hat) @ 2015-02-18 18:29 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, jolsa, acme, tglx, rostedt, mingo,
	masami.hiramatsu.pt, hpa, namhyung, akpm

Commit-ID:  dd6dda27a8be563eaebb3f38b1d1d50920bb7991
Gitweb:     http://git.kernel.org/tip/dd6dda27a8be563eaebb3f38b1d1d50920bb7991
Author:     Steven Rostedt (Red Hat) <rostedt@goodmis.org>
AuthorDate: Mon, 2 Feb 2015 14:35:06 -0500
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Sat, 7 Feb 2015 14:00:10 +0100

tools lib api fs: Add {tracefs,debugfs}_configured() functions

Add tracefs_configured() to return true if tracefs is configured in the
kernel (succeeds to find tracefs), and debugfs_configured() if debugfs
is configured in the kernel (succeeds to find debugfs).

Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: http://lkml.kernel.org/r/20150202193553.190606690@goodmis.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/lib/api/fs/debugfs.c | 8 ++++++++
 tools/lib/api/fs/debugfs.h | 1 +
 tools/lib/api/fs/findfs.h  | 2 ++
 tools/lib/api/fs/tracefs.c | 8 ++++++++
 tools/lib/api/fs/tracefs.h | 1 +
 5 files changed, 20 insertions(+)

diff --git a/tools/lib/api/fs/debugfs.c b/tools/lib/api/fs/debugfs.c
index 07d74b0..8305b3e 100644
--- a/tools/lib/api/fs/debugfs.c
+++ b/tools/lib/api/fs/debugfs.c
@@ -3,8 +3,11 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <unistd.h>
 #include <stdbool.h>
 #include <sys/vfs.h>
+#include <sys/types.h>
+#include <sys/stat.h>
 #include <sys/mount.h>
 #include <linux/kernel.h>
 
@@ -24,6 +27,11 @@ static const char * const debugfs_known_mountpoints[] = {
 
 static bool debugfs_found;
 
+bool debugfs_configured(void)
+{
+	return debugfs_find_mountpoint() != NULL;
+}
+
 /* find the path to the mounted debugfs */
 const char *debugfs_find_mountpoint(void)
 {
diff --git a/tools/lib/api/fs/debugfs.h b/tools/lib/api/fs/debugfs.h
index 1074ac8..4550236 100644
--- a/tools/lib/api/fs/debugfs.h
+++ b/tools/lib/api/fs/debugfs.h
@@ -11,6 +11,7 @@
 #define PERF_DEBUGFS_ENVIRONMENT "PERF_DEBUGFS_DIR"
 #endif
 
+bool debugfs_configured(void);
 const char *debugfs_find_mountpoint(void);
 char *debugfs_mount(const char *mountpoint);
 
diff --git a/tools/lib/api/fs/findfs.h b/tools/lib/api/fs/findfs.h
index 9e7d876..b6f5d05 100644
--- a/tools/lib/api/fs/findfs.h
+++ b/tools/lib/api/fs/findfs.h
@@ -1,6 +1,8 @@
 #ifndef __API_FINDFS_H__
 #define __API_FINDFS_H__
 
+#include <stdbool.h>
+
 #define _STR(x) #x
 #define STR(x) _STR(x)
 
diff --git a/tools/lib/api/fs/tracefs.c b/tools/lib/api/fs/tracefs.c
index ef40d15..e4aa968 100644
--- a/tools/lib/api/fs/tracefs.c
+++ b/tools/lib/api/fs/tracefs.c
@@ -2,8 +2,11 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <unistd.h>
 #include <stdbool.h>
 #include <sys/vfs.h>
+#include <sys/types.h>
+#include <sys/stat.h>
 #include <sys/mount.h>
 #include <linux/kernel.h>
 
@@ -25,6 +28,11 @@ static const char * const tracefs_known_mountpoints[] = {
 
 static bool tracefs_found;
 
+bool tracefs_configured(void)
+{
+	return tracefs_find_mountpoint() != NULL;
+}
+
 /* find the path to the mounted tracefs */
 const char *tracefs_find_mountpoint(void)
 {
diff --git a/tools/lib/api/fs/tracefs.h b/tools/lib/api/fs/tracefs.h
index e6f7f51..da780ac 100644
--- a/tools/lib/api/fs/tracefs.h
+++ b/tools/lib/api/fs/tracefs.h
@@ -11,6 +11,7 @@
 #define PERF_TRACEFS_ENVIRONMENT "PERF_TRACEFS_DIR"
 #endif
 
+bool tracefs_configured(void);
 const char *tracefs_find_mountpoint(void);
 int tracefs_valid_mountpoint(const char *debugfs);
 char *tracefs_mount(const char *mountpoint);

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

* [tip:perf/core] perf tools: Make perf aware of tracefs
  2015-02-02 19:35 ` [PATCH 6/6 v2] perf: Make perf aware of tracefs Steven Rostedt
  2015-02-03 14:16   ` Jiri Olsa
  2015-02-08 14:12   ` Namhyung Kim
@ 2015-02-18 18:29   ` tip-bot for Steven Rostedt (Red Hat)
  2 siblings, 0 replies; 18+ messages in thread
From: tip-bot for Steven Rostedt (Red Hat) @ 2015-02-18 18:29 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: jolsa, tglx, masami.hiramatsu.pt, namhyung, hpa, rostedt, akpm,
	acme, linux-kernel, mingo

Commit-ID:  23773ca18b399051eb94f98b689cf7a9173c795b
Gitweb:     http://git.kernel.org/tip/23773ca18b399051eb94f98b689cf7a9173c795b
Author:     Steven Rostedt (Red Hat) <rostedt@goodmis.org>
AuthorDate: Mon, 2 Feb 2015 14:35:07 -0500
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 11 Feb 2015 12:37:08 -0300

perf tools: Make perf aware of tracefs

As tracefs may be mounted instead of debugfs to get to the event
directories, have perf know about tracefs, and use that file system over
debugfs if it is present.

Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: http://lkml.kernel.org/r/20150202193553.340946602@goodmis.org
[ Fixed up error messages about tracefs pointed out by Namhyung ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/tests/open-syscall-all-cpus.c |  7 +++-
 tools/perf/tests/open-syscall.c          |  7 +++-
 tools/perf/tests/parse-events.c          | 13 +++++--
 tools/perf/util/cache.h                  |  1 +
 tools/perf/util/evlist.c                 |  1 -
 tools/perf/util/parse-events.h           |  2 +-
 tools/perf/util/probe-event.c            | 24 ++++++++-----
 tools/perf/util/util.c                   | 60 ++++++++++++++++++++++++++------
 tools/perf/util/util.h                   |  1 +
 9 files changed, 91 insertions(+), 25 deletions(-)

diff --git a/tools/perf/tests/open-syscall-all-cpus.c b/tools/perf/tests/open-syscall-all-cpus.c
index 8fa82d1..3ec885c 100644
--- a/tools/perf/tests/open-syscall-all-cpus.c
+++ b/tools/perf/tests/open-syscall-all-cpus.c
@@ -29,7 +29,12 @@ int test__open_syscall_event_on_all_cpus(void)
 
 	evsel = perf_evsel__newtp("syscalls", "sys_enter_open");
 	if (evsel == NULL) {
-		pr_debug("is debugfs mounted on /sys/kernel/debug?\n");
+		if (tracefs_configured())
+			pr_debug("is tracefs mounted on /sys/kernel/tracing?\n");
+		else if (debugfs_configured())
+			pr_debug("is debugfs mounted on /sys/kernel/debug?\n");
+		else
+			pr_debug("Neither tracefs or debugfs is enabled in this kernel\n");
 		goto out_thread_map_delete;
 	}
 
diff --git a/tools/perf/tests/open-syscall.c b/tools/perf/tests/open-syscall.c
index a33b2da..07aa319 100644
--- a/tools/perf/tests/open-syscall.c
+++ b/tools/perf/tests/open-syscall.c
@@ -18,7 +18,12 @@ int test__open_syscall_event(void)
 
 	evsel = perf_evsel__newtp("syscalls", "sys_enter_open");
 	if (evsel == NULL) {
-		pr_debug("is debugfs mounted on /sys/kernel/debug?\n");
+		if (tracefs_configured())
+			pr_debug("is tracefs mounted on /sys/kernel/tracing?\n");
+		else if (debugfs_configured())
+			pr_debug("is debugfs mounted on /sys/kernel/debug?\n");
+		else
+			pr_debug("Neither tracefs or debugfs is enabled in this kernel\n");
 		goto out_thread_map_delete;
 	}
 
diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-events.c
index 1cdab0c..ac243eb 100644
--- a/tools/perf/tests/parse-events.c
+++ b/tools/perf/tests/parse-events.c
@@ -3,6 +3,7 @@
 #include "evsel.h"
 #include "evlist.h"
 #include <api/fs/fs.h>
+#include <api/fs/tracefs.h>
 #include <api/fs/debugfs.h>
 #include "tests.h"
 #include "debug.h"
@@ -1192,11 +1193,19 @@ static int count_tracepoints(void)
 {
 	char events_path[PATH_MAX];
 	struct dirent *events_ent;
+	const char *mountpoint;
 	DIR *events_dir;
 	int cnt = 0;
 
-	scnprintf(events_path, PATH_MAX, "%s/tracing/events",
-		  debugfs_find_mountpoint());
+	mountpoint = tracefs_find_mountpoint();
+	if (mountpoint) {
+		scnprintf(events_path, PATH_MAX, "%s/events",
+			  mountpoint);
+	} else {
+		mountpoint = debugfs_find_mountpoint();
+		scnprintf(events_path, PATH_MAX, "%s/tracing/events",
+			  mountpoint);
+	}
 
 	events_dir = opendir(events_path);
 
diff --git a/tools/perf/util/cache.h b/tools/perf/util/cache.h
index d04d770..fbcca21 100644
--- a/tools/perf/util/cache.h
+++ b/tools/perf/util/cache.h
@@ -17,6 +17,7 @@
 #define EXEC_PATH_ENVIRONMENT "PERF_EXEC_PATH"
 #define DEFAULT_PERF_DIR_ENVIRONMENT ".perf"
 #define PERF_DEBUGFS_ENVIRONMENT "PERF_DEBUGFS_DIR"
+#define PERF_TRACEFS_ENVIRONMENT "PERF_TRACEFS_DIR"
 
 typedef int (*config_fn_t)(const char *, const char *, void *);
 extern int perf_default_config(const char *, const char *, void *);
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index c602ebb..a8b2c57 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -7,7 +7,6 @@
  * Released under the GPL v2. (and only v2, not any later version)
  */
 #include "util.h"
-#include <api/fs/debugfs.h>
 #include <api/fs/fs.h>
 #include <poll.h>
 #include "cpumap.h"
diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h
index ff6e1fa..39c3b57 100644
--- a/tools/perf/util/parse-events.h
+++ b/tools/perf/util/parse-events.h
@@ -122,6 +122,6 @@ void print_tracepoint_events(const char *subsys_glob, const char *event_glob,
 int print_hwcache_events(const char *event_glob, bool name_only);
 extern int is_valid_tracepoint(const char *event_string);
 
-extern int valid_debugfs_mount(const char *debugfs);
+int valid_event_mount(const char *eventfs);
 
 #endif /* __PERF_PARSE_EVENTS_H */
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 919937e..9dfbed9 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -41,6 +41,7 @@
 #include "symbol.h"
 #include "thread.h"
 #include <api/fs/debugfs.h>
+#include <api/fs/tracefs.h>
 #include "trace-event.h"	/* For __maybe_unused */
 #include "probe-event.h"
 #include "probe-finder.h"
@@ -1805,7 +1806,7 @@ static void print_open_warning(int err, bool is_kprobe)
 			   " - please rebuild kernel with %s.\n",
 			   is_kprobe ? 'k' : 'u', config);
 	} else if (err == -ENOTSUP)
-		pr_warning("Debugfs is not mounted.\n");
+		pr_warning("Tracefs or debugfs is not mounted.\n");
 	else
 		pr_warning("Failed to open %cprobe_events: %s\n",
 			   is_kprobe ? 'k' : 'u',
@@ -1816,7 +1817,7 @@ static void print_both_open_warning(int kerr, int uerr)
 {
 	/* Both kprobes and uprobes are disabled, warn it. */
 	if (kerr == -ENOTSUP && uerr == -ENOTSUP)
-		pr_warning("Debugfs is not mounted.\n");
+		pr_warning("Tracefs or debugfs is not mounted.\n");
 	else if (kerr == -ENOENT && uerr == -ENOENT)
 		pr_warning("Please rebuild kernel with CONFIG_KPROBE_EVENTS "
 			   "or/and CONFIG_UPROBE_EVENTS.\n");
@@ -1833,13 +1834,20 @@ static int open_probe_events(const char *trace_file, bool readwrite)
 {
 	char buf[PATH_MAX];
 	const char *__debugfs;
+	const char *tracing_dir = "";
 	int ret;
 
-	__debugfs = debugfs_find_mountpoint();
-	if (__debugfs == NULL)
-		return -ENOTSUP;
+	__debugfs = tracefs_find_mountpoint();
+	if (__debugfs == NULL) {
+		tracing_dir = "tracing/";
 
-	ret = e_snprintf(buf, PATH_MAX, "%s/%s", __debugfs, trace_file);
+		__debugfs = debugfs_find_mountpoint();
+		if (__debugfs == NULL)
+			return -ENOTSUP;
+	}
+
+	ret = e_snprintf(buf, PATH_MAX, "%s/%s%s",
+			 __debugfs, tracing_dir, trace_file);
 	if (ret >= 0) {
 		pr_debug("Opening %s write=%d\n", buf, readwrite);
 		if (readwrite && !probe_event_dry_run)
@@ -1855,12 +1863,12 @@ static int open_probe_events(const char *trace_file, bool readwrite)
 
 static int open_kprobe_events(bool readwrite)
 {
-	return open_probe_events("tracing/kprobe_events", readwrite);
+	return open_probe_events("kprobe_events", readwrite);
 }
 
 static int open_uprobe_events(bool readwrite)
 {
-	return open_probe_events("tracing/uprobe_events", readwrite);
+	return open_probe_events("uprobe_events", readwrite);
 }
 
 /* Get raw string list of current kprobe_events  or uprobe_events */
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c
index b86744f..92db3f1 100644
--- a/tools/perf/util/util.c
+++ b/tools/perf/util/util.c
@@ -303,13 +303,26 @@ void set_term_quiet_input(struct termios *old)
 	tcsetattr(0, TCSANOW, &tc);
 }
 
-static void set_tracing_events_path(const char *mountpoint)
+static void set_tracing_events_path(const char *tracing, const char *mountpoint)
 {
-	snprintf(tracing_events_path, sizeof(tracing_events_path), "%s/%s",
-		 mountpoint, "tracing/events");
+	snprintf(tracing_events_path, sizeof(tracing_events_path), "%s/%s%s",
+		 mountpoint, tracing, "events");
 }
 
-const char *perf_debugfs_mount(const char *mountpoint)
+static const char *__perf_tracefs_mount(const char *mountpoint)
+{
+	const char *mnt;
+
+	mnt = tracefs_mount(mountpoint);
+	if (!mnt)
+		return NULL;
+
+	set_tracing_events_path("", mnt);
+
+	return mnt;
+}
+
+static const char *__perf_debugfs_mount(const char *mountpoint)
 {
 	const char *mnt;
 
@@ -317,7 +330,20 @@ const char *perf_debugfs_mount(const char *mountpoint)
 	if (!mnt)
 		return NULL;
 
-	set_tracing_events_path(mnt);
+	set_tracing_events_path("tracing/", mnt);
+
+	return mnt;
+}
+
+const char *perf_debugfs_mount(const char *mountpoint)
+{
+	const char *mnt;
+
+	mnt = __perf_tracefs_mount(mountpoint);
+	if (mnt)
+		return mnt;
+
+	mnt = __perf_debugfs_mount(mountpoint);
 
 	return mnt;
 }
@@ -325,12 +351,19 @@ const char *perf_debugfs_mount(const char *mountpoint)
 void perf_debugfs_set_path(const char *mntpt)
 {
 	snprintf(debugfs_mountpoint, strlen(debugfs_mountpoint), "%s", mntpt);
-	set_tracing_events_path(mntpt);
+	set_tracing_events_path("tracing/", mntpt);
+}
+
+static const char *find_tracefs(void)
+{
+	const char *path = __perf_tracefs_mount(NULL);
+
+	return path;
 }
 
 static const char *find_debugfs(void)
 {
-	const char *path = perf_debugfs_mount(NULL);
+	const char *path = __perf_debugfs_mount(NULL);
 
 	if (!path)
 		fprintf(stderr, "Your kernel does not support the debugfs filesystem");
@@ -344,6 +377,7 @@ static const char *find_debugfs(void)
  */
 const char *find_tracing_dir(void)
 {
+	const char *tracing_dir = "";
 	static char *tracing;
 	static int tracing_found;
 	const char *debugfs;
@@ -351,11 +385,15 @@ const char *find_tracing_dir(void)
 	if (tracing_found)
 		return tracing;
 
-	debugfs = find_debugfs();
-	if (!debugfs)
-		return NULL;
+	debugfs = find_tracefs();
+	if (!debugfs) {
+		tracing_dir = "/tracing";
+		debugfs = find_debugfs();
+		if (!debugfs)
+			return NULL;
+	}
 
-	if (asprintf(&tracing, "%s/tracing", debugfs) < 0)
+	if (asprintf(&tracing, "%s%s", debugfs, tracing_dir) < 0)
 		return NULL;
 
 	tracing_found = 1;
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index 027a515..73c2f8e 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -75,6 +75,7 @@
 #include <linux/types.h>
 #include <sys/ttydefaults.h>
 #include <api/fs/debugfs.h>
+#include <api/fs/tracefs.h>
 #include <termios.h>
 #include <linux/bitops.h>
 #include <termios.h>

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

end of thread, other threads:[~2015-02-18 18:29 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-02 19:35 [PATCH 0/6 v2] perf: Have perf become tracefs aware Steven Rostedt
2015-02-02 19:35 ` [PATCH 1/6 v2] perf: Do not check debugfs MAGIC for tracing files Steven Rostedt
2015-02-18 18:27   ` [tip:perf/core] perf tools: " tip-bot for Steven Rostedt (Red Hat)
2015-02-02 19:35 ` [PATCH 2/6 v2] tools lib fs: Add helper to find mounted file systems Steven Rostedt
2015-02-18 18:28   ` [tip:perf/core] " tip-bot for Steven Rostedt (Red Hat)
2015-02-02 19:35 ` [PATCH 3/6 v2] tools lib api fs: Add tracefs mount helper functions Steven Rostedt
2015-02-18 18:28   ` [tip:perf/core] " tip-bot for Steven Rostedt (Red Hat)
2015-02-02 19:35 ` [PATCH 4/6 v2] tools lib api fs: Add DEBUGFS_DEFAULT_PATH macro Steven Rostedt
2015-02-18 18:28   ` [tip:perf/core] tools lib api debugfs: " tip-bot for Steven Rostedt (Red Hat)
2015-02-02 19:35 ` [PATCH 5/6 v2] tools lib api fs: Add {tracefs,debugfs}_configured() functions Steven Rostedt
2015-02-18 18:29   ` [tip:perf/core] tools lib api fs: Add {tracefs, debugfs}_configured() functions tip-bot for Steven Rostedt (Red Hat)
2015-02-02 19:35 ` [PATCH 6/6 v2] perf: Make perf aware of tracefs Steven Rostedt
2015-02-03 14:16   ` Jiri Olsa
2015-02-03 16:45     ` Steven Rostedt
2015-02-06  8:35       ` Arnaldo Carvalho de Melo
2015-02-08 14:12   ` Namhyung Kim
2015-02-09 15:24     ` Steven Rostedt
2015-02-18 18:29   ` [tip:perf/core] perf tools: " tip-bot for Steven Rostedt (Red Hat)

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.