From nobody Sat Feb 7 22:21:10 2026 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 0902B2F5318 for ; Wed, 29 Oct 2025 05:34:20 +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=1761716063; cv=none; b=huL0Q21rVUsdb/6H9LYbVWiVqIdhAcA0n85D5W3jEFOoKtXj8RdsMtVq+Xo90/qqDxtZrQhLlxaYqWa1zgsruz0I8GuzX4t8Ws6adCem54LdnrvevpYtmolNdzOUOlKTMRNulYJikKyI8i6xADKLr1NoLqmalyJO4NQABx+hKBA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761716063; c=relaxed/simple; bh=542/UtxOs4wTeyeK/jKTiKMC3a0OqaamQ7WTLZorbXg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=XupUaioS9dbo1HZZ2FQm8zs3vFxOOLy5pH3aPmTlBQS7m1PbO++J6IUnqWgpK1c7OrNG3BcFBPzCR7CN9nUPZoKWuILqR8Frr9r3WkFE4xFKV7fHDDUcjeSo5wM+XfvtJmwj8Zn1Zvz22/8jcE7zN8MDIVYEutkhJNTe11bThW8= 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=gpCqOpLJ; 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="gpCqOpLJ" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-b55283ff3fcso4341998a12.3 for ; Tue, 28 Oct 2025 22:34:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1761716060; x=1762320860; 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=PT/10oAHeoVqquR7dMAlDMAandjm5/1/h+dRRja64wk=; b=gpCqOpLJptVWtCUgVey71DcqCGHQWN7wb82UQ5cHe18jAMpRiMmX0of2pj9S/XmPza 2TRouYgtzcytfbuatUNkPYvURB2dxEdAAtMCdqRGPXehjhTmUPTG86LdW0zcuw3x/uD0 adWPdOWwCnK3TB6tkQ/JoV6DhJLTEtkuUClcLWPqBOgSZuUWg3n3xEu1pAyLiu7nbBk+ QqXuZeiMY57zIPGXYPciNJ3QS+KAynH4vqlo0d8osltWPUQy4eW2jkoABQCFriox8yj3 HIhhKaEJ8TLN7+IDAUMgrqM8tb2OAXO5M/8f0QiVSj4XDANoudlneSKrQGRlwQtDprzm 8hmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761716060; x=1762320860; 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=PT/10oAHeoVqquR7dMAlDMAandjm5/1/h+dRRja64wk=; b=MvYGExbfQf0QDoNpg4jSOtQrJ+H5lI8XNPD4fk8EluNGO9quoNND1U8W+5FI/KTf7R Jue+aMp6xaE7pyEm9uB//Ll5qlm6YsnfpbTWI2OXintlQInE0k8detCRT2hxgCiGyDHy 8KYE7MVqhBFnGRx2SiBsC/Cu/diTBstsylnbWBdjccSpI0I5Je63rtAnw90IilwzR+7L wYct+K3yi1Ph/M9KmnAT+n83CEuSIKf57q5Z9ulg/d/oPmQGhEUzOQLA3C3rWYa3zS76 IQYM4jkh3Mjjfgz6NpPfHeqWfru82LyZkhlZ+nhbSPYbltZG7C7kN/mTOcals0FQlhbE ynSw== X-Forwarded-Encrypted: i=1; AJvYcCUg1GDmYDoInDhUFm03AZI2OoDnNLKo7ftupJVUl+w42tpP7aRJUnU4sd32aFzFmyBSZFbIX4jUIGkrEZ0=@vger.kernel.org X-Gm-Message-State: AOJu0YzAe01VlD1fGGFEPS+4QaFVv7UhVW0/xiVUqN++GRPeryW1xZme RKzGjHU7Ru/KYHDaUH7RwVWidHuXbDnP2cKa6Bx06851XwNVIaV0o34CQH5joimq0TT3bO4wNvW 7+bWU91VKJg== X-Google-Smtp-Source: AGHT+IGOe4Pb1dCo9z9D62bEWfA3YaPeeB5O76SErHIJqTUTT/xA1otwE4sp5XQBWkdyM57M1KRXD8ZAbEho X-Received: from pjbbf19.prod.google.com ([2002:a17:90b:b13:b0:330:8c66:4984]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:48c4:b0:32e:59ef:f403 with SMTP id 98e67ed59e1d1-3403a2973a4mr2030947a91.17.1761716060242; Tue, 28 Oct 2025 22:34:20 -0700 (PDT) Date: Tue, 28 Oct 2025 22:33:59 -0700 In-Reply-To: <20251029053413.355154-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: <20251029053413.355154-1-irogers@google.com> X-Mailer: git-send-email 2.51.1.851.g4ebd6896fd-goog Message-ID: <20251029053413.355154-2-irogers@google.com> Subject: [RFC PATCH v1 01/15] perf arch arm: Sort includes and add missed explicit dependencies From: Ian Rogers To: Suzuki K Poulose , Mike Leach , James Clark , John Garry , Will Deacon , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Greg Kroah-Hartman , Charlie Jenkins , Thomas Falcon , Yicong Yang , Thomas Richter , Athira Rajeev , Howard Chu , Song Liu , Dapeng Mi , Levi Yun , Zhongqiu Han , Blake Jones , Anubhav Shelat , Chun-Tse Shao , Christophe Leroy , Jean-Philippe Romain , Gautam Menghani , Dmitry Vyukov , Yang Li , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Andi Kleen , Weilin Wang Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Fix missing #includes found while cleaning the evsel/evlist header files. Sort the remaining header files for consistency with the rest of the code. Signed-off-by: Ian Rogers --- tools/perf/arch/arm/util/cs-etm.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/c= s-etm.c index ea891d12f8f4..a0086ca8385b 100644 --- a/tools/perf/arch/arm/util/cs-etm.c +++ b/tools/perf/arch/arm/util/cs-etm.c @@ -3,10 +3,14 @@ * Copyright(C) 2015 Linaro Limited. All rights reserved. * Author: Mathieu Poirier */ +#include +#include +#include =20 #include -#include +#include // page_size #include +#include #include #include #include @@ -15,24 +19,20 @@ #include #include =20 -#include "cs-etm.h" -#include "../../../util/debug.h" -#include "../../../util/record.h" #include "../../../util/auxtrace.h" #include "../../../util/cpumap.h" +#include "../../../util/cs-etm.h" +#include "../../../util/debug.h" #include "../../../util/event.h" #include "../../../util/evlist.h" #include "../../../util/evsel.h" -#include "../../../util/perf_api_probe.h" #include "../../../util/evsel_config.h" +#include "../../../util/perf_api_probe.h" +#include "../../../util/pmu.h" #include "../../../util/pmus.h" -#include "../../../util/cs-etm.h" -#include // page_size +#include "../../../util/record.h" #include "../../../util/session.h" - -#include -#include -#include +#include "cs-etm.h" =20 struct cs_etm_recording { struct auxtrace_record itr; --=20 2.51.1.851.g4ebd6896fd-goog From nobody Sat Feb 7 22:21:10 2026 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 D8DD52F83BB for ; Wed, 29 Oct 2025 05:34:22 +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=1761716064; cv=none; b=YxRctwS1Shvi4VADwLQv52AZyQLbwDoL+cANQxAQ6YT7K5UDTwpetPx1UoO2vsRLYTxpZU3mwVRpV/z21ykGLIisPsrKXlSjxehJYBr9/FmFJSs0fndeuvdsjejIZhwpnYuavh5Buc0ALOdOKgu03fJu8mpS3lb0O6DDUCvUDpM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761716064; c=relaxed/simple; bh=YFa6BrzuwE5/5cO1/PAM2OEPqhpeJKANuxeGrZoNU4o=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=uH0s+O/olUiwhpeVEPHDLCm80sUNmXnGyxgiiLUYTNnEVETqOJPGLlBu8FwGSQMwCu4OJgjnbmj5Cb9Ha1htCgjfI3qutM7b3LXNxaixpA5ZwNB9q1bhzSPnN9CNwGtdlo7VHonlAStHR20CwW4s+UD9Qzyib3w64QfvL7eLZ7c= 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=HCsHPE9o; 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="HCsHPE9o" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-b55283ff3fcso4342024a12.3 for ; Tue, 28 Oct 2025 22:34:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1761716062; x=1762320862; 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=8oMwqNr4KsoGOxn51PlsqAlxOnnnA+qu7AX98PEqNWM=; b=HCsHPE9oocYo6eeRpotq6/FsNW4cCbnVkBbAcQnkCrHtU2ds/Szx5OU60UC2loQMBr zT9HwVNoza+diB+Pb+DdlM/DTF7acATAg1pBf6MCEZkXV1EhDcIOJuBPqwDryylkT2wl iJFNgwWY+gYkSk115Fjcjamq40vFXDVX5u8z5VxF47gaOhZGq+5MU4AY/j9Wl2BAlTyy 2CnY7M9mZEbHpAVHb3ga/aBaD+QGAStD2eUeSVjW5XEEAzSot/teGTKcJXb/Eknw0NGL WUbwK9VWQSewimNj8AwfrNJ1fAn7XoeC08xWI4Yd5C6/CD2RpNB5duDs6zY3TGiwf+yk pujQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761716062; x=1762320862; 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=8oMwqNr4KsoGOxn51PlsqAlxOnnnA+qu7AX98PEqNWM=; b=acwyRAi7/q7M0EAGL25gQRgDdDeqo2k8VlYqC9OdOBVn+4he5jLIWHKs9sFfNcggSw FOu9mKG94ZWNKUFsNoeWXLagnivRoRbNhI4PM+CAE+7tSexVQBTtfNa41JeNO0Vtgcu6 GrgNuVYLY2ScUvH2U63PkfHgPt5c79olfEqrUqaAVG4etWgvXq06+b6mWLGialHLmOj4 p0CucDzSQRLWJ6so6CKyK2EJjgM8SWXCSAL/GCur1c0IuXiUK7WRPf8DZrnj3R4rfr90 7lQLDH4SajweFjvlruM25VBqrfyv2W1JpoH4oMjFa0GCiBBZYZVztQOfJlvC8i25KlUH C9Ug== X-Forwarded-Encrypted: i=1; AJvYcCX7gEpdVHxNYh2AsIB7+auk3+uwLRCbgj1ufKJmYn94HuNqNkHhUcCryL411d79x0GMQ3kTfWn3cm3bDQA=@vger.kernel.org X-Gm-Message-State: AOJu0YwAVtSTSts8Fvky3QCOV3JPd4hVBbcPlYEyyLhkRErurjq1MqXw xiWZe73DbUIT5+ybMRs3jEoH0HwcqJqZDUXa8Gt5qltyp11+AGdBFdRDwCyzAgMZK4x4mpeOpsR l68BK08jtMA== X-Google-Smtp-Source: AGHT+IGXe3xRWMqIyJ5Z6kbOfEqQsUFSZQt0QMui38JDXMLAHaq4dgc0lEfNTaG7EDI4peeaS1Y1wlOkAV2Q X-Received: from pjvm7.prod.google.com ([2002:a17:90a:de07:b0:332:a4e1:42ec]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:380a:b0:32e:5646:d43f with SMTP id 98e67ed59e1d1-3403a297403mr2041709a91.19.1761716062019; Tue, 28 Oct 2025 22:34:22 -0700 (PDT) Date: Tue, 28 Oct 2025 22:34:00 -0700 In-Reply-To: <20251029053413.355154-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: <20251029053413.355154-1-irogers@google.com> X-Mailer: git-send-email 2.51.1.851.g4ebd6896fd-goog Message-ID: <20251029053413.355154-3-irogers@google.com> Subject: [RFC PATCH v1 02/15] perf arch x86: Sort includes and add missed explicit dependencies From: Ian Rogers To: Suzuki K Poulose , Mike Leach , James Clark , John Garry , Will Deacon , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Greg Kroah-Hartman , Charlie Jenkins , Thomas Falcon , Yicong Yang , Thomas Richter , Athira Rajeev , Howard Chu , Song Liu , Dapeng Mi , Levi Yun , Zhongqiu Han , Blake Jones , Anubhav Shelat , Chun-Tse Shao , Christophe Leroy , Jean-Philippe Romain , Gautam Menghani , Dmitry Vyukov , Yang Li , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Andi Kleen , Weilin Wang Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Fix missing #includes found while cleaning the evsel/evlist header files. Sort the remaining header files for consistency with the rest of the code. Signed-off-by: Ian Rogers --- tools/perf/arch/x86/util/intel-bts.c | 14 +++++++------ tools/perf/arch/x86/util/intel-pt.c | 31 ++++++++++++++-------------- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/tools/perf/arch/x86/util/intel-bts.c b/tools/perf/arch/x86/uti= l/intel-bts.c index 85c8186300c8..c778d3407bea 100644 --- a/tools/perf/arch/x86/util/intel-bts.c +++ b/tools/perf/arch/x86/util/intel-bts.c @@ -5,25 +5,27 @@ */ =20 #include + +#include // page_size #include #include #include #include #include =20 +#include "../../../util/auxtrace.h" #include "../../../util/cpumap.h" +#include "../../../util/debug.h" #include "../../../util/event.h" -#include "../../../util/evsel.h" #include "../../../util/evlist.h" +#include "../../../util/evsel.h" +#include "../../../util/intel-bts.h" #include "../../../util/mmap.h" -#include "../../../util/session.h" +#include "../../../util/pmu.h" #include "../../../util/pmus.h" -#include "../../../util/debug.h" #include "../../../util/record.h" +#include "../../../util/session.h" #include "../../../util/tsc.h" -#include "../../../util/auxtrace.h" -#include "../../../util/intel-bts.h" -#include // page_size =20 #define KiB(x) ((x) * 1024) #define MiB(x) ((x) * 1024 * 1024) diff --git a/tools/perf/arch/x86/util/intel-pt.c b/tools/perf/arch/x86/util= /intel-pt.c index 2d7c0dec86b0..9ca197cc396e 100644 --- a/tools/perf/arch/x86/util/intel-pt.c +++ b/tools/perf/arch/x86/util/intel-pt.c @@ -3,37 +3,38 @@ * intel_pt.c: Intel Processor Trace support * Copyright (c) 2013-2015, Intel Corporation. */ - +#include #include #include -#include -#include + +#include +#include // page_size #include +#include +#include #include +#include #include -#include -#include +#include =20 -#include "../../../util/session.h" +#include "../../../util/auxtrace.h" +#include "../../../util/config.h" +#include "../../../util/cpumap.h" +#include "../../../util/debug.h" #include "../../../util/event.h" #include "../../../util/evlist.h" #include "../../../util/evsel.h" #include "../../../util/evsel_config.h" -#include "../../../util/config.h" -#include "../../../util/cpumap.h" +#include "../../../util/intel-pt.h" #include "../../../util/mmap.h" -#include #include "../../../util/parse-events.h" -#include "../../../util/pmus.h" -#include "../../../util/debug.h" -#include "../../../util/auxtrace.h" #include "../../../util/perf_api_probe.h" +#include "../../../util/pmu.h" +#include "../../../util/pmus.h" #include "../../../util/record.h" +#include "../../../util/session.h" #include "../../../util/target.h" #include "../../../util/tsc.h" -#include // page_size -#include "../../../util/intel-pt.h" -#include =20 #define KiB(x) ((x) * 1024) #define MiB(x) ((x) * 1024 * 1024) --=20 2.51.1.851.g4ebd6896fd-goog From nobody Sat Feb 7 22:21:10 2026 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 8D6342F7ACD for ; Wed, 29 Oct 2025 05:34:24 +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=1761716066; cv=none; b=CPJwlwoWUGgCRAp/a1aCgsf8kA1uApGgXsLTe3o7lXl2TqKD+7aipzQKwW/iXnDPU9jZR0v3J+jzwnAWF1N3xvBxL9j8dwtlAzXmobqwfIKfNELx2GgmkSMjIJVEisLQObrB7WfqCG80uynhj8aWmZ0vT0osQnCaunvtlUR5hkk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761716066; c=relaxed/simple; bh=rQBABjY2ZcI7bzoVi9MOUvkB6OWm9RvFP8qPtuA7Et4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=Oq7RSK++Dg0nqQTSF4KM96bdvkbtvo59+Z13YeQ4caBCZXyaUAhfjdVfnjEopDjg5ayp0toOHjeM19lrOnLvEy4Jjj0v0A8t2m3BZh3i+zhZ9MtuGbngoZQtH+oMaqtIpzW6XzbE7D+RgN8JFzshAAfBF/ONHKAoRGR8PThrq9M= 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=J4kh14A8; 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="J4kh14A8" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-3403e994649so284045a91.3 for ; Tue, 28 Oct 2025 22:34:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1761716064; x=1762320864; 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=dR63+sQBngTuWGvF49cBTkLmw7RMYV8Fq7W7/Lk4BTE=; b=J4kh14A8l+7ozTUmnedfenDSYrxKa1+HC0wCXHViFnWgQXM6tpT+K0zt3LWiy1ExzN vOJITGYUSBUAjkFBwhFfHADSCEeMxuX+aJKnRWDLMGcbvmVQ37o6rldjIcSqwsUf7acH RfY0wNWA019xfo/7G01j05d9gVfFAAxzIjX1maPyzwIqWMACYgGYZ3wd2xzHItHVt1zy 05HW13Da4UDm1ID3hZ3zRZUzaSrXT7g/yzobEQdHU9NHoEK5ZjNygVxMyT/yvYkZ9gU0 6yaMF77/Ek/TBgMQ8U+x2gKDYXPm7lF7un9Raq36gi3kDwpQhJptUBACnTbxJu9BIps+ P7gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761716064; x=1762320864; 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=dR63+sQBngTuWGvF49cBTkLmw7RMYV8Fq7W7/Lk4BTE=; b=MugvbqmI+PY1LcIR90xGUbndU8zck1tVHvlHyqT2OOwLjp3um13j6GXZDxiH6tdxAq UuFtL8XyYT6It/klvNMO5zvJhaNp+ZlCPT230JqNr23dHHlPj8xBT/zTDw+p53VGDqCk UfpDRrDEb0Hm0EyQp20ASUJkPjKOUUi0QOR1HhUOtEA3+joUwq32svfpylK4dGS4qdn5 e+gNPw4xqxLWo5+9D0p+kTUX+5IakeP7tTO41VcnC3ECC11L/Bwcrx6YNlRPt+bZcbTp pFABmxOdHRIPnAaBCBz8G/X1IgNR/qPxrQUl9nSgO6YD9A4NLU96NfX2qgngyKpkWrGr rAug== X-Forwarded-Encrypted: i=1; AJvYcCWvwbLv/WvQP764w7tv4zfTGmfXtu9ygFBB8p0z2k5B1bhwgoZQ9/1BKFCOHgYgbfpDZ+2A870z1t0umiI=@vger.kernel.org X-Gm-Message-State: AOJu0YxbfLugYV6TIar5fPWYGqpbIizHSceApZIGZt57e68Enm+NOnVv PqF3NXCi2Bmld+QTJRPEsVQ48v3htUdBZe9zxkYFbdDI7SS41I0n47+F9Pnn7drtW+tNxNYMtIi Cru4E3p8l6w== X-Google-Smtp-Source: AGHT+IFaRofd+fIISr/OLS3duPI/DGom8F/PI6KVPtolRQ7YsoC25vZxQqLqCVYXl7ckhJjYy4gcCkR4t4ba X-Received: from pjbci8.prod.google.com ([2002:a17:90a:fc88:b0:33b:bf1b:2cfa]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:4b09:b0:32e:e3af:45f6 with SMTP id 98e67ed59e1d1-3403a265529mr1978753a91.10.1761716063765; Tue, 28 Oct 2025 22:34:23 -0700 (PDT) Date: Tue, 28 Oct 2025 22:34:01 -0700 In-Reply-To: <20251029053413.355154-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: <20251029053413.355154-1-irogers@google.com> X-Mailer: git-send-email 2.51.1.851.g4ebd6896fd-goog Message-ID: <20251029053413.355154-4-irogers@google.com> Subject: [RFC PATCH v1 03/15] perf tests: Sort includes and add missed explicit dependencies From: Ian Rogers To: Suzuki K Poulose , Mike Leach , James Clark , John Garry , Will Deacon , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Greg Kroah-Hartman , Charlie Jenkins , Thomas Falcon , Yicong Yang , Thomas Richter , Athira Rajeev , Howard Chu , Song Liu , Dapeng Mi , Levi Yun , Zhongqiu Han , Blake Jones , Anubhav Shelat , Chun-Tse Shao , Christophe Leroy , Jean-Philippe Romain , Gautam Menghani , Dmitry Vyukov , Yang Li , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Andi Kleen , Weilin Wang Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Fix missing #includes found while cleaning the evsel/evlist header files. Sort the remaining header files for consistency with the rest of the code. Signed-off-by: Ian Rogers --- tools/perf/tests/hwmon_pmu.c | 12 +++++++----- tools/perf/tests/mmap-basic.c | 13 ++++++++----- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/tools/perf/tests/hwmon_pmu.c b/tools/perf/tests/hwmon_pmu.c index 151f02701c8c..97ea036ebae6 100644 --- a/tools/perf/tests/hwmon_pmu.c +++ b/tools/perf/tests/hwmon_pmu.c @@ -1,14 +1,16 @@ // SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) -#include "debug.h" -#include "evlist.h" -#include "hwmon_pmu.h" -#include "parse-events.h" -#include "tests.h" #include #include #include #include #include +#include "debug.h" +#include "evlist.h" +#include "hwmon_pmu.h" +#include "parse-events.h" +#include "pmus.h" +#include "tests.h" + =20 static const struct test_event { const char *name; diff --git a/tools/perf/tests/mmap-basic.c b/tools/perf/tests/mmap-basic.c index 3c89d3001887..a622bb8d4cc8 100644 --- a/tools/perf/tests/mmap-basic.c +++ b/tools/perf/tests/mmap-basic.c @@ -5,21 +5,24 @@ #include #include =20 +#include +#include +#include +#include +#include + #include "cpumap.h" #include "debug.h" #include "event.h" #include "evlist.h" #include "evsel.h" +#include "pmu.h" +#include "pmus.h" #include "thread_map.h" #include "tests.h" #include "util/affinity.h" #include "util/mmap.h" #include "util/sample.h" -#include -#include -#include -#include -#include =20 /* * This test will generate random numbers of calls to some getpid syscalls, --=20 2.51.1.851.g4ebd6896fd-goog From nobody Sat Feb 7 22:21:10 2026 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 1D76F2FB60E for ; Wed, 29 Oct 2025 05:34:25 +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=1761716067; cv=none; b=Nb641joksjv9y7n1jBgCFAzhgvg8Zzmb3YrYtkWze/gRMfdrdQ+pGrN6yyT6+Bhg7ueslh2T4h16/DnKC6Rzt0Cw+fWbINOJ/goqfDYC5fUjpMkEbEkR07SjDyNb1kcOX4FxgAz0vkZte9Xo8gp7eeCrko2rO3revVyP6JvjT4M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761716067; c=relaxed/simple; bh=ranWxnwVVnhb7a4sJ4cWUIXkpo3ejNkKQLJIyPpZgxk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=avBYhdd/KDoX/eVWa8649AzwM3gM8Xz8EV5wFJJAp66AGCDCAcPlRs7g7hM7yNQxGAFYfunih+nHBYMM5zNRG0ja1Jklsr0o1RkjczUztgki6ncNrTwlF5pGh/eCRzBlYtNM+lswncrCIj4KF4PdRThFbzoq1jViA4Ju12gfxIE= 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=b3WL2ZOq; 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="b3WL2ZOq" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-792722e4ebeso6213290b3a.3 for ; Tue, 28 Oct 2025 22:34:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1761716065; x=1762320865; 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=DUkEiwNTcxutgH1681ccYZp/nzKyRF3IgBfM6aUXBnU=; b=b3WL2ZOqjnIqbPIbb5GAc+4oxjmIdlgyZ2ry0Hd2nNRlZZQL+7buYAJiwC8MfTI/bZ rFgIJKNU49GgGZfxEYFEogyhDEkLRpR+WmrzoN6ktlS75up0kaokpOfoVL2nPY7MeNT+ UPRwvG1IadFmKAmjxzClcXmsfw3uloKh3KnWwaPICyM5OkcVtx3Kam3Au+pojGCWOLiB +dRyL81sMb1Yoo8BnhMtlBRmBWtdItnpOW66Ad4NSYm5+q6aS3H8Tg0CT10oF8ZrL9uw lq564lcR/SL8PisvS6ZmZAKXoDOJo1JiypaKS+d8qx8ckEPpA1jDN28qNUCeraxHZZMM oIPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761716065; x=1762320865; 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=DUkEiwNTcxutgH1681ccYZp/nzKyRF3IgBfM6aUXBnU=; b=pV/Xot56h6gLl9NER1NnQblv4KN9pa2uH09uflAhGul8SXG+v90MT+DYT4nh88jEzG Z5Qd0blTuMnshtOoVqw+0UMtpZECpzbXP6ygjlmJoUMq3YGOxfXTNROCBkcIDvowYnLP f9vWHpC4PK/LFePO4fCXKYDy8kj6oCBGzec1plAA/ZdQsodNlKhqC0FTbryjkFylncvp 2EFklb/Oh9/HJsqN1z/noPwqWeuvqhBq8Iw+dAZBPP+sqKVLVBhS/ryYNEQ1uH3gHnXl tflkuJ9AiR0JzNLgzMg97jc8i0/p0n7ESKNDf3A4a0Q7ICc2kUkgMI4SkPPsW0r6N3eN ZVxQ== X-Forwarded-Encrypted: i=1; AJvYcCVQ/EXDPK86L6mj1xR4y1gMveaqFsG1gbMR7lzHbuOmPDZVvi/I9Fl010ajO+pkDWvjqZ5xhfRKkcEWSVw=@vger.kernel.org X-Gm-Message-State: AOJu0YxohJWiXGShsdpAeOrLRdQ1OS4oadW8GUya9zJ8DA44Uf/jLhWT jvisqfh2D41BiE0TotaDdm3nH+gTouP8hN3u90yhnfYgPTvuDUuXlwBdgILva2l8Ml4815D8DPQ VnlxIh02TDQ== X-Google-Smtp-Source: AGHT+IF+BjckzF5VoiR/5cRXQMEHOdLbE4JXF2/bLj6EoYEqR1C0axI+NHBNSllDjqjUD87IOW62ah6aEKNq X-Received: from pjn8.prod.google.com ([2002:a17:90b:5708:b0:31f:2a78:943]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:3d84:b0:342:bf0d:a791 with SMTP id adf61e73a8af0-34652f52eeamr2110253637.27.1761716065291; Tue, 28 Oct 2025 22:34:25 -0700 (PDT) Date: Tue, 28 Oct 2025 22:34:02 -0700 In-Reply-To: <20251029053413.355154-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: <20251029053413.355154-1-irogers@google.com> X-Mailer: git-send-email 2.51.1.851.g4ebd6896fd-goog Message-ID: <20251029053413.355154-5-irogers@google.com> Subject: [RFC PATCH v1 04/15] perf script: Sort includes and add missed explicit dependencies From: Ian Rogers To: Suzuki K Poulose , Mike Leach , James Clark , John Garry , Will Deacon , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Greg Kroah-Hartman , Charlie Jenkins , Thomas Falcon , Yicong Yang , Thomas Richter , Athira Rajeev , Howard Chu , Song Liu , Dapeng Mi , Levi Yun , Zhongqiu Han , Blake Jones , Anubhav Shelat , Chun-Tse Shao , Christophe Leroy , Jean-Philippe Romain , Gautam Menghani , Dmitry Vyukov , Yang Li , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Andi Kleen , Weilin Wang Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Fix missing #include of pmu.h found while cleaning the evsel/evlist header files. Sort the remaining header files for consistency with the rest of the code. Doing this exposed a missing forward declaration of addr_location in print_insn.h, add this and sort the forward declarations. Signed-off-by: Ian Rogers --- tools/perf/builtin-script.c | 109 ++++++++++++++++++----------------- tools/perf/util/print_insn.h | 5 +- 2 files changed, 59 insertions(+), 55 deletions(-) diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 8124fcb51da9..6c3d98b51ee7 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -1,74 +1,77 @@ // SPDX-License-Identifier: GPL-2.0 #include "builtin.h" =20 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "archinsn.h" +#include "asm/bug.h" +#include "perf.h" +#include "print_binary.h" +#include "print_insn.h" +#include "ui/ui.h" +#include "util/annotate.h" +#include "util/auxtrace.h" +#include "util/cgroup.h" +#include "util/color.h" #include "util/counts.h" +#include "util/cpumap.h" +#include "util/data.h" #include "util/debug.h" +#include "util/dlfilter.h" #include "util/dso.h" -#include -#include "util/header.h" -#include -#include "util/perf_regs.h" -#include "util/session.h" -#include "util/tool.h" -#include "util/map.h" -#include "util/srcline.h" -#include "util/symbol.h" -#include "util/thread.h" -#include "util/trace-event.h" +#include "util/dump-insn.h" #include "util/env.h" +#include "util/event.h" #include "util/evlist.h" #include "util/evsel.h" #include "util/evsel_fprintf.h" #include "util/evswitch.h" +#include "util/header.h" +#include "util/map.h" +#include "util/mem-events.h" +#include "util/mem-info.h" +#include "util/path.h" +#include "util/perf_regs.h" +#include "util/pmu.h" +#include "util/record.h" +#include "util/session.h" #include "util/sort.h" -#include "util/data.h" -#include "util/auxtrace.h" -#include "util/cpumap.h" -#include "util/thread_map.h" +#include "util/srcline.h" #include "util/stat.h" -#include "util/color.h" #include "util/string2.h" +#include "util/symbol.h" #include "util/thread-stack.h" +#include "util/thread.h" +#include "util/thread_map.h" #include "util/time-utils.h" -#include "util/path.h" -#include "util/event.h" -#include "util/mem-info.h" -#include "ui/ui.h" -#include "print_binary.h" -#include "print_insn.h" -#include "archinsn.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include "asm/bug.h" -#include "util/mem-events.h" -#include "util/dump-insn.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "util/dlfilter.h" -#include "util/record.h" +#include "util/tool.h" +#include "util/trace-event.h" #include "util/util.h" -#include "util/cgroup.h" -#include "util/annotate.h" -#include "perf.h" =20 -#include #ifdef HAVE_LIBTRACEEVENT #include #endif diff --git a/tools/perf/util/print_insn.h b/tools/perf/util/print_insn.h index 07d11af3fc1c..a54f7e858e49 100644 --- a/tools/perf/util/print_insn.h +++ b/tools/perf/util/print_insn.h @@ -5,10 +5,11 @@ #include #include =20 -struct perf_sample; -struct thread; +struct addr_location; struct machine; struct perf_insn; +struct perf_sample; +struct thread; =20 #define PRINT_INSN_IMM_HEX (1<<0) =20 --=20 2.51.1.851.g4ebd6896fd-goog From nobody Sat Feb 7 22:21:10 2026 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.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 4099A2FB602 for ; Wed, 29 Oct 2025 05:34:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761716070; cv=none; b=oPa3+77caKD/y9rD+3fkwrQ9PomXcm4MsNpACwYuANTn03RMI4Nd0EO+fdT1MViesFhIKVZQ1kHj9YZ2DFD4z0+JNzH8nf7MJwbelK2XFJs01xwuL1qV4P7dx6lnzRghKebegnu0fEXhcA+cT/fglRSY7RYfofcCBbMzPu59ALY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761716070; c=relaxed/simple; bh=RCOWYW0eWdVan8nSdNr58xSEWGyXHpqrK98TvRvgRaI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=JMM8w0/dYiV1sL33egUR75HvpGIzGok3+YqKOP4ZK86Lx4YbA63kyo7We7q09DG+ouvM3oMpHSu0y3GNQ2/+mPy5IQ06TqV78v2qVMAJFga4MZWVoFDYhX6Is2cwC0EFAlDJytP4Dtxb9+vRoOFce/qd09+EqPtp7OQGWAI4Ifk= 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=XL6z7IoN; arc=none smtp.client-ip=209.85.128.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="XL6z7IoN" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-78103962c97so71895847b3.0 for ; Tue, 28 Oct 2025 22:34:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1761716067; x=1762320867; 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=THSPkwfdbOYwyEt2kIyr7orJhsGJmegrl3TMMEOJz4M=; b=XL6z7IoNE9pixp20OYkuIjGlaEAuHfUOuw4HLQsQGCmmd6aTtxBKTzYJjnGiKJ5ocT yem2GuD4ypEaK2r3yYabJi5LVMyQ1Y2mWu5NUAJKgRfIIjPqkBOvkdfY8mWG3YY9BoBr NgpYeukZHvEblIyvZKuzT9Pa/0MVJoXFgGRWjB0GAdYZ6PQQ7S+5AhFak4fz5e3q6gCF vzfqkcx8aZWRDpkKH+UYpHdASAOyufCAFYUwgWokO9HupOxZ9ZAQkagLoSUH66oqRdJJ EVBxSUqFYvpEtpR1UcwezEQaYc6i7btMnMG8axHXogvJfHmogbTXvJsjhIDQSsIAkr4A 1elg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761716067; x=1762320867; 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=THSPkwfdbOYwyEt2kIyr7orJhsGJmegrl3TMMEOJz4M=; b=X+p/MsFJsK2OSs0Lw2cBya0IW0uVEm2GNjUMkbSY4fMnWMEz0H8bzKn4DUDnOJOaro LJ7RgYkgEsX3XRnlNjYzCrYlgQROk6nmF/+p2eBuKAquJILX6gGaW3EGza7GjwcGJcis tE+sytBIrD6R/aAhJF9Ki8o+qN9GiWMiBQRAjb9qb5cYAVIw8tS3XYj6TTwxSnja0CTO 2xOf3F7AzMMMrprXie4rQfZ3koaaoAEEfY7QqxXG2TjQGn0pBz9S/9T+lutmeMDol7pS Cglu3GgmVA0g1k0H/5dCDq9NzOreXJDdWldHE32VGlGD3243/fehE/y6dYvxcr+yK0tE i/vg== X-Forwarded-Encrypted: i=1; AJvYcCUQRB58tC6eoHO5Q+7wwaQkdPnU/IqphmTHyDutChuBMKtmV1m57aXANhnOV3BqGcMEbVZzKsOk621lAcI=@vger.kernel.org X-Gm-Message-State: AOJu0YxHMqshH6Oe3XhkJpON1CFGoGD2XALb4cb6kz7jiKfSXGhtkD6R AWiZSnmEwEDm1qtgsDM+CGq4tN5lCq7awnCNn/SntSku/JsuGgfKOf15vFc9K+egXrt/zmNDbCi +UxOVJYstig== X-Google-Smtp-Source: AGHT+IHO5ntVJHgND97kqmZAzJ3mDz13n7CAuE5Jwt6yaOfFz/tSrxBkFQnE5UX83bEG1um2uV9otIRx1dPA X-Received: from ywbik2.prod.google.com ([2002:a05:690c:4a02:b0:783:777f:c91f]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:690c:23c6:b0:781:c87:c2fe with SMTP id 00721157ae682-78628fd908dmr17341407b3.56.1761716067252; Tue, 28 Oct 2025 22:34:27 -0700 (PDT) Date: Tue, 28 Oct 2025 22:34:03 -0700 In-Reply-To: <20251029053413.355154-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: <20251029053413.355154-1-irogers@google.com> X-Mailer: git-send-email 2.51.1.851.g4ebd6896fd-goog Message-ID: <20251029053413.355154-6-irogers@google.com> Subject: [RFC PATCH v1 05/15] perf util: Sort includes and add missed explicit dependencies From: Ian Rogers To: Suzuki K Poulose , Mike Leach , James Clark , John Garry , Will Deacon , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Greg Kroah-Hartman , Charlie Jenkins , Thomas Falcon , Yicong Yang , Thomas Richter , Athira Rajeev , Howard Chu , Song Liu , Dapeng Mi , Levi Yun , Zhongqiu Han , Blake Jones , Anubhav Shelat , Chun-Tse Shao , Christophe Leroy , Jean-Philippe Romain , Gautam Menghani , Dmitry Vyukov , Yang Li , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Andi Kleen , Weilin Wang Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Fix missing includes found while cleaning the evsel/evlist header files. Sort the remaining header files for consistency with the rest of the code. Signed-off-by: Ian Rogers --- tools/perf/util/bpf_off_cpu.c | 28 ++++++----- tools/perf/util/bpf_trace_augment.c | 7 +-- tools/perf/util/evlist.c | 78 ++++++++++++++--------------- tools/perf/util/evsel.c | 77 ++++++++++++++-------------- tools/perf/util/map.h | 6 +-- tools/perf/util/perf_api_probe.c | 17 ++++--- tools/perf/util/s390-sample-raw.c | 15 +++--- tools/perf/util/stat-shadow.c | 1 + tools/perf/util/stat.c | 15 +++--- 9 files changed, 127 insertions(+), 117 deletions(-) diff --git a/tools/perf/util/bpf_off_cpu.c b/tools/perf/util/bpf_off_cpu.c index 88e0660c4bff..707ab14aa4ca 100644 --- a/tools/perf/util/bpf_off_cpu.c +++ b/tools/perf/util/bpf_off_cpu.c @@ -1,22 +1,24 @@ // SPDX-License-Identifier: GPL-2.0 -#include "util/bpf_counter.h" -#include "util/debug.h" -#include "util/evsel.h" -#include "util/evlist.h" -#include "util/off_cpu.h" -#include "util/perf-hooks.h" -#include "util/record.h" -#include "util/session.h" -#include "util/target.h" -#include "util/cpumap.h" -#include "util/thread_map.h" -#include "util/cgroup.h" -#include "util/strlist.h" #include #include #include #include =20 +#include "bpf_counter.h" +#include "cgroup.h" +#include "cpumap.h" +#include "debug.h" +#include "evlist.h" +#include "evsel.h" +#include "off_cpu.h" +#include "parse-events.h" +#include "perf-hooks.h" +#include "record.h" +#include "session.h" +#include "strlist.h" +#include "target.h" +#include "thread_map.h" + #include "bpf_skel/off_cpu.skel.h" =20 #define MAX_STACKS 32 diff --git a/tools/perf/util/bpf_trace_augment.c b/tools/perf/util/bpf_trac= e_augment.c index 56ed17534caa..c2d502c1c358 100644 --- a/tools/perf/util/bpf_trace_augment.c +++ b/tools/perf/util/bpf_trace_augment.c @@ -1,9 +1,10 @@ #include #include =20 -#include "util/debug.h" -#include "util/evlist.h" -#include "util/trace_augment.h" +#include "debug.h" +#include "evlist.h" +#include "parse-events.h" +#include "trace_augment.h" =20 #include "bpf_skel/augmented_raw_syscalls.skel.h" =20 diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index e8217efdda53..d99a3f12606f 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -5,66 +5,66 @@ * Parts came from builtin-{top,stat,record}.c, see those files for further * copyright notes. */ -#include #include +#include #include #include -#include "cpumap.h" -#include "util/mmap.h" -#include "thread_map.h" -#include "target.h" -#include "evlist.h" -#include "evsel.h" -#include "record.h" -#include "debug.h" -#include "units.h" -#include "bpf_counter.h" -#include // page_size -#include "affinity.h" -#include "../perf.h" -#include "asm/bug.h" -#include "bpf-event.h" -#include "util/event.h" -#include "util/string2.h" -#include "util/perf_api_probe.h" -#include "util/evsel_fprintf.h" -#include "util/pmu.h" -#include "util/sample.h" -#include "util/bpf-filter.h" -#include "util/stat.h" -#include "util/util.h" -#include "util/env.h" -#include "util/intel-tpebs.h" -#include "util/metricgroup.h" -#include "util/strbuf.h" -#include -#include #include +#include #include - -#include "parse-events.h" -#include - -#include #include #include #include #include #include +#include =20 +#include +#include // page_size +#include #include +#include #include #include -#include #include #include #include +#include #include #include -#include #include +#include + +#include "../perf.h" +#include "affinity.h" +#include "asm/bug.h" +#include "bpf-event.h" +#include "bpf_counter.h" +#include "cpumap.h" +#include "debug.h" +#include "evlist.h" +#include "evsel.h" +#include "parse-events.h" +#include "record.h" +#include "target.h" +#include "thread_map.h" +#include "units.h" +#include "bpf-filter.h" +#include "env.h" +#include "event.h" +#include "evsel_fprintf.h" +#include "intel-tpebs.h" +#include "metricgroup.h" +#include "mmap.h" +#include "perf_api_probe.h" +#include "pmu.h" +#include "pmus.h" +#include "sample.h" +#include "stat.h" +#include "strbuf.h" +#include "string2.h" +#include "util.h" =20 -#include =20 #ifdef LACKS_SIGQUEUE_PROTOTYPE int sigqueue(pid_t pid, int sig, const union sigval value); diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index ad11cbfcbff1..6769cd27b6e4 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -12,66 +12,67 @@ #define __SANE_USERSPACE_TYPES__ =20 #include +#include #include #include -#include +#include +#include +#include +#include +#include + #include #include -#include -#include +#include +#include +#include +#include #include +#include #include +#include +#include #include -#include -#include -#include -#include -#include -#include +#include #include + +#include "../perf-sys.h" #include "asm/bug.h" +#include "bpf-filter.h" #include "bpf_counter.h" #include "callchain.h" #include "cgroup.h" #include "counts.h" +#include "debug.h" +#include "drm_pmu.h" +#include "env.h" #include "event.h" -#include "evsel.h" -#include "time-utils.h" -#include "util/env.h" -#include "util/evsel_config.h" -#include "util/evsel_fprintf.h" #include "evlist.h" -#include -#include "thread_map.h" -#include "target.h" +#include "evsel.h" +#include "evsel_config.h" +#include "evsel_fprintf.h" +#include "hashmap.h" +#include "hist.h" +#include "hwmon_pmu.h" +#include "intel-tpebs.h" +#include "memswap.h" +#include "off_cpu.h" +#include "parse-branch-options.h" #include "perf_regs.h" +#include "pmu.h" +#include "pmus.h" #include "record.h" -#include "debug.h" -#include "trace-event.h" +#include "rlimit.h" #include "session.h" #include "stat.h" #include "string2.h" -#include "memswap.h" -#include "util.h" -#include "util/hashmap.h" -#include "off_cpu.h" -#include "pmu.h" -#include "pmus.h" -#include "drm_pmu.h" -#include "hwmon_pmu.h" +#include "target.h" +#include "thread_map.h" +#include "time-utils.h" #include "tool_pmu.h" #include "tp_pmu.h" -#include "rlimit.h" -#include "../perf-sys.h" -#include "util/parse-branch-options.h" -#include "util/bpf-filter.h" -#include "util/hist.h" -#include -#include -#include -#include "util/intel-tpebs.h" - -#include +#include "trace-event.h" +#include "util.h" =20 #ifdef HAVE_LIBTRACEEVENT #include diff --git a/tools/perf/util/map.h b/tools/perf/util/map.h index 979b3e11b9bc..7cd5188fe628 100644 --- a/tools/perf/util/map.h +++ b/tools/perf/util/map.h @@ -2,13 +2,11 @@ #ifndef __PERF_MAP_H #define __PERF_MAP_H =20 -#include -#include -#include -#include #include #include #include + +#include #include #include =20 diff --git a/tools/perf/util/perf_api_probe.c b/tools/perf/util/perf_api_pr= obe.c index 6ecf38314f01..3345145a9307 100644 --- a/tools/perf/util/perf_api_probe.c +++ b/tools/perf/util/perf_api_probe.c @@ -1,13 +1,16 @@ /* SPDX-License-Identifier: GPL-2.0 */ +#include =20 -#include "perf-sys.h" -#include "util/cloexec.h" -#include "util/evlist.h" -#include "util/evsel.h" -#include "util/parse-events.h" -#include "util/perf_api_probe.h" #include -#include + +#include "cloexec.h" +#include "evlist.h" +#include "evsel.h" +#include "parse-events.h" +#include "perf-sys.h" +#include "perf_api_probe.h" +#include "pmu.h" +#include "pmus.h" =20 typedef void (*setup_probe_fn_t)(struct evsel *evsel); =20 diff --git a/tools/perf/util/s390-sample-raw.c b/tools/perf/util/s390-sampl= e-raw.c index 335217bb532b..a2d6a1f93cce 100644 --- a/tools/perf/util/s390-sample-raw.c +++ b/tools/perf/util/s390-sample-raw.c @@ -12,21 +12,22 @@ * sample was taken from. */ =20 -#include +#include #include #include -#include +#include =20 -#include -#include #include +#include +#include =20 +#include "color.h" #include "debug.h" -#include "session.h" #include "evlist.h" -#include "color.h" -#include "sample-raw.h" +#include "pmus.h" #include "s390-cpumcf-kernel.h" +#include "sample-raw.h" +#include "session.h" #include "util/pmu.h" #include "util/sample.h" =20 diff --git a/tools/perf/util/stat-shadow.c b/tools/perf/util/stat-shadow.c index abaf6b579bfc..3588b469de9d 100644 --- a/tools/perf/util/stat-shadow.c +++ b/tools/perf/util/stat-shadow.c @@ -6,6 +6,7 @@ #include "color.h" #include "debug.h" #include "pmu.h" +#include "pmus.h" #include "rblist.h" #include "evlist.h" #include "expr.h" diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c index 101ed6c497bc..c1c44c417c93 100644 --- a/tools/perf/util/stat.c +++ b/tools/perf/util/stat.c @@ -1,21 +1,24 @@ // SPDX-License-Identifier: GPL-2.0 #include -#include #include #include #include + +#include +#include + #include "counts.h" #include "cpumap.h" #include "debug.h" +#include "evlist.h" +#include "evsel.h" +#include "hashmap.h" #include "header.h" -#include "stat.h" +#include "pmu.h" #include "session.h" +#include "stat.h" #include "target.h" -#include "evlist.h" -#include "evsel.h" #include "thread_map.h" -#include "util/hashmap.h" -#include =20 void update_stats(struct stats *stats, u64 val) { --=20 2.51.1.851.g4ebd6896fd-goog From nobody Sat Feb 7 22:21:10 2026 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 F0D102F12C7 for ; Wed, 29 Oct 2025 05:34:29 +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=1761716071; cv=none; b=uGscmwjtLQRaIL2xnSSVQrlXFhlleAyvgAtLfn+JYbW0pfWeCC1VzQI8Qyr0jhZnnDw0vvxgR/j+8dbqwVVbgebUowYxLZM9OtnynrpCCPvqxfM/mO535gBpo8qlnSmZGjguhDnZlL0wsqwjvVPs6avnDKWgn9euqR3VD2sQo+4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761716071; c=relaxed/simple; bh=KYZYhoiep3KHKYom3Zxs1sXwmI85jni0UlVUbeI2XEA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=R7gRaEHjlwXI+GsifVep+pL5ngtwCIQOxP5VIij3M0uHVoV8Wx7RQ97ekUs1jT684ERTuedDPCjSRT7EIhPjsCXu9BBzjnIz7/AndIhsD3igYHn95KfWpT/yb2SXShqHNeTonPNbvheZFkvpB48sBavfukzD3Yd9Yjrt7chCfak= 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=Nbw3OGJo; 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="Nbw3OGJo" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-294880e7ca4so120509085ad.0 for ; Tue, 28 Oct 2025 22:34:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1761716069; x=1762320869; 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=pW3iPoPH/G2JC3s4g+WDYgzHzmDlxJjv1jy/9KHXcKA=; b=Nbw3OGJo+rnt48QSyZgtHZkbDavdtp9pHR8BGGvWAV/+9xfD9Hp0ZVkMN8P2ltWOaz hficBc5jdLiDC3bU1JYwVaYGttw++/B9Sfk2Jur+2t3D+Fcf7MhMYghWAv0dUeaTojWW hzsybNWwuK3exBurgQtqjtS2HwyJM0Z48O+VTnTQom3zcWbF1gaur0V9pS8ctRapcK7M I+nxrvbkkY1qZIq8oVjvF6G64xdKYdJ7idselo5T0kfGN6KcnoZ7QCWwH3DugrCek2V4 EDE25r3CXzVr0NUbR0ZAB0UQlYKR03CAI9l6KYqwsOIjDpKApgcy1PzOThs9ZpuCjHEC f/7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761716069; x=1762320869; 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=pW3iPoPH/G2JC3s4g+WDYgzHzmDlxJjv1jy/9KHXcKA=; b=KbRtPnXR892tJggR1DQvM/1ucExrgwoXh6M4UkV2WM5s+2f9eu/Ves+jBfGm9WnIQi hnXphLTQwvPFdq4ZwxOcL6FFivWUvW0vzwRbldn+wAI9GRvn2+l9Fs6oi4iduhDMHe5A aukl264oBsjg0pVdfsETVeaMPe972Dsr5W3YTea8hiLEzo1WV3p5KDm/OW4kgjVaPtDF E3tdeM59/UL4jUuHKVgdsP7RDlB8Xii4JjFjrB+l4DHAn+fCWrK/u3qnAHMyPCNtYryU dKqu44IwVqzNEdxgFtWZsfnMtIzfh515sA/4+roZ44JOWPxjgGyjku3zf9d/X0TrnoB3 FcTA== X-Forwarded-Encrypted: i=1; AJvYcCVrS1YmSJhWd0X5l6mJ/aMf50MyugUZT5nAMh8k9yfUCg3NwfeJNYEizpPQ6f8318n2Es6siaYJ/+QpVo0=@vger.kernel.org X-Gm-Message-State: AOJu0YyU+Fj24FLj9Q/D58kaoe0Y5/Xb3WChDnQpSpi5b0tvOtvnqxtV nMKZWh4hNcWwfbAtnfOy2T36dIyV1SxAS5iHBuGocA1Ss0HxS9VPB6RTy4W8hzUjCQ2N6ywnLLS fz9KYVh0Sjg== X-Google-Smtp-Source: AGHT+IHkOM4Uz1plX/1V7B8s2UzjmVdM7pC7uU+GhzKDrWisEtFUM/NjdRl5/HzXEOoYBKFOyAOC0WdbgzoV X-Received: from pldu20.prod.google.com ([2002:a17:903:1094:b0:290:ab6a:13c3]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:1585:b0:26f:7db2:3e1e with SMTP id d9443c01a7336-294deeed0d9mr22357265ad.47.1761716069136; Tue, 28 Oct 2025 22:34:29 -0700 (PDT) Date: Tue, 28 Oct 2025 22:34:04 -0700 In-Reply-To: <20251029053413.355154-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: <20251029053413.355154-1-irogers@google.com> X-Mailer: git-send-email 2.51.1.851.g4ebd6896fd-goog Message-ID: <20251029053413.355154-7-irogers@google.com> Subject: [RFC PATCH v1 06/15] perf python: Add add missed explicit dependencies From: Ian Rogers To: Suzuki K Poulose , Mike Leach , James Clark , John Garry , Will Deacon , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Greg Kroah-Hartman , Charlie Jenkins , Thomas Falcon , Yicong Yang , Thomas Richter , Athira Rajeev , Howard Chu , Song Liu , Dapeng Mi , Levi Yun , Zhongqiu Han , Blake Jones , Anubhav Shelat , Chun-Tse Shao , Christophe Leroy , Jean-Philippe Romain , Gautam Menghani , Dmitry Vyukov , Yang Li , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Andi Kleen , Weilin Wang Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Fix missing #include of pmus.h found while cleaning the evsel/evlist header files. Signed-off-by: Ian Rogers --- tools/perf/util/python.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index fa5e4270d182..0366142184d8 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -15,6 +15,7 @@ #include "evsel.h" #include "event.h" #include "expr.h" +#include "pmus.h" #include "print_binary.h" #include "record.h" #include "strbuf.h" --=20 2.51.1.851.g4ebd6896fd-goog From nobody Sat Feb 7 22:21:10 2026 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 782EA2FFFAB for ; Wed, 29 Oct 2025 05:34:31 +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=1761716073; cv=none; b=I0akQcH9Fk88Gmy11Ck/ZcWk/faq8SgERdPNa3gVhEb3PgMeXVYGh6bXQtl7+RHSSz0I4bMTkoyWSw+oU8/P65zw4QHg3gqBNO6LAA6HvBfF6kgjmofMyOWhOLHZMX3pKucYBQX9j9AdbfHhEybc8PDnoL9hilBcGaU6NgFMNwc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761716073; c=relaxed/simple; bh=nxogn7CzCOcaoMnM/yWVx3HVxrL+JJuNtx6lpItOEXE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=ScenFU4ulTzLjRNZY88XGb5IcZ+QGqIBzIk/MCDoI+pZ9YdPSn7g23AvtNaFISgE5Gjsm+cu+GIRSoFbNpliHqiR3O5C7A7kpHt6zdW0eRtr6cEes/wO9WPqIudHwHZ2h6gpMYzLHvciokyQq43YGxQwMPXCcZYTCuFq4J06gb0= 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=XJmP08vb; 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="XJmP08vb" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-33bbbb41a84so14927592a91.1 for ; Tue, 28 Oct 2025 22:34:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1761716071; x=1762320871; 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=P/m+GGJEX4XS9igs9SnnZKBVhxyHpjFasFgfyaBk6K8=; b=XJmP08vbE3WlHd+L5ja0CmJMQii/AfjZfocrQ1yI9wgTjYH0ZPYK03M3ICiW47+wXN ySdQ+jNn4mTDsIkQBFWlghZ+R8nhnjyZrMOh+BBAJRICO61opn65ZLXDSv9eqAN8NT/K m1m9QU7Il1Nxsc3k2Y7c7vj2B7z7twG6cAV5rRrwDt5jOm2KgZ5giZ/1P6z2SJmAet31 QqONK1zGG1j9PPRVQwlx3+Jadg9dDwxORxh4tyOPGxLYGLAk/iRLSMMR8ijW1+hZZpc0 hOyWqlJP3ZvfRJrSmQJNyFYgs6xVZuZWjB3ZpwuuDxCVIjZG9DHpjjjYcHTgdB41viP9 VCTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761716071; x=1762320871; 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=P/m+GGJEX4XS9igs9SnnZKBVhxyHpjFasFgfyaBk6K8=; b=hctxsO9UPOgj9jG7rQtR91ZWXABIAHLFHzYfx9CDR/GVu1V9QYX827mJgVSMIZ/KSk LSkfuG8DOXSv3AwUa8Bh1TOIb5Ifi6bbfEB2IlkMHR1QOh4ry1WTfIyDEXHjez6GRo7s V1cJglWdsB51FAlarPOKxwF0sPxOW0zErdtS8dJnQeDtA7TY+iqEdXfPY6H/YEhYApK0 h0EqRmCescKkScA/WEL1RNHI5v/iHuYr7EWa18QQnE59jMRkg3dxZD06f3dAvD6w9UpH fV0qvufKp8iWJCohaS7gRvsJszScoX/x4Xljvz2O/lpMqEvNRkxorPAkt9A+mUQAYj31 x2mw== X-Forwarded-Encrypted: i=1; AJvYcCUPgIqbh2CKbvewyRSDj++qpjA4baW+mCaz0Qrxw28ihR9cfuRMKZpxHUUegim3Z4dRcVMgaOCUOfpglbs=@vger.kernel.org X-Gm-Message-State: AOJu0Yy0Q6T1+xb6qtq7efEi4RxlJXYnpSQMOIROqbiAnV8cRqoPbPx6 5m3+SIEUCLV5soagify09K3/eiTgg9oi73WfiYGWKBhI8Z+SMQR2tTZEnAXK/SaF+qHu7MBEjzj St8FXWJB5AQ== X-Google-Smtp-Source: AGHT+IFa/+7mOOLGV31OTSxrEinUSkkcBJPH0/NM79JpffezlY8J1bwcb9IheSMk05AgTiw07XZTVKFycJDn X-Received: from plhc9.prod.google.com ([2002:a17:903:2349:b0:288:e43f:73ce]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:2348:b0:25d:37fc:32df with SMTP id d9443c01a7336-294deedb5c6mr21426035ad.47.1761716070749; Tue, 28 Oct 2025 22:34:30 -0700 (PDT) Date: Tue, 28 Oct 2025 22:34:05 -0700 In-Reply-To: <20251029053413.355154-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: <20251029053413.355154-1-irogers@google.com> X-Mailer: git-send-email 2.51.1.851.g4ebd6896fd-goog Message-ID: <20251029053413.355154-8-irogers@google.com> Subject: [RFC PATCH v1 07/15] perf evsel/evlist: Avoid unnecessary #includes From: Ian Rogers To: Suzuki K Poulose , Mike Leach , James Clark , John Garry , Will Deacon , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Greg Kroah-Hartman , Charlie Jenkins , Thomas Falcon , Yicong Yang , Thomas Richter , Athira Rajeev , Howard Chu , Song Liu , Dapeng Mi , Levi Yun , Zhongqiu Han , Blake Jones , Anubhav Shelat , Chun-Tse Shao , Christophe Leroy , Jean-Philippe Romain , Gautam Menghani , Dmitry Vyukov , Yang Li , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Andi Kleen , Weilin Wang Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use forward declarations and remove unnecessary #includes in evsel.h and evlist.h. Sort the forward declaration.s Signed-off-by: Ian Rogers --- tools/perf/util/evlist.h | 16 +++++++++------- tools/perf/util/evsel.h | 19 ++++++++++--------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h index 5e71e3dc6042..61acbb10d9a5 100644 --- a/tools/perf/util/evlist.h +++ b/tools/perf/util/evlist.h @@ -2,28 +2,30 @@ #ifndef __PERF_EVLIST_H #define __PERF_EVLIST_H 1 =20 +#include +#include +#include + #include #include -#include #include +#include #include #include -#include #include + #include "events_stats.h" #include "evsel.h" #include "rblist.h" -#include -#include -#include =20 -struct pollfd; -struct thread_map; +struct evsel; struct perf_cpu_map; struct perf_stat_config; +struct pollfd; struct record_opts; struct strbuf; struct target; +struct thread_map; =20 /* * State machine of bkw_mmap_state: diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index f8de0f9a719b..f4540920604e 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -2,28 +2,29 @@ #ifndef __PERF_EVSEL_H #define __PERF_EVSEL_H 1 =20 -#include #include #include + +#include +#include #include #include -#include #include + #include "symbol_conf.h" -#include "pmus.h" -#include "pmu.h" =20 +struct bperf_follower_bpf; +struct bperf_leader_bpf; +struct bpf_counter_ops; struct bpf_object; struct cgroup; +struct hashmap; struct perf_counts; +struct perf_pmu; struct perf_stat_config; struct perf_stat_evsel; -union perf_event; -struct bpf_counter_ops; struct target; -struct hashmap; -struct bperf_leader_bpf; -struct bperf_follower_bpf; +union perf_event; =20 typedef int (evsel__sb_cb_t)(union perf_event *event, void *data); =20 --=20 2.51.1.851.g4ebd6896fd-goog From nobody Sat Feb 7 22:21:10 2026 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 2A06A301027 for ; Wed, 29 Oct 2025 05:34:33 +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=1761716074; cv=none; b=sog/1HKjJjZf8O/wM121w0WJRs9U1lWOdWPwqh37Fo9g94M9eroZx+ll/+pc+Xwe5yes53YQDn1pCxbXEOIrF95YFQt0JO4zOU4XK5XXVAaP6TntkcXMjdRI2BujbITXX36jjBsnTaFMheYTCoHzxco2PdDHbNMBsFyDupkk2as= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761716074; c=relaxed/simple; bh=FpTNaUgVqmGmNx+bs8r+sBPdEgElqkdTfPkxVn0Dheg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=ALC7FM5zsJObVhCFFTOBeP4ZfXGwLquINF39EhgvSjM3rPh76vxdWbwiyUl2Lpi07rxTdQdcmHBIfPgI+uxEC1tHveWzEK6IuWOCARAQY/wAE8wSVEGmXi6ntQYKJjz4y5hGpkVQvJLDPsfdJVTf4vnpBOR8H0Cmx/J4Wr5cVY0= 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=BFh/Q84l; 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="BFh/Q84l" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-33d8970ae47so6321745a91.1 for ; Tue, 28 Oct 2025 22:34:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1761716072; x=1762320872; 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=cXh9vvoEB9Xb55r/nl1gF45ib8UAR7LGEcM4G2fJGr4=; b=BFh/Q84lpAFXB9NGqxntPcB2KPeHXTY9IbsQk+d6jOZXRd6oCfcjeKQDjuBpXRVDQz S2OzuI5JZ10AOAlH30fEY91Dp/QWUfM07H07gAgGnevBAlerPK3QoL2nd7iCqEyNHZXj 98bRjRrCXMwP0YaeDDrbOMZMgVdX+haYre9fbfJZfa/NJFM834nZXUP8np/40ranva7t 3+B/Iq1vkHYPoSgvdOXvpDb/e0ERmRSlWOX2uzx2LqcgiwnKYXpXDSj1Sd1yzp5uRKTq fqZwdGqWEr1hNOgKSqQMEAgpzOHHxTmscxtWL6Huh4WWOnCGQ3JwP+rh62u7sfRygqOI uAGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761716072; x=1762320872; 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=cXh9vvoEB9Xb55r/nl1gF45ib8UAR7LGEcM4G2fJGr4=; b=mO04+BuZAquBMjqrLJxiIA9eSo6/5Jg1iA7DmIbXLlYn41qEMTWOUAc5SLn000zV3q TTGfaEvlzNhs+HXcTP153xx3A2dtdOZdX82XsG71LpFqdMr5I479jcqLC+C0obrLc2IK G7U+o0BNfvB0BlQlek14vnS7YEhfX+iCogbM4lADuT2PIUl1WbEq6BsrhRspi4EvNzGA jvdsfSWvTBNYdj4+9cG5KdzzFITIFpQMXEmSeQWuJyCsSn3pvLOorBzDMdhgcnkKPZH1 uKtacxmdRO/G3OaavKGmTddwaA2t/7kw23dl4ugM3DeeudLFlAlTmvCWEeeG0wV9CRYp bvEA== X-Forwarded-Encrypted: i=1; AJvYcCWTn5Eg2sAVRGjy/rhEwU6CQyBMGxJpdqF8Dhhrm3e5wys2TbgUyaBvXkssnMot/ixmixBI20ai17Mxokk=@vger.kernel.org X-Gm-Message-State: AOJu0YxeMhY48XJrIO7PdpXijaRTdp28sIbUnyHJD9QSp7QelFyHVFUd wX0nvQtw2RayjaFc4A9UfwNcGMpUaK4pJ2anxjt2kV+7ig7Bx2OBfxFhCtzTEIuUuCUVSVFW4Rs aNDKGDZqtsw== X-Google-Smtp-Source: AGHT+IFYFiJlBRaGLzSEmcCEbMSqw7Tcy2yTZ+uTBtdINjm9r1zrdE4366XK6lGXYL8X+Dma5glPmwjlqQdn X-Received: from pjbhd9.prod.google.com ([2002:a17:90b:4589:b0:33e:3482:597b]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:3ec4:b0:33b:b020:5968 with SMTP id 98e67ed59e1d1-3403a2a2304mr2228319a91.21.1761716072438; Tue, 28 Oct 2025 22:34:32 -0700 (PDT) Date: Tue, 28 Oct 2025 22:34:06 -0700 In-Reply-To: <20251029053413.355154-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: <20251029053413.355154-1-irogers@google.com> X-Mailer: git-send-email 2.51.1.851.g4ebd6896fd-goog Message-ID: <20251029053413.355154-9-irogers@google.com> Subject: [RFC PATCH v1 08/15] perf maps: Move getting debug_file to verbose path From: Ian Rogers To: Suzuki K Poulose , Mike Leach , James Clark , John Garry , Will Deacon , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Greg Kroah-Hartman , Charlie Jenkins , Thomas Falcon , Yicong Yang , Thomas Richter , Athira Rajeev , Howard Chu , Song Liu , Dapeng Mi , Levi Yun , Zhongqiu Han , Blake Jones , Anubhav Shelat , Chun-Tse Shao , Christophe Leroy , Jean-Philippe Romain , Gautam Menghani , Dmitry Vyukov , Yang Li , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Andi Kleen , Weilin Wang Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Getting debug_file can trigger warnings if not set. Avoid getting these warnings by pushing the use under the controlling if. Signed-off-by: Ian Rogers --- tools/perf/util/maps.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tools/perf/util/maps.c b/tools/perf/util/maps.c index 779f6230130a..44cfd63f10dc 100644 --- a/tools/perf/util/maps.c +++ b/tools/perf/util/maps.c @@ -811,7 +811,6 @@ static int __maps__insert_sorted(struct maps *maps, uns= igned int first_after_ind static int __maps__fixup_overlap_and_insert(struct maps *maps, struct map = *new) { int err =3D 0; - FILE *fp =3D debug_file(); unsigned int i, ni =3D INT_MAX; // Some gcc complain, but depends on maps= _by_name... =20 if (!maps__maps_by_address_sorted(maps)) @@ -839,8 +838,8 @@ static int __maps__fixup_overlap_and_insert(struct maps= *maps, struct map *new) dso__name(map__dso(new))); } else if (verbose >=3D 2) { pr_debug("overlapping maps:\n"); - map__fprintf(new, fp); - map__fprintf(pos, fp); + map__fprintf(new, debug_file()); + map__fprintf(pos, debug_file()); } =20 if (maps_by_name) @@ -861,7 +860,7 @@ static int __maps__fixup_overlap_and_insert(struct maps= *maps, struct map *new) map__set_end(before, map__start(new)); =20 if (verbose >=3D 2 && !use_browser) - map__fprintf(before, fp); + map__fprintf(before, debug_file()); } if (map__end(new) < map__end(pos)) { /* The new map isn't as long as the existing map. */ @@ -879,7 +878,7 @@ static int __maps__fixup_overlap_and_insert(struct maps= *maps, struct map *new) map__map_ip(after, map__end(new))); =20 if (verbose >=3D 2 && !use_browser) - map__fprintf(after, fp); + map__fprintf(after, debug_file()); } /* * If adding one entry, for `before` or `after`, we can replace --=20 2.51.1.851.g4ebd6896fd-goog From nobody Sat Feb 7 22:21:10 2026 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 AE27C302CA4 for ; Wed, 29 Oct 2025 05:34:34 +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=1761716076; cv=none; b=kREb8Q7KJcrFuJJRysqAMcBJY3QNQIiskqnm6tye+1EGsYZbv427/gE5tSTF95OynHC4U3s6JIz/pZNdPQoXNoudSK/GNicyLR7X5NoFeemEwispxl/UPoDBb19/auV+cuuiQldNisbDYl9Xiyj6dwCEQCXRigQJUZ5B3ldcfuE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761716076; c=relaxed/simple; bh=74LyauEa54VSeyBugbC9rVUwrSwDFISXcFDxOO63Khs=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=H6i3WaIh0RpzhJtg5UVikkGHMC2PDixcoFWtKpq2wvEC2v+E3FLbSUxsywuRfg5StUXnDZBBJuI0Zc26xHy7U7jxU+PusRB29zTxwadqgxjsnSphPxazddV55vbHm44hKtkh9Wyos4EMb3MjdelzXstLefMSXkbCl/BHN1ARTec= 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=afvsTekO; 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="afvsTekO" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-33bbbb41a84so14927661a91.1 for ; Tue, 28 Oct 2025 22:34:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1761716074; x=1762320874; 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=w2IX0DiDTomYBm5p1BWLB1HY9azDnjX1LkSLbsVS32A=; b=afvsTekOd8bVUWUBXV4G4PxlOsuJQ5nuTLnHsoSJZNrMSKmkVXwYzmYLV61w6yQ1Sr VI02ta1NP67jxQs1+HYDi2IQIFqa1KZ3NllxdZtdGjFeSLFVENt/VCOOzJTehORQZLmA cTH7FbgW9N1h2zQN0l1GK4ROwcsp3rqw/ZeqzpIBZ/bl8gMl4/NEZWnp3sKWdkNQnI+B HIDiOMneXkegIfoYG2haFw8TKp3RRZVMxrth8S8xiAmsNwWvt9rgeWzKm5CHyvZuwfqK kHi59AmURUpVEhIA7q1cGkMCMWvZt9QlPjJ6+4ANRuKB3E7EPUjr3bl7JScEinvOAaxE +1aw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761716074; x=1762320874; 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=w2IX0DiDTomYBm5p1BWLB1HY9azDnjX1LkSLbsVS32A=; b=vUu/lemgkeDAyj1GnbdlC2ZVofOaf+d48XavMqz+RH2pVXFxWDxT8PVSkpsI36/8jr ENzaKes5bhh6dWZZEFQkYKFwIq6p2khviSlY50neG2qm359slp1HvNOdi/koBkZOuxs/ kk/Ria4atdzYbdLwqeDXJ7HBbs3HeErUxGvL8TSfBQevkzhVCVI6jHWxImy39VKSIaXV FIqnFZoSNa1RrRBbjPGq6D+q0Hoq/g/anY9Pdg1/Jkz0M/m1feVowevnzbgrteo28fpF FVmjBpV2TcyvbvwN/cuP3Lst0Hsh+WJ1Wey8v6Qp1TBr9auZzk/Jb7hgV4sCIoDED+wZ 5uWQ== X-Forwarded-Encrypted: i=1; AJvYcCWNPG44U7QvURpsVZjpIaA2BKb2yN+WLZZmy/j1x+DzLwGVI8ywawHUibHlndlnRPf336mIYa2CRIZCmiE=@vger.kernel.org X-Gm-Message-State: AOJu0Yy0h+IAISbtxXU2hSrgQj80XhTzbYHLVpz8YiW+fEQJDOKxkAZY 9HftRLOMIrmYPCx61aFpzoGTmZSI+JX0reUIP67uEHuNyLLN4HCGquhJFoa4ebF5H5NSb4Bzss7 e8vZ5ehhGbQ== X-Google-Smtp-Source: AGHT+IFiKkz/9OzVUG9X/jUDA0Ctos0V8/bNH6kNseIOK99SlYBiURzIzAp3RpTufC5uxH7Urtm1a+WEoomM X-Received: from plrs15.prod.google.com ([2002:a17:902:b18f:b0:290:28e2:ce44]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:d512:b0:262:9c4:5470 with SMTP id d9443c01a7336-294dee9966emr21879795ad.28.1761716074024; Tue, 28 Oct 2025 22:34:34 -0700 (PDT) Date: Tue, 28 Oct 2025 22:34:07 -0700 In-Reply-To: <20251029053413.355154-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: <20251029053413.355154-1-irogers@google.com> X-Mailer: git-send-email 2.51.1.851.g4ebd6896fd-goog Message-ID: <20251029053413.355154-10-irogers@google.com> Subject: [RFC PATCH v1 09/15] perf data: Clean up use_stdio and structures From: Ian Rogers To: Suzuki K Poulose , Mike Leach , James Clark , John Garry , Will Deacon , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Greg Kroah-Hartman , Charlie Jenkins , Thomas Falcon , Yicong Yang , Thomas Richter , Athira Rajeev , Howard Chu , Song Liu , Dapeng Mi , Levi Yun , Zhongqiu Han , Blake Jones , Anubhav Shelat , Chun-Tse Shao , Christophe Leroy , Jean-Philippe Romain , Gautam Menghani , Dmitry Vyukov , Yang Li , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Andi Kleen , Weilin Wang Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" use_stdio was associated with struct perf_data and not perf_data_file meaning there was implicit use of fd rather than fptr that may not be safe. For example, in perf_data_file__write. Reorganize perf_data_file to better abstract use_stdio, add kernel-doc and more consistently use perf_data__ accessors so that use_stdio is better respected. Signed-off-by: Ian Rogers --- tools/perf/builtin-inject.c | 7 ++-- tools/perf/builtin-record.c | 10 +++-- tools/perf/tests/topology.c | 3 +- tools/perf/util/data.c | 81 ++++++++++++++++++++++++------------- tools/perf/util/data.h | 52 ++++++++++++++++++++---- tools/perf/util/session.c | 2 +- 6 files changed, 109 insertions(+), 46 deletions(-) diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index a114b3fa1bea..bc2725dcdc8c 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c @@ -269,9 +269,8 @@ static s64 perf_event__repipe_auxtrace(struct perf_sess= ion *session, inject->have_auxtrace =3D true; =20 if (!inject->output.is_pipe) { - off_t offset; + off_t offset =3D perf_data__seek(&inject->output, 0, SEEK_CUR); =20 - offset =3D lseek(inject->output.file.fd, 0, SEEK_CUR); if (offset =3D=3D -1) return -errno; ret =3D auxtrace_index__auxtrace_event(&session->auxtrace_index, @@ -2364,12 +2363,12 @@ int cmd_inject(int argc, const char **argv) .output =3D { .path =3D "-", .mode =3D PERF_DATA_MODE_WRITE, - .use_stdio =3D true, + .file.use_stdio =3D true, }, }; struct perf_data data =3D { .mode =3D PERF_DATA_MODE_READ, - .use_stdio =3D true, + .file.use_stdio =3D true, }; int ret; const char *known_build_ids =3D NULL; diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index cb52aea9607d..3d8cf4090a92 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -453,7 +453,7 @@ static int record__aio_pushfn(struct mmap *map, void *t= o, void *buf, size_t size static int record__aio_push(struct record *rec, struct mmap *map, off_t *o= ff) { int ret, idx; - int trace_fd =3D rec->session->data->file.fd; + int trace_fd =3D perf_data__fd(rec->session->data); struct record_aio aio =3D { .rec =3D rec, .size =3D 0 }; =20 /* @@ -1676,7 +1676,7 @@ static int record__mmap_read_evlist(struct record *re= c, struct evlist *evlist, int rc =3D 0; int nr_mmaps; struct mmap **maps; - int trace_fd =3D rec->data.file.fd; + int trace_fd =3D perf_data__fd(&rec->data); off_t off =3D 0; =20 if (!evlist) @@ -1885,8 +1885,10 @@ record__finish_output(struct record *rec) rec->session->header.data_size +=3D rec->bytes_written; data->file.size =3D lseek(perf_data__fd(data), 0, SEEK_CUR); if (record__threads_enabled(rec)) { - for (i =3D 0; i < data->dir.nr; i++) - data->dir.files[i].size =3D lseek(data->dir.files[i].fd, 0, SEEK_CUR); + for (i =3D 0; i < data->dir.nr; i++) { + data->dir.files[i].size =3D + perf_data_file__seek(&data->dir.files[i], 0, SEEK_CUR); + } } =20 /* Buildid scanning disabled or build ID in kernel and synthesized map ev= ents. */ diff --git a/tools/perf/tests/topology.c b/tools/perf/tests/topology.c index ec01150d208d..af4618c3124a 100644 --- a/tools/perf/tests/topology.c +++ b/tools/perf/tests/topology.c @@ -52,7 +52,8 @@ static int session_write_header(char *path) session->header.data_size +=3D DATA_SIZE; =20 TEST_ASSERT_VAL("failed to write header", - !perf_session__write_header(session, session->evlist, data.file.fd, tru= e)); + !perf_session__write_header(session, session->evlist, + perf_data__fd(&data), true)); =20 evlist__delete(session->evlist); perf_session__delete(session); diff --git a/tools/perf/util/data.c b/tools/perf/util/data.c index 164eb45a0b36..0dcd4b8c51ce 100644 --- a/tools/perf/util/data.c +++ b/tools/perf/util/data.c @@ -20,18 +20,30 @@ #include "rlimit.h" #include =20 -static void close_dir(struct perf_data_file *files, int nr) +static void perf_data_file__close(struct perf_data_file *file) { - while (--nr >=3D 0) { - close(files[nr].fd); - zfree(&files[nr].path); + if (file->use_stdio) { + fclose(file->fptr); + file->fptr =3D NULL; + } else { + close(file->fd); + file->fd =3D -1; } + zfree(&file->path); +} + +static void close_dir(struct perf_data_file *files, int nr) +{ + while (--nr >=3D 0) + perf_data_file__close(&files[nr]); + free(files); } =20 void perf_data__close_dir(struct perf_data *data) { close_dir(data->dir.files, data->dir.nr); + data->dir.files =3D NULL; } =20 int perf_data__create_dir(struct perf_data *data, int nr) @@ -174,7 +186,7 @@ static bool check_pipe(struct perf_data *data) } =20 if (is_pipe) { - if (data->use_stdio) { + if (data->file.use_stdio) { const char *mode; =20 mode =3D perf_data__is_read(data) ? "r" : "w"; @@ -182,7 +194,7 @@ static bool check_pipe(struct perf_data *data) =20 if (data->file.fptr =3D=3D NULL) { data->file.fd =3D fd; - data->use_stdio =3D false; + data->file.use_stdio =3D false; } =20 /* @@ -353,7 +365,7 @@ int perf_data__open(struct perf_data *data) return 0; =20 /* currently it allows stdio for pipe only */ - data->use_stdio =3D false; + data->file.use_stdio =3D false; =20 if (!data->path) data->path =3D "perf.data"; @@ -373,41 +385,55 @@ void perf_data__close(struct perf_data *data) if (perf_data__is_dir(data)) perf_data__close_dir(data); =20 - zfree(&data->file.path); - - if (data->use_stdio) - fclose(data->file.fptr); - else - close(data->file.fd); + perf_data_file__close(&data->file); } =20 -ssize_t perf_data__read(struct perf_data *data, void *buf, size_t size) +static ssize_t perf_data_file__read(struct perf_data_file *file, void *buf= , size_t size) { - if (data->use_stdio) { - if (fread(buf, size, 1, data->file.fptr) =3D=3D 1) + if (file->use_stdio) { + if (fread(buf, size, 1, file->fptr) =3D=3D 1) return size; - return feof(data->file.fptr) ? 0 : -1; + return feof(file->fptr) ? 0 : -1; } - return readn(data->file.fd, buf, size); + return readn(file->fd, buf, size); +} + +ssize_t perf_data__read(struct perf_data *data, void *buf, size_t size) +{ + return perf_data_file__read(&data->file, buf, size); } =20 ssize_t perf_data_file__write(struct perf_data_file *file, void *buf, size_t size) { + if (file->use_stdio) { + if (fwrite(buf, size, /*nmemb=3D*/1, file->fptr) =3D=3D 1) + return size; + return -1; + } return writen(file->fd, buf, size); } =20 ssize_t perf_data__write(struct perf_data *data, void *buf, size_t size) { - if (data->use_stdio) { - if (fwrite(buf, size, 1, data->file.fptr) =3D=3D 1) - return size; - return -1; - } return perf_data_file__write(&data->file, buf, size); } =20 +off_t perf_data_file__seek(struct perf_data_file *file, off_t offset, int = whence) +{ + if (file->use_stdio) + return fseek(file->fptr, offset, whence); + + return lseek(file->fd, offset, whence); +} + +off_t perf_data__seek(struct perf_data *data, off_t offset, int whence) +{ + assert(!data->is_pipe); + return perf_data_file__seek(&data->file, offset, whence); +} + int perf_data__switch(struct perf_data *data, const char *postfix, size_t pos, bool at_exit, @@ -429,19 +455,18 @@ int perf_data__switch(struct perf_data *data, pr_warning("Failed to rename %s to %s\n", data->path, *new_filepath); =20 if (!at_exit) { - close(data->file.fd); + perf_data_file__close(&data->file); ret =3D perf_data__open(data); if (ret < 0) goto out; =20 - if (lseek(data->file.fd, pos, SEEK_SET) =3D=3D (off_t)-1) { + if (perf_data__seek(data, pos, SEEK_SET) =3D=3D (off_t)-1) { ret =3D -errno; - pr_debug("Failed to lseek to %zu: %s", - pos, strerror(errno)); + pr_debug("Failed to seek to %zu: %s", pos, strerror(errno)); goto out; } } - ret =3D data->file.fd; + ret =3D perf_data__fd(data); out: return ret; } diff --git a/tools/perf/util/data.h b/tools/perf/util/data.h index 1438e32e0451..71f06df7abdb 100644 --- a/tools/perf/util/data.h +++ b/tools/perf/util/data.h @@ -17,32 +17,70 @@ enum perf_dir_version { PERF_DIR_VERSION =3D 1, }; =20 +/** + * struct perf_data_file: A wrapper around a file used for perf.data readi= ng or writing. Generally part + * of struct perf_data. + */ struct perf_data_file { + /** + * @path: Path of file. Generally a copy of perf_data.path but for a + * directory it is the file within the directory. + */ char *path; union { + /** @fd: File descriptor for read/writes. Valid if use_stdio is false. */ int fd; + /** + * @fptr: Stdio FILE. Valid if use_stdio is true, currently just + * pipes in perf inject. + */ FILE *fptr; }; + /** @size: Size of file when opened. */ unsigned long size; + /** @use_stdio: Use buffered stdio operations. */ + bool use_stdio; }; =20 +/** + * struct perf_data: A wrapper around a file used for perf.data reading or= writing. + */ struct perf_data { + /** @path: Path to open and of the file. NULL implies 'perf.data' will be= used. */ const char *path; + /** @file: Underlying file to be used. */ struct perf_data_file file; + /** @is_pipe: Underlying file is a pipe. */ bool is_pipe; + /** @is_dir: Underlying file is a directory. */ bool is_dir; + /** @force: Ignore opening a file creating created by a different user. */ bool force; - bool use_stdio; + /** @in_place_update: A file opened for reading but will be written to. */ bool in_place_update; + /** @mode: Read or write mode. */ enum perf_data_mode mode; =20 struct { + /** @version: perf_dir_version. */ u64 version; + /** @files: perf data files for the directory. */ struct perf_data_file *files; + /** @nr: Number of perf data files for the directory. */ int nr; } dir; }; =20 +static inline int perf_data_file__fd(struct perf_data_file *file) +{ + return file->use_stdio ? fileno(file->fptr) : file->fd; +} + +ssize_t perf_data_file__write(struct perf_data_file *file, + void *buf, size_t size); +off_t perf_data_file__seek(struct perf_data_file *file, off_t offset, int = whence); + + static inline bool perf_data__is_read(struct perf_data *data) { return data->mode =3D=3D PERF_DATA_MODE_READ; @@ -70,10 +108,7 @@ static inline bool perf_data__is_single_file(struct per= f_data *data) =20 static inline int perf_data__fd(struct perf_data *data) { - if (data->use_stdio) - return fileno(data->file.fptr); - - return data->file.fd; + return perf_data_file__fd(&data->file); } =20 int perf_data__open(struct perf_data *data); @@ -81,8 +116,7 @@ void perf_data__close(struct perf_data *data); ssize_t perf_data__read(struct perf_data *data, void *buf, size_t size); ssize_t perf_data__write(struct perf_data *data, void *buf, size_t size); -ssize_t perf_data_file__write(struct perf_data_file *file, - void *buf, size_t size); +off_t perf_data__seek(struct perf_data *data, off_t offset, int whence); /* * If at_exit is set, only rename current perf.data to * perf.data., continue write on original data. @@ -99,8 +133,10 @@ int perf_data__open_dir(struct perf_data *data); void perf_data__close_dir(struct perf_data *data); unsigned long perf_data__size(struct perf_data *data); int perf_data__make_kcore_dir(struct perf_data *data, char *buf, size_t bu= f_sz); -bool has_kcore_dir(const char *path); char *perf_data__kallsyms_name(struct perf_data *data); char *perf_data__guest_kallsyms_name(struct perf_data *data, pid_t machine= _pid); + +bool has_kcore_dir(const char *path); bool is_perf_data(const char *path); + #endif /* __PERF_DATA_H */ diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 09af486c83e4..081e68c72c30 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -2358,7 +2358,7 @@ static int __perf_session__process_dir_events(struct = perf_session *session) if (!data->dir.files[i].size) continue; rd[readers] =3D (struct reader) { - .fd =3D data->dir.files[i].fd, + .fd =3D perf_data_file__fd(&data->dir.files[i]), .path =3D data->dir.files[i].path, .data_size =3D data->dir.files[i].size, .data_offset =3D 0, --=20 2.51.1.851.g4ebd6896fd-goog From nobody Sat Feb 7 22:21:10 2026 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 C8F82304BD7 for ; Wed, 29 Oct 2025 05:34:36 +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=1761716078; cv=none; b=U7l/0Hl6XcEzAkS/pVCATWVnOuLyL5orbrvzf11VPOX6DhAiIic0j3XoZn5euRu3zOBPR3huisCDisGZt5mPX4/tj8A+G2jBtf0WQ9govY7vmPqt1tHOLwyy0sN6cnuuaCuaBnxwQCBlpmFLS6uScY/P9sMceTaK6cj6BIUTNmQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761716078; c=relaxed/simple; bh=pjgQBus0qG0hjaxrSH0uu3Qq9AJCdOwC0H/in0+OSb8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=Z5hfD+KxeGbeZ0bEy0OEknLoq1v5mUrrfDvDkCp6gw+XqPSeW6fEOYRkBvn+Y1rbUgHikLhwL2vTxK0iD0AYOgYOhfRMvnRhZ2Co6Q9cu/dA3vEHz8HR4VBSQbMOpD/TEWPj6zPHL6/ismlcIa94CxoccpirGjE/jn0/FRYw5I4= 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=1PsGQEeF; 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="1PsGQEeF" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-33d75897745so16029442a91.0 for ; Tue, 28 Oct 2025 22:34:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1761716076; x=1762320876; 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=ltgvCiIYngiUZhvcaMFlzhWnCiNVZZ80aMVr+t5YAMI=; b=1PsGQEeFBx1BLrwqeQrZSQngy/LO/XTMmKPd+IPO1CvcJQC7ztxw1wZkY4p8hHsgz2 lf20TxGe3VWwgc/NFPbvl41pwj1PmwCz+IDT16FUpARp4cwUtpJ1TIym2XdVrPvRFHg1 ymfT2Kv3oKvPg5MsaesHaxrvTiK+wRdRPlqczZ1ViAZQIs4LnBxfOdttxdJjVgPX6u8f HhLoAGITyQ+gILWI8Y08frSTl9NlbvPgLQMtkpLdl5DWvU2pARfCTnLRcibEnk6xK/Lp rsOCYCOWzXx/OsOSvuzsYDGXrRLHlNXCtkOT80dlWzrgp5jp9KmnqFmhH3CJ4C/hSbX8 yhtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761716076; x=1762320876; 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=ltgvCiIYngiUZhvcaMFlzhWnCiNVZZ80aMVr+t5YAMI=; b=tS6wGDGUaM1j0TWRXn6DInrv+7q9LvEthUe9C1YauY3uiBg5CxTVrg4qHtkiHtXiFT nU1Q8WZIrAwu2Kl1olgU1ndJjJ0yNqcuibh/j44DT6UbH1vsn7DGc7XSQPoejT4zWns2 gUY97GoYuYew4BrIYredAhFeXVkGsqw6WnY/xZljVO3gCGk/pT7bb5u2+lirI1ughhfc bTY2XK6zQbRdkZIkYk79m4nMVTRJ9X0Dg33wlowD5bdLKrK+Mku1zvKLdHlFgbOZZ4Uv 4DJFMxQny9n+QI9q+9N24vqAiMxEPB/Tr2JqFD1SNjyjp65sA8iP3Ql6UjeHl86QJSC+ eVsA== X-Forwarded-Encrypted: i=1; AJvYcCXqB5vTpGMMXRjtqwTQRf6kNHBhTdVHLesqEUyQawFuKbJKL6XJ1Ko5UgZ4ZSarkMnAlSAmcKIuL+g19FE=@vger.kernel.org X-Gm-Message-State: AOJu0YwCmSvad3ih34cWz2YY9s4XiQkvyrn9bRrXFUjrvfmoqRB3jHR4 ek64GdKYdEuXtEze4U9DB1cyttfrLdOGPATNzKhhQPC7J8Pifw5b6Pyl2HxYuYvFxhauLbG+5P3 zDFZJ+QRb/w== X-Google-Smtp-Source: AGHT+IF+xxZSEDuibZ447qr1lEdxF5eqLdcI/dMQoFhe3SPYlME8LKCSsUdHdyZ3ziTAaX+mA+o9UpTdLIMj X-Received: from pjca7.prod.google.com ([2002:a17:90b:5b87:b0:31f:b2f:aeed]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:e54e:b0:258:f033:3ff9 with SMTP id d9443c01a7336-294deede339mr21502015ad.48.1761716075602; Tue, 28 Oct 2025 22:34:35 -0700 (PDT) Date: Tue, 28 Oct 2025 22:34:08 -0700 In-Reply-To: <20251029053413.355154-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: <20251029053413.355154-1-irogers@google.com> X-Mailer: git-send-email 2.51.1.851.g4ebd6896fd-goog Message-ID: <20251029053413.355154-11-irogers@google.com> Subject: [RFC PATCH v1 10/15] perf python: Add wrapper for perf_data file abstraction From: Ian Rogers To: Suzuki K Poulose , Mike Leach , James Clark , John Garry , Will Deacon , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Greg Kroah-Hartman , Charlie Jenkins , Thomas Falcon , Yicong Yang , Thomas Richter , Athira Rajeev , Howard Chu , Song Liu , Dapeng Mi , Levi Yun , Zhongqiu Han , Blake Jones , Anubhav Shelat , Chun-Tse Shao , Christophe Leroy , Jean-Philippe Romain , Gautam Menghani , Dmitry Vyukov , Yang Li , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Andi Kleen , Weilin Wang Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The perf_data struct is needed for session supported. Signed-off-by: Ian Rogers --- tools/perf/util/python.c | 62 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index 0366142184d8..f96c1f6dca56 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -11,6 +11,7 @@ #include #include "callchain.h" #include "counts.h" +#include "data.h" #include "evlist.h" #include "evsel.h" #include "event.h" @@ -2163,6 +2164,61 @@ static PyObject *pyrf__metrics(PyObject *self, PyObj= ect *args) return list; } =20 +struct pyrf_data { + PyObject_HEAD + + struct perf_data data; +}; + +static int pyrf_data__init(struct pyrf_data *pdata, PyObject *args, PyObje= ct *kwargs) +{ + static char *kwlist[] =3D { "path", "fd", NULL }; + char *path =3D NULL; + int fd =3D -1; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|si", kwlist, &path, &fd)) + return -1; + + pdata->data.path =3D strdup(path); + pdata->data.mode =3D PERF_DATA_MODE_READ; + pdata->data.file.fd =3D fd; + return perf_data__open(&pdata->data) < 0 ? -1 : 0; +} + +static void pyrf_data__delete(struct pyrf_data *pdata) +{ + perf_data__close(&pdata->data); + free((char *)pdata->data.path); + Py_TYPE(pdata)->tp_free((PyObject *)pdata); +} + +static PyObject *pyrf_data__str(PyObject *self) +{ + const struct pyrf_data *pdata =3D (const struct pyrf_data *)self; + + return PyUnicode_FromString(pdata->data.path); +} + +static const char pyrf_data__doc[] =3D PyDoc_STR("perf data file object."); + +static PyTypeObject pyrf_data__type =3D { + PyVarObject_HEAD_INIT(NULL, 0) + .tp_name =3D "perf.data", + .tp_basicsize =3D sizeof(struct pyrf_data), + .tp_dealloc =3D (destructor)pyrf_data__delete, + .tp_flags =3D Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, + .tp_doc =3D pyrf_data__doc, + .tp_init =3D (initproc)pyrf_data__init, + .tp_repr =3D pyrf_data__str, + .tp_str =3D pyrf_data__str, +}; + +static int pyrf_data__setup_types(void) +{ + pyrf_data__type.tp_new =3D PyType_GenericNew; + return PyType_Ready(&pyrf_data__type); +} + static PyMethodDef perf__methods[] =3D { { .ml_name =3D "metrics", @@ -2225,7 +2281,8 @@ PyMODINIT_FUNC PyInit_perf(void) pyrf_cpu_map__setup_types() < 0 || pyrf_pmu_iterator__setup_types() < 0 || pyrf_pmu__setup_types() < 0 || - pyrf_counts_values__setup_types() < 0) + pyrf_counts_values__setup_types() < 0 || + pyrf_data__setup_types() < 0) return module; =20 /* The page_size is placed in util object. */ @@ -2273,6 +2330,9 @@ PyMODINIT_FUNC PyInit_perf(void) Py_INCREF(&pyrf_counts_values__type); PyModule_AddObject(module, "counts_values", (PyObject *)&pyrf_counts_valu= es__type); =20 + Py_INCREF(&pyrf_data__type); + PyModule_AddObject(module, "data", (PyObject *)&pyrf_data__type); + dict =3D PyModule_GetDict(module); if (dict =3D=3D NULL) goto error; --=20 2.51.1.851.g4ebd6896fd-goog From nobody Sat Feb 7 22:21:10 2026 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 9DA423054F9 for ; Wed, 29 Oct 2025 05:34:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761716080; cv=none; b=dtidhFfIsHHhNMkcPya7Ia4e0mpkWOLx9LagE8X8KRymT0Hd0DCjnt9dIYen77iL05JpUxQEvoljC1XkP/E0oS6AAwmTyDh9LsZiXAXPo5KG+Ma02wbq0lKTUB42/beAZTvN3/R7xdwwYopH9VlX/UyQF1z4CrD7NVA5PhVe5io= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761716080; c=relaxed/simple; bh=3gJJs/cKyH4mv+4ETps0tCMJbEWbE+kP2uDKqKle03E=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=ic20OLw2Hk/NzohAIE3MrbjkHhzbBMZEek5iXsVPbym4O5OdW/1sSsdvFmiHcyv8ZP4y23xoCnVIumE1VQkgnpZm7OOBKeO9tKE8RohhKJ62uUouu1YNZ0xeSGnWvM0ZiuaHEadV3OL8FzKwAOXiS0uoG0CyiBjwgY9elsWim1k= 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=Xmr3EqTS; 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="Xmr3EqTS" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-b62f9247dd1so5486082a12.0 for ; Tue, 28 Oct 2025 22:34:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1761716078; x=1762320878; 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=3Cw/3sMiecO8APVzgVFRs1sMzit7Si8lcEDrQ/T37n8=; b=Xmr3EqTSL0gjIYzH5oG9V9Zx9GCQTXKZ9TjYF5IdwdLDIdihqjgpCBhWr3qKO8U4Rp VEYER43+C/AnAFLfZlQg16jYqRuBKbwNrpP6WGe/3yj62bflrPNzSySG43BvaV1yjQBo n8wMTKxLZ0m8gb9zAyF0/9NQW1rhjMRSnckVFzLoL8uDEb+eRxIk3ux0ne03R/RLUtDm GPjF1A/bp0akAzfm0/C0I0FL1JTozDJMUg0WSYwFFEWX5jD5chGRlOStx0/xytz9Ip3P UNqx22dzWxoVu0s4hrr5X3wsb4XtGQxSIgCcsn8au3LM06Fv2VhRBBB+VD/PdzBAm2k7 bgmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761716078; x=1762320878; 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=3Cw/3sMiecO8APVzgVFRs1sMzit7Si8lcEDrQ/T37n8=; b=eDoE4Jz1mb4sNcNYuj31ppnsvrTckFDWOA7ldYIOevM1aedj/eqd4/eT0sx0kc67yy tR01vtCn1Vgy2m6N/bzJ5Evj7jdVA5pVz4hwz4jmXxsG7H0OpAQybmVWALLCBepCAdJc u2o6U8055SRMz508RBwPU7XwiTQ+UZKw/5nO1d3kRAAqRWTBCFVeK1/yG+GBPqO6oln1 IY18Cej+KmOUGSF80qe6k77HZeJuT4N/vnNzvrX4qgCFMXcstqMmQDSW+4sd7NGrg++e nx5jxVVQNY51hbByEUN8Gp5XM2j6+E6XcXkh9DCMdqspQSiWE/97ZIgZanGVN/j8d7Lk Netw== X-Forwarded-Encrypted: i=1; AJvYcCWmEhaV+8zAa5xrEEY3feEDtGKeejsAtNan5veoX/2RnIpV9UJp07ISbtC+UqPiEMkxA9+RIcBEukNaTdw=@vger.kernel.org X-Gm-Message-State: AOJu0YyuhCbF491kbVYVLNfgNQj3cHFcuIRO55XLg+OLkyMyx+BmxZbk Q8MC9L8VecRTMuRzSjpi8rbljx5hgKAa+AVEkdE2bMFtdLjm1hXvSViQwfdESWkaB1sEzPb8Ijq 0dIuK0ZgJqg== X-Google-Smtp-Source: AGHT+IFfoyQMg5EWaL68EG2WIFdLmz5ML5FPEnKP1GI/SlQzNqJrph73+HiTtd7C+V5QRkXlyD/WNRl8fZbt X-Received: from plsm19.prod.google.com ([2002:a17:902:bb93:b0:28e:7fd3:5812]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:230b:b0:235:e8da:8d1 with SMTP id d9443c01a7336-294dedfc92bmr15592975ad.8.1761716077910; Tue, 28 Oct 2025 22:34:37 -0700 (PDT) Date: Tue, 28 Oct 2025 22:34:09 -0700 In-Reply-To: <20251029053413.355154-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: <20251029053413.355154-1-irogers@google.com> X-Mailer: git-send-email 2.51.1.851.g4ebd6896fd-goog Message-ID: <20251029053413.355154-12-irogers@google.com> Subject: [RFC PATCH v1 11/15] perf python: Add python session abstraction wrapping perf's session From: Ian Rogers To: Suzuki K Poulose , Mike Leach , James Clark , John Garry , Will Deacon , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Greg Kroah-Hartman , Charlie Jenkins , Thomas Falcon , Yicong Yang , Thomas Richter , Athira Rajeev , Howard Chu , Song Liu , Dapeng Mi , Levi Yun , Zhongqiu Han , Blake Jones , Anubhav Shelat , Chun-Tse Shao , Christophe Leroy , Jean-Philippe Romain , Gautam Menghani , Dmitry Vyukov , Yang Li , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Andi Kleen , Weilin Wang Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Sessions are necessary to be able to use perf.data files within a tool. Add a wrapper python type that incorporates the tool. Allow a sample callback to be passed when creating the session. When process_events is run this callback will be called, if supplied, for sample events. An example use looks like: ``` $ perf record -e cycles,instructions -a sleep 3 $ PYTHONPATH=3D..../perf/python python3 Python 3.13.7 (main, Aug 20 2025, 22:17:40) [GCC 14.2.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import perf >>> count=3D0 ... def handle_sample(x): ... global count ... if count < 3: ... print(dir(x)) ... count =3D count + 1 ... perf.session(perf.data("perf.data"),sample=3Dhandle_sample).process_eve= nts() ... ['__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', = '__ge__', '__getattribute__', '__getstate__', '__gt__', '__hash__', '__init= __', '__init_subclass__', '__le__', '__lt__', '__ne__', '__new__', '__reduc= e__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', = '__subclasshook__', 'sample_addr', 'sample_cpu', 'sample_id', 'sample_ip', = 'sample_period', 'sample_pid', 'sample_stream_id', 'sample_tid', 'sample_ti= me', 'type'] ['__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', = '__ge__', '__getattribute__', '__getstate__', '__gt__', '__hash__', '__init= __', '__init_subclass__', '__le__', '__lt__', '__ne__', '__new__', '__reduc= e__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', = '__subclasshook__', 'sample_addr', 'sample_cpu', 'sample_id', 'sample_ip', = 'sample_period', 'sample_pid', 'sample_stream_id', 'sample_tid', 'sample_ti= me', 'type'] ['__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', = '__ge__', '__getattribute__', '__getstate__', '__gt__', '__hash__', '__init= __', '__init_subclass__', '__le__', '__lt__', '__ne__', '__new__', '__reduc= e__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', = '__subclasshook__', 'sample_addr', 'sample_cpu', 'sample_id', 'sample_ip', = 'sample_period', 'sample_pid', 'sample_stream_id', 'sample_tid', 'sample_ti= me', 'type'] ``` Signed-off-by: Ian Rogers --- tools/perf/util/python.c | 114 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 113 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index f96c1f6dca56..dfc6e9299af9 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -19,8 +19,10 @@ #include "pmus.h" #include "print_binary.h" #include "record.h" +#include "session.h" #include "strbuf.h" #include "thread_map.h" +#include "tool.h" #include "tp_pmu.h" #include "trace-event.h" #include "metricgroup.h" @@ -2219,6 +2221,112 @@ static int pyrf_data__setup_types(void) return PyType_Ready(&pyrf_data__type); } =20 +struct pyrf_session { + PyObject_HEAD + + struct perf_session *session; + struct perf_tool tool; + struct pyrf_data *pdata; + PyObject *sample; + PyObject *stat; +}; + +static int pyrf_session_tool__sample(const struct perf_tool *tool, + union perf_event *event, + struct perf_sample *sample, + struct evsel *evsel, + struct machine *machine __maybe_unused) +{ + struct pyrf_session *psession =3D container_of(tool, struct pyrf_session,= tool); + PyObject *pyevent =3D pyrf_event__new(event); + struct pyrf_event *pevent =3D (struct pyrf_event *)pyevent; + + if (pyevent =3D=3D NULL) + return -ENOMEM; + + pevent->evsel =3D evsel; + memcpy(&pevent->sample, sample, sizeof(struct perf_sample)); + + PyObject_CallFunction(psession->sample, "O", pyevent); + Py_DECREF(pyevent); + return 0; +} + +static int pyrf_session__init(struct pyrf_session *psession, PyObject *arg= s, PyObject *kwargs) +{ + struct pyrf_data *pdata; + PyObject *sample =3D NULL; + static char *kwlist[] =3D { "data", "sample", NULL }; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|O", kwlist, &pdata, &sa= mple)) + return -1; + + Py_INCREF(pdata); + psession->pdata =3D pdata; + perf_tool__init(&psession->tool, /*ordered_events=3D*/true); + + #define ADD_TOOL(name) \ + if (name) { \ + if (!PyCallable_Check(name)) {\ + PyErr_SetString(PyExc_TypeError, #name " must be callable"); \ + return -1;\ + }\ + psession->tool.name =3D pyrf_session_tool__##name; \ + Py_INCREF(name); \ + psession->name =3D name; \ + } + + ADD_TOOL(sample); + #undef ADD_TOOL + + psession->session =3D perf_session__new(&pdata->data, &psession->tool); + return psession->session ? 0 : -1; +} + +static void pyrf_session__delete(struct pyrf_session *psession) +{ + Py_XDECREF(psession->pdata); + Py_XDECREF(psession->sample); + perf_session__delete(psession->session); + Py_TYPE(psession)->tp_free((PyObject *)psession); +} + +static PyObject *pyrf_session__process_events(struct pyrf_session *psessio= n) +{ + perf_session__process_events(psession->session); + Py_INCREF(Py_None); + return Py_None; +} + +static PyMethodDef pyrf_session__methods[] =3D { + { + .ml_name =3D "process_events", + .ml_meth =3D (PyCFunction)pyrf_session__process_events, + .ml_flags =3D METH_NOARGS, + .ml_doc =3D PyDoc_STR("Iterate and process events.") + }, + { .ml_name =3D NULL, } +}; + +static const char pyrf_session__doc[] =3D PyDoc_STR("perf session object."= ); + +static PyTypeObject pyrf_session__type =3D { + PyVarObject_HEAD_INIT(NULL, 0) + .tp_name =3D "perf.session", + .tp_basicsize =3D sizeof(struct pyrf_session), + .tp_dealloc =3D (destructor)pyrf_session__delete, + .tp_flags =3D Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, + .tp_methods =3D pyrf_session__methods, + .tp_doc =3D pyrf_session__doc, + .tp_init =3D (initproc)pyrf_session__init, +}; + +static int pyrf_session__setup_types(void) +{ + pyrf_session__type.tp_new =3D PyType_GenericNew; + return PyType_Ready(&pyrf_session__type); +} + static PyMethodDef perf__methods[] =3D { { .ml_name =3D "metrics", @@ -2282,7 +2390,8 @@ PyMODINIT_FUNC PyInit_perf(void) pyrf_pmu_iterator__setup_types() < 0 || pyrf_pmu__setup_types() < 0 || pyrf_counts_values__setup_types() < 0 || - pyrf_data__setup_types() < 0) + pyrf_data__setup_types() < 0 || + pyrf_session__setup_types() < 0) return module; =20 /* The page_size is placed in util object. */ @@ -2333,6 +2442,9 @@ PyMODINIT_FUNC PyInit_perf(void) Py_INCREF(&pyrf_data__type); PyModule_AddObject(module, "data", (PyObject *)&pyrf_data__type); =20 + Py_INCREF(&pyrf_data__type); + PyModule_AddObject(module, "session", (PyObject *)&pyrf_session__type); + dict =3D PyModule_GetDict(module); if (dict =3D=3D NULL) goto error; --=20 2.51.1.851.g4ebd6896fd-goog From nobody Sat Feb 7 22:21:10 2026 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 10D722FB97A for ; Wed, 29 Oct 2025 05:34:40 +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=1761716086; cv=none; b=bZor/xtKHJYqCODAAbPjYQlr99WvelAvTqgLn2oG5rNnQGdSaSnG9cLvKwVnjUwqy/8k8vKPFLlNKWOv4fe80jJxp4UTTCTwsvfaR1cNh0IDktfFwmkWYR9nQZojoGQ0LLlQvnIsiEPAuZi6TUyQ1Tx+5rj0uCfLxVkvleY977o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761716086; c=relaxed/simple; bh=W6n1hOpZLpLRWfMMLiiB5SbmiTTabiHevMYVePPJwgY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=V/OWvvM13oWXgUisnYmE6Kn5Y5eljL+atLgj55oFsD96ebP/VWvdWfDVXQw4ILkWiOuXHnvnfiq8k3lSqm3E3j54ip5pj++skJm9uxpP3/U1UbWS4gzGmPnWjpSu96lAxo07/1lAz5GqCbWBhqvf/qpgR1g1TUILMstatiRAW6Y= 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=byUdYp1Z; 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="byUdYp1Z" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-3304def7909so5271085a91.3 for ; Tue, 28 Oct 2025 22:34:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1761716080; x=1762320880; 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=pyFyBq96TiZma0cDgJerxfOqJbz0r78y5HqX7NoO0q8=; b=byUdYp1ZbHnap1qxHe9pqef7r6FDA6WGDAmCGdwTJf+U79SiIDJ8QeMTI3uBeJEv/G IRIf1WF+F0ufd1pWF5RQ+laMMKdrLLnIBPvAajx88Ht+LKPKsImoXcRxQZBme1K/EVtb yDQxuPPjiRgPlJBofIPp4PhyLu1C7RztPJspw3VAODFk90zBVbw80J+lJT9G0WsGA4ZH 297XmOWU8VcpiGW0+UsULQaD0kFEd2RNIs5bcc27EHKfXzIXXT8Zof0t1GFqVINPyYIN l98X+6ZWH+68tyDLbwSp4je5nqqs0huENbJsoYhupiyRfWDCCKFCcL1qyHcqGijVT9Mm Epsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761716080; x=1762320880; 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=pyFyBq96TiZma0cDgJerxfOqJbz0r78y5HqX7NoO0q8=; b=XPuBjTUHz1QFsIdJo9my0ioBM43w2zA/ispNA1eWJn/M8k6WxB/Jkyw2OUriFUgmw2 GwAHQ/cTvYVA7luDfm2n+fW93un1gxu6lDo2qElpPhYawZ3MC7h+S6yiR6cWZVzTzYBa TMxbDSEkhJIAaalw/vHGbM6HUV4eaOL32m3vbFq+4HXqpSTNbcw/VbJfQsWsJc1RxPl6 GdZa+VMBPhariMWCtzXwPIFmIWyzOJSHnJ9Gh5U+BZOqlOB/oe6ahXlJAMOHsRTS0nuF LQuTP3Tk8Uv7XRDFnE2hYQyShit14Tt7OyO3CyOqji8DAB9YmH57gi5yG/lxa9e4ojUx c5Aw== X-Forwarded-Encrypted: i=1; AJvYcCW30Im3tQjtvHsoyKCxjEG0XQeYGiaY4HwuZuVLiquPe0gwIaSbo8DWfrbz2dtwxbpRLgAShKchjRrdQTM=@vger.kernel.org X-Gm-Message-State: AOJu0Yz3RF/eCXDdG+it9HPy0NNtA4WLwwGWJY1jmL5huXfoVZGYmPhy NDObHh6b4RuLAjw8jzCs2ZsD1kcObmWTIY9lJ9UQSqLN2VpXEXDLeLh0tJU+QSECnWoxU42ud42 h7P7qqOfWxw== X-Google-Smtp-Source: AGHT+IEG786U5+BUJZ6CfNB/KkNHAxFkYVlEH2FEx2oLm+QJ22iQQwTlWSRLEeHYMfOnyAjCplq4+1C6uecQ X-Received: from pjboi15.prod.google.com ([2002:a17:90b:3a0f:b0:32f:46d:993b]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:17cd:b0:330:4604:3ae8 with SMTP id 98e67ed59e1d1-3403a2973afmr2185597a91.21.1761716080206; Tue, 28 Oct 2025 22:34:40 -0700 (PDT) Date: Tue, 28 Oct 2025 22:34:10 -0700 In-Reply-To: <20251029053413.355154-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: <20251029053413.355154-1-irogers@google.com> X-Mailer: git-send-email 2.51.1.851.g4ebd6896fd-goog Message-ID: <20251029053413.355154-13-irogers@google.com> Subject: [RFC PATCH v1 12/15] perf evlist: Add reference count From: Ian Rogers To: Suzuki K Poulose , Mike Leach , James Clark , John Garry , Will Deacon , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Greg Kroah-Hartman , Charlie Jenkins , Thomas Falcon , Yicong Yang , Thomas Richter , Athira Rajeev , Howard Chu , Song Liu , Dapeng Mi , Levi Yun , Zhongqiu Han , Blake Jones , Anubhav Shelat , Chun-Tse Shao , Christophe Leroy , Jean-Philippe Romain , Gautam Menghani , Dmitry Vyukov , Yang Li , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Andi Kleen , Weilin Wang Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This a no-op for most of the perf tool. The reference count is set to 1 at allocation, the put will see the 1, decrement it and perform the delete. The purpose for adding the reference count is for the python code. Prior to this change the python code would clone evlists, but this has issues if events are opened, etc. This change adds a reference count for the evlists and a later change will add it to evsels. The combination is needed for the python code to operate correctly (not hit asserts in the evsel clone), but the changes are broken apart for the sake of smaller patches. Signed-off-by: Ian Rogers --- tools/perf/arch/x86/tests/hybrid.c | 2 +- tools/perf/arch/x86/tests/topdown.c | 2 +- tools/perf/arch/x86/util/iostat.c | 2 +- tools/perf/bench/evlist-open-close.c | 18 +- tools/perf/builtin-ftrace.c | 8 +- tools/perf/builtin-kvm.c | 4 +- tools/perf/builtin-lock.c | 2 +- tools/perf/builtin-record.c | 4 +- tools/perf/builtin-stat.c | 8 +- tools/perf/builtin-top.c | 52 +++--- tools/perf/builtin-trace.c | 26 +-- tools/perf/tests/backward-ring-buffer.c | 18 +- tools/perf/tests/code-reading.c | 4 +- tools/perf/tests/event-times.c | 4 +- tools/perf/tests/event_update.c | 2 +- tools/perf/tests/evsel-roundtrip-name.c | 8 +- tools/perf/tests/expand-cgroup.c | 8 +- tools/perf/tests/hists_cumulate.c | 2 +- tools/perf/tests/hists_filter.c | 2 +- tools/perf/tests/hists_link.c | 2 +- tools/perf/tests/hists_output.c | 2 +- tools/perf/tests/hwmon_pmu.c | 2 +- tools/perf/tests/keep-tracking.c | 2 +- tools/perf/tests/mmap-basic.c | 18 +- tools/perf/tests/openat-syscall-tp-fields.c | 18 +- tools/perf/tests/parse-events.c | 4 +- tools/perf/tests/parse-metric.c | 4 +- tools/perf/tests/parse-no-sample-id-all.c | 2 +- tools/perf/tests/perf-record.c | 18 +- tools/perf/tests/perf-time-to-tsc.c | 2 +- tools/perf/tests/pfm.c | 4 +- tools/perf/tests/pmu-events.c | 6 +- tools/perf/tests/pmu.c | 2 +- tools/perf/tests/sw-clock.c | 14 +- tools/perf/tests/switch-tracking.c | 2 +- tools/perf/tests/task-exit.c | 14 +- tools/perf/tests/tool_pmu.c | 2 +- tools/perf/tests/topology.c | 2 +- tools/perf/util/cgroup.c | 4 +- tools/perf/util/data-convert-bt.c | 2 +- tools/perf/util/evlist.c | 20 ++- tools/perf/util/evlist.h | 7 +- tools/perf/util/expr.c | 2 +- tools/perf/util/header.c | 12 +- tools/perf/util/metricgroup.c | 6 +- tools/perf/util/parse-events.c | 4 +- tools/perf/util/perf_api_probe.c | 2 +- tools/perf/util/python.c | 176 +++++++------------- tools/perf/util/record.c | 2 +- tools/perf/util/session.c | 2 +- tools/perf/util/sideband_evlist.c | 16 +- 51 files changed, 252 insertions(+), 299 deletions(-) diff --git a/tools/perf/arch/x86/tests/hybrid.c b/tools/perf/arch/x86/tests= /hybrid.c index e221ea104174..dfb0ffc0d030 100644 --- a/tools/perf/arch/x86/tests/hybrid.c +++ b/tools/perf/arch/x86/tests/hybrid.c @@ -268,7 +268,7 @@ static int test_event(const struct evlist_test *e) ret =3D e->check(evlist); } parse_events_error__exit(&err); - evlist__delete(evlist); + evlist__put(evlist); =20 return ret; } diff --git a/tools/perf/arch/x86/tests/topdown.c b/tools/perf/arch/x86/test= s/topdown.c index 1eba3b4594ef..b31aef4ef28b 100644 --- a/tools/perf/arch/x86/tests/topdown.c +++ b/tools/perf/arch/x86/tests/topdown.c @@ -55,7 +55,7 @@ static int event_cb(void *state, struct pmu_event_info *i= nfo) *ret =3D TEST_FAIL; } } - evlist__delete(evlist); + evlist__put(evlist); return 0; } =20 diff --git a/tools/perf/arch/x86/util/iostat.c b/tools/perf/arch/x86/util/i= ostat.c index 7442a2cd87ed..e0417552b0cb 100644 --- a/tools/perf/arch/x86/util/iostat.c +++ b/tools/perf/arch/x86/util/iostat.c @@ -337,7 +337,7 @@ int iostat_prepare(struct evlist *evlist, struct perf_s= tat_config *config) if (evlist->core.nr_entries > 0) { pr_warning("The -e and -M options are not supported." "All chosen events/metrics will be dropped\n"); - evlist__delete(evlist); + evlist__put(evlist); evlist =3D evlist__new(); if (!evlist) return -ENOMEM; diff --git a/tools/perf/bench/evlist-open-close.c b/tools/perf/bench/evlist= -open-close.c index bfaf50e4e519..a802fb005ee3 100644 --- a/tools/perf/bench/evlist-open-close.c +++ b/tools/perf/bench/evlist-open-close.c @@ -75,7 +75,7 @@ static struct evlist *bench__create_evlist(char *evstr, c= onst char *uid_str) parse_events_error__exit(&err); pr_err("Run 'perf list' for a list of valid events\n"); ret =3D 1; - goto out_delete_evlist; + goto out_put_evlist; } parse_events_error__exit(&err); if (uid_str) { @@ -84,24 +84,24 @@ static struct evlist *bench__create_evlist(char *evstr,= const char *uid_str) if (uid =3D=3D UINT_MAX) { pr_err("Invalid User: %s", uid_str); ret =3D -EINVAL; - goto out_delete_evlist; + goto out_put_evlist; } ret =3D parse_uid_filter(evlist, uid); if (ret) - goto out_delete_evlist; + goto out_put_evlist; } ret =3D evlist__create_maps(evlist, &opts.target); if (ret < 0) { pr_err("Not enough memory to create thread/cpu maps\n"); - goto out_delete_evlist; + goto out_put_evlist; } =20 evlist__config(evlist, &opts, NULL); =20 return evlist; =20 -out_delete_evlist: - evlist__delete(evlist); +out_put_evlist: + evlist__put(evlist); return NULL; } =20 @@ -150,7 +150,7 @@ static int bench_evlist_open_close__run(char *evstr, co= nst char *uid_str) evlist->core.nr_entries, evlist__count_evsel_fds(evlist)); printf(" Number of iterations:\t%d\n", iterations); =20 - evlist__delete(evlist); + evlist__put(evlist); =20 for (i =3D 0; i < iterations; i++) { pr_debug("Started iteration %d\n", i); @@ -161,7 +161,7 @@ static int bench_evlist_open_close__run(char *evstr, co= nst char *uid_str) gettimeofday(&start, NULL); err =3D bench__do_evlist_open_close(evlist); if (err) { - evlist__delete(evlist); + evlist__put(evlist); return err; } =20 @@ -170,7 +170,7 @@ static int bench_evlist_open_close__run(char *evstr, co= nst char *uid_str) runtime_us =3D timeval2usec(&diff); update_stats(&time_stats, runtime_us); =20 - evlist__delete(evlist); + evlist__put(evlist); pr_debug("Iteration %d took:\t%" PRIu64 "us\n", i, runtime_us); } =20 diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c index 6b6eec65f93f..4a2fe05e9786 100644 --- a/tools/perf/builtin-ftrace.c +++ b/tools/perf/builtin-ftrace.c @@ -1993,20 +1993,20 @@ int cmd_ftrace(int argc, const char **argv) =20 ret =3D evlist__create_maps(ftrace.evlist, &ftrace.target); if (ret < 0) - goto out_delete_evlist; + goto out_put_evlist; =20 if (argc) { ret =3D evlist__prepare_workload(ftrace.evlist, &ftrace.target, argv, false, ftrace__workload_exec_failed_signal); if (ret < 0) - goto out_delete_evlist; + goto out_put_evlist; } =20 ret =3D cmd_func(&ftrace); =20 -out_delete_evlist: - evlist__delete(ftrace.evlist); +out_put_evlist: + evlist__put(ftrace.evlist); =20 out_delete_filters: delete_filter_func(&ftrace.filters); diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index f0f285763f19..b07cbe051e33 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c @@ -1806,7 +1806,7 @@ static struct evlist *kvm_live_event_list(void) =20 out: if (err) { - evlist__delete(evlist); + evlist__put(evlist); evlist =3D NULL; } =20 @@ -1937,7 +1937,7 @@ static int kvm_events_live(struct perf_kvm_stat *kvm, out: perf_session__delete(kvm->session); kvm->session =3D NULL; - evlist__delete(kvm->evlist); + evlist__put(kvm->evlist); =20 return err; } diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c index 078634461df2..2a57767f03a9 100644 --- a/tools/perf/builtin-lock.c +++ b/tools/perf/builtin-lock.c @@ -2143,7 +2143,7 @@ static int __cmd_contention(int argc, const char **ar= gv) =20 out_delete: lock_filter_finish(); - evlist__delete(con.evlist); + evlist__put(con.evlist); lock_contention_finish(&con); perf_session__delete(session); perf_env__exit(&host_env); diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 3d8cf4090a92..738dbae80eac 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -4349,7 +4349,7 @@ int cmd_record(int argc, const char **argv) goto out; =20 evlist__splice_list_tail(rec->evlist, &def_evlist->core.entries); - evlist__delete(def_evlist); + evlist__put(def_evlist); } =20 if (rec->opts.target.tid && !rec->opts.no_inherit_set) @@ -4460,7 +4460,7 @@ int cmd_record(int argc, const char **argv) auxtrace_record__free(rec->itr); out_opts: evlist__close_control(rec->opts.ctl_fd, rec->opts.ctl_fd_ack, &rec->opts.= ctl_fd_close); - evlist__delete(rec->evlist); + evlist__put(rec->evlist); return err; } =20 diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 886727ae8529..282926c6abd4 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -2067,7 +2067,7 @@ static int add_default_events(void) metricgroup__copy_metric_events(evlist, /*cgrp=3D*/NULL, &evlist->metric_events, &metric_evlist->metric_events); - evlist__delete(metric_evlist); + evlist__put(metric_evlist); } } =20 @@ -2142,7 +2142,7 @@ static int add_default_events(void) metricgroup__copy_metric_events(evsel_list, /*cgrp=3D*/NULL, &evsel_list->metric_events, &evlist->metric_events); - evlist__delete(evlist); + evlist__put(evlist); return ret; } =20 @@ -2373,7 +2373,7 @@ static int __cmd_report(int argc, const char **argv) =20 perf_stat.session =3D session; stat_config.output =3D stderr; - evlist__delete(evsel_list); + evlist__put(evsel_list); evsel_list =3D session->evlist; =20 ret =3D perf_session__process_events(session); @@ -3042,7 +3042,7 @@ int cmd_stat(int argc, const char **argv) if (smi_cost && smi_reset) sysfs__write_int(FREEZE_ON_SMI_PATH, 0); =20 - evlist__delete(evsel_list); + evlist__put(evsel_list); =20 evlist__close_control(stat_config.ctl_fd, stat_config.ctl_fd_ack, &stat_c= onfig.ctl_fd_close); =20 diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index 710604c4f6f6..45d5dae54dcd 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c @@ -1641,14 +1641,14 @@ int cmd_top(int argc, const char **argv) perf_env__init(&host_env); status =3D perf_config(perf_top_config, &top); if (status) - goto out_delete_evlist; + goto out_put_evlist; /* * Since the per arch annotation init routine may need the cpuid, read * it here, since we are not getting this from the perf.data header. */ status =3D perf_env__set_cmdline(&host_env, argc, argv); if (status) - goto out_delete_evlist; + goto out_put_evlist; =20 status =3D perf_env__read_cpuid(&host_env); if (status) { @@ -1669,44 +1669,44 @@ int cmd_top(int argc, const char **argv) annotate_opts.disassembler_style =3D strdup(disassembler_style); if (!annotate_opts.disassembler_style) { status =3D -ENOMEM; - goto out_delete_evlist; + goto out_put_evlist; } } if (objdump_path) { annotate_opts.objdump_path =3D strdup(objdump_path); if (!annotate_opts.objdump_path) { status =3D -ENOMEM; - goto out_delete_evlist; + goto out_put_evlist; } } if (addr2line_path) { symbol_conf.addr2line_path =3D strdup(addr2line_path); if (!symbol_conf.addr2line_path) { status =3D -ENOMEM; - goto out_delete_evlist; + goto out_put_evlist; } } =20 status =3D symbol__validate_sym_arguments(); if (status) - goto out_delete_evlist; + goto out_put_evlist; =20 if (annotate_check_args() < 0) - goto out_delete_evlist; + goto out_put_evlist; =20 if (!top.evlist->core.nr_entries) { struct evlist *def_evlist =3D evlist__new_default(); =20 if (!def_evlist) - goto out_delete_evlist; + goto out_put_evlist; =20 evlist__splice_list_tail(top.evlist, &def_evlist->core.entries); - evlist__delete(def_evlist); + evlist__put(def_evlist); } =20 status =3D evswitch__init(&top.evswitch, top.evlist, stderr); if (status) - goto out_delete_evlist; + goto out_put_evlist; =20 if (symbol_conf.report_hierarchy) { /* disable incompatible options */ @@ -1717,18 +1717,18 @@ int cmd_top(int argc, const char **argv) pr_err("Error: --hierarchy and --fields options cannot be used together= \n"); parse_options_usage(top_usage, options, "fields", 0); parse_options_usage(NULL, options, "hierarchy", 0); - goto out_delete_evlist; + goto out_put_evlist; } } =20 if (top.stitch_lbr && !(callchain_param.record_mode =3D=3D CALLCHAIN_LBR)= ) { pr_err("Error: --stitch-lbr must be used with --call-graph lbr\n"); - goto out_delete_evlist; + goto out_put_evlist; } =20 if (nr_cgroups > 0 && opts->record_cgroup) { pr_err("--cgroup and --all-cgroups cannot be used together\n"); - goto out_delete_evlist; + goto out_put_evlist; } =20 if (branch_call_mode) { @@ -1752,7 +1752,7 @@ int cmd_top(int argc, const char **argv) status =3D perf_env__read_core_pmu_caps(&host_env); if (status) { pr_err("PMU capability data is not available\n"); - goto out_delete_evlist; + goto out_put_evlist; } } =20 @@ -1775,7 +1775,7 @@ int cmd_top(int argc, const char **argv) if (IS_ERR(top.session)) { status =3D PTR_ERR(top.session); top.session =3D NULL; - goto out_delete_evlist; + goto out_put_evlist; } top.evlist->session =3D top.session; =20 @@ -1785,7 +1785,7 @@ int cmd_top(int argc, const char **argv) if (field_order) parse_options_usage(sort_order ? NULL : top_usage, options, "fields", 0); - goto out_delete_evlist; + goto out_put_evlist; } =20 status =3D target__validate(target); @@ -1800,11 +1800,11 @@ int cmd_top(int argc, const char **argv) if (uid =3D=3D UINT_MAX) { ui__error("Invalid User: %s", top.uid_str); status =3D -EINVAL; - goto out_delete_evlist; + goto out_put_evlist; } status =3D parse_uid_filter(top.evlist, uid); if (status) - goto out_delete_evlist; + goto out_put_evlist; } =20 if (target__none(target)) @@ -1814,7 +1814,7 @@ int cmd_top(int argc, const char **argv) ui__error("Couldn't create thread/CPU maps: %s\n", errno =3D=3D ENOENT ? "No such process" : str_error_r(errno, errbuf, = sizeof(errbuf))); status =3D -errno; - goto out_delete_evlist; + goto out_put_evlist; } =20 if (top.delay_secs < 1) @@ -1822,7 +1822,7 @@ int cmd_top(int argc, const char **argv) =20 if (record_opts__config(opts)) { status =3D -EINVAL; - goto out_delete_evlist; + goto out_put_evlist; } =20 top.sym_evsel =3D evlist__first(top.evlist); @@ -1837,14 +1837,14 @@ int cmd_top(int argc, const char **argv) =20 status =3D symbol__annotation_init(); if (status < 0) - goto out_delete_evlist; + goto out_put_evlist; =20 annotation_config__init(); =20 symbol_conf.try_vmlinux_path =3D (symbol_conf.vmlinux_name =3D=3D NULL); status =3D symbol__init(NULL); if (status < 0) - goto out_delete_evlist; + goto out_put_evlist; =20 sort__setup_elide(stdout); =20 @@ -1864,13 +1864,13 @@ int cmd_top(int argc, const char **argv) if (top.sb_evlist =3D=3D NULL) { pr_err("Couldn't create side band evlist.\n."); status =3D -EINVAL; - goto out_delete_evlist; + goto out_put_evlist; } =20 if (evlist__add_bpf_sb_event(top.sb_evlist, &host_env)) { pr_err("Couldn't ask for PERF_RECORD_BPF_EVENT side band events.\n."); status =3D -EINVAL; - goto out_delete_evlist; + goto out_put_evlist; } } #endif @@ -1885,8 +1885,8 @@ int cmd_top(int argc, const char **argv) if (!opts->no_bpf_event) evlist__stop_sb_thread(top.sb_evlist); =20 -out_delete_evlist: - evlist__delete(top.evlist); +out_put_evlist: + evlist__put(top.evlist); perf_session__delete(top.session); annotation_options__exit(); perf_env__exit(&host_env); diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index a743bda294bd..c056df42a78f 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -4364,7 +4364,7 @@ static int trace__run(struct trace *trace, int argc, = const char **argv) =20 if (trace->summary_bpf) { if (trace_prepare_bpf_summary(trace->summary_mode) < 0) - goto out_delete_evlist; + goto out_put_evlist; =20 if (trace->summary_only) goto create_maps; @@ -4432,19 +4432,19 @@ static int trace__run(struct trace *trace, int argc= , const char **argv) err =3D evlist__create_maps(evlist, &trace->opts.target); if (err < 0) { fprintf(trace->output, "Problems parsing the target to trace, check your= options!\n"); - goto out_delete_evlist; + goto out_put_evlist; } =20 err =3D trace__symbols_init(trace, argc, argv, evlist); if (err < 0) { fprintf(trace->output, "Problems initializing symbol libraries!\n"); - goto out_delete_evlist; + goto out_put_evlist; } =20 if (trace->summary_mode =3D=3D SUMMARY__BY_TOTAL && !trace->summary_bpf) { trace->syscall_stats =3D alloc_syscall_stats(); if (IS_ERR(trace->syscall_stats)) - goto out_delete_evlist; + goto out_put_evlist; } =20 evlist__config(evlist, &trace->opts, &callchain_param); @@ -4453,7 +4453,7 @@ static int trace__run(struct trace *trace, int argc, = const char **argv) err =3D evlist__prepare_workload(evlist, &trace->opts.target, argv, fals= e, NULL); if (err < 0) { fprintf(trace->output, "Couldn't run the workload!\n"); - goto out_delete_evlist; + goto out_put_evlist; } workload_pid =3D evlist->workload.pid; } @@ -4501,7 +4501,7 @@ static int trace__run(struct trace *trace, int argc, = const char **argv) =20 err =3D trace__expand_filters(trace, &evsel); if (err) - goto out_delete_evlist; + goto out_put_evlist; err =3D evlist__apply_filters(evlist, &evsel, &trace->opts.target); if (err < 0) goto out_error_apply_filters; @@ -4618,12 +4618,12 @@ static int trace__run(struct trace *trace, int argc= , const char **argv) } } =20 -out_delete_evlist: +out_put_evlist: trace_cleanup_bpf_summary(); delete_syscall_stats(trace->syscall_stats); trace__symbols__exit(trace); evlist__free_syscall_tp_fields(evlist); - evlist__delete(evlist); + evlist__put(evlist); cgroup__put(trace->cgroup); trace->evlist =3D NULL; trace->live =3D false; @@ -4648,22 +4648,22 @@ static int trace__run(struct trace *trace, int argc= , const char **argv) =20 out_error: fprintf(trace->output, "%s\n", errbuf); - goto out_delete_evlist; + goto out_put_evlist; =20 out_error_apply_filters: fprintf(trace->output, "Failed to set filter \"%s\" on event %s with %d (%s)\n", evsel->filter, evsel__name(evsel), errno, str_error_r(errno, errbuf, sizeof(errbuf))); - goto out_delete_evlist; + goto out_put_evlist; } out_error_mem: fprintf(trace->output, "Not enough memory to run!\n"); - goto out_delete_evlist; + goto out_put_evlist; =20 out_errno: fprintf(trace->output, "errno=3D%d,%s\n", errno, strerror(errno)); - goto out_delete_evlist; + goto out_put_evlist; } =20 static int trace__replay(struct trace *trace) @@ -5331,7 +5331,7 @@ static void trace__exit(struct trace *trace) zfree(&trace->syscalls.table); } zfree(&trace->perfconfig_events); - evlist__delete(trace->evlist); + evlist__put(trace->evlist); trace->evlist =3D NULL; ordered_events__free(&trace->oe.data); #ifdef HAVE_LIBBPF_SUPPORT diff --git a/tools/perf/tests/backward-ring-buffer.c b/tools/perf/tests/bac= kward-ring-buffer.c index c5e7999f2817..2b49b002d749 100644 --- a/tools/perf/tests/backward-ring-buffer.c +++ b/tools/perf/tests/backward-ring-buffer.c @@ -111,7 +111,7 @@ static int test__backward_ring_buffer(struct test_suite= *test __maybe_unused, in err =3D evlist__create_maps(evlist, &opts.target); if (err < 0) { pr_debug("Not enough memory to create thread/cpu maps\n"); - goto out_delete_evlist; + goto out_put_evlist; } =20 parse_events_error__init(&parse_error); @@ -124,7 +124,7 @@ static int test__backward_ring_buffer(struct test_suite= *test __maybe_unused, in if (err) { pr_debug("Failed to parse tracepoint event, try use root\n"); ret =3D TEST_SKIP; - goto out_delete_evlist; + goto out_put_evlist; } =20 evlist__config(evlist, &opts, NULL); @@ -133,19 +133,19 @@ static int test__backward_ring_buffer(struct test_sui= te *test __maybe_unused, in if (err < 0) { pr_debug("perf_evlist__open: %s\n", str_error_r(errno, sbuf, sizeof(sbuf))); - goto out_delete_evlist; + goto out_put_evlist; } =20 ret =3D TEST_FAIL; err =3D do_test(evlist, opts.mmap_pages, &sample_count, &comm_count); if (err !=3D TEST_OK) - goto out_delete_evlist; + goto out_put_evlist; =20 if ((sample_count !=3D NR_ITERS) || (comm_count !=3D NR_ITERS)) { pr_err("Unexpected counter: sample_count=3D%d, comm_count=3D%d\n", sample_count, comm_count); - goto out_delete_evlist; + goto out_put_evlist; } =20 evlist__close(evlist); @@ -154,16 +154,16 @@ static int test__backward_ring_buffer(struct test_sui= te *test __maybe_unused, in if (err < 0) { pr_debug("perf_evlist__open: %s\n", str_error_r(errno, sbuf, sizeof(sbuf))); - goto out_delete_evlist; + goto out_put_evlist; } =20 err =3D do_test(evlist, 1, &sample_count, &comm_count); if (err !=3D TEST_OK) - goto out_delete_evlist; + goto out_put_evlist; =20 ret =3D TEST_OK; -out_delete_evlist: - evlist__delete(evlist); +out_put_evlist: + evlist__put(evlist); return ret; } =20 diff --git a/tools/perf/tests/code-reading.c b/tools/perf/tests/code-readin= g.c index 5927d1ea20e2..8da8951154d8 100644 --- a/tools/perf/tests/code-reading.c +++ b/tools/perf/tests/code-reading.c @@ -806,7 +806,7 @@ static int do_test_code_reading(bool try_kcore) } =20 perf_evlist__set_maps(&evlist->core, NULL, NULL); - evlist__delete(evlist); + evlist__put(evlist); evlist =3D NULL; continue; } @@ -843,7 +843,7 @@ static int do_test_code_reading(bool try_kcore) out_put: thread__put(thread); out_err: - evlist__delete(evlist); + evlist__put(evlist); perf_cpu_map__put(cpus); perf_thread_map__put(threads); machine__delete(machine); diff --git a/tools/perf/tests/event-times.c b/tools/perf/tests/event-times.c index ae3b98bb42cf..94ab54ecd3f9 100644 --- a/tools/perf/tests/event-times.c +++ b/tools/perf/tests/event-times.c @@ -186,7 +186,7 @@ static int test_times(int (attach)(struct evlist *), err =3D attach(evlist); if (err =3D=3D TEST_SKIP) { pr_debug(" SKIP : not enough rights\n"); - evlist__delete(evlist); + evlist__put(evlist); return err; } =20 @@ -205,7 +205,7 @@ static int test_times(int (attach)(struct evlist *), count.ena, count.run); =20 out_err: - evlist__delete(evlist); + evlist__put(evlist); return !err ? TEST_OK : TEST_FAIL; } =20 diff --git a/tools/perf/tests/event_update.c b/tools/perf/tests/event_updat= e.c index cb9e6de2e033..8de66dac52b0 100644 --- a/tools/perf/tests/event_update.c +++ b/tools/perf/tests/event_update.c @@ -115,7 +115,7 @@ static int test__event_update(struct test_suite *test _= _maybe_unused, int subtes TEST_ASSERT_VAL("failed to synthesize attr update cpus", !perf_event__synthesize_event_update_cpus(&tmp.tool, evsel, process_eve= nt_cpus)); =20 - evlist__delete(evlist); + evlist__put(evlist); return 0; } =20 diff --git a/tools/perf/tests/evsel-roundtrip-name.c b/tools/perf/tests/evs= el-roundtrip-name.c index 1922cac13a24..6a220634c52f 100644 --- a/tools/perf/tests/evsel-roundtrip-name.c +++ b/tools/perf/tests/evsel-roundtrip-name.c @@ -33,7 +33,7 @@ static int perf_evsel__roundtrip_cache_name_test(void) if (err) { pr_debug("Failure to parse cache event '%s' possibly as PMUs don't su= pport it", name); - evlist__delete(evlist); + evlist__put(evlist); continue; } evlist__for_each_entry(evlist, evsel) { @@ -42,7 +42,7 @@ static int perf_evsel__roundtrip_cache_name_test(void) ret =3D TEST_FAIL; } } - evlist__delete(evlist); + evlist__put(evlist); } } } @@ -66,7 +66,7 @@ static int perf_evsel__name_array_test(const char *const = names[], int nr_names) if (err) { pr_debug("failed to parse event '%s', err %d\n", names[i], err); - evlist__delete(evlist); + evlist__put(evlist); ret =3D TEST_FAIL; continue; } @@ -76,7 +76,7 @@ static int perf_evsel__name_array_test(const char *const = names[], int nr_names) ret =3D TEST_FAIL; } } - evlist__delete(evlist); + evlist__put(evlist); } return ret; } diff --git a/tools/perf/tests/expand-cgroup.c b/tools/perf/tests/expand-cgr= oup.c index c7b32a220ca1..9060b085e3de 100644 --- a/tools/perf/tests/expand-cgroup.c +++ b/tools/perf/tests/expand-cgroup.c @@ -104,7 +104,7 @@ static int expand_default_events(void) TEST_ASSERT_VAL("failed to get evlist", evlist); =20 ret =3D test_expand_events(evlist); - evlist__delete(evlist); + evlist__put(evlist); return ret; } =20 @@ -131,7 +131,7 @@ static int expand_group_events(void) ret =3D test_expand_events(evlist); out: parse_events_error__exit(&err); - evlist__delete(evlist); + evlist__put(evlist); return ret; } =20 @@ -162,7 +162,7 @@ static int expand_libpfm_events(void) =20 ret =3D test_expand_events(evlist); out: - evlist__delete(evlist); + evlist__put(evlist); return ret; } =20 @@ -186,7 +186,7 @@ static int expand_metric_events(void) ret =3D test_expand_events(evlist); =20 out: - evlist__delete(evlist); + evlist__put(evlist); return ret; } =20 diff --git a/tools/perf/tests/hists_cumulate.c b/tools/perf/tests/hists_cum= ulate.c index 3eb9ef8d7ec6..8f7cce7b5085 100644 --- a/tools/perf/tests/hists_cumulate.c +++ b/tools/perf/tests/hists_cumulate.c @@ -744,7 +744,7 @@ static int test__hists_cumulate(struct test_suite *test= __maybe_unused, int subt =20 out: /* tear down everything */ - evlist__delete(evlist); + evlist__put(evlist); machines__exit(&machines); put_fake_samples(); =20 diff --git a/tools/perf/tests/hists_filter.c b/tools/perf/tests/hists_filte= r.c index 1cebd20cc91c..447fb2b5947c 100644 --- a/tools/perf/tests/hists_filter.c +++ b/tools/perf/tests/hists_filter.c @@ -331,7 +331,7 @@ static int test__hists_filter(struct test_suite *test _= _maybe_unused, int subtes =20 out: /* tear down everything */ - evlist__delete(evlist); + evlist__put(evlist); reset_output_field(); machines__exit(&machines); put_fake_samples(); diff --git a/tools/perf/tests/hists_link.c b/tools/perf/tests/hists_link.c index 996f5f0b3bd1..9646c3b7b4de 100644 --- a/tools/perf/tests/hists_link.c +++ b/tools/perf/tests/hists_link.c @@ -352,7 +352,7 @@ static int test__hists_link(struct test_suite *test __m= aybe_unused, int subtest =20 out: /* tear down everything */ - evlist__delete(evlist); + evlist__put(evlist); reset_output_field(); machines__exit(&machines); put_fake_samples(); diff --git a/tools/perf/tests/hists_output.c b/tools/perf/tests/hists_outpu= t.c index ee5ec8bda60e..aa8565fbaf90 100644 --- a/tools/perf/tests/hists_output.c +++ b/tools/perf/tests/hists_output.c @@ -631,7 +631,7 @@ static int test__hists_output(struct test_suite *test _= _maybe_unused, int subtes =20 out: /* tear down everything */ - evlist__delete(evlist); + evlist__put(evlist); machines__exit(&machines); put_fake_samples(); =20 diff --git a/tools/perf/tests/hwmon_pmu.c b/tools/perf/tests/hwmon_pmu.c index 97ea036ebae6..7d1040619575 100644 --- a/tools/perf/tests/hwmon_pmu.c +++ b/tools/perf/tests/hwmon_pmu.c @@ -211,7 +211,7 @@ static int do_test(size_t i, bool with_pmu, bool with_a= lias) =20 out: parse_events_error__exit(&err); - evlist__delete(evlist); + evlist__put(evlist); return ret; } =20 diff --git a/tools/perf/tests/keep-tracking.c b/tools/perf/tests/keep-track= ing.c index 729cc9cc1cb7..51cfd6522867 100644 --- a/tools/perf/tests/keep-tracking.c +++ b/tools/perf/tests/keep-tracking.c @@ -153,7 +153,7 @@ static int test__keep_tracking(struct test_suite *test = __maybe_unused, int subte out_err: if (evlist) { evlist__disable(evlist); - evlist__delete(evlist); + evlist__put(evlist); } perf_cpu_map__put(cpus); perf_thread_map__put(threads); diff --git a/tools/perf/tests/mmap-basic.c b/tools/perf/tests/mmap-basic.c index a622bb8d4cc8..2591b6fbec3f 100644 --- a/tools/perf/tests/mmap-basic.c +++ b/tools/perf/tests/mmap-basic.c @@ -93,7 +93,7 @@ static int test__basic_mmap(struct test_suite *test __may= be_unused, int subtest /* Permissions failure, flag the failure as a skip. */ err =3D TEST_SKIP; } - goto out_delete_evlist; + goto out_put_evlist; } =20 evsels[i]->core.attr.wakeup_events =3D 1; @@ -105,7 +105,7 @@ static int test__basic_mmap(struct test_suite *test __m= aybe_unused, int subtest pr_debug("failed to open counter: %s, " "tweak /proc/sys/kernel/perf_event_paranoid?\n", str_error_r(errno, sbuf, sizeof(sbuf))); - goto out_delete_evlist; + goto out_put_evlist; } =20 nr_events[i] =3D 0; @@ -115,7 +115,7 @@ static int test__basic_mmap(struct test_suite *test __m= aybe_unused, int subtest if (evlist__mmap(evlist, 128) < 0) { pr_debug("failed to mmap events: %d (%s)\n", errno, str_error_r(errno, sbuf, sizeof(sbuf))); - goto out_delete_evlist; + goto out_put_evlist; } =20 for (i =3D 0; i < nsyscalls; ++i) @@ -133,7 +133,7 @@ static int test__basic_mmap(struct test_suite *test __m= aybe_unused, int subtest if (event->header.type !=3D PERF_RECORD_SAMPLE) { pr_debug("unexpected %s event\n", perf_event__name(event->header.type)); - goto out_delete_evlist; + goto out_put_evlist; } =20 perf_sample__init(&sample, /*all=3D*/false); @@ -141,7 +141,7 @@ static int test__basic_mmap(struct test_suite *test __m= aybe_unused, int subtest if (err) { pr_err("Can't parse sample, err =3D %d\n", err); perf_sample__exit(&sample); - goto out_delete_evlist; + goto out_put_evlist; } =20 err =3D -1; @@ -150,7 +150,7 @@ static int test__basic_mmap(struct test_suite *test __m= aybe_unused, int subtest if (evsel =3D=3D NULL) { pr_debug("event with id %" PRIu64 " doesn't map to an evsel\n", sample.id); - goto out_delete_evlist; + goto out_put_evlist; } nr_events[evsel->core.idx]++; perf_mmap__consume(&md->core); @@ -165,12 +165,12 @@ static int test__basic_mmap(struct test_suite *test _= _maybe_unused, int subtest expected_nr_events[evsel->core.idx], evsel__name(evsel), nr_events[evsel->core.idx]); err =3D -1; - goto out_delete_evlist; + goto out_put_evlist; } } =20 -out_delete_evlist: - evlist__delete(evlist); +out_put_evlist: + evlist__put(evlist); out_free_cpus: perf_cpu_map__put(cpus); out_free_threads: diff --git a/tools/perf/tests/openat-syscall-tp-fields.c b/tools/perf/tests= /openat-syscall-tp-fields.c index 2a139d2781a8..3ff595c7a86a 100644 --- a/tools/perf/tests/openat-syscall-tp-fields.c +++ b/tools/perf/tests/openat-syscall-tp-fields.c @@ -51,7 +51,7 @@ static int test__syscall_openat_tp_fields(struct test_sui= te *test __maybe_unused if (IS_ERR(evsel)) { pr_debug("%s: evsel__newtp\n", __func__); ret =3D PTR_ERR(evsel) =3D=3D -EACCES ? TEST_SKIP : TEST_FAIL; - goto out_delete_evlist; + goto out_put_evlist; } =20 evlist__add(evlist, evsel); @@ -59,7 +59,7 @@ static int test__syscall_openat_tp_fields(struct test_sui= te *test __maybe_unused err =3D evlist__create_maps(evlist, &opts.target); if (err < 0) { pr_debug("%s: evlist__create_maps\n", __func__); - goto out_delete_evlist; + goto out_put_evlist; } =20 evsel__config(evsel, &opts, NULL); @@ -70,14 +70,14 @@ static int test__syscall_openat_tp_fields(struct test_s= uite *test __maybe_unused if (err < 0) { pr_debug("perf_evlist__open: %s\n", str_error_r(errno, sbuf, sizeof(sbuf))); - goto out_delete_evlist; + goto out_put_evlist; } =20 err =3D evlist__mmap(evlist, UINT_MAX); if (err < 0) { pr_debug("evlist__mmap: %s\n", str_error_r(errno, sbuf, sizeof(sbuf))); - goto out_delete_evlist; + goto out_put_evlist; } =20 evlist__enable(evlist); @@ -115,7 +115,7 @@ static int test__syscall_openat_tp_fields(struct test_s= uite *test __maybe_unused if (err) { pr_debug("Can't parse sample, err =3D %d\n", err); perf_sample__exit(&sample); - goto out_delete_evlist; + goto out_put_evlist; } =20 tp_flags =3D evsel__intval(evsel, &sample, "flags"); @@ -123,7 +123,7 @@ static int test__syscall_openat_tp_fields(struct test_s= uite *test __maybe_unused if (flags !=3D tp_flags) { pr_debug("%s: Expected flags=3D%#x, got %#x\n", __func__, flags, tp_flags); - goto out_delete_evlist; + goto out_put_evlist; } =20 goto out_ok; @@ -136,13 +136,13 @@ static int test__syscall_openat_tp_fields(struct test= _suite *test __maybe_unused =20 if (++nr_polls > 5) { pr_debug("%s: no events!\n", __func__); - goto out_delete_evlist; + goto out_put_evlist; } } out_ok: ret =3D TEST_OK; -out_delete_evlist: - evlist__delete(evlist); +out_put_evlist: + evlist__put(evlist); out: return ret; } diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-event= s.c index e4cdb517c10e..0778462016f7 100644 --- a/tools/perf/tests/parse-events.c +++ b/tools/perf/tests/parse-events.c @@ -2550,7 +2550,7 @@ static int test_event(const struct evlist_test *e) ret =3D e->check(evlist); } parse_events_error__exit(&err); - evlist__delete(evlist); + evlist__put(evlist); =20 return ret; } @@ -2576,7 +2576,7 @@ static int test_event_fake_pmu(const char *str) } =20 parse_events_error__exit(&err); - evlist__delete(evlist); + evlist__put(evlist); =20 return ret; } diff --git a/tools/perf/tests/parse-metric.c b/tools/perf/tests/parse-metri= c.c index 66a5275917e2..b343628c7a7e 100644 --- a/tools/perf/tests/parse-metric.c +++ b/tools/perf/tests/parse-metric.c @@ -83,7 +83,7 @@ static int __compute_metric(const char *name, struct valu= e *vals, =20 cpus =3D perf_cpu_map__new("0"); if (!cpus) { - evlist__delete(evlist); + evlist__put(evlist); return -ENOMEM; } =20 @@ -112,7 +112,7 @@ static int __compute_metric(const char *name, struct va= lue *vals, /* ... cleanup. */ evlist__free_stats(evlist); perf_cpu_map__put(cpus); - evlist__delete(evlist); + evlist__put(evlist); return err; } =20 diff --git a/tools/perf/tests/parse-no-sample-id-all.c b/tools/perf/tests/p= arse-no-sample-id-all.c index 50e68b7d43aa..d5a8d065809e 100644 --- a/tools/perf/tests/parse-no-sample-id-all.c +++ b/tools/perf/tests/parse-no-sample-id-all.c @@ -49,7 +49,7 @@ static int process_events(union perf_event **events, size= _t count) for (i =3D 0; i < count && !err; i++) err =3D process_event(&evlist, events[i]); =20 - evlist__delete(evlist); + evlist__put(evlist); =20 return err; } diff --git a/tools/perf/tests/perf-record.c b/tools/perf/tests/perf-record.c index efbd9cd60c63..babec674b83c 100644 --- a/tools/perf/tests/perf-record.c +++ b/tools/perf/tests/perf-record.c @@ -102,7 +102,7 @@ static int test__PERF_RECORD(struct test_suite *test __= maybe_unused, int subtest err =3D evlist__create_maps(evlist, &opts.target); if (err < 0) { pr_debug("Not enough memory to create thread/cpu maps\n"); - goto out_delete_evlist; + goto out_put_evlist; } =20 /* @@ -114,7 +114,7 @@ static int test__PERF_RECORD(struct test_suite *test __= maybe_unused, int subtest err =3D evlist__prepare_workload(evlist, &opts.target, argv, false, NULL); if (err < 0) { pr_debug("Couldn't run the workload!\n"); - goto out_delete_evlist; + goto out_put_evlist; } =20 /* @@ -131,7 +131,7 @@ static int test__PERF_RECORD(struct test_suite *test __= maybe_unused, int subtest pr_debug("sched__get_first_possible_cpu: %s\n", str_error_r(errno, sbuf, sizeof(sbuf))); evlist__cancel_workload(evlist); - goto out_delete_evlist; + goto out_put_evlist; } =20 cpu =3D err; @@ -143,7 +143,7 @@ static int test__PERF_RECORD(struct test_suite *test __= maybe_unused, int subtest pr_debug("sched_setaffinity: %s\n", str_error_r(errno, sbuf, sizeof(sbuf))); evlist__cancel_workload(evlist); - goto out_delete_evlist; + goto out_put_evlist; } =20 /* @@ -155,7 +155,7 @@ static int test__PERF_RECORD(struct test_suite *test __= maybe_unused, int subtest pr_debug("perf_evlist__open: %s\n", str_error_r(errno, sbuf, sizeof(sbuf))); evlist__cancel_workload(evlist); - goto out_delete_evlist; + goto out_put_evlist; } =20 /* @@ -168,7 +168,7 @@ static int test__PERF_RECORD(struct test_suite *test __= maybe_unused, int subtest pr_debug("evlist__mmap: %s\n", str_error_r(errno, sbuf, sizeof(sbuf))); evlist__cancel_workload(evlist); - goto out_delete_evlist; + goto out_put_evlist; } =20 /* @@ -206,7 +206,7 @@ static int test__PERF_RECORD(struct test_suite *test __= maybe_unused, int subtest if (verbose > 0) perf_event__fprintf(event, NULL, stderr); pr_debug("Couldn't parse sample\n"); - goto out_delete_evlist; + goto out_put_evlist; } =20 if (verbose > 0) { @@ -346,9 +346,9 @@ static int test__PERF_RECORD(struct test_suite *test __= maybe_unused, int subtest pr_debug("PERF_RECORD_MMAP for %s missing!\n", "[vdso]"); ++errs; } -out_delete_evlist: +out_put_evlist: CPU_FREE(cpu_mask); - evlist__delete(evlist); + evlist__put(evlist); out: perf_sample__exit(&sample); if (err =3D=3D -EACCES) diff --git a/tools/perf/tests/perf-time-to-tsc.c b/tools/perf/tests/perf-ti= me-to-tsc.c index cca41bd37ae3..d3538fa20af3 100644 --- a/tools/perf/tests/perf-time-to-tsc.c +++ b/tools/perf/tests/perf-time-to-tsc.c @@ -201,7 +201,7 @@ static int test__perf_time_to_tsc(struct test_suite *te= st __maybe_unused, int su err =3D TEST_OK; =20 out_err: - evlist__delete(evlist); + evlist__put(evlist); perf_cpu_map__put(cpus); perf_thread_map__put(threads); return err; diff --git a/tools/perf/tests/pfm.c b/tools/perf/tests/pfm.c index 2e38dfa34b6c..099a50dec37e 100644 --- a/tools/perf/tests/pfm.c +++ b/tools/perf/tests/pfm.c @@ -79,7 +79,7 @@ static int test__pfm_events(struct test_suite *test __may= be_unused, evlist__nr_groups(evlist), 0); =20 - evlist__delete(evlist); + evlist__put(evlist); } return 0; } @@ -164,7 +164,7 @@ static int test__pfm_group(struct test_suite *test __ma= ybe_unused, evlist__nr_groups(evlist), table[i].nr_groups); =20 - evlist__delete(evlist); + evlist__put(evlist); } return 0; } diff --git a/tools/perf/tests/pmu-events.c b/tools/perf/tests/pmu-events.c index f40a828c9861..ab547f301c61 100644 --- a/tools/perf/tests/pmu-events.c +++ b/tools/perf/tests/pmu-events.c @@ -797,7 +797,7 @@ static int check_parse_id(const char *id, struct parse_= events_error *error) /*warn_if_reordered=3D*/true, /*fake_tp=3D*/false); free(dup); =20 - evlist__delete(evlist); + evlist__put(evlist); return ret; } =20 @@ -844,7 +844,7 @@ static int test__parsing_callback(const struct pmu_metr= ic *pm, =20 cpus =3D perf_cpu_map__new("0"); if (!cpus) { - evlist__delete(evlist); + evlist__put(evlist); return -ENOMEM; } =20 @@ -901,7 +901,7 @@ static int test__parsing_callback(const struct pmu_metr= ic *pm, /* ... cleanup. */ evlist__free_stats(evlist); perf_cpu_map__put(cpus); - evlist__delete(evlist); + evlist__put(evlist); return err; } =20 diff --git a/tools/perf/tests/pmu.c b/tools/perf/tests/pmu.c index cbded2c6faa4..bd3f4a2806ed 100644 --- a/tools/perf/tests/pmu.c +++ b/tools/perf/tests/pmu.c @@ -249,7 +249,7 @@ static int test__pmu_events(struct test_suite *test __m= aybe_unused, int subtest ret =3D TEST_OK; err_out: parse_events_error__exit(&err); - evlist__delete(evlist); + evlist__put(evlist); test_pmu_put(dir, pmu); return ret; } diff --git a/tools/perf/tests/sw-clock.c b/tools/perf/tests/sw-clock.c index 4a2ad7176fa0..f7f1f16638b4 100644 --- a/tools/perf/tests/sw-clock.c +++ b/tools/perf/tests/sw-clock.c @@ -58,7 +58,7 @@ static int __test__sw_clock_freq(enum perf_sw_ids clock_i= d) evsel =3D evsel__new(&attr); if (evsel =3D=3D NULL) { pr_debug("evsel__new\n"); - goto out_delete_evlist; + goto out_put_evlist; } evlist__add(evlist, evsel); =20 @@ -67,7 +67,7 @@ static int __test__sw_clock_freq(enum perf_sw_ids clock_i= d) if (!cpus || !threads) { err =3D -ENOMEM; pr_debug("Not enough memory to create thread/cpu maps\n"); - goto out_delete_evlist; + goto out_put_evlist; } =20 perf_evlist__set_maps(&evlist->core, cpus, threads); @@ -79,14 +79,14 @@ static int __test__sw_clock_freq(enum perf_sw_ids clock= _id) pr_debug("Couldn't open evlist: %s\nHint: check %s, using %" PRIu64 " in= this test.\n", str_error_r(errno, sbuf, sizeof(sbuf)), knob, (u64)attr.sample_freq); - goto out_delete_evlist; + goto out_put_evlist; } =20 err =3D evlist__mmap(evlist, 128); if (err < 0) { pr_debug("failed to mmap event: %d (%s)\n", errno, str_error_r(errno, sbuf, sizeof(sbuf))); - goto out_delete_evlist; + goto out_put_evlist; } =20 evlist__enable(evlist); @@ -112,7 +112,7 @@ static int __test__sw_clock_freq(enum perf_sw_ids clock= _id) if (err < 0) { pr_debug("Error during parse sample\n"); perf_sample__exit(&sample); - goto out_delete_evlist; + goto out_put_evlist; } =20 total_periods +=3D sample.period; @@ -130,10 +130,10 @@ static int __test__sw_clock_freq(enum perf_sw_ids clo= ck_id) err =3D -1; } =20 -out_delete_evlist: +out_put_evlist: perf_cpu_map__put(cpus); perf_thread_map__put(threads); - evlist__delete(evlist); + evlist__put(evlist); return err; } =20 diff --git a/tools/perf/tests/switch-tracking.c b/tools/perf/tests/switch-t= racking.c index 15791fcb76b2..c3d5825df0a8 100644 --- a/tools/perf/tests/switch-tracking.c +++ b/tools/perf/tests/switch-tracking.c @@ -577,7 +577,7 @@ static int test__switch_tracking(struct test_suite *tes= t __maybe_unused, int sub out: if (evlist) { evlist__disable(evlist); - evlist__delete(evlist); + evlist__put(evlist); } perf_cpu_map__put(cpus); perf_thread_map__put(threads); diff --git a/tools/perf/tests/task-exit.c b/tools/perf/tests/task-exit.c index 4053ff2813bb..a46650b10689 100644 --- a/tools/perf/tests/task-exit.c +++ b/tools/perf/tests/task-exit.c @@ -74,7 +74,7 @@ static int test__task_exit(struct test_suite *test __mayb= e_unused, int subtest _ if (!cpus || !threads) { err =3D -ENOMEM; pr_debug("Not enough memory to create thread/cpu maps\n"); - goto out_delete_evlist; + goto out_put_evlist; } =20 perf_evlist__set_maps(&evlist->core, cpus, threads); @@ -82,7 +82,7 @@ static int test__task_exit(struct test_suite *test __mayb= e_unused, int subtest _ err =3D evlist__prepare_workload(evlist, &target, argv, false, workload_e= xec_failed_signal); if (err < 0) { pr_debug("Couldn't run the workload!\n"); - goto out_delete_evlist; + goto out_put_evlist; } =20 evsel =3D evlist__first(evlist); @@ -101,14 +101,14 @@ static int test__task_exit(struct test_suite *test __= maybe_unused, int subtest _ if (err < 0) { pr_debug("Couldn't open the evlist: %s\n", str_error_r(-err, sbuf, sizeof(sbuf))); - goto out_delete_evlist; + goto out_put_evlist; } =20 if (evlist__mmap(evlist, 128) < 0) { pr_debug("failed to mmap events: %d (%s)\n", errno, str_error_r(errno, sbuf, sizeof(sbuf))); err =3D -1; - goto out_delete_evlist; + goto out_put_evlist; } =20 evlist__start_workload(evlist); @@ -133,7 +133,7 @@ static int test__task_exit(struct test_suite *test __ma= ybe_unused, int subtest _ if (retry_count++ > 1000) { pr_debug("Failed after retrying 1000 times\n"); err =3D -1; - goto out_delete_evlist; + goto out_put_evlist; } =20 goto retry; @@ -144,10 +144,10 @@ static int test__task_exit(struct test_suite *test __= maybe_unused, int subtest _ err =3D -1; } =20 -out_delete_evlist: +out_put_evlist: perf_cpu_map__put(cpus); perf_thread_map__put(threads); - evlist__delete(evlist); + evlist__put(evlist); return err; } =20 diff --git a/tools/perf/tests/tool_pmu.c b/tools/perf/tests/tool_pmu.c index 1e900ef92e37..e78ff9dcea97 100644 --- a/tools/perf/tests/tool_pmu.c +++ b/tools/perf/tests/tool_pmu.c @@ -67,7 +67,7 @@ static int do_test(enum tool_pmu_event ev, bool with_pmu) =20 out: parse_events_error__exit(&err); - evlist__delete(evlist); + evlist__put(evlist); return ret; } =20 diff --git a/tools/perf/tests/topology.c b/tools/perf/tests/topology.c index af4618c3124a..b88447899021 100644 --- a/tools/perf/tests/topology.c +++ b/tools/perf/tests/topology.c @@ -55,7 +55,7 @@ static int session_write_header(char *path) !perf_session__write_header(session, session->evlist, perf_data__fd(&data), true)); =20 - evlist__delete(session->evlist); + evlist__put(session->evlist); perf_session__delete(session); =20 return 0; diff --git a/tools/perf/util/cgroup.c b/tools/perf/util/cgroup.c index 25e2769b5e74..ed230cd44ba7 100644 --- a/tools/perf/util/cgroup.c +++ b/tools/perf/util/cgroup.c @@ -503,8 +503,8 @@ int evlist__expand_cgroup(struct evlist *evlist, const = char *str, bool open_cgro cgrp_event_expanded =3D true; =20 out_err: - evlist__delete(orig_list); - evlist__delete(tmp_list); + evlist__put(orig_list); + evlist__put(tmp_list); metricgroup__rblist_exit(&orig_metric_events); release_cgroup_list(); =20 diff --git a/tools/perf/util/data-convert-bt.c b/tools/perf/util/data-conve= rt-bt.c index 3d2e437e1354..1166cdb00aca 100644 --- a/tools/perf/util/data-convert-bt.c +++ b/tools/perf/util/data-convert-bt.c @@ -1331,7 +1331,7 @@ static void cleanup_events(struct perf_session *sessi= on) zfree(&evsel->priv); } =20 - evlist__delete(evlist); + evlist__put(evlist); session->evlist =3D NULL; } =20 diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index d99a3f12606f..ea1f398c14e3 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -73,7 +73,7 @@ int sigqueue(pid_t pid, int sig, const union sigval value= ); #define FD(e, x, y) (*(int *)xyarray__entry(e->core.fd, x, y)) #define SID(e, x, y) xyarray__entry(e->core.sample_id, x, y) =20 -void evlist__init(struct evlist *evlist, struct perf_cpu_map *cpus, +static void evlist__init(struct evlist *evlist, struct perf_cpu_map *cpus, struct perf_thread_map *threads) { perf_evlist__init(&evlist->core); @@ -85,6 +85,7 @@ void evlist__init(struct evlist *evlist, struct perf_cpu_= map *cpus, evlist->ctl_fd.pos =3D -1; evlist->nr_br_cntr =3D -1; metricgroup__rblist_init(&evlist->metric_events); + refcount_set(&evlist->refcnt, 1); } =20 struct evlist *evlist__new(void) @@ -116,7 +117,7 @@ struct evlist *evlist__new_default(void) can_profile_kernel ? "P" : "Pu"); err =3D parse_event(evlist, buf); if (err) { - evlist__delete(evlist); + evlist__put(evlist); return NULL; } } @@ -136,13 +137,19 @@ struct evlist *evlist__new_dummy(void) struct evlist *evlist =3D evlist__new(); =20 if (evlist && evlist__add_dummy(evlist)) { - evlist__delete(evlist); + evlist__put(evlist); evlist =3D NULL; } =20 return evlist; } =20 +struct evlist *evlist__get(struct evlist *evlist) +{ + refcount_inc(&evlist->refcnt); + return evlist; +} + /** * evlist__set_id_pos - set the positions of event ids. * @evlist: selected event list @@ -181,7 +188,7 @@ static void evlist__purge(struct evlist *evlist) evlist->core.nr_entries =3D 0; } =20 -void evlist__exit(struct evlist *evlist) +static void evlist__exit(struct evlist *evlist) { metricgroup__rblist_exit(&evlist->metric_events); event_enable_timer__exit(&evlist->eet); @@ -190,11 +197,14 @@ void evlist__exit(struct evlist *evlist) perf_evlist__exit(&evlist->core); } =20 -void evlist__delete(struct evlist *evlist) +void evlist__put(struct evlist *evlist) { if (evlist =3D=3D NULL) return; =20 + if (!refcount_dec_and_test(&evlist->refcnt)) + return; + evlist__free_stats(evlist); evlist__munmap(evlist); evlist__close(evlist); diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h index 61acbb10d9a5..66fb5da08160 100644 --- a/tools/perf/util/evlist.h +++ b/tools/perf/util/evlist.h @@ -59,6 +59,7 @@ struct event_enable_timer; =20 struct evlist { struct perf_evlist core; + refcount_t refcnt; bool enabled; int id_pos; int is_pos; @@ -104,10 +105,8 @@ struct evsel_str_handler { struct evlist *evlist__new(void); struct evlist *evlist__new_default(void); struct evlist *evlist__new_dummy(void); -void evlist__init(struct evlist *evlist, struct perf_cpu_map *cpus, - struct perf_thread_map *threads); -void evlist__exit(struct evlist *evlist); -void evlist__delete(struct evlist *evlist); +struct evlist *evlist__get(struct evlist *evlist); +void evlist__put(struct evlist *evlist); =20 void evlist__add(struct evlist *evlist, struct evsel *entry); void evlist__remove(struct evlist *evlist, struct evsel *evsel); diff --git a/tools/perf/util/expr.c b/tools/perf/util/expr.c index 7fda0ff89c16..4304b53b5a37 100644 --- a/tools/perf/util/expr.c +++ b/tools/perf/util/expr.c @@ -451,7 +451,7 @@ double expr__has_event(const struct expr_parse_ctx *ctx= , bool compute_ids, const ret =3D parse_event(tmp, id) ? 0 : 1; } out: - evlist__delete(tmp); + evlist__put(tmp); return ret; } =20 diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 4f2a6e10ed5c..e959ddb12dc8 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -4307,12 +4307,12 @@ int perf_session__read_header(struct perf_session *= session) evsel =3D evsel__new(&f_attr.attr); =20 if (evsel =3D=3D NULL) - goto out_delete_evlist; + goto out_put_evlist; =20 evsel->needs_swap =3D header->needs_swap; /* * Do it before so that if perf_evsel__alloc_id fails, this - * entry gets purged too at evlist__delete(). + * entry gets purged too at evlist__put(). */ evlist__add(session->evlist, evsel); =20 @@ -4323,7 +4323,7 @@ int perf_session__read_header(struct perf_session *se= ssion) * hattr->ids threads. */ if (perf_evsel__alloc_id(&evsel->core, 1, nr_ids)) - goto out_delete_evlist; + goto out_put_evlist; =20 lseek(fd, f_attr.ids.offset, SEEK_SET); =20 @@ -4342,7 +4342,7 @@ int perf_session__read_header(struct perf_session *se= ssion) perf_file_section__process); =20 if (evlist__prepare_tracepoint_events(session->evlist, session->tevent.pe= vent)) - goto out_delete_evlist; + goto out_put_evlist; #else perf_header__process_sections(header, fd, NULL, perf_file_section__proces= s); #endif @@ -4351,8 +4351,8 @@ int perf_session__read_header(struct perf_session *se= ssion) out_errno: return -errno; =20 -out_delete_evlist: - evlist__delete(session->evlist); +out_put_evlist: + evlist__put(session->evlist); session->evlist =3D NULL; return -ENOMEM; } diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index 595b83142d2c..64c64dff7424 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -212,7 +212,7 @@ static void metric__free(struct metric *m) zfree(&m->metric_refs); expr__ctx_free(m->pctx); zfree(&m->modifier); - evlist__delete(m->evlist); + evlist__put(m->evlist); free(m); } =20 @@ -1318,7 +1318,7 @@ static int parse_ids(bool metric_no_merge, bool fake_= pmu, parsed_evlist =3D NULL; err_out: parse_events_error__exit(&parse_error); - evlist__delete(parsed_evlist); + evlist__put(parsed_evlist); strbuf_release(&events); return ret; } @@ -1470,7 +1470,7 @@ static int parse_groups(struct evlist *perf_evlist, =20 if (combined_evlist) { evlist__splice_list_tail(perf_evlist, &combined_evlist->core.entries); - evlist__delete(combined_evlist); + evlist__put(combined_evlist); } =20 list_for_each_entry(m, &metric_list, nd) { diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 0c0dc20b1c13..607ab7b82486 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -2223,7 +2223,7 @@ int __parse_events(struct evlist *evlist, const char = *str, const char *pmu_filte =20 /* * There are 2 users - builtin-record and builtin-test objects. - * Both call evlist__delete in case of error, so we dont + * Both call evlist__put in case of error, so we dont * need to bother. */ return ret; @@ -2424,7 +2424,7 @@ int parse_events_option_new_evlist(const struct optio= n *opt, const char *str, in } ret =3D parse_events_option(opt, str, unset); if (ret) { - evlist__delete(*args->evlistp); + evlist__put(*args->evlistp); *args->evlistp =3D NULL; } =20 diff --git a/tools/perf/util/perf_api_probe.c b/tools/perf/util/perf_api_pr= obe.c index 3345145a9307..8cd254d36220 100644 --- a/tools/perf/util/perf_api_probe.c +++ b/tools/perf/util/perf_api_probe.c @@ -56,7 +56,7 @@ static int perf_do_probe_api(setup_probe_fn_t fn, struct = perf_cpu cpu, const cha err =3D 0; =20 out_delete: - evlist__delete(evlist); + evlist__put(evlist); return err; } =20 diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index dfc6e9299af9..4149a51e9878 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -1273,7 +1273,7 @@ static int pyrf_evsel__setup_types(void) struct pyrf_evlist { PyObject_HEAD =20 - struct evlist evlist; + struct evlist *evlist; }; =20 static int pyrf_evlist__init(struct pyrf_evlist *pevlist, @@ -1286,15 +1286,21 @@ static int pyrf_evlist__init(struct pyrf_evlist *pe= vlist, if (!PyArg_ParseTuple(args, "OO", &pcpus, &pthreads)) return -1; =20 + pevlist->evlist =3D evlist__new(); + if (!pevlist->evlist) { + PyErr_NoMemory(); + return -1; + } threads =3D ((struct pyrf_thread_map *)pthreads)->threads; cpus =3D ((struct pyrf_cpu_map *)pcpus)->cpus; - evlist__init(&pevlist->evlist, cpus, threads); + perf_evlist__set_maps(&pevlist->evlist->core, cpus, threads); + return 0; } =20 static void pyrf_evlist__delete(struct pyrf_evlist *pevlist) { - evlist__exit(&pevlist->evlist); + evlist__put(pevlist->evlist); Py_TYPE(pevlist)->tp_free((PyObject*)pevlist); } =20 @@ -1303,7 +1309,7 @@ static PyObject *pyrf_evlist__all_cpus(struct pyrf_ev= list *pevlist) struct pyrf_cpu_map *pcpu_map =3D PyObject_New(struct pyrf_cpu_map, &pyrf= _cpu_map__type); =20 if (pcpu_map) - pcpu_map->cpus =3D perf_cpu_map__get(pevlist->evlist.core.all_cpus); + pcpu_map->cpus =3D perf_cpu_map__get(pevlist->evlist->core.all_cpus); =20 return (PyObject *)pcpu_map; } @@ -1316,7 +1322,7 @@ static PyObject *pyrf_evlist__metrics(struct pyrf_evl= ist *pevlist) if (!list) return NULL; =20 - for (node =3D rb_first_cached(&pevlist->evlist.metric_events.entries); no= de; + for (node =3D rb_first_cached(&pevlist->evlist->metric_events.entries); n= ode; node =3D rb_next(node)) { struct metric_event *me =3D container_of(node, struct metric_event, nd); struct list_head *pos; @@ -1400,7 +1406,7 @@ static PyObject *pyrf_evlist__compute_metric(struct p= yrf_evlist *pevlist, if (!PyArg_ParseTuple(args, "sii", &metric, &cpu, &thread)) return NULL; =20 - for (node =3D rb_first_cached(&pevlist->evlist.metric_events.entries); + for (node =3D rb_first_cached(&pevlist->evlist->metric_events.entries); mexp =3D=3D NULL && node; node =3D rb_next(node)) { struct metric_event *me =3D container_of(node, struct metric_event, nd); @@ -1456,7 +1462,7 @@ static PyObject *pyrf_evlist__compute_metric(struct p= yrf_evlist *pevlist, static PyObject *pyrf_evlist__mmap(struct pyrf_evlist *pevlist, PyObject *args, PyObject *kwargs) { - struct evlist *evlist =3D &pevlist->evlist; + struct evlist *evlist =3D pevlist->evlist; static char *kwlist[] =3D { "pages", "overwrite", NULL }; int pages =3D 128, overwrite =3D false; =20 @@ -1476,7 +1482,7 @@ static PyObject *pyrf_evlist__mmap(struct pyrf_evlist= *pevlist, static PyObject *pyrf_evlist__poll(struct pyrf_evlist *pevlist, PyObject *args, PyObject *kwargs) { - struct evlist *evlist =3D &pevlist->evlist; + struct evlist *evlist =3D pevlist->evlist; static char *kwlist[] =3D { "timeout", NULL }; int timeout =3D -1, n; =20 @@ -1496,7 +1502,7 @@ static PyObject *pyrf_evlist__get_pollfd(struct pyrf_= evlist *pevlist, PyObject *args __maybe_unused, PyObject *kwargs __maybe_unused) { - struct evlist *evlist =3D &pevlist->evlist; + struct evlist *evlist =3D pevlist->evlist; PyObject *list =3D PyList_New(0); int i; =20 @@ -1525,7 +1531,7 @@ static PyObject *pyrf_evlist__add(struct pyrf_evlist = *pevlist, PyObject *args, PyObject *kwargs __maybe_unused) { - struct evlist *evlist =3D &pevlist->evlist; + struct evlist *evlist =3D pevlist->evlist; PyObject *pevsel; struct evsel *evsel; =20 @@ -1557,7 +1563,7 @@ static struct mmap *get_md(struct evlist *evlist, int= cpu) static PyObject *pyrf_evlist__read_on_cpu(struct pyrf_evlist *pevlist, PyObject *args, PyObject *kwargs) { - struct evlist *evlist =3D &pevlist->evlist; + struct evlist *evlist =3D pevlist->evlist; union perf_event *event; int sample_id_all =3D 1, cpu; static char *kwlist[] =3D { "cpu", "sample_id_all", NULL }; @@ -1614,7 +1620,7 @@ static PyObject *pyrf_evlist__read_on_cpu(struct pyrf= _evlist *pevlist, static PyObject *pyrf_evlist__open(struct pyrf_evlist *pevlist, PyObject *args, PyObject *kwargs) { - struct evlist *evlist =3D &pevlist->evlist; + struct evlist *evlist =3D pevlist->evlist; =20 if (evlist__open(evlist) < 0) { PyErr_SetFromErrno(PyExc_OSError); @@ -1627,7 +1633,7 @@ static PyObject *pyrf_evlist__open(struct pyrf_evlist= *pevlist, =20 static PyObject *pyrf_evlist__close(struct pyrf_evlist *pevlist) { - struct evlist *evlist =3D &pevlist->evlist; + struct evlist *evlist =3D pevlist->evlist; =20 evlist__close(evlist); =20 @@ -1653,7 +1659,7 @@ static PyObject *pyrf_evlist__config(struct pyrf_evli= st *pevlist) .no_buffering =3D true, .no_inherit =3D true, }; - struct evlist *evlist =3D &pevlist->evlist; + struct evlist *evlist =3D pevlist->evlist; =20 evlist__config(evlist, &opts, &callchain_param); Py_INCREF(Py_None); @@ -1662,14 +1668,14 @@ static PyObject *pyrf_evlist__config(struct pyrf_ev= list *pevlist) =20 static PyObject *pyrf_evlist__disable(struct pyrf_evlist *pevlist) { - evlist__disable(&pevlist->evlist); + evlist__disable(pevlist->evlist); Py_INCREF(Py_None); return Py_None; } =20 static PyObject *pyrf_evlist__enable(struct pyrf_evlist *pevlist) { - evlist__enable(&pevlist->evlist); + evlist__enable(pevlist->evlist); Py_INCREF(Py_None); return Py_None; } @@ -1760,7 +1766,23 @@ static Py_ssize_t pyrf_evlist__length(PyObject *obj) { struct pyrf_evlist *pevlist =3D (void *)obj; =20 - return pevlist->evlist.core.nr_entries; + return pevlist->evlist->core.nr_entries; +} + +static PyObject *pyrf_evsel__from_evsel(struct evsel *evsel) +{ + struct pyrf_evsel *pevsel =3D PyObject_New(struct pyrf_evsel, &pyrf_evsel= __type); + + if (!pevsel) + return NULL; + + memset(&pevsel->evsel, 0, sizeof(pevsel->evsel)); + evsel__init(&pevsel->evsel, &evsel->core.attr, evsel->core.idx); + + evsel__clone(&pevsel->evsel, evsel); + if (evsel__is_group_leader(evsel)) + evsel__set_leader(&pevsel->evsel, &pevsel->evsel); + return (PyObject *)pevsel; } =20 static PyObject *pyrf_evlist__item(PyObject *obj, Py_ssize_t i) @@ -1768,17 +1790,16 @@ static PyObject *pyrf_evlist__item(PyObject *obj, P= y_ssize_t i) struct pyrf_evlist *pevlist =3D (void *)obj; struct evsel *pos; =20 - if (i >=3D pevlist->evlist.core.nr_entries) { + if (i >=3D pevlist->evlist->core.nr_entries) { PyErr_SetString(PyExc_IndexError, "Index out of range"); return NULL; } =20 - evlist__for_each_entry(&pevlist->evlist, pos) { + evlist__for_each_entry(pevlist->evlist, pos) { if (i-- =3D=3D 0) break; } - - return Py_BuildValue("O", container_of(pos, struct pyrf_evsel, evsel)); + return pyrf_evsel__from_evsel(pos); } =20 static PyObject *pyrf_evlist__str(PyObject *self) @@ -1790,7 +1811,7 @@ static PyObject *pyrf_evlist__str(PyObject *self) PyObject *result; =20 strbuf_addstr(&sb, "evlist(["); - evlist__for_each_entry(&pevlist->evlist, pos) { + evlist__for_each_entry(pevlist->evlist, pos) { if (!first) strbuf_addch(&sb, ','); if (!pos->pmu) @@ -1931,110 +1952,30 @@ static PyObject *pyrf__tracepoint(struct pyrf_evse= l *pevsel, return PyLong_FromLong(tp_pmu__id(sys, name)); } =20 -static PyObject *pyrf_evsel__from_evsel(struct evsel *evsel) -{ - struct pyrf_evsel *pevsel =3D PyObject_New(struct pyrf_evsel, &pyrf_evsel= __type); - - if (!pevsel) - return NULL; - - memset(&pevsel->evsel, 0, sizeof(pevsel->evsel)); - evsel__init(&pevsel->evsel, &evsel->core.attr, evsel->core.idx); - - evsel__clone(&pevsel->evsel, evsel); - if (evsel__is_group_leader(evsel)) - evsel__set_leader(&pevsel->evsel, &pevsel->evsel); - return (PyObject *)pevsel; -} - -static int evlist__pos(struct evlist *evlist, struct evsel *evsel) -{ - struct evsel *pos; - int idx =3D 0; - - evlist__for_each_entry(evlist, pos) { - if (evsel =3D=3D pos) - return idx; - idx++; - } - return -1; -} - -static struct evsel *evlist__at(struct evlist *evlist, int idx) -{ - struct evsel *pos; - int idx2 =3D 0; - - evlist__for_each_entry(evlist, pos) { - if (idx =3D=3D idx2) - return pos; - idx2++; - } - return NULL; -} - static PyObject *pyrf_evlist__from_evlist(struct evlist *evlist) { struct pyrf_evlist *pevlist =3D PyObject_New(struct pyrf_evlist, &pyrf_ev= list__type); - struct evsel *pos; - struct rb_node *node; =20 if (!pevlist) return NULL; =20 - memset(&pevlist->evlist, 0, sizeof(pevlist->evlist)); - evlist__init(&pevlist->evlist, evlist->core.all_cpus, evlist->core.thread= s); - evlist__for_each_entry(evlist, pos) { - struct pyrf_evsel *pevsel =3D (void *)pyrf_evsel__from_evsel(pos); - - evlist__add(&pevlist->evlist, &pevsel->evsel); - } - evlist__for_each_entry(&pevlist->evlist, pos) { - struct evsel *leader =3D evsel__leader(pos); - - if (pos !=3D leader) { - int idx =3D evlist__pos(evlist, leader); - - if (idx >=3D 0) - evsel__set_leader(pos, evlist__at(&pevlist->evlist, idx)); - else if (leader =3D=3D NULL) - evsel__set_leader(pos, pos); - } - } - metricgroup__copy_metric_events(&pevlist->evlist, /*cgrp=3D*/NULL, - &pevlist->evlist.metric_events, - &evlist->metric_events); - for (node =3D rb_first_cached(&pevlist->evlist.metric_events.entries); no= de; - node =3D rb_next(node)) { - struct metric_event *me =3D container_of(node, struct metric_event, nd); - struct list_head *mpos; - int idx =3D evlist__pos(evlist, me->evsel); - - if (idx >=3D 0) - me->evsel =3D evlist__at(&pevlist->evlist, idx); - list_for_each(mpos, &me->head) { - struct metric_expr *e =3D container_of(mpos, struct metric_expr, nd); - - for (int j =3D 0; e->metric_events[j]; j++) { - idx =3D evlist__pos(evlist, e->metric_events[j]); - if (idx >=3D 0) - e->metric_events[j] =3D evlist__at(&pevlist->evlist, idx); - } - } - } + pevlist->evlist =3D evlist__get(evlist); return (PyObject *)pevlist; } =20 static PyObject *pyrf__parse_events(PyObject *self, PyObject *args) { const char *input; - struct evlist evlist =3D {}; + struct evlist *evlist =3D evlist__new(); struct parse_events_error err; PyObject *result; PyObject *pcpus =3D NULL, *pthreads =3D NULL; struct perf_cpu_map *cpus; struct perf_thread_map *threads; =20 + if (!evlist) + return PyErr_NoMemory(); + if (!PyArg_ParseTuple(args, "s|OO", &input, &pcpus, &pthreads)) return NULL; =20 @@ -2042,35 +1983,38 @@ static PyObject *pyrf__parse_events(PyObject *self,= PyObject *args) cpus =3D pcpus ? ((struct pyrf_cpu_map *)pcpus)->cpus : NULL; =20 parse_events_error__init(&err); - evlist__init(&evlist, cpus, threads); - if (parse_events(&evlist, input, &err)) { + perf_evlist__set_maps(&evlist->core, cpus, threads); + if (parse_events(evlist, input, &err)) { parse_events_error__print(&err, input); PyErr_SetFromErrno(PyExc_OSError); return NULL; } - result =3D pyrf_evlist__from_evlist(&evlist); - evlist__exit(&evlist); + result =3D pyrf_evlist__from_evlist(evlist); + evlist__put(evlist); return result; } =20 static PyObject *pyrf__parse_metrics(PyObject *self, PyObject *args) { const char *input, *pmu =3D NULL; - struct evlist evlist =3D {}; + struct evlist *evlist =3D evlist__new(); PyObject *result; PyObject *pcpus =3D NULL, *pthreads =3D NULL; struct perf_cpu_map *cpus; struct perf_thread_map *threads; int ret; =20 + if (!evlist) + return PyErr_NoMemory(); + if (!PyArg_ParseTuple(args, "s|sOO", &input, &pmu, &pcpus, &pthreads)) return NULL; =20 threads =3D pthreads ? ((struct pyrf_thread_map *)pthreads)->threads : NU= LL; cpus =3D pcpus ? ((struct pyrf_cpu_map *)pcpus)->cpus : NULL; =20 - evlist__init(&evlist, cpus, threads); - ret =3D metricgroup__parse_groups(&evlist, pmu ?: "all", input, + perf_evlist__set_maps(&evlist->core, cpus, threads); + ret =3D metricgroup__parse_groups(evlist, pmu ?: "all", input, /*metric_no_group=3D*/ false, /*metric_no_merge=3D*/ false, /*metric_no_threshold=3D*/ true, @@ -2082,8 +2026,8 @@ static PyObject *pyrf__parse_metrics(PyObject *self, = PyObject *args) PyErr_SetFromErrno(PyExc_OSError); return NULL; } - result =3D pyrf_evlist__from_evlist(&evlist); - evlist__exit(&evlist); + result =3D pyrf_evlist__from_evlist(evlist); + evlist__put(evlist); return result; } =20 diff --git a/tools/perf/util/record.c b/tools/perf/util/record.c index e867de8ddaaa..8a5fc7d5e43c 100644 --- a/tools/perf/util/record.c +++ b/tools/perf/util/record.c @@ -264,7 +264,7 @@ bool evlist__can_select_event(struct evlist *evlist, co= nst char *str) ret =3D true; =20 out_delete: - evlist__delete(temp_evlist); + evlist__put(temp_evlist); return ret; } =20 diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 081e68c72c30..f241d91221d7 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -256,7 +256,7 @@ void perf_session__delete(struct perf_session *session) machines__exit(&session->machines); if (session->data) { if (perf_data__is_read(session->data)) - evlist__delete(session->evlist); + evlist__put(session->evlist); perf_data__close(session->data); } #ifdef HAVE_LIBTRACEEVENT diff --git a/tools/perf/util/sideband_evlist.c b/tools/perf/util/sideband_e= vlist.c index 388846f17bc1..b84a5463e039 100644 --- a/tools/perf/util/sideband_evlist.c +++ b/tools/perf/util/sideband_evlist.c @@ -102,7 +102,7 @@ int evlist__start_sb_thread(struct evlist *evlist, stru= ct target *target) return 0; =20 if (evlist__create_maps(evlist, target)) - goto out_delete_evlist; + goto out_put_evlist; =20 if (evlist->core.nr_entries > 1) { bool can_sample_identifier =3D perf_can_sample_identifier(); @@ -116,25 +116,25 @@ int evlist__start_sb_thread(struct evlist *evlist, st= ruct target *target) evlist__for_each_entry(evlist, counter) { if (evsel__open(counter, evlist->core.user_requested_cpus, evlist->core.threads) < 0) - goto out_delete_evlist; + goto out_put_evlist; } =20 if (evlist__mmap(evlist, UINT_MAX)) - goto out_delete_evlist; + goto out_put_evlist; =20 evlist__for_each_entry(evlist, counter) { if (evsel__enable(counter)) - goto out_delete_evlist; + goto out_put_evlist; } =20 evlist->thread.done =3D 0; if (pthread_create(&evlist->thread.th, NULL, perf_evlist__poll_thread, ev= list)) - goto out_delete_evlist; + goto out_put_evlist; =20 return 0; =20 -out_delete_evlist: - evlist__delete(evlist); +out_put_evlist: + evlist__put(evlist); evlist =3D NULL; return -1; } @@ -145,5 +145,5 @@ void evlist__stop_sb_thread(struct evlist *evlist) return; evlist->thread.done =3D 1; pthread_join(evlist->thread.th, NULL); - evlist__delete(evlist); + evlist__put(evlist); } --=20 2.51.1.851.g4ebd6896fd-goog From nobody Sat Feb 7 22:21:10 2026 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 B47653081CE for ; Wed, 29 Oct 2025 05:34:42 +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=1761716085; cv=none; b=ahz8EdJFTs8NMA9ZgS8OdA5ieDrgNIJPsJ67fjKGZPOpvnUa8+cU4WLa6mZFPnQwqLwGJ3YyGbn3SmIR5pzFDAVGR95Pju4ewqX24wirp5iatDg01Cw9lSOL8Rd/UPkWQhlGEEOAtyIExWqmb3LulTHVKzY9vth8MplBDB4tL5o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761716085; c=relaxed/simple; bh=cjJrqP3PhFWrUnpJAFSlrQGyKHEhV6VPoRZSaSLf/r0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=m8zNT8Ee+Z11WR4A72AlGgRrcfppWixaM/u/YCCL38JuW2RcA9WHeEEeH7gJxN8izVmmA9L4rPtwYhBJQEwzK16G5F5gLLShyp1LwedbSCTZZ55Q7Dos6KRWe3YogUe41Q3o1Bq4M2tRTemMw8ERZVuFKy4x/N0AAxjzXEqaHZI= 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=veK+REv+; 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="veK+REv+" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-340299fd99dso1764876a91.0 for ; Tue, 28 Oct 2025 22:34:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1761716082; x=1762320882; 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=w4FHRoIXwozyDq2OI6JitQ6frsI8lP29+tytphMUEl8=; b=veK+REv+YXSs1Dxj4eRTPCmCML28ZOe7aBdDWTpBGrehvnsaBKqKfkeQYlJoiVEPnn N3vdbAfiU73lbS4RAx78zXbggM87K+Y8IK122faxOPVJflqtS6j34fzpLhDzOwLhv1XE RJOsP8nZ6Pw968fRBbtQXB+DB3kiuOhO2O8RFFqqkhT8/+8PIEvyPuFPz7KhG0QVXVQ6 3iP33R562+GAOhV5OAQZqG/9JzP9+BgrfDybhQkTwtWSe7X+9fiqK+Jhnp2yMABhGAMS M7FO5q/ohONyuuL7e8DxzBOZbri2CKioOjOsb5WLbKPd7hDzKa55WPWeYZZXRLp9vzht mbwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761716082; x=1762320882; 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=w4FHRoIXwozyDq2OI6JitQ6frsI8lP29+tytphMUEl8=; b=JPQCWOMQDV0bi4SvRxW8blGqynAws1OjP/LIltpH8Kh2ZZy5YYaMnBreFBHLNRMq4W pMLWhOr4+LijG0eCsMt4drz09L3twyPWLIARptUEUeozGGj/bFjQLz5eAsLl9AKCCBMQ lN3Lo9QjZkLA7yi+nnJbiHSHJpzCxSQkGF8XWUEboVlMYKMt8cuWMl+mjS+jgBeAT0QV Aa0h5tB246T/Jh+6T4dv6naPS246auBI7CuF6lrktML8Kq8cT+9SwM1pa/tzJqVP0+za YUYCNKYm6+jZL46qqJ7PGk8BTrekHpmLRh6xky0ymawHA5P8lpbeH/i0HRp/hajWtzUh jB3Q== X-Forwarded-Encrypted: i=1; AJvYcCW+VkXjKXfX0DTaziUGw5gfRUtfbz22Uvl73URw7nNDZnztVkKhP6QmLKhl0ymPvH6XFeYFEmqtAd6GqA4=@vger.kernel.org X-Gm-Message-State: AOJu0Yw8uLPKoBvvPr00LJhPxMI/q7NY8dU37oHjfduleuISAfuQFdOX AKZZHgP6SKvitj4p32pv4WT5yGW1NLXr6iJBmUa54xWObz2uv6arzzQw2o6yx9MFPy3Q9KY75KW WDcFCrLGpDA== X-Google-Smtp-Source: AGHT+IHhAzAfaPEyv5F0rXMF6LDk184VOiayS7SJisbf7OlvmKS/qKtb9pSc3NI1+FzqJwTb7GHvmrBLwK7+ X-Received: from pjbgq17.prod.google.com ([2002:a17:90b:1051:b0:33d:acf4:5aac]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:4b43:b0:33b:8b1c:5e85 with SMTP id 98e67ed59e1d1-3403a25a668mr1625016a91.3.1761716081965; Tue, 28 Oct 2025 22:34:41 -0700 (PDT) Date: Tue, 28 Oct 2025 22:34:11 -0700 In-Reply-To: <20251029053413.355154-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: <20251029053413.355154-1-irogers@google.com> X-Mailer: git-send-email 2.51.1.851.g4ebd6896fd-goog Message-ID: <20251029053413.355154-14-irogers@google.com> Subject: [RFC PATCH v1 13/15] perf evsel: Add reference count From: Ian Rogers To: Suzuki K Poulose , Mike Leach , James Clark , John Garry , Will Deacon , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Greg Kroah-Hartman , Charlie Jenkins , Thomas Falcon , Yicong Yang , Thomas Richter , Athira Rajeev , Howard Chu , Song Liu , Dapeng Mi , Levi Yun , Zhongqiu Han , Blake Jones , Anubhav Shelat , Chun-Tse Shao , Christophe Leroy , Jean-Philippe Romain , Gautam Menghani , Dmitry Vyukov , Yang Li , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Andi Kleen , Weilin Wang Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" As with evlist this a no-op for most of the perf tool. The reference count is set to 1 at allocation, the put will see the 1, decrement it and perform the delete. The purpose for adding the reference count is for the python code. Prior to this change the python code would clone evsels, but this has issues if events are opened, etc. leading to assertion failures. With a reference count the same evsel can be used and the reference count incremented for the python usage. To not change the python evsel API getset functions are added for the evsel members, no set function is provided for size as it doesn't make sense to alter this. Signed-off-by: Ian Rogers --- tools/perf/builtin-trace.c | 12 +- tools/perf/tests/evsel-tp-sched.c | 4 +- tools/perf/tests/openat-syscall-all-cpus.c | 6 +- tools/perf/tests/openat-syscall.c | 6 +- tools/perf/util/bpf_counter_cgroup.c | 2 +- tools/perf/util/cgroup.c | 2 +- tools/perf/util/evlist.c | 2 +- tools/perf/util/evsel.c | 26 ++- tools/perf/util/evsel.h | 11 +- tools/perf/util/parse-events.y | 2 +- tools/perf/util/pfm.c | 2 +- tools/perf/util/print-events.c | 2 +- tools/perf/util/python.c | 212 +++++++++++++++++---- 13 files changed, 218 insertions(+), 71 deletions(-) diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index c056df42a78f..1168759983da 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -449,10 +449,10 @@ static int evsel__init_tp_ptr_field(struct evsel *evs= el, struct tp_field *field, ({ struct syscall_tp *sc =3D __evsel__syscall_tp(evsel);\ evsel__init_tp_ptr_field(evsel, &sc->name, #name); }) =20 -static void evsel__delete_priv(struct evsel *evsel) +static void evsel__put_and_free_priv(struct evsel *evsel) { zfree(&evsel->priv); - evsel__delete(evsel); + evsel__put(evsel); } =20 static int evsel__init_syscall_tp(struct evsel *evsel) @@ -532,7 +532,7 @@ static struct evsel *perf_evsel__raw_syscall_newtp(cons= t char *direction, void * return evsel; =20 out_delete: - evsel__delete_priv(evsel); + evsel__put_and_free_priv(evsel); return NULL; } =20 @@ -3560,7 +3560,7 @@ static bool evlist__add_vfs_getname(struct evlist *ev= list) =20 list_del_init(&evsel->core.node); evsel->evlist =3D NULL; - evsel__delete(evsel); + evsel__put(evsel); } =20 return found; @@ -3674,9 +3674,9 @@ static int trace__add_syscall_newtp(struct trace *tra= ce) return ret; =20 out_delete_sys_exit: - evsel__delete_priv(sys_exit); + evsel__put_and_free_priv(sys_exit); out_delete_sys_enter: - evsel__delete_priv(sys_enter); + evsel__put_and_free_priv(sys_enter); goto out; } =20 diff --git a/tools/perf/tests/evsel-tp-sched.c b/tools/perf/tests/evsel-tp-= sched.c index 226196fb9677..9e456f88a13a 100644 --- a/tools/perf/tests/evsel-tp-sched.c +++ b/tools/perf/tests/evsel-tp-sched.c @@ -64,7 +64,7 @@ static int test__perf_evsel__tp_sched_test(struct test_su= ite *test __maybe_unuse if (evsel__test_field(evsel, "next_prio", 4, true)) ret =3D TEST_FAIL; =20 - evsel__delete(evsel); + evsel__put(evsel); =20 evsel =3D evsel__newtp("sched", "sched_wakeup"); =20 @@ -85,7 +85,7 @@ static int test__perf_evsel__tp_sched_test(struct test_su= ite *test __maybe_unuse if (evsel__test_field(evsel, "target_cpu", 4, true)) ret =3D TEST_FAIL; =20 - evsel__delete(evsel); + evsel__put(evsel); return ret; } =20 diff --git a/tools/perf/tests/openat-syscall-all-cpus.c b/tools/perf/tests/= openat-syscall-all-cpus.c index 3644d6f52c07..605d41295e8a 100644 --- a/tools/perf/tests/openat-syscall-all-cpus.c +++ b/tools/perf/tests/openat-syscall-all-cpus.c @@ -58,7 +58,7 @@ static int test__openat_syscall_event_on_all_cpus(struct = test_suite *test __mayb "tweak /proc/sys/kernel/perf_event_paranoid?\n", str_error_r(errno, sbuf, sizeof(sbuf))); err =3D TEST_SKIP; - goto out_evsel_delete; + goto out_evsel_put; } =20 perf_cpu_map__for_each_cpu(cpu, idx, cpus) { @@ -115,8 +115,8 @@ static int test__openat_syscall_event_on_all_cpus(struc= t test_suite *test __mayb evsel__free_counts(evsel); out_close_fd: perf_evsel__close_fd(&evsel->core); -out_evsel_delete: - evsel__delete(evsel); +out_evsel_put: + evsel__put(evsel); out_cpu_map_delete: perf_cpu_map__put(cpus); out_thread_map_delete: diff --git a/tools/perf/tests/openat-syscall.c b/tools/perf/tests/openat-sy= scall.c index b54cbe5f1808..9f16f0dd3a29 100644 --- a/tools/perf/tests/openat-syscall.c +++ b/tools/perf/tests/openat-syscall.c @@ -42,7 +42,7 @@ static int test__openat_syscall_event(struct test_suite *= test __maybe_unused, "tweak /proc/sys/kernel/perf_event_paranoid?\n", str_error_r(errno, sbuf, sizeof(sbuf))); err =3D TEST_SKIP; - goto out_evsel_delete; + goto out_evsel_put; } =20 for (i =3D 0; i < nr_openat_calls; ++i) { @@ -64,8 +64,8 @@ static int test__openat_syscall_event(struct test_suite *= test __maybe_unused, err =3D TEST_OK; out_close_fd: perf_evsel__close_fd(&evsel->core); -out_evsel_delete: - evsel__delete(evsel); +out_evsel_put: + evsel__put(evsel); out_thread_map_delete: perf_thread_map__put(threads); return err; diff --git a/tools/perf/util/bpf_counter_cgroup.c b/tools/perf/util/bpf_cou= nter_cgroup.c index 68bd994c8880..f12c45c27c40 100644 --- a/tools/perf/util/bpf_counter_cgroup.c +++ b/tools/perf/util/bpf_counter_cgroup.c @@ -314,7 +314,7 @@ static int bperf_cgrp__destroy(struct evsel *evsel) return 0; =20 bperf_cgroup_bpf__destroy(skel); - evsel__delete(cgrp_switch); // it'll destroy on_switch progs too + evsel__put(cgrp_switch); // it'll destroy on_switch progs too =20 return 0; } diff --git a/tools/perf/util/cgroup.c b/tools/perf/util/cgroup.c index ed230cd44ba7..5409878e3ec6 100644 --- a/tools/perf/util/cgroup.c +++ b/tools/perf/util/cgroup.c @@ -468,7 +468,7 @@ int evlist__expand_cgroup(struct evlist *evlist, const = char *str, bool open_cgro =20 leader =3D NULL; evlist__for_each_entry(orig_list, pos) { - evsel =3D evsel__clone(/*dest=3D*/NULL, pos); + evsel =3D evsel__clone(pos); if (evsel =3D=3D NULL) goto out_err; =20 diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index ea1f398c14e3..bfa99d0c9e25 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -182,7 +182,7 @@ static void evlist__purge(struct evlist *evlist) evlist__for_each_entry_safe(evlist, n, pos) { list_del_init(&pos->core.node); pos->evlist =3D NULL; - evsel__delete(pos); + evsel__put(pos); } =20 evlist->core.nr_entries =3D 0; diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 6769cd27b6e4..514ad4797562 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -385,10 +385,11 @@ bool evsel__is_function_event(struct evsel *evsel) #undef FUNCTION_EVENT } =20 -void evsel__init(struct evsel *evsel, +static void evsel__init(struct evsel *evsel, struct perf_event_attr *attr, int idx) { perf_evsel__init(&evsel->core, attr, idx); + refcount_set(&evsel->refcnt, 1); evsel->tracking =3D !idx; evsel->unit =3D strdup(""); evsel->scale =3D 1.0; @@ -470,7 +471,7 @@ static int evsel__copy_config_terms(struct evsel *dst, = struct evsel *src) * The assumption is that @orig is not configured nor opened yet. * So we only care about the attributes that can be set while it's parsed. */ -struct evsel *evsel__clone(struct evsel *dest, struct evsel *orig) +struct evsel *evsel__clone(struct evsel *orig) { struct evsel *evsel; =20 @@ -483,11 +484,7 @@ struct evsel *evsel__clone(struct evsel *dest, struct = evsel *orig) if (orig->bpf_obj) return NULL; =20 - if (dest) - evsel =3D dest; - else - evsel =3D evsel__new(&orig->core.attr); - + evsel =3D evsel__new(&orig->core.attr); if (evsel =3D=3D NULL) return NULL; =20 @@ -571,7 +568,7 @@ struct evsel *evsel__clone(struct evsel *dest, struct e= vsel *orig) return evsel; =20 out_err: - evsel__delete(evsel); + evsel__put(evsel); return NULL; } =20 @@ -630,6 +627,12 @@ struct evsel *evsel__newtp_idx(const char *sys, const = char *name, int idx, bool return ERR_PTR(err); } =20 +struct evsel *evsel__get(struct evsel *evsel) +{ + refcount_inc(&evsel->refcnt); + return evsel; +} + #ifdef HAVE_LIBTRACEEVENT struct tep_event *evsel__tp_format(struct evsel *evsel) { @@ -1728,7 +1731,7 @@ void evsel__set_priv_destructor(void (*destructor)(vo= id *priv)) evsel__priv_destructor =3D destructor; } =20 -void evsel__exit(struct evsel *evsel) +static void evsel__exit(struct evsel *evsel) { assert(list_empty(&evsel->core.node)); assert(evsel->evlist =3D=3D NULL); @@ -1764,11 +1767,14 @@ void evsel__exit(struct evsel *evsel) xyarray__delete(evsel->start_times); } =20 -void evsel__delete(struct evsel *evsel) +void evsel__put(struct evsel *evsel) { if (!evsel) return; =20 + if (!refcount_dec_and_test(&evsel->refcnt)) + return; + evsel__exit(evsel); free(evsel); } diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index f4540920604e..2e65a3d84a7f 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -8,6 +8,7 @@ #include #include #include +#include #include #include =20 @@ -46,6 +47,7 @@ typedef int (evsel__sb_cb_t)(union perf_event *event, voi= d *data); struct evsel { struct perf_evsel core; struct evlist *evlist; + refcount_t refcnt; off_t id_offset; int id_pos; int is_pos; @@ -258,7 +260,7 @@ static inline struct evsel *evsel__new(struct perf_even= t_attr *attr) return evsel__new_idx(attr, 0); } =20 -struct evsel *evsel__clone(struct evsel *dest, struct evsel *orig); +struct evsel *evsel__clone(struct evsel *orig); =20 int copy_config_terms(struct list_head *dst, struct list_head *src); void free_config_terms(struct list_head *config_terms); @@ -273,14 +275,13 @@ static inline struct evsel *evsel__newtp(const char *= sys, const char *name) return evsel__newtp_idx(sys, name, 0, true); } =20 +struct evsel *evsel__get(struct evsel *evsel); +void evsel__put(struct evsel *evsel); + #ifdef HAVE_LIBTRACEEVENT struct tep_event *evsel__tp_format(struct evsel *evsel); #endif =20 -void evsel__init(struct evsel *evsel, struct perf_event_attr *attr, int id= x); -void evsel__exit(struct evsel *evsel); -void evsel__delete(struct evsel *evsel); - void evsel__set_priv_destructor(void (*destructor)(void *priv)); =20 struct callchain_param; diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y index c194de5ec1ec..b531b1f0ceb3 100644 --- a/tools/perf/util/parse-events.y +++ b/tools/perf/util/parse-events.y @@ -47,7 +47,7 @@ static void free_list_evsel(struct list_head* list_evsel) =20 list_for_each_entry_safe(evsel, tmp, list_evsel, core.node) { list_del_init(&evsel->core.node); - evsel__delete(evsel); + evsel__put(evsel); } free(list_evsel); } diff --git a/tools/perf/util/pfm.c b/tools/perf/util/pfm.c index e5b3a2a5ddef..f226ffd2b596 100644 --- a/tools/perf/util/pfm.c +++ b/tools/perf/util/pfm.c @@ -158,7 +158,7 @@ static bool is_libpfm_event_supported(const char *name,= struct perf_cpu_map *cpu result =3D false; =20 evsel__close(evsel); - evsel__delete(evsel); + evsel__put(evsel); =20 return result; } diff --git a/tools/perf/util/print-events.c b/tools/perf/util/print-events.c index 8f3ed83853a9..bbefbc49a062 100644 --- a/tools/perf/util/print-events.c +++ b/tools/perf/util/print-events.c @@ -179,7 +179,7 @@ bool is_event_supported(u8 type, u64 config) } =20 evsel__close(evsel); - evsel__delete(evsel); + evsel__put(evsel); } =20 perf_thread_map__put(tmap); diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index 4149a51e9878..27410b3fb7c5 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -275,6 +275,7 @@ static PyMemberDef pyrf_sample_event__members[] =3D { =20 static void pyrf_sample_event__delete(struct pyrf_event *pevent) { + evsel__put(pevent->evsel); perf_sample__exit(&pevent->sample); Py_TYPE(pevent)->tp_free((PyObject*)pevent); } @@ -946,7 +947,7 @@ static int pyrf_counts_values__setup_types(void) struct pyrf_evsel { PyObject_HEAD =20 - struct evsel evsel; + struct evsel *evsel; }; =20 static int pyrf_evsel__init(struct pyrf_evsel *pevsel, @@ -1054,20 +1055,20 @@ static int pyrf_evsel__init(struct pyrf_evsel *pevs= el, attr.sample_id_all =3D sample_id_all; attr.size =3D sizeof(attr); =20 - evsel__init(&pevsel->evsel, &attr, idx); - return 0; + pevsel->evsel =3D evsel__new(&attr); + return pevsel->evsel ? 0 : -1; } =20 static void pyrf_evsel__delete(struct pyrf_evsel *pevsel) { - evsel__exit(&pevsel->evsel); + evsel__put(pevsel->evsel); Py_TYPE(pevsel)->tp_free((PyObject*)pevsel); } =20 static PyObject *pyrf_evsel__open(struct pyrf_evsel *pevsel, PyObject *args, PyObject *kwargs) { - struct evsel *evsel =3D &pevsel->evsel; + struct evsel *evsel =3D pevsel->evsel; struct perf_cpu_map *cpus =3D NULL; struct perf_thread_map *threads =3D NULL; PyObject *pcpus =3D NULL, *pthreads =3D NULL; @@ -1103,7 +1104,7 @@ static PyObject *pyrf_evsel__cpus(struct pyrf_evsel *= pevsel) struct pyrf_cpu_map *pcpu_map =3D PyObject_New(struct pyrf_cpu_map, &pyrf= _cpu_map__type); =20 if (pcpu_map) - pcpu_map->cpus =3D perf_cpu_map__get(pevsel->evsel.core.cpus); + pcpu_map->cpus =3D perf_cpu_map__get(pevsel->evsel->core.cpus); =20 return (PyObject *)pcpu_map; } @@ -1114,7 +1115,7 @@ static PyObject *pyrf_evsel__threads(struct pyrf_evse= l *pevsel) PyObject_New(struct pyrf_thread_map, &pyrf_thread_map__type); =20 if (pthread_map) - pthread_map->threads =3D perf_thread_map__get(pevsel->evsel.core.threads= ); + pthread_map->threads =3D perf_thread_map__get(pevsel->evsel->core.thread= s); =20 return (PyObject *)pthread_map; } @@ -1148,7 +1149,7 @@ static int evsel__ensure_counts(struct evsel *evsel) static PyObject *pyrf_evsel__read(struct pyrf_evsel *pevsel, PyObject *args, PyObject *kwargs) { - struct evsel *evsel =3D &pevsel->evsel; + struct evsel *evsel =3D pevsel->evsel; int cpu =3D 0, cpu_idx, thread =3D 0, thread_idx; struct perf_counts_values *old_count, *new_count; struct pyrf_counts_values *count_values =3D PyObject_New(struct pyrf_coun= ts_values, @@ -1193,7 +1194,7 @@ static PyObject *pyrf_evsel__read(struct pyrf_evsel *= pevsel, static PyObject *pyrf_evsel__str(PyObject *self) { struct pyrf_evsel *pevsel =3D (void *)self; - struct evsel *evsel =3D &pevsel->evsel; + struct evsel *evsel =3D pevsel->evsel; =20 return PyUnicode_FromFormat("evsel(%s/%s/)", evsel__pmu_name(evsel), evse= l__name(evsel)); } @@ -1226,26 +1227,170 @@ static PyMethodDef pyrf_evsel__methods[] =3D { { .ml_name =3D NULL, } }; =20 -#define evsel_member_def(member, ptype, help) \ - { #member, ptype, \ - offsetof(struct pyrf_evsel, evsel.member), \ - 0, help } +static PyObject *pyrf_evsel__get_tracking(PyObject *self, void */*closure*= /) +{ + struct pyrf_evsel *pevsel =3D (void *)self; =20 -#define evsel_attr_member_def(member, ptype, help) \ - { #member, ptype, \ - offsetof(struct pyrf_evsel, evsel.core.attr.member), \ - 0, help } + if (pevsel->evsel->tracking) + Py_RETURN_TRUE; + else + Py_RETURN_FALSE; +} =20 -static PyMemberDef pyrf_evsel__members[] =3D { - evsel_member_def(tracking, T_BOOL, "tracking event."), - evsel_attr_member_def(type, T_UINT, "attribute type."), - evsel_attr_member_def(size, T_UINT, "attribute size."), - evsel_attr_member_def(config, T_ULONGLONG, "attribute config."), - evsel_attr_member_def(sample_period, T_ULONGLONG, "attribute sample_perio= d."), - evsel_attr_member_def(sample_type, T_ULONGLONG, "attribute sample_type."), - evsel_attr_member_def(read_format, T_ULONGLONG, "attribute read_format."), - evsel_attr_member_def(wakeup_events, T_UINT, "attribute wakeup_events."), - { .name =3D NULL, }, +static int pyrf_evsel__set_tracking(PyObject *self, PyObject *val, void */= *closure*/) +{ + struct pyrf_evsel *pevsel =3D (void *)self; + + pevsel->evsel->tracking =3D Py_IsTrue(val) ? true : false; + return 0; +} + +static int pyrf_evsel__set_attr_config(PyObject *self, PyObject *val, void= */*closure*/) +{ + struct pyrf_evsel *pevsel =3D (void *)self; + + pevsel->evsel->core.attr.config =3D PyLong_AsUnsignedLongLong(val); + return PyErr_Occurred() ? -1 : 0; +} + +static PyObject *pyrf_evsel__get_attr_config(PyObject *self, void */*closu= re*/) +{ + struct pyrf_evsel *pevsel =3D (void *)self; + + return PyLong_FromUnsignedLongLong(pevsel->evsel->core.attr.config); +} + +static int pyrf_evsel__set_attr_read_format(PyObject *self, PyObject *val,= void */*closure*/) +{ + struct pyrf_evsel *pevsel =3D (void *)self; + + pevsel->evsel->core.attr.read_format =3D PyLong_AsUnsignedLongLong(val); + return PyErr_Occurred() ? -1 : 0; +} + +static PyObject *pyrf_evsel__get_attr_read_format(PyObject *self, void */*= closure*/) +{ + struct pyrf_evsel *pevsel =3D (void *)self; + + return PyLong_FromUnsignedLongLong(pevsel->evsel->core.attr.read_format); +} + +static int pyrf_evsel__set_attr_sample_period(PyObject *self, PyObject *va= l, void */*closure*/) +{ + struct pyrf_evsel *pevsel =3D (void *)self; + + pevsel->evsel->core.attr.sample_period =3D PyLong_AsUnsignedLongLong(val); + return PyErr_Occurred() ? -1 : 0; +} + +static PyObject *pyrf_evsel__get_attr_sample_period(PyObject *self, void *= /*closure*/) +{ + struct pyrf_evsel *pevsel =3D (void *)self; + + return PyLong_FromUnsignedLongLong(pevsel->evsel->core.attr.sample_period= ); +} + +static int pyrf_evsel__set_attr_sample_type(PyObject *self, PyObject *val,= void */*closure*/) +{ + struct pyrf_evsel *pevsel =3D (void *)self; + + pevsel->evsel->core.attr.sample_type =3D PyLong_AsUnsignedLongLong(val); + return PyErr_Occurred() ? -1 : 0; +} + +static PyObject *pyrf_evsel__get_attr_sample_type(PyObject *self, void */*= closure*/) +{ + struct pyrf_evsel *pevsel =3D (void *)self; + + return PyLong_FromUnsignedLongLong(pevsel->evsel->core.attr.sample_type); +} + +static PyObject *pyrf_evsel__get_attr_size(PyObject *self, void */*closure= */) +{ + struct pyrf_evsel *pevsel =3D (void *)self; + + return PyLong_FromUnsignedLong(pevsel->evsel->core.attr.size); +} + +static int pyrf_evsel__set_attr_type(PyObject *self, PyObject *val, void *= /*closure*/) +{ + struct pyrf_evsel *pevsel =3D (void *)self; + + pevsel->evsel->core.attr.type =3D PyLong_AsUnsignedLong(val); + return PyErr_Occurred() ? -1 : 0; +} + +static PyObject *pyrf_evsel__get_attr_type(PyObject *self, void */*closure= */) +{ + struct pyrf_evsel *pevsel =3D (void *)self; + + return PyLong_FromUnsignedLong(pevsel->evsel->core.attr.type); +} + +static int pyrf_evsel__set_attr_wakeup_events(PyObject *self, PyObject *va= l, void */*closure*/) +{ + struct pyrf_evsel *pevsel =3D (void *)self; + + pevsel->evsel->core.attr.wakeup_events =3D PyLong_AsUnsignedLong(val); + return PyErr_Occurred() ? -1 : 0; +} + +static PyObject *pyrf_evsel__get_attr_wakeup_events(PyObject *self, void *= /*closure*/) +{ + struct pyrf_evsel *pevsel =3D (void *)self; + + return PyLong_FromUnsignedLong(pevsel->evsel->core.attr.wakeup_events); +} + +static PyGetSetDef pyrf_evsel__getset[] =3D { + { + .name =3D "tracking", + .get =3D pyrf_evsel__get_tracking, + .set =3D pyrf_evsel__set_tracking, + .doc =3D "tracking event.", + }, + { + .name =3D "config", + .get =3D pyrf_evsel__get_attr_config, + .set =3D pyrf_evsel__set_attr_config, + .doc =3D "attribute config.", + }, + { + .name =3D "read_format", + .get =3D pyrf_evsel__get_attr_read_format, + .set =3D pyrf_evsel__set_attr_read_format, + .doc =3D "attribute read_format.", + }, + { + .name =3D "sample_period", + .get =3D pyrf_evsel__get_attr_sample_period, + .set =3D pyrf_evsel__set_attr_sample_period, + .doc =3D "attribute sample_period.", + }, + { + .name =3D "sample_type", + .get =3D pyrf_evsel__get_attr_sample_type, + .set =3D pyrf_evsel__set_attr_sample_type, + .doc =3D "attribute sample_type.", + }, + { + .name =3D "size", + .get =3D pyrf_evsel__get_attr_size, + .doc =3D "attribute size.", + }, + { + .name =3D "type", + .get =3D pyrf_evsel__get_attr_type, + .set =3D pyrf_evsel__set_attr_type, + .doc =3D "attribute type.", + }, + { + .name =3D "wakeup_events", + .get =3D pyrf_evsel__get_attr_wakeup_events, + .set =3D pyrf_evsel__set_attr_wakeup_events, + .doc =3D "attribute wakeup_events.", + }, + { .name =3D NULL}, }; =20 static const char pyrf_evsel__doc[] =3D PyDoc_STR("perf event selector lis= t object."); @@ -1257,7 +1402,7 @@ static PyTypeObject pyrf_evsel__type =3D { .tp_dealloc =3D (destructor)pyrf_evsel__delete, .tp_flags =3D Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, .tp_doc =3D pyrf_evsel__doc, - .tp_members =3D pyrf_evsel__members, + .tp_getset =3D pyrf_evsel__getset, .tp_methods =3D pyrf_evsel__methods, .tp_init =3D (initproc)pyrf_evsel__init, .tp_str =3D pyrf_evsel__str, @@ -1539,7 +1684,7 @@ static PyObject *pyrf_evlist__add(struct pyrf_evlist = *pevlist, return NULL; =20 Py_INCREF(pevsel); - evsel =3D &((struct pyrf_evsel *)pevsel)->evsel; + evsel =3D ((struct pyrf_evsel *)pevsel)->evsel; evsel->core.idx =3D evlist->core.nr_entries; evlist__add(evlist, evsel); =20 @@ -1776,12 +1921,7 @@ static PyObject *pyrf_evsel__from_evsel(struct evsel= *evsel) if (!pevsel) return NULL; =20 - memset(&pevsel->evsel, 0, sizeof(pevsel->evsel)); - evsel__init(&pevsel->evsel, &evsel->core.attr, evsel->core.idx); - - evsel__clone(&pevsel->evsel, evsel); - if (evsel__is_group_leader(evsel)) - evsel__set_leader(&pevsel->evsel, &pevsel->evsel); + pevsel->evsel =3D evsel__get(evsel); return (PyObject *)pevsel; } =20 @@ -2188,7 +2328,7 @@ static int pyrf_session_tool__sample(const struct per= f_tool *tool, if (pyevent =3D=3D NULL) return -ENOMEM; =20 - pevent->evsel =3D evsel; + pevent->evsel =3D evsel__get(evsel); memcpy(&pevent->sample, sample, sizeof(struct perf_sample)); =20 PyObject_CallFunction(psession->sample, "O", pyevent); --=20 2.51.1.851.g4ebd6896fd-goog From nobody Sat Feb 7 22:21:10 2026 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 5E0D22FBE13 for ; Wed, 29 Oct 2025 05:34:44 +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=1761716086; cv=none; b=JVxNhc91LGAqiJgqUgLTL1hh1ttZA9+g8QLM3pArY0EfWb6pRTJQA8adNDLSdmm0ElLaTLIcY+3Otz5TSxkWpOIR4hZoS4si4JpHgDMTqAyNDJ3+r151mHHk0qz//Mj5Lbwvb2BEMylv3///DPvXusuhOfO+YoUk3WlGqrf4JHA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761716086; c=relaxed/simple; bh=dJp7d9Mo/YI8Mc8WeyxTFkIzH06kCcUy8iih/vjPQs4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=ZJYEX0z+IG3l7SiGcRT8lizZMCI36Y86aZ4JEKtUu0FW9V7nxzk+I10LTqJ5ZSm+wLfOzhpOT+m/Fj9YmbG9cr+5KMbnbD2ncDz3mD5rtJgKjfjWiYVSuTV75G+VdLUoFqi44tg+EKyybJrQKlJk1nsFK1LCxwzTP+pO2BKRJFY= 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=fOvB6Jb5; 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="fOvB6Jb5" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-2904e9e0ef9so126919605ad.3 for ; Tue, 28 Oct 2025 22:34:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1761716084; x=1762320884; 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=Zqi6Ry5NSVNk8CjQYGSWrFXfHqr50wrE9agsn8Mgayg=; b=fOvB6Jb5K9Oj29yWtOu9xkKtbPpfAJr8gNSlvHCeiTEwj/mwsGf/pzMSF9cnvUqLNJ sV6W+t29qADdkCOEEwS7EIMldKqCjkm59d3NDMiKw9fJcUoh1V7hB87u0omn1HwVzedh 0OWI/6UfT/VTmLnZCf6C7XOB1JxN60xKj5Pl/DvZKqW0a7wMxRDhJCbIoJHCXIjviG2K xjI7RROfZY9fktCrJI2logqrr1FFUcMvMGL6LAOS/37A1CAf5gU/gAFQtH9PSTgDovJ+ 4NKJ+ruBjpZWbR1Bii0+NUzCN+9mh+XeA1uah8lT604V34RZNBwJ6PekcEvJoLc1dIy5 3lIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761716084; x=1762320884; 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=Zqi6Ry5NSVNk8CjQYGSWrFXfHqr50wrE9agsn8Mgayg=; b=m9TDu+FGUFJjF0UUhGWMFjE7AAnxxbb73vvOD1GUPRnCwGdedRh5tfX2yNDvdtSVDN AEmNoL3cPlhHbc4aFRvA497D/o16x2P6Qpwq3OMub53FF6Ca1g48xYtNxByxXGQreevn w2cUtriqDjrTZEpba4TOW5lXmXoL9QvYE2dnhsJ2L3N3zQSvl9E3H6Q3ROw36yRy/fmZ TRkw3XcrtH0Te/IjFfwiyFWwOTVtdqwYSzZei7iYXIw7agC1NtRxsVlD7WEGTydKpLvK DUk+ew9U0AyrMR5rek07K5D8JZRUj5bISKSE+4oFwSgOLPPccW7XwcbbnzKbSKctRAO2 xgkQ== X-Forwarded-Encrypted: i=1; AJvYcCWoZxa7oM7eG5OZfa2FZN+cCMbGLxo85+cuQ8QEpSZovSitCqbTbEU6AQc2heSurzGpzT3YKKclC7TguqQ=@vger.kernel.org X-Gm-Message-State: AOJu0YyTkh3y+8g/OhdFH1UFh6nxm/VbkH8w1zx2x8P8GzxhVJTUG+Hk 8Al1x6vgfvb3HiPPqFAFo4HbbXLkzA2vQPxUucrw3B7Oi+s7JqnrckHhDdZ45w1I4u1QuGN1Y6/ sFu8Oh5F1FA== X-Google-Smtp-Source: AGHT+IEssDD1Wr8QgcOB4tVI4HLcQH9yG9e29tLmTkb9S16XsXoxbGnLaEAJhXlcKNm2geB/qU1Fe91ExQ6z X-Received: from pli3.prod.google.com ([2002:a17:902:c103:b0:292:adbb:88e3]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:d4ce:b0:272:a900:c42e with SMTP id d9443c01a7336-294dee990fbmr23651385ad.35.1761716083608; Tue, 28 Oct 2025 22:34:43 -0700 (PDT) Date: Tue, 28 Oct 2025 22:34:12 -0700 In-Reply-To: <20251029053413.355154-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: <20251029053413.355154-1-irogers@google.com> X-Mailer: git-send-email 2.51.1.851.g4ebd6896fd-goog Message-ID: <20251029053413.355154-15-irogers@google.com> Subject: [RFC PATCH v1 14/15] perf python: Add access to evsel and phys_addr in event From: Ian Rogers To: Suzuki K Poulose , Mike Leach , James Clark , John Garry , Will Deacon , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Greg Kroah-Hartman , Charlie Jenkins , Thomas Falcon , Yicong Yang , Thomas Richter , Athira Rajeev , Howard Chu , Song Liu , Dapeng Mi , Levi Yun , Zhongqiu Han , Blake Jones , Anubhav Shelat , Chun-Tse Shao , Christophe Leroy , Jean-Philippe Romain , Gautam Menghani , Dmitry Vyukov , Yang Li , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Andi Kleen , Weilin Wang Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use the reference counting to wrap the evsel in the sample processing pyrf_event and access using a getter routine. Expose the phys_addr in the perf_sample. Signed-off-by: Ian Rogers --- tools/perf/util/python.c | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index 27410b3fb7c5..09098c1112d3 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -32,6 +32,8 @@ =20 PyMODINIT_FUNC PyInit_perf(void); =20 +static PyObject *pyrf_evsel__from_evsel(struct evsel *evsel); + #define member_def(type, member, ptype, help) \ { #member, ptype, \ offsetof(struct pyrf_event, event) + offsetof(struct type, member), \ @@ -55,11 +57,29 @@ struct pyrf_event { sample_member_def(sample_tid, tid, T_INT, "event tid"), \ sample_member_def(sample_time, time, T_ULONGLONG, "event timestamp"), \ sample_member_def(sample_addr, addr, T_ULONGLONG, "event addr"), \ + sample_member_def(sample_phys_addr, phys_addr, T_ULONGLONG, "event physic= al addr"), \ sample_member_def(sample_id, id, T_ULONGLONG, "event id"), \ sample_member_def(sample_stream_id, stream_id, T_ULONGLONG, "event stream= id"), \ sample_member_def(sample_period, period, T_ULONGLONG, "event period"), \ sample_member_def(sample_cpu, cpu, T_UINT, "event cpu"), =20 +static PyObject *pyrf_event__get_evsel(PyObject *self, void */*closure*/) +{ + struct pyrf_event *pevent =3D (void *)self; + + return pyrf_evsel__from_evsel(pevent->evsel); +} + +static PyGetSetDef pyrf_event__getset[] =3D { + { + .name =3D "evsel", + .get =3D pyrf_event__get_evsel, + .set =3D NULL, + .doc =3D "tracking event.", + }, + { .name =3D NULL, }, +}; + static const char pyrf_mmap_event__doc[] =3D PyDoc_STR("perf mmap event ob= ject."); =20 static PyMemberDef pyrf_mmap_event__members[] =3D { @@ -101,6 +121,7 @@ static PyTypeObject pyrf_mmap_event__type =3D { .tp_flags =3D Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, .tp_doc =3D pyrf_mmap_event__doc, .tp_members =3D pyrf_mmap_event__members, + .tp_getset =3D pyrf_event__getset, .tp_repr =3D (reprfunc)pyrf_mmap_event__repr, }; =20 @@ -136,6 +157,7 @@ static PyTypeObject pyrf_task_event__type =3D { .tp_flags =3D Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, .tp_doc =3D pyrf_task_event__doc, .tp_members =3D pyrf_task_event__members, + .tp_getset =3D pyrf_event__getset, .tp_repr =3D (reprfunc)pyrf_task_event__repr, }; =20 @@ -165,6 +187,7 @@ static PyTypeObject pyrf_comm_event__type =3D { .tp_flags =3D Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, .tp_doc =3D pyrf_comm_event__doc, .tp_members =3D pyrf_comm_event__members, + .tp_getset =3D pyrf_event__getset, .tp_repr =3D (reprfunc)pyrf_comm_event__repr, }; =20 @@ -197,6 +220,7 @@ static PyTypeObject pyrf_throttle_event__type =3D { .tp_flags =3D Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, .tp_doc =3D pyrf_throttle_event__doc, .tp_members =3D pyrf_throttle_event__members, + .tp_getset =3D pyrf_event__getset, .tp_repr =3D (reprfunc)pyrf_throttle_event__repr, }; =20 @@ -232,6 +256,7 @@ static PyTypeObject pyrf_lost_event__type =3D { .tp_flags =3D Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, .tp_doc =3D pyrf_lost_event__doc, .tp_members =3D pyrf_lost_event__members, + .tp_getset =3D pyrf_event__getset, .tp_repr =3D (reprfunc)pyrf_lost_event__repr, }; =20 @@ -262,6 +287,7 @@ static PyTypeObject pyrf_read_event__type =3D { .tp_flags =3D Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, .tp_doc =3D pyrf_read_event__doc, .tp_members =3D pyrf_read_event__members, + .tp_getset =3D pyrf_event__getset, .tp_repr =3D (reprfunc)pyrf_read_event__repr, }; =20 @@ -387,6 +413,7 @@ static PyTypeObject pyrf_sample_event__type =3D { .tp_flags =3D Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, .tp_doc =3D pyrf_sample_event__doc, .tp_members =3D pyrf_sample_event__members, + .tp_getset =3D pyrf_event__getset, .tp_repr =3D (reprfunc)pyrf_sample_event__repr, .tp_getattro =3D (getattrofunc) pyrf_sample_event__getattro, }; @@ -425,6 +452,7 @@ static PyTypeObject pyrf_context_switch_event__type =3D= { .tp_flags =3D Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, .tp_doc =3D pyrf_context_switch_event__doc, .tp_members =3D pyrf_context_switch_event__members, + .tp_getset =3D pyrf_event__getset, .tp_repr =3D (reprfunc)pyrf_context_switch_event__repr, }; =20 @@ -1196,7 +1224,7 @@ static PyObject *pyrf_evsel__str(PyObject *self) struct pyrf_evsel *pevsel =3D (void *)self; struct evsel *evsel =3D pevsel->evsel; =20 - return PyUnicode_FromFormat("evsel(%s/%s/)", evsel__pmu_name(evsel), evse= l__name(evsel)); + return PyUnicode_FromFormat("evsel(%s)", evsel__name(evsel)); } =20 static PyMethodDef pyrf_evsel__methods[] =3D { @@ -1954,10 +1982,7 @@ static PyObject *pyrf_evlist__str(PyObject *self) evlist__for_each_entry(pevlist->evlist, pos) { if (!first) strbuf_addch(&sb, ','); - if (!pos->pmu) - strbuf_addstr(&sb, evsel__name(pos)); - else - strbuf_addf(&sb, "%s/%s/", pos->pmu->name, evsel__name(pos)); + strbuf_addstr(&sb, evsel__name(pos)); first =3D false; } strbuf_addstr(&sb, "])"); --=20 2.51.1.851.g4ebd6896fd-goog From nobody Sat Feb 7 22:21:10 2026 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 1F9772F619F for ; Wed, 29 Oct 2025 05:34:45 +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=1761716087; cv=none; b=dbZ4jHFm8BvawggMr3+uHXmq6lga/EAu0F4LgcGwv9CwpHYf29o/yOl6JttSHJp1GWHXRaHZEjkn5w88i5uK2IzriKw8z8h2SRwp5Hor/kCmYkHi9DeuhLVEhJHNSq5yYlVzp7Woy3Ze3Y+DfPloL5qMkymtbschsJ//M3e1JjQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761716087; c=relaxed/simple; bh=cXBb0FpLHE2+FneP8Fo+45jo0Wy454pCH8ScJIJcmqA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=iezpiFlHz/fMylmZC8CDJfcsWAtnzPXVgf8cJy1TPia1BZO30cHXYOMCk58TagKWWTvXkvrDjXRJpmPJkINJuaaEMef8asbsZgM6y5aK5L3OCgxLbvy9ZNTioWUEM/ow51ECbgPbinAKla2xmkhhFYEPNxybhfQQiXu3yeBbs+A= 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=cx3NmWig; 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="cx3NmWig" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-339b704e2e3so6216171a91.2 for ; Tue, 28 Oct 2025 22:34:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1761716085; x=1762320885; 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=gC3uJBytFjGETcDOSgD3LOM/9/gCLbGFWg1YShV84iU=; b=cx3NmWigG++FEG+yZxZLKwDkLaP9dRHHR+Uif9tw5qQq1g8R2ON2Jryv3wDAi+hrpo zQwE6o/7E9HMCyKy4w32R4VuX/daoUOqIZMhBD+Fft2zd+Fqd7KZtVHcpf+vl+lXtYR0 jvoCVXJkdLMmp988WFnz/P4idsG+0E09LrZA0oMYUDEWLbY9UXFGqqQw8HLCpRUUGFVc +tQieKwFUAh9kk2touFuVeivz6yBFb/xntiV8mEew0wmlAiUG+Brd0WI6KB7JGUAMtUs Spg9zOa8Uxwjv120gqFXfMw72nAMnKroCGx32gAtwnAillCR+ohfW/wJWNdTvNHcVxJ+ 4rMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761716085; x=1762320885; 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=gC3uJBytFjGETcDOSgD3LOM/9/gCLbGFWg1YShV84iU=; b=pO/qJMv2G1+xt4Oa2jlrhhmLUghd9rrcTPdfS11Zt3S628J3uXFlgdo5WPAGfMjb7Z Lu5INmnX9RhQB0SAutWbZOr006QlrobwoHmzPLRe6IzE+kwRDIRUBzTT0MWN0knTiPK8 D9TGWuGbhfSYSgXry5vvD41IBn4ZPe1NUctQWkLcD/CTu13oehE7GpjmLpuPYdXpC1tf 8kVoLkIsA+G9S9aWp2SBZw+u4GPYh6PiU4xfKJoTKb0x2upHBYqK1eeCIWgdYnWvNcZ1 Zp8uD//puUZWUaLp4f19pFDue9lzs2GOhdnu/EKm+B7z2uCUWUlJZGgmdfkp+gZynFtz ieRg== X-Forwarded-Encrypted: i=1; AJvYcCUQy3Elz9nmx+s+zcfqt4MCLBH6NSD6zUI4HyXcwFYg+Zg40jYu/FmLxsdov2R3FIsL1JUWdZ5dE5eZluA=@vger.kernel.org X-Gm-Message-State: AOJu0YyLUmoKR1M79PFd5BFZ/Z5bu4XKAGXDz+rukGTTSqHRp3zOyYO9 j1xQKNh/BDaKVwPGC6qel990MY6qqsr1qy3sRVtrifV9+i9EFyzd54yXCdfWMjFOb4IV4hEBHwM dcmPM20H1Xg== X-Google-Smtp-Source: AGHT+IHyABFgO5ifFMRWloVxbgKF6DgOKTCx7hX5z8zDswf1AZ0hIWHCguMLeQj+zWYBmU7ntB23e4WGxRng X-Received: from pjob9.prod.google.com ([2002:a17:90a:8c89:b0:33b:8aa1:75ed]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:2e4b:b0:33b:bf8d:6172 with SMTP id 98e67ed59e1d1-3403a305995mr1671076a91.34.1761716085290; Tue, 28 Oct 2025 22:34:45 -0700 (PDT) Date: Tue, 28 Oct 2025 22:34:13 -0700 In-Reply-To: <20251029053413.355154-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: <20251029053413.355154-1-irogers@google.com> X-Mailer: git-send-email 2.51.1.851.g4ebd6896fd-goog Message-ID: <20251029053413.355154-16-irogers@google.com> Subject: [RFC PATCH v1 15/15] perf mem-phys-addr.py: Port to standalone application from perf script From: Ian Rogers To: Suzuki K Poulose , Mike Leach , James Clark , John Garry , Will Deacon , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Greg Kroah-Hartman , Charlie Jenkins , Thomas Falcon , Yicong Yang , Thomas Richter , Athira Rajeev , Howard Chu , Song Liu , Dapeng Mi , Levi Yun , Zhongqiu Han , Blake Jones , Anubhav Shelat , Chun-Tse Shao , Christophe Leroy , Jean-Philippe Romain , Gautam Menghani , Dmitry Vyukov , Yang Li , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Andi Kleen , Weilin Wang Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Give an example of using the perf python session API to load a perf.data file and perform the behavior of tools/perf/scripts/python/mem-phys-addr.py. Signed-off-by: Ian Rogers --- tools/perf/python/mem-phys-addr.py | 117 +++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 tools/perf/python/mem-phys-addr.py diff --git a/tools/perf/python/mem-phys-addr.py b/tools/perf/python/mem-phy= s-addr.py new file mode 100644 index 000000000000..32bb63598239 --- /dev/null +++ b/tools/perf/python/mem-phys-addr.py @@ -0,0 +1,117 @@ +# mem-phys-addr.py: Resolve physical address samples +# SPDX-License-Identifier: GPL-2.0 +# +# Copyright (c) 2018, Intel Corporation. + +import bisect +import collections +import os +import perf +import re +import sys +from dataclasses import dataclass +from typing import (Dict, Optional) + +@dataclass(frozen=3DTrue) +class IomemEntry: + """Read from a line in /proc/iomem""" + begin: int + end: int + indent: int + label: str + +# Physical memory layout from /proc/iomem. Key is the indent and then +# a list of ranges. +iomem: Dict[int, list[IomemEntry]] =3D collections.defaultdict(list) +# Child nodes from the iomem parent. +children: Dict[IomemEntry, set[IomemEntry]] =3D collections.defaultdict(se= t) +# Maximum indent seen before an entry in the iomem file. +max_indent: int =3D 0 +# Count for each range of memory. +load_mem_type_cnt: Dict[IomemEntry, int] =3D collections.Counter() +# Perf event name set from the first sample in the data. +event_name: Optional[str] =3D None + +def parse_iomem(): + """Populate iomem from /proc/iomem file""" + global iomem + global max_indent + global children + with open('/proc/iomem', 'r', encoding=3D'ascii') as f: + for line in f: + indent =3D 0 + while line[indent] =3D=3D ' ': + indent +=3D 1 + if indent > max_indent: + max_indent =3D indent + m =3D re.split('-|:', line, maxsplit=3D2) + begin =3D int(m[0], 16) + end =3D int(m[1], 16) + label =3D m[2].strip() + entry =3D IomemEntry(begin, end, indent, label) + # Before adding entry, search for a parent node using its begi= n. + if indent > 0: + parent =3D find_memory_type(begin) + assert parent, f"Given indent expected a parent for {label= }" + children[parent].add(entry) + iomem[indent].append(entry) + +def find_memory_type(phys_addr) -> Optional[IomemEntry]: + """Search iomem for the range containing phys_addr with the maximum in= dent""" + for i in range(max_indent, -1, -1): + if i not in iomem: + continue + position =3D bisect.bisect_right(iomem[i], phys_addr, + key=3Dlambda entry: entry.begin) + if position is None: + continue + iomem_entry =3D iomem[i][position-1] + if iomem_entry.begin <=3D phys_addr <=3D iomem_entry.end: + return iomem_entry + print(f"Didn't find {phys_addr}") + return None + +def print_memory_type(): + print(f"Event: {event_name}") + print(f"{'Memory type':<40} {'count':>10} {'percentage':>10}") + print(f"{'-' * 40:<40} {'-' * 10:>10} {'-' * 10:>10}") + total =3D sum(load_mem_type_cnt.values()) + # Add count from children into the parent. + for i in range(max_indent, -1, -1): + if i not in iomem: + continue + for entry in iomem[i]: + global children + for child in children[entry]: + if load_mem_type_cnt[child] > 0: + load_mem_type_cnt[entry] +=3D load_mem_type_cnt[child] + + def print_entries(entries): + """Print counts from parents down to their children""" + global children + for entry in sorted(entries, + key =3D lambda entry: load_mem_type_cnt[entry], + reverse =3D True): + count =3D load_mem_type_cnt[entry] + if count > 0: + mem_type =3D ' ' * entry.indent + f"{entry.begin:x}-{entry= .end:x} : {entry.label}" + percent =3D 100 * count / total + print(f"{mem_type:<40} {count:>10} {percent:>10.1f}") + print_entries(children[entry]) + + print_entries(iomem[0]) + +if __name__ =3D=3D "__main__": + def process_event(sample): + phys_addr =3D sample.sample_phys_addr + entry =3D find_memory_type(phys_addr) + if entry: + load_mem_type_cnt[entry] +=3D 1 + + global event_name + if event_name is None: + event_name =3D str(sample.evsel) + + parse_iomem() + perf.session(perf.data("perf.data"), sample=3Dprocess_event).process_e= vents() + print_memory_type() --=20 2.51.1.851.g4ebd6896fd-goog