Skip to contentSkip to conversation

perf tools: Add perf_event_max_sample_rate freq check

PATCH Superseded Jiri Olsa 3 participants 11 messages Nov 4, 2013 – Nov 5, 2013 perf events

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jiri Olsa

author
#0 lore raw

cover perf tools: Add perf_event_max_sample_rate freq check

hi,
adding the check for maximum allowed frequency rate defined in perf_event_max_sample_rate.

Plus procfs mountpoint reading code. Reachable here:
git://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git
perf/cc

jirka

Cc Adrian Hunter <[email protected]>
Cc Corey Ashford <[email protected]>
Cc David Ahern <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Joe Mario <[email protected]>
Cc Don Zickus <[email protected]>

---
Jiri Olsa (3):
perf tools: Factor sysfs code into generic fs object perf tools: Add procfs support into fs object perf tools: Check maximum frequency rate for record/top

 tools/perf/Makefile.perf              |   4 ++--
 tools/perf/builtin-record.c           |   3 +++
 tools/perf/builtin-top.c              |   3 +++
 tools/perf/tests/parse-events.c       |   2 +-
 tools/perf/util/cpumap.c              |   2 +-
 tools/perf/util/evlist.h              |   1 +
 tools/perf/util/fs.c                  | 119 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 tools/perf/util/fs.h                  |   7 ++++++
 tools/perf/util/include/linux/magic.h |   4 ++++
 tools/perf/util/pmu.c                 |   2 +-
 tools/perf/util/python-ext-sources    |   2 +-
 tools/perf/util/record.c              |  35 ++++++++++++++++++++++++++++
 tools/perf/util/sysfs.c               |  60 -----------------------------------------------
 tools/perf/util/sysfs.h               |   6 -----
 14 files changed, 178 insertions(+), 72 deletions(-)
 create mode 100644 tools/perf/util/fs.c
 create mode 100644 tools/perf/util/fs.h
 delete mode 100644 tools/perf/util/sysfs.c
 delete mode 100644 tools/perf/util/sysfs.h
author
#1 lore raw

PATCH 1/3 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.

Cc Adrian Hunter <[email protected]>
Cc Corey Ashford <[email protected]>
Cc David Ahern <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
---
 tools/perf/Makefile.perf           |   4 +-
 tools/perf/tests/parse-events.c    |   2 +-
 tools/perf/util/cpumap.c           |   2 +-
 tools/perf/util/fs.c               | 107 +++++++++++++++++++++++++++++++++++++
 tools/perf/util/fs.h               |   6 +++
 tools/perf/util/pmu.c              |   2 +-
 tools/perf/util/python-ext-sources |   2 +-
 tools/perf/util/sysfs.c            |  60 ---------------------
 tools/perf/util/sysfs.h            |   6 ---
 9 files changed, 119 insertions(+), 72 deletions(-)
 create mode 100644 tools/perf/util/fs.c
 create mode 100644 tools/perf/util/fs.h
 delete mode 100644 tools/perf/util/sysfs.c
 delete mode 100644 tools/perf/util/sysfs.h
tools/perf/Makefile.perf +2 -2
index bc7cfa1..f5d3251 100644
@@ -242,7 +242,7 @@ LIB_H += util/cache.h
 LIB_H += util/callchain.h
 LIB_H += util/build-id.h
 LIB_H += util/debug.h
-LIB_H += util/sysfs.h
+LIB_H += util/fs.h
 LIB_H += util/pmu.h
 LIB_H += util/event.h
 LIB_H += util/evsel.h
@@ -303,7 +303,7 @@ LIB_OBJS += $(OUTPUT)util/annotate.o
 LIB_OBJS += $(OUTPUT)util/build-id.o
 LIB_OBJS += $(OUTPUT)util/config.o
 LIB_OBJS += $(OUTPUT)util/ctype.o
-LIB_OBJS += $(OUTPUT)util/sysfs.o
+LIB_OBJS += $(OUTPUT)util/fs.o
 LIB_OBJS += $(OUTPUT)util/pmu.o
 LIB_OBJS += $(OUTPUT)util/environment.o
 LIB_OBJS += $(OUTPUT)util/event.o
