From nobody Sun Feb 8 02:56:36 2026 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 952E0183CB0 for ; Mon, 7 Apr 2025 05:01:11 +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=1744002073; cv=none; b=jRqJRXnzZ/1vBZ0Hz9h8XiMLh+qKFTtE4e4aAf/SA8rZM9UN7aRoDr5lP3zfF9vtAYmRIfetbKQjakbiuGfVuUsiXqDSafAunR6zF2vGWP7VxNo5on92n6LhRx9k+kPIIJKPWPHxAnloQzLzQQebmvG5GDtb9FzwyF6NCv8d8x0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744002073; c=relaxed/simple; bh=oTGRBpcL/2sIHNUD+/BM6BV/LmnMI5XK3yo3xDS6KyQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=lcroLb3h1X2J7J5sGEGmLXUQgYpPJo3lEMLbc86TNyO7x9K7efbVH6NDRxCJJQsduH4wbEx+FVG6/9z/77MHxHhlI1fzicALUJCcPFjJatwgIN8zyaRUN1vIgD0k+9wmloQ4Di9w6g5tWG51vKLX+PezmXXtaTnIiBFyWiPZqFg= 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=OOrxBJBa; 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="OOrxBJBa" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-225505d1ca5so33478175ad.2 for ; Sun, 06 Apr 2025 22:01:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1744002071; x=1744606871; 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=pClnDyLnT+OkOC5ziZK4pcS5wTXzmuK+3iocOmka5vs=; b=OOrxBJBa5y8DxC9IHKI8LS2ReAl02ZJXELuGJau/kfwRoTlWFNmll+iOlgA6a4INqe da2YGLRGLak3OgvEG6ifVsaANBbm6ZtF4yyFwHDBuwwXlTPCLEIn172TLWQYuWXKAw/f nbPHdbHY/r8B/LvdZt6e++Ii2qE6AL543HSyxPx1jcQHYy2FVq7VWDy4JUYA/zo4DVdq t96gYbkm0H2AtFugVFz4rxAbIRHjZVfuOR45o81qtJJ1YXBIW6Byw+UlQ/H/5+zOjtsY HncLl+frBUux+4v5SDoCZ83MM11cT+E/5JnVH42bsBk1GJ0ux1tCb4azWVbDTKOIjkyX l1sw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744002071; x=1744606871; 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=pClnDyLnT+OkOC5ziZK4pcS5wTXzmuK+3iocOmka5vs=; b=mTy/74fVrmskQKDpOiMbtVxHhtLGHgAsfF8yc0+rYnfxblYBrkPUTxAbsUH3QRsvH5 Mn+MOOiyhgC8QKjXK8ZB2suk1Av9XMsAfYw3mJH0TYmeiMhRodYWiRckZJydz7G0tfE/ TM8LZCdTfHCXIpfyriWbpcThw9Nn6REh3/cRkHEoe+vjwZv+CJQTUHhvaNMtjJcckd8o a7kMCee/2IYnKPOJ0yFOsenIyJ3rb8/xLQtxWwwDcWsN31csiYO3iEJK22fR1GFG36kF 33gUAVkm0IsY/MkMOWB592f7f3yoai21i//RTSN5brzQeZBqIolGdLRb3wtIC53mgUNn MN5A== X-Forwarded-Encrypted: i=1; AJvYcCVwGp3Mdfl99z8DcFO/4Oc8BQ5xRP2mJwvXGoYY1WGLnQGWubd/rHUIVIyeZMjWundt4Vb4QXLPKY9p3fE=@vger.kernel.org X-Gm-Message-State: AOJu0YzSC2+f8ccp1Jwrl4S0TNEIDQKy/ZtQWWEnHeYZK7IVlqiSkcnG 0Q89Il9dQ86QUmO43ZVq3VhaEQXEZ6RgtdDcwhC0/Fal9D/Cuz9z5gS6Eq4A3AqrardjwYWGl9l WyPZo/w== X-Google-Smtp-Source: AGHT+IHtXYrhzXX5JxDuzoW7tJBuh4QL0x7CroaLG2+rZjoBqiO7OwMRkspeZawt4VsOgtX+FEZKpBCnt1kK X-Received: from plbmf5.prod.google.com ([2002:a17:902:fc85:b0:227:e538:4d17]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:d48a:b0:220:f7bb:842 with SMTP id d9443c01a7336-22a8a0b3707mr133401375ad.42.1744002070815; Sun, 06 Apr 2025 22:01:10 -0700 (PDT) Date: Sun, 6 Apr 2025 22:00:46 -0700 In-Reply-To: <20250407050101.1389825-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: <20250407050101.1389825-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.504.g3bcea36a83-goog Message-ID: <20250407050101.1389825-2-irogers@google.com> Subject: [PATCH v2 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 , Weilin Wang , James Clark , Xu Yang , John Garry , Howard Chu , Levi Yun , Dominique Martinet , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org 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 --- 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.504.g3bcea36a83-goog From nobody Sun Feb 8 02:56:36 2026 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7B9E0185B4C for ; Mon, 7 Apr 2025 05:01:13 +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=1744002075; cv=none; b=uOdN/uqVXIB4p3WyrUE8RCYiBKNIPfqDepp/MIu5sY6hFvy2Kjr910S1ssi3LOz4MhPIworgnIVI/WE4GGaiwzThyIwcswSrKW53oCLTKZCFKkTRZ8/UAQ5DsnVRlXFXxH9vVAZDhfPb6U2eu5mz3wcb3YF06gNGpUPIDSRdb38= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744002075; c=relaxed/simple; bh=ifUhHpvB3YWjewd+FCiG+bnPL8N1hMQyEOj1ALhK2zo=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=bJDcdTGCTLVgu/snFelOfRkyiHfaiMR9df53V19uU1C2yQxqx0xAFS7TJqwDrseyyGLX8EYdxn/U0Im3JgStnKG3c6Gi8UN3q4+7aKnolIRutaEi/EUCJELRXpD6MbjGQixc2R4X32BIsFknCkTXnvK7oxM7XTdky98VDaUdHsU= 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=twQf/uXz; 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="twQf/uXz" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-afd1e7f52f7so890571a12.1 for ; Sun, 06 Apr 2025 22:01:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1744002073; x=1744606873; 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=Kljzr7zwrGyBJiGR5feDDMzqEBYffKkoUZPkiCSQTN4=; b=twQf/uXzxXIf9QY9dl5uK5xQfd2qPgKQEhdQHWx6GqaEKh/DiXEwPSW0xBDDSjUesw kcwMz5uy1tIePEmcgAjn0J1kq1sdrtAjRJDS1+gwCTc0FDXxQ8CRwKgeFhtgK6ZTwMEl LMBq0GnttcEOOgzhLQgHVuQhfxTnS0I1mMsl+a0twno8jHAN7Gv96yyntIcq9muNcgEf /J+wWe6ycL1hsWU61NPMWC57Tftroz3/2vMofT1dg2fkQrAUcl1YL7EEAXEEKa5/WA/L Wo0aJ4xXpXCtr8OXGRKgt7N1q7U9bmD3Q+EjysXBD+tlifrI6fwDHAdRzY21ya7CFtKj BEqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744002073; x=1744606873; 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=Kljzr7zwrGyBJiGR5feDDMzqEBYffKkoUZPkiCSQTN4=; b=EGtR4boSlhtD348OZ+CVHqpxt1bcK+OfbTBefsBIBN6JSdtrvhrB0C9ruyaxU2wh6O +ExHOxHRUrcAFFygW43i+crZ+Wjb8lyD7f0CHncX1SMuJt1oQJOE+Tuw26qv3AmoZhnh PPZszAa9V1eUh8gYiyY7WDVAL6K7VE7UdF3VgvPE+RFTMnb63QTTZPgpTWiDjfHZISgK ptKDzE9/W3w7ni9tw86jPzs7bvm6+bjnl9CwgD+8E+kqiU0Aow9kFgERaTznbVOFNXO4 HQ527fg0zjw8qiWiL7qraulMnGwjtnOs3zyVEvKOo4/x8Ly9srTJ1q0/PvOUqz9m6NYn wz3w== X-Forwarded-Encrypted: i=1; AJvYcCUdV0KbIkkL3f01fh9I6/JOFvW/xFNOVlV2/0pg3NPBMVuv0X8Rw98saiqU/8BFdcdHN4Y3RtdfnUmvbes=@vger.kernel.org X-Gm-Message-State: AOJu0Yyu0srMCHw672IiCsKEF5PNpBWyu0JA2m6KPgUJxhooXJUrprt/ vfTHAcSfq4EXlgMjfgOQ1ovg7r2MfPb71OYs+I5aXJpZg2UJhJF+fhKq0ECU6gH9hsSmk9gYGea ElK1PAQ== X-Google-Smtp-Source: AGHT+IGXOEpn+ENpgqWaSgghPpFJxN+0lXMimIDgaO3K2fwkBbHciFVHEAl+hivZM8eAmZAhQfPo2toYXBqQ X-Received: from plbh6.prod.google.com ([2002:a17:902:eec6:b0:223:536f:9461]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:f64e:b0:21f:6546:9af0 with SMTP id d9443c01a7336-22a8a0b38b2mr172584875ad.44.1744002072672; Sun, 06 Apr 2025 22:01:12 -0700 (PDT) Date: Sun, 6 Apr 2025 22:00:47 -0700 In-Reply-To: <20250407050101.1389825-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: <20250407050101.1389825-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.504.g3bcea36a83-goog Message-ID: <20250407050101.1389825-3-irogers@google.com> Subject: [PATCH v2 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 , Weilin Wang , James Clark , Xu Yang , John Garry , Howard Chu , Levi Yun , Dominique Martinet , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org 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 --- 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.504.g3bcea36a83-goog From nobody Sun Feb 8 02:56:36 2026 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 366162222CB for ; Mon, 7 Apr 2025 05:01:15 +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=1744002076; cv=none; b=j1zw7+WUsNDw7RQARlsg4T7mLRDD/dJJ2lKtANsQfAExKtVYkPEX+neA4CvE4VrBrk39Oev+ETqQrA1HYcVeR6OVzMTbQ63EpHSoPmtvzKtaTum+v155k84YHQRrt9xsx/BNNGT+usKAwmeuKSElxOOU2Q8da4mcxXkPMbA5oZk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744002076; c=relaxed/simple; bh=2l/1oKHeKrpT+PnW/axoFCb0/bWcsP4vJAsPyglQu90=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=FpclGHp5hEndFJThFH4iE56Yhz123r0Hs31prh37codEEOlceA+ZjBo2t+psfeAlgslAuVdhfS7f7a4ZZcE3G6aEguf+ZDAMOH2WDAKGrhXbNZfoRrI6r2AQ4LVmZtXWZfbILaw/FtLAprhvtWpI68GZeeZ/f1T+U55/q7KYD9Y= 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=nDQEbHHj; 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="nDQEbHHj" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-2ff68033070so3639846a91.2 for ; Sun, 06 Apr 2025 22:01:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1744002074; x=1744606874; 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=n0w8p9z7uIDU2rw9JTfItdCw1PZrvXFzExYD6rhP3a4=; b=nDQEbHHjeYO8eNhBLLmjWQXpwkX7vb1QMh0E4lBSoJY8gc8X8VaScI8EnoYmQ8mMts yxgGXCm+PJzCPkxSYZEmu1uVADJHbb3DeccdY0QWQOd28xzTVKgLkiR6wruIQwubO+oP sNwJS3d/Ugs5Z+6PCSE4IUIiiY+iMGGzFQ6zkzwuH40xvMKLaPWlPrzZpBU298hfy3y6 PFdN//8GWs0I/T3fs5wQFiB6TYqhafBer6IFjsklC1FO/IaEAJgTMxrlGEnW/FVYoy3y isY296/VG2Ke5C9Q0FVJPQ7+AnNplgyovrqBDWhalhoGBZQkHdKgpGhaFDNbVvFLVmwy rb6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744002074; x=1744606874; 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=n0w8p9z7uIDU2rw9JTfItdCw1PZrvXFzExYD6rhP3a4=; b=gcTMvZx69Etf0M78TjR8Owy7NqgXsQ4Idxim5fJNb44ff3Rq+070IgyH8M4AXvCCV/ W0WPxZd5YDn3Sk033weVTQejRUQIAoHYhCUrYLsLY1goQHmAotiJbD0Oy6XcAwusWQEZ 8yqNIylNZW3N68peN576oWocI9ZJQiRuB5BAmA204vXx2lHThGiTT/jZHx469jBWI7Pw BBMJKqwr79ARbYkma2SRfo+66iO1q3MN0Mhhdghw7Ymhs2+po7tBFojiPzXPjr1Hg2O3 Q4V1DETd0nMwb98T6MVwPLEEppxxfsF24tkQuIj47T0uGcJvLrCgzwfcTaGYAy7SAQla GnYQ== X-Forwarded-Encrypted: i=1; AJvYcCWCJ3fFlecnG+E2doRkfK8oB/eKaqJUmkuV0RiNnecFYYvBFWNbssdo01kH92WmBJQhvd3BRoaXIgqQgfQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yx7E2SGdq3FdAlwTq94EDtFwNBWno6lA3MhfWNO73cEvTj9+55J 0s2R8yCMrCeBlgpr92ET3EN0LOTFSsJHcowPOc+f7sGOUiGmeCbxbmCEylOr+IOVVl0QvL2GygD SPG+vGQ== X-Google-Smtp-Source: AGHT+IG8N3mPKXVD522zb67He0muPojk2SfhipQ3PxfaRroQ1AwtdR8vbE1Fb2RtpQ4hzJgmoSEnQC3M0COC X-Received: from pjbsz6.prod.google.com ([2002:a17:90b:2d46:b0:2fe:800f:23a]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:2709:b0:2f9:c139:b61f with SMTP id 98e67ed59e1d1-306a48650dfmr18771002a91.14.1744002074573; Sun, 06 Apr 2025 22:01:14 -0700 (PDT) Date: Sun, 6 Apr 2025 22:00:48 -0700 In-Reply-To: <20250407050101.1389825-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: <20250407050101.1389825-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.504.g3bcea36a83-goog Message-ID: <20250407050101.1389825-4-irogers@google.com> Subject: [PATCH v2 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 , Weilin Wang , James Clark , Xu Yang , John Garry , Howard Chu , Levi Yun , Dominique Martinet , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org 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 --- 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.504.g3bcea36a83-goog From nobody Sun Feb 8 02:56:36 2026 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 36B2D222572 for ; Mon, 7 Apr 2025 05:01:17 +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=1744002079; cv=none; b=djhwq3ITrCJE/hFTdMOPFFD7JrcI5ZGQfvv7Hb00nJttsjObaLKBRkMXuZFPwHyOh20FwUk9XKw6bHfMHzQdIwDYUVKizZQORMdzhKnw/PJ1bPUcBeEOGwc8LC4sNSu6CE/+bZpljVgeQ7326rozXogwGAywRh0Rtm7x9yLD3AM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744002079; c=relaxed/simple; bh=JVanJEDpcMknG2x/X1wULUkE8JUqUZb8O7VIacDzqk4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=HHp4VWp1BGIJQ5nIQEBqDOIQzb+o1tL4qqOtrg+OjvnNydZGX2jqrhEl8U/HGGmXoCeefvYYJm+D8VMBvGWNcaqzrZiR5x1u3q+vBO1PCv6FGgBwRB/AbN7fDwgSWT8OEr0e6U9fkYraRebsr9+38wdOwlXQUansMXbyJDeYkY0= 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=Jg8hfxpN; 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="Jg8hfxpN" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-2ff8340d547so3624792a91.2 for ; Sun, 06 Apr 2025 22:01:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1744002076; x=1744606876; 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=EpNqTL2jhuFhMzQj4yTZFm6mW4YS6L/CEY0JlzRGbe8=; b=Jg8hfxpNE4CLi29SwpOwcqjlLKR8J/0dgPLAPdhnnRzB+WY1l/RJhZ2Al9V8Tof5C2 Y42VfVVf3T0Jqv60mi2mgF8gIcDEPCSWsxd0lJx0pLfI1/pHT969synJO7noAtHti7Ra O8tsCPp5CXK0g/jToCi5jgt9GVU/ElxNWUUx5T+nC7CWdRrrGVKSX8OetBdSZIQVrA3C FWwnuJYM7VmNBGcFQdCoG6XJG28/w1dEVdL6CYCRDNX55MuPo75DrpvNaBH8OJCpAo3L QLXPKtDRUWMzuihylTT1FiHXrl1bfCos5DKstxbfWZVfTDPK0KWBOuWS0F0NvwLTIg1I 0RLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744002076; x=1744606876; 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=EpNqTL2jhuFhMzQj4yTZFm6mW4YS6L/CEY0JlzRGbe8=; b=wVQbxGndgSY5Q1cgcqQFvvPfq5B2K4IlhhYz5+6aYEV0uUs+6jvSVPiRX6GP7rJdff uATbF+h8KLXfEBx4SrcZZGjoLzPNMGZUIAF9jBK/oS3txlri2nRMLrKEOApE0kUw3N7q n6vUUtTROJApsbK8ln0IyRjtfGj8hTzb/eqReNB/sHCzca4fDD09mDSwLIceqHGg31u0 FC6kRUH7+4pY95fSYCoeiRSfLWhC1Uskg4/0D3+vTrtKc6CC4gkrAyrP/dVUsR0dqkbV XORoH8PoX7Yc7uYYFgSNSVMbqVGWi43rX/xHCdGNJ0yGKtRfS97+HsFqSEeyEB6OVxfp jMdw== X-Forwarded-Encrypted: i=1; AJvYcCUBjRFUx0CPbWbvPPmCNnQBhJ8Vr15Bkl2BfohmeEQhuTATTvbIz4OcEHqCus7qhjlk/5pKKPMjMtXX1+M=@vger.kernel.org X-Gm-Message-State: AOJu0YwisllAIm9oCvVbOqhJ3mkaIWUA7TppSOLAEsNLbvgactcW9EYo xBetYv784eCGESC6FmoQymgKT97p4i7zzBg1GP3ND1Io4DzuVZqmoaVM/+7yPpibDqeGe15GT+o BTuRvYw== X-Google-Smtp-Source: AGHT+IFVyCvW/Feca4p+3QkEEYUKy/g8V1QEEW2jH9+cPAXYC8KCcIe55abMoTfG5uAAP7CNk9mofbT8RVSJ X-Received: from pjn3.prod.google.com ([2002:a17:90b:5703:b0:301:1bf5:2f07]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:6d0:b0:2ee:e518:c1d8 with SMTP id 98e67ed59e1d1-306a491f86amr16428164a91.30.1744002076510; Sun, 06 Apr 2025 22:01:16 -0700 (PDT) Date: Sun, 6 Apr 2025 22:00:49 -0700 In-Reply-To: <20250407050101.1389825-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: <20250407050101.1389825-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.504.g3bcea36a83-goog Message-ID: <20250407050101.1389825-5-irogers@google.com> Subject: [PATCH v2 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 , Weilin Wang , James Clark , Xu Yang , John Garry , Howard Chu , Levi Yun , Dominique Martinet , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org 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 --- 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.504.g3bcea36a83-goog From nobody Sun Feb 8 02:56:36 2026 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E3EEF22259C for ; Mon, 7 Apr 2025 05:01:18 +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=1744002080; cv=none; b=KtCvDJsqoJVT4SHPBtQOrjhBhWv3o3yyalyAhO9lnRvt4RRGpvMBWkPsJjSLHiCKRUrDl/xcfGv2tUENvYlLaa/2FOPF/x+GwM+PyiD+KhkQknidmIC8pjdlbdPkFYCWwbqLTQZv9/LKu94gsQFpoiZSL4YmzwSGoD//51nkEVs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744002080; c=relaxed/simple; bh=yUglDtEpwZVjaGPveMCOEFvdP87AB0tTSBss9c6TB98=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=cZ3fsuBNh9sD4PgJy1q9WCzccFNQlwTLz1qHzL5WomFFKYOZ0s6PYbMxaxtODuP9JRb4b4SuWIqBFK6teUXCo3Hcyy74Xl+j5BffhnHPqEfzntpC0Rr8UeQrLUqC6DiXAQetMCea/xjweHO5NPXU63EGtKiIT60yc71r4OazVmc= 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=v2CEREzz; 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="v2CEREzz" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-22406ee0243so30707975ad.3 for ; Sun, 06 Apr 2025 22:01:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1744002078; x=1744606878; 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=XafRrptC07unstJw1HreG0n5lBFJ2gSj/BsZTF4fwvk=; b=v2CEREzzT0G1l1d2+QGgLHi8m0SEY9N2AELXY5mu43Mv+FWyni+zta4CYXkciJCupH AFdM6UBFYWE06GGGnpPXBAQq82y2RdBO0Burh7koshOdqnovR+R4p9/b5L7B1xOLN4Mq GbyZP+BeiZ/LXBBkwTcY/3B/5B9DomNExkttKhTBusNxnPfiPy6Unn/A3BYNvYtWVltt yciUT49BoaWgV3zg9qQVvqGvMqaQsyla+8KwPPy+Ux3AOn6O67UVYsdWHufLKAlE3MaB kd+RYnCMnpy9pmBjA+w5Om5iieDzDJoJLNF87wWAvZET28GAi9sTNXne7yyQuI6Jts5k 1YNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744002078; x=1744606878; 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=XafRrptC07unstJw1HreG0n5lBFJ2gSj/BsZTF4fwvk=; b=t+a85/PPzUUEazP0CIP4/BNfyBhw2BZCm8cPx0KCqiGzn3wDw9xnFRGSADr7eWr0uy XOjxlkR7NXEWD+xFQ1dI4ayMwdySo4Uq5bAQvzgxrhXhBeR2S/zaMt7ekcxywkoH6v93 ME9Gyo6HwxaiqpCA8bU/bYcyG+fBkJKN+rJHAoo+f2v84RLs8i/Fnz/5LQMpyyPOFQv8 KYdUjsB2QLtIlE4DxMiRt6SDi57PReWZskDtMwjnVcaulUuqmmc4Sca5O37JbYkugjcH lvXhEFrbxDB97/IfHxaGknEZc2L0zQZEpTb6QsQP0YiLHd2/R87osCZpcRo227z9GiRm uf0A== X-Forwarded-Encrypted: i=1; AJvYcCUFhxOlfUeBhXgGqNt6V4O+AjrJZpeW3z+t8OlnmeDReihUxj/6WyC7TeSVy8rkj2bbLhPQSD7LTUyBE+w=@vger.kernel.org X-Gm-Message-State: AOJu0YwWiSdpNwxJT8TdRkp0ex/DICu89e19QKT3nZ8dbiNvc8Tgsctx T8LsKLLRBPhwiTCk8yOuBGx1OtlCOJnz+e62HNUvLHlDoW2Xvwib+CtVds6R+sxyDgzx8RjXPJ8 mlfcIzA== X-Google-Smtp-Source: AGHT+IH+ztOPbx3Kmwe9F+goW9ZQVGpeYeUrP+qUHa4YPTewYdbk5u8w73AsM92dGciR8tHBXeL8YUcOoDgw X-Received: from pjbsk12.prod.google.com ([2002:a17:90b:2dcc:b0:2ff:5516:6add]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:d48d:b0:223:66bc:f1de with SMTP id d9443c01a7336-22a8a06b382mr147697185ad.21.1744002078144; Sun, 06 Apr 2025 22:01:18 -0700 (PDT) Date: Sun, 6 Apr 2025 22:00:50 -0700 In-Reply-To: <20250407050101.1389825-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: <20250407050101.1389825-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.504.g3bcea36a83-goog Message-ID: <20250407050101.1389825-6-irogers@google.com> Subject: [PATCH v2 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 , Weilin Wang , James Clark , Xu Yang , John Garry , Howard Chu , Levi Yun , Dominique Martinet , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org 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 --- 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.504.g3bcea36a83-goog From nobody Sun Feb 8 02:56:36 2026 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DF92D223335 for ; Mon, 7 Apr 2025 05:01:20 +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=1744002082; cv=none; b=r66gEPd1dVA41b1T1SabZBKGgNrpeWr3m/SlE9r3ZYNP7eCGIlm8JGUsdeIAXXY7ryRd+x18qC2JTlSXxrDyzW4lj6J04tYSFHaKZpx65peRg40ieuSPez3mm5ShOy4/yEZNEo/bN0oRvCGhs6rvHexGfxqnW/XsVG4a0zB8syM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744002082; c=relaxed/simple; bh=uzrqNAXM/KeEjp8qWr6xTf3VLWW7e0MNaK/cvBjUNjU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=M2DvU42Y3CudUL1zpqms/IL8JVQmr0Ri9AwIUfRnfMFsgYdluWZDKZXgsVlQSDkNpIybQ0+ZzhU9WmIs7mzCZIBQ1GSnY474/KIQCYxvBgqvN90fOe9xBQdYnBraZsfPOGnAjnzAdE6/dlUwFCgq5wPtkp4uF6lerr5d+3aICd8= 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=cTvnBtMd; 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="cTvnBtMd" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-2ff854a2541so3508450a91.0 for ; Sun, 06 Apr 2025 22:01:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1744002080; x=1744606880; 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=fqf5UWKI2N4Og32+0x3lkK0y6IoadYAF1NX3nVy0tDA=; b=cTvnBtMd2pCzZMYgbDbOFBMH53bcb3oZgfT1Q/FjpLlot9mZwTf4C1BmmhPx0hnAo1 FlIiD3+OfXicErPm6ayesfD5cMWAE6RJSQxon2hmd984XnVCGcjmi0WTSqmF1xDZ1DXV cI+eruNWjKbAoff6hcIBOZcrx6mnxJy9iB9Rf/rFA861IjGEN+qIJml+pVZEhEBsbRuG uL1aWTsJG+L5p7WHge2HLwMpilzFbOatmp96ZVMas+/ShIwNWvraEen9UEpTSN3+6Qis 85X6DZg9WavDPC+Fdw6j+uy1yEY783tztK2AGMOks/waC4Km/qnbyoHzhWoxHzk/yIDW wfbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744002080; x=1744606880; 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=fqf5UWKI2N4Og32+0x3lkK0y6IoadYAF1NX3nVy0tDA=; b=I6ZGqJH9CYR8CA1pxcxgXzc0sqhoNfEQpXmgx04vOzOxhkL/NQa+FCKjdeeNV9ck+Q TUstMkv/SGhXtlTgQVsF+84Vy1/pyuI/Dn4ZRoFoxfj9vV85weTJq31uBVDFgWsHrTB7 XhcCf5StS00y6ETfKrQYrrpPnTnoOlx19icz0K7hB6HQVyA5nGhUbF9UbBzk/uT2xtal +KOoizzckZ1mqRn1Wb/HtmlXdR4q09oGLHlDLTZ9kYRt4vzz3bZAZf23qJ6erZS0vl06 S7Ut73K3cxVJUi6Y4VzvUSn5DayALy2wywcfxJnj5ptIzyaIUWL2znhHiDQjhBUUT0KW fISQ== X-Forwarded-Encrypted: i=1; AJvYcCWUOwHRYM3DSxpc3vaM8hrm2kH0mAxIFnQn0GF6nZ857jZT0Kh7gmcBG73hZpifhGjtNAaeOtSzHEfw+UA=@vger.kernel.org X-Gm-Message-State: AOJu0YzZRzczNVVYPP5gk9Vk9eVkxub0B4XqtrT5pGOOzDVWZXjYZLBq R0G5F/Sn/eQ0m9Oc8djPCu5IKL7J05cIsgc5LLcGZwKI1q3j6pUQDdGsur2NUFP42bQEQ6EYlhY CpI+Rhg== X-Google-Smtp-Source: AGHT+IGmcAVt5EMV3QErs7No50mhGib7CCW7DyRluV6DypHgyQ+07hXaXEDAfyGrowz+s51DmBz1jIqqE+KR X-Received: from pjyp8.prod.google.com ([2002:a17:90a:e708:b0:2fc:2c9c:880]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:3a4e:b0:2ff:6fc3:79c4 with SMTP id 98e67ed59e1d1-306a4b70f41mr15349365a91.27.1744002080157; Sun, 06 Apr 2025 22:01:20 -0700 (PDT) Date: Sun, 6 Apr 2025 22:00:51 -0700 In-Reply-To: <20250407050101.1389825-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: <20250407050101.1389825-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.504.g3bcea36a83-goog Message-ID: <20250407050101.1389825-7-irogers@google.com> Subject: [PATCH v2 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 , Weilin Wang , James Clark , Xu Yang , John Garry , Howard Chu , Levi Yun , Dominique Martinet , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org 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 --- 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.504.g3bcea36a83-goog From nobody Sun Feb 8 02:56:36 2026 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D5B9B223711 for ; Mon, 7 Apr 2025 05:01:22 +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=1744002084; cv=none; b=KmxC7FpixuTGplaGkaGGCAaZ3aDUlje7aE8TuyzELXF8ybbannLO3C417OxAJ9wyGfHWLcDiBkuVjTIBdDkEBZ8/cx1co4Ux95gKTIcab4X0hsKwYr2QnoM/J2b0fA3ScIdcL7wu7yDmx/3F5qLXakL9hdngHqIf0r4O1uvM5PU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744002084; c=relaxed/simple; bh=dmk99xLT8Nx0mz4ddF1+mWBkWibkJI69saN0P2VeVFI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=f6fMyW4MXY6YqjlIX1+ufY/DZ27ZY233OjxmCQHsLFWWGXAKwqlB3G5dg8lXkybfJoEwH42HyxBba/bRJc7azOZyz3+H5RyCCZLN+JgD6TkSWOFq7WAghOO8RHD66konHiqwZ/8pDiDZu2lnqTiYc+jfdwwKOqKtDpVs3iO4/Xg= 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=una14eo1; 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="una14eo1" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-2ff7aecba07so3817935a91.2 for ; Sun, 06 Apr 2025 22:01:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1744002082; x=1744606882; 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=hurkMSaqLGDLbW/1AFRFsncWr/nyXd3OBuzAUIRrz+4=; b=una14eo1Cfsh0MLKEqWh7qX94r3f6YKZsK1qN6P7UCqWSGOSMilDmfSpuJcbxxAhlw Kg3NuYsQruCbIQGl+GW955dkjiYtpcWHdBMYThgzIgJMYNrj/8wuRH3ilEY/EoDtDVMd 9s0ap4iRd0d30o0bVoIhdto8vGXhtd2UfIUc5Sd45HOu5ZhNTBRgGI5JYOs+YCs6NhJ9 M+saRZUV7lyxwdcgwW3Qu1T1s7IHbCtbYDy8qn2ShhWuf1OVHZ1fo0KEega5m7MSlOea r01SQpIijXxm3of/tUWnU9RLfcjBiqeOep9IbQe+/DwZ3hLfKop5nYv6fe+HfuAX1Mb3 KxJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744002082; x=1744606882; 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=hurkMSaqLGDLbW/1AFRFsncWr/nyXd3OBuzAUIRrz+4=; b=kLG0l6ELlLiwnSomlHACBIcn3dlzaMnnkNiUxN6CLUQHJIaVuWlgJYeWSi0vzqA5Vu sO0QXVrTfRmfAxH45w/G4fWTLUptKVksLSsf6yJ/hWpZyeaxfGrHLiZ2iTkNaSK6vPol f43A2OBqBGehuB5VIxAZ31rSTkVmTX/CUnX26LVMp/cDA1I8QrPGc9Up1tyMmC/Kzmx2 fNo9ZLaqYmnkbEzylmGOSmXxHOq4Xl8kWT54cZ1ox+dkCFulSMUw/Ykgko5FTTGOBeiI xsd3F9WJTFtj2iNVuWhiehhoIRuwS9NLx56STZFPa0Q3F2YuFo6wf6z2TOmRLHUs3Uuq iiWQ== X-Forwarded-Encrypted: i=1; AJvYcCVlbfCuE42r3fW7bOo9oykadGqyV3/vPjBzyAjjUHdALe7XOOU+y5gkGVqCsMyZpSl2JqdCyZm1tMbCc8I=@vger.kernel.org X-Gm-Message-State: AOJu0YyqLcBjSMj0w/6iqZJJiHRhtNh0WchsNyo2EzQTlG1xp4m08ubW xV6yma9njU+df39AbalGV31NTm0RHqQgP9o7J5qqBDQtRgDdaRoNiW0u5L0lyt5MjNVn1lNM+Rj zjrfXrA== X-Google-Smtp-Source: AGHT+IFf7l0FRxTgMKZUycey8xKIKLXESGcbBpMRHTMH2F6GHI62YOsUKOSUl848EsIQfL7D7M3u8MLdCIa+ X-Received: from pjbta11.prod.google.com ([2002:a17:90b:4ecb:b0:2fc:2ee0:d38a]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:2744:b0:2fe:e0a9:49d4 with SMTP id 98e67ed59e1d1-306a60e4ab5mr15148453a91.2.1744002082122; Sun, 06 Apr 2025 22:01:22 -0700 (PDT) Date: Sun, 6 Apr 2025 22:00:52 -0700 In-Reply-To: <20250407050101.1389825-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: <20250407050101.1389825-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.504.g3bcea36a83-goog Message-ID: <20250407050101.1389825-8-irogers@google.com> Subject: [PATCH v2 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 , Weilin Wang , James Clark , Xu Yang , John Garry , Howard Chu , Levi Yun , Dominique Martinet , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org 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 --- 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.504.g3bcea36a83-goog From nobody Sun Feb 8 02:56:36 2026 Received: from mail-oo1-f73.google.com (mail-oo1-f73.google.com [209.85.161.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 19E29224241 for ; Mon, 7 Apr 2025 05:01:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744002086; cv=none; b=mKo6cA/fnpn8tqbeDAgj18WeRzPkmXVQ9jlFIOJF7H9gqyKriurqR6ZKeaN9zeMDPErCEh/6U5WKPEDOVTF1b/mU/hS3lkFaXcNSUQ9dLUu5VsslUXouiN8P2tm0BtMTIpWty+sXBK3D4xffWkUM+FqRPu02bnFloH2HhsbrqGA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744002086; c=relaxed/simple; bh=6EEZTd9lf9aeTITKws4CXHLVcUfJH0Aqr7eXP+eg5Q0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=QLlHpzj0D8BH26TEFTXRoTuCuuyyyh8JGUPY53+l17LDdt+s9ZHT/wCKArIVee8WpQI4SVbGAEMb+iFH96gwlz8PoXlD+OMmjZCMYZD7W2eputYv0f329gml8Oy3rtv+sk4AhwRJWqpSAKu8OZu3iLWmE7v2v2Zl8Ge1eEI5hck= 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=ydYH0lkM; arc=none smtp.client-ip=209.85.161.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="ydYH0lkM" Received: by mail-oo1-f73.google.com with SMTP id 006d021491bc7-603f8bab77cso3483806eaf.0 for ; Sun, 06 Apr 2025 22:01:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1744002084; x=1744606884; 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=O4eUmflRE5uebU4/SNO43FiJCwVtS3ISrTa0e4ce5bk=; b=ydYH0lkMBXAVfQXp4vR7PxaJbZbktEJU2L88I7E8KaPHtvwEmqqAsogid0XL4fwKdv U+JDTLKZRgNE2vByMUf2jVDfsiHGgV5nwds4ieNcJqiIRZYsaLGxD4QPRjF/UT5X7rx8 5hrMnXPEE7WUS0t+ctLxcv2V5MkZvpXlwNJF34rphm8V00BRroODXwGUaR4hbD0rXRs5 E/bI1YCYDNV3h4QkpG2R5eb1cbv1htxYMwvf2MTeh3jgWb1Up5GBh0/qqrrzWWw5e2hU dpLB7tSIH2CC3Qnx3dJiDYWkEuguAg32tGF9WldO7BcRq52IKH8HWKawi8QXsEZNvNsL f34A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744002084; x=1744606884; 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=O4eUmflRE5uebU4/SNO43FiJCwVtS3ISrTa0e4ce5bk=; b=k7zWaZd8aXtEEVQE09UW0VePdkGDsOooKFXWQROqlrRKH6YSmlyx/6Jy52wQzM1jAE 920RE8JTwWuBEVlSjWSpS3vhk43kb9e0ACiuWD8iCRBEUBiM/a3IMenSKN84BzuLipw2 FPpdde1/gZf8l5i+HJUwAJBKCK2ZBYHAF/Yug/nZg9xEm5OosVRWZ4xo7z8HfufJKaS+ bv7iB2L3udeGy6BozlmkSryM3U2U9IzVcHYpqLxb/12Y11wh29tmolB/vYxai2WSWA8q nDrWJwKhpZLAG3EVA8PmBv8kNcsrg8cksegguTHaG/opQhxe2N2//4w7FXaf1kivOMxY 6V/Q== X-Forwarded-Encrypted: i=1; AJvYcCW+1nkpJRVE9bdezT9MYuzRU8zp0CnjG4URaaAymDE3cUiBZGYdxlla6ejKUVC4MzuVLo/P6ARd2YiknlY=@vger.kernel.org X-Gm-Message-State: AOJu0YxMmlC+mHn8SyOJZG16RD5IwzbX3e/3gHusGd1dZSRuXRIAD0KB rYWxGQ/K2d4sQ3k24o9aeBW5Zn6Jph529lAMMZL+cWUH2GFJ06c/xN1llhH8MLeg0YUCEsbW5zF XnRZDGg== X-Google-Smtp-Source: AGHT+IGfdfeZHDwYGdcI8n801pAf5P+Uopk1if+BxycztRji+1E9SmPXJxfweFzNVoVlCGV6oYhyxlAwVp1t X-Received: from oablu21.prod.google.com ([2002:a05:6871:4315:b0:2c2:5b99:3e17]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6871:788b:b0:2c1:539a:6071 with SMTP id 586e51a60fabf-2cc9ef50083mr6757489fac.10.1744002084142; Sun, 06 Apr 2025 22:01:24 -0700 (PDT) Date: Sun, 6 Apr 2025 22:00:53 -0700 In-Reply-To: <20250407050101.1389825-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: <20250407050101.1389825-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.504.g3bcea36a83-goog Message-ID: <20250407050101.1389825-9-irogers@google.com> Subject: [PATCH v2 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 , Weilin Wang , James Clark , Xu Yang , John Garry , Howard Chu , Levi Yun , Dominique Martinet , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org 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 --- 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.504.g3bcea36a83-goog From nobody Sun Feb 8 02:56:36 2026 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BCE42224258 for ; Mon, 7 Apr 2025 05:01:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744002088; cv=none; b=qvC/f7FAp7C0xQi8Q8NFhbnanGWTiMfCHdnkyTzK5BFK1iSZwIhyrOMJiElsf37lv0t+wJYn/FgVgufO462GVAtUOIyYXrmejpui11po5mzfkr/QbKzTGOObTuBe3sItDNXykER0xmcHtZaRixPstRJLn64TE8OBQNC4UjM2W0M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744002088; c=relaxed/simple; bh=PFCPi/G+0TpTPi0JgfJuEuy5Gdf6Z4J8KlzZAU5QsZw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=vA0Efj2ZeIpY3nx1JiPqR08T7nI1geIVjr51yE7W1N8k/RprCZ2f2QWkscJRwXsBLHOMabeAp7E53j0KBlBvEMPYVjpJ0ObMrCqiwscBEVG5HeN4CFnloD80ICmRdcq6xykFv1XSohON1G+7ry6mtXDnhag6xpea4k/OY53w6yg= 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=VoA5K40y; arc=none smtp.client-ip=209.85.215.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="VoA5K40y" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-af5cd71de6aso2636332a12.3 for ; Sun, 06 Apr 2025 22:01:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1744002086; x=1744606886; 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=L1P2rK8yf1Fpba6pWFWmg8jvoaup1pRJRMRZyXjMqjo=; b=VoA5K40yLqJafMKnlJklUEOljcIk/kC9/DzaFSuHniWvuEFK1Dy58D4uuKHC0Kuzgq QsPToayFoHHYnfWshW6oeF2LfTxUgXDehFhTCNkuVF0IYJoIfWxc36w5nA0gsnySpuXL Dmxq8UkybfGtGTA9yBXWEJ9dF19Y1uZDxQMzsYQgHMGtwsl8f16r6CcoWI122W5yeeou axwKx1P54UjA6qU4KVtBXj91w2O6DpSC6TZR+WZYE2ksla2Z+7MV06wUt4q0yoz4JEN3 n4SUzzcatDysPkWlfaTnBb9z1DjNvQ+93/WuMADQLZqDp0Ke7iSFZlQITYe6LlU9/jD+ 25aQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744002086; x=1744606886; 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=L1P2rK8yf1Fpba6pWFWmg8jvoaup1pRJRMRZyXjMqjo=; b=Es52syd1dUlbCAOkjN/E2WE7nk1WZLx215ozpSz85kzAxlUQml/DuDX+0DXp9FJCiQ TSJui0w+j9suk3Z/zz5qqVYsUsvwNCmXlTB1lt0sSL0z+SIyAfKiRYWv67230lce9tT+ oLcAY5k0NjKg4USu247YXNSAhqzuCddifzNW59bHcwLABUcwo2zIsLDY+oC1mM0Xh381 d/idM9ywvysxXH5PeN44tzcV1GgF53c7+3KBUyWwduyyvvIP6/xwIMttLjBOmNuk0pQs t/+lWiMm5rFBFvnWklmeYG3y4eewXa4PxPh9uG/Qib8Z0perI0vKxiNBahhcQC28NcFf k0ng== X-Forwarded-Encrypted: i=1; AJvYcCUU3tbdBwKtxb43Yv9MjA16my+1yGybl4uhbRzevr0HhNovuDuUhEueNKU1D70p1CUpXpm2ZPDgWm6Skr0=@vger.kernel.org X-Gm-Message-State: AOJu0Yz11hDzfUTUqOVwaxuVjMklDdMUlHxlQkCS0Y4piKQ/GDblnsd8 DzkWlHDs/UpWuNnKKA7zA0/cDBaOi/JpWNXEsT3Rqi5F2GmLUVacuuRZZMBO5ZFY4oZnqoNLLRv vdvQYUw== X-Google-Smtp-Source: AGHT+IHhdA5nQMN/wjk1RtqNFaOJW69u8c8bSYzE3Uk7wzbJ24kkXGolPUBP5Te+WaxgE3bVyrtICesFk2Lu X-Received: from plgx9.prod.google.com ([2002:a17:902:ec89:b0:215:48e7:5dc8]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:e546:b0:21f:7880:8472 with SMTP id d9443c01a7336-22a8a0a297fmr168506505ad.35.1744002086085; Sun, 06 Apr 2025 22:01:26 -0700 (PDT) Date: Sun, 6 Apr 2025 22:00:54 -0700 In-Reply-To: <20250407050101.1389825-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: <20250407050101.1389825-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.504.g3bcea36a83-goog Message-ID: <20250407050101.1389825-10-irogers@google.com> Subject: [PATCH v2 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 , Weilin Wang , James Clark , Xu Yang , John Garry , Howard Chu , Levi Yun , Dominique Martinet , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org 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 --- tools/perf/builtin-stat.c | 2 - tools/perf/util/evlist.c | 1 - tools/perf/util/evsel.c | 2 +- tools/perf/util/intel-tpebs.c | 152 ++++++++++++++++++++-------------- tools/perf/util/intel-tpebs.h | 2 +- 5 files changed, 94 insertions(+), 65 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..e3227646a9cc 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; + if (!*name) + 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.504.g3bcea36a83-goog From nobody Sun Feb 8 02:56:36 2026 Received: from mail-oa1-f73.google.com (mail-oa1-f73.google.com [209.85.160.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 DA42122489F for ; Mon, 7 Apr 2025 05:01:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744002090; cv=none; b=ouf9gTHpCudH8tAqCADbPQIWsMT1ud32vklSL6bRUxE98S+aHSoFjzO/68t5sduxxDc53UqaxaYxBEzMXhzJcsiK9vmz2PE0YNDuEMDkysYpLeZWIU7hNQEHfh784h3c1XTW5ef/bfU9J+uyOCzggsyA6W6ZOI19PADLj5az0vs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744002090; c=relaxed/simple; bh=IFNfdI150vfN3Xo7/oCHlYzJh62CBUFp0b4auUgNBxw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=LyVArlDCuYu0I39f/MQkvYctSNre7vzLXp78JDBCixGhL/uoaP0vPhahb26IWYJAQmyFoMTPTwLQNmM2I3sZ5BCQYf0uyZlEtIp7yhq4Caa4fMe6z9fUihymx9TB5LN8NIZU+o2sJ7RlBPbHEa1h9WQze1lTRAngt/fBzDLctBE= 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=MmLGtOgK; arc=none smtp.client-ip=209.85.160.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="MmLGtOgK" Received: by mail-oa1-f73.google.com with SMTP id 586e51a60fabf-2c23beea898so2865567fac.0 for ; Sun, 06 Apr 2025 22:01:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1744002088; x=1744606888; 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=TQsKQ1vCjAU+l2hcTiBlNbndjH+ZisU6X+PObJgZnSg=; b=MmLGtOgKgteDHYftzUH7Q9e3SYh4gjvTDcuBkcSzaNajuRUatQQscISiTw0c8h243v SdcU1CwQSR94HigBnDqPqy+ZOeDEbqge3Jx4ECvBpw3QlJHmTUZklKfEaNTvQmWid/Sm tTppPB57HV+kA6GOLNrCQifbEZ6Xo9LHXHXiseUwIzFb5l9mDlzaO6iZMYDk0bRSLuJZ +yEIsYmGw12qyn7VQEch/cWsnwkBp6+Aof8sIVNwzjU26vxHX1DK/m2vt8giC4I4RI/n hRPivP9SIAJDfEE9/te30Tb0dfr8jQ+8dJIMtT+IuciEOYnG7fqmCQ8/ol2dGmh9GqIY 876g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744002088; x=1744606888; 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=TQsKQ1vCjAU+l2hcTiBlNbndjH+ZisU6X+PObJgZnSg=; b=KBZEw1bgG32BAHTjsIgBnKN6IsYqDwUw4YznEcJAGbBEHmQ7pyiB3V4ivJk9hYwOFR YujFiayGcuYLLoLjzCbS2X0sdnd7brRsrOAn5SkShXKDNLqYM6u0I3EVdq43jyA/rfds srANdF/8roefrL3uCM8exLpCT+6pfcswPmNlztlKnR7NrD4U9Y3zB1SNXuDPfs+Tvm9Q OiFqiPaSkWqM8yQADjJEMdCwqS1jUJMZVy3H4ydBUVMbW3wUB7Y7+zTY8YVoXMGiQXpX j/JtrBfaKcB6vOhmMvyDjY7twTsc6sP0NQyespcFICiv1InJBqCKE72BJsfMTTqt9Fim kQWA== X-Forwarded-Encrypted: i=1; AJvYcCUKyho3DXLjuHSTpL/otf6guhUsND3v7UMN4ohyswXiaEbuQXeo54sb6OEjxUJ6rnCOW91nvznKG6zoB+g=@vger.kernel.org X-Gm-Message-State: AOJu0Yz6yNcT/bLMdGhqIVQaedYaSOJsnf+sm7Wl0rG6IsDOv/4btJQu TlrhdnW1q2TW4qAEfhmTQLWLq8jro8H9eXdF7TyRP+D1gCDGasie2AquPeFnAYbjtNMLGTtrJNb 1mcrdFw== X-Google-Smtp-Source: AGHT+IHHRJRJoRVVv373ETzoRN0aw6OQoD6tbuJEgZ3VSq5A9ONhRxoH6jr/k8Z300LMtg7liYoqQzi0ty/2 X-Received: from oacny17.prod.google.com ([2002:a05:6871:7511:b0:2b8:55dd:faa7]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6870:e38e:b0:29d:c832:7ef6 with SMTP id 586e51a60fabf-2cd331bc71cmr4132687fac.39.1744002088039; Sun, 06 Apr 2025 22:01:28 -0700 (PDT) Date: Sun, 6 Apr 2025 22:00:55 -0700 In-Reply-To: <20250407050101.1389825-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: <20250407050101.1389825-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.504.g3bcea36a83-goog Message-ID: <20250407050101.1389825-11-irogers@google.com> Subject: [PATCH v2 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 , Weilin Wang , James Clark , Xu Yang , John Garry , Howard Chu , Levi Yun , Dominique Martinet , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org 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 --- 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 e3227646a9cc..452ce3698221 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.504.g3bcea36a83-goog From nobody Sun Feb 8 02:56:36 2026 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A10D1224AE6 for ; Mon, 7 Apr 2025 05:01:30 +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=1744002092; cv=none; b=fTiuEaOBF89vq8OjLpBWSipMIV0i3pA09o+9XDXsH3F8ioBLVNk7Lhbg4FbXXVV+rNUqpRilPFCmtZLSGTSbsI77/6ngQ9TWGM3T7mxzerQpcw9l3tm4mnFpUVMrQlHSl5d6Rv4N8cSw5tFQjR6nqUtecW4fisZ0s9u7eJtm0RA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744002092; c=relaxed/simple; bh=pgA22qZPkNb7zHVoAYDr39LnkgEB6ecOZTk58/HOErU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=EQeHAnr7azQxFVH7BfC7WE5HIvUeR1E4fC9kgXa8dv6X7MLwB1ZKtf7GwMU1I+U0RcMSoUTkebHN3hDTkSfWwABvbDIiYIiDgWl0kCLRbfS6BRFtzC2npcP8nEb/dVvtUVCDvOwtSvbTSg/oLMS8x6+/svWQp68nr0LconYdO+A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=k7U11RmZ; 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="k7U11RmZ" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-3054210ce06so5734053a91.2 for ; Sun, 06 Apr 2025 22:01:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1744002090; x=1744606890; 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=aJzpjcltssyTndX39CXnR31oCFaKZdU16+qgh2x63Vg=; b=k7U11RmZnWcv8BgfVFaKQye2KgCv+M5d1VThIIshDpjC2puuo+7xPyT1Oe2a9QZwRc NBltd9esVepA0KovyFLR7TNkN2Sz2TJfjtFBTT58ph08Uei/sBZvi8fKNfux2FZqGWk1 fUDHuld26Xkuzse/IA9iAajrQBM1wgHTRLnrnNR3I7FCvF1jfvJowCHoSHLmCffcGazS Jp2pWjGDHbE2gdZBt22TzHNfvoPwtHlnQPnqlO/KoTvpCJISK1oMRDjZfNG1ZYz4Bkt5 gYj6Y3I83eoiYgO5TAGdZlmI5kyPRl33Q1357xRmZhSJ1aI/fkLlYaVHnXdEkljLc/6o MrBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744002090; x=1744606890; 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=aJzpjcltssyTndX39CXnR31oCFaKZdU16+qgh2x63Vg=; b=PE8fnUW+Rd0Q30vXIQ89u6tclPmaMdnULw3iXmxioYFBgZUO75EtczYoYsVC3eyR2d UwpXv0WOd6Jg7E3W0xblh7Fo40QLTtApZPZ8WAtxxKDoLi3460abB7OOd8bBBEWIgBGB 4l4HB9s9iCxzxbmxG4gtnXbUx4sM9l1d9iJ999Sw8R2S45v+OCi6I/0Su7WI8vAF/cO6 kDMgDwWJnvzW6AbmihQeI5L+qe282XpC1vFq5u8/B7HTj71bwVs1/aSZQqigvmJYaOiU Q+xJDophcrpEV3KK/WDxqan6Two8B9aIRBiunF2YL92z4pBOPINp78P8HNmU+RwwPBRS OOcw== X-Forwarded-Encrypted: i=1; AJvYcCU+Frvy1O0NXjy+nKruCsLAo0uLdC48JhEG0MN6eEvozCPqNdEgvP4ptrcqjDBOmd3qCadVoN1K/jSVLwA=@vger.kernel.org X-Gm-Message-State: AOJu0YyLy2+yRZxnLa0jKPMo61RrOLILtf+SZZgE6VIWbT1VAxDfiNQ2 iuVo/N3edIucJe7SP5+jtzaB6os1a31vY4YpLtu58blanH8hbRF9i8jrUQ4987O6Fri9YPxx98h evA8g2Q== X-Google-Smtp-Source: AGHT+IF04qgBoVxDOc49hH7Vp/li+r40rUQDo1djjDt+aWnNZByAYG8kgDAXB8ulUE/trExk1fRrj4gFhiq7 X-Received: from pjbdb3.prod.google.com ([2002:a17:90a:d643:b0:2ea:3a1b:f493]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:2f0c:b0:2fe:a515:4a98 with SMTP id 98e67ed59e1d1-306a48b3f9dmr14334638a91.31.1744002090039; Sun, 06 Apr 2025 22:01:30 -0700 (PDT) Date: Sun, 6 Apr 2025 22:00:56 -0700 In-Reply-To: <20250407050101.1389825-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: <20250407050101.1389825-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.504.g3bcea36a83-goog Message-ID: <20250407050101.1389825-12-irogers@google.com> Subject: [PATCH v2 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 , Weilin Wang , James Clark , Xu Yang , John Garry , Howard Chu , Levi Yun , Dominique Martinet , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org 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 --- tools/perf/util/intel-tpebs.c | 51 ++++++++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 7 deletions(-) diff --git a/tools/perf/util/intel-tpebs.c b/tools/perf/util/intel-tpebs.c index 452ce3698221..29616d087bce 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,16 +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) return -ENOMEM; =20 + list_add_tail(&tpebs_event->nd, &tpebs_results); + mutex_unlock(tpebs_mtx_get()); + /* * Eagerly prepare all other evsels on the list to try to ensure that by * open they are all known. @@ -317,6 +344,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 +364,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 +467,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 +493,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.504.g3bcea36a83-goog From nobody Sun Feb 8 02:56:36 2026 Received: from mail-oa1-f74.google.com (mail-oa1-f74.google.com [209.85.160.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 1910B22539E for ; Mon, 7 Apr 2025 05:01:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744002095; cv=none; b=n12dFutCM4brbbm+JVZOaoK3b3L5GIyVimiTISV5mVGye+kBkPLiUdE75UdR20N3lHXBfGq/5Gq8vxovwnc06t984Xh/qbbf5Z4iboDG2RL0JsnC4nO45l+nAlIC1e1sc3ML85hmGT3jQWPSiHFHWKE8sc0Rzh+6T8SjWLHO8gc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744002095; c=relaxed/simple; bh=FYAEedft2Wzc8yizERM1wPF85NL5BS8GBfTwqLgBmKU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=QZwdMHDsKN1IiipphG/5jWYhROnrvpnhPdDQGTa7EA9ET8AHaujWq4GThnE3ipSzjbf1B3I/jbXrH+alCR/Iz3NTjRA8m4eKYGayhPCtL+9+BxAVgoZhKG1Nx6UczDrkYEnE6q/a4q2ySWME80XO7gA+UMDjWRL3V1wxOc477yc= 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=DnN7jhB/; arc=none smtp.client-ip=209.85.160.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="DnN7jhB/" Received: by mail-oa1-f74.google.com with SMTP id 586e51a60fabf-2c2339b26fcso3459908fac.3 for ; Sun, 06 Apr 2025 22:01:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1744002092; x=1744606892; 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=cIyqsd5omsCZtMoMd6pty+zaQU2fmFYP7fPNPX2RbQ8=; b=DnN7jhB/uq18xIXT9PJlvp/U1lou5y1thG0zv95vE1tEnRXWhAUX+m0B38OHumjy5x h09hZnUjCuz4cR+GycAARyWnAlHn/9EpDMOoXFmUvt3xVO3iryDlL9bNSzT0ABiUGyEl 9NUNz9LBj8qxcq3pM1KLDmAf/EX72VIyjryRuUqVrCEnXJwY4q0zpmiAHUef18XJuKyg IMQmgqHvrM2llySP+tWz9VXWXak2a1skVVTPiD/vtOhHALOQ5n3pHA3mvIYgjj/5M69k /SGhbRbjHcm7IO5tiqzQ0frewa/XRltd4vnjV40/hVbJk7NbaXn5086fltO/y1+26x/j QI3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744002092; x=1744606892; 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=cIyqsd5omsCZtMoMd6pty+zaQU2fmFYP7fPNPX2RbQ8=; b=qrawcak5FET/eCeDD+pc/urAUcfWv8JmteAa7cwylW/BOGNIchZlLvm2POvrgUJhOx VcshNm3+UJ33KS3j+KdonP3fvhAKRqKJaqfi8a9xJNfE9bvDOiyw4pPti1vyGzVj3/cY Qfd6ugTWcG6lDO4BOQKam3n0Jfx5thSGnZM2JereJUu+e1Z21XOEtbiTBR5v99JSAy5i Z2nUvgftrkF0bezGhzJMJMnU/JgqHVgjyaT1Z2f6UzqpHy2FWImhPRXoJM2ZSDkymM6O 8R1wkq58qmkks+ClywR2oGO1iYIeyxA85k3Z+JWp4wNtBGnVOksd81x0GlZvduKFHwVG iw4A== X-Forwarded-Encrypted: i=1; AJvYcCV0AYrcHFGwxZyDbH58DsBZyo7ow3nlRYuF+5Ue/OkX1hYIG1wv/2aFr19iMFu2mAtOVa6eT081RLn7hAo=@vger.kernel.org X-Gm-Message-State: AOJu0YxCsRTq8ZhPzBoaR0x8IEE9QvqLAt7Xp0wFnBF0Ep2/wkG0fhum qd72LcwPdoqIp3n1tEX4hMDKRC4l/SrZ+RowSPtTfdQSM2GCf76Dz+S1OWvqafy436cuPn1BVuH 262gO7w== X-Google-Smtp-Source: AGHT+IFSmEA3prf+vdBCu53z2oFS+pjImXBHpEuz1Jjg8qmTVMcj3VPvF9JTUWqSaWt/xDVLoI8CkjVnEae8 X-Received: from oabvz22.prod.google.com ([2002:a05:6871:a416:b0:2ba:b7af:e2be]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6870:808e:b0:2c8:5831:8d4 with SMTP id 586e51a60fabf-2cc9e8bd98emr6305793fac.39.1744002092235; Sun, 06 Apr 2025 22:01:32 -0700 (PDT) Date: Sun, 6 Apr 2025 22:00:57 -0700 In-Reply-To: <20250407050101.1389825-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: <20250407050101.1389825-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.504.g3bcea36a83-goog Message-ID: <20250407050101.1389825-13-irogers@google.com> Subject: [PATCH v2 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 , Weilin Wang , James Clark , Xu Yang , John Garry , Howard Chu , Levi Yun , Dominique Martinet , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org 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 --- tools/perf/util/evsel.c | 2 + tools/perf/util/intel-tpebs.c | 205 +++++++++++++++++++++------------- 2 files changed, 132 insertions(+), 75 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 29616d087bce..eee105dbd544 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; @@ -313,9 +398,10 @@ static int evsel__tpebs_prepare(struct evsel *evsel) 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 @@ -351,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); @@ -366,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"); @@ -384,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 @@ -396,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 @@ -451,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) @@ -461,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 @@ -497,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.504.g3bcea36a83-goog From nobody Sun Feb 8 02:56:36 2026 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 692B5224258 for ; Mon, 7 Apr 2025 05:01:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744002095; cv=none; b=lQkqHBc59lcLP+9d+zjxJqyHe5/r4UbpM2nqIp18dJRtUANak7be2PIpD0uocQMycKo9pD7kkEPFTBfGt7uH+lKZ/P8qzXkMUYYsc+ioVnQHnpPKt7VNtzPnkQvd+q0p2eB06WloQA7nat+yGkrxjr42w0+t3x3VKh/bJg7CJ8E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744002095; c=relaxed/simple; bh=nqVoBCX+NQVq/fKv3GRf4qovTPQSejn32aFhaxMkhGI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=op6OgDtbvId7hox4BOrtvpTaae2I8VK02cqHcggzM/dL6Fvy5PmTWU+QrScaSsIBrI3zgxQN9ut/gt+9+XYM9CJs/50HDzla8XE9lC6mHqvW/7fXQxThs58tdRaqqSm5ePJHy4WKkuKXYSkDJQsiVuSqBp+FhCIQMSu3XqnkRP8= 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=PmPEIdHb; 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="PmPEIdHb" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-2ff6af1e264so6125861a91.3 for ; Sun, 06 Apr 2025 22:01:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1744002094; x=1744606894; 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=MRFvhDcXFq+LlBxT88cNN7nW7dqBbDfpT2imY8liKzY=; b=PmPEIdHbRWcwa0j6Ca0VH/lmqkmc/KaMCPi37O/ViBs7h56Hlo7Bm2SJNaqCudfTPb gs0s0gDW2NugOvqsDnYtYifA8hU+mDn3Pb5NeirfihMqrSAS/9ZhT+uk6RknVctqEkzx GO7r8+DXC3QAvNx0O4JxfpYUAOf7FyvJDG2MdVaIHSkgF5bRzEb0uS4Vp/67Gy28ItPt IkNMnqtjlOsfAA5A3J771m+CUqUbBG5qc5825MqSzm2UKvqj6M7q0Kf5cl6GPRGAfvNF FfRgT402PaagXcqOuFby/j3pwS5TMeIn1vI4oBIf4NSDInv1PhxDWjIBmLLLsCAgS3XS hA5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744002094; x=1744606894; 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=MRFvhDcXFq+LlBxT88cNN7nW7dqBbDfpT2imY8liKzY=; b=o3b49z1qkfSFAEYVEWiLCXa40XwAeYh057QaDTufXDZQEiT+n1nOx1qLa1GLGQrh8c 7d1fq5sJhfmuP9EZ9hHPW48ZZGNGgTho8bDC8Fqdg45KFHStoFVkSOA/MdPz3y5EPMgb n+XegTEAput5G0qye1HwnM6Tb2nrleODMz6Db+unqERyK7kJatLPXZVYwUAo2OK04kp9 mXKK1285umdE4RYsru6n50+GO29JQb1JL69DO4Ov5m1t1NucJX6l3Rp1OAVQPaJCmL8f gWAoSHrsBAjhYywyr/2tYlPn+JXLc7En8yHTJG1I1gPLW2p5q1pRW+fCWO5vAoIHGJMj MzqQ== X-Forwarded-Encrypted: i=1; AJvYcCUODSHb+cwOY3PVNR3dJfdg1pXOGKEXvv4asbDWSvV/+thercFfjqeb6L/ZPOstmaeTbpdl0QOO3MoAN4s=@vger.kernel.org X-Gm-Message-State: AOJu0YxvKB6vmO8F0UjScXAEGp4x3wj2ghiiKz4lDf/2AKfC9ejSTQ0y NmsRcpUpyHApdZ/w8IkyD7ImvrLMynescFt9TYkMH5+mXZrL9IK1GyQXqz1m30B59nCrFZdps1Z 9N7NbmA== X-Google-Smtp-Source: AGHT+IGAxC+bZRaaNm5i6cXKhKoClDumhpYJ9DJ0SMj0GkdUyJiR3ISOmEF1F9ULliuDvJrtutKjL1CadOc5 X-Received: from pjbee5.prod.google.com ([2002:a17:90a:fc45:b0:2ff:5752:a78f]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:5344:b0:2ff:69d4:6fe2 with SMTP id 98e67ed59e1d1-306a617994dmr16188183a91.16.1744002093824; Sun, 06 Apr 2025 22:01:33 -0700 (PDT) Date: Sun, 6 Apr 2025 22:00:58 -0700 In-Reply-To: <20250407050101.1389825-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: <20250407050101.1389825-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.504.g3bcea36a83-goog Message-ID: <20250407050101.1389825-14-irogers@google.com> Subject: [PATCH v2 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 , Weilin Wang , James Clark , Xu Yang , John Garry , Howard Chu , Levi Yun , Dominique Martinet , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org 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 --- 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 eee105dbd544..f9584b00fb05 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.504.g3bcea36a83-goog From nobody Sun Feb 8 02:56:36 2026 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DD041225760 for ; Mon, 7 Apr 2025 05:01:36 +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=1744002098; cv=none; b=nIgitfBFICKG4yc4LzgfjIZBjCdcjz1GA2nGJrNxhk4uIMJnlbbSZVr/bi9SKqLAKpoHeNTxUpQbAyJhZim1LpdLTcuPxdsjNzuCPJ5ZUEFS0qAqRJW0S4I+AmxFSZH5gmO/7mAL4QqCmLROYeVGihX/Jweo+ZbNauJ+gb2hQyw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744002098; c=relaxed/simple; bh=cdG1DckkHDj22sHpK9HS7gWTsrY/18LLLL+7/8X5MXc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=h9dE0WZdz4Tvu2WP/cabZcBuNwGnkKRrpgRxy5uyEmni8ftEt03GckhE5TTW6sjhXSLdQc4OCcc+u96FvhLfl7wFgE2UAYzVRG+o9jNUyiiKsf4HiWh/y243xox++SZGej8ajJ1ukbYrAOTeqtTlkUc63Ar1m3u7VSXNDaltF/E= 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=ShrBdcFG; 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="ShrBdcFG" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-2ff5296726fso6263989a91.0 for ; Sun, 06 Apr 2025 22:01:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1744002096; x=1744606896; 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=UO5h79lqUTXSxHoC3YRlFA2RD9CJ36+9ihWt0OUyzC8=; b=ShrBdcFGkKQ6De+Za/nMr75nm0uaeChwouipPXqfrgk0ZhS6JFGvS7n7srB8/LIwrx /obZ2+Kvp3MgTrLJ8Godr98MW98LAtNnwEwZNefVU5BACZ+wBgRlLQSCo7b1uvEgblN9 xiFS7bmvIzxL+aSZAIQy2q2Ckoz8Px+DDvpRvnPK5CFbU4WqrhaaA43VVHjbmkw/5nTL 6l9Gj9Pv3vRHyPXUkQsEOEw5lDjXh8710TKKiMt/ZgSLmIsCUN+Ak0wDQ5TCq+1CXpnC EQ5UehezGdUBPXcXX9xjiL6IEW0jRfr6tvnhJtYT8yVcM5EYXNp7glKE4U1BGp4NPzKb 0jAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744002096; x=1744606896; 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=UO5h79lqUTXSxHoC3YRlFA2RD9CJ36+9ihWt0OUyzC8=; b=xRjlhFgMNh0ZkPrGHjIvvm6gtiSxPDYcA0YD05Nw/p8349ZkN7CYO6O38bkqSGM3yb mYedD6Bee21R5pIkx2mVIc2mEQv02KaUkepBzOmm/BNj6i4ys2tM68cClUhABKQCamiq gTtTSWtvoTDUFG14QaLUiXCrgv5s1twBtqEKHH8WG1WnOuG0uW8RrciT8qK3LyumKMrn wXXW0bFPcXd9lb7DXZVhLxBMJzbaJ42F3zoJ4j7/ZU+UihxRBD96Zq+/dLf4tocJv0eT 4Bpxg+RIAXbv9RFNZzQrV+2PtcUYKoYU5ChPDYjETOqFjk5WrC/EWJ2/yCQe1Dw1ysFc I5cA== X-Forwarded-Encrypted: i=1; AJvYcCXTj2UNo4Pe5a6M0mfEm1T3Yudciv25620QJ8BeHxSVqyJfuKURf18TFDk3ATuIwAfz/YGw32BX3EIhHA4=@vger.kernel.org X-Gm-Message-State: AOJu0YwFGlPBDhsXnjnYmztuqGleXIGcReiunXgXuxKLl/1pq/SemHUj t37B1ya/voL+w4uqXT1mK0LpkiOx5SLeYyRy7nERZ3H9ctr9PSw70mJmXGbVzYpOo6oW/TFsMpA 3h1drgw== X-Google-Smtp-Source: AGHT+IEUIVPhcPoDAWrNPs1N4IkmDKTBlxiHPpQRkoSscSY32F0ELyCbQNdYtUVIauqh3ttX3+wf1XVVEG9S X-Received: from pjbph11.prod.google.com ([2002:a17:90b:3bcb:b0:2fc:3022:36b8]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:3503:b0:2ee:5958:828 with SMTP id 98e67ed59e1d1-306af7303c1mr11734046a91.9.1744002095763; Sun, 06 Apr 2025 22:01:35 -0700 (PDT) Date: Sun, 6 Apr 2025 22:00:59 -0700 In-Reply-To: <20250407050101.1389825-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: <20250407050101.1389825-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.504.g3bcea36a83-goog Message-ID: <20250407050101.1389825-15-irogers@google.com> Subject: [PATCH v2 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 , Weilin Wang , James Clark , Xu Yang , John Garry , Howard Chu , Levi Yun , Dominique Martinet , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org 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 --- 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 f9584b00fb05..e1bdab4bba6f 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.mean); + break; + case TPEBS_MODE__MAX: + val =3D rint(t->stats.mean); + 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.504.g3bcea36a83-goog From nobody Sun Feb 8 02:56:36 2026 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A1AE0225795 for ; Mon, 7 Apr 2025 05:01:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744002101; cv=none; b=A1milNKejy8Wb4I2hdfBqT+XCKQHAsgFe9CzGtveyjdpzClnXUkXdI2/qdWbYJgAMS3FuHXpPdNYeMSQnepq8vZ/KYPKH62GWyfJELL1N4dXq4D1ReGsHSJoC2qlhfkph1umdYB+TwZH/NGTtB9hASSE0Yf+AB2aZzXyTXzP9QI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744002101; c=relaxed/simple; bh=CiHAR0Q7SLmeOGt4ytLWrORKi0z+Hj5r6RjPKq+YzEk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=dmJb7jQMMOWbirBEcf7DOY+oLKpBP+26wdxpR1CDlpZX/uQYTkCprX1SfD+ls0t0FMNZpKucRstN5GFlkPnnDnTUyYCmu+lasp/Mdk19PYBugZDQGsKC04yTv0Bptb0kcdXj1yXH53XnBDVohRGdPtdBhDAtHacmGOyM4/RQ5AM= 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=OVO4l6UC; arc=none smtp.client-ip=209.85.210.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="OVO4l6UC" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-736cd36189bso5574097b3a.2 for ; Sun, 06 Apr 2025 22:01:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1744002098; x=1744606898; 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=LplcUV+zoSNSD2DxCsUHiXNVbDXs0RgfkVOVvVDtPBc=; b=OVO4l6UCqApDWa4VXNCUhbALkcU+jPjSXKXsvEYnkoHjyvPniZjQAjys8DB8OgCdUp yvInHZG7XwPsQAXZgX2xHcEEpwSJsxXYdEpA7Ab6iHbULgpDHF0yYP0+3AvD0/8QGiIz MilaxCVajX5YksEK6Q5Y8ApWklP122NDMlCH6NuV6n+OnZGnPA34UufUvMrODJXtRqko ihMLj85uFXQCWXuXbP2piEb2+LrocuiGK5k1jAgDzE+Hnw+a5mABfzyICg4rhfv4a7Al sV3ADhKXRjXP9kE7tpjB0i0cEb13Qskg2onpxALCOtyK7qXfGshfULQ3nu7Dbacjk5No BwLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744002098; x=1744606898; 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=LplcUV+zoSNSD2DxCsUHiXNVbDXs0RgfkVOVvVDtPBc=; b=w6CYtIG4TSS7Mp1/AVepHgkuMXh2nL6HytZzcULXO6gH3XlCqrtUaKEsT5mESDy1Ro D/f71C73jng+PaorI8cLFjHy3AfKxj7vuSCH6wQ0iv5vYhRFd6OV+IoxcWg7IFprB5U1 aBXxBL/7F1FXimlpb7/xMIh7dNvrQoEigLBmRg+wHgBIMUDe1YnEB/vcKRQv9N9bI6vM +t8qH+1l3qGskjJP6ASedCU9kY2RwIS2LNG2rQsKQ7AwiLHlV5XFTvA7dOz38mdbU2sU kOLsrS013/w00xvsOVJjeBnKOY2rMKFFlC58b2u7zbXJFZfZDLomHz1l/H0qQSHasrY2 rWWA== X-Forwarded-Encrypted: i=1; AJvYcCUco2/H9h6wcQWEoEI8t2Wiw6EArbQXU8ul29RrauCAgfpIgpqr2+X7HIh9qgpHpaX94YOb0DBoHmgWTH4=@vger.kernel.org X-Gm-Message-State: AOJu0YwSJG0qNBaEermmCYVi/jec8eVBVw3X+wqCXhF1WWCYUt5GsLQ7 jYguc+gfm1u25sYKFuW3hwItRkFn5/EDQb5iYYBl+kBwb7LT4w9qSuY520aHeWxNdpbu8AmCsZN Gz1GYqQ== X-Google-Smtp-Source: AGHT+IFX30fLFwEdAUfptL91qs8QUgWuJ/en3gvTFzTBmBUaIEcbkr+1o23ITzGnm3HP1IBmG0kT7zTg+qBM X-Received: from pgbdo12.prod.google.com ([2002:a05:6a02:e8c:b0:af2:37c4:2ad]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:9149:b0:1ee:ef0b:7bf7 with SMTP id adf61e73a8af0-20104665f8bmr16341051637.19.1744002097867; Sun, 06 Apr 2025 22:01:37 -0700 (PDT) Date: Sun, 6 Apr 2025 22:01:00 -0700 In-Reply-To: <20250407050101.1389825-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: <20250407050101.1389825-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.504.g3bcea36a83-goog Message-ID: <20250407050101.1389825-16-irogers@google.com> Subject: [PATCH v2 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 , Weilin Wang , James Clark , Xu Yang , John Garry , Howard Chu , Levi Yun , Dominique Martinet , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org 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 --- 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 | 51 ++++-- tools/perf/util/parse-events.c | 4 + tools/perf/util/pmu.c | 52 +++++- tools/perf/util/pmu.h | 3 + 8 files changed, 218 insertions(+), 123 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 e1bdab4bba6f..ccd2a4d02c38 100644 --- a/tools/perf/util/intel-tpebs.c +++ b/tools/perf/util/intel-tpebs.c @@ -514,29 +514,48 @@ 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.mean); - break; - case TPEBS_MODE__MAX: - val =3D rint(t->stats.mean); - 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. */ + mutex_unlock(tpebs_mtx_get()); + 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 rint(t->stats.mean); + break; + case TPEBS_MODE__MAX: + val =3D rint(t->stats.mean); + 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()); } - mutex_unlock(tpebs_mtx_get()); =20 if (old_count) { count->val =3D old_count->val + val; 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.504.g3bcea36a83-goog From nobody Sun Feb 8 02:56:36 2026 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A82482222D4 for ; Mon, 7 Apr 2025 05:01:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744002102; cv=none; b=aVFrl/y3kWa2bucoUTBjruTyQq18YdCUJ4aXjqx1D0VPNGdIY/8JyfxbnP7QojXnBxwEkNOcnnnC/P1quvLgqz3hjoMmtH7Pzkkef1Z6y23TzhDK9HByNCIbLk+OSKAKSzxQDmLhuWmnrp+KODRnU0FuhWujK9C95RrNqIz605I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744002102; c=relaxed/simple; bh=4/dJlTWkcf5FOf5+oh0Up7fh8r5QO82sMonPjvpz42s=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=sGrj0Al0zFuKyvF7Lb11luF7DVr7Bbl5SpzWTeBzuwxeWX6MUeDEuyzo2tUlWl1BSzBiS0qUfiLHXBUhOk4FysZ9xpwZx3G8IehJ4+z4yfg0Cx7oF0mOkITMAgz1LFexqgYf10MQhZhGcLB1TWODwM32+Z1H+KRX78PflC1RZ50= 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=2HyDl5o0; 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="2HyDl5o0" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-af59547f55bso2382981a12.0 for ; Sun, 06 Apr 2025 22:01:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1744002100; x=1744606900; 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=AtCRHQR2grinPcYBxNOrxZNvf1a5RF1zR0pJL1Q63Gw=; b=2HyDl5o0K4GRDnDtVvjgF56pDV3nMhss75zm8m2xqL5vdDp82j6fBhoSqb5ppjSHAw AMwFZBcpOtiL0LBIOrT9M9wGGxpSWVVt1aTimsbmWiBynPAgp/MrCmgeCq5UUUI/dBrH 2VQXNff6Z9GgYVKfh7WFbPPCYoiyNNuPP1NkmFJ8ejOTxiw7Xbp4PiJTLSguKHC0VPyp SBuanuhQh07JOweG2pSUGTTDvx9Gdy6CtwOtRE/iHaGg6QySXf0ARezh00c8xmhRV+EO aTNFies2yBk47ZLqpk/AdO6aW6w3JVEFef5w3a7XwhNdl3EnGxbQZTjUv+XT7iDM6jy1 O8CQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744002100; x=1744606900; 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=AtCRHQR2grinPcYBxNOrxZNvf1a5RF1zR0pJL1Q63Gw=; b=JvH8XDV4E6yIFwqQLPMHObBoi03ZlsQQRyW0eaBO3ZoIQxTUyTSpojxnbCmkWs9ly9 Lz8rY4YrGwQEzmtjIjH7xOhl9qYgcKNP8WKTyteQVNffO6GV7wIyDi6Mfi12zwc6sCiy mlCqmTx90Rr54RUFLufk1uQS9bE6jyLcMP3m0psyIFCBrQOoSvdgyjSg1TL5wmdBwAWw 4GG01aQjBqiGtEBJksc38t+2WPs2FlQuDiAiaCHLO3Dks/2Olbg+N5rJxzKkBYo8p2S/ Kb5prwpNLdNkB7+nG/VFp3ZnXZtzEoBnNAhXM9FpRL1ZmjKKtJ3tHOwvX1fkOdrtkFFE 0Bmg== X-Forwarded-Encrypted: i=1; AJvYcCVV6kltq83wiARx+P5JUHqNT3RSyOL4/hGUK3z4s86EHjUUIx6AxAylRvjccvDI87mt40uWETEjp9ofEok=@vger.kernel.org X-Gm-Message-State: AOJu0Yw2HuX27Tj52cdyDN8kbvG03ddECL5o+/57YrDYab6QE/Xibkoj s3OOPBzfmPhU1c7I8cA4QGJuj4RmGxypKvIX48V3PxKCM/uNVKpX0ZKleZ708fPEmn1QG82tKRR 6pKPkgw== X-Google-Smtp-Source: AGHT+IEjajBXa+ImbR9+M7N6IJYR9vPfq9GEqRJ+O38SQ6pLjk2N6Ar0bQ675WJLx+x+Zi12lyBWB7Q29nuS X-Received: from pjur7.prod.google.com ([2002:a17:90a:d407:b0:2fc:b544:749e]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:224b:b0:2fe:a742:51b0 with SMTP id 98e67ed59e1d1-306a4b86c9dmr11892592a91.31.1744002099857; Sun, 06 Apr 2025 22:01:39 -0700 (PDT) Date: Sun, 6 Apr 2025 22:01:01 -0700 In-Reply-To: <20250407050101.1389825-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: <20250407050101.1389825-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.504.g3bcea36a83-goog Message-ID: <20250407050101.1389825-17-irogers@google.com> Subject: [PATCH v2 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 , Weilin Wang , James Clark , Xu Yang , John Garry , Howard Chu , Levi Yun , Dominique Martinet , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org 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 --- 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.504.g3bcea36a83-goog