From nobody Tue Oct 7 08:53:53 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 DAD9B2F0E42 for ; Thu, 10 Jul 2025 23:51:45 +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=1752191507; cv=none; b=STDYj5s51GbCqKz4Y8KOq5p1n+gjURMy7piCF2YzFlNFq+mvuKeB4NNJtdGijiHziHAUtBNT5MduTMNgS1qBPmhSmJ2R9SkRzoo2APG3viZLCt96i85Rytd6kN6+QJ51IMmXjFEYvLo4tglzsi5/YW4B5saM+Ckuzt/aPPWM6Yg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752191507; c=relaxed/simple; bh=1lk85E3pggo+4g2GknSYWSWNs6o0Mw8jBXtuFvYNkFU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=in/WAmQbDAgBFjoDtb9EnXcfYKIZrc4rd+/AYhjXlt+P5kvCi1YOhegGLzrHGigtAVTeJ8/piMRHZua4vFB7uBlu0Y2p3+MjtWfdggg+Ipw72woww5KU4YX7DKejFHm7QcvSX7FlCla9nvpHtSGFjBRllWLXVQaJauIwgA75tG0= 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=A16fptkP; 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="A16fptkP" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-74b537e8d05so1340240b3a.3 for ; Thu, 10 Jul 2025 16:51:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1752191505; x=1752796305; 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=A16fptkPUgMygWL5n7EteLN9T4o9of8nwLL2MQo/A3AEpbJOp3ZeioPHB9/xIIOXqu S5Un/v7xQk+bHi3k4yzpEbB27I3CBIGAF+hJkNzOLC+/qt+zpXBx4oQSiGFAc5yDzj45 oYha+KdWFW5lFNunyEWp1zcHC8d4fBLuVPYFAjmUW1mbanY4NFuNIK5Ft3x/PmD1xAYd R0vbBRC0zPkxvqYijirXUY5sv8c9C/Xj4ORIxH6ZLa5wRVeuMW+IsfugogN5sB67651+ /oreDCWkTWhuQ9Zlgo5XwN1eEkRw626eJLhl51okoa8cEAXuFcHZwbdENkXe2bbyXQ7l 1xMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752191505; x=1752796305; 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=LgWdtUsZ4HG/9B9+L3/VnTuBxzeG3hzLdO1G1Y+WnKvplcrD8kcq4cbY8eD1/kNvKJ Ue4sVM8EhG5EHk7qGJux4F6gG8a7nNrz/xkHkYAVrOLxQOK9pYPqTanCCIseHzKKrd6T xs36C2N9Phl9R8GhUkFWa0SHo/CKTZlcnDvtFt1EmA+ZJ3u1X62T+fcHjWYPj/qaBPRw IRk8cTU169jHvuW1i6hFeaJIOH80+p/uCKBd6uzVtCVRKl28ov0uvFheOm2w39GZKru1 SlC5Opxeq8gh9PMc+j1RzoteC/uTyRnWnkZeyHcLtL9OC7tNqNIQnEw4V6Z4ZBTuDTO+ OXSw== X-Forwarded-Encrypted: i=1; AJvYcCUvzr2IpBYiPgMBUq59GpMhQrxB0WChuJluqUqcH1MFEKU9mNdcD+1O1ygoP+Yd381ehtirjJeK3LJYqXo=@vger.kernel.org X-Gm-Message-State: AOJu0YzCVaP7XkEdfKggt7AcMBdHasRvtgKk03xk3Bru2hGI64fRnKC1 TAALo5cxc8AK9SUFZKzueZVp89nxxQ8b5mhO2tu4NK/ZvsjQhklaKM+WWCRwu5kIMcrw6BwKrMA 84wI82c/Bsg== X-Google-Smtp-Source: AGHT+IHhdLwz+3hSGBHFsdbHDLyXIj63VirYBMWizArAnpS5ZmCGhuVXeLyvLkf5528juWTzIYXLANFzoFZC X-Received: from pgct4.prod.google.com ([2002:a05:6a02:5284:b0:b2f:a31c:f7bc]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:c709:b0:215:efed:acfc with SMTP id adf61e73a8af0-2311dd59489mr2325349637.7.1752191505056; Thu, 10 Jul 2025 16:51:45 -0700 (PDT) Date: Thu, 10 Jul 2025 16:51:14 -0700 In-Reply-To: <20250710235126.1086011-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: <20250710235126.1086011-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250710235126.1086011-2-irogers@google.com> Subject: [PATCH v2 01/13] 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 , Thomas Falcon , Chun-Tse Shao , 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 Oct 7 08:53:53 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 B319C2BEFF0 for ; Thu, 10 Jul 2025 23:51:50 +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=1752191512; cv=none; b=Ve8AC3p1eR3sU4VgOH1bfu8VO/j8EKqWvGjV5qRq1hRR/uEJoWYCRbUS3RfbzwLMMfj3a6aDyLiuAyN3EHR7pVZAMbd8BElIzRtAyDQqLczKM4h7Uu4M/74YZW9XSQ4SsZ3XAtf3vZAt1n1/rMJHXqAlIQnSI3IiDNfq143IOh0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752191512; c=relaxed/simple; bh=SCSVRXj5DB/cfKYLIvAW2+qqqcd9DzSoDst4X0cpuZc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=XO6uny5u37cbn/f0nUyKJ0E+16S4wzyYdL264F2jTBFV4hgIqTPN0XZgXCuubtGuT2uaJNK2lmz9fe/PmQ+1jNlHHtZyGzCKwLl7Q+eGUZOnNa0J2NGUt9ACHv69J6hkKDDpovj+NPch/FOH8nBJ+3TBhv8ccPxCW1SvX3Ji+Nk= 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=g86iauXM; 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="g86iauXM" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-3132c1942a1so2330787a91.2 for ; Thu, 10 Jul 2025 16:51:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1752191510; x=1752796310; 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=g86iauXMog/VEE5iAQ2iWB1tnmY3YGO4AkWNVcWuytSSeiI9T/VWxUOPwwg5FZHrjY GJ9da4oB2BatBO+/DpxYiBQ1YibpfR+mQPVdXgX2lMvvxPoun9+tIf+oJEgi1LKAVD3S tek2XcVFX5cbE1VcO9dYwf/9glUMWY3xvlhLAaQzqgYTlOx/y8t7wXaRlXukKN5sF4AO K9MLvHnmOi//sI8QuSE8XHvUQpdF590KjsTWcKJpZKa1lPEcUw38Q8hdLkmdQ0aHMVcq vDZEUOripCHraAEyDoS4elGFWCULGczAP6ki+a32ZenCo+vqC+6EULFew2FilKjWAdXs m1oQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752191510; x=1752796310; 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=Yl6KEPRI3GH/EVkJc/8bFjzQodIYxIMmi48jlrwbDPBClYtWFF6d4Ep2R/NodY6Jkx cBcx/wayP/GObF0BtsY1EaIho7WGhX/y6mWwVOQY1BR2PweKyNdZnnolq0mJt57AbrX7 EtPIhBtxgbCFV/jj6OtJvW7XEiXVxBSayt5QScYrknAQeM8h1LP3ulnsRynvHbmMBffb +rWiG0HVrJbqKBm4Yu5WuHEpV/D93Pm07RcbBfdB4q0JTmHGkADirIPV8yatOksPCnJr 3nbATxDclvVlHXoCmOFA5a/BeFlf8KCHqPBmek6UDUs0bSDNMIjtaHdqG3qixjP8kGd9 YrNg== X-Forwarded-Encrypted: i=1; AJvYcCV5o3JCJ3FN7bLUs3S9X40KRPWrM9/dPLJoIH70dUav7y2vDdC8B7WO8EocMQ4ubgZVwzPCGCeSepuR29w=@vger.kernel.org X-Gm-Message-State: AOJu0Yzp5cjTkH7tYUXjPSwSkB79PppDVgu/GnatL4RjdqTlAEhCEyg6 TQYd1fofVbDhmQ2Nop4wHxONDwSu1m3Wxq8FyNOU+N5ne8/fNh0I/JFEz6oLapY4dRD8Ngket7L IMmYAPK/xZA== X-Google-Smtp-Source: AGHT+IGDs1DJDRF+w5DfFiNFxRUIQpInUV1CXnVwgdORwT/YMVNMGT7CuysH9mPzHKNuwHFli0N1Okh1N8rH X-Received: from pjur8.prod.google.com ([2002:a17:90a:d408:b0:31c:2fe4:33bf]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:4b83:b0:311:e8cc:4248 with SMTP id 98e67ed59e1d1-31c4f5d782fmr773133a91.33.1752191510088; Thu, 10 Jul 2025 16:51:50 -0700 (PDT) Date: Thu, 10 Jul 2025 16:51:15 -0700 In-Reply-To: <20250710235126.1086011-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: <20250710235126.1086011-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250710235126.1086011-3-irogers@google.com> Subject: [PATCH v2 02/13] 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 , Thomas Falcon , Chun-Tse Shao , 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 Oct 7 08:53:53 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 2E5AE2F0E42 for ; Thu, 10 Jul 2025 23:51:52 +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=1752191514; cv=none; b=URNMw2OUtw2ZDRcVPYulMqBbr1/kvg0chmhwfD5xCr47y025yLLOoXm4px2t9ehatS+XkxyEKo8MCPpDuBa3W53+3+xFsToWJwprJoOkrzi/kfQGdofJ8mAktWYYCzIPRl490mpDCf5V4oX/x0tFMJ0xP67OGghn44TsG9qw2wg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752191514; c=relaxed/simple; bh=4RhnUIdDBTq0pKyjxJeOi7qIuV8UBI3E2+4jD3YcP7M=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=UEsUH5wGnPD0RrwQOxVxvhQIyUSJnJWqrQNPF6pipjnkuw+DDcjpHOeuqHhXjIs4PxdzDkmMzFdAtrgvDSM6/E3DrxGutQTVaM3gS6WUEkFg3sMVnWDaRI7EecGpV5K+gqtkS7OqdpaF5e2p/k13GBgz4pWlrp4gpS+KScOngLI= 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=lHsJ89L1; 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="lHsJ89L1" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-23638e1605dso11526505ad.0 for ; Thu, 10 Jul 2025 16:51:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1752191512; x=1752796312; 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=lHsJ89L1kDJvdPXp1LYvPU/cvGMxlERd5bJIycrz8YsKd0zBgTM9ZEX18R3Rm0NptA 4G6klv4+J3oIgfwLLuV7iV/SrE5PU2Q58aW7/OHWbPoGoycGbU43flkv34+OKDkVIxur NxDe9Cq/Dx40OZh9MzyakPEBFggpaqri39PjI8Q3ecMBNpl1ybS2BmctxLj4rTHkFYrV 8MzT7fkI1su0PEC8aFfkwzzxUyf/hkSTFOF5iqd2bRzWWVKAkjCy+xo1dnlAeBBl/ZsO nieXQQBUwUTP1YiGefDGVih9TYiPiBpLM6YPeQjYI7azJyHO1gU9OYdJnZpjPX43Lfd7 4Y7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752191512; x=1752796312; 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=gitG+y52SCmnEFMjYzFeZ+tC93EKVRu9UsjYX0XOtRBftcUZXzQqkEGRehflG3EyUK Tzcw4oXlqd7i7euJ2GaRg5zcbXmjM/tkPxqifPoyhkZQfcHaUJdx9UUCG2bkGYiKk+Zg uBiSJMZxsmvgPgkim+yh3AWx94HPixqM/MMBDCOKtR1JDeUofOXcPXUs0lkpcrraMz+4 2PyB+CQ9hfM9lv59AsN4W6VK5c+54UCZ32rjDEZ+a//fXqVQTYhuSKynVRsMSlyDwYI8 vC0hmNkEUEkHQx3Lb3YsX1/EqAHL57UYKylyBXuc6zrQB5AIqZLFImIjcE3AqI/0GC6K lL7g== X-Forwarded-Encrypted: i=1; AJvYcCVmHvx//owV6kU07KTAs6QhJgRbc7Y928e6jaOfRkhNMCgSd7274u/eDs+Mw59DlW+y4OAXxOaX/Xox+ns=@vger.kernel.org X-Gm-Message-State: AOJu0YxECgDXrmzMoGpw0ewijB5OHUkDovmRsXXaaI1MS61J8cadOMkP Dzaq5ix675BCLkAPwfFK+jOnKE1zQDTSKfHF2Nzsuo1sa5CvY8etH1tCqgQXbpZEVx2rbr94uV8 PhjrMOsrlBQ== X-Google-Smtp-Source: AGHT+IGLTNBJqqNRFe03rtohHZtVjV3PGAjgEaeS1rjfmd9WiCQvjWw/Kq0cU8IwP5OHRC196EtcxUqGNwTt X-Received: from pjbsi9.prod.google.com ([2002:a17:90b:5289:b0:311:485b:d057]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:e78d:b0:234:a139:1215 with SMTP id d9443c01a7336-23dee28fa46mr12324755ad.35.1752191512306; Thu, 10 Jul 2025 16:51:52 -0700 (PDT) Date: Thu, 10 Jul 2025 16:51:16 -0700 In-Reply-To: <20250710235126.1086011-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: <20250710235126.1086011-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250710235126.1086011-4-irogers@google.com> Subject: [PATCH v2 03/13] 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 , Thomas Falcon , Chun-Tse Shao , 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 Oct 7 08:53:53 2025 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (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 0CB9530749D for ; Thu, 10 Jul 2025 23:51:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752191516; cv=none; b=izFFra/Ku/Qh0g8a+YK+16o1wmTteXmBAUL/1Pwqu3AfX2bLRptBGauV6cBaFX4VuJS0Er8V4mY8W9k0YtE7mwIgBljknbYhVDFk2lQvqNnyKrQysXd2Q0XwcUk78//y36kV6Xl3Jzv6c4VyUajXLPxUIfwdjzO7cT+QW00+n84= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752191516; c=relaxed/simple; bh=8+fzwKbYyh0HgEc4+oNZYk8ZhmbZCi8quzaYQRyDMRY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=Kdon57wBiZeS2fN1gCNixLnNSFLNjVoa1dLL9JkWfXpv/HOyVQhzKoka2lqTRmdl58F8bkZ8+Z9V0Jm+Y4Ex0QXB2oKIEDGmcsl4/mwZkSr4m32qlDKB/42oV7gZtthUoKtX05Odfdktrs8PpOiOnj6QtLmmjUQK9m8YveRQBvg= 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=kbK4XSok; arc=none smtp.client-ip=209.85.216.73 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="kbK4XSok" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-31315427249so1388902a91.1 for ; Thu, 10 Jul 2025 16:51:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1752191514; x=1752796314; 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=kbK4XSokMMpOfu3C4NT75FrWVKyi907FrU6rUGqmKYh0g/o6sXiRe79oZi1+fARaaM JPBmGIbhYA2uQ03JwhgCoEBgHuwn38O2viANakUw5MekoAQNk/yTbrMzv2DFNA6aKebq EBHpd7jiNDoyNMGoORYaMgVAgz21RpLv3VVIsIGQdkXsVTLqYBFbRlWFZAEMgvRFMcHI Cd9/cjEnvCg5Gu6t2vquEFvcIvKYHv6hprBlcZOpYXs20yJZ7S79sAX93mfoZ52MqilW erc44ptiPys+KiEcjWwot+Mht8yz2ynurfKplrYzmz2hChgNdaC4xfO5mFyXVfk7CISl 8jhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752191514; x=1752796314; 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=t1ndOd3KL7bZ5E22vdeBPvKNsDQylCohWr9mcijbxzDL+VGmu+whUKKUpIylP4wMy+ gEWdjbsz4DHGDnidXaBiXUgVqbNeeE2Que4xpCeUBiTI3Clm4qCj2jDhLGLEoSEiIavH 46+1NBiz94AUsRoHHydVkFm3omUQvJNY8uOVtx6rYDHHRl/KFldCIvlNxXt36xLkdIu+ LaGHEzzlw1EPeMc8q3gRhDdymPoTIkAgbSuocpsb1Mu04StytWf8bmOzdhutQUlLTfmz I79ZEBtjJ8NQgoqoAFIfshB5luDo8TniExynPfL26OMCUI43eltWQMMDUcCWIbmK+GUM NEwQ== X-Forwarded-Encrypted: i=1; AJvYcCWH+zzfm4mh6LceRAyskelPXoPtNndZvSBFBGQ+OhcE7vG5sdUBRc/e3jTN8m4MYciIhRmoFJIF1fvCtTY=@vger.kernel.org X-Gm-Message-State: AOJu0YwnY4xXjy1F3pljbuXxm+IU2bdvad/hN1EG5rxtNQXUr0cMUK/W W9/OvrsYkMMv6l/XqDkvJCdEEDwJn8lL3I7vN2KVa2qAKSeYk66kSg17heO1Hn0ZrHBZHEQ70uS FAyO1TtmfgQ== X-Google-Smtp-Source: AGHT+IFHzoDdAVLiVt9wqChVcdmJwG5lwune8sMQ5I/kskubztWTyZMq3w6w/iqjpi5C0lsgndQnJd7FY+BX X-Received: from pjbqi10.prod.google.com ([2002:a17:90b:274a:b0:311:a4ee:7c3d]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:4c0d:b0:315:af43:12ee with SMTP id 98e67ed59e1d1-31c50e1763cmr185604a91.16.1752191514187; Thu, 10 Jul 2025 16:51:54 -0700 (PDT) Date: Thu, 10 Jul 2025 16:51:17 -0700 In-Reply-To: <20250710235126.1086011-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: <20250710235126.1086011-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250710235126.1086011-5-irogers@google.com> Subject: [PATCH v2 04/13] 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 , Thomas Falcon , Chun-Tse Shao , 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 Oct 7 08:53:53 2025 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (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 61FF5307AF4 for ; Thu, 10 Jul 2025 23:52:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752191522; cv=none; b=UnxZVa0f8VyJuijrpaCCaB/keWcS1GRLdoXkFXhaBHSu803y1uwvtzlz49B+bsRByb8rONoGAdP3dEBsT+CeRVjUQi01yZCVELt54asXaVW2neqVOd3b8aqcU3WiMj7qMWR7oYTgpEQu5q7QO42odTr3+Ev/NoLN/K4ERnHBqzA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752191522; c=relaxed/simple; bh=w5eNqcWn2O0y6EMKp9jCIupHTttD6lDBxXRkCF1rGCU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=kVxXIxFNoEDlb1dMklmUVv9GwSWWuxOyYFdzfxg/Rxl2kLqtDQzwzKLhRvLF5wZm1x0ZaHJLHlv+/qNP0O85wpeVljjP+RrdO8k2rLsRfRm2BHvQ9v4kB1L4aWjvcfw1Q94GMpXxGQORUi3VganDYnut8LAHP4YxwmCLCzHdWWw= 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=DrNQHEIN; arc=none smtp.client-ip=209.85.216.73 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="DrNQHEIN" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-31202bbaafaso1584713a91.1 for ; Thu, 10 Jul 2025 16:52:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1752191520; x=1752796320; 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=DrNQHEINvvWLzrTNTaKRt6nKM5tm5AgbaTlpNQcsKKiwoBz60SbcXYj/ZNlZdsDtnP swEgFJduysgZh/i8CFMwiTgXMgpq2GdQIQISdta6HLv0eyyqEPG7YtptoPNvPopvQG3T b80vTR3PNRrq1dHH836p5RCLV4qKH/J+sqp3Vu3MBxw82+3IiSoFiw7fWFmvCLVgrtzb SVMIDztd5chlDnR5xD2nVr2RqnZELwZUvtglhFPQFjhun+vDR5w+S3RHRtNqqWseXRj9 3hTne3xCyZ8zwklSW1yA9hidwuN1L1bcH8vZwzzcWNGra3y6GCd9l2E+v8iCmgi6bVUk yLCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752191520; x=1752796320; 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=hLGBRKBqX2z+t1Pn4GqRQP3aQZXCwCQVgLw6wJTMQ1rOL1nOsN6mKLMwaXYTplzEyE u5rw/+FvXre6TQz2pEvK3mL6htzenAQ0WBcq/aptO4qVin6MZIeV9If5MgAuufZ6Z0af iPxL13TLA27Ez8UPu16L205EZzCRK8YDLL5G+UW0PnihKFBIzrrLbrgYd1fbNK85o5lJ UXJDJxuGNVhT3qEs3W8xvZ/xo0j8lltxa/oy/aEGZNPzTMQLjKoGflP+87YkUqmBrzix N3rPUcAxypTbveEf0Bv9CVo6w6HyqJANrQqo+p/HcfLgJ8sYHQbHIdz+niQQXNosyWvm TDHg== X-Forwarded-Encrypted: i=1; AJvYcCUlCfEMNIp/fDkcaHHfXULGJ4GUtsG4p7c/GEyGN+zv2b7X/XC9158yZcBFsJzywnlVbLSGPqViRrtHtNc=@vger.kernel.org X-Gm-Message-State: AOJu0YxE1VJXJxUYEflMRFQD1G0MXZVHBMqorvwsZg2kEPfFXCOOfYO5 7rMH4w3U/IXMrkZ6MYZu3m7b1v6eSCNq1p/JIy35KOe3ed+25BnYvirgkbLdJ1hWC4cKA92zw0K RFvPzaBPfSw== X-Google-Smtp-Source: AGHT+IG0B8YFEZA8V8LiUmGV5dCe3b/biwYNthB5zqBtruQZhOYLikGG3vCBQ54sznM4CvSliMGF+JWuyPHh X-Received: from pjbta6.prod.google.com ([2002:a17:90b:4ec6:b0:31c:2fe4:33b7]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:1d84:b0:312:db8:dbdd with SMTP id 98e67ed59e1d1-31c4f54963amr582991a91.28.1752191519728; Thu, 10 Jul 2025 16:51:59 -0700 (PDT) Date: Thu, 10 Jul 2025 16:51:18 -0700 In-Reply-To: <20250710235126.1086011-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: <20250710235126.1086011-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250710235126.1086011-6-irogers@google.com> Subject: [PATCH v2 05/13] 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 , Thomas Falcon , Chun-Tse Shao , 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 Oct 7 08:53:53 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 3EE3D2F0044 for ; Thu, 10 Jul 2025 23:52:01 +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=1752191524; cv=none; b=ddS77Eqf5o1bz/ileavbZhXmcOheutjutCh3l20UZt38b64YmZx/aLsJ3l4+RHZVRwmyQwYi1W9THj0WV2lDsxhsN4oZaCVgQLh90J8W4vssOfTz0ZwWFUr1VToumjhcB1eD6i8KN3fcTehTWlZMWwC73aDWmhORX6a8wpDTFp8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752191524; c=relaxed/simple; bh=GzuZ8LUXET7BGYQ2eRqRzJYQa6EtqNPAew8uEpnPOvk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=CrcX3UCJ64KiJotzc7ahyVUBAcugDwhdY1E0f9gqylTdTIyklh1lCPwdMWvrQ8kLCoOnMU51bXXhIz6R/tmS6Z5Ne4FQvEde59oVLLw1D+qOBT/WvtG6JF2Pjn5pez0WJHYuq3I+KVES2VXb/KSfbZMCya7FcxIlwwLuj3jNL2Q= 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=y3y8Pixh; 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="y3y8Pixh" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-b2c00e965d0so1129442a12.2 for ; Thu, 10 Jul 2025 16:52:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1752191521; x=1752796321; 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=y3y8PixhdH1uC5Uqn5G7Ex7BGwOJHlnaMRn1zUC20hJRBgUOg98HMjuTX0nbtZXn5t j5tDlpWeh9Wtfm+BNpHnQFF5Cz9KEMBGLGr/q0fB4Fo/xrU3+EyEf2GD4Kek+U2uPEsI HY+5DlgTLBekDEI8JTxUG/eyv4sGsuhPsIEDw5E2dq1r/CTP9mQ4BplFoDh06qSxlYsA G2MzTZfOKvPazYKm9DsWr2GVRINIdQsoDzWvmftfCWGAZ7yP1imV/727pJVESvL5Cm+N JpP8Vyf+TiLAmAfdGThLx+09VDhEtSxFGqEMq41T3L9hBRaPz825jWkQPfVm41mZWKXu 0QaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752191521; x=1752796321; 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=vGrmhu8XO2EvW+AOFMho1hXBF8/iAICv0dwLkIWJqGhmzZzYXNo/u/97in0J+o/IAp RDxghyU1m0+8NsEfP1FkAzCTUeVQxx2CEK7/loE3vQSCkUbd5qc6T2nNxQTglyZ/YV1A Gs7VemL/kvMgstM/KRdWdrKB+6kXwF9YRMAROmKaRbw9QpbdCHu7qKE+RcokwkkAmb6v w7nGcx1+Iswm/A0nATLSh4JHSWhe0PsxnYNGIaA5nnkw0vGplefLKymvSBdHuiwhkrNy USFxIaFVcmSgP11TQBTJqsDW4py8zjyjGL5l3cfZTwP+QsrXbCpwC9IHtxAqBt8ZHdS+ 97hw== X-Forwarded-Encrypted: i=1; AJvYcCUc9909pvTGi6d87bjnR7Ufkzx6yKdFqaC5VM03bS/gnWRJU145yBZbCLh/B7JSKNhisKQtAwpBJrYlqSo=@vger.kernel.org X-Gm-Message-State: AOJu0Yy0aQDQDZP24jW4OJzQ55fZE5BNyx1kfcjZw7CoG/TEOVdyE3cG AjIQlSrsZPAiq6sP/SC6hs/0An9ccqaFb4h+Kb7tdyOgmTJi7Jg0owh/z4jIPKEMUx/2tj0wyTv r6ostodY9MA== X-Google-Smtp-Source: AGHT+IF9UULWfJv8Dz+26Xfv0bjSOjjhrCaf/+ZqNlycBLjTYZoHW1pZ+c1yS3XMaKkC5FElOU18qCxQMIpc X-Received: from pjbse12.prod.google.com ([2002:a17:90b:518c:b0:312:f650:c7aa]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:3845:b0:312:639:a06a with SMTP id 98e67ed59e1d1-31c4cdb73aemr1844084a91.31.1752191521465; Thu, 10 Jul 2025 16:52:01 -0700 (PDT) Date: Thu, 10 Jul 2025 16:51:19 -0700 In-Reply-To: <20250710235126.1086011-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: <20250710235126.1086011-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250710235126.1086011-7-irogers@google.com> Subject: [PATCH v2 06/13] 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 , Thomas Falcon , Chun-Tse Shao , 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 Oct 7 08:53:53 2025 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (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 4BBCE309A42 for ; Thu, 10 Jul 2025 23:52:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752191528; cv=none; b=VAFd5+l86UbRQxUYNbbH+SqsLAVhGa/mcoXWm3HPL9tt7y+2Eb9n0Zkrd62vshRq/FmRyJ8aK7UTDX+K9AFxBvWNoyknsg/7MBWDZGnAbL7fzF/+QJThSHvoLh/Chhq1aju0ZGuqgbUYbKZtRB30+yiC2Ce4dsJonsV04G8a2LY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752191528; c=relaxed/simple; bh=gv1i3DNEGxqaAyeBCm8oJ3IImT0PmMzZRaQt45Qua7I=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=hwoNh976ba46780CdYz/+M3CmZVpHO8hZMYsMuKyXdSd1r8fSdLdn4qlQ2/vSaxYiSaicpNObD4+8bMCV1rRbwvXzskul5IdlXf68gW7kaOeFCtODmP6UQrAkTvfPGRziIgV15bIhHeqz/n7V/817uHTpT1+w3PMPeIrfkEXwsU= 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=AJbawKBd; arc=none smtp.client-ip=209.85.216.73 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="AJbawKBd" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-313f702d37fso1588713a91.3 for ; Thu, 10 Jul 2025 16:52:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1752191527; x=1752796327; 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=AJbawKBd11qgB2xmABcsQN/zKaiEweQH6A9ZkLPB3BJHXOprZBS9tBHcLZP0b3mVKl DjBMVTJ/1oHlEOHItYn4FVFFqB6FDo61+6zMDCa/hxewTFhjubwzkj/FH1nHCNhVtnjl yQH0rnI2sm17WBZKdHFC4sTAOVlRbf3hwI1FDIn95QljZEvodH+Nhjwmqqp70oSf4e+T HfnbrEtVO2UfttWf6wskyBEXaG932HkMElLfJq0rD3RZTLC8bVv2DTSQhGBbJV3EMcQo HvLWCqWP507uyAhdnItQR8pmXEBP6QV1N8uUxvBM/NfHL+bu1gHSXHk/DHRJfdWColf3 jLoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752191527; x=1752796327; 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=fGyWSgJ24JBVLLUr3MiqR/0QqUj9W+76pS3Yzg2qCstkviHjkFxQCFScFSUED41NMy jWELruCPSY3RcPRlAHbAhSzW85miiY6z6KkdLYb4GDVeCFkhkoH97OLF1EnSK90Q7hgZ YDKmBPNcTx9np1RbE+uLYxj18UqImwTzp4FhQ+l99emgwkcwtBfNFmsVEqjmYrkRN2Uh 7zCIHy8pL0J/HG+NWc4J0+LPt05jzoS0ilhgOl/s30TT195v4f+aVRZNbg0p9sNH7ttV TP/HFqQ42wvbv3+sx3Rm74FOBFXgG1kdYV7Am2EYGde8c0MiTH+opqfXtuHhHuSJxZKj XqVw== X-Forwarded-Encrypted: i=1; AJvYcCUGg47zbT5AX27lI94H830sTLX1AnHuz9izlzWkmjbyc91ehn++mW91I1BFeAn2cisvelyRa3WmckgApm4=@vger.kernel.org X-Gm-Message-State: AOJu0Yy3UH0INYB6Lmdj5uteLiJl7g4gxbcGW5p74PmrA82IRoUsRpEI rQdibwtAryK/pZ/P1JjBBzO+yGBfBUwPHVHxzm/EyBNmRI4fYj4ogqnFLS8dEvLiXsRvPV0nci4 KBxQBGjIXwA== X-Google-Smtp-Source: AGHT+IGxVkRUBkrU23Iuy028HmTd6f1O0vsX3aB33ymJ13pw4jtm5YKvpLkoaVw9+YgZTXWB3mE1TOSYqRv0 X-Received: from pjbof7.prod.google.com ([2002:a17:90b:39c7:b0:31c:4a51:8b75]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90a:f944:b0:31c:3c45:87c with SMTP id 98e67ed59e1d1-31c4f4af646mr640793a91.13.1752191526857; Thu, 10 Jul 2025 16:52:06 -0700 (PDT) Date: Thu, 10 Jul 2025 16:51:20 -0700 In-Reply-To: <20250710235126.1086011-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: <20250710235126.1086011-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250710235126.1086011-8-irogers@google.com> Subject: [PATCH v2 07/13] 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 , Thomas Falcon , Chun-Tse Shao , 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 Oct 7 08:53:53 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 61E19309A58 for ; Thu, 10 Jul 2025 23:52:09 +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=1752191532; cv=none; b=E7lIRrqjJkyWw7nOAJ5H5CkQmvdJeQmBkucyLOgZDXUN1mg1CcC3z/sAIvid3LZh39Gt0ujKx8kG20N9eQlltAKKgUxFdSJvn24BSCWRQ/Ew8AG+TBlTT5pQdxQUjfmUZmXq2ipfGYmJC+OxXwHyMXR73M7A6niO8iokgQAASrk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752191532; c=relaxed/simple; bh=SlQ4yQiCxha6D90EaERBK4fPSe2+4PNG3jcD2ckQ+FY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=IE+upyCN4JEQtwD5984eSrnIRgLro0N/9X6RT9ZUPs7U/6xHz+eXfsUZFuMmAX9hbRMASZhpHPun4FZY++EiarsyuWQ8qK0lmOlg2snIv/PIoSpfjo968OerUVJIMs51nq8ev12Y67jz8pUA6UMMntV6GzMYiMiyibSjlXWoHnM= 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=0cKPZb/A; 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="0cKPZb/A" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-74b185fba41so1350164b3a.1 for ; Thu, 10 Jul 2025 16:52:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1752191529; x=1752796329; 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=0cKPZb/A81+ouAZDdBXSzE3Dtyq2Iz0XKnAbr3zgFuRfcE6qfXE2096lloIGFaDor9 ULk08o9cWCv5cy7Jg+HD3j3sTkC2DsIO0RF989vcOjCP2b3KuvnoVw76fwqmwnIKQ0rI FVKEQ+oY2iGylEYBBAyR54smtWMLwr7aZnFj2NzqaPUCYOthD8MitJUgFUZ7YoUOx0mc VXpiEGt419ZU6Eykr4QrmNapo5T5okzpHjsO+VzexO2+o9mjlzljepSwmAexkv8F8UfB yWi55pOKs/Q6BHR5UZLESsDA+mpYEl3rA9FK8TbRI8/eTJT9R3wu2P6aIM5bYin2MXlQ OcKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752191529; x=1752796329; 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=GSfaVkdn1ilL4A48O8CqVOpgujqvYYYWVXmLsRsJEnCuerCLPzKI7Ekr8BavUsCBAr 1X8AegnBo4maRIuplRnNLOuiiWngwg2N9vw+LXsMbMu1dtlcHu0vuWly4/O07thEgZaQ ZLuX96Lk33SXu7XTnkueRtAIQQ/FC/4hCAq3E5mw5QThO2qm62EOaCBINFPvhrAUbPGo h0fNVARvB7u9B7KgKwuxhUoqlZxnU2/QYKvvoUSFZxaKCwP74CRdJC2kyIXr4SRk5dpi bm6mHXo5jVXUtSyPv21r2ddXBJY4PTgS8OjrGtKL7B0m2sMDFqD4V7ZPZaD4TXYG4yo1 7zLA== X-Forwarded-Encrypted: i=1; AJvYcCWGxJiM08D2a4DxLKwz1PWXzydVeXKrpDVOkHAUD7LF+wXRSHn+0mTHut1k1MyY3xPkSmH7sHxZUN+WzG0=@vger.kernel.org X-Gm-Message-State: AOJu0YzpNBuojxZiP1p6X4eDcqNbP9ctApLqNYCELXQGyPCEHcLzNgdj ldtefhMSGmrsfLO/J3413ndg4WcJme+DzaYxgRMNo7pXnwl9VBWPKGCGA5dNdiX5WASkjIpyvZH HiweWreYX3w== X-Google-Smtp-Source: AGHT+IFh6Fg3ksjmSwJXoa/kWGdQw07uCsldaExv1pwntJmY7Im9JB1DE2GmtXhugn0sUv4yeH1Eg6JhVw8X X-Received: from pjbqn8.prod.google.com ([2002:a17:90b:3d48:b0:312:4b0b:a94]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:430d:b0:21f:97f3:d4c2 with SMTP id adf61e73a8af0-2311eb48bcamr1760617637.16.1752191528684; Thu, 10 Jul 2025 16:52:08 -0700 (PDT) Date: Thu, 10 Jul 2025 16:51:21 -0700 In-Reply-To: <20250710235126.1086011-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: <20250710235126.1086011-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250710235126.1086011-9-irogers@google.com> Subject: [PATCH v2 08/13] 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 , Thomas Falcon , Chun-Tse Shao , 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 Oct 7 08:53:53 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 5005F309DB4 for ; Thu, 10 Jul 2025 23:52:11 +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=1752191532; cv=none; b=C+aTJimIq3qrV0T1SwS7JzCLilC4mvUSGl9tibmcXbxBIzQsJkJi/3HtXCqgno95Cg9x/55esbfflds9ujNkyA0mKwuRp5R1n5pGfUbGKnFojeJzktQ0gEG9EAXAs2yDFEuWgblytVRCrAByaLkrqdqXsZVm0myE9TmgiYJHqgw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752191532; c=relaxed/simple; bh=S3yRMHiJp63Z3sa35dQZZnYodURgDAIos+timRoWgfo=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=fx++2iSnapMm9xb3LI+gcK26kR5QvRg//qhcIZmlri9byGC5iHA/SHgI6eu/oNFikUZEbOC6fSeVKkh8QEfiBS0NqKx3lJWIOXiLAl5i0y0EXoPnZ4vBwKtckedatSvlOsUt5LlWcy90IMiQkOU25DkuOWPV+JZpBPS8YlfpwtU= 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=bpQ1TdXL; 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="bpQ1TdXL" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-313fb0ec33bso1471516a91.2 for ; Thu, 10 Jul 2025 16:52:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1752191531; x=1752796331; 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=bpQ1TdXLCaa9bK0DJrk04lk8HBZBjA2/mcWf3m07VL05NqjNoEPq4rKRa8+x7jObIk ItHQtcWJbc6RIahOUVOYiNn8lpwZkJXDH3uR97Rr3I7+e6fket0jvut0GeZvnjr5Jbo/ X3S3B2g7OdWTVmclNJ9zg8pNvTII0KQre6qLY/7XhjhygoKBXFWcL1mWg8eDhuxnBwJH OIQB2Tq5pEZzLW1JvkcdsvYf8oxPNr6yw2APBdLoB+IxfKWd/2o+IcWzqbie/puFjOq2 ZLfIlM8Osz0N6Sk679SS14XSJisyMY3I+qHmJRW7uk9CQ/yhRwmq7p1XkMlZqXFQPM7+ eKpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752191531; x=1752796331; 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=B4q0APqpBAZbG0vQ0XBtg2ewtewmMuJqsrC/UmdxS4U35nZwzdyFkRNlQJH/STYc51 qZttJOpPuVYuYDv1Y5m4Ai63+P6d3L/EGjO961vOCnT+ZtZfCFCaaEoSVP9oJbPVn0Dr af4jVMG9M+ggzcbJ2pXl0IUHVtGyoUhQQYZCxJ+bsI7xRes4ZsoUStpXL/drNQSmpzi9 ufVq9pStzJv9nM1/7mNSwcjFpjsweRFF3JS9KomRxn7IGYqmwFI2wirv2TCVQ9VD8u5m 4LrBupIvIflEHfpvUjx2EjgwtrMop2Zv+FLj9bqQN9LApdzVPyxgVFlVBH545jYzayt+ O9jA== X-Forwarded-Encrypted: i=1; AJvYcCXh5erPa+3Gbi2yt6Nupz0BpUHQrzYcSnTZAR8/UBiIjjMBF7MxV/xjo34ya9Cwd1ncGWVvDtwAen05F5I=@vger.kernel.org X-Gm-Message-State: AOJu0YxRVX4q4XSGwtxPOJrz0FhpewPQpZXDbYAr3nQ38yO1MVyf2rWz 0Hqio0WDzAANGTsASu+7CvqZCcXHmb8sy0U0t2zfilS7K1uzV0ree8/N0nMPk/LUsSohjfJk121 Ty+9ickPCrA== X-Google-Smtp-Source: AGHT+IHuXYQqG8mUduYyNsVRYiw4AnUaYNbBCA0c5zjyQheARQpeOx7R6/xtZBMi4TILoaAcAku0wTI+Ked+ X-Received: from pjbsq16.prod.google.com ([2002:a17:90b:5310:b0:313:221f:6571]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:3844:b0:311:df4b:4b93 with SMTP id 98e67ed59e1d1-31c4cc9c984mr1813908a91.7.1752191530631; Thu, 10 Jul 2025 16:52:10 -0700 (PDT) Date: Thu, 10 Jul 2025 16:51:22 -0700 In-Reply-To: <20250710235126.1086011-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: <20250710235126.1086011-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250710235126.1086011-10-irogers@google.com> Subject: [PATCH v2 09/13] 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 , Thomas Falcon , Chun-Tse Shao , 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 Oct 7 08:53:53 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 1CC91309DCE for ; Thu, 10 Jul 2025 23:52:12 +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=1752191534; cv=none; b=YSwwgGinPcqq+jWYpKns6wUnBrMBhzJFEo9yMqSQNZ2xsNNxAaRjrlly48T9Qsy8ak8vXk3aZE1L4GrZQJFZq3bVgbZ5hm00VK70G8YEBJLbDRSrs2RKRyHmZOeYxc1hjCmdS6fTZD9HA1iAryBtdSJbXOPZW1sKKhpSm87aIr8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752191534; c=relaxed/simple; bh=vOwZDvr9Vl8FEdFAuVf8wVoxDa4D0UfmaiOanE6AyxM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=c1Q32Kn/SUIl5vNPYgCW+bOO8H6wbVLKVhRPIMAaNVOzYYY6V09En/ydScj4VgUtAEvw3E4RKhZBrjvvR0cBF0ZqgflWpmpu1RPOt9f2JcEfpjBj/htQLrBDQ7ez2H291T4NHYQlgqu1kPNURwwT5E2kP+preTBG1BnTzYIVkM4= 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=KMF1siaN; 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="KMF1siaN" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-23507382e64so14956625ad.2 for ; Thu, 10 Jul 2025 16:52:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1752191532; x=1752796332; 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=KMF1siaNhhRF6BdDNK6EvHL09zaSIDgSwhmCwdC3C8eDQafCCkys3ngL0Z9P/DL7Lw 5Qct7U12U/Lb+VUPoXi3fP52bnVlg2Q0AgCIYqFmQleb3wPUDpr464HI8vS0B5DWwZUS +XlsGVXpReuxwqyHjmX8R/ERsYNBscjywKbtUVC/ofvDfVzsg+6XYC+bvqiwmQlJfZyd JoNDWuQGT3tU2hHUlhvmhwh/gPV1lgp2DDPG4lIc1gfY1DlRQfuFkSS+zjbuubgt12QW P83Qi7b9e/TSyINH1EenpavJyQTVL2f+Dss57bBvlUTOpNnLyRMADTnRPMk72ZcjOKox NFZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752191532; x=1752796332; 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=AakuJ2Ao/NB3FIZdXdYTEPW+NJFTDbUIQPM6P5QjhiFexJHA1LiQdiKHBBenhzOWU5 QBdsnYhWfvDce5k1EvM+L+lxADBjaTNKj+2VQYKgOy2NuESSSotOFhr2A9r6gZ3d7ZKe Dz9qo4Wap7qYTeQ/VD2pDkblpj6xSqK3Wyju0q9MeO4Mb6Ms52zE7TQVVTNFaIAqQfRu 7VCCWEGBbDxpPrGinuTBV1vHl7sbDMfBGMGMeozUf4qpYbhFoOVsFdfbwiQf5GJkbEH6 /+jTihtNPE/uhgsCe+GD1ACGpjOnGap8D7M3ceBcY7r/xkU+TzqYz+s5gYt952+yLKig fGQg== X-Forwarded-Encrypted: i=1; AJvYcCWOI51NdDdtXBZOzhJ8ZsI9Ga9EfcLQWtUkslNaVQZQakSV0Rl243REyerWEyZEULGCDRAv0dL7E7ZMeEM=@vger.kernel.org X-Gm-Message-State: AOJu0YwM6XODklmbZtTIBUjkzA5JCOJW0GzNk9FXXgtui3RxsvgOhLCf Dop7xVGuObMs/cz0VNAYdXiGAvXjfwS2UHDSJyMwdK5QZzL4RVK2OTj2oAtSM2RSIvyMr0g0dEW tOh544tykew== X-Google-Smtp-Source: AGHT+IGKgTvhcIfECoRo0EwvPfvA3uvrF7VJo3TOsFhyG3H1BqHSXGgjm7Chs5YU2fkMuaqzSbhbCA8q9hBz X-Received: from pgam26.prod.google.com ([2002:a05:6a02:2b5a:b0:b31:ebae:e100]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:e548:b0:234:c86d:4572 with SMTP id d9443c01a7336-23dee26deb3mr12625565ad.30.1752191532485; Thu, 10 Jul 2025 16:52:12 -0700 (PDT) Date: Thu, 10 Jul 2025 16:51:23 -0700 In-Reply-To: <20250710235126.1086011-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: <20250710235126.1086011-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250710235126.1086011-11-irogers@google.com> Subject: [PATCH v2 10/13] 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 , Thomas Falcon , Chun-Tse Shao , 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 Oct 7 08:53:53 2025 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (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 E43A0306DD5 for ; Thu, 10 Jul 2025 23:52:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752191539; cv=none; b=EdFXLWSchxuIrCF9SDe2s2tLpS/iYIlrmmMu6x5R0xAZYSkzKD3vFiQ+sv2zzFAcGmZV7zQwqUbY4UETBGITVIDdmp+ZftKVsdbw781mF1xogszM/SDN0OZplWSpHmzP9GhYB9I7Imyo50Niw4wBkWvHJXOpICg0/ivNkZ2D4ts= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752191539; c=relaxed/simple; bh=E5+kvYI2Rn6W9To+wrAcq/gxgLLQZbgSx4MLHJcahUI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=oKOnIIAz4mJs5NLO3HQoRKR4Qw+M4unaZAxWgJDHhMxDczwunGReF2kFDuUwsRumumti9OlYUYbEhO366JUTHJnqOWrDclf8rwcMv+zJ1fcPHeoAA8n+3/CkxytLA7uxncFiSqoUbF1SmeU2k0+n5Au0Yk4YQlhWJQ+BIQ2MDqI= 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=MI8HuiFp; arc=none smtp.client-ip=209.85.216.73 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="MI8HuiFp" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-313c3915345so2272316a91.3 for ; Thu, 10 Jul 2025 16:52:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1752191537; x=1752796337; 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=MI8HuiFpMNnvz+uJu1EE0LlmUtlr6RueSvA2Q4yywzwzoKVeGoWxj2+OjLer8c2FEz gZ+FFcuVE/x6GBg68i5vuL5bBtfRiuvHjG/PYteyE1lOPzqgTIYOsdhIRnknXFazMpxw seoBxHQX51lJN/ygg5pO+eqSYG+uaceWDzgVJKPcCMLYQu/SxgYiTlTreCR6CWpgIkDG bHgDHatpy6J9CikbihKYKQuqxFHJFNa+D31PB6LFjMwFyTkrvb+Ca8zPfx+C8P6ULqCs usvd05dlwcl7A/mFf4MdHvQJfSUTBUN4eLRfkvL98cauxjPLnqwc8P8F2TigPaW3zYjj frpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752191537; x=1752796337; 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=RhfsIDuQI3iZJM1HrYARHn15ELKgGkWRA1wQhLyGYwB2AsB4nv5nC3ciHRgCs082jH RxTn/c6WP1Z4YSDiwDrKtfVestH+KlYbY/siy5v/KbG5iIp7UFPyCpf15OxpxAm5YEew CUq6iJnkGUxlaOU9bLNBwbw2UMk2PI+beoTsifEEzIY+zbpuwnO93Fz5QNh2u9a4xI6C R5nq7sAdZTCrSAuB/8ceKLTkphuY2W9cWmNnbsz37enPNhNoxdEB06JoYANrjy+FkUxU 1g6upX3KcVOWJhxoHSNsRS+5iRSvSEAeVr/BEL0lkZyTebKeRaT9O1kXe4QOiT58KOux OuHg== X-Forwarded-Encrypted: i=1; AJvYcCU3xscHymvijTyeXBJ+hPscBwxaWlXJsCM/24CW3hNro269Yi3Jz4xvWK53dyhBF9y9o40ofRjuam8mAFw=@vger.kernel.org X-Gm-Message-State: AOJu0YxnqMBQjip3hzxi58joRPt+zPAztYXNN+B/CpKt4Dg6MnVExm09 wLdyTCMuoq7J8swJ2gqelel8NPfztxG6neXvZ+KoGHu/guoqHChvrEE6qeIWLlfI4j85SXl64Fo 9fGKgP09qfw== X-Google-Smtp-Source: AGHT+IHJsuF2z6Bvn0PuYTCBRxnqhbfcAz/bXYQtjNJUh31jdC3iRUP0zoIA5a/Y12HFO1VhXy3RDUCXDmFq X-Received: from pjbqi10.prod.google.com ([2002:a17:90b:274a:b0:311:a4ee:7c3d]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:3d86:b0:313:d6ce:6c6e with SMTP id 98e67ed59e1d1-31c4ca845e2mr1867994a91.8.1752191537223; Thu, 10 Jul 2025 16:52:17 -0700 (PDT) Date: Thu, 10 Jul 2025 16:51:24 -0700 In-Reply-To: <20250710235126.1086011-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: <20250710235126.1086011-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250710235126.1086011-12-irogers@google.com> Subject: [PATCH v2 11/13] 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 , Thomas Falcon , Chun-Tse Shao , 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 Oct 7 08:53:53 2025 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (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 D4AAF30E833 for ; Thu, 10 Jul 2025 23:52:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752191541; cv=none; b=JPXPBe2yExVBuoqpbbXss0aSwKa4VHFLxlGFFAouGun+mWcK6r7s4bGZ+Lwz8YYSH6vCCiQ5W9yEDJ7l9Mrwj6gA/KLMNrmu7eMCQXqpzCJ20BieldpHlqOBIlfvUzrbAEyEtl7cWDcX05M002tnZ+ajwbH6FJ40NhtmUb+S1wE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752191541; c=relaxed/simple; bh=5zleGua1Zw/ZaEwM7EA6L7ilWgpRL02HZYzo8k822ac=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=jzmnse0/YAZ/YF0lbDs9MC+uJnXT9D7FChmIOJ7H05jwoglYiLUGzxXC01DvSQ3K7MsaxAONO0Df1+pKY9coib79d4y0ZyTuzcoLiKgSwZDGP8JH5CsSCOGcMXSvJWUdM80H7fmy9SNRyTbI8SsYndC57tB8+twEziFuRpBsyIU= 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=dvbv/yun; arc=none smtp.client-ip=209.85.216.73 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="dvbv/yun" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-3132c8437ffso2177754a91.1 for ; Thu, 10 Jul 2025 16:52:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1752191539; x=1752796339; 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=wqFyL3Z59+3lc3ZxktOSwyrKwJmku2CJiAkRKO+qTP0=; b=dvbv/yunjigfYqhzfmnCndg2YP3+son+gV+3tRWIxEIhhQD6rjVPDS2VI83qhx0wk+ pl+0o1dd8WPSQJ310wx6m/iuNAY8kUQAXEuOImTtloP5Jm0eFMpSeDPlklvXxHkdzVKs lhbQbvJ80wYNF0nu0TgQPXwdR6Mp8YX6T2Ns1MLsEAiX6qv7SZR64aNpWkb2nXc3GqBo DoG6gPMmpAotJ8CvKCc4SnINHN+x88oCzPJu0BexD2GOzJ/V1DtLpxDtmLh0HDLCQszH FZLXE4KhXoBjHvbvdE/0UtsV5O/HGu+Tlko4iA9Nl+MshXoqCyV+9LZyTIek9hzJtF6Y 8cvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752191539; x=1752796339; 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=wqFyL3Z59+3lc3ZxktOSwyrKwJmku2CJiAkRKO+qTP0=; b=kUc451qMuv8H4Q8Vn4pLgIBkJzFm9AoefOtzGJ+LMr6LCTYBpR20IapvUozm1NECcX VPybi98QUhuKhUeBU6f8c/oJBIFbmiOCPzaAUPdjK3YlSa0rEa0a/sB9yhM5vercQ4AC vs3dzoxksGMICiAPxLtvX7FwJUz23Bvg1I+cv0ffZ8JAJHGPp7FKOxEO+eRqj8g4YE0G D/ffXdooWbWPxNo8KH1aiegXGK509QnBJAnLd41qWUyrcoLPz3CbS8zai8II0tCV4enI PQ/v1X7V1RJuTK8PcaokjSheMw2v6+RFwPserUgZFYhKFJmxRG1JHkyPNfbPMWxzh7K4 qg6w== X-Forwarded-Encrypted: i=1; AJvYcCXl6C5SGMEoSeuejXQ74REbIhYIASiGCS+wjEJ57rnAcvPanUfKxafk9r3dP7B7RowQ9GL1idP2B2kuooE=@vger.kernel.org X-Gm-Message-State: AOJu0YyjwlfDC8fXlOssN+wosecwQ8ohtqK+2qvCFNsXrPinmy1a2pE2 PeX6taQj61YCXtVrkTrL0IYhjFXovwWWS0ig0lhalU/CDFG6iLGwCL5/NohmXQeIbKeKdiwtr56 Oe9CTNWnIQg== X-Google-Smtp-Source: AGHT+IGh/C/5InyJG63p8fKWBtjZwpODL6P7kzvpQrT88GcQmbobXyDzMu/1DHri/G4w4+OvP8s17U8z5mwx X-Received: from pjtu14.prod.google.com ([2002:a17:90a:c88e:b0:2fa:1803:2f9f]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:5444:b0:311:fde5:c4b6 with SMTP id 98e67ed59e1d1-31c4ca64d1dmr1855436a91.6.1752191539105; Thu, 10 Jul 2025 16:52:19 -0700 (PDT) Date: Thu, 10 Jul 2025 16:51:25 -0700 In-Reply-To: <20250710235126.1086011-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: <20250710235126.1086011-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250710235126.1086011-13-irogers@google.com> Subject: [PATCH v2 12/13] 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 , Thomas Falcon , Chun-Tse Shao , 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 | 57 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index f689560192f4..1d9fa33d377a 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -1568,10 +1568,37 @@ static PyObject *pyrf_evsel__from_evsel(struct evse= l *evsel) return (PyObject *)pevsel; } =20 +static int evlist__pos(struct evlist *evlist, struct evsel *evsel) +{ + struct evsel *pos; + int idx =3D 0; + + evlist__for_each_entry(evlist, pos) { + if (evsel =3D=3D 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; + idx2++; + } + 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); struct evsel *pos; + struct rb_node *node; =20 if (!pevlist) return NULL; @@ -1583,9 +1610,39 @@ 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); + + if (pos !=3D leader) { + int idx =3D evlist__pos(evlist, leader); + + if (idx >=3D 0) + evsel__set_leader(pos, evlist__at(&pevlist->evlist, idx)); + else if (leader =3D=3D NULL) + evsel__set_leader(pos, pos); + } + } metricgroup__copy_metric_events(&pevlist->evlist, /*cgrp=3D*/NULL, &pevlist->evlist.metric_events, &evlist->metric_events); + for (node =3D rb_first_cached(&pevlist->evlist.metric_events.entries); no= de; + node =3D rb_next(node)) { + struct metric_event *me =3D container_of(node, struct metric_event, nd); + struct list_head *mpos; + int idx =3D evlist__pos(evlist, me->evsel); + + if (idx >=3D 0) + me->evsel =3D evlist__at(&pevlist->evlist, idx); + list_for_each(mpos, &me->head) { + struct metric_expr *e =3D container_of(mpos, struct metric_expr, nd); + + for (int j =3D 0; e->metric_events[j]; j++) { + idx =3D evlist__pos(evlist, e->metric_events[j]); + if (idx >=3D 0) + e->metric_events[j] =3D evlist__at(&pevlist->evlist, idx); + } + } + } return (PyObject *)pevlist; } =20 --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Tue Oct 7 08:53:53 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 5BBAE30E833 for ; Thu, 10 Jul 2025 23:52:25 +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=1752191546; cv=none; b=nu811pCwH71TfW8sEpb+blrTEzu3EWwHwH5d72skHOeVFBOvSDgiCDgWTVS+aluWhcsK3czh1TfEKxEmd6aRZL2ORzlxkYisObPvCkuyOldCv4imzdNDTbOR4BNOkj9CoAMmzNM7whR+UZHCZSl27HHT92qIjigYs6O5acFNE34= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752191546; c=relaxed/simple; bh=m3mVuOV+FjGGQZSQOa/RyvRh8gyTPqaU/j/jeYS6pP8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=r8gG8m4MVOMSkf9OXuYkY/kB/NXCcxsctoQ+mpaVpXOuz1ho/77fgwvdxQS12iyZJwxnuNG63oNUpDckzdU31qOTym7s93BZgWJvJ52EQFzS6qhPCHb1SMVcbw+NemfTbb3Pwml6DgU+0FGkpzFPL1xhz3maFYUHuQXiIq2GXrs= 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=qwuvr5lO; 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="qwuvr5lO" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-311e98ee3fcso2381405a91.0 for ; Thu, 10 Jul 2025 16:52:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1752191545; x=1752796345; 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=bKKjyG04zvY4B3Cxa079gRu3GQTHZmfWcF0bIyCmCUs=; b=qwuvr5lOwwqVPQTQsMSGw0l30jY/H4mszQ1VzIOx5OO2KBF7MUdi6kOlaAwOjw3NdO yKwH+olDcyKIeY0Y057UQMA0jX3ocn4AatrS08Fya5H6gEq5Jd+/SugcrzrrPRLNMYTU i06G92xBBsIOzWTYcoIKCe4cFsMFQgQLRV8Df7ADCYNEn8EulimyX5ln1xLCdC9/7CmQ aHIGN/EDULPC9KFIeJxnVAhYJ/TQ0cq6AMuURrwNYC0egyGXryP4fVK9ySPbupoWQn7x QOLXhKEniDBEDtdNCSDT1AMZxdocNi1f6vkXoxbxi5UNQaC5QvMNL2zRWpdE6ibWrqxp eG6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752191545; x=1752796345; 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=bKKjyG04zvY4B3Cxa079gRu3GQTHZmfWcF0bIyCmCUs=; b=YarYucWHFKnsEPBaY/K+LQFpAjq7qb2vtS2liQLLpWUcXJqYe8mt7SEX3KQLAQb7Ig YZgwHGhtogt1RsQmcOnuu0K5kUM4gL9UEEU18yV2EoU3OHrXw17FGX3/Dl1K8dp3/6xW TpQ73LAZqFmWVZ5swbKIQumSWuZ56YIfEswiVC4AqV6dJRkajyOw0Xwojhfs1Qe09ySE PgTTF4yuy+deI6s/dIxbrOzuCSs164gr0E/EPLFMEY+iB6NQXogNYyJrkDu/aIAFISTS YoucI0Ptg/9UvMp64blts61bxLTVBIs/dFUYVnLyabkGtADlpqLQR50lkruabQPuCyag nWDg== X-Forwarded-Encrypted: i=1; AJvYcCU2TL2l6jSpd6M4fNLnywoUCuVcyg9JfminHNxbAIwGfY+mXBWVwdIyo2RN3V1BGXn2D2Oo4SWguiySw1M=@vger.kernel.org X-Gm-Message-State: AOJu0YxdmvhUxruE90Rh9sD2D/VZfa/74LCvPzms/WaRmIprSRzrLyJZ e8r27Ec31O2ZgulDOzWTdbTMOv25xVX5rLVaatESNMVuBq5wsgdTbyUykBjl/jqxaFyz5S4kqzp h0Ue5BaeGsQ== X-Google-Smtp-Source: AGHT+IEft9H81ix8+PRtUb8fGu0rx8aTovDOrMeNFLdvqd3XCOAMP/4bRQbIg7tplRXJRqSEWXoqJsDp6j+n X-Received: from pjbss4.prod.google.com ([2002:a17:90b:2ec4:b0:31c:2fe4:33be]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:2b50:b0:30e:6a9d:d78b with SMTP id 98e67ed59e1d1-31c4d4d0740mr1354347a91.12.1752191544776; Thu, 10 Jul 2025 16:52:24 -0700 (PDT) Date: Thu, 10 Jul 2025 16:51:26 -0700 In-Reply-To: <20250710235126.1086011-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: <20250710235126.1086011-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250710235126.1086011-14-irogers@google.com> Subject: [PATCH v2 13/13] perf python: Set index error for invalid thread/cpu map items 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 , Thomas Falcon , Chun-Tse Shao , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Returning NULL for out of bound CPU or thread map items causes internal errors. Fix by correctly setting the error to be an index error. Signed-off-by: Ian Rogers --- tools/perf/util/python.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index 1d9fa33d377a..2f28f71325a8 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -529,8 +529,10 @@ static PyObject *pyrf_cpu_map__item(PyObject *obj, Py_= ssize_t i) { struct pyrf_cpu_map *pcpus =3D (void *)obj; =20 - if (i >=3D perf_cpu_map__nr(pcpus->cpus)) + if (i >=3D perf_cpu_map__nr(pcpus->cpus)) { + PyErr_SetString(PyExc_IndexError, "Index out of range"); return NULL; + } =20 return Py_BuildValue("i", perf_cpu_map__cpu(pcpus->cpus, i).cpu); } @@ -598,8 +600,10 @@ static PyObject *pyrf_thread_map__item(PyObject *obj, = Py_ssize_t i) { struct pyrf_thread_map *pthreads =3D (void *)obj; =20 - if (i >=3D perf_thread_map__nr(pthreads->threads)) + if (i >=3D perf_thread_map__nr(pthreads->threads)) { + PyErr_SetString(PyExc_IndexError, "Index out of range"); return NULL; + } =20 return Py_BuildValue("i", perf_thread_map__pid(pthreads->threads, i)); } --=20 2.50.0.727.gbf7dc18ff4-goog