Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp5879842ybi; Sun, 21 Jul 2019 04:33:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqwwmQIw1AaYDstH94cJGRd1nqur59VFefNn15jprL5ttVELEKgdgUJn8U9VQKCw+CoXLy10 X-Received: by 2002:a63:5c07:: with SMTP id q7mr14085110pgb.436.1563708809886; Sun, 21 Jul 2019 04:33:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563708809; cv=none; d=google.com; s=arc-20160816; b=XBgdBaJaEUCucIeu3Nl5ukzBrUk8RODQlvqQ9N5JaYpLa7HMjUaRRmpoUk/aVMcQmp 0+1GYYsGuhc6Jfg89l70+5EgOfi3CAXyS4GvC7CLIno4CB7VANZ2asKucwGRGeMx3QgY qSf2QVsrBdjA9iyAOFKBQozgSvsJoLW1y3uIBv/OC/RMotYumkEkzMc3Q1HxChZEVk4V u6+Ve+gqs0wHTJiKEVT96qzZO2Z6ytBBf+1c/c9UqJk0f9FNIe7iWofzrsHHHCAdnHOp KqBemg5JAUx0AVQ9+BUw94M56CCUnoKoEs0LHYhahByVvCZEwm0mZ1fCX07R1pmTzO3p 48xA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=gODBBj8nvy1Kit5pREMaIOSpJom4Y04y4qGHNSZKThI=; b=nVazXmP/kmJI98mo6EJTNjK5vfYiBpwt5mcDduTeyT0MBuQQCOJsb84YsDFus+VyJa +CjiAGmnuew0YA7SKoMijgMhwnnatxpGIzOJFPsUFKilFjciq9PkV2+oN/Or3SYC3r+Q 5yqW9mlXGTMzGItCtwXG61lDext5hoCINqInjnZD3qUzKe2fVXgWe8HjTRZkXPUjHJSy JOkTjZR6ELmo2WebHMtki6cXUhHbpIxd62b8tvPMbcK3E9exKjO+XGix3IKrTj/pe/+/ kJgmE/vEfvXTww1Y+CWo4A/3YV+vzqjKSakXbBUM4Lh5pYBdWdjwPVZ+P5FQEDWue+Kj gfew== ARC-Authentication-Results: i=1; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w10si8321964pfq.115.2019.07.21.04.33.14; Sun, 21 Jul 2019 04:33:29 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727458AbfGULcN (ORCPT + 99 others); Sun, 21 Jul 2019 07:32:13 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43788 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726390AbfGULcM (ORCPT ); Sun, 21 Jul 2019 07:32:12 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F0779308425C; Sun, 21 Jul 2019 11:32:11 +0000 (UTC) Received: from krava.redhat.com (ovpn-204-23.brq.redhat.com [10.40.204.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id C7E745D9D3; Sun, 21 Jul 2019 11:32:07 +0000 (UTC) From: Jiri Olsa To: Arnaldo Carvalho de Melo Cc: lkml , Ingo Molnar , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Andi Kleen , Alexey Budankov , Michael Petlan Subject: [PATCH 66/79] libperf: Add perf_cpu_map__for_each_cpu macro Date: Sun, 21 Jul 2019 13:24:53 +0200 Message-Id: <20190721112506.12306-67-jolsa@kernel.org> In-Reply-To: <20190721112506.12306-1-jolsa@kernel.org> References: <20190721112506.12306-1-jolsa@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Sun, 21 Jul 2019 11:32:12 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Adding following macro to libperf: perf_cpu_map__for_each_cpu And its related functions: perf_cpu_map__cpu perf_cpu_map__nr Link: http://lkml.kernel.org/n/tip-gi0e8h1qqrvh0enk43gp7d5g@git.kernel.org Signed-off-by: Jiri Olsa --- tools/perf/lib/cpumap.c | 13 +++++++++++++ tools/perf/lib/include/perf/cpumap.h | 7 +++++++ tools/perf/lib/libperf.map | 2 ++ 3 files changed, 22 insertions(+) diff --git a/tools/perf/lib/cpumap.c b/tools/perf/lib/cpumap.c index a5d4f7ff7174..1ddb69e796e5 100644 --- a/tools/perf/lib/cpumap.c +++ b/tools/perf/lib/cpumap.c @@ -224,3 +224,16 @@ struct perf_cpu_map *perf_cpu_map__new(const char *cpu_list) out: return cpus; } + +int perf_cpu_map__cpu(const struct perf_cpu_map *cpus, int idx) +{ + if (idx < cpus->nr) + return cpus->map[idx]; + + return -1; +} + +int perf_cpu_map__nr(const struct perf_cpu_map *cpus) +{ + return cpus ? cpus->nr : 1; +} diff --git a/tools/perf/lib/include/perf/cpumap.h b/tools/perf/lib/include/perf/cpumap.h index b4a9283a5dfa..1b6e7db3fa2b 100644 --- a/tools/perf/lib/include/perf/cpumap.h +++ b/tools/perf/lib/include/perf/cpumap.h @@ -12,5 +12,12 @@ LIBPERF_API struct perf_cpu_map *perf_cpu_map__new(const char *cpu_list); LIBPERF_API struct perf_cpu_map *perf_cpu_map__read(FILE *file); LIBPERF_API struct perf_cpu_map *perf_cpu_map__get(struct perf_cpu_map *map); LIBPERF_API void perf_cpu_map__put(struct perf_cpu_map *map); +LIBPERF_API int perf_cpu_map__cpu(const struct perf_cpu_map *cpus, int idx); +LIBPERF_API int perf_cpu_map__nr(const struct perf_cpu_map *cpus); + +#define perf_cpu_map__for_each_cpu(cpu, idx, cpus) \ + for ((idx) = 0, (cpu) = perf_cpu_map__cpu(cpus, idx); \ + (idx) < perf_cpu_map__nr(cpus); \ + (idx)++, (cpu) = perf_cpu_map__cpu(cpus, idx)) #endif /* __LIBPERF_CPUMAP_H */ diff --git a/tools/perf/lib/libperf.map b/tools/perf/lib/libperf.map index 5bd491ac1762..d4d34bea0b40 100644 --- a/tools/perf/lib/libperf.map +++ b/tools/perf/lib/libperf.map @@ -6,6 +6,8 @@ LIBPERF_0.0.1 { perf_cpu_map__put; perf_cpu_map__new; perf_cpu_map__read; + perf_cpu_map__nr; + perf_cpu_map__cpu; perf_thread_map__new_dummy; perf_thread_map__set_pid; perf_thread_map__comm; -- 2.21.0