From patchwork Fri Jul 15 10:08:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 72088 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp530783qga; Fri, 15 Jul 2016 03:09:07 -0700 (PDT) X-Received: by 10.66.254.196 with SMTP id ak4mr30458308pad.62.1468577345559; Fri, 15 Jul 2016 03:09:05 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q6si8469721pag.32.2016.07.15.03.09.05; Fri, 15 Jul 2016 03:09:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752931AbcGOKIo (ORCPT + 29 others); Fri, 15 Jul 2016 06:08:44 -0400 Received: from foss.arm.com ([217.140.101.70]:48133 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932561AbcGOKIi (ORCPT ); Fri, 15 Jul 2016 06:08:38 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 18B0C3A1; Fri, 15 Jul 2016 03:09:39 -0700 (PDT) Received: from leverpostej.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 123B93F215; Fri, 15 Jul 2016 03:08:30 -0700 (PDT) From: Mark Rutland To: linux-kernel@vger.kernel.org Cc: acme@kernel.org, adrian.hunter@intel.com, alexander.shishkin@linux.intel.com, hekuang@huawei.com, jolsa@kernel.org, kan.liang@intel.com, mark.rutland@arm.com, mingo@redhat.com, peterz@infradead.org, wangnan0@huawei.com Subject: [RFCv2 2/4] perf: util: Add more cpu_map helpers Date: Fri, 15 Jul 2016 11:08:11 +0100 Message-Id: <1468577293-19667-3-git-send-email-mark.rutland@arm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1468577293-19667-1-git-send-email-mark.rutland@arm.com> References: <1468577293-19667-1-git-send-email-mark.rutland@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Cc: Alexander Shishkin Cc: Arnaldo Carvalho de Melo Cc: Ingo Molnar Cc: Jiri Olsa Cc: Kan Liang Cc: Peter Zijlstra Cc: linux-kernel@vger.kernel.org --- tools/perf/util/cpumap.c | 14 ++++++++++++-- tools/perf/util/cpumap.h | 2 ++ 2 files changed, 14 insertions(+), 2 deletions(-) -- 1.9.1 diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c index 02d8016..efc88fe 100644 --- a/tools/perf/util/cpumap.c +++ b/tools/perf/util/cpumap.c @@ -590,12 +590,22 @@ 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]; } diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h index 1a0a350..46f7642 100644 --- a/tools/perf/util/cpumap.h +++ b/tools/perf/util/cpumap.h @@ -67,5 +67,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 */