From 4299a549979783668d787959d61ba22b6b200877 Mon Sep 17 00:00:00 2001 From: Jiri Olsa Date: Tue, 5 Nov 2013 15:14:45 +0100 Subject: perf tools: Factor sysfs code into generic fs object Moving sysfs code into generic fs object and preparing it to carry procfs support. This should be merged with tools/lib/lk/debugfs.c at some point in the future. Signed-off-by: Jiri Olsa Cc: Adrian Hunter Cc: Corey Ashford Cc: David Ahern Cc: Frederic Weisbecker Cc: Ingo Molnar Cc: Namhyung Kim Cc: Paul Mackerras Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/1383660887-1734-2-git-send-email-jolsa@redhat.com [ Added fs__ namespace qualifier to some more functions ] Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/fs.h | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 tools/perf/util/fs.h (limited to 'tools/perf/util/fs.h') diff --git a/tools/perf/util/fs.h b/tools/perf/util/fs.h new file mode 100644 index 00000000000..082edbd2159 --- /dev/null +++ b/tools/perf/util/fs.h @@ -0,0 +1,6 @@ +#ifndef __PERF_FS +#define __PERF_FS + +const char *sysfs_find_mountpoint(void); + +#endif /* __PERF_FS */ -- cgit v1.2.3-70-g09d2 From cf38fadade52df937521dd70d4437df1a9354cd9 Mon Sep 17 00:00:00 2001 From: Arnaldo Carvalho de Melo Date: Tue, 5 Nov 2013 14:48:50 -0300 Subject: perf fs: Rename NAME_find_mountpoint() to NAME__mountpoint() Shorten it, "finding" it is an implementation detail, what callers want is the pathname, not to ask for it to _always_ do the lookup. And the existing implementation already caches it, i.e. it doesn't "finds" it on every call. Cc: Adrian Hunter Cc: David Ahern Cc: Frederic Weisbecker Cc: Jiri Olsa Cc: Mike Galbraith Cc: Paul Mackerras Cc: Peter Zijlstra Cc: Stephane Eranian Link: http://lkml.kernel.org/n/tip-r24wa4bvtccg7mnkessrbbdj@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/tests/parse-events.c | 4 ++-- tools/perf/util/cpumap.c | 4 ++-- tools/perf/util/fs.c | 12 ++++++------ tools/perf/util/fs.h | 2 +- tools/perf/util/pmu.c | 15 +++++---------- 5 files changed, 16 insertions(+), 21 deletions(-) (limited to 'tools/perf/util/fs.h') diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-events.c index f47bf459c3f..ef671cd41bb 100644 --- a/tools/perf/tests/parse-events.c +++ b/tools/perf/tests/parse-events.c @@ -1456,7 +1456,7 @@ static int test_pmu(void) int ret; snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/format/", - sysfs_find_mountpoint()); + sysfs__mountpoint()); ret = stat(path, &st); if (ret) @@ -1473,7 +1473,7 @@ static int test_pmu_events(void) int ret; snprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu/events/", - sysfs_find_mountpoint()); + sysfs__mountpoint()); ret = stat(path, &st); if (ret) { diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c index 4af5a23b242..a9b48c42e81 100644 --- a/tools/perf/util/cpumap.c +++ b/tools/perf/util/cpumap.c @@ -216,7 +216,7 @@ int cpu_map__get_socket(struct cpu_map *map, int idx) cpu = map->map[idx]; - mnt = sysfs_find_mountpoint(); + mnt = sysfs__mountpoint(); if (!mnt) return -1; @@ -279,7 +279,7 @@ int cpu_map__get_core(struct cpu_map *map, int idx) cpu = map->map[idx]; - mnt = sysfs_find_mountpoint(); + mnt = sysfs__mountpoint(); if (!mnt) return -1; diff --git a/tools/perf/util/fs.c b/tools/perf/util/fs.c index a2413e842a0..77bac4e4c11 100644 --- a/tools/perf/util/fs.c +++ b/tools/perf/util/fs.c @@ -88,7 +88,7 @@ static const char *fs__get_mountpoint(struct fs *fs) return fs__read_mounts(fs) ? fs->path : NULL; } -static const char *fs__find_mountpoint(int idx) +static const char *fs__mountpoint(int idx) { struct fs *fs = &fs__entries[idx]; @@ -98,10 +98,10 @@ static const char *fs__find_mountpoint(int idx) return fs__get_mountpoint(fs); } -#define FIND_MOUNTPOINT(name, idx) \ -const char *name##_find_mountpoint(void) \ -{ \ - return fs__find_mountpoint(idx); \ +#define FS__MOUNTPOINT(name, idx) \ +const char *name##__mountpoint(void) \ +{ \ + return fs__mountpoint(idx); \ } -FIND_MOUNTPOINT(sysfs, FS__SYSFS); +FS__MOUNTPOINT(sysfs, FS__SYSFS); diff --git a/tools/perf/util/fs.h b/tools/perf/util/fs.h index 082edbd2159..a7561c83c33 100644 --- a/tools/perf/util/fs.h +++ b/tools/perf/util/fs.h @@ -1,6 +1,6 @@ #ifndef __PERF_FS #define __PERF_FS -const char *sysfs_find_mountpoint(void); +const char *sysfs__mountpoint(void); #endif /* __PERF_FS */ diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 45b42dffcd7..c232d8dd410 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -77,9 +77,8 @@ static int pmu_format(const char *name, struct list_head *format) { struct stat st; char path[PATH_MAX]; - const char *sysfs; + const char *sysfs = sysfs__mountpoint(); - sysfs = sysfs_find_mountpoint(); if (!sysfs) return -1; @@ -166,9 +165,8 @@ static int pmu_aliases(const char *name, struct list_head *head) { struct stat st; char path[PATH_MAX]; - const char *sysfs; + const char *sysfs = sysfs__mountpoint(); - sysfs = sysfs_find_mountpoint(); if (!sysfs) return -1; @@ -212,11 +210,10 @@ static int pmu_type(const char *name, __u32 *type) { struct stat st; char path[PATH_MAX]; - const char *sysfs; FILE *file; int ret = 0; + const char *sysfs = sysfs__mountpoint(); - sysfs = sysfs_find_mountpoint(); if (!sysfs) return -1; @@ -241,11 +238,10 @@ static int pmu_type(const char *name, __u32 *type) static void pmu_read_sysfs(void) { char path[PATH_MAX]; - const char *sysfs; DIR *dir; struct dirent *dent; + const char *sysfs = sysfs__mountpoint(); - sysfs = sysfs_find_mountpoint(); if (!sysfs) return; @@ -270,11 +266,10 @@ static struct cpu_map *pmu_cpumask(const char *name) { struct stat st; char path[PATH_MAX]; - const char *sysfs; FILE *file; struct cpu_map *cpus; + const char *sysfs = sysfs__mountpoint(); - sysfs = sysfs_find_mountpoint(); if (!sysfs) return NULL; -- cgit v1.2.3-70-g09d2 From a9862418547e818aa5842840aecfa81d733b97e9 Mon Sep 17 00:00:00 2001 From: Jiri Olsa Date: Tue, 5 Nov 2013 15:14:46 +0100 Subject: perf fs: Add procfs support Adding procfs support into fs class. The interface function: const char *procfs__mountpoint(void); provides existing mountpoint path for procfs. Signed-off-by: Jiri Olsa Cc: Adrian Hunter Cc: Corey Ashford Cc: David Ahern Cc: Frederic Weisbecker Cc: Ingo Molnar Cc: Namhyung Kim Cc: Paul Mackerras Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/1383660887-1734-3-git-send-email-jolsa@redhat.com [ Fixup namespace ] Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/fs.c | 16 ++++++++++++++-- tools/perf/util/fs.h | 1 + tools/perf/util/include/linux/magic.h | 4 ++++ 3 files changed, 19 insertions(+), 2 deletions(-) (limited to 'tools/perf/util/fs.h') diff --git a/tools/perf/util/fs.c b/tools/perf/util/fs.c index 77bac4e4c11..f5be1f26e72 100644 --- a/tools/perf/util/fs.c +++ b/tools/perf/util/fs.c @@ -9,6 +9,11 @@ static const char * const sysfs__fs_known_mountpoints[] = { 0, }; +static const char * const procfs__known_mountpoints[] = { + "/proc", + 0, +}; + struct fs { const char *name; const char * const *mounts; @@ -18,7 +23,8 @@ struct fs { }; enum { - FS__SYSFS = 0, + FS__SYSFS = 0, + FS__PROCFS = 1, }; static struct fs fs__entries[] = { @@ -27,6 +33,11 @@ static struct fs fs__entries[] = { .mounts = sysfs__fs_known_mountpoints, .magic = SYSFS_MAGIC, }, + [FS__PROCFS] = { + .name = "proc", + .mounts = procfs__known_mountpoints, + .magic = PROC_SUPER_MAGIC, + }, }; static bool fs__read_mounts(struct fs *fs) @@ -104,4 +115,5 @@ const char *name##__mountpoint(void) \ return fs__mountpoint(idx); \ } -FS__MOUNTPOINT(sysfs, FS__SYSFS); +FS__MOUNTPOINT(sysfs, FS__SYSFS); +FS__MOUNTPOINT(procfs, FS__PROCFS); diff --git a/tools/perf/util/fs.h b/tools/perf/util/fs.h index a7561c83c33..5e09ce1bab0 100644 --- a/tools/perf/util/fs.h +++ b/tools/perf/util/fs.h @@ -2,5 +2,6 @@ #define __PERF_FS const char *sysfs__mountpoint(void); +const char *procfs__mountpoint(void); #endif /* __PERF_FS */ diff --git a/tools/perf/util/include/linux/magic.h b/tools/perf/util/include/linux/magic.h index 58b64ed4da1..07d63cf3e0f 100644 --- a/tools/perf/util/include/linux/magic.h +++ b/tools/perf/util/include/linux/magic.h @@ -9,4 +9,8 @@ #define SYSFS_MAGIC 0x62656572 #endif +#ifndef PROC_SUPER_MAGIC +#define PROC_SUPER_MAGIC 0x9fa0 +#endif + #endif -- cgit v1.2.3-70-g09d2