From: Jiri Olsa <jolsa@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: Jiri Olsa <jolsa@redhat.com>,
Adrian Hunter <adrian.hunter@intel.com>,
Corey Ashford <cjashfor@linux.vnet.ibm.com>,
David Ahern <dsahern@gmail.com>,
Frederic Weisbecker <fweisbec@gmail.com>,
Ingo Molnar <mingo@elte.hu>, Namhyung Kim <namhyung@kernel.org>,
Paul Mackerras <paulus@samba.org>,
Peter Zijlstra <a.p.zijlstra@chello.nl>,
Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH 3/3] perf tools: Check maximum frequency rate for record/top
Date: Mon, 4 Nov 2013 12:06:13 +0100 [thread overview]
Message-ID: <1383563173-17466-4-git-send-email-jolsa@redhat.com> (raw)
In-Reply-To: <1383563173-17466-1-git-send-email-jolsa@redhat.com>
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@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
---
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
next prev parent reply other threads:[~2013-11-04 11:07 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-04 11:06 [PATCH 0/3] perf tools: Add perf_event_max_sample_rate freq check Jiri Olsa
2013-11-04 11:06 ` [PATCH 1/3] perf tools: Factor sysfs code into generic fs object Jiri Olsa
2013-11-05 12:48 ` Arnaldo Carvalho de Melo
2013-11-05 13:07 ` Jiri Olsa
2013-11-05 14:55 ` Arnaldo Carvalho de Melo
2013-11-04 11:06 ` [PATCH 2/3] perf tools: Add procfs support into " Jiri Olsa
2013-11-04 11:06 ` Jiri Olsa [this message]
2013-11-04 15:17 ` [PATCH 3/3] perf tools: Check maximum frequency rate for record/top David Ahern
2013-11-04 15:32 ` Jiri Olsa
2013-11-04 17:56 ` Arnaldo Carvalho de Melo
2013-11-04 19:01 ` [PATCH 0/3] perf tools: Add perf_event_max_sample_rate freq check Jiri Olsa
2013-11-05 14:14 [PATCHv2 " Jiri Olsa
2013-11-05 14:14 ` [PATCH 3/3] perf tools: Check maximum frequency rate for record/top Jiri Olsa
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1383563173-17466-4-git-send-email-jolsa@redhat.com \
--to=jolsa@redhat.com \
--cc=a.p.zijlstra@chello.nl \
--cc=acme@redhat.com \
--cc=adrian.hunter@intel.com \
--cc=cjashfor@linux.vnet.ibm.com \
--cc=dsahern@gmail.com \
--cc=fweisbec@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=namhyung@kernel.org \
--cc=paulus@samba.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome