From nobody Thu Nov 28 13:33:32 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 611EC28FF; Tue, 1 Oct 2024 00:20:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727742030; cv=none; b=a/gfBaGhNhkc8NIseHWzNcYOV7vnCB9EFelGiKd62s7wZQgmcIrhuo5FYmJM1xib3f7u5CJg8DmmgNRxUB9HYpVKqgRi1eq7HTu3OPzu3n81WR9Xtsi+giMWx4chkwWEKC2ITHCQnnh/E8SiglJ8pnmpjU/07zazGGSkvskU0ZQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727742030; c=relaxed/simple; bh=SCiLTiO0cp8e6Kfe5pAOVI5Gp/s3ui2/Ngx6XNpetHw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HxXpDPU2IQ/xHiK/+gzscHsrX0En/tsVsbTmy6K47GJ87J2G5ydfoEGNfCKkvovU/PerPrInhCw7RJOP1o8sGahccPlsig3qoxRBoX5vhsc+Xkk/2PdG87PZHXicW56WupxYwZtOAEBUkgjgt12mZciRoGcr1h8nLKA1SvvtibI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GL/ITFIG; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="GL/ITFIG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4F5DAC4CED1; Tue, 1 Oct 2024 00:20:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727742029; bh=SCiLTiO0cp8e6Kfe5pAOVI5Gp/s3ui2/Ngx6XNpetHw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GL/ITFIGKEEtS/vA1OKYEn2ivPHkLfsUsztWdOo+kYZDUObsmVazQeWF/dP92ulpq 4niEVmfYJ0b4KaELgTd1Fprh6BQO4Y9cTzoe3MpY37tiEcfqzRag6vB2XT/TIk19/W t6DABt+V7j9kblxhPflchpUYcIl6LUKzzyxYAruncWWTmOZRyQI6Lg8gwuTwTQVNj6 6TBdXkK40KHdkp5h33mRNVUk5nzInzL/qBTqW7Wnt8CO+Dr4GfdJc+f1NDjbtn+nPK u8rkCVIV7WnX+pGJikkjnC2Kuu4inGuLu8+vrva6Q7nseIucqB3UG/i+abT8yPNfBH Nv3guNupkCRYA== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers , Kan Liang Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Ravi Bangoria , Mark Rutland , James Clark , Kajol Jain , Thomas Richter , Atish Patra , Palmer Dabbelt , Mingwei Zhang , James Clark Subject: [PATCH 1/8] perf tools: Add fallback for exclude_guest Date: Mon, 30 Sep 2024 17:20:20 -0700 Message-ID: <20241001002027.1272889-2-namhyung@kernel.org> X-Mailer: git-send-email 2.46.1.824.gd892dcdcdd-goog In-Reply-To: <20241001002027.1272889-1-namhyung@kernel.org> References: <20241001002027.1272889-1-namhyung@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Commit 7b100989b4f6bce70 ("perf evlist: Remove __evlist__add_default") changed to parse "cycles:P" event instead of creating a new cycles event for perf record. But it also changed the way how modifiers are handled so it doesn't set the exclude_guest bit by default. It seems Apple M1 PMU requires exclude_guest set and returns EOPNOTSUPP if not. Let's add a fallback so that it can work with default events. Fixes: 7b100989b4f6bce70 ("perf evlist: Remove __evlist__add_default") Cc: Mark Rutland Cc: James Clark Signed-off-by: Namhyung Kim Acked-by: Kan Liang Reviewed-by: Ian Rogers Reviewed-by: James Clark Reviewed-by: Ravi Bangoria --- tools/perf/builtin-stat.c | 18 +++++++++++++++--- tools/perf/util/evsel.c | 21 +++++++++++++++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 1521b6df26065ccf..fd9ea15f6b1c0809 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -639,8 +639,7 @@ static enum counter_recovery stat_handle_error(struct e= vsel *counter) * (behavior changed with commit b0a873e). */ if (errno =3D=3D EINVAL || errno =3D=3D ENOSYS || - errno =3D=3D ENOENT || errno =3D=3D EOPNOTSUPP || - errno =3D=3D ENXIO) { + errno =3D=3D ENOENT || errno =3D=3D ENXIO) { if (verbose > 0) ui__warning("%s event is not supported by the kernel.\n", evsel__name(counter)); @@ -658,7 +657,7 @@ static enum counter_recovery stat_handle_error(struct e= vsel *counter) if (verbose > 0) ui__warning("%s\n", msg); return COUNTER_RETRY; - } else if (target__has_per_thread(&target) && + } else if (target__has_per_thread(&target) && errno !=3D EOPNOTSUPP && evsel_list->core.threads && evsel_list->core.threads->err_thread !=3D -1) { /* @@ -679,6 +678,19 @@ static enum counter_recovery stat_handle_error(struct = evsel *counter) return COUNTER_SKIP; } =20 + if (errno =3D=3D EOPNOTSUPP) { + if (verbose > 0) { + ui__warning("%s event is not supported by the kernel.\n", + evsel__name(counter)); + } + counter->supported =3D false; + counter->errored =3D true; + + if ((evsel__leader(counter) !=3D counter) || + !(counter->core.leader->nr_members > 1)) + return COUNTER_SKIP; + } + evsel__open_strerror(counter, &target, errno, msg, sizeof(msg)); ui__error("%s\n", msg); =20 diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index da0bada62140d9b0..0ddd77c139e89a2e 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -3259,6 +3259,27 @@ bool evsel__fallback(struct evsel *evsel, struct tar= get *target, int err, evsel->core.attr.exclude_kernel =3D 1; evsel->core.attr.exclude_hv =3D 1; =20 + return true; + } else if (err =3D=3D EOPNOTSUPP && !evsel->core.attr.exclude_guest && + !evsel->exclude_GH) { + const char *name =3D evsel__name(evsel); + char *new_name; + const char *sep =3D ":"; + + /* Is there already the separator in the name. */ + if (strchr(name, '/') || + (strchr(name, ':') && !evsel->is_libpfm_event)) + sep =3D ""; + + if (asprintf(&new_name, "%s%sH", name, sep) < 0) + return false; + + free(evsel->name); + evsel->name =3D new_name; + /* Apple M1 requires exclude_guest */ + scnprintf(msg, msgsize, "trying to fall back to excluding guest samples"= ); + evsel->core.attr.exclude_guest =3D 1; + return true; } =20 --=20 2.46.1.824.gd892dcdcdd-goog From nobody Thu Nov 28 13:33:32 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 237564A11; Tue, 1 Oct 2024 00:20:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727742031; cv=none; b=as6/XEt/ZECqgC2w5jspQPMCyWRjO6EA1JPaVuOq+ShZUk07cA+4nouTrdgPc6E1RBd7KqJpWP0H80YYLSVE3SFLHFBqPhZ128LXGbv68i9/5jdPe1Vfo3Dd0NUjFUrto/GhEJwVR+shVwXktz9JsiyaMBjfd2FIHv0+fH8UD3M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727742031; c=relaxed/simple; bh=ZTAUJtGBCA92G9auFnZoo3tHeZiI0RIqR6tlTOwqNVE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZxRLaP38YnfN6X0ob/8kMvPxsldvy1PHWzVc8q3oTUDGoJjRJPNR2p7NRG737cNbHwofpU4DQ3jqw3s+o5dA+IaqpNi3oOdtYvnylePXPJuR0U4/YQVttzvGrqfeaEuAm/spnkBsA7xXu0pvtw4K1+NLsLqq0STeBcd3DzCnpA8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PBzGjJ5f; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="PBzGjJ5f" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1894CC4CED6; Tue, 1 Oct 2024 00:20:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727742030; bh=ZTAUJtGBCA92G9auFnZoo3tHeZiI0RIqR6tlTOwqNVE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PBzGjJ5f0jGoJtAhdmPTUXYL7aNMvmwBMW+KrLIILHK9T7RCb6MiiJEvSpWAiFxVd 6/Q23b2lEN78KeyCsVz7cRfNnuLCKAeHDO+sJcmT5Y4VdPRHxXr4Gw7Ze8h9nQLs6F rpR2ZQORpYbBDwKJN8EpsBwT1iFqSmQAhFo2T2IY4ti5Ta3yMeEAG3jVjnotpw6e5H 889PpnucNPobjsyaZs4A+3t2244LKDW/NcYXefWC4bRv6D1YSxlXQECbTF4GrTUTc/ w5jr8aJY3dJj/KZFHTP1SDA4La0tP1kPZKIlrjz4girB+UZE9IE5Xt0VC9xqEbvion Zp78qduvq3qUw== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers , Kan Liang Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Ravi Bangoria , Mark Rutland , James Clark , Kajol Jain , Thomas Richter , Atish Patra , Palmer Dabbelt , Mingwei Zhang , James Clark Subject: [PATCH 2/8] perf tools: Don't set attr.exclude_guest by default Date: Mon, 30 Sep 2024 17:20:21 -0700 Message-ID: <20241001002027.1272889-3-namhyung@kernel.org> X-Mailer: git-send-email 2.46.1.824.gd892dcdcdd-goog In-Reply-To: <20241001002027.1272889-1-namhyung@kernel.org> References: <20241001002027.1272889-1-namhyung@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The exclude_guest in the event attribute is to limit profiling in the host environment. But I'm not sure why we want to set it by default cause we don't care about it in most cases and I feel like it just makes new PMU implementation complicated. Of course it's useful for perf kvm command so I added the exclude_GH_default variable to preserve the old behavior for perf kvm and other commands like perf record and stat won't set the exclude bit. This is helpful for AMD IBS case since having exclude_guest bit will clear new feature bit due to the missing feature check logic. $ sysctl kernel.perf_event_paranoid kernel.perf_event_paranoid =3D 0 $ perf record -W -e ibs_op// -vv true 2>&1 | grep switching switching off PERF_FORMAT_LOST support switching off weight struct support switching off bpf_event switching off ksymbol switching off cloexec flag switching off mmap2 switching off exclude_guest, exclude_host Intestingly, I found it sets the exclude_bit if "u" modifier is used. I don't know why but it's neither intuitive nor consistent. Let's remove the bit there too. Cc: Mark Rutland Cc: James Clark Cc: Ravi Bangoria Signed-off-by: Namhyung Kim Acked-by: Kan Liang Reviewed-by: Ian Rogers Reviewed-by: James Clark Reviewed-by: Ravi Bangoria --- tools/perf/builtin-kvm.c | 1 + tools/perf/tests/attr/test-record-dummy-C0 | 2 +- tools/perf/tests/parse-events.c | 18 +++++++++--------- tools/perf/util/parse-events.c | 2 +- tools/perf/util/util.c | 10 ++++++++-- tools/perf/util/util.h | 3 +++ 6 files changed, 23 insertions(+), 13 deletions(-) diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index 55ea17c5ff02acf7..099ce3ebf67ce6ee 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -2147,6 +2147,7 @@ int cmd_kvm(int argc, const char **argv) "buildid-list", "stat", NULL }; const char *kvm_usage[] =3D { NULL, NULL }; =20 + exclude_GH_default =3D true; perf_host =3D 0; perf_guest =3D 1; =20 diff --git a/tools/perf/tests/attr/test-record-dummy-C0 b/tools/perf/tests/= attr/test-record-dummy-C0 index 576ec48b3aafaa6a..8ce6f0a5df5b7013 100644 --- a/tools/perf/tests/attr/test-record-dummy-C0 +++ b/tools/perf/tests/attr/test-record-dummy-C0 @@ -37,7 +37,7 @@ precise_ip=3D0 mmap_data=3D0 sample_id_all=3D1 exclude_host=3D0 -exclude_guest=3D1 +exclude_guest=3D0 exclude_callchain_kernel=3D0 exclude_callchain_user=3D0 mmap2=3D1 diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-event= s.c index 78e999f03d2d75f4..727683f249f66f5a 100644 --- a/tools/perf/tests/parse-events.c +++ b/tools/perf/tests/parse-events.c @@ -932,7 +932,7 @@ static int test__group2(struct evlist *evlist) TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user); TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kerne= l); TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv); - TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest); + TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest); TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host); TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel)); @@ -947,7 +947,7 @@ static int test__group2(struct evlist *evlist) TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user); TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel= ); TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv); - TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest); + TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest); TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host); TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); if (evsel__has_leader(evsel, leader)) @@ -1072,7 +1072,7 @@ static int test__group3(struct evlist *evlist __maybe= _unused) TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user); TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel); TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv); - TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest); + TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest); TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host); TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel)); @@ -1222,7 +1222,7 @@ static int test__group5(struct evlist *evlist __maybe= _unused) TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user); TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel= ); TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv); - TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest); + TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest); TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host); TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel)); @@ -1437,7 +1437,7 @@ static int test__leader_sample1(struct evlist *evlist) TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user); TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel= ); TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv); - TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest); + TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest); TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host); TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); TEST_ASSERT_VAL("wrong group name", !evsel->group_name); @@ -1453,7 +1453,7 @@ static int test__leader_sample1(struct evlist *evlist) TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user); TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel= ); TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv); - TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest); + TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest); TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host); TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader)); @@ -1468,7 +1468,7 @@ static int test__leader_sample1(struct evlist *evlist) TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user); TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel= ); TEST_ASSERT_VAL("wrong exclude_hv", !evsel->core.attr.exclude_hv); - TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest); + TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest); TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host); TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); TEST_ASSERT_VAL("wrong group name", !evsel->group_name); @@ -1497,7 +1497,7 @@ static int test__leader_sample2(struct evlist *evlist= __maybe_unused) TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user); TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel); TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv); - TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest); + TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest); TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host); TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); TEST_ASSERT_VAL("wrong group name", !evsel->group_name); @@ -1513,7 +1513,7 @@ static int test__leader_sample2(struct evlist *evlist= __maybe_unused) TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user); TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel); TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv); - TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest); + TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest); TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host); TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip); TEST_ASSERT_VAL("wrong group name", !evsel->group_name); diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index e96cf13dc396193f..ff67213d6e887169 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -1776,7 +1776,7 @@ static int parse_events__modifier_list(struct parse_e= vents_state *parse_state, if (mod.user) { if (!exclude) exclude =3D eu =3D ek =3D eh =3D 1; - if (!exclude_GH && !perf_guest) + if (!exclude_GH && !perf_guest && exclude_GH_default) eG =3D 1; eu =3D 0; } diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c index 9d55a13787ce3c05..280c86d61d8a7956 100644 --- a/tools/perf/util/util.c +++ b/tools/perf/util/util.c @@ -78,17 +78,23 @@ bool sysctl__nmi_watchdog_enabled(void) =20 bool test_attr__enabled; =20 +bool exclude_GH_default; + bool perf_host =3D true; bool perf_guest =3D false; =20 void event_attr_init(struct perf_event_attr *attr) { + /* to capture ABI version */ + attr->size =3D sizeof(*attr); + + if (!exclude_GH_default) + return; + if (!perf_host) attr->exclude_host =3D 1; if (!perf_guest) attr->exclude_guest =3D 1; - /* to capture ABI version */ - attr->size =3D sizeof(*attr); } =20 int mkdir_p(char *path, mode_t mode) diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h index 9966c21aaf048479..4920e102ff54879a 100644 --- a/tools/perf/util/util.h +++ b/tools/perf/util/util.h @@ -21,6 +21,9 @@ extern const char perf_more_info_string[]; =20 extern const char *input_name; =20 +/* This will control if perf_{host,guest} will set attr.exclude_{host,gues= t}. */ +extern bool exclude_GH_default; + extern bool perf_host; extern bool perf_guest; =20 --=20 2.46.1.824.gd892dcdcdd-goog From nobody Thu Nov 28 13:33:32 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C482AC2E3; Tue, 1 Oct 2024 00:20:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727742031; cv=none; b=ShqdzwynDqXy8EK5TZwnmHswjklPYXKvi3uw5qxFlQa/Ce0PEFLLVZbJG6BrYd7Tk7jfuUNcO9Hbn3ByzzeylfkvhE7SUxtHxD2FivQbcg7M2B/+BqPdvPG4TKEUgrbNjKArYf6X8fMxHbf4ufmEGjRMuOmFDULULdVTDD15qsA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727742031; c=relaxed/simple; bh=WisHYEcdCSkfkVkvX+IWJW/zRWzgI9OT+00Jz6iq/pg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=s6+e9XdkUpTeDx4NUWuANKJ1euaCvknXHw+bHglKZJ45QcyZGbcRj6GKPlXxGAPOS21xIX9TwP8YR/c1/yus5frO7NOftvZazkE1cilU4q8SBhBgvgeHVNb9XTFlEwRJhJlc3/rARP3bst3M9kVPJrUmp8VcUSyc20v3uyv4A7M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=uJzgdUAq; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="uJzgdUAq" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D26DCC4CEC7; Tue, 1 Oct 2024 00:20:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727742031; bh=WisHYEcdCSkfkVkvX+IWJW/zRWzgI9OT+00Jz6iq/pg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uJzgdUAqncYD6+xk+gCEKgwgohZe03N1Vpr0tzDWoHH6gWdBA0id55G2Q1HgBuLV6 MQs01yb9Agymf/Junzsp9Jf1yY6MLdWoegxA5RaqgDXXghMAQlEX4CU06JARBWH4lX +pHh9gYBWrzS8ibjwBkqhmyBC7hN6ixwJrJHrDxDWg8hFVPdQ/zbIhoqAYWhkiZqGV 3Le1mtqAhlwK+Lof2nbCH4k8BaSr1x7GORL83cyIYBSUu5PHjxhaqp9uVqCQdHpmiO ua+RrZGRHWJsiiDzxkrRdNH64IH+soHhG4HlCIfBR28lRA66CzfQRrmAEpUnbQpmpd PUCSWvG1y/95g== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers , Kan Liang Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Ravi Bangoria , Mark Rutland , James Clark , Kajol Jain , Thomas Richter , Atish Patra , Palmer Dabbelt , Mingwei Zhang Subject: [PATCH 3/8] perf tools: Simplify evsel__add_modifier() Date: Mon, 30 Sep 2024 17:20:22 -0700 Message-ID: <20241001002027.1272889-4-namhyung@kernel.org> X-Mailer: git-send-email 2.46.1.824.gd892dcdcdd-goog In-Reply-To: <20241001002027.1272889-1-namhyung@kernel.org> References: <20241001002027.1272889-1-namhyung@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Since it doesn't set the exclude_guest, no need to special handle the bit and simply show only if one of host or guest bit is set. Now the default event name might not have :H prefix anymore so change the dlfilter test not to compare the ":" at the end. Signed-off-by: Namhyung Kim Acked-by: Kan Liang Reviewed-by: Ian Rogers Reviewed-by: James Clark Reviewed-by: Ravi Bangoria --- tools/perf/dlfilters/dlfilter-test-api-v0.c | 2 +- tools/perf/dlfilters/dlfilter-test-api-v2.c | 2 +- tools/perf/util/evsel.c | 5 +---- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/tools/perf/dlfilters/dlfilter-test-api-v0.c b/tools/perf/dlfil= ters/dlfilter-test-api-v0.c index 4083b1abeaabe605..4ca2d7b2ea6c8200 100644 --- a/tools/perf/dlfilters/dlfilter-test-api-v0.c +++ b/tools/perf/dlfilters/dlfilter-test-api-v0.c @@ -220,7 +220,7 @@ static int check_sample(struct filter_data *d, const st= ruct perf_dlfilter_sample CHECK_SAMPLE(raw_callchain_nr); CHECK(!sample->raw_callchain); =20 -#define EVENT_NAME "branches:" +#define EVENT_NAME "branches" CHECK(!strncmp(sample->event, EVENT_NAME, strlen(EVENT_NAME))); =20 return 0; diff --git a/tools/perf/dlfilters/dlfilter-test-api-v2.c b/tools/perf/dlfil= ters/dlfilter-test-api-v2.c index 32ff619e881caa50..00d73a16c4fdaece 100644 --- a/tools/perf/dlfilters/dlfilter-test-api-v2.c +++ b/tools/perf/dlfilters/dlfilter-test-api-v2.c @@ -235,7 +235,7 @@ static int check_sample(struct filter_data *d, const st= ruct perf_dlfilter_sample CHECK_SAMPLE(raw_callchain_nr); CHECK(!sample->raw_callchain); =20 -#define EVENT_NAME "branches:" +#define EVENT_NAME "branches" CHECK(!strncmp(sample->event, EVENT_NAME, strlen(EVENT_NAME))); =20 return 0; diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 0ddd77c139e89a2e..f202d28147d62a44 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -545,7 +545,6 @@ static int evsel__add_modifiers(struct evsel *evsel, ch= ar *bf, size_t size) { int colon =3D 0, r =3D 0; struct perf_event_attr *attr =3D &evsel->core.attr; - bool exclude_guest_default =3D false; =20 #define MOD_PRINT(context, mod) do { \ if (!attr->exclude_##context) { \ @@ -557,17 +556,15 @@ static int evsel__add_modifiers(struct evsel *evsel, = char *bf, size_t size) MOD_PRINT(kernel, 'k'); MOD_PRINT(user, 'u'); MOD_PRINT(hv, 'h'); - exclude_guest_default =3D true; } =20 if (attr->precise_ip) { if (!colon) colon =3D ++r; r +=3D scnprintf(bf + r, size - r, "%.*s", attr->precise_ip, "ppp"); - exclude_guest_default =3D true; } =20 - if (attr->exclude_host || attr->exclude_guest =3D=3D exclude_guest_defaul= t) { + if (attr->exclude_host || attr->exclude_guest) { MOD_PRINT(host, 'H'); MOD_PRINT(guest, 'G'); } --=20 2.46.1.824.gd892dcdcdd-goog From nobody Thu Nov 28 13:33:32 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 518A1FC1D; Tue, 1 Oct 2024 00:20:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727742032; cv=none; b=N9SLROhzziRbuB7i8smA+ybuqTuIXybME+SPYDxiKyaM+NGPCwSyYm1YMVBQwDc6vcCrp/SflSDvu5mfcA6n56knh+cjQTyReCrm68s4bYbYGBOPNxYWyvcTyjl14T2PRMU20XI4Fl3MWhJsDmbbSJ9WhXeAQRid9hKTWwePbnY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727742032; c=relaxed/simple; bh=ut9u55jdhq5M67Do2dHpjwUdaOd2nUKmdtBRzlq7nKk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sSa8OHMkooM+KVY7smTy6UQ0p73sw9tUcrwEAZlcrdStQDRtaMZfoaaE/A14/Mt0cEUgAjAeFeHdoiKqzXFx2DmcMKoWVoIHh5nG1/H7Xt78BI6FEfBrylcVwwgR7wmskcHVmhFUuDoAEoCpcrTaERm4h4zq4gxcJ5WnOCDL2bs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GjUA11B+; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="GjUA11B+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 94716C4CED1; Tue, 1 Oct 2024 00:20:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727742032; bh=ut9u55jdhq5M67Do2dHpjwUdaOd2nUKmdtBRzlq7nKk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GjUA11B+ZHcrgaFojJXwrf8e6fCcawUKiEj4POlRip6PD4jOeJkr7rrl1k/0vu7EQ mmGS6U0nnVZgslxW25zV35fWOZZCf5ycILaFi1gP3wKkTssMz+YAZ/6fG2hZPDB931 I4JbYFIFOIpV/x++FVpoYdJfW5kteRCrqVjuSeoTAqWq1uk+FTI99ve/2VTtfjcq6f xJIsoeXYDNlwfdE9apR1QXjr0LlSiYLKo0gd8ouW6HwuSw5pKuBAg28dp6iYdIGTBL 83PulCpfu/H+/H1vaQmxkn1/pZo+7rCO2qEHs0zdvain/AWkpjCECHrqMbmxJj9Ban 05YpCElaAam5w== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers , Kan Liang Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Ravi Bangoria , Mark Rutland , James Clark , Kajol Jain , Thomas Richter , Atish Patra , Palmer Dabbelt , Mingwei Zhang Subject: [PATCH 4/8] perf tools: Do not set exclude_guest for precise_ip Date: Mon, 30 Sep 2024 17:20:23 -0700 Message-ID: <20241001002027.1272889-5-namhyung@kernel.org> X-Mailer: git-send-email 2.46.1.824.gd892dcdcdd-goog In-Reply-To: <20241001002027.1272889-1-namhyung@kernel.org> References: <20241001002027.1272889-1-namhyung@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" It seems perf sets the exclude_guest bit because of Intel PEBS implementation which uses a virtual address. IIUC now kernel disables PEBS when it goes to the guest mode regardless of this bit so we don't need to set it explicitly. At least for the other archs/vendors. I found the commit 1342798cc13e set the exclude_guest for precise_ip in the tool and the commit 20b279ddb38c added kernel side enforcement which was reverted by commit a706d965dcfd later. Actually it doesn't set the exclude_guest for the default event (cycles:P) already. $ grep -m1 vendor /proc/cpuinfo vendor_id : GenuineIntel $ perf record -e cycles:P true [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.002 MB perf.data (9 samples) ] $ perf evlist -v | tr ',' '\n' | grep -e exclude -e precise precise_ip: 3 But having lower 'p' modifier set the bit for some reason. $ perf record -e cycles:pp true [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.002 MB perf.data (9 samples) ] $ perf evlist -v | tr ',' '\n' | grep -e exclude -e precise precise_ip: 2 exclude_guest: 1 Actually AMD IBS suffers from this because it doesn't support excludes and having this bit effectively disables new features in the current implementation (due to the missing feature check). $ grep -m1 vendor /proc/cpuinfo vendor_id : AuthenticAMD $ perf record -W -e cycles:p -vv true 2>&1 | grep switching switching off PERF_FORMAT_LOST support switching off weight struct support switching off bpf_event switching off ksymbol switching off cloexec flag switching off mmap2 switching off exclude_guest, exclude_host By not setting exclude_guest, we can fix this inconsistency and the troubles. Signed-off-by: Namhyung Kim Acked-by: Kan Liang Reviewed-by: Ian Rogers Reviewed-by: James Clark Reviewed-by: Ravi Bangoria --- tools/perf/tests/parse-events.c | 12 ++++-------- tools/perf/util/parse-events.c | 4 ---- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-event= s.c index 727683f249f66f5a..82a19674a38f774e 100644 --- a/tools/perf/tests/parse-events.c +++ b/tools/perf/tests/parse-events.c @@ -898,8 +898,7 @@ static int test__group1(struct evlist *evlist) TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user); TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel); TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv); - /* use of precise requires exclude_guest */ - TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest); + TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest); TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host); TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip =3D=3D 2= ); TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader)); @@ -1016,9 +1015,8 @@ static int test__group3(struct evlist *evlist __maybe= _unused) TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel); TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv); - /* use of precise requires exclude_guest */ TEST_ASSERT_VAL("wrong exclude guest", - evsel->core.attr.exclude_guest); + !evsel->core.attr.exclude_guest); TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host); TEST_ASSERT_VAL("wrong precise_ip", @@ -1103,8 +1101,7 @@ static int test__group4(struct evlist *evlist __maybe= _unused) TEST_ASSERT_VAL("wrong exclude_user", !evsel->core.attr.exclude_user); TEST_ASSERT_VAL("wrong exclude_kernel", evsel->core.attr.exclude_kernel); TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv); - /* use of precise requires exclude_guest */ - TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest); + TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest); TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host); TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip =3D=3D 1= ); TEST_ASSERT_VAL("wrong group name", !evsel->group_name); @@ -1122,8 +1119,7 @@ static int test__group4(struct evlist *evlist __maybe= _unused) TEST_ASSERT_VAL("wrong exclude_user", evsel->core.attr.exclude_user); TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->core.attr.exclude_kernel= ); TEST_ASSERT_VAL("wrong exclude_hv", evsel->core.attr.exclude_hv); - /* use of precise requires exclude_guest */ - TEST_ASSERT_VAL("wrong exclude guest", evsel->core.attr.exclude_guest); + TEST_ASSERT_VAL("wrong exclude guest", !evsel->core.attr.exclude_guest); TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host); TEST_ASSERT_VAL("wrong precise_ip", evsel->core.attr.precise_ip =3D=3D 2= ); TEST_ASSERT_VAL("wrong leader", evsel__has_leader(evsel, leader)); diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index ff67213d6e887169..63da105ba914ef29 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -1769,10 +1769,6 @@ static int parse_events__modifier_list(struct parse_= events_state *parse_state, int exclude =3D eu | ek | eh; int exclude_GH =3D group ? evsel->exclude_GH : 0; =20 - if (mod.precise) { - /* use of precise requires exclude_guest */ - eG =3D 1; - } if (mod.user) { if (!exclude) exclude =3D eu =3D ek =3D eh =3D 1; --=20 2.46.1.824.gd892dcdcdd-goog From nobody Thu Nov 28 13:33:32 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5614D26AFB; Tue, 1 Oct 2024 00:20:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727742033; cv=none; b=BE1H0fIUeMaoyn7n5IryUw4Tt/CxgiR4h0pOZ54il3Jc6sYQAdBfRgJqK/JBmtst9hBGdZLD2M4aPHG8DY4ichvz0aDZyMZDlcqSSFo/yGOszQl5REo2MeJeSftxXKjVOG/PWLUTemTpjw6jWthNzERvfPETJUZb86VFVNEK5io= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727742033; c=relaxed/simple; bh=2ptCQpVMnHWaOaDmDBPPCdoy5ML1jYi83Mp2dZ9qdJ8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cxVBVU+VY1FUCvOCELZtX/sP2l52t5AwwihkstxVDKH3RiZ8d5bAV7+TT1KZkvSey/q2snY6S8BQQMM4SamB4bXBIEzkQqrW6r2t/n97wQumpbX4/QaIRj7sJGKNmipKcRSJSbxAmPgAnJbMZj0OXUyV9TW3aBnOqUh1DHwOod8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=uzy7jiRM; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="uzy7jiRM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4EBFAC4CECD; Tue, 1 Oct 2024 00:20:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727742032; bh=2ptCQpVMnHWaOaDmDBPPCdoy5ML1jYi83Mp2dZ9qdJ8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uzy7jiRMx0AlBdm3+NYAIQKTb9ypbgxGe+tz4q9m6f4tnIY2M2F+BnOwPBQ3ViifG WlC0f70tkXj8Ifnx0Tr44mgiUSF5CjHiM4qSn6jW+KInM89vUgMMDb/jKGpiiPRTNj cGw1J2ajYHe4iwdTWeIp4BgfNTZ0u3zUAKy12figJJynnf7BHSweo1H1DH1lkVMmga yAk0vRK9+76rPXJP27isX36ht7hDvc7X2ddviurq5dSEqOtHvXK+dwBQbDp4HGTYJv Owx5emK8Pf5ylITWARiDcPyJUcNMOyc2xMFBK89pJl/gUPVSd146ZG2NViYHFNaO3p vPCy1JeRByRVQ== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers , Kan Liang Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Ravi Bangoria , Mark Rutland , James Clark , Kajol Jain , Thomas Richter , Atish Patra , Palmer Dabbelt , Mingwei Zhang Subject: [PATCH 5/8] perf tools: Detect missing kernel features properly Date: Mon, 30 Sep 2024 17:20:24 -0700 Message-ID: <20241001002027.1272889-6-namhyung@kernel.org> X-Mailer: git-send-email 2.46.1.824.gd892dcdcdd-goog In-Reply-To: <20241001002027.1272889-1-namhyung@kernel.org> References: <20241001002027.1272889-1-namhyung@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The evsel__detect_missing_features() is to check if the attributes of the evsel is supported or not. But it checks the attribute based on the given evsel, it might miss something if the attr doesn't have the bit or give incorrect results if the event is special. Also it maintains the order of the feature that was added to the kernel which means it can assume older features should be supported once it detects the current feature is working. To minimized the confusion and to accurately check the kernel features, I think it's better to use a software event and go through all the features at once. Also make the function static since it's only used in evsel.c. Signed-off-by: Namhyung Kim Acked-by: Kan Liang Reviewed-by: James Clark Reviewed-by: Ravi Bangoria --- tools/perf/util/evsel.c | 345 +++++++++++++++++++++++++++++----------- tools/perf/util/evsel.h | 1 - 2 files changed, 249 insertions(+), 97 deletions(-) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index f202d28147d62a44..32e30c293d0c6198 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -2150,120 +2151,272 @@ int evsel__prepare_open(struct evsel *evsel, stru= ct perf_cpu_map *cpus, return err; } =20 -bool evsel__detect_missing_features(struct evsel *evsel) +static bool has_attr_feature(struct perf_event_attr *attr, unsigned long f= lags) { + int fd =3D syscall(SYS_perf_event_open, attr, /*pid=3D*/0, /*cpu=3D*/-1, + /*group_fd=3D*/-1, flags); + close(fd); + + if (fd < 0) { + attr->exclude_kernel =3D 1; + + fd =3D syscall(SYS_perf_event_open, attr, /*pid=3D*/0, /*cpu=3D*/-1, + /*group_fd=3D*/-1, flags); + close(fd); + } + + if (fd < 0) { + attr->exclude_hv =3D 1; + + fd =3D syscall(SYS_perf_event_open, attr, /*pid=3D*/0, /*cpu=3D*/-1, + /*group_fd=3D*/-1, flags); + close(fd); + } + + if (fd < 0) { + attr->exclude_guest =3D 1; + + fd =3D syscall(SYS_perf_event_open, attr, /*pid=3D*/0, /*cpu=3D*/-1, + /*group_fd=3D*/-1, flags); + close(fd); + } + + attr->exclude_kernel =3D 0; + attr->exclude_guest =3D 0; + attr->exclude_hv =3D 0; + + return fd >=3D 0; +} + +static void evsel__detect_missing_brstack_features(struct evsel *evsel) +{ + static bool detection_done =3D false; + struct perf_event_attr attr =3D { + .type =3D evsel->core.attr.type, + .config =3D evsel->core.attr.config, + .disabled =3D 1, + .sample_type =3D PERF_SAMPLE_BRANCH_STACK, + .sample_period =3D 1000, + }; + int old_errno; + + if (detection_done) + return; + + old_errno =3D errno; + /* * Must probe features in the order they were added to the - * perf_event_attr interface. + * perf_event_attr interface. These are PMU specific limitation + * so we can detect with the given hardware event and stop on the + * first one succeeded. */ - if (!perf_missing_features.branch_counters && - (evsel->core.attr.branch_sample_type & PERF_SAMPLE_BRANCH_COUNTERS)) { - perf_missing_features.branch_counters =3D true; - pr_debug2("switching off branch counters support\n"); - return true; - } else if (!perf_missing_features.read_lost && - (evsel->core.attr.read_format & PERF_FORMAT_LOST)) { - perf_missing_features.read_lost =3D true; - pr_debug2("switching off PERF_FORMAT_LOST support\n"); + + /* Please add new feature detection here. */ + + attr.branch_sample_type =3D PERF_SAMPLE_BRANCH_COUNTERS; + if (has_attr_feature(&attr, /*flags=3D*/0)) + goto found; + perf_missing_features.branch_counters =3D true; + pr_debug2("switching off branch counters support\n"); + + attr.branch_sample_type =3D PERF_SAMPLE_BRANCH_HW_INDEX; + if (has_attr_feature(&attr, /*flags=3D*/0)) + goto found; + perf_missing_features.branch_hw_idx =3D true; + pr_debug2("switching off branch HW index support\n"); + + attr.branch_sample_type =3D PERF_SAMPLE_BRANCH_NO_CYCLES | PERF_SAMPLE_BR= ANCH_NO_FLAGS; + if (has_attr_feature(&attr, /*flags=3D*/0)) + goto found; + perf_missing_features.lbr_flags =3D true; + pr_debug2_peo("switching off branch sample type no (cycles/flags)\n"); + +found: + detection_done =3D true; + errno =3D old_errno; +} + +static bool evsel__detect_missing_features(struct evsel *evsel) +{ + static bool detection_done =3D false; + struct perf_event_attr attr =3D { + .type =3D PERF_TYPE_SOFTWARE, + .config =3D PERF_COUNT_SW_TASK_CLOCK, + .disabled =3D 1, + }; + int old_errno; + + if (evsel__has_br_stack(evsel)) + evsel__detect_missing_brstack_features(evsel); + + if (detection_done) + goto check; + + old_errno =3D errno; + + /* + * Must probe features in the order they were added to the + * perf_event_attr interface. These are kernel core limitation + * not PMU-specific so we can detect with a software event and + * stop on the first one succeeded. + */ + + /* Please add new feature detection here. */ + + attr.read_format =3D PERF_FORMAT_LOST; + if (has_attr_feature(&attr, /*flags=3D*/0)) + goto found; + perf_missing_features.read_lost =3D true; + pr_debug2("switching off PERF_FORMAT_LOST support\n"); + attr.read_format =3D 0; + + attr.sample_type =3D PERF_SAMPLE_WEIGHT_STRUCT; + if (has_attr_feature(&attr, /*flags=3D*/0)) + goto found; + perf_missing_features.weight_struct =3D true; + pr_debug2("switching off weight struct support\n"); + attr.sample_type =3D 0; + + attr.sample_type =3D PERF_SAMPLE_CODE_PAGE_SIZE; + if (has_attr_feature(&attr, /*flags=3D*/0)) + goto found; + perf_missing_features.code_page_size =3D true; + pr_debug2_peo("Kernel has no PERF_SAMPLE_CODE_PAGE_SIZE support\n"); + attr.sample_type =3D 0; + + attr.sample_type =3D PERF_SAMPLE_DATA_PAGE_SIZE; + if (has_attr_feature(&attr, /*flags=3D*/0)) + goto found; + perf_missing_features.data_page_size =3D true; + pr_debug2_peo("Kernel has no PERF_SAMPLE_DATA_PAGE_SIZE support\n"); + attr.sample_type =3D 0; + + attr.cgroup =3D 1; + if (has_attr_feature(&attr, /*flags=3D*/0)) + goto found; + perf_missing_features.cgroup =3D true; + pr_debug2_peo("Kernel has no cgroup sampling support\n"); + attr.cgroup =3D 0; + + attr.aux_output =3D 1; + if (has_attr_feature(&attr, /*flags=3D*/0)) + goto found; + perf_missing_features.aux_output =3D true; + pr_debug2_peo("Kernel has no attr.aux_output support\n"); + attr.aux_output =3D 0; + + attr.bpf_event =3D 1; + if (has_attr_feature(&attr, /*flags=3D*/0)) + goto found; + perf_missing_features.bpf =3D true; + pr_debug2_peo("switching off bpf_event\n"); + attr.bpf_event =3D 0; + + attr.ksymbol =3D 1; + if (has_attr_feature(&attr, /*flags=3D*/0)) + goto found; + perf_missing_features.ksymbol =3D true; + pr_debug2_peo("switching off ksymbol\n"); + attr.ksymbol =3D 0; + + attr.write_backward =3D 1; + if (has_attr_feature(&attr, /*flags=3D*/0)) + goto found; + perf_missing_features.write_backward =3D true; + pr_debug2_peo("switching off write_backward\n"); + attr.write_backward =3D 0; + + attr.use_clockid =3D 1; + attr.clockid =3D CLOCK_MONOTONIC; + if (has_attr_feature(&attr, /*flags=3D*/0)) + goto found; + perf_missing_features.clockid =3D true; + pr_debug2_peo("switching off clockid\n"); + attr.use_clockid =3D 0; + attr.clockid =3D 0; + + if (has_attr_feature(&attr, /*flags=3D*/PERF_FLAG_FD_CLOEXEC)) + goto found; + perf_missing_features.cloexec =3D true; + pr_debug2_peo("switching off cloexec flag\n"); + + attr.mmap2 =3D 1; + if (has_attr_feature(&attr, /*flags=3D*/0)) + goto found; + perf_missing_features.mmap2 =3D true; + pr_debug2_peo("switching off mmap2\n"); + attr.mmap2 =3D 0; + + /* set this unconditionally? */ + perf_missing_features.sample_id_all =3D true; + pr_debug2_peo("switching off sample_id_all\n"); + + attr.inherit =3D 1; + attr.read_format =3D PERF_FORMAT_GROUP; + if (has_attr_feature(&attr, /*flags=3D*/0)) + goto found; + perf_missing_features.group_read =3D true; + pr_debug2_peo("switching off group read\n"); + attr.inherit =3D 0; + attr.read_format =3D 0; + +found: + detection_done =3D true; + errno =3D old_errno; + +check: + if ((evsel->core.attr.branch_sample_type & PERF_SAMPLE_BRANCH_COUNTERS) && + perf_missing_features.branch_counters) return true; - } else if (!perf_missing_features.weight_struct && - (evsel->core.attr.sample_type & PERF_SAMPLE_WEIGHT_STRUCT)) { - perf_missing_features.weight_struct =3D true; - pr_debug2("switching off weight struct support\n"); + + if ((evsel->core.attr.read_format & PERF_FORMAT_LOST) && + perf_missing_features.read_lost) return true; - } else if (!perf_missing_features.code_page_size && - (evsel->core.attr.sample_type & PERF_SAMPLE_CODE_PAGE_SIZE)) { - perf_missing_features.code_page_size =3D true; - pr_debug2_peo("Kernel has no PERF_SAMPLE_CODE_PAGE_SIZE support, bailing= out\n"); - return false; - } else if (!perf_missing_features.data_page_size && - (evsel->core.attr.sample_type & PERF_SAMPLE_DATA_PAGE_SIZE)) { - perf_missing_features.data_page_size =3D true; - pr_debug2_peo("Kernel has no PERF_SAMPLE_DATA_PAGE_SIZE support, bailing= out\n"); - return false; - } else if (!perf_missing_features.cgroup && evsel->core.attr.cgroup) { - perf_missing_features.cgroup =3D true; - pr_debug2_peo("Kernel has no cgroup sampling support, bailing out\n"); - return false; - } else if (!perf_missing_features.branch_hw_idx && - (evsel->core.attr.branch_sample_type & PERF_SAMPLE_BRANCH_HW_INDEX)) { - perf_missing_features.branch_hw_idx =3D true; - pr_debug2("switching off branch HW index support\n"); + + if ((evsel->core.attr.sample_type & PERF_SAMPLE_WEIGHT_STRUCT) && + perf_missing_features.weight_struct) return true; - } else if (!perf_missing_features.aux_output && evsel->core.attr.aux_outp= ut) { - perf_missing_features.aux_output =3D true; - pr_debug2_peo("Kernel has no attr.aux_output support, bailing out\n"); - return false; - } else if (!perf_missing_features.bpf && evsel->core.attr.bpf_event) { - perf_missing_features.bpf =3D true; - pr_debug2_peo("switching off bpf_event\n"); + + if (evsel->core.attr.use_clockid && evsel->core.attr.clockid !=3D CLOCK_M= ONOTONIC && + !perf_missing_features.clockid) { + perf_missing_features.clockid_wrong =3D true; return true; - } else if (!perf_missing_features.ksymbol && evsel->core.attr.ksymbol) { - perf_missing_features.ksymbol =3D true; - pr_debug2_peo("switching off ksymbol\n"); + } + + if (evsel->core.attr.use_clockid && perf_missing_features.clockid) return true; - } else if (!perf_missing_features.write_backward && evsel->core.attr.writ= e_backward) { - perf_missing_features.write_backward =3D true; - pr_debug2_peo("switching off write_backward\n"); - return false; - } else if (!perf_missing_features.clockid_wrong && evsel->core.attr.use_c= lockid) { - perf_missing_features.clockid_wrong =3D true; - pr_debug2_peo("switching off clockid\n"); + + if ((evsel->open_flags & PERF_FLAG_FD_CLOEXEC) && + perf_missing_features.cloexec) return true; - } else if (!perf_missing_features.clockid && evsel->core.attr.use_clockid= ) { - perf_missing_features.clockid =3D true; - pr_debug2_peo("switching off use_clockid\n"); + + if (evsel->core.attr.mmap2 && perf_missing_features.mmap2) return true; - } else if (!perf_missing_features.cloexec && (evsel->open_flags & PERF_FL= AG_FD_CLOEXEC)) { - perf_missing_features.cloexec =3D true; - pr_debug2_peo("switching off cloexec flag\n"); + + if ((evsel->core.attr.branch_sample_type & (PERF_SAMPLE_BRANCH_NO_FLAGS | + PERF_SAMPLE_BRANCH_NO_CYCLES)) && + perf_missing_features.lbr_flags) return true; - } else if (!perf_missing_features.mmap2 && evsel->core.attr.mmap2) { - perf_missing_features.mmap2 =3D true; - pr_debug2_peo("switching off mmap2\n"); + + if (evsel->core.attr.inherit && (evsel->core.attr.read_format & PERF_FORM= AT_GROUP) && + perf_missing_features.group_read) return true; - } else if (evsel->core.attr.exclude_guest || evsel->core.attr.exclude_hos= t) { - if (evsel->pmu =3D=3D NULL) - evsel->pmu =3D evsel__find_pmu(evsel); - - if (evsel->pmu) - evsel->pmu->missing_features.exclude_guest =3D true; - else { - /* we cannot find PMU, disable attrs now */ - evsel->core.attr.exclude_host =3D false; - evsel->core.attr.exclude_guest =3D false; - } =20 - if (evsel->exclude_GH) { - pr_debug2_peo("PMU has no exclude_host/guest support, bailing out\n"); - return false; - } - if (!perf_missing_features.exclude_guest) { - perf_missing_features.exclude_guest =3D true; - pr_debug2_peo("switching off exclude_guest, exclude_host\n"); - } + if (evsel->core.attr.ksymbol && perf_missing_features.ksymbol) return true; - } else if (!perf_missing_features.sample_id_all) { - perf_missing_features.sample_id_all =3D true; - pr_debug2_peo("switching off sample_id_all\n"); + + if (evsel->core.attr.bpf_event && perf_missing_features.bpf) return true; - } else if (!perf_missing_features.lbr_flags && - (evsel->core.attr.branch_sample_type & - (PERF_SAMPLE_BRANCH_NO_CYCLES | - PERF_SAMPLE_BRANCH_NO_FLAGS))) { - perf_missing_features.lbr_flags =3D true; - pr_debug2_peo("switching off branch sample type no (cycles/flags)\n"); + + if ((evsel->core.attr.branch_sample_type & PERF_SAMPLE_BRANCH_HW_INDEX) && + perf_missing_features.branch_hw_idx) return true; - } else if (!perf_missing_features.group_read && - evsel->core.attr.inherit && - (evsel->core.attr.read_format & PERF_FORMAT_GROUP) && - evsel__is_group_leader(evsel)) { - perf_missing_features.group_read =3D true; - pr_debug2_peo("switching off group read\n"); + + if (evsel->core.attr.sample_id_all && perf_missing_features.sample_id_all) return true; - } else { - return false; - } + + return false; } =20 static int evsel__open_cpu(struct evsel *evsel, struct perf_cpu_map *cpus, diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index 3e751ea769ac4d3a..ea3140cd91c589fd 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -368,7 +368,6 @@ int evsel__open(struct evsel *evsel, struct perf_cpu_ma= p *cpus, void evsel__close(struct evsel *evsel); int evsel__prepare_open(struct evsel *evsel, struct perf_cpu_map *cpus, struct perf_thread_map *threads); -bool evsel__detect_missing_features(struct evsel *evsel); =20 bool evsel__precise_ip_fallback(struct evsel *evsel); =20 --=20 2.46.1.824.gd892dcdcdd-goog From nobody Thu Nov 28 13:33:32 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EBC382A1D6; Tue, 1 Oct 2024 00:20:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727742034; cv=none; b=AboorJAYq7L3Y/jqIeTXdOo5ENkblfIB/Iyamui45l8eqzCdTHunwc7JbhK9REeRgEG4FSfPXnOULU7qnQkpUjStjn5irdw9L9+4hn/hxpxLGpVkdOd++sAk53XKKiOaMAQ71wwFZM7bnuQOv7zOx6kzakRu3cy/oz3H0zovh1g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727742034; c=relaxed/simple; bh=vJUrEzL1ey5YRE3Aw1gnAesBPqg7rTPF+ARvCNGukDs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iYF6PmSX3qaR3Go8wbnIV4MN6RPCWKKcdTKDb54RcPWuQnPROnuqaelTWkP35ReephPBMidLzzGmdfwxPT1+daMNpYkVwbpsO1+mkmKOr3Nxjie3WbsqPgmNqjJFo1Ndw6H1qvBrNSDaq2GHSbExJlAkICRyP3TI7dhN8az+Tns= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=beYqo76C; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="beYqo76C" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 12DBFC4CEC7; Tue, 1 Oct 2024 00:20:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727742033; bh=vJUrEzL1ey5YRE3Aw1gnAesBPqg7rTPF+ARvCNGukDs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=beYqo76CxCMJhGzTCyQUP3Q/HKA9X0W5DpJjjThmXYAsG/h56a4DF6I89+tINOREm +Uece5kaVbTyQGuraAlOP/aR84xZEt/qeGGyWFYAlTuQjbr+Arvt3SiNhtT4Y1zgmO MQuM+rhYRLFsD7pDNHi6lnShlTHt98/ephLi9h3fVWL05KmtBqEk/6lInfVkVgDH33 giiJblyM5dbeRb2HT/lu+3r9lWWjuSqgyyBZdKZvSbA0SSFo/e2IHtbV22mcUYtueT +lc9etUnyAqLlioUwhZM5a6ml9t8+62VgoUhIzOtPVFp4STBs/990wSvOq1DFhsQR1 UoRI7UqfSod3w== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers , Kan Liang Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Ravi Bangoria , Mark Rutland , James Clark , Kajol Jain , Thomas Richter , Atish Patra , Palmer Dabbelt , Mingwei Zhang Subject: [PATCH 6/8] perf tools: Move x86__is_amd_cpu() to util/env.c Date: Mon, 30 Sep 2024 17:20:25 -0700 Message-ID: <20241001002027.1272889-7-namhyung@kernel.org> X-Mailer: git-send-email 2.46.1.824.gd892dcdcdd-goog In-Reply-To: <20241001002027.1272889-1-namhyung@kernel.org> References: <20241001002027.1272889-1-namhyung@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" It can be called from non-x86 platform so let's move it to the general util directory. Also add a new helper perf_env__is_x86_amd_cpu() so that it can be called with an existing perf_env as well. Signed-off-by: Namhyung Kim Acked-by: Kan Liang Reviewed-by: James Clark Reviewed-by: Ravi Bangoria --- tools/perf/arch/x86/util/Build | 1 - tools/perf/arch/x86/util/env.c | 19 ------------------- tools/perf/arch/x86/util/env.h | 7 ------- tools/perf/arch/x86/util/pmu.c | 2 +- tools/perf/util/env.c | 24 ++++++++++++++++++++++++ tools/perf/util/env.h | 4 ++++ 6 files changed, 29 insertions(+), 28 deletions(-) delete mode 100644 tools/perf/arch/x86/util/env.c delete mode 100644 tools/perf/arch/x86/util/env.h diff --git a/tools/perf/arch/x86/util/Build b/tools/perf/arch/x86/util/Build index 2607ed5c42966543..ce6d802a1381c5ab 100644 --- a/tools/perf/arch/x86/util/Build +++ b/tools/perf/arch/x86/util/Build @@ -10,7 +10,6 @@ perf-util-y +=3D evlist.o perf-util-y +=3D mem-events.o perf-util-y +=3D evsel.o perf-util-y +=3D iostat.o -perf-util-y +=3D env.o =20 perf-util-$(CONFIG_DWARF) +=3D dwarf-regs.o perf-util-$(CONFIG_BPF_PROLOGUE) +=3D dwarf-regs.o diff --git a/tools/perf/arch/x86/util/env.c b/tools/perf/arch/x86/util/env.c deleted file mode 100644 index 3e537ffb1353aab2..0000000000000000 --- a/tools/perf/arch/x86/util/env.c +++ /dev/null @@ -1,19 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -#include "linux/string.h" -#include "util/env.h" -#include "env.h" - -bool x86__is_amd_cpu(void) -{ - struct perf_env env =3D { .total_mem =3D 0, }; - static int is_amd; /* 0: Uninitialized, 1: Yes, -1: No */ - - if (is_amd) - goto ret; - - perf_env__cpuid(&env); - is_amd =3D env.cpuid && strstarts(env.cpuid, "AuthenticAMD") ? 1 : -1; - perf_env__exit(&env); -ret: - return is_amd >=3D 1 ? true : false; -} diff --git a/tools/perf/arch/x86/util/env.h b/tools/perf/arch/x86/util/env.h deleted file mode 100644 index d78f080b6b3f889a..0000000000000000 --- a/tools/perf/arch/x86/util/env.h +++ /dev/null @@ -1,7 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef _X86_ENV_H -#define _X86_ENV_H - -bool x86__is_amd_cpu(void); - -#endif /* _X86_ENV_H */ diff --git a/tools/perf/arch/x86/util/pmu.c b/tools/perf/arch/x86/util/pmu.c index c3d89d6ba1bf03ad..e0060dac2a9f9242 100644 --- a/tools/perf/arch/x86/util/pmu.c +++ b/tools/perf/arch/x86/util/pmu.c @@ -16,7 +16,7 @@ #include "../../../util/fncache.h" #include "../../../util/pmus.h" #include "mem-events.h" -#include "env.h" +#include "util/env.h" =20 void perf_pmu__arch_init(struct perf_pmu *pmu __maybe_unused) { diff --git a/tools/perf/util/env.c b/tools/perf/util/env.c index 1edbccfc3281d2b1..470a0156e0722e4e 100644 --- a/tools/perf/util/env.c +++ b/tools/perf/util/env.c @@ -5,6 +5,7 @@ #include "util/header.h" #include "linux/compiler.h" #include +#include #include #include "cgroup.h" #include @@ -625,6 +626,7 @@ char *perf_env__find_pmu_cap(struct perf_env *env, cons= t char *pmu_name, return NULL; } =20 + void perf_env__find_br_cntr_info(struct perf_env *env, unsigned int *nr, unsigned int *width) @@ -639,3 +641,25 @@ void perf_env__find_br_cntr_info(struct perf_env *env, env->pmu_caps->br_cntr_width; } } + +bool perf_env__is_x86_amd_cpu(struct perf_env *env) +{ + static int is_amd; /* 0: Uninitialized, 1: Yes, -1: No */ + + if (is_amd =3D=3D 0) + is_amd =3D env->cpuid && strstarts(env->cpuid, "AuthenticAMD") ? 1 : -1; + + return is_amd >=3D 1 ? true : false; +} + +bool x86__is_amd_cpu(void) +{ + struct perf_env env =3D { .total_mem =3D 0, }; + bool is_amd; + + perf_env__cpuid(&env); + is_amd =3D perf_env__is_x86_amd_cpu(&env); + perf_env__exit(&env); + + return is_amd; +} diff --git a/tools/perf/util/env.h b/tools/perf/util/env.h index 51b36c36019be666..ae604c4edbb7eb44 100644 --- a/tools/perf/util/env.h +++ b/tools/perf/util/env.h @@ -195,4 +195,8 @@ bool perf_env__has_pmu_mapping(struct perf_env *env, co= nst char *pmu_name); void perf_env__find_br_cntr_info(struct perf_env *env, unsigned int *nr, unsigned int *width); + +bool x86__is_amd_cpu(void); +bool perf_env__is_x86_amd_cpu(struct perf_env *env); + #endif /* __PERF_ENV_H */ --=20 2.46.1.824.gd892dcdcdd-goog From nobody Thu Nov 28 13:33:32 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 826A32BB1C; Tue, 1 Oct 2024 00:20:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727742034; cv=none; b=n4u8pwtH1RH7mNkOxnkLek0Cjm7eNfAkiz4r7+iRLNTQOunes8tjsIEpxpjJmc3BP+qRTb541ZaiQSxjtapI7jIosERGP4C9aegOn55BNEHAIkZGUfTzyhMwGh/ZNEmetahQqKRC61S6HeREgbI8/t6oCanAqojqaTZfBYocikg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727742034; c=relaxed/simple; bh=bnuIx94/I4mNE95yKMxIO/90FkFYQ2/++qPAUf+SEMw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OhSPVZbYWFWrWbehekkWbGxqVVN6+E6DoiiUDrKnezO8vGZlYNdTkZn7HahQrZNcQ4ztVAIpq1e6n9A6RoxtoZwhzJGK/jxFV4zZztG0ZF2rs724UMDYQPPTAqHJgqcxatk58s1+YM1E1impl6XiVMItWLDFDbnjySEHYws2+PQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qCS3RON5; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="qCS3RON5" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C6C33C4CED0; Tue, 1 Oct 2024 00:20:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727742034; bh=bnuIx94/I4mNE95yKMxIO/90FkFYQ2/++qPAUf+SEMw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qCS3RON5sLSnuiyF+gyBB9lajpoH4ZYtrHQa8AQwoPEqAdT7i38ChHYwtqBAzKWKz zdONLnPgx+qrbY/A5qJGqiEYO7lybEiH/HFfSV3DMfHBO6dk+vev86RAm9wzJ1sQR3 8GMJLBJO8XymBzU99RdJZp5ljOnDevRYp38fuInAy2l/OxOYvwogcoPShY93dJPYAG HYMNq2qKxHhtiQM7TxpBY931hfkFBHVsmW5eux1FnHhqVLGcQ0fuvwlRtLy96ZlwoJ 0K1KqQs21hY4LYVk9YzMm8rjnP2izSPAYkeQPP7ptsNv+MyeQgAju1G1KbbPLnKdXM Gxy3CqmaILURg== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers , Kan Liang Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Ravi Bangoria , Mark Rutland , James Clark , Kajol Jain , Thomas Richter , Atish Patra , Palmer Dabbelt , Mingwei Zhang Subject: [PATCH 7/8] perf tools: Check fallback error and order Date: Mon, 30 Sep 2024 17:20:26 -0700 Message-ID: <20241001002027.1272889-8-namhyung@kernel.org> X-Mailer: git-send-email 2.46.1.824.gd892dcdcdd-goog In-Reply-To: <20241001002027.1272889-1-namhyung@kernel.org> References: <20241001002027.1272889-1-namhyung@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The perf_event_open might fail due to various reasons, so blindly reducing precise_ip level might not be the best way to deal with it. It seems the kernel return -EOPNOTSUPP when PMU doesn't support the given precise level. Let's try again with the correct error code. This caused a problem on AMD, as it stops on precise_ip of 2 for IBS but user events with exclude_kernel=3D1 cannot make progress. Let's add the evsel__handle_error_quirks() to this case specially. I plan to work on the kernel side to improve this situation but it'd still need some special handling for IBS. Signed-off-by: Namhyung Kim Acked-by: Kan Liang Reviewed-by: James Clark Reviewed-by: Ravi Bangoria --- tools/perf/util/evsel.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 32e30c293d0c6198..ef8356260eea54cd 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -2419,6 +2419,20 @@ static bool evsel__detect_missing_features(struct ev= sel *evsel) return false; } =20 +static bool evsel__handle_error_quirks(struct evsel *evsel, int error) +{ + /* AMD IBS doesn't support exclude_kernel, forward it to core PMU */ + if (error =3D=3D -EINVAL && evsel->precise_max && evsel->core.attr.precis= e_ip && + evsel->core.attr.exclude_kernel && x86__is_amd_cpu()) { + evsel->core.attr.precise_ip =3D 0; + pr_debug2_peo("removing precise_ip on AMD\n"); + display_attr(&evsel->core.attr); + return true; + } + + return false; +} + static int evsel__open_cpu(struct evsel *evsel, struct perf_cpu_map *cpus, struct perf_thread_map *threads, int start_cpu_map_idx, int end_cpu_map_idx) @@ -2580,9 +2594,6 @@ static int evsel__open_cpu(struct evsel *evsel, struc= t perf_cpu_map *cpus, return 0; =20 try_fallback: - if (evsel__precise_ip_fallback(evsel)) - goto retry_open; - if (evsel__ignore_missing_thread(evsel, perf_cpu_map__nr(cpus), idx, threads, thread, err)) { /* We just removed 1 thread, so lower the upper nthreads limit. */ @@ -2599,11 +2610,15 @@ static int evsel__open_cpu(struct evsel *evsel, str= uct perf_cpu_map *cpus, if (err =3D=3D -EMFILE && rlimit__increase_nofile(&set_rlimit)) goto retry_open; =20 - if (err !=3D -EINVAL || idx > 0 || thread > 0) - goto out_close; + if (err =3D=3D -EOPNOTSUPP && evsel__precise_ip_fallback(evsel)) + goto retry_open; =20 - if (evsel__detect_missing_features(evsel)) + if (err =3D=3D -EINVAL && evsel__detect_missing_features(evsel)) goto fallback_missing_features; + + if (evsel__handle_error_quirks(evsel, err)) + goto retry_open; + out_close: if (err) threads->err_thread =3D thread; --=20 2.46.1.824.gd892dcdcdd-goog From nobody Thu Nov 28 13:33:32 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5307044374; Tue, 1 Oct 2024 00:20:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727742036; cv=none; b=l3ZouqBwAc53IUzjKb1RgpFe00RAeKbsSTjBMOpY6Mj55UIXVZxH44ZR+ONlFY3/8RGBLJ6+XC9dTkcWQ45AZYyX5hXTGOja2ODNFa30Yr5QBbpUNO8fYnDMT4YrkXpDnoaMA3NBtqS5D1HFX45ZNYXfGP9usvW5dyB1QKUc8BY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727742036; c=relaxed/simple; bh=7aieh78om/yhYCq16DdxzBsiyA5Y6XfHwyZ+r8siS3A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fKn0nba5pTJFZsHDR1sy8aoIz/QhnPi+o3DSMBbyINzNin3HIZgfabtUDiMhMxJXSzQTv3sa772awqDlKypD4+NKiAqOF25gYDCfkE4p87TuZEQzrfLfKcLBuVfGtpvMHyK69v+UMQpjsIivHOsEdapoFf+sIqYHjCVlig9SEHI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=h4ASG11v; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="h4ASG11v" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8A001C4AF0D; Tue, 1 Oct 2024 00:20:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727742035; bh=7aieh78om/yhYCq16DdxzBsiyA5Y6XfHwyZ+r8siS3A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=h4ASG11vHtUugMFKHmoZPmRXX/4xL+wgrP/D0u/ky/8O1QhDtd9GCOW6qo6Exp1IM jn81qmPho3LdqxET20EVBVITHedVOTakiwm31T/lUbyCppIh7q1OGgltm4lC7w7UZm c5vC4nZWR/daUuBctL9Ul/6Av0qL5t50u2A8TLjGgW987l+X3M45lgFydfyqJ/C45L kiHcZ8oyUpJ9meQIxSNa1d89u6brvoSiZQ+iXvBGZAVVFF9o67TvNDJiw9gPjpQB8f V34D3/xcirZJhb9Ntptp3qT5YHnfwgsiiF0MoOEV0ZnQ6Hdpom8VsbQ4HJK9sD7FUF xY6W9y7GIPgxQ== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers , Kan Liang Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Ravi Bangoria , Mark Rutland , James Clark , Kajol Jain , Thomas Richter , Atish Patra , Palmer Dabbelt , Mingwei Zhang Subject: [PATCH 8/8] perf record: Just use "cycles:P" as the default event Date: Mon, 30 Sep 2024 17:20:27 -0700 Message-ID: <20241001002027.1272889-9-namhyung@kernel.org> X-Mailer: git-send-email 2.46.1.824.gd892dcdcdd-goog In-Reply-To: <20241001002027.1272889-1-namhyung@kernel.org> References: <20241001002027.1272889-1-namhyung@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The fallback logic can add ":u" modifier if needed. Signed-off-by: Namhyung Kim Acked-by: Kan Liang Reviewed-by: Ian Rogers Reviewed-by: James Clark Reviewed-by: Ravi Bangoria --- tools/perf/builtin-record.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index adbaf80b398c1f4c..f8325247292112d7 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -4157,9 +4157,7 @@ int cmd_record(int argc, const char **argv) record.opts.tail_synthesize =3D true; =20 if (rec->evlist->core.nr_entries =3D=3D 0) { - bool can_profile_kernel =3D perf_event_paranoid_check(1); - - err =3D parse_event(rec->evlist, can_profile_kernel ? "cycles:P" : "cycl= es:Pu"); + err =3D parse_event(rec->evlist, "cycles:P"); if (err) goto out; } --=20 2.46.1.824.gd892dcdcdd-goog