From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: linux-kernel@vger.kernel.org, Mark Rutland <mark.rutland@arm.com>,
Adrian Hunter <adrian.hunter@intel.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
He Kuang <hekuang@huawei.com>, Kan Liang <kan.liang@intel.com>,
Peter Zijlstra <peterz@infradead.org>,
Wang Nan <wangnan0@huawei.com>,
Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH 11/15] perf cpu_map: Add more helpers
Date: Mon, 18 Jul 2016 20:33:14 -0300 [thread overview]
Message-ID: <1468884798-14932-12-git-send-email-acme@kernel.org> (raw)
In-Reply-To: <1468884798-14932-1-git-send-email-acme@kernel.org>
From: Mark Rutland <mark.rutland@arm.com>
In some cases it's necessry to figure out the map-local index of a given
Linux logical CPU ID. Add a new helper, cpu_map__idx, to acquire this.
As the logic is largely the same as the existing cpu_map__has, this is
rewritten in terms of the new helper.
At the same time, add the inverse operation, cpu_map__cpu, which yields
the logical CPU id for a map-local index. While this can be performed
manually, wrapping this in a helper can make code more legible.
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: He Kuang <hekuang@huawei.com>
Cc: Kan Liang <kan.liang@intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/r/1468577293-19667-3-git-send-email-mark.rutland@arm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/util/cpumap.c | 14 ++++++++++++--
tools/perf/util/cpumap.h | 2 ++
2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c
index 15f83acac1b8..2c0b52264a46 100644
--- a/tools/perf/util/cpumap.c
+++ b/tools/perf/util/cpumap.c
@@ -589,14 +589,24 @@ int cpu__setup_cpunode_map(void)
bool cpu_map__has(struct cpu_map *cpus, int cpu)
{
+ return cpu_map__idx(cpus, cpu) != -1;
+}
+
+int cpu_map__idx(struct cpu_map *cpus, int cpu)
+{
int i;
for (i = 0; i < cpus->nr; ++i) {
if (cpus->map[i] == cpu)
- return true;
+ return i;
}
- return false;
+ return -1;
+}
+
+int cpu_map__cpu(struct cpu_map *cpus, int idx)
+{
+ return cpus->map[idx];
}
size_t cpu_map__snprint(struct cpu_map *map, char *buf, size_t size)
diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h
index 206dc550354a..06bd689f5989 100644
--- a/tools/perf/util/cpumap.h
+++ b/tools/perf/util/cpumap.h
@@ -68,5 +68,7 @@ int cpu_map__build_map(struct cpu_map *cpus, struct cpu_map **res,
int (*f)(struct cpu_map *map, int cpu, void *data),
void *data);
+int cpu_map__cpu(struct cpu_map *cpus, int idx);
bool cpu_map__has(struct cpu_map *cpus, int cpu);
+int cpu_map__idx(struct cpu_map *cpus, int cpu);
#endif /* __PERF_CPUMAP_H */
--
2.7.4
next prev parent reply other threads:[~2016-07-18 23:34 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-18 23:33 [GIT PULL 00/15] perf/core improvements and fixes Arnaldo Carvalho de Melo
2016-07-18 23:33 ` [PATCH 01/15] perf jit: Add missing curly braces Arnaldo Carvalho de Melo
2016-07-18 23:33 ` Arnaldo Carvalho de Melo
2016-07-18 23:33 ` [PATCH 02/15] perf jit: Remove some no-op error handling Arnaldo Carvalho de Melo
2016-07-18 23:33 ` Arnaldo Carvalho de Melo
2016-07-18 23:33 ` [PATCH 03/15] perf tools: Add missing linux/compiler.h include to perf-sys.h Arnaldo Carvalho de Melo
2016-07-18 23:33 ` [PATCH 04/15] perf tools: Remove tools/perf/util/include/asm/byteorder.h Arnaldo Carvalho de Melo
2016-07-18 23:33 ` [PATCH 05/15] perf tools: Remove tools/perf/util/include/linux/const.h Arnaldo Carvalho de Melo
2016-07-18 23:33 ` [PATCH 06/15] Remove: kernel unistd*h files from perf's MANIFEST, not used Arnaldo Carvalho de Melo
2016-07-18 23:33 ` [PATCH 07/15] tools: Copy the bitops files accessed from the kernel and check for drift Arnaldo Carvalho de Melo
2016-07-18 23:33 ` [PATCH 08/15] perf tools: Remove include/linux/list.h from perf's MANIFEST Arnaldo Carvalho de Melo
2016-07-18 23:33 ` [PATCH 09/15] tools: Copy linux/{hash,poison}.h and check for drift Arnaldo Carvalho de Melo
2016-07-18 23:33 ` [PATCH 10/15] perf stat: Balance opening and reading events Arnaldo Carvalho de Melo
2016-07-18 23:33 ` Arnaldo Carvalho de Melo [this message]
2016-07-18 23:33 ` [PATCH 12/15] perf probe: Warn unmatched function filter correctly Arnaldo Carvalho de Melo
2016-07-18 23:33 ` [PATCH 13/15] perf script python: Fix string vs byte array resolving Arnaldo Carvalho de Melo
2016-07-28 18:42 ` Steven Rostedt
2016-07-18 23:33 ` [PATCH 14/15] perf tools: Make is_printable_array global Arnaldo Carvalho de Melo
2016-07-18 23:33 ` [PATCH 15/15] perf tests: Add is_printable_array test Arnaldo Carvalho de Melo
2016-07-19 6:46 ` [GIT PULL 00/15] perf/core improvements and fixes Ingo Molnar
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=1468884798-14932-12-git-send-email-acme@kernel.org \
--to=acme@kernel.org \
--cc=acme@redhat.com \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=hekuang@huawei.com \
--cc=kan.liang@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=wangnan0@huawei.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.