From nobody Fri Dec 19 17:37:02 2025 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 648E1289341 for ; Mon, 14 Apr 2025 17:41:58 +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=1744652520; cv=none; b=OidNsvxYKpgc4x9tEr11KXAFmspzEtjH4L5slnr972l3jmYOw89GVpPB0N9+oeIaRYOVTVY4V11L0nkglW9Tww8+vyxBSZmwHkPWpqIUz5YJ5GxLSjIDNFc8UN6xD+suYlhW95vzVKhwdD1eRa1Vc5yWsrlBNz4I2WWXlOWarn4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744652520; c=relaxed/simple; bh=slHe5WC35Qo1w8hHbLkGv/83Qna2F02lahPNQerHbw8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=U/TlOwUgrFxqOvUDrI2uQd6cJBzOE+JSI+nM+gjQ7DlCAy3PReW/pR4BUBv6oXslNgquicybLppZ5mk6ZE9QwYRfTXrh/VxKFMh/Esk0hHEvN54p88LhRfG9EoBNhhHCt7WkOH8Eh7j9tCC/s2tZ1q19MATZvobQO9/axyO4gFA= 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=I0TQkECW; 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="I0TQkECW" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-3055f2e1486so6922178a91.0 for ; Mon, 14 Apr 2025 10:41:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1744652517; x=1745257317; 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=zlPSRtvb4/+TTghxrsueo1A3tWRb8o4F7DCTI51/qHU=; b=I0TQkECWxjPav8Enyn6SYKgmiZPcbhR8KsVmlwKtnZ1IQRVJ7kV8sdPgZEvhdHXwZJ BDVQbgC07kDmr2PTenKAi58lc3cgcfTJLg7Bcc/P0n5j7qvOrVFmaBdJ8iIKPzC/Oy+I z1HGLQ5hB+GWLlJwudWR98a/WI8vHYYu8ZhRPaD4Vfmnkwpqc1YG8345pUzDZZ7GcPIo t/GZZDaJ0uTFPf8h+dE12LUiL9VaSUiUPh/sXbVJ6maWZ125SvGeiW30ZrCOswNmqxiD c9Xt7t63AZr7H+6gxGPOjejDygzKE1V/KOvncgOrL2jXBv5ipvxwSi8cS7cWoXbMj0GB HHsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744652517; x=1745257317; 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=zlPSRtvb4/+TTghxrsueo1A3tWRb8o4F7DCTI51/qHU=; b=wVP/NvW0+CXiNLRZb2vvfGjo/Ezu5UrZSZd8tvnXw/7dcz+LcMfZt46KokWk25Y2ZI cKE13F6zuv0pxqqb6R0yTWg/fAqP0EYhgvO6VOrd8ou9ITMQClqMvc9MJ9BtDFBseZ33 zuuDIG5Ed9trfU2uKbEqnn9kqOuTGx6TwD/02dnFnjkkvePDxOS/uEvPw0GjoPnb6o/w xKTTHX3Bj5Fm2mSzC4EvvviGKPf1aofPjE+apIs9WCjoaDRb4WWry3tLUtsxgnGVOy0M r6DXEthsxdcN2qFy3LsDKi+FMCM9al328eplmJQ1idp4fvIJvo214n0YTOBsRm1h9dxS gRAQ== X-Forwarded-Encrypted: i=1; AJvYcCVYo0463oKy8SYKBRmvbnc3z9mGW3ncgYBh+enxy6urnmsWiIW/BZA2T6iDEbjRj1NVB/qcKF8vTwsuVmk=@vger.kernel.org X-Gm-Message-State: AOJu0YzCZ6i/WxH+B+chAD6XiHSpBUSZpB8tlHzJGbFy7UwPl/9wfgW1 b+vALlRUNrGhWL/X/cr+/oYcTgFHMGUnkcXUIS+uUIXOU4WlXIH+9kMy+3gFXNCrxFrBgBw/VLs QloLh9g== X-Google-Smtp-Source: AGHT+IH9rV1O8BX4TziERNYAHUqTWDiePpMXRosCaFe8xB6DJ3X2Nfbl3Vec8TG/UcvWizJkMElzLTcdYlym X-Received: from pjbpl17.prod.google.com ([2002:a17:90b:2691:b0:2f7:d453:e587]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90a:dfc4:b0:306:b593:4557 with SMTP id 98e67ed59e1d1-30823633eb7mr16671483a91.4.1744652517625; Mon, 14 Apr 2025 10:41:57 -0700 (PDT) Date: Mon, 14 Apr 2025 10:41:19 -0700 In-Reply-To: <20250414174134.3095492-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: <20250414174134.3095492-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.604.gff1f9ca942-goog Message-ID: <20250414174134.3095492-2-irogers@google.com> Subject: [PATCH v5 01/16] perf intel-tpebs: Cleanup header From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , "=?UTF-8?q?Andreas=20F=C3=A4rber?=" , Manivannan Sadhasivam , Maxime Coquelin , Alexandre Torgue , Caleb Biggers , Weilin Wang , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Perry Taylor , Thomas Falcon Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Remove arch conditional compilation. Arch conditional compilation belongs in the arch/ directory. Tidy header guards to match other files. Remove unneeded includes and switch to forward declarations when necesary. Signed-off-by: Ian Rogers Tested-by: Weilin Wang Acked-by: Namhyung Kim Reviewed-by: Kan Liang --- tools/perf/util/Build | 2 +- tools/perf/util/intel-tpebs.c | 1 + tools/perf/util/intel-tpebs.h | 30 ++++++------------------------ 3 files changed, 8 insertions(+), 25 deletions(-) diff --git a/tools/perf/util/Build b/tools/perf/util/Build index 946bce6628f3..815274b199fd 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build @@ -161,7 +161,7 @@ perf-util-y +=3D clockid.o perf-util-y +=3D list_sort.o perf-util-y +=3D mutex.o perf-util-y +=3D sharded_mutex.o -perf-util-$(CONFIG_X86_64) +=3D intel-tpebs.o +perf-util-y +=3D intel-tpebs.o =20 perf-util-$(CONFIG_LIBBPF) +=3D bpf_map.o perf-util-$(CONFIG_PERF_BPF_SKEL) +=3D bpf_counter.o diff --git a/tools/perf/util/intel-tpebs.c b/tools/perf/util/intel-tpebs.c index 2c421b475b3b..3503da28a12f 100644 --- a/tools/perf/util/intel-tpebs.c +++ b/tools/perf/util/intel-tpebs.c @@ -19,6 +19,7 @@ #include "tool.h" #include "cpumap.h" #include "metricgroup.h" +#include "stat.h" #include #include #include diff --git a/tools/perf/util/intel-tpebs.h b/tools/perf/util/intel-tpebs.h index 766b3fbd79f1..63c16e759a71 100644 --- a/tools/perf/util/intel-tpebs.h +++ b/tools/perf/util/intel-tpebs.h @@ -2,34 +2,16 @@ /* * intel_tpebs.h: Intel TEPBS support */ -#ifndef INCLUDE__PERF_INTEL_TPEBS_H__ -#define INCLUDE__PERF_INTEL_TPEBS_H__ +#ifndef __INTEL_TPEBS_H +#define __INTEL_TPEBS_H =20 -#include "stat.h" -#include "evsel.h" - -#ifdef HAVE_ARCH_X86_64_SUPPORT +struct evlist; +struct evsel; =20 extern bool tpebs_recording; + int tpebs_start(struct evlist *evsel_list); void tpebs_delete(void); int tpebs_set_evsel(struct evsel *evsel, int cpu_map_idx, int thread); =20 -#else - -static inline int tpebs_start(struct evlist *evsel_list __maybe_unused) -{ - return 0; -} - -static inline void tpebs_delete(void) {}; - -static inline int tpebs_set_evsel(struct evsel *evsel __maybe_unused, - int cpu_map_idx __maybe_unused, - int thread __maybe_unused) -{ - return 0; -} - -#endif -#endif +#endif /* __INTEL_TPEBS_H */ --=20 2.49.0.604.gff1f9ca942-goog From nobody Fri Dec 19 17:37:02 2025 Received: from mail-ot1-f74.google.com (mail-ot1-f74.google.com [209.85.210.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 789AE289374 for ; Mon, 14 Apr 2025 17:42:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744652522; cv=none; b=BWlX5u3WNYw8aSqy9qpUoLGQExlUH91KzrR34UIGlzs0oW+RU4XulDT7pXV+vflIq0gp0EB1GjgehZ2WxPvklm69QpqQffXC0oQ98bCOhdSkB0QAtJm+gyISXyRiVlBHwHUmE1opJIQr3C37xXmgMBHbyzkATLneUTLzKAbzuE0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744652522; c=relaxed/simple; bh=GYcCF2ln1JP9ulMcXVsY5IXeTj02wNp7Ku5VYlensd8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=EWNPInqJ5RPnjj+kUPYHWCrX1Mr3gJ3D1BnqIvRNuXyAjKjHHRWs6Dz+2pFWxQF0i6s9GE6NDhWgwshidirSqEe1A/F7/tt0lfGU8WhEuNNzvBWH8ca96S9HG7sAvPHG1NwkcvKNfPMCGDq/zD6RCAWtUylBmfW8szatf/O9Qlo= 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=D+w8eaZ9; arc=none smtp.client-ip=209.85.210.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="D+w8eaZ9" Received: by mail-ot1-f74.google.com with SMTP id 46e09a7af769-72b7c00f3c6so1659400a34.0 for ; Mon, 14 Apr 2025 10:42:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1744652519; x=1745257319; 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=8Xjqd/eHoa9qdRaFqxZ6wL6dtilUZmMfUfX3xchqEoQ=; b=D+w8eaZ9LWeAy3RsxYoZ6weGow39NJQ23GjJJS906dhIFQpX3Hyyp3QzFUaB6/LKcl e/pXOPXKP/fkBcl3Zw/vbmFjqtjCU358sofL1Ye7/gkQ1U32yR9+GZhaCF/PjqPkd2H7 pHJzWBPpRfozLPmBhv9ao0/SV0QKBQoACzosBdV1nQGKF2u+QuCEkEbngUSoRyhbwBcs YuOB+ryPZmgMMQ7kLFiwxv2JFYUBeQ8+G0r6YhWTlMAJSiy6uFVMzO290+2DVdhcTey6 3Jqlvlqxm+bQVz7aelHeFpE9EqYiFJ4RiQpmV6sFCDlVHTn59mkH7AFfVaXC8GZttpfI zkxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744652519; x=1745257319; 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=8Xjqd/eHoa9qdRaFqxZ6wL6dtilUZmMfUfX3xchqEoQ=; b=EruvPfm7JVXDNEVUXGHh/GYe10d1PC3+3GJWf1UpbuI5UfnR1KP48phSReP/Ej3CBv YIgQnarDhO2J/TdQD8W4P6PCXzfdHIVavqkGpy/XQez2Cn65q9ZzTGgDljhIq0DVeDN7 +WK/dxLDMEagE3Kp2rB6PMub4osh/t5X2tKHz024fo7PTajlS+1swh8dwIdJcoicLQ8i K3JXp0PXy7zeVba8TIGsgizXuZt3Zz+8MESACwrdB8YmVQ9XA+x7vPkHUEAqnzsmiC8Q 1K9WVkz7nibz553CNkH07hqwqSQWScfk3smi6taqyVXzSB3w9YjA2kPHZ3/m8rz1zI0R tkIQ== X-Forwarded-Encrypted: i=1; AJvYcCXFKsHx2VOGdHyLxYBxdWbGRzAbxO4oe3FrxpgexW6e2dGH2BGiLcKeMIf8moVAzP4RNdYsMs6a6gh+HrM=@vger.kernel.org X-Gm-Message-State: AOJu0Yy08/BRRvvwibTKi6zV0IcPopq9hluVJEBgOZWsaGbkyoGKHi9+ mRGamdoWq+lFOV/CBCU2pEQwak2J6iza9T/+Ee8cRCGkprOOi9y/6B83AkuKfoth8xrU/s6l+xX ZaanZDQ== X-Google-Smtp-Source: AGHT+IHAIHvmg45ZH8ZmmVp/o/FWbJr3iih77T1GTi8Z3PZ66JhZvV5CYV4n9hK5Yd6wEJ4qlbsRbrKYH0jU X-Received: from oacoz11.prod.google.com ([2002:a05:6871:788b:b0:29d:f69c:1743]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6830:470c:b0:72a:1ecc:d23a with SMTP id 46e09a7af769-72e86341148mr8606745a34.15.1744652519541; Mon, 14 Apr 2025 10:41:59 -0700 (PDT) Date: Mon, 14 Apr 2025 10:41:20 -0700 In-Reply-To: <20250414174134.3095492-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: <20250414174134.3095492-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.604.gff1f9ca942-goog Message-ID: <20250414174134.3095492-3-irogers@google.com> Subject: [PATCH v5 02/16] perf intel-tpebs: Simplify tpebs_cmd From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , "=?UTF-8?q?Andreas=20F=C3=A4rber?=" , Manivannan Sadhasivam , Maxime Coquelin , Alexandre Torgue , Caleb Biggers , Weilin Wang , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Perry Taylor , Thomas Falcon Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" No need to dynamically allocate when there is 1. tpebs_pid duplicates tpebs_cmd.pid, so remove. Use 0 as the uninitialized value (PID =3D=3D 0 is reserved for the kernel) rather than -1. Signed-off-by: Ian Rogers Tested-by: Weilin Wang Acked-by: Namhyung Kim Reviewed-by: Kan Liang --- tools/perf/util/intel-tpebs.c | 55 ++++++++++++----------------------- 1 file changed, 18 insertions(+), 37 deletions(-) diff --git a/tools/perf/util/intel-tpebs.c b/tools/perf/util/intel-tpebs.c index 3503da28a12f..74b43faab986 100644 --- a/tools/perf/util/intel-tpebs.c +++ b/tools/perf/util/intel-tpebs.c @@ -28,11 +28,10 @@ #define PERF_DATA "-" =20 bool tpebs_recording; -static pid_t tpebs_pid =3D -1; static size_t tpebs_event_size; static LIST_HEAD(tpebs_results); static pthread_t tpebs_reader_thread; -static struct child_process *tpebs_cmd; +static struct child_process tpebs_cmd; =20 struct tpebs_retire_lat { struct list_head nd; @@ -83,16 +82,6 @@ static int get_perf_record_args(const char **record_argv= , char buf[], return 0; } =20 -static int prepare_run_command(const char **argv) -{ - tpebs_cmd =3D zalloc(sizeof(struct child_process)); - if (!tpebs_cmd) - return -ENOMEM; - tpebs_cmd->argv =3D argv; - tpebs_cmd->out =3D -1; - return 0; -} - static int start_perf_record(int control_fd[], int ack_fd[], const char *cpumap_buf) { @@ -110,10 +99,10 @@ static int start_perf_record(int control_fd[], int ack= _fd[], if (ret) goto out; =20 - ret =3D prepare_run_command(record_argv); - if (ret) - goto out; - ret =3D start_command(tpebs_cmd); + assert(tpebs_cmd.pid =3D=3D 0); + tpebs_cmd.argv =3D record_argv; + tpebs_cmd.out =3D -1; + ret =3D start_command(&tpebs_cmd); out: free(record_argv); return ret; @@ -156,14 +145,13 @@ static int process_feature_event(struct perf_session = *session, return 0; } =20 -static void *__sample_reader(void *arg) +static void *__sample_reader(void *arg __maybe_unused) { - struct child_process *child =3D arg; struct perf_session *session; struct perf_data data =3D { .mode =3D PERF_DATA_MODE_READ, .path =3D PERF_DATA, - .file.fd =3D child->out, + .file.fd =3D tpebs_cmd.out, }; struct perf_tool tool; =20 @@ -189,12 +177,12 @@ static int tpebs_stop(void) int ret =3D 0; =20 /* Like tpebs_start, we should only run tpebs_end once. */ - if (tpebs_pid !=3D -1) { - kill(tpebs_cmd->pid, SIGTERM); - tpebs_pid =3D -1; + if (tpebs_cmd.pid !=3D 0) { + kill(tpebs_cmd.pid, SIGTERM); pthread_join(tpebs_reader_thread, NULL); - close(tpebs_cmd->out); - ret =3D finish_command(tpebs_cmd); + close(tpebs_cmd.out); + ret =3D finish_command(&tpebs_cmd); + tpebs_cmd.pid =3D 0; if (ret =3D=3D -ERR_RUN_COMMAND_WAITPID_SIGNAL) ret =3D 0; } @@ -219,7 +207,7 @@ int tpebs_start(struct evlist *evsel_list) * We should only run tpebs_start when tpebs_recording is enabled. * And we should only run it once with all the required events. */ - if (tpebs_pid !=3D -1 || !tpebs_recording) + if (tpebs_cmd.pid !=3D 0 || !tpebs_recording) return 0; =20 cpu_map__snprint(evsel_list->core.user_requested_cpus, cpumap_buf, sizeof= (cpumap_buf)); @@ -284,10 +272,11 @@ int tpebs_start(struct evlist *evsel_list) ret =3D start_perf_record(control_fd, ack_fd, cpumap_buf); if (ret) goto out; - tpebs_pid =3D tpebs_cmd->pid; - if (pthread_create(&tpebs_reader_thread, NULL, __sample_reader, tpebs_cm= d)) { - kill(tpebs_cmd->pid, SIGTERM); - close(tpebs_cmd->out); + + if (pthread_create(&tpebs_reader_thread, /*attr=3D*/NULL, __sample_reade= r, + /*arg=3D*/NULL)) { + kill(tpebs_cmd.pid, SIGTERM); + close(tpebs_cmd.out); pr_err("Could not create thread to process sample data.\n"); ret =3D -1; goto out; @@ -416,18 +405,10 @@ void tpebs_delete(void) { struct tpebs_retire_lat *r, *rtmp; =20 - if (tpebs_pid =3D=3D -1) - return; - tpebs_stop(); =20 list_for_each_entry_safe(r, rtmp, &tpebs_results, nd) { list_del_init(&r->nd); tpebs_retire_lat__delete(r); } - - if (tpebs_cmd) { - free(tpebs_cmd); - tpebs_cmd =3D NULL; - } } --=20 2.49.0.604.gff1f9ca942-goog From nobody Fri Dec 19 17:37:02 2025 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1218728B502 for ; Mon, 14 Apr 2025 17:42:01 +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=1744652523; cv=none; b=jWSbkGYiAEaojso8oPMVN3q8p9Dis8p2R+wlWq7pA7tj8IojES0IJlr1C6dyUcGXQQw1EhjobRxMlH2SKqwTHqmgONgf9IcFMcyxtNFJCpzdiiFzC74HA/VjrAHJxxP+fYdIyGKmvWU9ELSieHo5+M5zinrQ4CSU9Nb0SOoZiAg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744652523; c=relaxed/simple; bh=aAdzhzW38NjSMOvy9Z8oUVow8Z9ErhbvXK/Tehm7JYQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=NnXGPhWxtn1dR0dURqpvE5xajIVTAlfhAk1dis6X0ws1MBVxn9NDqQPAJmlT93TPTt1fOXzK2iEamKXzpXLhfrLDQZZlx6GXTsJ2iifDaT/qwEvcduwd2AKU14797+7DjtUj+qeKGSY7abTbY0stZkFq8QCZjKGxdDTXxtkwTlU= 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=dv/WpeWd; 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="dv/WpeWd" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-229170fbe74so38033545ad.2 for ; Mon, 14 Apr 2025 10:42:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1744652521; x=1745257321; 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=rPTy94ffbUEhOKiK1IPtcVt4myAa/NejYMC0O4TJ2i8=; b=dv/WpeWdwBXaGMk39ivgRu5BqbUJnCRjxIT9W53FEFbCs098MZ+xsbWPUCObl8lNTb Toy6Lvfrl8WjC13qtNWPPtFc6RhgOdMdervxwO48IDhyvjd7EL2UqEhHtofKWa6+un6H ncuPMzr95N8cGd50149fTBVc1JPkc89BYYQgliwcbzl5AgqXdcg1hB0yV7QnDCqcm+l+ nV3sOJ63ec/ziEwGkXbL3O2hxoJvtGVajc/Lqv555QubtOSyFl1WChYz58XmUTlt+3a1 uTUzyDcUbfQP/wc8d6xKIX0ehADSvtfIXMhdRMFo22HQ+U/RpsCrxmETYFYW5eFX1C12 4bKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744652521; x=1745257321; 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=rPTy94ffbUEhOKiK1IPtcVt4myAa/NejYMC0O4TJ2i8=; b=gNP1SueoEl8MOzKTxefc7tt1QaB6fCqKlhC6YooQ29ma1z8hMOtCyarcd4/MPbuOUy yimSJLwwI1VkePDw62QioFzyoIGY6uHo8r3HR8ng4leAjhQrH6T34jEip7WwBR2uezqO Q3039ovEe9s1szHeLgfX+6EB5aJJJZymEREo56p81D0X3Qr6gVXpOk/NI82X8so7K0jF eaZf6EOIuvYy0kGOkWxBB/7N+BVOyvYFzPTyzK2xlPSgd0FYfqtFNqkACYiXQC3cGsen cvrz/6IHx8fD0g5Jd5xYd9RSGZBi4uzig8QmK7/hO+o7ty/X8iPPcfqzAaoYckKNISs3 o0KQ== X-Forwarded-Encrypted: i=1; AJvYcCW+OPczGataERWq3uDM47hfb8xee8Oj8IJWINlOuigxjEx72QPvNzk9+SqKedA8zWtRLIrHml24LzVokjc=@vger.kernel.org X-Gm-Message-State: AOJu0YxpSIUL2iz+aIuVwDV6YA/aAKxAGBy6ZpptgtLLR/QLb/TrtZCZ re5d8MzB9NAj7/sf3SJymxerOUsMFDtabztRsH+RYHNX74XDUp6UDYW4qki49zYmFLVWdiGty8V gwZ3lig== X-Google-Smtp-Source: AGHT+IG/gtBJJm+4WgoCQHddaWlnyMc8L5+ILxbIyEsaY8UY7mmKrwp+YEP7LUoIH2k4YQQ0A0Ws08PeGF+f X-Received: from plbkg5.prod.google.com ([2002:a17:903:605:b0:21f:3ef1:c029]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:230d:b0:223:fbc7:25f4 with SMTP id d9443c01a7336-22bea4b70cbmr164437455ad.14.1744652521390; Mon, 14 Apr 2025 10:42:01 -0700 (PDT) Date: Mon, 14 Apr 2025 10:41:21 -0700 In-Reply-To: <20250414174134.3095492-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: <20250414174134.3095492-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.604.gff1f9ca942-goog Message-ID: <20250414174134.3095492-4-irogers@google.com> Subject: [PATCH v5 03/16] perf intel-tpebs: Rename tpebs_start to evsel__tpebs_open From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , "=?UTF-8?q?Andreas=20F=C3=A4rber?=" , Manivannan Sadhasivam , Maxime Coquelin , Alexandre Torgue , Caleb Biggers , Weilin Wang , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Perry Taylor , Thomas Falcon Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Try to add more consistency to evsel by having tpebs_start renamed to evsel__tpebs_open, passing the evsel that is being opened. The unusual behavior of evsel__tpebs_open opening all events on the evlist is kept and will be cleaned up further in later patches. The comments are cleaned up as tpebs_start isn't called from evlist. Signed-off-by: Ian Rogers Tested-by: Weilin Wang Acked-by: Namhyung Kim Reviewed-by: Kan Liang --- tools/perf/util/evsel.c | 2 +- tools/perf/util/intel-tpebs.c | 33 ++++++++++++++++----------------- tools/perf/util/intel-tpebs.h | 2 +- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 1974395492d7..121283f2f382 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -2595,7 +2595,7 @@ static int evsel__open_cpu(struct evsel *evsel, struc= t perf_cpu_map *cpus, struct perf_cpu cpu; =20 if (evsel__is_retire_lat(evsel)) - return tpebs_start(evsel->evlist); + return evsel__tpebs_open(evsel); =20 err =3D __evsel__prepare_open(evsel, cpus, threads); if (err) diff --git a/tools/perf/util/intel-tpebs.c b/tools/perf/util/intel-tpebs.c index 74b43faab986..566e0ddcad88 100644 --- a/tools/perf/util/intel-tpebs.c +++ b/tools/perf/util/intel-tpebs.c @@ -12,6 +12,7 @@ #include #include #include "sample.h" +#include "counts.h" #include "debug.h" #include "evlist.h" #include "evsel.h" @@ -189,18 +190,16 @@ static int tpebs_stop(void) return ret; } =20 -/* - * tpebs_start - start tpebs execution. - * @evsel_list: retire_latency evsels in this list will be selected and sa= mpled - * to get the average retire_latency value. - * - * This function will be called from evlist level later when evlist__open(= ) is - * called consistently. +/** + * evsel__tpebs_open - starts tpebs execution. + * @evsel: retire_latency evsel, all evsels on its list will be selected. = Each + * evsel is sampled to get the average retire_latency value. */ -int tpebs_start(struct evlist *evsel_list) +int evsel__tpebs_open(struct evsel *evsel) { int ret =3D 0; - struct evsel *evsel; + struct evsel *pos; + struct evlist *evsel_list =3D evsel->evlist; char cpumap_buf[50]; =20 /* @@ -215,25 +214,25 @@ int tpebs_start(struct evlist *evsel_list) * Prepare perf record for sampling event retire_latency before fork and * prepare workload */ - evlist__for_each_entry(evsel_list, evsel) { + evlist__for_each_entry(evsel_list, pos) { int i; char *name; struct tpebs_retire_lat *new; =20 - if (!evsel->retire_lat) + if (!pos->retire_lat) continue; =20 - pr_debug("tpebs: Retire_latency of event %s is required\n", evsel->name); - for (i =3D strlen(evsel->name) - 1; i > 0; i--) { - if (evsel->name[i] =3D=3D 'R') + pr_debug("tpebs: Retire_latency of event %s is required\n", pos->name); + for (i =3D strlen(pos->name) - 1; i > 0; i--) { + if (pos->name[i] =3D=3D 'R') break; } - if (i <=3D 0 || evsel->name[i] !=3D 'R') { + if (i <=3D 0 || pos->name[i] !=3D 'R') { ret =3D -1; goto err; } =20 - name =3D strdup(evsel->name); + name =3D strdup(pos->name); if (!name) { ret =3D -ENOMEM; goto err; @@ -247,7 +246,7 @@ int tpebs_start(struct evlist *evsel_list) goto err; } new->name =3D name; - new->tpebs_name =3D evsel->name; + new->tpebs_name =3D pos->name; list_add_tail(&new->nd, &tpebs_results); tpebs_event_size +=3D 1; } diff --git a/tools/perf/util/intel-tpebs.h b/tools/perf/util/intel-tpebs.h index 63c16e759a71..cc98203719c8 100644 --- a/tools/perf/util/intel-tpebs.h +++ b/tools/perf/util/intel-tpebs.h @@ -10,7 +10,7 @@ struct evsel; =20 extern bool tpebs_recording; =20 -int tpebs_start(struct evlist *evsel_list); +int evsel__tpebs_open(struct evsel *evsel); void tpebs_delete(void); int tpebs_set_evsel(struct evsel *evsel, int cpu_map_idx, int thread); =20 --=20 2.49.0.604.gff1f9ca942-goog From nobody Fri Dec 19 17:37:02 2025 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3149F28BA90 for ; Mon, 14 Apr 2025 17:42:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744652525; cv=none; b=EH0p063AsKdkOQpBolbvMJ6iL8n0wqxm9GhOnp32qkolouISI2z7MTUaIdrTPy9BI03ER8fNSWbBpiSW+3ZBh/xX/SFJJa6RflcbBdVp77s5A6orIZ1NJS1BOn0N+MNk8S0rXbwtrN4NfgO0tOrrxW/iF0y7MIx0B++cRg05fA8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744652525; c=relaxed/simple; bh=cldPljtNT7qHiWPUEEbz2VWvuqG4wWZhrYjwH64BME4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=tqkBKlCzan9SqhJSz6ItesxpgSxCFF6sn0PigEKjPjEWiwRxNS2ZNqy+oHLpA26U4QFt4x8JQIW4wwVryYCT9gsHxxDWqy3G3YxeCtCGnVKJ7GqhGYgk88GaEQEx0OaejH5rdSwGnSoLRKbMgf4u0a/cU9HrgPqrltYH4cwDsrg= 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=PvXGM2M3; 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="PvXGM2M3" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-afd3f1adff7so4043922a12.1 for ; Mon, 14 Apr 2025 10:42:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1744652523; x=1745257323; 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=1iLUqminNY9h66ZOYZ2ICZcvhX324SmqH91RvhsK5HA=; b=PvXGM2M3CH6kn0coZsEasyQRZSXgh7E5ONVHNbpl9FygQt+Mz3Lm37OSGHzB8YhrCK CxUJUW5Ey3Xuua73RL+b8b/j72f+mhMzFbteUutCeiXvIB0r6WcAMdpLk6b/1AFNTcGI fS11angRIq+guEx3ULsSq6X9KvZ0fsmBQbgxUla9vHPZ7iujGHDjbSskV77RfMwxt1GT zR5cCqp+3Y6l7/DcJy8ojKu/MP5zYqqqWAkjdyDFn428mYr8sAIwo+ET53FYCpPRRJ3r su4S5QrpB5VCxHtXj6AR3TDy8jeaCOdrUMC9kqJpP6x2Hok/LhDGaz9d6RaWJw5ReKc4 Fkhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744652523; x=1745257323; 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=1iLUqminNY9h66ZOYZ2ICZcvhX324SmqH91RvhsK5HA=; b=LlxGDdBMPA6IHQVqo/+nYxZ3mI2fDbpQ8YDdUq72jrbR0R90kZQ+xtVHLrutm+VfYh ZPXT82nRSKi+i/9OdL7pM4/FKVWprcwZtyTSIfM4OKAURyxoO0Tr6z+xP1OoZqLJVTtH H3vQ9A9DHDhhC15LzYry+rFtdOybOV2BU4bLT9OADun5xWo/+FDj1eLsFrAye5rF+ofN VbHXMC92g7Urq8JTXDgW1ZxdcuCCriEkDQdCXU7XfrUfZfuZiO/BEsye5nLdY7R0tFfO Mg1RD/go78BMeCVVE1fF0RlH4ROs+cs/QQMSvEsFBHd8xbQlU95T+14TgeF61BBdpyn8 aT/A== X-Forwarded-Encrypted: i=1; AJvYcCU6/k0Kv1PdjpBcfqlaUh9XhWVxDf4i/RH6vew5IDz2woLaDIDtfbFbrDP4xkGm3JaaUVDab3P9VrfQPuU=@vger.kernel.org X-Gm-Message-State: AOJu0YyZyZBH6wC7U5TNXbKBYlK0GzPsDZXlb0HmxdpBUachd7MVgZFg +UulqEpoPmE73tX0ISDn2ekMPZWZL9LlQKSFwUpQxUMJqTDm+VvRtabNqR9tYEG18vHsysP/FdZ 8u92cdg== X-Google-Smtp-Source: AGHT+IHdmELhPxIFAiAZcNIPY0tCHWJxBvhCbZlFXjCC25dE912X35YAB3Gcl004AeJKAB/efk5XIPYPF2i4 X-Received: from pjxx16.prod.google.com ([2002:a17:90b:58d0:b0:2e5:5ffc:1c36]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:5848:b0:2fa:17e4:b1cf with SMTP id 98e67ed59e1d1-3084f306d88mr434225a91.2.1744652523505; Mon, 14 Apr 2025 10:42:03 -0700 (PDT) Date: Mon, 14 Apr 2025 10:41:22 -0700 In-Reply-To: <20250414174134.3095492-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: <20250414174134.3095492-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.604.gff1f9ca942-goog Message-ID: <20250414174134.3095492-5-irogers@google.com> Subject: [PATCH v5 04/16] perf intel-tpebs: Separate evsel__tpebs_prepare out of evsel__tpebs_open From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , "=?UTF-8?q?Andreas=20F=C3=A4rber?=" , Manivannan Sadhasivam , Maxime Coquelin , Alexandre Torgue , Caleb Biggers , Weilin Wang , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Perry Taylor , Thomas Falcon Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Separate the creation of the tpebs_retire_lat result out of the opening step. This is in preparation for adding a prepare operation for evlists. Signed-off-by: Ian Rogers Tested-by: Weilin Wang Acked-by: Namhyung Kim Reviewed-by: Kan Liang --- tools/perf/util/intel-tpebs.c | 133 ++++++++++++++++++++++------------ 1 file changed, 86 insertions(+), 47 deletions(-) diff --git a/tools/perf/util/intel-tpebs.c b/tools/perf/util/intel-tpebs.c index 566e0ddcad88..2186818b2c9b 100644 --- a/tools/perf/util/intel-tpebs.c +++ b/tools/perf/util/intel-tpebs.c @@ -37,7 +37,7 @@ static struct child_process tpebs_cmd; struct tpebs_retire_lat { struct list_head nd; /* Event name */ - const char *name; + char *name; /* Event name with the TPEBS modifier R */ const char *tpebs_name; /* Count of retire_latency values found in sample data */ @@ -190,6 +190,82 @@ static int tpebs_stop(void) return ret; } =20 +static char *evsel__tpebs_name(struct evsel *evsel) +{ + char *name, *modifier; + + name =3D strdup(evsel->name); + if (!name) + return NULL; + + modifier =3D strrchr(name, 'R'); + if (!modifier) { + pr_err("Tpebs event missing modifier '%s'\n", name); + free(name); + return NULL; + } + + *modifier =3D 'p'; + return name; +} + +static struct tpebs_retire_lat *tpebs_retire_lat__new(struct evsel *evsel) +{ + struct tpebs_retire_lat *result =3D zalloc(sizeof(*result)); + + if (!result) + return NULL; + + result->tpebs_name =3D evsel->name; + result->name =3D evsel__tpebs_name(evsel); + if (!result->name) { + free(result); + return NULL; + } + list_add_tail(&result->nd, &tpebs_results); + tpebs_event_size++; + return result; +} + +/** + * evsel__tpebs_prepare - create tpebs data structures ready for opening. + * @evsel: retire_latency evsel, all evsels on its list will be prepared. + */ +static int evsel__tpebs_prepare(struct evsel *evsel) +{ + struct evsel *pos; + struct tpebs_retire_lat *tpebs_event; + + list_for_each_entry(tpebs_event, &tpebs_results, nd) { + if (!strcmp(tpebs_event->tpebs_name, evsel->name)) { + /* + * evsel, or an identically named one, was already + * prepared. + */ + return 0; + } + } + tpebs_event =3D tpebs_retire_lat__new(evsel); + if (!tpebs_event) + return -ENOMEM; + + /* + * Eagerly prepare all other evsels on the list to try to ensure that by + * open they are all known. + */ + evlist__for_each_entry(evsel->evlist, pos) { + int ret; + + if (pos =3D=3D evsel || !pos->retire_lat) + continue; + + ret =3D evsel__tpebs_prepare(pos); + if (ret) + return ret; + } + return 0; +} + /** * evsel__tpebs_open - starts tpebs execution. * @evsel: retire_latency evsel, all evsels on its list will be selected. = Each @@ -197,10 +273,7 @@ static int tpebs_stop(void) */ int evsel__tpebs_open(struct evsel *evsel) { - int ret =3D 0; - struct evsel *pos; - struct evlist *evsel_list =3D evsel->evlist; - char cpumap_buf[50]; + int ret; =20 /* * We should only run tpebs_start when tpebs_recording is enabled. @@ -209,49 +282,13 @@ int evsel__tpebs_open(struct evsel *evsel) if (tpebs_cmd.pid !=3D 0 || !tpebs_recording) return 0; =20 - cpu_map__snprint(evsel_list->core.user_requested_cpus, cpumap_buf, sizeof= (cpumap_buf)); - /* - * Prepare perf record for sampling event retire_latency before fork and - * prepare workload - */ - evlist__for_each_entry(evsel_list, pos) { - int i; - char *name; - struct tpebs_retire_lat *new; - - if (!pos->retire_lat) - continue; - - pr_debug("tpebs: Retire_latency of event %s is required\n", pos->name); - for (i =3D strlen(pos->name) - 1; i > 0; i--) { - if (pos->name[i] =3D=3D 'R') - break; - } - if (i <=3D 0 || pos->name[i] !=3D 'R') { - ret =3D -1; - goto err; - } - - name =3D strdup(pos->name); - if (!name) { - ret =3D -ENOMEM; - goto err; - } - name[i] =3D 'p'; - - new =3D zalloc(sizeof(*new)); - if (!new) { - ret =3D -1; - zfree(&name); - goto err; - } - new->name =3D name; - new->tpebs_name =3D pos->name; - list_add_tail(&new->nd, &tpebs_results); - tpebs_event_size +=3D 1; - } + ret =3D evsel__tpebs_prepare(evsel); + if (ret) + return ret; =20 if (tpebs_event_size > 0) { + struct evlist *evsel_list =3D evsel->evlist; + char cpumap_buf[50]; struct pollfd pollfd =3D { .events =3D POLLIN, }; int control_fd[2], ack_fd[2], len; char ack_buf[8]; @@ -268,6 +305,9 @@ int evsel__tpebs_open(struct evsel *evsel) goto out; } =20 + cpu_map__snprint(evsel_list->core.user_requested_cpus, cpumap_buf, + sizeof(cpumap_buf)); + ret =3D start_perf_record(control_fd, ack_fd, cpumap_buf); if (ret) goto out; @@ -321,7 +361,6 @@ int evsel__tpebs_open(struct evsel *evsel) close(ack_fd[0]); close(ack_fd[1]); } -err: if (ret) tpebs_delete(); return ret; --=20 2.49.0.604.gff1f9ca942-goog From nobody Fri Dec 19 17:37:02 2025 Received: from mail-ot1-f73.google.com (mail-ot1-f73.google.com [209.85.210.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 514F028DEF6 for ; Mon, 14 Apr 2025 17:42:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744652527; cv=none; b=MFv4d4cCoaOL4p6P+BHfJVxKmtTxxOEkN4fwxD5qKhA7yqlOoX6rVQAB068TY2Lhfyb84WQ6/yQUdh++YfsIsltT3FyTR39AL+RSMp5zq1YseARoAFXJf2sQpxZXDz+aHSqOAhQSONcS0prnT0YFAoayod7+rSWlTUN6j8zMiCU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744652527; c=relaxed/simple; bh=DFjxBYDyDfEAtlYSsxu3IuiLYb25T54vCkre2zk9ReI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=A5BqghCtvZdwQWYKz6Htm/A6XpzpOmPUZeutIR23t7JDrhPFmTMLtNMvkh+NQCz3K64Tzk4t3/5eJOe4EtdxUTUMozDd548MA1idga1nt0OhZ5md2nOC7JZAGY5MlLDrps+PDjczblsiVZM+U1BrjzRC5Ocyq11WqZxi33mFoCg= 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=qQYeeKP6; arc=none smtp.client-ip=209.85.210.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="qQYeeKP6" Received: by mail-ot1-f73.google.com with SMTP id 46e09a7af769-72e313f527cso3990043a34.3 for ; Mon, 14 Apr 2025 10:42:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1744652525; x=1745257325; 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=/6B+tTNmgbE+npKfz9VIYvdTpAi1BUpsjCK1/o5jdOk=; b=qQYeeKP6DpOyQbZ8QhtwVOnZp0LLeWrDGMquyhR68bAt/5BHOBkrO2bvbrAjdIokVD GvKJnNolbR8okjvNH9A01mH2wggVsqRXKfYGYkBV7wutYWguAz9ZI9i1ebuedlmQCzhc 7bp0uUmEPRt/FryhIQPTC6ce6LiyWI5uTPg/YyOTOurlCvTfxTgpR5XSY+3siN1x2mAx qeJhvjpIauvDxNGlbdYfRTr0fT4kZyYt1s0RKT9ob+whyOn3PUquLeTzCFsyl6HHFwBj Z26hsYN9/Gf8GPg5RxukvssX3n9Q6ZOkGcIsHPtnUBvoNI3uOtjt11QKC4VsbPxwrWxy HCrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744652525; x=1745257325; 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=/6B+tTNmgbE+npKfz9VIYvdTpAi1BUpsjCK1/o5jdOk=; b=MNMD2FMCrPaZfBOUbd4T7etCtj8cOlPA3+70DtA6oIyJm+5EQOstGGZizICQKnuuvW Z2eZ9H/2IN41626AZIqyDeL8Ecss3Sq3ZRWG4Ojt5oyZdHZflmUBvi+YwQtKN4OzPUhH kZz8gB2HLlnKaTAmh4K+egv1K6DkrT42n3P7inPxtwfx8yHX0KCiMAeU++utz88ReqPg UTq5oD9U/+/wova0vV2hxWq7QteE7fBktHG2/PCcLbkpDW7CY7bXx5RPi/h41w2RvLei IRd+TvSozNiCSDEFYI281Tlpdw/hAqUO3BqHf4uK9dQdDGTuWGAs+zgzcvo8FgAcOsSQ piyg== X-Forwarded-Encrypted: i=1; AJvYcCWBV9X5iZTfrJORs6QjBalAy5lHSxlTYQKlVAuTk8qbr5Qi8u+iTWwdrclG0tFd6A2NeUdE13WDa9qnPcQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yx9OPrvwtaONt4MX4fJCzSes5uxmPUy0Aa5f68w8+28QkMeOyA4 f44O4fYeRybXzmU/MBbGGvfRm6sdyW2hjNdknZ0YEZZ7hQxsbdFGNa8NnvYb0/8dfqEOfkqham8 yOE240g== X-Google-Smtp-Source: AGHT+IFZfQRoFisi7/6v7utCC2NsJldmcEFv3ovdDOV3Vl+uF2EaQpByAfXxRfOr3QgYOXe434yeoSfClnHM X-Received: from oacoz11.prod.google.com ([2002:a05:6871:788b:b0:29d:f69c:1743]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6830:2aa5:b0:72b:8aec:fbd4 with SMTP id 46e09a7af769-72e862d8597mr9409860a34.3.1744652525506; Mon, 14 Apr 2025 10:42:05 -0700 (PDT) Date: Mon, 14 Apr 2025 10:41:23 -0700 In-Reply-To: <20250414174134.3095492-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: <20250414174134.3095492-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.604.gff1f9ca942-goog Message-ID: <20250414174134.3095492-6-irogers@google.com> Subject: [PATCH v5 05/16] perf intel-tpebs: Move cpumap_buf out of evsel__tpebs_open From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , "=?UTF-8?q?Andreas=20F=C3=A4rber?=" , Manivannan Sadhasivam , Maxime Coquelin , Alexandre Torgue , Caleb Biggers , Weilin Wang , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Perry Taylor , Thomas Falcon Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The buffer holds the cpumap to pass to the perf record command, so move it down to the perf record function. Make this function an evsel function given the need for the evsel for the cpumap. Signed-off-by: Ian Rogers Tested-by: Weilin Wang Acked-by: Namhyung Kim Reviewed-by: Kan Liang --- tools/perf/util/intel-tpebs.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/tools/perf/util/intel-tpebs.c b/tools/perf/util/intel-tpebs.c index 2186818b2c9b..2b04deaf66ff 100644 --- a/tools/perf/util/intel-tpebs.c +++ b/tools/perf/util/intel-tpebs.c @@ -83,12 +83,15 @@ static int get_perf_record_args(const char **record_arg= v, char buf[], return 0; } =20 -static int start_perf_record(int control_fd[], int ack_fd[], - const char *cpumap_buf) +static int evsel__tpebs_start_perf_record(struct evsel *evsel, int control= _fd[], int ack_fd[]) { const char **record_argv; int ret; char buf[32]; + char cpumap_buf[50]; + + cpu_map__snprint(evsel->evlist->core.user_requested_cpus, cpumap_buf, + sizeof(cpumap_buf)); =20 scnprintf(buf, sizeof(buf), "--control=3Dfd:%d,%d", control_fd[0], ack_fd= [1]); =20 @@ -287,8 +290,6 @@ int evsel__tpebs_open(struct evsel *evsel) return ret; =20 if (tpebs_event_size > 0) { - struct evlist *evsel_list =3D evsel->evlist; - char cpumap_buf[50]; struct pollfd pollfd =3D { .events =3D POLLIN, }; int control_fd[2], ack_fd[2], len; char ack_buf[8]; @@ -305,10 +306,7 @@ int evsel__tpebs_open(struct evsel *evsel) goto out; } =20 - cpu_map__snprint(evsel_list->core.user_requested_cpus, cpumap_buf, - sizeof(cpumap_buf)); - - ret =3D start_perf_record(control_fd, ack_fd, cpumap_buf); + ret =3D evsel__tpebs_start_perf_record(evsel, control_fd, ack_fd); if (ret) goto out; =20 --=20 2.49.0.604.gff1f9ca942-goog From nobody Fri Dec 19 17:37:02 2025 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 854BA28E5E6 for ; Mon, 14 Apr 2025 17:42:08 +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=1744652529; cv=none; b=l4KCDwL1LjOX6zzdrPtcV3GaybdsHbhZACnwGrXGECh81H4fUZ6L/UUINFOXgwreLSEaoqbDX/LMAFh19hw0Yio6aK93jMj7bZSoExkwT0lDxd/AtueHtzgSD3M2jc3mn0BkpiiuwYDhwr77CaeSQMWjbLyD1IRbATRVsLzSrds= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744652529; c=relaxed/simple; bh=w1EZ7SZI9fDDkdvQk8qfQctTw0UoNSKrjDMhX8UQJ6o=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=o6Zvr1hMnvj9ji1RwsJmN0Ckg7NsBgUKvKTnBQuycJsDg2Uz9FDkK6i1fO4sFusXOv+g1G5Z6zB+Ya+eQxwUgqJ3nqrn/Y8dCShe9RJWvvyaVeF1xPy3NZhG4/PW+mrixvjequn+zlugrlV8tAJbz6p6vUn7wc8QxPL5hZgpEfk= 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=HKAMQk6u; 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="HKAMQk6u" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-3032ea03448so4255951a91.2 for ; Mon, 14 Apr 2025 10:42:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1744652528; x=1745257328; 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=8Q/2QxvKgBwpNRidHntZVw+BDhIuLs7JcmHsBDszg6o=; b=HKAMQk6uyQ4d2hbT2CQGYw2EyU0nCaUcYQBim9slkRBiyV6TNDExb+7SEVCYVvOTid rz/t9N8Td5CvOqnIyWJNY8gBpq1j0NYOVkC3A3AOSFU4IsWi2QtLsFA7jhiFnyqoNML8 H6Le1WMmXfWJeuFM30bwOyeJtj2tatoIu9aiRaJoJQD2qP2GBdrcO7DB0SrTK3XzCluT CKBWGaRf0uMTwSpD8cj1IZyObrnadgnpX6iYQMRd+BxhONOlrV8NI4JmNo+5JnTyOo3r TDwdNizLtzh38/1lIjy6xh6l2AqcnpVP7u/948H8VouZPBL9TZ274rvJMvlcBHT99nue 3Mew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744652528; x=1745257328; 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=8Q/2QxvKgBwpNRidHntZVw+BDhIuLs7JcmHsBDszg6o=; b=UwDxcpSejWJASD0icRud0tt3bhXVBTHOeO0CTpsf+DBMW+x3UJAtfS7khqT+tH+cwY vJ6SVwaKLTqLgSUUlfw0Mi0Fc04cEygok0r2A72TnAbE/swYiOeVG7f5O27F8aJIymM2 8HUvzMqlU9XHbsaSkqH5e0lG6no+AH3q0tBUwl7T1eMX4yfRBmFD3mcxlqvJuoCV1Lqb ZEIpc9eKCRT0TZ2AtRY5uwbo01F7/hDt9pTGK4drrCN5wKnbZKGv/KfT+X4N8aDVDWKx TXOcdcISPpBMSIdPnvpUzueINgOcL2oZsvzIlVNYbJrLbzu/RK/GQZy+CTaLJDCpvaeQ iL4w== X-Forwarded-Encrypted: i=1; AJvYcCVqLduGf/FvGg2BHCoMU71yNKd754CKg5HIsi/Q0pHodh+tbegJ9O5QQRE+EwciFhwqz8eEJB8mxvMQFO8=@vger.kernel.org X-Gm-Message-State: AOJu0YwjJ/JoOgP4zHGD7aRPlAfiO5Din1DBaX3ExLA8t9ZHCXtopKV+ lgSg+EwhrnNdJ26W4exmWphiy+RR8V4BtUnq7wHHf1HsoOeuCv0GyTvXP5i/4gms16cvSvNWPas 47gu8+A== X-Google-Smtp-Source: AGHT+IHsX72kv7nW5H7UmGDIZduBS3wpm/m1tbynchBPRllDDYnQyo+nLM9To+gQafBY2Scul4pL3voAlg1B X-Received: from pjxx16.prod.google.com ([2002:a17:90b:58d0:b0:2e5:5ffc:1c36]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90a:e183:b0:2fa:15ab:4df5 with SMTP id 98e67ed59e1d1-308237c1177mr16263891a91.34.1744652527829; Mon, 14 Apr 2025 10:42:07 -0700 (PDT) Date: Mon, 14 Apr 2025 10:41:24 -0700 In-Reply-To: <20250414174134.3095492-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: <20250414174134.3095492-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.604.gff1f9ca942-goog Message-ID: <20250414174134.3095492-7-irogers@google.com> Subject: [PATCH v5 06/16] perf intel-tpebs: Reduce scope of tpebs_events_size From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , "=?UTF-8?q?Andreas=20F=C3=A4rber?=" , Manivannan Sadhasivam , Maxime Coquelin , Alexandre Torgue , Caleb Biggers , Weilin Wang , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Perry Taylor , Thomas Falcon Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Moved to record argument computation rather than being global. Signed-off-by: Ian Rogers Tested-by: Weilin Wang Acked-by: Namhyung Kim Reviewed-by: Kan Liang --- tools/perf/util/intel-tpebs.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tools/perf/util/intel-tpebs.c b/tools/perf/util/intel-tpebs.c index 2b04deaf66ff..e3bed86145b9 100644 --- a/tools/perf/util/intel-tpebs.c +++ b/tools/perf/util/intel-tpebs.c @@ -29,7 +29,6 @@ #define PERF_DATA "-" =20 bool tpebs_recording; -static size_t tpebs_event_size; static LIST_HEAD(tpebs_results); static pthread_t tpebs_reader_thread; static struct child_process tpebs_cmd; @@ -86,15 +85,20 @@ static int get_perf_record_args(const char **record_arg= v, char buf[], static int evsel__tpebs_start_perf_record(struct evsel *evsel, int control= _fd[], int ack_fd[]) { const char **record_argv; + size_t tpebs_event_size =3D 0; int ret; char buf[32]; char cpumap_buf[50]; + struct tpebs_retire_lat *t; =20 cpu_map__snprint(evsel->evlist->core.user_requested_cpus, cpumap_buf, sizeof(cpumap_buf)); =20 scnprintf(buf, sizeof(buf), "--control=3Dfd:%d,%d", control_fd[0], ack_fd= [1]); =20 + list_for_each_entry(t, &tpebs_results, nd) + tpebs_event_size++; + record_argv =3D calloc(12 + 2 * tpebs_event_size, sizeof(char *)); if (!record_argv) return -ENOMEM; @@ -226,7 +230,6 @@ static struct tpebs_retire_lat *tpebs_retire_lat__new(s= truct evsel *evsel) return NULL; } list_add_tail(&result->nd, &tpebs_results); - tpebs_event_size++; return result; } =20 @@ -289,7 +292,7 @@ int evsel__tpebs_open(struct evsel *evsel) if (ret) return ret; =20 - if (tpebs_event_size > 0) { + if (!list_empty(&tpebs_results)) { struct pollfd pollfd =3D { .events =3D POLLIN, }; int control_fd[2], ack_fd[2], len; char ack_buf[8]; --=20 2.49.0.604.gff1f9ca942-goog From nobody Fri Dec 19 17:37:02 2025 Received: from mail-oi1-f202.google.com (mail-oi1-f202.google.com [209.85.167.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 A739028E60E for ; Mon, 14 Apr 2025 17:42:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744652532; cv=none; b=YHqn0Fr6MIWbMCRMefxrGoIM9i6WXGfwkgEQNlGIUhpWNKsug8jmI8zq78sopaUZeFl2rtzI6WGEgX4tVva9o+iZwYmFmHLSHZrU7jrUqDmMqB97Okiok9nXcxS4ee01m1sbp9uPIIMHrOa11+Z+mDmzxCGoIl/MnjCaOFT6jVA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744652532; c=relaxed/simple; bh=R62rwMee94H0rnPIOO0lHetf2H/4+Du7n6a2l3MvTjI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=CLcIlmVafGMHsbJZkOvi8/Fsanlb0xO4jL6O0moDcoz44y/3xfD9xkwABMjLcPg1DlYAy/W+qfT8aIAgcKW9vcUjoG9pGEc/UmIMDgQSSim2Dt+Qx8DGyDBoPZFkE+Wojff4HlVkwNs/Mrzhb3MgLhrsAeS1QoJ6EE7gPMfOTmg= 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=CwwyyVNB; arc=none smtp.client-ip=209.85.167.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="CwwyyVNB" Received: by mail-oi1-f202.google.com with SMTP id 5614622812f47-3ff0944ab23so3554999b6e.2 for ; Mon, 14 Apr 2025 10:42:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1744652530; x=1745257330; 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=ZTJEV/tjpAK53HcSV+hpcQMNf976ySouQHMzXMjrJnQ=; b=CwwyyVNBZgkVuv5aeEZVM9kJuwZZ7eu1jVxJBGpBFnlLYFe2LWfd0LQ1t53e3EMJZe qm6IU02AZInq7gNa3sv/wl4F58y3QSICt5z0L8snL5MEZWBOlOd/m7quR845Y5dxL1iB cRA+bJ23rdh4w3mOV5NJ9UYSr2bEJgiT0N7CNI3vw7ZsTJR/jWgBZZMNFFVHTMp0+AE2 6L6vyBL+8cI98sauMxUwq51pH4xHZs+EH4ePXn3qDxwaEPS61Whn3M6H6E4R3+5cIG/q 4XeCChkdEdWenWqJhplyJ8wqjRcEV+ZUIQBPPYCnqVR37bYwrL785xA5IrOE7TTmFDHN jw0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744652530; x=1745257330; 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=ZTJEV/tjpAK53HcSV+hpcQMNf976ySouQHMzXMjrJnQ=; b=lauR8pT0Ndv5HlUf9A+WiJBHU4nWXXJCs9MEv0BRfoK/Wl7i5Lqsy8fvqtNv1iQw1q e5A8qzJer8N4mQKKlbaM0VsaqyU0RebEhJz4+CCqtz3hxhXQL/Z2MixMzh3gSpg6C+GV flgWFK3IuUKKVj/Cot+cDDnVj+KC2pWyrsz65Bvo1uopAG77b8PNBp+4fVWFJSQ0Zc5M X/67Wk9hbLMXCbEc87U09oFfO11QLOvC+cqfoXh6DsveRSju9RKAk7jVqeik/mKGgOl7 bU0qI7dFrYftnfcA8Z8t/ptw/af1qNZwAzLMp9laeQggbTTd6J7BpP61KkKaDr4/SPlV 9IeQ== X-Forwarded-Encrypted: i=1; AJvYcCXW1xNA88m+GIjdSrxia3xr4ZjH/nOridYj/BsqyTuL3K9TlRIx5Up9sMevBtCyL4Zs+VwTEMEmXnQUDrA=@vger.kernel.org X-Gm-Message-State: AOJu0YwY4DC2znThxdvxuf3Fmn6QOPukQLStbiHt6dOZfY1snwnWAdQX iZBFHJ5lSMhk41JbHwgymppmrudpS5vzn+cc1oT9dBUYs1Ar6llZbeXIHiGapTQDzpmhBwHOBD6 /ScfMug== X-Google-Smtp-Source: AGHT+IH+UMuFH9H0s3bHooULbZSWFshQucW+flyS9sfdNKc8Btka99t1duhHoCLHChL1OaTuf7tcOHadbuE6 X-Received: from oabuu9.prod.google.com ([2002:a05:6870:ae09:b0:2c2:5b99:3e17]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6808:19a5:b0:3f6:abec:2ba4 with SMTP id 5614622812f47-40085089067mr9037803b6e.23.1744652529815; Mon, 14 Apr 2025 10:42:09 -0700 (PDT) Date: Mon, 14 Apr 2025 10:41:25 -0700 In-Reply-To: <20250414174134.3095492-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: <20250414174134.3095492-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.604.gff1f9ca942-goog Message-ID: <20250414174134.3095492-8-irogers@google.com> Subject: [PATCH v5 07/16] perf intel-tpebs: Inline get_perf_record_args From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , "=?UTF-8?q?Andreas=20F=C3=A4rber?=" , Manivannan Sadhasivam , Maxime Coquelin , Alexandre Torgue , Caleb Biggers , Weilin Wang , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Perry Taylor , Thomas Falcon Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Code is short enough to be inlined and there are no error cases when made inline. Make the implicit NULL pointer at the end of the argv explicit. Move the fixed number of arguments before the variable number of arguments. Correctly size the argv allocation and zero when feeing to avoid a dangling pointer. Signed-off-by: Ian Rogers Tested-by: Weilin Wang Acked-by: Namhyung Kim Reviewed-by: Kan Liang --- tools/perf/util/intel-tpebs.c | 75 +++++++++++++---------------------- 1 file changed, 28 insertions(+), 47 deletions(-) diff --git a/tools/perf/util/intel-tpebs.c b/tools/perf/util/intel-tpebs.c index e3bed86145b9..c4c818f32239 100644 --- a/tools/perf/util/intel-tpebs.c +++ b/tools/perf/util/intel-tpebs.c @@ -47,72 +47,53 @@ struct tpebs_retire_lat { double val; }; =20 -static int get_perf_record_args(const char **record_argv, char buf[], - const char *cpumap_buf) +static int evsel__tpebs_start_perf_record(struct evsel *evsel, int control= _fd[], int ack_fd[]) { - struct tpebs_retire_lat *e; - int i =3D 0; + const char **record_argv; + int tpebs_event_size =3D 0, i =3D 0, ret; + char control_fd_buf[32]; + char cpumap_buf[50]; + struct tpebs_retire_lat *t; + + list_for_each_entry(t, &tpebs_results, nd) + tpebs_event_size++; =20 - pr_debug("tpebs: Prepare perf record for retire_latency\n"); + record_argv =3D malloc((10 + 2 * tpebs_event_size) * sizeof(*record_argv)= ); + if (!record_argv) + return -ENOMEM; =20 record_argv[i++] =3D "perf"; record_argv[i++] =3D "record"; record_argv[i++] =3D "-W"; record_argv[i++] =3D "--synth=3Dno"; - record_argv[i++] =3D buf; =20 - if (!cpumap_buf) { - pr_err("tpebs: Require cpumap list to run sampling\n"); - return -ECANCELED; - } - /* Use -C when cpumap_buf is not "-1" */ - if (strcmp(cpumap_buf, "-1")) { + scnprintf(control_fd_buf, sizeof(control_fd_buf), "--control=3Dfd:%d,%d", + control_fd[0], ack_fd[1]); + record_argv[i++] =3D control_fd_buf; + + record_argv[i++] =3D "-o"; + record_argv[i++] =3D PERF_DATA; + + if (!perf_cpu_map__is_any_cpu_or_is_empty(evsel->evlist->core.user_reques= ted_cpus)) { + cpu_map__snprint(evsel->evlist->core.user_requested_cpus, cpumap_buf, + sizeof(cpumap_buf)); record_argv[i++] =3D "-C"; record_argv[i++] =3D cpumap_buf; } =20 - list_for_each_entry(e, &tpebs_results, nd) { + list_for_each_entry(t, &tpebs_results, nd) { record_argv[i++] =3D "-e"; - record_argv[i++] =3D e->name; + record_argv[i++] =3D t->name; } - - record_argv[i++] =3D "-o"; - record_argv[i++] =3D PERF_DATA; - - return 0; -} - -static int evsel__tpebs_start_perf_record(struct evsel *evsel, int control= _fd[], int ack_fd[]) -{ - const char **record_argv; - size_t tpebs_event_size =3D 0; - int ret; - char buf[32]; - char cpumap_buf[50]; - struct tpebs_retire_lat *t; - - cpu_map__snprint(evsel->evlist->core.user_requested_cpus, cpumap_buf, - sizeof(cpumap_buf)); - - scnprintf(buf, sizeof(buf), "--control=3Dfd:%d,%d", control_fd[0], ack_fd= [1]); - - list_for_each_entry(t, &tpebs_results, nd) - tpebs_event_size++; - - record_argv =3D calloc(12 + 2 * tpebs_event_size, sizeof(char *)); - if (!record_argv) - return -ENOMEM; - - ret =3D get_perf_record_args(record_argv, buf, cpumap_buf); - if (ret) - goto out; + record_argv[i++] =3D NULL; + assert(i =3D=3D 10 + 2 * tpebs_event_size || i =3D=3D 8 + 2 * tpebs_event= _size); + /* Note, no workload given so system wide is implied. */ =20 assert(tpebs_cmd.pid =3D=3D 0); tpebs_cmd.argv =3D record_argv; tpebs_cmd.out =3D -1; ret =3D start_command(&tpebs_cmd); -out: - free(record_argv); + zfree(&tpebs_cmd.argv); return ret; } =20 --=20 2.49.0.604.gff1f9ca942-goog From nobody Fri Dec 19 17:37:02 2025 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 576E728F505 for ; Mon, 14 Apr 2025 17:42:12 +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=1744652534; cv=none; b=s0kcjqJ/lOWZxX+WGYk3ccqVyFkOUV+DIC3GC278xS76W4jALAmLq2U/6aPR7CvEoXlaMuwTindX+txqaIVZw1lO0198v5Jr2+rq1s/2iw9QPqbaeO6ryzqhEWvB+UiF58sKWkfs4nFu1iswqEJSNC+xv7eMW5uYpclcgqXi688= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744652534; c=relaxed/simple; bh=5clFH5cBbA9DkiIJRGFWXyQBekw3Gsouq1gTcIF6OIA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=ZsYbqS2QVM1FM09/2sH4u8VMEIX/YnaCPhh2n3WZMjnY+BYopmWWpLX2BU2HYdakceQnz63i/OGP/LMXPen3aT96dM/XTOAl6Oacd9Wg77+CS1q58uXppoGg5YVaJyaj2+w51M+KNx78PgfGyu7nVZZ1O+wIXmdShGFxWfOJvx4= 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=r8Aac6ut; 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="r8Aac6ut" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-224347aef79so61466865ad.2 for ; Mon, 14 Apr 2025 10:42:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1744652531; x=1745257331; 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=2H/tpH/91QrndnjLgNTFU53UhH+5V7b1PzR5S5R0EcM=; b=r8Aac6utzPDOKuLGbT0KWcn/7v919Tyt8kEfjkft3La72vw2HJlHQhlQlPUwYr+zp+ kXvE7ZInrur3GoBZ+ZKFC0e9ziqDNWpd4dDefFY7ge1nOanutzK/0n2Yml5dc3fZ0H3w aOEz0Pd4LUGCXpZWKu50zUzq3SRXIETN5zHyYYSX2V7Mmb1ofJqBGw6j3pvxYjDBJ9Fc L8x4DMgzXG9Qsu3vs9ewhA7URHh63vWwk2slQF7wiGTdGr+rENQdYD/HJV0kW1pmkWAb dWtkQXLEULooEUvIz+Znvt4zbAOxKZsgTpN8WGO4+VoQLfZvMoZX9wdCivDMAN41WveH 2/8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744652531; x=1745257331; 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=2H/tpH/91QrndnjLgNTFU53UhH+5V7b1PzR5S5R0EcM=; b=hYrdJXM3VarJwoQziZSR12MYffiJA4tPHXJ7C8G/K3OV7hV3oqW2qz5oxkSAUrMl2G BvQ+4+6UAqKumDbRBM0l5LdJnRkJF8kpVSNlEU5UwP2tmTCIwTZ/mjgxCnZ4VraHoBLY efwTBc7+93zMTv9QetulCNA/liD66V5Mk3GOP2dGXCnsALKm8Z5gOCihGH5xOopcKdTz HbuuFYpDB/jaR/miBTZteCT0d35WNDvL8n8V94/wmPqMAfRpx5raDSNA7muM503zj/Im hf2ujyQQkGu9JiiZXqeehD94vhNp6KrDEVFattbi2D4jXV3dw33ob4Kuxig9mQzrPeSa GAPg== X-Forwarded-Encrypted: i=1; AJvYcCWcW78g6bKsbqdk97IowqS2XlA+oIphNonFaO9QVyay1m+f8llHD4cTqBKROJfdco22YxjSv37poNEyhcE=@vger.kernel.org X-Gm-Message-State: AOJu0YypzpYlIb7bsuUiw4ht7R47bCq/af/libmcDW6bYR6u/Ss8yxLF CSp9uJ3oWH1MtmRdKgHOwMRJU0u3dautWxA4tEa7TU2JytIgxMgFAQwFcu8NpLgyBMFCiUOzBtX kXuITOw== X-Google-Smtp-Source: AGHT+IGxaixyz+5/bRId9UGgT/WpZ2tOtE4HFXXb6ZT+XhmhnXMMxhswPag0zV/Fr6Kb+wIMZNm0WsyOIfnb X-Received: from plbba6.prod.google.com ([2002:a17:902:7206:b0:21f:b748:a1c8]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:e54b:b0:224:24d3:6103 with SMTP id d9443c01a7336-22bea4efe70mr190994685ad.35.1744652531685; Mon, 14 Apr 2025 10:42:11 -0700 (PDT) Date: Mon, 14 Apr 2025 10:41:26 -0700 In-Reply-To: <20250414174134.3095492-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: <20250414174134.3095492-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.604.gff1f9ca942-goog Message-ID: <20250414174134.3095492-9-irogers@google.com> Subject: [PATCH v5 08/16] perf intel-tpebs: Ensure events are opened, factor out finding From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , "=?UTF-8?q?Andreas=20F=C3=A4rber?=" , Manivannan Sadhasivam , Maxime Coquelin , Alexandre Torgue , Caleb Biggers , Weilin Wang , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Perry Taylor , Thomas Falcon Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Factor out finding an tpebs_retire_lat from an evsel. Don't blindly return when ignoring an open request, which happens after the first open request, ensure the event was started on a fork of perf record. Signed-off-by: Ian Rogers Tested-by: Weilin Wang Acked-by: Namhyung Kim Reviewed-by: Kan Liang --- tools/perf/util/intel-tpebs.c | 61 +++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 24 deletions(-) diff --git a/tools/perf/util/intel-tpebs.c b/tools/perf/util/intel-tpebs.c index c4c818f32239..e42f3ec39a64 100644 --- a/tools/perf/util/intel-tpebs.c +++ b/tools/perf/util/intel-tpebs.c @@ -45,6 +45,8 @@ struct tpebs_retire_lat { int sum; /* Average of retire_latency, val =3D sum / count */ double val; + /* Has the event been sent to perf record? */ + bool started; }; =20 static int evsel__tpebs_start_perf_record(struct evsel *evsel, int control= _fd[], int ack_fd[]) @@ -94,6 +96,9 @@ static int evsel__tpebs_start_perf_record(struct evsel *e= vsel, int control_fd[], tpebs_cmd.out =3D -1; ret =3D start_command(&tpebs_cmd); zfree(&tpebs_cmd.argv); + list_for_each_entry(t, &tpebs_results, nd) + t->started =3D true; + return ret; } =20 @@ -214,6 +219,19 @@ static struct tpebs_retire_lat *tpebs_retire_lat__new(= struct evsel *evsel) return result; } =20 +static struct tpebs_retire_lat *tpebs_retire_lat__find(struct evsel *evsel) +{ + struct tpebs_retire_lat *t; + + list_for_each_entry(t, &tpebs_results, nd) { + if (t->tpebs_name =3D=3D evsel->name || + !strcmp(t->tpebs_name, evsel->name) || + (evsel->metric_id && !strcmp(t->tpebs_name, evsel->metric_id))) + return t; + } + return NULL; +} + /** * evsel__tpebs_prepare - create tpebs data structures ready for opening. * @evsel: retire_latency evsel, all evsels on its list will be prepared. @@ -221,16 +239,11 @@ static struct tpebs_retire_lat *tpebs_retire_lat__new= (struct evsel *evsel) static int evsel__tpebs_prepare(struct evsel *evsel) { struct evsel *pos; - struct tpebs_retire_lat *tpebs_event; - - list_for_each_entry(tpebs_event, &tpebs_results, nd) { - if (!strcmp(tpebs_event->tpebs_name, evsel->name)) { - /* - * evsel, or an identically named one, was already - * prepared. - */ - return 0; - } + struct tpebs_retire_lat *tpebs_event =3D tpebs_retire_lat__find(evsel); + + if (tpebs_event) { + /* evsel, or an identically named one, was already prepared. */ + return 0; } tpebs_event =3D tpebs_retire_lat__new(evsel); if (!tpebs_event) @@ -262,12 +275,19 @@ int evsel__tpebs_open(struct evsel *evsel) { int ret; =20 - /* - * We should only run tpebs_start when tpebs_recording is enabled. - * And we should only run it once with all the required events. - */ - if (tpebs_cmd.pid !=3D 0 || !tpebs_recording) + /* We should only run tpebs_start when tpebs_recording is enabled. */ + if (!tpebs_recording) return 0; + /* Only start the events once. */ + if (tpebs_cmd.pid !=3D 0) { + struct tpebs_retire_lat *t =3D tpebs_retire_lat__find(evsel); + + if (!t || !t->started) { + /* Fail, as the event wasn't started. */ + return -EBUSY; + } + return 0; + } =20 ret =3D evsel__tpebs_prepare(evsel); if (ret) @@ -352,7 +372,6 @@ int evsel__tpebs_open(struct evsel *evsel) int tpebs_set_evsel(struct evsel *evsel, int cpu_map_idx, int thread) { __u64 val; - bool found =3D false; struct tpebs_retire_lat *t; struct perf_counts_values *count; =20 @@ -367,19 +386,13 @@ int tpebs_set_evsel(struct evsel *evsel, int cpu_map_= idx, int thread) tpebs_stop(); count =3D perf_counts(evsel->counts, cpu_map_idx, thread); =20 - list_for_each_entry(t, &tpebs_results, nd) { - if (t->tpebs_name =3D=3D evsel->name || - (evsel->metric_id && !strcmp(t->tpebs_name, evsel->metric_id))) { - found =3D true; - break; - } - } + t =3D tpebs_retire_lat__find(evsel); =20 /* Set ena and run to non-zero */ count->ena =3D count->run =3D 1; count->lost =3D 0; =20 - if (!found) { + if (!t) { /* * Set default value or 0 when retire_latency for this event is * not found from sampling data (record_tpebs not set or 0 --=20 2.49.0.604.gff1f9ca942-goog From nobody Fri Dec 19 17:37:02 2025 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 882FE28B4E5 for ; Mon, 14 Apr 2025 17:42:14 +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=1744652536; cv=none; b=HpFeiy5hf183UOD+Fng+unGbBgHSNddlqBJq7xnWkdpSx+WkzUEbqoBPbSsUqT0sBckyFnh7qMwKFIwyQq6i39rrlVw50V76E7OMgIcCl9NLtfz1Aw2nGOKMaPKukTOtVc5I6QKE6mgkGRuUmq0Kgo/z38rEt/WH/djr7EJ6x9k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744652536; c=relaxed/simple; bh=Ardu5Zto369kK4zW/dNPurCFIiVTURm10s2RGR0ve7o=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=PLoTgz7qARZToUOSx7fS5obrbgD5FLAP5EcgiB4awuo4NxHIKU4cQS/dH4EBbR58ixkt6ma/hnjM3tPwqOUI/gD3fEBVhZDVn/ww3wA1OyeieuiRkdl2K0iStvaswCcdcvIXdQzgLs+BU4lTNp/KfxxDh+yGKcGK2SeHdPz596U= 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=OUOdqRMl; 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="OUOdqRMl" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-227ed471999so39953515ad.3 for ; Mon, 14 Apr 2025 10:42:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1744652533; x=1745257333; 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=uWCJjFZOu/EVf/VdW/8Vm5rWlieUQQLXgc9oCiiDvVY=; b=OUOdqRMlMhqtd2V+QMPRXUNGPqR9Ypw/7xAD/fMQJL865ECPLnxv0UQQTNn8ALynfg k0yx1L8b7lSgou9D1UbOZMc/7vxloUCAvbb9N4IFBwOK7yvhIeqdxyPV0NOLzX711+V7 R15DtRmd6mA/TCLV9pSpbudVJkX+T0djLSBvid3SsVt1hIwMHgY4TXQwxqhAVMgnuAgc 4ymZCMvlqKuIswfj/4NjBHa+/ZyOGfQsVzS/rjDpNqj7quUt46bza8LM5/G7x0prlUxl DoJLqksfQ7GMTImqDbflSgzNC8y2YTKQ+ietwnOLmyVkLwWmVVKvAxntk6iewqHwdQKW h91Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744652533; x=1745257333; 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=uWCJjFZOu/EVf/VdW/8Vm5rWlieUQQLXgc9oCiiDvVY=; b=lvkhec1bjiuiEAEcsVESEZzu6G2BronPFRxR2GovOpUgZtr1K9cXW6/rV5Qh8ePEwZ e8OiWnhY2GRG/0WPJnjvVL8WQ0Ov4E64d6FQ3S2Cnw86/WzpwXhQnzAFzE/jIaMEXPOm MaxKHvhqKO3VIHpL2o6wPZ+vXZP4gtmVGfMixaF4hhrxv1KKGm6SIlq0uLSipyUD+U+8 bJims678OM4UI8FPVWtOotDZcqyi9cbzTv7pr3NjXK/S7wdzC6dhnq5cQ7R2Evt2KW8I YkL6ISfrka1toIA0uibq99ef3epF7aF+Xp2E8CNqYFnU5cYORZqD/Cto2tFuAyjjedwX aYMQ== X-Forwarded-Encrypted: i=1; AJvYcCWR4vn4rJLjp+oI8w4EPUeopvB9Qydb4U3bV3LMuLRd8qtVULtBqFYJYwzgshdCJKk/1maZQRDZkdbi7l8=@vger.kernel.org X-Gm-Message-State: AOJu0Yy7WDi1CeP+zn6vhHncmazxZyOLy2Z3NX+wD+eBc0eCL/BobH3n 4YCyHPRb4mFSsZ9eNSyh3N8qV01hqZ3+9lbk4Ozxu64ZoNuTxi9cYkk0YStXaLQSimG3pEY72at Ykr9y6g== X-Google-Smtp-Source: AGHT+IG8dNrboCUfG+ZW8OqTLUhYiuQzZKuXDCNhKV/lf7U+k/W/b7E1OBBuHlvpn6ZP9CZcdt6kK0X9ke97 X-Received: from plhb12.prod.google.com ([2002:a17:903:228c:b0:223:5739:92d]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:daca:b0:223:5e6a:57ab with SMTP id d9443c01a7336-22bea4efe4dmr194271195ad.39.1744652533627; Mon, 14 Apr 2025 10:42:13 -0700 (PDT) Date: Mon, 14 Apr 2025 10:41:27 -0700 In-Reply-To: <20250414174134.3095492-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: <20250414174134.3095492-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.604.gff1f9ca942-goog Message-ID: <20250414174134.3095492-10-irogers@google.com> Subject: [PATCH v5 09/16] perf intel-tpebs: Refactor tpebs_results list From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , "=?UTF-8?q?Andreas=20F=C3=A4rber?=" , Manivannan Sadhasivam , Maxime Coquelin , Alexandre Torgue , Caleb Biggers , Weilin Wang , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Perry Taylor , Thomas Falcon Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" evsel names and metric-ids are used for matching but this can be problematic, for example, multiple occurrences of the same retirement latency event become a single event for the record. Change the name of the record events so they are unique and reflect the evsel of the retirement latency event that opens them (the retirement latency event's evsel address is embedded within them). This allows an evsel based close to close the event when the retirement latency event is closed. This is important as perf stat has an evlist and the session listen to the record events has an evlist, knowing which event should remove the tpebs_retire_lat can't be tied to an evlist list as there is more than 1, so closing which evlist should cause the tpebs to stop? Using the evsel and the last one out doing the tpebs_stop is cleaner. Signed-off-by: Ian Rogers Tested-by: Weilin Wang Acked-by: Namhyung Kim Reviewed-by: Kan Liang --- tools/perf/builtin-stat.c | 2 - tools/perf/util/evlist.c | 1 - tools/perf/util/evsel.c | 2 +- tools/perf/util/intel-tpebs.c | 150 +++++++++++++++++++++------------- tools/perf/util/intel-tpebs.h | 2 +- 5 files changed, 93 insertions(+), 64 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 68ea7589c143..80e491bd775b 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -681,8 +681,6 @@ static enum counter_recovery stat_handle_error(struct e= vsel *counter) if (child_pid !=3D -1) kill(child_pid, SIGTERM); =20 - tpebs_delete(); - return COUNTER_FATAL; } =20 diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index c1a04141aed0..0a21da4f990f 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -183,7 +183,6 @@ void evlist__delete(struct evlist *evlist) if (evlist =3D=3D NULL) return; =20 - tpebs_delete(); evlist__free_stats(evlist); evlist__munmap(evlist); evlist__close(evlist); diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 121283f2f382..554252ed1aab 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -2759,7 +2759,7 @@ int evsel__open(struct evsel *evsel, struct perf_cpu_= map *cpus, void evsel__close(struct evsel *evsel) { if (evsel__is_retire_lat(evsel)) - tpebs_delete(); + evsel__tpebs_close(evsel); perf_evsel__close(&evsel->core); perf_evsel__free_id(&evsel->core); } diff --git a/tools/perf/util/intel-tpebs.c b/tools/perf/util/intel-tpebs.c index e42f3ec39a64..a723687e67f6 100644 --- a/tools/perf/util/intel-tpebs.c +++ b/tools/perf/util/intel-tpebs.c @@ -35,10 +35,10 @@ static struct child_process tpebs_cmd; =20 struct tpebs_retire_lat { struct list_head nd; - /* Event name */ - char *name; - /* Event name with the TPEBS modifier R */ - const char *tpebs_name; + /** @evsel: The evsel that opened the retire_lat event. */ + struct evsel *evsel; + /** @event: Event passed to perf record. */ + char *event; /* Count of retire_latency values found in sample data */ size_t count; /* Sum of all the retire_latency values in sample data */ @@ -49,6 +49,8 @@ struct tpebs_retire_lat { bool started; }; =20 +static struct tpebs_retire_lat *tpebs_retire_lat__find(struct evsel *evsel= ); + static int evsel__tpebs_start_perf_record(struct evsel *evsel, int control= _fd[], int ack_fd[]) { const char **record_argv; @@ -85,7 +87,7 @@ static int evsel__tpebs_start_perf_record(struct evsel *e= vsel, int control_fd[], =20 list_for_each_entry(t, &tpebs_results, nd) { record_argv[i++] =3D "-e"; - record_argv[i++] =3D t->name; + record_argv[i++] =3D t->event; } record_argv[i++] =3D NULL; assert(i =3D=3D 10 + 2 * tpebs_event_size || i =3D=3D 8 + 2 * tpebs_event= _size); @@ -108,27 +110,20 @@ static int process_sample_event(const struct perf_too= l *tool __maybe_unused, struct evsel *evsel, struct machine *machine __maybe_unused) { - int ret =3D 0; - const char *evname; struct tpebs_retire_lat *t; =20 - evname =3D evsel__name(evsel); - + t =3D tpebs_retire_lat__find(evsel); + if (!t) + return -EINVAL; /* * Need to handle per core results? We are assuming average retire * latency value will be used. Save the number of samples and the sum of * retire latency value for each event. */ - list_for_each_entry(t, &tpebs_results, nd) { - if (!strcmp(evname, t->name)) { - t->count +=3D 1; - t->sum +=3D sample->retire_lat; - t->val =3D (double) t->sum / t->count; - break; - } - } - - return ret; + t->count +=3D 1; + t->sum +=3D sample->retire_lat; + t->val =3D (double) t->sum / t->count; + return 0; } =20 static int process_feature_event(struct perf_session *session, @@ -183,50 +178,98 @@ static int tpebs_stop(void) return ret; } =20 -static char *evsel__tpebs_name(struct evsel *evsel) +/** + * evsel__tpebs_event() - Create string event encoding to pass to `perf re= cord`. + */ +static int evsel__tpebs_event(struct evsel *evsel, char **event) { char *name, *modifier; + int ret; =20 name =3D strdup(evsel->name); if (!name) - return NULL; + return -ENOMEM; =20 modifier =3D strrchr(name, 'R'); if (!modifier) { - pr_err("Tpebs event missing modifier '%s'\n", name); - free(name); - return NULL; + ret =3D -EINVAL; + goto out; } - *modifier =3D 'p'; - return name; + modifier =3D strchr(name, ':'); + if (!modifier) + modifier =3D strrchr(name, '/'); + if (!modifier) { + ret =3D -EINVAL; + goto out; + } + *modifier =3D '\0'; + if (asprintf(event, "%s/name=3Dtpebs_event_%p/%s", name, evsel, modifier = + 1) > 0) + ret =3D 0; + else + ret =3D -ENOMEM; +out: + if (ret) + pr_err("Tpebs event modifier broken '%s'\n", evsel->name); + free(name); + return ret; } =20 static struct tpebs_retire_lat *tpebs_retire_lat__new(struct evsel *evsel) { struct tpebs_retire_lat *result =3D zalloc(sizeof(*result)); + int ret; =20 if (!result) return NULL; =20 - result->tpebs_name =3D evsel->name; - result->name =3D evsel__tpebs_name(evsel); - if (!result->name) { + ret =3D evsel__tpebs_event(evsel, &result->event); + if (ret) { free(result); return NULL; } + result->evsel =3D evsel; list_add_tail(&result->nd, &tpebs_results); return result; } =20 +static void tpebs_retire_lat__delete(struct tpebs_retire_lat *r) +{ + zfree(&r->event); + free(r); +} + static struct tpebs_retire_lat *tpebs_retire_lat__find(struct evsel *evsel) { struct tpebs_retire_lat *t; + uint64_t num; + const char *evsel_name; =20 + /* + * Evsels will match for evlist with the retirement latency event. The + * name with "tpebs_event_" prefix will be present on events being read + * from `perf record`. + */ + if (evsel__is_retire_lat(evsel)) { + list_for_each_entry(t, &tpebs_results, nd) { + if (t->evsel =3D=3D evsel) + return t; + } + return NULL; + } + evsel_name =3D strstr(evsel->name, "tpebs_event_"); + if (!evsel_name) { + /* Unexpected that the perf record should have other events. */ + return NULL; + } + errno =3D 0; + num =3D strtoull(evsel_name + 12, NULL, 16); + if (errno) { + pr_err("Bad evsel for tpebs find '%s'\n", evsel->name); + return NULL; + } list_for_each_entry(t, &tpebs_results, nd) { - if (t->tpebs_name =3D=3D evsel->name || - !strcmp(t->tpebs_name, evsel->name) || - (evsel->metric_id && !strcmp(t->tpebs_name, evsel->metric_id))) + if ((uint64_t)t->evsel =3D=3D num) return t; } return NULL; @@ -363,8 +406,12 @@ int evsel__tpebs_open(struct evsel *evsel) close(ack_fd[0]); close(ack_fd[1]); } - if (ret) - tpebs_delete(); + if (ret) { + struct tpebs_retire_lat *t =3D tpebs_retire_lat__find(evsel); + + list_del_init(&t->nd); + tpebs_retire_lat__delete(t); + } return ret; } =20 @@ -414,34 +461,19 @@ int tpebs_set_evsel(struct evsel *evsel, int cpu_map_= idx, int thread) return 0; } =20 -static void tpebs_retire_lat__delete(struct tpebs_retire_lat *r) -{ - zfree(&r->name); - free(r); -} - - -/* - * tpebs_delete - delete tpebs related data and stop the created thread and - * process by calling tpebs_stop(). - * - * This function is called from evlist_delete() and also from builtin-stat - * stat_handle_error(). If tpebs_start() is called from places other then = perf - * stat, need to ensure tpebs_delete() is also called to safely free mem a= nd - * close the data read thread and the forked perf record process. +/** + * evsel__tpebs_close() - delete tpebs related data. If the last event, st= op the + * created thread and process by calling tpebs_stop(). * - * This function is also called in evsel__close() to be symmetric with - * tpebs_start() being called in evsel__open(). We will update this call s= ite - * when move tpebs_start() to evlist level. + * This function is called in evsel__close() to be symmetric with + * evsel__tpebs_open() being called in evsel__open(). */ -void tpebs_delete(void) +void evsel__tpebs_close(struct evsel *evsel) { - struct tpebs_retire_lat *r, *rtmp; + struct tpebs_retire_lat *t =3D tpebs_retire_lat__find(evsel); =20 - tpebs_stop(); + tpebs_retire_lat__delete(t); =20 - list_for_each_entry_safe(r, rtmp, &tpebs_results, nd) { - list_del_init(&r->nd); - tpebs_retire_lat__delete(r); - } + if (list_empty(&tpebs_results)) + tpebs_stop(); } diff --git a/tools/perf/util/intel-tpebs.h b/tools/perf/util/intel-tpebs.h index cc98203719c8..5c671181ec60 100644 --- a/tools/perf/util/intel-tpebs.h +++ b/tools/perf/util/intel-tpebs.h @@ -11,7 +11,7 @@ struct evsel; extern bool tpebs_recording; =20 int evsel__tpebs_open(struct evsel *evsel); -void tpebs_delete(void); +void evsel__tpebs_close(struct evsel *evsel); int tpebs_set_evsel(struct evsel *evsel, int cpu_map_idx, int thread); =20 #endif /* __INTEL_TPEBS_H */ --=20 2.49.0.604.gff1f9ca942-goog From nobody Fri Dec 19 17:37:02 2025 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D3485290BC6 for ; Mon, 14 Apr 2025 17:42:15 +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=1744652537; cv=none; b=fp6tMyfsO1lOnaY2WOIKZFvuDdqMD2yMiQ5uvu6JrLMQkk3PfHGC6XptkY/ENFAgtAhx7NFcxgstxxcnQB5R560kn01Q+q8OYjfOVixnN1QklZHlER94Lpi4gYNBp1IHT9Nbz3Dovu2AKrlq0/l9SopRT+50hkJ+e+/d9wboQ2g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744652537; c=relaxed/simple; bh=MgG4bnT5Y/IoeACL6/FF7p03vqokpT32ooyjAmiA7KQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=ibp9QGcqYXX7TciAvSirZZ6dmlA2JAdYxrH5IhAkteXQdTDZl3OVjQ7HnC+yxNtLnb6/+lO6ZAgG0/GSeQO8QencrZqL5v9kKKKDXadWQ7FUXbJMpdwSHBG5WB5KYLBQekQRGUTyPLbkCDZOzQvHDgtv53tj0iDSDw6+3Nx7kwo= 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=nVUxIVoA; 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="nVUxIVoA" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-2254e500a73so33862395ad.0 for ; Mon, 14 Apr 2025 10:42:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1744652535; x=1745257335; 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=Vv8qTLQ3WWzCt/xaflHVEhOOne4O1wpQ1+AlCg4wrv0=; b=nVUxIVoALamMCHdbgj9aa7JF3cd+eLlJcOqJrXi4fmQhXufLxCxbvAH1IO5kSCsb5G OzIA09+CX9O1SalVbmoTxmvdILgpy7AN+tIOVXgAOtlvJiHo+zuVop1dR+olBrSAVvtO 9AT3gmt1/G96U4JqLn7It1kwROubXuRZWXdbVc+d3vouDQw9y8808hUpDaaTLSSB8Sbo 9+NSdB3BMD4GpAZo7QlAy84JCx5dp44txrC3gZLE1yXAoBoh6YvhMfnPvodc8v8ctwbL Ba/FE2x+Qx0ZltEOtha9iaumWGr58zOEo3mudOY490nd+HPS8JjgMBQsNc0lDmWr1nBv JBKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744652535; x=1745257335; 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=Vv8qTLQ3WWzCt/xaflHVEhOOne4O1wpQ1+AlCg4wrv0=; b=iWFE0bQFdeGJR3xrjwXA/GSGImEZPpdhknCzYPwm6vPKWcfoJiIDu+dvZ/8hGJ3g2S GPEjDDwaTyGWlD/T9Swjgq3F88iJbWzWsB39skh1z1bFi+WtzeMkP9MxfsAI1qx1cBnF DuzmtJHyKsJEjGVzrjiRwdOPp9NbG2wrvanjHVpoBMo28Jj7pssX0+RndDkORSpNkmBc PhZoWrgBiRfORxPc4rp8aoBdQvfdVDXyTViWJdkXCmkXHgY+gy+F/qjDyWB1H2BF3kXS mVJOSEys7kte92DaJ5aIDqLqcJv1oKTV9/EQSmqJMfknMbAm8Ws4BsIH67fDONNIh+P1 DoBg== X-Forwarded-Encrypted: i=1; AJvYcCX9qFbWsGtdNr9BkplHiBWv/e7xL7Kuhf3rBJoEV+OGSrNGTnali+1zcdhzhouYoEHXExTtDh+E1AphMBQ=@vger.kernel.org X-Gm-Message-State: AOJu0YzNw3i7uXtdM50udrzLsLcE1npFg/kNzAxSMnQSoBBVpwU7zePF AOqTlXWcd+w3QS7UG9xWvqWaE6nbTvpetfF+NUWBPIgZ+ZSzjRM2CXO9ngYqjMUCbmZ16Wo3U8H 69POcSw== X-Google-Smtp-Source: AGHT+IGPF0PMmdXij8fuZdV6Cs9uvdSOjaLLJifCXxrH0wvmcTSs20hI4FLmxC0qgXO/FnO1nhSJhEjWPXAS X-Received: from pldy12.prod.google.com ([2002:a17:902:cacc:b0:226:453a:f2db]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:f705:b0:220:e9ac:e746 with SMTP id d9443c01a7336-22bea4fdc7amr214690705ad.53.1744652535173; Mon, 14 Apr 2025 10:42:15 -0700 (PDT) Date: Mon, 14 Apr 2025 10:41:28 -0700 In-Reply-To: <20250414174134.3095492-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: <20250414174134.3095492-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.604.gff1f9ca942-goog Message-ID: <20250414174134.3095492-11-irogers@google.com> Subject: [PATCH v5 10/16] perf intel-tpebs: Add support for updating counts in evsel__tpebs_read From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , "=?UTF-8?q?Andreas=20F=C3=A4rber?=" , Manivannan Sadhasivam , Maxime Coquelin , Alexandre Torgue , Caleb Biggers , Weilin Wang , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Perry Taylor , Thomas Falcon Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Rename to reflect evsel argument and for consistency with other tpebs functions. Update count from prev_raw_counts when available. Eventually this will allow inteval mode support. Signed-off-by: Ian Rogers Tested-by: Weilin Wang Acked-by: Namhyung Kim Reviewed-by: Kan Liang --- tools/perf/util/evsel.c | 11 ++------ tools/perf/util/intel-tpebs.c | 52 ++++++++++++++--------------------- tools/perf/util/intel-tpebs.h | 2 +- 3 files changed, 25 insertions(+), 40 deletions(-) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 554252ed1aab..1d343f51225b 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1718,11 +1718,6 @@ static int evsel__read_one(struct evsel *evsel, int = cpu_map_idx, int thread) return perf_evsel__read(&evsel->core, cpu_map_idx, thread, count); } =20 -static int evsel__read_retire_lat(struct evsel *evsel, int cpu_map_idx, in= t thread) -{ - return tpebs_set_evsel(evsel, cpu_map_idx, thread); -} - static void evsel__set_count(struct evsel *counter, int cpu_map_idx, int t= hread, u64 val, u64 ena, u64 run, u64 lost) { @@ -1730,8 +1725,8 @@ static void evsel__set_count(struct evsel *counter, i= nt cpu_map_idx, int thread, =20 count =3D perf_counts(counter->counts, cpu_map_idx, thread); =20 - if (counter->retire_lat) { - evsel__read_retire_lat(counter, cpu_map_idx, thread); + if (evsel__is_retire_lat(counter)) { + evsel__tpebs_read(counter, cpu_map_idx, thread); perf_counts__set_loaded(counter->counts, cpu_map_idx, thread, true); return; } @@ -1889,7 +1884,7 @@ int evsel__read_counter(struct evsel *evsel, int cpu_= map_idx, int thread) return evsel__hwmon_pmu_read(evsel, cpu_map_idx, thread); =20 if (evsel__is_retire_lat(evsel)) - return evsel__read_retire_lat(evsel, cpu_map_idx, thread); + return evsel__tpebs_read(evsel, cpu_map_idx, thread); =20 if (evsel->core.attr.read_format & PERF_FORMAT_GROUP) return evsel__read_group(evsel, cpu_map_idx, thread); diff --git a/tools/perf/util/intel-tpebs.c b/tools/perf/util/intel-tpebs.c index a723687e67f6..f648fca17556 100644 --- a/tools/perf/util/intel-tpebs.c +++ b/tools/perf/util/intel-tpebs.c @@ -415,49 +415,39 @@ int evsel__tpebs_open(struct evsel *evsel) return ret; } =20 - -int tpebs_set_evsel(struct evsel *evsel, int cpu_map_idx, int thread) +int evsel__tpebs_read(struct evsel *evsel, int cpu_map_idx, int thread) { - __u64 val; + struct perf_counts_values *count, *old_count =3D NULL; struct tpebs_retire_lat *t; - struct perf_counts_values *count; + uint64_t val; + + /* Only set retire_latency value to the first CPU and thread. */ + if (cpu_map_idx !=3D 0 || thread !=3D 0) + return 0; + + if (evsel->prev_raw_counts) + old_count =3D perf_counts(evsel->prev_raw_counts, cpu_map_idx, thread); =20 - /* Non reitre_latency evsel should never enter this function. */ - if (!evsel__is_retire_lat(evsel)) - return -1; + count =3D perf_counts(evsel->counts, cpu_map_idx, thread); =20 /* * Need to stop the forked record to ensure get sampled data from the * PIPE to process and get non-zero retire_lat value for hybrid. */ tpebs_stop(); - count =3D perf_counts(evsel->counts, cpu_map_idx, thread); =20 t =3D tpebs_retire_lat__find(evsel); - - /* Set ena and run to non-zero */ - count->ena =3D count->run =3D 1; - count->lost =3D 0; - - if (!t) { - /* - * Set default value or 0 when retire_latency for this event is - * not found from sampling data (record_tpebs not set or 0 - * sample recorded). - */ - count->val =3D 0; - return 0; + val =3D rint(t->val); + + if (old_count) { + count->val =3D old_count->val + val; + count->run =3D old_count->run + 1; + count->ena =3D old_count->ena + 1; + } else { + count->val =3D val; + count->run++; + count->ena++; } - - /* - * Only set retire_latency value to the first CPU and thread. - */ - if (cpu_map_idx =3D=3D 0 && thread =3D=3D 0) - val =3D rint(t->val); - else - val =3D 0; - - count->val =3D val; return 0; } =20 diff --git a/tools/perf/util/intel-tpebs.h b/tools/perf/util/intel-tpebs.h index 5c671181ec60..218a82866cee 100644 --- a/tools/perf/util/intel-tpebs.h +++ b/tools/perf/util/intel-tpebs.h @@ -12,6 +12,6 @@ extern bool tpebs_recording; =20 int evsel__tpebs_open(struct evsel *evsel); void evsel__tpebs_close(struct evsel *evsel); -int tpebs_set_evsel(struct evsel *evsel, int cpu_map_idx, int thread); +int evsel__tpebs_read(struct evsel *evsel, int cpu_map_idx, int thread); =20 #endif /* __INTEL_TPEBS_H */ --=20 2.49.0.604.gff1f9ca942-goog From nobody Fri Dec 19 17:37:02 2025 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9B02429114D for ; Mon, 14 Apr 2025 17:42:17 +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=1744652539; cv=none; b=MNIlnhBN8mjCJlx0Xq36uQfx3cmpvg4F6MQ0SluVyGxB5wsmshRqfEsAGYzIBxkwqlzqkjPI0kX/ntIu2CODDUkTqYxFLH/rfpwC7+ju9DiTaZtfTmlH80dKTec9Uqv98Pkr4h55nbUa9eUPfLchoBUdvWG1PQCVzeUyJbfN9H0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744652539; c=relaxed/simple; bh=WKPQcboFiB+hGHxUYzO4w2ckiNZXOOLFUP7lGFlNwWY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=NZnB3GYzcnFpsqKZhRm7sIN5fUOCLkwpYHJUWfm0DdrEV13yYZyAjz563IJt3E3puWuqj/km9m6uDx5d6eZChfDk9DHoFUgeUZ4FklSld3qiJRxOm4LyImkqy5HsdjA76uWLu7psC+iji53R1e14a30PAq5gSjr6/yTX7rc91lw= 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=cveDsJxu; 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="cveDsJxu" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-2241e7e3addso39989205ad.1 for ; Mon, 14 Apr 2025 10:42:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1744652537; x=1745257337; 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=uYPEm9NL3VZPHY9E6/DgquYd8q3uRuheFZCN9+58cmE=; b=cveDsJxutt5Esx7vRc6ahsFtupQ1pLbf28taPIyCCU4ywMW2bO1h1eaEPFd+4rPxSo Wx7Nlie1VOATzUGTgf9jyrg+kU4h5F46P3UWq8uehPPr4hAI2Sm7QwLpUrfqo3D4Ao0V ygn4sU/5MOJTBnXdVascGSmMX/D1O2WrR8tyz7XyLmBxUK2wHoLFIn67zsV+D5Zu1gYW pwhaG9nzLv24Mq/Hc7VlJ0er6pgFyx1LLcAtFcYhUM/RNFEWHJQwTKMc+S7vhAPUuzwb azdO4/LMFf7978cnUyRzhni07H8GUMh57Pu//icpHe/nGtpE+uPbNmztGMNuWjaR4If1 kFCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744652537; x=1745257337; 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=uYPEm9NL3VZPHY9E6/DgquYd8q3uRuheFZCN9+58cmE=; b=CraZ6gY9/Zk0tfLmIFKGpfV6Czu+yQcjyTNzwUhUcNaYAt7t/GHclHETtRgMRePX7i f5R71dYyd88p9YFJCZwb2ZwefNSGdjsPHynWl5Vyfdqjf5No2gGXfUPFq2F2DV8T1bzR KUspTcWzunp1sc5ofOIk+EI9ZUFcLa8ISfw51YOeohs2isA3xZiTLpK/YJQ5cHBjrBmh aebVzKOFhO2CMjk1MOKQsu7IFnNUeygeJiqHHuczDp6vWYchayjEmpCTGZxy8R4/as5I EJmr+d1k89akTlewosv1VrABPY7EfEmzO+382m9PeLTbRzxlagab0TjwQ/41mKgWvBeT wfHA== X-Forwarded-Encrypted: i=1; AJvYcCU6hn5NHevUVVnxMO4bBrNXGxd/QAwaqfsVYVaFGfH/LISNHLJP7Bqr/B0Mz95p80MoONDoVvinhzChu1A=@vger.kernel.org X-Gm-Message-State: AOJu0Yy2iB2M/wdCBXnl6SznVZKVnlMnsJ78VgPRZ0ZDYiJInK2cDATA S65EPGfbodsU2uyGTrrvnvl7KURkQVokC6N1bAFm7U19qpqZG9vvZq7mwDhe1Fig5nMWk6WO64o mSW6FrA== X-Google-Smtp-Source: AGHT+IGyKIuM07n7cmrhe91nvxQ1s4pZVlktHt4FzYtDlOdKGZpHGdcVIsvx1wZO0pb66Pi24JVdJeZGgAqF X-Received: from plly18.prod.google.com ([2002:a17:902:7c92:b0:223:5c97:5c3c]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:1c7:b0:223:4537:65b1 with SMTP id d9443c01a7336-22bea4efec4mr187177005ad.36.1744652537178; Mon, 14 Apr 2025 10:42:17 -0700 (PDT) Date: Mon, 14 Apr 2025 10:41:29 -0700 In-Reply-To: <20250414174134.3095492-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: <20250414174134.3095492-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.604.gff1f9ca942-goog Message-ID: <20250414174134.3095492-12-irogers@google.com> Subject: [PATCH v5 11/16] perf intel-tpebs: Add mutex for tpebs_results From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , "=?UTF-8?q?Andreas=20F=C3=A4rber?=" , Manivannan Sadhasivam , Maxime Coquelin , Alexandre Torgue , Caleb Biggers , Weilin Wang , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Perry Taylor , Thomas Falcon Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Ensure sample reader isn't racing with events being added/removed. Signed-off-by: Ian Rogers Tested-by: Weilin Wang Acked-by: Namhyung Kim Reviewed-by: Kan Liang --- tools/perf/util/intel-tpebs.c | 54 +++++++++++++++++++++++++++++------ 1 file changed, 46 insertions(+), 8 deletions(-) diff --git a/tools/perf/util/intel-tpebs.c b/tools/perf/util/intel-tpebs.c index f648fca17556..aa6bcdf2bf6c 100644 --- a/tools/perf/util/intel-tpebs.c +++ b/tools/perf/util/intel-tpebs.c @@ -16,6 +16,7 @@ #include "debug.h" #include "evlist.h" #include "evsel.h" +#include "mutex.h" #include "session.h" #include "tool.h" #include "cpumap.h" @@ -32,6 +33,7 @@ bool tpebs_recording; static LIST_HEAD(tpebs_results); static pthread_t tpebs_reader_thread; static struct child_process tpebs_cmd; +static struct mutex tpebs_mtx; =20 struct tpebs_retire_lat { struct list_head nd; @@ -51,6 +53,19 @@ struct tpebs_retire_lat { =20 static struct tpebs_retire_lat *tpebs_retire_lat__find(struct evsel *evsel= ); =20 +static void tpebs_mtx_init(void) +{ + mutex_init(&tpebs_mtx); +} + +static struct mutex *tpebs_mtx_get(void) +{ + static pthread_once_t tpebs_mtx_once =3D PTHREAD_ONCE_INIT; + + pthread_once(&tpebs_mtx_once, tpebs_mtx_init); + return &tpebs_mtx; +} + static int evsel__tpebs_start_perf_record(struct evsel *evsel, int control= _fd[], int ack_fd[]) { const char **record_argv; @@ -59,13 +74,15 @@ static int evsel__tpebs_start_perf_record(struct evsel = *evsel, int control_fd[], char cpumap_buf[50]; struct tpebs_retire_lat *t; =20 + mutex_lock(tpebs_mtx_get()); list_for_each_entry(t, &tpebs_results, nd) tpebs_event_size++; =20 record_argv =3D malloc((10 + 2 * tpebs_event_size) * sizeof(*record_argv)= ); - if (!record_argv) + if (!record_argv) { + mutex_unlock(tpebs_mtx_get()); return -ENOMEM; - + } record_argv[i++] =3D "perf"; record_argv[i++] =3D "record"; record_argv[i++] =3D "-W"; @@ -101,6 +118,7 @@ static int evsel__tpebs_start_perf_record(struct evsel = *evsel, int control_fd[], list_for_each_entry(t, &tpebs_results, nd) t->started =3D true; =20 + mutex_unlock(tpebs_mtx_get()); return ret; } =20 @@ -112,9 +130,12 @@ static int process_sample_event(const struct perf_tool= *tool __maybe_unused, { struct tpebs_retire_lat *t; =20 + mutex_lock(tpebs_mtx_get()); t =3D tpebs_retire_lat__find(evsel); - if (!t) + if (!t) { + mutex_unlock(tpebs_mtx_get()); return -EINVAL; + } /* * Need to handle per core results? We are assuming average retire * latency value will be used. Save the number of samples and the sum of @@ -123,6 +144,7 @@ static int process_sample_event(const struct perf_tool = *tool __maybe_unused, t->count +=3D 1; t->sum +=3D sample->retire_lat; t->val =3D (double) t->sum / t->count; + mutex_unlock(tpebs_mtx_get()); return 0; } =20 @@ -229,7 +251,6 @@ static struct tpebs_retire_lat *tpebs_retire_lat__new(s= truct evsel *evsel) return NULL; } result->evsel =3D evsel; - list_add_tail(&result->nd, &tpebs_results); return result; } =20 @@ -282,15 +303,22 @@ static struct tpebs_retire_lat *tpebs_retire_lat__fin= d(struct evsel *evsel) static int evsel__tpebs_prepare(struct evsel *evsel) { struct evsel *pos; - struct tpebs_retire_lat *tpebs_event =3D tpebs_retire_lat__find(evsel); + struct tpebs_retire_lat *tpebs_event; =20 + mutex_lock(tpebs_mtx_get()); + tpebs_event =3D tpebs_retire_lat__find(evsel); if (tpebs_event) { /* evsel, or an identically named one, was already prepared. */ + mutex_unlock(tpebs_mtx_get()); return 0; } tpebs_event =3D tpebs_retire_lat__new(evsel); - if (!tpebs_event) + if (!tpebs_event) { + mutex_unlock(tpebs_mtx_get()); return -ENOMEM; + } + list_add_tail(&tpebs_event->nd, &tpebs_results); + mutex_unlock(tpebs_mtx_get()); =20 /* * Eagerly prepare all other evsels on the list to try to ensure that by @@ -317,6 +345,7 @@ static int evsel__tpebs_prepare(struct evsel *evsel) int evsel__tpebs_open(struct evsel *evsel) { int ret; + bool tpebs_empty; =20 /* We should only run tpebs_start when tpebs_recording is enabled. */ if (!tpebs_recording) @@ -336,7 +365,10 @@ int evsel__tpebs_open(struct evsel *evsel) if (ret) return ret; =20 - if (!list_empty(&tpebs_results)) { + mutex_lock(tpebs_mtx_get()); + tpebs_empty =3D list_empty(&tpebs_results); + mutex_unlock(tpebs_mtx_get()); + if (!tpebs_empty) { struct pollfd pollfd =3D { .events =3D POLLIN, }; int control_fd[2], ack_fd[2], len; char ack_buf[8]; @@ -436,8 +468,10 @@ int evsel__tpebs_read(struct evsel *evsel, int cpu_map= _idx, int thread) */ tpebs_stop(); =20 + mutex_lock(tpebs_mtx_get()); t =3D tpebs_retire_lat__find(evsel); val =3D rint(t->val); + mutex_unlock(tpebs_mtx_get()); =20 if (old_count) { count->val =3D old_count->val + val; @@ -460,9 +494,13 @@ int evsel__tpebs_read(struct evsel *evsel, int cpu_map= _idx, int thread) */ void evsel__tpebs_close(struct evsel *evsel) { - struct tpebs_retire_lat *t =3D tpebs_retire_lat__find(evsel); + struct tpebs_retire_lat *t; =20 + mutex_lock(tpebs_mtx_get()); + t =3D tpebs_retire_lat__find(evsel); + list_del_init(&t->nd); tpebs_retire_lat__delete(t); + mutex_unlock(tpebs_mtx_get()); =20 if (list_empty(&tpebs_results)) tpebs_stop(); --=20 2.49.0.604.gff1f9ca942-goog From nobody Fri Dec 19 17:37:02 2025 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2DA0E291174 for ; Mon, 14 Apr 2025 17:42:19 +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=1744652543; cv=none; b=pFA0it0oiO8Iib5TkVWEhem8pN0oHsx8Z7YAjEELqOiO/JJji9sWolw0WAGpJ2hApWwpURpmsnIY9EfbZ1z3vGt7lp66MrIQgHy5OhAZzjHN9vvqDGyNMtEXyI8K1JHyIgp5rGTMw55Ormjr0EEo2ztMs33g8vL/kZvRxJePf0s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744652543; c=relaxed/simple; bh=/n1D0aH+aEk2XO0eFvDbfFi5XFTjuCJOPuFxCOifGAo=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=Bix4FN0XxXaCgjzYsO2pl9Umny8NmXoKi33v6ULUd1KZSbx96tnTMkHgmwr33OItNckN1LFFox2KE+wfboV15Ij1pMlagc9/E/f6hvmRfdwaRxnykPuT8MJuIP6drj7kFnaWprN6wzfQXK5I8OvN6AXsmhkFF/RbfUGTaNT7dtY= 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=ULy+HraF; 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="ULy+HraF" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-2ff8340d547so4156412a91.2 for ; Mon, 14 Apr 2025 10:42:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1744652539; x=1745257339; 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=+v5/q5rPSGglKhge482QHSxn0kDSG2APb/UlulErBlA=; b=ULy+HraFSkD5UVJGh+bh5B0pQLqhFipAK8AoRi5GPmux/XvvAyYc/AIdIhvTciYMAw atEpul5SSAX37sYlrK3MfB489q5ujrzx2g9gU5hT2+/EQoaFpZNZRFi+mo93yViPNwy5 TyLuhuueyFXfBtRPtM4yedxDF6fAMg2lnuUv18YNveeVmukqAhlHuExyLvZRgvs6Xoc5 JbJu3haHHJUuFeotNB6WnnxbLuaBWncFz5dsTRwNNIaWwHiF0/JvistGhQ3Ntw11xqMH F9M1Dwp8x0PBiNLSPSt+YPK2xgrImKF9QdkaOuu5W1j7EnNDfloUHKVEn1g+wNqIRfR9 ZdPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744652539; x=1745257339; 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=+v5/q5rPSGglKhge482QHSxn0kDSG2APb/UlulErBlA=; b=CkjhUP3M3xJdpczj0z9pOwclL2/iBU1nSIUTsvE1qylKT/vqVamHlxnptrKGV1QfB/ TkGJtkhx0C8rmquIKWyIz9Bl68v9mbnO0zUGgmbGEoJcfE2R+L+//V6gE0pUNYApQU8o eG1AtlDNng0jAz6GR0XpiaUsPxEX1T5kw1xHe77DBvlMYVqbGHzj/AxQxo/BSfqaIbNN 7U1zPPgrS+Dds4FpcSHlFXAKbTNp93kCtCpHPbx8s/FBQXVdnONG1VJg+5XptLjlgonB 7tLKqSnEQOAl6UGO3cwGi1HsoZtUVuv43ukPEIdzVUe++Sx9cxaM9fwQN3nnZ1fjaHXH kMyw== X-Forwarded-Encrypted: i=1; AJvYcCX/ECM/wHBJpmdtGaUumDAz5uJSAGlX+7zAA/SwdxZNzFv4BnYc2vKynrt5FYXMmOcK6xYH8uf8EfBBUj0=@vger.kernel.org X-Gm-Message-State: AOJu0YzabaaEXX8gM0gAR0GooM/R/Gcix7firwrZKfF1StJAlZanmObK k0F1UHzAJY8QByOmvUF+xfgbdghXJt4O4zUq3YCZsDLwYOW0maLDK45jbok4wbJMpSZpg5nE/vx nQBW0JQ== X-Google-Smtp-Source: AGHT+IG427R/lno3K5WSfhSr/PrtGfyC0AAoSR1CaVNs9fF0cIKkbSGqaJd7SnL4Vyi1rOuK9Kt95u+JIiee X-Received: from pjbsz5.prod.google.com ([2002:a17:90b:2d45:b0:2f5:63a:4513]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:264c:b0:2f9:9ddd:689b with SMTP id 98e67ed59e1d1-308236728a0mr17494499a91.22.1744652539466; Mon, 14 Apr 2025 10:42:19 -0700 (PDT) Date: Mon, 14 Apr 2025 10:41:30 -0700 In-Reply-To: <20250414174134.3095492-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: <20250414174134.3095492-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.604.gff1f9ca942-goog Message-ID: <20250414174134.3095492-13-irogers@google.com> Subject: [PATCH v5 12/16] perf intel-tpebs: Don't close record on read From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , "=?UTF-8?q?Andreas=20F=C3=A4rber?=" , Manivannan Sadhasivam , Maxime Coquelin , Alexandre Torgue , Caleb Biggers , Weilin Wang , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Perry Taylor , Thomas Falcon Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Factor sending record control fd code into its own function. Rather than killing the record process send it a ping when reading. Timeouts were witnessed if done too frequently, so only ping for the first tpebs events. Don't kill the record command send it a stop command. As close isn't reliably called also close on evsel__exit. Add extra checks on the record being terminated to avoid warnings. Adjust the locking as needed and incorporate extra -Wthread-safety checks. Check to do six 500ms poll timeouts when sending commands, rather than the larger 3000ms, to allow the record process terminating to be better witnessed. Signed-off-by: Ian Rogers Tested-by: Weilin Wang Acked-by: Namhyung Kim Reviewed-by: Kan Liang --- tools/perf/util/evsel.c | 2 + tools/perf/util/intel-tpebs.c | 200 +++++++++++++++++++++------------- 2 files changed, 129 insertions(+), 73 deletions(-) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 1d343f51225b..661a07cbdb25 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1656,6 +1656,8 @@ void evsel__exit(struct evsel *evsel) { assert(list_empty(&evsel->core.node)); assert(evsel->evlist =3D=3D NULL); + if (evsel__is_retire_lat(evsel)) + evsel__tpebs_close(evsel); bpf_counter__destroy(evsel); perf_bpf_filter__destroy(evsel); evsel__free_counts(evsel); diff --git a/tools/perf/util/intel-tpebs.c b/tools/perf/util/intel-tpebs.c index aa6bcdf2bf6c..a9446e7a1c5c 100644 --- a/tools/perf/util/intel-tpebs.c +++ b/tools/perf/util/intel-tpebs.c @@ -33,6 +33,7 @@ bool tpebs_recording; static LIST_HEAD(tpebs_results); static pthread_t tpebs_reader_thread; static struct child_process tpebs_cmd; +static int control_fd[2], ack_fd[2]; static struct mutex tpebs_mtx; =20 struct tpebs_retire_lat { @@ -51,8 +52,6 @@ struct tpebs_retire_lat { bool started; }; =20 -static struct tpebs_retire_lat *tpebs_retire_lat__find(struct evsel *evsel= ); - static void tpebs_mtx_init(void) { mutex_init(&tpebs_mtx); @@ -66,7 +65,10 @@ static struct mutex *tpebs_mtx_get(void) return &tpebs_mtx; } =20 -static int evsel__tpebs_start_perf_record(struct evsel *evsel, int control= _fd[], int ack_fd[]) +static struct tpebs_retire_lat *tpebs_retire_lat__find(struct evsel *evsel) + EXCLUSIVE_LOCKS_REQUIRED(tpebs_mtx_get()); + +static int evsel__tpebs_start_perf_record(struct evsel *evsel) { const char **record_argv; int tpebs_event_size =3D 0, i =3D 0, ret; @@ -74,15 +76,13 @@ static int evsel__tpebs_start_perf_record(struct evsel = *evsel, int control_fd[], char cpumap_buf[50]; struct tpebs_retire_lat *t; =20 - mutex_lock(tpebs_mtx_get()); list_for_each_entry(t, &tpebs_results, nd) tpebs_event_size++; =20 record_argv =3D malloc((10 + 2 * tpebs_event_size) * sizeof(*record_argv)= ); - if (!record_argv) { - mutex_unlock(tpebs_mtx_get()); + if (!record_argv) return -ENOMEM; - } + record_argv[i++] =3D "perf"; record_argv[i++] =3D "record"; record_argv[i++] =3D "-W"; @@ -118,7 +118,6 @@ static int evsel__tpebs_start_perf_record(struct evsel = *evsel, int control_fd[], list_for_each_entry(t, &tpebs_results, nd) t->started =3D true; =20 - mutex_unlock(tpebs_mtx_get()); return ret; } =20 @@ -131,6 +130,11 @@ static int process_sample_event(const struct perf_tool= *tool __maybe_unused, struct tpebs_retire_lat *t; =20 mutex_lock(tpebs_mtx_get()); + if (tpebs_cmd.pid =3D=3D 0) { + /* Record has terminated. */ + mutex_unlock(tpebs_mtx_get()); + return 0; + } t =3D tpebs_retire_lat__find(evsel); if (!t) { mutex_unlock(tpebs_mtx_get()); @@ -180,17 +184,98 @@ static void *__sample_reader(void *arg __maybe_unused) return NULL; } =20 +static int tpebs_send_record_cmd(const char *msg) EXCLUSIVE_LOCKS_REQUIRED= (tpebs_mtx_get()) +{ + struct pollfd pollfd =3D { .events =3D POLLIN, }; + int ret, len, retries =3D 0; + char ack_buf[8]; + + /* Check if the command exited before the send, done with the lock held. = */ + if (tpebs_cmd.pid =3D=3D 0) + return 0; + + /* + * Let go of the lock while sending/receiving as blocking can starve the + * sample reading thread. + */ + mutex_unlock(tpebs_mtx_get()); + + /* Send perf record command.*/ + len =3D strlen(msg); + ret =3D write(control_fd[1], msg, len); + if (ret !=3D len) { + pr_err("perf record control write control message '%s' failed\n", msg); + ret =3D -EPIPE; + goto out; + } + + if (!strcmp(msg, EVLIST_CTL_CMD_STOP_TAG)) { + ret =3D 0; + goto out; + } + + /* Wait for an ack. */ + pollfd.fd =3D ack_fd[0]; + + /* + * We need this poll to ensure the ack_fd PIPE will not hang + * when perf record failed for any reason. The timeout value + * 3000ms is an empirical selection. + */ +again: + if (!poll(&pollfd, 1, 500)) { + if (check_if_command_finished(&tpebs_cmd)) { + ret =3D 0; + goto out; + } + + if (retries++ < 6) + goto again; + pr_err("tpebs failed: perf record ack timeout for '%s'\n", msg); + ret =3D -ETIMEDOUT; + goto out; + } + + if (!(pollfd.revents & POLLIN)) { + if (check_if_command_finished(&tpebs_cmd)) { + ret =3D 0; + goto out; + } + + pr_err("tpebs failed: did not received an ack for '%s'\n", msg); + ret =3D -EPIPE; + goto out; + } + + ret =3D read(ack_fd[0], ack_buf, sizeof(ack_buf)); + if (ret > 0) + ret =3D strcmp(ack_buf, EVLIST_CTL_CMD_ACK_TAG); + else + pr_err("tpebs: perf record control ack failed\n"); +out: + /* Re-take lock as expected by caller. */ + mutex_lock(tpebs_mtx_get()); + return ret; +} + /* * tpebs_stop - stop the sample data read thread and the perf record proce= ss. */ -static int tpebs_stop(void) +static int tpebs_stop(void) EXCLUSIVE_LOCKS_REQUIRED(tpebs_mtx_get()) { int ret =3D 0; =20 /* Like tpebs_start, we should only run tpebs_end once. */ if (tpebs_cmd.pid !=3D 0) { - kill(tpebs_cmd.pid, SIGTERM); + tpebs_send_record_cmd(EVLIST_CTL_CMD_STOP_TAG); + tpebs_cmd.pid =3D 0; + mutex_unlock(tpebs_mtx_get()); pthread_join(tpebs_reader_thread, NULL); + mutex_lock(tpebs_mtx_get()); + close(control_fd[0]); + close(control_fd[1]); + close(ack_fd[0]); + close(ack_fd[1]); close(tpebs_cmd.out); ret =3D finish_command(&tpebs_cmd); tpebs_cmd.pid =3D 0; @@ -352,13 +437,15 @@ int evsel__tpebs_open(struct evsel *evsel) return 0; /* Only start the events once. */ if (tpebs_cmd.pid !=3D 0) { - struct tpebs_retire_lat *t =3D tpebs_retire_lat__find(evsel); + struct tpebs_retire_lat *t; + bool valid; =20 - if (!t || !t->started) { - /* Fail, as the event wasn't started. */ - return -EBUSY; - } - return 0; + mutex_lock(tpebs_mtx_get()); + t =3D tpebs_retire_lat__find(evsel); + valid =3D t && t->started; + mutex_unlock(tpebs_mtx_get()); + /* May fail as the event wasn't started. */ + return valid ? 0 : -EBUSY; } =20 ret =3D evsel__tpebs_prepare(evsel); @@ -367,12 +454,7 @@ int evsel__tpebs_open(struct evsel *evsel) =20 mutex_lock(tpebs_mtx_get()); tpebs_empty =3D list_empty(&tpebs_results); - mutex_unlock(tpebs_mtx_get()); if (!tpebs_empty) { - struct pollfd pollfd =3D { .events =3D POLLIN, }; - int control_fd[2], ack_fd[2], len; - char ack_buf[8]; - /*Create control and ack fd for --control*/ if (pipe(control_fd) < 0) { pr_err("tpebs: Failed to create control fifo"); @@ -385,7 +467,7 @@ int evsel__tpebs_open(struct evsel *evsel) goto out; } =20 - ret =3D evsel__tpebs_start_perf_record(evsel, control_fd, ack_fd); + ret =3D evsel__tpebs_start_perf_record(evsel); if (ret) goto out; =20 @@ -397,53 +479,16 @@ int evsel__tpebs_open(struct evsel *evsel) ret =3D -1; goto out; } - /* Wait for perf record initialization.*/ - len =3D strlen(EVLIST_CTL_CMD_ENABLE_TAG); - ret =3D write(control_fd[1], EVLIST_CTL_CMD_ENABLE_TAG, len); - if (ret !=3D len) { - pr_err("perf record control write control message failed\n"); - goto out; - } - - /* wait for an ack */ - pollfd.fd =3D ack_fd[0]; - - /* - * We need this poll to ensure the ack_fd PIPE will not hang - * when perf record failed for any reason. The timeout value - * 3000ms is an empirical selection. - */ - if (!poll(&pollfd, 1, 3000)) { - pr_err("tpebs failed: perf record ack timeout\n"); - ret =3D -1; - goto out; - } - - if (!(pollfd.revents & POLLIN)) { - pr_err("tpebs failed: did not received an ack\n"); - ret =3D -1; - goto out; - } - - ret =3D read(ack_fd[0], ack_buf, sizeof(ack_buf)); - if (ret > 0) - ret =3D strcmp(ack_buf, EVLIST_CTL_CMD_ACK_TAG); - else { - pr_err("tpebs: perf record control ack failed\n"); - goto out; - } -out: - close(control_fd[0]); - close(control_fd[1]); - close(ack_fd[0]); - close(ack_fd[1]); + ret =3D tpebs_send_record_cmd(EVLIST_CTL_CMD_ENABLE_TAG); } +out: if (ret) { struct tpebs_retire_lat *t =3D tpebs_retire_lat__find(evsel); =20 list_del_init(&t->nd); tpebs_retire_lat__delete(t); } + mutex_unlock(tpebs_mtx_get()); return ret; } =20 @@ -452,6 +497,7 @@ int evsel__tpebs_read(struct evsel *evsel, int cpu_map_= idx, int thread) struct perf_counts_values *count, *old_count =3D NULL; struct tpebs_retire_lat *t; uint64_t val; + int ret; =20 /* Only set retire_latency value to the first CPU and thread. */ if (cpu_map_idx !=3D 0 || thread !=3D 0) @@ -462,14 +508,20 @@ int evsel__tpebs_read(struct evsel *evsel, int cpu_ma= p_idx, int thread) =20 count =3D perf_counts(evsel->counts, cpu_map_idx, thread); =20 - /* - * Need to stop the forked record to ensure get sampled data from the - * PIPE to process and get non-zero retire_lat value for hybrid. - */ - tpebs_stop(); - mutex_lock(tpebs_mtx_get()); t =3D tpebs_retire_lat__find(evsel); + /* + * If reading the first tpebs result, send a ping to the record + * process. Allow the sample reader a chance to read by releasing and + * reacquiring the lock. + */ + if (&t->nd =3D=3D tpebs_results.next) { + ret =3D tpebs_send_record_cmd(EVLIST_CTL_CMD_PING_TAG); + mutex_unlock(tpebs_mtx_get()); + if (ret) + return ret; + mutex_lock(tpebs_mtx_get()); + } val =3D rint(t->val); mutex_unlock(tpebs_mtx_get()); =20 @@ -498,10 +550,12 @@ void evsel__tpebs_close(struct evsel *evsel) =20 mutex_lock(tpebs_mtx_get()); t =3D tpebs_retire_lat__find(evsel); - list_del_init(&t->nd); - tpebs_retire_lat__delete(t); - mutex_unlock(tpebs_mtx_get()); + if (t) { + list_del_init(&t->nd); + tpebs_retire_lat__delete(t); =20 - if (list_empty(&tpebs_results)) - tpebs_stop(); + if (list_empty(&tpebs_results)) + tpebs_stop(); + } + mutex_unlock(tpebs_mtx_get()); } --=20 2.49.0.604.gff1f9ca942-goog From nobody Fri Dec 19 17:37:02 2025 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2562A2918D8 for ; Mon, 14 Apr 2025 17:42:21 +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=1744652543; cv=none; b=GNrZbGaUSSh1R7EIEWfm+jKJt8K+W664LZOtSLVfNjpvjpmgWMaYaaX6XPjJH2j2Wy0KRAVJVIMr8nh/iUfcBcdF3kboaCMp0ngaWShQjdY6Du0Y3pCSAHHpwgPzQ1UDavCvm4IxZU1ajle7k1qwxzvOxx9DIVnpj39NpyYobec= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744652543; c=relaxed/simple; bh=XQBjLpvUcKT1rbTwpwSIA4ZEcfX1eZFeIrszq9/gIZc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=cpMGEk6Ci9KLlve8VXWi5kiy2umgtdME8/t3sb3BGY5Uzw+ZLKGGaaEJrJIdlGZ1DNkuqSDVpjk0RfBsZjEe9hWjBaUVF/67D35uWxkJU5GWb66lUCVWuP/uNr6HU3ZfLH7pPqSXkwZ3z616wOZE3f/J862b7dImbhprFI9FOHQ= 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=luR06qGR; 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="luR06qGR" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-22647ff3cf5so37372285ad.0 for ; Mon, 14 Apr 2025 10:42:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1744652541; x=1745257341; 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=x3YaC980+r1nZ2D8a7F/BKfpCPrV+UZzeRb3LiqHQpw=; b=luR06qGRNmLjcrXzsgdBHMATB3ggM3StNV8KU6HYDlJPCGpHYkHIRccwNVzEiW9QHp 4fwfKmeBd9/7Wsy2pxjrzjFMToqzP0WtWf/sDNSBQs+sWugtXc4ozGvmFPGMDEmVZzo0 7tOOBtxU7CRS6UzKRDzNLhvGg5SFNzBz8lIN8hjpl+mLAMHOnJOx8jwwCrJxqKigIPhj 0Ne4iUq1pRrQFofpz1gqJZlVNYJi7lSSgkqDRKfgLIQV16WCp25rT982K0g+KrExJlCb CYVx5o5F9X7tXlX5Yj3ZEZzU/53gI98KqHrBn8AKRUy25ekYAIhuvEgP4xbNjedyETmm SwXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744652541; x=1745257341; 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=x3YaC980+r1nZ2D8a7F/BKfpCPrV+UZzeRb3LiqHQpw=; b=nbt3qeEBl1A1zK6pEOISzIEm612JKl2uNrrNf05Qzt/osGWaU/t6OiyP7tf4WwgbeR zYzabWTzVtWWUnMYCw7GTL345o+FNppX0WVZPcal94hi57lc+AZMkqiCSyCsKPJ4bRGj 53HfegTV1EC/4mQLL9RIJUVTG6xYFeDs+L9rTB7Bgk7fsjv7PunoA4BNJuD8tG1fXWDc CuDxvedLhNnN6Xtu/naMnZnTF5hSDkW0ShrXkSVivJAj/imDTm1QlEPXbKxmuATfxSVk Hop1nhnLdF7jANnCJsy6Ll/XkPDoy8EIraz13T+Bx3YSxg7LSMk3px0l/r5A0v6JcgRC DhXA== X-Forwarded-Encrypted: i=1; AJvYcCU2eI3QuHMlaiatNdJUJkpbjuo1io1XGBJEiNmww9di2CxeVPxaPPesSBHlF4HV/Cloqeo7DjdcL2/yFzI=@vger.kernel.org X-Gm-Message-State: AOJu0YwMghdreOlpZrvAS/eZhMLprBphBzPh28pY0Pi/zxGEWTGGfwEH OMgU4iCc8rRmxnBSufe9UAKv4Z13WFNwOACQsleYyzkjNH1UtoRRJ+J+IHfNLh798nBUwteCX7C nVh/YQw== X-Google-Smtp-Source: AGHT+IF5D6jK1ghfd0t52mg85WD4BqRqb97G15GYc+m35//A00eC8Z31mPAniL9z9mLgfFeaaxaeb3nP3bkJ X-Received: from pldy12.prod.google.com ([2002:a17:902:cacc:b0:226:453a:f2db]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:2444:b0:220:c813:dfd1 with SMTP id d9443c01a7336-22bea4f398emr184470065ad.36.1744652541411; Mon, 14 Apr 2025 10:42:21 -0700 (PDT) Date: Mon, 14 Apr 2025 10:41:31 -0700 In-Reply-To: <20250414174134.3095492-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: <20250414174134.3095492-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.604.gff1f9ca942-goog Message-ID: <20250414174134.3095492-14-irogers@google.com> Subject: [PATCH v5 13/16] perf intel-tpebs: Use stats for retirement latency statistics From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , "=?UTF-8?q?Andreas=20F=C3=A4rber?=" , Manivannan Sadhasivam , Maxime Coquelin , Alexandre Torgue , Caleb Biggers , Weilin Wang , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Perry Taylor , Thomas Falcon Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" struct stats provides access to mean, min and max. It also provides uniformity with statistics code used elsewhere in perf. Signed-off-by: Ian Rogers Tested-by: Weilin Wang Acked-by: Namhyung Kim Reviewed-by: Kan Liang --- tools/perf/util/intel-tpebs.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/tools/perf/util/intel-tpebs.c b/tools/perf/util/intel-tpebs.c index a9446e7a1c5c..de9fea601964 100644 --- a/tools/perf/util/intel-tpebs.c +++ b/tools/perf/util/intel-tpebs.c @@ -18,6 +18,7 @@ #include "evsel.h" #include "mutex.h" #include "session.h" +#include "stat.h" #include "tool.h" #include "cpumap.h" #include "metricgroup.h" @@ -42,12 +43,8 @@ struct tpebs_retire_lat { struct evsel *evsel; /** @event: Event passed to perf record. */ char *event; - /* Count of retire_latency values found in sample data */ - size_t count; - /* Sum of all the retire_latency values in sample data */ - int sum; - /* Average of retire_latency, val =3D sum / count */ - double val; + /** @stats: Recorded retirement latency stats. */ + struct stats stats; /* Has the event been sent to perf record? */ bool started; }; @@ -145,9 +142,7 @@ static int process_sample_event(const struct perf_tool = *tool __maybe_unused, * latency value will be used. Save the number of samples and the sum of * retire latency value for each event. */ - t->count +=3D 1; - t->sum +=3D sample->retire_lat; - t->val =3D (double) t->sum / t->count; + update_stats(&t->stats, sample->retire_lat); mutex_unlock(tpebs_mtx_get()); return 0; } @@ -522,7 +517,7 @@ int evsel__tpebs_read(struct evsel *evsel, int cpu_map_= idx, int thread) return ret; mutex_lock(tpebs_mtx_get()); } - val =3D rint(t->val); + val =3D rint(t->stats.mean); mutex_unlock(tpebs_mtx_get()); =20 if (old_count) { --=20 2.49.0.604.gff1f9ca942-goog From nobody Fri Dec 19 17:37:02 2025 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DF29D290BC6 for ; Mon, 14 Apr 2025 17:42:23 +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=1744652545; cv=none; b=Vp6p2L7dcVOcbQo1+TwE+TsY8mSSHvWDrzkUuvo3OL4ZhxTn/O/0Ck70wzTtxRanZGAJF+jQFGLkA4ght2ngYDQAIQI8NoZSztkiH9PXYNKZ2CxaawBWmtOC3qSiOp56PaimbAUikAuSxa2SamrU0BrUEpWICZyjqMYcwN/mYh0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744652545; c=relaxed/simple; bh=jxvwzo+E0Y6REh0vGM59W3ZsATahVyXgFYiSUfatgsQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=oK819JMhdq3rUx2PD0scNbP5yNUNqD6vABnp6UenUJYsDOCcJM2srMERyMa2orCfwVr7yrhM/E+b/GKl5GD7JwoTMb4lZAFvOd8TvHQjBeGg/HOkP2RW9DPtmToLlnFQDFCo9rfRAUXc0RzPjICBbGaUhtxLoBxlp56CVCNOqf4= 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=qzvo4LZm; 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="qzvo4LZm" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-30566e34290so4969700a91.3 for ; Mon, 14 Apr 2025 10:42:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1744652543; x=1745257343; 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=/wtTJDwGjBW9lW9i9Wpstm5B+fjJHY6yZ6LuJ53a/ko=; b=qzvo4LZmuCuWQw/IbbW9Jo/cweA62B5pb+/jCFhnvqdqWOqiKpxWeYLWIrc0E5GWfu Pl/wAJYGwc78mlWhSCO6hS9zuLHLwqlOL9ADq8iubJxMJVEnqXzPuBS2ivawzv0qR526 bIUubW+RxM4/MbpFUbR47/Gv7Y48DbRuvbulp1b0e+doZMqjbKtQnnRFwKDfLdOzuVv1 o262rOFXztwXka7x0qZiXq1ZXndtDyviAUb89XP3rqFWxSqZYHopPbcCNz3f6mO6hV7O R+pzCKcfS03qXJlh4uldAAENOa23lqUQyHNhPGpBucPCtrtsRex8m5CirtEJYXczYuh4 pKEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744652543; x=1745257343; 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=/wtTJDwGjBW9lW9i9Wpstm5B+fjJHY6yZ6LuJ53a/ko=; b=eqNkmiHGRo5WR034wybAlNtffP2DJ+IKJ5adMOpx7zjo3SAnsQyzM1iHP1IxMxFij4 JGipi7kWumXl5WvRPoCayfaIrU/bo2GBXG8FjauNjBQDsd6pGPENZ3iweNQouBThjW7g 6uzClDtXntZ6FrKwSilf55P0xU5GAWkMfIYARvGmsgAkg7T0MxKmGbfLRMSsooOCqQXI 9Mr+w9i9M6rqPMs4tfTPeOWCb/YqiPHEB/lSQVpFCk4VMGQ+vvZpJnk23rkmQ6eyGE3n UEDJwWDVgwZEzs0Bi/RiiAkJtliso+b/14vy9XFoY2mh+lw0o3H6UHl1/xSQiwCVSZfW l7HA== X-Forwarded-Encrypted: i=1; AJvYcCXQWvDM4DjrhjF0/Dr0cZcziCGG+jRGXHNcuz0kJKD1qeLByS+jAaU9AvT5chrygNnUiGcP6/Sb/KfJgAU=@vger.kernel.org X-Gm-Message-State: AOJu0Yz4NqwSBC2DHTKjQtRf6YZuIMwNSVHiYeQUoGAm7erNrM4de5ac zgRfE5cCGeHwNjvtNzmR6WHkE2cYueo5WmB5TGn03qfFMf8ObcgIbm75LQG8QEp2wVCBptiy/sQ ySjEcWA== X-Google-Smtp-Source: AGHT+IHxhg/HSfq/QtHRtd4AIxDQ/mcgJ4pFkSlpMKM/NqthKSS7lzqjhJF0YGsGpeUc3yVgHHsYEitGrfcf X-Received: from pjbsl16.prod.google.com ([2002:a17:90b:2e10:b0:2fe:800f:23a]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:2751:b0:305:2d68:8d39 with SMTP id 98e67ed59e1d1-3082377c2c4mr23724970a91.12.1744652543036; Mon, 14 Apr 2025 10:42:23 -0700 (PDT) Date: Mon, 14 Apr 2025 10:41:32 -0700 In-Reply-To: <20250414174134.3095492-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: <20250414174134.3095492-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.604.gff1f9ca942-goog Message-ID: <20250414174134.3095492-15-irogers@google.com> Subject: [PATCH v5 14/16] perf stat: Add mean, min, max and last --tpebs-mode options From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , "=?UTF-8?q?Andreas=20F=C3=A4rber?=" , Manivannan Sadhasivam , Maxime Coquelin , Alexandre Torgue , Caleb Biggers , Weilin Wang , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Perry Taylor , Thomas Falcon Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add command line configuration option for how retirement latency events are combined. The default "mean" gives the average of retirement latency. "min" or "max" give the smallest or largest retirment latency times respectively. "last" uses the last retirment latency sample's time. Signed-off-by: Ian Rogers Tested-by: Weilin Wang Acked-by: Namhyung Kim Reviewed-by: Kan Liang --- tools/perf/Documentation/perf-stat.txt | 7 +++++++ tools/perf/builtin-stat.c | 27 ++++++++++++++++++++++++++ tools/perf/util/intel-tpebs.c | 20 ++++++++++++++++++- tools/perf/util/intel-tpebs.h | 8 ++++++++ 4 files changed, 61 insertions(+), 1 deletion(-) diff --git a/tools/perf/Documentation/perf-stat.txt b/tools/perf/Documentat= ion/perf-stat.txt index 2bc063672486..61d091670dee 100644 --- a/tools/perf/Documentation/perf-stat.txt +++ b/tools/perf/Documentation/perf-stat.txt @@ -506,6 +506,13 @@ this option is not set. The TPEBS hardware feature sta= rts from Intel Granite Rapids microarchitecture. This option only exists in X86_64 and is meaning= ful on Intel platforms with TPEBS feature. =20 +--tpebs-mode=3D[mean|min|max|last]:: +Set how retirement latency events have their sample times +combined. The default "mean" gives the average of retirement +latency. "min" or "max" give the smallest or largest retirment latency +times respectively. "last" uses the last retirment latency sample's +time. + --td-level:: Print the top-down statistics that equal the input level. It allows users to print the interested top-down metrics level instead of the diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 80e491bd775b..4adf2ae53b11 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -2327,6 +2327,30 @@ static void setup_system_wide(int forks) } } =20 +static int parse_tpebs_mode(const struct option *opt, const char *str, + int unset __maybe_unused) +{ + enum tpebs_mode *mode =3D opt->value; + + if (!strcasecmp("mean", str)) { + *mode =3D TPEBS_MODE__MEAN; + return 0; + } + if (!strcasecmp("min", str)) { + *mode =3D TPEBS_MODE__MIN; + return 0; + } + if (!strcasecmp("max", str)) { + *mode =3D TPEBS_MODE__MAX; + return 0; + } + if (!strcasecmp("last", str)) { + *mode =3D TPEBS_MODE__LAST; + return 0; + } + return -1; +} + int cmd_stat(int argc, const char **argv) { struct opt_aggr_mode opt_mode =3D {}; @@ -2431,6 +2455,9 @@ int cmd_stat(int argc, const char **argv) #ifdef HAVE_ARCH_X86_64_SUPPORT OPT_BOOLEAN(0, "record-tpebs", &tpebs_recording, "enable recording for tpebs when retire_latency required"), + OPT_CALLBACK(0, "tpebs-mode", &tpebs_mode, "tpebs-mode", + "Mode of TPEBS recording: mean, min or max", + parse_tpebs_mode), #endif OPT_UINTEGER(0, "td-level", &stat_config.topdown_level, "Set the metrics level for the top-down statistics (0: max level)"), diff --git a/tools/perf/util/intel-tpebs.c b/tools/perf/util/intel-tpebs.c index de9fea601964..6b00bd5b0af1 100644 --- a/tools/perf/util/intel-tpebs.c +++ b/tools/perf/util/intel-tpebs.c @@ -31,6 +31,7 @@ #define PERF_DATA "-" =20 bool tpebs_recording; +enum tpebs_mode tpebs_mode; static LIST_HEAD(tpebs_results); static pthread_t tpebs_reader_thread; static struct child_process tpebs_cmd; @@ -45,6 +46,8 @@ struct tpebs_retire_lat { char *event; /** @stats: Recorded retirement latency stats. */ struct stats stats; + /** @last: Last retirement latency read. */ + uint64_t last; /* Has the event been sent to perf record? */ bool started; }; @@ -142,6 +145,7 @@ static int process_sample_event(const struct perf_tool = *tool __maybe_unused, * latency value will be used. Save the number of samples and the sum of * retire latency value for each event. */ + t->last =3D sample->retire_lat; update_stats(&t->stats, sample->retire_lat); mutex_unlock(tpebs_mtx_get()); return 0; @@ -517,7 +521,21 @@ int evsel__tpebs_read(struct evsel *evsel, int cpu_map= _idx, int thread) return ret; mutex_lock(tpebs_mtx_get()); } - val =3D rint(t->stats.mean); + switch (tpebs_mode) { + case TPEBS_MODE__MIN: + val =3D rint(t->stats.min); + break; + case TPEBS_MODE__MAX: + val =3D rint(t->stats.max); + break; + case TPEBS_MODE__LAST: + val =3D t->last; + break; + default: + case TPEBS_MODE__MEAN: + val =3D rint(t->stats.mean); + break; + } mutex_unlock(tpebs_mtx_get()); =20 if (old_count) { diff --git a/tools/perf/util/intel-tpebs.h b/tools/perf/util/intel-tpebs.h index 218a82866cee..9475e2e6ea74 100644 --- a/tools/perf/util/intel-tpebs.h +++ b/tools/perf/util/intel-tpebs.h @@ -8,7 +8,15 @@ struct evlist; struct evsel; =20 +enum tpebs_mode { + TPEBS_MODE__MEAN, + TPEBS_MODE__MIN, + TPEBS_MODE__MAX, + TPEBS_MODE__LAST, +}; + extern bool tpebs_recording; +extern enum tpebs_mode tpebs_mode; =20 int evsel__tpebs_open(struct evsel *evsel); void evsel__tpebs_close(struct evsel *evsel); --=20 2.49.0.604.gff1f9ca942-goog From nobody Fri Dec 19 17:37:02 2025 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9A9232918FA for ; Mon, 14 Apr 2025 17:42:25 +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=1744652548; cv=none; b=lWdQdgbjPX/BQcRbcuhdAI4XChUz+/8erPbB+TK5BP0HvrZRD1HXDmHQiE4FMG77Er6MVMWUbOYxmljTL67pnTKcx1mwNN5De0JKBMIxTOm692Bf84noH/iXVdlnfLEl7uxIiEylUEOqVQoA/ed7Z7xBDdixDEEhMxVicms2YHQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744652548; c=relaxed/simple; bh=SidP6NBdj2Uv3Y+dMu29dmAeVT7IMRLnJeXlx5lSny8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=sPoMkafsQ8ApcIFzGeWD8FGb+4gLFQnCAKAPmoG3AWpXErWAjOmyD++tvNAJhomN8k1kvv+5h+z+u8fbKhqJ5fv3fVQvAalnFuyT0FanwVVbWB+MY3O2oK32zHiHG+pMFWF+IV7vajqTiX/XJgkPubwq3GbBRh3/kPQ31zKY91A= 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=0o0xUAnX; 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="0o0xUAnX" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-22410053005so74957585ad.1 for ; Mon, 14 Apr 2025 10:42:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1744652545; x=1745257345; 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=1sfu3//0rZwyVhNzYhtgUvMv5lXrohu01OslCwom1AA=; b=0o0xUAnX9kiJNXcc7uCLWT45SWsy+W7vp847px+7XFIMCi1JSgjL8AYDs5HRifWqsW l+8szdshoa3vjQ61AtFQnoqDHQVJPLcahVn1Tbmc7M/xr+Q63sf/Vfn8g9j1U6QHGNJC iDubGlF+42RIdtfud/eUGKI2kehEfwwiU2euC/XsvZgJ12P+j4eOOzgbaLh79AZTkiLg RqATWZm/Apgnc1VuN2FCyA/7GnYjP9s1BHuLAydsV4vsf4QbvfmwtT5a3FWJtw6fv3Yx tGtY/HCnH8cmmDOiAAivKCJyJWGQ3gnaRcVUl68lSwrV4DsUTjpEXcDr2fnQB0vge+hZ v9kA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744652545; x=1745257345; 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=1sfu3//0rZwyVhNzYhtgUvMv5lXrohu01OslCwom1AA=; b=cHy5TTWVITe0EqCgKmEZ6GmRbnkm4aBrp9hLQW5NW1AtuOOTZmbNACfJXNQqWxpQC4 QWneVU1zjy6ASGbjvmLj0gv2+ogOqFDaixTWmdyhC4UDziJrnE8GFuAaUSH+ttmLD1rO tLrptpfI3yvJQzACpLUTC1jOvdUAgeZExV1quZXDGqUVpMw+JsGFsXQT14AumGNt4lI5 0x5W8v/nH9YHOYXPCrX6Ixr9gIWDBC1g/9N1Jkq8rwmGMxBYdE1/wIMB3WuGMUcCp50v lExwBgLYkeAz0juHfc4mK380OC23lRuuYfNLBRgdSTntpBjpPasWx2FEhPo/b/mEDQTe SrCg== X-Forwarded-Encrypted: i=1; AJvYcCWuXnFx+AcrFimlncEFDNkbiiG7jOf6KYEfInZGUyZFx7eFFIvVXCeNA61cQ+SByv9+jWWdyKCr8Y7msio=@vger.kernel.org X-Gm-Message-State: AOJu0Yy16zbec0v4WZhKs2Gduecg9zpPy7h7hZnu2qlWEDspdizyDx+b Sn5I3vbBZvhePftxNbljtTWab4Ny/Lx/72JG9nBhJmtYvg7LeU5cmX7aLbr+WOmxFzLkRE3A9Lj yAcUdEw== X-Google-Smtp-Source: AGHT+IHBxiN/QZ+imxn11IqfNhrRwwMevzEpqN124h1QuO0aV/Ba5M8LO5CiXQaT8qQFYyOuvqgvpNyGikYt X-Received: from plv16.prod.google.com ([2002:a17:903:bd0:b0:223:5e68:a70f]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:1cd:b0:215:6e01:ad07 with SMTP id d9443c01a7336-22bea49559emr162318775ad.6.1744652545154; Mon, 14 Apr 2025 10:42:25 -0700 (PDT) Date: Mon, 14 Apr 2025 10:41:33 -0700 In-Reply-To: <20250414174134.3095492-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: <20250414174134.3095492-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.604.gff1f9ca942-goog Message-ID: <20250414174134.3095492-16-irogers@google.com> Subject: [PATCH v5 15/16] perf pmu-events: Add retirement latency to JSON events inside of perf From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , "=?UTF-8?q?Andreas=20F=C3=A4rber?=" , Manivannan Sadhasivam , Maxime Coquelin , Alexandre Torgue , Caleb Biggers , Weilin Wang , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Perry Taylor , Thomas Falcon Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The updated Intel vendor events add retirement latency for graniterapids: https://lore.kernel.org/lkml/20250322063403.364981-14-irogers@google.com/ This change makes those values available within an alias/event within a PMU and saves them into the evsel at event parse time. When no TPEBS data is available the default values are substituted in for TMA metrics that are using retirement latency events - currently just those on graniterapids. Signed-off-by: Ian Rogers Tested-by: Weilin Wang Acked-by: Namhyung Kim Reviewed-by: Kan Liang --- tools/perf/pmu-events/empty-pmu-events.c | 216 ++++++++++++----------- tools/perf/pmu-events/jevents.py | 6 + tools/perf/pmu-events/pmu-events.h | 3 + tools/perf/util/evsel.h | 6 + tools/perf/util/intel-tpebs.c | 52 ++++-- tools/perf/util/parse-events.c | 4 + tools/perf/util/pmu.c | 52 +++++- tools/perf/util/pmu.h | 3 + 8 files changed, 220 insertions(+), 122 deletions(-) diff --git a/tools/perf/pmu-events/empty-pmu-events.c b/tools/perf/pmu-even= ts/empty-pmu-events.c index 0cb7ba7912e8..0361bcc1eb58 100644 --- a/tools/perf/pmu-events/empty-pmu-events.c +++ b/tools/perf/pmu-events/empty-pmu-events.c @@ -20,73 +20,73 @@ struct pmu_table_entry { =20 static const char *const big_c_string =3D /* offset=3D0 */ "tool\000" -/* offset=3D5 */ "duration_time\000tool\000Wall clock interval time in nan= oseconds\000config=3D1\000\00000\000\000" -/* offset=3D78 */ "user_time\000tool\000User (non-kernel) time in nanoseco= nds\000config=3D2\000\00000\000\000" -/* offset=3D145 */ "system_time\000tool\000System/kernel time in nanosecon= ds\000config=3D3\000\00000\000\000" -/* offset=3D210 */ "has_pmem\000tool\0001 if persistent memory installed o= therwise 0\000config=3D4\000\00000\000\000" -/* offset=3D283 */ "num_cores\000tool\000Number of cores. A core consists = of 1 or more thread, with each thread being associated with a logical Linux= CPU\000config=3D5\000\00000\000\000" -/* offset=3D425 */ "num_cpus\000tool\000Number of logical Linux CPUs. Ther= e may be multiple such CPUs on a core\000config=3D6\000\00000\000\000" -/* offset=3D525 */ "num_cpus_online\000tool\000Number of online logical Li= nux CPUs. There may be multiple such CPUs on a core\000config=3D7\000\00000= \000\000" -/* offset=3D639 */ "num_dies\000tool\000Number of dies. Each die has 1 or = more cores\000config=3D8\000\00000\000\000" -/* offset=3D712 */ "num_packages\000tool\000Number of packages. Each packa= ge has 1 or more die\000config=3D9\000\00000\000\000" -/* offset=3D795 */ "slots\000tool\000Number of functional units that in pa= rallel can execute parts of an instruction\000config=3D0xa\000\00000\000\00= 0" -/* offset=3D902 */ "smt_on\000tool\0001 if simultaneous multithreading (ak= a hyperthreading) is enable otherwise 0\000config=3D0xb\000\00000\000\000" -/* offset=3D1006 */ "system_tsc_freq\000tool\000The amount a Time Stamp Co= unter (TSC) increases per second\000config=3D0xc\000\00000\000\000" -/* offset=3D1102 */ "default_core\000" -/* offset=3D1115 */ "bp_l1_btb_correct\000branch\000L1 BTB Correction\000e= vent=3D0x8a\000\00000\000\000" -/* offset=3D1174 */ "bp_l2_btb_correct\000branch\000L2 BTB Correction\000e= vent=3D0x8b\000\00000\000\000" -/* offset=3D1233 */ "l3_cache_rd\000cache\000L3 cache access, read\000even= t=3D0x40\000\00000\000Attributable Level 3 cache access, read\000" -/* offset=3D1328 */ "segment_reg_loads.any\000other\000Number of segment r= egister loads\000event=3D6,period=3D200000,umask=3D0x80\000\00000\000\000" -/* offset=3D1427 */ "dispatch_blocked.any\000other\000Memory cluster signa= ls to block micro-op dispatch for any reason\000event=3D9,period=3D200000,u= mask=3D0x20\000\00000\000\000" -/* offset=3D1557 */ "eist_trans\000other\000Number of Enhanced Intel Speed= Step(R) Technology (EIST) transitions\000event=3D0x3a,period=3D200000\000\0= 0000\000\000" -/* offset=3D1672 */ "hisi_sccl,ddrc\000" -/* offset=3D1687 */ "uncore_hisi_ddrc.flux_wcmd\000uncore\000DDRC write co= mmands\000event=3D2\000\00000\000DDRC write commands\000" -/* offset=3D1773 */ "uncore_cbox\000" -/* offset=3D1785 */ "unc_cbo_xsnp_response.miss_eviction\000uncore\000A cr= oss-core snoop resulted from L3 Eviction which misses in some processor cor= e\000event=3D0x22,umask=3D0x81\000\00000\000A cross-core snoop resulted fro= m L3 Eviction which misses in some processor core\000" -/* offset=3D2016 */ "event-hyphen\000uncore\000UNC_CBO_HYPHEN\000event=3D0= xe0\000\00000\000UNC_CBO_HYPHEN\000" -/* offset=3D2081 */ "event-two-hyph\000uncore\000UNC_CBO_TWO_HYPH\000event= =3D0xc0\000\00000\000UNC_CBO_TWO_HYPH\000" -/* offset=3D2152 */ "hisi_sccl,l3c\000" -/* offset=3D2166 */ "uncore_hisi_l3c.rd_hit_cpipe\000uncore\000Total read = hits\000event=3D7\000\00000\000Total read hits\000" -/* offset=3D2246 */ "uncore_imc_free_running\000" -/* offset=3D2270 */ "uncore_imc_free_running.cache_miss\000uncore\000Total= cache misses\000event=3D0x12\000\00000\000Total cache misses\000" -/* offset=3D2365 */ "uncore_imc\000" -/* offset=3D2376 */ "uncore_imc.cache_hits\000uncore\000Total cache hits\0= 00event=3D0x34\000\00000\000Total cache hits\000" -/* offset=3D2454 */ "uncore_sys_ddr_pmu\000" -/* offset=3D2473 */ "sys_ddr_pmu.write_cycles\000uncore\000ddr write-cycle= s event\000event=3D0x2b\000v8\00000\000\000" -/* offset=3D2546 */ "uncore_sys_ccn_pmu\000" -/* offset=3D2565 */ "sys_ccn_pmu.read_cycles\000uncore\000ccn read-cycles = event\000config=3D0x2c\0000x01\00000\000\000" -/* offset=3D2639 */ "uncore_sys_cmn_pmu\000" -/* offset=3D2658 */ "sys_cmn_pmu.hnf_cache_miss\000uncore\000Counts total = cache misses in first lookup result (high priority)\000eventid=3D1,type=3D5= \000(434|436|43c|43a).*\00000\000\000" -/* offset=3D2798 */ "CPI\000\0001 / IPC\000\000\000\000\000\000\000\00000" -/* offset=3D2820 */ "IPC\000group1\000inst_retired.any / cpu_clk_unhalted.= thread\000\000\000\000\000\000\000\00000" -/* offset=3D2883 */ "Frontend_Bound_SMT\000\000idq_uops_not_delivered.core= / (4 * (cpu_clk_unhalted.thread / 2 * (1 + cpu_clk_unhalted.one_thread_act= ive / cpu_clk_unhalted.ref_xclk)))\000\000\000\000\000\000\000\00000" -/* offset=3D3049 */ "dcache_miss_cpi\000\000l1d\\-loads\\-misses / inst_re= tired.any\000\000\000\000\000\000\000\00000" -/* offset=3D3113 */ "icache_miss_cycles\000\000l1i\\-loads\\-misses / inst= _retired.any\000\000\000\000\000\000\000\00000" -/* offset=3D3180 */ "cache_miss_cycles\000group1\000dcache_miss_cpi + icac= he_miss_cycles\000\000\000\000\000\000\000\00000" -/* offset=3D3251 */ "DCache_L2_All_Hits\000\000l2_rqsts.demand_data_rd_hit= + l2_rqsts.pf_hit + l2_rqsts.rfo_hit\000\000\000\000\000\000\000\00000" -/* offset=3D3345 */ "DCache_L2_All_Miss\000\000max(l2_rqsts.all_demand_dat= a_rd - l2_rqsts.demand_data_rd_hit, 0) + l2_rqsts.pf_miss + l2_rqsts.rfo_mi= ss\000\000\000\000\000\000\000\00000" -/* offset=3D3479 */ "DCache_L2_All\000\000DCache_L2_All_Hits + DCache_L2_A= ll_Miss\000\000\000\000\000\000\000\00000" -/* offset=3D3543 */ "DCache_L2_Hits\000\000d_ratio(DCache_L2_All_Hits, DCa= che_L2_All)\000\000\000\000\000\000\000\00000" -/* offset=3D3611 */ "DCache_L2_Misses\000\000d_ratio(DCache_L2_All_Miss, D= Cache_L2_All)\000\000\000\000\000\000\000\00000" -/* offset=3D3681 */ "M1\000\000ipc + M2\000\000\000\000\000\000\000\00000" -/* offset=3D3703 */ "M2\000\000ipc + M1\000\000\000\000\000\000\000\00000" -/* offset=3D3725 */ "M3\000\0001 / M3\000\000\000\000\000\000\000\00000" -/* offset=3D3745 */ "L1D_Cache_Fill_BW\000\00064 * l1d.replacement / 1e9 /= duration_time\000\000\000\000\000\000\000\00000" +/* offset=3D5 */ "duration_time\000tool\000Wall clock interval time in nan= oseconds\000config=3D1\000\00000\000\000\000\000\000" +/* offset=3D81 */ "user_time\000tool\000User (non-kernel) time in nanoseco= nds\000config=3D2\000\00000\000\000\000\000\000" +/* offset=3D151 */ "system_time\000tool\000System/kernel time in nanosecon= ds\000config=3D3\000\00000\000\000\000\000\000" +/* offset=3D219 */ "has_pmem\000tool\0001 if persistent memory installed o= therwise 0\000config=3D4\000\00000\000\000\000\000\000" +/* offset=3D295 */ "num_cores\000tool\000Number of cores. A core consists = of 1 or more thread, with each thread being associated with a logical Linux= CPU\000config=3D5\000\00000\000\000\000\000\000" +/* offset=3D440 */ "num_cpus\000tool\000Number of logical Linux CPUs. Ther= e may be multiple such CPUs on a core\000config=3D6\000\00000\000\000\000\0= 00\000" +/* offset=3D543 */ "num_cpus_online\000tool\000Number of online logical Li= nux CPUs. There may be multiple such CPUs on a core\000config=3D7\000\00000= \000\000\000\000\000" +/* offset=3D660 */ "num_dies\000tool\000Number of dies. Each die has 1 or = more cores\000config=3D8\000\00000\000\000\000\000\000" +/* offset=3D736 */ "num_packages\000tool\000Number of packages. Each packa= ge has 1 or more die\000config=3D9\000\00000\000\000\000\000\000" +/* offset=3D822 */ "slots\000tool\000Number of functional units that in pa= rallel can execute parts of an instruction\000config=3D0xa\000\00000\000\00= 0\000\000\000" +/* offset=3D932 */ "smt_on\000tool\0001 if simultaneous multithreading (ak= a hyperthreading) is enable otherwise 0\000config=3D0xb\000\00000\000\000\0= 00\000\000" +/* offset=3D1039 */ "system_tsc_freq\000tool\000The amount a Time Stamp Co= unter (TSC) increases per second\000config=3D0xc\000\00000\000\000\000\000\= 000" +/* offset=3D1138 */ "default_core\000" +/* offset=3D1151 */ "bp_l1_btb_correct\000branch\000L1 BTB Correction\000e= vent=3D0x8a\000\00000\000\000\000\000\000" +/* offset=3D1213 */ "bp_l2_btb_correct\000branch\000L2 BTB Correction\000e= vent=3D0x8b\000\00000\000\000\000\000\000" +/* offset=3D1275 */ "l3_cache_rd\000cache\000L3 cache access, read\000even= t=3D0x40\000\00000\000\000\000\000Attributable Level 3 cache access, read\0= 00" +/* offset=3D1373 */ "segment_reg_loads.any\000other\000Number of segment r= egister loads\000event=3D6,period=3D200000,umask=3D0x80\000\00000\000\000\0= 00\000\000" +/* offset=3D1475 */ "dispatch_blocked.any\000other\000Memory cluster signa= ls to block micro-op dispatch for any reason\000event=3D9,period=3D200000,u= mask=3D0x20\000\00000\000\000\000\000\000" +/* offset=3D1608 */ "eist_trans\000other\000Number of Enhanced Intel Speed= Step(R) Technology (EIST) transitions\000event=3D0x3a,period=3D200000\000\0= 0000\000\000\000\000\000" +/* offset=3D1726 */ "hisi_sccl,ddrc\000" +/* offset=3D1741 */ "uncore_hisi_ddrc.flux_wcmd\000uncore\000DDRC write co= mmands\000event=3D2\000\00000\000\000\000\000DDRC write commands\000" +/* offset=3D1830 */ "uncore_cbox\000" +/* offset=3D1842 */ "unc_cbo_xsnp_response.miss_eviction\000uncore\000A cr= oss-core snoop resulted from L3 Eviction which misses in some processor cor= e\000event=3D0x22,umask=3D0x81\000\00000\000\000\000\000A cross-core snoop = resulted from L3 Eviction which misses in some processor core\000" +/* offset=3D2076 */ "event-hyphen\000uncore\000UNC_CBO_HYPHEN\000event=3D0= xe0\000\00000\000\000\000\000UNC_CBO_HYPHEN\000" +/* offset=3D2144 */ "event-two-hyph\000uncore\000UNC_CBO_TWO_HYPH\000event= =3D0xc0\000\00000\000\000\000\000UNC_CBO_TWO_HYPH\000" +/* offset=3D2218 */ "hisi_sccl,l3c\000" +/* offset=3D2232 */ "uncore_hisi_l3c.rd_hit_cpipe\000uncore\000Total read = hits\000event=3D7\000\00000\000\000\000\000Total read hits\000" +/* offset=3D2315 */ "uncore_imc_free_running\000" +/* offset=3D2339 */ "uncore_imc_free_running.cache_miss\000uncore\000Total= cache misses\000event=3D0x12\000\00000\000\000\000\000Total cache misses\0= 00" +/* offset=3D2437 */ "uncore_imc\000" +/* offset=3D2448 */ "uncore_imc.cache_hits\000uncore\000Total cache hits\0= 00event=3D0x34\000\00000\000\000\000\000Total cache hits\000" +/* offset=3D2529 */ "uncore_sys_ddr_pmu\000" +/* offset=3D2548 */ "sys_ddr_pmu.write_cycles\000uncore\000ddr write-cycle= s event\000event=3D0x2b\000v8\00000\000\000\000\000\000" +/* offset=3D2624 */ "uncore_sys_ccn_pmu\000" +/* offset=3D2643 */ "sys_ccn_pmu.read_cycles\000uncore\000ccn read-cycles = event\000config=3D0x2c\0000x01\00000\000\000\000\000\000" +/* offset=3D2720 */ "uncore_sys_cmn_pmu\000" +/* offset=3D2739 */ "sys_cmn_pmu.hnf_cache_miss\000uncore\000Counts total = cache misses in first lookup result (high priority)\000eventid=3D1,type=3D5= \000(434|436|43c|43a).*\00000\000\000\000\000\000" +/* offset=3D2882 */ "CPI\000\0001 / IPC\000\000\000\000\000\000\000\00000" +/* offset=3D2904 */ "IPC\000group1\000inst_retired.any / cpu_clk_unhalted.= thread\000\000\000\000\000\000\000\00000" +/* offset=3D2967 */ "Frontend_Bound_SMT\000\000idq_uops_not_delivered.core= / (4 * (cpu_clk_unhalted.thread / 2 * (1 + cpu_clk_unhalted.one_thread_act= ive / cpu_clk_unhalted.ref_xclk)))\000\000\000\000\000\000\000\00000" +/* offset=3D3133 */ "dcache_miss_cpi\000\000l1d\\-loads\\-misses / inst_re= tired.any\000\000\000\000\000\000\000\00000" +/* offset=3D3197 */ "icache_miss_cycles\000\000l1i\\-loads\\-misses / inst= _retired.any\000\000\000\000\000\000\000\00000" +/* offset=3D3264 */ "cache_miss_cycles\000group1\000dcache_miss_cpi + icac= he_miss_cycles\000\000\000\000\000\000\000\00000" +/* offset=3D3335 */ "DCache_L2_All_Hits\000\000l2_rqsts.demand_data_rd_hit= + l2_rqsts.pf_hit + l2_rqsts.rfo_hit\000\000\000\000\000\000\000\00000" +/* offset=3D3429 */ "DCache_L2_All_Miss\000\000max(l2_rqsts.all_demand_dat= a_rd - l2_rqsts.demand_data_rd_hit, 0) + l2_rqsts.pf_miss + l2_rqsts.rfo_mi= ss\000\000\000\000\000\000\000\00000" +/* offset=3D3563 */ "DCache_L2_All\000\000DCache_L2_All_Hits + DCache_L2_A= ll_Miss\000\000\000\000\000\000\000\00000" +/* offset=3D3627 */ "DCache_L2_Hits\000\000d_ratio(DCache_L2_All_Hits, DCa= che_L2_All)\000\000\000\000\000\000\000\00000" +/* offset=3D3695 */ "DCache_L2_Misses\000\000d_ratio(DCache_L2_All_Miss, D= Cache_L2_All)\000\000\000\000\000\000\000\00000" +/* offset=3D3765 */ "M1\000\000ipc + M2\000\000\000\000\000\000\000\00000" +/* offset=3D3787 */ "M2\000\000ipc + M1\000\000\000\000\000\000\000\00000" +/* offset=3D3809 */ "M3\000\0001 / M3\000\000\000\000\000\000\000\00000" +/* offset=3D3829 */ "L1D_Cache_Fill_BW\000\00064 * l1d.replacement / 1e9 /= duration_time\000\000\000\000\000\000\000\00000" ; =20 static const struct compact_pmu_event pmu_events__common_tool[] =3D { -{ 5 }, /* duration_time\000tool\000Wall clock interval time in nanoseconds= \000config=3D1\000\00000\000\000 */ -{ 210 }, /* has_pmem\000tool\0001 if persistent memory installed otherwise= 0\000config=3D4\000\00000\000\000 */ -{ 283 }, /* num_cores\000tool\000Number of cores. A core consists of 1 or = more thread, with each thread being associated with a logical Linux CPU\000= config=3D5\000\00000\000\000 */ -{ 425 }, /* num_cpus\000tool\000Number of logical Linux CPUs. There may be= multiple such CPUs on a core\000config=3D6\000\00000\000\000 */ -{ 525 }, /* num_cpus_online\000tool\000Number of online logical Linux CPUs= . There may be multiple such CPUs on a core\000config=3D7\000\00000\000\000= */ -{ 639 }, /* num_dies\000tool\000Number of dies. Each die has 1 or more cor= es\000config=3D8\000\00000\000\000 */ -{ 712 }, /* num_packages\000tool\000Number of packages. Each package has 1= or more die\000config=3D9\000\00000\000\000 */ -{ 795 }, /* slots\000tool\000Number of functional units that in parallel c= an execute parts of an instruction\000config=3D0xa\000\00000\000\000 */ -{ 902 }, /* smt_on\000tool\0001 if simultaneous multithreading (aka hypert= hreading) is enable otherwise 0\000config=3D0xb\000\00000\000\000 */ -{ 145 }, /* system_time\000tool\000System/kernel time in nanoseconds\000co= nfig=3D3\000\00000\000\000 */ -{ 1006 }, /* system_tsc_freq\000tool\000The amount a Time Stamp Counter (T= SC) increases per second\000config=3D0xc\000\00000\000\000 */ -{ 78 }, /* user_time\000tool\000User (non-kernel) time in nanoseconds\000c= onfig=3D2\000\00000\000\000 */ +{ 5 }, /* duration_time\000tool\000Wall clock interval time in nanoseconds= \000config=3D1\000\00000\000\000\000\000\000 */ +{ 219 }, /* has_pmem\000tool\0001 if persistent memory installed otherwise= 0\000config=3D4\000\00000\000\000\000\000\000 */ +{ 295 }, /* num_cores\000tool\000Number of cores. A core consists of 1 or = more thread, with each thread being associated with a logical Linux CPU\000= config=3D5\000\00000\000\000\000\000\000 */ +{ 440 }, /* num_cpus\000tool\000Number of logical Linux CPUs. There may be= multiple such CPUs on a core\000config=3D6\000\00000\000\000\000\000\000 */ +{ 543 }, /* num_cpus_online\000tool\000Number of online logical Linux CPUs= . There may be multiple such CPUs on a core\000config=3D7\000\00000\000\000= \000\000\000 */ +{ 660 }, /* num_dies\000tool\000Number of dies. Each die has 1 or more cor= es\000config=3D8\000\00000\000\000\000\000\000 */ +{ 736 }, /* num_packages\000tool\000Number of packages. Each package has 1= or more die\000config=3D9\000\00000\000\000\000\000\000 */ +{ 822 }, /* slots\000tool\000Number of functional units that in parallel c= an execute parts of an instruction\000config=3D0xa\000\00000\000\000\000\00= 0\000 */ +{ 932 }, /* smt_on\000tool\0001 if simultaneous multithreading (aka hypert= hreading) is enable otherwise 0\000config=3D0xb\000\00000\000\000\000\000\0= 00 */ +{ 151 }, /* system_time\000tool\000System/kernel time in nanoseconds\000co= nfig=3D3\000\00000\000\000\000\000\000 */ +{ 1039 }, /* system_tsc_freq\000tool\000The amount a Time Stamp Counter (T= SC) increases per second\000config=3D0xc\000\00000\000\000\000\000\000 */ +{ 81 }, /* user_time\000tool\000User (non-kernel) time in nanoseconds\000c= onfig=3D2\000\00000\000\000\000\000\000 */ =20 }; =20 @@ -99,29 +99,29 @@ const struct pmu_table_entry pmu_events__common[] =3D { }; =20 static const struct compact_pmu_event pmu_events__test_soc_cpu_default_cor= e[] =3D { -{ 1115 }, /* bp_l1_btb_correct\000branch\000L1 BTB Correction\000event=3D0= x8a\000\00000\000\000 */ -{ 1174 }, /* bp_l2_btb_correct\000branch\000L2 BTB Correction\000event=3D0= x8b\000\00000\000\000 */ -{ 1427 }, /* dispatch_blocked.any\000other\000Memory cluster signals to bl= ock micro-op dispatch for any reason\000event=3D9,period=3D200000,umask=3D0= x20\000\00000\000\000 */ -{ 1557 }, /* eist_trans\000other\000Number of Enhanced Intel SpeedStep(R) = Technology (EIST) transitions\000event=3D0x3a,period=3D200000\000\00000\000= \000 */ -{ 1233 }, /* l3_cache_rd\000cache\000L3 cache access, read\000event=3D0x40= \000\00000\000Attributable Level 3 cache access, read\000 */ -{ 1328 }, /* segment_reg_loads.any\000other\000Number of segment register = loads\000event=3D6,period=3D200000,umask=3D0x80\000\00000\000\000 */ +{ 1151 }, /* bp_l1_btb_correct\000branch\000L1 BTB Correction\000event=3D0= x8a\000\00000\000\000\000\000\000 */ +{ 1213 }, /* bp_l2_btb_correct\000branch\000L2 BTB Correction\000event=3D0= x8b\000\00000\000\000\000\000\000 */ +{ 1475 }, /* dispatch_blocked.any\000other\000Memory cluster signals to bl= ock micro-op dispatch for any reason\000event=3D9,period=3D200000,umask=3D0= x20\000\00000\000\000\000\000\000 */ +{ 1608 }, /* eist_trans\000other\000Number of Enhanced Intel SpeedStep(R) = Technology (EIST) transitions\000event=3D0x3a,period=3D200000\000\00000\000= \000\000\000\000 */ +{ 1275 }, /* l3_cache_rd\000cache\000L3 cache access, read\000event=3D0x40= \000\00000\000\000\000\000Attributable Level 3 cache access, read\000 */ +{ 1373 }, /* segment_reg_loads.any\000other\000Number of segment register = loads\000event=3D6,period=3D200000,umask=3D0x80\000\00000\000\000\000\000\0= 00 */ }; static const struct compact_pmu_event pmu_events__test_soc_cpu_hisi_sccl_d= drc[] =3D { -{ 1687 }, /* uncore_hisi_ddrc.flux_wcmd\000uncore\000DDRC write commands\0= 00event=3D2\000\00000\000DDRC write commands\000 */ +{ 1741 }, /* uncore_hisi_ddrc.flux_wcmd\000uncore\000DDRC write commands\0= 00event=3D2\000\00000\000\000\000\000DDRC write commands\000 */ }; static const struct compact_pmu_event pmu_events__test_soc_cpu_hisi_sccl_l= 3c[] =3D { -{ 2166 }, /* uncore_hisi_l3c.rd_hit_cpipe\000uncore\000Total read hits\000= event=3D7\000\00000\000Total read hits\000 */ +{ 2232 }, /* uncore_hisi_l3c.rd_hit_cpipe\000uncore\000Total read hits\000= event=3D7\000\00000\000\000\000\000Total read hits\000 */ }; static const struct compact_pmu_event pmu_events__test_soc_cpu_uncore_cbox= [] =3D { -{ 2016 }, /* event-hyphen\000uncore\000UNC_CBO_HYPHEN\000event=3D0xe0\000\= 00000\000UNC_CBO_HYPHEN\000 */ -{ 2081 }, /* event-two-hyph\000uncore\000UNC_CBO_TWO_HYPH\000event=3D0xc0\= 000\00000\000UNC_CBO_TWO_HYPH\000 */ -{ 1785 }, /* unc_cbo_xsnp_response.miss_eviction\000uncore\000A cross-core= snoop resulted from L3 Eviction which misses in some processor core\000eve= nt=3D0x22,umask=3D0x81\000\00000\000A cross-core snoop resulted from L3 Evi= ction which misses in some processor core\000 */ +{ 2076 }, /* event-hyphen\000uncore\000UNC_CBO_HYPHEN\000event=3D0xe0\000\= 00000\000\000\000\000UNC_CBO_HYPHEN\000 */ +{ 2144 }, /* event-two-hyph\000uncore\000UNC_CBO_TWO_HYPH\000event=3D0xc0\= 000\00000\000\000\000\000UNC_CBO_TWO_HYPH\000 */ +{ 1842 }, /* unc_cbo_xsnp_response.miss_eviction\000uncore\000A cross-core= snoop resulted from L3 Eviction which misses in some processor core\000eve= nt=3D0x22,umask=3D0x81\000\00000\000\000\000\000A cross-core snoop resulted= from L3 Eviction which misses in some processor core\000 */ }; static const struct compact_pmu_event pmu_events__test_soc_cpu_uncore_imc[= ] =3D { -{ 2376 }, /* uncore_imc.cache_hits\000uncore\000Total cache hits\000event= =3D0x34\000\00000\000Total cache hits\000 */ +{ 2448 }, /* uncore_imc.cache_hits\000uncore\000Total cache hits\000event= =3D0x34\000\00000\000\000\000\000Total cache hits\000 */ }; static const struct compact_pmu_event pmu_events__test_soc_cpu_uncore_imc_= free_running[] =3D { -{ 2270 }, /* uncore_imc_free_running.cache_miss\000uncore\000Total cache m= isses\000event=3D0x12\000\00000\000Total cache misses\000 */ +{ 2339 }, /* uncore_imc_free_running.cache_miss\000uncore\000Total cache m= isses\000event=3D0x12\000\00000\000\000\000\000Total cache misses\000 */ =20 }; =20 @@ -129,51 +129,51 @@ const struct pmu_table_entry pmu_events__test_soc_cpu= [] =3D { { .entries =3D pmu_events__test_soc_cpu_default_core, .num_entries =3D ARRAY_SIZE(pmu_events__test_soc_cpu_default_core), - .pmu_name =3D { 1102 /* default_core\000 */ }, + .pmu_name =3D { 1138 /* default_core\000 */ }, }, { .entries =3D pmu_events__test_soc_cpu_hisi_sccl_ddrc, .num_entries =3D ARRAY_SIZE(pmu_events__test_soc_cpu_hisi_sccl_ddrc), - .pmu_name =3D { 1672 /* hisi_sccl,ddrc\000 */ }, + .pmu_name =3D { 1726 /* hisi_sccl,ddrc\000 */ }, }, { .entries =3D pmu_events__test_soc_cpu_hisi_sccl_l3c, .num_entries =3D ARRAY_SIZE(pmu_events__test_soc_cpu_hisi_sccl_l3c), - .pmu_name =3D { 2152 /* hisi_sccl,l3c\000 */ }, + .pmu_name =3D { 2218 /* hisi_sccl,l3c\000 */ }, }, { .entries =3D pmu_events__test_soc_cpu_uncore_cbox, .num_entries =3D ARRAY_SIZE(pmu_events__test_soc_cpu_uncore_cbox), - .pmu_name =3D { 1773 /* uncore_cbox\000 */ }, + .pmu_name =3D { 1830 /* uncore_cbox\000 */ }, }, { .entries =3D pmu_events__test_soc_cpu_uncore_imc, .num_entries =3D ARRAY_SIZE(pmu_events__test_soc_cpu_uncore_imc), - .pmu_name =3D { 2365 /* uncore_imc\000 */ }, + .pmu_name =3D { 2437 /* uncore_imc\000 */ }, }, { .entries =3D pmu_events__test_soc_cpu_uncore_imc_free_running, .num_entries =3D ARRAY_SIZE(pmu_events__test_soc_cpu_uncore_imc_free_= running), - .pmu_name =3D { 2246 /* uncore_imc_free_running\000 */ }, + .pmu_name =3D { 2315 /* uncore_imc_free_running\000 */ }, }, }; =20 static const struct compact_pmu_event pmu_metrics__test_soc_cpu_default_co= re[] =3D { -{ 2798 }, /* CPI\000\0001 / IPC\000\000\000\000\000\000\000\00000 */ -{ 3479 }, /* DCache_L2_All\000\000DCache_L2_All_Hits + DCache_L2_All_Miss\= 000\000\000\000\000\000\000\00000 */ -{ 3251 }, /* DCache_L2_All_Hits\000\000l2_rqsts.demand_data_rd_hit + l2_rq= sts.pf_hit + l2_rqsts.rfo_hit\000\000\000\000\000\000\000\00000 */ -{ 3345 }, /* DCache_L2_All_Miss\000\000max(l2_rqsts.all_demand_data_rd - l= 2_rqsts.demand_data_rd_hit, 0) + l2_rqsts.pf_miss + l2_rqsts.rfo_miss\000\0= 00\000\000\000\000\000\00000 */ -{ 3543 }, /* DCache_L2_Hits\000\000d_ratio(DCache_L2_All_Hits, DCache_L2_A= ll)\000\000\000\000\000\000\000\00000 */ -{ 3611 }, /* DCache_L2_Misses\000\000d_ratio(DCache_L2_All_Miss, DCache_L2= _All)\000\000\000\000\000\000\000\00000 */ -{ 2883 }, /* Frontend_Bound_SMT\000\000idq_uops_not_delivered.core / (4 * = (cpu_clk_unhalted.thread / 2 * (1 + cpu_clk_unhalted.one_thread_active / cp= u_clk_unhalted.ref_xclk)))\000\000\000\000\000\000\000\00000 */ -{ 2820 }, /* IPC\000group1\000inst_retired.any / cpu_clk_unhalted.thread\0= 00\000\000\000\000\000\000\00000 */ -{ 3745 }, /* L1D_Cache_Fill_BW\000\00064 * l1d.replacement / 1e9 / duratio= n_time\000\000\000\000\000\000\000\00000 */ -{ 3681 }, /* M1\000\000ipc + M2\000\000\000\000\000\000\000\00000 */ -{ 3703 }, /* M2\000\000ipc + M1\000\000\000\000\000\000\000\00000 */ -{ 3725 }, /* M3\000\0001 / M3\000\000\000\000\000\000\000\00000 */ -{ 3180 }, /* cache_miss_cycles\000group1\000dcache_miss_cpi + icache_miss_= cycles\000\000\000\000\000\000\000\00000 */ -{ 3049 }, /* dcache_miss_cpi\000\000l1d\\-loads\\-misses / inst_retired.an= y\000\000\000\000\000\000\000\00000 */ -{ 3113 }, /* icache_miss_cycles\000\000l1i\\-loads\\-misses / inst_retired= .any\000\000\000\000\000\000\000\00000 */ +{ 2882 }, /* CPI\000\0001 / IPC\000\000\000\000\000\000\000\00000 */ +{ 3563 }, /* DCache_L2_All\000\000DCache_L2_All_Hits + DCache_L2_All_Miss\= 000\000\000\000\000\000\000\00000 */ +{ 3335 }, /* DCache_L2_All_Hits\000\000l2_rqsts.demand_data_rd_hit + l2_rq= sts.pf_hit + l2_rqsts.rfo_hit\000\000\000\000\000\000\000\00000 */ +{ 3429 }, /* DCache_L2_All_Miss\000\000max(l2_rqsts.all_demand_data_rd - l= 2_rqsts.demand_data_rd_hit, 0) + l2_rqsts.pf_miss + l2_rqsts.rfo_miss\000\0= 00\000\000\000\000\000\00000 */ +{ 3627 }, /* DCache_L2_Hits\000\000d_ratio(DCache_L2_All_Hits, DCache_L2_A= ll)\000\000\000\000\000\000\000\00000 */ +{ 3695 }, /* DCache_L2_Misses\000\000d_ratio(DCache_L2_All_Miss, DCache_L2= _All)\000\000\000\000\000\000\000\00000 */ +{ 2967 }, /* Frontend_Bound_SMT\000\000idq_uops_not_delivered.core / (4 * = (cpu_clk_unhalted.thread / 2 * (1 + cpu_clk_unhalted.one_thread_active / cp= u_clk_unhalted.ref_xclk)))\000\000\000\000\000\000\000\00000 */ +{ 2904 }, /* IPC\000group1\000inst_retired.any / cpu_clk_unhalted.thread\0= 00\000\000\000\000\000\000\00000 */ +{ 3829 }, /* L1D_Cache_Fill_BW\000\00064 * l1d.replacement / 1e9 / duratio= n_time\000\000\000\000\000\000\000\00000 */ +{ 3765 }, /* M1\000\000ipc + M2\000\000\000\000\000\000\000\00000 */ +{ 3787 }, /* M2\000\000ipc + M1\000\000\000\000\000\000\000\00000 */ +{ 3809 }, /* M3\000\0001 / M3\000\000\000\000\000\000\000\00000 */ +{ 3264 }, /* cache_miss_cycles\000group1\000dcache_miss_cpi + icache_miss_= cycles\000\000\000\000\000\000\000\00000 */ +{ 3133 }, /* dcache_miss_cpi\000\000l1d\\-loads\\-misses / inst_retired.an= y\000\000\000\000\000\000\000\00000 */ +{ 3197 }, /* icache_miss_cycles\000\000l1i\\-loads\\-misses / inst_retired= .any\000\000\000\000\000\000\000\00000 */ =20 }; =20 @@ -181,18 +181,18 @@ const struct pmu_table_entry pmu_metrics__test_soc_cp= u[] =3D { { .entries =3D pmu_metrics__test_soc_cpu_default_core, .num_entries =3D ARRAY_SIZE(pmu_metrics__test_soc_cpu_default_core), - .pmu_name =3D { 1102 /* default_core\000 */ }, + .pmu_name =3D { 1138 /* default_core\000 */ }, }, }; =20 static const struct compact_pmu_event pmu_events__test_soc_sys_uncore_sys_= ccn_pmu[] =3D { -{ 2565 }, /* sys_ccn_pmu.read_cycles\000uncore\000ccn read-cycles event\00= 0config=3D0x2c\0000x01\00000\000\000 */ +{ 2643 }, /* sys_ccn_pmu.read_cycles\000uncore\000ccn read-cycles event\00= 0config=3D0x2c\0000x01\00000\000\000\000\000\000 */ }; static const struct compact_pmu_event pmu_events__test_soc_sys_uncore_sys_= cmn_pmu[] =3D { -{ 2658 }, /* sys_cmn_pmu.hnf_cache_miss\000uncore\000Counts total cache mi= sses in first lookup result (high priority)\000eventid=3D1,type=3D5\000(434= |436|43c|43a).*\00000\000\000 */ +{ 2739 }, /* sys_cmn_pmu.hnf_cache_miss\000uncore\000Counts total cache mi= sses in first lookup result (high priority)\000eventid=3D1,type=3D5\000(434= |436|43c|43a).*\00000\000\000\000\000\000 */ }; static const struct compact_pmu_event pmu_events__test_soc_sys_uncore_sys_= ddr_pmu[] =3D { -{ 2473 }, /* sys_ddr_pmu.write_cycles\000uncore\000ddr write-cycles event\= 000event=3D0x2b\000v8\00000\000\000 */ +{ 2548 }, /* sys_ddr_pmu.write_cycles\000uncore\000ddr write-cycles event\= 000event=3D0x2b\000v8\00000\000\000\000\000\000 */ =20 }; =20 @@ -200,17 +200,17 @@ const struct pmu_table_entry pmu_events__test_soc_sys= [] =3D { { .entries =3D pmu_events__test_soc_sys_uncore_sys_ccn_pmu, .num_entries =3D ARRAY_SIZE(pmu_events__test_soc_sys_uncore_sys_ccn_p= mu), - .pmu_name =3D { 2546 /* uncore_sys_ccn_pmu\000 */ }, + .pmu_name =3D { 2624 /* uncore_sys_ccn_pmu\000 */ }, }, { .entries =3D pmu_events__test_soc_sys_uncore_sys_cmn_pmu, .num_entries =3D ARRAY_SIZE(pmu_events__test_soc_sys_uncore_sys_cmn_p= mu), - .pmu_name =3D { 2639 /* uncore_sys_cmn_pmu\000 */ }, + .pmu_name =3D { 2720 /* uncore_sys_cmn_pmu\000 */ }, }, { .entries =3D pmu_events__test_soc_sys_uncore_sys_ddr_pmu, .num_entries =3D ARRAY_SIZE(pmu_events__test_soc_sys_uncore_sys_ddr_p= mu), - .pmu_name =3D { 2454 /* uncore_sys_ddr_pmu\000 */ }, + .pmu_name =3D { 2529 /* uncore_sys_ddr_pmu\000 */ }, }, }; =20 @@ -316,6 +316,12 @@ static void decompress_event(int offset, struct pmu_ev= ent *pe) p++; pe->unit =3D (*p =3D=3D '\0' ? NULL : p); while (*p++); + pe->retirement_latency_mean =3D (*p =3D=3D '\0' ? NULL : p); + while (*p++); + pe->retirement_latency_min =3D (*p =3D=3D '\0' ? NULL : p); + while (*p++); + pe->retirement_latency_max =3D (*p =3D=3D '\0' ? NULL : p); + while (*p++); pe->long_desc =3D (*p =3D=3D '\0' ? NULL : p); } =20 diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jeven= ts.py index 7499a35bfadd..e3a55486c08e 100755 --- a/tools/perf/pmu-events/jevents.py +++ b/tools/perf/pmu-events/jevents.py @@ -47,6 +47,9 @@ _json_event_attributes =3D [ 'event', # Short things in alphabetical order. 'compat', 'deprecated', 'perpkg', 'unit', + # Retirement latency specific to Intel granite rapids currently. + 'retirement_latency_mean', 'retirement_latency_min', + 'retirement_latency_max', # Longer things (the last won't be iterated over during decompress). 'long_desc' ] @@ -341,6 +344,9 @@ class JsonEvent: self.perpkg =3D jd.get('PerPkg') self.aggr_mode =3D convert_aggr_mode(jd.get('AggregationMode')) self.deprecated =3D jd.get('Deprecated') + self.retirement_latency_mean =3D jd.get('RetirementLatencyMean') + self.retirement_latency_min =3D jd.get('RetirementLatencyMin') + self.retirement_latency_max =3D jd.get('RetirementLatencyMax') self.metric_name =3D jd.get('MetricName') self.metric_group =3D jd.get('MetricGroup') self.metricgroup_no_group =3D jd.get('MetricgroupNoGroup') diff --git a/tools/perf/pmu-events/pmu-events.h b/tools/perf/pmu-events/pmu= -events.h index 675562e6f770..a95fee561622 100644 --- a/tools/perf/pmu-events/pmu-events.h +++ b/tools/perf/pmu-events/pmu-events.h @@ -47,6 +47,9 @@ struct pmu_event { const char *long_desc; const char *pmu; const char *unit; + const char *retirement_latency_mean; + const char *retirement_latency_min; + const char *retirement_latency_max; bool perpkg; bool deprecated; }; diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index aae431d63d64..42dcadfef8ce 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -177,6 +177,12 @@ struct evsel { /* For tool events */ /* Beginning time subtracted when the counter is read. */ union { + /* Defaults for retirement latency events. */ + struct _retirement_latency { + double mean; + double min; + double max; + } retirement_latency; /* duration_time is a single global time. */ __u64 start_time; /* diff --git a/tools/perf/util/intel-tpebs.c b/tools/perf/util/intel-tpebs.c index 6b00bd5b0af1..467d990d09ce 100644 --- a/tools/perf/util/intel-tpebs.c +++ b/tools/perf/util/intel-tpebs.c @@ -514,27 +514,49 @@ int evsel__tpebs_read(struct evsel *evsel, int cpu_ma= p_idx, int thread) * process. Allow the sample reader a chance to read by releasing and * reacquiring the lock. */ - if (&t->nd =3D=3D tpebs_results.next) { + if (t && &t->nd =3D=3D tpebs_results.next) { ret =3D tpebs_send_record_cmd(EVLIST_CTL_CMD_PING_TAG); mutex_unlock(tpebs_mtx_get()); if (ret) return ret; mutex_lock(tpebs_mtx_get()); } - switch (tpebs_mode) { - case TPEBS_MODE__MIN: - val =3D rint(t->stats.min); - break; - case TPEBS_MODE__MAX: - val =3D rint(t->stats.max); - break; - case TPEBS_MODE__LAST: - val =3D t->last; - break; - default: - case TPEBS_MODE__MEAN: - val =3D rint(t->stats.mean); - break; + if (t =3D=3D NULL || t->stats.n =3D=3D 0) { + /* No sample data, use default. */ + if (tpebs_recording) { + pr_warning_once( + "Using precomputed retirement latency data as no samples\n"); + } + val =3D 0; + switch (tpebs_mode) { + case TPEBS_MODE__MIN: + val =3D rint(evsel->retirement_latency.min); + break; + case TPEBS_MODE__MAX: + val =3D rint(evsel->retirement_latency.max); + break; + default: + case TPEBS_MODE__LAST: + case TPEBS_MODE__MEAN: + val =3D rint(evsel->retirement_latency.mean); + break; + } + } else { + switch (tpebs_mode) { + case TPEBS_MODE__MIN: + val =3D t->stats.min; + break; + case TPEBS_MODE__MAX: + val =3D t->stats.max; + break; + case TPEBS_MODE__LAST: + val =3D t->last; + break; + default: + case TPEBS_MODE__MEAN: + val =3D rint(t->stats.mean); + break; + } } mutex_unlock(tpebs_mtx_get()); =20 diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 5152fd5a6ead..89708d1769c8 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -1539,6 +1539,10 @@ static int parse_events_add_pmu(struct parse_events_= state *parse_state, evsel->scale =3D info.scale; evsel->per_pkg =3D info.per_pkg; evsel->snapshot =3D info.snapshot; + evsel->retirement_latency.mean =3D info.retirement_latency_mean; + evsel->retirement_latency.min =3D info.retirement_latency_min; + evsel->retirement_latency.max =3D info.retirement_latency_max; + return 0; } =20 diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index b7ebac5ab1d1..bbb906bb2159 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -77,6 +77,12 @@ struct perf_pmu_alias { char unit[UNIT_MAX_LEN+1]; /** @scale: Value to scale read counter values by. */ double scale; + /** @retirement_latency_mean: Value to be given for unsampled retirement = latency mean. */ + double retirement_latency_mean; + /** @retirement_latency_min: Value to be given for unsampled retirement l= atency min. */ + double retirement_latency_min; + /** @retirement_latency_max: Value to be given for unsampled retirement l= atency max. */ + double retirement_latency_max; /** * @per_pkg: Does the file * /bus/event_source/devices//events/.per-pkg or @@ -257,7 +263,7 @@ static int pmu_format(struct perf_pmu *pmu, int dirfd, = const char *name, bool ea return 0; } =20 -int perf_pmu__convert_scale(const char *scale, char **end, double *sval) +static int parse_double(const char *scale, char **end, double *sval) { char *lc; int ret =3D 0; @@ -294,6 +300,11 @@ int perf_pmu__convert_scale(const char *scale, char **= end, double *sval) return ret; } =20 +int perf_pmu__convert_scale(const char *scale, char **end, double *sval) +{ + return parse_double(scale, end, sval); +} + static int perf_pmu__parse_scale(struct perf_pmu *pmu, struct perf_pmu_ali= as *alias) { struct stat st; @@ -525,6 +536,18 @@ static int update_alias(const struct pmu_event *pe, if (!ret) snprintf(data->alias->unit, sizeof(data->alias->unit), "%s", unit); } + if (!ret && pe->retirement_latency_mean) { + ret =3D parse_double(pe->retirement_latency_mean, NULL, + &data->alias->retirement_latency_mean); + } + if (!ret && pe->retirement_latency_min) { + ret =3D parse_double(pe->retirement_latency_min, NULL, + &data->alias->retirement_latency_min); + } + if (!ret && pe->retirement_latency_max) { + ret =3D parse_double(pe->retirement_latency_max, NULL, + &data->alias->retirement_latency_max); + } return ret; } =20 @@ -533,7 +556,7 @@ static int perf_pmu__new_alias(struct perf_pmu *pmu, co= nst char *name, const struct pmu_event *pe, enum event_source src) { struct perf_pmu_alias *alias; - int ret; + int ret =3D 0; const char *long_desc =3D NULL, *topic =3D NULL, *unit =3D NULL, *pmu_nam= e =3D NULL; bool deprecated =3D false, perpkg =3D false; =20 @@ -562,6 +585,24 @@ static int perf_pmu__new_alias(struct perf_pmu *pmu, c= onst char *name, alias->per_pkg =3D perpkg; alias->snapshot =3D false; alias->deprecated =3D deprecated; + alias->retirement_latency_mean =3D 0.0; + alias->retirement_latency_min =3D 0.0; + alias->retirement_latency_max =3D 0.0; + + if (!ret && pe && pe->retirement_latency_mean) { + ret =3D parse_double(pe->retirement_latency_mean, NULL, + &alias->retirement_latency_mean); + } + if (!ret && pe && pe->retirement_latency_min) { + ret =3D parse_double(pe->retirement_latency_min, NULL, + &alias->retirement_latency_min); + } + if (!ret && pe && pe->retirement_latency_max) { + ret =3D parse_double(pe->retirement_latency_max, NULL, + &alias->retirement_latency_max); + } + if (ret) + return ret; =20 ret =3D parse_events_terms(&alias->terms, val, val_fd); if (ret) { @@ -1678,6 +1719,9 @@ int perf_pmu__check_alias(struct perf_pmu *pmu, struc= t parse_events_terms *head_ info->unit =3D NULL; info->scale =3D 0.0; info->snapshot =3D false; + info->retirement_latency_mean =3D 0.0; + info->retirement_latency_min =3D 0.0; + info->retirement_latency_max =3D 0.0; =20 if (perf_pmu__is_hwmon(pmu)) { ret =3D hwmon_pmu__check_alias(head_terms, info, err); @@ -1711,6 +1755,10 @@ int perf_pmu__check_alias(struct perf_pmu *pmu, stru= ct parse_events_terms *head_ if (term->alternate_hw_config) *alternate_hw_config =3D term->val.num; =20 + info->retirement_latency_mean =3D alias->retirement_latency_mean; + info->retirement_latency_min =3D alias->retirement_latency_min; + info->retirement_latency_max =3D alias->retirement_latency_max; + list_del_init(&term->list); parse_events_term__delete(term); } diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index b93014cc3670..13dd3511f504 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -194,6 +194,9 @@ struct perf_pmu { struct perf_pmu_info { const char *unit; double scale; + double retirement_latency_mean; + double retirement_latency_min; + double retirement_latency_max; bool per_pkg; bool snapshot; }; --=20 2.49.0.604.gff1f9ca942-goog From nobody Fri Dec 19 17:37:02 2025 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0BA9828B4F5 for ; Mon, 14 Apr 2025 17:42:27 +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=1744652550; cv=none; b=csecBk6Gnag3yO+2DtT4ZnHaQeHHI7CNqV5EgkQi3b6a4z+1l/v2tjEZ09NztOeDLitkbpPHlWmk1dNxWctfLv4Axdlqn2TzPAVTooRviy9xVDugeXu86yUVeQrB7WLgCzxHT0kbwFuqWYYmIEA4vp5eM5k1+9t29TXFNSaTs5Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744652550; c=relaxed/simple; bh=SomKEZjiqnP411eTa4RWzo05FrdFH31Ut1NNYLapab0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=MpHjoKIkjzpe4g8l8LnEfyj82mHDBU4OXRi6a+qjnL9TS3qiq6eEfz1XBSEyIvRKUtCcQb8OajohX1Rk+gD6ZdJomDXm3EkkWhV4VxKlo6xYuiYe6u/DKI1aOsV3kt5h4hoJgK5zEYXbr4n0/sRX/N7fFMTV7r6VI8oLnxtTqiw= 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=Q8ByRYu/; 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="Q8ByRYu/" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-3054210ce06so6124239a91.2 for ; Mon, 14 Apr 2025 10:42:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1744652547; x=1745257347; 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=272QWo3N2/8KrEceZ3Y5V9F3EMqW3wkjRAZ/C8l8AXw=; b=Q8ByRYu/GyN3qm1uj2L6QTGrVdUP+WIyeM2J90C6uEsFKqo8Omz3cL1XUJwWScr40n p4YKzbHZ3j6QJePcngS6WVM4OBpzgTsY/I4HmnyT90SGePg0X8eAKv0qrknX9Hiuut2o dC/qWypLVhilMcFdcdrpquRuiJ8FDO4k4e2Rik3BamA+0GYGrqFmTvDX0edhPUcKupj7 P4w6L7BPflFrNJfh9o3Hg0QW9XX5R7Bz6bWKqgWQKXuTZIx3SS0rrkN29Da3zGsEymMN A77CszdwUT693YBTRIuSek8HVLtJPg3lhunum7k/Q8eGemXIzmeqnfIgsNfRmlFEIKki 6kzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744652547; x=1745257347; 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=272QWo3N2/8KrEceZ3Y5V9F3EMqW3wkjRAZ/C8l8AXw=; b=HS/NXxU0bIJh0CfwkASmj9d/zqjDE6YZOQjW98zclRbFJjc+t1KkSunzN+ae3eRKzN 4w+DPCXBs6RIxAJeMctX1UF8hPrsz3e6zs2qLTZNWiCy4RXUgxL20L1QWh3XnixFdOL+ fLlaeVu1rRRAeZjFAuLA++pELXkotjEo5AFJkdE0HzTA0b9rbiyIypXpxDMsqOZGGW5L Q3JwB/iJgjGaChoD62zSaTMSwPh9IKDZAKzV0hhRL5TaqNtqwJS6Aaa5fAgH7LsrIe38 r0l8p22HidpOnmeCEBHszWwFlAJd8T95O/cUDsBTR4SLntFVP/Z6oqAkaYJzorIvaxXz vrBA== X-Forwarded-Encrypted: i=1; AJvYcCUcTOX0g5dEmAbPvomKhpIX7Qm1g1MimWY/6vwFMVEknH6X+4ounK0b3CIMJlnNzoeOqA/eRp/AVrW3tGU=@vger.kernel.org X-Gm-Message-State: AOJu0YzfSOwF3nTOivazfhvl6w9X0CfWzpiRcqzrHqRb0ePSDZfqxujg T5HZ72bruailpsH2Cv4+YbjOTSdiKx87jSS0JgcaPEpk7wjIt+wDmW0fbzQ1VJdP9aTav4oem0H owZ7wNw== X-Google-Smtp-Source: AGHT+IHKQXzYZsPd1emW5mymOx2ih0yymDwCa7QOwk9ye4CQI309sFEd4KkK0iKEkR0PdlCtKrtXkduqPk5D X-Received: from pji15.prod.google.com ([2002:a17:90b:3fcf:b0:2fa:1803:2f9f]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:58eb:b0:2fa:1851:a023 with SMTP id 98e67ed59e1d1-30823784865mr20250837a91.35.1744652547187; Mon, 14 Apr 2025 10:42:27 -0700 (PDT) Date: Mon, 14 Apr 2025 10:41:34 -0700 In-Reply-To: <20250414174134.3095492-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: <20250414174134.3095492-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.604.gff1f9ca942-goog Message-ID: <20250414174134.3095492-17-irogers@google.com> Subject: [PATCH v5 16/16] perf record: Retirement latency cleanup in evsel__config From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , "=?UTF-8?q?Andreas=20F=C3=A4rber?=" , Manivannan Sadhasivam , Maxime Coquelin , Alexandre Torgue , Caleb Biggers , Weilin Wang , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Perry Taylor , Thomas Falcon Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Perf record will fail with retirement latency events as the open doesn't do a perf_event_open system call. Use evsel__config to set up such events for recording by removing the flag and enabling sample weights - the sample weights containing the retirement latency. Signed-off-by: Ian Rogers Tested-by: Weilin Wang Acked-by: Namhyung Kim Reviewed-by: Kan Liang --- tools/perf/util/evsel.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 661a07cbdb25..6a84893e3c58 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1440,9 +1440,10 @@ void evsel__config(struct evsel *evsel, struct recor= d_opts *opts, attr->branch_sample_type =3D opts->branch_stack; } =20 - if (opts->sample_weight) + if (opts->sample_weight || evsel->retire_lat) { arch_evsel__set_sample_weight(evsel); - + evsel->retire_lat =3D false; + } attr->task =3D track; attr->mmap =3D track; attr->mmap2 =3D track && !perf_missing_features.mmap2; --=20 2.49.0.604.gff1f9ca942-goog