From nobody Fri Oct 10 02:41:51 2025 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3AEEC1C1F2F for ; Mon, 16 Jun 2025 05:15:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750050930; cv=none; b=pTAMMB5FsbmOJoQ9nVWQL9SzdljmZG74ezkmLXj2YkEk7XU2HZDWT7h10qnCTFC04wu/w183ImazOYJKzwiIqB4P4Cf9uAQArX6i9iYhthxnSTasvrFBtlWzocYKmU7S/kEdIAErFotrKmrEx2i5hpsUiQQZ5ercQWmG1pdvJqs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750050930; c=relaxed/simple; bh=t/FRxYTG+D54BYUz0KeUNeKNi7Xmml5aAZJln458g4I=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=H1wbFj4d9jFMlTKQCPq82nGXFs/EVILMC4h35fU3Lj99vvo69BwO+d7zOAehLGWhr4T6cHRqVa/lZQynbaHKRhEwGuLIi1zw5MNW9Wid0kYm647w2KQA+SdBla9oYXbGDTY8BqQtjVh8rWUs0B7YRkcIkDFHDTnGLF/nHWXRWn8= 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=0qDcivQb; arc=none smtp.client-ip=209.85.216.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="0qDcivQb" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-31332dc2b59so3583470a91.0 for ; Sun, 15 Jun 2025 22:15:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1750050928; x=1750655728; 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=j/FsflWYTCgAT92JI9ObGbeoiqi07FQ5gkzYOBlamRE=; b=0qDcivQb+0eab7hVfdscWlq97nlwuT/QpHRjjXYIUMUSTN6DgkboDAPGqsUgbV3pgD niWcK/93L/+UGXMJhiNyznzG6e0Cte1PitezlFobfXeFHZMCCAUUds618qpChNp1xVFN Ddju8dzd0yfcTIPoOcrjvaCvc8vzvWfZxc4sspigPJmK2Tl1F6xPb7jWC4/iqDv+4Ibr tVjc7dLoWHAaBq3QGPuqi8sM7ShqM1YosF6sFUikbJRqjQzcE9MtZoTszVxvWJJrOyzl xQ65QxtY+LzfQO9yaHZeNxLPuvG/DXFFhcLsBHZovwLteXM55Pww3KyFstxP7A94jeJW zJwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750050928; x=1750655728; 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=j/FsflWYTCgAT92JI9ObGbeoiqi07FQ5gkzYOBlamRE=; b=k98jTBQxrG3eoq8P9GRcxi80K/Jvqb6lFYMo0wAKYQyDL0DQx7NGjoJkyGk5WfcvlN +n9iTGQhMjtQu3JHHKk3YdpSDIXj0wVI94Kuj1tl4v7LVwB2b3zyPD60yhokSXffU2SC BIbJ5+rSgxZI603Gtnj7ZDe2VF3NfKIjLjEdS1ysY8zEsoAhZojnEqTOJfvzJJ51LgXM l8hUgo5jI8QtrW/PmHBE4jboEVwNMp8sohpqawrk2LQDWsTBQCCbRJBUueuTCS8REW0r j4MEnYxB0LVAdDjopKviWf7NmQgaywUs86ItFt62CHbiHWf0sOphgMLqbipemlBc2IaP wpfg== X-Forwarded-Encrypted: i=1; AJvYcCUKK4b0RyPYGoLU3BfALFUyrv32G232u3lpZ3nzveNOxPSZgd36MjMpnKoT6DdFAs7fTJMSM8uAJec5X8U=@vger.kernel.org X-Gm-Message-State: AOJu0YzOXcrMPoWnk/hI6N8PY3EWZrqwUvCnQkUdfAGK/MxH0pat/3Z2 Efpe4Px6oCYX0w++PZqm0+4oNUs3HoCiS2bMLEGG3r11Djn1sRyeutSfcB5tAlE4MBPgaPhumo4 dgBNHFwIM3w== X-Google-Smtp-Source: AGHT+IEgHMJj4LWgi+OvKWFekCaf1ai+6sfMoZu7Eri7YtGVBDQExF7fJeRMENT/jO8QAfgNdpvjMlYg7nwg X-Received: from pjbqo16.prod.google.com ([2002:a17:90b:3dd0:b0:312:ea08:fa64]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90a:da90:b0:312:daf3:bac9 with SMTP id 98e67ed59e1d1-313f1d07b65mr10747037a91.34.1750050928324; Sun, 15 Jun 2025 22:15:28 -0700 (PDT) Date: Sun, 15 Jun 2025 22:14:46 -0700 In-Reply-To: <20250616051500.1047173-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: <20250616051500.1047173-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.rc2.696.g1fc2a0284f-goog Message-ID: <20250616051500.1047173-2-irogers@google.com> Subject: [PATCH v3 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.rc2.696.g1fc2a0284f-goog From nobody Fri Oct 10 02:41:51 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 632AD1D63F8 for ; Mon, 16 Jun 2025 05:15:31 +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=1750050932; cv=none; b=dlfQ5fm2YPE6EgeVPM8ZOoauobz3B3qJOOaXqhxYmPPOYOfmkgiMyzihoxmufSlqeMXzfVP+AxplxIYWf99hUDHEClyDgrJuHw/2xRYg1ZD+IEx0SEf5P2902UeAazeDcpBmplPmGXCormxDD22oTG1Nrpk4ycCrxaMNTydDscY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750050932; c=relaxed/simple; bh=+rzqLnUZ9aKJHwPLS6rKWr6+5uLxahK86bnCKy+9kCU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=QRKFsq0rkUPo+yBBxGn/Xy3ABV4DPFU7wpvqOIOyDwZHqJUEohaIzn6KuXIjDldgEsTRtHxyBowRccFVVA0+2Rlwk5kRs5ogBErzzUMCKHhxr7BkCnBjzc5pci3tBMiBRDGMYg8msWzRvmh3ul1nKDd1/25yQV8wkuSQNOJYr7M= 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=vTHwa3sW; 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="vTHwa3sW" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-747ddba7c90so3418872b3a.0 for ; Sun, 15 Jun 2025 22:15:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1750050930; x=1750655730; 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=9cHBz9Jxgvdqu2C+765Nd/C5I0sI5XdrVknxJ/DmjSo=; b=vTHwa3sWOrisW1w0E0au4E4n2Vh2ejWi+rfOCUssgmcU1YqxCa4UETyB6oj7vXdNJg 2cTsMUrX8AVveAF7H9sdCvK0u+wagpg3mRtN18xl9isBwd5J6NC9tc2ufwaUT885ua3o bQMpKXqId6rAxsw0bvLG/mniHQbrvtYr2TnrtCaJzM7ybhxy857xTGCx5yPuQjsZghPN uNPOES8pzYVBZ4u9K9VUIsOQnV/ajMe+pZhUebocw5aMGh0wtDX8vD7J1LeYZ6hokP+i qUGZtSF/gk2lA8l1WbqctRyghSYSKBwpIFLguVvJoX6xicT/pr2LmamTe4c3pRZtAMeo rSAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750050930; x=1750655730; 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=9cHBz9Jxgvdqu2C+765Nd/C5I0sI5XdrVknxJ/DmjSo=; b=qwL7lfVOdT6Oqk5G+AVoZJsFV1z1zuxBqojno6XEQJj9LPo0C1XXNW0npZLW3GVhuD BlvMOmU4h4q6M94c23eY+AZ/m9VDOc/Jgg331gxY5+/5gSFZ+/DmvB+MqiezfOCBQ81I 9tD0Bacf+zxJTJmVjqz4zI2YreRiffwAzwPlDBa99LkzHBvY7U5Pn0ZRkAwROFaCOoUD u7p1Dn5vez7t1V1LTFHM4DBEXEEg8Mpis6/waJzgbauoy37fS0IrZrSqwzTp01EQPBoE oM+9zjdRdqCA3ncO8UKut5BisZEifTiFpRGar2GTi2daDA4Id3xAruEWTtxobOrjswAs fpDw== X-Forwarded-Encrypted: i=1; AJvYcCW/Q9qGrnBNaUydh1omcY0mz8IHIT7bGPEtfr3xliCk7dp29AAUZhAqDHOvhmRtGSoFINkPu2sFTVnuU3Y=@vger.kernel.org X-Gm-Message-State: AOJu0YwmWEZ502SUw+2kAm2YuWGv9fAwuw+1qjJDkph99Yl3i45nggMh PJhrjlt4Lmi32eEXiquTMMV695Fqu1cGLEAXBhXHLdZXg6hdXWb7VFyBkgikEBekX0AhkGpJBum 28cHG4P2vFw== X-Google-Smtp-Source: AGHT+IGsqLtLqfPivL8Z6UmUsOUy9pRSswLZ1JX/hHTzfJz7520mL2IlDRISK5F4XF1mIBfRUHSHqsf0SGe1 X-Received: from pgbdh21.prod.google.com ([2002:a05:6a02:b95:b0:b2e:b370:6975]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:6186:b0:1f3:418d:91b5 with SMTP id adf61e73a8af0-21fbd55a331mr12605812637.24.1750050930485; Sun, 15 Jun 2025 22:15:30 -0700 (PDT) Date: Sun, 15 Jun 2025 22:14:47 -0700 In-Reply-To: <20250616051500.1047173-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: <20250616051500.1047173-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.rc2.696.g1fc2a0284f-goog Message-ID: <20250616051500.1047173-3-irogers@google.com> Subject: [PATCH v3 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 7f34e602fc08..9dd0216cfae4 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.rc2.696.g1fc2a0284f-goog From nobody Fri Oct 10 02:41:51 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 42E971DDC0F for ; Mon, 16 Jun 2025 05:15:33 +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=1750050934; cv=none; b=cDsOrc7PWTH9si0efwpkY5uw56YUHlCHz9tL1xZnhIMu8Sjk7vP/EE/a1vHVwsfplWhaZ9sEEHPPy4FR0OUFdQKNinytE2oZP4wb2OMP7GYkLRLOpL4knkxNfJ9KP+PjmynkooK/5kk+ZbbDB/uBgcFlZHLbUcEXMM5ZE6f6Gr0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750050934; c=relaxed/simple; bh=SsXRDJHGxhBiVFvbMp5Va3kQ1XX9V2ptMIP6IAJfjik=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=qhEJRwl579IktNVTxM2F4xZrU+yF7Bi8bT90JhzSate3MM+BIZ26GNuZJ68rjI87Eem/565B1JSWyNI0DEYuvZTLAvT6FpLrtqeXvjr5DtNxxbgSjCxGwls0N5lqn2livgsDHO9JNVOM7qKcgFSlioBXmiiBUoSvt+XVEw054dk= 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=ez3U4JEw; 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="ez3U4JEw" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-234aceaf591so30452455ad.1 for ; Sun, 15 Jun 2025 22:15:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1750050932; x=1750655732; 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=YKPUrJSvkU3DHLcEcQ+79yvgqlWdK0rvwPvnQ7AV5Oc=; b=ez3U4JEwP6XDacPl3pw3k5xOwLXxb/CZT+cYmSAo/rO/TPl/WjKazeaLvibf8NiaAQ eMVfmuTldSGcWxuF4unKq9BQzz2gSeezCxw7aSxkYVkltJIt1r1YQRa4jV6UjLT2fpno WcqwdaTpe4gSYMLFPKKgegZRSGeljqTyHltVHuMTMOdvxlsBmFlgLbGGx1K92W2u/NUE b1IFvDU9fCybCI5MUXc/K5o68HSgTll89n9sexCMBF9h4lW8gYlCyiWJH1/r8RmvocBZ yR3n6eXVqbgcZNQ0gh1C0j2I0st7TwoUeqMZzHg81vp5y3ul51d7dv0CsxUgkO+sZMK0 X3JA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750050932; x=1750655732; 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=YKPUrJSvkU3DHLcEcQ+79yvgqlWdK0rvwPvnQ7AV5Oc=; b=KTcgoyTghZi8Kb1k4zC11hEXuKNvEdUv3toQFVEAo7ePrUFQjXQKNIdSxxB351cCsV tDhpqa2zVNDH7vRVtOIgZ31UxnFc6cTvz9FA0UnE2PkcLDxjtJ14FOUIJ0wp/3qE/V3D ab1ytCX7Q/76So1+IzAphHzE4yd0kJj+CorLr7MgiCc9i1gYTTKreuBhL2JxmXX4Xdzd hkXWVmCy/kdfQGlifmdtc1/UlVU0pzBj8YK/gfOWQxjEdKkzDJQf36mJJrEwC3zoMrfM 8/zqhWF3eD6QuCJHkImBsArFlaKvKlgx5/hlkU69gSj+UbBgz4Dj1BuiXoYnodo4wm/O WfCw== X-Forwarded-Encrypted: i=1; AJvYcCVlmzOZ1G+euH8dqPckfQvbHzuHAAxnqdQ4/ldRcc5VbjNrRU3eW4P3mwUcxy8u0c1YXe0+peU/9K4dohs=@vger.kernel.org X-Gm-Message-State: AOJu0Yw4Zb0DyA58Oa5oVqLJjus9NRSFX1bY1Pgy8+neXHQcj/loW10g pDeAO864fIfW2KOUEYKX+l34wCVPS3jU47Z364TP+rDhRIayM1DN4jmtmlKzXNU23I4PRNINC8t U2loXTGp+0A== X-Google-Smtp-Source: AGHT+IH0O2STUfLj/UIOx0adavcx35iiADUlahiPG/Xf/979SkMc7TFDRmdyv9KtZZr+1FEkeToo93gA14P8 X-Received: from plzw5.prod.google.com ([2002:a17:902:9045:b0:235:6d5:688b]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:3c66:b0:235:f45f:ed41 with SMTP id d9443c01a7336-2366b32ce9dmr119423765ad.19.1750050932608; Sun, 15 Jun 2025 22:15:32 -0700 (PDT) Date: Sun, 15 Jun 2025 22:14:48 -0700 In-Reply-To: <20250616051500.1047173-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: <20250616051500.1047173-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.rc2.696.g1fc2a0284f-goog Message-ID: <20250616051500.1047173-4-irogers@google.com> Subject: [PATCH v3 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.rc2.696.g1fc2a0284f-goog From nobody Fri Oct 10 02:41:51 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 50EB41BE238 for ; Mon, 16 Jun 2025 05:15:35 +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=1750050936; cv=none; b=pqLBekxjE74jED7G3Ka+ewF6IYVykkDNKFaSoZuCaYF7epAWFnAA+jEDCT4gpWQWH5JLtCa0X69sUXIOe62uLKDXz0ZnOOicCoIvDEL369bghCADRM8LvQFl3Q2nKwfLC+6lLh2WDV/J2+U7ah2JQNdwmPqHAOBZV9cc2Z5Ymco= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750050936; c=relaxed/simple; bh=7wfzPfloqPFtdu8appty5yDqvoo3d+FnbjSk3uLpwNw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=A9RMF8vrxaYSUoehtiVh24Eai67Fai6BaJFXPJV0vDtBSo5kHO/SiFnr8aAvGNVnbjBOFn4ZN8LV+A3NRKbWK7dP5ak47kv10obV69Xe+BCbDM6LsD2JRDUketZcEo70mhJNGQMJinPCePIMobfHIev3lf72sFjbt4GbyIP2auA= 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=yXrcD+b6; 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="yXrcD+b6" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-742c03c0272so4988657b3a.1 for ; Sun, 15 Jun 2025 22:15:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1750050935; x=1750655735; 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=ZhNmVeczvFZi2XQh4klX/GK/kqpwRZijs1pAh8xoIM0=; b=yXrcD+b6r+L/oNpAqMIQ5KTbzAaWu8D4vsqRpRQf1NmTbbl5K+LdP9SRKJwxNysa+E E3F41oyf1r+3UqY964XxX+9FYHR2bZQVtjnQjJMDnX2GBpwDwk9VteI+DvmzpA6QIGT3 qfBvVaevcJ/aWOYffKYFMwdhCeHQcupV57GLcM8L8QqWEhqBK6p2hh6GnGqGUdb/KVqR YEOs4sD8C2Q+a0YmDqnJYmIoE0Yh9PFcP/62gcIrgOief2tthWt0PHHkWRq35qIAhdki JOBRwLq7nwzfTLM9Zhx6nnHk7/zkgY25T2M7rjflXrwsG4XLkkCDiyFhJaqY5qbhxojc lBgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750050935; x=1750655735; 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=ZhNmVeczvFZi2XQh4klX/GK/kqpwRZijs1pAh8xoIM0=; b=hd8j0VYdJx2K2ZB5hAM24sIm8q74T2U+XiLcrgs3S5Z6CO03Bx1ZSJOnjTnqQu27Fp EPS9fA49TOPBxT0oY3IIzbuCeADQ1wD6h/kGruSYXYiAAd3CmHOrbyeSrQUz/OTnGe9V 734pjyDTfz5qO911fLYoqyd/ynHbYOFvip5ZXAdHngVAeffBzz93BE7ggi0NK8EEcN2F lL0ACjGKSc14AAcWceUcKhSH+Tw8rXqqIPXF5gXXVyiqw6KwcCdI/jnTXbXSNx7CVo8p OV+lyucBm1pKptJARAePtGNxq49cGpo2/Z1QSA+GnW7dLy5pQtKYIpaOn64D1O+/ZjM2 8Njg== X-Forwarded-Encrypted: i=1; AJvYcCXoTEbXJhEiNi1PTQI5bGN4O66/9OrIIF/syjieT9c691BbA3SS/neAQ/r4Ajo1/tfgTHFRWSBz1VhAC14=@vger.kernel.org X-Gm-Message-State: AOJu0Yz0gnr4rRU++W4+vX0IZytNK7wggfDMSsu/zPSU19zOuOGfzI3H FYK3WoSv7QtE+CfW8Y7pDj+H3H/I/8aCIDqozmOzxpJctBGvF+tB+/B83tHsbSFcHaNLMma++f4 zXASyw6sK0Q== X-Google-Smtp-Source: AGHT+IH9k5VTNRbgPa2VljKzH6sK8cPg3DFKfBqECGQifwLWqC6iC7aOAmiRVZnwKongPp6lSNxKHZzhIvmP X-Received: from pfbho10.prod.google.com ([2002:a05:6a00:880a:b0:746:2897:67e3]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:3e10:b0:72d:9cbc:730d with SMTP id d2e1a72fcca58-7489cffbf39mr10049316b3a.11.1750050934692; Sun, 15 Jun 2025 22:15:34 -0700 (PDT) Date: Sun, 15 Jun 2025 22:14:49 -0700 In-Reply-To: <20250616051500.1047173-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: <20250616051500.1047173-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.rc2.696.g1fc2a0284f-goog Message-ID: <20250616051500.1047173-5-irogers@google.com> Subject: [PATCH v3 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.rc2.696.g1fc2a0284f-goog From nobody Fri Oct 10 02:41:51 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 0E2671E32C6 for ; Mon, 16 Jun 2025 05:15:36 +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=1750050940; cv=none; b=IghQkDh2JfGGvM1k/eUT5uZPYEjLzPrD2qIckBA3O4hz9LREOg55vpLlj+9yWGUt7K+x2WEX75anuBWgT8KXOTcHn9Bqo+SaYIDBQ6RHgaPADG/AAtX/POnrsL2dJYDT+hERWjoS2F3UuHuLgWeEqSGNSIBp4xuAyOHZEcoovy8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750050940; c=relaxed/simple; bh=yKpHM+BCHbeFrpnY+3JEnhGTh0ytgZYNLTTi4rBzWCk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=uq6wvhC82ykIyT/JrVlM6KanGmcUi2SfQB43G/SfUXcq+reekF94WfmNnMZElJKqLRkklBEQatm0Jz1XbH9U2pGAor7n0X/hPgiEEl8VfvBqZ4i81L8y3zWCYnI3/xfLp0UKA7G4badVphbBsB9NKBWGZfx7I9XVLBhTMFdU+J8= 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=y9OgqlqL; 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="y9OgqlqL" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-b115fb801bcso4542383a12.3 for ; Sun, 15 Jun 2025 22:15:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1750050936; x=1750655736; 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=aJlPf9F5g9Wk9gssd6aqu3WR8vZd4WrO7zxv/Qci614=; b=y9OgqlqLJx15qy2BQk7a/RMjyK3cL6qeZN1RUdITvCEGEpFViARjLXh37RdZOetHpH yvoDp1joMvo1WGi1muYCmUzZXmkO//rYmUbDrg1ygPr/sQlUBhymegl0tZPkn7qnxKjS Q1sqEJFbXFtukOpY1PvRQltEoiGGBtzDbvcm4tkHRhIw5zOjxWtlFwU6/n1HTGp84akF VZFOnaQfC3n2qg33js6/zEKhWH1ojKtyyC7qAys8JU+oVxGDGCoh2O87VP0M7tXTbd6A Ixzt+4Cs+i4DJqLtaYvM66JPExsQPEF3ttpWt5LF9MZqTqQ6tCMtxqLOiCZfWd1LF6bt qKVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750050936; x=1750655736; 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=aJlPf9F5g9Wk9gssd6aqu3WR8vZd4WrO7zxv/Qci614=; b=vDIUbOkqIffSm2yRUnXlsRUJhLCTd4flcrPTTNPKP1UvnmYuBP8eyfngGciUKkDu+q Cn9GoxNXU0hXLq1X3NJPHJXebaQzqZIa4AGiU+F+12RD+xUH8tgufZHMdZgmrFbSwDNH CGWlRPaO2+lDUnQj4HUWmMJ+VSaGsmU7K0Dtmy1aoCDUZSLCsMnO7lRrXWafLzBcSeT8 LuxM2bCCAg9/t3p66lUYHUHm7Px9pYZPwyDIADGTQi48hGUTJVnOpfrVM4NGjOEkNu3I qqXDJl7q52il1a3v1CyMI1RsxnyxNrBQenkMvg9Y1ZNY56BGe1pdALID9Yac2AEwkmdQ Lmeg== X-Forwarded-Encrypted: i=1; AJvYcCVTp+xKJ6qr+rI93POfodrrRBQo18hGuEVKJ1QAXUxR/pizk7hKpALUh+P+rZcISz+lbl5uwXRuiKvBkEg=@vger.kernel.org X-Gm-Message-State: AOJu0YwCTg32bynW/TrG3Jj6SqBI/4vdCDIF2CX5K1NU4mM8RJhyia4b f8+J5nvRr3moFrc8PKbEmPYW6pObVkJ3/XUD5Xk6mB68HfftiIkU2l6N/IskGrnuEeJhXskhwhE AD5a+1abLBw== X-Google-Smtp-Source: AGHT+IG8/lpjRrXKSMUNfgQtOdF3/fPjhcRdKaaH7jugd3IevsUPJkeZLGKMaZeT5E8zo0HJDv/ht6QFjnmf X-Received: from pgbdi9.prod.google.com ([2002:a05:6a02:c09:b0:b2c:3afe:6ece]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:1443:b0:21d:939:18c with SMTP id adf61e73a8af0-21fbd4741e0mr11715398637.4.1750050936503; Sun, 15 Jun 2025 22:15:36 -0700 (PDT) Date: Sun, 15 Jun 2025 22:14:50 -0700 In-Reply-To: <20250616051500.1047173-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: <20250616051500.1047173-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.rc2.696.g1fc2a0284f-goog Message-ID: <20250616051500.1047173-6-irogers@google.com> Subject: [PATCH v3 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.rc2.696.g1fc2a0284f-goog From nobody Fri Oct 10 02:41:51 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 0DFE21E32C3 for ; Mon, 16 Jun 2025 05:15:38 +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=1750050940; cv=none; b=nR0+6FT0MMozGWZXKd5A+VwDgobbpFhYdeHunXAIpQ8znd+FBAMOfLF/uZJFiSuT5+iZ3sROLOditBmXxHb2+Tl0i2bYYsJxWSZymzXxNsFqEY8+jQEbyAbs04shvBky0T4LsEQxp+INjKMAde7tg0gCanXE4MgPWKIKSOvaUsk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750050940; c=relaxed/simple; bh=FDHXLU4J2D78n30kero/Zz2zkovLAiNRWMXuqyzrGCw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=nWDSZ4pghCqyUqMJRPDryOYvBsasMEms39GvqMp/E3R6ALBSHW5+HZWLrvFjt7HM5tjXEdiqTv/gHsaVXB+VUGhd2VJt9TK1c74blPNsRFuJbhlWs4PYx6UAL7ejWmjgJs+ZsmVnD99eOzfzA+22xKcoyN571AqazgUTOgnRsOw= 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=mkcTB7jE; 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="mkcTB7jE" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-235e1d66fa6so39341785ad.0 for ; Sun, 15 Jun 2025 22:15:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1750050938; x=1750655738; 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=sTKqdcYyHF9clcVtgl1QXOADzr9s/Gb9doCvReUrwZ4=; b=mkcTB7jE+SJuvZ0mTKmqpnoE1Iy64bu4kEq35lEUxKb2c4jaJjWf2y++isIR62H3bI +s14KXUyc/8/Ek3n0Cn2MxoqAnxz8DbkSTQRWerEjLxvBfFcKlaKNg4MJTFrZuUhafgB Cu9I+dhNk29hBuvWMLYpg4rr6YJQzpT2VGz14+j2C/NSDsW1opWkLAvYUEhEynpplJdw a349DyIadYdV1jYiz90lY+14udy6vVkbbigoMJmkx6wl4ms4DFh3A+akexdcYayQ5yfs jk5n4ZckHjYknY44gXMRYKBhfTKI6ieV+FrMyF0cRk1cuvKLyM3a+vYPapGZp+m8/4/1 BMIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750050938; x=1750655738; 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=sTKqdcYyHF9clcVtgl1QXOADzr9s/Gb9doCvReUrwZ4=; b=bwdKJi58ltnG4l1JRF+AR3/2j+7n9vLlD7szFZ5FOowInjK/aEa35go7d6Wsg1Lu0s hP9HDwReaYQpGP+0DgIh2Uy9ZRwCAhyrTYk4UaRy1K7aW8P6nrP1GLCZq8nyTLxmfr0t bWellgLO+3+sjhV7bjtNnv8M1hT1KJ/SDeOSrr9j8KQ0PMjtaFyusp8IwaFbOkzXSQZ0 ZCJLCapbinjshNFxkEkQ9VbHY99GADvbGJH+7jFtRJGKlloDPYUfbEN3RAqJ1yUAdqx3 eIXGC4hiJd//VIx8FWR2AUQWRoVX2vdeXrv1o0CP7qtsuaKWFIqkOf7Cpq1wleEtO4yE Scrg== X-Forwarded-Encrypted: i=1; AJvYcCUQ8Ah6M0pIicj0oV/JVYBh2HnZHZVuVovQc7RsB4ilP5M1tmpylPVHtpZxjRoznivXs6+55U4BjVIh+3Y=@vger.kernel.org X-Gm-Message-State: AOJu0YwcUuDj0i5Tzr6Qd/JilHztmRcAeAH8NHY7G+6rhcscazO0Rm0e fDFCJX5ZT8U31ltW/GKVN7NPuWHW+WqUC6INhpYt9cMFCdersZUQTN+xy7ZQBubC3lG+XVzEjg9 t9W+7EWMYGA== X-Google-Smtp-Source: AGHT+IHAPYNAv465eOEq5YoSg/nkLLSoi5rsqXTEcUYGxPxVFq2qs/MG23h5xOFSmuKncDzY5lZ2sYPF0mxQ X-Received: from pgar5.prod.google.com ([2002:a05:6a02:2e85:b0:b2c:4702:db0e]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:f90:b0:225:abd2:5e4b with SMTP id d9443c01a7336-2366afe7c13mr124614375ad.16.1750050938284; Sun, 15 Jun 2025 22:15:38 -0700 (PDT) Date: Sun, 15 Jun 2025 22:14:51 -0700 In-Reply-To: <20250616051500.1047173-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: <20250616051500.1047173-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.rc2.696.g1fc2a0284f-goog Message-ID: <20250616051500.1047173-7-irogers@google.com> Subject: [PATCH v3 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.rc2.696.g1fc2a0284f-goog From nobody Fri Oct 10 02:41:51 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 C97891E47A3 for ; Mon, 16 Jun 2025 05:15:40 +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=1750050942; cv=none; b=AqWhtAxIKz46Yc/o1xbxobmoYRWTPe2ka13fvGv6cIuGijrdXtbO9ymvmrLB4IyyfrxhKlAqD3aTKg0B0n+d0nEH4F8/10KlWx4zImFQLmoWBUtS7hSWWhHvlpn571xwucY4cd2YRAmVf5+Ysp0wxktH5aWC5g++4QgdLYPL2XQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750050942; c=relaxed/simple; bh=zZY5QdAaatWoVBW7I7LQ11kD76DX+GBxtTOi8p7XfOs=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=iXoEhtIXyLPSXPnypwD/q0y0ExcMUESHzvBD2M0OZviWDyumjIKeY6h7BLnV8p60VZmoI6lUGR2xM4IedBHc0wCnIPFDRbojjMkfrPeBm1Z4vja7ODK+DrG7LhH9Kbmepyo0meu+bQQIuKEL4w5zB0/cWuXSFHGRZUAImGZPh4Q= 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=WGJMyN2k; 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="WGJMyN2k" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-b2eeff19115so5273962a12.0 for ; Sun, 15 Jun 2025 22:15:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1750050940; x=1750655740; 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=TPESPEzAQJj2q7drTkMDX/Th9kHricV7LFea55YSIjA=; b=WGJMyN2kAFztVPM0q8EEUB+VNz6M5wFwR65nz9skEk0KvUKFtDZtpLL2doUShTfkac cGELlrg7MwJslCX2kU16P8YkqGzWy3TJUNCISIY4J/oZy8sST+7+B76nDhKiMsKtDKFE eMY3qMM/BZhMkI45cIiwWVXcdTMhPYQ3dz4joCm1JChY7qkmGg3vjRVEEJmcJQn7XG1N DdzEZQF66uN1XEXcvCcA4wbBDGBIi8TE1M/5Nxk94WrEKzoJFzjdmJtf41fO51DTZpbD /TINIdPTuYMbfBtCQtpgJZhL64bHTwGOlR1vuoS6Xm8dkXZfL3nlqOYggVvzcQfAO9nS PgYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750050940; x=1750655740; 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=TPESPEzAQJj2q7drTkMDX/Th9kHricV7LFea55YSIjA=; b=RVT78v+nmyYTYwq9BorXskGJT+uegSCUkpX5BUT6GLvY2HLj6LWGq6ojAC1b9goPGD jthafv7nXfHurc5bHIsZxslZukMe6F8TYJiXRW2RwqyD7mHH+gwHkLeBnobF7iXRWFve QdFqX9LyDB2yYh2V+bh3DSWX/zIKQDYAvbpZs1VZe29gJCF0RjMiyXb2G0+wAwu+1f+M KmXMtOdua/sLVnl+akZ/PYKN41Zj9CaeBumchOOoZ8TBkmeUbw7LJkMFXJsGD8IeJW2R hesSQYDQvUOJFTW7mRicjI2vCngxOp+6s46bcHyiw8lIiweu7LUT6CFaiX3gYvqkN1j2 D38w== X-Forwarded-Encrypted: i=1; AJvYcCXvOPibn7iw/2ywK9JmpK31Sg8cKbGkxGsTZNAy1uH94ZTn4496mypI52S50Dy4sOEaNXJyGpkyGLn2oIQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yz0AInXuDh4jluiV2KmZtlwQ1+4ZamVbWVvRTlBEQzXUynH9hyB b49o0oE2/UveJgwva+Wr2g0vdo7pUn+X5VSpJtm4OunRRpUNsb98woMzKjhCRkUFVzteSa2kSvY O7v9Tgl3jSg== X-Google-Smtp-Source: AGHT+IEqUCk6kDNnznwLR7QswDVgEKNTjE47vrZVlVegCSdLW0pjKFX8we9erSxwtSxzpV8I2/gJIE8scUhO X-Received: from pgbfe2.prod.google.com ([2002:a05:6a02:2882:b0:b2c:3c0e:f01c]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:7a90:b0:1f5:70d8:6a98 with SMTP id adf61e73a8af0-21fbd295a7fmr11528932637.0.1750050940348; Sun, 15 Jun 2025 22:15:40 -0700 (PDT) Date: Sun, 15 Jun 2025 22:14:52 -0700 In-Reply-To: <20250616051500.1047173-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: <20250616051500.1047173-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.rc2.696.g1fc2a0284f-goog Message-ID: <20250616051500.1047173-8-irogers@google.com> Subject: [PATCH v3 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.rc2.696.g1fc2a0284f-goog From nobody Fri Oct 10 02:41:51 2025 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 553DC1EDA3C for ; Mon, 16 Jun 2025 05:15:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750050945; cv=none; b=PJlCiheiMNppcksFflHGzAhlyFCMV7WbasivOpdpmiLeKLtyn7iqrJVvYDcjgPr2AdRPpKUfVOpZVC/zaf0nxaLFskLQeZB+kaNamSzYLz67U10/vttZxlQYCX3Anw2jbNOVnWsSMssm3+UZ0gXJ4jJSShsyLQFXAvAtJEc8pOQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750050945; c=relaxed/simple; bh=htoxwdnbpqodVaYi1vg6ASyk/arLh/Veqjm0uXpKpU0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=mq7NWKJ8TRPM40uBv/BnKcObsp/bvwyHh9XfI4sK56hG+TWPFpUEYNXM/GnWAExsK2danHQFgARwanpyYo1X2Dj9AwfG3U3RpgPcaDwKSBpMtj5PUXofp0W0fTdVyTzTcn8iAChflcTn3p1uaLAKDfkksKt8MVLbJ9NPlOgYIUE= 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=0d5xCnIZ; arc=none smtp.client-ip=209.85.215.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="0d5xCnIZ" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-b31831b0335so2254170a12.3 for ; Sun, 15 Jun 2025 22:15:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1750050943; x=1750655743; 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=nSTJqOfE12dA611lb++peOUTVFTOX8QFYvu9s7A7Ce0=; b=0d5xCnIZZFpj+VJe+UL4qjTcHtpYtbfgE1DFf4wjzPw7hrOSERTOuNgk8IeuXg1ZEq 6903qaaW4RpDwHkrrYE5/z/HM+I/Jl07c3B0GexzKm+P3etFg78LuaqcgWIONVxbubGT RqnB9I9HUFlr7EWd/LuTrjhIEDzxtz1Q8p9xBXC+DdZod1R5OMQi6q6PrYrVLxSS8e43 c+L7s8T0lRLUj+NHa12gkFkXyXVnhUl+ftK7qJI9ZG7BKg1FXkh4kkuRl6M2NAXX2Yfz Z1unxtWKlexAYGNttQfw7XP5qsYazCYZt3rqRqk6QcIYZVm9ys+Oxgfeku9VGOWD7n+X G2WQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750050943; x=1750655743; 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=nSTJqOfE12dA611lb++peOUTVFTOX8QFYvu9s7A7Ce0=; b=r5Vg0iM2kqzHghguDkvj/684hd5HGdCwBzViEIqaH9fxZcQt6k7lac2C6E+GrQByvl xPEQcFFjlbTMyIkUAIwY4U5BXmTVdM2Bhqh4gKxDxth8N2K/E9xE6iPfHQ9E4RvNZHih NZZORn2Mcyws3ZUF00jNWgQ+9wbouEqD6yRdWXy2J9SY4ONOumH5FV1Y0g5GFDNcENMB 1igrBWDLxICIevgVOD7HRoGXZJNlWRvuVcE8xD3XOf9ZBE2ljbprMqSLaUIvFcY1VCXb SyIvKmuor1fuLnE/Jdi7D+7FQA1mKa+k+Fm1YyOKX4sofRht+SptVRdBNOhcj5P1VBM8 vcnQ== X-Forwarded-Encrypted: i=1; AJvYcCUGuB7wpIuBIBMxouMDFSLNPMwdBXpIhDJm8jDkfrnHJOdGXg53iF4143R1ocv6+6kBz8BPb1zFPY+SWZk=@vger.kernel.org X-Gm-Message-State: AOJu0YxuqLdHxzuq66VbFQfjQQXpQGi0RW+ysXaG4dDQw0ZDxJ+L3kaR Sx7qTDreCRZevsck6Yl93K0FOaSafIpHtepG64Ccnyw9ZkGE7wrXtFQ4tdq3lnpjGKjHF129r2m OxMrzmwb53A== X-Google-Smtp-Source: AGHT+IGiNJcriaSZJyGROvA4ygiLrIS4gld0jM25ZoXjpuKhN7lGGM80JpMrvkfxBHSy44Rna+1SKnFEMcwU X-Received: from pfun1.prod.google.com ([2002:a05:6a00:7c1:b0:746:1d26:e8c8]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:e687:b0:1f5:9330:29fe with SMTP id adf61e73a8af0-21fbd4c7e08mr9806999637.17.1750050942437; Sun, 15 Jun 2025 22:15:42 -0700 (PDT) Date: Sun, 15 Jun 2025 22:14:53 -0700 In-Reply-To: <20250616051500.1047173-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: <20250616051500.1047173-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.rc2.696.g1fc2a0284f-goog Message-ID: <20250616051500.1047173-9-irogers@google.com> Subject: [PATCH v3 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 609828513f6c..76b7ded7fbf4 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -622,8 +622,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.rc2.696.g1fc2a0284f-goog From nobody Fri Oct 10 02:41:51 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 44FAB1F12F8 for ; Mon, 16 Jun 2025 05:15:45 +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=1750050947; cv=none; b=MYHffuN3eDLgov9/5cI5P6PnVRb6qdX+bhZ8s5QfIHkbI2WTZxI5maEjmmrNNYX+XMXFzXL0NgNb+B9mneQyrb9aJDrHzPnI4kWPCaDXtEsqyb6Z0Kq4B3ijRZAFmHk5jfk7eKTrjD9DZDMClw4sgO+0yJ0e9U74d/MtNp4BH2o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750050947; c=relaxed/simple; bh=4pQN5jluai5Q1Bn5GnKmsLvBkCOsmSQJKX14e951gjE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=Vu/+n3Zh69Wm+6XIlJv4WrA1cdYTXL0OV6ZYZbg14YUe/5e1nHdRN/ThTRfW1AWwZ+ylAN0Mi1sSiln9YUMwdXg96p11hh4osGrEZhJ0XwhkkFIMcOZuRq0POKzTRzGeEKbuJqVJcPcQJ+4a0YPB/lRisNlLV3aM3oS+Zg/ET6M= 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=VYSH6POi; 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="VYSH6POi" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-23689228a7fso1338585ad.1 for ; Sun, 15 Jun 2025 22:15:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1750050945; x=1750655745; 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=mYyv8s/Sddxg16KkEv6ixlo8jCxdrdssIDKWf3vY2U0=; b=VYSH6POiJvMWbM0rpZLJn6veNZhcXL9A6kMeOL8gDEEvBtKmmDdotBBD9EAbpMPf1T DEf3A/oomLCnQfiCd++kCgsTrkZzK3isnffvZxgLhkPdnzSOrqzgyjjGnQt2ng1DyPNa gGQMP1TXKcwzDqbcoGlOR+P26AWa92IiOzaFEhQTU1m/RIkk6Dw/w5b50TPgEsSS7dtW 0JwuNcfgzXllrshivHNYOTAHNY853jNQ19/wa5DK+vdVS7wy0pbKL0806lTlqhldr1yw zyJKPtU7213fA6aUHYbPKOab87NZxE/HeTGxSmMisaDO9KYSvmn6wApSs8qPEohMIwx1 46Ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750050945; x=1750655745; 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=mYyv8s/Sddxg16KkEv6ixlo8jCxdrdssIDKWf3vY2U0=; b=ZMr3m7GYHId2lp4ORMjIg1WIiScHe7uxdwn1aCpmX0IQCI5iuvg3L0ZfCcHk4ErK3m C2Wkyj0QrtMAlKRchkbHcq5QeyGdM+QaMF5/842iH3M85KnfOaIXhvErvMKqlQLE6ISl bt9x19c18SL741D0YXOUiSU+DBaRwIKHfj8iZW00kLdrwSlp5G26B7ZeYO2A0kRZ5TyW v+F+/vzTp0FWWQZqEMurbaqOKnxMxmmC5+avJVFP/WO56P3D4Ac2mJQ3J3PTAFBHwJPK 2f8dkqBWP5Fx3YlkA0jXVssiVz7mnkrqmWkSyv/9W4GkXprRRxL9zcK/Q3EcBYgG9ACX 4GOg== X-Forwarded-Encrypted: i=1; AJvYcCWQfT8LkTMrJrxbwKiKN9WbkiunQxiYyo9g2x9n6DGoeE3wnzOHBqL7y6g6+5Dl/VmASYsgrCJxFzvO4y4=@vger.kernel.org X-Gm-Message-State: AOJu0YyH2dz90jtjMyY5BqybuIECqjh052B1jjgAhblZJzxZUPdHzLT9 EunuWjQ0L5ZVJWnWcT4q5+sMGFtMRif8F+2Y2TBqFV6OHj2e8Y0vffaJb/Cls8m85+xI48BtqKQ 24OU/e1rTmQ== X-Google-Smtp-Source: AGHT+IG2HKnLfYGSE/CD9bC/Kt7Y2DqrfJ25Q4sR8ZmI4LQAPXho6ap9AkriwXATV4k/G2P8CGis3uw1JTEA X-Received: from plqu3.prod.google.com ([2002:a17:902:a603:b0:235:ed02:286a]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:f706:b0:234:d7b2:2aab with SMTP id d9443c01a7336-2366b3502ebmr125257255ad.14.1750050944792; Sun, 15 Jun 2025 22:15:44 -0700 (PDT) Date: Sun, 15 Jun 2025 22:14:54 -0700 In-Reply-To: <20250616051500.1047173-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: <20250616051500.1047173-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.rc2.696.g1fc2a0284f-goog Message-ID: <20250616051500.1047173-10-irogers@google.com> Subject: [PATCH v3 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.rc2.696.g1fc2a0284f-goog From nobody Fri Oct 10 02:41:51 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 8E2A81EF0B9 for ; Mon, 16 Jun 2025 05:15: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=1750050948; cv=none; b=jB+jFRcDN90Igj/LRcbn7w6nbh9l+MXUU7k1G/edKw7GRU2eSML4N5Kh63PRRR5mX3j2JwTQC997fNKkVz9vOQBGIH/brKeGMjtNxquFH+ji9q4ucNaYlUlbGm0W7QR2CvxMbkfcLNKEYTOFTEUbGhlUvNhVcOGDvpucz4Glrag= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750050948; c=relaxed/simple; bh=oHlVYZzRVwAe+UXK9uHdGLjOLnxQvDDCV87amYBN0F0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=sl4GkFMAIxupJUkbeAyOZ5q6CvFWdiYpF6ge3LxY1IflC4t99zR2ATyw5VpDlE6K8w3narCiT6SkySJATKYk+WiX+PuQwvNCUzrNjy3ewTP6/RjaJZ5Jnt15iJsIgLuZWsLqG3HYH+poT19i8coNLC8l9tyq2PmpfDe81ZbOhp8= 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=Bq/mFvDB; 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="Bq/mFvDB" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-2362e130be8so38695695ad.0 for ; Sun, 15 Jun 2025 22:15:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1750050947; x=1750655747; 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=Wsyda4WtQQy5+ceUs120ZRx1vnKpP9F70AgtsBQ2bGg=; b=Bq/mFvDBp5MuA5B5f01iaFZ8r7lO+CttGxvLfyxJY77sONscn+CUCEEhZFtgmW3PT4 UDtNV+G5v522zdaJsJ0w73i4Rr5z8iAgbBcqjI3SMqfIfelVAMB2lgOI4GFVq504PGhL JF8xnVSYKyV/jHMTZPpvMHn6pyXs7CbROvxvMN85eeEu8BzE9OnCSF8Wips3xtun5aOM +j2KoEc4fzsAGjJSTu+0lM3ZLtz05flogTohqYwcUt2uiFBrUHHT6ixeeeYi5R/1n2Ev LFl/zJUsFTMhakkzvvLvFmTRwvOGXRFF8m7umPwuRh4HKtLPJy+6+KQaAwIv1EKTgPXL Nsqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750050947; x=1750655747; 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=Wsyda4WtQQy5+ceUs120ZRx1vnKpP9F70AgtsBQ2bGg=; b=f8SJ2Wedclc1hcEnkZG1iBZ7copamFTDhym8em/bd28q5W3SLm8ddyvrmM9q19E+uP Eirp5ocvHVFN1pOa4ngTG4/TB1MxqU8+EQGwXrexSwjBuvvfFXY2ueRpi86ldtR7oNgk 2K4QAVzihzMZUt5AYwgLrU+mZGc5j/V4FbSWTbWtCbhZZNgBMbOuN5ydCtJB7Fe909KA KnqkplnCgi4ajvfucniwlz39bR8B5BwyLWS7Eld5+oTWHTPRT0Kr/lHRr8bZqQyXQcXE LvSvBrmWD/XUAeQ5CwMhkDGqxVfrVpltJEyvUTj5SV//Z8Ci4qQLwl+eLBniW4T5SaGj 0i8A== X-Forwarded-Encrypted: i=1; AJvYcCVk9AaEpPhqmuNwqmfbISCU63bsEqZkosl74zRx2wpqAi6kN64qwdoegnFQyQnJS5BNXOM/3IZ3X0oPWEI=@vger.kernel.org X-Gm-Message-State: AOJu0YxbWpYpTvYZmapJynTfPQGD35mVuClgZTW1EznDzV0IDgCmqKDh /W3+I2291/P1xLQOA7Vf1ve6vhNBSMkZljo9oSjnjV769S5qahHZ+jw+zSUFpBkYEy7157OiTh/ wQrwi848Z1g== X-Google-Smtp-Source: AGHT+IGwfWpc//cUVY4b4gWE7CLvuCzE1A8Mm52F41Dmu8y2Xdr19DhW2SlYDWwzD5GvgD+CV+Qi1YzCmNCn X-Received: from plpn20.prod.google.com ([2002:a17:902:9694:b0:235:e1d6:6dd9]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:fc87:b0:234:d1f2:da31 with SMTP id d9443c01a7336-2366b001621mr134870535ad.2.1750050946836; Sun, 15 Jun 2025 22:15:46 -0700 (PDT) Date: Sun, 15 Jun 2025 22:14:55 -0700 In-Reply-To: <20250616051500.1047173-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: <20250616051500.1047173-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.rc2.696.g1fc2a0284f-goog Message-ID: <20250616051500.1047173-11-irogers@google.com> Subject: [PATCH v3 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 76b7ded7fbf4..c0c12880146a 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -1180,6 +1180,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) { @@ -1199,8 +1225,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.rc2.696.g1fc2a0284f-goog From nobody Fri Oct 10 02:41:51 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 89CE11F473A for ; Mon, 16 Jun 2025 05:15:49 +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=1750050951; cv=none; b=RDvfJSeaycxlxYHx/nTVKYvWrVp8ZYa+vQF4Kxw+mn8PoBZ5TXS2ni6TsGiqCqsNrDpL2OdvZHjOpg8TF1zqrlGTmU20WqdMfAGLryu0yNcO7oFxsH+edO4UPXRXtlJ6OxSMML9Vix62bcj7kR3ggbXflkG83R6GoPAtRTQOCkY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750050951; c=relaxed/simple; bh=5iPWIdvkpilK2S8k5jUjqTJE/tpZh6ximXRboDJbTeo=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=DKquKCFxTzwGfwJ2hIj7m1n3665sp3EazP0zCPhkP7eecD2w6j4IYtUiGRoHt9vCCvFAkbx0fLCBW9xLOtInYdjopx5EsYl/dX5/8ed3LGw4nFFRSREbOLHRY4g5zX+R4oT/mVP1dGrVRPchH0x80uI+C2Iv37NbEYs07/2Z92c= 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=Zj53GBgV; 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="Zj53GBgV" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-7377139d8b1so3743680b3a.0 for ; Sun, 15 Jun 2025 22:15:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1750050949; x=1750655749; 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=sR6/2QTCkoINPxbY2i50zv5RW5L8V5dsJdMruxu3sps=; b=Zj53GBgVNiGwNnqQ5O3xJ/oEfCBh/t4aNoOxF/uYQ9dIPga/enbugSMA2/sqPKUSke 7smmxwzLQYi30dCK3z4e9o5TeqdTAqAVq7Zr2OuopLrWbwPrcYoo77Ya8SL5HKm6daG1 iyWZ1eQ7ZRMCAOrf3PH+Vd0oY+2IMWm6NXrGHm07kdt8gS5j/e4iHZHbCFwsyYySx2dA qOcuRgGe9zrIu8tOwpb9OcZ73ECoXP59DMxEJhvlHdjeB/9oViAU/wgNUvlDKfN8qa1Z b9gCeV8SRSLNiDaw3D7QjbSN96AzwSRTvdgx8AUM/jX9wjjG1Yp2anNQuP6R5NsNc+vJ lqNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750050949; x=1750655749; 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=sR6/2QTCkoINPxbY2i50zv5RW5L8V5dsJdMruxu3sps=; b=Sfj4FL5au8DDCTtMcfj2nhLv+V8ta+WP412vTE252T4QgVLHMjSc90BOk/ri4/O5Uh X3NdZRj4Re+RdZ25MUBN1SPL5WOtwE5OYYQjd7KP/SEzOCIwZsevy0X2FPfQdrc8KUR+ f7+ktMT6p21Zq+64BIY90l6iHe3kqs87w6kMKZBDDdQfgcJFASoQZsV+dQEkUwn2ON6W qc2qbY9WWVTww9eTQOgOaIIhJ/IKi53uLOUwG8nUGrFdPChch2aGPs89QidtUIopwVGe p/IpAggqXVPJ2rh9mye3s284QCECXuO0Zn8nPs6NYKaRAHvzJyMtFRMnPA7u2O7UCaz1 f3Ng== X-Forwarded-Encrypted: i=1; AJvYcCXU2fWSI/FSFDZgwZ9jBkvidjfMXHiK8NWGe4Ma1ie6/FiW+3VeSRiB9Mcs1FT0p89ts7x1Fn+/yvJcMhg=@vger.kernel.org X-Gm-Message-State: AOJu0Yy+xWvL0toE0MrWGZAF785KqEp8L5J7Kcbb86dPkdb1JOsbqqSB 9Iap1iMpyR3vm1YpFduN1gHLIf8+tkJ0JTHVp4WSPpJcfEnQW8bb50zT4QOOo3KEqH4CdPYp6CG Zwy/RrVjtSQ== X-Google-Smtp-Source: AGHT+IEW0BNxwIEQGoAsJ5WPADlW40JN8qLSDdlA0rmHScJcAh/2M/on/xJRcZ07YwJdsHtOR2TpYiISveJk X-Received: from pga17.prod.google.com ([2002:a05:6a02:4f91:b0:b2c:43c2:d8b8]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:6a06:b0:21a:bdd2:c2f7 with SMTP id adf61e73a8af0-21fbd58732bmr12280546637.29.1750050948915; Sun, 15 Jun 2025 22:15:48 -0700 (PDT) Date: Sun, 15 Jun 2025 22:14:56 -0700 In-Reply-To: <20250616051500.1047173-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: <20250616051500.1047173-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.rc2.696.g1fc2a0284f-goog Message-ID: <20250616051500.1047173-12-irogers@google.com> Subject: [PATCH v3 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 9dd0216cfae4..4dbae59dccb3 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 a786cbfb0ff5..362e93fc33d2 100644 --- a/tools/perf/util/print-events.c +++ b/tools/perf/util/print-events.c @@ -387,8 +387,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.rc2.696.g1fc2a0284f-goog From nobody Fri Oct 10 02:41:51 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 C20C31FAC4D for ; Mon, 16 Jun 2025 05:15:51 +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=1750050954; cv=none; b=oTaiVj/sAd+UH4B+RvfZnybMk8FJzc3L/XA6J7kaIvgaUwIX/f1odQO7Q+gX5I7PPtqMbfZg6hQ379DJaA3QWGWt+MMcmpOrLwk7blOz6xnfV06CCKRFZkfm6JbOENMgWRim3TB/HbLd31UWyFEGusfpmlKCTMLDKgKEzkQ8ovw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750050954; c=relaxed/simple; bh=1MWPyFOi1/GoUcsqXK25Y3904s3Kehm3Fw9Fh/2O+gk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=qxD8x3t5+OjC/KH9bFvT6+p7BBJL5vivjP1tfOa7zFF5S5RImPG8FM9JEQhMRVl0jCJXi6WvoURxS4VT4NDm/9v4qjF9U9yqad3l13NQfAqVEW7llWniSPaGmgcvOU+bFsSDVNfJvjS+0M4oED+fKntirh8MYxMJQHBYcQSg2Ec= 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=MFd3wGQ9; 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="MFd3wGQ9" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-31202bbaafaso3759420a91.1 for ; Sun, 15 Jun 2025 22:15:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1750050951; x=1750655751; 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=kFCa6TUdPFwTF6/gzbUNjOw6rOCDbrBUWir2XCQ0ybg=; b=MFd3wGQ9xpx2da8hkV59hDirg70EAcAa5KfQK8SxAEdibbKldWVIKpb+ZCWRznQdUH kqrU6TNGRzyPJUOGWPiMHw8dkq+yHQ2uxBDdF7v/RY5Ne+jTau9y0hUYVv0a9QhGXJCP H3NXXwWHS6Uqzr8jURuQDDeXQBbFnrgOONySC3j6KLj0KlqecKUWO8hdVlnHSnNxsbN5 uZrnycGF89k1M9MlcIjUPPYN0IbGbCIBe4j8Av0NRDkmMpuFMSLt0GdLC9VXmjv+7Iue J+97iMjXfjrmOEFZZAn7rE32DTNXOQoAu3oyIaeDE/KhQzLK8aHWO98miWxWzt18bADF TNKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750050951; x=1750655751; 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=kFCa6TUdPFwTF6/gzbUNjOw6rOCDbrBUWir2XCQ0ybg=; b=DzWMiNKAySiHATBAMHZVrLeTG0TicMNE2eBtNKR5aDU7ghOAugyZeyDVCvS7CPLi+a DvshIQ3A1qoaeNh4vZavjlgergZjZrKvi1Vfd8Mn56ysYI7Om7f6sEBmW4E1eTXDmLNM bPYe1pUjZEl3/SOMVCWg+LKd84R1OqzZCJJWIa+428FIJ0hk12ILL5CWp2PD77g7tr53 GFEjwh0rn/Ea7mmSdqcy0FJB2Guee1hBsAwhn3pcJ9p8aovBmhBv7A/+mEE89v0QEDAy hyjPBqnuFhWJFKA491PNQx9g2u/jhQ5AidOZCv86p7cIIj4qDI5DkN8kBJOv1ze3wlWz lZww== X-Forwarded-Encrypted: i=1; AJvYcCXuaf/4kWyXVS3KSgcp7/p/BFIQPIq7muUCXy+9pFzHVVOT7JcSgWoTxCxkwUhy/hxjife/mvQUQoVvWqs=@vger.kernel.org X-Gm-Message-State: AOJu0YwBCRxpJIjGin4eO7wqjbq46tbkCPs39LnsV4GQVHQeZtHipA/o iQ/6q6Yp+eWoPBXUHLK8kgg2icV1YlE9T0aXdIbCgjjeuq/TGq+gA7QZMR4TzcYwCc7c2R2SDGc 0TQPOVE8AzQ== X-Google-Smtp-Source: AGHT+IGUzYJwQxex/N/iBG/6ouOxN4qo6le4GQrouZ8qDvOGw8Tzly7xESr6M5dyHrZbKuG3KzpWWhFuLiwz X-Received: from pjtu3.prod.google.com ([2002:a17:90a:c883:b0:312:e914:4548]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:1a87:b0:311:abba:53c0 with SMTP id 98e67ed59e1d1-313f1c03004mr12655127a91.9.1750050950842; Sun, 15 Jun 2025 22:15:50 -0700 (PDT) Date: Sun, 15 Jun 2025 22:14:57 -0700 In-Reply-To: <20250616051500.1047173-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: <20250616051500.1047173-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.rc2.696.g1fc2a0284f-goog Message-ID: <20250616051500.1047173-13-irogers@google.com> Subject: [PATCH v3 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 7910d908c814..a06ff82f9dd7 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build @@ -86,6 +86,7 @@ perf-util-y +=3D pmu-flex.o perf-util-y +=3D pmu-bison.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 d55482f094bf..beab9710fbf5 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -58,6 +58,7 @@ #include "pmus.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" @@ -570,24 +571,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. */ @@ -621,7 +604,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 4dbae59dccb3..b3f56236fd60 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.rc2.696.g1fc2a0284f-goog From nobody Fri Oct 10 02:41:51 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 8212F1EDA3C for ; Mon, 16 Jun 2025 05:15:53 +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=1750050955; cv=none; b=lEuzjHfUHQD01dGW7wRH7sZgoPKZzWXsa94pA1Dt2AW38l8PELQU1Rw6QbapC3q8vqsyxgpD7FQsYPguGvjPjQXtqm009Tnq+GcweTe3YySpd9g+rSqc5YbLNCLni5D9RfArhTzuV3aG1HZqPpgow/ZsPLbvoqBXeA/gfP96Ehw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750050955; c=relaxed/simple; bh=Oml9++Abq7g3FkDJmOrjARftTN1uoBIInMWrq2h0mFk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=Fc55lTWnHUjTcD6QBxOPpPiD02PiCiCSnrbWra9UCTAha9V4Aw23L/zv7h7s2CCc8SlG1o8Rbp2UNUDHlLYKfgEOLzpez7D/bT1cd/7T5R/75SjxlKW4CqXk57Ovm8CkkmZamfiau3M9yjP8HxNboqH2mZvmTjQ8lgVqxfdm+Yk= 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=zTyugVBm; 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="zTyugVBm" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-313c3915345so5263868a91.3 for ; Sun, 15 Jun 2025 22:15:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1750050953; x=1750655753; 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=InwfgEsJlVa5WtWhUcLkvO5lR5T2Ob+LyUCpO5IsVdU=; b=zTyugVBmUoYX4EqGi5BkS4wj2rf/8q0KMZ2lUa5mGcOvq/bCfZBy8AVEN4ssF1aPtw zmJoe98msqVziZXLXJQIko2C4UvEjdlX29FZPqMEBg8XiA9Ao8e8hPzZc2BHR60xTJgi Rte9wZzipP3pOhK32mNa6DnBrSAFd2KCLaYCr41IvV03CneZ+GrI7JVr42785DqB4j78 20yELtRevrTB8qsUrzBbAdj/LkJupY3bQu9YiYAUjabxtMM9rdyQhooKdT2JqzjogXjw 8HNz+jZ/M+GqhOrmj9Fud08spqMWBU8tpoyJT8axak1zXo94MUvQ3TXcmRlyurzMQOX1 7Y7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750050953; x=1750655753; 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=InwfgEsJlVa5WtWhUcLkvO5lR5T2Ob+LyUCpO5IsVdU=; b=hA1tCYDsnecRbUixxx3Cf+mmMHUMW8nakCMaZn0ivxz3xgIB6AGxI/0tEcXBQoshR+ Oq2eDynnkmf+N1U8Zqg6zSlbGyJrQD+HVrnmTpg6FLWhvUx3Hj42yqfpOU9ScqgAdTQ3 DrdVkoP3dhfA+R/wQVfmS5JRI1B/bE0y1IF1Kc4LX6NCp4X1Qm7Pg07ugt8ajkSaDVig 15B8P2OJLd46Xy8Qy5lUXOPkyAhr61oJrK9x7BwRKqEJxtoCdchHq9/zcHGjTJ/7UGj/ 1oCIxiSW5xUtZRbNzMe55CZKGt/Igh7utIWy5QS5qlcBE0Gj+18qBENnvCvX8rPII9B1 ZCnQ== X-Forwarded-Encrypted: i=1; AJvYcCXb6tNm4zAIT60Fv64ShhxNrTvLaKE0Vqpk6CkiV4kwyO6Xu7qKIovJTRS/x20wTh+rF97vXkI4W2b2w+8=@vger.kernel.org X-Gm-Message-State: AOJu0YzAOqvkKc9eFnTjmtWxBx7nDOQ54Q0MO5gqNwUKhhxHtoSQnms+ kEYQeJnrzloX045GmN3JP+zQRfjb+chegsA67Cie3RkFO/1RRwlheCnTzP0OG5hk1+/3W6x4U+N W+7Qf8ziPBQ== X-Google-Smtp-Source: AGHT+IFjNcbVLRpKDzB1+cGidoQ6jru3UYvZTwpg+7RV/Z9c7270tYSK/s09toXvZdmZKCJeGDe+3MDNrRql X-Received: from pjbsl16.prod.google.com ([2002:a17:90b:2e10:b0:311:ff0f:6962]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:5104:b0:311:ad7f:329c with SMTP id 98e67ed59e1d1-313f1ce5cacmr14167125a91.18.1750050952947; Sun, 15 Jun 2025 22:15:52 -0700 (PDT) Date: Sun, 15 Jun 2025 22:14:58 -0700 In-Reply-To: <20250616051500.1047173-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: <20250616051500.1047173-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.rc2.696.g1fc2a0284f-goog Message-ID: <20250616051500.1047173-14-irogers@google.com> Subject: [PATCH v3 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 c0c12880146a..2b7671d5bbb4 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -23,6 +23,7 @@ #include "hwmon_pmu.h" #include "pmus.h" #include "tool_pmu.h" +#include "tp_pmu.h" #include #include #include "parse-events.h" @@ -1976,6 +1977,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__find_alias(pmu, name, /*load=3D*/ true) !=3D NULL) @@ -1989,6 +1992,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); =20 @@ -2057,6 +2062,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); =20 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.rc2.696.g1fc2a0284f-goog From nobody Fri Oct 10 02:41:51 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 92F2720297B for ; Mon, 16 Jun 2025 05:15:55 +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=1750050958; cv=none; b=QhgHKr1Zg5Sl+c96A844sNUQdQlbyPovusu+gdb9Atl76jmNGw+w0JPfEHyQJgETc9PX20UcypLc4oFR5XZE3d89v+/HvLdKk6TDnOl2470iwLrlkd+uYs2/QYqbIKp1cO2KpN36//rgk7s6bESSF4ImwaQXWl31MCrEtd2qWss= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750050958; c=relaxed/simple; bh=5g6NXNZKvaIDA4lgIQvx83+6XNu6ZjqforAQL/j1ROM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=r7wVTGnkRRNcVM2umSWiRXIStJ1/wzVS6GNPqVSb17uMvNSeJgwSgyk44EDhWKIOFaOwuMI43JhtjSModSvoxLxOaNPcfrb+5OSBcabfe0bcMlPXwvb2WLSQ0BTwJlB6yuioi/Vozsa2N+pyV3Fs3A5QOlCaempQNBM7ydQeEUo= 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=EEMLnpWP; 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="EEMLnpWP" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-b2c00e965d0so2657383a12.2 for ; Sun, 15 Jun 2025 22:15:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1750050955; x=1750655755; 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=/VtBOHd4FHxz+dBPYGp95I2JdXXzZIX3WKfTkMyniMg=; b=EEMLnpWPdwOrUs1+rsa6ZEsYoKmp6pdP+Zap3iALL+Fc+6YhCsBSx4zyLVs8vQPFe8 qvZjxTx6OkcJ3LihH5xiwj+o+B3a4NwIc0C8Kly9el2IIEU3UsM0zJ/GeAlkGZecGo7i F8nNH5AhNQdDIQGfgbu5MAx0blC2ly4bfuRwaWqrHybs65abIxg3+YL9JjpJlbdxuwjy WYnCnoXaxIiMMR0jbAbvAWlzWLgAVdX7a7kdG1+tTgPwciG5YEuGOgxfgv6VA7Xef5+7 J+eB603T7MNU4txSs3HUiRVx28YHzPs6NvdcAR/Ca2tTp5nqdFL4+hxAbCEy7XKylzOg d1iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750050955; x=1750655755; 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=/VtBOHd4FHxz+dBPYGp95I2JdXXzZIX3WKfTkMyniMg=; b=OrXi8llYjE5uKF6qjEINGnO4ZEeFBZpgKcSqZAwM5njk1v15PS/h5kknz1KwysXIw9 jJVjz8LcWf19/Hb4CcgrHtRS1UWwjUT0b+DfSsd+58Grn4lLpnSlo6y6FSo9TYY+yE0n QEixNQEC2y5jvSPAkD1SwaYNPewSPvYmH1HvA5eiKJFFkFYnBggIfhgNUfg+XpFX6GX9 /hL/OvSXT6BQ5a3qwGA+eBjTL7TczeXaVchb23Tr7Jbf+SPKxmZlnAwgWh08KR61a6Rx rKkOPPVJceXXY//lfzj7bOOL/6x0x5f62Cy+OJs6Ypcr71Xvu2I9iP7vbzDHOmiuviVN jNeQ== X-Forwarded-Encrypted: i=1; AJvYcCUXTNpi6FUMk9stGJyfKyQcRHMRaZfaACSYzg9SYiWbMJT+yL8ThdZfmVpTnkmCgiYQ5+aNiChwLb1nZhE=@vger.kernel.org X-Gm-Message-State: AOJu0Yygf8PjV8vrGITcOgeV3R/GDOGcIxqFkUp4hKEIFsvzJWVlP7UK XKEk9dxgPOL/dgVgSF96aetrWbm8SscVAgifEeiSHg38GcO2pfVOpD0NVL/eMWOnpp870wqkUJ0 T1rjTgrdUSg== X-Google-Smtp-Source: AGHT+IFLk65fyoJ7KOKDxz1UROvvFsVIsqxvU8icq1XV0ID2ECOpvVHpmEJH4MG6fmiJloKnmRSPFNck84U8 X-Received: from pge21.prod.google.com ([2002:a05:6a02:2d15:b0:b2f:a049:b765]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:330b:b0:21f:5674:3dd8 with SMTP id adf61e73a8af0-21fbd63161cmr11001622637.26.1750050954791; Sun, 15 Jun 2025 22:15:54 -0700 (PDT) Date: Sun, 15 Jun 2025 22:14:59 -0700 In-Reply-To: <20250616051500.1047173-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: <20250616051500.1047173-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.rc2.696.g1fc2a0284f-goog Message-ID: <20250616051500.1047173-15-irogers@google.com> Subject: [PATCH v3 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 362e93fc33d2..8e629409f45e 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; @@ -418,8 +327,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.rc2.696.g1fc2a0284f-goog From nobody Fri Oct 10 02:41:51 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 DF4CA2063F3 for ; Mon, 16 Jun 2025 05:15:57 +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=1750050960; cv=none; b=dCuMc2atsV89OQ2zkjKpVjT7EHDhhXj1SSPBdv9ApCyzL2nMIzbflTH8c+DGrAjuA6M+VOnhh1UaTi2rCkKug3aejjrcS+NRScSE6oL+Mb5pMmbCFknmSGp+wNKvCe0ScfZkfKB5ig/+pCMbk7Oi6kMq2msrdFx0PlE3gNoN21U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750050960; c=relaxed/simple; bh=vMpp3wE4YxxlsaW079icYYQfKWfxXZSmzDTouEee0nc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=o0aE0oEhh1XtKj/o/tsJ52jSLJ31+jm9hAkgqytLg1v2KqOM+ezo6vE3JzdOCaUgIwY45wmp16tm+UHp/WKAX64FSBLOpJka+PKK79FQEb/wPTqn2ThPfcmkK0LLkD2DnnymTYpvYcoaRu/OZEyTBVkdU5a7K/nO0zrZGWNHnMs= 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=oZhmwjsY; 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="oZhmwjsY" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-2356ce55d33so53222505ad.0 for ; Sun, 15 Jun 2025 22:15:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1750050957; x=1750655757; 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=jEbchuSB875SLepbJuHjmJtYDConDg5qTi58URUH7g4=; b=oZhmwjsY/Ro68dNtUlXLE/X8+TxFQNEkf/hCVNQvRup0z3IX7yndHSszVjZNRI5ssS N+sh0d+kEgZV9kbc3yYlT2IliWDASANtM2xlr5RDSJf8WTwlDQjQ7xhh67H4Lel9Yb5j Iinec5VuPtxew8dzCNl96751/kMy867xT5TO9xLOtmm0yXk6YeG4+NhzHkheeMvRqJf8 mUigVTodqC70J+n+FZkcIJDeFebU3O9rX/gHkQpkBjUP5aUHLjKKdPQUCUxujSUmrWwu naQcXswpxYuZMHSm10ddiMiGYIxna9rlY3ihFg57moR+Z68+FvA1bfLYxY7AsweC89Zg F2Zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750050957; x=1750655757; 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=jEbchuSB875SLepbJuHjmJtYDConDg5qTi58URUH7g4=; b=VEHe0JPZKlyLRGnjlUIa1eF7E4gLrGI8X12icJjBubQNMK8wUFgBIGFNKlRXgNv7xw 0VEXYxOIczfmqPbwbf97izhNeie0Dofe5yERGHRMjLwnqp3XIrKJteStF2JK8jnMIJPO 0ltjYU3+i9FnMTEwlgLwk3eUKLK9+n1WzTvmXrwOd7oAQ46nAYXcpmpL1/U0VK58V9+H URo96x6dIJQiUhamgniK+TGlIpI45dJwoh7yh66C6ANHLu2hg451EqO4TOzhaqsfcUs7 TXw0jptFoWn+2vN3rc6b8yC613mTIFpP2y0+qWTCVlaFbffEsxpgIVQD6VFPzfqaa24V Scrg== X-Forwarded-Encrypted: i=1; AJvYcCVh9+TCcoSVSlS0WQLu0cXWQplH5LXJGvuvw0UMUH+jUVKzA80txMWz5YhFnLUk43X5Y4xouPZ7Ia3bkZA=@vger.kernel.org X-Gm-Message-State: AOJu0YxR7jkRYG2OFUnNuNdfyuNYNge3ehTZJ44sfsMDUwO8xj59oaPg godoVKMyLfnJazKKjao6cHLvI9g9FPx8IgeqUMM2T35c1nxUrudJmFb1SvN4E6f7XAGJab3djfF uIca/Y/rklg== X-Google-Smtp-Source: AGHT+IHKCKhRh5mvyE2Tcm3j094T49EqOlAYmNKvSEKLlJL9zq3tw4Dyo5ImZMUXVRQbYUKPZvJU7C88do6K X-Received: from pllk22.prod.google.com ([2002:a17:902:7616:b0:220:eaab:51c4]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:da8c:b0:234:ed31:fcae with SMTP id d9443c01a7336-2366b3504b7mr123875505ad.22.1750050957000; Sun, 15 Jun 2025 22:15:57 -0700 (PDT) Date: Sun, 15 Jun 2025 22:15:00 -0700 In-Reply-To: <20250616051500.1047173-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: <20250616051500.1047173-1-irogers@google.com> X-Mailer: git-send-email 2.50.0.rc2.696.g1fc2a0284f-goog Message-ID: <20250616051500.1047173-16-irogers@google.com> Subject: [PATCH v3 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.rc2.696.g1fc2a0284f-goog