tools/perf/tests/parse-events.c +1 -1
index 48114d1..f47bf45 100644
@@ -2,7 +2,7 @@
 #include "parse-events.h"
 #include "evsel.h"
 #include "evlist.h"
-#include "sysfs.h"
+#include "fs.h"
 #include <lk/debugfs.h>
 #include "tests.h"
 #include <linux/hw_breakpoint.h>
tools/perf/util/cpumap.c +1 -1
index beb8cf9..4af5a23 100644
@@ -1,5 +1,5 @@
 #include "util.h"
-#include "sysfs.h"
+#include "fs.h"
 #include "../perf.h"
 #include "cpumap.h"
 #include <assert.h>
tools/perf/util/fs.c new file +107 -0

107 lines not on this page · raw message

tools/perf/util/fs.h new file +6 -0
new file mode 100644
index 0000000..082edbd
@@ -0,0 +1,6 @@
+#ifndef __PERF_FS
+#define __PERF_FS
+
+const char *sysfs_find_mountpoint(void);
+
+#endif /* __PERF_FS */
tools/perf/util/pmu.c +1 -1
index 64362fe..45b42df 100644
@@ -4,7 +4,7 @@
 #include <unistd.h>
 #include <stdio.h>
 #include <dirent.h>
-#include "sysfs.h"
+#include "fs.h"
 #include "util.h"
 #include "pmu.h"
 #include "parse-events.h"
tools/perf/util/python-ext-sources +1 -1
index f75ae1b..239036f 100644
@@ -17,5 +17,5 @@ util/xyarray.c
 util/cgroup.c
 util/rblist.c
 util/strlist.c
-util/sysfs.c
+util/fs.c
 ../../lib/rbtree.c
tools/perf/util/sysfs.c deleted +0 -60

60 lines not on this page · raw message

tools/perf/util/sysfs.h deleted +0 -6
deleted file mode 100644
index a813b72..0000000
@@ -1,6 +0,0 @@
-#ifndef __SYSFS_H__
-#define __SYSFS_H__
-
-const char *sysfs_find_mountpoint(void);
-
-#endif /* __DEBUGFS_H__ */
Signature · 1 line
1.7.11.7
#2 lore raw

Re: [PATCH 1/3] perf tools: Factor sysfs code into generic fs object

Em Mon, Nov 04, 2013 at 12:06:11PM +0100, Jiri Olsa escreveu:

Quoted 2 lines

Moving sysfs code into generic fs object and preparing it to carry procfs support.

Cool, but these are not 'perf' specific at all, so, please see below some requests/suggestions:

tools/perf/Makefile.perf LIB_H += util/cache.h · line 245

Quoted 11 lines
tools/perf/Makefile.perf +1 -1
index bc7cfa1..f5d3251 100644
@@ -242,7 +242,7 @@ LIB_H += util/cache.h
 LIB_H += util/callchain.h
 LIB_H += util/build-id.h
 LIB_H += util/debug.h
-LIB_H += util/sysfs.h
+LIB_H += util/fs.h

Perfect naming, 'fs'

Quoted 19 lines
tools/perf/util/cpumap.c +1 -1
index beb8cf9..4af5a23 100644
@@ -1,5 +1,5 @@
 #include "util.h"
-#include "sysfs.h"
+#include "fs.h"
 #include "../perf.h"
 #include "cpumap.h"
 #include <assert.h>
tools/perf/util/fs.c new file +2 -0
new file mode 100644
index 0000000..346669a
@@ -0,0 +1,107 @@
+
+/* TODO merge/factor into tools/lib/lk/debugfs.c */

tools/perf/util/fs.c line 12

Quoted 10 lines
tools/perf/util/fs.c new file +10 -0
+
+#include "util.h"
+#include "util/fs.h"
+
+static const char * const sysfs_known_mountpoints[] = {
+	"/sys",
+	0,
+};
+
+struct perf_fs {

Ditch the 'perf', make it plain 'struct fs'.

tools/perf/util/fs.c line 21

Quoted 9 lines
tools/perf/util/fs.c new file +9 -0
+	const char		*name;
+	const char * const	*mounts;
+	char			 path[PATH_MAX + 1];
+	bool			 found;
+	long			 magic;
+};
+
+enum {
+	FS_SYSFS = 0,

FS__SYSFS

tools/perf/util/fs.c line 24

Quoted 3 lines
tools/perf/util/fs.c new file +3 -0
+};
+
+static struct perf_fs fss[] = {

Funny name, perhaps fs__entries instead? :-)

