Browse Source

perf tools: Add perf_event_paranoid()

Add a function to return the value of
/proc/sys/kernel/perf_event_paranoid.

This will be used to determine default values for mmap size because perf
is not subject to mmap limits when perf_event_paranoid is less than
zero.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/1386765443-26966-12-git-send-email-alexander.shishkin@linux.intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Adrian Hunter 11 years ago
parent
commit
1a47245d2f
3 changed files with 21 additions and 2 deletions
  1. 1 2
      tools/perf/util/evlist.c
  2. 19 0
      tools/perf/util/util.c
  3. 1 0
      tools/perf/util/util.h

+ 1 - 2
tools/perf/util/evlist.c

@@ -1191,8 +1191,7 @@ int perf_evlist__strerror_open(struct perf_evlist *evlist __maybe_unused,
 				    "Error:\t%s.\n"
 				    "Error:\t%s.\n"
 				    "Hint:\tCheck /proc/sys/kernel/perf_event_paranoid setting.", emsg);
 				    "Hint:\tCheck /proc/sys/kernel/perf_event_paranoid setting.", emsg);
 
 
-		if (filename__read_int("/proc/sys/kernel/perf_event_paranoid", &value))
-			break;
+		value = perf_event_paranoid();
 
 
 		printed += scnprintf(buf + printed, size - printed, "\nHint:\t");
 		printed += scnprintf(buf + printed, size - printed, "\nHint:\t");
 
 

+ 19 - 0
tools/perf/util/util.c

@@ -1,5 +1,6 @@
 #include "../perf.h"
 #include "../perf.h"
 #include "util.h"
 #include "util.h"
+#include "fs.h"
 #include <sys/mman.h>
 #include <sys/mman.h>
 #ifdef HAVE_BACKTRACE_SUPPORT
 #ifdef HAVE_BACKTRACE_SUPPORT
 #include <execinfo.h>
 #include <execinfo.h>
@@ -8,6 +9,7 @@
 #include <stdlib.h>
 #include <stdlib.h>
 #include <string.h>
 #include <string.h>
 #include <errno.h>
 #include <errno.h>
+#include <limits.h>
 #include <linux/kernel.h>
 #include <linux/kernel.h>
 
 
 /*
 /*
@@ -496,3 +498,20 @@ const char *get_filename_for_perf_kvm(void)
 
 
 	return filename;
 	return filename;
 }
 }
+
+int perf_event_paranoid(void)
+{
+	char path[PATH_MAX];
+	const char *procfs = procfs__mountpoint();
+	int value;
+
+	if (!procfs)
+		return INT_MAX;
+
+	scnprintf(path, PATH_MAX, "%s/sys/kernel/perf_event_paranoid", procfs);
+
+	if (filename__read_int(path, &value))
+		return INT_MAX;
+
+	return value;
+}

+ 1 - 0
tools/perf/util/util.h

@@ -321,6 +321,7 @@ void free_srcline(char *srcline);
 
 
 int filename__read_int(const char *filename, int *value);
 int filename__read_int(const char *filename, int *value);
 int filename__read_str(const char *filename, char **buf, size_t *sizep);
 int filename__read_str(const char *filename, char **buf, size_t *sizep);
+int perf_event_paranoid(void);
 
 
 const char *get_filename_for_perf_kvm(void);
 const char *get_filename_for_perf_kvm(void);
 #endif /* GIT_COMPAT_UTIL_H */
 #endif /* GIT_COMPAT_UTIL_H */