linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jiri Olsa <jolsa@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: Jiri Olsa <jolsa@redhat.com>,
	Corey Ashford <cjashfor@linux.vnet.ibm.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>,
	Andi Kleen <ak@linux.intel.com>, David Ahern <dsahern@gmail.com>
Subject: [PATCH 02/25] perf tools: Add possibility to specify mmap size
Date: Sun,  1 Sep 2013 12:36:13 +0200	[thread overview]
Message-ID: <1378031796-17892-3-git-send-email-jolsa@redhat.com> (raw)
In-Reply-To: <1378031796-17892-1-git-send-email-jolsa@redhat.com>

Adding possibility to specify mmap size via -m/--mmap-pages
by appending unit size character (B/K/M/G) to the
number, like:
  $ perf record -m 8K ls
  $ perf record -m 2M ls

The size is rounded up appropriately to follow perf
mmap restrictions.

If no unit is specified the number provides pages as
of now, like:
  $ perf record -m 8 ls

Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.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>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
---
 tools/perf/Documentation/perf-kvm.txt    |  4 +++-
 tools/perf/Documentation/perf-record.txt |  4 +++-
 tools/perf/Documentation/perf-top.txt    |  4 +++-
 tools/perf/Documentation/perf-trace.txt  |  4 +++-
 tools/perf/util/evlist.c                 | 32 ++++++++++++++++++++++++++------
 tools/perf/util/util.c                   | 25 +++++++++++++++++++++++++
 tools/perf/util/util.h                   | 14 ++++++++++++++
 7 files changed, 77 insertions(+), 10 deletions(-)

diff --git a/tools/perf/Documentation/perf-kvm.txt b/tools/perf/Documentation/perf-kvm.txt
index ac84db2..6a06cef 100644
--- a/tools/perf/Documentation/perf-kvm.txt
+++ b/tools/perf/Documentation/perf-kvm.txt
@@ -109,7 +109,9 @@ STAT LIVE OPTIONS
 
 -m::
 --mmap-pages=::
-    Number of mmap data pages. Must be a power of two.
+    Number of mmap data pages (must be a power of two) or size
+    specification with appended unit character - B/K/M/G. The
+    size is rounded up to have nearest pages power of two value.
 
 -a::
 --all-cpus::
diff --git a/tools/perf/Documentation/perf-record.txt b/tools/perf/Documentation/perf-record.txt
index e297b74..400e9bb 100644
--- a/tools/perf/Documentation/perf-record.txt
+++ b/tools/perf/Documentation/perf-record.txt
@@ -87,7 +87,9 @@ OPTIONS
 
 -m::
 --mmap-pages=::
-	Number of mmap data pages. Must be a power of two.
+	Number of mmap data pages (must be a power of two) or size
+	specification with appended unit character - B/K/M/G. The
+	size is rounded up to have nearest pages power of two value.
 
 -g::
 --call-graph::
diff --git a/tools/perf/Documentation/perf-top.txt b/tools/perf/Documentation/perf-top.txt
index 58d6598..19ab69e 100644
--- a/tools/perf/Documentation/perf-top.txt
+++ b/tools/perf/Documentation/perf-top.txt
@@ -68,7 +68,9 @@ Default is to monitor all CPUS.
 
 -m <pages>::
 --mmap-pages=<pages>::
-	Number of mmapped data pages.
+	Number of mmap data pages (must be a power of two) or size
+	specification with appended unit character - B/K/M/G. The
+	size is rounded up to have nearest pages power of two value.
 
 -p <pid>::
 --pid=<pid>::
diff --git a/tools/perf/Documentation/perf-trace.txt b/tools/perf/Documentation/perf-trace.txt
index daccd2c..d390efa 100644
--- a/tools/perf/Documentation/perf-trace.txt
+++ b/tools/perf/Documentation/perf-trace.txt
@@ -59,7 +59,9 @@ OPTIONS
 
 -m::
 --mmap-pages=::
-	Number of mmap data pages. Must be a power of two.
+	Number of mmap data pages (must be a power of two) or size
+	specification with appended unit character - B/K/M/G. The
+	size is rounded up to have nearest pages power of two value.
 
 -C::
 --cpu::
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 4780b9e..8ea933f 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -634,14 +634,33 @@ static size_t perf_evlist__mmap_size(unsigned long pages)
 int perf_evlist__parse_mmap_pages(const struct option *opt, const char *str,
 				  int unset __maybe_unused)
 {
-	unsigned int pages, *mmap_pages = opt->value;
+	unsigned int pages, val, *mmap_pages = opt->value;
 	size_t size;
-	char *eptr;
+	static struct parse_tag tags[] = {
+		{ .tag  = 'B', .mult = 1       },
+		{ .tag  = 'K', .mult = 1 << 10 },
+		{ .tag  = 'M', .mult = 1 << 20 },
+		{ .tag  = 'G', .mult = 1 << 30 },
+		{ .tag  = 0 },
+	};
 
-	pages = strtoul(str, &eptr, 10);
-	if (*eptr != '\0') {
-		pr_err("failed to parse --mmap_pages/-m value\n");
-		return -1;
+	val = parse_tag_value(str, tags);
+	if (val != (unsigned int) -1) {
+		/* we got file size value */
+		pages = PERF_ALIGN(val, page_size) / page_size;
+		if (!is_power_of_2(pages)) {
+			pages = next_pow2(pages);
+			pr_info("rounding mmap pages size to %u (%u pages)\n",
+				pages * page_size, pages);
+		}
+	} else {
+		/* we got pages count value */
+		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);
@@ -685,6 +704,7 @@ int perf_evlist__mmap(struct perf_evlist *evlist, unsigned int pages,
 
 	evlist->overwrite = overwrite;
 	evlist->mmap_len = perf_evlist__mmap_size(pages);
+	pr_debug("mmap size %luB\n", evlist->mmap_len);
 	mask = evlist->mmap_len - page_size - 1;
 
 	list_for_each_entry(evsel, &evlist->entries, node) {
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c
index 6d17b18..141317e 100644
--- a/tools/perf/util/util.c
+++ b/tools/perf/util/util.c
@@ -361,3 +361,28 @@ int parse_nsec_time(const char *str, u64 *ptime)
 	*ptime = time_sec * NSEC_PER_SEC + time_nsec;
 	return 0;
 }
+
+unsigned long parse_tag_value(const char *str, struct parse_tag *tags)
+{
+	struct parse_tag *i = tags;
+
+	while (i->tag) {
+		char *s;
+
+		s = strchr(str, i->tag);
+		if (s) {
+			unsigned long int value;
+			char *endptr;
+
+			value = strtoul(str, &endptr, 10);
+			if (s != endptr)
+				break;
+
+			value *= i->mult;
+			return value;
+		}
+		i++;
+	}
+
+	return (unsigned long) -1;
+}
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index a535359..c29ecaa 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -270,6 +270,13 @@ bool is_power_of_2(unsigned long n)
 	return (n != 0 && ((n & (n - 1)) == 0));
 }
 
+static inline unsigned next_pow2(unsigned x)
+{
+	if (!x)
+		return 1;
+	return 1ULL << (32 - __builtin_clz(x - 1));
+}
+
 size_t hex_width(u64 v);
 int hex2u64(const char *ptr, u64 *val);
 
@@ -281,4 +288,11 @@ void dump_stack(void);
 extern unsigned int page_size;
 
 void get_term_dimensions(struct winsize *ws);
+
+struct parse_tag {
+	char tag;
+	int mult;
+};
+
+unsigned long parse_tag_value(const char *str, struct parse_tag *tags);
 #endif /* GIT_COMPAT_UTIL_H */
-- 
1.7.11.7


  parent reply	other threads:[~2013-09-01 10:37 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:perf/core] " tip-bot for Jiri Olsa
2013-09-01 10:36 ` Jiri Olsa [this message]
2013-10-15  5:25   ` [tip:perf/core] perf tools: Add possibility to specify mmap size 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=1378031796-17892-3-git-send-email-jolsa@redhat.com \
    --to=jolsa@redhat.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=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;
as well as URLs for NNTP newsgroup(s).