From nobody Fri Dec 19 14:27:09 2025 Received: from mail-ot1-f73.google.com (mail-ot1-f73.google.com [209.85.210.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5201D22422B for ; Mon, 7 Apr 2025 21:10:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744060223; cv=none; b=dY70DAcYRm9W9r6ULqCM4IkwMOeSW/zTkuetBrGTnFftEaV2NdRVNJbv/KmHOB/CnI2XcRXisNiUUyhJQAGo8zVYX6uar4BegFlJpiJsJIf/VWsoko04HarkKKWO6ckpmnLNTt4DRTkrjSxH0LFjnDA+kZz0gkb1X70gFgqwzbY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744060223; c=relaxed/simple; bh=oTGRBpcL/2sIHNUD+/BM6BV/LmnMI5XK3yo3xDS6KyQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=b4GfRJLW6BWPGYWpN8doBP49h0MeGTBZhPBieg/SMq1MKQaGm6pQr98HcpsK7ahiVQL2yHz4DBQQX8bVkXDcFnsxouQcd+rU6ti3AKSVAxQj6oASCH+6kGVrWoGKBPaF2PRWyJVDt3eSTVNtDGTmm17SKOYEeHYPqKxFZdxHp1g= 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=jy9Tkv+G; arc=none smtp.client-ip=209.85.210.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="jy9Tkv+G" Received: by mail-ot1-f73.google.com with SMTP id 46e09a7af769-72bc266dc24so5422797a34.2 for ; Mon, 07 Apr 2025 14:10:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1744060221; x=1744665021; 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=jy9Tkv+GCBUtPbS3Iv3v7fn1J9jWreDgLWYOg6fhXaJDWs7BpIF8+1LxxN3eGweLDZ Yy7xc9KdGCMaeuZkSJLT3wuQkpsY1kUSAF6UO76aNiYgWHuPr9d1Asx1r2858nqsW8VF H+EqcPI4v3lz2CRv1VFMRX9NV3cIgTRq+/o6DQyKwoTXpQGe2s+GfnyINyBDPmFQbIK/ TPGPIe/WyCqPeIqXFp44NjWqvEBbiGK66TWltI4sKm+rqg9me0VY1bJRgTGYswuzvpgU kgbOG5ldULQwUodbiqIWCBfpDmE1YXNQPrQPfkhRhyKNSh8wCoXALhlWiIv+PdHNdZMr lhiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744060221; x=1744665021; 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=tBhIcYGzRIhbH4VR5nzKFe01KIlDj8XgL3TCga1vzZE6xPYfhTexCEjEOhzADFbxYt 0as1Qza1ZMfOdyNvMlRl+7j7n4Sju/FvbifKpAn+iWq9lYFzzJMyjWjZIWbul8DmkvO5 k/hRz+HYqaRG++yX4VFjAF12VW0TFWj2WcuD/U7jyQM3LGk1i9w72EIEoYmAyIOY1yj4 0onip51WN/HN03o9q34FGU0NswuoZJVIleT1bMUtht952VFABRWAOX2PMWKBHigTZLkp IzHp+mOccqql2hBhXwcf9cF7Nr7gonEGeQPQ97UMOmhyAtpxhYBrO3hyjKNG/+glNb2N TgOA== X-Forwarded-Encrypted: i=1; AJvYcCXBgGdt7s9L1Ow0Xyf5ZqU9cva+jn3rIVZpQCDQmjQzAf8d8aYc61ZS7M6dp3LuUv59Hdn4aDjeAgVp39A=@vger.kernel.org X-Gm-Message-State: AOJu0YxeVQ0wrTA7HSzJ3aIAX1f1m+79STdGpUvttYaQhCT0ZP3tf3By Qvj0kKN8Nc6o36/yqT3dAXKP7HLMpVI/TPwI7fJB932QvPvD1MhcK7OUtDdCW8xXQhfByGBUELh U0vvLpQ== X-Google-Smtp-Source: AGHT+IH86lGfxCgWinbFenzzBxH0UG6egEG9qpsbS3h/oG/yaY/g6stYBTEZyLftj9OgRe77MLupZYD2cLwl X-Received: from oacnq19.prod.google.com ([2002:a05:6871:3793:b0:2b8:ed65:d4c7]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6830:3704:b0:72b:96cc:f994 with SMTP id 46e09a7af769-72e37f2b89amr8850830a34.5.1744060220966; Mon, 07 Apr 2025 14:10:20 -0700 (PDT) Date: Mon, 7 Apr 2025 14:09:22 -0700 In-Reply-To: <20250407210937.131681-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: <20250407210937.131681-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.504.g3bcea36a83-goog Message-ID: <20250407210937.131681-2-irogers@google.com> Subject: [PATCH v3 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 Fri Dec 19 14:27:09 2025 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AF48A22425A for ; Mon, 7 Apr 2025 21:10:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744060225; cv=none; b=LqqgMS4DPHOSlIJ64MpaXB3cCPyFFATqlAD9+8Y3otq/bgEVh1NyGRZENQ4MiddE4pCwEh8tRhe1j8KLPdf8JiVVo4ey9LldLH7s/Y9mPU7QJa3G8QdR1tLpGFwiwclFG91tfljLG2KIJQ5u4lliqT2h0n4+7xZzTFfuxhjrOQg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744060225; c=relaxed/simple; bh=ifUhHpvB3YWjewd+FCiG+bnPL8N1hMQyEOj1ALhK2zo=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=CseN5vkCepF5CD9K30b4ScJbvi9aKfJQnxkb+aRbM/wM0Xh8UVKOOLMzeJA/WFCbA+3PGoJorpwZ9hpfJYLchL0Qmb+eI7afpiHsmFggDG0aDYp7RgwV24l+jpw+6Y3JlfBsJ2o1mEt99x7YyBt5PDwm6m8Fdn807Ur4iX4OMQc= 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=oJEtIFHR; arc=none smtp.client-ip=209.85.214.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="oJEtIFHR" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-224364f2492so41212505ad.3 for ; Mon, 07 Apr 2025 14:10:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1744060223; x=1744665023; 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=oJEtIFHR/xWIcSH92yqkomCZDa2rgp+wMrkl8lHCHmog0tHNDkS/so7rAHfLyxgl4Q SCKk67wnPj/Xn2ZoJ3uMOIfLhrJV0W0zkYbQBMrv73wJdgO6vHlKui43kqA6D1jWeEYD 2yVHXEVCDdDCg4tqP4TWEiZmwBZz+J1LopEEcK6e2Zzb+Q05RCcIm9d9KX1wilib28ZC 2lXGGPArTzT8iOE6r/DshzWIeq9jYdpXfGhU++qYVfjGlOeTNPo/1aw4Ip8pk6jF/0Xv tXwwkeIdJHUBKCeX2RL+pqNsLiN4RX6UeXbe6+dNwKsW7c00hhhbfCrXkA4nOJzazLzC s3Kg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744060223; x=1744665023; 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=didM3Yed5kpdkM1nuomfM6X3Job37RIFfzwWhnN36JQqa5IpToxYNlzpbATPMnjnyE n+kzxN86fqyMQ1cY4gG/fSxdrp63KGtch3n9z/LOl5+8fmeOi6OK4pbc4vpFNUveKrI5 d/ZMonPlWi4EZktWhpjrxFHBrOAiryrPzdvG0sw/RbJcU1AX+NFC1x7vEhvOds/Hm/5/ XrigaO0O8PPt/CyU/YstfnOZXtERfnG95kxS0gT/AwCBhmFfHZX04R+JNxNPONX/kAtb 4ocu/SZyKQYXDcO8ayTw5S2Ydfg6RPmHV8x60YNWyqRt5BsJyPiCKn7lGe+H7Rtn1VrN bsHA== X-Forwarded-Encrypted: i=1; AJvYcCUxEV3yPEHirwn3zu9Qe2VYWdkEal7O6nkXjZMErNYcUgBxW/Gppof07uCTZ6nTl+566XCwZz2dfMCk4oo=@vger.kernel.org X-Gm-Message-State: AOJu0Yxt2f/hSG8raxPLsCtfJjzOyENSLQW+L4EluooqKoVcgVxpoe8N 4VjP1RoMPWK6wITCnMzFxB1zHs5vHGw+WyeodpYEPd5Y8mLiTHXIlyLCfuMVjaIXKk8SK47x0+a vXJHOMQ== X-Google-Smtp-Source: AGHT+IEM3/2+3p4g2+IjgFL6miLEqz06Qs4xo+S+z4grR7818G19GtbHRP8lOTbPqoj/HNDYBnreHi+4zdDE X-Received: from plcc1.prod.google.com ([2002:a17:902:c1c1:b0:220:c4f0:4f1e]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:f54f:b0:223:88af:2c30 with SMTP id d9443c01a7336-22a8a0583d6mr184935005ad.16.1744060223017; Mon, 07 Apr 2025 14:10:23 -0700 (PDT) Date: Mon, 7 Apr 2025 14:09:23 -0700 In-Reply-To: <20250407210937.131681-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: <20250407210937.131681-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.504.g3bcea36a83-goog Message-ID: <20250407210937.131681-3-irogers@google.com> Subject: [PATCH v3 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 Fri Dec 19 14:27:09 2025 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 63072225779 for ; Mon, 7 Apr 2025 21:10:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744060227; cv=none; b=GiI7hcZBBnPVqlSEVxDOUoya63p5pf7qLrFq/WGb3dESMRNxXwazN4TgMf4Bd9pfd6r9tXogt7olwskGNuGcj5e0qN7lGx4qNeZNCTDJsJchs+r8QfHWKqXuEUfxGeONOW880cvAkpHJdAa/kD3vG9fDGJnMIlaagcyT33Irzyg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744060227; 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=G5mVz1TDSpZH1AOaIXHb9wW7OcYHHEU7stMrnVHFWuLfSJwwMKyT4k/7LR3XD6FB9VMSw1TBrTWLZBHvA2vXyiRlm6v30Pw1+X3PxmJYlXfbIW7jnbhgdJq0Me8xtYpNnNRZotWhg82ESUgzhlVBkw0al1nIP/j28WTvjSSk7w0= 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=IKB5aZ6T; arc=none smtp.client-ip=209.85.214.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="IKB5aZ6T" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-227ea16b03dso68112135ad.3 for ; Mon, 07 Apr 2025 14:10:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1744060224; x=1744665024; 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=IKB5aZ6TGaEuUOoHR3vthZg6WPaoEtcwCIsykYKcs3nML9cpL3F1gsqvqcUfSI/N8l e74Gz56fhyDKlb/FmB2T6QgE9lhWtpFbHRouDOwVDGmyOHD0WjeivMkfL8uqIkn85tQs 2ZrBFuNWN13Y3yE3hQ0O3JdKWFOi7BXXFZ0xUhV1W0lRnHmu17OWSXi60k7SI6nDU1sB bv59Mbc0QZq3gGFRu9jMio2jsPAyTf0mgdiopGla9JrGtH6r9vTY+NGf3cN/7udzll1c cdMWp8SPQNYgn3SiRgOFg+j/pwytEsMmfuv4z1O2az8Qo/bQC2eRgA+CDh/vvHwB0QGu kA/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744060224; x=1744665024; 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=EZbMqbT5ESEXt3WcjWkrO7XANQqHaFyNa9OmpnVar7BDoQ1k2UyBugKycHH3mN3Ydg 8cKSNMP+os7i7DsCEPBEKw1IFeIICglD9jaS3w4EsZBdChudMPxDC7gMYDjsMmWv4q5R WHhO24DOdftHVjIG3G84aATek1Vk0U0PHtWNl5ujYXJEwcimuzPkPTsT/0geqUoTAlD8 le50EmuQlbN0k4rR2RHl4tcEu3+Knx/ZZUWqzKXJchg7HfE1A7oKChIjqJscaB2gNxhn 5O365t+DBRGAAx8u0+3DKo8P9TgN/Pd6mXTVPYVXq5YZkeIu3TL0Dbn6EPtHSA6cHqeI FzsA== X-Forwarded-Encrypted: i=1; AJvYcCUSyCt+GIyyQFCMDIriutK460wKBBQ7TAhe6rcZzfrO06oqx+ZEQhp+1P4rqFmeIv1eqRLh/lw2mtkWCho=@vger.kernel.org X-Gm-Message-State: AOJu0YzPRLRraWMl7fXBXbQPwnY1fyPATuPcXsRw+IM4eD3Ds2Dmg9FJ gyhtGNjEoOMbld4bi41fhuqlXIk3UqY3gdE13ilcxs1EWeWDqGbO90j5RhC5UXXfaaCkevSF7IP hhH48Vw== X-Google-Smtp-Source: AGHT+IEdWPPIqwn5SQ6gdoZhbvYZj7NCxoOyVuJtRMp0USM7fGqNRDiVzvwVugZTgrPnttBZw5vpC9OJwKMM X-Received: from plpj21.prod.google.com ([2002:a17:903:3d95:b0:226:342c:5750]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:d487:b0:220:efc8:60b1 with SMTP id d9443c01a7336-22a8a0a38c6mr196325175ad.39.1744060224626; Mon, 07 Apr 2025 14:10:24 -0700 (PDT) Date: Mon, 7 Apr 2025 14:09:24 -0700 In-Reply-To: <20250407210937.131681-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: <20250407210937.131681-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.504.g3bcea36a83-goog Message-ID: <20250407210937.131681-4-irogers@google.com> Subject: [PATCH v3 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 Fri Dec 19 14:27:09 2025 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 705D222ACFB for ; Mon, 7 Apr 2025 21:10:27 +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=1744060229; cv=none; b=iyF0h+rTs/MwBj+Ngj7te1dxQDgwzYZsB5tapWdufgqFIKOi/3r5EXTbIOJUGfP7DnY9WU1tog+cCNphO9FYnjX4/kmCqd0s6kRxi3Xw8MSF8MS13y8Jjq/NCmnmeIsX7BJ3Z3RJgBWeBOaOuda/2HqscPVaamXX0uzvFBU66mw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744060229; c=relaxed/simple; bh=JVanJEDpcMknG2x/X1wULUkE8JUqUZb8O7VIacDzqk4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=hsn51+ZBua9BYGMQVNDWuz4IBSdmwd6WMR/NTtdr15YpDGK0UWDA2opLx41WAbu9M2qSJDuJqqPNqbbD2bo8QBI69RlwgOjt4yo3sVBDh3SwIw3UGMw1SxQFDevywdZQQy7HXBb/wfg0/PYZKEx5ZUYkjFYNHgnzaj9x6OfK+Jw= 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=mNIzovsO; 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="mNIzovsO" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-224192ff68bso43761215ad.1 for ; Mon, 07 Apr 2025 14:10:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1744060226; x=1744665026; 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=mNIzovsOcWqGtIoU45YEMxjs6AlXhf+KEL0W8n4yXK638qZzSVUDnS6bNUR++nOvXC nKwHT/CmIkSAOytHJWUa+YjNY4r3stD+nt0Q+wrzkTpc8qLLBmJKKnaGt7F+Ii2vuILl PNdCEBCeI9NW/kTrl0tZTByoNFxxu3GWbwPp0kXV9hk084zgB5cOtB1hklEJ5Id1TIM4 drUl02TaR5gr9eF8sTWVB76iOum6qRLN8e5GWvXhPy8Me61+eGY3CeDmuIUWhKASdTmn pCo6DvXNsN02t8qaT1YkRwvfX+4iVvsYCzFtLW5CAhiZUu2JW1QNtkbekw6rPlMChawi nfzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744060226; x=1744665026; 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=g1D+MekRtSoRm+WZLnzw9YaajZFu+ChnQGAW8dy5RJBw3Bmih1MYTOyLt+0Nyes9G9 kCAUYMqX/5nRrk7oe8UnfdEcZvibhpMhAy59n7I8JhR+Ab0aFdAjDdDsDt9Z2zkwrmMv kWfB6R1J64BMgvTYXBnQXQebUUCdqZrZoqNa9ovjzh6xF1Uw4boka4HlQlq1ihuXgBFd dILPzvi1YLMr1fAdnPiwbBuRArPzv2HYv9q6WpIgiGlY7LtggULq3sLI8N7IYRwxhDTn DPlgfXp28fvfjv2oH7DvmqKLk+Y+MIMMBN4hw+2D2c/wuWeGZGrLc7mRLf0XNZhbXRZ+ zuMg== X-Forwarded-Encrypted: i=1; AJvYcCWEOqE8HSLFakRaHHlZul/OWr4RuV2vlZyEjGUwkZo6CmqQKrFalH80r0Wn3c3A9k/XPOLl9RgvaFdcFlM=@vger.kernel.org X-Gm-Message-State: AOJu0YxWlPgQZnGW3o/XHc25ZZo304zstfycWCKnd7065D7emKs5cxNe zcKwCvtFDy2gnJAcE54NaO+Hi+/J8prw26YZfHmCUbpbI2y/mXTktntgyyssyv0sgFS0IZkC9XI a6kGcUw== X-Google-Smtp-Source: AGHT+IHbbjyFTsZ+5LX5MDdV+PblkpIeW4FoDHAWfCSTa1wPjBafh5IcHt3bt7H+l2RfM8DnB4h2Ux0P8And X-Received: from plbh13.prod.google.com ([2002:a17:902:eecd:b0:223:4be1:70df]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:1b08:b0:223:5e56:a1ce with SMTP id d9443c01a7336-22a9558975cmr163703025ad.32.1744060226581; Mon, 07 Apr 2025 14:10:26 -0700 (PDT) Date: Mon, 7 Apr 2025 14:09:25 -0700 In-Reply-To: <20250407210937.131681-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: <20250407210937.131681-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.504.g3bcea36a83-goog Message-ID: <20250407210937.131681-5-irogers@google.com> Subject: [PATCH v3 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 Fri Dec 19 14:27:09 2025 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C2DA824EAAC for ; Mon, 7 Apr 2025 21:10:29 +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=1744060231; cv=none; b=g9mZV6uGj4ywjmECf8XBwdodvEvqLpGjGQpZb1/orQyg5YaDZ6izoYg+5l/nr5+vwnCO2VHIhj0/DaQvl5JrcRP+vzMw7BboVesUMVa6X9DeldD6Uv2h9BkTS2SMMMFrfgJi56PyfazKvuWEtUImbgGO5IZVtEED8g0gMreLew0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744060231; c=relaxed/simple; bh=yUglDtEpwZVjaGPveMCOEFvdP87AB0tTSBss9c6TB98=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=BWxGX08MVlhaP7biOqbPLXFWuJcqJxD5JKg43yyeUacs2vZGSqaQRKOBnpT4TrRdTnpKDCZ0Rr8ojCd2RqUEecQgD1xI0+jgwI0RbMTPCohxHDxuJc2MhtN4p/F+Y0O1WPIEH7oEnuSMv2gnkcVB2ULgo9Jp53PQ/4KbKWuKiuE= 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=4FNIBkLk; 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="4FNIBkLk" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-225ab228a37so44086195ad.2 for ; Mon, 07 Apr 2025 14:10:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1744060229; x=1744665029; 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=4FNIBkLkKHPBXj6w6sLljQJ5b+3PJwnYTk/MmVivkAW+aUyjLtD3EocFDqrLbCQGcq EjEPt8SaTXpndqpPsBXoeMwqLSR5n8VhokwOqSKLykxCb6zeewRHYuo3tyT4gxe7Hqw0 wrilFG/YpD5sM/NNv2upJudnbZX8mqPTSWkHrI1+P8t15yslwK4w/qhiJkTs5iIHnofw nROqSnQ5meLZ25PjTRDQoDlDhvvpeVsCCIu6wLpyBB7+DvfD7HoifFn/E+tn0QxIAU0x RmDXQZSgSWdUanHRwDZtPQt0/V3lYS5GabL+vtt2I76jDvtC9NzCfPn0Ckxj9fCXkU2S Jc4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744060229; x=1744665029; 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=k1lCcTAxUVt1B8i7H3i1x+TFvQA/5GOAKCsv3XRLJAlYe+nPH1rToei5elyNzhWxxj g+lR3NhOk0DpNhErYuD+eWwnyCyZghJQPQE1f0oCvtVIqrpWBGXyw4Ew+QI0ILt2hZl9 7qbB33KqHDAuaPcme5Q6/dTao4/zWVLKX92aWPWwGESbaCovhqlLgQKuHgaBcQDIhtKP Qrfx8uW9OThGyUitnuPjfR0hq+JJYB38SCO4yQfipfzOFB2ZUh66jkaincPwdVVzjBQQ 6GPc2YrVF5q0vYGuTHiDa+tSzHdtWdRPu6a4BlvHw997eV/sERnzEcb2c7bMh63e+vUW aP/A== X-Forwarded-Encrypted: i=1; AJvYcCUrtmRELeuIGEGI4wUTjmtkLrtgDHBbAURzobZg4nLYw1YdBiSTl/+2oFdL16fb36qmFcA1xOKxIz97X5w=@vger.kernel.org X-Gm-Message-State: AOJu0Ywge9Mm4cs9i1H1wn/Kmhg6a7ivBXwWAtquMK7hQ1tP5n5R2/z3 NOsLj2bNcva4bp0YnwojPujpLkqY3ZLzyiK3buk5Xa9OBTjKYTxo53aoFKVfuwcCDB3LScApiMO kZP6PpA== X-Google-Smtp-Source: AGHT+IG9rZiysNyuhyIctDtrxbq1yit5AwHZJLJwPgP4NCKY3s30lJRz5iRQOMp/NGlivPfByMiJlgivi0VS X-Received: from plao11.prod.google.com ([2002:a17:903:300b:b0:227:eb6c:504a]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:f550:b0:224:1c1:4aba with SMTP id d9443c01a7336-22a955a198amr151717825ad.50.1744060228980; Mon, 07 Apr 2025 14:10:28 -0700 (PDT) Date: Mon, 7 Apr 2025 14:09:26 -0700 In-Reply-To: <20250407210937.131681-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: <20250407210937.131681-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.504.g3bcea36a83-goog Message-ID: <20250407210937.131681-6-irogers@google.com> Subject: [PATCH v3 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 Fri Dec 19 14:27:09 2025 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A9EA22222D4 for ; Mon, 7 Apr 2025 21:10:31 +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=1744060233; cv=none; b=g+zkTR1ToHwAIZggVzgkv79nqBffQOocmB8IHg6Xlm6PbAaIBb/O46H3nQjPfc1POorrGAhwZBcIhwubzkIHIn8ciTU9ME3ssNb0Z+HldKAWz3jjCseQjg7iz59Ai8w8l19mErocMT7unct1hZvOqdyudQeYTrvP9e0GfpkBp74= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744060233; c=relaxed/simple; bh=uzrqNAXM/KeEjp8qWr6xTf3VLWW7e0MNaK/cvBjUNjU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=frueuE+Qt2SVhRDCd03wiwBRgOMTXMBD42zFye/UtAP0sEaK/LtSlZOrFQw/vj/NvBd2rK0hJcISLfBpjeMXKYInEkQPayeUqdSvcnlMKb+SXsatH7xFRMmb3dJy0YnpFvQahlHw9cWBzz4dENgt/J0io5vwZcfkJo+XTJa8pBA= 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=S7u+bNNu; 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="S7u+bNNu" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-af9b25da540so3169859a12.2 for ; Mon, 07 Apr 2025 14:10:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1744060231; x=1744665031; 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=S7u+bNNus/tPoNXhTSKRhC+Sewg5Y/tYbsTzKD/8IQI1lI7yZwC7ulFuQwGpLYRKqC hmjabGSyIrBNeyVH+iYBpGvwzvXC7wOc1KAvmSCIPxHd9Nnx/P7xL0hug9fUCYAww2oW fjUpuGwD/seQJNtaUsvayoXvntCRIKsjbW5itS6v9aG3FpXzBkK7uGcp5EdSUqctJ2Vg r71lKvWDmmArpj2x77X9qTCPx4jLjrYXn+lr02qm9twz5KwUsyxn1tftoEYFCEUjHWtc ek/PrrU3FknCmLBxMO1hhmkNxLCS+LldEsWo0EIORwEoEW46RsAg9HnJDontq4v7EMmf M0Yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744060231; x=1744665031; 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=uvznW2045vfmeUcU9QbcCo6fdrfkK9Cuzu9SbqRA8/Su+pqdzPfZZiTCh32kYo5+nf 6qLIWTA5XKYVB7AyDqJfp1/kcCXU853z6RnbLMiHKKiN5BSCV2BBT+HL10XYxb9JsQ6d kDGIPL0QmGZ1QdWp2Btc1HicHlZbizsGXZeOEvEHz12k7cKTE9gFKtZ88wvbjda7Eevc AyyZAuV4zRJhfjmhjHij+h+KHDkvZeRGz4h6BXwbbRueWzIBwxyhIOiLtLTIGqzZ5q2p hLUwz58gc/D4YaVdJrYjX/ldRbbRyECfAtFh/ECrV9ysc0RrLicWL1oyAnxygt5Ff8zf ZKgA== X-Forwarded-Encrypted: i=1; AJvYcCVdoFBXBstJzX8HMlbpx6i8V3FJO1PEpY3B0r4nbozuWmWkQa34XUrWdZUZ8sGfzChyho8EuTzEdVMfEqs=@vger.kernel.org X-Gm-Message-State: AOJu0YzhsOS6E3n+xF/I+vBhODGfqZlazOWHnYVLn2JhjJqSeSinX28w +JPrC3DHtvF+t462SNIgAhXwNzA/gKWLYJuCG8zan7+mGojQaXF13FPc5Q71zjCqrjD8dxn62uK IC4ANdA== X-Google-Smtp-Source: AGHT+IG2k9E2FGZOV6UOH2nAXBeyLI9TdPuQtWFKKCrGUOPFaJAXJTcOzcwDaP2Hq/2jrPZ9jTd9BB9ksEtQ X-Received: from pjd8.prod.google.com ([2002:a17:90b:54c8:b0:2e9:ee22:8881]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:2398:b0:306:b6f7:58ba with SMTP id 98e67ed59e1d1-306b6f75902mr6667474a91.6.1744060231030; Mon, 07 Apr 2025 14:10:31 -0700 (PDT) Date: Mon, 7 Apr 2025 14:09:27 -0700 In-Reply-To: <20250407210937.131681-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: <20250407210937.131681-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.504.g3bcea36a83-goog Message-ID: <20250407210937.131681-7-irogers@google.com> Subject: [PATCH v3 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 Fri Dec 19 14:27:09 2025 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 62C8E25484B for ; Mon, 7 Apr 2025 21:10:33 +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=1744060234; cv=none; b=o26tX4tccJJlozbS/27KoZFm7+go6JA9M9+0iAauO4EXLEwgMf0V4stkn4XdDsccvw1veXuB7TnNb6Pa5pKth0VTv9JguuO+6NNU0Vd4VezzUG5y+ZO3eR5LjRcGuF7Qz3lu0rMbWmr5l7S9JSh8lLuJ3mF4qK2LrA7B1rMJ5Qk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744060234; c=relaxed/simple; bh=dmk99xLT8Nx0mz4ddF1+mWBkWibkJI69saN0P2VeVFI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=bgg9aDzZID9ej6bX8nxyfKT0C+mQtcY9QVxeBv2cv8D5Gg24xT3y/oGqqlYok+xeewOjq+lFGUpxzzbO+oWhYcTuA6ovYrPzOebX3lG3FWWUq0j991hmRUAJNoWeSHhgjR9RqpSBrha15T4IsYMrzEacA20OP6Y0MZ1R18gDPTo= 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=XGcFkcbe; 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="XGcFkcbe" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-b00aa1f50d1so348874a12.3 for ; Mon, 07 Apr 2025 14:10:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1744060233; x=1744665033; 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=XGcFkcbeC+e2Aiggw3tosm5r1SjWZJqwqnHUCR225LsXmflF+TJfr7QvJwGWLZTO3c UZrp8F44vEncjKI03XYxDMzWwC+LgffFPFmSbCWWNDstekgq8AEnDCD8AWB2CX4bV+29 WgIkbHFarU3wpeen6KEiAv0Ce5UhM+QvXDXyWX0D8Mjk80X0Pa/pv43eYdHTyvBoBNJj dGsOdaQrXwQQCdVUD5nIWhDFrhMus15h9t3xJ2+gl0BIufVpKFd2zzzpUDynzZPuHzAY qoduNqUBjVWW+/iQBSpjhQ97VIt0GPhJEn6xgf1M0H0SL5qPTiSHKYOUDuij+OQZBiCW fbUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744060233; x=1744665033; 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=sRKPcgD1f9kXkPVv0zufHeqZJbgfszjDF9JOTtJUp7JR2IvkINPJfkoqqy+IQAAJaA VZukYPlc/DHJXNDiPjmxL83O9ZrwCrWNlhvrvTGdNxvU4pFtAESzWvf1YasE2P/1K9YH rqntolVkxcGsgTx/+6vkgus261L9dCtjRN0ZOkICzLBf9NEDlZ9kGl5kmvsVZEnvGEo/ aokPcwz+F9DiTdjhmItFnj2gQdoRdbMUpzyjnS3+EFHY8dn3ZU5GIbuotPluFJaCyc+1 X9JHeUQMfrrVjjTNxKMePUf7/yZCb6MdgBee/Vbegdt9RCDLJNg0CSng69NFj8xTJjgQ bYwQ== X-Forwarded-Encrypted: i=1; AJvYcCVfdTL+qxRuTq3q6OwvaQMR+/DUPRQWIVX2+DLCiSPh+wg/imwI8L8o4iPLqV6ocq8g89WykmgRvrx+cqM=@vger.kernel.org X-Gm-Message-State: AOJu0YwT589Owo7IdgL7TFoJAX7ou9P3Lb+zewcDLDWKAm7AfwJyF0oT 7/ojJNbeNP4wbtYQK1ExO35hBg7TkosBy8sMY/1kNpiTw2uL9Q7HWBMBnhfIf9xG0TN1EDfuh+Z dsB1zNQ== X-Google-Smtp-Source: AGHT+IHxbggJBMjv0kTrMcvBAtE/UmKuR2I5q/zXUAd4FNzjEiQbmTkyWuNrkiEcvkeLqrJ3n+r4Y7hqCjfu X-Received: from pjur6.prod.google.com ([2002:a17:90a:d406:b0:2fc:ccfe:368]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:2709:b0:2f9:c139:b61f with SMTP id 98e67ed59e1d1-306a48650dfmr22917867a91.14.1744060232771; Mon, 07 Apr 2025 14:10:32 -0700 (PDT) Date: Mon, 7 Apr 2025 14:09:28 -0700 In-Reply-To: <20250407210937.131681-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: <20250407210937.131681-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.504.g3bcea36a83-goog Message-ID: <20250407210937.131681-8-irogers@google.com> Subject: [PATCH v3 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 Fri Dec 19 14:27:09 2025 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C919F254AE5 for ; Mon, 7 Apr 2025 21:10:35 +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=1744060237; cv=none; b=BMEiz9PkTn2AF3+gfeK5wQGpHoBvKVOyxICJ6e97yaSbvY45qAZ3T+C+71asFadU6ZT4Ek7IDSqxH00XXKuOtZIctZp1m+kFOIdnKVJ7mR678/fR2N7p7QxprSX0DypBTw0gl8vJAVStdKaQcosgTGOvnEtVhPfABtBARxXKnjo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744060237; c=relaxed/simple; bh=6EEZTd9lf9aeTITKws4CXHLVcUfJH0Aqr7eXP+eg5Q0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=ejZWGEhHbFGOcn4DlXR0cgVrE52HzAYePxXufi8pxXZdHwft9riaN3pXGNVLCbXhNH8sqRLPJZavdu31lRFOh/ip7R3UCOsTlniTOn8IZaX13I8MR3sMVdOgvI9HjXW3kCZ0XdN7CbdbCRjpkLf9wgVuQU1F+SPf+wUgvho888c= 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=b0ZdOWDY; 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="b0ZdOWDY" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-736c7d0d35aso6781887b3a.1 for ; Mon, 07 Apr 2025 14:10:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1744060235; x=1744665035; 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=b0ZdOWDYPzkKlLBSwuPn98o9jZQxubFiLbREpnTjOoNZyWrPhzmFJJd7vboG48wi+3 F+vU6GoDAp/mMNSJi3r88OHFCREUMRAbWCmUA76aaW2IaLpUSLBrZoxKJTDGMIJv3QeZ 7j3/naKX9qQcl+uI2Xt8UCiN4+nkiPtjrH7+4ZW2WMKBs3teWk/qTL3rm/p6NB/kZaqK UQ24uEPIwnOasz86px5ugdD8iOEEsULBODJ0lzZcgU51A9z2UXEEKSbnBwpTwyJY7vgB pj2B2/VgV/4JcbgkSV4zGuo2u2MUDyl3sjd/4r+yeAAQHILwSyJ75uqLnPsTfV/PS4rp xyFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744060235; x=1744665035; 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=R8ZAOPbQ/n6tBkJHs8IZpaLxfGxz4WZMkrV7JAuXWdrrn1tykGsMCE+mCj+FmQIQcd kr43KNj9SVcbBMkNyGeaFe72KBJloT0jptwZP0ivoq372Vjr+PWtEA5hifeYQmolbxMy 4Q/c0HqjFs8H8wSSdiDPUcDRNbNtL9Bkqv1QF2OBeZs/Rvf/Tjqm496wY1b39FPvpShL Kx1LSkEL/gdWwcFmSM85BnPEGzqTKLxGW05M7+ZNoC2zaT3sKJfz9M6FNqm4oGOeJ/cR xNQfwIt2+G/64/YAjlVwn8xhgA+Y0btEPKX3zHdEou+QC1xc/9wZaq5RnNv+oT+SMJcI ZxhQ== X-Forwarded-Encrypted: i=1; AJvYcCUVamCx5/HO7ynYAVyDYIgXWtAisJJYT7qG+NrOYxCENECR1K9B5COqSSpdGywACqm+NVFMg80aPHKPXjQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yx+HrPSuZAxP1ei1+zIPQ511RwJActod8tJYmMBZBTPGNehd+sH SxBRCgQggjKRg1uX6aRai1zBYJmrolIVBmJVtZ3F/qhSwVS057bNoG+1yO26RQczPdX++8s9iRu sOri/xQ== X-Google-Smtp-Source: AGHT+IG2gReaDEhE7AblA2Y3U9htDI7NfqmCOk34FgpaGt3QgefP3GK+JbE++vQfUPtqb40kDnRoF1PxAKTC X-Received: from pgbgb3.prod.google.com ([2002:a05:6a02:4b43:b0:af9:1196:c39c]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:c896:b0:1f5:889c:3cbd with SMTP id adf61e73a8af0-20113d5539amr17830240637.35.1744060234905; Mon, 07 Apr 2025 14:10:34 -0700 (PDT) Date: Mon, 7 Apr 2025 14:09:29 -0700 In-Reply-To: <20250407210937.131681-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: <20250407210937.131681-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.504.g3bcea36a83-goog Message-ID: <20250407210937.131681-9-irogers@google.com> Subject: [PATCH v3 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 Fri Dec 19 14:27:09 2025 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 865B8254B06 for ; Mon, 7 Apr 2025 21:10:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744060239; cv=none; b=tJ4E8cVDcKiKL7VwzmlWFeceWUYr+/K8KPjs2XofdpTgKYXs8edERp+55fRH8Jcc0XOKxfNk8j+FxFEZc2+6loMNNSdUVq7gOgQ212aiRS0M/Y2wi+gUymPB635x6+Gw40m0HsDNzhIn9+tFaUoO862gvMhY0o6EDMxs24Bq6bw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744060239; c=relaxed/simple; bh=x712Sf+REbTmULA7rLtp2gm66BCVWDC8OsSNLy0MlXs=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=MY8Fl1cxH9ml+bOINsNPB4GgQm0hicj90aHB60nCt3/1YORjt+RLZSL0EYsbk8555O7M027oUpgKb6jMrE5N7E/ksXAf+n1oqvA+3jARPe18Zn6ggVN3LJm32UwiFBRPyCGYOO+8DzvKbix/R+tuDKAOgo1hamf3coKsqdykQV4= 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=2sRiGEmx; 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="2sRiGEmx" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-af5329791f1so3586966a12.0 for ; Mon, 07 Apr 2025 14:10:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1744060237; x=1744665037; 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=P1svmlgZ1hdj/s5BLTsbiEJmcy0BtMBOLnzcKMtls/k=; b=2sRiGEmxPhylJN01ed7DX+uPbo4/HxTftRN7SFmz+MNBdNuVUZhxHGZOwFkX30y1Ql nNchujkbAMZlG+zxFS4ROe5Zc29+MZ/UvqLuWSZSNWVZhLT9e7vhW7xNfPLEokEHUuWj rEnWFfB0uvpYXwXfR/paTMdYvU8r+yax0v8msk9RBIj83tGnXSgz2Q63HwC9SbVREcma +tN1j1J/AIznTQKepFIDLa+hVIiSaGQqpQSQU7qi935qmevtHU9suBzqeTIX4xKKN3wh 37fOmt4axZ+N9dVUMZoZHuShCNqbXUTmxZfsEEUtFtWbCAKiaEFgWBCvuh6v4pKdT4/2 OujQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744060237; x=1744665037; 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=P1svmlgZ1hdj/s5BLTsbiEJmcy0BtMBOLnzcKMtls/k=; b=vZ5W7l4qj9GpZTZPGwR6xMZgfJPCBCOw3NvPYZ9dnfXnANbIvZXNA20QVzj1p13wuJ xgySAghZ9r4q0NCC/MmnxjeOotctiqsORpS60YDoLK1Esk6ClY6dKjTdHmdIdyg4+GaF iUhjA0aZP6P/3Cii2EvtejwhkCvbBPSrQAGfiYT9mUE4l+9FxJZ8qNPXTJAvPw/Wo7O3 VIyBsZrCvHaQ6yuk3qNsxGoh515xkkSfg4SZaqWWXJu7DwOQTHwHZ9W1u5WzW6cYNmDj e7rhIoKp8wCxOMzpMNyfVvlK2riQdX1Jlvy3KmzkCQ6TLutQOT8Y7Jn13yGS0ag5HXZP TTjQ== X-Forwarded-Encrypted: i=1; AJvYcCX89xrg0Y0tIKeQjO3d3CEE3cr8+BT6X+O2JxTe4BTWE7hyggDu5lcAhhaqOqosaynSERqkKWhPWEwagqo=@vger.kernel.org X-Gm-Message-State: AOJu0YxU1S8HzVrs655xWbwirssCEotyJTP/5YS+9Eaux480jrRkmrfn mw+oR2iJ39h9RKTgAq2bA4OswJbudPeqRX1/zcCXR31vHFIWZGCZ5qh6Fse8TVwHh2jTVhyknKd Y1ikMiA== X-Google-Smtp-Source: AGHT+IH+afIrKpqPXcZF8fKrH42N9R2uOY/IteCCDWB/4EJvLNqiOBA8K/dKFiY/HEtJU79AGqPXXoYPbFhz X-Received: from pjboi8.prod.google.com ([2002:a17:90b:3a08:b0:2f4:465d:5c61]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:4b83:b0:2e2:c2b0:d03e with SMTP id 98e67ed59e1d1-306d0bf1183mr987286a91.5.1744060237034; Mon, 07 Apr 2025 14:10:37 -0700 (PDT) Date: Mon, 7 Apr 2025 14:09:30 -0700 In-Reply-To: <20250407210937.131681-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: <20250407210937.131681-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.504.g3bcea36a83-goog Message-ID: <20250407210937.131681-10-irogers@google.com> Subject: [PATCH v3 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 | 150 +++++++++++++++++++++------------- tools/perf/util/intel-tpebs.h | 2 +- 5 files changed, 93 insertions(+), 64 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 68ea7589c143..80e491bd775b 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -681,8 +681,6 @@ static enum counter_recovery stat_handle_error(struct e= vsel *counter) if (child_pid !=3D -1) kill(child_pid, SIGTERM); =20 - tpebs_delete(); - return COUNTER_FATAL; } =20 diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index c1a04141aed0..0a21da4f990f 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -183,7 +183,6 @@ void evlist__delete(struct evlist *evlist) if (evlist =3D=3D NULL) return; =20 - tpebs_delete(); evlist__free_stats(evlist); evlist__munmap(evlist); evlist__close(evlist); diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 121283f2f382..554252ed1aab 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -2759,7 +2759,7 @@ int evsel__open(struct evsel *evsel, struct perf_cpu_= map *cpus, void evsel__close(struct evsel *evsel) { if (evsel__is_retire_lat(evsel)) - tpebs_delete(); + evsel__tpebs_close(evsel); perf_evsel__close(&evsel->core); perf_evsel__free_id(&evsel->core); } diff --git a/tools/perf/util/intel-tpebs.c b/tools/perf/util/intel-tpebs.c index e42f3ec39a64..a723687e67f6 100644 --- a/tools/perf/util/intel-tpebs.c +++ b/tools/perf/util/intel-tpebs.c @@ -35,10 +35,10 @@ static struct child_process tpebs_cmd; =20 struct tpebs_retire_lat { struct list_head nd; - /* Event name */ - char *name; - /* Event name with the TPEBS modifier R */ - const char *tpebs_name; + /** @evsel: The evsel that opened the retire_lat event. */ + struct evsel *evsel; + /** @event: Event passed to perf record. */ + char *event; /* Count of retire_latency values found in sample data */ size_t count; /* Sum of all the retire_latency values in sample data */ @@ -49,6 +49,8 @@ struct tpebs_retire_lat { bool started; }; =20 +static struct tpebs_retire_lat *tpebs_retire_lat__find(struct evsel *evsel= ); + static int evsel__tpebs_start_perf_record(struct evsel *evsel, int control= _fd[], int ack_fd[]) { const char **record_argv; @@ -85,7 +87,7 @@ static int evsel__tpebs_start_perf_record(struct evsel *e= vsel, int control_fd[], =20 list_for_each_entry(t, &tpebs_results, nd) { record_argv[i++] =3D "-e"; - record_argv[i++] =3D t->name; + record_argv[i++] =3D t->event; } record_argv[i++] =3D NULL; assert(i =3D=3D 10 + 2 * tpebs_event_size || i =3D=3D 8 + 2 * tpebs_event= _size); @@ -108,27 +110,20 @@ static int process_sample_event(const struct perf_too= l *tool __maybe_unused, struct evsel *evsel, struct machine *machine __maybe_unused) { - int ret =3D 0; - const char *evname; struct tpebs_retire_lat *t; =20 - evname =3D evsel__name(evsel); - + t =3D tpebs_retire_lat__find(evsel); + if (!t) + return -EINVAL; /* * Need to handle per core results? We are assuming average retire * latency value will be used. Save the number of samples and the sum of * retire latency value for each event. */ - list_for_each_entry(t, &tpebs_results, nd) { - if (!strcmp(evname, t->name)) { - t->count +=3D 1; - t->sum +=3D sample->retire_lat; - t->val =3D (double) t->sum / t->count; - break; - } - } - - return ret; + t->count +=3D 1; + t->sum +=3D sample->retire_lat; + t->val =3D (double) t->sum / t->count; + return 0; } =20 static int process_feature_event(struct perf_session *session, @@ -183,50 +178,98 @@ static int tpebs_stop(void) return ret; } =20 -static char *evsel__tpebs_name(struct evsel *evsel) +/** + * evsel__tpebs_event() - Create string event encoding to pass to `perf re= cord`. + */ +static int evsel__tpebs_event(struct evsel *evsel, char **event) { char *name, *modifier; + int ret; =20 name =3D strdup(evsel->name); if (!name) - return NULL; + return -ENOMEM; =20 modifier =3D strrchr(name, 'R'); if (!modifier) { - pr_err("Tpebs event missing modifier '%s'\n", name); - free(name); - return NULL; + ret =3D -EINVAL; + goto out; } - *modifier =3D 'p'; - return name; + modifier =3D strchr(name, ':'); + if (!modifier) + modifier =3D strrchr(name, '/'); + if (!modifier) { + ret =3D -EINVAL; + goto out; + } + *modifier =3D '\0'; + if (asprintf(event, "%s/name=3Dtpebs_event_%p/%s", name, evsel, modifier = + 1) > 0) + ret =3D 0; + else + ret =3D -ENOMEM; +out: + if (ret) + pr_err("Tpebs event modifier broken '%s'\n", evsel->name); + free(name); + return ret; } =20 static struct tpebs_retire_lat *tpebs_retire_lat__new(struct evsel *evsel) { struct tpebs_retire_lat *result =3D zalloc(sizeof(*result)); + int ret; =20 if (!result) return NULL; =20 - result->tpebs_name =3D evsel->name; - result->name =3D evsel__tpebs_name(evsel); - if (!result->name) { + ret =3D evsel__tpebs_event(evsel, &result->event); + if (ret) { free(result); return NULL; } + result->evsel =3D evsel; list_add_tail(&result->nd, &tpebs_results); return result; } =20 +static void tpebs_retire_lat__delete(struct tpebs_retire_lat *r) +{ + zfree(&r->event); + free(r); +} + static struct tpebs_retire_lat *tpebs_retire_lat__find(struct evsel *evsel) { struct tpebs_retire_lat *t; + uint64_t num; + const char *evsel_name; =20 + /* + * Evsels will match for evlist with the retirement latency event. The + * name with "tpebs_event_" prefix will be present on events being read + * from `perf record`. + */ + if (evsel__is_retire_lat(evsel)) { + list_for_each_entry(t, &tpebs_results, nd) { + if (t->evsel =3D=3D evsel) + return t; + } + return NULL; + } + evsel_name =3D strstr(evsel->name, "tpebs_event_"); + if (!evsel_name) { + /* Unexpected that the perf record should have other events. */ + return NULL; + } + errno =3D 0; + num =3D strtoull(evsel_name + 12, NULL, 16); + if (errno) { + pr_err("Bad evsel for tpebs find '%s'\n", evsel->name); + return NULL; + } list_for_each_entry(t, &tpebs_results, nd) { - if (t->tpebs_name =3D=3D evsel->name || - !strcmp(t->tpebs_name, evsel->name) || - (evsel->metric_id && !strcmp(t->tpebs_name, evsel->metric_id))) + if ((uint64_t)t->evsel =3D=3D num) return t; } return NULL; @@ -363,8 +406,12 @@ int evsel__tpebs_open(struct evsel *evsel) close(ack_fd[0]); close(ack_fd[1]); } - if (ret) - tpebs_delete(); + if (ret) { + struct tpebs_retire_lat *t =3D tpebs_retire_lat__find(evsel); + + list_del_init(&t->nd); + tpebs_retire_lat__delete(t); + } return ret; } =20 @@ -414,34 +461,19 @@ int tpebs_set_evsel(struct evsel *evsel, int cpu_map_= idx, int thread) return 0; } =20 -static void tpebs_retire_lat__delete(struct tpebs_retire_lat *r) -{ - zfree(&r->name); - free(r); -} - - -/* - * tpebs_delete - delete tpebs related data and stop the created thread and - * process by calling tpebs_stop(). - * - * This function is called from evlist_delete() and also from builtin-stat - * stat_handle_error(). If tpebs_start() is called from places other then = perf - * stat, need to ensure tpebs_delete() is also called to safely free mem a= nd - * close the data read thread and the forked perf record process. +/** + * evsel__tpebs_close() - delete tpebs related data. If the last event, st= op the + * created thread and process by calling tpebs_stop(). * - * This function is also called in evsel__close() to be symmetric with - * tpebs_start() being called in evsel__open(). We will update this call s= ite - * when move tpebs_start() to evlist level. + * This function is called in evsel__close() to be symmetric with + * evsel__tpebs_open() being called in evsel__open(). */ -void tpebs_delete(void) +void evsel__tpebs_close(struct evsel *evsel) { - struct tpebs_retire_lat *r, *rtmp; + struct tpebs_retire_lat *t =3D tpebs_retire_lat__find(evsel); =20 - tpebs_stop(); + tpebs_retire_lat__delete(t); =20 - list_for_each_entry_safe(r, rtmp, &tpebs_results, nd) { - list_del_init(&r->nd); - tpebs_retire_lat__delete(r); - } + if (list_empty(&tpebs_results)) + tpebs_stop(); } diff --git a/tools/perf/util/intel-tpebs.h b/tools/perf/util/intel-tpebs.h index cc98203719c8..5c671181ec60 100644 --- a/tools/perf/util/intel-tpebs.h +++ b/tools/perf/util/intel-tpebs.h @@ -11,7 +11,7 @@ struct evsel; extern bool tpebs_recording; =20 int evsel__tpebs_open(struct evsel *evsel); -void tpebs_delete(void); +void evsel__tpebs_close(struct evsel *evsel); int tpebs_set_evsel(struct evsel *evsel, int cpu_map_idx, int thread); =20 #endif /* __INTEL_TPEBS_H */ --=20 2.49.0.504.g3bcea36a83-goog From nobody Fri Dec 19 14:27:09 2025 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D6398254B10 for ; Mon, 7 Apr 2025 21:10:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744060241; cv=none; b=F9z//5mlzpsvIWYMh4f6bAKjlc6QpKBKVReUecrdSmt9qKhJAlilvXOXcY8vTUsaB5v4mIKcB4Klz+ryHHEfW5bvGUZANId7PEXtta5hp3Wcvj0bxbGz1J5nv9JB/T7gJPFAhgfeGoRJaUVe2AQN0kwyOqPr7uLzGpOYwXzDMHI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744060241; c=relaxed/simple; bh=midHO3Z3byxoUBHfKzM92TodrGzwSNi/xUV5ijTnPeg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=XYn+lpJrNVBjyEVNeXCxPE2kQVS7uaeXLqoH6PiGB3VulAOkyyHlPcvwgFD9jyqwqIvD8IpAhRHKt+O+6T6kARvU8khmwPvXCQXJnWzC44KKIqh0A1QEqxQdYsVOlymr4Jf41HJ+siGQFMLe26p7iUuEttlU05tz8yaIhEfxhhg= 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=Mb0MEax6; arc=none smtp.client-ip=209.85.214.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Mb0MEax6" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-2241e7e3addso39728665ad.1 for ; Mon, 07 Apr 2025 14:10:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1744060239; x=1744665039; 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=w1vjvtqlcWS/+dNR0OE++xaid1m3UsjjNffN8GtQ4ds=; b=Mb0MEax6JUqQd2OotEHLXGOJrfdKwhKK50VRq5JFGx8rItq4mX9d1B805DSdaMXalP Bu9f6M8NrbJCbdbrWz1zTIUAtRSqnQed3mSqDsT9gau0GU9B3FlJIOHHqDrUnswxT+K7 Iiyhru9do947dIv+VofzVDsliFAWCoV35iND5PML5BZY5sl8fHDQZEXcR6Xz6MurDbMv 0QK6YMCz5agGWMnl85tq3wfET37ngV4NkWhN5iRGBHEgGvtDLHXAzxh/MteWF6VN176B 3eRBfFidQMy4kM5F9uRMEdBQZ6v05jgbroOZAzGxtjKmW7z+9uyUwjUQCnjNJ0K83FBe +QeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744060239; x=1744665039; 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=w1vjvtqlcWS/+dNR0OE++xaid1m3UsjjNffN8GtQ4ds=; b=IW0paG5zfTP+g0xodk7G0XqVhXhigZ1PXwzxPH5noxazklIN/aWqDmd5fQRfrGbdLl yQDUbn5OFWDU4RKwpIC8sRPVnXvmvlhRWCPJcej5WStr1Lg0O59BgzkRqenfaqhyApFb zmi7bpIb583S16nvFezNpKM1wPq6ikQLHNqFIEHGZhMCQIk1nSbwCbliNnXjDQ8txoYc SYuCij6W7Vjt3Q4Ctldw550+KGInIP+EEj0sIwGUDfJiD2+ySBh3nyriCN8DCijuSfO4 nZh5z/t3kTdTEKoHsCf4bXs8ekDA291GCVlybiagPGUeSTjYngL+5GF0cwoRnE8dSfpG W4Mg== X-Forwarded-Encrypted: i=1; AJvYcCUjh+CwaaN98JCz1edOtW3K8fJ022pwZk2LXvwOTaA5CXZXvd+jLRG1IPH+NBRKkdFAMQ2P2+vAuVeDgLE=@vger.kernel.org X-Gm-Message-State: AOJu0Yx4LhixGLYQQ5y2pW0WkjgDDX/E6mzQJBTYb+67KRwwqWmApRrp oJI5VaN3DAPei3Gf1iacjDETjdSmngJtgbSbPpj3g+7Bfsl8Z9fOLtLpoqMuOSHWtqX4gw8ty79 TOdK6Kw== X-Google-Smtp-Source: AGHT+IGADpgsCuG4PHa3Qu9sgQTTobjrW0PuIpK1wi9mW1TmFE2abMLBb0bRgk7WFEzx8RlVsADBzs7CRw5z X-Received: from plnu5.prod.google.com ([2002:a17:903:1a45:b0:223:58e2:570d]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:41c6:b0:221:78a1:27fb with SMTP id d9443c01a7336-22a8a049ee7mr143568095ad.11.1744060239381; Mon, 07 Apr 2025 14:10:39 -0700 (PDT) Date: Mon, 7 Apr 2025 14:09:31 -0700 In-Reply-To: <20250407210937.131681-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: <20250407210937.131681-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.504.g3bcea36a83-goog Message-ID: <20250407210937.131681-11-irogers@google.com> Subject: [PATCH v3 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 a723687e67f6..f648fca17556 100644 --- a/tools/perf/util/intel-tpebs.c +++ b/tools/perf/util/intel-tpebs.c @@ -415,49 +415,39 @@ int evsel__tpebs_open(struct evsel *evsel) return ret; } =20 - -int tpebs_set_evsel(struct evsel *evsel, int cpu_map_idx, int thread) +int evsel__tpebs_read(struct evsel *evsel, int cpu_map_idx, int thread) { - __u64 val; + struct perf_counts_values *count, *old_count =3D NULL; struct tpebs_retire_lat *t; - struct perf_counts_values *count; + uint64_t val; + + /* Only set retire_latency value to the first CPU and thread. */ + if (cpu_map_idx !=3D 0 || thread !=3D 0) + return 0; + + if (evsel->prev_raw_counts) + old_count =3D perf_counts(evsel->prev_raw_counts, cpu_map_idx, thread); =20 - /* Non reitre_latency evsel should never enter this function. */ - if (!evsel__is_retire_lat(evsel)) - return -1; + count =3D perf_counts(evsel->counts, cpu_map_idx, thread); =20 /* * Need to stop the forked record to ensure get sampled data from the * PIPE to process and get non-zero retire_lat value for hybrid. */ tpebs_stop(); - count =3D perf_counts(evsel->counts, cpu_map_idx, thread); =20 t =3D tpebs_retire_lat__find(evsel); - - /* Set ena and run to non-zero */ - count->ena =3D count->run =3D 1; - count->lost =3D 0; - - if (!t) { - /* - * Set default value or 0 when retire_latency for this event is - * not found from sampling data (record_tpebs not set or 0 - * sample recorded). - */ - count->val =3D 0; - return 0; + val =3D rint(t->val); + + if (old_count) { + count->val =3D old_count->val + val; + count->run =3D old_count->run + 1; + count->ena =3D old_count->ena + 1; + } else { + count->val =3D val; + count->run++; + count->ena++; } - - /* - * Only set retire_latency value to the first CPU and thread. - */ - if (cpu_map_idx =3D=3D 0 && thread =3D=3D 0) - val =3D rint(t->val); - else - val =3D 0; - - count->val =3D val; return 0; } =20 diff --git a/tools/perf/util/intel-tpebs.h b/tools/perf/util/intel-tpebs.h index 5c671181ec60..218a82866cee 100644 --- a/tools/perf/util/intel-tpebs.h +++ b/tools/perf/util/intel-tpebs.h @@ -12,6 +12,6 @@ extern bool tpebs_recording; =20 int evsel__tpebs_open(struct evsel *evsel); void evsel__tpebs_close(struct evsel *evsel); -int tpebs_set_evsel(struct evsel *evsel, int cpu_map_idx, int thread); +int evsel__tpebs_read(struct evsel *evsel, int cpu_map_idx, int thread); =20 #endif /* __INTEL_TPEBS_H */ --=20 2.49.0.504.g3bcea36a83-goog From nobody Fri Dec 19 14:27:09 2025 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0F02525524B for ; Mon, 7 Apr 2025 21:10:41 +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=1744060244; cv=none; b=V7M0MOt4fPsHAkx2xi2ch7FgWOR9s2EGiHwTCMVmOhkZ8QbCM23NPVrfXyxqkB9gGdW5YFk2d1ZBVzej6rIaRG+s5P6UzA8qvHvlyISZi+IlcbeswHUC74OqjpqEXG2477amomXplmcnMLmoTbEHTZt818tIMONy+stNsPbq5TI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744060244; c=relaxed/simple; bh=ljmD0cTVkTPSjeRTew6uc5xLS1AYn1ipDaRrb9bphs4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=Jvsxw1G+WREHYeB6jlT/0rqEda7ibHH8Z/gug4Y01mQgI9q943yZ2JKamt+4wWmoxHwTzNxMW3A4yPk9572jlTgwKbR2+M+St6Y9/0MAYbBA6vBGwTXG1r2VCxNAUKynuWmdCU5PWg5jcWz4gnsGmkLb1P1by+DoLBu9KNbEPXM= 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=2nxiuIhy; 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="2nxiuIhy" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-306b51e30ffso1901726a91.1 for ; Mon, 07 Apr 2025 14:10:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1744060241; x=1744665041; 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=n0AuvTirY7qrM/gCswfIrUXj0T0vw1kKdRIHGiOGwYc=; b=2nxiuIhyxew/GaSsn8TRIwUvxK1nemuPdmhjsxrj5jX7lKVtRL1I10nDzfnI3BmF7l qEIQKr7yDEWy2fBxTfXtDCKBOyZJojcU15zucr3l6kZyBhQBVNek3zD/mDD1vD59WPT9 pCNbPrMlBwVK3gdulTbicZkYCOa+9LMvcQAyWfNCcG+39dt8BzuNE2/SN71T+suANscL xWn5f3O6Yjj28MB0wTlhacZzZa3wnoo4HUkOVHsgFGYst5abuAn0j+eQlpJrCYBb6f5H u+ODMT1686S6Q0bH7RXAR6YIPYJBQVJLK0yr5KOia7Djm2WYLOoPcz7LTgJXGtlHmb0B zTDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744060241; x=1744665041; 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=n0AuvTirY7qrM/gCswfIrUXj0T0vw1kKdRIHGiOGwYc=; b=AUZ/E0qOeqCmfa2Bnh5LHCvsDPKBK8SC1SuKB0Pj/i54ZwCZGMcDn+prabmDPfYTW0 VNAYTlyVwmwLzhWaUkdDo4NK9lJJE7yitCIeB1x2YSOmzSzcv8/jVOi17wMfBmCGuw+a 8JZBPtg2NcU7XoiYUruE4wJsqIbwnhf5s0fPpzO6s1UoBcW2vgaL66SHNFPr1Ceq8h1V S7K0sYgGzFHgoaXlEG/+N0pWdCs79REuaX+844juVOS905/pKx2zChJZm/jR6gOfN40u wBm7ko9cllVGfQuPVfVnou/0S4zf8JQ6NKSzD9IajAuWl7sWds11D0O5BZPv2pA8UdoL s/kw== X-Forwarded-Encrypted: i=1; AJvYcCXZAtk2JrIs3NmP0ik84Jorjl14HU9FbAMESM5YpdiTejSOYz3EgRmaE8O3CaP64w3J69WNYqnHFNlnbTU=@vger.kernel.org X-Gm-Message-State: AOJu0YynDc1FaIag3IgHwEohJYMbRSG46Ah+C5Nkstr/psNG6UyCCass 4v1DHLYKaPvIVVYCi0arZopNBv1iNeXgkvMir1kG2AikSctYfctMqS1S9lvIA4vzVpA4ERM49mB 6CEifDQ== X-Google-Smtp-Source: AGHT+IEtTIEPINOIddrhAnqXLHcRpH0YQH7WZU5gzCPFXyCuGjFEH5RfJxdh7z/ihaa8Hk3xhz5i+C7CL3ti X-Received: from pjbsc7.prod.google.com ([2002:a17:90b:5107:b0:2fa:1481:81f5]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:2744:b0:2fe:e0a9:49d4 with SMTP id 98e67ed59e1d1-306a60e4ab5mr18849904a91.2.1744060241459; Mon, 07 Apr 2025 14:10:41 -0700 (PDT) Date: Mon, 7 Apr 2025 14:09:32 -0700 In-Reply-To: <20250407210937.131681-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: <20250407210937.131681-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.504.g3bcea36a83-goog Message-ID: <20250407210937.131681-12-irogers@google.com> Subject: [PATCH v3 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 f648fca17556..c5ccdbc42dc6 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 Fri Dec 19 14:27:09 2025 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3AA3D255E4D for ; Mon, 7 Apr 2025 21:10:43 +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=1744060247; cv=none; b=Z5mzo+WmiHOAMwiVMDCi2WWNAeGGzf8brefTl6ezxvc0VBZgG1qE7JMAUUtHl2HJNeqPA7vwACzYaCQ1mPYiZ7ZvNjLNiuOV+h1WuwX0xvamENn41aLNgFkaDltnGcUybIvDSY+n5+9oUqlZbgwUoDFsnqWFOV+Xjl7Ffo4r5Mk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744060247; c=relaxed/simple; bh=rq1T4nW3ptF3rW6w1vwJRYhMU8sLO7lL7UaD2qb6LQE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=qheRKo+XGISoRNWvwFPcp9sPR0lmfTA/A6oULHBVY2XKqqJFaqO5E4GoQKaMxkii4MnV8V+JKYdYlGVw2suaoEa40678syfFvUGmE1KXdWC1n4HZ0KMpe9FXx1CYfjohUx4/v3GTNVBEqEaE6toORCz44VEyRy6Yb1LngabQ1CY= 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=BRBSk2h5; 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="BRBSk2h5" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-af54a9109f4so1931328a12.2 for ; Mon, 07 Apr 2025 14:10:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1744060243; x=1744665043; 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=dJnQ6O5jw867vwmHrVw3vRVHN/Cs2sIpYKycpB+54Lg=; b=BRBSk2h5r20DMxtP0Lr2/T6YwzCDdShhGmDgyKxv++oiAqJPrDwup3Sgky/INEt1eW mdd6lCszoA9mF37LxTDpp7EZLs/OMSGbnh5ItNgyY+RUgKMwx9bMjjno9uluBP7GMUcC bn8cPQuta0XzHWOEgDUUO3J9dsTBoporB+tYLgDWGH7LlVhYg8w/RB2D9nYOLKYLy0p5 bRCkAsrWGij6W90S8CunwhTF6DU2yjMuqs4L0lDUvHNzJ7WO4/boqiXELWJx5MqZDnFs QDEFXdRx1ymK8pAyOFNkmw7w7/pcU2gTwIoa+DMbaFy5Ao1IeSMbvbzhgjJ0MZKW780D ui5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744060243; x=1744665043; 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=dJnQ6O5jw867vwmHrVw3vRVHN/Cs2sIpYKycpB+54Lg=; b=NXiaoSw58MOeoNBm31gRtBLHn8PMGARh4ILFh06O/5GRBWVH19rT3GtZvhvNTZU3MQ V8xuCgdymNXS9gyY4/gGx8Wcvq3V7KS0TkZMnIBQwBbqTbOA7gIRbBahPZ6giQRrPCku Ot40CXwEjqpxA+COvZ3GGEHjtyXKzCzHmwPM0FYxqLaLWeXby7fSzlVqErTNaRd/O+4Y tWTRZdZt+pS6X+BVjIdGXKTLLR4Nw7VmHGYNV6mQ1xz1seQi4a3slPp48gTAaocIrlIf Dcdlkb2Co5ztwuxT7T56jzsWHaZzaECTRegJgWIxpImoSjqZaDcP0lxRYXD8oijvMfTg GHSQ== X-Forwarded-Encrypted: i=1; AJvYcCV3LOEyUzhAETHkgDvWjIvRnUTPMUW6Z9x2pUZ0EWWYPk6DbYuIdlAZeg1U9zFio90iqSQa+ShJUZJfgKY=@vger.kernel.org X-Gm-Message-State: AOJu0Yxrc0AR3BhM9nyTUXeob2vstxybhpR+4sGA/4maV/624+mg94WT Ytus288Oy4jtw19bAH3hnshkn5UmJW2dSL+cYtylKp0G3Xq73rWrXG6Yx3LCLqQvyH3tvcvSf8K 8Xc93lg== X-Google-Smtp-Source: AGHT+IF7wpA5PTmDJWkY01tJDs4bCuELZ2QAFndIAgA6tC6ZVYoDHGmaTRvHKZX40caPWaNJLBkaMZ9nn5ne X-Received: from plbjf14.prod.google.com ([2002:a17:903:268e:b0:227:e4a6:fc21]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:e805:b0:223:4bd6:3863 with SMTP id d9443c01a7336-22a8a85a489mr177565295ad.10.1744060243436; Mon, 07 Apr 2025 14:10:43 -0700 (PDT) Date: Mon, 7 Apr 2025 14:09:33 -0700 In-Reply-To: <20250407210937.131681-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: <20250407210937.131681-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.504.g3bcea36a83-goog Message-ID: <20250407210937.131681-13-irogers@google.com> Subject: [PATCH v3 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 c5ccdbc42dc6..a9446e7a1c5c 100644 --- a/tools/perf/util/intel-tpebs.c +++ b/tools/perf/util/intel-tpebs.c @@ -33,6 +33,7 @@ bool tpebs_recording; static LIST_HEAD(tpebs_results); static pthread_t tpebs_reader_thread; static struct child_process tpebs_cmd; +static int control_fd[2], ack_fd[2]; static struct mutex tpebs_mtx; =20 struct tpebs_retire_lat { @@ -51,8 +52,6 @@ struct tpebs_retire_lat { bool started; }; =20 -static struct tpebs_retire_lat *tpebs_retire_lat__find(struct evsel *evsel= ); - static void tpebs_mtx_init(void) { mutex_init(&tpebs_mtx); @@ -66,7 +65,10 @@ static struct mutex *tpebs_mtx_get(void) return &tpebs_mtx; } =20 -static int evsel__tpebs_start_perf_record(struct evsel *evsel, int control= _fd[], int ack_fd[]) +static struct tpebs_retire_lat *tpebs_retire_lat__find(struct evsel *evsel) + EXCLUSIVE_LOCKS_REQUIRED(tpebs_mtx_get()); + +static int evsel__tpebs_start_perf_record(struct evsel *evsel) { const char **record_argv; int tpebs_event_size =3D 0, i =3D 0, ret; @@ -74,15 +76,13 @@ static int evsel__tpebs_start_perf_record(struct evsel = *evsel, int control_fd[], char cpumap_buf[50]; struct tpebs_retire_lat *t; =20 - mutex_lock(tpebs_mtx_get()); list_for_each_entry(t, &tpebs_results, nd) tpebs_event_size++; =20 record_argv =3D malloc((10 + 2 * tpebs_event_size) * sizeof(*record_argv)= ); - if (!record_argv) { - mutex_unlock(tpebs_mtx_get()); + if (!record_argv) return -ENOMEM; - } + record_argv[i++] =3D "perf"; record_argv[i++] =3D "record"; record_argv[i++] =3D "-W"; @@ -118,7 +118,6 @@ static int evsel__tpebs_start_perf_record(struct evsel = *evsel, int control_fd[], list_for_each_entry(t, &tpebs_results, nd) t->started =3D true; =20 - mutex_unlock(tpebs_mtx_get()); return ret; } =20 @@ -131,6 +130,11 @@ static int process_sample_event(const struct perf_tool= *tool __maybe_unused, struct tpebs_retire_lat *t; =20 mutex_lock(tpebs_mtx_get()); + if (tpebs_cmd.pid =3D=3D 0) { + /* Record has terminated. */ + mutex_unlock(tpebs_mtx_get()); + return 0; + } t =3D tpebs_retire_lat__find(evsel); if (!t) { mutex_unlock(tpebs_mtx_get()); @@ -180,17 +184,98 @@ static void *__sample_reader(void *arg __maybe_unused) return NULL; } =20 +static int tpebs_send_record_cmd(const char *msg) EXCLUSIVE_LOCKS_REQUIRED= (tpebs_mtx_get()) +{ + struct pollfd pollfd =3D { .events =3D POLLIN, }; + int ret, len, retries =3D 0; + char ack_buf[8]; + + /* Check if the command exited before the send, done with the lock held. = */ + if (tpebs_cmd.pid =3D=3D 0) + return 0; + + /* + * Let go of the lock while sending/receiving as blocking can starve the + * sample reading thread. + */ + mutex_unlock(tpebs_mtx_get()); + + /* Send perf record command.*/ + len =3D strlen(msg); + ret =3D write(control_fd[1], msg, len); + if (ret !=3D len) { + pr_err("perf record control write control message '%s' failed\n", msg); + ret =3D -EPIPE; + goto out; + } + + if (!strcmp(msg, EVLIST_CTL_CMD_STOP_TAG)) { + ret =3D 0; + goto out; + } + + /* Wait for an ack. */ + pollfd.fd =3D ack_fd[0]; + + /* + * We need this poll to ensure the ack_fd PIPE will not hang + * when perf record failed for any reason. The timeout value + * 3000ms is an empirical selection. + */ +again: + if (!poll(&pollfd, 1, 500)) { + if (check_if_command_finished(&tpebs_cmd)) { + ret =3D 0; + goto out; + } + + if (retries++ < 6) + goto again; + pr_err("tpebs failed: perf record ack timeout for '%s'\n", msg); + ret =3D -ETIMEDOUT; + goto out; + } + + if (!(pollfd.revents & POLLIN)) { + if (check_if_command_finished(&tpebs_cmd)) { + ret =3D 0; + goto out; + } + + pr_err("tpebs failed: did not received an ack for '%s'\n", msg); + ret =3D -EPIPE; + goto out; + } + + ret =3D read(ack_fd[0], ack_buf, sizeof(ack_buf)); + if (ret > 0) + ret =3D strcmp(ack_buf, EVLIST_CTL_CMD_ACK_TAG); + else + pr_err("tpebs: perf record control ack failed\n"); +out: + /* Re-take lock as expected by caller. */ + mutex_lock(tpebs_mtx_get()); + return ret; +} + /* * tpebs_stop - stop the sample data read thread and the perf record proce= ss. */ -static int tpebs_stop(void) +static int tpebs_stop(void) EXCLUSIVE_LOCKS_REQUIRED(tpebs_mtx_get()) { int ret =3D 0; =20 /* Like tpebs_start, we should only run tpebs_end once. */ if (tpebs_cmd.pid !=3D 0) { - kill(tpebs_cmd.pid, SIGTERM); + tpebs_send_record_cmd(EVLIST_CTL_CMD_STOP_TAG); + tpebs_cmd.pid =3D 0; + mutex_unlock(tpebs_mtx_get()); pthread_join(tpebs_reader_thread, NULL); + mutex_lock(tpebs_mtx_get()); + close(control_fd[0]); + close(control_fd[1]); + close(ack_fd[0]); + close(ack_fd[1]); close(tpebs_cmd.out); ret =3D finish_command(&tpebs_cmd); tpebs_cmd.pid =3D 0; @@ -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 Fri Dec 19 14:27:09 2025 Received: from mail-ot1-f74.google.com (mail-ot1-f74.google.com [209.85.210.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 046812561A5 for ; Mon, 7 Apr 2025 21:10:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744060247; cv=none; b=chyVmjfW4vYgbhywxSf6NRHQaWnIr4LquHDdBGJos3SIpq9lFyP5TbhFkpPWfI37r3CLAlEaOjMASITQmtRu3nuCiq/TJHQkIdzUmqJr13gpZ9V9Fi1C9Wr+FRl3K5PV8NcxvE78tr+NRNZ+1ho13xfPDvNPxffzL90kqzU4KgU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744060247; c=relaxed/simple; bh=DOdUTxLI7/zQjgCEpln88RgVE7J5L5+nYgmvVB4LmPU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=ZL/DwHzHJeUG/yUvI1r5SQsj23E/lVs2zxEJOiYHkKX5X6WSREsDprNxdCegC4xhIiWsHKKYQu1EvA7DyJHuJiWqJkR5g+f5p2OjaXJCthYTIzar+jk5quJmlCvy/sFQIBXTY11Y5tyGEDhNmLxmPiZcKCMi1GiodaBQ1bzoNEM= 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=CCEP7HrN; arc=none smtp.client-ip=209.85.210.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="CCEP7HrN" Received: by mail-ot1-f74.google.com with SMTP id 46e09a7af769-72b881599f6so4481612a34.1 for ; Mon, 07 Apr 2025 14:10:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1744060245; x=1744665045; 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=bbV+FoNiQvVRc13/UCAfNK3Jak/b5U1tJ5tpMxpqA0g=; b=CCEP7HrNwBRsKmyyVSru7yW+4opRoVEczz/hVTAnlXjP8M9MuBUJ0qcIkrkB5Iu7p1 lQsQm/QGLdPJJ72rputOtaBQ90PSdIpa5FwCHmtGgl26YX/WsNWk1jjWEDyOgMGFEZUX GAHkYzXMBBxYrwNqe4BRR4DUSFTQ2vZgqQW50QS8CsjTJGsTuQsvJfNBCXKL77DOvRSE FESa8h7Pg8Ve4s8QD51wnGSrc2TyzWR7ceNUme/X/zkGsmLgTTd4Yi/vrwDWWUFh8+Si wUSPklJvK82AgPKa5t5dbOWKttlKO0Z9vuXDK+m8y3B/V5XtaapyBYZpdV568tuHx+r3 CVLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744060245; x=1744665045; 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=bbV+FoNiQvVRc13/UCAfNK3Jak/b5U1tJ5tpMxpqA0g=; b=i0uZhHZNaQFSgGpOB0mTiKCwPbFGFcWB+/KQp8qvxj0MCFKMTZxQipGHttcIfXrhA3 rZWIKN+SLpW8Vhjcl9GWrLqzs4DccYC8DVdP4kpZhNUVpIw+u6nb1XuVOwYQEovd4KEn aS14btcYaE5xf1WLbOXDUngN7srS7mzMcm/8o1mY82MNNiUDlFOXc2WwbH4e+JMSj+ZS s21kqLi0pWarzSEh0y5jl8JR7g80TH+xzSGHW7T9L8Xh5AcIpXo9SK64Rf60sQjZ8HXU IjapaWNFWw4R44wNj+HTBpNlCZJ3TXtAdg6ANDonOZGskrPuQ89l3kZwYaEq6rUMeZBW ex3Q== X-Forwarded-Encrypted: i=1; AJvYcCVu5h+z9RhYG5H/SjTwOYOXwT9Py+iAtr61YcsmaJLMd6BuDYdZBFrBAvl+39PytY+WVH/UA+dT/RurqNY=@vger.kernel.org X-Gm-Message-State: AOJu0Yx2/jLKLQLtajg980QxD5YCD3AXa26uTsJJyGeC21eUUtPION3z MFpesz4Mzznpmi7fOzagkrouTHJViHuk+AXZ0rUXEkXlRIe08oxlirVOPf1YcckdV2FVmqMSQGd qkbYj5Q== X-Google-Smtp-Source: AGHT+IHvSiuBOO02/UbSYhhz96i5QSBrJEvlzEK8IJSZdcVPKNE6XbUiOCTXlBXY1mne4J6Eb41byqs/Fhez X-Received: from oacsc18.prod.google.com ([2002:a05:6871:5e12:b0:2b8:e26f:1d53]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6830:d8c:b0:72b:87bd:ad47 with SMTP id 46e09a7af769-72e366b0c07mr8386588a34.3.1744060245194; Mon, 07 Apr 2025 14:10:45 -0700 (PDT) Date: Mon, 7 Apr 2025 14:09:34 -0700 In-Reply-To: <20250407210937.131681-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: <20250407210937.131681-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.504.g3bcea36a83-goog Message-ID: <20250407210937.131681-14-irogers@google.com> Subject: [PATCH v3 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 a9446e7a1c5c..de9fea601964 100644 --- a/tools/perf/util/intel-tpebs.c +++ b/tools/perf/util/intel-tpebs.c @@ -18,6 +18,7 @@ #include "evsel.h" #include "mutex.h" #include "session.h" +#include "stat.h" #include "tool.h" #include "cpumap.h" #include "metricgroup.h" @@ -42,12 +43,8 @@ struct tpebs_retire_lat { struct evsel *evsel; /** @event: Event passed to perf record. */ char *event; - /* Count of retire_latency values found in sample data */ - size_t count; - /* Sum of all the retire_latency values in sample data */ - int sum; - /* Average of retire_latency, val =3D sum / count */ - double val; + /** @stats: Recorded retirement latency stats. */ + struct stats stats; /* Has the event been sent to perf record? */ bool started; }; @@ -145,9 +142,7 @@ static int process_sample_event(const struct perf_tool = *tool __maybe_unused, * latency value will be used. Save the number of samples and the sum of * retire latency value for each event. */ - t->count +=3D 1; - t->sum +=3D sample->retire_lat; - t->val =3D (double) t->sum / t->count; + update_stats(&t->stats, sample->retire_lat); mutex_unlock(tpebs_mtx_get()); return 0; } @@ -522,7 +517,7 @@ int evsel__tpebs_read(struct evsel *evsel, int cpu_map_= idx, int thread) return ret; mutex_lock(tpebs_mtx_get()); } - val =3D rint(t->val); + val =3D rint(t->stats.mean); mutex_unlock(tpebs_mtx_get()); =20 if (old_count) { --=20 2.49.0.504.g3bcea36a83-goog From nobody Fri Dec 19 14:27:09 2025 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D19072561BB for ; Mon, 7 Apr 2025 21:10:47 +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=1744060249; cv=none; b=IjRQkTYdKQL3sCmepAA5R1YKbwJu0fAylYZyDdHsym8YKq/JzlJeSlTFShtzhHraAB/rEXILodhBZpPTbGWA/VoKCWedNUeAxgJu4NQirzjBTuxpbWtoDpHq8vcIdaCT1WSJ5LxSdqV2kPtOuaLNtBNYFZ7wUNo9rJ3a+YjxKSU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744060249; c=relaxed/simple; bh=j+ajFhze8XNvNedW0+qQsxa4xJpNyLgqbtH3uNHZnh4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=sLf6q0KMc814U5PcrT6yC6vAFFhVgOcPBtSI9L+dgbtMuann2YTLHyIiA3JV+lID/nbF5viynfOh6kEcdvdWqeJgDA5trXzLLcFTDveEO8FeP8WVB3f9e0I5pKlpqnNeTghe4YBf3r2avP4KGsV5VL58G6Lg2PPWrPKlJaQs1Nc= 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=SXZQH6Rh; 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="SXZQH6Rh" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-af91ea9e885so4197482a12.3 for ; Mon, 07 Apr 2025 14:10:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1744060247; x=1744665047; 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=CHpmhSJgyl8CfNQkTk9ozGn6lbmpXan8KmxzNdnU62A=; b=SXZQH6Rhw68T0VZ1RYwjBm+YCrN1K5CHQJ8oD+lV/710ZjJWGZq21ThaVOCEbt7vvx LgAe4AO+ASMkEyMBFrsP1hqSZA9H33CduUvbVwJBYRu9DclyRXuS47dXZTDQkqVd1o2r gmJ4BqVS4wo8LtvWpkYs2A8ArdrliDu4ylZw7wjSk+o+Er4Sjub2DDRE9iM3YY14UG8/ 9lBi3ZpzU4WNVLF30ijvjmqi+AoH78d9YH9JeN6f2TG3YU+zqkiBUYS0qQJHj7tsEIGF //ue5StwhfLf6T06OQcqnVo+NsN0LXjR994hMsDd+txqkVdzOnegY+nFm/yndMwLKPGm 4YMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744060247; x=1744665047; 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=CHpmhSJgyl8CfNQkTk9ozGn6lbmpXan8KmxzNdnU62A=; b=CjZIXcY+Q+KZyCDalRvTVx74zWyFuya/djXz6ZV6ionqcmJ4Zx24SBz5X6aoaApZS9 xIrarkvh27eKiuYTVPdWEY8zUwwI8BoIjbcIO6PrCbZhkiathwK3gwxWfnUjna4nO78x Ril4bGEcEFJ4COQkYARod0BP2GB/SHOAH4mTR3DKmYEy1NgC3RIcvTAkmTlJYdoSbSmG dZaNlI81EHHqvkdEIEfZfcQgpC/pm9M773j//jCDmVhV55DQASGi6XPM5TeNhGva1e+1 eNfy2QbsO7mNybyhovrrpb+L1n/v9c1aufcumOJ7aD9NImSf7RQigov6aBqFkgvjoPEs 0nCg== X-Forwarded-Encrypted: i=1; AJvYcCUTQb+F1h/EeL7P3OAI30nlk/Xzh/f34SZ2eB6ODO8Zn9rYunt1pk3Njb7ncwmV+EZV90qFPWnWwUbyasY=@vger.kernel.org X-Gm-Message-State: AOJu0Yzg5L/wFKh9+TP8mq40qtyIKlv9kkemhxy+PMksDMn9DAPh0G72 i+nrt87y3f3ZC7yWO6uzFShnE6Ctl2UW0PXnvgFh3Z0rCij3uLql4Yqx7BBbBKwDFknkaFbGv2Z PmUKW2g== X-Google-Smtp-Source: AGHT+IEwSvokNi/bh76gbjqrB9lCNL67U9jQB6qnUBpqgfqIQSvWOOeL5/jsukJeGPYmZaTV7kgFf9IZb7nR X-Received: from plhu6.prod.google.com ([2002:a17:903:1246:b0:223:f321:1a96]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:98b:b0:224:1074:63a2 with SMTP id d9443c01a7336-22a8a8cf281mr180860945ad.43.1744060247123; Mon, 07 Apr 2025 14:10:47 -0700 (PDT) Date: Mon, 7 Apr 2025 14:09:35 -0700 In-Reply-To: <20250407210937.131681-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: <20250407210937.131681-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.504.g3bcea36a83-goog Message-ID: <20250407210937.131681-15-irogers@google.com> Subject: [PATCH v3 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 de9fea601964..6b00bd5b0af1 100644 --- a/tools/perf/util/intel-tpebs.c +++ b/tools/perf/util/intel-tpebs.c @@ -31,6 +31,7 @@ #define PERF_DATA "-" =20 bool tpebs_recording; +enum tpebs_mode tpebs_mode; static LIST_HEAD(tpebs_results); static pthread_t tpebs_reader_thread; static struct child_process tpebs_cmd; @@ -45,6 +46,8 @@ struct tpebs_retire_lat { char *event; /** @stats: Recorded retirement latency stats. */ struct stats stats; + /** @last: Last retirement latency read. */ + uint64_t last; /* Has the event been sent to perf record? */ bool started; }; @@ -142,6 +145,7 @@ static int process_sample_event(const struct perf_tool = *tool __maybe_unused, * latency value will be used. Save the number of samples and the sum of * retire latency value for each event. */ + t->last =3D sample->retire_lat; update_stats(&t->stats, sample->retire_lat); mutex_unlock(tpebs_mtx_get()); return 0; @@ -517,7 +521,21 @@ int evsel__tpebs_read(struct evsel *evsel, int cpu_map= _idx, int thread) return ret; mutex_lock(tpebs_mtx_get()); } - val =3D rint(t->stats.mean); + switch (tpebs_mode) { + case TPEBS_MODE__MIN: + val =3D rint(t->stats.min); + break; + case TPEBS_MODE__MAX: + val =3D rint(t->stats.max); + break; + case TPEBS_MODE__LAST: + val =3D t->last; + break; + default: + case TPEBS_MODE__MEAN: + val =3D rint(t->stats.mean); + break; + } mutex_unlock(tpebs_mtx_get()); =20 if (old_count) { diff --git a/tools/perf/util/intel-tpebs.h b/tools/perf/util/intel-tpebs.h index 218a82866cee..9475e2e6ea74 100644 --- a/tools/perf/util/intel-tpebs.h +++ b/tools/perf/util/intel-tpebs.h @@ -8,7 +8,15 @@ struct evlist; struct evsel; =20 +enum tpebs_mode { + TPEBS_MODE__MEAN, + TPEBS_MODE__MIN, + TPEBS_MODE__MAX, + TPEBS_MODE__LAST, +}; + extern bool tpebs_recording; +extern enum tpebs_mode tpebs_mode; =20 int evsel__tpebs_open(struct evsel *evsel); void evsel__tpebs_close(struct evsel *evsel); --=20 2.49.0.504.g3bcea36a83-goog From nobody Fri Dec 19 14:27:09 2025 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C2DDB2566D4 for ; Mon, 7 Apr 2025 21:10:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744060253; cv=none; b=ii2UeWYRlPAq5FJ08LI3FTazgE0Ku//93a4ydhC9sBhAtVBPMnpiIMuJ0VeKEtf/g47JkBctd5hlqIu8Xw6mU5wQejuOkaI5fFO4QEWpZsqYuIt82yyY2KvG3Fz+vAr01/mTkj/fOGxoap4lgevi74D0+MQQLhkOySoQ/1TSl/8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744060253; c=relaxed/simple; bh=1fWMQVlJwz1tN6Hur4X0h+HaVomcW3OMLwsHx5m97hE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=g2q3pwIKzcG+dbaRg/51B4VaQschSlnr9YvNqHWCecxl/oD8OfFTFWAN0X3PPYd4ZzcaToD0uwgZVhSH1PCNK38aW3QLK7PtwpMBObjXE/2jo9UtdztsjlC9xwn1tyrTGGG16Qyhlqg5rTwtHMIiYWyH7tKzzphiHHdNBN2lIZ0= 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=00FQSZmG; arc=none smtp.client-ip=209.85.210.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="00FQSZmG" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-7369c5ed395so5679595b3a.0 for ; Mon, 07 Apr 2025 14:10:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1744060249; x=1744665049; 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=XER1T4UKMjoPSozPZWo9dv2miNBpBaF37Pvg91kH1b0=; b=00FQSZmGMtQa97DpChH6QCSA0ooOKUCB8rylkMX8ge6Lrl5Tp1r7IYrfBdlhIhAbSV wSA39VgaIGYlEikHWUpT+e3raH9lHeIEIPCWnAHgKHnqjJcJLr9ZAyhN93AvRIVCiNrY E6KMCOF2R7vG2vFvetSr8kRLsBtUFSvapOkaehXuT7x4Lchlr7iwE10KItJeL9tExq4E 0CPvbU3e44FcGtB9FrAFSTehXjAl5lH/dVMzy6N0TdyswP+SkNkMGT9zQh/4w0dKyOaN a/2hIBMwW2ab/kIW2VBQ5X6Vg910ZLpadX6G7lXnyymr14hJ4izuJxbnxHoy8B7XhMzw xxWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744060249; x=1744665049; 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=XER1T4UKMjoPSozPZWo9dv2miNBpBaF37Pvg91kH1b0=; b=P6YkiW8O3c529C1vW5lchoIsCyW8NZiJdfRiH1s43lJKMpZzPgJkHy+sByex/ezeE3 Ee6RzKfQHLBEHW8lSyfjWFj5Tas52D62Win3P2YaAm/UoPK4jYdugNQ48C9YByNms+jo fOFZEGhyqo/If6liVIfEl4hC0cLsOlZqzM+HV81bRGYIUR6AgBxVvMovgpp09F2ZfKKq 2crUGdP4B0zU0QkjOtU6rTFg0Kyxlb+xuHJUBGvLbZ6Yr06sfPhpLu3/Z1/ls3weQupQ qh+pU7EGKXDWjJDRlRi00x5OZDImd5ZJy3cIH+i/n+CY9wfIM3xDfIJDFom0hy8K9sdy ai8A== X-Forwarded-Encrypted: i=1; AJvYcCVSkdf/W5IwtGH8YAJHdRgnJw0fYJj+3Loe9B0m54dRRwvzjFQlMBZznsctwlu1jQRF/d+ktIppCikqJv4=@vger.kernel.org X-Gm-Message-State: AOJu0YwHVyF1ngl3/62Tb1ziVHBstFSvajBR+//8ITFJkvlseCtNehfS P10aHpnp/ZVX3Zuktjn3xPHpzTh5Mizbb1T3yUt8uGyiZClfiUG9fUlWs3D50kB5w9fL6cyUoVn VglOjZg== X-Google-Smtp-Source: AGHT+IFUh2w31Wjyx7D06LRd2b8npYTMmrYGA1006gxi1quhChbLnQ7kIWT4UvL7Bsqml+8eWpRjgJasyMDv X-Received: from pgbda9.prod.google.com ([2002:a05:6a02:2389:b0:af2:22fe:cfb3]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:cd91:b0:1f5:8a1d:3904 with SMTP id adf61e73a8af0-2010458cc7emr23831402637.7.1744060249119; Mon, 07 Apr 2025 14:10:49 -0700 (PDT) Date: Mon, 7 Apr 2025 14:09:36 -0700 In-Reply-To: <20250407210937.131681-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: <20250407210937.131681-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.504.g3bcea36a83-goog Message-ID: <20250407210937.131681-16-irogers@google.com> Subject: [PATCH v3 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. If the default values are used the min or max in the sampled statistics are also updated so that the max never decreases or the min increases. 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 | 52 ++++-- tools/perf/util/parse-events.c | 4 + tools/perf/util/pmu.c | 52 +++++- tools/perf/util/pmu.h | 3 + 8 files changed, 220 insertions(+), 122 deletions(-) diff --git a/tools/perf/pmu-events/empty-pmu-events.c b/tools/perf/pmu-even= ts/empty-pmu-events.c index 0cb7ba7912e8..0361bcc1eb58 100644 --- a/tools/perf/pmu-events/empty-pmu-events.c +++ b/tools/perf/pmu-events/empty-pmu-events.c @@ -20,73 +20,73 @@ struct pmu_table_entry { =20 static const char *const big_c_string =3D /* offset=3D0 */ "tool\000" -/* offset=3D5 */ "duration_time\000tool\000Wall clock interval time in nan= oseconds\000config=3D1\000\00000\000\000" -/* offset=3D78 */ "user_time\000tool\000User (non-kernel) time in nanoseco= nds\000config=3D2\000\00000\000\000" -/* offset=3D145 */ "system_time\000tool\000System/kernel time in nanosecon= ds\000config=3D3\000\00000\000\000" -/* offset=3D210 */ "has_pmem\000tool\0001 if persistent memory installed o= therwise 0\000config=3D4\000\00000\000\000" -/* offset=3D283 */ "num_cores\000tool\000Number of cores. A core consists = of 1 or more thread, with each thread being associated with a logical Linux= CPU\000config=3D5\000\00000\000\000" -/* offset=3D425 */ "num_cpus\000tool\000Number of logical Linux CPUs. Ther= e may be multiple such CPUs on a core\000config=3D6\000\00000\000\000" -/* offset=3D525 */ "num_cpus_online\000tool\000Number of online logical Li= nux CPUs. There may be multiple such CPUs on a core\000config=3D7\000\00000= \000\000" -/* offset=3D639 */ "num_dies\000tool\000Number of dies. Each die has 1 or = more cores\000config=3D8\000\00000\000\000" -/* offset=3D712 */ "num_packages\000tool\000Number of packages. Each packa= ge has 1 or more die\000config=3D9\000\00000\000\000" -/* offset=3D795 */ "slots\000tool\000Number of functional units that in pa= rallel can execute parts of an instruction\000config=3D0xa\000\00000\000\00= 0" -/* offset=3D902 */ "smt_on\000tool\0001 if simultaneous multithreading (ak= a hyperthreading) is enable otherwise 0\000config=3D0xb\000\00000\000\000" -/* offset=3D1006 */ "system_tsc_freq\000tool\000The amount a Time Stamp Co= unter (TSC) increases per second\000config=3D0xc\000\00000\000\000" -/* offset=3D1102 */ "default_core\000" -/* offset=3D1115 */ "bp_l1_btb_correct\000branch\000L1 BTB Correction\000e= vent=3D0x8a\000\00000\000\000" -/* offset=3D1174 */ "bp_l2_btb_correct\000branch\000L2 BTB Correction\000e= vent=3D0x8b\000\00000\000\000" -/* offset=3D1233 */ "l3_cache_rd\000cache\000L3 cache access, read\000even= t=3D0x40\000\00000\000Attributable Level 3 cache access, read\000" -/* offset=3D1328 */ "segment_reg_loads.any\000other\000Number of segment r= egister loads\000event=3D6,period=3D200000,umask=3D0x80\000\00000\000\000" -/* offset=3D1427 */ "dispatch_blocked.any\000other\000Memory cluster signa= ls to block micro-op dispatch for any reason\000event=3D9,period=3D200000,u= mask=3D0x20\000\00000\000\000" -/* offset=3D1557 */ "eist_trans\000other\000Number of Enhanced Intel Speed= Step(R) Technology (EIST) transitions\000event=3D0x3a,period=3D200000\000\0= 0000\000\000" -/* offset=3D1672 */ "hisi_sccl,ddrc\000" -/* offset=3D1687 */ "uncore_hisi_ddrc.flux_wcmd\000uncore\000DDRC write co= mmands\000event=3D2\000\00000\000DDRC write commands\000" -/* offset=3D1773 */ "uncore_cbox\000" -/* offset=3D1785 */ "unc_cbo_xsnp_response.miss_eviction\000uncore\000A cr= oss-core snoop resulted from L3 Eviction which misses in some processor cor= e\000event=3D0x22,umask=3D0x81\000\00000\000A cross-core snoop resulted fro= m L3 Eviction which misses in some processor core\000" -/* offset=3D2016 */ "event-hyphen\000uncore\000UNC_CBO_HYPHEN\000event=3D0= xe0\000\00000\000UNC_CBO_HYPHEN\000" -/* offset=3D2081 */ "event-two-hyph\000uncore\000UNC_CBO_TWO_HYPH\000event= =3D0xc0\000\00000\000UNC_CBO_TWO_HYPH\000" -/* offset=3D2152 */ "hisi_sccl,l3c\000" -/* offset=3D2166 */ "uncore_hisi_l3c.rd_hit_cpipe\000uncore\000Total read = hits\000event=3D7\000\00000\000Total read hits\000" -/* offset=3D2246 */ "uncore_imc_free_running\000" -/* offset=3D2270 */ "uncore_imc_free_running.cache_miss\000uncore\000Total= cache misses\000event=3D0x12\000\00000\000Total cache misses\000" -/* offset=3D2365 */ "uncore_imc\000" -/* offset=3D2376 */ "uncore_imc.cache_hits\000uncore\000Total cache hits\0= 00event=3D0x34\000\00000\000Total cache hits\000" -/* offset=3D2454 */ "uncore_sys_ddr_pmu\000" -/* offset=3D2473 */ "sys_ddr_pmu.write_cycles\000uncore\000ddr write-cycle= s event\000event=3D0x2b\000v8\00000\000\000" -/* offset=3D2546 */ "uncore_sys_ccn_pmu\000" -/* offset=3D2565 */ "sys_ccn_pmu.read_cycles\000uncore\000ccn read-cycles = event\000config=3D0x2c\0000x01\00000\000\000" -/* offset=3D2639 */ "uncore_sys_cmn_pmu\000" -/* offset=3D2658 */ "sys_cmn_pmu.hnf_cache_miss\000uncore\000Counts total = cache misses in first lookup result (high priority)\000eventid=3D1,type=3D5= \000(434|436|43c|43a).*\00000\000\000" -/* offset=3D2798 */ "CPI\000\0001 / IPC\000\000\000\000\000\000\000\00000" -/* offset=3D2820 */ "IPC\000group1\000inst_retired.any / cpu_clk_unhalted.= thread\000\000\000\000\000\000\000\00000" -/* offset=3D2883 */ "Frontend_Bound_SMT\000\000idq_uops_not_delivered.core= / (4 * (cpu_clk_unhalted.thread / 2 * (1 + cpu_clk_unhalted.one_thread_act= ive / cpu_clk_unhalted.ref_xclk)))\000\000\000\000\000\000\000\00000" -/* offset=3D3049 */ "dcache_miss_cpi\000\000l1d\\-loads\\-misses / inst_re= tired.any\000\000\000\000\000\000\000\00000" -/* offset=3D3113 */ "icache_miss_cycles\000\000l1i\\-loads\\-misses / inst= _retired.any\000\000\000\000\000\000\000\00000" -/* offset=3D3180 */ "cache_miss_cycles\000group1\000dcache_miss_cpi + icac= he_miss_cycles\000\000\000\000\000\000\000\00000" -/* offset=3D3251 */ "DCache_L2_All_Hits\000\000l2_rqsts.demand_data_rd_hit= + l2_rqsts.pf_hit + l2_rqsts.rfo_hit\000\000\000\000\000\000\000\00000" -/* offset=3D3345 */ "DCache_L2_All_Miss\000\000max(l2_rqsts.all_demand_dat= a_rd - l2_rqsts.demand_data_rd_hit, 0) + l2_rqsts.pf_miss + l2_rqsts.rfo_mi= ss\000\000\000\000\000\000\000\00000" -/* offset=3D3479 */ "DCache_L2_All\000\000DCache_L2_All_Hits + DCache_L2_A= ll_Miss\000\000\000\000\000\000\000\00000" -/* offset=3D3543 */ "DCache_L2_Hits\000\000d_ratio(DCache_L2_All_Hits, DCa= che_L2_All)\000\000\000\000\000\000\000\00000" -/* offset=3D3611 */ "DCache_L2_Misses\000\000d_ratio(DCache_L2_All_Miss, D= Cache_L2_All)\000\000\000\000\000\000\000\00000" -/* offset=3D3681 */ "M1\000\000ipc + M2\000\000\000\000\000\000\000\00000" -/* offset=3D3703 */ "M2\000\000ipc + M1\000\000\000\000\000\000\000\00000" -/* offset=3D3725 */ "M3\000\0001 / M3\000\000\000\000\000\000\000\00000" -/* offset=3D3745 */ "L1D_Cache_Fill_BW\000\00064 * l1d.replacement / 1e9 /= duration_time\000\000\000\000\000\000\000\00000" +/* offset=3D5 */ "duration_time\000tool\000Wall clock interval time in nan= oseconds\000config=3D1\000\00000\000\000\000\000\000" +/* offset=3D81 */ "user_time\000tool\000User (non-kernel) time in nanoseco= nds\000config=3D2\000\00000\000\000\000\000\000" +/* offset=3D151 */ "system_time\000tool\000System/kernel time in nanosecon= ds\000config=3D3\000\00000\000\000\000\000\000" +/* offset=3D219 */ "has_pmem\000tool\0001 if persistent memory installed o= therwise 0\000config=3D4\000\00000\000\000\000\000\000" +/* offset=3D295 */ "num_cores\000tool\000Number of cores. A core consists = of 1 or more thread, with each thread being associated with a logical Linux= CPU\000config=3D5\000\00000\000\000\000\000\000" +/* offset=3D440 */ "num_cpus\000tool\000Number of logical Linux CPUs. Ther= e may be multiple such CPUs on a core\000config=3D6\000\00000\000\000\000\0= 00\000" +/* offset=3D543 */ "num_cpus_online\000tool\000Number of online logical Li= nux CPUs. There may be multiple such CPUs on a core\000config=3D7\000\00000= \000\000\000\000\000" +/* offset=3D660 */ "num_dies\000tool\000Number of dies. Each die has 1 or = more cores\000config=3D8\000\00000\000\000\000\000\000" +/* offset=3D736 */ "num_packages\000tool\000Number of packages. Each packa= ge has 1 or more die\000config=3D9\000\00000\000\000\000\000\000" +/* offset=3D822 */ "slots\000tool\000Number of functional units that in pa= rallel can execute parts of an instruction\000config=3D0xa\000\00000\000\00= 0\000\000\000" +/* offset=3D932 */ "smt_on\000tool\0001 if simultaneous multithreading (ak= a hyperthreading) is enable otherwise 0\000config=3D0xb\000\00000\000\000\0= 00\000\000" +/* offset=3D1039 */ "system_tsc_freq\000tool\000The amount a Time Stamp Co= unter (TSC) increases per second\000config=3D0xc\000\00000\000\000\000\000\= 000" +/* offset=3D1138 */ "default_core\000" +/* offset=3D1151 */ "bp_l1_btb_correct\000branch\000L1 BTB Correction\000e= vent=3D0x8a\000\00000\000\000\000\000\000" +/* offset=3D1213 */ "bp_l2_btb_correct\000branch\000L2 BTB Correction\000e= vent=3D0x8b\000\00000\000\000\000\000\000" +/* offset=3D1275 */ "l3_cache_rd\000cache\000L3 cache access, read\000even= t=3D0x40\000\00000\000\000\000\000Attributable Level 3 cache access, read\0= 00" +/* offset=3D1373 */ "segment_reg_loads.any\000other\000Number of segment r= egister loads\000event=3D6,period=3D200000,umask=3D0x80\000\00000\000\000\0= 00\000\000" +/* offset=3D1475 */ "dispatch_blocked.any\000other\000Memory cluster signa= ls to block micro-op dispatch for any reason\000event=3D9,period=3D200000,u= mask=3D0x20\000\00000\000\000\000\000\000" +/* offset=3D1608 */ "eist_trans\000other\000Number of Enhanced Intel Speed= Step(R) Technology (EIST) transitions\000event=3D0x3a,period=3D200000\000\0= 0000\000\000\000\000\000" +/* offset=3D1726 */ "hisi_sccl,ddrc\000" +/* offset=3D1741 */ "uncore_hisi_ddrc.flux_wcmd\000uncore\000DDRC write co= mmands\000event=3D2\000\00000\000\000\000\000DDRC write commands\000" +/* offset=3D1830 */ "uncore_cbox\000" +/* offset=3D1842 */ "unc_cbo_xsnp_response.miss_eviction\000uncore\000A cr= oss-core snoop resulted from L3 Eviction which misses in some processor cor= e\000event=3D0x22,umask=3D0x81\000\00000\000\000\000\000A cross-core snoop = resulted from L3 Eviction which misses in some processor core\000" +/* offset=3D2076 */ "event-hyphen\000uncore\000UNC_CBO_HYPHEN\000event=3D0= xe0\000\00000\000\000\000\000UNC_CBO_HYPHEN\000" +/* offset=3D2144 */ "event-two-hyph\000uncore\000UNC_CBO_TWO_HYPH\000event= =3D0xc0\000\00000\000\000\000\000UNC_CBO_TWO_HYPH\000" +/* offset=3D2218 */ "hisi_sccl,l3c\000" +/* offset=3D2232 */ "uncore_hisi_l3c.rd_hit_cpipe\000uncore\000Total read = hits\000event=3D7\000\00000\000\000\000\000Total read hits\000" +/* offset=3D2315 */ "uncore_imc_free_running\000" +/* offset=3D2339 */ "uncore_imc_free_running.cache_miss\000uncore\000Total= cache misses\000event=3D0x12\000\00000\000\000\000\000Total cache misses\0= 00" +/* offset=3D2437 */ "uncore_imc\000" +/* offset=3D2448 */ "uncore_imc.cache_hits\000uncore\000Total cache hits\0= 00event=3D0x34\000\00000\000\000\000\000Total cache hits\000" +/* offset=3D2529 */ "uncore_sys_ddr_pmu\000" +/* offset=3D2548 */ "sys_ddr_pmu.write_cycles\000uncore\000ddr write-cycle= s event\000event=3D0x2b\000v8\00000\000\000\000\000\000" +/* offset=3D2624 */ "uncore_sys_ccn_pmu\000" +/* offset=3D2643 */ "sys_ccn_pmu.read_cycles\000uncore\000ccn read-cycles = event\000config=3D0x2c\0000x01\00000\000\000\000\000\000" +/* offset=3D2720 */ "uncore_sys_cmn_pmu\000" +/* offset=3D2739 */ "sys_cmn_pmu.hnf_cache_miss\000uncore\000Counts total = cache misses in first lookup result (high priority)\000eventid=3D1,type=3D5= \000(434|436|43c|43a).*\00000\000\000\000\000\000" +/* offset=3D2882 */ "CPI\000\0001 / IPC\000\000\000\000\000\000\000\00000" +/* offset=3D2904 */ "IPC\000group1\000inst_retired.any / cpu_clk_unhalted.= thread\000\000\000\000\000\000\000\00000" +/* offset=3D2967 */ "Frontend_Bound_SMT\000\000idq_uops_not_delivered.core= / (4 * (cpu_clk_unhalted.thread / 2 * (1 + cpu_clk_unhalted.one_thread_act= ive / cpu_clk_unhalted.ref_xclk)))\000\000\000\000\000\000\000\00000" +/* offset=3D3133 */ "dcache_miss_cpi\000\000l1d\\-loads\\-misses / inst_re= tired.any\000\000\000\000\000\000\000\00000" +/* offset=3D3197 */ "icache_miss_cycles\000\000l1i\\-loads\\-misses / inst= _retired.any\000\000\000\000\000\000\000\00000" +/* offset=3D3264 */ "cache_miss_cycles\000group1\000dcache_miss_cpi + icac= he_miss_cycles\000\000\000\000\000\000\000\00000" +/* offset=3D3335 */ "DCache_L2_All_Hits\000\000l2_rqsts.demand_data_rd_hit= + l2_rqsts.pf_hit + l2_rqsts.rfo_hit\000\000\000\000\000\000\000\00000" +/* offset=3D3429 */ "DCache_L2_All_Miss\000\000max(l2_rqsts.all_demand_dat= a_rd - l2_rqsts.demand_data_rd_hit, 0) + l2_rqsts.pf_miss + l2_rqsts.rfo_mi= ss\000\000\000\000\000\000\000\00000" +/* offset=3D3563 */ "DCache_L2_All\000\000DCache_L2_All_Hits + DCache_L2_A= ll_Miss\000\000\000\000\000\000\000\00000" +/* offset=3D3627 */ "DCache_L2_Hits\000\000d_ratio(DCache_L2_All_Hits, DCa= che_L2_All)\000\000\000\000\000\000\000\00000" +/* offset=3D3695 */ "DCache_L2_Misses\000\000d_ratio(DCache_L2_All_Miss, D= Cache_L2_All)\000\000\000\000\000\000\000\00000" +/* offset=3D3765 */ "M1\000\000ipc + M2\000\000\000\000\000\000\000\00000" +/* offset=3D3787 */ "M2\000\000ipc + M1\000\000\000\000\000\000\000\00000" +/* offset=3D3809 */ "M3\000\0001 / M3\000\000\000\000\000\000\000\00000" +/* offset=3D3829 */ "L1D_Cache_Fill_BW\000\00064 * l1d.replacement / 1e9 /= duration_time\000\000\000\000\000\000\000\00000" ; =20 static const struct compact_pmu_event pmu_events__common_tool[] =3D { -{ 5 }, /* duration_time\000tool\000Wall clock interval time in nanoseconds= \000config=3D1\000\00000\000\000 */ -{ 210 }, /* has_pmem\000tool\0001 if persistent memory installed otherwise= 0\000config=3D4\000\00000\000\000 */ -{ 283 }, /* num_cores\000tool\000Number of cores. A core consists of 1 or = more thread, with each thread being associated with a logical Linux CPU\000= config=3D5\000\00000\000\000 */ -{ 425 }, /* num_cpus\000tool\000Number of logical Linux CPUs. There may be= multiple such CPUs on a core\000config=3D6\000\00000\000\000 */ -{ 525 }, /* num_cpus_online\000tool\000Number of online logical Linux CPUs= . There may be multiple such CPUs on a core\000config=3D7\000\00000\000\000= */ -{ 639 }, /* num_dies\000tool\000Number of dies. Each die has 1 or more cor= es\000config=3D8\000\00000\000\000 */ -{ 712 }, /* num_packages\000tool\000Number of packages. Each package has 1= or more die\000config=3D9\000\00000\000\000 */ -{ 795 }, /* slots\000tool\000Number of functional units that in parallel c= an execute parts of an instruction\000config=3D0xa\000\00000\000\000 */ -{ 902 }, /* smt_on\000tool\0001 if simultaneous multithreading (aka hypert= hreading) is enable otherwise 0\000config=3D0xb\000\00000\000\000 */ -{ 145 }, /* system_time\000tool\000System/kernel time in nanoseconds\000co= nfig=3D3\000\00000\000\000 */ -{ 1006 }, /* system_tsc_freq\000tool\000The amount a Time Stamp Counter (T= SC) increases per second\000config=3D0xc\000\00000\000\000 */ -{ 78 }, /* user_time\000tool\000User (non-kernel) time in nanoseconds\000c= onfig=3D2\000\00000\000\000 */ +{ 5 }, /* duration_time\000tool\000Wall clock interval time in nanoseconds= \000config=3D1\000\00000\000\000\000\000\000 */ +{ 219 }, /* has_pmem\000tool\0001 if persistent memory installed otherwise= 0\000config=3D4\000\00000\000\000\000\000\000 */ +{ 295 }, /* num_cores\000tool\000Number of cores. A core consists of 1 or = more thread, with each thread being associated with a logical Linux CPU\000= config=3D5\000\00000\000\000\000\000\000 */ +{ 440 }, /* num_cpus\000tool\000Number of logical Linux CPUs. There may be= multiple such CPUs on a core\000config=3D6\000\00000\000\000\000\000\000 */ +{ 543 }, /* num_cpus_online\000tool\000Number of online logical Linux CPUs= . There may be multiple such CPUs on a core\000config=3D7\000\00000\000\000= \000\000\000 */ +{ 660 }, /* num_dies\000tool\000Number of dies. Each die has 1 or more cor= es\000config=3D8\000\00000\000\000\000\000\000 */ +{ 736 }, /* num_packages\000tool\000Number of packages. Each package has 1= or more die\000config=3D9\000\00000\000\000\000\000\000 */ +{ 822 }, /* slots\000tool\000Number of functional units that in parallel c= an execute parts of an instruction\000config=3D0xa\000\00000\000\000\000\00= 0\000 */ +{ 932 }, /* smt_on\000tool\0001 if simultaneous multithreading (aka hypert= hreading) is enable otherwise 0\000config=3D0xb\000\00000\000\000\000\000\0= 00 */ +{ 151 }, /* system_time\000tool\000System/kernel time in nanoseconds\000co= nfig=3D3\000\00000\000\000\000\000\000 */ +{ 1039 }, /* system_tsc_freq\000tool\000The amount a Time Stamp Counter (T= SC) increases per second\000config=3D0xc\000\00000\000\000\000\000\000 */ +{ 81 }, /* user_time\000tool\000User (non-kernel) time in nanoseconds\000c= onfig=3D2\000\00000\000\000\000\000\000 */ =20 }; =20 @@ -99,29 +99,29 @@ const struct pmu_table_entry pmu_events__common[] =3D { }; =20 static const struct compact_pmu_event pmu_events__test_soc_cpu_default_cor= e[] =3D { -{ 1115 }, /* bp_l1_btb_correct\000branch\000L1 BTB Correction\000event=3D0= x8a\000\00000\000\000 */ -{ 1174 }, /* bp_l2_btb_correct\000branch\000L2 BTB Correction\000event=3D0= x8b\000\00000\000\000 */ -{ 1427 }, /* dispatch_blocked.any\000other\000Memory cluster signals to bl= ock micro-op dispatch for any reason\000event=3D9,period=3D200000,umask=3D0= x20\000\00000\000\000 */ -{ 1557 }, /* eist_trans\000other\000Number of Enhanced Intel SpeedStep(R) = Technology (EIST) transitions\000event=3D0x3a,period=3D200000\000\00000\000= \000 */ -{ 1233 }, /* l3_cache_rd\000cache\000L3 cache access, read\000event=3D0x40= \000\00000\000Attributable Level 3 cache access, read\000 */ -{ 1328 }, /* segment_reg_loads.any\000other\000Number of segment register = loads\000event=3D6,period=3D200000,umask=3D0x80\000\00000\000\000 */ +{ 1151 }, /* bp_l1_btb_correct\000branch\000L1 BTB Correction\000event=3D0= x8a\000\00000\000\000\000\000\000 */ +{ 1213 }, /* bp_l2_btb_correct\000branch\000L2 BTB Correction\000event=3D0= x8b\000\00000\000\000\000\000\000 */ +{ 1475 }, /* dispatch_blocked.any\000other\000Memory cluster signals to bl= ock micro-op dispatch for any reason\000event=3D9,period=3D200000,umask=3D0= x20\000\00000\000\000\000\000\000 */ +{ 1608 }, /* eist_trans\000other\000Number of Enhanced Intel SpeedStep(R) = Technology (EIST) transitions\000event=3D0x3a,period=3D200000\000\00000\000= \000\000\000\000 */ +{ 1275 }, /* l3_cache_rd\000cache\000L3 cache access, read\000event=3D0x40= \000\00000\000\000\000\000Attributable Level 3 cache access, read\000 */ +{ 1373 }, /* segment_reg_loads.any\000other\000Number of segment register = loads\000event=3D6,period=3D200000,umask=3D0x80\000\00000\000\000\000\000\0= 00 */ }; static const struct compact_pmu_event pmu_events__test_soc_cpu_hisi_sccl_d= drc[] =3D { -{ 1687 }, /* uncore_hisi_ddrc.flux_wcmd\000uncore\000DDRC write commands\0= 00event=3D2\000\00000\000DDRC write commands\000 */ +{ 1741 }, /* uncore_hisi_ddrc.flux_wcmd\000uncore\000DDRC write commands\0= 00event=3D2\000\00000\000\000\000\000DDRC write commands\000 */ }; static const struct compact_pmu_event pmu_events__test_soc_cpu_hisi_sccl_l= 3c[] =3D { -{ 2166 }, /* uncore_hisi_l3c.rd_hit_cpipe\000uncore\000Total read hits\000= event=3D7\000\00000\000Total read hits\000 */ +{ 2232 }, /* uncore_hisi_l3c.rd_hit_cpipe\000uncore\000Total read hits\000= event=3D7\000\00000\000\000\000\000Total read hits\000 */ }; static const struct compact_pmu_event pmu_events__test_soc_cpu_uncore_cbox= [] =3D { -{ 2016 }, /* event-hyphen\000uncore\000UNC_CBO_HYPHEN\000event=3D0xe0\000\= 00000\000UNC_CBO_HYPHEN\000 */ -{ 2081 }, /* event-two-hyph\000uncore\000UNC_CBO_TWO_HYPH\000event=3D0xc0\= 000\00000\000UNC_CBO_TWO_HYPH\000 */ -{ 1785 }, /* unc_cbo_xsnp_response.miss_eviction\000uncore\000A cross-core= snoop resulted from L3 Eviction which misses in some processor core\000eve= nt=3D0x22,umask=3D0x81\000\00000\000A cross-core snoop resulted from L3 Evi= ction which misses in some processor core\000 */ +{ 2076 }, /* event-hyphen\000uncore\000UNC_CBO_HYPHEN\000event=3D0xe0\000\= 00000\000\000\000\000UNC_CBO_HYPHEN\000 */ +{ 2144 }, /* event-two-hyph\000uncore\000UNC_CBO_TWO_HYPH\000event=3D0xc0\= 000\00000\000\000\000\000UNC_CBO_TWO_HYPH\000 */ +{ 1842 }, /* unc_cbo_xsnp_response.miss_eviction\000uncore\000A cross-core= snoop resulted from L3 Eviction which misses in some processor core\000eve= nt=3D0x22,umask=3D0x81\000\00000\000\000\000\000A cross-core snoop resulted= from L3 Eviction which misses in some processor core\000 */ }; static const struct compact_pmu_event pmu_events__test_soc_cpu_uncore_imc[= ] =3D { -{ 2376 }, /* uncore_imc.cache_hits\000uncore\000Total cache hits\000event= =3D0x34\000\00000\000Total cache hits\000 */ +{ 2448 }, /* uncore_imc.cache_hits\000uncore\000Total cache hits\000event= =3D0x34\000\00000\000\000\000\000Total cache hits\000 */ }; static const struct compact_pmu_event pmu_events__test_soc_cpu_uncore_imc_= free_running[] =3D { -{ 2270 }, /* uncore_imc_free_running.cache_miss\000uncore\000Total cache m= isses\000event=3D0x12\000\00000\000Total cache misses\000 */ +{ 2339 }, /* uncore_imc_free_running.cache_miss\000uncore\000Total cache m= isses\000event=3D0x12\000\00000\000\000\000\000Total cache misses\000 */ =20 }; =20 @@ -129,51 +129,51 @@ const struct pmu_table_entry pmu_events__test_soc_cpu= [] =3D { { .entries =3D pmu_events__test_soc_cpu_default_core, .num_entries =3D ARRAY_SIZE(pmu_events__test_soc_cpu_default_core), - .pmu_name =3D { 1102 /* default_core\000 */ }, + .pmu_name =3D { 1138 /* default_core\000 */ }, }, { .entries =3D pmu_events__test_soc_cpu_hisi_sccl_ddrc, .num_entries =3D ARRAY_SIZE(pmu_events__test_soc_cpu_hisi_sccl_ddrc), - .pmu_name =3D { 1672 /* hisi_sccl,ddrc\000 */ }, + .pmu_name =3D { 1726 /* hisi_sccl,ddrc\000 */ }, }, { .entries =3D pmu_events__test_soc_cpu_hisi_sccl_l3c, .num_entries =3D ARRAY_SIZE(pmu_events__test_soc_cpu_hisi_sccl_l3c), - .pmu_name =3D { 2152 /* hisi_sccl,l3c\000 */ }, + .pmu_name =3D { 2218 /* hisi_sccl,l3c\000 */ }, }, { .entries =3D pmu_events__test_soc_cpu_uncore_cbox, .num_entries =3D ARRAY_SIZE(pmu_events__test_soc_cpu_uncore_cbox), - .pmu_name =3D { 1773 /* uncore_cbox\000 */ }, + .pmu_name =3D { 1830 /* uncore_cbox\000 */ }, }, { .entries =3D pmu_events__test_soc_cpu_uncore_imc, .num_entries =3D ARRAY_SIZE(pmu_events__test_soc_cpu_uncore_imc), - .pmu_name =3D { 2365 /* uncore_imc\000 */ }, + .pmu_name =3D { 2437 /* uncore_imc\000 */ }, }, { .entries =3D pmu_events__test_soc_cpu_uncore_imc_free_running, .num_entries =3D ARRAY_SIZE(pmu_events__test_soc_cpu_uncore_imc_free_= running), - .pmu_name =3D { 2246 /* uncore_imc_free_running\000 */ }, + .pmu_name =3D { 2315 /* uncore_imc_free_running\000 */ }, }, }; =20 static const struct compact_pmu_event pmu_metrics__test_soc_cpu_default_co= re[] =3D { -{ 2798 }, /* CPI\000\0001 / IPC\000\000\000\000\000\000\000\00000 */ -{ 3479 }, /* DCache_L2_All\000\000DCache_L2_All_Hits + DCache_L2_All_Miss\= 000\000\000\000\000\000\000\00000 */ -{ 3251 }, /* DCache_L2_All_Hits\000\000l2_rqsts.demand_data_rd_hit + l2_rq= sts.pf_hit + l2_rqsts.rfo_hit\000\000\000\000\000\000\000\00000 */ -{ 3345 }, /* DCache_L2_All_Miss\000\000max(l2_rqsts.all_demand_data_rd - l= 2_rqsts.demand_data_rd_hit, 0) + l2_rqsts.pf_miss + l2_rqsts.rfo_miss\000\0= 00\000\000\000\000\000\00000 */ -{ 3543 }, /* DCache_L2_Hits\000\000d_ratio(DCache_L2_All_Hits, DCache_L2_A= ll)\000\000\000\000\000\000\000\00000 */ -{ 3611 }, /* DCache_L2_Misses\000\000d_ratio(DCache_L2_All_Miss, DCache_L2= _All)\000\000\000\000\000\000\000\00000 */ -{ 2883 }, /* Frontend_Bound_SMT\000\000idq_uops_not_delivered.core / (4 * = (cpu_clk_unhalted.thread / 2 * (1 + cpu_clk_unhalted.one_thread_active / cp= u_clk_unhalted.ref_xclk)))\000\000\000\000\000\000\000\00000 */ -{ 2820 }, /* IPC\000group1\000inst_retired.any / cpu_clk_unhalted.thread\0= 00\000\000\000\000\000\000\00000 */ -{ 3745 }, /* L1D_Cache_Fill_BW\000\00064 * l1d.replacement / 1e9 / duratio= n_time\000\000\000\000\000\000\000\00000 */ -{ 3681 }, /* M1\000\000ipc + M2\000\000\000\000\000\000\000\00000 */ -{ 3703 }, /* M2\000\000ipc + M1\000\000\000\000\000\000\000\00000 */ -{ 3725 }, /* M3\000\0001 / M3\000\000\000\000\000\000\000\00000 */ -{ 3180 }, /* cache_miss_cycles\000group1\000dcache_miss_cpi + icache_miss_= cycles\000\000\000\000\000\000\000\00000 */ -{ 3049 }, /* dcache_miss_cpi\000\000l1d\\-loads\\-misses / inst_retired.an= y\000\000\000\000\000\000\000\00000 */ -{ 3113 }, /* icache_miss_cycles\000\000l1i\\-loads\\-misses / inst_retired= .any\000\000\000\000\000\000\000\00000 */ +{ 2882 }, /* CPI\000\0001 / IPC\000\000\000\000\000\000\000\00000 */ +{ 3563 }, /* DCache_L2_All\000\000DCache_L2_All_Hits + DCache_L2_All_Miss\= 000\000\000\000\000\000\000\00000 */ +{ 3335 }, /* DCache_L2_All_Hits\000\000l2_rqsts.demand_data_rd_hit + l2_rq= sts.pf_hit + l2_rqsts.rfo_hit\000\000\000\000\000\000\000\00000 */ +{ 3429 }, /* DCache_L2_All_Miss\000\000max(l2_rqsts.all_demand_data_rd - l= 2_rqsts.demand_data_rd_hit, 0) + l2_rqsts.pf_miss + l2_rqsts.rfo_miss\000\0= 00\000\000\000\000\000\00000 */ +{ 3627 }, /* DCache_L2_Hits\000\000d_ratio(DCache_L2_All_Hits, DCache_L2_A= ll)\000\000\000\000\000\000\000\00000 */ +{ 3695 }, /* DCache_L2_Misses\000\000d_ratio(DCache_L2_All_Miss, DCache_L2= _All)\000\000\000\000\000\000\000\00000 */ +{ 2967 }, /* Frontend_Bound_SMT\000\000idq_uops_not_delivered.core / (4 * = (cpu_clk_unhalted.thread / 2 * (1 + cpu_clk_unhalted.one_thread_active / cp= u_clk_unhalted.ref_xclk)))\000\000\000\000\000\000\000\00000 */ +{ 2904 }, /* IPC\000group1\000inst_retired.any / cpu_clk_unhalted.thread\0= 00\000\000\000\000\000\000\00000 */ +{ 3829 }, /* L1D_Cache_Fill_BW\000\00064 * l1d.replacement / 1e9 / duratio= n_time\000\000\000\000\000\000\000\00000 */ +{ 3765 }, /* M1\000\000ipc + M2\000\000\000\000\000\000\000\00000 */ +{ 3787 }, /* M2\000\000ipc + M1\000\000\000\000\000\000\000\00000 */ +{ 3809 }, /* M3\000\0001 / M3\000\000\000\000\000\000\000\00000 */ +{ 3264 }, /* cache_miss_cycles\000group1\000dcache_miss_cpi + icache_miss_= cycles\000\000\000\000\000\000\000\00000 */ +{ 3133 }, /* dcache_miss_cpi\000\000l1d\\-loads\\-misses / inst_retired.an= y\000\000\000\000\000\000\000\00000 */ +{ 3197 }, /* icache_miss_cycles\000\000l1i\\-loads\\-misses / inst_retired= .any\000\000\000\000\000\000\000\00000 */ =20 }; =20 @@ -181,18 +181,18 @@ const struct pmu_table_entry pmu_metrics__test_soc_cp= u[] =3D { { .entries =3D pmu_metrics__test_soc_cpu_default_core, .num_entries =3D ARRAY_SIZE(pmu_metrics__test_soc_cpu_default_core), - .pmu_name =3D { 1102 /* default_core\000 */ }, + .pmu_name =3D { 1138 /* default_core\000 */ }, }, }; =20 static const struct compact_pmu_event pmu_events__test_soc_sys_uncore_sys_= ccn_pmu[] =3D { -{ 2565 }, /* sys_ccn_pmu.read_cycles\000uncore\000ccn read-cycles event\00= 0config=3D0x2c\0000x01\00000\000\000 */ +{ 2643 }, /* sys_ccn_pmu.read_cycles\000uncore\000ccn read-cycles event\00= 0config=3D0x2c\0000x01\00000\000\000\000\000\000 */ }; static const struct compact_pmu_event pmu_events__test_soc_sys_uncore_sys_= cmn_pmu[] =3D { -{ 2658 }, /* sys_cmn_pmu.hnf_cache_miss\000uncore\000Counts total cache mi= sses in first lookup result (high priority)\000eventid=3D1,type=3D5\000(434= |436|43c|43a).*\00000\000\000 */ +{ 2739 }, /* sys_cmn_pmu.hnf_cache_miss\000uncore\000Counts total cache mi= sses in first lookup result (high priority)\000eventid=3D1,type=3D5\000(434= |436|43c|43a).*\00000\000\000\000\000\000 */ }; static const struct compact_pmu_event pmu_events__test_soc_sys_uncore_sys_= ddr_pmu[] =3D { -{ 2473 }, /* sys_ddr_pmu.write_cycles\000uncore\000ddr write-cycles event\= 000event=3D0x2b\000v8\00000\000\000 */ +{ 2548 }, /* sys_ddr_pmu.write_cycles\000uncore\000ddr write-cycles event\= 000event=3D0x2b\000v8\00000\000\000\000\000\000 */ =20 }; =20 @@ -200,17 +200,17 @@ const struct pmu_table_entry pmu_events__test_soc_sys= [] =3D { { .entries =3D pmu_events__test_soc_sys_uncore_sys_ccn_pmu, .num_entries =3D ARRAY_SIZE(pmu_events__test_soc_sys_uncore_sys_ccn_p= mu), - .pmu_name =3D { 2546 /* uncore_sys_ccn_pmu\000 */ }, + .pmu_name =3D { 2624 /* uncore_sys_ccn_pmu\000 */ }, }, { .entries =3D pmu_events__test_soc_sys_uncore_sys_cmn_pmu, .num_entries =3D ARRAY_SIZE(pmu_events__test_soc_sys_uncore_sys_cmn_p= mu), - .pmu_name =3D { 2639 /* uncore_sys_cmn_pmu\000 */ }, + .pmu_name =3D { 2720 /* uncore_sys_cmn_pmu\000 */ }, }, { .entries =3D pmu_events__test_soc_sys_uncore_sys_ddr_pmu, .num_entries =3D ARRAY_SIZE(pmu_events__test_soc_sys_uncore_sys_ddr_p= mu), - .pmu_name =3D { 2454 /* uncore_sys_ddr_pmu\000 */ }, + .pmu_name =3D { 2529 /* uncore_sys_ddr_pmu\000 */ }, }, }; =20 @@ -316,6 +316,12 @@ static void decompress_event(int offset, struct pmu_ev= ent *pe) p++; pe->unit =3D (*p =3D=3D '\0' ? NULL : p); while (*p++); + pe->retirement_latency_mean =3D (*p =3D=3D '\0' ? NULL : p); + while (*p++); + pe->retirement_latency_min =3D (*p =3D=3D '\0' ? NULL : p); + while (*p++); + pe->retirement_latency_max =3D (*p =3D=3D '\0' ? NULL : p); + while (*p++); pe->long_desc =3D (*p =3D=3D '\0' ? NULL : p); } =20 diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jeven= ts.py index 7499a35bfadd..e3a55486c08e 100755 --- a/tools/perf/pmu-events/jevents.py +++ b/tools/perf/pmu-events/jevents.py @@ -47,6 +47,9 @@ _json_event_attributes =3D [ 'event', # Short things in alphabetical order. 'compat', 'deprecated', 'perpkg', 'unit', + # Retirement latency specific to Intel granite rapids currently. + 'retirement_latency_mean', 'retirement_latency_min', + 'retirement_latency_max', # Longer things (the last won't be iterated over during decompress). 'long_desc' ] @@ -341,6 +344,9 @@ class JsonEvent: self.perpkg =3D jd.get('PerPkg') self.aggr_mode =3D convert_aggr_mode(jd.get('AggregationMode')) self.deprecated =3D jd.get('Deprecated') + self.retirement_latency_mean =3D jd.get('RetirementLatencyMean') + self.retirement_latency_min =3D jd.get('RetirementLatencyMin') + self.retirement_latency_max =3D jd.get('RetirementLatencyMax') self.metric_name =3D jd.get('MetricName') self.metric_group =3D jd.get('MetricGroup') self.metricgroup_no_group =3D jd.get('MetricgroupNoGroup') diff --git a/tools/perf/pmu-events/pmu-events.h b/tools/perf/pmu-events/pmu= -events.h index 675562e6f770..a95fee561622 100644 --- a/tools/perf/pmu-events/pmu-events.h +++ b/tools/perf/pmu-events/pmu-events.h @@ -47,6 +47,9 @@ struct pmu_event { const char *long_desc; const char *pmu; const char *unit; + const char *retirement_latency_mean; + const char *retirement_latency_min; + const char *retirement_latency_max; bool perpkg; bool deprecated; }; diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index aae431d63d64..42dcadfef8ce 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -177,6 +177,12 @@ struct evsel { /* For tool events */ /* Beginning time subtracted when the counter is read. */ union { + /* Defaults for retirement latency events. */ + struct _retirement_latency { + double mean; + double min; + double max; + } retirement_latency; /* duration_time is a single global time. */ __u64 start_time; /* diff --git a/tools/perf/util/intel-tpebs.c b/tools/perf/util/intel-tpebs.c index 6b00bd5b0af1..31c845da4e8f 100644 --- a/tools/perf/util/intel-tpebs.c +++ b/tools/perf/util/intel-tpebs.c @@ -514,27 +514,49 @@ int evsel__tpebs_read(struct evsel *evsel, int cpu_ma= p_idx, int thread) * process. Allow the sample reader a chance to read by releasing and * reacquiring the lock. */ - if (&t->nd =3D=3D tpebs_results.next) { + if (t && &t->nd =3D=3D tpebs_results.next) { ret =3D tpebs_send_record_cmd(EVLIST_CTL_CMD_PING_TAG); mutex_unlock(tpebs_mtx_get()); if (ret) return ret; mutex_lock(tpebs_mtx_get()); } - switch (tpebs_mode) { - case TPEBS_MODE__MIN: - val =3D rint(t->stats.min); - break; - case TPEBS_MODE__MAX: - val =3D rint(t->stats.max); - break; - case TPEBS_MODE__LAST: - val =3D t->last; - break; - default: - case TPEBS_MODE__MEAN: - val =3D rint(t->stats.mean); - break; + if (t =3D=3D NULL || t->stats.n =3D=3D 0) { + /* No sample data, use default. */ + val =3D 0; + switch (tpebs_mode) { + case TPEBS_MODE__MIN: + val =3D rint(evsel->retirement_latency.min); + if (t) + t->stats.min =3D val; + break; + case TPEBS_MODE__MAX: + val =3D rint(evsel->retirement_latency.max); + if (t) + t->stats.max =3D val; + break; + default: + case TPEBS_MODE__LAST: + case TPEBS_MODE__MEAN: + val =3D rint(evsel->retirement_latency.mean); + break; + } + } else { + switch (tpebs_mode) { + case TPEBS_MODE__MIN: + val =3D t->stats.min; + break; + case TPEBS_MODE__MAX: + val =3D t->stats.max; + break; + case TPEBS_MODE__LAST: + val =3D t->last; + break; + default: + case TPEBS_MODE__MEAN: + val =3D rint(t->stats.mean); + break; + } } mutex_unlock(tpebs_mtx_get()); =20 diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 5152fd5a6ead..89708d1769c8 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -1539,6 +1539,10 @@ static int parse_events_add_pmu(struct parse_events_= state *parse_state, evsel->scale =3D info.scale; evsel->per_pkg =3D info.per_pkg; evsel->snapshot =3D info.snapshot; + evsel->retirement_latency.mean =3D info.retirement_latency_mean; + evsel->retirement_latency.min =3D info.retirement_latency_min; + evsel->retirement_latency.max =3D info.retirement_latency_max; + return 0; } =20 diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index b7ebac5ab1d1..bbb906bb2159 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -77,6 +77,12 @@ struct perf_pmu_alias { char unit[UNIT_MAX_LEN+1]; /** @scale: Value to scale read counter values by. */ double scale; + /** @retirement_latency_mean: Value to be given for unsampled retirement = latency mean. */ + double retirement_latency_mean; + /** @retirement_latency_min: Value to be given for unsampled retirement l= atency min. */ + double retirement_latency_min; + /** @retirement_latency_max: Value to be given for unsampled retirement l= atency max. */ + double retirement_latency_max; /** * @per_pkg: Does the file * /bus/event_source/devices//events/.per-pkg or @@ -257,7 +263,7 @@ static int pmu_format(struct perf_pmu *pmu, int dirfd, = const char *name, bool ea return 0; } =20 -int perf_pmu__convert_scale(const char *scale, char **end, double *sval) +static int parse_double(const char *scale, char **end, double *sval) { char *lc; int ret =3D 0; @@ -294,6 +300,11 @@ int perf_pmu__convert_scale(const char *scale, char **= end, double *sval) return ret; } =20 +int perf_pmu__convert_scale(const char *scale, char **end, double *sval) +{ + return parse_double(scale, end, sval); +} + static int perf_pmu__parse_scale(struct perf_pmu *pmu, struct perf_pmu_ali= as *alias) { struct stat st; @@ -525,6 +536,18 @@ static int update_alias(const struct pmu_event *pe, if (!ret) snprintf(data->alias->unit, sizeof(data->alias->unit), "%s", unit); } + if (!ret && pe->retirement_latency_mean) { + ret =3D parse_double(pe->retirement_latency_mean, NULL, + &data->alias->retirement_latency_mean); + } + if (!ret && pe->retirement_latency_min) { + ret =3D parse_double(pe->retirement_latency_min, NULL, + &data->alias->retirement_latency_min); + } + if (!ret && pe->retirement_latency_max) { + ret =3D parse_double(pe->retirement_latency_max, NULL, + &data->alias->retirement_latency_max); + } return ret; } =20 @@ -533,7 +556,7 @@ static int perf_pmu__new_alias(struct perf_pmu *pmu, co= nst char *name, const struct pmu_event *pe, enum event_source src) { struct perf_pmu_alias *alias; - int ret; + int ret =3D 0; const char *long_desc =3D NULL, *topic =3D NULL, *unit =3D NULL, *pmu_nam= e =3D NULL; bool deprecated =3D false, perpkg =3D false; =20 @@ -562,6 +585,24 @@ static int perf_pmu__new_alias(struct perf_pmu *pmu, c= onst char *name, alias->per_pkg =3D perpkg; alias->snapshot =3D false; alias->deprecated =3D deprecated; + alias->retirement_latency_mean =3D 0.0; + alias->retirement_latency_min =3D 0.0; + alias->retirement_latency_max =3D 0.0; + + if (!ret && pe && pe->retirement_latency_mean) { + ret =3D parse_double(pe->retirement_latency_mean, NULL, + &alias->retirement_latency_mean); + } + if (!ret && pe && pe->retirement_latency_min) { + ret =3D parse_double(pe->retirement_latency_min, NULL, + &alias->retirement_latency_min); + } + if (!ret && pe && pe->retirement_latency_max) { + ret =3D parse_double(pe->retirement_latency_max, NULL, + &alias->retirement_latency_max); + } + if (ret) + return ret; =20 ret =3D parse_events_terms(&alias->terms, val, val_fd); if (ret) { @@ -1678,6 +1719,9 @@ int perf_pmu__check_alias(struct perf_pmu *pmu, struc= t parse_events_terms *head_ info->unit =3D NULL; info->scale =3D 0.0; info->snapshot =3D false; + info->retirement_latency_mean =3D 0.0; + info->retirement_latency_min =3D 0.0; + info->retirement_latency_max =3D 0.0; =20 if (perf_pmu__is_hwmon(pmu)) { ret =3D hwmon_pmu__check_alias(head_terms, info, err); @@ -1711,6 +1755,10 @@ int perf_pmu__check_alias(struct perf_pmu *pmu, stru= ct parse_events_terms *head_ if (term->alternate_hw_config) *alternate_hw_config =3D term->val.num; =20 + info->retirement_latency_mean =3D alias->retirement_latency_mean; + info->retirement_latency_min =3D alias->retirement_latency_min; + info->retirement_latency_max =3D alias->retirement_latency_max; + list_del_init(&term->list); parse_events_term__delete(term); } diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index b93014cc3670..13dd3511f504 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -194,6 +194,9 @@ struct perf_pmu { struct perf_pmu_info { const char *unit; double scale; + double retirement_latency_mean; + double retirement_latency_min; + double retirement_latency_max; bool per_pkg; bool snapshot; }; --=20 2.49.0.504.g3bcea36a83-goog From nobody Fri Dec 19 14:27:09 2025 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7E1C7227EA8 for ; Mon, 7 Apr 2025 21:10:51 +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=1744060253; cv=none; b=fQfKIzlR39dS9C4JRy3Vom87iZRTOlKWMoeHXpOceHci0CnbXfV52Lf5EDRbU8KjAYx5i4akXjo9l4oot0j3LiLLCBQUR+4Af7iYm+HtfVSv6yofVDaiLKiOPGyoOqjiznJORoK0hUzOSleBwtS7RUYizgcxRM0yJjOjs4m99Cw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744060253; c=relaxed/simple; bh=4/dJlTWkcf5FOf5+oh0Up7fh8r5QO82sMonPjvpz42s=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=WKcGDWC03blFcw4OwoS0dnThrKBgZ7l+edfzxfbm0aKeadirGrCf4d/60+QleHIYlqYzJccPZuTBLQ2iX4RDF51WdkyvNqq1QHhMH8owezcGot74Xr6f7vfnIFOZzhRY6w3LLA/sDFs9Rqc860vmVA9gbYEzcQdyN4ucVQHcMUg= 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=k1xalQf+; 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="k1xalQf+" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-227ea16b03dso68118055ad.3 for ; Mon, 07 Apr 2025 14:10:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1744060251; x=1744665051; 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=k1xalQf+IohWxoOhqhCy3+DOLKylYi0MuPRj4O1Nu9cBMY/h/vfcNuHPdUB7p2Or+I YJGtkr2Qs+E+uYG4vCdmcIRXK0Em+F7KmIsgNcHKEj4O89xfI4Zl5eUweFcWTLpKgAXA QExPa2fwACRqtsiMrpEnYmKCcySMphE3XC5e2MjRKGwkWHQayNUd6u6htNuIgc8cwTEL ZWN8tHGFjRWpKktzOqcuskqq3EpswFrlfRRnMSA33Ns8IO1UMJ3nu48P5WHP9EtvO3Xi btnM3b9S1YkJtaj8p4gGw6X6jcgaZhJkif+plbhREOwRi6op1W4fs5eaWGBjGE/9zgMd SkWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744060251; x=1744665051; 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=E4JIAgyjOSimXAxd0nplm3WgnroV4Lu3R5CiqimQsEZoLjk408rM0z6Xw6LHR+RygZ YwyM6m6xB3YrzbElfm+BwJXBchLQ9DgAC4RRlT0aBPYQsXiqELvG3pD2f5Yrjqic8RNJ yKv6paQnzBv2ptec5uASwQSlaq+HmIiexwLSa1fAA7Bi4eOk6hwBWQMgqsIW8+mLbFT7 h3vsCtHUxpM0C1crt7AdUa1uT4JpcO5SrjouGuWT1ACsE2q7qIF661nFKPQQZ49DTRZQ /2wZ67yCQqVCmV34AMW2a8BIdheAuZ2JL9IGyIHS0dPJ+ohWuexPzz5OoRWIyPTuWP2R jfog== X-Forwarded-Encrypted: i=1; AJvYcCVkq+AgCb3d3nVvk0p5EcSnYzMlFIJNpeCVJqjcKLUMi1nD1vUOakqKPAKszpoI6uI8tH/1uKzVue+lSpU=@vger.kernel.org X-Gm-Message-State: AOJu0YzcpBBmMJUQuRRu0HV+ol9+GStS4kNENhJtDVPrDEAwQzGdhcg0 vw+CpdOprFnUPkA5xS6HTSKDZNqpM5IIL+dIAe9hixkb5IDtTmXgsZ2a46Azvy+9DPXKur/pNMX mgHdumA== X-Google-Smtp-Source: AGHT+IGqB05o89f/GZLTfHiKkNCXx4VfitNRXgR4OWmwniHUHrAOl4AGxryB83reY0YfENZ/8BQg9qCCsrJy X-Received: from plgy12.prod.google.com ([2002:a17:903:22cc:b0:223:49cb:8f99]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:d50e:b0:21f:85ee:f2df with SMTP id d9443c01a7336-22a8a05524fmr190586515ad.15.1744060250746; Mon, 07 Apr 2025 14:10:50 -0700 (PDT) Date: Mon, 7 Apr 2025 14:09:37 -0700 In-Reply-To: <20250407210937.131681-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: <20250407210937.131681-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.504.g3bcea36a83-goog Message-ID: <20250407210937.131681-17-irogers@google.com> Subject: [PATCH v3 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