From patchwork Sat Dec 21 19:26:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13917911 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 AF1C11898E8 for ; Sat, 21 Dec 2024 19:27:01 +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=1734809223; cv=none; b=D2fqAJiRilMVhpevxSTjshVfsa1CXxV0YCWSu6euibxchQhE14rzv9lnNSF9QxjZObM53XDEFTU+Cq70i3CCRfw5dlDl67oiByeBAJaftAfKYW3+/zrGO9X42yG2f4Oh2hqK2dfv0xBkKntKs/S9+v0ZizCrA4xZGh6pT7Ny5nw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734809223; c=relaxed/simple; bh=z0BXIU+cy5J4APMsTNwNrDiG3aEgH1lNySzfDNpVA+Q=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Cc:Content-Type; b=jNeXKz2UWSER9Sbu4NmMGdyGRZ/mj0EexxOfpM7eJXu0UgyoVaH3FDxpApb28kBKQ0WTTmtYFImPNiVT0S7ILgKYGTn3TWJvX6UBOiZ95StImfkCHYiU9XJixrXU+j6sholpPdk9Jf4gXMC0MnpfKr13mHuUm8iyF5Mzc80SbX0= 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=XqQEcoTX; 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="XqQEcoTX" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e3984b68708so4214247276.0 for ; Sat, 21 Dec 2024 11:27:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734809221; x=1735414021; 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=To5Q6DXsmBuoVyAB+Coe+PRFSr7U5wanl+AgsMSjmUE=; b=XqQEcoTXhp/9f8BVzb08Zaz31FZtXl0B2dVcGvtpqPj3XXUpFhnaKskf8QWJYRx5mT Z5+m+UpQj8UYHyJDVb/No5a+xJSDNLCVIFq1WNU5fq6vwfAaDIOPbql8+nI4Cj4ZbWaJ pncvT6YvWS0AHIpQbRdp6t+KrWrmhJHGvnl7Pj8EQMhxUtdVyWgJ0msojFGteiNrPy1o 36qHHkse74BsVKTQtMSWcx2geJvZHegcwDxa6g0q4vcwDNS4ZEdxxGCQ9S44wrw0jYXD myXPCqt9ALDvW2W4t0ODZSURkDw6A/0wjzp0iopboq4votGQIbqyhQPT3x/09CPXS6Fm 08OQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734809221; x=1735414021; 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=To5Q6DXsmBuoVyAB+Coe+PRFSr7U5wanl+AgsMSjmUE=; b=IoqRkLyR+Z5yHuw2+9lglxdt+BKfFQOcgCWXGl0hbi9ZmSpHU2oMHRfd73WTrMoG1I 18TmtFyrXiYx/SlwHMw0UqYuMO5FTlIyJUinwp6pD3VT7ftphxeAZYRiuaeMQ9vqnTsQ Q3T7LD+8F3W0Tu4yCJU7zKAwj1PmBDCHc9geHXpYvxgniTd6LEedM/PR37xAaiK7cwNl jx7MkVALW7KCraMslxm04HUMdN4AsFzKJPH50kwA7GoKbv0ZrX+CxXfDjKvmw7Rfng3M j5X5LJy361kpLo5V8LsAVBoYShs/pdBTJJI9iGq05Fvk40tZyATry1GCqzd2onk3f7Q/ t3bg== X-Forwarded-Encrypted: i=1; AJvYcCWWeP858Z/LDpssORPtY2CJhjvGdxhYjByapzKc27w/yt+aoPo4fSJMNgAkqT8tKUy2uYc=@vger.kernel.org X-Gm-Message-State: AOJu0YzpxpEDu85wkcPobVuWQ3jV1bzC2lfyYMMw5FJpZXm1TX0iVWir HOyRSuz5i0Qjy5WF1bdY1zyeZmfgx2WfPpj6U7EEgguDE/E2/6NAL/QPH4b9cSwMrK/QajwLGct +KuYxuw== X-Google-Smtp-Source: AGHT+IFhFbpXLuh09c3OfbDr6j+ZeLOL/XrOzEbPkiGL/D7Eikc8Jn90QIx8Q+lGeqhu14rEJvLMbRvQzmio X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:a2bc:ec03:1143:41ab]) (user=irogers job=sendgmr) by 2002:a25:2705:0:b0:e39:8506:c03d with SMTP id 3f1490d57ef6-e538c3cb14bmr16811276.9.1734809220613; Sat, 21 Dec 2024 11:27:00 -0800 (PST) Date: Sat, 21 Dec 2024 11:26:51 -0800 In-Reply-To: <20241221192654.94344-1-irogers@google.com> Message-Id: <20241221192654.94344-2-irogers@google.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241221192654.94344-1-irogers@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Subject: [PATCH v3 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 6ae5d110994a..109c4f188dec 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 5ad352c94d00..cfa2660a06e8 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -235,6 +235,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 Sat Dec 21 19:26:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13917912 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 E9FAA18FDA9 for ; Sat, 21 Dec 2024 19:27:03 +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=1734809225; cv=none; b=RprJJeuUP3JH91wAzWypIHv5sUm04cLDjOF5Lc132VDETCbc3YYuHRi6U3852pnZmkH3WssLINWSVi0/oIRFAQ6YwYVFFn+SYre1naFrQdfdVGX80jNbAZ3cLAp2a7Wx/lqz7F7GPqir+Vojj1pcj/qoD41DB9bgsgsOPEV6y/s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734809225; c=relaxed/simple; bh=mbSjQSmFx03BBbUNYmEFNvOSfaebIobQfcRuwGZsa6E=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Cc:Content-Type; b=O9MR1ADMqB3Yjx3x4DihkjAHEU8SS+obH6u8uxW/K6vOP5ArSkZS3nIMx58uHagN3RdPbOkSgrx9wXew3kK46VZrA3pZ4ikNc/lRCbksYVRHWC0Z/ct4iP2Qj6y+oHNfb2vD6Z1lr/CLyZAg9fOa8LYGZNo7oGytczBAlSUfm8Q= 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=2XsK/ur9; 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="2XsK/ur9" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e3a1bc0c876so4018351276.1 for ; Sat, 21 Dec 2024 11:27:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734809223; x=1735414023; 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=Jx8LXjjEYC9Y4HOJdp2FCstQyDUI0FCzF2hebA9zeIg=; b=2XsK/ur9aNDHZtoTxoJJ2oIf3sMrFoXRUJG/wGbqvODPblCuSTzhjQzdfkdCRLFcMq 7YP5bkmtL0V93g4Et8SF5O9AYhnWPzXdlC2wh9AqI2xaV2BsXzGS2RJH3pfhfmtj/WyG IVsEiQKOQbF5ZN4Qtrzxz6cVbzsfOjxVcV11G7eB+WTCaGbTCB1lw2il3zCSQUZ3leKQ fL6c+1V+Y7oDlPfi9tvLdvxV6ffxcxlXhTCO7ie1nLoct8V7CJeJYPW24GBi5F+livR3 KdUDIOK8WpfPjr7rRfCGdZSxI5SPqZ2WWXDsXj5gwpmnOVhf6lElRPESr5aJjSWwJGsJ oYCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734809223; x=1735414023; 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=Jx8LXjjEYC9Y4HOJdp2FCstQyDUI0FCzF2hebA9zeIg=; b=u5Ey/rsLJCGbw1ckouyeXB4QQ9YvkfKuPcOd33LllGfdECEChuHuhTPJ37LCIFKdeb nix2DyxMZ7GvIXq8CvrsQvZ1FgOZ+WPRhIU0gzGY0iQVSdcke0yIlwRtNy9bY4jXlfXg y4Zjgp80/clibsRieczmWzTACbxhhEU6gy40Bye7L/NzsBsUPE5k6ED9sfpBvfS7pNWz FGO7hebl97IDB0rvMse53fBBs2kXLdF+p8yEGjrhbmBGMDw7d0rRcfHXRPUxR/JI1iUk ImM8kC+4PC4kNyAW3MorWdtvWPcYLcA+cMnuquyjhkkkXpivX2sidEncebVxBWYvX/MS xnEw== X-Forwarded-Encrypted: i=1; AJvYcCUhlPRQpPdLxk5Bcu140obAmc7LUekVOPVHV7xfjo8tNxMeYS+vXBjUJjWX+tzxRdzImuE=@vger.kernel.org X-Gm-Message-State: AOJu0YyHBXqwjZnGIxGdAcE0Vtgj8euhSBanZ1Oae9PGuRqUaQKpZc0z zdrFva2n1ig+QtoFBt80FvOojPT4rrXebEq8wa3UlAaHA9i864jzW7Z/+RVP1NqpS587urkxepU 7vmWiNg== X-Google-Smtp-Source: AGHT+IFXmoVmR4aIc2dv+ZDgEpdlVfba/zEH9nUjbZlAMKv2bwtgTIAVXJj4c4ROsh93/QVcrAxMBYEXb7iA X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:a2bc:ec03:1143:41ab]) (user=irogers job=sendgmr) by 2002:a25:acd7:0:b0:e39:6fdc:556d with SMTP id 3f1490d57ef6-e538c019dfcmr14276276.0.1734809222886; Sat, 21 Dec 2024 11:27:02 -0800 (PST) Date: Sat, 21 Dec 2024 11:26:52 -0800 In-Reply-To: <20241221192654.94344-1-irogers@google.com> Message-Id: <20241221192654.94344-3-irogers@google.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241221192654.94344-1-irogers@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Subject: [PATCH v3 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 47718610d5d8..109c4a012ce8 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 Sat Dec 21 19:26:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13917913 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.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 E0B00198A0E for ; Sat, 21 Dec 2024 19:27:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734809227; cv=none; b=GjqE8qvc1u7ELh510k1kysSBLE67ZxdxtON3sinW3YPGxgIeIi6Iu5PDjh0Ui40ti0PYOGAfkQ1nSJYPnmjHzORIE0JzmgMu33TrroEGeu2FINkrTtzh5Ww82/+eL3PSnp1FCgPatEu2ZSjOtBa6XrnJT2MRL8qmOV/TLkJfUic= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734809227; c=relaxed/simple; bh=7fu/DFLrm5Jp+7q0HzW9A2i9nE4/DlX6NN15iJnlQ6U=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Cc:Content-Type; b=jcsNrtzYHtmo/V0NSE3n+Jgj++huACt1d5TYkme+3PG1dblF8woj+8A3OBA+1k87DEJxzkByo9+TZe4bvXVsz6k9jpEQCp8FCREJOr3RvadT2BITL0j36vn6/OZ3KdLaBmvQa8nbQT/UJQE0ljkNlRcCskaYZvNHxAHRtYg1l/Y= 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=irwTCG3W; arc=none smtp.client-ip=209.85.128.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="irwTCG3W" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6f013249180so50993927b3.0 for ; Sat, 21 Dec 2024 11:27:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734809225; x=1735414025; 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=pOE3L6cGLsIo5XojcUzlg5FYQWc469qpQODvd7cISPA=; b=irwTCG3WRDeHuHBncr3Vh51rVKTmpdCNCjPT8SycxGJkmfLwTvvbvQaJoRNMq/301x udpUV2B2QU6hup6rNUeyluqFUHiETz7IUor+7H+4GGSVRJbzcibDSjUMFRriMYt9xxQM XViwcRgF60v3cpMLp2Xnw94iUWecrbv76wgdgyWAEVQvlcIYN7TQdn0ah0WJUh+39yAd 78XjGSojrjTeTMvCsZHkce7DrA7kKOK5QvwM8LRfuX/EryB5BLFZ+sIKcR2coOkDtdym B4ow8+jOhHn8pndlEv9yRx61XwrwMPQMbNy6cRe/TK4oZGVo8nCGPj07h57lwzc6Pzv4 rpfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734809225; x=1735414025; 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=pOE3L6cGLsIo5XojcUzlg5FYQWc469qpQODvd7cISPA=; b=kS6uwmUDPDuU50OX5rBnfbHpo18T10guYinYJAGUb4xiVjOHf6nNkiZdcTy/AIxG4c 3992BN4zljxMhC5ixpwSegGL6xG+mND70KB7gqO5PoCxkI+AW2Tq6ri6BGoWAghlsFp3 tE+Ee9bANdQM7tprAEYq6HDAdKTD5ov6LRccmcUT4TKmZUGuXhFoAWuMGdnQSiTM6phe /LLE6RMuC0XRgvIhDcyUCiN0Fqd1Hjxh6326WfyqrEBV5EhFcUsnWKf3ZUAXnXq5JlPo NBISJ05aPRTnfGHpOVhjx96t8/riMiOwTdF98X/4gzNMGk+FsI3B+gp2vwwIyttiLOme wtfQ== X-Forwarded-Encrypted: i=1; AJvYcCUQ7KILo4gK1y/MQh0gMRmSNYZWJIV3CIi8KnwdJmvh/dj7j5rChRS44rL59XLlwg0obls=@vger.kernel.org X-Gm-Message-State: AOJu0YxJEXxsyPWbsr2ufEeN7c+P4em/eILPbOhV4z3it2IAgqhKXr4P /3vNz2+iPOeS30I2iWNxyOfdgr92/G1x76BSU+ALE03LGQ40eJ6Xv2UPH664FFc3x2h9e8BlV9r VbQdE7g== X-Google-Smtp-Source: AGHT+IEGHxVmpRg7agVhGMQxTEkDH6CeIzWWB/q/lfFTYjK6su8nXsn7LYNanXrXBILQDmSYStsQKqCppo0U X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:a2bc:ec03:1143:41ab]) (user=irogers job=sendgmr) by 2002:a25:7453:0:b0:e38:9694:4c6e with SMTP id 3f1490d57ef6-e5376587242mr23513276.2.1734809224969; Sat, 21 Dec 2024 11:27:04 -0800 (PST) Date: Sat, 21 Dec 2024 11:26:53 -0800 In-Reply-To: <20241221192654.94344-1-irogers@google.com> Message-Id: <20241221192654.94344-4-irogers@google.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241221192654.94344-1-irogers@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Subject: [PATCH v3 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 a dummy event was added by perf and seeing if the evlist is empty without it. 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 | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 5db1aedf48df..7415036c1724 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -171,6 +171,7 @@ struct record { bool timestamp_filename; bool timestamp_boundary; bool off_cpu; + bool dummy_event_added; const char *filter_action; struct switch_output switch_output; unsigned long long samples; @@ -961,7 +962,7 @@ 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) { - + int evlist_entries_before = evlist->core.nr_entries; /* * User space tasks can migrate between CPUs, so when tracing * selected CPUs, sideband for all CPUs is still needed. @@ -973,6 +974,8 @@ static int record__config_tracking_events(struct record *rec) if (!evsel) return -ENOMEM; + rec->dummy_event_added = evlist->core.nr_entries > evlist_entries_before; + /* * Enable the tracking event when the process is forked for * initial_delay, immediately for system wide. @@ -1366,6 +1369,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 +1385,33 @@ 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; + + evlist__for_each_entry_safe(evlist, tmp, pos) { + if (pos->skippable) + evlist__remove(evlist, pos); + } + evlist__for_each_entry(evlist, pos) { + pos->core.idx = idx++; + } + if (idx == 0 || (idx == 1 && rec->dummy_event_added)) { + 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" From patchwork Sat Dec 21 19:26:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13917914 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.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 4B0AF1A8408 for ; Sat, 21 Dec 2024 19:27:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734809231; cv=none; b=UEsFzGUdmrlj5dkdVl1n3U8UhOCyJX5p2Lqe0K6U4uvv77/IiNjk35rHXM5XsVj8AlcsExCQSGPuCtX77hsKu7opy+xaMIm9Tl1Eac1zJGCyuLkVDKf/tbjy9jX2MiJLqPEDgaBCJAqR1ac94gguf+rynQLX97G3hlJth/xKe9E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734809231; 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=BfWUHZ0QjPUgwH9WF3/ES9XuiGzu3VN8gZ1xeolpWjO9ThwXR48o8g+wKA3tyhBMLXt7mA4mi5c3ujKdbfHXqM1UOzpLI83FKg44c61uxNxf4Hf7l9Ow6X3eCoFD0FhE/6iHlEbJkF4GKfvOXh3m2l0o071SB4fIEljxLAF7VVs= 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=3gBuJ4k+; arc=none smtp.client-ip=209.85.128.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="3gBuJ4k+" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6ef542990dbso30425507b3.1 for ; Sat, 21 Dec 2024 11:27:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734809227; x=1735414027; 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=3gBuJ4k+4UKAvIkJ8MWRnXpH/Qqm9uRLKeZZIdxCPteTPdi5ucIstRHJ2syNgOhArs ArL2XItg62Uwj3vMUWFfLot4gj7WDLTj0v8cvV5yHsd12TZE6SmcHF0psRF020M4Jz+D hUz7+ciFyh8YfPSfNt+Pf3kOMmvWqgSb2nGsM5Peg2hv00BprRuS/ex2CZjAinCBs0cP uAMnlIjj8NbyGulNF/4zLJNQf5MwlinFL4ZyzF1QefG3T5YQ4ZrJBnnSMqfIi7E8A/BZ tRu/ltBUIQFFEdSh+8JdH4z4/mgNAjLuT8RLslrY/K1sjPyS1JSwyGw7zK4WzNibJh+/ guWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734809227; x=1735414027; 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=Hql5gM+aqlzbxZMgzJZ3b6J8QHBo5iGs3GmKulTanwP9sT62Q63Wc6LOjvybmXgU/j Q9jMLxxsmpO7yFoKoSn8h8GNjkf5XJluMSE1ZKr1yWTf0/AlIjHP5KUEeI5gUdSH8qte 6QQ2k+/gll8Xg776uKpYc+xvCDe0JrmM8ET9AmU+9O5liE9uEVSUorz8me9oPLRqNd/x E8IgP91TZQabjR4ZEExpuyotqWqdxMLUhIgoeSzVt9t1y/NE5XzycRttBpaosI+sAM9B R5Jt9OFS+G+2Ij765GmG0B3HtHv5BHtoU3T2wwuUchZCx5p725cMFzNFCVO/cfUjtJrj PjeQ== X-Forwarded-Encrypted: i=1; AJvYcCWs3DhfRlsv4el9ov+7CC/Ze5dv6m3lsyS0w47TnWdOOlsNpFFCDo4dcTsFSZ+8iR8shFo=@vger.kernel.org X-Gm-Message-State: AOJu0YxffsSgiJOzwmbjJ/aKJ0jwg51vHCwX2YT+DHORaVh0HLuXjkkh GQjbY/GZJglrOU31G7Z0GsJqNFMIgmYO3KhRg9JfIh2H2NnNbsCLcj4bQPmQRuhxNlOUw7yud2A poCJ27g== X-Google-Smtp-Source: AGHT+IHBZDUkpvQeZy3FcJFEfq6MwwNIBVkBtMOFeNRB923rmDP/2fgHlbt3fG9m5NJ+kGqdWoMsGqsCws9N X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:a2bc:ec03:1143:41ab]) (user=irogers job=sendgmr) by 2002:a81:fb07:0:b0:6ef:5e7a:aa72 with SMTP id 00721157ae682-6f3f8261ee6mr171607b3.8.1734809227308; Sat, 21 Dec 2024 11:27:07 -0800 (PST) Date: Sat, 21 Dec 2024 11:26:54 -0800 In-Reply-To: <20241221192654.94344-1-irogers@google.com> Message-Id: <20241221192654.94344-5-irogers@google.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241221192654.94344-1-irogers@google.com> X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Subject: [PATCH v3 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;