Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp4135572ybg; Fri, 25 Oct 2019 13:54:28 -0700 (PDT) X-Google-Smtp-Source: APXvYqzbnpG+LaT3x++hIFTotS9yeQ/0gPoFyT9+mbO9UzkDpYAZZJ0iSY+etiMG1NMjeaMc7Mce X-Received: by 2002:a17:906:e2c4:: with SMTP id gr4mr5529496ejb.260.1572036868709; Fri, 25 Oct 2019 13:54:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572036868; cv=none; d=google.com; s=arc-20160816; b=px6jpeSm2RLfEhpMrQ10yWmCGL5KxHg1b8R40Z/iCnFo/fTVrSKJ3VkONduuLkGTy7 3+LExYF/oy5AIV/brcnO0Ttx+7xeRwvzNt0oGqkhkFUU/S/9yvQ9lnNp8LjoFmBfJcNA sGEbLxnYzQLGdsgBhMCi0OMVLd71g70pzHZNRYNF/bJBGVrnshZSj3aW59F/LAz+WKAD 1A6MYaknSS0ABq1r8km0ZDfjXwkeHg+fQHcUuXECZDXm+rRezN0jMqYdzdH08PeyfFln u/lfLzuf27IUkEyhoQSkixb7xybeJ6HmFJexpemcp8X5fEUxxaRAm8UG2ywNcgOpAg+S wZtA== 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=gq4oSuDrqUN2Hp+0sqAqtmo6F4w3N4bZO4FRSR3f8k0=; b=edXOCbie6o0CW21gos9Rku/PXxadV+7PhWkknKh7uBQC7kCsCnPkKeslZ90evjQWMH hgOsz5zEvHg/yuoYEUt7VcKgN6YFhPo3cdscZeojU/yFZg6mQ6mFp9bbWrZUjaVRS+JQ aovl7VVzHMsdcmY/Hs/i5BRh3oTCezC/EZnFEb468T8trPrjU3sBtBq4u8XN2rvA/jwd budO4R22CNAAaFD4QiniLpTZo9V9hHdxwiFCEuWIOr4RMZRjOMGZTuBI+yb0B0xA3G1u 4TXGemsAXVgi//7FAnaXxYvpUR828nRGlHuQxqy0WFbq8FmdlwCl6hOiGAmH8lP2FOBh U7hQ== 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 t4si2409433edc.171.2019.10.25.13.54.05; Fri, 25 Oct 2019 13:54:28 -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 S2388281AbfJYSO1 (ORCPT + 99 others); Fri, 25 Oct 2019 14:14:27 -0400 Received: from mga18.intel.com ([134.134.136.126]:12175 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388172AbfJYSO0 (ORCPT ); Fri, 25 Oct 2019 14:14:26 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Oct 2019 11:14:25 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.68,229,1569308400"; d="scan'208";a="192617509" Received: from tassilo.jf.intel.com (HELO tassilo.localdomain) ([10.7.201.137]) by orsmga008.jf.intel.com with ESMTP; 25 Oct 2019 11:14:25 -0700 Received: by tassilo.localdomain (Postfix, from userid 1000) id F1D5D300EE9; Fri, 25 Oct 2019 11:14:24 -0700 (PDT) From: Andi Kleen To: acme@kernel.org Cc: jolsa@kernel.org, eranian@google.com, linux-kernel@vger.kernel.org, Andi Kleen Subject: [PATCH v3 7/7] perf stat: Use affinity for enabling/disabling events Date: Fri, 25 Oct 2019 11:14:17 -0700 Message-Id: <20191025181417.10670-8-andi@firstfloor.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191025181417.10670-1-andi@firstfloor.org> References: <20191025181417.10670-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 --- tools/perf/lib/evsel.c | 49 +++++++++++++++++++++-------- tools/perf/lib/include/perf/evsel.h | 2 ++ tools/perf/util/evlist.c | 48 +++++++++++++++++++++++++--- tools/perf/util/evsel.c | 13 ++++++++ tools/perf/util/evsel.h | 2 ++ 5 files changed, 96 insertions(+), 18 deletions(-) diff --git a/tools/perf/lib/evsel.c b/tools/perf/lib/evsel.c index ea775dacbd2d..89ddfade0b96 100644 --- a/tools/perf/lib/evsel.c +++ b/tools/perf/lib/evsel.c @@ -198,38 +198,61 @@ int perf_evsel__read(struct perf_evsel *evsel, int cpu, int thread, } static int perf_evsel__run_ioctl(struct perf_evsel *evsel, - int ioc, void *arg) + int ioc, void *arg, + int cpu) { - int cpu, thread; + int thread; - for (cpu = 0; cpu < xyarray__max_x(evsel->fd); cpu++) { - for (thread = 0; thread < xyarray__max_y(evsel->fd); thread++) { - int fd = FD(evsel, cpu, thread), - err = ioctl(fd, ioc, arg); + for (thread = 0; thread < xyarray__max_y(evsel->fd); thread++) { + int fd = FD(evsel, cpu, thread), + err = ioctl(fd, ioc, arg); - if (err) - return err; - } + if (err) + return err; } return 0; } +int perf_evsel__enable_cpu(struct perf_evsel *evsel, int cpu) +{ + return perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_ENABLE, 0, cpu); +} + int perf_evsel__enable(struct perf_evsel *evsel) { - return perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_ENABLE, 0); + int i; + int err = 0; + + for (i = 0; i < evsel->cpus->nr && !err; i++) + err = perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_ENABLE, 0, i); + return err; +} + +int perf_evsel__disable_cpu(struct perf_evsel *evsel, int cpu) +{ + return perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_DISABLE, 0, cpu); } int perf_evsel__disable(struct perf_evsel *evsel) { - return perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_DISABLE, 0); + int i; + int err = 0; + + for (i = 0; i < evsel->cpus->nr && !err; i++) + err = perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_DISABLE, 0, i); + return err; } int perf_evsel__apply_filter(struct perf_evsel *evsel, const char *filter) { - return perf_evsel__run_ioctl(evsel, + int err = 0, i; + + for (i = 0; i < evsel->cpus->nr && !err; i++) + err = perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_SET_FILTER, - (void *)filter); + (void *)filter, i); + return err; } struct perf_cpu_map *perf_evsel__cpus(struct perf_evsel *evsel) diff --git a/tools/perf/lib/include/perf/evsel.h b/tools/perf/lib/include/perf/evsel.h index e7add554f861..c82ec39a4ad0 100644 --- a/tools/perf/lib/include/perf/evsel.h +++ b/tools/perf/lib/include/perf/evsel.h @@ -30,7 +30,9 @@ LIBPERF_API void perf_evsel__close_cpu(struct perf_evsel *evsel, int cpu); LIBPERF_API int perf_evsel__read(struct perf_evsel *evsel, int cpu, int thread, struct perf_counts_values *count); LIBPERF_API int perf_evsel__enable(struct perf_evsel *evsel); +LIBPERF_API int perf_evsel__enable_cpu(struct perf_evsel *evsel, int cpu); LIBPERF_API int perf_evsel__disable(struct perf_evsel *evsel); +LIBPERF_API int perf_evsel__disable_cpu(struct perf_evsel *evsel, int cpu); LIBPERF_API struct perf_cpu_map *perf_evsel__cpus(struct perf_evsel *evsel); LIBPERF_API struct perf_thread_map *perf_evsel__threads(struct perf_evsel *evsel); LIBPERF_API struct perf_event_attr *perf_evsel__attr(struct perf_evsel *evsel); diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index ca9b06979fc0..e3e4c2fedc8a 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -379,26 +379,64 @@ void evlist__cpu_iter_next(struct evsel *ev) void evlist__disable(struct evlist *evlist) { struct evsel *pos; + struct affinity affinity; + struct perf_cpu_map *cpus; + int i, cpu; + + if (affinity__setup(&affinity) < 0) + return; + + cpus = evlist__cpu_iter_start(evlist); + cpumap__for_each_cpu (cpus, i, cpu) { + affinity__set(&affinity, cpu); + evlist__for_each_entry(evlist, pos) { + if (evlist__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_index); + evlist__cpu_iter_next(pos); + } + } + 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; } void evlist__enable(struct evlist *evlist) { struct evsel *pos; + struct affinity affinity; + struct perf_cpu_map *cpus; + int i, cpu; + + if (affinity__setup(&affinity) < 0) + return; + cpus = evlist__cpu_iter_start(evlist); + cpumap__for_each_cpu (cpus, i, cpu) { + affinity__set(&affinity, cpu); + + evlist__for_each_entry(evlist, pos) { + if (evlist__cpu_iter_skip(pos, cpu)) + continue; + if (!perf_evsel__is_group_leader(pos) || !pos->core.fd) + continue; + evsel__enable_cpu(pos, pos->cpu_index); + evlist__cpu_iter_next(pos); + } + } + 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; } diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 7106f9a067df..79050a6f4991 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1205,13 +1205,26 @@ int perf_evsel__append_addr_filter(struct evsel *evsel, const char *filter) return perf_evsel__append_filter(evsel, "%s,%s", filter); } +/* Caller has to clear disabled after going through all CPUs. */ +int evsel__enable_cpu(struct evsel *evsel, int cpu) +{ + int err = perf_evsel__enable_cpu(&evsel->core, cpu); + return err; +} + int evsel__enable(struct evsel *evsel) { int err = perf_evsel__enable(&evsel->core); if (!err) evsel->disabled = false; + return err; +} +/* Caller has to set disabled after going through all CPUs. */ +int evsel__disable_cpu(struct evsel *evsel, int cpu) +{ + int err = perf_evsel__disable_cpu(&evsel->core, cpu); return err; } diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index 9fc9f6698aa4..15977bbe7b63 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -222,8 +222,10 @@ int perf_evsel__set_filter(struct evsel *evsel, const char *filter); int perf_evsel__append_tp_filter(struct evsel *evsel, const char *filter); int perf_evsel__append_addr_filter(struct evsel *evsel, const char *filter); +int evsel__enable_cpu(struct evsel *evsel, int cpu); int evsel__enable(struct evsel *evsel); int evsel__disable(struct evsel *evsel); +int evsel__disable_cpu(struct evsel *evsel, int cpu); int perf_evsel__open_per_cpu(struct evsel *evsel, struct perf_cpu_map *cpus, -- 2.21.0