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

From: Jiri Olsa
Date: Mon Nov 04 2013 - 06:07:42 EST


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.

Signed-off-by: Jiri Olsa <jolsa@xxxxxxxxxx>
Cc: Adrian Hunter <adrian.hunter@xxxxxxxxx>
Cc: Corey Ashford <cjashfor@xxxxxxxxxxxxxxxxxx>
Cc: David Ahern <dsahern@xxxxxxxxx>
Cc: Frederic Weisbecker <fweisbec@xxxxxxxxx>
Cc: Ingo Molnar <mingo@xxxxxxx>
Cc: Namhyung Kim <namhyung@xxxxxxxxxx>
Cc: Paul Mackerras <paulus@xxxxxxxxx>
Cc: Peter Zijlstra <a.p.zijlstra@xxxxxxxxx>
Cc: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
---
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(+)

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index ab8d15e..f300034 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -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) {
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 04f5bf2..9c17af8 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -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) {
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h
index 6e8acc9..3acadd9 100644
--- a/tools/perf/util/evlist.h
+++ b/tools/perf/util/evlist.h
@@ -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,
diff --git a/tools/perf/util/record.c b/tools/perf/util/record.c
index 18d73aa..d881209 100644
--- a/tools/perf/util/record.c
+++ b/tools/perf/util/record.c
@@ -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;
+}
--
1.7.11.7

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/