And here we have it static, at some point we could introduce a 'fs__register', that would be the counterpart of 'register_filesystem' in the kernel sources.

Quoted 18 lines
tools/perf/util/fs.c new file +18 -0
+	[FS_SYSFS] = {
+		.name	= "sysfs",
+		.mounts	= sysfs_known_mountpoints,
+		.magic	= SYSFS_MAGIC,
+	},
+};
+
+static bool read_mounts(struct perf_fs *fs)
+{
+	bool found = false;
+	char type[100];
+	FILE *fp;
+
+	fp = fopen("/proc/mounts", "r");
+	if (fp == NULL)
+		return NULL;
+
+	while (!found &&

tools/perf/util/fs.c line 52

Quoted 10 lines
tools/perf/util/fs.c new file +10 -0
+	       fscanf(fp, "%*s %" STR(PATH_MAX) "s %99s %*s %*d %*d\n",
+		      fs->path, type) == 2) {
+
+		if (strcmp(type, fs->name) == 0)
+			found = true;
+	}
+
+	fclose(fp);
+	return fs->found = found;
+}

This is not a per instance method, I to traverse /proc/mounts once, checking all entries in 'fs__entries' marking the ones that are present, i.e. fs__entries would be a list/tree of 'struct fs'.

tools/perf/util/fs.c line 64

Quoted 11 lines
tools/perf/util/fs.c new file +11 -0
+static int valid_mount(const char *fs, long magic)
+{
+	struct statfs st_fs;
+
+	if (statfs(fs, &st_fs) < 0)
+		return -ENOENT;
+	else if (st_fs.f_type != magic)
+		return -ENOENT;
+
+	return 0;
+}

Now this is getting me confused, so we will have to traverse /proc/mounts looking for that .name to be what we expect in entries and afterwards we do a second step, checking if the magic number is the one expected? Can't we do both verifications in just one place?

I know you haven't written this code, is just generalizing, but I got confused so had to comment on it :-\

Perhaps since you're just making it useful for more filesystems just please address the 'perf_fs' naming suggestions and we can deal with these other issues later?

- Arnaldo

Quoted 158 lines
tools/perf/util/fs.c new file +42 -0
+static bool check_mounts(struct perf_fs *fs)
+{
+	const char * const *ptr;
+
+	ptr = fs->mounts;
+	while (*ptr) {
+		if (valid_mount(*ptr, fs->magic) == 0) {
+			fs->found = true;
+			strcpy(fs->path, *ptr);
+			return true;
+		}
+		ptr++;
+	}
+
+	return false;
+}
+
+static const char *get_mountpoint(struct perf_fs *fs)
+{
+	if (check_mounts(fs))
+		return fs->path;
+
+	return read_mounts(fs) ? fs->path : NULL;
+}
+
+static const char *find_mountpoint(int idx)
+{
+	struct perf_fs *fs = &fss[idx];
+
+	if (fs->found)
+		return (const char *) fs->path;
+
+	return get_mountpoint(fs);
+}
+
+#define FIND_MOUNTPOINT(name, idx)		\
+const char *name##_find_mountpoint(void)	\
+{						\
+	return find_mountpoint(idx);		\
+}
+
+FIND_MOUNTPOINT(sysfs, FS_SYSFS);
tools/perf/util/fs.h new file +6 -0
new file mode 100644
index 0000000..082edbd
@@ -0,0 +1,6 @@
+#ifndef __PERF_FS
+#define __PERF_FS
+
+const char *sysfs_find_mountpoint(void);
+
+#endif /* __PERF_FS */
tools/perf/util/pmu.c +1 -1
index 64362fe..45b42df 100644
@@ -4,7 +4,7 @@
 #include <unistd.h>
 #include <stdio.h>
 #include <dirent.h>
