linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: tip-bot for Jiri Olsa <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: acme@redhat.com, linux-kernel@vger.kernel.org, paulus@samba.org,
	hpa@zytor.com, mingo@kernel.org, a.p.zijlstra@chello.nl,
	namhyung@kernel.org, jolsa@redhat.com, fweisbec@gmail.com,
	ak@linux.intel.com, dsahern@gmail.com, tglx@linutronix.de,
	cjashfor@linux.vnet.ibm.com, mingo@elte.hu
Subject: [tip:perf/core] perf tools: Check mmap pages value early
Date: Mon, 14 Oct 2013 22:24:55 -0700	[thread overview]
Message-ID: <tip-994a1f78b191df0c9d6caca3f3afb03e247aff26@git.kernel.org> (raw)
In-Reply-To: <1378031796-17892-2-git-send-email-jolsa@redhat.com>

Commit-ID:  994a1f78b191df0c9d6caca3f3afb03e247aff26
Gitweb:     http://git.kernel.org/tip/994a1f78b191df0c9d6caca3f3afb03e247aff26
Author:     Jiri Olsa <jolsa@redhat.com>
AuthorDate: Sun, 1 Sep 2013 12:36:12 +0200
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 9 Oct 2013 11:24:10 -0300

perf tools: Check mmap pages value early

Move the check of the mmap_pages value to the options parsing time, so
we could rely on this value on other parts of code.

Related changes come in the next patches.

Also changes perf_evlist::mmap_len to proper size_t type.

Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Cc: Andi Kleen <ak@linux.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>
Link: http://lkml.kernel.org/r/1378031796-17892-2-git-send-email-jolsa@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-kvm.c    |  5 +++--
 tools/perf/builtin-record.c |  9 +++------
 tools/perf/builtin-top.c    |  5 +++--
 tools/perf/builtin-trace.c  |  5 +++--
 tools/perf/util/evlist.c    | 46 ++++++++++++++++++++++++++++++++++++---------
 tools/perf/util/evlist.h    |  6 +++++-
 6 files changed, 54 insertions(+), 22 deletions(-)

diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index 935d522..cfa0b79 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -1426,8 +1426,9 @@ static int kvm_events_live(struct perf_kvm_stat *kvm,
 	const struct option live_options[] = {
 		OPT_STRING('p', "pid", &kvm->opts.target.pid, "pid",
 			"record events on existing process id"),
-		OPT_UINTEGER('m', "mmap-pages", &kvm->opts.mmap_pages,
-			"number of mmap data pages"),
+		OPT_CALLBACK('m', "mmap-pages", &kvm->opts.mmap_pages, "pages",
+			"number of mmap data pages",
+			perf_evlist__parse_mmap_pages),
 		OPT_INCR('v', "verbose", &verbose,
 			"be more verbose (show counter open errors, etc)"),
 		OPT_BOOLEAN('a', "all-cpus", &kvm->opts.target.system_wide,
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 0aacd62..92ca541 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -233,10 +233,6 @@ try_again:
 			       "or try again with a smaller value of -m/--mmap_pages.\n"
 			       "(current value: %d)\n", opts->mmap_pages);
 			rc = -errno;
-		} else if (!is_power_of_2(opts->mmap_pages) &&
-			   (opts->mmap_pages != UINT_MAX)) {
-			pr_err("--mmap_pages/-m value must be a power of two.");
-			rc = -EINVAL;
 		} else {
 			pr_err("failed to mmap with %d (%s)\n", errno, strerror(errno));
 			rc = -errno;
@@ -854,8 +850,9 @@ const struct option record_options[] = {
 	OPT_BOOLEAN('i', "no-inherit", &record.opts.no_inherit,
 		    "child tasks do not inherit counters"),
 	OPT_UINTEGER('F', "freq", &record.opts.user_freq, "profile at this frequency"),
-	OPT_UINTEGER('m', "mmap-pages", &record.opts.mmap_pages,
-		     "number of mmap data pages"),
+	OPT_CALLBACK('m', "mmap-pages", &record.opts.mmap_pages, "pages",
+		     "number of mmap data pages",
+		     perf_evlist__parse_mmap_pages),
 	OPT_BOOLEAN(0, "group", &record.opts.group,
 		    "put the counters into a counter group"),
 	OPT_CALLBACK_DEFAULT('g', "call-graph", &record.opts,
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index b3e0229..e846695 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -1075,8 +1075,9 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused)
 		   "file", "vmlinux pathname"),
 	OPT_BOOLEAN('K', "hide_kernel_symbols", &top.hide_kernel_symbols,
 		    "hide kernel symbols"),
-	OPT_UINTEGER('m', "mmap-pages", &opts->mmap_pages,
-		     "number of mmap data pages"),
+	OPT_CALLBACK('m', "mmap-pages", &opts->mmap_pages, "pages",
+		     "number of mmap data pages",
+		     perf_evlist__parse_mmap_pages),
 	OPT_INTEGER('r', "realtime", &top.realtime_prio,
 		    "collect data with this RT SCHED_FIFO priority"),
 	OPT_INTEGER('d', "delay", &top.delay_secs,
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index be65843..f3ddbb0 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -1528,8 +1528,9 @@ int cmd_trace(int argc, const char **argv, const char *prefix __maybe_unused)
 		    "list of cpus to monitor"),
 	OPT_BOOLEAN(0, "no-inherit", &trace.opts.no_inherit,
 		    "child tasks do not inherit counters"),
-	OPT_UINTEGER('m', "mmap-pages", &trace.opts.mmap_pages,
-		     "number of mmap data pages"),
+	OPT_CALLBACK('m', "mmap-pages", &trace.opts.mmap_pages, "pages",
+		     "number of mmap data pages",
+		     perf_evlist__parse_mmap_pages),
 	OPT_STRING('u', "uid", &trace.opts.target.uid_str, "user",
 		   "user to profile"),
 	OPT_CALLBACK(0, "duration", &trace, "float",
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index f9f77be..4283f49 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -18,6 +18,7 @@
 #include <unistd.h>
 
 #include "parse-events.h"
+#include "parse-options.h"
 
 #include <sys/mman.h>
 
@@ -672,6 +673,40 @@ out_unmap:
 	return -1;
 }
 
+static size_t perf_evlist__mmap_size(unsigned long pages)
+{
+	/* 512 kiB: default amount of unprivileged mlocked memory */
+	if (pages == UINT_MAX)
+		pages = (512 * 1024) / page_size;
+	else if (!is_power_of_2(pages))
+		return 0;
+
+	return (pages + 1) * page_size;
+}
+
+int perf_evlist__parse_mmap_pages(const struct option *opt, const char *str,
+				  int unset __maybe_unused)
+{
+	unsigned int pages, *mmap_pages = opt->value;
+	size_t size;
+	char *eptr;
+
+	pages = strtoul(str, &eptr, 10);
+	if (*eptr != '\0') {
+		pr_err("failed to parse --mmap_pages/-m value\n");
+		return -1;
+	}
+
+	size = perf_evlist__mmap_size(pages);
+	if (!size) {
+		pr_err("--mmap_pages/-m value must be a power of two.");
+		return -1;
+	}
+
+	*mmap_pages = pages;
+	return 0;
+}
+
 /** perf_evlist__mmap - Create per cpu maps to receive events
  *
  * @evlist - list of events
@@ -695,14 +730,6 @@ int perf_evlist__mmap(struct perf_evlist *evlist, unsigned int pages,
 	const struct thread_map *threads = evlist->threads;
 	int prot = PROT_READ | (overwrite ? 0 : PROT_WRITE), mask;
 
-        /* 512 kiB: default amount of unprivileged mlocked memory */
-        if (pages == UINT_MAX)
-                pages = (512 * 1024) / page_size;
-	else if (!is_power_of_2(pages))
-		return -EINVAL;
-
-	mask = pages * page_size - 1;
-
 	if (evlist->mmap == NULL && perf_evlist__alloc_mmap(evlist) < 0)
 		return -ENOMEM;
 
@@ -710,7 +737,8 @@ int perf_evlist__mmap(struct perf_evlist *evlist, unsigned int pages,
 		return -ENOMEM;
 
 	evlist->overwrite = overwrite;
-	evlist->mmap_len = (pages + 1) * page_size;
+	evlist->mmap_len = perf_evlist__mmap_size(pages);
+	mask = evlist->mmap_len - page_size - 1;
 
 	list_for_each_entry(evsel, &evlist->entries, node) {
 		if ((evsel->attr.read_format & PERF_FORMAT_ID) &&
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h
index 880d713..4edb500 100644
--- a/tools/perf/util/evlist.h
+++ b/tools/perf/util/evlist.h
@@ -31,7 +31,7 @@ struct perf_evlist {
 	int		 nr_groups;
 	int		 nr_fds;
 	int		 nr_mmaps;
-	int		 mmap_len;
+	size_t		 mmap_len;
 	int		 id_pos;
 	int		 is_pos;
 	u64		 combined_sample_type;
@@ -103,6 +103,10 @@ int perf_evlist__prepare_workload(struct perf_evlist *evlist,
 				  bool want_signal);
 int perf_evlist__start_workload(struct perf_evlist *evlist);
 
+int perf_evlist__parse_mmap_pages(const struct option *opt,
+				  const char *str,
+				  int unset);
+
 int perf_evlist__mmap(struct perf_evlist *evlist, unsigned int pages,
 		      bool overwrite);
 void perf_evlist__munmap(struct perf_evlist *evlist);

  reply	other threads:[~2013-10-15  5:25 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-01 10:36 [PATCHv2 00/25] perf tool: Add support for multiple data file storage Jiri Olsa
2013-09-01 10:36 ` [PATCH 01/25] perf tools: Check mmap pages value early Jiri Olsa
2013-10-15  5:24   ` tip-bot for Jiri Olsa [this message]
2013-09-01 10:36 ` [PATCH 02/25] perf tools: Add possibility to specify mmap size Jiri Olsa
2013-10-15  5:25   ` [tip:perf/core] " tip-bot for Jiri Olsa
2013-09-01 10:36 ` [PATCH 03/25] perf tools: Introduce perf_evlist__new_default function Jiri Olsa
2013-10-15  5:25   ` [tip:perf/core] perf evlist: " tip-bot for Jiri Olsa
2013-09-01 10:36 ` [PATCH 04/25] perf tools: Adding throttle event data struct support Jiri Olsa
2013-10-15  5:25   ` [tip:perf/core] " tip-bot for Jiri Olsa
2013-09-01 10:36 ` [PATCH 05/25] perf tests: Add simple session read/write test Jiri Olsa
2013-09-01 10:36 ` [PATCH 06/25] perf tests: Add session reading test for little endian perf data Jiri Olsa
2013-09-01 10:36 ` [PATCH 07/25] perf tests: Add session reading test for big " Jiri Olsa
2013-09-01 10:36 ` [PATCH 08/25] perf doc: Add perf data file documentation Jiri Olsa
2013-09-01 10:36 ` [PATCH 09/25] perf tools: Introduce perf data file version CHECK macro Jiri Olsa
2013-09-01 10:36 ` [PATCH 10/25] perf tools: Introduce swap_features function Jiri Olsa
2013-09-01 10:36 ` [PATCH 11/25] perf tools: Introduce swap_header function Jiri Olsa
2013-09-01 10:36 ` [PATCH 12/25] perf tools: Separate version 2 specific perf data header bits Jiri Olsa
2013-09-01 10:36 ` [PATCH 13/25] perf tools: Using evlist as a holder for event_desc feature Jiri Olsa
2013-09-01 10:36 ` [PATCH 14/25] perf tools: Introduce perf.data version 3 format Jiri Olsa
2013-09-01 10:36 ` [PATCH 15/25] perf tools: Add perf data version 3 header swap Jiri Olsa
2013-09-01 10:36 ` [PATCH 16/25] perf tools: Add perf data version 3 header read Jiri Olsa
2013-09-01 10:36 ` [PATCH 17/25] perf tools: Add perf.data version 3 header write Jiri Olsa
2013-09-01 10:36 ` [PATCH 18/25] perf tools: Get rid of post_processing_offset in record command Jiri Olsa
2013-09-01 10:36 ` [PATCH 19/25] perf tools: Move synthesizing into single function Jiri Olsa
2013-09-01 10:36 ` [PATCH 20/25] perf tools: Add perf_data_file__open interface to data object Jiri Olsa
2013-09-01 10:36 ` [PATCH 21/25] perf tools: Separating data file properties from session Jiri Olsa
2013-09-01 10:36 ` [PATCH 22/25] perf tests: Add session reading test for little endian perf data v3 Jiri Olsa
2013-09-01 10:36 ` [PATCH 23/25] perf tests: Add session reading test for big " Jiri Olsa
2013-09-01 10:36 ` [PATCH 24/25] perf tools: Add multi file '-M' option for record command Jiri Olsa
2013-09-02  7:52   ` Adrian Hunter
2013-09-02  8:37     ` Jiri Olsa
2013-09-02  9:11       ` Adrian Hunter
2013-09-02  9:40         ` Jiri Olsa
2013-09-01 10:36 ` [PATCH 25/25] perf tools: Have the process properly sythesized in subsequent data files Jiri Olsa
2013-09-02  2:42 ` [PATCHv2 00/25] perf tool: Add support for multiple data file storage Andi Kleen
2013-09-09 11:17 ` Peter Zijlstra
2013-09-09 11:36   ` Jiri Olsa
2013-09-09 11:55     ` Peter Zijlstra
2013-09-09 14:03       ` Jiri Olsa
2013-09-09 14:11         ` David Ahern
2013-09-09 14:31           ` Jiri Olsa
2013-09-09 15:03             ` David Ahern
2013-09-14 18:32               ` David Ahern
2013-09-09 16:06           ` Ingo Molnar
2013-09-10 17:29             ` David Ahern
2013-09-10  6:54   ` Adrian Hunter
2013-09-10  9:15     ` Peter Zijlstra
2013-09-10  8:57   ` Namhyung Kim

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=tip-994a1f78b191df0c9d6caca3f3afb03e247aff26@git.kernel.org \
    --to=tipbot@zytor.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@redhat.com \
    --cc=ak@linux.intel.com \
    --cc=cjashfor@linux.vnet.ibm.com \
    --cc=dsahern@gmail.com \
    --cc=fweisbec@gmail.com \
    --cc=hpa@zytor.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=paulus@samba.org \
    --cc=tglx@linutronix.de \
    /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;
as well as URLs for NNTP newsgroup(s).