From nobody Tue Dec 16 03:25:18 2025 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.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 652E7241664 for ; Wed, 9 Jul 2025 21:40:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752097239; cv=none; b=DoIff9f16SYhsWkt+qefyDoJ4TYKms7mjyxBSkfq1m0fKHGXhzLe1K6lKL9jdji42fvfd+47vW1XhKo4squTR6kyECq1mSYS3m/48rKS5EfhTJDjiuGsjqi8uPTfb0/WXm/pDDWDPzpTHSw+Y8hd4IjeyJdHoYR5jf1dX1RnSPg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752097239; c=relaxed/simple; bh=1lk85E3pggo+4g2GknSYWSWNs6o0Mw8jBXtuFvYNkFU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=L56Y3uv+a/cXcIXAOG9CYo1hum+5RSch0B56GD27TizTRg9OxLejDyMfjFFXgjCv60yGl4pgxWrAsQXP4+6n33wHQE1YOd4ntg8x2NTqm8CuWB0T9Jz45xTDJiTyY3dDt9F0Th0YsjEwsdgq8dwCqmYDgUG869/i6yGTjlKOfvg= 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=FScjL0Rs; arc=none smtp.client-ip=209.85.210.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="FScjL0Rs" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-748efefedb5so258867b3a.2 for ; Wed, 09 Jul 2025 14:40:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1752097235; x=1752702035; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=1RNkMgAEj4/GnB7BeI8C0UUIpPaOTXLCNgb+45zsMxs=; b=FScjL0RsBI9fOqixWgw+s3e0+ZVU6uRoglAfNGTOq4KMPjaGwfvlvsO3bneN9Sg+Rs j6q+LX5Ds0EbGDcGfdcZqXXwQQo4/0Q+rBJqjt3hLjnFzpbWs0iE0E/6oCSqSQF/zAjm 6tl976wwpI83zeobotT8tN+5t91xiVigcPGyAt2wRxXHeJt04PhRaN5nKhFx+nOGh5MA BYXDpDFt4cB1A9JTOCB2k3cGM6+9jmJmY/I3yyOIyJnpK59wsEAjnSW2CLGMf2TNtTga +j0cEU7uyN34aMcuf4ErsRIv8ywSMD+FeTYrioFJaMHeTmyOjbhAFlhdHTWzOlF2QdI0 A/pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752097235; x=1752702035; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=1RNkMgAEj4/GnB7BeI8C0UUIpPaOTXLCNgb+45zsMxs=; b=rz4PcfAJiBO3PhPWyXVPTffVCHlcVukE/+FK/cHymt/uG6z4K8N6vVrrss3ZB5E18o kwDUhebzj2CkUJNag4yoW0lqpELkZtdxYs5kXSqaUrW6DLWost7nKN0bXia4T56R0xqa x70/lNcYvqHSPEUsVjX/3D6ZY8ETzLkkHudGbCekZeXfA853/JaVMmzJb7t3U2yVYzTu kPM/ckxKTpSj/DWmyiieNuLXRhUlEQVC9Ukhiny8Y1LSwJ/vipsR9o31Bd217MtUBNrk +kx1iPSZeUhsvPu2r4KhHjX4yZGFr10HNpXiQsME/lyZWCu7NUcLGMrmaZ3ZSaIhlx9l XvHg== X-Forwarded-Encrypted: i=1; AJvYcCVBP3+N4uaU0qWevXXi6wiwlMuwbRPRluY4k6Og4uXxK/1YxtSahkmzLkXY7N7LPc4CRIxe3p0SoEPgoGs=@vger.kernel.org X-Gm-Message-State: AOJu0YyS+ekJNpnkVYRzzy+lzjhKRf9vfA+GToodFh2s5iEuy7LimFY2 nRnznA6faAcouhkKW46XV+14MqzMk10lOCw14PYkLA4hmcPWsT060mPfGveQlPGYmtY+Do8Fv3X bPlhXtJQWOA== X-Google-Smtp-Source: AGHT+IH2bEm5D5vL0/SOlKgLMUnkYuyDxrvhEh8Sk1TmdRPm6c9OAhUY7JUi0TVyz5YNrku0Gkgejj3nrlBH X-Received: from pgr1.prod.google.com ([2002:a63:1141:0:b0:b2f:a31c:f7bc]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:6e91:b0:215:efed:acfc with SMTP id adf61e73a8af0-22cd5a06069mr6978021637.7.1752097235636; Wed, 09 Jul 2025 14:40:35 -0700 (PDT) Date: Wed, 9 Jul 2025 14:40:18 -0700 In-Reply-To: <20250709214029.1769089-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250709214029.1769089-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250709214029.1769089-2-irogers@google.com> Subject: [PATCH v1 01/12] perf hwmon_pmu: Avoid shortening hwmon PMU name 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 , Xu Yang , Howard Chu , "Dr. David Alan Gilbert" , Levi Yun , Andi Kleen , Thomas Richter , Weilin Wang , Tiezhu Yang , Gautam Menghani , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Long names like ucsi_source_psy_USBC000:001 when prefixed with hwmon_ exceed the buffer size and the last digit is lost. This causes confusion with similar names like ucsi_source_psy_USBC000:002. Extend the buffer size to avoid this. Fixes: 53cc0b351ec9 ("perf hwmon_pmu: Add a tool PMU exposing events from h= wmon in sysfs") Signed-off-by: Ian Rogers --- tools/perf/util/hwmon_pmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/util/hwmon_pmu.c b/tools/perf/util/hwmon_pmu.c index 7edda010ba27..416dfea9ffff 100644 --- a/tools/perf/util/hwmon_pmu.c +++ b/tools/perf/util/hwmon_pmu.c @@ -345,7 +345,7 @@ static int hwmon_pmu__read_events(struct hwmon_pmu *pmu) struct perf_pmu *hwmon_pmu__new(struct list_head *pmus, const char *hwmon_= dir, const char *sysfs_name, const char *name) { - char buf[32]; + char buf[64]; struct hwmon_pmu *hwm; __u32 type =3D PERF_PMU_TYPE_HWMON_START + strtoul(sysfs_name + 5, NULL, = 10); =20 --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Tue Dec 16 03:25:18 2025 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.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 DF80C21FF39 for ; Wed, 9 Jul 2025 21:40:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752097240; cv=none; b=PQGPmRlRo0EPPcbM+yskDJNFPw8awvIb1nlW5epBVQrPPxaMj34u3qsRoyCLrKLMVlhYMlgZRXLeKes3Ix02lhutn2Ew9oLLM+cUuGLZuzTSe3A9tDXdaJ1YLl5oJf8FRJNY0AYfyLKoadEr2DrQxB6RswYKWYlPN532oPp4S84= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752097240; c=relaxed/simple; bh=SCSVRXj5DB/cfKYLIvAW2+qqqcd9DzSoDst4X0cpuZc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=IiE6E76RU/5jbUlTnkoPO95xigOq+espd7p3P1cGeL7+fR+f8hlJqfiaYObgD3CeJJMbdykKMnhYjqq6jzk3LU+kvHS5Fgov1PtiqYjeUb+lIddyiFQoCf9pqzmK95u4J70Uckj/cCblzxnRHLgsFe279GU3NnILTlOcEeRzgvI= 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=Y0BOpsuU; arc=none smtp.client-ip=209.85.215.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="Y0BOpsuU" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-b31f112c90aso229504a12.0 for ; Wed, 09 Jul 2025 14:40:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1752097238; x=1752702038; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=uM9b0q174RElAGAUOsRC1+X9nDdEI4t5lPgRji4c5mk=; b=Y0BOpsuUIGsy3gWSx0LPqxrT2TyUQqsjK2c0lOykR4xIAxUL/xhYx9WPaxYYYzub8A HG/XCuEYV1y5XkuFoNDFLZXw92xkwkLAUsVl6WvwHSnFVeFp0dAGHe2UbCj8V4woTMdp v4Ud1Ou5EutbVMQNwqxbcdbhOfG8Z/5I3OsP7Pbve/IDmcLj2ZEgrCEz3OOOcM+pDngg o/OxVoozsmb0ny5USi0Qd6Bx1j6qTAgYctyZxRW/kaN5plkBYBGFdT0vmmD1KPUWOVuh 71ukpZdc9Upb2kAGKKjEnWbFxw15pVYCRpqkTfo+NxAWnOepAu6AHha03q/602aV7ZGY u1aQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752097238; x=1752702038; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=uM9b0q174RElAGAUOsRC1+X9nDdEI4t5lPgRji4c5mk=; b=jevY59wEg6x7u0Essy+xeWFlHvBPukv0QCveJSL7lAD38XMEeaiufUwag1+7VZxCgw d4sfLkWev3kIs89LTc4+zGAPvkMX/rRGUsVFyr8IRe+XS8pGmk8PctffK6T776b3s2dH GE3dNb/6mX2taG/vGa8OjoNpOcJ9qt/tcVrXrndvvb2meIJJSP6SuFvxxzfQ2gacDzSP xh1w171Q4qab1qfZ9R+VgLgkWGpGju9eeqd2tmcz6crLW3lvVmOVxpn34Hro1dmNNqrX e7aXYNxisEYoSoy4NAc7yzSTznlgdoXW+3Vmh6CktbRyaH8rXzJQcemsWQXieR9ElIkU vZlA== X-Forwarded-Encrypted: i=1; AJvYcCXxk7Bv9xzL7kR8qARVju/BMtwJD3Fbv1D9S63orFjUyGNcNMp+wodOkkKMa1HuCNjW0i5kEY7kaxeytjM=@vger.kernel.org X-Gm-Message-State: AOJu0YyxeRhSGbF0dJlvjkZY6HWbjZ28tMVoDnO9s/BxS6yOwD/19p1j oicLW9WjFWOognLN5XWb+sKbaxn6hYzmcrXPJ6bQj2CSBvxwVeL8drxdOzJFxTVvV343fKN9kLI gQI7EQ1hDFQ== X-Google-Smtp-Source: AGHT+IFltfmQBS7U87C0TdDrtf1ntKrR6/OIw7n3Wyza61DuU6qTE108cX1iKXZNifSy30Gaf+LTVp5Ftm1u X-Received: from pjqq12.prod.google.com ([2002:a17:90b:584c:b0:314:3438:8e79]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90a:d40c:b0:313:d361:73d7 with SMTP id 98e67ed59e1d1-31c3cf9aaffmr1475713a91.13.1752097237503; Wed, 09 Jul 2025 14:40:37 -0700 (PDT) Date: Wed, 9 Jul 2025 14:40:19 -0700 In-Reply-To: <20250709214029.1769089-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250709214029.1769089-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250709214029.1769089-3-irogers@google.com> Subject: [PATCH v1 02/12] perf parse-events: Minor tidy up of event_type 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 , Xu Yang , Howard Chu , "Dr. David Alan Gilbert" , Levi Yun , Andi Kleen , Thomas Richter , Weilin Wang , Tiezhu Yang , Gautam Menghani , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add missing breakpoint and raw types. Avoid a switch, just use a lookup array. Switch the type to unsigned to avoid checking negative values. Signed-off-by: Ian Rogers --- tools/perf/util/parse-events.c | 31 +++++++++++++------------------ tools/perf/util/parse-events.h | 2 +- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 4cd64ffa4fcd..a59ae5ca0f89 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -135,26 +135,21 @@ const struct event_symbol event_symbols_sw[PERF_COUNT= _SW_MAX] =3D { }, }; =20 -const char *event_type(int type) -{ - switch (type) { - case PERF_TYPE_HARDWARE: - return "hardware"; - - case PERF_TYPE_SOFTWARE: - return "software"; - - case PERF_TYPE_TRACEPOINT: - return "tracepoint"; - - case PERF_TYPE_HW_CACHE: - return "hardware-cache"; +static const char *const event_types[] =3D { + [PERF_TYPE_HARDWARE] =3D "hardware", + [PERF_TYPE_SOFTWARE] =3D "software", + [PERF_TYPE_TRACEPOINT] =3D "tracepoint", + [PERF_TYPE_HW_CACHE] =3D "hardware-cache", + [PERF_TYPE_RAW] =3D "raw", + [PERF_TYPE_BREAKPOINT] =3D "breakpoint", +}; =20 - default: - break; - } +const char *event_type(size_t type) +{ + if (type >=3D PERF_TYPE_MAX) + return "unknown"; =20 - return "unknown"; + return event_types[type]; } =20 static char *get_config_str(const struct parse_events_terms *head_terms, diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h index 1c20ed0879aa..b47bf2810112 100644 --- a/tools/perf/util/parse-events.h +++ b/tools/perf/util/parse-events.h @@ -21,7 +21,7 @@ struct option; struct perf_pmu; struct strbuf; =20 -const char *event_type(int type); +const char *event_type(size_t type); =20 /* Arguments encoded in opt->value. */ struct parse_events_option_args { --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Tue Dec 16 03:25:18 2025 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5D41124466F for ; Wed, 9 Jul 2025 21:40:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752097241; cv=none; b=DtRQWtYxcWerfbS0NwSujAy+41JQ4yLW+x/6eCstJqQ9Axcx2JqmnsJ5EJEOWNlccF0pmOMU3wcf5HYUVXC5ZYKhdunw/TZ2hls6t1/H/gQj21D0RjuqOjbYYO5p8rKEhJJh2jtbYkymtMxzqtmXBso9vgJxyEULuKMu678wR+c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752097241; c=relaxed/simple; bh=4RhnUIdDBTq0pKyjxJeOi7qIuV8UBI3E2+4jD3YcP7M=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=LhOT0LP33NYETJxN04Ymcjz30odt9EmyoQWpyp2GpR8ga5jf5YOmpGfY0XAbEFO9xLSKCqx/wXndwheYKHgP/9XZwnwwBBFVnfhQAc8M5tWPJw5n9p4ZvFKwHQMpJ6NjQLoDiCdpe8dSVvG099filp3XbEFnurZxEP3LEcdaAB4= 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=o8lTCzpa; arc=none smtp.client-ip=209.85.214.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="o8lTCzpa" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-235e3f93687so4281715ad.2 for ; Wed, 09 Jul 2025 14:40:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1752097239; x=1752702039; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=tRZkm/myoY8JXQXFYiK3d6FXz7MSloychwQltzDxXbc=; b=o8lTCzpankEju9ZY/zHFZ2grfNnZExQK88ExddhOE0vAVt4O990tGW8znkvBQdODO+ iVZgoJ6s/+K+jWeDumaFDeKYZv0F/4uTW0pQV7wUlf7+WIDdAL2boUGWSxJzeFKQYHL9 c3cktyT1loomwDkTbCHCNSaYnwd5H+lzpSn/gXjXYatd3eBriK3OEs0Aeu2H15EX1vVa gwB9MFSJMQvHc8P5RnEmhreBsEewfQF15FctnDPo7qnTdicOWNlqhamVBBuIGaZn0tD4 N+e2YVltPwOrIMEHvxdiOhnPtLnx+dc7uLY9Zk68jBIKVv89K2EI/SlPsV7YneV50kIe N3Fw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752097239; x=1752702039; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=tRZkm/myoY8JXQXFYiK3d6FXz7MSloychwQltzDxXbc=; b=hK5eWaD7PJ84T3Cu17zTn46N2dyXW69VgOrErjmTk5sJei1Q86BqNrwFX6CP63EHBj mNrqU1cwp/owN9F9dLsr1QDHolM9krQx6A9uZtjNijDZeVS9/mqQrytgg5Sd4pSaR1Dt MXVlrIgIldueMUu3Lw3oPtyGzpJp8k8s1p/CSQjUSoHCmNBBqHswTxxGQo2vtq+kLzzB sWigLmjNRE7YeOc3powQ427EDLuTaSVQwpPKrOd5vg81qytvkoDAdbetM9fAbxj2bFsk 9qh45GuRi7YBYdfhLHKEudhMFcVOHq/D0/ZATUnjdZ3wmsP6fZrVbiMxxKlzDcEiB2JQ 9Mrg== X-Forwarded-Encrypted: i=1; AJvYcCWf2+WTHlVRGb5/lEh/LhkiC87t6JNOulqL5FaxCPcumajt6XJJ5H+P4eZL+s0cGXr9ArGH6X00ZyljFCo=@vger.kernel.org X-Gm-Message-State: AOJu0Yw4qy4bnhXLrVsA/wg0TfdJ/yowsTFVxLo89PCI1/Ff8bWUE0fg 8vPW/0qxwg7Bb3U9WD1sJY0MrTvlKq/SafNcJuq5yQS7rqGlvc49ruVEyFxGWIvpt1NODBEmjPd WfGaxMss35g== X-Google-Smtp-Source: AGHT+IGZ5grGeIuw5glQVkklBxNEKKxomcSYAQGiwSohPNNQHUy7vJojGsm5h6sCDpZq0PO+bkWJuZ69hg1F X-Received: from pgar20.prod.google.com ([2002:a05:6a02:2e94:b0:b2e:c00e:65ed]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:240a:b0:236:9402:a622 with SMTP id d9443c01a7336-23de4872c01mr289295ad.34.1752097239690; Wed, 09 Jul 2025 14:40:39 -0700 (PDT) Date: Wed, 9 Jul 2025 14:40:20 -0700 In-Reply-To: <20250709214029.1769089-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250709214029.1769089-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250709214029.1769089-4-irogers@google.com> Subject: [PATCH v1 03/12] perf spark: Fix includes and add SPDX 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 , Xu Yang , Howard Chu , "Dr. David Alan Gilbert" , Levi Yun , Andi Kleen , Thomas Richter , Weilin Wang , Tiezhu Yang , Gautam Menghani , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" scnprintf is declared in linux/kernel.h, directly depend upon it. Add missing SPDX comments. Signed-off-by: Ian Rogers --- tools/perf/util/spark.c | 8 +++----- tools/perf/util/spark.h | 1 + 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/tools/perf/util/spark.c b/tools/perf/util/spark.c index 70272a8b81a6..65ca253cc22e 100644 --- a/tools/perf/util/spark.c +++ b/tools/perf/util/spark.c @@ -1,9 +1,7 @@ -#include -#include -#include -#include +// SPDX-License-Identifier: GPL-2.0 #include "spark.h" -#include "stat.h" +#include +#include =20 #define SPARK_SHIFT 8 =20 diff --git a/tools/perf/util/spark.h b/tools/perf/util/spark.h index 25402d7d7a64..78597c38ef35 100644 --- a/tools/perf/util/spark.h +++ b/tools/perf/util/spark.h @@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: GPL-2.0 */ #ifndef SPARK_H #define SPARK_H 1 =20 --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Tue Dec 16 03:25:18 2025 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.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 5EE9623D2B6 for ; Wed, 9 Jul 2025 21:40:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752097243; cv=none; b=GdRJOGHoRovchbi9Nl8DO40nGT8R2va0VcgNo1Lmxs8hZPLMWuDXMjjquQSfZTGGQEalAOGB9FbA22hZf0vAwifY+J+UcIRd2kIx0Z9Rg53fBZa85ZMYkBPvPHzKO3Aj+bqxQlZVOuZD8UtrYh6w3BB+yrVCRMcOIaD0MVKZq34= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752097243; c=relaxed/simple; bh=8+fzwKbYyh0HgEc4+oNZYk8ZhmbZCi8quzaYQRyDMRY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=KYpDEaL5qo5mNRPeJDxs3OUeLGHuLssDZgRXk8jyQeJ2r8zYnKEcex+/e4ArkDc2zV6S+Ld0XE6eHqi08chMDWdfUjYVFgt3YFJd+Rk8Xev0e7pPpAU6YJ99iy1LEy/TrhAzJete8o348DBO+yCkV9zdHulsNqYYRblsV/+TdgI= 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=rcZzNcEr; arc=none smtp.client-ip=209.85.215.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="rcZzNcEr" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-b321087b1cdso367431a12.2 for ; Wed, 09 Jul 2025 14:40:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1752097242; x=1752702042; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=jB43BWOgr1OVnJk/vG7v3SNwpLjEdqHnInxVydle4NQ=; b=rcZzNcErVyUuTI4nsH102cf2L0gjFgkGyi/lkxRnA6lyu0g5JYxVWkdTUKCiNsDB+b oUR/bYiFVEeWlCFFSH1FATj7QVs2+ryEDDtknIDMQil7DOFSJhDG15e3X3s+IVzegF6s OF/SYE+tSvZhQm4/xxY+nxuvBJqsknwr4K9A5SrdOgm62HYfXl3EaoH/Bd36Idr4X2OA kUZB1wDkjMYWiNgmTln85kE+/IH/kTyn+2m/felf7HY6f/U2A5JT4WYWw5QdQIeC8vKY fRke8VBXAA7DEEucWqh3oTNwYFyI2jsOLhPsjIqj+c1jgvkKn4KUlypZ5uL73n1zN40r ntgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752097242; x=1752702042; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=jB43BWOgr1OVnJk/vG7v3SNwpLjEdqHnInxVydle4NQ=; b=xS1mBxB7V5GDyB+I3oEqN9EDynZXZ/kxnxyUMgpseBkZacKi7Rrc4e2z2bMnKJhZlR aJCrt3aQnRkOoJ7dyLRgCgfNwmoTmVLv7zHSS57KB8t8clMRfwQ/C3fPjbv7pk6irr1X KVdH37vQNIPVQFuxGji6dmXGTpfikzM0ODay0aX0/QPzYrR+wjlApC8LtfYPVfm9G8ag ZaJ8lCTFLFlwfSoIk6mGwOfYI/e3hpvMhHVxyYLCvcAN1nzYyAsFBlRI2EQ4cUEncvA5 dDSkt46yPmmQnx7dTg85IRM7tOW2IcJFyL3TWIt6rHX5ACXV+49KIWxcICopMCYqIxW2 bLyw== X-Forwarded-Encrypted: i=1; AJvYcCWzQHF0J/fj3IzmB6IrvumUuIeaLRzdecLzIx1p2NVCeZjpt9YvwOAd9hLnfd0la/kK4nOX76lgARoHDz0=@vger.kernel.org X-Gm-Message-State: AOJu0YzHYLmDffCooIAKGDjQb5+/ssykGaLoET63HXEDU/5yGx9yrRqy ZOUNkhqkwAuEbIKt6yLL3DXp+sm4v8IomidpKa69xNP9jxVLtJ3LSV0iENtOza9FexICL+D5HW6 youhpQFAT5Q== X-Google-Smtp-Source: AGHT+IEBtciJsh8xRDvIq+Sgsncs0zNYJD3rc0jF/WOqfdg3f+RccueHuYWIQOWwgAEZQpSuy2QQRcospvlu X-Received: from pgdk7.prod.google.com ([2002:a05:6a02:5467:b0:b31:c7e5:6664]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:7489:b0:220:9c00:6879 with SMTP id adf61e73a8af0-230045c6577mr308556637.17.1752097241840; Wed, 09 Jul 2025 14:40:41 -0700 (PDT) Date: Wed, 9 Jul 2025 14:40:21 -0700 In-Reply-To: <20250709214029.1769089-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250709214029.1769089-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250709214029.1769089-5-irogers@google.com> Subject: [PATCH v1 04/12] perf pmu: Tolerate failure to read the type for wellknown PMUs 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 , Xu Yang , Howard Chu , "Dr. David Alan Gilbert" , Levi Yun , Andi Kleen , Thomas Richter , Weilin Wang , Tiezhu Yang , Gautam Menghani , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" If sysfs isn't mounted then we may fail to read a PMU's type. In this situation resort to lookup of wellknown types. Only applies to software, tracepoint and breakpoint PMUs. Signed-off-by: Ian Rogers --- tools/perf/util/pmu.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index f795883c233f..23666883049d 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -1182,6 +1182,32 @@ int perf_pmu__init(struct perf_pmu *pmu, __u32 type,= const char *name) return 0; } =20 +static __u32 wellknown_pmu_type(const char *pmu_name) +{ + struct { + const char *pmu_name; + __u32 type; + } wellknown_pmus[] =3D { + { + "software", + PERF_TYPE_SOFTWARE + }, + { + "tracepoint", + PERF_TYPE_TRACEPOINT + }, + { + "breakpoint", + PERF_TYPE_BREAKPOINT + }, + }; + for (size_t i =3D 0; i < ARRAY_SIZE(wellknown_pmus); i++) { + if (!strcmp(wellknown_pmus[i].pmu_name, pmu_name)) + return wellknown_pmus[i].type; + } + return PERF_TYPE_MAX; +} + struct perf_pmu *perf_pmu__lookup(struct list_head *pmus, int dirfd, const= char *name, bool eager_load) { @@ -1201,8 +1227,12 @@ struct perf_pmu *perf_pmu__lookup(struct list_head *= pmus, int dirfd, const char * that type value is successfully assigned (return 1). */ if (perf_pmu__scan_file_at(pmu, dirfd, "type", "%u", &pmu->type) !=3D 1) { - perf_pmu__delete(pmu); - return NULL; + /* Double check the PMU's name isn't wellknown. */ + pmu->type =3D wellknown_pmu_type(name); + if (pmu->type =3D=3D PERF_TYPE_MAX) { + perf_pmu__delete(pmu); + return NULL; + } } =20 /* --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Tue Dec 16 03:25:18 2025 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.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 7552025484A for ; Wed, 9 Jul 2025 21:40:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752097246; cv=none; b=ZZ/QbVnJ92JuPb9/EwdG4uADuIHfXCAr3NHFbs54ebMfDUvV7BinEbYWITRcM3eq7tMkRgdU6SfMyDNXRQ/i3/6CdeH0hER8ycb6pceThJq4TBLwP/yxwkeW8nQMw6ramqViEM6ub1UaSUNJ+5jocg+t0HigFFJvAEYDgLgTq/0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752097246; c=relaxed/simple; bh=w5eNqcWn2O0y6EMKp9jCIupHTttD6lDBxXRkCF1rGCU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=Mc/QVByY8d8YWu3ZLdCh2XVABQeEglV+tgElkI858pPKXpTpXw3vvKRT80Zot8eJZANQI8DGqygQ9VokMbnDlFF4oA9MzQ+VNpN858sSdT745nm/ahdFPAlNkwHgkZp3Fg1AgRD1NeP6+aSI8mCPYsZ9FjZNhfc52jqa+laGGAA= 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=taEcZ6KU; arc=none smtp.client-ip=209.85.210.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="taEcZ6KU" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-7492da755a1so215216b3a.1 for ; Wed, 09 Jul 2025 14:40:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1752097244; x=1752702044; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=NoNwchClBb7Gcfk0e4XraPQtQcpY/XFOcoy596WayHU=; b=taEcZ6KUZWJ9OKaeovOI+2PRWrN1EjFzKt9M3Q5+HgwASQTWSUVl5V0IO36MV7YYHV SBo+nNW6oTX1u7LfmhL7DX+sHmAmNbtg2ABQD0rvClXe1pqdZWqIzL4bi5OhGA2CeDwz U/9wWt2yAaWPB0nhrTFoSIR9Ga0lkrrVluT9KCrcGHNesVmCQ9HFQtOhl8/FSPcQYnfW DB5nPb9Nx5b62M9PHiNot5eb2Yw546PK/QK/k9cZ8KIdhFP9BUKV3XpJh7HghJtXEhbQ DaiU/PYHIr277KiEiE/R+T5fAbDCnhBx+34kVs1fV0zPUC/5qBZvd+n7DNg7Hg/O5JuC pOBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752097244; x=1752702044; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=NoNwchClBb7Gcfk0e4XraPQtQcpY/XFOcoy596WayHU=; b=amm3Xm+yWrSBs70QuJlePn2m5oSCbGFRX1nF583PSZO6KL1EuzxzE1zcGCQSWjoQsf p3YY13mtKcW3sitDMZM0wLbvuj8xDy/HN4GOo5aPKyjmeTFVmXmTcWh3qliPqDLlRcp2 HAuZzs13NUvOVx7mwOdgsHHzANadELE4/umtbPdfvYW5jxpCufMtRzTqUPSPXuwi5LHH ca29gL9o05nOrOXaCa52nR05fXHNh+KI1QMhwn4U1VadJo4PU2NRZI2pb2WGQkKQLH7p ZWEoUPBDZm8JulLfM6guV4FbsfLd7FymOg6Ixa6FcFGNo8m8af3PYswV32HjIhpE+zlD yYVA== X-Forwarded-Encrypted: i=1; AJvYcCWC8+W1n0h4kMtKx/qr01grfNnwcNrd6yv3kl9xSb4JkG+73Guk4tnDavQvYgKzanR0gpHH8YZ5JhQLtfY=@vger.kernel.org X-Gm-Message-State: AOJu0YzUQbUTiDngZhshcn/DCEUYw+T5gzix4Ifg88o1Fx47vHbW5PKv 8iZB2Z3sn+if8YWvj8dcLMf91VKyQh888Njge9NkedM8PHaq78SUUWUUNs+Mkvnmr50O8DXMJxk E/jnmfxyOAA== X-Google-Smtp-Source: AGHT+IHbQDBQev54wBPYAaHigKEDot5pz607jOo3YDSKBnzEYxbdvLW+Vqi8za47wrF7vtQtUAhBb2vfXcB1 X-Received: from pgjh9.prod.google.com ([2002:a63:df49:0:b0:b32:1431:4415]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6300:614e:b0:21f:5aa1:3124 with SMTP id adf61e73a8af0-230040daa2fmr342549637.13.1752097243758; Wed, 09 Jul 2025 14:40:43 -0700 (PDT) Date: Wed, 9 Jul 2025 14:40:22 -0700 In-Reply-To: <20250709214029.1769089-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250709214029.1769089-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250709214029.1769089-6-irogers@google.com> Subject: [PATCH v1 05/12] perf metricgroup: Factor out for-each function and move out printing 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 , Xu Yang , Howard Chu , "Dr. David Alan Gilbert" , Levi Yun , Andi Kleen , Thomas Richter , Weilin Wang , Tiezhu Yang , Gautam Menghani , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Factor metricgroup__for_each_metric into its own function handling regular and sys metrics. Make the metric adding and printing code use it, move the printing code into print-events files. Signed-off-by: Ian Rogers --- tools/perf/util/metricgroup.c | 241 ++++----------------------------- tools/perf/util/metricgroup.h | 3 +- tools/perf/util/print-events.c | 133 ++++++++++++++++++ tools/perf/util/print-events.h | 2 + 4 files changed, 165 insertions(+), 214 deletions(-) diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index 43d35f956a33..ddd5c362d183 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -384,107 +384,6 @@ static bool match_pm_metric_or_groups(const struct pm= u_metric *pm, const char *p match_metric_or_groups(pm->metric_name, metric_or_groups); } =20 -/** struct mep - RB-tree node for building printing information. */ -struct mep { - /** nd - RB-tree element. */ - struct rb_node nd; - /** @metric_group: Owned metric group name, separated others with ';'. */ - char *metric_group; - const char *metric_name; - const char *metric_desc; - const char *metric_long_desc; - const char *metric_expr; - const char *metric_threshold; - const char *metric_unit; - const char *pmu_name; -}; - -static int mep_cmp(struct rb_node *rb_node, const void *entry) -{ - struct mep *a =3D container_of(rb_node, struct mep, nd); - struct mep *b =3D (struct mep *)entry; - int ret; - - ret =3D strcmp(a->metric_group, b->metric_group); - if (ret) - return ret; - - return strcmp(a->metric_name, b->metric_name); -} - -static struct rb_node *mep_new(struct rblist *rl __maybe_unused, const voi= d *entry) -{ - struct mep *me =3D malloc(sizeof(struct mep)); - - if (!me) - return NULL; - - memcpy(me, entry, sizeof(struct mep)); - return &me->nd; -} - -static void mep_delete(struct rblist *rl __maybe_unused, - struct rb_node *nd) -{ - struct mep *me =3D container_of(nd, struct mep, nd); - - zfree(&me->metric_group); - free(me); -} - -static struct mep *mep_lookup(struct rblist *groups, const char *metric_gr= oup, - const char *metric_name) -{ - struct rb_node *nd; - struct mep me =3D { - .metric_group =3D strdup(metric_group), - .metric_name =3D metric_name, - }; - nd =3D rblist__find(groups, &me); - if (nd) { - free(me.metric_group); - return container_of(nd, struct mep, nd); - } - rblist__add_node(groups, &me); - nd =3D rblist__find(groups, &me); - if (nd) - return container_of(nd, struct mep, nd); - return NULL; -} - -static int metricgroup__add_to_mep_groups(const struct pmu_metric *pm, - struct rblist *groups) -{ - const char *g; - char *omg, *mg; - - mg =3D strdup(pm->metric_group ?: pm->metric_name); - if (!mg) - return -ENOMEM; - omg =3D mg; - while ((g =3D strsep(&mg, ";")) !=3D NULL) { - struct mep *me; - - g =3D skip_spaces(g); - if (strlen(g)) - me =3D mep_lookup(groups, g, pm->metric_name); - else - me =3D mep_lookup(groups, pm->metric_name, pm->metric_name); - - if (me) { - me->metric_desc =3D pm->desc; - me->metric_long_desc =3D pm->long_desc; - me->metric_expr =3D pm->metric_expr; - me->metric_threshold =3D pm->metric_threshold; - me->metric_unit =3D pm->unit; - me->pmu_name =3D pm->pmu; - } - } - free(omg); - - return 0; -} - struct metricgroup_iter_data { pmu_metric_iter_fn fn; void *data; @@ -510,54 +409,22 @@ static int metricgroup__sys_event_iter(const struct p= mu_metric *pm, return 0; } =20 -static int metricgroup__add_to_mep_groups_callback(const struct pmu_metric= *pm, - const struct pmu_metrics_table *table __maybe_unused, - void *vdata) +int metricgroup__for_each_metric(const struct pmu_metrics_table *table, pm= u_metric_iter_fn fn, + void *data) { - struct rblist *groups =3D vdata; - - return metricgroup__add_to_mep_groups(pm, groups); -} - -void metricgroup__print(const struct print_callbacks *print_cb, void *prin= t_state) -{ - struct rblist groups; - const struct pmu_metrics_table *table; - struct rb_node *node, *next; + struct metricgroup_iter_data sys_data =3D { + .fn =3D fn, + .data =3D data, + }; =20 - rblist__init(&groups); - groups.node_new =3D mep_new; - groups.node_cmp =3D mep_cmp; - groups.node_delete =3D mep_delete; - table =3D pmu_metrics_table__find(); if (table) { - pmu_metrics_table__for_each_metric(table, - metricgroup__add_to_mep_groups_callback, - &groups); - } - { - struct metricgroup_iter_data data =3D { - .fn =3D metricgroup__add_to_mep_groups_callback, - .data =3D &groups, - }; - pmu_for_each_sys_metric(metricgroup__sys_event_iter, &data); - } + int ret =3D pmu_metrics_table__for_each_metric(table, fn, data); =20 - for (node =3D rb_first_cached(&groups.entries); node; node =3D next) { - struct mep *me =3D container_of(node, struct mep, nd); - - print_cb->print_metric(print_state, - me->metric_group, - me->metric_name, - me->metric_desc, - me->metric_long_desc, - me->metric_expr, - me->metric_threshold, - me->metric_unit, - me->pmu_name); - next =3D rb_next(node); - rblist__remove_node(&groups, node); + if (ret) + return ret; } + + return pmu_for_each_sys_metric(metricgroup__sys_event_iter, &sys_data); } =20 static const char *code_characters =3D ",-=3D@"; @@ -1090,29 +957,6 @@ static int add_metric(struct list_head *metric_list, return ret; } =20 -static int metricgroup__add_metric_sys_event_iter(const struct pmu_metric = *pm, - const struct pmu_metrics_table *table __maybe_unused, - void *data) -{ - struct metricgroup_add_iter_data *d =3D data; - int ret; - - if (!match_pm_metric_or_groups(pm, d->pmu, d->metric_name)) - return 0; - - ret =3D add_metric(d->metric_list, pm, d->modifier, d->metric_no_group, - d->metric_no_threshold, d->user_requested_cpu_list, - d->system_wide, d->root_metric, d->visited, d->table); - if (ret) - goto out; - - *(d->has_match) =3D true; - -out: - *(d->ret) =3D ret; - return ret; -} - /** * metric_list_cmp - list_sort comparator that sorts metrics with more eve= nts to * the front. tool events are excluded from the count. @@ -1216,55 +1060,26 @@ static int metricgroup__add_metric(const char *pmu,= const char *metric_name, con { LIST_HEAD(list); int ret; - bool has_match =3D false; - - { - struct metricgroup__add_metric_data data =3D { - .list =3D &list, - .pmu =3D pmu, - .metric_name =3D metric_name, - .modifier =3D modifier, - .metric_no_group =3D metric_no_group, - .metric_no_threshold =3D metric_no_threshold, - .user_requested_cpu_list =3D user_requested_cpu_list, - .system_wide =3D system_wide, - .has_match =3D false, - }; - /* - * Iterate over all metrics seeing if metric matches either the - * name or group. When it does add the metric to the list. - */ - ret =3D pmu_metrics_table__for_each_metric(table, metricgroup__add_metri= c_callback, - &data); - if (ret) - goto out; + struct metricgroup__add_metric_data data =3D { + .list =3D &list, + .pmu =3D pmu, + .metric_name =3D metric_name, + .modifier =3D modifier, + .metric_no_group =3D metric_no_group, + .metric_no_threshold =3D metric_no_threshold, + .user_requested_cpu_list =3D user_requested_cpu_list, + .system_wide =3D system_wide, + .has_match =3D false, + }; =20 - has_match =3D data.has_match; - } - { - struct metricgroup_iter_data data =3D { - .fn =3D metricgroup__add_metric_sys_event_iter, - .data =3D (void *) &(struct metricgroup_add_iter_data) { - .metric_list =3D &list, - .pmu =3D pmu, - .metric_name =3D metric_name, - .modifier =3D modifier, - .metric_no_group =3D metric_no_group, - .user_requested_cpu_list =3D user_requested_cpu_list, - .system_wide =3D system_wide, - .has_match =3D &has_match, - .ret =3D &ret, - .table =3D table, - }, - }; - - pmu_for_each_sys_metric(metricgroup__sys_event_iter, &data); - } - /* End of pmu events. */ - if (!has_match) + /* + * Iterate over all metrics seeing if metric matches either the + * name or group. When it does add the metric to the list. + */ + ret =3D metricgroup__for_each_metric(table, metricgroup__add_metric_callb= ack, &data); + if (!ret && !data.has_match) ret =3D -EINVAL; =20 -out: /* * add to metric_list so that they can be released * even if it's failed diff --git a/tools/perf/util/metricgroup.h b/tools/perf/util/metricgroup.h index a04ac1afa6cc..1c07295931c1 100644 --- a/tools/perf/util/metricgroup.h +++ b/tools/perf/util/metricgroup.h @@ -84,7 +84,8 @@ int metricgroup__parse_groups_test(struct evlist *evlist, const char *str, struct rblist *metric_events); =20 -void metricgroup__print(const struct print_callbacks *print_cb, void *prin= t_state); +int metricgroup__for_each_metric(const struct pmu_metrics_table *table, pm= u_metric_iter_fn fn, + void *data); bool metricgroup__has_metric_or_groups(const char *pmu, const char *metric= _or_groups); unsigned int metricgroups__topdown_max_level(void); int arch_get_runtimeparam(const struct pmu_metric *pm); diff --git a/tools/perf/util/print-events.c b/tools/perf/util/print-events.c index 83aaf7cda635..e233bacaa641 100644 --- a/tools/perf/util/print-events.c +++ b/tools/perf/util/print-events.c @@ -381,6 +381,139 @@ void print_symbol_events(const struct print_callbacks= *print_cb, void *print_sta strlist__delete(evt_name_list); } =20 +/** struct mep - RB-tree node for building printing information. */ +struct mep { + /** nd - RB-tree element. */ + struct rb_node nd; + /** @metric_group: Owned metric group name, separated others with ';'. */ + char *metric_group; + const char *metric_name; + const char *metric_desc; + const char *metric_long_desc; + const char *metric_expr; + const char *metric_threshold; + const char *metric_unit; + const char *pmu_name; +}; + +static int mep_cmp(struct rb_node *rb_node, const void *entry) +{ + struct mep *a =3D container_of(rb_node, struct mep, nd); + struct mep *b =3D (struct mep *)entry; + int ret; + + ret =3D strcmp(a->metric_group, b->metric_group); + if (ret) + return ret; + + return strcmp(a->metric_name, b->metric_name); +} + +static struct rb_node *mep_new(struct rblist *rl __maybe_unused, const voi= d *entry) +{ + struct mep *me =3D malloc(sizeof(struct mep)); + + if (!me) + return NULL; + + memcpy(me, entry, sizeof(struct mep)); + return &me->nd; +} + +static void mep_delete(struct rblist *rl __maybe_unused, + struct rb_node *nd) +{ + struct mep *me =3D container_of(nd, struct mep, nd); + + zfree(&me->metric_group); + free(me); +} + +static struct mep *mep_lookup(struct rblist *groups, const char *metric_gr= oup, + const char *metric_name) +{ + struct rb_node *nd; + struct mep me =3D { + .metric_group =3D strdup(metric_group), + .metric_name =3D metric_name, + }; + nd =3D rblist__find(groups, &me); + if (nd) { + free(me.metric_group); + return container_of(nd, struct mep, nd); + } + rblist__add_node(groups, &me); + nd =3D rblist__find(groups, &me); + if (nd) + return container_of(nd, struct mep, nd); + return NULL; +} + +static int metricgroup__add_to_mep_groups_callback(const struct pmu_metric= *pm, + const struct pmu_metrics_table *table __maybe_unused, + void *vdata) +{ + struct rblist *groups =3D vdata; + const char *g; + char *omg, *mg; + + mg =3D strdup(pm->metric_group ?: pm->metric_name); + if (!mg) + return -ENOMEM; + omg =3D mg; + while ((g =3D strsep(&mg, ";")) !=3D NULL) { + struct mep *me; + + g =3D skip_spaces(g); + if (strlen(g)) + me =3D mep_lookup(groups, g, pm->metric_name); + else + me =3D mep_lookup(groups, pm->metric_name, pm->metric_name); + + if (me) { + me->metric_desc =3D pm->desc; + me->metric_long_desc =3D pm->long_desc; + me->metric_expr =3D pm->metric_expr; + me->metric_threshold =3D pm->metric_threshold; + me->metric_unit =3D pm->unit; + me->pmu_name =3D pm->pmu; + } + } + free(omg); + + return 0; +} + +void metricgroup__print(const struct print_callbacks *print_cb, void *prin= t_state) +{ + struct rblist groups; + struct rb_node *node, *next; + const struct pmu_metrics_table *table =3D pmu_metrics_table__find(); + + rblist__init(&groups); + groups.node_new =3D mep_new; + groups.node_cmp =3D mep_cmp; + groups.node_delete =3D mep_delete; + + metricgroup__for_each_metric(table, metricgroup__add_to_mep_groups_callba= ck, &groups); + + for (node =3D rb_first_cached(&groups.entries); node; node =3D next) { + struct mep *me =3D container_of(node, struct mep, nd); + + print_cb->print_metric(print_state, + me->metric_group, + me->metric_name, + me->metric_desc, + me->metric_long_desc, + me->metric_expr, + me->metric_threshold, + me->metric_unit, + me->pmu_name); + next =3D rb_next(node); + rblist__remove_node(&groups, node); + } +} + /* * Print the help text for the event symbols: */ diff --git a/tools/perf/util/print-events.h b/tools/perf/util/print-events.h index 8f19c2bea64a..48682e2d166d 100644 --- a/tools/perf/util/print-events.h +++ b/tools/perf/util/print-events.h @@ -37,7 +37,9 @@ void print_sdt_events(const struct print_callbacks *print= _cb, void *print_state) void print_symbol_events(const struct print_callbacks *print_cb, void *pri= nt_state, unsigned int type, const struct event_symbol *syms, unsigned int max); + void print_tracepoint_events(const struct print_callbacks *print_cb, void = *print_state); +void metricgroup__print(const struct print_callbacks *print_cb, void *prin= t_state); bool is_event_supported(u8 type, u64 config); =20 #endif /* __PERF_PRINT_EVENTS_H */ --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Tue Dec 16 03:25:18 2025 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (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 B6AB523F40A for ; Wed, 9 Jul 2025 21:40:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752097249; cv=none; b=Pb7C9tn3WcDz/KTbDsZwhvmuqcH4OGFxALknpw7mWx8PVPcaHaSFHXr4W5L29ub66+HKMhtz2Q2MiANQ0qy7/NuM6SKgxGvaSzP6frczIQD/SMtH2at0qZHGTZtD0n7cLlG5H3eQ1bM/R+D3Ofsacuae+f4Rc5zt4zZUNvlFvGc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752097249; c=relaxed/simple; bh=GzuZ8LUXET7BGYQ2eRqRzJYQa6EtqNPAew8uEpnPOvk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=PSIrLemF86vt2U3eFubgZP7BdBt62XI2CiV4Vrvi8bSCEaZNQASACrx5RRhqa6Eo0bxkmBNV+ml1tvVpYPHAU3sRz5iWnxj2/xWpn/aNJCz/alNWw3iQ2B+m57C2jS0rtmdTQ9dpODo4/HfM5rEO/khXMA7wtSsS4kkyWCQRm/8= 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=F/cMxvvz; arc=none smtp.client-ip=209.85.216.74 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="F/cMxvvz" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-3138e671316so288439a91.0 for ; Wed, 09 Jul 2025 14:40:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1752097246; x=1752702046; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=W2539RPpMNpcfZ5HJ4hJiH976Tmx+CPKS+Y0VYmUbAY=; b=F/cMxvvz692befqQ+BGveSMmUHc5+cOIDM1cDAC24lZEFX/G924IQA3JVtjfCHTtvD PdcRIo3nuejeHNgHY2xjQPYSDRukVApWX1jWAwiW/t1HkH1fsToqS4s3nUb3iCyX0n1C OdHS0FHmp4eNJmy3DnmI/tggbn1XuhmFB9aRpmmI5ZpCCirr2rdBXYx5Q/GmBPSrFdIa LqxGyAbG7rVmN/YrQgjRsR3T+nJFM6kPh3oB/ChoX/9fuGxTs7W1SW7A2hF+qv82vtoc MZWLl4ALViuj4wF3l7Jbtlrrv8/PagJ0d16XwV25cORwyGL0pU24bh5W9CqgBv1Wq+96 EJ6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752097246; x=1752702046; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=W2539RPpMNpcfZ5HJ4hJiH976Tmx+CPKS+Y0VYmUbAY=; b=UmSAPiPd2e3KGc7ajyhZlHcpN1LGFA7EmoSaPn/mWhBnG0cZTyzxydamP503ZqWJpn BNYVJNlBePbAc5lWNvBZNKH2i9Grxi+qibvqNj1iETrL0AAgz2kdsXmbiGDeuuxNyWcR vsc2qX8O76kR7pQxkJeU1HkgqsyfUlHnAMzl8IT3et2OlxrFrMYx5NGmK42GAEqxFSUY /W6hkuu/FOBHf93HfEOH0vzJF4yNhDmHyAXJi8TtXxgipcl1JPzZVJx4FF1XP1djB4oK 3UvCtmw84EA5XCw/G6ZCU3tLaxjjH6ZjEmszeziIkzIicxo7b3dO0mvmp+66VpXq4+LR V8pA== X-Forwarded-Encrypted: i=1; AJvYcCXz75moCgKM/OVeJJyPvgoaZNGrnFImD/c0gbO17LrDMeavROj8uxSfRcCt389NdcRGsPvs9lBBYb5fcTM=@vger.kernel.org X-Gm-Message-State: AOJu0Yy/KQWAtoeZt4zUwTMbfb83GAT7l0NKQzUrdBc9yW2DfWxqDyPZ lD0L0BXZza6HBhRyeLiEVLUP9g6umHavYZwULLl4NdPzIRYHV9EWBmT027DfB1/n/9hfi70z/z+ lZAGJiVKoRQ== X-Google-Smtp-Source: AGHT+IFQfemZ2ppOa9hMxLSulWEGp1wnzmPO2ByLfr+dgrEONL6khFd2h8EArFH493ZkLKiWN9jYq9zwASUq X-Received: from pjcc3.prod.google.com ([2002:a17:90b:5743:b0:31c:160d:e3be]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:2f43:b0:311:a5ab:3d47 with SMTP id 98e67ed59e1d1-31c3cf3a81dmr1612801a91.1.1752097246030; Wed, 09 Jul 2025 14:40:46 -0700 (PDT) Date: Wed, 9 Jul 2025 14:40:23 -0700 In-Reply-To: <20250709214029.1769089-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250709214029.1769089-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250709214029.1769089-7-irogers@google.com> Subject: [PATCH v1 06/12] perf stat: Move metric list from config to evlist 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 , Xu Yang , Howard Chu , "Dr. David Alan Gilbert" , Levi Yun , Andi Kleen , Thomas Richter , Weilin Wang , Tiezhu Yang , Gautam Menghani , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The rblist of metric_event that then have a list of associated metric_expr is moved out of the stat_config and into the evlist. This is done as part of refactoring things for python, having the state split in two places complicates that implementation. The evlist is doing the harder work of enabling and disabling events, the metrics are needed to compute a value and it doesn't seem unreasonable to hang them from the evlist. Signed-off-by: Ian Rogers --- tools/perf/builtin-script.c | 3 +-- tools/perf/builtin-stat.c | 25 ++++++++++++------------- tools/perf/tests/expand-cgroup.c | 24 +++++++----------------- tools/perf/tests/parse-metric.c | 16 +++++----------- tools/perf/tests/pmu-events.c | 8 ++------ tools/perf/util/cgroup.c | 23 ++++++++--------------- tools/perf/util/cgroup.h | 3 +-- tools/perf/util/evlist.c | 3 +++ tools/perf/util/evlist.h | 6 ++++++ tools/perf/util/metricgroup.c | 20 ++++++++------------ tools/perf/util/metricgroup.h | 7 +++---- tools/perf/util/python.c | 4 ++++ tools/perf/util/stat-display.c | 16 ++++++---------- tools/perf/util/stat-shadow.c | 13 ++++++------- tools/perf/util/stat.h | 12 +++--------- 15 files changed, 75 insertions(+), 108 deletions(-) diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 4001e621b6cb..271f22962e32 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -2136,8 +2136,7 @@ static void perf_sample__fprint_metric(struct perf_sc= ript *script, perf_stat__print_shadow_stats(&stat_config, ev2, evsel_script(ev2)->val, sample->cpu, - &ctx, - NULL); + &ctx); } evsel_script(leader)->gnum =3D 0; } diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 50fc53adb7e4..77e2248fa7fc 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -1863,8 +1863,7 @@ static int add_default_events(void) stat_config.metric_no_threshold, stat_config.user_requested_cpu_list, stat_config.system_wide, - stat_config.hardware_aware_grouping, - &stat_config.metric_events); + stat_config.hardware_aware_grouping); goto out; } =20 @@ -1901,8 +1900,7 @@ static int add_default_events(void) stat_config.metric_no_threshold, stat_config.user_requested_cpu_list, stat_config.system_wide, - stat_config.hardware_aware_grouping, - &stat_config.metric_events); + stat_config.hardware_aware_grouping); goto out; } =20 @@ -1939,8 +1937,7 @@ static int add_default_events(void) /*metric_no_threshold=3D*/true, stat_config.user_requested_cpu_list, stat_config.system_wide, - stat_config.hardware_aware_grouping, - &stat_config.metric_events) < 0) { + stat_config.hardware_aware_grouping) < 0) { ret =3D -1; goto out; } @@ -1989,8 +1986,7 @@ static int add_default_events(void) /*metric_no_threshold=3D*/true, stat_config.user_requested_cpu_list, stat_config.system_wide, - stat_config.hardware_aware_grouping, - &stat_config.metric_events) < 0) { + stat_config.hardware_aware_grouping) < 0) { ret =3D -1; goto out; } @@ -1999,6 +1995,9 @@ static int add_default_events(void) evsel->default_metricgroup =3D true; =20 evlist__splice_list_tail(evlist, &metric_evlist->core.entries); + metricgroup__copy_metric_events(evlist, /*cgrp=3D*/NULL, + &evlist->metric_events, + &metric_evlist->metric_events); evlist__delete(metric_evlist); } } @@ -2053,6 +2052,9 @@ static int add_default_events(void) } parse_events_error__exit(&err); evlist__splice_list_tail(evsel_list, &evlist->core.entries); + metricgroup__copy_metric_events(evsel_list, /*cgrp=3D*/NULL, + &evsel_list->metric_events, + &evlist->metric_events); evlist__delete(evlist); return ret; } @@ -2739,8 +2741,7 @@ int cmd_stat(int argc, const char **argv) stat_config.metric_no_threshold, stat_config.user_requested_cpu_list, stat_config.system_wide, - stat_config.hardware_aware_grouping, - &stat_config.metric_events); + stat_config.hardware_aware_grouping); =20 zfree(&metrics); if (ret) { @@ -2760,8 +2761,7 @@ int cmd_stat(int argc, const char **argv) goto out; } =20 - if (evlist__expand_cgroup(evsel_list, stat_config.cgroup_list, - &stat_config.metric_events, true) < 0) { + if (evlist__expand_cgroup(evsel_list, stat_config.cgroup_list, true) < 0= ) { parse_options_usage(stat_usage, stat_options, "for-each-cgroup", 0); goto out; @@ -2936,7 +2936,6 @@ int cmd_stat(int argc, const char **argv) =20 evlist__delete(evsel_list); =20 - metricgroup__rblist_exit(&stat_config.metric_events); evlist__close_control(stat_config.ctl_fd, stat_config.ctl_fd_ack, &stat_c= onfig.ctl_fd_close); =20 return status; diff --git a/tools/perf/tests/expand-cgroup.c b/tools/perf/tests/expand-cgr= oup.c index 31966ff856f8..c7b32a220ca1 100644 --- a/tools/perf/tests/expand-cgroup.c +++ b/tools/perf/tests/expand-cgroup.c @@ -13,8 +13,7 @@ #include #include =20 -static int test_expand_events(struct evlist *evlist, - struct rblist *metric_events) +static int test_expand_events(struct evlist *evlist) { int i, ret =3D TEST_FAIL; int nr_events; @@ -47,7 +46,7 @@ static int test_expand_events(struct evlist *evlist, was_group_event =3D evsel__is_group_event(evlist__first(evlist)); nr_members =3D evlist__first(evlist)->core.nr_members; =20 - ret =3D evlist__expand_cgroup(evlist, cgrp_str, metric_events, false); + ret =3D evlist__expand_cgroup(evlist, cgrp_str, false); if (ret < 0) { pr_debug("failed to expand events for cgroups\n"); goto out; @@ -100,13 +99,11 @@ out: for (i =3D 0; i < nr_events; i++) static int expand_default_events(void) { int ret; - struct rblist metric_events; struct evlist *evlist =3D evlist__new_default(); =20 TEST_ASSERT_VAL("failed to get evlist", evlist); =20 - rblist__init(&metric_events); - ret =3D test_expand_events(evlist, &metric_events); + ret =3D test_expand_events(evlist); evlist__delete(evlist); return ret; } @@ -115,7 +112,6 @@ static int expand_group_events(void) { int ret; struct evlist *evlist; - struct rblist metric_events; struct parse_events_error err; const char event_str[] =3D "{cycles,instructions}"; =20 @@ -132,8 +128,7 @@ static int expand_group_events(void) goto out; } =20 - rblist__init(&metric_events); - ret =3D test_expand_events(evlist, &metric_events); + ret =3D test_expand_events(evlist); out: parse_events_error__exit(&err); evlist__delete(evlist); @@ -144,7 +139,6 @@ static int expand_libpfm_events(void) { int ret; struct evlist *evlist; - struct rblist metric_events; const char event_str[] =3D "CYCLES"; struct option opt =3D { .value =3D &evlist, @@ -166,8 +160,7 @@ static int expand_libpfm_events(void) goto out; } =20 - rblist__init(&metric_events); - ret =3D test_expand_events(evlist, &metric_events); + ret =3D test_expand_events(evlist); out: evlist__delete(evlist); return ret; @@ -177,25 +170,22 @@ static int expand_metric_events(void) { int ret; struct evlist *evlist; - struct rblist metric_events; const char metric_str[] =3D "CPI"; const struct pmu_metrics_table *pme_test; =20 evlist =3D evlist__new(); TEST_ASSERT_VAL("failed to get evlist", evlist); =20 - rblist__init(&metric_events); pme_test =3D find_core_metrics_table("testarch", "testcpu"); - ret =3D metricgroup__parse_groups_test(evlist, pme_test, metric_str, &met= ric_events); + ret =3D metricgroup__parse_groups_test(evlist, pme_test, metric_str); if (ret < 0) { pr_debug("failed to parse '%s' metric\n", metric_str); goto out; } =20 - ret =3D test_expand_events(evlist, &metric_events); + ret =3D test_expand_events(evlist); =20 out: - metricgroup__rblist_exit(&metric_events); evlist__delete(evlist); return ret; } diff --git a/tools/perf/tests/parse-metric.c b/tools/perf/tests/parse-metri= c.c index 2c28fb50dc24..66a5275917e2 100644 --- a/tools/perf/tests/parse-metric.c +++ b/tools/perf/tests/parse-metric.c @@ -45,15 +45,14 @@ static void load_runtime_stat(struct evlist *evlist, st= ruct value *vals) } } =20 -static double compute_single(struct rblist *metric_events, struct evlist *= evlist, - const char *name) +static double compute_single(struct evlist *evlist, const char *name) { struct metric_expr *mexp; struct metric_event *me; struct evsel *evsel; =20 evlist__for_each_entry(evlist, evsel) { - me =3D metricgroup__lookup(metric_events, evsel, false); + me =3D metricgroup__lookup(&evlist->metric_events, evsel, false); if (me !=3D NULL) { list_for_each_entry (mexp, &me->head, nd) { if (strcmp(mexp->metric_name, name)) @@ -69,9 +68,6 @@ static int __compute_metric(const char *name, struct valu= e *vals, const char *name1, double *ratio1, const char *name2, double *ratio2) { - struct rblist metric_events =3D { - .nr_entries =3D 0, - }; const struct pmu_metrics_table *pme_test; struct perf_cpu_map *cpus; struct evlist *evlist; @@ -95,8 +91,7 @@ static int __compute_metric(const char *name, struct valu= e *vals, =20 /* Parse the metric into metric_events list. */ pme_test =3D find_core_metrics_table("testarch", "testcpu"); - err =3D metricgroup__parse_groups_test(evlist, pme_test, name, - &metric_events); + err =3D metricgroup__parse_groups_test(evlist, pme_test, name); if (err) goto out; =20 @@ -109,13 +104,12 @@ static int __compute_metric(const char *name, struct = value *vals, =20 /* And execute the metric */ if (name1 && ratio1) - *ratio1 =3D compute_single(&metric_events, evlist, name1); + *ratio1 =3D compute_single(evlist, name1); if (name2 && ratio2) - *ratio2 =3D compute_single(&metric_events, evlist, name2); + *ratio2 =3D compute_single(evlist, name2); =20 out: /* ... cleanup. */ - metricgroup__rblist_exit(&metric_events); evlist__free_stats(evlist); perf_cpu_map__put(cpus); evlist__delete(evlist); diff --git a/tools/perf/tests/pmu-events.c b/tools/perf/tests/pmu-events.c index 815b40097428..8bbe0516ecc0 100644 --- a/tools/perf/tests/pmu-events.c +++ b/tools/perf/tests/pmu-events.c @@ -868,9 +868,6 @@ static int test__parsing_callback(const struct pmu_metr= ic *pm, struct evlist *evlist; struct perf_cpu_map *cpus; struct evsel *evsel; - struct rblist metric_events =3D { - .nr_entries =3D 0, - }; int err =3D 0; =20 if (!pm->metric_expr) @@ -895,7 +892,7 @@ static int test__parsing_callback(const struct pmu_metr= ic *pm, =20 perf_evlist__set_maps(&evlist->core, cpus, NULL); =20 - err =3D metricgroup__parse_groups_test(evlist, table, pm->metric_name, &m= etric_events); + err =3D metricgroup__parse_groups_test(evlist, table, pm->metric_name); if (err) { if (!strcmp(pm->metric_name, "M1") || !strcmp(pm->metric_name, "M2") || !strcmp(pm->metric_name, "M3")) { @@ -922,7 +919,7 @@ static int test__parsing_callback(const struct pmu_metr= ic *pm, k++; } evlist__for_each_entry(evlist, evsel) { - struct metric_event *me =3D metricgroup__lookup(&metric_events, evsel, f= alse); + struct metric_event *me =3D metricgroup__lookup(&evlist->metric_events, = evsel, false); =20 if (me !=3D NULL) { struct metric_expr *mexp; @@ -944,7 +941,6 @@ static int test__parsing_callback(const struct pmu_metr= ic *pm, pr_debug("Broken metric %s\n", pm->metric_name); =20 /* ... cleanup. */ - metricgroup__rblist_exit(&metric_events); evlist__free_stats(evlist); perf_cpu_map__put(cpus); evlist__delete(evlist); diff --git a/tools/perf/util/cgroup.c b/tools/perf/util/cgroup.c index fbcc0626f9ce..25e2769b5e74 100644 --- a/tools/perf/util/cgroup.c +++ b/tools/perf/util/cgroup.c @@ -413,8 +413,7 @@ static bool has_pattern_string(const char *str) return !!strpbrk(str, "{}[]()|*+?^$"); } =20 -int evlist__expand_cgroup(struct evlist *evlist, const char *str, - struct rblist *metric_events, bool open_cgroup) +int evlist__expand_cgroup(struct evlist *evlist, const char *str, bool ope= n_cgroup) { struct evlist *orig_list, *tmp_list; struct evsel *pos, *evsel, *leader; @@ -440,12 +439,8 @@ int evlist__expand_cgroup(struct evlist *evlist, const= char *str, evlist__splice_list_tail(orig_list, &evlist->core.entries); evlist->core.nr_entries =3D 0; =20 - if (metric_events) { - orig_metric_events =3D *metric_events; - rblist__init(metric_events); - } else { - rblist__init(&orig_metric_events); - } + orig_metric_events =3D evlist->metric_events; + metricgroup__rblist_init(&evlist->metric_events); =20 if (has_pattern_string(str)) prefix_len =3D match_cgroups(str); @@ -490,12 +485,10 @@ int evlist__expand_cgroup(struct evlist *evlist, cons= t char *str, cgroup__put(cgrp); nr_cgroups++; =20 - if (metric_events) { - if (metricgroup__copy_metric_events(tmp_list, cgrp, - metric_events, - &orig_metric_events) < 0) - goto out_err; - } + if (metricgroup__copy_metric_events(tmp_list, cgrp, + &evlist->metric_events, + &orig_metric_events) < 0) + goto out_err; =20 evlist__splice_list_tail(evlist, &tmp_list->core.entries); tmp_list->core.nr_entries =3D 0; @@ -512,7 +505,7 @@ int evlist__expand_cgroup(struct evlist *evlist, const = char *str, out_err: evlist__delete(orig_list); evlist__delete(tmp_list); - rblist__exit(&orig_metric_events); + metricgroup__rblist_exit(&orig_metric_events); release_cgroup_list(); =20 return ret; diff --git a/tools/perf/util/cgroup.h b/tools/perf/util/cgroup.h index de8882d6e8d3..7b1bda22878c 100644 --- a/tools/perf/util/cgroup.h +++ b/tools/perf/util/cgroup.h @@ -28,8 +28,7 @@ struct rblist; =20 struct cgroup *cgroup__new(const char *name, bool do_open); struct cgroup *evlist__findnew_cgroup(struct evlist *evlist, const char *n= ame); -int evlist__expand_cgroup(struct evlist *evlist, const char *cgroups, - struct rblist *metric_events, bool open_cgroup); +int evlist__expand_cgroup(struct evlist *evlist, const char *cgroups, bool= open_cgroup); =20 void evlist__set_default_cgroup(struct evlist *evlist, struct cgroup *cgro= up); =20 diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 5664ebf6bbc6..995ad5f654d0 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -35,6 +35,7 @@ #include "util/util.h" #include "util/env.h" #include "util/intel-tpebs.h" +#include "util/metricgroup.h" #include "util/strbuf.h" #include #include @@ -83,6 +84,7 @@ void evlist__init(struct evlist *evlist, struct perf_cpu_= map *cpus, evlist->ctl_fd.ack =3D -1; evlist->ctl_fd.pos =3D -1; evlist->nr_br_cntr =3D -1; + metricgroup__rblist_init(&evlist->metric_events); } =20 struct evlist *evlist__new(void) @@ -173,6 +175,7 @@ static void evlist__purge(struct evlist *evlist) =20 void evlist__exit(struct evlist *evlist) { + metricgroup__rblist_exit(&evlist->metric_events); event_enable_timer__exit(&evlist->eet); zfree(&evlist->mmap); zfree(&evlist->overwrite_mmap); diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h index 85859708393e..fac1a01ba13f 100644 --- a/tools/perf/util/evlist.h +++ b/tools/perf/util/evlist.h @@ -12,6 +12,7 @@ #include #include "events_stats.h" #include "evsel.h" +#include "rblist.h" #include #include #include @@ -86,6 +87,11 @@ struct evlist { int pos; /* index at evlist core object to check signals */ } ctl_fd; struct event_enable_timer *eet; + /** + * @metric_events: A list of struct metric_event which each have a list + * of struct metric_expr. + */ + struct rblist metric_events; }; =20 struct evsel_str_handler { diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index ddd5c362d183..3cc6c47402bd 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -103,7 +103,7 @@ static void metric_event_delete(struct rblist *rblist _= _maybe_unused, free(me); } =20 -static void metricgroup__rblist_init(struct rblist *metric_events) +void metricgroup__rblist_init(struct rblist *metric_events) { rblist__init(metric_events); metric_events->node_cmp =3D metric_event_cmp; @@ -1323,7 +1323,6 @@ static int parse_groups(struct evlist *perf_evlist, const char *user_requested_cpu_list, bool system_wide, bool fake_pmu, - struct rblist *metric_events_list, const struct pmu_metrics_table *table) { struct evlist *combined_evlist =3D NULL; @@ -1333,8 +1332,6 @@ static int parse_groups(struct evlist *perf_evlist, bool is_default =3D !strcmp(str, "Default"); int ret; =20 - if (metric_events_list->nr_entries =3D=3D 0) - metricgroup__rblist_init(metric_events_list); ret =3D metricgroup__add_metric_list(pmu, str, metric_no_group, metric_no= _threshold, user_requested_cpu_list, system_wide, &metric_list, table); @@ -1425,7 +1422,8 @@ static int parse_groups(struct evlist *perf_evlist, goto out; } =20 - me =3D metricgroup__lookup(metric_events_list, metric_events[0], true); + me =3D metricgroup__lookup(&perf_evlist->metric_events, metric_events[0], + /*create=3D*/true); =20 expr =3D malloc(sizeof(struct metric_expr)); if (!expr) { @@ -1485,8 +1483,7 @@ int metricgroup__parse_groups(struct evlist *perf_evl= ist, bool metric_no_threshold, const char *user_requested_cpu_list, bool system_wide, - bool hardware_aware_grouping, - struct rblist *metric_events) + bool hardware_aware_grouping) { const struct pmu_metrics_table *table =3D pmu_metrics_table__find(); =20 @@ -1497,13 +1494,12 @@ int metricgroup__parse_groups(struct evlist *perf_e= vlist, =20 return parse_groups(perf_evlist, pmu, str, metric_no_group, metric_no_mer= ge, metric_no_threshold, user_requested_cpu_list, system_wide, - /*fake_pmu=3D*/false, metric_events, table); + /*fake_pmu=3D*/false, table); } =20 int metricgroup__parse_groups_test(struct evlist *evlist, const struct pmu_metrics_table *table, - const char *str, - struct rblist *metric_events) + const char *str) { return parse_groups(evlist, "all", str, /*metric_no_group=3D*/false, @@ -1511,7 +1507,7 @@ int metricgroup__parse_groups_test(struct evlist *evl= ist, /*metric_no_threshold=3D*/false, /*user_requested_cpu_list=3D*/NULL, /*system_wide=3D*/false, - /*fake_pmu=3D*/true, metric_events, table); + /*fake_pmu=3D*/true, table); } =20 struct metricgroup__has_metric_data { @@ -1596,7 +1592,7 @@ int metricgroup__copy_metric_events(struct evlist *ev= list, struct cgroup *cgrp, evsel =3D evlist__find_evsel(evlist, old_me->evsel->core.idx); if (!evsel) return -EINVAL; - new_me =3D metricgroup__lookup(new_metric_events, evsel, true); + new_me =3D metricgroup__lookup(new_metric_events, evsel, /*create=3D*/tr= ue); if (!new_me) return -ENOMEM; =20 diff --git a/tools/perf/util/metricgroup.h b/tools/perf/util/metricgroup.h index 1c07295931c1..324880b2ed8f 100644 --- a/tools/perf/util/metricgroup.h +++ b/tools/perf/util/metricgroup.h @@ -77,18 +77,17 @@ int metricgroup__parse_groups(struct evlist *perf_evlis= t, bool metric_no_threshold, const char *user_requested_cpu_list, bool system_wide, - bool hardware_aware_grouping, - struct rblist *metric_events); + bool hardware_aware_grouping); int metricgroup__parse_groups_test(struct evlist *evlist, const struct pmu_metrics_table *table, - const char *str, - struct rblist *metric_events); + const char *str); =20 int metricgroup__for_each_metric(const struct pmu_metrics_table *table, pm= u_metric_iter_fn fn, void *data); bool metricgroup__has_metric_or_groups(const char *pmu, const char *metric= _or_groups); unsigned int metricgroups__topdown_max_level(void); int arch_get_runtimeparam(const struct pmu_metric *pm); +void metricgroup__rblist_init(struct rblist *metric_events); void metricgroup__rblist_exit(struct rblist *metric_events); =20 int metricgroup__copy_metric_events(struct evlist *evlist, struct cgroup *= cgrp, diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index 82666bcd2eda..b5ee9f7a4662 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -18,6 +18,7 @@ #include "strbuf.h" #include "thread_map.h" #include "trace-event.h" +#include "metricgroup.h" #include "mmap.h" #include "util/sample.h" #include @@ -1544,6 +1545,9 @@ static PyObject *pyrf_evlist__from_evlist(struct evli= st *evlist) =20 evlist__add(&pevlist->evlist, &pevsel->evsel); } + metricgroup__copy_metric_events(&pevlist->evlist, /*cgrp=3D*/NULL, + &pevlist->evlist.metric_events, + &evlist->metric_events); return (PyObject *)pevlist; } =20 diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index 9cb5245a92aa..a67b991f4e81 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -899,12 +899,11 @@ static void printout(struct perf_stat_config *config,= struct outstate *os, print_noise(config, os, counter, noise, /*before_metric=3D*/true); print_running(config, os, run, ena, /*before_metric=3D*/true); from =3D perf_stat__print_shadow_stats_metricgroup(config, counter, ag= gr_idx, - &num, from, &out, - &config->metric_events); + &num, from, &out); } while (from !=3D NULL); - } else - perf_stat__print_shadow_stats(config, counter, uval, aggr_idx, - &out, &config->metric_events); + } else { + perf_stat__print_shadow_stats(config, counter, uval, aggr_idx, &out); + } } else { pm(config, os, METRIC_THRESHOLD_UNKNOWN, /*format=3D*/NULL, /*unit=3D*/N= ULL, /*val=3D*/0); } @@ -1016,7 +1015,7 @@ static void print_counter_aggrdata(struct perf_stat_c= onfig *config, ena =3D aggr->counts.ena; run =3D aggr->counts.run; =20 - if (perf_stat__skip_metric_event(counter, &config->metric_events, ena, ru= n)) + if (perf_stat__skip_metric_event(counter, ena, run)) return; =20 if (val =3D=3D 0 && should_skip_zero_counter(config, counter, &id)) @@ -1275,10 +1274,7 @@ static void print_metric_headers(struct perf_stat_co= nfig *config, =20 os.evsel =3D counter; =20 - perf_stat__print_shadow_stats(config, counter, 0, - 0, - &out, - &config->metric_events); + perf_stat__print_shadow_stats(config, counter, 0, 0, &out); } =20 if (!config->json_output) diff --git a/tools/perf/util/stat-shadow.c b/tools/perf/util/stat-shadow.c index d83bda5824d2..2b4950f56fae 100644 --- a/tools/perf/util/stat-shadow.c +++ b/tools/perf/util/stat-shadow.c @@ -15,6 +15,7 @@ #include #include "iostat.h" #include "util/hashmap.h" +#include "rblist.h" #include "tool_pmu.h" =20 struct stats walltime_nsecs_stats; @@ -635,14 +636,14 @@ void *perf_stat__print_shadow_stats_metricgroup(struc= t perf_stat_config *config, int aggr_idx, int *num, void *from, - struct perf_stat_output_ctx *out, - struct rblist *metric_events) + struct perf_stat_output_ctx *out) { struct metric_event *me; struct metric_expr *mexp =3D from; void *ctxp =3D out->ctx; bool header_printed =3D false; const char *name =3D NULL; + struct rblist *metric_events =3D &evsel->evlist->metric_events; =20 me =3D metricgroup__lookup(metric_events, evsel, false); if (me =3D=3D NULL) @@ -683,8 +684,7 @@ void *perf_stat__print_shadow_stats_metricgroup(struct = perf_stat_config *config, void perf_stat__print_shadow_stats(struct perf_stat_config *config, struct evsel *evsel, double avg, int aggr_idx, - struct perf_stat_output_ctx *out, - struct rblist *metric_events) + struct perf_stat_output_ctx *out) { typedef void (*stat_print_function_t)(struct perf_stat_config *config, const struct evsel *evsel, @@ -735,7 +735,7 @@ void perf_stat__print_shadow_stats(struct perf_stat_con= fig *config, } =20 perf_stat__print_shadow_stats_metricgroup(config, evsel, aggr_idx, - &num, NULL, out, metric_events); + &num, NULL, out); =20 if (num =3D=3D 0) { print_metric(config, ctxp, METRIC_THRESHOLD_UNKNOWN, @@ -748,7 +748,6 @@ void perf_stat__print_shadow_stats(struct perf_stat_con= fig *config, * if it's not running or not the metric event. */ bool perf_stat__skip_metric_event(struct evsel *evsel, - struct rblist *metric_events, u64 ena, u64 run) { if (!evsel->default_metricgroup) @@ -757,5 +756,5 @@ bool perf_stat__skip_metric_event(struct evsel *evsel, if (!ena || !run) return true; =20 - return !metricgroup__lookup(metric_events, evsel, false); + return !metricgroup__lookup(&evsel->evlist->metric_events, evsel, false); } diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h index 1bcd7634bf47..4b0f14ae4e5f 100644 --- a/tools/perf/util/stat.h +++ b/tools/perf/util/stat.h @@ -7,7 +7,6 @@ #include #include #include "cpumap.h" -#include "rblist.h" #include "counts.h" =20 struct perf_cpu_map; @@ -108,7 +107,6 @@ struct perf_stat_config { aggr_get_id_t aggr_get_id; struct cpu_aggr_map *cpus_aggr_map; u64 *walltime_run; - struct rblist metric_events; int ctl_fd; int ctl_fd_ack; bool ctl_fd_close; @@ -187,18 +185,14 @@ struct perf_stat_output_ctx { void perf_stat__print_shadow_stats(struct perf_stat_config *config, struct evsel *evsel, double avg, int aggr_idx, - struct perf_stat_output_ctx *out, - struct rblist *metric_events); -bool perf_stat__skip_metric_event(struct evsel *evsel, - struct rblist *metric_events, - u64 ena, u64 run); + struct perf_stat_output_ctx *out); +bool perf_stat__skip_metric_event(struct evsel *evsel, u64 ena, u64 run); void *perf_stat__print_shadow_stats_metricgroup(struct perf_stat_config *c= onfig, struct evsel *evsel, int aggr_idx, int *num, void *from, - struct perf_stat_output_ctx *out, - struct rblist *metric_events); + struct perf_stat_output_ctx *out); =20 int evlist__alloc_stats(struct perf_stat_config *config, struct evlist *evlist, bool alloc_raw); --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Tue Dec 16 03:25:18 2025 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C6047258CD8 for ; Wed, 9 Jul 2025 21:40:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752097250; cv=none; b=dmx8xk6W2kSikTjAqO01TKIYaFTrToH60Z+NkPI37acuASLN3shbyAouy0GLLUi1BBa89RzJZg9fqU5342QnBu0p9gXXPrM6XFBn5F5BqeD12L37xXzfzh6SgzHdf3JhMQDCoIKI7FK/wgm+Qci4k7kZ5hog4QgtPeZpclvAJqM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752097250; c=relaxed/simple; bh=gv1i3DNEGxqaAyeBCm8oJ3IImT0PmMzZRaQt45Qua7I=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=Qx/EQIKAtUuuF6x+XDSYYwu94ivZwwyTVQHp3zBEq+/hzqNzqNGh100C3bNjaGCKx7vnZfxP1GyjSI4qf3Ysj+auMt53UN/BV4VJX3VhbTl0fDaGqLDvjE/B09HRm/+8iOOZGs16nmXZfAHs6pOEbDxrCvuzORpV/zVb51FO5is= 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=WVulkJtP; arc=none smtp.client-ip=209.85.214.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="WVulkJtP" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-235196dfc50so2989015ad.1 for ; Wed, 09 Jul 2025 14:40:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1752097248; x=1752702048; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=WHFbmZZJXyMo6toKRekC1Kog8DjIMtKrGBEtrtRAi4A=; b=WVulkJtPYzidkgMfIz2HXX+bTEr3+bJWsIz+0xVf9kwJAO+dMADGGaubnaAlbnyb4R 9v8jQhm11XuuJmRcG1zBR1IZ1Hp+568kVGhyYidARgb7ZQ/VBmZIeHf+qkvLBAIUPkX2 7+hK/EGdPnkcSoj9TnKiQ2TxcIaJUSGo4z/Omqa8JtdpcagpfRMNatyXMvP3ldWw+Lrz gi7vECYqfWQYQG6n2/lonECi/6v9zbCgcStv+83qnxL4ti6pu5112hH5kTdiE8wO61iJ mlm+OLvG8TPcPUyBe9P0lv+TkCvuSM6HPW2FEB/vDPB5R1WiRxI+cXPjnN7QbfW4oa4d XR3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752097248; x=1752702048; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=WHFbmZZJXyMo6toKRekC1Kog8DjIMtKrGBEtrtRAi4A=; b=eoL8EoobgaO/JK1+9UzfNYi5i9wfdOlLzCIq4NkMfFKfUa3Fwiew0X25X+w0Di71/H eO68qkdRiZHuvtt1A16SUfcTTnqD3J1yfL2NrFHQiV5aR9lhI/Ed6atW996K4J81utDE d2zRG7wciKDGZ4ZmrVuXZJvfIcLQoZkITkcMUhfj9dJhM9+PSy05zmycNAptaQ9Zc8ha vunkSVAZRAgevFGgcENDGTdpdlzzE4Fyp6aitOpmreOA1KCkgBeWpAiz75bsMy8YU7kO YTC8swQmADotqUpfSE9hH2HDX01MuJ+HJEKLMybREZZmxxw44gK3225U/ev57eoH0sSR ylRQ== X-Forwarded-Encrypted: i=1; AJvYcCVDq0HfwPdPQqBT35GufQtldwQEkx57z+3Nqq1eMXyq9UrM7Y6Aw1i2WGKYVzsdYBM0Rp05ip3FxR56QHw=@vger.kernel.org X-Gm-Message-State: AOJu0YyeUjgFabsbp+gTtofkFjOtSNMGMqCTd6+H70PDXEZPgDqJkwQu z1BcA1FdkSW5dzUsv9AtEDl+/8nkTdVsoDje8yi6uNWTn6yUA5iPkr+T8JdclSJkM8pNAqVwfPd mLeyDAPUKlQ== X-Google-Smtp-Source: AGHT+IEPhXi1EE/yKqxcf/Tb2Zb4kUGNN8tEUGHpwwrfPN8hR88hey/bUWtBivYsketan+WB+niZag1LozhC X-Received: from pjbdy15.prod.google.com ([2002:a17:90b:6cf:b0:311:4aa8:2179]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:1b2c:b0:234:595d:a58e with SMTP id d9443c01a7336-23de3008346mr15749645ad.25.1752097248268; Wed, 09 Jul 2025 14:40:48 -0700 (PDT) Date: Wed, 9 Jul 2025 14:40:24 -0700 In-Reply-To: <20250709214029.1769089-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250709214029.1769089-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250709214029.1769089-8-irogers@google.com> Subject: [PATCH v1 07/12] perf expr: Accumulate rather than replace in the context counts 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 , Xu Yang , Howard Chu , "Dr. David Alan Gilbert" , Levi Yun , Andi Kleen , Thomas Richter , Weilin Wang , Tiezhu Yang , Gautam Menghani , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Metrics will fill in the context to have mappings from an event to a count. When counts are added they replace existing mappings which generally shouldn't exist with aggregation. Switch to accumulating to better support cases where perf stat's aggregation isn't used and we may see a counter more than once. Signed-off-by: Ian Rogers --- tools/perf/util/expr.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/expr.c b/tools/perf/util/expr.c index 6413537442aa..ca70a14c7cdf 100644 --- a/tools/perf/util/expr.c +++ b/tools/perf/util/expr.c @@ -166,8 +166,12 @@ int expr__add_id_val_source_count(struct expr_parse_ct= x *ctx, const char *id, data_ptr->kind =3D EXPR_ID_DATA__VALUE; =20 ret =3D hashmap__set(ctx->ids, id, data_ptr, &old_key, &old_data); - if (ret) + if (ret) { free(data_ptr); + } else if (old_data) { + data_ptr->val.val +=3D old_data->val.val; + data_ptr->val.source_count +=3D old_data->val.source_count; + } free(old_key); free(old_data); return ret; --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Tue Dec 16 03:25:18 2025 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2A74B25B1FF for ; Wed, 9 Jul 2025 21:40:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752097253; cv=none; b=C/RtnBRGhdd5B2yfctYJVjNnsRaJIu/gsr6D46s23jLGhNpZmbeXk1N8JyDmNQDhEFPxi5bm7SAirC8RW4Bh5R3u5U9makd+35fJARDoTwOOi86UjsdlVtZzknJkPdJ/Ps4FgIDPqVVeDqXPuH9Y6teFRKORZnbRFGoWzGXd9QA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752097253; c=relaxed/simple; bh=SlQ4yQiCxha6D90EaERBK4fPSe2+4PNG3jcD2ckQ+FY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=koGgd3ZWT4xwrSo0egdUOHDzA2PnCD5EYb/X0QFwsVsMrRuk03OMfMYtLPEROtfxJAct+f7B9KPaZs7Z1sselAUzNNKujpXQihGKC5Uj4D5IHxOLBDixqsk2GaQqKqwB6dh2Klunc8Zg6tQbZesrOmCQQLuWP63A8GItvRzDZwA= 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=zIxTo2SK; arc=none smtp.client-ip=209.85.214.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="zIxTo2SK" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-2349fe994a9so2539665ad.1 for ; Wed, 09 Jul 2025 14:40:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1752097250; x=1752702050; darn=vger.kernel.org; h=content-transfer-encoding:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=KNRFcAbNZdrNDSocF3ZCTE7cXmpBNdhTgAmXtSDNfiQ=; b=zIxTo2SKCLcFCXhKfjvuuwaaI67AiLSGsz3EdYvyNYxjXZqTAOailbjT1Hsw7LrBET bjsIlEq/X66wWgqseTpVXoxzd+do+5AW8A5FTjvJ5Z4PlWRlrO2eGCiJBfGCrL9dr/qQ vkIqk7rUnRcIkxtct6CS0pBoMptDLV+qIfgaC9cBhrkA2Kq5W3KwNqgyx2OR2G8hBJKq IW5gDztVZ7G3+L/nETIgL7BYcFqB+vPHPjZ9FQUiSm2DF0BpFzcFf2Qg6ig09K9kvV5Q Bef8zDrbZExVIIuD7q3zrUeuGRcFZBerc85xE8OQ4ZylnO18SRuljXZFrSp8T4HMZyRz H3NA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752097250; x=1752702050; h=content-transfer-encoding:to:from:subject:message-id:references :mime-version:in-reply-to:date:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=KNRFcAbNZdrNDSocF3ZCTE7cXmpBNdhTgAmXtSDNfiQ=; b=eYatlOBTrGiaCWvc+axOAkhjP7v0WIZpI3TS2GP2dMmouQ1qPSblr80mWTdKusBYth 76t4jMUVN4c+SLniR0rfdLtRvw5ljtooLwEhLS1gji80JSFVkLxDWfsuit8A+mSqLCRk UlR8Nkqt9P51k/0vd4wV3XBJ+TAMvq3Kz8/yvTa2O9y6H7KH0dNzZC4vK+3wHDrHQBn9 qgbx73n17ZsV28es1I38vMOz7588sOeFkyA72m2yABHbu9cIMlohZ9fGXfYTUM3/dLbw mGgZP8+2C0eLtzotxPQWIBTLE7lLwz90ASBAtqP8YzOxvUxYjlmWGzCapEhx2A/9rVnn ykrg== X-Forwarded-Encrypted: i=1; AJvYcCVy6Vc47C0DcncVBr4Q4nmGqlBKEXVxOtvI0QfIQcvUzoIZjoREXk1zouiUqSC9r+w4ZATQ057Pdk5OUmQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yzp/DWsCfKgHAL7ZPCZV9imKHqZGRvNSrnf19yEWXsArt5iPgIM 4VMr47Yh99q4l9UYLvpUK6Llgi3vyYj4PAcd+tz52oXyPY5TVxinpAp1Q6BjH4ucdy6K5AXP5em Z8JmI8qQI3g== X-Google-Smtp-Source: AGHT+IHoonnPuhcOJMDMsyRRUK62Ej8e2hIEwTvQIb3Ec6/wgya7AQKQ7nEQp2Qy/LfmBXoUamXc98uezfRP X-Received: from plbld14.prod.google.com ([2002:a17:902:face:b0:236:6f45:7ec1]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:f70e:b0:235:ef67:b5a0 with SMTP id d9443c01a7336-23de48a0664mr199065ad.36.1752097250379; Wed, 09 Jul 2025 14:40:50 -0700 (PDT) Date: Wed, 9 Jul 2025 14:40:25 -0700 In-Reply-To: <20250709214029.1769089-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250709214029.1769089-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250709214029.1769089-9-irogers@google.com> Subject: [PATCH v1 08/12] perf jevents: If the long_desc and desc are identical then drop the long_desc 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 , Xu Yang , Howard Chu , "Dr. David Alan Gilbert" , Levi Yun , Andi Kleen , Thomas Richter , Weilin Wang , Tiezhu Yang , Gautam Menghani , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" If the short and long descriptions are the same then save space and don't store both of them. When storing the desc in the perf_pmu_alias, don't duplicate the desc into the long_desc. By avoiding storing the duplicate the size of the events string in the binary on x86 is reduced by 29,840 bytes. Fix tests that expect a duplicated description. Signed-off-by: Ian Rogers --- tools/perf/pmu-events/empty-pmu-events.c | 128 +++++++++++------------ tools/perf/pmu-events/jevents.py | 3 + tools/perf/tests/pmu-events.c | 22 ---- tools/perf/util/pmu.c | 3 +- 4 files changed, 68 insertions(+), 88 deletions(-) diff --git a/tools/perf/pmu-events/empty-pmu-events.c b/tools/perf/pmu-even= ts/empty-pmu-events.c index d4017007a991..a4569a74db07 100644 --- a/tools/perf/pmu-events/empty-pmu-events.c +++ b/tools/perf/pmu-events/empty-pmu-events.c @@ -40,38 +40,38 @@ static const char *const big_c_string =3D /* offset=3D1475 */ "dispatch_blocked.any\000other\000Memory cluster signa= ls to block micro-op dispatch for any reason\000event=3D9,period=3D200000,u= mask=3D0x20\000\00000\000\000\000\000\000" /* offset=3D1608 */ "eist_trans\000other\000Number of Enhanced Intel Speed= Step(R) Technology (EIST) transitions\000event=3D0x3a,period=3D200000\000\0= 0000\000\000\000\000\000" /* offset=3D1726 */ "hisi_sccl,ddrc\000" -/* offset=3D1741 */ "uncore_hisi_ddrc.flux_wcmd\000uncore\000DDRC write co= mmands\000event=3D2\000\00000\000\000\000\000DDRC write commands\000" -/* offset=3D1830 */ "uncore_cbox\000" -/* offset=3D1842 */ "unc_cbo_xsnp_response.miss_eviction\000uncore\000A cr= oss-core snoop resulted from L3 Eviction which misses in some processor cor= e\000event=3D0x22,umask=3D0x81\000\00000\000\000\000\000A cross-core snoop = resulted from L3 Eviction which misses in some processor core\000" -/* offset=3D2076 */ "event-hyphen\000uncore\000UNC_CBO_HYPHEN\000event=3D0= xe0\000\00000\000\000\000\000UNC_CBO_HYPHEN\000" -/* offset=3D2144 */ "event-two-hyph\000uncore\000UNC_CBO_TWO_HYPH\000event= =3D0xc0\000\00000\000\000\000\000UNC_CBO_TWO_HYPH\000" -/* offset=3D2218 */ "hisi_sccl,l3c\000" -/* offset=3D2232 */ "uncore_hisi_l3c.rd_hit_cpipe\000uncore\000Total read = hits\000event=3D7\000\00000\000\000\000\000Total read hits\000" -/* offset=3D2315 */ "uncore_imc_free_running\000" -/* offset=3D2339 */ "uncore_imc_free_running.cache_miss\000uncore\000Total= cache misses\000event=3D0x12\000\00000\000\000\000\000Total cache misses\0= 00" -/* offset=3D2437 */ "uncore_imc\000" -/* offset=3D2448 */ "uncore_imc.cache_hits\000uncore\000Total cache hits\0= 00event=3D0x34\000\00000\000\000\000\000Total cache hits\000" -/* offset=3D2529 */ "uncore_sys_ddr_pmu\000" -/* offset=3D2548 */ "sys_ddr_pmu.write_cycles\000uncore\000ddr write-cycle= s event\000event=3D0x2b\000v8\00000\000\000\000\000\000" -/* offset=3D2624 */ "uncore_sys_ccn_pmu\000" -/* offset=3D2643 */ "sys_ccn_pmu.read_cycles\000uncore\000ccn read-cycles = event\000config=3D0x2c\0000x01\00000\000\000\000\000\000" -/* offset=3D2720 */ "uncore_sys_cmn_pmu\000" -/* offset=3D2739 */ "sys_cmn_pmu.hnf_cache_miss\000uncore\000Counts total = cache misses in first lookup result (high priority)\000eventid=3D1,type=3D5= \000(434|436|43c|43a).*\00000\000\000\000\000\000" -/* offset=3D2882 */ "CPI\000\0001 / IPC\000\000\000\000\000\000\000\00000" -/* offset=3D2904 */ "IPC\000group1\000inst_retired.any / cpu_clk_unhalted.= thread\000\000\000\000\000\000\000\00000" -/* offset=3D2967 */ "Frontend_Bound_SMT\000\000idq_uops_not_delivered.core= / (4 * (cpu_clk_unhalted.thread / 2 * (1 + cpu_clk_unhalted.one_thread_act= ive / cpu_clk_unhalted.ref_xclk)))\000\000\000\000\000\000\000\00000" -/* offset=3D3133 */ "dcache_miss_cpi\000\000l1d\\-loads\\-misses / inst_re= tired.any\000\000\000\000\000\000\000\00000" -/* offset=3D3197 */ "icache_miss_cycles\000\000l1i\\-loads\\-misses / inst= _retired.any\000\000\000\000\000\000\000\00000" -/* offset=3D3264 */ "cache_miss_cycles\000group1\000dcache_miss_cpi + icac= he_miss_cycles\000\000\000\000\000\000\000\00000" -/* offset=3D3335 */ "DCache_L2_All_Hits\000\000l2_rqsts.demand_data_rd_hit= + l2_rqsts.pf_hit + l2_rqsts.rfo_hit\000\000\000\000\000\000\000\00000" -/* offset=3D3429 */ "DCache_L2_All_Miss\000\000max(l2_rqsts.all_demand_dat= a_rd - l2_rqsts.demand_data_rd_hit, 0) + l2_rqsts.pf_miss + l2_rqsts.rfo_mi= ss\000\000\000\000\000\000\000\00000" -/* offset=3D3563 */ "DCache_L2_All\000\000DCache_L2_All_Hits + DCache_L2_A= ll_Miss\000\000\000\000\000\000\000\00000" -/* offset=3D3627 */ "DCache_L2_Hits\000\000d_ratio(DCache_L2_All_Hits, DCa= che_L2_All)\000\000\000\000\000\000\000\00000" -/* offset=3D3695 */ "DCache_L2_Misses\000\000d_ratio(DCache_L2_All_Miss, D= Cache_L2_All)\000\000\000\000\000\000\000\00000" -/* offset=3D3765 */ "M1\000\000ipc + M2\000\000\000\000\000\000\000\00000" -/* offset=3D3787 */ "M2\000\000ipc + M1\000\000\000\000\000\000\000\00000" -/* offset=3D3809 */ "M3\000\0001 / M3\000\000\000\000\000\000\000\00000" -/* offset=3D3829 */ "L1D_Cache_Fill_BW\000\00064 * l1d.replacement / 1e9 /= duration_time\000\000\000\000\000\000\000\00000" +/* offset=3D1741 */ "uncore_hisi_ddrc.flux_wcmd\000uncore\000DDRC write co= mmands\000event=3D2\000\00000\000\000\000\000\000" +/* offset=3D1811 */ "uncore_cbox\000" +/* offset=3D1823 */ "unc_cbo_xsnp_response.miss_eviction\000uncore\000A cr= oss-core snoop resulted from L3 Eviction which misses in some processor cor= e\000event=3D0x22,umask=3D0x81\000\00000\000\000\000\000\000" +/* offset=3D1977 */ "event-hyphen\000uncore\000UNC_CBO_HYPHEN\000event=3D0= xe0\000\00000\000\000\000\000\000" +/* offset=3D2031 */ "event-two-hyph\000uncore\000UNC_CBO_TWO_HYPH\000event= =3D0xc0\000\00000\000\000\000\000\000" +/* offset=3D2089 */ "hisi_sccl,l3c\000" +/* offset=3D2103 */ "uncore_hisi_l3c.rd_hit_cpipe\000uncore\000Total read = hits\000event=3D7\000\00000\000\000\000\000\000" +/* offset=3D2171 */ "uncore_imc_free_running\000" +/* offset=3D2195 */ "uncore_imc_free_running.cache_miss\000uncore\000Total= cache misses\000event=3D0x12\000\00000\000\000\000\000\000" +/* offset=3D2275 */ "uncore_imc\000" +/* offset=3D2286 */ "uncore_imc.cache_hits\000uncore\000Total cache hits\0= 00event=3D0x34\000\00000\000\000\000\000\000" +/* offset=3D2351 */ "uncore_sys_ddr_pmu\000" +/* offset=3D2370 */ "sys_ddr_pmu.write_cycles\000uncore\000ddr write-cycle= s event\000event=3D0x2b\000v8\00000\000\000\000\000\000" +/* offset=3D2446 */ "uncore_sys_ccn_pmu\000" +/* offset=3D2465 */ "sys_ccn_pmu.read_cycles\000uncore\000ccn read-cycles = event\000config=3D0x2c\0000x01\00000\000\000\000\000\000" +/* offset=3D2542 */ "uncore_sys_cmn_pmu\000" +/* offset=3D2561 */ "sys_cmn_pmu.hnf_cache_miss\000uncore\000Counts total = cache misses in first lookup result (high priority)\000eventid=3D1,type=3D5= \000(434|436|43c|43a).*\00000\000\000\000\000\000" +/* offset=3D2704 */ "CPI\000\0001 / IPC\000\000\000\000\000\000\000\00000" +/* offset=3D2726 */ "IPC\000group1\000inst_retired.any / cpu_clk_unhalted.= thread\000\000\000\000\000\000\000\00000" +/* offset=3D2789 */ "Frontend_Bound_SMT\000\000idq_uops_not_delivered.core= / (4 * (cpu_clk_unhalted.thread / 2 * (1 + cpu_clk_unhalted.one_thread_act= ive / cpu_clk_unhalted.ref_xclk)))\000\000\000\000\000\000\000\00000" +/* offset=3D2955 */ "dcache_miss_cpi\000\000l1d\\-loads\\-misses / inst_re= tired.any\000\000\000\000\000\000\000\00000" +/* offset=3D3019 */ "icache_miss_cycles\000\000l1i\\-loads\\-misses / inst= _retired.any\000\000\000\000\000\000\000\00000" +/* offset=3D3086 */ "cache_miss_cycles\000group1\000dcache_miss_cpi + icac= he_miss_cycles\000\000\000\000\000\000\000\00000" +/* offset=3D3157 */ "DCache_L2_All_Hits\000\000l2_rqsts.demand_data_rd_hit= + l2_rqsts.pf_hit + l2_rqsts.rfo_hit\000\000\000\000\000\000\000\00000" +/* offset=3D3251 */ "DCache_L2_All_Miss\000\000max(l2_rqsts.all_demand_dat= a_rd - l2_rqsts.demand_data_rd_hit, 0) + l2_rqsts.pf_miss + l2_rqsts.rfo_mi= ss\000\000\000\000\000\000\000\00000" +/* offset=3D3385 */ "DCache_L2_All\000\000DCache_L2_All_Hits + DCache_L2_A= ll_Miss\000\000\000\000\000\000\000\00000" +/* offset=3D3449 */ "DCache_L2_Hits\000\000d_ratio(DCache_L2_All_Hits, DCa= che_L2_All)\000\000\000\000\000\000\000\00000" +/* offset=3D3517 */ "DCache_L2_Misses\000\000d_ratio(DCache_L2_All_Miss, D= Cache_L2_All)\000\000\000\000\000\000\000\00000" +/* offset=3D3587 */ "M1\000\000ipc + M2\000\000\000\000\000\000\000\00000" +/* offset=3D3609 */ "M2\000\000ipc + M1\000\000\000\000\000\000\000\00000" +/* offset=3D3631 */ "M3\000\0001 / M3\000\000\000\000\000\000\000\00000" +/* offset=3D3651 */ "L1D_Cache_Fill_BW\000\00064 * l1d.replacement / 1e9 /= duration_time\000\000\000\000\000\000\000\00000" ; =20 static const struct compact_pmu_event pmu_events__common_tool[] =3D { @@ -107,21 +107,21 @@ static const struct compact_pmu_event pmu_events__tes= t_soc_cpu_default_core[] =3D { 1373 }, /* segment_reg_loads.any\000other\000Number of segment register = loads\000event=3D6,period=3D200000,umask=3D0x80\000\00000\000\000\000\000\0= 00 */ }; static const struct compact_pmu_event pmu_events__test_soc_cpu_hisi_sccl_d= drc[] =3D { -{ 1741 }, /* uncore_hisi_ddrc.flux_wcmd\000uncore\000DDRC write commands\0= 00event=3D2\000\00000\000\000\000\000DDRC write commands\000 */ +{ 1741 }, /* uncore_hisi_ddrc.flux_wcmd\000uncore\000DDRC write commands\0= 00event=3D2\000\00000\000\000\000\000\000 */ }; static const struct compact_pmu_event pmu_events__test_soc_cpu_hisi_sccl_l= 3c[] =3D { -{ 2232 }, /* uncore_hisi_l3c.rd_hit_cpipe\000uncore\000Total read hits\000= event=3D7\000\00000\000\000\000\000Total read hits\000 */ +{ 2103 }, /* uncore_hisi_l3c.rd_hit_cpipe\000uncore\000Total read hits\000= event=3D7\000\00000\000\000\000\000\000 */ }; static const struct compact_pmu_event pmu_events__test_soc_cpu_uncore_cbox= [] =3D { -{ 2076 }, /* event-hyphen\000uncore\000UNC_CBO_HYPHEN\000event=3D0xe0\000\= 00000\000\000\000\000UNC_CBO_HYPHEN\000 */ -{ 2144 }, /* event-two-hyph\000uncore\000UNC_CBO_TWO_HYPH\000event=3D0xc0\= 000\00000\000\000\000\000UNC_CBO_TWO_HYPH\000 */ -{ 1842 }, /* unc_cbo_xsnp_response.miss_eviction\000uncore\000A cross-core= snoop resulted from L3 Eviction which misses in some processor core\000eve= nt=3D0x22,umask=3D0x81\000\00000\000\000\000\000A cross-core snoop resulted= from L3 Eviction which misses in some processor core\000 */ +{ 1977 }, /* event-hyphen\000uncore\000UNC_CBO_HYPHEN\000event=3D0xe0\000\= 00000\000\000\000\000\000 */ +{ 2031 }, /* event-two-hyph\000uncore\000UNC_CBO_TWO_HYPH\000event=3D0xc0\= 000\00000\000\000\000\000\000 */ +{ 1823 }, /* unc_cbo_xsnp_response.miss_eviction\000uncore\000A cross-core= snoop resulted from L3 Eviction which misses in some processor core\000eve= nt=3D0x22,umask=3D0x81\000\00000\000\000\000\000\000 */ }; static const struct compact_pmu_event pmu_events__test_soc_cpu_uncore_imc[= ] =3D { -{ 2448 }, /* uncore_imc.cache_hits\000uncore\000Total cache hits\000event= =3D0x34\000\00000\000\000\000\000Total cache hits\000 */ +{ 2286 }, /* uncore_imc.cache_hits\000uncore\000Total cache hits\000event= =3D0x34\000\00000\000\000\000\000\000 */ }; static const struct compact_pmu_event pmu_events__test_soc_cpu_uncore_imc_= free_running[] =3D { -{ 2339 }, /* uncore_imc_free_running.cache_miss\000uncore\000Total cache m= isses\000event=3D0x12\000\00000\000\000\000\000Total cache misses\000 */ +{ 2195 }, /* uncore_imc_free_running.cache_miss\000uncore\000Total cache m= isses\000event=3D0x12\000\00000\000\000\000\000\000 */ =20 }; =20 @@ -139,41 +139,41 @@ const struct pmu_table_entry pmu_events__test_soc_cpu= [] =3D { { .entries =3D pmu_events__test_soc_cpu_hisi_sccl_l3c, .num_entries =3D ARRAY_SIZE(pmu_events__test_soc_cpu_hisi_sccl_l3c), - .pmu_name =3D { 2218 /* hisi_sccl,l3c\000 */ }, + .pmu_name =3D { 2089 /* hisi_sccl,l3c\000 */ }, }, { .entries =3D pmu_events__test_soc_cpu_uncore_cbox, .num_entries =3D ARRAY_SIZE(pmu_events__test_soc_cpu_uncore_cbox), - .pmu_name =3D { 1830 /* uncore_cbox\000 */ }, + .pmu_name =3D { 1811 /* uncore_cbox\000 */ }, }, { .entries =3D pmu_events__test_soc_cpu_uncore_imc, .num_entries =3D ARRAY_SIZE(pmu_events__test_soc_cpu_uncore_imc), - .pmu_name =3D { 2437 /* uncore_imc\000 */ }, + .pmu_name =3D { 2275 /* uncore_imc\000 */ }, }, { .entries =3D pmu_events__test_soc_cpu_uncore_imc_free_running, .num_entries =3D ARRAY_SIZE(pmu_events__test_soc_cpu_uncore_imc_free_= running), - .pmu_name =3D { 2315 /* uncore_imc_free_running\000 */ }, + .pmu_name =3D { 2171 /* uncore_imc_free_running\000 */ }, }, }; =20 static const struct compact_pmu_event pmu_metrics__test_soc_cpu_default_co= re[] =3D { -{ 2882 }, /* CPI\000\0001 / IPC\000\000\000\000\000\000\000\00000 */ -{ 3563 }, /* DCache_L2_All\000\000DCache_L2_All_Hits + DCache_L2_All_Miss\= 000\000\000\000\000\000\000\00000 */ -{ 3335 }, /* DCache_L2_All_Hits\000\000l2_rqsts.demand_data_rd_hit + l2_rq= sts.pf_hit + l2_rqsts.rfo_hit\000\000\000\000\000\000\000\00000 */ -{ 3429 }, /* DCache_L2_All_Miss\000\000max(l2_rqsts.all_demand_data_rd - l= 2_rqsts.demand_data_rd_hit, 0) + l2_rqsts.pf_miss + l2_rqsts.rfo_miss\000\0= 00\000\000\000\000\000\00000 */ -{ 3627 }, /* DCache_L2_Hits\000\000d_ratio(DCache_L2_All_Hits, DCache_L2_A= ll)\000\000\000\000\000\000\000\00000 */ -{ 3695 }, /* DCache_L2_Misses\000\000d_ratio(DCache_L2_All_Miss, DCache_L2= _All)\000\000\000\000\000\000\000\00000 */ -{ 2967 }, /* Frontend_Bound_SMT\000\000idq_uops_not_delivered.core / (4 * = (cpu_clk_unhalted.thread / 2 * (1 + cpu_clk_unhalted.one_thread_active / cp= u_clk_unhalted.ref_xclk)))\000\000\000\000\000\000\000\00000 */ -{ 2904 }, /* IPC\000group1\000inst_retired.any / cpu_clk_unhalted.thread\0= 00\000\000\000\000\000\000\00000 */ -{ 3829 }, /* L1D_Cache_Fill_BW\000\00064 * l1d.replacement / 1e9 / duratio= n_time\000\000\000\000\000\000\000\00000 */ -{ 3765 }, /* M1\000\000ipc + M2\000\000\000\000\000\000\000\00000 */ -{ 3787 }, /* M2\000\000ipc + M1\000\000\000\000\000\000\000\00000 */ -{ 3809 }, /* M3\000\0001 / M3\000\000\000\000\000\000\000\00000 */ -{ 3264 }, /* cache_miss_cycles\000group1\000dcache_miss_cpi + icache_miss_= cycles\000\000\000\000\000\000\000\00000 */ -{ 3133 }, /* dcache_miss_cpi\000\000l1d\\-loads\\-misses / inst_retired.an= y\000\000\000\000\000\000\000\00000 */ -{ 3197 }, /* icache_miss_cycles\000\000l1i\\-loads\\-misses / inst_retired= .any\000\000\000\000\000\000\000\00000 */ +{ 2704 }, /* CPI\000\0001 / IPC\000\000\000\000\000\000\000\00000 */ +{ 3385 }, /* DCache_L2_All\000\000DCache_L2_All_Hits + DCache_L2_All_Miss\= 000\000\000\000\000\000\000\00000 */ +{ 3157 }, /* DCache_L2_All_Hits\000\000l2_rqsts.demand_data_rd_hit + l2_rq= sts.pf_hit + l2_rqsts.rfo_hit\000\000\000\000\000\000\000\00000 */ +{ 3251 }, /* DCache_L2_All_Miss\000\000max(l2_rqsts.all_demand_data_rd - l= 2_rqsts.demand_data_rd_hit, 0) + l2_rqsts.pf_miss + l2_rqsts.rfo_miss\000\0= 00\000\000\000\000\000\00000 */ +{ 3449 }, /* DCache_L2_Hits\000\000d_ratio(DCache_L2_All_Hits, DCache_L2_A= ll)\000\000\000\000\000\000\000\00000 */ +{ 3517 }, /* DCache_L2_Misses\000\000d_ratio(DCache_L2_All_Miss, DCache_L2= _All)\000\000\000\000\000\000\000\00000 */ +{ 2789 }, /* Frontend_Bound_SMT\000\000idq_uops_not_delivered.core / (4 * = (cpu_clk_unhalted.thread / 2 * (1 + cpu_clk_unhalted.one_thread_active / cp= u_clk_unhalted.ref_xclk)))\000\000\000\000\000\000\000\00000 */ +{ 2726 }, /* IPC\000group1\000inst_retired.any / cpu_clk_unhalted.thread\0= 00\000\000\000\000\000\000\00000 */ +{ 3651 }, /* L1D_Cache_Fill_BW\000\00064 * l1d.replacement / 1e9 / duratio= n_time\000\000\000\000\000\000\000\00000 */ +{ 3587 }, /* M1\000\000ipc + M2\000\000\000\000\000\000\000\00000 */ +{ 3609 }, /* M2\000\000ipc + M1\000\000\000\000\000\000\000\00000 */ +{ 3631 }, /* M3\000\0001 / M3\000\000\000\000\000\000\000\00000 */ +{ 3086 }, /* cache_miss_cycles\000group1\000dcache_miss_cpi + icache_miss_= cycles\000\000\000\000\000\000\000\00000 */ +{ 2955 }, /* dcache_miss_cpi\000\000l1d\\-loads\\-misses / inst_retired.an= y\000\000\000\000\000\000\000\00000 */ +{ 3019 }, /* icache_miss_cycles\000\000l1i\\-loads\\-misses / inst_retired= .any\000\000\000\000\000\000\000\00000 */ =20 }; =20 @@ -186,13 +186,13 @@ const struct pmu_table_entry pmu_metrics__test_soc_cp= u[] =3D { }; =20 static const struct compact_pmu_event pmu_events__test_soc_sys_uncore_sys_= ccn_pmu[] =3D { -{ 2643 }, /* sys_ccn_pmu.read_cycles\000uncore\000ccn read-cycles event\00= 0config=3D0x2c\0000x01\00000\000\000\000\000\000 */ +{ 2465 }, /* sys_ccn_pmu.read_cycles\000uncore\000ccn read-cycles event\00= 0config=3D0x2c\0000x01\00000\000\000\000\000\000 */ }; static const struct compact_pmu_event pmu_events__test_soc_sys_uncore_sys_= cmn_pmu[] =3D { -{ 2739 }, /* sys_cmn_pmu.hnf_cache_miss\000uncore\000Counts total cache mi= sses in first lookup result (high priority)\000eventid=3D1,type=3D5\000(434= |436|43c|43a).*\00000\000\000\000\000\000 */ +{ 2561 }, /* sys_cmn_pmu.hnf_cache_miss\000uncore\000Counts total cache mi= sses in first lookup result (high priority)\000eventid=3D1,type=3D5\000(434= |436|43c|43a).*\00000\000\000\000\000\000 */ }; static const struct compact_pmu_event pmu_events__test_soc_sys_uncore_sys_= ddr_pmu[] =3D { -{ 2548 }, /* sys_ddr_pmu.write_cycles\000uncore\000ddr write-cycles event\= 000event=3D0x2b\000v8\00000\000\000\000\000\000 */ +{ 2370 }, /* sys_ddr_pmu.write_cycles\000uncore\000ddr write-cycles event\= 000event=3D0x2b\000v8\00000\000\000\000\000\000 */ =20 }; =20 @@ -200,17 +200,17 @@ const struct pmu_table_entry pmu_events__test_soc_sys= [] =3D { { .entries =3D pmu_events__test_soc_sys_uncore_sys_ccn_pmu, .num_entries =3D ARRAY_SIZE(pmu_events__test_soc_sys_uncore_sys_ccn_p= mu), - .pmu_name =3D { 2624 /* uncore_sys_ccn_pmu\000 */ }, + .pmu_name =3D { 2446 /* uncore_sys_ccn_pmu\000 */ }, }, { .entries =3D pmu_events__test_soc_sys_uncore_sys_cmn_pmu, .num_entries =3D ARRAY_SIZE(pmu_events__test_soc_sys_uncore_sys_cmn_p= mu), - .pmu_name =3D { 2720 /* uncore_sys_cmn_pmu\000 */ }, + .pmu_name =3D { 2542 /* uncore_sys_cmn_pmu\000 */ }, }, { .entries =3D pmu_events__test_soc_sys_uncore_sys_ddr_pmu, .num_entries =3D ARRAY_SIZE(pmu_events__test_soc_sys_uncore_sys_ddr_p= mu), - .pmu_name =3D { 2529 /* uncore_sys_ddr_pmu\000 */ }, + .pmu_name =3D { 2351 /* uncore_sys_ddr_pmu\000 */ }, }, }; =20 diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jeven= ts.py index a1899f35ec74..e821155151ec 100755 --- a/tools/perf/pmu-events/jevents.py +++ b/tools/perf/pmu-events/jevents.py @@ -397,6 +397,9 @@ class JsonEvent: self.desc +=3D extra_desc if self.long_desc and extra_desc: self.long_desc +=3D extra_desc + if self.desc and self.long_desc and self.desc =3D=3D self.long_desc: + # Avoid duplicated descriptions. + self.long_desc =3D None if arch_std: if arch_std.lower() in _arch_std_events: event =3D _arch_std_events[arch_std.lower()].event diff --git a/tools/perf/tests/pmu-events.c b/tools/perf/tests/pmu-events.c index 8bbe0516ecc0..95fd9f671a22 100644 --- a/tools/perf/tests/pmu-events.c +++ b/tools/perf/tests/pmu-events.c @@ -53,7 +53,6 @@ static const struct perf_pmu_test_event bp_l1_btb_correct= =3D { .topic =3D "branch", }, .alias_str =3D "event=3D0x8a", - .alias_long_desc =3D "L1 BTB Correction", }; =20 static const struct perf_pmu_test_event bp_l2_btb_correct =3D { @@ -65,7 +64,6 @@ static const struct perf_pmu_test_event bp_l2_btb_correct= =3D { .topic =3D "branch", }, .alias_str =3D "event=3D0x8b", - .alias_long_desc =3D "L2 BTB Correction", }; =20 static const struct perf_pmu_test_event segment_reg_loads_any =3D { @@ -77,7 +75,6 @@ static const struct perf_pmu_test_event segment_reg_loads= _any =3D { .topic =3D "other", }, .alias_str =3D "event=3D0x6,period=3D0x30d40,umask=3D0x80", - .alias_long_desc =3D "Number of segment register loads", }; =20 static const struct perf_pmu_test_event dispatch_blocked_any =3D { @@ -89,7 +86,6 @@ static const struct perf_pmu_test_event dispatch_blocked_= any =3D { .topic =3D "other", }, .alias_str =3D "event=3D0x9,period=3D0x30d40,umask=3D0x20", - .alias_long_desc =3D "Memory cluster signals to block micro-op dispatch f= or any reason", }; =20 static const struct perf_pmu_test_event eist_trans =3D { @@ -101,7 +97,6 @@ static const struct perf_pmu_test_event eist_trans =3D { .topic =3D "other", }, .alias_str =3D "event=3D0x3a,period=3D0x30d40", - .alias_long_desc =3D "Number of Enhanced Intel SpeedStep(R) Technology (E= IST) transitions", }; =20 static const struct perf_pmu_test_event l3_cache_rd =3D { @@ -133,11 +128,9 @@ static const struct perf_pmu_test_event uncore_hisi_dd= rc_flux_wcmd =3D { .event =3D "event=3D2", .desc =3D "DDRC write commands", .topic =3D "uncore", - .long_desc =3D "DDRC write commands", .pmu =3D "hisi_sccl,ddrc", }, .alias_str =3D "event=3D0x2", - .alias_long_desc =3D "DDRC write commands", .matching_pmu =3D "hisi_sccl1_ddrc2", }; =20 @@ -147,11 +140,9 @@ static const struct perf_pmu_test_event unc_cbo_xsnp_r= esponse_miss_eviction =3D { .event =3D "event=3D0x22,umask=3D0x81", .desc =3D "A cross-core snoop resulted from L3 Eviction which misses in = some processor core", .topic =3D "uncore", - .long_desc =3D "A cross-core snoop resulted from L3 Eviction which misse= s in some processor core", .pmu =3D "uncore_cbox", }, .alias_str =3D "event=3D0x22,umask=3D0x81", - .alias_long_desc =3D "A cross-core snoop resulted from L3 Eviction which = misses in some processor core", .matching_pmu =3D "uncore_cbox_0", }; =20 @@ -161,11 +152,9 @@ static const struct perf_pmu_test_event uncore_hyphen = =3D { .event =3D "event=3D0xe0", .desc =3D "UNC_CBO_HYPHEN", .topic =3D "uncore", - .long_desc =3D "UNC_CBO_HYPHEN", .pmu =3D "uncore_cbox", }, .alias_str =3D "event=3D0xe0", - .alias_long_desc =3D "UNC_CBO_HYPHEN", .matching_pmu =3D "uncore_cbox_0", }; =20 @@ -175,11 +164,9 @@ static const struct perf_pmu_test_event uncore_two_hyp= h =3D { .event =3D "event=3D0xc0", .desc =3D "UNC_CBO_TWO_HYPH", .topic =3D "uncore", - .long_desc =3D "UNC_CBO_TWO_HYPH", .pmu =3D "uncore_cbox", }, .alias_str =3D "event=3D0xc0", - .alias_long_desc =3D "UNC_CBO_TWO_HYPH", .matching_pmu =3D "uncore_cbox_0", }; =20 @@ -189,11 +176,9 @@ static const struct perf_pmu_test_event uncore_hisi_l3= c_rd_hit_cpipe =3D { .event =3D "event=3D7", .desc =3D "Total read hits", .topic =3D "uncore", - .long_desc =3D "Total read hits", .pmu =3D "hisi_sccl,l3c", }, .alias_str =3D "event=3D0x7", - .alias_long_desc =3D "Total read hits", .matching_pmu =3D "hisi_sccl3_l3c7", }; =20 @@ -203,11 +188,9 @@ static const struct perf_pmu_test_event uncore_imc_fre= e_running_cache_miss =3D { .event =3D "event=3D0x12", .desc =3D "Total cache misses", .topic =3D "uncore", - .long_desc =3D "Total cache misses", .pmu =3D "uncore_imc_free_running", }, .alias_str =3D "event=3D0x12", - .alias_long_desc =3D "Total cache misses", .matching_pmu =3D "uncore_imc_free_running_0", }; =20 @@ -217,11 +200,9 @@ static const struct perf_pmu_test_event uncore_imc_cac= he_hits =3D { .event =3D "event=3D0x34", .desc =3D "Total cache hits", .topic =3D "uncore", - .long_desc =3D "Total cache hits", .pmu =3D "uncore_imc", }, .alias_str =3D "event=3D0x34", - .alias_long_desc =3D "Total cache hits", .matching_pmu =3D "uncore_imc_0", }; =20 @@ -246,7 +227,6 @@ static const struct perf_pmu_test_event sys_ddr_pmu_wri= te_cycles =3D { .compat =3D "v8", }, .alias_str =3D "event=3D0x2b", - .alias_long_desc =3D "ddr write-cycles event", .matching_pmu =3D "uncore_sys_ddr_pmu0", }; =20 @@ -260,7 +240,6 @@ static const struct perf_pmu_test_event sys_ccn_pmu_rea= d_cycles =3D { .compat =3D "0x01", }, .alias_str =3D "config=3D0x2c", - .alias_long_desc =3D "ccn read-cycles event", .matching_pmu =3D "uncore_sys_ccn_pmu4", }; =20 @@ -274,7 +253,6 @@ static const struct perf_pmu_test_event sys_cmn_pmu_hnf= _cache_miss =3D { .compat =3D "(434|436|43c|43a).*", }, .alias_str =3D "eventid=3D0x1,type=3D0x5", - .alias_long_desc =3D "Counts total cache misses in first lookup result (h= igh priority)", .matching_pmu =3D "uncore_sys_cmn_pmu0", }; =20 diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 23666883049d..b09b2ea2407a 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -623,8 +623,7 @@ static int perf_pmu__new_alias(struct perf_pmu *pmu, co= nst char *name, =20 alias->name =3D strdup(name); alias->desc =3D desc ? strdup(desc) : NULL; - alias->long_desc =3D long_desc ? strdup(long_desc) : - desc ? strdup(desc) : NULL; + alias->long_desc =3D long_desc ? strdup(long_desc) : NULL; alias->topic =3D topic ? strdup(topic) : NULL; alias->pmu_name =3D pmu_name ? strdup(pmu_name) : NULL; if (unit) { --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Tue Dec 16 03:25:18 2025 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.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 2899525C833 for ; Wed, 9 Jul 2025 21:40:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752097254; cv=none; b=pqkZfQ5YSKH6GeiiR+5qke2aIFGRamMVD+g8RNkjyOYBPuVqX8rO+Mx9dEtYcfipn9r7uG9yNHK0c4P+IeJmSg7VCIl1JW1J64BtsycsimyiTCQ50GM5KEG66Uy6ugtJAv3y3neFqs27qoywin+iSjMxdz7UVLRjaaMwKEGtol0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752097254; c=relaxed/simple; bh=S3yRMHiJp63Z3sa35dQZZnYodURgDAIos+timRoWgfo=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=J1sFokLYzjHFPH7VHsLdNeiZMFFQZjJNdQvA6vzsRFJcRMR8rxAYwmGwk2w2V+bIO8mUVpKA9oLnJhwvO0VH8hZG9RrOOU5h5zMiKJhn3ba5LWcdm2KUvTHaZBEbNuXfxKvs16jJfLUYu92wklsqirVmfF5QsvqMY6O369Pl5eQ= 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=p2/+vNdi; arc=none smtp.client-ip=209.85.215.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="p2/+vNdi" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-b2fcbd76b61so406334a12.3 for ; Wed, 09 Jul 2025 14:40:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1752097252; x=1752702052; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=Ah0+wkOLh0SfnYMJxPVvQJg73AT2FFx/KryIhqiVcI4=; b=p2/+vNdiFF1ScDWAvzuaEWKFbLT0cPrtWaUvoZunRoRGqke1KS907gZVn5/CgQizma UBaYCF6Pm7pqCKO8W+uEl7A3MhvH24XskV8Z4+EjZKI9DlS/AdqRDlwU7RQNVS5AX48N FhuU8yraFrx+tW+xhg214tNW4+9qIXqYTK21m7y/drAzQAjiOXn6H9BUhxb+84JC+oGj BhNLhQx0k2SqFmZ/H+XRHSukryEmxOsPj6WmwIJ+dtzSq0afskwo+5rY3dui5YvBfEVU Y+p9Z+iFdERQrk9Q2HfR4BFV7vJ05Ya92TFKKPFtcCNYi8vCXlaZludAemAYlhJKKWYl Byew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752097252; x=1752702052; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Ah0+wkOLh0SfnYMJxPVvQJg73AT2FFx/KryIhqiVcI4=; b=eqhss8Z+LUQmnCoS5PRle8CcafelaMj+rJJHW+v0V0uS6aUVBc2OmyD0ECxIOCPCHh 4IVckTMnrssgG0WbCSHV7p3CJKUmQKUJFVKX4VroQp4GSFtEILjNLUHlTNWVs/AMAIoo 71jokUmuVgujKAnnCEH9vQqmvn2OqTxWAuG8lUVNY5DP0fb7bCV+8G/L6LUT5/brKxkW CnLmwS0LTJU/R+mD8I5Fbq8RFSRcCcfJgRXcOuRxFQP5/c/otzAsEdl1hzPu364Mbdo8 M/c7GMs6ildQasKW7Z+h253nA53y8Wb5xHsc/KQ0a2X6bbsMdxMktJNWZARAGqnXnjwN JqAw== X-Forwarded-Encrypted: i=1; AJvYcCV68oqxaSIAB0RUeAYwdmorK1aLAOKIcy4KmzQp1IsRiL27nwVL9l9XjdM1uFKu6sUSPDmMiqyBKEm2Ihg=@vger.kernel.org X-Gm-Message-State: AOJu0Yxtn8bAoUOLSpbig93TgvPgo/tKijL3sj0nM+MTl2/2+2G5D5XV uCL695Av9pJyXOGvfylU55FA5fHRO1kif5JgcIB9RYc8Oe91c3boSw9Pkl8EtccUuDXTDfq3t6s LlWiEeGfW+Q== X-Google-Smtp-Source: AGHT+IE3bMTEiaAvZjwECwHqvmNwTimZoOEIqLX76Q+VxD1c2+r6Vimd0Q4OgbRb6fCXgT+dFIOu6fecErrE X-Received: from pgae25.prod.google.com ([2002:a63:3719:0:b0:b2f:1e09:528b]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:9188:b0:1f5:7eee:bb10 with SMTP id adf61e73a8af0-23003de3380mr346052637.8.1752097252483; Wed, 09 Jul 2025 14:40:52 -0700 (PDT) Date: Wed, 9 Jul 2025 14:40:26 -0700 In-Reply-To: <20250709214029.1769089-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250709214029.1769089-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250709214029.1769089-10-irogers@google.com> Subject: [PATCH v1 09/12] perf python: In str(evsel) use the evsel__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 , Xu Yang , Howard Chu , "Dr. David Alan Gilbert" , Levi Yun , Andi Kleen , Thomas Richter , Weilin Wang , Tiezhu Yang , Gautam Menghani , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The evsel__pmu_name helper will internally use evsel__find_pmu that handles legacy events, extended types, etc. in determining a PMU and will provide a better value than just trying to access the PMU's name directly as the PMU may not have been computed. Signed-off-by: Ian Rogers --- tools/perf/util/python.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index b5ee9f7a4662..0821205b1aaa 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -925,10 +925,7 @@ static PyObject *pyrf_evsel__str(PyObject *self) struct pyrf_evsel *pevsel =3D (void *)self; struct evsel *evsel =3D &pevsel->evsel; =20 - if (!evsel->pmu) - return PyUnicode_FromFormat("evsel(%s)", evsel__name(evsel)); - - return PyUnicode_FromFormat("evsel(%s/%s/)", evsel->pmu->name, evsel__nam= e(evsel)); + return PyUnicode_FromFormat("evsel(%s/%s/)", evsel__pmu_name(evsel), evse= l__name(evsel)); } =20 static PyMethodDef pyrf_evsel__methods[] =3D { --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Tue Dec 16 03:25:18 2025 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.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 4FE1725DB0B for ; Wed, 9 Jul 2025 21:40:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752097256; cv=none; b=SI8/qaroQjKQdKaQWOOejYuSFHTwvG5RJ3fFikrEdK6yMJJ3NucHQog4Ti+Hzfdv2Hmw7WEyd9tBykylXrNnshiVmWLTZktYd3VhVit6wSbMAHvsLXT3BgUyHz/KdyGh2rgyHq9OTwduz0CciR1Qdgeh/IDnwrC4gh+z/MAXAOE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752097256; c=relaxed/simple; bh=vOwZDvr9Vl8FEdFAuVf8wVoxDa4D0UfmaiOanE6AyxM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=ToFSCeATDI2wLpmwXJGPcIwecIT8Q7c64klh7jtMEYw/YsRlspw0PmIhw26v0e/LSQ5HkLMOQBDksV52qnlA4fL4teRRWuX8m4L9f+SCGGorO15l0zdT1RRhONAXrNyrLgGXsnar6stgKbgh2zbF+OmB9p0P8cOc5Bn8sQGsWuk= 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=JB+lxBE+; arc=none smtp.client-ip=209.85.215.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="JB+lxBE+" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-b31c38d4063so217074a12.3 for ; Wed, 09 Jul 2025 14:40:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1752097255; x=1752702055; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=P9BHuR06NtQbT/Ectw1+ZMQbL3vfn86FK+37sdptByE=; b=JB+lxBE+QAjc9IcWC4+sFfYgrhR2/aNgWL3GIBL4nGni824czDlDqcbDp9+5766wZy xd4XaOaefbDNw4IvagVuNEhebBe/jiyxFK7kSu9epAh87LHR/1cYXf4o4JejtQzDyteZ eM+PdGE7ruquAtg6kS1Ji+9IcD+UjHqKf06gvbQD3ZdQLGQznKQzpQXVXdvY8gD6Nk9r jaKKqTsGz6isqaC7CWvQKpoBoBWxOmwlMbzDB7KUMzW3hP/Yjha6b2Do5qh+4y8p5Q41 abR5lf7TGDlnbA+218rnMjOWabUyb3HoBC0HM1GAxQWjdeVC9S1nYCDMj0L1bTdGkUvk gHBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752097255; x=1752702055; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=P9BHuR06NtQbT/Ectw1+ZMQbL3vfn86FK+37sdptByE=; b=p2t3RILLt+my2rsYebXiAbgbQ0+QjMlkcfmWhiRiFAaH1wcHF6JKen9HvTR6YSyew6 SuKXNS+UNTr+AC5Ln++zCMC1Zpm/se1ZGmHhLZIwjYZoS+LPbUJDXWHqueq6eN1anB3V 0gnf3OEwib52JvYk6pkMqyR67KiWjWqreWVvBdQ5sUIEj8zhHkFDDnSI/HZ8b/VFcnZI R1/vUDVoQPAywqD/0pYApNdoqepjDEwain0KNb6ojW127DF6FmaZO4y+Ygj6ijqeLTra l2tVt8bVmJNfyEbGYmfBrjKgADHHsH+sC+jBsC1cY3ekkCZBrd9rA5J82GiqQ5SO6/Gu zTrQ== X-Forwarded-Encrypted: i=1; AJvYcCUPsyD7o7HPHg3y+1NyV8onXQFFzrekuaUEtO9zndBosfmM5aTXUpFPYXqTJbISPbbZz4zBnA8Op0fiESs=@vger.kernel.org X-Gm-Message-State: AOJu0YxuWad7mFasDVyoyZKBdmy95KfYAyZlP4hPEDL7HTmVRT1yj5D9 kBIWqJrrpBnKkw1FUDMVFX86sXbOU9UC8s7kzjOY86bhsYoL2MENSjBQIA/Uv7Fv5ugKx28ISYX mO0AD0celyQ== X-Google-Smtp-Source: AGHT+IET4wDIl8RWHQ92JBgsF3e1FcY+s+Ox/E3fRRO5h6tw2hx4TVcghr6OXM4+cGpdN8tZCfY3Osn5sSmw X-Received: from pjbqd13.prod.google.com ([2002:a17:90b:3ccd:b0:312:26c4:236]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:3512:b0:311:c1ec:7d0a with SMTP id 98e67ed59e1d1-31c3f03f810mr234327a91.25.1752097254579; Wed, 09 Jul 2025 14:40:54 -0700 (PDT) Date: Wed, 9 Jul 2025 14:40:27 -0700 In-Reply-To: <20250709214029.1769089-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250709214029.1769089-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250709214029.1769089-11-irogers@google.com> Subject: [PATCH v1 10/12] perf python: Fix thread check in pyrf_evsel__read 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 , Xu Yang , Howard Chu , "Dr. David Alan Gilbert" , Levi Yun , Andi Kleen , Thomas Richter , Weilin Wang , Tiezhu Yang , Gautam Menghani , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The CPU index is incorrectly checked rather than the thread index. Fixes: 739621f65702 ("perf python: Add evsel read method") Signed-off-by: Ian Rogers --- tools/perf/util/python.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index 0821205b1aaa..4a3c2b4dd79f 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -910,7 +910,7 @@ static PyObject *pyrf_evsel__read(struct pyrf_evsel *pe= vsel, return NULL; } thread_idx =3D perf_thread_map__idx(evsel->core.threads, thread); - if (cpu_idx < 0) { + if (thread_idx < 0) { PyErr_Format(PyExc_TypeError, "Thread %d is not part of evsel's threads", thread); return NULL; --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Tue Dec 16 03:25:18 2025 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.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 611BC262FE5 for ; Wed, 9 Jul 2025 21:40:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752097259; cv=none; b=U/OBD/23kpj1RPyYsdk0LPWCe7UUbc1lWJQdO3jtFv1WLgMnPLKsKdF/KgSBCnOpoKvciYzhnRdPLxRsZNjHbxYdxvxGARbhRifOfhuemvgD4bTHRuItSMIfRdJ2YXTBbasu0f/3nmqZaKXSvZ7ypJRJd0veuc5t5RDqzZb/mok= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752097259; c=relaxed/simple; bh=E5+kvYI2Rn6W9To+wrAcq/gxgLLQZbgSx4MLHJcahUI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=is2EQAxmYdg3Oqt0Tde9J86Vvs4fOkZB/VSlR20S/0vmUAsq4Pco3ks/SkYPsPbktZ9Y8a8RSsvhEDgkg+VZy6oZaFNq345A5z993MN+eXcfomSKzyt6Oi9ZBAWo1+OJ99zioiASwXNRNEBM3wgF9jk+zz8JVG5Qj/nrbuXbob0= 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=cvxw8i4h; arc=none smtp.client-ip=209.85.210.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="cvxw8i4h" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-748e1e474f8so426163b3a.2 for ; Wed, 09 Jul 2025 14:40:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1752097257; x=1752702057; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=wPzAwcY5wS+r0tfRkqlbV0oEuH3EOdPNkOfWet+RrhE=; b=cvxw8i4hPFeu8AI/dRWkVIm4epLpc6eL3IPRWDFZNBQEXkt8avfPYn9mOYWJH3rB6G 3+3A5CU7a4viQIY6l/2OEzByupY9E7SK8MzfkLbQ0NYt4CDbGJBFYKErX0jZypM+VRFz leUAXrYU6DqlR8FDWHEA4ch/0dP0SqCOsO5H8JGXg2k3JV6nqZITLjg8sSnnXupBKr6J Kzz3W0I7CZ8VHVW9n4dy5oDIhw6sy5QbOwtGHQgbaw4b5E0LtIaqfNdt8bWEvwDHBd32 W9bMP4JH2PGVO4QCR187nlO20rynQP73+LFjYI0A9G/+pZDqpw7sZx9bI69JezIV/Fys KP2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752097257; x=1752702057; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=wPzAwcY5wS+r0tfRkqlbV0oEuH3EOdPNkOfWet+RrhE=; b=BMybcqOn5KZUFdu3wCNZMrokGzW4uHrdyyXcE1w3aJTIz5Ezci1Xnx2PXpgu1eVkX6 jtepeMq6h6N7yYlQ/asQEmiT4A++9riNwXkbmfNDcbe7iwvun8PlGjtaFTPAXUMxX7JI Sw72+R7Up1PlNsmj+5AA6+pPmg0URUnSF0zO3R/JQS/u4W8rVsmwDwHNJFVfFoDf7FMl jdT69DNODLpx6UG3PIW78xQt72aSecRhzbBv5+Lrfi04u15JdL1MdQ3vMi5Ui2D3IaUV AOgJL9vD18ybEt9wWqjK6TSNGNVNGkRZlCv4ZmmL23Gx0qMgceQLI5ChA3uquDiiVgli xaOQ== X-Forwarded-Encrypted: i=1; AJvYcCVSGIT3r+w0se4vO7BXHum+kqOkXbIxP50piNpUYW7t2DtY2JNoAAngR6RpkkRyWER9F4Z1PbseoggecgA=@vger.kernel.org X-Gm-Message-State: AOJu0YyoP+4VQLf9F6vI+1RxZsGgOBgWjihyIh9pyfIZE5A0NTM6jHtQ 0qkG45DKKziiehzMrvluHOYRWjD+VhXpxH1674uGAPtIctJxLgBHVB/s2rxEr/ablbhSCLlGndz ElB1MWgKdEQ== X-Google-Smtp-Source: AGHT+IHL51fC9ib1TAeOQOpDuRYctIEJ481bXGA827xdlsrjNXSyz3KO6lUfEvpnf7effYW5jNRaUhpYIczi X-Received: from pgmw27.prod.google.com ([2002:a63:935b:0:b0:b2e:c3bd:cf90]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:3d07:b0:21f:77e2:13a0 with SMTP id adf61e73a8af0-23003fdf125mr305814637.5.1752097256732; Wed, 09 Jul 2025 14:40:56 -0700 (PDT) Date: Wed, 9 Jul 2025 14:40:28 -0700 In-Reply-To: <20250709214029.1769089-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250709214029.1769089-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250709214029.1769089-12-irogers@google.com> Subject: [PATCH v1 11/12] perf python: Correct pyrf_evsel__read for tool PMUs 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 , Xu Yang , Howard Chu , "Dr. David Alan Gilbert" , Levi Yun , Andi Kleen , Thomas Richter , Weilin Wang , Tiezhu Yang , Gautam Menghani , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Tool PMUs assume that stat's process_counter_values is being used to read the counters. Specifically they hold onto old values in evsel->prev_raw_counts and give the cumulative count based off of this value. Update pyrf_evsel__read to allocate counts and prev_raw_counts, use evsel__read_counter rather than perf_evsel__read so tool PMUs are read from not just perf_event_open events, make the returned pyrf_counts_values contain the delta value rather than the cumulative value. Fixes: 739621f65702 ("perf python: Add evsel read method") Signed-off-by: Ian Rogers --- tools/perf/util/python.c | 47 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index 4a3c2b4dd79f..f689560192f4 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -10,6 +10,7 @@ #endif #include #include "callchain.h" +#include "counts.h" #include "evlist.h" #include "evsel.h" #include "event.h" @@ -889,12 +890,38 @@ static PyObject *pyrf_evsel__threads(struct pyrf_evse= l *pevsel) return (PyObject *)pthread_map; } =20 +/* + * Ensure evsel's counts and prev_raw_counts are allocated, the latter + * used by tool PMUs to compute the cumulative count as expected by + * stat's process_counter_values. + */ +static int evsel__ensure_counts(struct evsel *evsel) +{ + int nthreads, ncpus; + + if (evsel->counts !=3D NULL) + return 0; + + nthreads =3D perf_thread_map__nr(evsel->core.threads); + ncpus =3D perf_cpu_map__nr(evsel->core.cpus); + + evsel->counts =3D perf_counts__new(ncpus, nthreads); + if (evsel->counts =3D=3D NULL) + return -ENOMEM; + + evsel->prev_raw_counts =3D perf_counts__new(ncpus, nthreads); + if (evsel->prev_raw_counts =3D=3D NULL) + return -ENOMEM; + + return 0; +} + static PyObject *pyrf_evsel__read(struct pyrf_evsel *pevsel, PyObject *args, PyObject *kwargs) { struct evsel *evsel =3D &pevsel->evsel; int cpu =3D 0, cpu_idx, thread =3D 0, thread_idx; - struct perf_counts_values counts; + struct perf_counts_values *old_count, *new_count; struct pyrf_counts_values *count_values =3D PyObject_New(struct pyrf_coun= ts_values, &pyrf_counts_values__type); =20 @@ -915,8 +942,22 @@ static PyObject *pyrf_evsel__read(struct pyrf_evsel *p= evsel, thread); return NULL; } - perf_evsel__read(&(evsel->core), cpu_idx, thread_idx, &counts); - count_values->values =3D counts; + + if (evsel__ensure_counts(evsel)) + return PyErr_NoMemory(); + + /* Set up pointers to the old and newly read counter values. */ + old_count =3D perf_counts(evsel->prev_raw_counts, cpu_idx, thread_idx); + new_count =3D perf_counts(evsel->counts, cpu_idx, thread_idx); + /* Update the value in evsel->counts. */ + evsel__read_counter(evsel, cpu_idx, thread_idx); + /* Copy the value and turn it into the delta from old_count. */ + count_values->values =3D *new_count; + count_values->values.val -=3D old_count->val; + count_values->values.ena -=3D old_count->ena; + count_values->values.run -=3D old_count->run; + /* Save the new count over the old_count for the next read. */ + *old_count =3D *new_count; return (PyObject *)count_values; } =20 --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Tue Dec 16 03:25:18 2025 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.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 58BC6265284 for ; Wed, 9 Jul 2025 21:40:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752097261; cv=none; b=CrS7LhG0/xcjXeIZ+8mzmStyg8+GOHQ6lE8esx+D4zTp+itZQ93Dz+sPCYGjbi7HYjrHI2bZhIpOor9nMzvWHiVMWQjXz8ttdB4/fGfppdwjbkaSx+r8vFbbl5wlDABtMHf/UnKXyBvI84iqZ3pJfFFmO4JXGI9tt2Hc1besOsU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752097261; c=relaxed/simple; bh=taguiAu+XCAIQfq0Yy35oTrHyGgNZ8BMVFBK/i0b2/E=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=VP6Qn4jDn47I1BqAn9zFyxnPKZ3yZduxi1XA3JIsDBR/XEmaKd82KKVhiB1UPibpBRkd6wzm5x/UD0bncbyEL4u7WPFkFkggZczdDS51a+9IQ5RN6B6j9VXeXyB8llOrBbY+aOD9SA9loiWw1ejrJA6YjgDSe6C9XesRrZq9tdo= 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=yixeryP8; arc=none smtp.client-ip=209.85.215.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="yixeryP8" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-b34abbcdcf3so233489a12.1 for ; Wed, 09 Jul 2025 14:40:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1752097258; x=1752702058; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=Yn07du8/mYddRoeb96O+tFsLyXiFjIJK2Jw/FgUbdtQ=; b=yixeryP8KEElgnO/5DnaiqjdeQtzhRymHgTjENkdbpBZzNGkBimW1/iNNZEeJFbsoR LRICQT4YK36+rEuFFQtkhzsfI1pk1/jsmCLZbaw+e1WVj/YkXLARynsJjNVJZGKbDrHc mQzVuH42MwFUZ8ANUXfBNXYdiLOOkRJeOTQqJJzB6h9Tak0PvKjoWkS6tnwau/O3d7A1 /2cFfgYMelORqntP2R6w1xeWb1Ea4zXh/mTWqDfKX1tfre5WDIP3LUFtdmOgWMN7qka3 uEzlbVVIM8NHKvXtwMlm7fDbKUlsPY8L2ipojzedlSqGUrZkrohCBZUdW7js23w3qF9M +tyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752097258; x=1752702058; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Yn07du8/mYddRoeb96O+tFsLyXiFjIJK2Jw/FgUbdtQ=; b=iANmZPqLhvZNyikjXa+hOOxk2zSpQCeRbqpVoZs75YlxcXeL7UnhYXSihGGC6MFahO kdAHqTb/VCRwXRTM4fIJEPkc519TLUXjEMNuOyxShem8yTh3pqLXeMfoRolwhmJBSUEW It9ZRWu6mw4QLzIjsYWJwEBa5gKbQXx99i2oPLujE60Z6V4YY0Ja0HSdgZoPs5RGydYX Jh4QCQ/KkJbB5kK0N9H/cBTpjlg1C9vyxstlAeeHkXuCs4JUSkXedL9BBkgZT8MT7VXJ NSx8pLFJdPJNQ6+pxr4QYF8lWGOElA8yfcuZfOQLX4yL02YyLhJwFr87zVFnyPPF5/L9 wHyg== X-Forwarded-Encrypted: i=1; AJvYcCVsEGXj/T4LVRUxsvXKds22Z/vsmkS5Zr6BN3ZgvFdxspCuXrefMN4Qvx6As8O6We24/vOo0G5gh0YR4MQ=@vger.kernel.org X-Gm-Message-State: AOJu0Ywof0PvjUVlmCw0/s9Iiil6U+xTYY2vCkbcHhq8JFgFvKf0DO6C HJ5AM/0xzhopfslytZi/rQZtMyTt/jmHnqaYXkLHusmv0xzhIwshSQG+QVlcHfyyK8tjdannerb 1bUxwt1C0SA== X-Google-Smtp-Source: AGHT+IFpZES2b6ONLtzlMFYm7NFl1lVqMzCjtuWVqhSi7IKE8r7O3xr8e2sxXbNipHUDbPKriS5aVIZ1HZ5Y X-Received: from pjbsw6.prod.google.com ([2002:a17:90b:2c86:b0:313:245:8921]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:568e:b0:2ee:d371:3227 with SMTP id 98e67ed59e1d1-31c2fdba404mr8152456a91.17.1752097258649; Wed, 09 Jul 2025 14:40:58 -0700 (PDT) Date: Wed, 9 Jul 2025 14:40:29 -0700 In-Reply-To: <20250709214029.1769089-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250709214029.1769089-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250709214029.1769089-13-irogers@google.com> Subject: [PATCH v1 12/12] perf python: Improve leader copying from evlist 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 , Xu Yang , Howard Chu , "Dr. David Alan Gilbert" , Levi Yun , Andi Kleen , Thomas Richter , Weilin Wang , Tiezhu Yang , Gautam Menghani , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The struct pyrf_evlist embeds the evlist requiring the copying from things like parsed events. The copying logic handles the leader being the event itself, but if the leader group event is a different in the list it will cause an evsel to point to the evsel in the list that was copied from which is bad. Fix this by adding another pass over the evlist rewriting leaders, simplified by the introductin of two evlist helpers. Signed-off-by: Ian Rogers --- tools/perf/util/python.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index f689560192f4..ad2437d132f3 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -1568,6 +1568,32 @@ static PyObject *pyrf_evsel__from_evsel(struct evsel= *evsel) return (PyObject *)pevsel; } =20 +static int evlist__leader_pos(struct evlist *evlist, struct evsel *leader) +{ + struct evsel *pos; + int idx =3D 0; + + evlist__for_each_entry(evlist, pos) { + if (leader =3D=3D evsel__leader(pos)) + return idx; + idx++; + } + return -1; +} + +static struct evsel *evlist__at(struct evlist *evlist, int idx) +{ + struct evsel *pos; + int idx2 =3D 0; + + evlist__for_each_entry(evlist, pos) { + if (idx =3D=3D idx2) + return pos; + idx++; + } + return NULL; +} + static PyObject *pyrf_evlist__from_evlist(struct evlist *evlist) { struct pyrf_evlist *pevlist =3D PyObject_New(struct pyrf_evlist, &pyrf_ev= list__type); @@ -1583,6 +1609,13 @@ static PyObject *pyrf_evlist__from_evlist(struct evl= ist *evlist) =20 evlist__add(&pevlist->evlist, &pevsel->evsel); } + evlist__for_each_entry(&pevlist->evlist, pos) { + struct evsel *leader =3D evsel__leader(pos); + int idx =3D evlist__leader_pos(evlist, leader); + + if (idx >=3D 0) + evsel__set_leader(pos, evlist__at(&pevlist->evlist, idx)); + } metricgroup__copy_metric_events(&pevlist->evlist, /*cgrp=3D*/NULL, &pevlist->evlist.metric_events, &evlist->metric_events); --=20 2.50.0.727.gbf7dc18ff4-goog