-#include "sysfs.h"
+#include "fs.h"
 #include "util.h"
 #include "pmu.h"
 #include "parse-events.h"
tools/perf/util/python-ext-sources +1 -1
index f75ae1b..239036f 100644
@@ -17,5 +17,5 @@ util/xyarray.c
 util/cgroup.c
 util/rblist.c
 util/strlist.c
-util/sysfs.c
+util/fs.c
 ../../lib/rbtree.c
tools/perf/util/sysfs.c deleted +0 -60
deleted file mode 100644
index f71e9ea..0000000
@@ -1,60 +0,0 @@
-
-#include "util.h"
-#include "sysfs.h"
-
-static const char * const sysfs_known_mountpoints[] = {
-	"/sys",
-	0,
-};
-
-static int sysfs_found;
-char sysfs_mountpoint[PATH_MAX + 1];
-
-static int sysfs_valid_mountpoint(const char *sysfs)
-{
-	struct statfs st_fs;
-
-	if (statfs(sysfs, &st_fs) < 0)
-		return -ENOENT;
-	else if (st_fs.f_type != (long) SYSFS_MAGIC)
-		return -ENOENT;
-
-	return 0;
-}
-
-const char *sysfs_find_mountpoint(void)
-{
-	const char * const *ptr;
-	char type[100];
-	FILE *fp;
-
-	if (sysfs_found)
-		return (const char *) sysfs_mountpoint;
-
-	ptr = sysfs_known_mountpoints;
-	while (*ptr) {
-		if (sysfs_valid_mountpoint(*ptr) == 0) {
-			sysfs_found = 1;
-			strcpy(sysfs_mountpoint, *ptr);
-			return sysfs_mountpoint;
-		}
-		ptr++;
-	}
-
-	/* give up and parse /proc/mounts */
-	fp = fopen("/proc/mounts", "r");
-	if (fp == NULL)
-		return NULL;
-
-	while (!sysfs_found &&
-	       fscanf(fp, "%*s %" STR(PATH_MAX) "s %99s %*s %*d %*d\n",
-		      sysfs_mountpoint, type) == 2) {
-
-		if (strcmp(type, "sysfs") == 0)
-			sysfs_found = 1;
-	}
-
-	fclose(fp);
-
-	return sysfs_found ? sysfs_mountpoint : NULL;
-}
tools/perf/util/sysfs.h deleted +0 -6
deleted file mode 100644
index a813b72..0000000
@@ -1,6 +0,0 @@
-#ifndef __SYSFS_H__
-#define __SYSFS_H__
-
-const char *sysfs_find_mountpoint(void);
-
-#endif /* __DEBUGFS_H__ */
Signature · 1 line
1.7.11.7
author
#3 lore raw

Re: [PATCH 1/3] perf tools: Factor sysfs code into generic fs object

On Tue, Nov 05, 2013 at 10:48:14AM -0200, Arnaldo Carvalho de Melo wrote:

SNIP

Quoted 16 lines
Quoted 1 line

+struct perf_fs {

Ditch the 'perf', make it plain 'struct fs'.

tools/perf/util/fs.c line 21

Quoted 9 lines
tools/perf/util/fs.c new file +9 -0
+	const char		*name;
+	const char * const	*mounts;
+	char			 path[PATH_MAX + 1];
+	bool			 found;
+	long			 magic;
+};
+
+enum {
+	FS_SYSFS = 0,

FS__SYSFS

Quoted 5 lines

tools/perf/util/fs.c line 24

Quoted 3 lines
tools/perf/util/fs.c new file +3 -0
+};
+
+static struct perf_fs fss[] = {

Funny name, perhaps fs__entries instead? :-)

ok, will change all above namings :)

Quoted 38 lines

And here we have it static, at some point we could introduce a 'fs__register', that would be the counterpart of 'register_filesystem' in the kernel sources.

