From patchwork Tue Aug 13 13:23:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Clark X-Patchwork-Id: 13762043 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AE653C52D7C for ; Tue, 13 Aug 2024 13:28:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=YJPiTzck/wj4Bl8bp1dFvT+bnyHvEgyjm9lLc0sAxDQ=; b=cREEX1AriZ6oE0uTv2GU6E9WVv 5mLGrKI0s0p0BllaaCBKsSl/I6i3xci4SzGRDTLi2I5clSUI59dynhKXXsKG99bD5hJ3N59FzB7Jd H1f6CGNP3Di0vu96WPjj6K8ED3Wih8BOmih1AjQ5tMZHyn75Su1WP+NKBhNzwcZf8OKzEzP1abyB6 shmUe2aLp+TqmfVIHgQ0fyp1lHYuRu2eUZRTXw0ylnLLM5/gxyYFMOXfIugzLeD96karW0NiZjnRD S0OrToNEtNWpZnLjxzSfJwG6tnqWoVs7KrATSP+kCG/AZ4SgMGLvfNz1bORWe930uyq7gu/qxKrIX 5P8sXspA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sdrZc-00000003sDz-1wlQ; Tue, 13 Aug 2024 13:28:28 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sdrWp-00000003rNb-18wS for linux-arm-kernel@bombadil.infradead.org; Tue, 13 Aug 2024 13:25:35 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=YJPiTzck/wj4Bl8bp1dFvT+bnyHvEgyjm9lLc0sAxDQ=; b=XbxXX6eUPrW038xB3wIsi1zsDd 2hwYVeFlJaKOSYA2oKX3EOsGwCxrRsFhCeceuDYqnOD6TPP3FCQnx8FZLV/r1U6iPrTg4tHBZ0tr2 UD0pgC5ljfclrv/IaCxpCA4qcq1gVjvJ1B9aEhoDPFWeNCL/VyVFkqpfgW467N4WJbGNrcR2rGFmf kzrzpfFUJLuc2Jb4rr7BjI8vd+a04zL9PFel92phIHGaGHluhaTgF0xKlIRJsIpvbWXIw0flMuvNP 0sAow6h8WfxDtk7jiik8oJLTuszFjItI+l2N7NqSwQOOXepOSjOmDVj3TCoXNc+byJD9VmgHinqx2 HJk7gPwA==; Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]) by desiato.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sdrWk-00000007nS3-0dbj for linux-arm-kernel@lists.infradead.org; Tue, 13 Aug 2024 13:25:32 +0000 Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-428e3129851so40535615e9.3 for ; Tue, 13 Aug 2024 06:25:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1723555529; x=1724160329; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YJPiTzck/wj4Bl8bp1dFvT+bnyHvEgyjm9lLc0sAxDQ=; b=vhwGVkxHRcFT+PIfS2187v/kmqVpB79y5Ssha0BQC77g2Ti7M1fWmntPnmRtzizQnX RdhWnRuRlPbG941UlLZdH29rxILiwXzF+N/Xo7GQ2iO7rFJjLovzFLXerRZAuZOWyzRi ZGImuy3I1nd6gPXRZYJ9Qp+jfSiVeyow0z1eo6yGT0+vABexgY18OZd8t02xw0KofCOS 5/7MHZZcRWce0lI+TCk1waALdtFjPlrg+JDmKYMrinAf9yA9FatiJu89hF37gZnMGU1g EIVMdV66lyNMHEVtZtHSYXQWHA8LwMCtSjyly/F1ItO79l0XAk6JACMAxq7jzgqjmwKc NiVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723555529; x=1724160329; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YJPiTzck/wj4Bl8bp1dFvT+bnyHvEgyjm9lLc0sAxDQ=; b=PSL0CejGLCUDnygplNAUImWJpLSKzE0ooMQKJoKZCnD2HXGjnRhuum4fxbznmWnWLY MIAfU/HSm06CXFMCWYW1+STUU3MmEcKf55rYdU6vT5yFtctg96TdAy4GQNHGfVLQiPa1 ugMHSTtVsoaVi0urVsDAO/+eRcEQDZ2KzHzCDEhLUiA4UN1yUMsLO9HjQavsEtNZLe0l us7yM2fHTZcsA/MEGIN0Rl0ThBEHEU14zupQA6Yx8uJojrNwxsDMAWnwX7Y8gBcljsU0 4t2hpD2stG7NoHJ3QM95UGo5prji64i4XhsXjtsBCtxxRCJB041oHlAKjC1zEfTzzVap kX1Q== X-Forwarded-Encrypted: i=1; AJvYcCXo7H1hjHLJguhMf4yUWFPVqmcoTqS84nieXmjgGHvwP9axvyx+vQvnpv7LhUYDxgTrHtvL9fl4j1X6dqWQByIQfAZQruit9j2BTKGYk2jJWBwjGWQ= X-Gm-Message-State: AOJu0YylZJrqrOuYUsSyQ/e73u1MTiMXakTmm8UY7ClAlWRC9pcvHbZC gI8qFS0o4doqvX7mwZ6uk77KtzI81QlU1QyBsYQa/8qyOdsfDscVfjJR0+yFLII= X-Google-Smtp-Source: AGHT+IGpUiL8HI1I4dgUEXAngk1hqDYSTUpCg0rDVeIRHKgEB9vHTQ+oOqXVgzYYIWv7xtQbj8/VkA== X-Received: by 2002:a05:600c:358c:b0:428:ea8e:b48a with SMTP id 5b1f17b1804b1-429d47f49fbmr28609085e9.8.1723555528866; Tue, 13 Aug 2024 06:25:28 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4290c738d21sm223186625e9.12.2024.08.13.06.25.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Aug 2024 06:25:28 -0700 (PDT) From: James Clark To: irogers@google.com, linux-perf-users@vger.kernel.org Cc: James Clark , John Garry , Will Deacon , Mike Leach , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Adrian Hunter , "Liang, Kan" , Dominique Martinet , Yang Jihong , Ze Gao , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 5/7] perf evlist: Use hybrid default attrs whenever extended type is supported Date: Tue, 13 Aug 2024 14:23:13 +0100 Message-Id: <20240813132323.98728-6-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240813132323.98728-1-james.clark@linaro.org> References: <20240813132323.98728-1-james.clark@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240813_142530_453095_59DCA37C X-CRM114-Status: GOOD ( 18.37 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org For x86, a hybrid version of ___evlist__add_default_attrs() was added to support default perf stat events. This can actually be used whenever perf_pmus__supports_extended_type() is true, which now makes default perf stat arguments work properly on Arm big.LITTLE: $ perf stat ... 3347093940 armv8_cortex_a53/cycles/ # 0.563 GHz (98.99%) 3295523067 armv8_cortex_a57/cycles/ # 0.554 GHz (67.07%) ... Signed-off-by: James Clark --- tools/perf/arch/x86/util/evlist.c | 65 ------------------------------- tools/perf/util/evlist.c | 65 +++++++++++++++++++++++++++---- tools/perf/util/evlist.h | 6 +-- 3 files changed, 59 insertions(+), 77 deletions(-) diff --git a/tools/perf/arch/x86/util/evlist.c b/tools/perf/arch/x86/util/evlist.c index b1ce0c52d88d..bbe6240c7f71 100644 --- a/tools/perf/arch/x86/util/evlist.c +++ b/tools/perf/arch/x86/util/evlist.c @@ -8,71 +8,6 @@ #include "topdown.h" #include "evsel.h" -static int ___evlist__add_default_attrs(struct evlist *evlist, - struct perf_event_attr *attrs, - size_t nr_attrs) -{ - LIST_HEAD(head); - size_t i = 0; - - for (i = 0; i < nr_attrs; i++) - event_attr_init(attrs + i); - - if (perf_pmus__num_core_pmus() == 1) - return evlist__add_attrs(evlist, attrs, nr_attrs); - - for (i = 0; i < nr_attrs; i++) { - struct perf_pmu *pmu = NULL; - - if (attrs[i].type == PERF_TYPE_SOFTWARE) { - struct evsel *evsel = evsel__new(attrs + i); - - if (evsel == NULL) - goto out_delete_partial_list; - list_add_tail(&evsel->core.node, &head); - continue; - } - - while ((pmu = perf_pmus__scan_core(pmu)) != NULL) { - struct perf_cpu_map *cpus; - struct evsel *evsel; - - evsel = evsel__new(attrs + i); - if (evsel == NULL) - goto out_delete_partial_list; - evsel->core.attr.config |= (__u64)pmu->type << PERF_PMU_TYPE_SHIFT; - cpus = perf_cpu_map__get(pmu->cpus); - evsel->core.cpus = cpus; - evsel->core.own_cpus = perf_cpu_map__get(cpus); - evsel->pmu_name = strdup(pmu->name); - list_add_tail(&evsel->core.node, &head); - } - } - - evlist__splice_list_tail(evlist, &head); - - return 0; - -out_delete_partial_list: - { - struct evsel *evsel, *n; - - __evlist__for_each_entry_safe(&head, n, evsel) - evsel__delete(evsel); - } - return -1; -} - -int arch_evlist__add_default_attrs(struct evlist *evlist, - struct perf_event_attr *attrs, - size_t nr_attrs) -{ - if (!nr_attrs) - return 0; - - return ___evlist__add_default_attrs(evlist, attrs, nr_attrs); -} - int arch_evlist__cmp(const struct evsel *lhs, const struct evsel *rhs) { if (topdown_sys_has_perf_metrics() && diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 1417f9a23083..e0c31399beb6 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -5,6 +5,7 @@ * Parts came from builtin-{top,stat,record}.c, see those files for further * copyright notes. */ +#include "pmus.h" #include #include #include @@ -338,24 +339,74 @@ int evlist__add_attrs(struct evlist *evlist, struct perf_event_attr *attrs, size return -1; } -int __evlist__add_default_attrs(struct evlist *evlist, struct perf_event_attr *attrs, size_t nr_attrs) + +static int __evlist__add_default_attrs_ext_type(struct evlist *evlist, + struct perf_event_attr *attrs, + size_t nr_attrs) { - size_t i; + LIST_HEAD(head); + size_t i = 0; for (i = 0; i < nr_attrs; i++) event_attr_init(attrs + i); - return evlist__add_attrs(evlist, attrs, nr_attrs); + for (i = 0; i < nr_attrs; i++) { + struct perf_pmu *pmu = NULL; + + if (attrs[i].type == PERF_TYPE_SOFTWARE) { + struct evsel *evsel = evsel__new(attrs + i); + + if (evsel == NULL) + goto out_delete_partial_list; + list_add_tail(&evsel->core.node, &head); + continue; + } + + while ((pmu = perf_pmus__scan_core(pmu)) != NULL) { + struct perf_cpu_map *cpus; + struct evsel *evsel; + + evsel = evsel__new(attrs + i); + if (evsel == NULL) + goto out_delete_partial_list; + evsel->core.attr.config |= (__u64)pmu->type << PERF_PMU_TYPE_SHIFT; + cpus = perf_cpu_map__get(pmu->cpus); + evsel->core.cpus = cpus; + evsel->core.own_cpus = perf_cpu_map__get(cpus); + evsel->pmu_name = strdup(pmu->name); + list_add_tail(&evsel->core.node, &head); + } + } + + evlist__splice_list_tail(evlist, &head); + + return 0; + +out_delete_partial_list: + { + struct evsel *evsel, *n; + + __evlist__for_each_entry_safe(&head, n, evsel) + evsel__delete(evsel); + } + return -1; } -__weak int arch_evlist__add_default_attrs(struct evlist *evlist, - struct perf_event_attr *attrs, - size_t nr_attrs) +int __evlist__add_default_attrs(struct evlist *evlist, struct perf_event_attr *attrs, + size_t nr_attrs) { + size_t i; + if (!nr_attrs) return 0; - return __evlist__add_default_attrs(evlist, attrs, nr_attrs); + if (perf_pmus__supports_extended_type()) + return __evlist__add_default_attrs_ext_type(evlist, attrs, nr_attrs); + + for (i = 0; i < nr_attrs; i++) + event_attr_init(attrs + i); + + return evlist__add_attrs(evlist, attrs, nr_attrs); } struct evsel *evlist__find_tracepoint_by_id(struct evlist *evlist, int id) diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h index cccc34da5a02..06d1eeacc0d1 100644 --- a/tools/perf/util/evlist.h +++ b/tools/perf/util/evlist.h @@ -106,12 +106,8 @@ int evlist__add_attrs(struct evlist *evlist, struct perf_event_attr *attrs, size int __evlist__add_default_attrs(struct evlist *evlist, struct perf_event_attr *attrs, size_t nr_attrs); -int arch_evlist__add_default_attrs(struct evlist *evlist, - struct perf_event_attr *attrs, - size_t nr_attrs); - #define evlist__add_default_attrs(evlist, array) \ - arch_evlist__add_default_attrs(evlist, array, ARRAY_SIZE(array)) + __evlist__add_default_attrs(evlist, array, ARRAY_SIZE(array)) int arch_evlist__cmp(const struct evsel *lhs, const struct evsel *rhs);