Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp152418ybl; Tue, 3 Dec 2019 23:55:21 -0800 (PST) X-Google-Smtp-Source: APXvYqyonne1CqAqEMEharolG5pNXHIwyBU7Zyxp62t01i3pZCXGbKOX6hKV4t84VECDJ1IqdHVF X-Received: by 2002:aca:60c4:: with SMTP id u187mr1512249oib.36.1575446121524; Tue, 03 Dec 2019 23:55:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575446121; cv=none; d=google.com; s=arc-20160816; b=sIuEluTn782v6JS75A7lAD54txHxKSt127KcZw5p71znAJwTToCf5N5dZz4bWVZGgp Vl6McGBcnl14vocX5BusmAWNE9944ani8VjJQ40/r4kMjzIYpHglIZEFEJDuoPfjRcwZ BgFacDMAXsOe07Oj6gqvTk83YWe3LSSYREc/5erFy7ChZDLQFD40nq5K2iAdLyb9KCFl +dVb9SAeSpoR3jVqFPWma46stlCs6tiI2GeQkKNvC3Q5VCmwOHlcJUDLmb9xcCp7DRQJ cimZdblaVl9I1gdM1ShdARDgBaQs/IQfy07Jy0hWnGnMRQd1uHQJ2dWCDV5cDb+ZnT5Y NWzg== 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 :robot-unsubscribe:robot-id:message-id:mime-version:references :in-reply-to:cc:subject:to:reply-to:from:date; bh=cdcWeOr3GlAJOdTNH1zSgBXwV97xgi200WQFCzqWb7c=; b=Z9lZdxXzllVq/xS5U+N+nnNKRXk4cvNt+URYVRTZHelsPB/i1DyeC1/rtU7neNhKZ4 YxqGDoNVahIWXb7i5QNzeskWsWk7XLJPuiaIVngI6F/fbiLnDoefqlXQxETn4DYpsLaq KLQHH4MGTb+jSaJhI/WxBp00sadj6Dlzqr6OtyDijvyppWIwlM22NQLG3+Ea4fffOtBU IkaiVhDtsXBiSo/fjJHMYEucerbMVsjH9EQfd6ExqEAZFvnnJEk1zKSfnapwouBD8T1E tVx3F9Jg7sFXQEg5rTU/Uj4k+W7OItIUT4jUIYjuRudEgL7ZsjuljOGnM1XnD79Pl/Rd DHow== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t134si1620460oie.148.2019.12.03.23.55.08; Tue, 03 Dec 2019 23:55:21 -0800 (PST) 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 S1727472AbfLDHyR (ORCPT + 99 others); Wed, 4 Dec 2019 02:54:17 -0500 Received: from Galois.linutronix.de ([193.142.43.55]:56144 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726166AbfLDHyG (ORCPT ); Wed, 4 Dec 2019 02:54:06 -0500 Received: from [5.158.153.53] (helo=tip-bot2.lab.linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1icPU1-0004Xq-LX; Wed, 04 Dec 2019 08:54:01 +0100 Received: from [127.0.1.1] (localhost [IPv6:::1]) by tip-bot2.lab.linutronix.de (Postfix) with ESMTP id 5AB9C1C2650; Wed, 4 Dec 2019 08:53:55 +0100 (CET) Date: Wed, 04 Dec 2019 07:53:55 -0000 From: "tip-bot2 for Andi Kleen" Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: perf/urgent] perf evsel: Add iterator to iterate over events ordered by CPU Cc: Andi Kleen , Jiri Olsa , Arnaldo Carvalho de Melo , x86 , LKML In-Reply-To: <20191121001522.180827-6-andi@firstfloor.org> References: <20191121001522.180827-6-andi@firstfloor.org> MIME-Version: 1.0 Message-ID: <157544603527.21853.4588479986568202605.tip-bot2@tip-bot2> X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the perf/urgent branch of tip: Commit-ID: a8cbe40fe9f4ba499cc60b8b6a6851c2c1963797 Gitweb: https://git.kernel.org/tip/a8cbe40fe9f4ba499cc60b8b6a6851c2c1963797 Author: Andi Kleen AuthorDate: Wed, 20 Nov 2019 16:15:15 -08:00 Committer: Arnaldo Carvalho de Melo CommitterDate: Fri, 29 Nov 2019 12:20:45 -03:00 perf evsel: Add iterator to iterate over events ordered by CPU Add some common code that is needed to iterate over all events in CPU order. Used in followon patches Signed-off-by: Andi Kleen Acked-by: Jiri Olsa Link: http://lore.kernel.org/lkml/20191121001522.180827-6-andi@firstfloor.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/cpumap.h | 1 + tools/perf/util/evlist.c | 32 ++++++++++++++++++++++++++++++++ tools/perf/util/evlist.h | 8 ++++++++ tools/perf/util/evsel.h | 1 + 4 files changed, 42 insertions(+) diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h index 57943f3..3a442f0 100644 --- a/tools/perf/util/cpumap.h +++ b/tools/perf/util/cpumap.h @@ -63,4 +63,5 @@ int cpu_map__build_map(struct perf_cpu_map *cpus, struct perf_cpu_map **res, int cpu_map__cpu(struct perf_cpu_map *cpus, int idx); bool cpu_map__has(struct perf_cpu_map *cpus, int cpu); + #endif /* __PERF_CPUMAP_H */ diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index fdce590..dae6e84 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -342,6 +342,38 @@ static int perf_evlist__nr_threads(struct evlist *evlist, return perf_thread_map__nr(evlist->core.threads); } +void evlist__cpu_iter_start(struct evlist *evlist) +{ + struct evsel *pos; + + /* + * Reset the per evsel cpu_iter. This is needed because + * each evsel's cpumap may have a different index space, + * and some operations need the index to modify + * the FD xyarray (e.g. open, close) + */ + evlist__for_each_entry(evlist, pos) + pos->cpu_iter = 0; +} + +bool evsel__cpu_iter_skip_no_inc(struct evsel *ev, int cpu) +{ + if (ev->cpu_iter >= ev->core.cpus->nr) + return true; + if (cpu >= 0 && ev->core.cpus->map[ev->cpu_iter] != cpu) + return true; + return false; +} + +bool evsel__cpu_iter_skip(struct evsel *ev, int cpu) +{ + if (!evsel__cpu_iter_skip_no_inc(ev, cpu)) { + ev->cpu_iter++; + return false; + } + return true; +} + void evlist__disable(struct evlist *evlist) { struct evsel *pos; diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h index 3655b9e..22e2f58 100644 --- a/tools/perf/util/evlist.h +++ b/tools/perf/util/evlist.h @@ -334,9 +334,17 @@ void perf_evlist__to_front(struct evlist *evlist, #define evlist__for_each_entry_safe(evlist, tmp, evsel) \ __evlist__for_each_entry_safe(&(evlist)->core.entries, tmp, evsel) +#define evlist__for_each_cpu(evlist, index, cpu) \ + evlist__cpu_iter_start(evlist); \ + perf_cpu_map__for_each_cpu (cpu, index, (evlist)->core.all_cpus) + void perf_evlist__set_tracking_event(struct evlist *evlist, struct evsel *tracking_evsel); +void evlist__cpu_iter_start(struct evlist *evlist); +bool evsel__cpu_iter_skip(struct evsel *ev, int cpu); +bool evsel__cpu_iter_skip_no_inc(struct evsel *ev, int cpu); + struct evsel * perf_evlist__find_evsel_by_str(struct evlist *evlist, const char *str); diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index ddc5ee6..b10d5ba 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -95,6 +95,7 @@ struct evsel { bool collect_stat; bool weak_group; bool percore; + int cpu_iter; const char *pmu_name; struct { perf_evsel__sb_cb_t *cb;