Quoted 18 lines
tools/perf/util/fs.c new file +18 -0
+	[FS_SYSFS] = {
+		.name	= "sysfs",
+		.mounts	= sysfs_known_mountpoints,
+		.magic	= SYSFS_MAGIC,
+	},
+};
+
+static bool read_mounts(struct perf_fs *fs)
+{
+	bool found = false;
+	char type[100];
+	FILE *fp;
+
+	fp = fopen("/proc/mounts", "r");
+	if (fp == NULL)
+		return NULL;
+
+	while (!found &&

tools/perf/util/fs.c line 52

Quoted 10 lines
tools/perf/util/fs.c new file +10 -0
+	       fscanf(fp, "%*s %" STR(PATH_MAX) "s %99s %*s %*d %*d\n",
+		      fs->path, type) == 2) {
+
+		if (strcmp(type, fs->name) == 0)
+			found = true;
+	}
+
+	fclose(fp);
+	return fs->found = found;
+}

This is not a per instance method, I to traverse /proc/mounts once, checking all entries in 'fs__entries' marking the ones that are present, i.e. fs__entries would be a list/tree of 'struct fs'.

Quoted 16 lines

tools/perf/util/fs.c line 64

Quoted 11 lines
tools/perf/util/fs.c new file +11 -0
+static int valid_mount(const char *fs, long magic)
+{
+	struct statfs st_fs;
+
+	if (statfs(fs, &st_fs) < 0)
+		return -ENOENT;
+	else if (st_fs.f_type != magic)
+		return -ENOENT;
+
+	return 0;
+}

Now this is getting me confused, so we will have to traverse /proc/mounts looking for that .name to be what we expect in entries and afterwards we do a second step, checking if the magic number is the one expected? Can't we do both verifications in just one place?

the valid_mount is called only for preconfigured
(known mountpoints) paths

Quoted 3 lines

I know you haven't written this code, is just generalizing, but I got confused so had to comment on it :-\

yep ;-) perhaps some init code could do that

Quoted 4 lines

Perhaps since you're just making it useful for more filesystems just please address the 'perf_fs' naming suggestions and we can deal with these other issues later?

ok, I have already changes for the 3/3 change,
I'll send it together

jirka

#4 lore raw

Re: [PATCH 1/3] perf tools: Factor sysfs code into generic fs object

Em Tue, Nov 05, 2013 at 02:07:29PM +0100, Jiri Olsa escreveu:

Quoted 5 lines · Arnaldo Carvalho de Melo
Quoted 2 lines

I know you haven't written this code, is just generalizing, but I got confused so had to comment on it :-\

yep ;-) perhaps some init code could do that

At some point I want to have an init system similar to the kernel, i.e. mark something as needing to be initialized with something like __init and some linker magic (stolen from the kernel) would do it, think about gtk, tui, symbol lib, lotsa init stuff, with some ordering constraints...

Quoted 6 lines
Quoted 3 lines

Perhaps since you're just making it useful for more filesystems just please address the 'perf_fs' naming suggestions and we can deal with these other issues later?

ok, I have already changes for the 3/3 change,
I'll send it together

Thanks!

- Arnaldo

author
#5 lore raw

PATCH 2/3 perf tools: Add procfs support into fs object

In reply to Jiri Olsa

Adding procfs support into fs object.

The interface function:
const char *procfs_find_mountpoint(void);

provides valid mountpoint path for procfs.

Cc Adrian Hunter <[email protected]>
Cc Corey Ashford <[email protected]>
Cc David Ahern <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Joe Mario <[email protected]>
Cc Don Zickus <[email protected]>
---
 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(-)
tools/perf/util/fs.c +14 -2
index 346669a..37b18b7 100644
@@ -9,6 +9,11 @@ static const char * const sysfs_known_mountpoints[] = {
 	0,
 };
 
+static const char * const procfs_known_mountpoints[] = {
+	"/proc",
+	0,
+};
+
 struct perf_fs {
 	const char		*name;
 	const char * const	*mounts;
@@ -18,7 +23,8 @@ struct perf_fs {
 };
 
 enum {
-	FS_SYSFS = 0,
+	FS_SYSFS  = 0,
+	FS_PROCFS = 1,
 };
 
 static struct perf_fs fss[] = {
@@ -27,6 +33,11 @@ static struct perf_fs fss[] = {
 		.mounts	= sysfs_known_mountpoints,
 		.magic	= SYSFS_MAGIC,
 	},
+	[FS_PROCFS] = {
+		.name	= "proc",
+		.mounts	= procfs_known_mountpoints,
+		.magic	= PROC_SUPER_MAGIC,
+	},
 };
 
 static bool read_mounts(struct perf_fs *fs)
@@ -104,4 +115,5 @@ const char *name##_find_mountpoint(void)	\
 	return find_mountpoint(idx);		\
 }
 
