From patchwork Tue Jan 7 18:08:51 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13929478 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.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 690FE1E47DB for ; Tue, 7 Jan 2025 18:09:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736273362; cv=none; b=e7E3PcrAOgQxtszMblTW0vQ+xBvJly1HDYH6/xwClWMq+qTd71xV+iXWOvUR+b6RIGOuctVhpOR5XjXc3ZKMcv4aTbkdfw7uVX63nzqfEpIevv72anKkKBXPcw5uGL+ZUlOcYuJir6nfxR47/X2QDxPnnU1dQEX14ZQgPd3aUlc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736273362; c=relaxed/simple; bh=6NiM1Nv7imSN6NGO0Qbw1eHxJQIVxr9LL1Tkk8/m+6M=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Cc:Content-Type; b=irxZPalOkKsgY8KzMctzzbszSER4lQzl/wJP9ZiEKij8ntjLFDSJhMm6U6CL4nIGcLXnUOGKGGtO8N5RBbNMI8MdGDUnABqC7zMB87mw3uJ7LXs7+D/l8LJrsKuKS0ckXLlbk3UQWQa5olsf6glt8zBIEuVH2CYEwXdmVM9Zb6M= 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=GavsVu4j; arc=none smtp.client-ip=209.85.219.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="GavsVu4j" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e3886f4cee2so177036276.0 for ; Tue, 07 Jan 2025 10:09:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1736273357; x=1736878157; darn=vger.kernel.org; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=5Rj5RspISvp82xBYwd7/3r2uv97UQb04V4mK5h3NrO0=; b=GavsVu4jMMFBCHUdPByfPS2S446LUqKmfNuKDRxC21L1C++wQpqbv55tuDTqPdPn5D 2oO8xEd3ilSHNS8x5DJll6Awm1USFsB6l3QDAvsmCaZBH2+qZl9ntfUXA8962GnO118P cAISRxy9Z+L050lV4iidopJJblzqf7WJUtuQwEQRucl0qbSNsj4yybX0SGp7sLHvFCQy z2n3Urzi7R7m2jeZN8NB6WLi7zQ+4wfRFhUbPfMaKDqgqSRttor7tBJ8FPsM3DeePEFm 2brOh/dBy3zTbhsLvdGFR2zgESCaYFx0N6eSBNsP+tgyFDl1gvB0I/lnue+2Ob6i7b7B GNNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736273357; x=1736878157; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=5Rj5RspISvp82xBYwd7/3r2uv97UQb04V4mK5h3NrO0=; b=S9bRCbAacylDOYRXap6DUVoU0swmOVUWyZWTdIjkYQnaMDIWyH+a77OiM27pFB74jV lXi3sJyPOPjaXyFM/IHjPIsmf8z7RHZ+UOc3pX1tupNj2yqljQ7gpkmivSdfvA1fKh3n g80+/9eny17jFbjMr1+mqWFlC/a2WJX2pWlDuLpwycxxLBaGB9n8a0LjLIXSl8jarjsw H0RF4Qtx1Xab2M9kNfQsX98CJa5DKkq2ZWxvvhVCID0nofEmc3ChkhxAFS0yLLRcBD9h WGdYwcjuB0jeruL3WqdkpkYoRyiw6GK6tL/3vvm81krmiB+OluYCLTFMEtuu3vVsqrqE JyGA== X-Forwarded-Encrypted: i=1; AJvYcCWdyeQTZ8CCUpi5g67WA2F3fAdH+XVtRSZ9W3JU4kt0JkIwU35Lu33OTCxeNPzNSlbP1Is=@vger.kernel.org X-Gm-Message-State: AOJu0Yy9460E4wYlhgjEjpZW3+3FJx2vkg89kC7rhN3EWzvI/8RuIsJ9 l/ASU6f0+aCV6GtDy9/5vqKdDlc8TLOVuykBZva86ixBrtkLGXZCk3nbZ7YhrAYMkQcjmhrLz9x iS/tx1Q== X-Google-Smtp-Source: AGHT+IEUTlQHgQ22Xtq7YLQQdmJRZ10UdmCV7tQ4aZj56dVKX0kWKQfKm7P9GtfRzBx/qViI3tPz15I9WnuN X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:ede7:40c7:c970:8d77]) (user=irogers job=sendgmr) by 2002:a25:2943:0:b0:e38:8e02:1f01 with SMTP id 3f1490d57ef6-e54ed8d5fddmr166276.1.1736273357373; Tue, 07 Jan 2025 10:09:17 -0800 (PST) Date: Tue, 7 Jan 2025 10:08:51 -0800 In-Reply-To: <20250107180854.770470-1-irogers@google.com> Message-Id: <20250107180854.770470-2-irogers@google.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250107180854.770470-1-irogers@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Subject: [PATCH v4 1/4] perf evsel: Add pmu_name helper 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 , James Clark , Ze Gao , Weilin Wang , Dominique Martinet , Jean-Philippe Romain , Junhao He , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, Aditya Bodkhe Cc: Leo Yan , Atish Patra Add helper to get the name of the evsel's PMU. This handles the case where there's no sysfs PMU via parse_events event_type helper. Signed-off-by: Ian Rogers Tested-by: James Clark Tested-by: Leo Yan Tested-by: Atish Patra --- tools/perf/util/evsel.c | 10 ++++++++++ tools/perf/util/evsel.h | 1 + 2 files changed, 11 insertions(+) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 697428efa644..da1308462c4e 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -237,6 +237,16 @@ int evsel__object_config(size_t object_size, int (*init)(struct evsel *evsel), return 0; } +const char *evsel__pmu_name(const struct evsel *evsel) +{ + struct perf_pmu *pmu = evsel__find_pmu(evsel); + + if (pmu) + return pmu->name; + + return event_type(evsel->core.attr.type); +} + #define FD(e, x, y) (*(int *)xyarray__entry(e->core.fd, x, y)) int __evsel__sample_size(u64 sample_type) diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index 5e789fa80590..2dd108a14b89 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -236,6 +236,7 @@ int evsel__object_config(size_t object_size, void (*fini)(struct evsel *evsel)); struct perf_pmu *evsel__find_pmu(const struct evsel *evsel); +const char *evsel__pmu_name(const struct evsel *evsel); bool evsel__is_aux_event(const struct evsel *evsel); struct evsel *evsel__new_idx(struct perf_event_attr *attr, int idx); From patchwork Tue Jan 7 18:08:52 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13929480 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.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 B87FB1F2C3F for ; Tue, 7 Jan 2025 18:09:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736273365; cv=none; b=r+wb8S86d664VmQhVC/14vM7EtqFtjd14t2vpC0hrxIOQMsaJFCYwON+XR19hgJtQGqqVuWht+uEfY56gZpuOMw6fOfR/23kb2O0eLC/k9HVc+wKs1R8H+BJBCiYSOvJOGDhNbd772jQNO+dhZVYMSC/npL3e/l4j8qX5ocCpto= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736273365; c=relaxed/simple; bh=3/t2IbEPz4rN8sB6XlwyAEYEFBdFqxnzZyoasEkvKao=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Cc:Content-Type; b=IOdEDG8wdQLOu0++JT6+53jPD1xyRgGwVuWweUFC1qidpHKjOU9OzCdWZfVifU5odbNqhuOHtzPvOjPQukVmtN87vorCOr7bWvqtRNK6bavI41KnfbnU/c59yIzlzcKUhAA+a4o5PdffnCO6kAyiMEjbJAoghRHj4IlMiPK1Yl8= 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=BkklKNO2; arc=none smtp.client-ip=209.85.219.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="BkklKNO2" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e39fd56398cso35892516276.1 for ; Tue, 07 Jan 2025 10:09:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1736273359; x=1736878159; darn=vger.kernel.org; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=1gsJqu5S2FVCHZY/sqyRxwjspJ6Srprq184fTFcf/+o=; b=BkklKNO2+7imfXW7x75Na3+4o5Q+fkR+8vbyaKHtMy3v4glKowR3IX9zNchNngf9s3 0Fsz9Tvs9MzsOx6EENwJN8zxbmdg1axZ9ATjaWK/LMOkK/1iwu6e00HZXfFSRAxkuSLp HhYr+HVRaDJT8RYrOxZzAfLBdnoHriHe6OIXStwaN0/pwGsxj5+PO8Z8S93n7SmGHOuJ h4L8SJbaHn42aHMTNALiDC3zPvBnZl+/A2hiSu7Ml609A/1ghQtoKL1CDVZNxHMbDhDZ Bef7ncLJ8A+8wN3gXY9KJChfJ8OZIPcvvudFxQqqLHb66ZHIao2Ox9BaLi13WIcO3yco CNdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736273359; x=1736878159; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=1gsJqu5S2FVCHZY/sqyRxwjspJ6Srprq184fTFcf/+o=; b=pspvLX17Vewf7yXLIO+tI63dBhNUAh90+HrPDNJj9/ZXDlCiN+6FSvhIsNzRDe8Zsu E5l8tj9LeHOjB8QgpnjwPoDTzJac5PwTqPsTITL0W2++WlfxjWxNhPlm1LiWnvjVuR4q 93NzZy8Mu0uT75md/EZesb7/PHJXWdpBp3VP/pZvxUOHpRPxnATmugHLqRlC4e8dVJdN oN1gkNYkOsqFFySxJYbj/tAMMBmaWLjdqDPhdRlT/yAB51lU/BN7HehV4u60Cjl2nEuT Ke3G79w+0CG2SIt1gyYU/fahJz3/iUf3ja7taZLg7pvIC3ULTBPTiQL5ZmvVdefQTN4A Fx3w== X-Forwarded-Encrypted: i=1; AJvYcCViBPsLTwrAUWFzEzhBFhBSL7LAbbsPuKeC3EStPDKLBAy0ExTcTswZ4Uhx2I6AQXcPNCM=@vger.kernel.org X-Gm-Message-State: AOJu0YzRyRSoeMuh5ZeFthawdB8kPiU9yMkXaTplqd5DGeBHYSBRYrnq Lq+xswQyFkbogdl5/sbnr8P5kPS6j+hDjDKPEWNxeukXalc5H67VWZoySu8j9/A1i1ElIEnVgv+ N0acW5A== X-Google-Smtp-Source: AGHT+IEXuCh6QcRMzYXeb67JLDoqi6EvpTvf4F+FY3EUZs8ddIo2R7QzCJ0n0HLdN2toAHdcS4AmbdyhLcXw X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:ede7:40c7:c970:8d77]) (user=irogers job=sendgmr) by 2002:a05:690c:6605:b0:6ef:3402:f56b with SMTP id 00721157ae682-6f3f80df0c6mr2573127b3.1.1736273359442; Tue, 07 Jan 2025 10:09:19 -0800 (PST) Date: Tue, 7 Jan 2025 10:08:52 -0800 In-Reply-To: <20250107180854.770470-1-irogers@google.com> Message-Id: <20250107180854.770470-3-irogers@google.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250107180854.770470-1-irogers@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Subject: [PATCH v4 2/4] perf stat: Fix find_stat for mixed legacy/non-legacy events 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 , James Clark , Ze Gao , Weilin Wang , Dominique Martinet , Jean-Philippe Romain , Junhao He , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, Aditya Bodkhe Cc: Leo Yan , Atish Patra Legacy events typically don't have a PMU when added leading to mismatched legacy/non-legacy cases in find_stat. Use evsel__find_pmu to make sure the evsel PMU is looked up. Update the evsel__find_pmu code to look for the PMU using the extended config type or, for legacy hardware/hw_cache events on non-hybrid systems, just use the core PMU. Before: ``` $ perf stat -e cycles,cpu/instructions/ -a sleep 1 Performance counter stats for 'system wide': 215,309,764 cycles 44,326,491 cpu/instructions/ 1.002555314 seconds time elapsed ``` After: ``` $ perf stat -e cycles,cpu/instructions/ -a sleep 1 Performance counter stats for 'system wide': 990,676,332 cycles 1,235,762,487 cpu/instructions/ # 1.25 insn per cycle 1.002667198 seconds time elapsed ``` Fixes: 3612ca8e2935 ("perf stat: Fix the hard-coded metrics calculation on the hybrid") Signed-off-by: Ian Rogers Tested-by: James Clark Tested-by: Leo Yan Tested-by: Atish Patra --- tools/perf/util/pmus.c | 20 +++++++++++++++++--- tools/perf/util/stat-shadow.c | 3 ++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/tools/perf/util/pmus.c b/tools/perf/util/pmus.c index b493da0d22ef..60d81d69503e 100644 --- a/tools/perf/util/pmus.c +++ b/tools/perf/util/pmus.c @@ -710,11 +710,25 @@ char *perf_pmus__default_pmu_name(void) struct perf_pmu *evsel__find_pmu(const struct evsel *evsel) { struct perf_pmu *pmu = evsel->pmu; + bool legacy_core_type; - if (!pmu) { - pmu = perf_pmus__find_by_type(evsel->core.attr.type); - ((struct evsel *)evsel)->pmu = pmu; + if (pmu) + return pmu; + + pmu = perf_pmus__find_by_type(evsel->core.attr.type); + legacy_core_type = + evsel->core.attr.type == PERF_TYPE_HARDWARE || + evsel->core.attr.type == PERF_TYPE_HW_CACHE; + if (!pmu && legacy_core_type) { + if (perf_pmus__supports_extended_type()) { + u32 type = evsel->core.attr.config >> PERF_PMU_TYPE_SHIFT; + + pmu = perf_pmus__find_by_type(type); + } else { + pmu = perf_pmus__find_core_pmu(); + } } + ((struct evsel *)evsel)->pmu = pmu; return pmu; } diff --git a/tools/perf/util/stat-shadow.c b/tools/perf/util/stat-shadow.c index fa8b2a1048ff..d83bda5824d2 100644 --- a/tools/perf/util/stat-shadow.c +++ b/tools/perf/util/stat-shadow.c @@ -151,6 +151,7 @@ static double find_stat(const struct evsel *evsel, int aggr_idx, enum stat_type { struct evsel *cur; int evsel_ctx = evsel_context(evsel); + struct perf_pmu *evsel_pmu = evsel__find_pmu(evsel); evlist__for_each_entry(evsel->evlist, cur) { struct perf_stat_aggr *aggr; @@ -177,7 +178,7 @@ static double find_stat(const struct evsel *evsel, int aggr_idx, enum stat_type * Except the SW CLOCK events, * ignore if not the PMU we're looking for. */ - if ((type != STAT_NSECS) && (evsel->pmu != cur->pmu)) + if ((type != STAT_NSECS) && (evsel_pmu != evsel__find_pmu(cur))) continue; aggr = &cur->stats->aggr[aggr_idx]; From patchwork Tue Jan 7 18:08:53 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13929479 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.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 AD9281F427B for ; Tue, 7 Jan 2025 18:09:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736273364; cv=none; b=CPT4jOuNKj84YaOSLnntgQOaLTWxMk/RHddncfTAdsYeDPaCUdRp2b5fSpne/rN4B1t4BuIMCuThTmsy/5KUI45VXgklR4amDlkLBTRQI7JlUFwK5zIwU2yr/4anXM6y5LvygULL29Zq1iAmP//EScP8TOHyjHGZqH37xP37osw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736273364; c=relaxed/simple; bh=K9n/++xGPh3y4Nwa4NW0TywaOLbQoC5fwQ8AFIxOBeI=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Cc:Content-Type; b=J4fqgFXig0viffof4hKENTqq82KT1yyALLcs1LqbCiVmeRC4rU2ex5+lXOoXUOEd8CGYj+d92DAFTMs79dJqWZR9u9nWM4wl7buwDmx63EGp7y+p76qTtdbiUGS3PcvLMRU2ibFi97jQBsLNbkwY4tHrBouddIkyd5NTee38BLE= 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=nng0W8Mq; arc=none smtp.client-ip=209.85.219.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="nng0W8Mq" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e39993d8594so35940432276.3 for ; Tue, 07 Jan 2025 10:09:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1736273362; x=1736878162; darn=vger.kernel.org; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=NCK4tac4gxTH978HKFsny7hyfeEYdVg/GMG1pWRcbRE=; b=nng0W8Mqycqq6zOhmt6hvjotmegsZHR04CZ/pt2uVL7L6Y8zUbiuT5zEl3yPE4Cakc /PKz2NUuYbpME1cx9fpcHJIKlptRwL0SIy9O4j1/9BSHJda7Saa/AcmRqM8ByasSoUu2 xsuNBAu+pDOxJ9Buq+0BKFmfXrSyhg5J4r24s3th+VCAHdgnuyPUuXpR2N41bVnoIS0y 96Owzo+leFXRI/BA2CRT62dvWza1J6EIDHdE30KdlD+RVI8zi08qleVJoeiaBMIzEbBs tYtbbvMyWaHOsW89gGQZcV+7VNJYCHfnHg3rCDRMFIJaNweR3YEladsnnZaIDc73X2y/ wlSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736273362; x=1736878162; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=NCK4tac4gxTH978HKFsny7hyfeEYdVg/GMG1pWRcbRE=; b=sCfBCVzYlrOBiCzMgcMBPfkcTKcmNJpBdb93Md6UdCtJ33xVsrOi+S8veQjysczW+5 tKsGVsu32MvroGYyvHZVrzz1CMpk2bf4SvxfwSCvx8vd5WlSP1VyeFvqku5vJtIWVcqr Xt10k5fg9RryGM3lcVzQI86ncZLqa+OqCsWUTxXuVWm+2WFDVshIi0r6Nzq5z31nQ/K4 QVdnhtjWnS9BGgl9gYmCb9M+IuvFLxbS9CFo/X1km4D9BKxNw7ub7lpMudrPvt4pB7Wm s8WKjKJId8myvmLsB0HxJQmtkDt+yM4OIPm9Y8iugNMEi5WEKOkuZJn5uFHQVqzypmNe xewg== X-Forwarded-Encrypted: i=1; AJvYcCXvPBl9kIdnJCjXdOeo/8C447UUP6z5VANIRXd0FrFKBqveq0TTICZAG/n2Ng1ibU0YWV4=@vger.kernel.org X-Gm-Message-State: AOJu0Yx1O4bC3CQalS4PFEUfBvn4USDiHDBLzv7ykCu6vZnx1FEI0T4I m1b8jYHp0NH+b53hX4/sZ9OHi+6z7JbhiI0H5G7fyEFqweCdtLgzLh1FcayiimMHUtC6HExBEUQ ehsKlWA== X-Google-Smtp-Source: AGHT+IE2VwDPvmAGHpRpdoTRTEzWLqDUDpSCUeqtBAPlzdKHsyWBG/nxoOfSsi/dHSEKLUY3/D6ugR9tVMuj X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:ede7:40c7:c970:8d77]) (user=irogers job=sendgmr) by 2002:a5b:305:0:b0:e4c:35c4:cee3 with SMTP id 3f1490d57ef6-e538c3d6749mr163782276.6.1736273361752; Tue, 07 Jan 2025 10:09:21 -0800 (PST) Date: Tue, 7 Jan 2025 10:08:53 -0800 In-Reply-To: <20250107180854.770470-1-irogers@google.com> Message-Id: <20250107180854.770470-4-irogers@google.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250107180854.770470-1-irogers@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Subject: [PATCH v4 3/4] perf record: Skip don't fail for events that don't open 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 , James Clark , Ze Gao , Weilin Wang , Dominique Martinet , Jean-Philippe Romain , Junhao He , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, Aditya Bodkhe Cc: Leo Yan , Atish Patra Whilst for many tools it is an expected behavior that failure to open a perf event is a failure, ARM decided to name PMU events the same as legacy events and then failed to rename such events on a server uncore SLC PMU. As perf's default behavior when no PMU is specified is to open the event on all PMUs that advertise/"have" the event, this yielded failures when trying to make the priority of legacy and sysfs/json events uniform - something requested by RISC-V and ARM. A legacy event user on ARM hardware may find their event opened on an uncore PMU which for perf record will fail. Arnaldo suggested skipping such events which this patch implements. Rather than have the skipping conditional on running on ARM, the skipping is done on all architectures as such a fundamental behavioral difference could lead to problems with tools built/depending on perf. An example of perf record failing to open events on x86 is: ``` $ perf record -e data_read,cycles,LLC-prefetch-read -a sleep 0.1 Error: Failure to open event 'data_read' on PMU 'uncore_imc_free_running_0' which will be removed. The sys_perf_event_open() syscall returned with 22 (Invalid argument) for event (data_read). "dmesg | grep -i perf" may provide additional information. Error: Failure to open event 'data_read' on PMU 'uncore_imc_free_running_1' which will be removed. The sys_perf_event_open() syscall returned with 22 (Invalid argument) for event (data_read). "dmesg | grep -i perf" may provide additional information. Error: Failure to open event 'LLC-prefetch-read' on PMU 'cpu' which will be removed. The LLC-prefetch-read event is not supported. [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 2.188 MB perf.data (87 samples) ] $ perf report --stats Aggregated stats: TOTAL events: 17255 MMAP events: 284 ( 1.6%) COMM events: 1961 (11.4%) EXIT events: 1 ( 0.0%) FORK events: 1960 (11.4%) SAMPLE events: 87 ( 0.5%) MMAP2 events: 12836 (74.4%) KSYMBOL events: 83 ( 0.5%) BPF_EVENT events: 36 ( 0.2%) FINISHED_ROUND events: 2 ( 0.0%) ID_INDEX events: 1 ( 0.0%) THREAD_MAP events: 1 ( 0.0%) CPU_MAP events: 1 ( 0.0%) TIME_CONV events: 1 ( 0.0%) FINISHED_INIT events: 1 ( 0.0%) cycles stats: SAMPLE events: 87 ``` If all events fail to open then the perf record will fail: ``` $ perf record -e LLC-prefetch-read true Error: Failure to open event 'LLC-prefetch-read' on PMU 'cpu' which will be removed. The LLC-prefetch-read event is not supported. Error: Failure to open any events for recording ``` This is done by detecting if dummy events were implicitly added by perf and seeing if the evlist is empty without them. This allows the dummy event still to be recorded: ``` $ perf record -e dummy true [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.046 MB perf.data ] ``` but fail when inserted: ``` $ perf record -e LLC-prefetch-read -a true Error: Failure to open event 'LLC-prefetch-read' on PMU 'cpu' which will be removed. The LLC-prefetch-read event is not supported. Error: Failure to open any events for recording ``` The issue with legacy events is that on RISC-V they want the driver to not have mappings from legacy to non-legacy config encodings for each vendor/model due to size, complexity and difficulty to update. It was reported that on ARM Apple-M? CPUs the legacy mapping in the driver was broken and the sysfs/json events should always take precedent, however, it isn't clear this is still the case. It is the case that without working around this issue a legacy event like cycles without a PMU can encode differently than when specified with a PMU - the non-PMU version favoring legacy encodings, the PMU one avoiding legacy encodings. The patch removes events and then adjusts the idx value for each evsel. This is done so that the dense xyarrays used for file descriptors, etc. don't contain broken entries. As event opening happens relatively late in the record process, use of the idx value before the open will have become corrupted, so it is expected there are latent bugs hidden behind this change - the change is best effort. As the only vendor that has broken event names is ARM, this will principally effect ARM users. They will also experience warning messages like those above because of the uncore PMU advertising legacy event names. Suggested-by: Arnaldo Carvalho de Melo Signed-off-by: Ian Rogers Tested-by: James Clark Tested-by: Leo Yan Tested-by: Atish Patra --- tools/perf/builtin-record.c | 54 ++++++++++++++++++++++++++++++++----- 1 file changed, 48 insertions(+), 6 deletions(-) diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 5db1aedf48df..b3f06638f3c6 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -161,6 +161,7 @@ struct record { struct evlist *sb_evlist; pthread_t thread_id; int realtime_prio; + int num_parsed_dummy_events; bool switch_output_event_set; bool no_buildid; bool no_buildid_set; @@ -961,7 +962,6 @@ static int record__config_tracking_events(struct record *rec) */ if (opts->target.initial_delay || target__has_cpu(&opts->target) || perf_pmus__num_core_pmus() > 1) { - /* * User space tasks can migrate between CPUs, so when tracing * selected CPUs, sideband for all CPUs is still needed. @@ -1366,6 +1366,7 @@ static int record__open(struct record *rec) struct perf_session *session = rec->session; struct record_opts *opts = &rec->opts; int rc = 0; + bool skipped = false; evlist__for_each_entry(evlist, pos) { try_again: @@ -1381,15 +1382,50 @@ static int record__open(struct record *rec) pos = evlist__reset_weak_group(evlist, pos, true); goto try_again; } - rc = -errno; evsel__open_strerror(pos, &opts->target, errno, msg, sizeof(msg)); - ui__error("%s\n", msg); - goto out; + ui__error("Failure to open event '%s' on PMU '%s' which will be removed.\n%s\n", + evsel__name(pos), evsel__pmu_name(pos), msg); + pos->skippable = true; + skipped = true; + } else { + pos->supported = true; } - - pos->supported = true; } + if (skipped) { + struct evsel *tmp; + int idx = 0, num_dummy = 0, num_non_dummy = 0, + removed_dummy = 0, removed_non_dummy = 0; + + /* Remove evsels that failed to open and update indices. */ + evlist__for_each_entry_safe(evlist, tmp, pos) { + if (evsel__is_dummy_event(pos)) + num_dummy++; + else + num_non_dummy++; + + if (!pos->skippable) + continue; + + if (evsel__is_dummy_event(pos)) + removed_dummy++; + else + removed_non_dummy++; + + evlist__remove(evlist, pos); + } + evlist__for_each_entry(evlist, pos) { + pos->core.idx = idx++; + } + /* If list is empty except implicitly added dummy events then fail. */ + if ((num_non_dummy == removed_non_dummy) && + ((rec->num_parsed_dummy_events == 0) || + (removed_dummy >= (num_dummy - rec->num_parsed_dummy_events)))) { + ui__error("Failure to open any events for recording.\n"); + rc = -1; + goto out; + } + } if (symbol_conf.kptr_restrict && !evlist__exclude_kernel(evlist)) { pr_warning( "WARNING: Kernel address maps (/proc/{kallsyms,modules}) are restricted,\n" @@ -3975,6 +4011,7 @@ int cmd_record(int argc, const char **argv) int err; struct record *rec = &record; char errbuf[BUFSIZ]; + struct evsel *evsel; setlocale(LC_ALL, ""); @@ -4001,6 +4038,11 @@ int cmd_record(int argc, const char **argv) if (quiet) perf_quiet_option(); + evlist__for_each_entry(rec->evlist, evsel) { + if (evsel__is_dummy_event(evsel)) + rec->num_parsed_dummy_events++; + } + err = symbol__validate_sym_arguments(); if (err) return err; From patchwork Tue Jan 7 18:08:54 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13929481 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.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 EAF821F4E30 for ; Tue, 7 Jan 2025 18:09:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736273368; cv=none; b=B1J90SqSrwowOcVu3PyDgLRvQTV59v5PStwv0dzkix80laWfWafXALb2imFhoWbp3eEw90fX/0vgMeZn0k/cqpe6yEnZzYwb8z0LRrUXczqutUk5AHsBFw8aNQnP+B7BpQjtBKlF3nhjQDj6aDgJ55xoQZC1T+8Scik9Qg/LCps= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736273368; c=relaxed/simple; bh=n4XpB7+dDzTwbB8GXiAOmHzEQ/znQPxkMuB/eKUElXQ=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Cc:Content-Type; b=hM9r1VEzkK5UxAKKo+mqADvCAysiU7qaV4ranVACg1+WfmqHA258DUUxfb8VZCh464A/H47RTQ3GMnUm4jqBLU0j0R4OzXaL/jBVs6pZGCUIsS6Rosr/k5nNqGMPHPIBELq6M1WpzLRD5eRnLYzqLJW+H5hzM3Ero3kcV0xJHS8= 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=GKsRiKRj; arc=none smtp.client-ip=209.85.219.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="GKsRiKRj" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e49f7374164so35178514276.3 for ; Tue, 07 Jan 2025 10:09:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1736273364; x=1736878164; darn=vger.kernel.org; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=LDo/fUVPAA6an7wAs+invcSM8+fvtDhXwgH0I+h7TOc=; b=GKsRiKRjRpZLjFW6y4yE4fFejgLF1gBivnC2M9Wayvmq4k6YwlRiX4xjUs6X16pp3o gW7LtA4x9NMpn2Rv1NJZs/Mjv+wd5CXcWnkI9wU+JJzv40Amh9XTY3x1uAVNe61RAV/n lAAowfL98xvJsYY0ngnLRmD+78RIE3S1POykRLRQjwt7o1nH0kH5YNT5GoaYshKCmlbC +mhaIFJsRwAxoXCxJfvmoc+vyjKUklDikKVSA++/ueWmRFiEnwPhFsS1byjl0ZU/WMTB AR9+G8vWxluCJZ9ns1ZSg/Hs+Q6yXbucsRPox/n5NY+M/G2GKfsWmzbSlHngFgDpUJgU XbBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736273364; x=1736878164; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=LDo/fUVPAA6an7wAs+invcSM8+fvtDhXwgH0I+h7TOc=; b=J6LYB+TKlC1NgbCCHeQSg4EbkILshFFFke8SDWyDN10h+ke75fG77A0IBSylRSQ7wn h6UBUOlSAlRkZHk+c8D0F+RyHdaczIgzlt4pIjDLgRfT+3veHGh+aPrEVBGWYywFpoRh PEVFB6TEoCXtzgz5DXfZFm7DFJqYfHbNz6VgLyZ47+dLqiMR6TaTJX4F1GfRHLR0O4lt Pla8hn/+vt6v02jLPZe/RFjqjAwnS4cUbc7dYdy7M9leWjALWH1kGLiB1vGwki3txeYB oaSA0J0sXIjnwqj1Pmc9v3+MQfo2MbBumVb/ATdzK1jx+xh4x7IVclVq1tr9HBJdcWwM xVYA== X-Forwarded-Encrypted: i=1; AJvYcCVeOYqMbifMFnt/dek44lExxgZcY1quhAedKS9Fu2SBbFPRJQ/CJ6Ueb/1913yaIRGYJYo=@vger.kernel.org X-Gm-Message-State: AOJu0YyqAcSqyVo5xG/sSvpfNX90JreWkywLyHL5r/TovhvhlAgvfXiF UUn+RB08GdyuclOX5BjCTVeYerUQqftWQnNQmkoO+g1/hrme0GbJBsKt3fVBG2SWCYw/1uOoXDM B9DcvDw== X-Google-Smtp-Source: AGHT+IG+1ChGa+h/lLDWe4IQ+gNhYcd3EHajbyg7wjQ4Dkg01Ne3YGhKzIPsakAsLuOCwpcvf45/Z4MAi7Ix X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:ede7:40c7:c970:8d77]) (user=irogers job=sendgmr) by 2002:a05:690c:2b03:b0:6eb:ac7:b4bc with SMTP id 00721157ae682-6f3f80de23amr1246637b3.2.1736273364088; Tue, 07 Jan 2025 10:09:24 -0800 (PST) Date: Tue, 7 Jan 2025 10:08:54 -0800 In-Reply-To: <20250107180854.770470-1-irogers@google.com> Message-Id: <20250107180854.770470-5-irogers@google.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250107180854.770470-1-irogers@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Subject: [PATCH v4 4/4] perf parse-events: Reapply "Prefer sysfs/JSON hardware events over legacy" 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 , James Clark , Ze Gao , Weilin Wang , Dominique Martinet , Jean-Philippe Romain , Junhao He , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, Aditya Bodkhe Cc: Atish Patra , Leo Yan , Beeman Strong , Arnaldo Carvalho de Melo Originally posted and merged from: https://lore.kernel.org/r/20240416061533.921723-10-irogers@google.com This reverts commit 4f1b067359ac8364cdb7f9fda41085fa85789d0f although the patch is now smaller due to related fixes being applied in commit 22a4db3c3603 ("perf evsel: Add alternate_hw_config and use in evsel__match"). The original commit message was: It was requested that RISC-V be able to add events to the perf tool so the PMU driver didn't need to map legacy events to config encodings: https://lore.kernel.org/lkml/20240217005738.3744121-1-atishp@rivosinc.com/ This change makes the priority of events specified without a PMU the same as those specified with a PMU, namely sysfs and JSON events are checked first before using the legacy encoding. The hw_term is made more generic as a hardware_event that encodes a pair of string and int value, allowing parse_events_multi_pmu_add to fall back on a known encoding when the sysfs/JSON adding fails for core events. As this covers PE_VALUE_SYM_HW, that token is removed and related code simplified. Signed-off-by: Ian Rogers Reviewed-by: Kan Liang Tested-by: Atish Patra Tested-by: James Clark Tested-by: Leo Yan Cc: Adrian Hunter Cc: Alexander Shishkin Cc: Beeman Strong Cc: Ingo Molnar Cc: Jiri Olsa Cc: Mark Rutland Cc: Namhyung Kim Cc: Peter Zijlstra Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/parse-events.c | 26 +++++++++--- tools/perf/util/parse-events.l | 76 +++++++++++++++++----------------- tools/perf/util/parse-events.y | 60 ++++++++++++++++++--------- 3 files changed, 98 insertions(+), 64 deletions(-) diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 1e23faa364b1..3a60fca53cfa 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -1545,8 +1545,8 @@ int parse_events_multi_pmu_add(struct parse_events_state *parse_state, struct list_head *list = NULL; struct perf_pmu *pmu = NULL; YYLTYPE *loc = loc_; - int ok = 0; - const char *config; + int ok = 0, core_ok = 0; + const char *tmp; struct parse_events_terms parsed_terms; *listp = NULL; @@ -1559,15 +1559,15 @@ int parse_events_multi_pmu_add(struct parse_events_state *parse_state, return ret; } - config = strdup(event_name); - if (!config) + tmp = strdup(event_name); + if (!tmp) goto out_err; if (parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER, - config, /*num=*/1, /*novalue=*/true, + tmp, /*num=*/1, /*novalue=*/true, loc, /*loc_val=*/NULL) < 0) { - zfree(&config); + zfree(&tmp); goto out_err; } list_add_tail(&term->list, &parsed_terms.terms); @@ -1598,6 +1598,8 @@ int parse_events_multi_pmu_add(struct parse_events_state *parse_state, pr_debug("%s -> %s/%s/\n", event_name, pmu->name, sb.buf); strbuf_release(&sb); ok++; + if (pmu->is_core) + core_ok++; } } @@ -1614,6 +1616,18 @@ int parse_events_multi_pmu_add(struct parse_events_state *parse_state, } } + if (hw_config != PERF_COUNT_HW_MAX && !core_ok) { + /* + * The event wasn't found on core PMUs but it has a hardware + * config version to try. + */ + if (!parse_events_add_numeric(parse_state, list, + PERF_TYPE_HARDWARE, hw_config, + const_parsed_terms, + /*wildcard=*/true)) + ok++; + } + out_err: parse_events_terms__exit(&parsed_terms); if (ok) diff --git a/tools/perf/util/parse-events.l b/tools/perf/util/parse-events.l index bf7f73548605..29082a22ccc9 100644 --- a/tools/perf/util/parse-events.l +++ b/tools/perf/util/parse-events.l @@ -113,12 +113,12 @@ do { \ yyless(0); \ } while (0) -static int sym(yyscan_t scanner, int type, int config) +static int sym(yyscan_t scanner, int config) { YYSTYPE *yylval = parse_events_get_lval(scanner); - yylval->num = (type << 16) + config; - return type == PERF_TYPE_HARDWARE ? PE_VALUE_SYM_HW : PE_VALUE_SYM_SW; + yylval->num = config; + return PE_VALUE_SYM_SW; } static int term(yyscan_t scanner, enum parse_events__term_type type) @@ -129,13 +129,13 @@ static int term(yyscan_t scanner, enum parse_events__term_type type) return PE_TERM; } -static int hw_term(yyscan_t scanner, int config) +static int hw(yyscan_t scanner, int config) { YYSTYPE *yylval = parse_events_get_lval(scanner); char *text = parse_events_get_text(scanner); - yylval->hardware_term.str = strdup(text); - yylval->hardware_term.num = PERF_TYPE_HARDWARE + config; + yylval->hardware_event.str = strdup(text); + yylval->hardware_event.num = config; return PE_TERM_HW; } @@ -324,16 +324,16 @@ aux-output { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_AUX_OUTPUT); } aux-action { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_AUX_ACTION); } aux-sample-size { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_AUX_SAMPLE_SIZE); } metric-id { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_METRIC_ID); } -cpu-cycles|cycles { return hw_term(yyscanner, PERF_COUNT_HW_CPU_CYCLES); } -stalled-cycles-frontend|idle-cycles-frontend { return hw_term(yyscanner, PERF_COUNT_HW_STALLED_CYCLES_FRONTEND); } -stalled-cycles-backend|idle-cycles-backend { return hw_term(yyscanner, PERF_COUNT_HW_STALLED_CYCLES_BACKEND); } -instructions { return hw_term(yyscanner, PERF_COUNT_HW_INSTRUCTIONS); } -cache-references { return hw_term(yyscanner, PERF_COUNT_HW_CACHE_REFERENCES); } -cache-misses { return hw_term(yyscanner, PERF_COUNT_HW_CACHE_MISSES); } -branch-instructions|branches { return hw_term(yyscanner, PERF_COUNT_HW_BRANCH_INSTRUCTIONS); } -branch-misses { return hw_term(yyscanner, PERF_COUNT_HW_BRANCH_MISSES); } -bus-cycles { return hw_term(yyscanner, PERF_COUNT_HW_BUS_CYCLES); } -ref-cycles { return hw_term(yyscanner, PERF_COUNT_HW_REF_CPU_CYCLES); } +cpu-cycles|cycles { return hw(yyscanner, PERF_COUNT_HW_CPU_CYCLES); } +stalled-cycles-frontend|idle-cycles-frontend { return hw(yyscanner, PERF_COUNT_HW_STALLED_CYCLES_FRONTEND); } +stalled-cycles-backend|idle-cycles-backend { return hw(yyscanner, PERF_COUNT_HW_STALLED_CYCLES_BACKEND); } +instructions { return hw(yyscanner, PERF_COUNT_HW_INSTRUCTIONS); } +cache-references { return hw(yyscanner, PERF_COUNT_HW_CACHE_REFERENCES); } +cache-misses { return hw(yyscanner, PERF_COUNT_HW_CACHE_MISSES); } +branch-instructions|branches { return hw(yyscanner, PERF_COUNT_HW_BRANCH_INSTRUCTIONS); } +branch-misses { return hw(yyscanner, PERF_COUNT_HW_BRANCH_MISSES); } +bus-cycles { return hw(yyscanner, PERF_COUNT_HW_BUS_CYCLES); } +ref-cycles { return hw(yyscanner, PERF_COUNT_HW_REF_CPU_CYCLES); } r{num_raw_hex} { return str(yyscanner, PE_RAW); } r0x{num_raw_hex} { return str(yyscanner, PE_RAW); } , { return ','; } @@ -377,28 +377,28 @@ r0x{num_raw_hex} { return str(yyscanner, PE_RAW); } <> { BEGIN(INITIAL); } } -cpu-cycles|cycles { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_CPU_CYCLES); } -stalled-cycles-frontend|idle-cycles-frontend { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_STALLED_CYCLES_FRONTEND); } -stalled-cycles-backend|idle-cycles-backend { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_STALLED_CYCLES_BACKEND); } -instructions { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_INSTRUCTIONS); } -cache-references { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_CACHE_REFERENCES); } -cache-misses { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_CACHE_MISSES); } -branch-instructions|branches { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_BRANCH_INSTRUCTIONS); } -branch-misses { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_BRANCH_MISSES); } -bus-cycles { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_BUS_CYCLES); } -ref-cycles { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_REF_CPU_CYCLES); } -cpu-clock { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CPU_CLOCK); } -task-clock { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_TASK_CLOCK); } -page-faults|faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_PAGE_FAULTS); } -minor-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_PAGE_FAULTS_MIN); } -major-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_PAGE_FAULTS_MAJ); } -context-switches|cs { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CONTEXT_SWITCHES); } -cpu-migrations|migrations { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CPU_MIGRATIONS); } -alignment-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_ALIGNMENT_FAULTS); } -emulation-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_EMULATION_FAULTS); } -dummy { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_DUMMY); } -bpf-output { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_BPF_OUTPUT); } -cgroup-switches { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CGROUP_SWITCHES); } +cpu-cycles|cycles { return hw(yyscanner, PERF_COUNT_HW_CPU_CYCLES); } +stalled-cycles-frontend|idle-cycles-frontend { return hw(yyscanner, PERF_COUNT_HW_STALLED_CYCLES_FRONTEND); } +stalled-cycles-backend|idle-cycles-backend { return hw(yyscanner, PERF_COUNT_HW_STALLED_CYCLES_BACKEND); } +instructions { return hw(yyscanner, PERF_COUNT_HW_INSTRUCTIONS); } +cache-references { return hw(yyscanner, PERF_COUNT_HW_CACHE_REFERENCES); } +cache-misses { return hw(yyscanner, PERF_COUNT_HW_CACHE_MISSES); } +branch-instructions|branches { return hw(yyscanner, PERF_COUNT_HW_BRANCH_INSTRUCTIONS); } +branch-misses { return hw(yyscanner, PERF_COUNT_HW_BRANCH_MISSES); } +bus-cycles { return hw(yyscanner, PERF_COUNT_HW_BUS_CYCLES); } +ref-cycles { return hw(yyscanner, PERF_COUNT_HW_REF_CPU_CYCLES); } +cpu-clock { return sym(yyscanner, PERF_COUNT_SW_CPU_CLOCK); } +task-clock { return sym(yyscanner, PERF_COUNT_SW_TASK_CLOCK); } +page-faults|faults { return sym(yyscanner, PERF_COUNT_SW_PAGE_FAULTS); } +minor-faults { return sym(yyscanner, PERF_COUNT_SW_PAGE_FAULTS_MIN); } +major-faults { return sym(yyscanner, PERF_COUNT_SW_PAGE_FAULTS_MAJ); } +context-switches|cs { return sym(yyscanner, PERF_COUNT_SW_CONTEXT_SWITCHES); } +cpu-migrations|migrations { return sym(yyscanner, PERF_COUNT_SW_CPU_MIGRATIONS); } +alignment-faults { return sym(yyscanner, PERF_COUNT_SW_ALIGNMENT_FAULTS); } +emulation-faults { return sym(yyscanner, PERF_COUNT_SW_EMULATION_FAULTS); } +dummy { return sym(yyscanner, PERF_COUNT_SW_DUMMY); } +bpf-output { return sym(yyscanner, PERF_COUNT_SW_BPF_OUTPUT); } +cgroup-switches { return sym(yyscanner, PERF_COUNT_SW_CGROUP_SWITCHES); } {lc_type} { return str(yyscanner, PE_LEGACY_CACHE); } {lc_type}-{lc_op_result} { return str(yyscanner, PE_LEGACY_CACHE); } diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y index f888cbb076d6..d2ef1890007e 100644 --- a/tools/perf/util/parse-events.y +++ b/tools/perf/util/parse-events.y @@ -55,7 +55,7 @@ static void free_list_evsel(struct list_head* list_evsel) %} %token PE_START_EVENTS PE_START_TERMS -%token PE_VALUE PE_VALUE_SYM_HW PE_VALUE_SYM_SW PE_TERM +%token PE_VALUE PE_VALUE_SYM_SW PE_TERM %token PE_EVENT_NAME %token PE_RAW PE_NAME %token PE_MODIFIER_EVENT PE_MODIFIER_BP PE_BP_COLON PE_BP_SLASH @@ -65,11 +65,9 @@ static void free_list_evsel(struct list_head* list_evsel) %token PE_DRV_CFG_TERM %token PE_TERM_HW %type PE_VALUE -%type PE_VALUE_SYM_HW %type PE_VALUE_SYM_SW %type PE_MODIFIER_EVENT %type PE_TERM -%type value_sym %type PE_RAW %type PE_NAME %type PE_LEGACY_CACHE @@ -85,6 +83,7 @@ static void free_list_evsel(struct list_head* list_evsel) %type opt_pmu_config %destructor { parse_events_terms__delete ($$); } %type event_pmu +%type event_legacy_hardware %type event_legacy_symbol %type event_legacy_cache %type event_legacy_mem @@ -102,8 +101,8 @@ static void free_list_evsel(struct list_head* list_evsel) %destructor { free_list_evsel ($$); } %type tracepoint_name %destructor { free ($$.sys); free ($$.event); } -%type PE_TERM_HW -%destructor { free ($$.str); } +%type PE_TERM_HW +%destructor { free ($$.str); } %union { @@ -118,10 +117,10 @@ static void free_list_evsel(struct list_head* list_evsel) char *sys; char *event; } tracepoint_name; - struct hardware_term { + struct hardware_event { char *str; u64 num; - } hardware_term; + } hardware_event; } %% @@ -264,6 +263,7 @@ PE_EVENT_NAME event_def event_def event_def: event_pmu | + event_legacy_hardware | event_legacy_symbol | event_legacy_cache sep_dc | event_legacy_mem sep_dc | @@ -306,24 +306,45 @@ PE_NAME sep_dc $$ = list; } -value_sym: -PE_VALUE_SYM_HW +event_legacy_hardware: +PE_TERM_HW opt_pmu_config +{ + /* List of created evsels. */ + struct list_head *list = NULL; + int err = parse_events_multi_pmu_add(_parse_state, $1.str, $1.num, $2, &list, &@1); + + free($1.str); + parse_events_terms__delete($2); + if (err) + PE_ABORT(err); + + $$ = list; +} | -PE_VALUE_SYM_SW +PE_TERM_HW sep_dc +{ + struct list_head *list; + int err; + + err = parse_events_multi_pmu_add(_parse_state, $1.str, $1.num, NULL, &list, &@1); + free($1.str); + if (err) + PE_ABORT(err); + $$ = list; +} event_legacy_symbol: -value_sym '/' event_config '/' +PE_VALUE_SYM_SW '/' event_config '/' { struct list_head *list; - int type = $1 >> 16; - int config = $1 & 255; int err; - bool wildcard = (type == PERF_TYPE_HARDWARE || type == PERF_TYPE_HW_CACHE); list = alloc_list(); if (!list) YYNOMEM; - err = parse_events_add_numeric(_parse_state, list, type, config, $3, wildcard); + err = parse_events_add_numeric(_parse_state, list, + /*type=*/PERF_TYPE_SOFTWARE, /*config=*/$1, + $3, /*wildcard=*/false); parse_events_terms__delete($3); if (err) { free_list_evsel(list); @@ -332,18 +353,17 @@ value_sym '/' event_config '/' $$ = list; } | -value_sym sep_slash_slash_dc +PE_VALUE_SYM_SW sep_slash_slash_dc { struct list_head *list; - int type = $1 >> 16; - int config = $1 & 255; - bool wildcard = (type == PERF_TYPE_HARDWARE || type == PERF_TYPE_HW_CACHE); int err; list = alloc_list(); if (!list) YYNOMEM; - err = parse_events_add_numeric(_parse_state, list, type, config, /*head_config=*/NULL, wildcard); + err = parse_events_add_numeric(_parse_state, list, + /*type=*/PERF_TYPE_SOFTWARE, /*config=*/$1, + /*head_config=*/NULL, /*wildcard=*/false); if (err) PE_ABORT(err); $$ = list;