From nobody Sun Nov 24 04:41:17 2024 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 E0CF9217320 for ; Thu, 7 Nov 2024 16:20:43 +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=1730996445; cv=none; b=cCSnGjdlOeD+nxc23ir7h4BY1/glRxGefkLMo4YwVvGHqRy24qS6gQDcajQotf0v//Il0NpBNFD+7HJ5cYdldS1Aal0itjY9/w6WPxnu61kD336HoFHJiyDyTHUL7nQXWCyStC6dHCAzzwMR1/+mgWB+DCke5XVRoC8NAJIB6rI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730996445; c=relaxed/simple; bh=OQ+ILS6ZdIDbpDd6fnm+5OYFklVHCZ8ERtWBLEZnFyg=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Cc:Content-Type; b=LWw2WkNUX8beA2Np/9wQDbD6nQiAAvfuPVYBKKf+2NohM3Y8hbVvlOrfqrA87OoxAaciHFccwjPX/DIX//IxIhCBq2McpqA2B+Db8oPGzTDrDtpFpzHrh9pQAJtcJDTRgrqrg2UrAr0QfO1vTtRRnieooJWEkJQfBBJFTAxVtFM= 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=zUcVm2ZX; 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="zUcVm2ZX" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e32ff6f578eso2897818276.1 for ; Thu, 07 Nov 2024 08:20:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730996443; x=1731601243; 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=6Zi7/BGIzk4kmPbaIIn5N5Q89D8reWg5dpAnu28NGJw=; b=zUcVm2ZXhGnSypH0GLkeSotuc0HUk4N/11XDq7hA1rvqRRCuts+swxtmwH8mby9NYG FjPmoUKFr7AYaBUm+ridTTXCuC0L5AzkyI2y171yuta8Nem/IG+AQX5jvIMSv0de6LEd 1hs2CfsGXyalmc5dPq7VBzh6/W+r+vzlV4N8DAOtavaWVaLt9lmX5FqpgvkHjpRXsXAx Oi1WgYyrmu4beez7OADsPLKcUDMKTbGRilw5olJeN+/bagoRtc0ZXgbe+6wcLiDKri6I XrMs5M6mE3VS7jtwNBZfw5FE3xP8nAjxru+zbvP8riHx4UVz5gbFjkrOy3xTAafQw/45 uEug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730996443; x=1731601243; 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=6Zi7/BGIzk4kmPbaIIn5N5Q89D8reWg5dpAnu28NGJw=; b=I4sd1KQu1Z7RTafiimg5erKyCF5EedOt+TcOhhWsCBnIUu87bInQViePvePHOfR4iR 8ljVY61Evl22HQJFOxqeS5vrGAX/4xQVhXl5WSbZv/MLd54LhZ40rXRFhzUUJFQ276l3 mZAusNcPWGRMlgY8GwPCqx+imvUur8g9kGsRPFReQ9l+a4RJMd/+fTy3/C8MlQEBAffy log/BEFKj2lV5ClxhS0MyItOcU5wgw93ZwdD9vp5BCGN7XWKHJgROe1SjUMi4EOQGgj/ O9b4P3rUvJkAyQ7c2S7Os63uS3EO2lvO7w2QUFAhOynHzZRFhHKk45jNsg3wo4j7OBii kiGA== X-Forwarded-Encrypted: i=1; AJvYcCXgVrx1xN5fvuUJ9wEJTN2M4DyYdc+2CZ2QV1laDEudtRIgWUIOL8qfICvFtQRao6zlGK6ghAw7mnWwWXY=@vger.kernel.org X-Gm-Message-State: AOJu0Yz8h2joUczFk6ga9wUwGkUoOUWfbi6dSACvCFWJyhX7+Yvmuvj+ E43pG5SUWa1hKNkY0q9VkdeozVMBT6O2pY3b6IpjD152nwXnXLi6XC7fRvVGNZdT16CNulb6eCc sIhM43Q== X-Google-Smtp-Source: AGHT+IH0/hEWrV52DVmrj7Z6n0WIT9Ut3IVouygX8jmB/XLHKPkNRIO9up6ksFd2vuXYZmCZkrEILwBAMRRP X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:acc7:bda:7167:18d8]) (user=irogers job=sendgmr) by 2002:a25:d843:0:b0:e29:7454:e773 with SMTP id 3f1490d57ef6-e337e1d738cmr33276.5.1730996442881; Thu, 07 Nov 2024 08:20:42 -0800 (PST) Date: Thu, 7 Nov 2024 08:20:28 -0800 In-Reply-To: <20241107162035.52206-1-irogers@google.com> Message-Id: <20241107162035.52206-2-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241107162035.52206-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.199.ga7371fff76-goog Subject: [PATCH v2 1/8] perf jevents: fix breakage when do perf stat on system metric From: Ian Rogers To: John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , 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 , Huacai Chen , Bibo Mao , Athira Rajeev , Ben Zong-You Xie , Alexandre Ghiti , Sandipan Das , Benjamin Gray , Xu Yang , Ravi Bangoria , "=?UTF-8?q?Cl=C3=A9ment=20Le=20Goffic?=" , Yicong Yang , "Masami Hiramatsu (Google)" , Dima Kogan , "Dr. David Alan Gilbert" , linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org Cc: stable@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Xu Yang When do perf stat on sys metric, perf tool output nothing now: $ perf stat -a -M imx95_ddr_read.all -I 1000 $ This command runs on an arm64 machine and the Soc has one DDR hw pmu except one armv8_cortex_a55 pmu. Their maps show as follows: const struct pmu_events_map pmu_events_map[] =3D { { .arch =3D "arm64", .cpuid =3D "0x00000000410fd050", .event_table =3D { .pmus =3D pmu_events__arm_cortex_a55, .num_pmus =3D ARRAY_SIZE(pmu_events__arm_cortex_a55) }, .metric_table =3D { .pmus =3D NULL, .num_pmus =3D 0 } }, static const struct pmu_sys_events pmu_sys_event_tables[] =3D { { .event_table =3D { .pmus =3D pmu_events__freescale_imx95_sys, .num_pmus =3D ARRAY_SIZE(pmu_events__freescale_imx95_sys) }, .metric_table =3D { .pmus =3D pmu_metrics__freescale_imx95_sys, .num_pmus =3D ARRAY_SIZE(pmu_metrics__freescale_imx95_sys) }, .name =3D "pmu_events__freescale_imx95_sys", }, Currently, pmu_metrics_table__find() will return NULL when only do perf stat on sys metric. Then parse_groups() will never be called to parse sys metric_name, finally perf tool will exit directly. This should be a common problem. To fix the issue, this will keep the logic before commit f20c15d13f01 ("perf pmu-events: Remember the perf_events_map for a PMU") to return a empty metric table rather than a NULL pointer. This should be fine since the removed part just check if the table match provided metric_name. Without these code, the code in parse_groups() will also check the validity of metrci_name too. Fixes: f20c15d13f01 ("perf pmu-events: Remember the perf_events_map for a P= MU") Cc: stable@vger.kernel.org Signed-off-by: Xu Yang Acked-by: Ian Rogers Signed-off-by: Ian Rogers --- tools/perf/pmu-events/empty-pmu-events.c | 12 +----------- tools/perf/pmu-events/jevents.py | 12 +----------- 2 files changed, 2 insertions(+), 22 deletions(-) diff --git a/tools/perf/pmu-events/empty-pmu-events.c b/tools/perf/pmu-even= ts/empty-pmu-events.c index 2b7516946ded..b8719dab264d 100644 --- a/tools/perf/pmu-events/empty-pmu-events.c +++ b/tools/perf/pmu-events/empty-pmu-events.c @@ -585,17 +585,7 @@ const struct pmu_metrics_table *perf_pmu__find_metrics= _table(struct perf_pmu *pm if (!map) return NULL; =20 - if (!pmu) - return &map->metric_table; - - for (size_t i =3D 0; i < map->metric_table.num_pmus; i++) { - const struct pmu_table_entry *table_pmu =3D &map->metric_t= able.pmus[i]; - const char *pmu_name =3D &big_c_string[table_pmu->pmu_name= .offset]; - - if (pmu__name_match(pmu, pmu_name)) - return &map->metric_table; - } - return NULL; + return &map->metric_table; } =20 const struct pmu_events_table *find_core_events_table(const char *arch, co= nst char *cpuid) diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jeven= ts.py index 6e71b09dbc2a..70f4fd5395fb 100755 --- a/tools/perf/pmu-events/jevents.py +++ b/tools/perf/pmu-events/jevents.py @@ -1101,17 +1101,7 @@ const struct pmu_metrics_table *perf_pmu__find_metri= cs_table(struct perf_pmu *pm if (!map) return NULL; =20 - if (!pmu) - return &map->metric_table; - - for (size_t i =3D 0; i < map->metric_table.num_pmus; i++) { - const struct pmu_table_entry *table_pmu =3D &map->metric_t= able.pmus[i]; - const char *pmu_name =3D &big_c_string[table_pmu->pmu_name= .offset]; - - if (pmu__name_match(pmu, pmu_name)) - return &map->metric_table; - } - return NULL; + return &map->metric_table; } =20 const struct pmu_events_table *find_core_events_table(const char *arch, co= nst char *cpuid) --=20 2.47.0.199.ga7371fff76-goog