-FIND_MOUNTPOINT(sysfs, FS_SYSFS);
+FIND_MOUNTPOINT(sysfs,  FS_SYSFS);
+FIND_MOUNTPOINT(procfs, FS_PROCFS);
tools/perf/util/fs.h +1 -0
index 082edbd..bc6556f 100644
@@ -2,5 +2,6 @@
 #define __PERF_FS
 
 const char *sysfs_find_mountpoint(void);
+const char *procfs_find_mountpoint(void);
 
 #endif /* __PERF_FS */
tools/perf/util/include/linux/magic.h +4 -0
index 58b64ed..07d63cf 100644
@@ -9,4 +9,8 @@
 #define SYSFS_MAGIC            0x62656572
 #endif
 
+#ifndef PROC_SUPER_MAGIC
+#define PROC_SUPER_MAGIC       0x9fa0
+#endif
+
 #endif
Signature · 1 line
1.7.11.7
author
#6 lore raw

PATCH 3/3 perf tools: Check maximum frequency rate for record/top

In reply to Jiri Olsa

Adding the check for maximum allowed frequency rate defined in following file:
/proc/sys/kernel/perf_event_max_sample_rate

When we cross the maximum value we fail and display detailed error message with advise.

Cc Adrian Hunter <[email protected]>
Cc Corey Ashford <[email protected]>
Cc David Ahern <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
---
 tools/perf/builtin-record.c |  3 +++
 tools/perf/builtin-top.c    |  3 +++
 tools/perf/util/evlist.h    |  1 +
 tools/perf/util/record.c    | 35 +++++++++++++++++++++++++++++++++++
 4 files changed, 42 insertions(+)
tools/perf/builtin-record.c +3 -0
index ab8d15e..f300034 100644
@@ -201,6 +201,9 @@ static int perf_record__open(struct perf_record *rec)
 	struct perf_record_opts *opts = &rec->opts;
 	int rc = 0;
 
