Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp1319154ybx; Thu, 7 Nov 2019 10:18:23 -0800 (PST) X-Google-Smtp-Source: APXvYqzzYVVhIpigs7tJA8sc8IgoC0BSXSVED/Uh1lchrGo4k/4qIEcR9v6IL9gXFjDv2CemFFI7 X-Received: by 2002:a17:906:3d2:: with SMTP id c18mr4453567eja.111.1573150702956; Thu, 07 Nov 2019 10:18:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573150702; cv=none; d=google.com; s=arc-20160816; b=YIBf9Qz6SRih7RA8q8tXF5WNavYYFDBp6ClmCSR3kIFDmozkLRIvRIb4nGTckDIH3a tLsUhjsmgz6VUAmLUshrQR23GZNhvTDVd6WlGochYjjtk9mxXvJA1t4k5ZlMSULnbuRe QL8L8Uz5NZVYigDsRgJS3WHHSMgPNDN8wSWArn2djAgY85v+u161CSW53luquUrx9cSv b3MUZOSIwjphszKxnRsxjnMk4NLjefLD6eSbuEc/ziMw52jsmhq1Tn/AzwpI8zz//1M/ eWXzPWKIxUY0m7/rzneMnDDDV3u/3Ey3Ut3niMGZ91o+3In6mitVA6D4SZizWFrdqwLq /FMQ== 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=L3xw+ZL9FWf7wUWzM/ob7jUjBPH3Xpkng65Su99ZI60=; b=OVfBiX/lyKoV1Ax49CyGH+D4Law1I4OzM/HvaAVUrjtJaNeYlZM9VQSDLWoGG4Nq/7 6erYjt2p46Qc/anwyUmj+U3U37nVcFwokbvWHaiI1O4wiW/J+H8nQvQb6+KJ6WxpV1t3 1j93c+roYOEqv+uOgLYyJL3Sehp6XT1/CNw92Ug0+iGG32YIyvp/mKHTlBBAS0YwKL0e ReyouQTwLehGH/kgWd26DBBK2kv+8g4voLwp8Y3gDcPld9kVqNAu7LYFSQPLQ5wbasgz MYUWh07Ux66mP7LqkD8Dp5KSrtafVzn99WpqAwqrGX51mo7OJ91DattFgWtcUru62a5T hBJQ== 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 v3si2014792ejq.52.2019.11.07.10.17.59; Thu, 07 Nov 2019 10:18:22 -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 S1730743AbfKGSRJ (ORCPT + 99 others); Thu, 7 Nov 2019 13:17:09 -0500 Received: from mga05.intel.com ([192.55.52.43]:55941 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730059AbfKGSQv (ORCPT ); Thu, 7 Nov 2019 13:16:51 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 Nov 2019 10:16:51 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.68,278,1569308400"; d="scan'208";a="286064062" Received: from tassilo.jf.intel.com (HELO tassilo.localdomain) ([10.7.201.21]) by orsmga001.jf.intel.com with ESMTP; 07 Nov 2019 10:16:49 -0800 Received: by tassilo.localdomain (Postfix, from userid 1000) id DD9A5301BE7; Thu, 7 Nov 2019 10:16:49 -0800 (PST) From: Andi Kleen To: jolsa@kernel.org Cc: acme@kernel.org, linux-kernel@vger.kernel.org, Andi Kleen Subject: [PATCH v5 13/13] perf stat: Use affinity for enabling/disabling events Date: Thu, 7 Nov 2019 10:16:46 -0800 Message-Id: <20191107181646.506734-14-andi@firstfloor.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191107181646.506734-1-andi@firstfloor.org> References: <20191107181646.506734-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 Restructure event enabling/disabling to use affinity, which minimizes the number of IPIs needed. Before on a large test case with 94 CPUs: % time seconds usecs/call calls errors syscall ------ ----------- ----------- --------- --------- ---------------- 54.65 1.899986 22 84812 660 ioctl after: 39.21 0.930451 10 84796 644 ioctl Signed-off-by: Andi Kleen --- v2: Use new iterator macros v3: Use new iterator macros v4: Update iterators again --- tools/perf/util/evlist.c | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 33080f79b977..571bb102b432 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -378,11 +378,28 @@ bool evsel__cpu_iter_skip(struct evsel *ev, int cpu) void evlist__disable(struct evlist *evlist) { struct evsel *pos; + struct affinity affinity; + int cpu, i; + + if (affinity__setup(&affinity) < 0) + return; + + evlist__for_each_cpu (evlist, i, cpu) { + affinity__set(&affinity, cpu); + evlist__for_each_entry(evlist, pos) { + if (evsel__cpu_iter_skip(pos, cpu)) + continue; + if (pos->disabled || !perf_evsel__is_group_leader(pos) || !pos->core.fd) + continue; + evsel__disable_cpu(pos, pos->cpu_iter - 1); + } + } + affinity__cleanup(&affinity); evlist__for_each_entry(evlist, pos) { - if (pos->disabled || !perf_evsel__is_group_leader(pos) || !pos->core.fd) + if (!perf_evsel__is_group_leader(pos) || !pos->core.fd) continue; - evsel__disable(pos); + pos->disabled = true; } evlist->enabled = false; @@ -391,11 +408,28 @@ void evlist__disable(struct evlist *evlist) void evlist__enable(struct evlist *evlist) { struct evsel *pos; + struct affinity affinity; + int cpu, i; + if (affinity__setup(&affinity) < 0) + return; + + evlist__for_each_cpu (evlist, i, cpu) { + affinity__set(&affinity, cpu); + + evlist__for_each_entry(evlist, pos) { + if (evsel__cpu_iter_skip(pos, cpu)) + continue; + if (!perf_evsel__is_group_leader(pos) || !pos->core.fd) + continue; + evsel__enable_cpu(pos, pos->cpu_iter - 1); + } + } + affinity__cleanup(&affinity); evlist__for_each_entry(evlist, pos) { if (!perf_evsel__is_group_leader(pos) || !pos->core.fd) continue; - evsel__enable(pos); + pos->disabled = false; } evlist->enabled = true; -- 2.23.0