From nobody Thu Dec 18 18:04:40 2025 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C53C31EFFB6 for ; Wed, 12 Mar 2025 21:16:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741814193; cv=none; b=LAJnWMjHrtYhBST5Q5fTF8EF01/eE7m7hEtKyv2iIorZN0Y4xTnK0URDz3dVBsjxWHv71KI22ZjXWC3Pb/x3BxfvFaz+duPjDHcOEj3YvAbXtlxrOJRpolF+v3NJT3p8uVRuiOxp8tYhStSF54EWV7B+BCCVfEvEgnxcWKF+hGI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741814193; c=relaxed/simple; bh=PdPgmcBYIWEeNLSGXkHHbQNrOkp0XMuWoBrNvNBx1oE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=kIdgZ8sIRZ7b2NSeNTwnRw5RU6EzTGU+YE30X+MAYtjh2krgWDVRznGwJSVPjalAytfpVZ9kCB2n2ycio8DpHhMtBcZJoeKzZDsay1OJnhhaQ1JVsePVJgi7VX9E6YdJATF0l7YWZ/CGXRCgJM0bmgWkPNolGvZh8G1EZtocEb0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=byw/udgO; arc=none smtp.client-ip=209.85.214.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="byw/udgO" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-2217a4bfcc7so4255815ad.3 for ; Wed, 12 Mar 2025 14:16:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1741814190; x=1742418990; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=Mtw5A6pnErP63NBf+2oMOxljRBPUk1W+HOiO6no4Q+Y=; b=byw/udgOa9rMmdP+amxslFO5uYU3WTM+07joqht8MaUQskONiGw+f1BaKU3N2hi3lo atny66NCZw5pUHtR75lKuKnj0BmJyxwKmMObMYeUkBtiMNfF2+9Z41p/0WbNrNuQAdO9 1iVVv8aksjQlbvMayDp1QnDkcUMiAnKpwLBtK7cz8Hq6V6UrOpTdsE4j57jmTOzYCuTY EQP187qDg7mQg1m+0NDlRGVD3u8VaZhfCEDRqLZmO6GlP25YdWhdVOkKPOgVWGT208d5 1iYpEpsPqC2jufc4vxtA8jaWkOkh2sLpv2pGz+ky4jdxX01F6jUm6Aj+oP0+802QevKu 2rww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741814190; x=1742418990; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Mtw5A6pnErP63NBf+2oMOxljRBPUk1W+HOiO6no4Q+Y=; b=BdHilcQyS8fguojFZP1DhOC5+5NjThhEqe3lQt/4CYSu2N3MEJIrcTol5/pCauQC+i VXZrJMMkniYJycq02Olat+wPjySRQFpo5iuOq2I5We5hX1NZaUCjeshVGLWY8afBsxCr l2ShDLp/JFDteF/I7mNN0Ib8oTaPoyuP41Uv3GBl9IyNICuuYQNlFfKwFmpkZLB47poF B1p9T0U6Jvq3S7eOrczwFTShIo1uSWSpJj+bbodFlNfbdFRL69OaNgqxrMi9LIhQQwXx pc7CIf1q7LyHLZQkIZBmFZGUriXCIELz8YI70tCraxVMvxXQCYhj8ATV4KiYNDp7AoCS J8nw== X-Forwarded-Encrypted: i=1; AJvYcCUest+s1urVwk8lY2dPI9F4mR6JZtbKIgjIS1gvGwt31qkvCE/5S8325tnzpSTVe7PRLmMO8sysmhNR3Rs=@vger.kernel.org X-Gm-Message-State: AOJu0YyDJ5hbFJLYqDejlYzICJHLaNB5emv/YsT08jKBg83POsqHkCEk VmkvDtxnhDD5hFzTiNcBnJQ2vMFkelNF2sJPoTZXGzIiQfRGnMHbrZaqjEfdRCAdIcf5RDTBOFD z7Bktvw== X-Google-Smtp-Source: AGHT+IE3fBCKu7LH5dWy4Mhc2DNcNCtpsN2q683UIyw1GVM1fMDJFk9jQ0EhTpT9uiJfq/9n5G9W16mHQqdN X-Received: from plty2.prod.google.com ([2002:a17:902:8642:b0:220:c8cf:970c]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:da90:b0:223:5ada:891e with SMTP id d9443c01a7336-22592e201e3mr110847595ad.7.1741814190032; Wed, 12 Mar 2025 14:16:30 -0700 (PDT) Date: Wed, 12 Mar 2025 14:16:22 -0700 In-Reply-To: <20250312211623.2495798-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250312211623.2495798-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.rc0.332.g42c0ae87b1-goog Message-ID: <20250312211623.2495798-2-irogers@google.com> Subject: [PATCH v2 1/2] perf parse-events: Make legacy events always have priority over sysfs/json From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , Paul Walmsley , Palmer Dabbelt , Albert Ou , James Clark , Dominique Martinet , Yang Jihong , Yang Li , Weilin Wang , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, Leo Yan Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This reverts the behavior of commit a24d9d9dc096 ("perf parse-events: Make legacy events lower priority than sysfs/JSON"). That commit states: As part of that report Mark Rutland requested that legacy events not be higher in priority when a PMU is specified reversing what has until this change been perf's default behavior. with an Acked-by: Mark Rutland tag. Mark expresses this preference here: https://lore.kernel.org/lkml/ZVzXjz_0nYbmSGPQ@FVFF77S0Q05N.cambridge.arm.co= m/ On an Alderlake this commit caused `cpu_core/instructions/` to be encoded as: ------------------------------------------------------------ perf_event_attr: type 4 (cpu_core) size 136 config 0xc0 (instructions) sample_type IDENTIFIER read_format TOTAL_TIME_ENABLED|TOTAL_TIME_RUNNING disabled 1 inherit 1 enable_on_exec 1 exclude_guest 1 ------------------------------------------------------------ While `instructions` would be encoded as: ------------------------------------------------------------ perf_event_attr: type 0 (PERF_TYPE_HARDWARE) size 136 config 0x400000001 sample_type IDENTIFIER read_format TOTAL_TIME_ENABLED|TOTAL_TIME_RUNNING disabled 1 inherit 1 enable_on_exec 1 exclude_guest 1 ------------------------------------------------------------ As the event parsing for legacy events uses parse_events_add_numeric, rather than the more generic PMU handling case, we end up with the same event name being encoded two ways. However, as instructions is also a cpu_atom event on Alderlake, or any hybrid system, the PMU prefixes are added in the stat output meaning instructions is reported as cpu_core/instructions/ and cpu_atom/instructions/ even though those events are encoded differently and potentially have different behaviors. We shouldn't be having the same event with two different encodings and I followed up the commit with changing the prioritization of legacy events also when no PMU is specified in commit 617824a7f0f7 ("perf parse-events: Prefer sysfs/JSON hardware events over legacy"). RISC-V have been asking that legacy events also be a lower priority than sysfs/json to avoid driver complexity. They've since had to work around this issue meaning it isn't a necessity: If the overriding legacy with JSON is available, each future vendor may just provide the json file instead of modifying the driver. However, it will be a matter of convenience and clutter free future rather than a necessity at this point. https://lists.riscv.org/g/sig-perf-analysis/topic/110906276#msg458 Landing the commit making encoding consistent and having sysfs/json a priority has been pushed back against by Namhyung Kim, Arnaldo Carvalho de Melo and James Clark. James assert the ARM drivers are now fixed and don't need the prioritization. RISC-V's interests have been ignored. The fact that legacy events are antiquated, imprecise in meaning, brittle, misleading and don't give us a way to fix kernel issues in software, have also been ignored: https://lore.kernel.org/lkml/Z8sMcta0zTWeOso4@x1/ Given the push back against sysfs/json being a priority, contrary to Mark Rutland's insistence this was the sensible way to do things, contrary to RISC-V's wishes, and contrary to my own preference that legacy events do become legacy, this patch changes the priority back to legacy events being the priority consistently - that is instructions and cpu_core/instructions/ are both encoded using legacy events. It isn't a straight revert as clean-ups/refactorings are kept in place. Signed-off-by: Ian Rogers --- tools/perf/tests/parse-events.c | 13 +++---------- tools/perf/util/parse-events.c | 26 +++++++++----------------- 2 files changed, 12 insertions(+), 27 deletions(-) diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-event= s.c index 5ec2e5607987..78e8ae825bf8 100644 --- a/tools/perf/tests/parse-events.c +++ b/tools/perf/tests/parse-events.c @@ -162,16 +162,9 @@ static int test__checkevent_numeric(struct evlist *evl= ist) =20 static int assert_hw(struct perf_evsel *evsel, enum perf_hw_id id, const c= har *name) { - struct perf_pmu *pmu; - - if (evsel->attr.type =3D=3D PERF_TYPE_HARDWARE) { - TEST_ASSERT_VAL("wrong config", test_perf_config(evsel, id)); - return 0; - } - pmu =3D perf_pmus__find_by_type(evsel->attr.type); - - TEST_ASSERT_VAL("unexpected PMU type", pmu); - TEST_ASSERT_VAL("PMU missing event", perf_pmu__have_event(pmu, name)); + TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE =3D=3D evsel->attr.type); + TEST_ASSERT_VAL("wrong config", test_perf_config(evsel, id)); + TEST_ASSERT_VAL("wrong name", !strcmp(evsel__hw_names[id], name)); return 0; } =20 diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 35e48fe56dfa..04bb70ba4292 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -1023,12 +1023,10 @@ static int config_term_pmu(struct perf_event_attr *= attr, return -EINVAL; } /* - * Rewrite the PMU event to a legacy cache one unless the PMU - * doesn't support legacy cache events or the event is present - * within the PMU. + * Rewrite the PMU event to a legacy cache one as legacy events + * take priority over sysfs/json. */ - if (perf_pmu__supports_legacy_cache(pmu) && - !perf_pmu__have_event(pmu, term->config)) { + if (perf_pmu__supports_legacy_cache(pmu)) { attr->type =3D PERF_TYPE_HW_CACHE; return parse_events__decode_legacy_cache(term->config, pmu->type, &attr->config); @@ -1049,19 +1047,13 @@ static int config_term_pmu(struct perf_event_attr *= attr, return -EINVAL; } /* - * If the PMU has a sysfs or json event prefer it over - * legacy. ARM requires this. + * Rewrite the PMU event to a legacy cache one as legacy events + * take priority over sysfs/json. */ - if (perf_pmu__have_event(pmu, term->config)) { - term->type_term =3D PARSE_EVENTS__TERM_TYPE_USER; - term->no_value =3D true; - term->alternate_hw_config =3D true; - } else { - attr->type =3D PERF_TYPE_HARDWARE; - attr->config =3D term->val.num; - if (perf_pmus__supports_extended_type()) - attr->config |=3D (__u64)pmu->type << PERF_PMU_TYPE_SHIFT; - } + attr->type =3D PERF_TYPE_HARDWARE; + attr->config =3D term->val.num; + if (perf_pmus__supports_extended_type()) + attr->config |=3D (__u64)pmu->type << PERF_PMU_TYPE_SHIFT; return 0; } if (term->type_term =3D=3D PARSE_EVENTS__TERM_TYPE_USER || --=20 2.49.0.rc0.332.g42c0ae87b1-goog From nobody Thu Dec 18 18:04:40 2025 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C938E1F03DE for ; Wed, 12 Mar 2025 21:16:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741814194; cv=none; b=hwBBFaA5QQzf44Cm8BI1IkVPJGrZzuCuqeXxs8y7MRC/hMxdhVS0Ee/XoR5riYdC1ImyJRClqxrtbQBrt0hCgxq9jT1vHnk9vwug5xSRnLveYTR7o1pIv3sM/kSUGfNmXNrqfZH7g7k5M4OVC5DIjTqtStAzO8u2b239Fw/mOHE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741814194; c=relaxed/simple; bh=XNnA41P2FkLgfB7dOkr7R5DdUKHwSszGuLTs53or31s=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=hUdJCvnCqCeFoqgEIUmb3dk2E6bUqeOtfouImRE+dT8WKeQ3UivaekbODXd8GLHD076Ppt11Z4ECPTHVPLhxdAgDv6Np/2HiPwv/13yw2XPA2Gz6WWzSuZLghbxbeteCCTaHZ6iYnORyVCq9lpN2qDY9Q2btj7I1BfzumGXBLPs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=LD8eSAYQ; arc=none smtp.client-ip=209.85.214.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="LD8eSAYQ" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-2217a4bfcc7so4256145ad.3 for ; Wed, 12 Mar 2025 14:16:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1741814192; x=1742418992; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=Lj4yu52t3shvn/Ldpu0xRqMM7tXahE2Q6XdhAGVh+Cw=; b=LD8eSAYQYhAofxwVf3jdTFKI9uuxsk5DpdmKaFleeAEDI2AG11KYnXCLrwKtMrJ6e4 I5fnkCW0fqySVmp8+uYN/7cQloMecA5pXRbQe/iCbp0ib3Elu0DBmAOiRgg/65QvcM06 Qcmu+npV1HThvvJ/v0deMXxnig1bAZQoy4uNLGEcHNF4hlRY8dskqsUa56K6OuOPSIc0 EGnofLqnJ6222Ym0yKinLDhNymJ+N9aFCcsDqNeTzd9xdWRxvdNmFpd0MuZo7cKEgYZb p15TBpE8dv9pk7emyyR+shmE+w3/5fk9vpG+m6cuQ5fqJ5j8zq9k6DloTpBmU7byaWDN H8Tg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741814192; x=1742418992; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Lj4yu52t3shvn/Ldpu0xRqMM7tXahE2Q6XdhAGVh+Cw=; b=avb7T+DuhlUwcTB5csJPSwU36B2pnpLPt8ffiyvf/Ti6q2X+tZfhI4ydOqCYL2Tied zt5eAv9RSkjpGjiSLRJQA8o8vTvr5qas3eA/9jq8YRC/QJx9vwkCXTpqT3uDnP+BIkXR 05BKWhhF+5WdarjkszmP/pSw3LPln6DNrVHigwUJyd5Omm4y8WkDVs0Wv3RNoV8wKN0B nAP947NxEa0VgP+nVtFbhtNNwTCppB1g0CiJX7y3p8pwaEPDSK2T0kYNvbiOdrS7HiH0 e3nRcwP7h247UJTcy5nwsdgSHrvPkNGPXZnmAmH6x+P6h1nHu6AFeOZCd69JcFEqNo5e jP8w== X-Forwarded-Encrypted: i=1; AJvYcCWo676KIYOLo9xLN1mNngLU/k/5CRemOixYgZa6CvtE9mk9zo7m5mxy0alXqu45SDGz5G7z2uauWN0DCzE=@vger.kernel.org X-Gm-Message-State: AOJu0YzVYuAh14ZTH5KTiu5yEzJg2X4IA6xEPWI1XGyKMA2TD2WNHMWU yemxhE+MTCAJD9CS0HHQQvTioPQ/zxvpJxoVCuohuAyDmFXt2V/ZhVWxD/NLOfq0PHtt0dEl4B+ gHIAGvA== X-Google-Smtp-Source: AGHT+IGWjyPRq+gE/vBuek0eRRjGWfl/YQuMJFtLtMQfTEsQZSRX084w/tdOE04eklGuX9qVaRMKlyO29FQf X-Received: from pjbpb8.prod.google.com ([2002:a17:90b:3c08:b0:2fa:15aa:4d1e]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:2283:b0:223:62f5:fd44 with SMTP id d9443c01a7336-22593183e06mr136761175ad.40.1741814192023; Wed, 12 Mar 2025 14:16:32 -0700 (PDT) Date: Wed, 12 Mar 2025 14:16:23 -0700 In-Reply-To: <20250312211623.2495798-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250312211623.2495798-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.rc0.332.g42c0ae87b1-goog Message-ID: <20250312211623.2495798-3-irogers@google.com> Subject: [PATCH v2 2/2] Revert "perf evsel: Add alternate_hw_config and use in evsel__match" From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , Paul Walmsley , Palmer Dabbelt , Albert Ou , James Clark , Dominique Martinet , Yang Jihong , Yang Li , Weilin Wang , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, Leo Yan Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This reverts commit 22a4db3c36034e2b034c5b88414680857fc59cf4. Now legacy events are prioritized there is no need to worry about a sysfs/json event being used when trying to pattern match a legacy event. Signed-off-by: Ian Rogers --- tools/perf/builtin-diff.c | 6 ++-- tools/perf/util/evsel.c | 21 ------------- tools/perf/util/evsel.h | 19 ++++++++++-- tools/perf/util/parse-events.c | 55 +++++++++++++--------------------- tools/perf/util/parse-events.h | 8 +---- tools/perf/util/parse-events.y | 2 +- tools/perf/util/pmu.c | 6 +--- tools/perf/util/pmu.h | 2 +- tools/perf/util/stat-display.c | 6 ---- 9 files changed, 45 insertions(+), 80 deletions(-) diff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c index ae490d58af92..b49c1dc1fd96 100644 --- a/tools/perf/builtin-diff.c +++ b/tools/perf/builtin-diff.c @@ -470,13 +470,13 @@ static int diff__process_sample_event(const struct pe= rf_tool *tool, =20 static struct perf_diff pdiff; =20 -static struct evsel *evsel_match(struct evsel *evsel, struct evlist *evlis= t) +static struct evsel *evsel_match(struct evsel *evsel, + struct evlist *evlist) { struct evsel *e; =20 evlist__for_each_entry(evlist, e) { - if ((evsel->core.attr.type =3D=3D e->core.attr.type) && - (evsel->core.attr.config =3D=3D e->core.attr.config)) + if (evsel__match2(evsel, e)) return e; } =20 diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 4a0ef095db92..5566232f9bb9 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -404,7 +404,6 @@ void evsel__init(struct evsel *evsel, evsel->collect_stat =3D false; evsel->group_pmu_name =3D NULL; evsel->skippable =3D false; - evsel->alternate_hw_config =3D PERF_COUNT_HW_MAX; evsel->script_output_type =3D -1; // FIXME: OUTPUT_TYPE_UNSET, see builti= n-script.c } =20 @@ -551,8 +550,6 @@ struct evsel *evsel__clone(struct evsel *dest, struct e= vsel *orig) if (evsel__copy_config_terms(evsel, orig) < 0) goto out_err; =20 - evsel->alternate_hw_config =3D orig->alternate_hw_config; - return evsel; =20 out_err: @@ -1848,24 +1845,6 @@ static int evsel__read_group(struct evsel *leader, i= nt cpu_map_idx, int thread) return evsel__process_group_data(leader, cpu_map_idx, thread, data); } =20 -bool __evsel__match(const struct evsel *evsel, u32 type, u64 config) -{ - - u32 e_type =3D evsel->core.attr.type; - u64 e_config =3D evsel->core.attr.config; - - if (e_type !=3D type) { - return type =3D=3D PERF_TYPE_HARDWARE && evsel->pmu && evsel->pmu->is_co= re && - evsel->alternate_hw_config =3D=3D config; - } - - if ((type =3D=3D PERF_TYPE_HARDWARE || type =3D=3D PERF_TYPE_HW_CACHE) && - perf_pmus__supports_extended_type()) - e_config &=3D PERF_HW_EVENT_MASK; - - return e_config =3D=3D config; -} - int evsel__read_counter(struct evsel *evsel, int cpu_map_idx, int thread) { if (evsel__is_tool(evsel)) diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index aae431d63d64..c199481d3338 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -87,7 +87,6 @@ struct evsel { int bpf_fd; struct bpf_object *bpf_obj; struct list_head config_terms; - u64 alternate_hw_config; }; =20 /* @@ -370,10 +369,26 @@ u64 format_field__intval(struct tep_format_field *fie= ld, struct perf_sample *sam struct tep_format_field *evsel__field(struct evsel *evsel, const char *nam= e); struct tep_format_field *evsel__common_field(struct evsel *evsel, const ch= ar *name); =20 -bool __evsel__match(const struct evsel *evsel, u32 type, u64 config); +static inline bool __evsel__match(const struct evsel *evsel, u32 type, u64= config) +{ + if (evsel->core.attr.type !=3D type) + return false; + + if ((type =3D=3D PERF_TYPE_HARDWARE || type =3D=3D PERF_TYPE_HW_CACHE) && + perf_pmus__supports_extended_type()) + return (evsel->core.attr.config & PERF_HW_EVENT_MASK) =3D=3D config; + + return evsel->core.attr.config =3D=3D config; +} =20 #define evsel__match(evsel, t, c) __evsel__match(evsel, PERF_TYPE_##t, PER= F_COUNT_##c) =20 +static inline bool evsel__match2(struct evsel *e1, struct evsel *e2) +{ + return (e1->core.attr.type =3D=3D e2->core.attr.type) && + (e1->core.attr.config =3D=3D e2->core.attr.config); +} + int evsel__read_counter(struct evsel *evsel, int cpu_map_idx, int thread); =20 int __evsel__read_on_cpu(struct evsel *evsel, int cpu_map_idx, int thread,= bool scale); diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 04bb70ba4292..a71492829c58 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -229,7 +229,7 @@ __add_event(struct list_head *list, int *idx, bool init_attr, const char *name, const char *metric_id, struct perf_pmu *pmu, struct list_head *config_terms, bool auto_merge_stats, - struct perf_cpu_map *cpu_list, u64 alternate_hw_config) + struct perf_cpu_map *cpu_list) { struct evsel *evsel; struct perf_cpu_map *cpus =3D perf_cpu_map__is_empty(cpu_list) && pmu ? p= mu->cpus : cpu_list; @@ -264,7 +264,6 @@ __add_event(struct list_head *list, int *idx, evsel->core.is_pmu_core =3D pmu ? pmu->is_core : false; evsel->auto_merge_stats =3D auto_merge_stats; evsel->pmu =3D pmu; - evsel->alternate_hw_config =3D alternate_hw_config; =20 if (name) evsel->name =3D strdup(name); @@ -287,19 +286,16 @@ struct evsel *parse_events__add_event(int idx, struct= perf_event_attr *attr, { return __add_event(/*list=3D*/NULL, &idx, attr, /*init_attr=3D*/false, na= me, metric_id, pmu, /*config_terms=3D*/NULL, - /*auto_merge_stats=3D*/false, /*cpu_list=3D*/NULL, - /*alternate_hw_config=3D*/PERF_COUNT_HW_MAX); + /*auto_merge_stats=3D*/false, /*cpu_list=3D*/NULL); } =20 static int add_event(struct list_head *list, int *idx, struct perf_event_attr *attr, const char *name, - const char *metric_id, struct list_head *config_terms, - u64 alternate_hw_config) + const char *metric_id, struct list_head *config_terms) { return __add_event(list, idx, attr, /*init_attr*/true, name, metric_id, /*pmu=3D*/NULL, config_terms, - /*auto_merge_stats=3D*/false, /*cpu_list=3D*/NULL, - alternate_hw_config) ? 0 : -ENOMEM; + /*auto_merge_stats=3D*/false, /*cpu_list=3D*/NULL) ? 0 : -ENOMEM; } =20 /** @@ -423,7 +419,7 @@ bool parse_events__filter_pmu(const struct parse_events= _state *parse_state, static int parse_events_add_pmu(struct parse_events_state *parse_state, struct list_head *list, struct perf_pmu *pmu, const struct parse_events_terms *const_parsed_terms, - bool auto_merge_stats, u64 alternate_hw_config); + bool auto_merge_stats); =20 int parse_events_add_cache(struct list_head *list, int *idx, const char *n= ame, struct parse_events_state *parse_state, @@ -449,8 +445,7 @@ int parse_events_add_cache(struct list_head *list, int = *idx, const char *name, */ ret =3D parse_events_add_pmu(parse_state, list, pmu, parsed_terms, - perf_pmu__auto_merge_stats(pmu), - /*alternate_hw_config=3D*/PERF_COUNT_HW_MAX); + perf_pmu__auto_merge_stats(pmu)); if (ret) return ret; continue; @@ -481,8 +476,7 @@ int parse_events_add_cache(struct list_head *list, int = *idx, const char *name, =20 if (__add_event(list, idx, &attr, /*init_attr*/true, config_name ?: name, metric_id, pmu, &config_terms, /*auto_merge_stats=3D*/false, - /*cpu_list=3D*/NULL, - /*alternate_hw_config=3D*/PERF_COUNT_HW_MAX) =3D=3D NULL) + /*cpu_list=3D*/NULL) =3D=3D NULL) return -ENOMEM; =20 free_config_terms(&config_terms); @@ -750,7 +744,7 @@ int parse_events_add_breakpoint(struct parse_events_sta= te *parse_state, name =3D get_config_name(head_config); =20 return add_event(list, &parse_state->idx, &attr, name, /*mertic_id=3D*/NU= LL, - &config_terms, /*alternate_hw_config=3D*/PERF_COUNT_HW_MAX); + &config_terms); } =20 static int check_type_val(struct parse_events_term *term, @@ -1354,9 +1348,8 @@ static int __parse_events_add_numeric(struct parse_ev= ents_state *parse_state, name =3D get_config_name(head_config); metric_id =3D get_config_metric_id(head_config); ret =3D __add_event(list, &parse_state->idx, &attr, /*init_attr*/true, na= me, - metric_id, pmu, &config_terms, /*auto_merge_stats=3D*/false, - /*cpu_list=3D*/NULL, /*alternate_hw_config=3D*/PERF_COUNT_HW_MAX - ) =3D=3D NULL ? -ENOMEM : 0; + metric_id, pmu, &config_terms, /*auto_merge_stats=3D*/false, + /*cpu_list=3D*/NULL) ? 0 : -ENOMEM; free_config_terms(&config_terms); return ret; } @@ -1407,7 +1400,7 @@ static bool config_term_percore(struct list_head *con= fig_terms) static int parse_events_add_pmu(struct parse_events_state *parse_state, struct list_head *list, struct perf_pmu *pmu, const struct parse_events_terms *const_parsed_terms, - bool auto_merge_stats, u64 alternate_hw_config) + bool auto_merge_stats) { struct perf_event_attr attr; struct perf_pmu_info info; @@ -1444,7 +1437,7 @@ static int parse_events_add_pmu(struct parse_events_s= tate *parse_state, /*init_attr=3D*/true, /*name=3D*/NULL, /*metric_id=3D*/NULL, pmu, /*config_terms=3D*/NULL, auto_merge_stats, - /*cpu_list=3D*/NULL, alternate_hw_config); + /*cpu_list=3D*/NULL); return evsel ? 0 : -ENOMEM; } =20 @@ -1465,8 +1458,7 @@ static int parse_events_add_pmu(struct parse_events_s= tate *parse_state, =20 /* Look for event names in the terms and rewrite into format based terms.= */ if (perf_pmu__check_alias(pmu, &parsed_terms, - &info, &alias_rewrote_terms, - &alternate_hw_config, err)) { + &info, &alias_rewrote_terms, err)) { parse_events_terms__exit(&parsed_terms); return -EINVAL; } @@ -1513,8 +1505,7 @@ static int parse_events_add_pmu(struct parse_events_s= tate *parse_state, evsel =3D __add_event(list, &parse_state->idx, &attr, /*init_attr=3D*/tru= e, get_config_name(&parsed_terms), get_config_metric_id(&parsed_terms), pmu, - &config_terms, auto_merge_stats, /*cpu_list=3D*/NULL, - alternate_hw_config); + &config_terms, auto_merge_stats, /*cpu_list=3D*/NULL); if (!evsel) { parse_events_terms__exit(&parsed_terms); return -ENOMEM; @@ -1535,7 +1526,7 @@ static int parse_events_add_pmu(struct parse_events_s= tate *parse_state, } =20 int parse_events_multi_pmu_add(struct parse_events_state *parse_state, - const char *event_name, u64 hw_config, + const char *event_name, const struct parse_events_terms *const_parsed_terms, struct list_head **listp, void *loc_) { @@ -1588,7 +1579,7 @@ int parse_events_multi_pmu_add(struct parse_events_st= ate *parse_state, =20 auto_merge_stats =3D perf_pmu__auto_merge_stats(pmu); if (!parse_events_add_pmu(parse_state, list, pmu, - &parsed_terms, auto_merge_stats, hw_config)) { + &parsed_terms, auto_merge_stats)) { struct strbuf sb; =20 strbuf_init(&sb, /*hint=3D*/ 0); @@ -1601,7 +1592,7 @@ int parse_events_multi_pmu_add(struct parse_events_st= ate *parse_state, =20 if (parse_state->fake_pmu) { if (!parse_events_add_pmu(parse_state, list, perf_pmus__fake_pmu(), &par= sed_terms, - /*auto_merge_stats=3D*/true, hw_config)) { + /*auto_merge_stats=3D*/true)) { struct strbuf sb; =20 strbuf_init(&sb, /*hint=3D*/ 0); @@ -1642,15 +1633,13 @@ int parse_events_multi_pmu_add_or_add_pmu(struct pa= rse_events_state *parse_state /* Attempt to add to list assuming event_or_pmu is a PMU name. */ pmu =3D perf_pmus__find(event_or_pmu); if (pmu && !parse_events_add_pmu(parse_state, *listp, pmu, const_parsed_t= erms, - /*auto_merge_stats=3D*/false, - /*alternate_hw_config=3D*/PERF_COUNT_HW_MAX)) + /*auto_merge_stats=3D*/false)) return 0; =20 if (parse_state->fake_pmu) { if (!parse_events_add_pmu(parse_state, *listp, perf_pmus__fake_pmu(), const_parsed_terms, - /*auto_merge_stats=3D*/false, - /*alternate_hw_config=3D*/PERF_COUNT_HW_MAX)) + /*auto_merge_stats=3D*/false)) return 0; } =20 @@ -1663,8 +1652,7 @@ int parse_events_multi_pmu_add_or_add_pmu(struct pars= e_events_state *parse_state =20 if (!parse_events_add_pmu(parse_state, *listp, pmu, const_parsed_terms, - auto_merge_stats, - /*alternate_hw_config=3D*/PERF_COUNT_HW_MAX)) { + auto_merge_stats)) { ok++; parse_state->wild_card_pmus =3D true; } @@ -1675,8 +1663,7 @@ int parse_events_multi_pmu_add_or_add_pmu(struct pars= e_events_state *parse_state =20 /* Failure to add, assume event_or_pmu is an event name. */ zfree(listp); - if (!parse_events_multi_pmu_add(parse_state, event_or_pmu, PERF_COUNT_HW_= MAX, - const_parsed_terms, listp, loc)) + if (!parse_events_multi_pmu_add(parse_state, event_or_pmu, const_parsed_t= erms, listp, loc)) return 0; =20 if (asprintf(&help, "Unable to find PMU or event on a PMU of '%s'", event= _or_pmu) < 0) diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h index e176a34ab088..0edb8b14e522 100644 --- a/tools/perf/util/parse-events.h +++ b/tools/perf/util/parse-events.h @@ -128,12 +128,6 @@ struct parse_events_term { * value is assumed to be 1. An event name also has no value. */ bool no_value; - /** - * @alternate_hw_config: config is the event name but num is an - * alternate PERF_TYPE_HARDWARE config value which is often nice for the - * sake of quick matching. - */ - bool alternate_hw_config; }; =20 struct parse_events_error { @@ -244,7 +238,7 @@ struct evsel *parse_events__add_event(int idx, struct p= erf_event_attr *attr, struct perf_pmu *pmu); =20 int parse_events_multi_pmu_add(struct parse_events_state *parse_state, - const char *event_name, u64 hw_config, + const char *event_name, const struct parse_events_terms *const_parsed_terms, struct list_head **listp, void *loc); =20 diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y index f888cbb076d6..5c4669264177 100644 --- a/tools/perf/util/parse-events.y +++ b/tools/perf/util/parse-events.y @@ -290,7 +290,7 @@ PE_NAME sep_dc struct list_head *list; int err; =20 - err =3D parse_events_multi_pmu_add(_parse_state, $1, PERF_COUNT_HW_MAX, N= ULL, &list, &@1); + err =3D parse_events_multi_pmu_add(_parse_state, $1, NULL, &list, &@1); if (err < 0) { struct parse_events_state *parse_state =3D _parse_state; struct parse_events_error *error =3D parse_state->error; diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 57450c73fb63..7b32b9638d5f 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -1662,7 +1662,7 @@ static int check_info_data(struct perf_pmu *pmu, */ int perf_pmu__check_alias(struct perf_pmu *pmu, struct parse_events_terms = *head_terms, struct perf_pmu_info *info, bool *rewrote_terms, - u64 *alternate_hw_config, struct parse_events_error *err) + struct parse_events_error *err) { struct parse_events_term *term, *h; struct perf_pmu_alias *alias; @@ -1699,7 +1699,6 @@ int perf_pmu__check_alias(struct perf_pmu *pmu, struc= t parse_events_terms *head_ NULL); return ret; } - *rewrote_terms =3D true; ret =3D check_info_data(pmu, alias, info, err, term->err_term); if (ret) @@ -1708,9 +1707,6 @@ int perf_pmu__check_alias(struct perf_pmu *pmu, struc= t parse_events_terms *head_ if (alias->per_pkg) info->per_pkg =3D true; =20 - if (term->alternate_hw_config) - *alternate_hw_config =3D term->val.num; - list_del_init(&term->list); parse_events_term__delete(term); } diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index b93014cc3670..71b979a4a9dc 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -231,7 +231,7 @@ __u64 perf_pmu__format_bits(struct perf_pmu *pmu, const= char *name); int perf_pmu__format_type(struct perf_pmu *pmu, const char *name); int perf_pmu__check_alias(struct perf_pmu *pmu, struct parse_events_terms = *head_terms, struct perf_pmu_info *info, bool *rewrote_terms, - u64 *alternate_hw_config, struct parse_events_error *err); + struct parse_events_error *err); int perf_pmu__find_event(struct perf_pmu *pmu, const char *event, void *st= ate, pmu_event_callback cb); =20 void perf_pmu_format__set_value(void *format, int config, unsigned long *b= its); diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index e852ac0d9847..289639a974bf 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -1699,12 +1699,6 @@ static void evsel__set_needs_uniquify(struct evsel *= counter, const struct perf_s return; } =20 - if (counter->pmu && counter->pmu->is_core && - counter->alternate_hw_config !=3D PERF_COUNT_HW_MAX) { - /* A sysfs or json event replacing a legacy event, don't uniquify. */ - return; - } - if (config->aggr_mode =3D=3D AGGR_NONE) { /* Always unique with no aggregation. */ counter->needs_uniquify =3D true; --=20 2.49.0.rc0.332.g42c0ae87b1-goog