+	if (perf_opts__check(opts))
+		return -1;
+
 	perf_evlist__config(evlist, opts);
 
 	list_for_each_entry(pos, &evlist->entries, node) {
tools/perf/builtin-top.c +3 -0
index 04f5bf2..9c17af8 100644
@@ -879,6 +879,9 @@ static int perf_top__start_counters(struct perf_top *top)
 	struct perf_evlist *evlist = top->evlist;
 	struct perf_record_opts *opts = &top->record_opts;
 
+	if (perf_opts__check(opts))
+		return -1;
+
 	perf_evlist__config(evlist, opts);
 
 	list_for_each_entry(counter, &evlist->entries, node) {
tools/perf/util/evlist.h +1 -0
index 6e8acc9..3acadd9 100644
@@ -99,6 +99,7 @@ void perf_evlist__set_id_pos(struct perf_evlist *evlist);
 bool perf_can_sample_identifier(void);
 void perf_evlist__config(struct perf_evlist *evlist,
 			 struct perf_record_opts *opts);
+int perf_opts__check(struct perf_record_opts *opts);
 
 int perf_evlist__prepare_workload(struct perf_evlist *evlist,
 				  struct perf_target *target,
tools/perf/util/record.c +35 -0
index 18d73aa..d881209 100644
@@ -2,6 +2,8 @@
 #include "evsel.h"
 #include "cpumap.h"
 #include "parse-events.h"
+#include "fs.h"
+#include "util.h"
 
 typedef void (*setup_probe_fn_t)(struct perf_evsel *evsel);
 
@@ -106,3 +108,36 @@ void perf_evlist__config(struct perf_evlist *evlist,
 
 	perf_evlist__set_id_pos(evlist);
 }
+
+static int get_max_rate(unsigned int *rate)
+{
+	const char *procfs;
+	char path[PATH_MAX];
+
+	procfs = procfs_find_mountpoint();
+	if (!procfs)
+		return -1;
+
+	snprintf(path, PATH_MAX,
+		 "%s/sys/kernel/perf_event_max_sample_rate", procfs);
+
+	return filename__read_int(path, (int *) rate);
+}
+
+int perf_opts__check(struct perf_record_opts *opts)
+{
+	unsigned int max_rate;
+
+	if (get_max_rate(&max_rate))
+		return 0;
+
+	if (max_rate < opts->freq) {
+		pr_err("Maximum rate (%u) for frequency reached.\n"
+		   "Please use -F freq option with lower value or consider\n"
+		   "tweaking /proc/sys/kernel/perf_event_max_sample_rate.\n",
+		   max_rate);
+		return -1;
+	}
+
+	return 0;
+}
Signature · 1 line
1.7.11.7
#7 lore raw

Re: [PATCH 3/3] perf tools: Check maximum frequency rate for record/top

Quoted 6 lines · Jiri Olsa

Adding the check for maximum allowed frequency rate defined in following file:
/proc/sys/kernel/perf_event_max_sample_rate

When we cross the maximum value we fail and display detailed error message with advise.

perf commands should automatically adjust the default frequency too. If the user did not specify a frequency then this message is going to be confusing.

Though the algorithm that keeps lowering the rate should be tweaked as well.

David

author
#8 lore raw

Re: [PATCH 3/3] perf tools: Check maximum frequency rate for record/top

Quoted 11 lines · David Ahern
Quoted 6 lines · Jiri Olsa

Adding the check for maximum allowed frequency rate defined in following file:
/proc/sys/kernel/perf_event_max_sample_rate

When we cross the maximum value we fail and display detailed error message with advise.

perf commands should automatically adjust the default frequency too. If the user did not specify a frequency then this message is going to be confusing.

ok, I'll add that check and probably some warning
if we are force to go below the default rate.

Quoted 2 lines

Though the algorithm that keeps lowering the rate should be tweaked as well.

yea.. I was thinking putting the max rate back up after some sane period

or/plus having 'echo 0 > /proc/sys/kernel/perf_event_max_sample_rate' to disable it completely

jirka

#9 lore raw

Re: [PATCH 3/3] perf tools: Check maximum frequency rate for record/top

Em Mon, Nov 04, 2013 at 04:32:16PM +0100, Jiri Olsa escreveu:

Quoted 9 lines · David Ahern
Quoted 8 lines · Jiri Olsa
Quoted 6 lines

Adding the check for maximum allowed frequency rate defined in following file:
/proc/sys/kernel/perf_event_max_sample_rate

When we cross the maximum value we fail and display detailed error message with advise.

Quoted 6 lines
Quoted 3 lines

perf commands should automatically adjust the default frequency too. If the user did not specify a frequency then this message is going to be confusing.

ok, I'll add that check and probably some warning
if we are force to go below the default rate.

I think we should just make it clear the frequency used and pick the best according to the hardware.

And we are not doing gthat at all, at least in the TUI, need to change that.

Only in the stdio, with that long list of commented lines, that should as well be hidden, too verbose.

And here we also see the frequency used:

[root@zoo linux]# perf evlist -v
cycles: sample_freq=4000, size: 96, sample_type: IP|TID|TIME|PERIOD,
disabled: 1, inherit: 1, mmap: 1, comm: 1, freq: 1, enable_on_exec: 1,
sample_id_all: 1, exclude_guest: 1
[root@zoo linux]#

Quoted 10 lines
Quoted 2 lines

Though the algorithm that keeps lowering the rate should be tweaked as well.

yea.. I was thinking putting the max rate back up after some sane period

or/plus having 'echo 0 > /proc/sys/kernel/perf_event_max_sample_rate' to disable it completely

jirka

author
#10 lore raw
In reply to Jiri Olsa
Quoted 7 lines · Jiri Olsa

hi,
adding the check for maximum allowed frequency rate defined in perf_event_max_sample_rate.

Plus procfs mountpoint reading code. Reachable here:
git://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git
perf/cc

oops, ^^^ should be 'perf/max_rate'

jirka