Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp2540551ybc; Wed, 20 Nov 2019 16:17:39 -0800 (PST) X-Google-Smtp-Source: APXvYqzIyjNM9PUq4dovnCJdCbdlciO5+nzRqTTazo68eBSzjBl5k6I0G62PKlUxmqJgi5LqDtu3 X-Received: by 2002:a17:906:c44f:: with SMTP id ck15mr9116481ejb.7.1574295459807; Wed, 20 Nov 2019 16:17:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574295459; cv=none; d=google.com; s=arc-20160816; b=CI9s5G988q1C+8i6UotsajaVNPicyywQOUcO5AizA0cy5u0NX/Fn/rqr86OLB1K8yR O0T7jFTM/p2mfipMam6cpC/5Ca2Z9l8edoTU1aNWeN3JK7qsvJDEnSl4PARPcikARMwk edif/T503wo+nbIsIWDRpG19oEVW+1nQNDzCgPPBl465I4LgF6gbJZSiiKHD2ymaDDOA uhxkceJ7HwF/oKDmpI4pGyfwBgw+Q4xTVsvi/bhf5grysgwd9WtRijx6JNIlsZcGL46f /hBM45NWxjHpTBKSp8mMlNhOhz1tIi/qJQgdXimnWiot2U435+ksm4f6xC1bOXCxY3xi HvqQ== 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=ctoJ487Fbv0YIijVHLTnwnaLT+a+r3Uo7ksJoESFkYg=; b=Lv6INc4ATabUX5DFvIJyvFC2O66Qy2OVZrnXgH/lGZCTAnqnFbgM32Sy74sVJ/zrIs p29mxSS4+Ig+wjsK5DH7d8HLTx3J5WarL7yoS37HcWG28BEFmgAEexZPdieQYwLZ5IX2 +FqcsG/JZ0s7fFrxoL58AlELavgyuA7cU8KF8kQ+dq00G1G7bXVu/onD/dye/bPmALjp Q+c2a9T28iQva9LGvZinhmW04/wlzegr44kyaQeginOWmXRrZLuD+TQH56KvOc9YO+sJ EgnAEz/Vu+QXh1qBalZhuxWiI2DwmcfTTpxbm3A5CCMPI9FO9sXEx2TpZPvUUHHAHB2p 8BCQ== 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 k24si568422ejv.111.2019.11.20.16.17.15; Wed, 20 Nov 2019 16:17:39 -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 S1727059AbfKUAPg (ORCPT + 99 others); Wed, 20 Nov 2019 19:15:36 -0500 Received: from mga18.intel.com ([134.134.136.126]:21688 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726739AbfKUAPf (ORCPT ); Wed, 20 Nov 2019 19:15:35 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Nov 2019 16:15:34 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,223,1571727600"; d="scan'208";a="197051437" Received: from tassilo.jf.intel.com (HELO tassilo.localdomain) ([10.7.201.21]) by orsmga007.jf.intel.com with ESMTP; 20 Nov 2019 16:15:34 -0800 Received: by tassilo.localdomain (Postfix, from userid 1000) id 98D1C300D85; Wed, 20 Nov 2019 16:15:34 -0800 (PST) From: Andi Kleen To: acme@kernel.org Cc: jolsa@kernel.org, linux-kernel@vger.kernel.org, Andi Kleen Subject: [PATCH 05/12] perf evsel: Add iterator to iterate over events ordered by CPU Date: Wed, 20 Nov 2019 16:15:15 -0800 Message-Id: <20191121001522.180827-6-andi@firstfloor.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191121001522.180827-1-andi@firstfloor.org> References: <20191121001522.180827-1-andi@firstfloor.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andi Kleen Add some common code that is needed to iterate over all events in CPU order. Used in followon patches Signed-off-by: Andi Kleen --- v2: Add cpumap__for_each_cpu macro to factor out some common code v3: Drop cpumap__for_each_cpu macro again, replace with evlist__for_each_cpu Add new evlist__for_each_cpu Don't compute cpus nr in cpu_index iterator init, just use all_cpus v4: Remove __next, move into skip Add _no_inc Move initialization into iterator macro Rename cpu_index to cpu_iter --- 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 57943f3685f8..3a442f021468 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 fdce590d2278..dae6e846b2f8 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 13051409fd22..12606efc1f7c 100644 --- a/tools/perf/util/evlist.h +++ b/tools/perf/util/evlist.h @@ -333,9 +333,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 ddc5ee6f6592..b10d5ba21966 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; -- 2.23.0