From nobody Wed Oct 8 12:52:11 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 019C84C6C for ; Sat, 28 Jun 2025 00:09:35 +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=1751069378; cv=none; b=kK4OAJEdcDJHwssIatoq7v6c9v6WGpvDlYTi07/XEbVVdzuqjyximXHkfmq1WkE6PsNdqcjlmsnuaAbf0HR8/mQss67fBNp8geDeCR1XC6b+hOQBAEUUFNUEEL7s/3I7vUqkbGmHnwjQ0mynZHglEh36D5S+a0kGGL0Gs034Nao= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751069378; c=relaxed/simple; bh=2GC+gz3NU/TsQzR0IgAKnBmtJMBkRxMKJ10VQOb4VUE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=R9KKVtvJ88UacWsJiixf8dWwQ8d5qPkT5GXldtvcqUnNdJCyxviLnubu97gSOfipGpieKtSc5lv2eDipUrB/s++63wPWhpBj0pKSrUmcc903YlZhUy20B1sgs8Da22tbZvxpSrwA+TwQ9T3o9ih6B9HSn1FhAoyeeEE3jUjjHtc= 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=IznjzVJb; 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="IznjzVJb" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-23638e1605dso690575ad.0 for ; Fri, 27 Jun 2025 17:09:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1751069375; x=1751674175; 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=FeoLfxu6vl8iu0oh1ON8hijy8JrvEUox5uGVMnB9N0M=; b=IznjzVJb+I52tkmfFQVjuywt0wWpMz/91DTviwaAVxrbsFEfczg0gpTzJnBcaf8YN7 X+P0OuiGI4K0ZtKLsMukwgE8I1pzPl4Qw96XeCNTJulgUHhd3yZIKUu0onfuU2ysVk41 epcE/vYRJoCJBBOfQ3pJ63C+nRXbaP086r1sToOUL+HX7mhzZwENmaYE8LtjlqqByqF3 IPqPeI963weO62ju0sMiW52y5lVVUALw2hb2Ggd9LzDwJFUWxDxJyga5vMREslQYBhKB JPyU6NLkrH8ATrZGENOt2OzcHUwr1OZVaXNfBCsecaMsyPfo6Q102PAEK7aEj9sl22+5 nKqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751069375; x=1751674175; 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=FeoLfxu6vl8iu0oh1ON8hijy8JrvEUox5uGVMnB9N0M=; b=uQx1HmNxShaqvoK8SRvREgcQbJTclTwvxfHVp5q7XAX0MQdEttcdPpdDbLhbdFnMES q7epCAhSSZJF+xJls8wj9/E9If6ahYpxJzeL1zUPGbnEhfbbW+StS86a1Qdt3vKcet3u b6nJ6SIClnxtxPOgl/H2KXeIpLmxgm4mBEOLYi/Z3O7zqBFEIoU9qJ4drGxfv1SJeKaG DhQSGke/I/ifO9U9yIclGR1Emle0bUVYAljWobV0SIhTIJy/iIytSrPa0agJHpuFpCde DsF6VQWo9fIoC2zWZdfFeP5w30iAqZzoicA2Iq3oBzU6lxyI7NBGXLdBxyaSrTAyI7r/ MyqA== X-Forwarded-Encrypted: i=1; AJvYcCVwH995j/lfdlqLZkRCQD+9Nc4r/ZXllrH+bdRNlKnptjlt9dWEukVuQWalCZ77YKgTi9PvQXOXc8ZPEX0=@vger.kernel.org X-Gm-Message-State: AOJu0YxstjXS/EaMTxo3stuOSrP9EqWQYc4JtwEsKqOXfZMZIyTXm8wm 2b2+cXHIt6rp6Dtk2efOJMnRElDWbLD/bO5q+fDDNrO5VtRHbKMwHDVoG/pWXke35V3W58EiN6n p/CXgQRzYVw== X-Google-Smtp-Source: AGHT+IHjF3eVZ4rb+9Jd0Y0bCQYcJEukiIKzVekz1mGzbrQ6INpOqjJFImlq0ucLFt1Eu8t6Qi1Is8EUx6zl X-Received: from pjn8.prod.google.com ([2002:a17:90b:5708:b0:312:151d:c818]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:1a67:b0:234:8a4a:adac with SMTP id d9443c01a7336-23ac3afda4emr57508945ad.20.1751069375191; Fri, 27 Jun 2025 17:09:35 -0700 (PDT) Date: Fri, 27 Jun 2025 17:09:15 -0700 In-Reply-To: <20250628000929.230406-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: <20250628000929.230406-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250628000929.230406-2-irogers@google.com> Subject: [PATCH v4 01/15] 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 , John Garry , "Masami Hiramatsu (Google)" , Howard Chu , Weilin Wang , Thomas Richter , Andi Kleen , Tiezhu Yang , Gautam Menghani , linux-kernel@vger.kernel.org, linux-perf-users@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 c25e7296f1c1..75683c543994 100644 --- a/tools/perf/util/hwmon_pmu.c +++ b/tools/perf/util/hwmon_pmu.c @@ -344,7 +344,7 @@ static int hwmon_pmu__read_events(struct hwmon_pmu *pmu) =20 struct perf_pmu *hwmon_pmu__new(struct list_head *pmus, int hwmon_dir, con= st 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 Wed Oct 8 12:52:11 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 01E7AD528 for ; Sat, 28 Jun 2025 00:09:37 +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=1751069379; cv=none; b=eYlPBpOL/pLbY9WkKHmkgc7RW+HTF4J1488+5mP8TrY8O+R8OUJCGxk9b+wuUrppIIni2qkJTYDjNJWxkUOmtdkiew5JA3znHYkf1Hwkff9v31OeipgpV6zIHZExojoqczMCo+wy7o0SYnIIIvs0HuWe8/9bH6tVUp//s3BtI+M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751069379; c=relaxed/simple; bh=SCSVRXj5DB/cfKYLIvAW2+qqqcd9DzSoDst4X0cpuZc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=uOWQs0HmejhywjQ9r5aZ4Tji0dhMaGGngjVoyXD/9xfaxiLAnhYeLXojpM00+FiqElQswDkXmjXysoVVnxw72Ay5Fb293/W7CLisMoXigneyj5DRl5dTxtMiRfKNC9IDEekOsaJVWzAYgeVM1Ypeff/mR5F4m4BhaDLADMFpnPA= 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=Skwh/E83; 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="Skwh/E83" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-b2fb347b3e6so3020261a12.1 for ; Fri, 27 Jun 2025 17:09:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1751069377; x=1751674177; 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=Skwh/E83+7tU5aJq06GugXApFjEYo9GfTRBpQYy/laBlZJTjtfYXtCMB0W1WKLrU+0 g5pDOW0jT9EfWM+miDv3BtPx96YnJO3zfYcXRrTxmS/ZRjG9RQR1KiNoHe3MenuyJhmG LhUJJ6c9PgeScT4TvFixZ7LXM2i6V65v1v1c4vtS2HdWy0n2yYrL1rxFiO5HlN3JMyO/ 2VjKTGa54xuDYFIg5UUlCf2WcDT+IwOBr4qGLIo+j9JQGUNdNrNcjNOaM/iPN93U4Tvq fYYvCQ3jF5wInCTyoT+1fegyhehONGY3guwFimYXG2/tsne9LfuYryS/4+ojCa2i8Ai/ R4vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751069377; x=1751674177; 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=V/svmEzAR6+XDVQy7+sYS9bE/fz/To9W3ap+XQhs8ePmy8OSJ6/q7JIojlXGOBd+9A 6cTZ0LEae1oQZAz9Jby77nVuSD8BQZWASsIUUWQZgwOnrj780K0LqvgIjfeWvvmnGyJi t1N5JwJSt9M/eu7F54nOkItWKmAeLoh5nwAAfkhYH8J0oJ805GTmNFFF88F/NjDhUE5X UCeWSWQsYc2pATspMLWeeQa4aqiTUkPvXnONoIYc6aKMhbzFjdlUbSecd12XaLVj5tYy SHamUiGB9aEQaXQLOrJwtwZa53qDmeVkWJ1OrtdA/diHIspBmasZ1S58ijUefpfSfE7R tFEg== X-Forwarded-Encrypted: i=1; AJvYcCULmmbpzTJhj4u4duyrZdYCSFuyOc4MWYKRkGKgWW2lPDStDtcyyMlDBSPgBJArh/h+GK4J0j1DTrWyeNI=@vger.kernel.org X-Gm-Message-State: AOJu0YwhkXkfPgYDoagdMqP6USNfPEBbDeTzXejUbzEqA0+sq3/Be4RW gYNzy8uqToow+ZsXbiZ4D24tvMTX/rNtTL5138MPMQm6lOMGLgQjY4K8GPWeydNmfC0R+DfSWPH AAaRK7Rvvhw== X-Google-Smtp-Source: AGHT+IFGs6aHSOiyXNrCU00NCL/c6uJ+2lnXnQ91a3SG2R8GfL5Yw7XlkLgRRFH3xzwbNKmbtXllaDIxcXX4 X-Received: from pfbbd20.prod.google.com ([2002:a05:6a00:2794:b0:746:fd4c:1fcf]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:2d0c:b0:21a:efe4:5c6f with SMTP id adf61e73a8af0-220a1265985mr8361320637.2.1751069377320; Fri, 27 Jun 2025 17:09:37 -0700 (PDT) Date: Fri, 27 Jun 2025 17:09:16 -0700 In-Reply-To: <20250628000929.230406-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: <20250628000929.230406-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250628000929.230406-3-irogers@google.com> Subject: [PATCH v4 02/15] 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 , John Garry , "Masami Hiramatsu (Google)" , Howard Chu , Weilin Wang , Thomas Richter , Andi Kleen , Tiezhu Yang , Gautam Menghani , linux-kernel@vger.kernel.org, linux-perf-users@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 Wed Oct 8 12:52:11 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 ECB6D1F94C for ; Sat, 28 Jun 2025 00:09:39 +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=1751069381; cv=none; b=KWjiPp/U/T9OiO07EEBWd7WVldBbkAYpeTFFORTmmiLEnnObsWaMgbbMRo6iVIQTbN5L6SFae+LnTDfincFcQcvpXwUVR4t63Dbro0Hadr5KhBCmQY1YRdy0ArqbIpmT2gZZk8H039syC53rwYTNF3lC1958yl81rcVK794tUAA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751069381; c=relaxed/simple; bh=kNO3vDYlEvZ0C+HDMguSyMRCpwtCigdQZxRa4vWHttI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=efh/BDFCpaJWERK5m0iJoThJTZGLixoASUx3OJXBGmgH//us0ZWUEfUpEplMahSmpXEBOTqaE/BnBSIpF29UGXDT/0pEdTKM9Eibgkrz+YXG4wVO7uN26Vl9r9W/xvoGWOx57RzLZmU3Zyzmi9AsJUcfDsFy9Y9bXIJh20JNH3Y= 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=WZwCxa49; 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="WZwCxa49" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-313f8835f29so160432a91.3 for ; Fri, 27 Jun 2025 17:09:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1751069379; x=1751674179; 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=nvPGYLp2e0uvMUDISbttjjvlMzPAeAoLlzlxkD8oChk=; b=WZwCxa49MtD46LTgrQmAkBuArQm/dBuKuPw/CsPSK2sn19TUPKZXH24wzFwP8jYblZ lfzFjTmPAqpmkgxGDuRqKQ9MULR9GwCp6r8moZUbRMl1NyArM2jZr4BaIA0yKyWj7Wsh u2goOrUE8P0WeLWyVMq7oeGEr1sL9hH0v+2r/MwfDRqaVClTOpesbeOmcIbi2/z+PZIi SD5b4yS3PlVw8OV3cU4vIJrL18G5EOCYfM3RFNgCbv7vNzy27FMP5vgLUan8UrU/1T4Z BZRyarAvmYve2Xx0u9qjGTysPfYQ5XN24MONpwTO5nibpnJu3H566hwBMF9LvqILji7T hg/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751069379; x=1751674179; 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=nvPGYLp2e0uvMUDISbttjjvlMzPAeAoLlzlxkD8oChk=; b=oubqnZYmRpQyyJaGckBFxPUTT0tgnHawCeSR/rZYQalX6m9x3AiTSsW5zqTFWyyxvP MWDtnfp9HBI2iawddaqhz4EKZMtM2oqA9JFFnU8ToPVHheWco+Hre2rJ3q8fASK+JCXs jcYDuZHcvPlTWQWOEk4O8o4CPKeWrGAlM2k6bNZ8gg6fW8/zJ5riWPZU86TQZfauZD6W ZR8r2+lcGM4ZSN26BEOL5OCpYtYX4GU5Mkr31vFpyEl9Lqc1kllCdALgwGoEJ3Xu9OIu tUaLryvVYEsJya4D0ytkkZFslYH0H6tDas8cUClUrtmEK9jw2CNUk0Tm7IFt8Klkyoop 2z9g== X-Forwarded-Encrypted: i=1; AJvYcCXPakatkxDfIoqSELQYRyOGi9UGQ7MfDGPxlA6USf7oQiMPxYrPaDPxrPbZbjqzM/1xY4dRnvG/lXpL77E=@vger.kernel.org X-Gm-Message-State: AOJu0YwWCrQTfEoyG41gZbtzPp8KpBWQSasv1Z7M30xgdlAwRZ5DwItz WAd+zmuixPzQg4nqybQjN4p70ZXmYpT3yncdQqAgaEuPRCYKWV9VEQ6fGf4ck28EN4L0MxMoxJz EGHdCc0eaUQ== X-Google-Smtp-Source: AGHT+IHpGtQcDFGzzHgc0j/PCxoD4+w4FTFjtyKxM9ve1cFeFf2CfBeemT2zOvJvofJH36F2BKnoJP0G5mWE X-Received: from pjb13.prod.google.com ([2002:a17:90b:2f0d:b0:30e:5bd5:880d]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:28d0:b0:312:1d2d:18e2 with SMTP id 98e67ed59e1d1-318c9243c54mr7191341a91.20.1751069379352; Fri, 27 Jun 2025 17:09:39 -0700 (PDT) Date: Fri, 27 Jun 2025 17:09:17 -0700 In-Reply-To: <20250628000929.230406-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: <20250628000929.230406-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250628000929.230406-4-irogers@google.com> Subject: [PATCH v4 03/15] 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 , John Garry , "Masami Hiramatsu (Google)" , Howard Chu , Weilin Wang , Thomas Richter , Andi Kleen , Tiezhu Yang , Gautam Menghani , linux-kernel@vger.kernel.org, linux-perf-users@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 82666bcd2eda..49e1db3feb87 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -924,10 +924,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 Wed Oct 8 12:52:11 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 D8809184F for ; Sat, 28 Jun 2025 00:09:41 +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=1751069383; cv=none; b=lJh34bHrwS6+5U5ivEpKngNXcfDh8EO/i60fZnvQ6/5dOgDTkDELBatvy2SC574G/JgMqxGE5Yq/l6jlCK7Kx8qef77T/fws/Gz8x7L6gFsn8lO1VkvP71ADQSjZTARH1MjnXm/vYNbu3lRooieQAwm7vjZUR9zd5ddYFW2kzM8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751069383; c=relaxed/simple; bh=LwbHih280ChFbYG9oVDlYtrszId/76RXBNEv7fnSzeI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=TnxzUQUjoRCEnc9WEYYu6q+6aD9sR+koMofE+IQCP/EuZ4oox69CR4WWW4iE+W0upN6YEPg3jIRRep8dfcj79CeMfB/um5i/zAlHtdwBOJdUoqJSGZyp8UHo0nQsc+SlLcrzsav1QaQDDuj+VU+lOg18cJGOSSabDVEjBMiJp4M= 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=GRO4UF0V; 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="GRO4UF0V" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-235f6b829cfso798425ad.2 for ; Fri, 27 Jun 2025 17:09:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1751069381; x=1751674181; 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=s2S9i2po54dMnEvHzrB8xMFU7a5iC7aF370u8g2mtdk=; b=GRO4UF0VpVxKUpdxzk7s4a+Ta26wWDbfInyCkBecJKUWZq6nRu2UBIYceNgqSQ7boh jxW/+VKNFhbIlRZVjeZ3A2+3Dgsib+Xl5Q57beaLPPe/4XBoF7jTLq/Xy/wSbkaRNfQb m3Wpdck4d8E+qgvyuJ+fBtHNkQK4ErFfsFsNsn1SBzXimGFE35yaiprRKrROH4FWbe0o PjKDM8n+NXPg5wtYoFhQMnKJ8oicSAPnxrslPlXKpDiUeIYrwgG1jreypj+4RKbk3YG9 cCNFL1z9PUmoU9Mgvg508kxAIXh41cCdbKcnlug1z3k6Pk0V9F8S4tZYVLbTFiSuLrIR ZlBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751069381; x=1751674181; 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=s2S9i2po54dMnEvHzrB8xMFU7a5iC7aF370u8g2mtdk=; b=jWqjQ+5KZBtNOfQ0o4Qc7L5iTouzLRYIeDtUm8S+jT5oMaojDDX/5ll+sbgOMsc/Nx FYj2qKseNwpTMhE0FTjkwZi01Zj5JZrt4n+Il/uQ0SYv0k5DN6vWvZII1aXwzpLjgTeG ydSnsU9ZQs7njhGS6BMNSlI4r0DBK28Ol++iTsBC4MTOFh47z3TK19Og1z37eKjbFuvi 9REqoOsAy+xbyqbql6asFbirWbfWQRyvWCpe/tyYy8YlB6JltcQbeFuGvCiocbn2/13B ZrlF2fKILWGF1z0kWdX4z6SHR2mmEJ2Kfj6PCyHCZT12Uy3RXefCX7LJm2lqAHJoMntR 1neA== X-Forwarded-Encrypted: i=1; AJvYcCVwq1yvewgsk+a87k6128PLELzW4uXCpgwpLCVvQorTqIiq59O4VW5Mw/LfmMU3UKUExy0eHiRnzjNnUmc=@vger.kernel.org X-Gm-Message-State: AOJu0Yzweuxdr9p2N6aLa1WqwnGqlrADR2xu3IdJ0mgz/4A3pq4QNBkn R7llKr6tPEIqCZ+rpoTnnryfjIuH+yn0hFyQD+dEKVibivQQKtDCXWoygHa4DLlMh8UztgonLVL fhcoGPIG6qw== X-Google-Smtp-Source: AGHT+IGX516F7yivz+ZLZ/vXjO8xw+uXMeaMucnwReGhLmqXBSH/Dq0xYYxY5RjbjyKw3CeFdsL0PsK/O8g6 X-Received: from plil14.prod.google.com ([2002:a17:903:17ce:b0:234:bf8f:6965]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:e807:b0:234:bca7:2926 with SMTP id d9443c01a7336-23ac4605990mr78443735ad.27.1751069381230; Fri, 27 Jun 2025 17:09:41 -0700 (PDT) Date: Fri, 27 Jun 2025 17:09:18 -0700 In-Reply-To: <20250628000929.230406-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: <20250628000929.230406-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250628000929.230406-5-irogers@google.com> Subject: [PATCH v4 04/15] 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 , John Garry , "Masami Hiramatsu (Google)" , Howard Chu , Weilin Wang , Thomas Richter , Andi Kleen , Tiezhu Yang , Gautam Menghani , linux-kernel@vger.kernel.org, linux-perf-users@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 49e1db3feb87..b724478fe34a 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -909,7 +909,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 Wed Oct 8 12:52:11 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 918A61494A3 for ; Sat, 28 Jun 2025 00:09: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=1751069387; cv=none; b=dIDUCfYfLKsWph7gGzGMRZeKpjoYccNYB1PdAjt8pVbo5YyW0i1J1z9nwC26MX2WOJArcpCZiHe3hEutWReqojjxqW49tgAd0ilcmXi+tSrbvNNMX/TL51tVU2il5ZlwiLv2/G5v+mCTcKPFKb5arvX/YVB/0VW7GMJxWuvsD5c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751069387; c=relaxed/simple; bh=fo0r240oHzpIwxpAOm3xs8m1o38s6/S9m0BaZW72G60=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=K+pYCF5G2Xre2wgDVxHHPN/Ka8IjFXR5dsfSV380UHl6TM6NiYToX2jehioswSIPPmbLWKUGkKBXlJHPgoipI7USq8SNnb548mv9OKQc6mn+fK8wMpIKrImIYCHXng26BmE6NCkNTqqTK0jZEx2SvZFiqvogNx4ErIjx2XP2feQ= 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=4GJvbUOO; 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="4GJvbUOO" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-74943a7cd9aso859555b3a.3 for ; Fri, 27 Jun 2025 17:09:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1751069385; x=1751674185; 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=rfCNuQAe9HbC089g4sg7a1ik2VZAO1ML1zW0HGkG2nY=; b=4GJvbUOO/Q5qDTKf1kdkzxtkGkLQFiQmsEQaxWjmTE7C4UVSbSvwGh6OV6GQcwrvFD 11QO4xRVpQlBWXUiNm5xbeuSht7UNPuURIW2X98h0Hd5Kt/K1sMb8WqlvxhegdYq+Ei1 q5KrUkV0+ghp+8OHrDTM71+byXx3AAqElKoOz3FpeF3SRWmGBFBIxnec3LJOgdiZRntk AkRx9tCNhCfLv6OKfn3yuGhbpjqCfgp4cupVBil05Xqr2wTGohLQedXvXNhlnzwqbx60 k3JkzrKzQbLO3FDVnlNuHeJ/oWDebHo7KE884Szzx3IiPdYFWs6SLO5bKNGG6iD44kgn 9/rg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751069385; x=1751674185; 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=rfCNuQAe9HbC089g4sg7a1ik2VZAO1ML1zW0HGkG2nY=; b=F66GZBnKAXg7+i/mkBKZGQnWTT+Ug1acHXPMY3hBZdBzTxAXS3aWN2ow1xhFDTf3RN FtLicJCadvbV+90cKAbum13P09vt6cSkP0xcqJ7ITG27dd1oyXGmuUs9QEBtv2foO7OR rAj6RHYlD7OXPsp/b7MfsbTy2iPxayfN+1cYFZFHgvKDXmr19OZB1OCzF8HkyBGeNOgo XnXDc2Kiq4LvDQc9NHwK7pPeaSmlatActPuuLrgQWzgsoQjuA9gjbH69LNSfVXipSBe+ +cfY4Nu3L2DuciXcT+xn45818xromleiBb0Q/5p/c3GoWlBUns9FzycbLbBeLZQ0uzsi Pk/w== X-Forwarded-Encrypted: i=1; AJvYcCUjD1ox3+t4NkLHQXK9/3v50JK9RcnO/CYiul94OkAZVKMz3GirO2XaYhWiWQWzcxVHH+nhHDfXW6Z5eTM=@vger.kernel.org X-Gm-Message-State: AOJu0YxedwDmLWqzjDtFRHzgTaDB7Mb72x2MICA03JSB9fXQp7nB09eU vpy5+iYLu/3Q4a3NpznOrsrHXxT9NWxSW/2N1crwQsJ60LM7MR7J027lkLL81U5diTw0Thu+OYV k7FCb7yPgwA== X-Google-Smtp-Source: AGHT+IHYrPuyNcxRNZkv92pYoCGxK6FD0ZGQWmWeIIB811AyLZuxmsar+jXhV4T0x/m8l+FiUYUiW35A9qh5 X-Received: from pfbiv27.prod.google.com ([2002:a05:6a00:66db:b0:748:ea16:c7ad]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:9194:b0:1fa:9819:c0a5 with SMTP id adf61e73a8af0-220a1277105mr7507317637.11.1751069384940; Fri, 27 Jun 2025 17:09:44 -0700 (PDT) Date: Fri, 27 Jun 2025 17:09:19 -0700 In-Reply-To: <20250628000929.230406-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: <20250628000929.230406-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250628000929.230406-6-irogers@google.com> Subject: [PATCH v4 05/15] 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 , John Garry , "Masami Hiramatsu (Google)" , Howard Chu , Weilin Wang , Thomas Richter , Andi Kleen , Tiezhu Yang , Gautam Menghani , linux-kernel@vger.kernel.org, linux-perf-users@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 | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index b724478fe34a..201fe04fb6dd 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" @@ -893,7 +894,7 @@ static PyObject *pyrf_evsel__read(struct pyrf_evsel *pe= vsel, { 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 @@ -914,8 +915,35 @@ 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; + + /* + * 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. + */ + if (evsel->counts =3D=3D NULL) { + int nthreads =3D perf_thread_map__nr(evsel->core.threads); + int ncpus =3D perf_cpu_map__nr(evsel->core.cpus); + + evsel->counts =3D perf_counts__new(ncpus, nthreads); + if (evsel->counts =3D=3D NULL) + return NULL; + evsel->prev_raw_counts =3D perf_counts__new(ncpus, nthreads); + if (evsel->prev_raw_counts =3D=3D NULL) + return NULL; + } + /* 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 Wed Oct 8 12:52:11 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 A8E8B152DE7 for ; Sat, 28 Jun 2025 00:09:47 +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=1751069389; cv=none; b=McVeSKrpPhFRFCLVYeDubgdfyz+XoWMB9ZSBVoxSswxw1+SJRLPd3KVy6Y0ZXin3d5kuNOP3Ros7doKCHIAuvNbMXRFrqf2Tf5HDEOEnS/G9sl4nL0Q52q0IxUOSR4ncWbmZEpvzRz/F1gorws5nWwy6xmb40h2tquVE1gEkVTE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751069389; c=relaxed/simple; bh=sW3k+IH/Kk6bAydSuZ/20LAWRGVVpRx5+p/hr7sjLVU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=DtGvtT0Ftu5wIFHcgXnwIyivv6Px51f8ukgQXZNH/AcrJmeGtM2/LFrK+ufbf5tUCbBaRn6xY5clnu4/JPU0t6S7zfs6MerGLo0gfLhux5h0gTbbQWyP1kev2qWvuZHqAWr89poHWjmoF/uFdp55eRRZGxacGO7FidY2YV6wc+c= 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=Vrk84Cwy; 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="Vrk84Cwy" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-2349fe994a9so756625ad.1 for ; Fri, 27 Jun 2025 17:09:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1751069387; x=1751674187; 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=4o/lre0OnbyRd/wtDw4wBY+CP15p0TI5/ASZaCCL+Tg=; b=Vrk84CwyrOzYYXynIq1zr0bE9ISA7eOVZR7685jvdEGTWzgOGWYTV93YQQbU7ISSgE 0QYfGdZ/YV9PTeFARMl11ubBwhraTCk7PFxD2e976OrplmiQQuNwoQSZkG/uj0fQJsDQ BdQcz+nPHG8hLDGt100qd0bvtlZpXCAHYrHN3lAKOF6n8J17jeT3M1t0aGxXcrIuXgCb t8a698ieI0mnSAjoba/zL44OVlsLHhN07EwKNet4rwxwv19Qhr3t/g10WNxbgxadHTSa gZJtYcIgTt679AeqYbppuwENkOCLAsDXXn05Q+pR0biH0Lbx2g1ZaqgSaq3b4eCxqUg7 xpsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751069387; x=1751674187; 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=4o/lre0OnbyRd/wtDw4wBY+CP15p0TI5/ASZaCCL+Tg=; b=O+OB2ODiL+4DAdJh0GGqrEpB6VBStV3D6E5FvIaELZOrWnpnndoka4Cjz0fQZWel0y ekwBfUBcqehcnm7qMLbQ8rDNa1KGj74v6FEeS5lHZXNAzJARJxk1MW1ORIg+8xhSaLP9 1V/Ny9+3oBoUcjPecD+YgZkoUAmgrzIJvLK0dhU5gPF2sT9yyfq1efa+y6TEml5SygIX +yFZJS5s0XzqRKQURzmrBablscO4KLOjgySeIhVTz6B0z9ijbBf2nqU8qeCYDc9sfF5f GAsYeKXSnY+zX/eds8zFIZpoTXnBV9yoois2ccx6ha9NKeXmg4n07Qf/TDCLnfiV3gu7 mgVw== X-Forwarded-Encrypted: i=1; AJvYcCUhPWlceikAWj72aBRs14YkZt5QqnVzp/9yTiDMqor5rNEBg58szBW/7AfkQ03oIs/IHCGK7g1uA16grII=@vger.kernel.org X-Gm-Message-State: AOJu0YzHDaYgjJuoF4qfEXDc0T+CLGGWuvT28BvjK4SIJpeVAwQEZjhh 6VRt1PA9MO9TBWHx6SBNe+s1M2kwXddaTEPGAmhfEYFqF+CO41mkTNlXWOw9eskfdiLOz3WhCMB EQar5q/O00g== X-Google-Smtp-Source: AGHT+IFSQq5dE70xsAE3IdVHYZJOQpV/EEOWUA1Q79g29OtOjsCKyNIlXC8CGiqatiKhCe7qYm5osskDpnpF X-Received: from plbju20.prod.google.com ([2002:a17:903:4294:b0:236:369f:dfc9]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:f8c:b0:235:eb71:a386 with SMTP id d9443c01a7336-23ac4891f49mr63903935ad.50.1751069387091; Fri, 27 Jun 2025 17:09:47 -0700 (PDT) Date: Fri, 27 Jun 2025 17:09:20 -0700 In-Reply-To: <20250628000929.230406-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: <20250628000929.230406-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250628000929.230406-7-irogers@google.com> Subject: [PATCH v4 06/15] perf python: Add basic PMU abstraction and pmus sequence 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 , John Garry , "Masami Hiramatsu (Google)" , Howard Chu , Weilin Wang , Thomas Richter , Andi Kleen , Tiezhu Yang , Gautam Menghani , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add an ability to iterate over PMUs and a basic PMU type then can just show the PMU's name. An example usage: ``` $ python Python 3.12.9 (main, Feb 5 2025, 01:31:18) [GCC 14.2.0] on linux >>> import perf >>> list(perf.pmus()) [pmu(cpu), pmu(breakpoint), pmu(cstate_core), pmu(cstate_pkg), pmu(hwmon_acpitz), pmu(hwmon_ac), pmu(hwmon_bat0), pmu(hwmon_coretemp), pmu(hwmon_iwlwifi_1), pmu(hwmon_nvme), pmu(hwmon_thinkpad), pmu(hwmon_ucsi_source_psy_usbc000_0), pmu(hwmon_ucsi_source_psy_usbc000_0), pmu(i915), pmu(intel_bts), pmu(intel_pt), pmu(kprobe), pmu(msr), pmu(power), pmu(software), pmu(tool), pmu(tracepoint), pmu(uncore_arb), pmu(uncore_cbox_0), pmu(uncore_cbox_1), pmu(uncore_cbox_2), pmu(uncore_cbox_3), pmu(uncore_cbox_4), pmu(uncore_cbox_5), pmu(uncore_cbox_6), pmu(uncore_cbox_7), pmu(uncore_clock), pmu(uncore_imc_free_running_0), pmu(uncore_imc_free_running_1), pmu(uprobe)] ``` Signed-off-by: Ian Rogers --- tools/perf/util/python.c | 140 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index 201fe04fb6dd..33b23d56dfb1 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -627,6 +627,138 @@ static int pyrf_thread_map__setup_types(void) return PyType_Ready(&pyrf_thread_map__type); } =20 +/** + * A python wrapper for perf_pmus that are globally owned by the pmus.c co= de. + */ +struct pyrf_pmu { + PyObject_HEAD + + struct perf_pmu *pmu; +}; + +static void pyrf_pmu__delete(struct pyrf_pmu *ppmu) +{ + Py_TYPE(ppmu)->tp_free((PyObject *)ppmu); +} + +static PyObject *pyrf_pmu__name(PyObject *self) +{ + struct pyrf_pmu *ppmu =3D (void *)self; + + return PyUnicode_FromString(ppmu->pmu->name); +} + +static PyObject *pyrf_pmu__repr(PyObject *self) +{ + struct pyrf_pmu *ppmu =3D (void *)self; + + return PyUnicode_FromFormat("pmu(%s)", ppmu->pmu->name); +} + +static const char pyrf_pmu__doc[] =3D PyDoc_STR("perf Performance Monitori= ng Unit (PMU) object."); + +static PyMethodDef pyrf_pmu__methods[] =3D { + { + .ml_name =3D "name", + .ml_meth =3D (PyCFunction)pyrf_pmu__name, + .ml_flags =3D METH_NOARGS, + .ml_doc =3D PyDoc_STR("Name of the PMU including suffixes.") + }, + { .ml_name =3D NULL, } +}; + +/** The python type for a perf.pmu. */ +static PyTypeObject pyrf_pmu__type =3D { + PyVarObject_HEAD_INIT(NULL, 0) + .tp_name =3D "perf.pmu", + .tp_basicsize =3D sizeof(struct pyrf_pmu), + .tp_dealloc =3D (destructor)pyrf_pmu__delete, + .tp_flags =3D Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, + .tp_doc =3D pyrf_pmu__doc, + .tp_methods =3D pyrf_pmu__methods, + .tp_str =3D pyrf_pmu__name, + .tp_repr =3D pyrf_pmu__repr, +}; + +static int pyrf_pmu__setup_types(void) +{ + pyrf_pmu__type.tp_new =3D PyType_GenericNew; + return PyType_Ready(&pyrf_pmu__type); +} + + +/** A python iterator for pmus that has no equivalent in the C code. */ +struct pyrf_pmu_iterator { + PyObject_HEAD + struct perf_pmu *pmu; +}; + +static void pyrf_pmu_iterator__dealloc(struct pyrf_pmu_iterator *self) +{ + Py_TYPE(self)->tp_free((PyObject *) self); +} + +static PyObject *pyrf_pmu_iterator__new(PyTypeObject *type, PyObject *args= __maybe_unused, + PyObject *kwds __maybe_unused) +{ + struct pyrf_pmu_iterator *itr =3D (void *)type->tp_alloc(type, 0); + + if (itr !=3D NULL) + itr->pmu =3D perf_pmus__scan(/*pmu=3D*/NULL); + + return (PyObject *) itr; +} + +static PyObject *pyrf_pmu_iterator__iter(PyObject *self) +{ + Py_INCREF(self); + return self; +} + +static PyObject *pyrf_pmu_iterator__iternext(PyObject *self) +{ + struct pyrf_pmu_iterator *itr =3D (void *)self; + struct pyrf_pmu *ppmu; + + if (itr->pmu =3D=3D NULL) { + PyErr_SetNone(PyExc_StopIteration); + return NULL; + } + // Create object to return. + ppmu =3D PyObject_New(struct pyrf_pmu, &pyrf_pmu__type); + if (ppmu) { + ppmu->pmu =3D itr->pmu; + // Advance iterator. + itr->pmu =3D perf_pmus__scan(itr->pmu); + } + return (PyObject *)ppmu; +} + +/** The python type for the PMU iterator. */ +static PyTypeObject pyrf_pmu_iterator__type =3D { + PyVarObject_HEAD_INIT(NULL, 0) + .tp_name =3D "pmus.iterator", + .tp_doc =3D "Iterator for the pmus string sequence.", + .tp_basicsize =3D sizeof(struct pyrf_pmu_iterator), + .tp_itemsize =3D 0, + .tp_flags =3D Py_TPFLAGS_DEFAULT, + .tp_new =3D pyrf_pmu_iterator__new, + .tp_dealloc =3D (destructor) pyrf_pmu_iterator__dealloc, + .tp_iter =3D pyrf_pmu_iterator__iter, + .tp_iternext =3D pyrf_pmu_iterator__iternext, +}; + +static int pyrf_pmu_iterator__setup_types(void) +{ + return PyType_Ready(&pyrf_pmu_iterator__type); +} + +static PyObject *pyrf__pmus(PyObject *self, PyObject *args) +{ + // Calling the class creates an instance of the iterator. + return PyObject_CallObject((PyObject *) &pyrf_pmu_iterator__type, /*args= =3D*/NULL); +} + struct pyrf_counts_values { PyObject_HEAD =20 @@ -1613,6 +1745,12 @@ static PyMethodDef perf__methods[] =3D { .ml_flags =3D METH_VARARGS, .ml_doc =3D PyDoc_STR("Parse a string of events and return an evlist.") }, + { + .ml_name =3D "pmus", + .ml_meth =3D (PyCFunction) pyrf__pmus, + .ml_flags =3D METH_NOARGS, + .ml_doc =3D PyDoc_STR("Returns a sequence of pmus.") + }, { .ml_name =3D NULL, } }; =20 @@ -1640,6 +1778,8 @@ PyMODINIT_FUNC PyInit_perf(void) pyrf_evsel__setup_types() < 0 || pyrf_thread_map__setup_types() < 0 || pyrf_cpu_map__setup_types() < 0 || + pyrf_pmu_iterator__setup_types() < 0 || + pyrf_pmu__setup_types() < 0 || pyrf_counts_values__setup_types() < 0) return module; =20 --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Wed Oct 8 12:52:11 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 A582217A305 for ; Sat, 28 Jun 2025 00:09:49 +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=1751069391; cv=none; b=LB+iZBuT3J5M/fZoPe7Isx/kdOqINFloeCSrPY6d2WfoQZwCUEkAo1dyb7/6JkG7idCMHtA2eOwChoOP46aonqsVt8fEPHwVm3WNRgeV313tCXtD2lmsUpCIV9Ff40tkKihkPLe3jv/n6Y6Ybu9M86pXJ+dL9c+mtX3I4d1Zn2I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751069391; c=relaxed/simple; bh=EHllJCh3FBBjFZEiqeZh0D/LqLJSXYnbMRpNl3cGfvQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=rVubwZiL5dajhtpoDclA2Xd44SmbnI/ovJmv15pz1OpJYu8u8vzpbhLH2rRdEH1QrOz8LU6ew9fBood2QBiZRSoonexBY91rnr+FPvScyY7BV6mP77lggAylWk1z8JIawP8t/DmpjEuKgAD9YjN/us7Z89fxtqcmGLlUFojzMak= 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=V+keBXxc; 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="V+keBXxc" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-3141f9ce4e2so181870a91.1 for ; Fri, 27 Jun 2025 17:09:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1751069389; x=1751674189; 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=tL5Y631MOdTPqAWECGEy7VLE1a+4bW8n2hhp8ck1U1s=; b=V+keBXxcsipNTx7QFCNZZGayE2VfoYw46G3lAsAIG/2Ph5Kbyb0xTyGsDI4RwnRQHT QQtjNnfhgVVSRtzWlY7Uc4jUU/60wHjKVut4RKr2GYkcI+bKVHf5HKLogciq/aNlLdnQ 6jYVhUO+bZVANj/Y0Fam4dk1NK/kbqqyent1rseHlP0CK5vYZXw/KvSeRiXWz7ZnhJrd qwqBdMmlPUmwpIRr1ipZrRde+Y9vImMBo18ml2+KVXQU/XQyhCaCKre1LvPuxPlxuqz9 /L3T1RBYVuxC5yjlcmqf9p1ea1f/sA3DRHMn4wJJB1SMrJWGNPq8oFiqivayPQquoTiG Ii/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751069389; x=1751674189; 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=tL5Y631MOdTPqAWECGEy7VLE1a+4bW8n2hhp8ck1U1s=; b=baakapgvIm4FDcgs9+NfMshS0dswDCnEqLPVNl0W64avcPJpvLCQf+6GUMpIialROH cR2zf3g/HAjeNe7+9KxSDH8tqKAZwAqvnfCYvkJ3sR4SVCBNFsWi66v58Wlb0Fgs8S3M O4xSh3ao6ymRdWhvJIyk1Sur/wvp/HL8utxfYb/oeZgDN9xkbjKdex6od8p3fJWsHz4J dIEJDf+LHhtMM14kMsSSH17XIlBPknABw+hvo5bioehih+JJh6KJHVGsvHI1NlXCFQ2v Wm9ptAjA5fT7lredji8ChuJnE5/vRc62BwM3DMNlWyLz9FM6EoVAT3zSWk4quY+9R09J ku1g== X-Forwarded-Encrypted: i=1; AJvYcCUJTlfRjPLEOR7Vst+FTzI1Wb+K3QZ9dfcCi/eGoR3LZk9b1L2TovQY0wcTnACvD3vj8u9cGRQ1DbJ9vKE=@vger.kernel.org X-Gm-Message-State: AOJu0YwnBj94KTvUD7bir7LiZLEpJ1lqxg7rL661IxpMJdRtMhYv5Tpi jb51iKr7kPY86LhwfKvcdHPWE43/dNrYKWz7dGNByMEZ8248oWcCjihG43DwwW1s+up3/2KBG1o a8m1+9eQOdA== X-Google-Smtp-Source: AGHT+IFZk1yuKbKwtaqMAJQzeJc3Q7lwZyApGvaGBinyjka+yHZt+6eYIOiRdHb3F8h5NAt0RO3Yv98gMaUP X-Received: from pjbpl1.prod.google.com ([2002:a17:90b:2681:b0:309:f831:28e0]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:4c4f:b0:314:2a2e:9da9 with SMTP id 98e67ed59e1d1-318c92e1a98mr7274791a91.25.1751069389082; Fri, 27 Jun 2025 17:09:49 -0700 (PDT) Date: Fri, 27 Jun 2025 17:09:21 -0700 In-Reply-To: <20250628000929.230406-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: <20250628000929.230406-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250628000929.230406-8-irogers@google.com> Subject: [PATCH v4 07/15] perf python: Add function returning dictionary of all events on a PMU 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 , John Garry , "Masami Hiramatsu (Google)" , Howard Chu , Weilin Wang , Thomas Richter , Andi Kleen , Tiezhu Yang , Gautam Menghani , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Allow all events on a PMU to be gathered, similar to how perf list gathers event information. An example usage: ``` $ python Python 3.12.9 (main, Feb 5 2025, 01:31:18) [GCC 14.2.0] on linux >>> import perf >>> for pmu in perf.pmus(): ... print(pmu.events()) ... [{'name': 'mem_load_retired.l3_hit', 'desc': 'Retired load instructions... ``` Signed-off-by: Ian Rogers --- tools/perf/util/python.c | 67 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index 33b23d56dfb1..f86a82548636 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -648,6 +648,67 @@ static PyObject *pyrf_pmu__name(PyObject *self) return PyUnicode_FromString(ppmu->pmu->name); } =20 +static bool add_to_dict(PyObject *dict, const char *key, const char *value) +{ + PyObject *pkey, *pvalue; + bool ret; + + if (value =3D=3D NULL) + return true; + + pkey =3D PyUnicode_FromString(key); + pvalue =3D PyUnicode_FromString(value); + + ret =3D pkey && pvalue && PyDict_SetItem(dict, pkey, pvalue) =3D=3D 0; + Py_XDECREF(pkey); + Py_XDECREF(pvalue); + return ret; +} + +static int pyrf_pmu__events_cb(void *state, struct pmu_event_info *info) +{ + PyObject *py_list =3D state; + PyObject *dict =3D PyDict_New(); + + if (!dict) + return -ENOMEM; + + if (!add_to_dict(dict, "name", info->name) || + !add_to_dict(dict, "alias", info->alias) || + !add_to_dict(dict, "scale_unit", info->scale_unit) || + !add_to_dict(dict, "desc", info->desc) || + !add_to_dict(dict, "long_desc", info->long_desc) || + !add_to_dict(dict, "encoding_desc", info->encoding_desc) || + !add_to_dict(dict, "topic", info->topic) || + !add_to_dict(dict, "event_type_desc", info->event_type_desc) || + !add_to_dict(dict, "str", info->str) || + !add_to_dict(dict, "deprecated", info->deprecated ? "deprecated" : NU= LL) || + PyList_Append(py_list, dict) !=3D 0) { + Py_DECREF(dict); + return -ENOMEM; + } + Py_DECREF(dict); + return 0; +} + +static PyObject *pyrf_pmu__events(PyObject *self) +{ + struct pyrf_pmu *ppmu =3D (void *)self; + PyObject *py_list =3D PyList_New(0); + + if (!py_list) + return NULL; + + if (perf_pmu__for_each_event(ppmu->pmu, + /*skip_duplicate_pmus=3D*/false, + py_list, + pyrf_pmu__events_cb) !=3D 0) { + Py_DECREF(py_list); + return NULL; + } + return py_list; +} + static PyObject *pyrf_pmu__repr(PyObject *self) { struct pyrf_pmu *ppmu =3D (void *)self; @@ -658,6 +719,12 @@ static PyObject *pyrf_pmu__repr(PyObject *self) static const char pyrf_pmu__doc[] =3D PyDoc_STR("perf Performance Monitori= ng Unit (PMU) object."); =20 static PyMethodDef pyrf_pmu__methods[] =3D { + { + .ml_name =3D "events", + .ml_meth =3D (PyCFunction)pyrf_pmu__events, + .ml_flags =3D METH_NOARGS, + .ml_doc =3D PyDoc_STR("Name of the PMU including suffixes.") + }, { .ml_name =3D "name", .ml_meth =3D (PyCFunction)pyrf_pmu__name, --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Wed Oct 8 12:52:11 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 7E39A194A73 for ; Sat, 28 Jun 2025 00:09:51 +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=1751069393; cv=none; b=YvmZmyqYQ+FNu/T5SCN8KadTAXwHnW+YzSjUvOBvav/guOXROQT56KKoQ8x10KhREJy925YCRigJz61DF36DPFM75z4VqhzcecarVE9TnaL9GD72/xgjXckcCA43zIfDQsXAUgpwNrsJK0/QyjByILQYBGAekVqqu1PUbojWb7M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751069393; c=relaxed/simple; bh=psqE77Pyy5/uOhxmfA6RaQ6/oLsvoziIlr+loXFna34=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=mHaJZGXL8bfk1YSG2Z8peVperyNs7ikauU6SnN9TsT8sbbYRsOpv5F+SWkH5KPDVaS1UU2P3oDluY7/9t8kYK7wFcQvYjSwdjmyZ13oaLNHSkQWPZKTfyZp/DRD1vs56wI0jbFp8wWuYh6Q3N2apgOSO7sH38mjqicve4eZneec= 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=fetIfbpO; 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="fetIfbpO" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-2358de17665so968305ad.3 for ; Fri, 27 Jun 2025 17:09:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1751069391; x=1751674191; 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=VLizt+Z1CxDbBZc7tqUJi1TbDzEztgwF5seXSe0yNb0=; b=fetIfbpOXUSMrisBQBTV4IpSIHrBeJHsCVI9yD4H07ZnJfi6xmFFowl9Dv7MT8HVuV f925r+/Ia45tWIwB+C8noXzyk+Wi7xawt2P9tmKgAz0j3cFVSyxhDdMQbRsCXpZM99G+ QRSnoCdd0cXJ0YH8ACHLkE5M1usgGHMIlUJtWdr1JpVRYcV8Zdaie4jS53eysvNWIKIP AdL8pZHNXqD4q/uS0xVKvododRwFj3n5SHWp5Z1CQsxwx+2XiGWRQB0zva4DVFDzO/on LHzVcD2K+B5M7sshQHf0wLJCVOoMSVwl+CQL8YvBWPm9BPWEA6GC8M2W1CSiQw/CYqIJ i8iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751069391; x=1751674191; 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=VLizt+Z1CxDbBZc7tqUJi1TbDzEztgwF5seXSe0yNb0=; b=LftIarIFysJapbmn8NL9HtIwmkUhsExt8u1ElHM2wbIzFRIeIWMEYhctxFbGrDiJX6 awKb6pT1/sj5+N3f67vPYCKuo0k8tnbTz9hPUEhda1vB5MrNSEDW/8YRtzanhNRUeEvF eyVl8LMPmvXEHxnsSpOb+W+76/ivcd3rWmow6DCxkBgAycO9pw8NrrDdhq22nvG3RFPJ G9gQZ06MUS72sfeHNJGuNpWtEjW7hJEOOX7GFkT6OF/AdktXLnBDnXUCO9phs6EaYSxr D7Kzpx7ymRvcOO3AOG1fDjxmGW34zK/NQ/Ri8SGS+MyzZEQlmvmV0eKPmKU9nIbOhjku tooQ== X-Forwarded-Encrypted: i=1; AJvYcCVQrPTys4JcrjAv/Mw/p/JDwO2aBHhuuJIQro3yrZR+1DJt0t/Fx57WKN36m/T7bHG45LXz/sx9nRsWDYg=@vger.kernel.org X-Gm-Message-State: AOJu0YybctwKo1AH9IyqZ94hvyACT7Y02F/FqitfAqNDnr+kSP2LKeRH 6MRmkw//TM6JZvf76/2xASwRj7KJZw9N1AmXJJDyRNVq598xOPfhiiypC2HIp9vbQIVJMEUDnqQ dFYRgrk9W4g== X-Google-Smtp-Source: AGHT+IEHJ0y9DwerGn0cGfH2tl2/iQ9m+DbZw0s7ofuBgXsqIAUVCmJGmB0M6GM7f67Ii7UuVLd+XFVSuX63 X-Received: from pfkq22.prod.google.com ([2002:a05:6a00:856:b0:746:2862:2a2f]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:4307:b0:220:78b9:f849 with SMTP id adf61e73a8af0-220a16a3048mr8852574637.24.1751069390895; Fri, 27 Jun 2025 17:09:50 -0700 (PDT) Date: Fri, 27 Jun 2025 17:09:22 -0700 In-Reply-To: <20250628000929.230406-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: <20250628000929.230406-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250628000929.230406-9-irogers@google.com> Subject: [PATCH v4 08/15] 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 , John Garry , "Masami Hiramatsu (Google)" , Howard Chu , Weilin Wang , Thomas Richter , Andi Kleen , Tiezhu Yang , Gautam Menghani , linux-kernel@vger.kernel.org, linux-perf-users@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. Signed-off-by: Ian Rogers --- tools/perf/pmu-events/empty-pmu-events.c | 128 +++++++++++------------ tools/perf/pmu-events/jevents.py | 3 + tools/perf/util/pmu.c | 3 +- 3 files changed, 68 insertions(+), 66 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/util/pmu.c b/tools/perf/util/pmu.c index f795883c233f..687288991eb4 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 Wed Oct 8 12:52:11 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 AABC91AF0B5 for ; Sat, 28 Jun 2025 00:09:53 +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=1751069397; cv=none; b=Jawu6VPWqjH5q0qxHxPL6/XU8vVslhbeYYz4vlsJfzAaH0iUc9i29Uqa3TUoFk+b7Iq56NVtFGgYc/c9VpmnUDbWmfdOGoDHkRE4T/pdJXf23tGd5NbpHzW8PWQy1zT53CwglE9OmaGD9SZ4UpA6AVuj9fyWdY2QKPGuoWvT7N0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751069397; c=relaxed/simple; bh=OBUnSNyWg9w1qVJi5lsWp0gnwPU6CVGbBfnB2vqpaFI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=a056fXGQBzwM4IU/32zF02KI8JPuXKPgpqdRZq9N6VKcxY5BAX+MqimOatUIi8bPF03XwOOn3+yD33nvlvPaVs7+FHmV9acTz8XKb0TTm6inCbPCrfskLWk+OGO27qUoeEVNJKseSCXvX2xSXmMNIV/r4Ir2y9O5XD3AM5v4uX4= 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=yggATWAc; 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="yggATWAc" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-2369261224bso1446875ad.0 for ; Fri, 27 Jun 2025 17:09:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1751069393; x=1751674193; 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=NRGNNr/giRHcF/RZj7awN1PXfLHMVDY5ladq/SDyrWA=; b=yggATWAcJr8YQj5FWf6Da+ph7ofd7srkEgajatrCDALWdBG+6ev+f64bWtjPCJtKnH ziFnSyAR41HNqs6MKxI/iGNo02TMFplKQLymapoyw8Z/0bMal8fnjWFNm3V2iegUvOwm U+rJevW+Yob4kRZdB/QwhG7Zwuk0pw5q/GsTu8Y9VLnWTfpp0z/a+5ni3brZ7VfXWHVg +s/m0L4/qbmTIYAqlb0wjOWlQIPNxHJ0XXpc/uh4/yjF2K5D8K0KYxXKAR7y7NkkX9E2 2TacqrXwdNT6ldElseNEpOi8YGLbRrizZILuzTPaMBVCxEy4poJK3EK3KLbM/3JjnXZo PFBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751069393; x=1751674193; 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=NRGNNr/giRHcF/RZj7awN1PXfLHMVDY5ladq/SDyrWA=; b=tsGDWNXLUxwED6/0+AZsKUI/aIMnkX/cibkehGkaccXk+3DyRXPEpXniBaiTnbuqC4 moJT1XLtHZtbA6MNUEskmPHOMYdQXG3pa7KQ+oxltty8XFvuagmG/egOhyEgJU+zosdv q1S/caaTD/hTDWEBzQJMgKeOgGAcMxr3s2jv/veIXlQqoaOZslwB+YJFI3+gAWDwrTYU C0VL/su0Vyr1YJaTOUsM9br5y3SycgQD00P85/+E97kEvTIH72iTUjmxUuPnjSxjfdVF iKIZTNXq4gyWvPy4mGC2FHJs0G3spA5d0bl+vNXWNLo05GhSA2t+FN7g7XrB7GzxMOvx 7tKA== X-Forwarded-Encrypted: i=1; AJvYcCWAiMGQQhOIW1OCrvqyGCGhEhR2i7wMs0DGABg4wj3BSgpGl8Qf5M5LnT1ljphuLiKK35p9O4YdWgivX4g=@vger.kernel.org X-Gm-Message-State: AOJu0YzJnd9cSur5Q4I93zv4wNX0jlmYOR4fuif2Yi5Gm6Vob0RifFn6 wYITBmPlJB34uzGZCPomOgWo+qn43rZ0bCgBo0JRoxM9cOKkrjR6n+lWSOIe5CKUMMXrqt52Gg1 8BxMYgcgkig== X-Google-Smtp-Source: AGHT+IEKjPmCl2GdnmP0vx6YL3lLsvP3ZqhYNKejhvHojetXyQjKCZnUXElkJyoqNjqNDLOOclOnwtUKti+H X-Received: from pgns23.prod.google.com ([2002:a63:9257:0:b0:b2f:556f:74a2]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:ec89:b0:234:be9b:539a with SMTP id d9443c01a7336-23ac4669445mr86349385ad.40.1751069393051; Fri, 27 Jun 2025 17:09:53 -0700 (PDT) Date: Fri, 27 Jun 2025 17:09:23 -0700 In-Reply-To: <20250628000929.230406-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: <20250628000929.230406-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250628000929.230406-10-irogers@google.com> Subject: [PATCH v4 09/15] perf jevents: Add common software event json 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 , John Garry , "Masami Hiramatsu (Google)" , Howard Chu , Weilin Wang , Thomas Richter , Andi Kleen , Tiezhu Yang , Gautam Menghani , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add json for software events so that in perf list the events can have a description. Common json exists for the tool PMU but it has no sysfs equivalent. Modify the map_for_pmu code to return the common map (rather than an architecture specific one) when a PMU with a common name is being looked for, this allows the events to be found. Signed-off-by: Ian Rogers --- .../arch/common/common/software.json | 92 ++++++ tools/perf/pmu-events/empty-pmu-events.c | 266 +++++++++++------- tools/perf/pmu-events/jevents.py | 15 +- 3 files changed, 264 insertions(+), 109 deletions(-) create mode 100644 tools/perf/pmu-events/arch/common/common/software.json diff --git a/tools/perf/pmu-events/arch/common/common/software.json b/tools= /perf/pmu-events/arch/common/common/software.json new file mode 100644 index 000000000000..3af2f565a601 --- /dev/null +++ b/tools/perf/pmu-events/arch/common/common/software.json @@ -0,0 +1,92 @@ +[ + { + "Unit": "software", + "EventName": "cpu-clock", + "BriefDescription": "Per-CPU high-resolution timer based event", + "ConfigCode": "0" + }, + { + "Unit": "software", + "EventName": "task-clock", + "BriefDescription": "Task based high-resolution timer based event", + "ConfigCode": "1" + }, + { + "Unit": "software", + "EventName": "faults", + "BriefDescription": "Number of page faults [This event is an alias of = page-faults]", + "ConfigCode": "2" + }, + { + "Unit": "software", + "EventName": "page-faults", + "BriefDescription": "Number of page faults [This event is an alias of = faults]", + "ConfigCode": "2" + }, + { + "Unit": "software", + "EventName": "context-switches", + "BriefDescription": "Number of context switches [This event is an alia= s of cs]", + "ConfigCode": "3" + }, + { + "Unit": "software", + "EventName": "cs", + "BriefDescription": "Number of context switches [This event is an alia= s of context-switches]", + "ConfigCode": "3" + }, + { + "Unit": "software", + "EventName": "cpu-migrations", + "BriefDescription": "Number of times a process has migrated to a new C= PU [This event is an alias of migrations]", + "ConfigCode": "4" + }, + { + "Unit": "software", + "EventName": "migrations", + "BriefDescription": "Number of times a process has migrated to a new C= PU [This event is an alias of cpu-migrations]", + "ConfigCode": "4" + }, + { + "Unit": "software", + "EventName": "minor-faults", + "BriefDescription": "Number of minor page faults. Minor faults don't r= equire I/O to handle", + "ConfigCode": "5" + }, + { + "Unit": "software", + "EventName": "major-faults", + "BriefDescription": "Number of major page faults. Major faults require= I/O to handle", + "ConfigCode": "6" + }, + { + "Unit": "software", + "EventName": "alignment-faults", + "BriefDescription": "Number of kernel handled memory alignment faults", + "ConfigCode": "7" + }, + { + "Unit": "software", + "EventName": "emulation-faults", + "BriefDescription": "Number of kernel handled unimplemented instructio= n faults handled through emulation", + "ConfigCode": "8" + }, + { + "Unit": "software", + "EventName": "dummy", + "BriefDescription": "A placeholder event that doesn't count anything", + "ConfigCode": "9" + }, + { + "Unit": "software", + "EventName": "bpf-output", + "BriefDescription": "An event used by BPF programs to write to the per= f ring buffer", + "ConfigCode": "10" + }, + { + "Unit": "software", + "EventName": "cgroup-switches", + "BriefDescription": "Number of context switches to a task in a differe= nt cgroup", + "ConfigCode": "11" + } +] diff --git a/tools/perf/pmu-events/empty-pmu-events.c b/tools/perf/pmu-even= ts/empty-pmu-events.c index a4569a74db07..7d179d703ab1 100644 --- a/tools/perf/pmu-events/empty-pmu-events.c +++ b/tools/perf/pmu-events/empty-pmu-events.c @@ -19,109 +19,147 @@ struct pmu_table_entry { }; =20 static const char *const big_c_string =3D -/* offset=3D0 */ "tool\000" -/* offset=3D5 */ "duration_time\000tool\000Wall clock interval time in nan= oseconds\000config=3D1\000\00000\000\000\000\000\000" -/* offset=3D81 */ "user_time\000tool\000User (non-kernel) time in nanoseco= nds\000config=3D2\000\00000\000\000\000\000\000" -/* offset=3D151 */ "system_time\000tool\000System/kernel time in nanosecon= ds\000config=3D3\000\00000\000\000\000\000\000" -/* offset=3D219 */ "has_pmem\000tool\0001 if persistent memory installed o= therwise 0\000config=3D4\000\00000\000\000\000\000\000" -/* offset=3D295 */ "num_cores\000tool\000Number of cores. A core consists = of 1 or more thread, with each thread being associated with a logical Linux= CPU\000config=3D5\000\00000\000\000\000\000\000" -/* offset=3D440 */ "num_cpus\000tool\000Number of logical Linux CPUs. Ther= e may be multiple such CPUs on a core\000config=3D6\000\00000\000\000\000\0= 00\000" -/* offset=3D543 */ "num_cpus_online\000tool\000Number of online logical Li= nux CPUs. There may be multiple such CPUs on a core\000config=3D7\000\00000= \000\000\000\000\000" -/* offset=3D660 */ "num_dies\000tool\000Number of dies. Each die has 1 or = more cores\000config=3D8\000\00000\000\000\000\000\000" -/* offset=3D736 */ "num_packages\000tool\000Number of packages. Each packa= ge has 1 or more die\000config=3D9\000\00000\000\000\000\000\000" -/* offset=3D822 */ "slots\000tool\000Number of functional units that in pa= rallel can execute parts of an instruction\000config=3D0xa\000\00000\000\00= 0\000\000\000" -/* offset=3D932 */ "smt_on\000tool\0001 if simultaneous multithreading (ak= a hyperthreading) is enable otherwise 0\000config=3D0xb\000\00000\000\000\0= 00\000\000" -/* offset=3D1039 */ "system_tsc_freq\000tool\000The amount a Time Stamp Co= unter (TSC) increases per second\000config=3D0xc\000\00000\000\000\000\000\= 000" -/* offset=3D1138 */ "default_core\000" -/* offset=3D1151 */ "bp_l1_btb_correct\000branch\000L1 BTB Correction\000e= vent=3D0x8a\000\00000\000\000\000\000\000" -/* offset=3D1213 */ "bp_l2_btb_correct\000branch\000L2 BTB Correction\000e= vent=3D0x8b\000\00000\000\000\000\000\000" -/* offset=3D1275 */ "l3_cache_rd\000cache\000L3 cache access, read\000even= t=3D0x40\000\00000\000\000\000\000Attributable Level 3 cache access, read\0= 00" -/* offset=3D1373 */ "segment_reg_loads.any\000other\000Number of segment r= egister loads\000event=3D6,period=3D200000,umask=3D0x80\000\00000\000\000\0= 00\000\000" -/* 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\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" +/* offset=3D0 */ "software\000" +/* offset=3D9 */ "cpu-clock\000software\000Per-CPU high-resolution timer b= ased event\000config=3D0\000\00000\000\000\000\000\000" +/* offset=3D87 */ "task-clock\000software\000Task based high-resolution ti= mer based event\000config=3D1\000\00000\000\000\000\000\000" +/* offset=3D169 */ "faults\000software\000Number of page faults [This even= t is an alias of page-faults]\000config=3D2\000\00000\000\000\000\000\000" +/* offset=3D264 */ "page-faults\000software\000Number of page faults [This= event is an alias of faults]\000config=3D2\000\00000\000\000\000\000\000" +/* offset=3D359 */ "context-switches\000software\000Number of context swit= ches [This event is an alias of cs]\000config=3D3\000\00000\000\000\000\000= \000" +/* offset=3D460 */ "cs\000software\000Number of context switches [This eve= nt is an alias of context-switches]\000config=3D3\000\00000\000\000\000\000= \000" +/* offset=3D561 */ "cpu-migrations\000software\000Number of times a proces= s has migrated to a new CPU [This event is an alias of migrations]\000confi= g=3D4\000\00000\000\000\000\000\000" +/* offset=3D693 */ "migrations\000software\000Number of times a process ha= s migrated to a new CPU [This event is an alias of cpu-migrations]\000confi= g=3D4\000\00000\000\000\000\000\000" +/* offset=3D825 */ "minor-faults\000software\000Number of minor page fault= s. Minor faults don't require I/O to handle\000config=3D5\000\00000\000\000= \000\000\000" +/* offset=3D934 */ "major-faults\000software\000Number of major page fault= s. Major faults require I/O to handle\000config=3D6\000\00000\000\000\000\0= 00\000" +/* offset=3D1037 */ "alignment-faults\000software\000Number of kernel hand= led memory alignment faults\000config=3D7\000\00000\000\000\000\000\000" +/* offset=3D1129 */ "emulation-faults\000software\000Number of kernel hand= led unimplemented instruction faults handled through emulation\000config=3D= 8\000\00000\000\000\000\000\000" +/* offset=3D1256 */ "dummy\000software\000A placeholder event that doesn't= count anything\000config=3D9\000\00000\000\000\000\000\000" +/* offset=3D1336 */ "bpf-output\000software\000An event used by BPF progra= ms to write to the perf ring buffer\000config=3D0xa\000\00000\000\000\000\0= 00\000" +/* offset=3D1438 */ "cgroup-switches\000software\000Number of context swit= ches to a task in a different cgroup\000config=3D0xb\000\00000\000\000\000\= 000\000" +/* offset=3D1541 */ "tool\000" +/* offset=3D1546 */ "duration_time\000tool\000Wall clock interval time in = nanoseconds\000config=3D1\000\00000\000\000\000\000\000" +/* offset=3D1622 */ "user_time\000tool\000User (non-kernel) time in nanose= conds\000config=3D2\000\00000\000\000\000\000\000" +/* offset=3D1692 */ "system_time\000tool\000System/kernel time in nanoseco= nds\000config=3D3\000\00000\000\000\000\000\000" +/* offset=3D1760 */ "has_pmem\000tool\0001 if persistent memory installed = otherwise 0\000config=3D4\000\00000\000\000\000\000\000" +/* offset=3D1836 */ "num_cores\000tool\000Number of cores. A core consists= of 1 or more thread, with each thread being associated with a logical Linu= x CPU\000config=3D5\000\00000\000\000\000\000\000" +/* offset=3D1981 */ "num_cpus\000tool\000Number of logical Linux CPUs. The= re may be multiple such CPUs on a core\000config=3D6\000\00000\000\000\000\= 000\000" +/* offset=3D2084 */ "num_cpus_online\000tool\000Number of online logical L= inux CPUs. There may be multiple such CPUs on a core\000config=3D7\000\0000= 0\000\000\000\000\000" +/* offset=3D2201 */ "num_dies\000tool\000Number of dies. Each die has 1 or= more cores\000config=3D8\000\00000\000\000\000\000\000" +/* offset=3D2277 */ "num_packages\000tool\000Number of packages. Each pack= age has 1 or more die\000config=3D9\000\00000\000\000\000\000\000" +/* offset=3D2363 */ "slots\000tool\000Number of functional units that in p= arallel can execute parts of an instruction\000config=3D0xa\000\00000\000\0= 00\000\000\000" +/* offset=3D2473 */ "smt_on\000tool\0001 if simultaneous multithreading (a= ka hyperthreading) is enable otherwise 0\000config=3D0xb\000\00000\000\000\= 000\000\000" +/* offset=3D2580 */ "system_tsc_freq\000tool\000The amount a Time Stamp Co= unter (TSC) increases per second\000config=3D0xc\000\00000\000\000\000\000\= 000" +/* offset=3D2679 */ "default_core\000" +/* offset=3D2692 */ "bp_l1_btb_correct\000branch\000L1 BTB Correction\000e= vent=3D0x8a\000\00000\000\000\000\000\000" +/* offset=3D2754 */ "bp_l2_btb_correct\000branch\000L2 BTB Correction\000e= vent=3D0x8b\000\00000\000\000\000\000\000" +/* offset=3D2816 */ "l3_cache_rd\000cache\000L3 cache access, read\000even= t=3D0x40\000\00000\000\000\000\000Attributable Level 3 cache access, read\0= 00" +/* offset=3D2914 */ "segment_reg_loads.any\000other\000Number of segment r= egister loads\000event=3D6,period=3D200000,umask=3D0x80\000\00000\000\000\0= 00\000\000" +/* offset=3D3016 */ "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=3D3149 */ "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=3D3267 */ "hisi_sccl,ddrc\000" +/* offset=3D3282 */ "uncore_hisi_ddrc.flux_wcmd\000uncore\000DDRC write co= mmands\000event=3D2\000\00000\000\000\000\000\000" +/* offset=3D3352 */ "uncore_cbox\000" +/* offset=3D3364 */ "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=3D3518 */ "event-hyphen\000uncore\000UNC_CBO_HYPHEN\000event=3D0= xe0\000\00000\000\000\000\000\000" +/* offset=3D3572 */ "event-two-hyph\000uncore\000UNC_CBO_TWO_HYPH\000event= =3D0xc0\000\00000\000\000\000\000\000" +/* offset=3D3630 */ "hisi_sccl,l3c\000" +/* offset=3D3644 */ "uncore_hisi_l3c.rd_hit_cpipe\000uncore\000Total read = hits\000event=3D7\000\00000\000\000\000\000\000" +/* offset=3D3712 */ "uncore_imc_free_running\000" +/* offset=3D3736 */ "uncore_imc_free_running.cache_miss\000uncore\000Total= cache misses\000event=3D0x12\000\00000\000\000\000\000\000" +/* offset=3D3816 */ "uncore_imc\000" +/* offset=3D3827 */ "uncore_imc.cache_hits\000uncore\000Total cache hits\0= 00event=3D0x34\000\00000\000\000\000\000\000" +/* offset=3D3892 */ "uncore_sys_ddr_pmu\000" +/* offset=3D3911 */ "sys_ddr_pmu.write_cycles\000uncore\000ddr write-cycle= s event\000event=3D0x2b\000v8\00000\000\000\000\000\000" +/* offset=3D3987 */ "uncore_sys_ccn_pmu\000" +/* offset=3D4006 */ "sys_ccn_pmu.read_cycles\000uncore\000ccn read-cycles = event\000config=3D0x2c\0000x01\00000\000\000\000\000\000" +/* offset=3D4083 */ "uncore_sys_cmn_pmu\000" +/* offset=3D4102 */ "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=3D4245 */ "CPI\000\0001 / IPC\000\000\000\000\000\000\000\00000" +/* offset=3D4267 */ "IPC\000group1\000inst_retired.any / cpu_clk_unhalted.= thread\000\000\000\000\000\000\000\00000" +/* offset=3D4330 */ "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=3D4496 */ "dcache_miss_cpi\000\000l1d\\-loads\\-misses / inst_re= tired.any\000\000\000\000\000\000\000\00000" +/* offset=3D4560 */ "icache_miss_cycles\000\000l1i\\-loads\\-misses / inst= _retired.any\000\000\000\000\000\000\000\00000" +/* offset=3D4627 */ "cache_miss_cycles\000group1\000dcache_miss_cpi + icac= he_miss_cycles\000\000\000\000\000\000\000\00000" +/* offset=3D4698 */ "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=3D4792 */ "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=3D4926 */ "DCache_L2_All\000\000DCache_L2_All_Hits + DCache_L2_A= ll_Miss\000\000\000\000\000\000\000\00000" +/* offset=3D4990 */ "DCache_L2_Hits\000\000d_ratio(DCache_L2_All_Hits, DCa= che_L2_All)\000\000\000\000\000\000\000\00000" +/* offset=3D5058 */ "DCache_L2_Misses\000\000d_ratio(DCache_L2_All_Miss, D= Cache_L2_All)\000\000\000\000\000\000\000\00000" +/* offset=3D5128 */ "M1\000\000ipc + M2\000\000\000\000\000\000\000\00000" +/* offset=3D5150 */ "M2\000\000ipc + M1\000\000\000\000\000\000\000\00000" +/* offset=3D5172 */ "M3\000\0001 / M3\000\000\000\000\000\000\000\00000" +/* offset=3D5192 */ "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_software[] =3D { +{ 1037 }, /* alignment-faults\000software\000Number of kernel handled memo= ry alignment faults\000config=3D7\000\00000\000\000\000\000\000 */ +{ 1336 }, /* bpf-output\000software\000An event used by BPF programs to wr= ite to the perf ring buffer\000config=3D0xa\000\00000\000\000\000\000\000 */ +{ 1438 }, /* cgroup-switches\000software\000Number of context switches to = a task in a different cgroup\000config=3D0xb\000\00000\000\000\000\000\000 = */ +{ 359 }, /* context-switches\000software\000Number of context switches [Th= is event is an alias of cs]\000config=3D3\000\00000\000\000\000\000\000 */ +{ 9 }, /* cpu-clock\000software\000Per-CPU high-resolution timer based eve= nt\000config=3D0\000\00000\000\000\000\000\000 */ +{ 561 }, /* cpu-migrations\000software\000Number of times a process has mi= grated to a new CPU [This event is an alias of migrations]\000config=3D4\00= 0\00000\000\000\000\000\000 */ +{ 460 }, /* cs\000software\000Number of context switches [This event is an= alias of context-switches]\000config=3D3\000\00000\000\000\000\000\000 */ +{ 1256 }, /* dummy\000software\000A placeholder event that doesn't count a= nything\000config=3D9\000\00000\000\000\000\000\000 */ +{ 1129 }, /* emulation-faults\000software\000Number of kernel handled unim= plemented instruction faults handled through emulation\000config=3D8\000\00= 000\000\000\000\000\000 */ +{ 169 }, /* faults\000software\000Number of page faults [This event is an = alias of page-faults]\000config=3D2\000\00000\000\000\000\000\000 */ +{ 934 }, /* major-faults\000software\000Number of major page faults. Major= faults require I/O to handle\000config=3D6\000\00000\000\000\000\000\000 */ +{ 693 }, /* migrations\000software\000Number of times a process has migrat= ed to a new CPU [This event is an alias of cpu-migrations]\000config=3D4\00= 0\00000\000\000\000\000\000 */ +{ 825 }, /* minor-faults\000software\000Number of minor page faults. Minor= faults don't require I/O to handle\000config=3D5\000\00000\000\000\000\000= \000 */ +{ 264 }, /* page-faults\000software\000Number of page faults [This event i= s an alias of faults]\000config=3D2\000\00000\000\000\000\000\000 */ +{ 87 }, /* task-clock\000software\000Task based high-resolution timer base= d event\000config=3D1\000\00000\000\000\000\000\000 */ +}; static const struct compact_pmu_event pmu_events__common_tool[] =3D { -{ 5 }, /* duration_time\000tool\000Wall clock interval time in nanoseconds= \000config=3D1\000\00000\000\000\000\000\000 */ -{ 219 }, /* has_pmem\000tool\0001 if persistent memory installed otherwise= 0\000config=3D4\000\00000\000\000\000\000\000 */ -{ 295 }, /* num_cores\000tool\000Number of cores. A core consists of 1 or = more thread, with each thread being associated with a logical Linux CPU\000= config=3D5\000\00000\000\000\000\000\000 */ -{ 440 }, /* num_cpus\000tool\000Number of logical Linux CPUs. There may be= multiple such CPUs on a core\000config=3D6\000\00000\000\000\000\000\000 */ -{ 543 }, /* num_cpus_online\000tool\000Number of online logical Linux CPUs= . There may be multiple such CPUs on a core\000config=3D7\000\00000\000\000= \000\000\000 */ -{ 660 }, /* num_dies\000tool\000Number of dies. Each die has 1 or more cor= es\000config=3D8\000\00000\000\000\000\000\000 */ -{ 736 }, /* num_packages\000tool\000Number of packages. Each package has 1= or more die\000config=3D9\000\00000\000\000\000\000\000 */ -{ 822 }, /* slots\000tool\000Number of functional units that in parallel c= an execute parts of an instruction\000config=3D0xa\000\00000\000\000\000\00= 0\000 */ -{ 932 }, /* smt_on\000tool\0001 if simultaneous multithreading (aka hypert= hreading) is enable otherwise 0\000config=3D0xb\000\00000\000\000\000\000\0= 00 */ -{ 151 }, /* system_time\000tool\000System/kernel time in nanoseconds\000co= nfig=3D3\000\00000\000\000\000\000\000 */ -{ 1039 }, /* system_tsc_freq\000tool\000The amount a Time Stamp Counter (T= SC) increases per second\000config=3D0xc\000\00000\000\000\000\000\000 */ -{ 81 }, /* user_time\000tool\000User (non-kernel) time in nanoseconds\000c= onfig=3D2\000\00000\000\000\000\000\000 */ +{ 1546 }, /* duration_time\000tool\000Wall clock interval time in nanoseco= nds\000config=3D1\000\00000\000\000\000\000\000 */ +{ 1760 }, /* has_pmem\000tool\0001 if persistent memory installed otherwis= e 0\000config=3D4\000\00000\000\000\000\000\000 */ +{ 1836 }, /* num_cores\000tool\000Number of cores. A core consists of 1 or= more thread, with each thread being associated with a logical Linux CPU\00= 0config=3D5\000\00000\000\000\000\000\000 */ +{ 1981 }, /* num_cpus\000tool\000Number of logical Linux CPUs. There may b= e multiple such CPUs on a core\000config=3D6\000\00000\000\000\000\000\000 = */ +{ 2084 }, /* num_cpus_online\000tool\000Number of online logical Linux CPU= s. There may be multiple such CPUs on a core\000config=3D7\000\00000\000\00= 0\000\000\000 */ +{ 2201 }, /* num_dies\000tool\000Number of dies. Each die has 1 or more co= res\000config=3D8\000\00000\000\000\000\000\000 */ +{ 2277 }, /* num_packages\000tool\000Number of packages. Each package has = 1 or more die\000config=3D9\000\00000\000\000\000\000\000 */ +{ 2363 }, /* slots\000tool\000Number of functional units that in parallel = can execute parts of an instruction\000config=3D0xa\000\00000\000\000\000\0= 00\000 */ +{ 2473 }, /* smt_on\000tool\0001 if simultaneous multithreading (aka hyper= threading) is enable otherwise 0\000config=3D0xb\000\00000\000\000\000\000\= 000 */ +{ 1692 }, /* system_time\000tool\000System/kernel time in nanoseconds\000c= onfig=3D3\000\00000\000\000\000\000\000 */ +{ 2580 }, /* system_tsc_freq\000tool\000The amount a Time Stamp Counter (T= SC) increases per second\000config=3D0xc\000\00000\000\000\000\000\000 */ +{ 1622 }, /* user_time\000tool\000User (non-kernel) time in nanoseconds\00= 0config=3D2\000\00000\000\000\000\000\000 */ =20 }; =20 const struct pmu_table_entry pmu_events__common[] =3D { +{ + .entries =3D pmu_events__common_software, + .num_entries =3D ARRAY_SIZE(pmu_events__common_software), + .pmu_name =3D { 0 /* software\000 */ }, +}, { .entries =3D pmu_events__common_tool, .num_entries =3D ARRAY_SIZE(pmu_events__common_tool), - .pmu_name =3D { 0 /* tool\000 */ }, + .pmu_name =3D { 1541 /* tool\000 */ }, }, }; =20 static const struct compact_pmu_event pmu_events__test_soc_cpu_default_cor= e[] =3D { -{ 1151 }, /* bp_l1_btb_correct\000branch\000L1 BTB Correction\000event=3D0= x8a\000\00000\000\000\000\000\000 */ -{ 1213 }, /* bp_l2_btb_correct\000branch\000L2 BTB Correction\000event=3D0= x8b\000\00000\000\000\000\000\000 */ -{ 1475 }, /* dispatch_blocked.any\000other\000Memory cluster signals to bl= ock micro-op dispatch for any reason\000event=3D9,period=3D200000,umask=3D0= x20\000\00000\000\000\000\000\000 */ -{ 1608 }, /* eist_trans\000other\000Number of Enhanced Intel SpeedStep(R) = Technology (EIST) transitions\000event=3D0x3a,period=3D200000\000\00000\000= \000\000\000\000 */ -{ 1275 }, /* l3_cache_rd\000cache\000L3 cache access, read\000event=3D0x40= \000\00000\000\000\000\000Attributable Level 3 cache access, read\000 */ -{ 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 */ +{ 2692 }, /* bp_l1_btb_correct\000branch\000L1 BTB Correction\000event=3D0= x8a\000\00000\000\000\000\000\000 */ +{ 2754 }, /* bp_l2_btb_correct\000branch\000L2 BTB Correction\000event=3D0= x8b\000\00000\000\000\000\000\000 */ +{ 3016 }, /* dispatch_blocked.any\000other\000Memory cluster signals to bl= ock micro-op dispatch for any reason\000event=3D9,period=3D200000,umask=3D0= x20\000\00000\000\000\000\000\000 */ +{ 3149 }, /* eist_trans\000other\000Number of Enhanced Intel SpeedStep(R) = Technology (EIST) transitions\000event=3D0x3a,period=3D200000\000\00000\000= \000\000\000\000 */ +{ 2816 }, /* l3_cache_rd\000cache\000L3 cache access, read\000event=3D0x40= \000\00000\000\000\000\000Attributable Level 3 cache access, read\000 */ +{ 2914 }, /* 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\000\000 */ +{ 3282 }, /* 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 { -{ 2103 }, /* uncore_hisi_l3c.rd_hit_cpipe\000uncore\000Total read hits\000= event=3D7\000\00000\000\000\000\000\000 */ +{ 3644 }, /* 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 { -{ 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 */ +{ 3518 }, /* event-hyphen\000uncore\000UNC_CBO_HYPHEN\000event=3D0xe0\000\= 00000\000\000\000\000\000 */ +{ 3572 }, /* event-two-hyph\000uncore\000UNC_CBO_TWO_HYPH\000event=3D0xc0\= 000\00000\000\000\000\000\000 */ +{ 3364 }, /* 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 { -{ 2286 }, /* uncore_imc.cache_hits\000uncore\000Total cache hits\000event= =3D0x34\000\00000\000\000\000\000\000 */ +{ 3827 }, /* 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 { -{ 2195 }, /* uncore_imc_free_running.cache_miss\000uncore\000Total cache m= isses\000event=3D0x12\000\00000\000\000\000\000\000 */ +{ 3736 }, /* uncore_imc_free_running.cache_miss\000uncore\000Total cache m= isses\000event=3D0x12\000\00000\000\000\000\000\000 */ =20 }; =20 @@ -129,51 +167,51 @@ const struct pmu_table_entry pmu_events__test_soc_cpu= [] =3D { { .entries =3D pmu_events__test_soc_cpu_default_core, .num_entries =3D ARRAY_SIZE(pmu_events__test_soc_cpu_default_core), - .pmu_name =3D { 1138 /* default_core\000 */ }, + .pmu_name =3D { 2679 /* default_core\000 */ }, }, { .entries =3D pmu_events__test_soc_cpu_hisi_sccl_ddrc, .num_entries =3D ARRAY_SIZE(pmu_events__test_soc_cpu_hisi_sccl_ddrc), - .pmu_name =3D { 1726 /* hisi_sccl,ddrc\000 */ }, + .pmu_name =3D { 3267 /* hisi_sccl,ddrc\000 */ }, }, { .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 { 2089 /* hisi_sccl,l3c\000 */ }, + .pmu_name =3D { 3630 /* 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 { 1811 /* uncore_cbox\000 */ }, + .pmu_name =3D { 3352 /* 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 { 2275 /* uncore_imc\000 */ }, + .pmu_name =3D { 3816 /* 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 { 2171 /* uncore_imc_free_running\000 */ }, + .pmu_name =3D { 3712 /* uncore_imc_free_running\000 */ }, }, }; =20 static const struct compact_pmu_event pmu_metrics__test_soc_cpu_default_co= re[] =3D { -{ 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 */ +{ 4245 }, /* CPI\000\0001 / IPC\000\000\000\000\000\000\000\00000 */ +{ 4926 }, /* DCache_L2_All\000\000DCache_L2_All_Hits + DCache_L2_All_Miss\= 000\000\000\000\000\000\000\00000 */ +{ 4698 }, /* 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 */ +{ 4792 }, /* 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 */ +{ 4990 }, /* DCache_L2_Hits\000\000d_ratio(DCache_L2_All_Hits, DCache_L2_A= ll)\000\000\000\000\000\000\000\00000 */ +{ 5058 }, /* DCache_L2_Misses\000\000d_ratio(DCache_L2_All_Miss, DCache_L2= _All)\000\000\000\000\000\000\000\00000 */ +{ 4330 }, /* 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 */ +{ 4267 }, /* IPC\000group1\000inst_retired.any / cpu_clk_unhalted.thread\0= 00\000\000\000\000\000\000\00000 */ +{ 5192 }, /* L1D_Cache_Fill_BW\000\00064 * l1d.replacement / 1e9 / duratio= n_time\000\000\000\000\000\000\000\00000 */ +{ 5128 }, /* M1\000\000ipc + M2\000\000\000\000\000\000\000\00000 */ +{ 5150 }, /* M2\000\000ipc + M1\000\000\000\000\000\000\000\00000 */ +{ 5172 }, /* M3\000\0001 / M3\000\000\000\000\000\000\000\00000 */ +{ 4627 }, /* cache_miss_cycles\000group1\000dcache_miss_cpi + icache_miss_= cycles\000\000\000\000\000\000\000\00000 */ +{ 4496 }, /* dcache_miss_cpi\000\000l1d\\-loads\\-misses / inst_retired.an= y\000\000\000\000\000\000\000\00000 */ +{ 4560 }, /* icache_miss_cycles\000\000l1i\\-loads\\-misses / inst_retired= .any\000\000\000\000\000\000\000\00000 */ =20 }; =20 @@ -181,18 +219,18 @@ const struct pmu_table_entry pmu_metrics__test_soc_cp= u[] =3D { { .entries =3D pmu_metrics__test_soc_cpu_default_core, .num_entries =3D ARRAY_SIZE(pmu_metrics__test_soc_cpu_default_core), - .pmu_name =3D { 1138 /* default_core\000 */ }, + .pmu_name =3D { 2679 /* default_core\000 */ }, }, }; =20 static const struct compact_pmu_event pmu_events__test_soc_sys_uncore_sys_= ccn_pmu[] =3D { -{ 2465 }, /* sys_ccn_pmu.read_cycles\000uncore\000ccn read-cycles event\00= 0config=3D0x2c\0000x01\00000\000\000\000\000\000 */ +{ 4006 }, /* 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 { -{ 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 */ +{ 4102 }, /* 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 { -{ 2370 }, /* sys_ddr_pmu.write_cycles\000uncore\000ddr write-cycles event\= 000event=3D0x2b\000v8\00000\000\000\000\000\000 */ +{ 3911 }, /* sys_ddr_pmu.write_cycles\000uncore\000ddr write-cycles event\= 000event=3D0x2b\000v8\00000\000\000\000\000\000 */ =20 }; =20 @@ -200,17 +238,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 { 2446 /* uncore_sys_ccn_pmu\000 */ }, + .pmu_name =3D { 3987 /* 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 { 2542 /* uncore_sys_cmn_pmu\000 */ }, + .pmu_name =3D { 4083 /* 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 { 2351 /* uncore_sys_ddr_pmu\000 */ }, + .pmu_name =3D { 3892 /* uncore_sys_ddr_pmu\000 */ }, }, }; =20 @@ -632,8 +670,20 @@ static const struct pmu_events_map *map_for_pmu(struct= perf_pmu *pmu) { struct perf_cpu cpu =3D {-1}; =20 - if (pmu) + if (pmu) { + for (size_t i=3D0; i < ARRAY_SIZE(pmu_events__common); i++= ) { + const char *pmu_name =3D &big_c_string[pmu_events_= _common[i].pmu_name.offset]; + + if (!strcmp(pmu_name, pmu->name)) { + const struct pmu_events_map *map =3D &pmu_= events_map[0]; + + while (strcmp("common", map->arch)) + map++; + return map; + } + } cpu =3D perf_cpu_map__min(pmu->cpus); + } return map_for_cpu(cpu); } =20 diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jeven= ts.py index e821155151ec..76c1e7b0bc22 100755 --- a/tools/perf/pmu-events/jevents.py +++ b/tools/perf/pmu-events/jevents.py @@ -295,6 +295,7 @@ class JsonEvent: 'cpu_atom': 'cpu_atom', 'ali_drw': 'ali_drw', 'arm_cmn': 'arm_cmn', + 'software': 'software', 'tool': 'tool', } return table[unit] if unit in table else f'uncore_{unit.lower()}' @@ -1158,8 +1159,20 @@ static const struct pmu_events_map *map_for_pmu(stru= ct perf_pmu *pmu) { struct perf_cpu cpu =3D {-1}; =20 - if (pmu) + if (pmu) { + for (size_t i=3D0; i < ARRAY_SIZE(pmu_events__common); i++= ) { + const char *pmu_name =3D &big_c_string[pmu_events_= _common[i].pmu_name.offset]; + + if (!strcmp(pmu_name, pmu->name)) { + const struct pmu_events_map *map =3D &pmu_= events_map[0]; + + while (strcmp("common", map->arch)) + map++; + return map; + } + } cpu =3D perf_cpu_map__min(pmu->cpus); + } return map_for_cpu(cpu); } =20 --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Wed Oct 8 12:52:11 2025 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CEC9B17A305 for ; Sat, 28 Jun 2025 00:09:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751069397; cv=none; b=agFS+YTsA5AurecAGWKv5fRL8YqHe78SKakg+1eYdZ7sEHFbYhjrliigbdjFLhosTtzjp9Ae6wT374PLdSFJE25qD0wlfGj3ZlXTd0szy/lPq5YXna+HrOVkhw+D0oY0OBMoIcioETiJAHcMPD9bJvkTebMNGBHjsCUR8+vyUBM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751069397; c=relaxed/simple; bh=J4OzpKjzAQvz4+NOOvDQC2wN1+kdU2op3Xo8SV5ZLbk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=GH0cAmcWQKwJHo7ZpEZn0Gt/07amsLOzl6vfwpKLnSlqPRK7640RGK4hiBk/YyQffaigB0J0Myx7KO0Wl7y6wgoUe2FsrTDMXhXZzeDCnB3f3mnzwzrltJOfNztEs2ZCW9mkX7CD+8GgWAK3B3w8pRVNskZbfHUslVigqx6016Y= 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=gKNjDDMQ; arc=none smtp.client-ip=209.85.210.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="gKNjDDMQ" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-747ddba7c90so385294b3a.0 for ; Fri, 27 Jun 2025 17:09:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1751069395; x=1751674195; 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=/8RYnoHHKYJ1Y4zKmI9S+F9LPJ5D9yBDipkEOnTdUXE=; b=gKNjDDMQG8hwZMGcr08TyYY1vF4eUguP7PK+E4b2Xx0Lf+eDzfiSu5lMieNiAuKfmD XLhSlygy6RDWI7X5RxnExaoUEpBtkKkzlQNMyElUyr3fBDKRjP7H1fKr0wLFo5JWtURv MgbzWE+oUYSfEmUA8AcIU+rw5Tq/NaG+uTWgmsQp25389TjJJqSQedRvSccync9iP5WB YH9Ez8Y7r5YoqlJiGjnoM4Pl2P24Swz+1fEA91VI4ubIpaVEAUsQbDNJm3qZnXExifaY 7ukYRAXcPlqHp4YSmSDJHAEMQJxmz6O1a5suj3/9xSoBUnWnrX8CYuJlzoAprgPOcls0 41+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751069395; x=1751674195; 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=/8RYnoHHKYJ1Y4zKmI9S+F9LPJ5D9yBDipkEOnTdUXE=; b=v1otm6FL9FUIUgjz2CTNppGQm0jw53A98NNcPSyb0wIbhrbm0zFmjlcynX3bPE0An+ VJ5QRB2rP90I4SZ+EmBBCQfKzy0zH47lCrsn0ubdS+Mg0QX/0/XUFMKtirrtgZt8dgE4 iNUzTP5MSsF4HGXYTk4d2wk1VaBArjcPh2OegTKwT4jLF65cVurmSJBhMkYeIYIshkAC sU2hWGCHbQAxXS3ehZw7PaR4egbxrcjrFUwha4W/tmtj0PgnMvaAIMn2dmxlW5HrNT4i v5l6Tv6IU1DY04H6Lx3i6K/efJwCjIXtqW8Z69rBiCRiUDQJhqprwKwx0HIS2V9zaPg7 6vhw== X-Forwarded-Encrypted: i=1; AJvYcCVegexE/yVEKtzniNMqsIv/I/B+WVYR/Js1K00jJnwBdu8+vbA0h/uqpByKL61zlyxUvJkhBf6PNkKuIZ4=@vger.kernel.org X-Gm-Message-State: AOJu0YwMrWVEaNTVbdz4zE3O2fPfGuD4V+Ku41ZLVeuqyKBXxcGgN6lA Fy1nO+3B5PDdSnH9gQS9LKqYP38R+/MfvHKJsjHEfdXcYr+m3Ibnx+si9XB6K58GiqrawUebiFN d71CPRlIgRA== X-Google-Smtp-Source: AGHT+IHI9yoH6ryjs/0r4lN1uoc1sVLOFEewvIRG3rwL1A72VaGHVS4LqMyQeJlSUs10Na5kPFr5nyABWMCu X-Received: from pfay37.prod.google.com ([2002:a05:6a00:1825:b0:748:f16c:14c5]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:648d:b0:1f5:769a:a4be with SMTP id adf61e73a8af0-220a181ba61mr9052587637.36.1751069395119; Fri, 27 Jun 2025 17:09:55 -0700 (PDT) Date: Fri, 27 Jun 2025 17:09:24 -0700 In-Reply-To: <20250628000929.230406-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: <20250628000929.230406-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250628000929.230406-11-irogers@google.com> Subject: [PATCH v4 10/15] 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 , John Garry , "Masami Hiramatsu (Google)" , Howard Chu , Weilin Wang , Thomas Richter , Andi Kleen , Tiezhu Yang , Gautam Menghani , linux-kernel@vger.kernel.org, linux-perf-users@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 687288991eb4..b09b2ea2407a 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -1181,6 +1181,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) { @@ -1200,8 +1226,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 Wed Oct 8 12:52:11 2025 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BB76E1A3179 for ; Sat, 28 Jun 2025 00:09:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751069399; cv=none; b=g2GXDIRlj05oGfNi7s2TTlEqJCoLAXhcddv0PJB9/KmGlDwcwHU0HXJP6m0sIEQMYFpJqaof5w9009pCVOKXC1o3ilKEr8eb3PGdamuMatq/i37GwLeE4CGLQY/EofAgY9NRIxkAkkVU3gMXV/MSn0wtzJFZCQrL800ErZDXGhg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751069399; c=relaxed/simple; bh=G72bnfuAzESwqoklX8PNfdwVx67YCWOYAKzlNjKKZ4c=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=HD/zHr5xnMB+hIqtCxv9ItOGohTr7phBa+n6z5WTEBrl51pJxbKGX6CZjddgimCMQbG6OfpwS461SZbgcftfpTTBMWN23WM23CKHzXY271mxVSb36ejnuOFzrP1D2pztHBPCJxRi55vZFL/9xKaxp+66RlS5GH7clmjg4toaz8A= 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=b1b7dZF8; arc=none smtp.client-ip=209.85.210.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="b1b7dZF8" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-747dd44048cso3235461b3a.3 for ; Fri, 27 Jun 2025 17:09:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1751069397; x=1751674197; 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=CLjJFNtTS5wrZiD3O0j9/NWWZofN5Wd2O/PmGh4D0Bc=; b=b1b7dZF82t1GPIkB7Xuph7pPRty78+wwHTiHY1dd6q/cr2DxdPYpMAON+la0v7d+Fu 3yQKKh5cEy2UyvSjXdSh2hokpZ2C2SiXtR1u2X7q7c/J1JOqnTWLcPyiRj837NJ40F7J 8JCMk7ESlONk9xwQYpFiVFWfJCIvyjaHM71stI7qnT4iN5EIuAkrAqTfBfC+YJzjTAiU YTVatC7oRja3hkzEj2ejJtvaQG7uqTKRyPl9BQ+A+9iIF6KgPpa0LPiUPpmRfWdHjQAV zQ3WpEC5qaQKOnv0e6cK4tZXEbf8JhwQahB3LQzvEokrkGrH2Oda5dLwstlUCFAi5AL7 +A1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751069397; x=1751674197; 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=CLjJFNtTS5wrZiD3O0j9/NWWZofN5Wd2O/PmGh4D0Bc=; b=kD7KljqPg4hvMgMW4Dpf+TdDfsu+B2/VaGK9FbR9ujRk0u9pBgKaRIyaAyOl/B6Q3r yGdN7IW2jiQNn4yRLyJQC58ZQGfPhiB/p08Lx0VOnnO4Bptpg4wejRC0sUI2X822YR/I OvOIxT7gT4+8jRLikEBFQrAQEDDHPDKZ7vv7ATlrEfOBw9pOfsT3VtCMK1TJWU7/w3pT 2FEUAXe4IKX+Cgws3JdS4HO1ywe8UYVLCkjBzJ0rg0OdDgdB4tBR0Lc/mJjaCzRlbTbv qMk8M0P2VZc791/8o4h6nD+CpCVKYLG1Mf8yss6X908OniGriVTqDxm6BTPLDsYVUk3w cGUA== X-Forwarded-Encrypted: i=1; AJvYcCWC24XJAxrcWs5oXIhqj25ul2WRKPZXdJTea/fOgztN1Rzz9vXD4cDnihALKoDmO+oduFJnEOzq8mhiho4=@vger.kernel.org X-Gm-Message-State: AOJu0YwSgPAPU2I40NiNp+Ii2xxbQpmXVHw5uPFWs1y3gx9/pVpQWi5E rBdU56SgDxk6lKel0IoQ/BJs808rXznsp6vlmXngYKK4lvZa/k+FS4AFvO134O1j9lPfh6KyDO8 s3Nq1vTXN5Q== X-Google-Smtp-Source: AGHT+IHWMy1Kqp83lLK+2KsTyyTJ2bfqVkuMAHHQbCsIYBoQ13GK0VtEBDNZ6lyiQB9ACXAys8eoTDvUfn14 X-Received: from pfbhw14.prod.google.com ([2002:a05:6a00:890e:b0:748:fb38:1909]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:cc1:b0:736:50d1:fc84 with SMTP id d2e1a72fcca58-74af6f57829mr6430055b3a.21.1751069397176; Fri, 27 Jun 2025 17:09:57 -0700 (PDT) Date: Fri, 27 Jun 2025 17:09:25 -0700 In-Reply-To: <20250628000929.230406-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: <20250628000929.230406-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250628000929.230406-12-irogers@google.com> Subject: [PATCH v4 11/15] perf parse-events: Remove non-json software events From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Xu Yang , John Garry , "Masami Hiramatsu (Google)" , Howard Chu , Weilin Wang , Thomas Richter , Andi Kleen , Tiezhu Yang , Gautam Menghani , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Remove the hard coded encodings from parse-events. This has the consequence that software events are matched using the sysfs/json priority, will be case insensitive and will be wildcarded across PMUs. As there were software and hardware types in the parsing code, the removal means software vs hardware logic can be removed and hardware assumed. Now the perf json provides detailed descriptions of software events, remove the previous listing support that didn't contain event descriptions. When globbing is required for the "sw" option in perf list, use string PMU globbing as was done previously for the tool PMU. Signed-off-by: Ian Rogers --- tools/perf/builtin-list.c | 19 ++++++------- tools/perf/util/parse-events.c | 51 ---------------------------------- tools/perf/util/parse-events.h | 1 - tools/perf/util/parse-events.l | 38 +++++++++---------------- tools/perf/util/parse-events.y | 29 ++++++++----------- tools/perf/util/print-events.c | 2 -- 6 files changed, 33 insertions(+), 107 deletions(-) diff --git a/tools/perf/builtin-list.c b/tools/perf/builtin-list.c index e9b595d75df2..674bb0afbf93 100644 --- a/tools/perf/builtin-list.c +++ b/tools/perf/builtin-list.c @@ -623,16 +623,17 @@ int cmd_list(int argc, const char **argv) else if (strcmp(argv[i], "sw") =3D=3D 0 || strcmp(argv[i], "software") =3D=3D 0) { char *old_pmu_glob =3D default_ps.pmu_glob; + static const char * const sw_globs[] =3D { "software", "tool" }; =20 - print_symbol_events(&print_cb, ps, PERF_TYPE_SOFTWARE, - event_symbols_sw, PERF_COUNT_SW_MAX); - default_ps.pmu_glob =3D strdup("tool"); - if (!default_ps.pmu_glob) { - ret =3D -1; - goto out; + for (size_t j =3D 0; j < ARRAY_SIZE(sw_globs); j++) { + default_ps.pmu_glob =3D strdup(sw_globs[j]); + if (!default_ps.pmu_glob) { + ret =3D -1; + goto out; + } + perf_pmus__print_pmu_events(&print_cb, ps); + zfree(&default_ps.pmu_glob); } - perf_pmus__print_pmu_events(&print_cb, ps); - zfree(&default_ps.pmu_glob); default_ps.pmu_glob =3D old_pmu_glob; } else if (strcmp(argv[i], "cache") =3D=3D 0 || strcmp(argv[i], "hwcache") =3D=3D 0) @@ -679,8 +680,6 @@ int cmd_list(int argc, const char **argv) default_ps.event_glob =3D s; print_symbol_events(&print_cb, ps, PERF_TYPE_HARDWARE, event_symbols_hw, PERF_COUNT_HW_MAX); - print_symbol_events(&print_cb, ps, PERF_TYPE_SOFTWARE, - event_symbols_sw, PERF_COUNT_SW_MAX); print_hwcache_events(&print_cb, ps); perf_pmus__print_pmu_events(&print_cb, ps); print_tracepoint_events(&print_cb, ps); diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index a59ae5ca0f89..1ae481c9802b 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -84,57 +84,6 @@ const struct event_symbol event_symbols_hw[PERF_COUNT_HW= _MAX] =3D { }, }; =20 -const struct event_symbol event_symbols_sw[PERF_COUNT_SW_MAX] =3D { - [PERF_COUNT_SW_CPU_CLOCK] =3D { - .symbol =3D "cpu-clock", - .alias =3D "", - }, - [PERF_COUNT_SW_TASK_CLOCK] =3D { - .symbol =3D "task-clock", - .alias =3D "", - }, - [PERF_COUNT_SW_PAGE_FAULTS] =3D { - .symbol =3D "page-faults", - .alias =3D "faults", - }, - [PERF_COUNT_SW_CONTEXT_SWITCHES] =3D { - .symbol =3D "context-switches", - .alias =3D "cs", - }, - [PERF_COUNT_SW_CPU_MIGRATIONS] =3D { - .symbol =3D "cpu-migrations", - .alias =3D "migrations", - }, - [PERF_COUNT_SW_PAGE_FAULTS_MIN] =3D { - .symbol =3D "minor-faults", - .alias =3D "", - }, - [PERF_COUNT_SW_PAGE_FAULTS_MAJ] =3D { - .symbol =3D "major-faults", - .alias =3D "", - }, - [PERF_COUNT_SW_ALIGNMENT_FAULTS] =3D { - .symbol =3D "alignment-faults", - .alias =3D "", - }, - [PERF_COUNT_SW_EMULATION_FAULTS] =3D { - .symbol =3D "emulation-faults", - .alias =3D "", - }, - [PERF_COUNT_SW_DUMMY] =3D { - .symbol =3D "dummy", - .alias =3D "", - }, - [PERF_COUNT_SW_BPF_OUTPUT] =3D { - .symbol =3D "bpf-output", - .alias =3D "", - }, - [PERF_COUNT_SW_CGROUP_SWITCHES] =3D { - .symbol =3D "cgroup-switches", - .alias =3D "", - }, -}; - static const char *const event_types[] =3D { [PERF_TYPE_HARDWARE] =3D "hardware", [PERF_TYPE_SOFTWARE] =3D "software", diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h index b47bf2810112..62dc7202e3ba 100644 --- a/tools/perf/util/parse-events.h +++ b/tools/perf/util/parse-events.h @@ -264,7 +264,6 @@ struct event_symbol { const char *alias; }; extern const struct event_symbol event_symbols_hw[]; -extern const struct event_symbol event_symbols_sw[]; =20 char *parse_events_formats_error_string(char *additional_terms); =20 diff --git a/tools/perf/util/parse-events.l b/tools/perf/util/parse-events.l index 4af7b9c1f44d..2034590eb789 100644 --- a/tools/perf/util/parse-events.l +++ b/tools/perf/util/parse-events.l @@ -117,12 +117,12 @@ do { \ yyless(0); \ } while (0) =20 -static int sym(yyscan_t scanner, int type, int config) +static int sym(yyscan_t scanner, int config) { YYSTYPE *yylval =3D parse_events_get_lval(scanner); =20 - yylval->num =3D (type << 16) + config; - return type =3D=3D PERF_TYPE_HARDWARE ? PE_VALUE_SYM_HW : PE_VALUE_SYM_SW; + yylval->num =3D config; + return PE_VALUE_SYM_HW; } =20 static int term(yyscan_t scanner, enum parse_events__term_type type) @@ -391,28 +391,16 @@ r0x{num_raw_hex} { return str(yyscanner, PE_RAW); } <> { BEGIN(INITIAL); } } =20 -cpu-cycles|cycles { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUN= T_HW_CPU_CYCLES); } -stalled-cycles-frontend|idle-cycles-frontend { return sym(yyscanner, PERF_= TYPE_HARDWARE, PERF_COUNT_HW_STALLED_CYCLES_FRONTEND); } -stalled-cycles-backend|idle-cycles-backend { return sym(yyscanner, PERF_TY= PE_HARDWARE, PERF_COUNT_HW_STALLED_CYCLES_BACKEND); } -instructions { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW= _INSTRUCTIONS); } -cache-references { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT= _HW_CACHE_REFERENCES); } -cache-misses { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW= _CACHE_MISSES); } -branch-instructions|branches { return sym(yyscanner, PERF_TYPE_HARDWARE,= PERF_COUNT_HW_BRANCH_INSTRUCTIONS); } -branch-misses { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_H= W_BRANCH_MISSES); } -bus-cycles { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_B= US_CYCLES); } -ref-cycles { return sym(yyscanner, PERF_TYPE_HARDWARE, PERF_COUNT_HW_R= EF_CPU_CYCLES); } -cpu-clock { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CP= U_CLOCK); } -task-clock { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_T= ASK_CLOCK); } -page-faults|faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COU= NT_SW_PAGE_FAULTS); } -minor-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW= _PAGE_FAULTS_MIN); } -major-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW= _PAGE_FAULTS_MAJ); } -context-switches|cs { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_CO= UNT_SW_CONTEXT_SWITCHES); } -cpu-migrations|migrations { return sym(yyscanner, PERF_TYPE_SOFTWARE, PE= RF_COUNT_SW_CPU_MIGRATIONS); } -alignment-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT= _SW_ALIGNMENT_FAULTS); } -emulation-faults { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT= _SW_EMULATION_FAULTS); } -dummy { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_DUMMY= ); } -bpf-output { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_B= PF_OUTPUT); } -cgroup-switches { return sym(yyscanner, PERF_TYPE_SOFTWARE, PERF_COUNT= _SW_CGROUP_SWITCHES); } +cpu-cycles|cycles { return sym(yyscanner, PERF_COUNT_HW_CPU_CYCLES); } +stalled-cycles-frontend|idle-cycles-frontend { return sym(yyscanner, PERF_= COUNT_HW_STALLED_CYCLES_FRONTEND); } +stalled-cycles-backend|idle-cycles-backend { return sym(yyscanner, PERF_CO= UNT_HW_STALLED_CYCLES_BACKEND); } +instructions { return sym(yyscanner, PERF_COUNT_HW_INSTRUCTIONS); } +cache-references { return sym(yyscanner, PERF_COUNT_HW_CACHE_REFERENCES= ); } +cache-misses { return sym(yyscanner, PERF_COUNT_HW_CACHE_MISSES); } +branch-instructions|branches { return sym(yyscanner, PERF_COUNT_HW_BRANC= H_INSTRUCTIONS); } +branch-misses { return sym(yyscanner, PERF_COUNT_HW_BRANCH_MISSES); } +bus-cycles { return sym(yyscanner, PERF_COUNT_HW_BUS_CYCLES); } +ref-cycles { return sym(yyscanner, PERF_COUNT_HW_REF_CPU_CYCLES); } =20 {lc_type} { return str(yyscanner, PE_LEGACY_CACHE); } {lc_type}-{lc_op_result} { return str(yyscanner, PE_LEGACY_CACHE); } diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y index f888cbb076d6..a2361c0040d7 100644 --- a/tools/perf/util/parse-events.y +++ b/tools/perf/util/parse-events.y @@ -55,7 +55,7 @@ static void free_list_evsel(struct list_head* list_evsel) %} =20 %token PE_START_EVENTS PE_START_TERMS -%token PE_VALUE PE_VALUE_SYM_HW PE_VALUE_SYM_SW PE_TERM +%token PE_VALUE PE_VALUE_SYM_HW PE_TERM %token PE_EVENT_NAME %token PE_RAW PE_NAME %token PE_MODIFIER_EVENT PE_MODIFIER_BP PE_BP_COLON PE_BP_SLASH @@ -66,10 +66,8 @@ static void free_list_evsel(struct list_head* list_evsel) %token PE_TERM_HW %type PE_VALUE %type PE_VALUE_SYM_HW -%type PE_VALUE_SYM_SW %type PE_MODIFIER_EVENT %type PE_TERM -%type value_sym %type PE_RAW %type PE_NAME %type PE_LEGACY_CACHE @@ -306,24 +304,19 @@ PE_NAME sep_dc $$ =3D list; } =20 -value_sym: -PE_VALUE_SYM_HW -| -PE_VALUE_SYM_SW - event_legacy_symbol: -value_sym '/' event_config '/' +PE_VALUE_SYM_HW '/' event_config '/' { struct list_head *list; - int type =3D $1 >> 16; - int config =3D $1 & 255; int err; - bool wildcard =3D (type =3D=3D PERF_TYPE_HARDWARE || type =3D=3D PERF_TYP= E_HW_CACHE); =20 list =3D alloc_list(); if (!list) YYNOMEM; - err =3D parse_events_add_numeric(_parse_state, list, type, config, $3, wi= ldcard); + err =3D parse_events_add_numeric(_parse_state, list, + PERF_TYPE_HARDWARE, $1, + $3, + /*wildcard=3D*/true); parse_events_terms__delete($3); if (err) { free_list_evsel(list); @@ -332,18 +325,18 @@ value_sym '/' event_config '/' $$ =3D list; } | -value_sym sep_slash_slash_dc +PE_VALUE_SYM_HW sep_slash_slash_dc { struct list_head *list; - int type =3D $1 >> 16; - int config =3D $1 & 255; - bool wildcard =3D (type =3D=3D PERF_TYPE_HARDWARE || type =3D=3D PERF_TYP= E_HW_CACHE); int err; =20 list =3D alloc_list(); if (!list) YYNOMEM; - err =3D parse_events_add_numeric(_parse_state, list, type, config, /*head= _config=3D*/NULL, wildcard); + err =3D parse_events_add_numeric(_parse_state, list, + PERF_TYPE_HARDWARE, $1, + /*head_config=3D*/NULL, + /*wildcard=3D*/true); if (err) PE_ABORT(err); $$ =3D list; diff --git a/tools/perf/util/print-events.c b/tools/perf/util/print-events.c index 83aaf7cda635..5c10d8fdfd7d 100644 --- a/tools/perf/util/print-events.c +++ b/tools/perf/util/print-events.c @@ -388,8 +388,6 @@ void print_events(const struct print_callbacks *print_c= b, void *print_state) { print_symbol_events(print_cb, print_state, PERF_TYPE_HARDWARE, event_symbols_hw, PERF_COUNT_HW_MAX); - print_symbol_events(print_cb, print_state, PERF_TYPE_SOFTWARE, - event_symbols_sw, PERF_COUNT_SW_MAX); =20 print_hwcache_events(print_cb, print_state); =20 --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Wed Oct 8 12:52:11 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 328161E2312 for ; Sat, 28 Jun 2025 00:09:59 +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=1751069403; cv=none; b=ZRes+rtN3cbxSho3gMc5nBsVZY7BqaVOUWuEb4mTKJi32YNVS3JKEosR9Jxe3ZRpbK2Cr2cb5p+bWztTf2K72VzsbqEPKV61jxT193wIsjrAfYSmb+9GJeqHp1SArFne2ldbpp6wiQOufywVq/AsVCTLu92XtwVmLlqO+5xkaFc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751069403; c=relaxed/simple; bh=NZ25etocvdr6C+Hlzu++citoCETSmGjjbxbFzunE4ak=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=sbtD7dSB4R6BGVtpiZM9qFmd4/EXP3rF0MkP3a+iPWrgt9d2CA692+fIPMSoMlsHw97CE1vsKegLc9MBSktUE7D8nzuFvyD7rnjh3gw5Ucvf44x7I+o4Jf8i7wqi1PzkhgYxRbNOSClatKjqg/pwX5YTuVhTZA8AXzfZU1lf4dI= 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=lLXtz13j; 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="lLXtz13j" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-7394772635dso2088836b3a.0 for ; Fri, 27 Jun 2025 17:09:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1751069399; x=1751674199; 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=kWm0G0sjkrU0nYEaAFtt7yTI4GIQGY3PReE0jusHdoo=; b=lLXtz13jn4exRwwsoUkPHlyuBHtzuQ87lAS+8ZG6thUa8dGa+nJajvPYfaUrmjFgHG Yc0UPSiz1e215E+1JWLRVmpOICz3y4OQ2sBznSdOKHWEJAtdO1N1xx6T2Jty39a8pkLg iOmQvwzgUrG4zBsXeE9zsTvKvlzksg51oQhs+Jv4hiosOcn/hu0aeQ5hwWThtfKbPJrC ZdYEDhU/pbHk4N3W/rz6OK33+HNMoCCAaiGZeNlM2MImKrg2wo35LmAlmOvWUMOx/95n NJUS9A+CuUPY9+bppbSdGNfl0kdqJ4JjZoPqogkzvUzHOtQBujr1/08mRpy0uVabt3aG 1V0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751069399; x=1751674199; 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=kWm0G0sjkrU0nYEaAFtt7yTI4GIQGY3PReE0jusHdoo=; b=KBHW/rlDvPIUhHHq3pYdULj0KUvIzjkPTvxZVTC0hEZtSs496LldHn5cNg/R0qNaWT OhgtMLp3XOkAtpT7mQFfWOEtterZ+y0VXcpBwNTO+Kz/zUjy13dyPKYZm9DLkUa7lrY2 2lqYSCYIfPl3CBfu3+sIr3Yr7Qn0kMRaUGClEt/sgqVPBPUz0fTvyvsOU+BQO1LYXn3U umU+B+TZGZs4WU9y0+F5R//mV2QN95kcdt3Jn1xJ3n4NEmBUNiSUVzjxf9aD5HkTZzjt EGEcl05Aau01TKWbV7+AFgGApvCaQ3QKQqU6xzmr7j9KU4Ll5O9YnEiRrkWtRR6XCWzT 6/aA== X-Forwarded-Encrypted: i=1; AJvYcCV6bZj9o4DuSSmwqS2VQoWuvklN6HZhezasuC/4Q5nSTyzMKL9Qj5YaGeCQ7TGTnzxe6NrZhhty2O2O3J0=@vger.kernel.org X-Gm-Message-State: AOJu0Yw0uYTpVUtHDeAzNQ1BPnOlX3cEsbRMfjuOyVB+8T6w+XAhZlK4 PA35iyzNEhI0CylhTtKlnxdULubxsahZkdHEqds2SnpFBYVUEO4glDIrjwcxLPBsyUUYr/LslIw z1/Tu/ETjow== X-Google-Smtp-Source: AGHT+IEDga8V5TBh+23vwY3Wgmg4MzKqUnl6BoVkVSQtmsOI8lUPJHY9+kwDDSNQaOyWIbCuKUu4tNHiSVXf X-Received: from pfbbw20.prod.google.com ([2002:a05:6a00:4094:b0:746:247f:7384]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:618b:b0:215:e1cc:6360 with SMTP id adf61e73a8af0-220a12dc82bmr7045183637.11.1751069399290; Fri, 27 Jun 2025 17:09:59 -0700 (PDT) Date: Fri, 27 Jun 2025 17:09:26 -0700 In-Reply-To: <20250628000929.230406-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: <20250628000929.230406-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250628000929.230406-13-irogers@google.com> Subject: [PATCH v4 12/15] perf tp_pmu: Factor existing tracepoint logic to new file 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 , John Garry , "Masami Hiramatsu (Google)" , Howard Chu , Weilin Wang , Thomas Richter , Andi Kleen , Tiezhu Yang , Gautam Menghani , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Start the creation of a tracepoint PMU abstraction. Tracepoint events don't follow the regular sysfs perf conventions. Eventually the new PMU abstraction will bridge the gap so tracepoint events look more like regular perf ones. Signed-off-by: Ian Rogers --- tools/perf/util/Build | 1 + tools/perf/util/evsel.c | 21 +---- tools/perf/util/parse-events.c | 147 ++++++++++++++------------------- tools/perf/util/tp_pmu.c | 95 +++++++++++++++++++++ tools/perf/util/tp_pmu.h | 12 +++ 5 files changed, 170 insertions(+), 106 deletions(-) create mode 100644 tools/perf/util/tp_pmu.c create mode 100644 tools/perf/util/tp_pmu.h diff --git a/tools/perf/util/Build b/tools/perf/util/Build index 45515b8f615a..12fd1135bff5 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build @@ -88,6 +88,7 @@ perf-util-y +=3D pmu-bison.o perf-util-y +=3D drm_pmu.o perf-util-y +=3D hwmon_pmu.o perf-util-y +=3D tool_pmu.o +perf-util-y +=3D tp_pmu.o perf-util-y +=3D svghelper.o perf-util-y +=3D trace-event-info.o perf-util-y +=3D trace-event-scripting.o diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 9c50c3960487..13d41f959728 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -59,6 +59,7 @@ #include "drm_pmu.h" #include "hwmon_pmu.h" #include "tool_pmu.h" +#include "tp_pmu.h" #include "rlimit.h" #include "../perf-sys.h" #include "util/parse-branch-options.h" @@ -571,24 +572,6 @@ struct evsel *evsel__clone(struct evsel *dest, struct = evsel *orig) return NULL; } =20 -static int trace_event__id(const char *sys, const char *name) -{ - char *tp_dir =3D get_events_file(sys); - char path[PATH_MAX]; - int id, err; - - if (!tp_dir) - return -1; - - scnprintf(path, PATH_MAX, "%s/%s/id", tp_dir, name); - put_events_file(tp_dir); - err =3D filename__read_int(path, &id); - if (err) - return err; - - return id; -} - /* * Returns pointer with encoded error via interface. */ @@ -622,7 +605,7 @@ struct evsel *evsel__newtp_idx(const char *sys, const c= har *name, int idx, bool event_attr_init(&attr); =20 if (format) { - id =3D trace_event__id(sys, name); + id =3D tp_pmu__id(sys, name); if (id < 0) { err =3D id; goto out_free; diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 1ae481c9802b..f19541ca5268 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -17,13 +17,12 @@ #include "string2.h" #include "strbuf.h" #include "debug.h" -#include -#include #include #include #include #include "pmu.h" #include "pmus.h" +#include "tp_pmu.h" #include "asm/bug.h" #include "ui/ui.h" #include "util/parse-branch-options.h" @@ -33,6 +32,7 @@ #include "util/stat.h" #include "util/util.h" #include "tracepoint.h" +#include =20 #define MAX_NAME_LEN 100 =20 @@ -558,105 +558,82 @@ static int add_tracepoint(struct parse_events_state = *parse_state, return 0; } =20 -static int add_tracepoint_multi_event(struct parse_events_state *parse_sta= te, - struct list_head *list, - const char *sys_name, const char *evt_name, - struct parse_events_error *err, - struct parse_events_terms *head_config, YYLTYPE *loc) -{ - char *evt_path; - struct io_dirent64 *evt_ent; - struct io_dir evt_dir; - int ret =3D 0, found =3D 0; - - evt_path =3D get_events_file(sys_name); - if (!evt_path) { - tracepoint_error(err, errno, sys_name, evt_name, loc->first_column); - return -1; - } - io_dir__init(&evt_dir, open(evt_path, O_CLOEXEC | O_DIRECTORY | O_RDONLY)= ); - if (evt_dir.dirfd < 0) { - put_events_file(evt_path); - tracepoint_error(err, errno, sys_name, evt_name, loc->first_column); - return -1; - } +struct add_tracepoint_multi_args { + struct parse_events_state *parse_state; + struct list_head *list; + const char *sys_glob; + const char *evt_glob; + struct parse_events_error *err; + struct parse_events_terms *head_config; + YYLTYPE *loc; + int found; +}; =20 - while (!ret && (evt_ent =3D io_dir__readdir(&evt_dir))) { - if (!strcmp(evt_ent->d_name, ".") - || !strcmp(evt_ent->d_name, "..") - || !strcmp(evt_ent->d_name, "enable") - || !strcmp(evt_ent->d_name, "filter")) - continue; +static int add_tracepoint_multi_event_cb(void *state, const char *sys_name= , const char *evt_name) +{ + struct add_tracepoint_multi_args *args =3D state; + int ret; =20 - if (!strglobmatch(evt_ent->d_name, evt_name)) - continue; + if (!strglobmatch(evt_name, args->evt_glob)) + return 0; =20 - found++; + args->found++; + ret =3D add_tracepoint(args->parse_state, args->list, sys_name, evt_name, + args->err, args->head_config, args->loc); =20 - ret =3D add_tracepoint(parse_state, list, sys_name, evt_ent->d_name, - err, head_config, loc); - } + return ret; +} =20 - if (!found) { - tracepoint_error(err, ENOENT, sys_name, evt_name, loc->first_column); - ret =3D -1; +static int add_tracepoint_multi_event(struct add_tracepoint_multi_args *ar= gs, const char *sys_name) +{ + if (strpbrk(args->evt_glob, "*?") =3D=3D NULL) { + /* Not a glob. */ + args->found++; + return add_tracepoint(args->parse_state, args->list, sys_name, args->evt= _glob, + args->err, args->head_config, args->loc); } =20 - put_events_file(evt_path); - close(evt_dir.dirfd); - return ret; + return tp_pmu__for_each_tp_event(sys_name, args, add_tracepoint_multi_eve= nt_cb); } =20 -static int add_tracepoint_event(struct parse_events_state *parse_state, - struct list_head *list, - const char *sys_name, const char *evt_name, - struct parse_events_error *err, - struct parse_events_terms *head_config, YYLTYPE *loc) +static int add_tracepoint_multi_sys_cb(void *state, const char *sys_name) { - return strpbrk(evt_name, "*?") ? - add_tracepoint_multi_event(parse_state, list, sys_name, evt_name, - err, head_config, loc) : - add_tracepoint(parse_state, list, sys_name, evt_name, - err, head_config, loc); + struct add_tracepoint_multi_args *args =3D state; + + if (!strglobmatch(sys_name, args->sys_glob)) + return 0; + + return add_tracepoint_multi_event(args, sys_name); } =20 static int add_tracepoint_multi_sys(struct parse_events_state *parse_state, struct list_head *list, - const char *sys_name, const char *evt_name, + const char *sys_glob, const char *evt_glob, struct parse_events_error *err, struct parse_events_terms *head_config, YYLTYPE *loc) { - struct io_dirent64 *events_ent; - struct io_dir events_dir; - int ret =3D 0; - char *events_dir_path =3D get_tracing_file("events"); + struct add_tracepoint_multi_args args =3D { + .parse_state =3D parse_state, + .list =3D list, + .sys_glob =3D sys_glob, + .evt_glob =3D evt_glob, + .err =3D err, + .head_config =3D head_config, + .loc =3D loc, + .found =3D 0, + }; + int ret; =20 - if (!events_dir_path) { - tracepoint_error(err, errno, sys_name, evt_name, loc->first_column); - return -1; + if (strpbrk(sys_glob, "*?") =3D=3D NULL) { + /* Not a glob. */ + ret =3D add_tracepoint_multi_event(&args, sys_glob); + } else { + ret =3D tp_pmu__for_each_tp_sys(&args, add_tracepoint_multi_sys_cb); } - io_dir__init(&events_dir, open(events_dir_path, O_CLOEXEC | O_DIRECTORY |= O_RDONLY)); - put_events_file(events_dir_path); - if (events_dir.dirfd < 0) { - tracepoint_error(err, errno, sys_name, evt_name, loc->first_column); - return -1; + if (args.found =3D=3D 0) { + tracepoint_error(err, ENOENT, sys_glob, evt_glob, loc->first_column); + return -ENOENT; } - - while (!ret && (events_ent =3D io_dir__readdir(&events_dir))) { - if (!strcmp(events_ent->d_name, ".") - || !strcmp(events_ent->d_name, "..") - || !strcmp(events_ent->d_name, "enable") - || !strcmp(events_ent->d_name, "header_event") - || !strcmp(events_ent->d_name, "header_page")) - continue; - - if (!strglobmatch(events_ent->d_name, sys_name)) - continue; - - ret =3D add_tracepoint_event(parse_state, list, events_ent->d_name, - evt_name, err, head_config, loc); - } - close(events_dir.dirfd); return ret; } =20 @@ -1348,12 +1325,8 @@ int parse_events_add_tracepoint(struct parse_events_= state *parse_state, return -EINVAL; } =20 - if (strpbrk(sys, "*?")) - return add_tracepoint_multi_sys(parse_state, list, sys, event, - err, head_config, loc); - else - return add_tracepoint_event(parse_state, list, sys, event, - err, head_config, loc); + return add_tracepoint_multi_sys(parse_state, list, sys, event, + err, head_config, loc); } =20 static int __parse_events_add_numeric(struct parse_events_state *parse_sta= te, diff --git a/tools/perf/util/tp_pmu.c b/tools/perf/util/tp_pmu.c new file mode 100644 index 000000000000..fd83164f8763 --- /dev/null +++ b/tools/perf/util/tp_pmu.c @@ -0,0 +1,95 @@ +// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) +#include "tp_pmu.h" +#include +#include +#include +#include +#include +#include + +int tp_pmu__id(const char *sys, const char *name) +{ + char *tp_dir =3D get_events_file(sys); + char path[PATH_MAX]; + int id, err; + + if (!tp_dir) + return -1; + + scnprintf(path, PATH_MAX, "%s/%s/id", tp_dir, name); + put_events_file(tp_dir); + err =3D filename__read_int(path, &id); + if (err) + return err; + + return id; +} + + +int tp_pmu__for_each_tp_event(const char *sys, void *state, tp_event_callb= ack cb) +{ + char *evt_path; + struct io_dirent64 *evt_ent; + struct io_dir evt_dir; + int ret =3D 0; + + evt_path =3D get_events_file(sys); + if (!evt_path) + return -errno; + + io_dir__init(&evt_dir, open(evt_path, O_CLOEXEC | O_DIRECTORY | O_RDONLY)= ); + if (evt_dir.dirfd < 0) { + ret =3D -errno; + put_events_file(evt_path); + return ret; + } + put_events_file(evt_path); + + while (!ret && (evt_ent =3D io_dir__readdir(&evt_dir))) { + if (!strcmp(evt_ent->d_name, ".") + || !strcmp(evt_ent->d_name, "..") + || !strcmp(evt_ent->d_name, "enable") + || !strcmp(evt_ent->d_name, "filter")) + continue; + + ret =3D cb(state, sys, evt_ent->d_name); + if (ret) + break; + } + close(evt_dir.dirfd); + return ret; +} + +int tp_pmu__for_each_tp_sys(void *state, tp_sys_callback cb) +{ + struct io_dirent64 *events_ent; + struct io_dir events_dir; + int ret =3D 0; + char *events_dir_path =3D get_tracing_file("events"); + + if (!events_dir_path) + return -errno; + + io_dir__init(&events_dir, open(events_dir_path, O_CLOEXEC | O_DIRECTORY |= O_RDONLY)); + if (events_dir.dirfd < 0) { + ret =3D -errno; + put_events_file(events_dir_path); + return ret; + } + put_events_file(events_dir_path); + + while (!ret && (events_ent =3D io_dir__readdir(&events_dir))) { + if (!strcmp(events_ent->d_name, ".") + || !strcmp(events_ent->d_name, "..") + || !strcmp(events_ent->d_name, "enable") + || !strcmp(events_ent->d_name, "header_event") + || !strcmp(events_ent->d_name, "header_page")) + continue; + + ret =3D cb(state, events_ent->d_name); + if (ret) + break; + } + close(events_dir.dirfd); + return ret; +} diff --git a/tools/perf/util/tp_pmu.h b/tools/perf/util/tp_pmu.h new file mode 100644 index 000000000000..49537303bd73 --- /dev/null +++ b/tools/perf/util/tp_pmu.h @@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */ +#ifndef __TP_PMU_H +#define __TP_PMU_H + +typedef int (*tp_sys_callback)(void *state, const char *sys_name); +typedef int (*tp_event_callback)(void *state, const char *sys_name, const = char *evt_name); + +int tp_pmu__id(const char *sys, const char *name); +int tp_pmu__for_each_tp_event(const char *sys, void *state, tp_event_callb= ack cb); +int tp_pmu__for_each_tp_sys(void *state, tp_sys_callback cb); + +#endif /* __TP_PMU_H */ --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Wed Oct 8 12:52:11 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 7D4331F8AC5 for ; Sat, 28 Jun 2025 00:10:03 +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=1751069406; cv=none; b=KfighhbWw87OGvMMjnKDv9CM+q1oWxAr+yD3VBUB/++YVO4mFT0mulB/wNqsft+Izpov4nsEES8278N4VusiW7cW0+PReseVzK6A2nwZqFUzj7hIyUc+rtUZ+ftg7opMnHNhYqfVwFY88dWKdE7rb1Lj+xD3QeJTaA6iyt9cf8o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751069406; c=relaxed/simple; bh=RZ/4wZ7BLS3RqD09YBHOjY7W3qZV5Jmx+MPGWahCs1s=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=A4JY0+W9gWQCnlnEcA0yrOGmenRC75V/Tzy863zP2pYo8Q9C8G4qpXqgqMNT9u3/+V6OGYFabmStkRV657yT9/YqmwipJEBsKB3MrUcPMEWMDiClOSAR1Ans3sEWiF/RCFPWr54qzwd9gcaQ1qJq3B90lfOlOYzKsIo0ZvJOQ78= 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=SVs0S+HT; 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="SVs0S+HT" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-b2eb60594e8so298805a12.1 for ; Fri, 27 Jun 2025 17:10:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1751069403; x=1751674203; 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=O5/KtDdH9KZtizmnT+G+DMzo0YjRxsCsauFrBz7enXg=; b=SVs0S+HT7EAgQjgmZOkr4S5E2BDAymqCdEViIbnPThRv7rPr0GLprz/vmlTCHqdjZR Oo1peA5Om6XYt4Wa714zvqbAMADL3vL4npBcKCmD/ifsuFWXfMhypCOXtLZN4Sjeaw81 A47phVdc//BH6nV5T1Yi6G2VHR9MUE7sCIOFfk3+ljASNe1TaEOMWB43dMPo+2k+k/oh 5vb9Uq15XyeOI4lnbgE186OBqDV5ADZ3+trGLnJzCSTIdQW+ay9sZygHpBI1MV8xtBlq e4Df4DbPZlCOL9o1Tkibu4j8xqpQSKRNijM7B2CloYPyhfXeqzSzfilRQ0ubSYTAhDzw weyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751069403; x=1751674203; 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=O5/KtDdH9KZtizmnT+G+DMzo0YjRxsCsauFrBz7enXg=; b=jAEjZQWFbpHwHsQqAsZ1Lp/+oK6ey2PyrQwobUffLVwhfPS7OeLAaPeLUbAQgIkuLd yk+ahXFam2Gsx3jtfzGcrc3hRxL4GbgbE9avaFGGIKGIm5HCGiOsLkWI3Or6QKmHXQq8 ZBkl6gbLueuJi+SuUBw3GfPUSJm0A/0yjPIEF5ClVpYmcTfE7hA6AYi+LVUnRzU7FfVf 4Zyw0eaeZX7Z6R2lzHyf/EfAq1XIsFu1V3o5uKmGca/wfS3ijpVRes+r5FTpF4oip8MM F7jQcG0jKm23KkI/PTu/bFxnjMQ8saUgAJs0ijC0zekFcEOHgSMTiispxALXPmu2rtNE LjPQ== X-Forwarded-Encrypted: i=1; AJvYcCVVxguwJhBAtrk4Ishya5cD/AYOdeDiPSZqGQZhnkhozY0ZVoJ+DoC8bxn4iUSuKtrX5d76D0tJAYq1muY=@vger.kernel.org X-Gm-Message-State: AOJu0YyanFpi0z/ylyYbcRdH9JWSh7Z2ozYePuIE721wxDK7WIo4mObn nIKGI7lmt4wifxsq7OhzlcEQfP8mELPsg9Dq6W/wf/q2qhAfYgl3yJ3EcbtLFyTES2mT6IUdJHW yAK43lKdEcg== X-Google-Smtp-Source: AGHT+IFfaWErwEWkdM77xhMbB2SsCw2H2bFaIgieGbl7n4DQyfnQbUFtF2Dc7oBV1oF534nb3xW8gEFjX3I0 X-Received: from pfwp48.prod.google.com ([2002:a05:6a00:26f0:b0:748:e8fc:e9f0]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:50e:b0:220:396b:9938 with SMTP id adf61e73a8af0-220a14149b7mr7595941637.18.1751069402838; Fri, 27 Jun 2025 17:10:02 -0700 (PDT) Date: Fri, 27 Jun 2025 17:09:27 -0700 In-Reply-To: <20250628000929.230406-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: <20250628000929.230406-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250628000929.230406-14-irogers@google.com> Subject: [PATCH v4 13/15] perf tp_pmu: Add event APIs 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 , John Garry , "Masami Hiramatsu (Google)" , Howard Chu , Weilin Wang , Thomas Richter , Andi Kleen , Tiezhu Yang , Gautam Menghani , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add event APIs for the tracepoint PMU allowing things like perf list to function using it. For perf list add the tracepoint format in the long description (shown with -v). Signed-off-by: Ian Rogers --- tools/perf/util/pmu.c | 7 +++ tools/perf/util/tp_pmu.c | 114 +++++++++++++++++++++++++++++++++++++++ tools/perf/util/tp_pmu.h | 7 +++ 3 files changed, 128 insertions(+) diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index b09b2ea2407a..dc05233e8232 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -24,6 +24,7 @@ #include "hwmon_pmu.h" #include "pmus.h" #include "tool_pmu.h" +#include "tp_pmu.h" #include #include #include "parse-events.h" @@ -1983,6 +1984,8 @@ bool perf_pmu__have_event(struct perf_pmu *pmu, const= char *name) return false; if (perf_pmu__is_tool(pmu) && tool_pmu__skip_event(name)) return false; + if (perf_pmu__is_tracepoint(pmu)) + return tp_pmu__have_event(pmu, name); if (perf_pmu__is_hwmon(pmu)) return hwmon_pmu__have_event(pmu, name); if (perf_pmu__is_drm(pmu)) @@ -1998,6 +2001,8 @@ size_t perf_pmu__num_events(struct perf_pmu *pmu) { size_t nr; =20 + if (perf_pmu__is_tracepoint(pmu)) + return tp_pmu__num_events(pmu); if (perf_pmu__is_hwmon(pmu)) return hwmon_pmu__num_events(pmu); if (perf_pmu__is_drm(pmu)) @@ -2068,6 +2073,8 @@ int perf_pmu__for_each_event(struct perf_pmu *pmu, bo= ol skip_duplicate_pmus, struct hashmap_entry *entry; size_t bkt; =20 + if (perf_pmu__is_tracepoint(pmu)) + return tp_pmu__for_each_event(pmu, state, cb); if (perf_pmu__is_hwmon(pmu)) return hwmon_pmu__for_each_event(pmu, state, cb); if (perf_pmu__is_drm(pmu)) diff --git a/tools/perf/util/tp_pmu.c b/tools/perf/util/tp_pmu.c index fd83164f8763..9d68a1da17f6 100644 --- a/tools/perf/util/tp_pmu.c +++ b/tools/perf/util/tp_pmu.c @@ -1,5 +1,6 @@ // SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) #include "tp_pmu.h" +#include "pmus.h" #include #include #include @@ -93,3 +94,116 @@ int tp_pmu__for_each_tp_sys(void *state, tp_sys_callbac= k cb) close(events_dir.dirfd); return ret; } + +bool perf_pmu__is_tracepoint(const struct perf_pmu *pmu) +{ + return pmu->type =3D=3D PERF_TYPE_TRACEPOINT; +} + +struct for_each_event_args { + void *state; + pmu_event_callback cb; + const struct perf_pmu *pmu; +}; + +static int for_each_event_cb(void *state, const char *sys_name, const char= *evt_name) +{ + struct for_each_event_args *args =3D state; + char name[2 * FILENAME_MAX + 2]; + /* 16 possible hex digits and 22 other characters and \0. */ + char encoding[16 + 22]; + char *format =3D NULL; + size_t format_size; + struct pmu_event_info info =3D { + .pmu =3D args->pmu, + .pmu_name =3D args->pmu->name, + .event_type_desc =3D "Tracepoint event", + }; + char *tp_dir =3D get_events_file(sys_name); + char path[PATH_MAX]; + int id, err; + + if (!tp_dir) + return -1; + + scnprintf(path, sizeof(path), "%s/%s/id", tp_dir, evt_name); + err =3D filename__read_int(path, &id); + if (err =3D=3D 0) { + snprintf(encoding, sizeof(encoding), "tracepoint/config=3D0x%x/", id); + info.encoding_desc =3D encoding; + } + + scnprintf(path, sizeof(path), "%s/%s/format", tp_dir, evt_name); + put_events_file(tp_dir); + err =3D filename__read_str(path, &format, &format_size); + if (err =3D=3D 0) { + info.long_desc =3D format; + for (size_t i =3D 0 ; i < format_size; i++) { + /* Swap tabs to spaces due to some rendering issues. */ + if (format[i] =3D=3D '\t') + format[i] =3D ' '; + } + } + snprintf(name, sizeof(name), "%s:%s", sys_name, evt_name); + info.name =3D name; + err =3D args->cb(args->state, &info); + free(format); + return err; +} + +static int for_each_event_sys_cb(void *state, const char *sys_name) +{ + return tp_pmu__for_each_tp_event(sys_name, state, for_each_event_cb); +} + +int tp_pmu__for_each_event(struct perf_pmu *pmu, void *state, pmu_event_ca= llback cb) +{ + struct for_each_event_args args =3D { + .state =3D state, + .cb =3D cb, + .pmu =3D pmu, + }; + + return tp_pmu__for_each_tp_sys(&args, for_each_event_sys_cb); +} + +static int num_events_cb(void *state, const char *sys_name __maybe_unused, + const char *evt_name __maybe_unused) +{ + size_t *count =3D state; + + (*count)++; + return 0; +} + +static int num_events_sys_cb(void *state, const char *sys_name) +{ + return tp_pmu__for_each_tp_event(sys_name, state, num_events_cb); +} + +size_t tp_pmu__num_events(struct perf_pmu *pmu __maybe_unused) +{ + size_t count =3D 0; + + tp_pmu__for_each_tp_sys(&count, num_events_sys_cb); + return count; +} + +bool tp_pmu__have_event(struct perf_pmu *pmu __maybe_unused, const char *n= ame) +{ + char *dup_name, *colon; + int id; + + if (strchr(name, ':') =3D=3D NULL) + return false; + + dup_name =3D strdup(name); + if (!dup_name) + return false; + + colon =3D strchr(dup_name, ':'); + *colon =3D '\0'; + id =3D tp_pmu__id(dup_name, colon + 1); + free(dup_name); + return id >=3D 0; +} diff --git a/tools/perf/util/tp_pmu.h b/tools/perf/util/tp_pmu.h index 49537303bd73..30456bd6943d 100644 --- a/tools/perf/util/tp_pmu.h +++ b/tools/perf/util/tp_pmu.h @@ -2,6 +2,8 @@ #ifndef __TP_PMU_H #define __TP_PMU_H =20 +#include "pmu.h" + typedef int (*tp_sys_callback)(void *state, const char *sys_name); typedef int (*tp_event_callback)(void *state, const char *sys_name, const = char *evt_name); =20 @@ -9,4 +11,9 @@ int tp_pmu__id(const char *sys, const char *name); int tp_pmu__for_each_tp_event(const char *sys, void *state, tp_event_callb= ack cb); int tp_pmu__for_each_tp_sys(void *state, tp_sys_callback cb); =20 +bool perf_pmu__is_tracepoint(const struct perf_pmu *pmu); +int tp_pmu__for_each_event(struct perf_pmu *pmu, void *state, pmu_event_ca= llback cb); +size_t tp_pmu__num_events(struct perf_pmu *pmu); +bool tp_pmu__have_event(struct perf_pmu *pmu, const char *name); + #endif /* __TP_PMU_H */ --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Wed Oct 8 12:52:11 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 8356C20E328 for ; Sat, 28 Jun 2025 00:10:08 +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=1751069410; cv=none; b=MN6DDkcIJjORMo3vcVp9OTlM3gvw4Av2uixi/jLVGbTgrSbhgq6y6W2b7g2mA2ij3lhNJhfYqO4Fdqu9zfLOfLJBJRgI38IVjIvHuxcIgW7VoJeQ8Vn6RF0TX6K1UIMJJzBIOEa6dRg64YvGkTjUfCbHRmGMbVUlJKX5OlXmCC0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751069410; c=relaxed/simple; bh=xVL9J0uE8YY2o5HuFc/58gTf3c9R2ulRZ1/ZjoL77C0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=FnUIT9eWVxgU+jZlrdxoF05zkkQ7KOR6XY4yZI3b0A92zT05oQ6GO44iHBi+8roU1bLiaerfBwfd4eaN17Auq8j+Riizl+/5vtSuRtiUL3em/XbWLNVakLGAqLxVwfxT3okpPYooFNnPBNkHG/5rvAyh26f/y0z4zntwYgOc/0s= 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=OeCF7Yw0; 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="OeCF7Yw0" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-23536f7c2d7so2041875ad.2 for ; Fri, 27 Jun 2025 17:10:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1751069408; x=1751674208; 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=Q/+JwjdhrMBO/5HpBVeSk3LlYGjPwTHvvOOU4/K1fc8=; b=OeCF7Yw0V66Mr0HVkePBbHqW8G14Jy3qATqz8bXSY0sKc1UOol5IQuwssSGKvdUIBn E6RyucFniiAddx+hBMQ41DB1q3PU0e1EEExeT11zyHmGE7J5AqjuHYKF9a0qUQ2BPTLe hGqsyxF0u0wkXtVYbtgh8sWtSlipDidQZz3+tscI9OEEJIowj3A767Hd+PC2sb+IPuJc 394ELJVqm+B7Hy/ogBPs/+wRYDuHvZfIwFR8j8mvnI9Ai2ATKJ9xPC8FRncUcewMQKWA it6Et03u6jghD+bREHXEPdnqSjsTWaTcGmgLfWt/EnjGoH9Vh3cmRESsxHa7BdsZv7JY /K0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751069408; x=1751674208; 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=Q/+JwjdhrMBO/5HpBVeSk3LlYGjPwTHvvOOU4/K1fc8=; b=X9+ZeARIgyTBcnIo2RyGreDhz6Aft6b35citPgWMz7V50nSLLcX2VVJCdkO30yp2YV PKdRmgsnx8XaUVA68iaTEL44anekWcL7Wnx893SmNo0aVOiuNJkMrovIgVTzXT+ciX+j VKUzswK9VdiGso8xNy+HNPCDwPP3frSeOD/8ASM9JzGjaV4SA3i3f/UuQqYmotDOEqxi 5Ve4XzVjHdDFYkxvBsuuWqB3iNGqUs2oQ9o2zwaXmQbRATAvkIc9bssna0qp+oXFRHN4 QodIFv1VMqNWOYCHMQQbWw2QyvGd4LSGoI3osl+OsWtje/hFd3v0r1Sdj89eZlC5TKHo u7yw== X-Forwarded-Encrypted: i=1; AJvYcCUqMtcnK1j1YhuKEMc1SuVoLr8k52B8Af6oGqnopb92Veqb0mCTAJLC5qsV4QkGjLVv8VONRmsZCutrsjE=@vger.kernel.org X-Gm-Message-State: AOJu0YyIiITH7DwrZg9BfbpHtyzjKsGND77h6hiTItIslXYZZ8+fKZua 78I9XqLJ3N1pE0h5tCND0JRFXSPCtFJHQHMncLo5wzesZpMm+niYU91mx7PPMNDDXuFoXeAfqmc /yuqQikpadA== X-Google-Smtp-Source: AGHT+IHGtGoo6yS7p8v8uk06oyvnmlCgNtCebfmcI1adPvKEg/Zh4ipwfx8AI7ZP+yXxiet+KcfserSya3fA X-Received: from plal21.prod.google.com ([2002:a17:903:55:b0:235:895:2564]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:1107:b0:235:a9b:21e7 with SMTP id d9443c01a7336-23ac48802ddmr82623725ad.48.1751069407768; Fri, 27 Jun 2025 17:10:07 -0700 (PDT) Date: Fri, 27 Jun 2025 17:09:28 -0700 In-Reply-To: <20250628000929.230406-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: <20250628000929.230406-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250628000929.230406-15-irogers@google.com> Subject: [PATCH v4 14/15] perf list: Remove tracepoint printing code 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 , John Garry , "Masami Hiramatsu (Google)" , Howard Chu , Weilin Wang , Thomas Richter , Andi Kleen , Tiezhu Yang , Gautam Menghani , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Now that the tp_pmu can iterate and describe events remove the custom tracepoint printing logic, this avoids perf list showing the tracepoint events twice. Signed-off-by: Ian Rogers --- tools/perf/builtin-list.c | 28 +++++++--- tools/perf/util/print-events.c | 93 ---------------------------------- tools/perf/util/print-events.h | 1 - 3 files changed, 22 insertions(+), 100 deletions(-) diff --git a/tools/perf/builtin-list.c b/tools/perf/builtin-list.c index 674bb0afbf93..3216be404f27 100644 --- a/tools/perf/builtin-list.c +++ b/tools/perf/builtin-list.c @@ -614,9 +614,18 @@ int cmd_list(int argc, const char **argv) for (i =3D 0; i < argc; ++i) { char *sep, *s; =20 - if (strcmp(argv[i], "tracepoint") =3D=3D 0) - print_tracepoint_events(&print_cb, ps); - else if (strcmp(argv[i], "hw") =3D=3D 0 || + if (strcmp(argv[i], "tracepoint") =3D=3D 0) { + char *old_pmu_glob =3D default_ps.pmu_glob; + + default_ps.pmu_glob =3D strdup("tracepoint"); + if (!default_ps.pmu_glob) { + ret =3D -1; + goto out; + } + perf_pmus__print_pmu_events(&print_cb, ps); + zfree(&default_ps.pmu_glob); + default_ps.pmu_glob =3D old_pmu_glob; + } else if (strcmp(argv[i], "hw") =3D=3D 0 || strcmp(argv[i], "hardware") =3D=3D 0) print_symbol_events(&print_cb, ps, PERF_TYPE_HARDWARE, event_symbols_hw, PERF_COUNT_HW_MAX); @@ -658,6 +667,7 @@ int cmd_list(int argc, const char **argv) #endif else if ((sep =3D strchr(argv[i], ':')) !=3D NULL) { char *old_pmu_glob =3D default_ps.pmu_glob; + char *old_event_glob =3D default_ps.event_glob; =20 default_ps.event_glob =3D strdup(argv[i]); if (!default_ps.event_glob) { @@ -665,13 +675,20 @@ int cmd_list(int argc, const char **argv) goto out; } =20 - print_tracepoint_events(&print_cb, ps); + default_ps.pmu_glob =3D strdup("tracepoint"); + if (!default_ps.pmu_glob) { + zfree(&default_ps.event_glob); + ret =3D -1; + goto out; + } + perf_pmus__print_pmu_events(&print_cb, ps); + default_ps.pmu_glob =3D old_pmu_glob; print_sdt_events(&print_cb, ps); default_ps.metrics =3D true; default_ps.metricgroups =3D true; metricgroup__print(&print_cb, ps); zfree(&default_ps.event_glob); - default_ps.pmu_glob =3D old_pmu_glob; + default_ps.event_glob =3D old_event_glob; } else { if (asprintf(&s, "*%s*", argv[i]) < 0) { printf("Critical: Not enough memory! Trying to continue...\n"); @@ -682,7 +699,6 @@ int cmd_list(int argc, const char **argv) event_symbols_hw, PERF_COUNT_HW_MAX); print_hwcache_events(&print_cb, ps); perf_pmus__print_pmu_events(&print_cb, ps); - print_tracepoint_events(&print_cb, ps); print_sdt_events(&print_cb, ps); default_ps.metrics =3D true; default_ps.metricgroups =3D true; diff --git a/tools/perf/util/print-events.c b/tools/perf/util/print-events.c index 5c10d8fdfd7d..45bfc2199f13 100644 --- a/tools/perf/util/print-events.c +++ b/tools/perf/util/print-events.c @@ -44,97 +44,6 @@ static const char * const event_type_descriptors[] =3D { "Hardware breakpoint", }; =20 -/* - * Print the events from /tracing/events - */ -void print_tracepoint_events(const struct print_callbacks *print_cb __mayb= e_unused, void *print_state __maybe_unused) -{ - char *events_path =3D get_tracing_file("events"); - int events_fd =3D open(events_path, O_PATH); - struct dirent **sys_namelist =3D NULL; - int sys_items; - - if (events_fd < 0) { - pr_err("Error: failed to open tracing events directory\n"); - pr_err("%s: %s\n", events_path, strerror(errno)); - return; - } - put_tracing_file(events_path); - - sys_items =3D tracing_events__scandir_alphasort(&sys_namelist); - - for (int i =3D 0; i < sys_items; i++) { - struct dirent *sys_dirent =3D sys_namelist[i]; - struct dirent **evt_namelist =3D NULL; - int dir_fd; - int evt_items; - - if (sys_dirent->d_type !=3D DT_DIR || - !strcmp(sys_dirent->d_name, ".") || - !strcmp(sys_dirent->d_name, "..")) - goto next_sys; - - dir_fd =3D openat(events_fd, sys_dirent->d_name, O_PATH); - if (dir_fd < 0) - goto next_sys; - - evt_items =3D scandirat(events_fd, sys_dirent->d_name, &evt_namelist, NU= LL, alphasort); - for (int j =3D 0; j < evt_items; j++) { - /* - * Buffer sized at twice the max filename length + 1 - * separator + 1 \0 terminator. - */ - char buf[NAME_MAX * 2 + 2]; - /* 16 possible hex digits and 22 other characters and \0. */ - char encoding[16 + 22]; - struct dirent *evt_dirent =3D evt_namelist[j]; - struct io id; - __u64 config; - - if (evt_dirent->d_type !=3D DT_DIR || - !strcmp(evt_dirent->d_name, ".") || - !strcmp(evt_dirent->d_name, "..")) - goto next_evt; - - snprintf(buf, sizeof(buf), "%s/id", evt_dirent->d_name); - io__init(&id, openat(dir_fd, buf, O_RDONLY), buf, sizeof(buf)); - - if (id.fd < 0) - goto next_evt; - - if (io__get_dec(&id, &config) < 0) { - close(id.fd); - goto next_evt; - } - close(id.fd); - - snprintf(buf, sizeof(buf), "%s:%s", - sys_dirent->d_name, evt_dirent->d_name); - snprintf(encoding, sizeof(encoding), "tracepoint/config=3D0x%llx/", con= fig); - print_cb->print_event(print_state, - /*topic=3D*/NULL, - /*pmu_name=3D*/NULL, /* really "tracepoint" */ - /*event_name=3D*/buf, - /*event_alias=3D*/NULL, - /*scale_unit=3D*/NULL, - /*deprecated=3D*/false, - "Tracepoint event", - /*desc=3D*/NULL, - /*long_desc=3D*/NULL, - encoding); -next_evt: - free(evt_namelist[j]); - } - close(dir_fd); - free(evt_namelist); -next_sys: - free(sys_namelist[i]); - } - - free(sys_namelist); - close(events_fd); -} - void print_sdt_events(const struct print_callbacks *print_cb, void *print_= state) { struct strlist *bidlist, *sdtlist; @@ -419,8 +328,6 @@ void print_events(const struct print_callbacks *print_c= b, void *print_state) /*long_desc=3D*/NULL, /*encoding_desc=3D*/NULL); =20 - print_tracepoint_events(print_cb, print_state); - print_sdt_events(print_cb, print_state); =20 metricgroup__print(print_cb, print_state); diff --git a/tools/perf/util/print-events.h b/tools/perf/util/print-events.h index 8f19c2bea64a..02511ed6ecad 100644 --- a/tools/perf/util/print-events.h +++ b/tools/perf/util/print-events.h @@ -37,7 +37,6 @@ 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); bool is_event_supported(u8 type, u64 config); =20 #endif /* __PERF_PRINT_EVENTS_H */ --=20 2.50.0.727.gbf7dc18ff4-goog From nobody Wed Oct 8 12:52:11 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 9971C207A0B for ; Sat, 28 Jun 2025 00:10:10 +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=1751069412; cv=none; b=sMj/y7SwMqNQagkGeqIc1DV8FqTMWY1rXWQi53BjNWCTlNVMZGS8H3BeMqN4YAY4k5xrVjulJNgLW1/8rL3YRvIgaBjFszVSYpPAoU0DZ3/3PZUn+R4LfTfvmGtNHmvv5lB23q+k+3xliE7VRrZCV74EZ0mDaziTEK89PTa3G84= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751069412; c=relaxed/simple; bh=D1meKHm9HLxVcV+eADlMNBj+6b4Bh9wc5AOyxldTOIA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=pJtEjpKUzm6KZWmrW7S3In3ejN+Pa3CpjFAM+DrCbZIDtqtvGutVlwiqeLNIm8bXSNuno7WVzl7Z0ITP9MwovfYaHpcVuLmHBc1x/1J5G1QnKMbI3I4Ah61qTsnZHgAX5q8cc8OzkOG49+O8LBsKSpy/CWLOaAS4oZCfsJU7vTI= 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=sh1wAB4R; 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="sh1wAB4R" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-311a6b43ed7so84403a91.1 for ; Fri, 27 Jun 2025 17:10:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1751069410; x=1751674210; 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=bWGI+WCsIN51TDRPS0BPiVuu9g5rUZhDYM76R7qcpLA=; b=sh1wAB4Req3TMH5QoF2wxxvJ+9lGBF4uImA/x8kBAH2Z69m4RZLeLWDHSUijqQmqXw zoNeidSt04cf4Ddg6h8viSFc38euNjFsRU/4nNE388YatNCXz4b5Gq8aZt0C7vYtFCf2 Aa4HneTrAb57Jard+kT/873XktRuVfiaJZHfPu+z0HyXxbu85m51AzUaTGcY8iSdHi0U gqODBzOKopx6v7fRsbltN1w9PkonUQN9Moz4bl6rdgWjDclRJq6PDT99lDJ1VPMnTbr6 d5YyShnigiHmmcwzxsNtAFAZe8GlqcihN7rnM1RQVLzzGP47l5bwzeWW1MBsArtFdVCv OAAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751069410; x=1751674210; 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=bWGI+WCsIN51TDRPS0BPiVuu9g5rUZhDYM76R7qcpLA=; b=rwU583fT+8FjDxeFMkqqbETKMcNhMBz7aDvKxrHd3BKnOLXe7dzE9WjZtuHgk6dzbM LzJD9k9FeMA/vzAsMCzG1Sgwf5uL95qTUCoVXN0L8C21DRC8cHeaHUKmd7iQWU8nLpi7 hipQcugCUWiZBX9a86alfTsUfM9r9hA+NxA7L22uzKDYvBjRed4usrtSFu1ZbttYbXxU Jmx/Xzvc4UmvWXHW+6dGquWv6aHaPNEc3kAMPL5clBQ15PdStFxdHWdzHeVQ1jnOYD3w W59XMCFYZBaQ5rCjyCLCLgbz9B/VER/zyHgtN1/sUwsKZIftnnuiABe9aHacnVez2l5A smYg== X-Forwarded-Encrypted: i=1; AJvYcCXgAG4tSq/JEIY20pmV1hsuf6vIkdLlQ6IgYdpkqImXjmBRrgFGmoyguNIoo3G+1n5NdENn1POTURqKJfQ=@vger.kernel.org X-Gm-Message-State: AOJu0YwM+q5R/jQyaBWti0NVW1nb/P342CtH2IDMU8V3JSAloSgY8inh 5gJE/WXw0sYfbFX4ZaVRRVODrDe1QAJr/cXbErXb84h4nx6tWxzlzrbDZzMBPwApd9lGSSAAbdv XpFA/6mKnrQ== X-Google-Smtp-Source: AGHT+IGAwnQyRjSgbgapVtoxeh23DljPd0BCoh547jG6xOR+St+CLwjz42P/Xrk5blh9oBXNXXcTwhqXrctn X-Received: from pjbcz16.prod.google.com ([2002:a17:90a:d450:b0:313:2ad9:17ec]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:5347:b0:311:e8cc:4255 with SMTP id 98e67ed59e1d1-318c930f93amr6304809a91.31.1751069409879; Fri, 27 Jun 2025 17:10:09 -0700 (PDT) Date: Fri, 27 Jun 2025 17:09:29 -0700 In-Reply-To: <20250628000929.230406-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: <20250628000929.230406-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Message-ID: <20250628000929.230406-16-irogers@google.com> Subject: [PATCH v4 15/15] perf ilist: Add new python ilist command 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 , John Garry , "Masami Hiramatsu (Google)" , Howard Chu , Weilin Wang , Thomas Richter , Andi Kleen , Tiezhu Yang , Gautam Menghani , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The perf ilist command is a textual app [1] similar to perf list. In the top-left pane a tree of PMUs is displayed. Selecting a PMU expands the events within it. Selecting an event displays the `perf list` style event information in the top-right pane. When an event is selected it is opened and the counters on each CPU the event is for are periodically read. The bottom of the screen contains a scrollable set of sparklines showing the events in total and on each CPU. Scrolling below the sparklines shows the same data as raw counts. The sparklines are small graphs where the height of the bar is in relation to maximum of the other counts in the graph. By default the counts are read with an interval of 0.1 seconds (10 times per second). A -I/--interval command line option allows the interval to be changed. The oldest read counts are dropped when the counts fill the line causing the sparkline to move from right to left. A search box can be pulled up with the 's' key. 'n' and 'p' iterate through the search results. As some PMUs have hundreds of events a 'c' key will collapse the events in the current PMU to make navigating the PMUs easier. [1] https://textual.textualize.io/ Signed-off-by: Ian Rogers --- tools/perf/python/ilist.py | 376 +++++++++++++++++++++++++++++++++++++ 1 file changed, 376 insertions(+) create mode 100755 tools/perf/python/ilist.py diff --git a/tools/perf/python/ilist.py b/tools/perf/python/ilist.py new file mode 100755 index 000000000000..b986447f8831 --- /dev/null +++ b/tools/perf/python/ilist.py @@ -0,0 +1,376 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) +"""Interactive perf list.""" + +import argparse +from typing import Any, Dict, Tuple +import perf +from textual import on +from textual.app import App, ComposeResult +from textual.binding import Binding +from textual.containers import Horizontal, HorizontalGroup, Vertical, Vert= icalScroll +from textual.command import SearchIcon +from textual.screen import ModalScreen +from textual.widgets import Button, Footer, Header, Input, Label, Sparklin= e, Static, Tree +from textual.widgets.tree import TreeNode + +class ErrorScreen(ModalScreen[bool]): + """Pop up dialog for errors.""" + + CSS=3D""" + ErrorScreen { + align: center middle; + } + """ + def __init__(self, error: str): + self.error =3D error + super().__init__() + + def compose(self) -> ComposeResult: + yield Button(f"Error: {self.error}", variant=3D"primary", id=3D"er= ror") + + def on_button_pressed(self, event: Button.Pressed) -> None: + self.dismiss(True) + + +class SearchScreen(ModalScreen[str]): + """Pop up dialog for search.""" + + CSS=3D""" + SearchScreen Horizontal { + align: center middle; + margin-top: 1; + } + SearchScreen Input { + width: 1fr; + } + """ + def compose(self) -> ComposeResult: + yield Horizontal(SearchIcon(), Input(placeholder=3D"Event name")) + + def on_input_submitted(self, event: Input.Submitted) -> None: + """Handle the user pressing Enter in the input field.""" + self.dismiss(event.value) + + +class Counter(HorizontalGroup): + """Two labels for a CPU and its counter value.""" + + CSS=3D""" + Label { + gutter: 1; + } + """ + + def __init__(self, cpu: int) -> None: + self.cpu =3D cpu + super().__init__() + + def compose(self) -> ComposeResult: + label =3D f"cpu{self.cpu}" if self.cpu >=3D 0 else "total" + yield Label(label + " ") + yield Label("0", id=3Df"counter_{label}") + + +class CounterSparkline(HorizontalGroup): + """A Sparkline for a performance counter.""" + + def __init__(self, cpu: int) -> None: + self.cpu =3D cpu + super().__init__() + + def compose(self) -> ComposeResult: + label =3D f"cpu{self.cpu}" if self.cpu >=3D 0 else "total" + yield Label(label) + yield Sparkline([], summary_function=3Dmax, id=3Df"sparkline_{labe= l}") + + +class IListApp(App): + TITLE =3D "Interactive Perf List" + + BINDINGS =3D [ + Binding(key=3D"s", action=3D"search", description=3D"Search", + tooltip=3D"Search events and PMUs"), + Binding(key=3D"n", action=3D"next", description=3D"Next", + tooltip=3D"Next search result or item"), + Binding(key=3D"p", action=3D"prev", description=3D"Previous", + tooltip=3D"Previous search result or item"), + Binding(key=3D"q", action=3D"quit", description=3D"Quit the app"), + Binding(key=3D"c", action=3D"collapse", description=3D"Collapse", + tooltip=3D"Collapse the current PMU"), + ] + + # Make the 'total' sparkline a different color. + CSS =3D """ + #sparkline_total > .sparkline--min-color { + color: $accent; + } + #sparkline_total > .sparkline--max-color { + color: $accent 30%; + } + """ + + + def __init__(self, interval: float) -> None: + self.interval =3D interval + self.evlist =3D None + self.search_results: list[TreeNode[str]] =3D [] + self.cur_search_result: TreeNode[str] | None =3D None + super().__init__() + + + + def expand_and_select(self, node: TreeNode[Any]) -> None: + """Expand select a node in the tree.""" + if node.parent: + node.parent.expand() + if node.parent.parent: + node.parent.parent.expand() + node.expand() + node.tree.select_node(node) + node.tree.scroll_to_node(node) + + + def set_searched_tree_node(self, previous: bool) -> None: + """Set the cur_search_result node to either the next or previous."= "" + l =3D len(self.search_results) + + if l < 1: + tree: Tree[str] =3D self.query_one("#pmus", Tree) + if previous: + tree.action_cursor_up() + else: + tree.action_cursor_down() + return + + if self.cur_search_result: + idx =3D self.search_results.index(self.cur_search_result) + if previous: + idx =3D idx - 1 if idx > 0 else l - 1 + else: + idx =3D idx + 1 if idx < l - 1 else 0 + else: + idx =3D l - 1 if previous else 0 + + node =3D self.search_results[idx] + if node =3D=3D self.cur_search_result: + return + + self.cur_search_result =3D node + self.expand_and_select(node) + + def action_search(self) -> None: + """Search was chosen.""" + def set_initial_focus(event: str | None) -> None: + """Sets the focus after the SearchScreen is dismissed.""" + if not event: + return + + event =3D event.lower() + self.query_one("#active_search", Label) \ + .update(f'Searching for events matching "{event}"') + tree: Tree[str] =3D self.query_one("#pmus", Tree) + def find_search_results(event: str, node: TreeNode[str], \ + cursor_seen: bool =3D False, \ + match_after_cursor: TreeNode[str] | No= ne =3D None) \ + -> Tuple[bool, TreeNode[str] | None]: + """Find nodes that match the search remembering the one af= ter the cursor.""" + if not cursor_seen and node =3D=3D tree.cursor_node: + cursor_seen =3D True + if node.data and event in node.data: + if cursor_seen and not match_after_cursor: + match_after_cursor =3D node + self.search_results.append(node) + + if node.children: + for child in node.children: + (cursor_seen, match_after_cursor) =3D \ + find_search_results(event, child, cursor_seen,= match_after_cursor) + return (cursor_seen, match_after_cursor) + + self.search_results.clear() + (_ , self.cur_search_result) =3D find_search_results(event, tr= ee.root) + if len(self.search_results) < 1: + self.push_screen(ErrorScreen(f"Failed to find pmu/event {e= vent}")) + elif self.cur_search_result: + self.expand_and_select(self.cur_search_result) + else: + self.set_searched_tree_node(previous=3DFalse) + + self.push_screen(SearchScreen(), set_initial_focus) + + + def action_next(self) -> None: + """Next was chosen.""" + self.set_searched_tree_node(previous=3DFalse) + + + def action_prev(self) -> None: + """Previous was chosen.""" + self.set_searched_tree_node(previous=3DTrue) + + + def action_collapse(self) -> None: + """Collapse the potentially large number of events under a PMU.""" + tree: Tree[str] =3D self.query_one("#pmus", Tree) + node =3D tree.cursor_node + if node and node.parent and node.parent.parent: + node.parent.collapse_all() + node.tree.scroll_to_node(node.parent) + + + def update_counts(self) -> None: + """Called every interval to update counts.""" + if not self.evlist: + return + + def update_count(cpu: int, count: int): + # Update the raw count display. + counter: Label =3D self.query(f"#counter_cpu{cpu}" if cpu >=3D= 0 else "#counter_total") + if not counter: + return + counter =3D counter.first(Label) + counter.update(str(count)) + + # Update the sparkline. + line: Sparkline =3D self.query(f"#sparkline_cpu{cpu}" if cpu >= =3D 0 else "#sparkline_total") + if not line: + return + line =3D line.first(Sparkline) + # If there are more events than the width, remove the front ev= ent. + if len(line.data) > line.size.width: + line.data.pop(0) + line.data.append(count) + line.mutate_reactive(Sparkline.data) + + # Update the total and each CPU counts, assume there's just 1 evse= l. + total =3D 0 + self.evlist.disable() + for evsel in self.evlist: + for cpu in evsel.cpus(): + aggr =3D 0 + for thread in evsel.threads(): + counts =3D evsel.read(cpu, thread) + aggr +=3D counts.val + update_count(cpu, aggr) + total +=3D aggr + update_count(-1, total) + self.evlist.enable() + + + def on_mount(self) -> None: + """When App starts set up periodic event updating.""" + self.update_counts() + self.set_interval(self.interval, self.update_counts) + + + def set_pmu_and_event(self, pmu: str, event: str) -> None: + """Updates the event/description and starts the counters.""" + # Remove previous event information. + if self.evlist: + self.evlist.disable() + self.evlist.close() + lines =3D self.query(CounterSparkline) + for line in lines: + line.remove() + lines =3D self.query(Counter) + for line in lines: + line.remove() + + def pmu_event_description(pmu: str, event: str) -> str: + """Find and format event description for {pmu}/{event}/.""" + def get_info(info: Dict[str, str], key: str): + return (info[key] + "\n") if key in info else "" + + for p in perf.pmus(): + if p.name() !=3D pmu: + continue + for info in p.events(): + if "name" not in info or info["name"] !=3D event: + continue + + desc =3D get_info(info, "topic") + desc +=3D get_info(info, "event_type_desc") + desc +=3D get_info(info, "desc") + desc +=3D get_info(info, "long_desc") + desc +=3D get_info(info, "encoding_desc") + return desc + return "description" + + # Parse event, update event text and description. + full_name =3D event if event.startswith(pmu) or ':' in event else = f"{pmu}/{event}/" + self.query_one("#event_name", Label).update(full_name) + self.query_one("#event_description", Static).update(pmu_event_desc= ription(pmu, event)) + + # Open the event. + try: + self.evlist =3D perf.parse_events(full_name) + if self.evlist: + self.evlist.open() + self.evlist.enable() + except: + self.evlist =3D None + + if not self.evlist: + self.push_screen(ErrorScreen(f"Failed to open {full_name}")) + return + + # Add spark lines for all the CPUs. Note, must be done after + # open so that the evlist CPUs have been computed by propagate + # maps. + lines =3D self.query_one("#lines") + line =3D CounterSparkline(cpu=3D-1) + lines.mount(line) + for cpu in self.evlist.all_cpus(): + line =3D CounterSparkline(cpu) + lines.mount(line) + line =3D Counter(cpu=3D-1) + lines.mount(line) + for cpu in self.evlist.all_cpus(): + line =3D Counter(cpu) + lines.mount(line) + + + def compose(self) -> ComposeResult: + """Draws the app.""" + def pmu_event_tree() -> Tree: + """Create tree of PMUs with events under.""" + tree: Tree[str] =3D Tree("PMUs", id=3D"pmus") + tree.root.expand() + for pmu in perf.pmus(): + pmu_name =3D pmu.name().lower() + pmu_node =3D tree.root.add(pmu_name, data=3Dpmu_name) + for event in sorted(pmu.events(), key=3Dlambda x: x["name"= ]): + if "name" in event: + e =3D event["name"].lower() + if "alias" in event: + pmu_node.add_leaf(f'{e} ({event["alias"]})', d= ata=3De) + else: + pmu_node.add_leaf(e, data=3De) + return tree + + yield Header(id=3D"header") + yield Horizontal(Vertical(pmu_event_tree(), id=3D"events"), + Vertical(Label("event name", id=3D"event_name"), + Static("description", markup=3DFalse, id= =3D"event_description"), + Label(id=3D"active_search") + )) + yield VerticalScroll(id=3D"lines") + yield Footer(id=3D"footer") + + + @on(Tree.NodeSelected) + def on_tree_node_selected(self, event: Tree.NodeSelected[str]) -> None: + """Called when a tree node is selected, selecting the event.""" + if event.node.parent and event.node.parent.parent: + assert event.node.parent.data is not None + assert event.node.data is not None + self.set_pmu_and_event(event.node.parent.data, event.node.data) + + +if __name__ =3D=3D "__main__": + ap =3D argparse.ArgumentParser() + ap.add_argument('-I', '--interval', help=3D"Counter update interval in= seconds", default=3D0.1) + args =3D ap.parse_args() + app =3D IListApp(float(args.interval)) + app.run() --=20 2.50.0.727.gbf7dc18ff4-goog