From nobody Tue Dec 16 23:41:40 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 7590D1EE7B1 for ; Mon, 24 Mar 2025 22:34:59 +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=1742855701; cv=none; b=qMd7j98YWe5igCSy3dfXAHuh6ATFKcTs6S5m5IBx4F9vaSBqhiYYSX+AyvMJSTZOeTlb80tMFpeBYnpcXqR7DfdmSYhiv7LOy1dk6NnEW4+Ag4jpXnsFd0S8qz4pgznS17HD69vXCLKFJ+PVViwTXWKdqZV1aaf5RgOR1obG17Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742855701; c=relaxed/simple; bh=yBzhhPVypfmeolNblUD88KPAtlHzfIA0bxATlPMR4zg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=rA3syQVw7J82xPlaO1wkP1frs3ivGnNlVXmrmG2w0iI7S6ZYo+4RbhZLZQfOq26wiKkW+DkqskqhWdr0fM3jVHDcRw5Pe2R2iUUc7YPLPMBKakkWnJdxrkiFnA3kKs3WHUNx9m42XHu+JSNzN9PhAWlOHZ4Y7wVPtHa96wtX6s8= 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=ykaDy1Vh; 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="ykaDy1Vh" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-224192ff68bso74876925ad.1 for ; Mon, 24 Mar 2025 15:34:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1742855699; x=1743460499; 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=ElJ2vHXmu+8BFmjOSMBFYzJE6czzTLhTmjrbpJ1kYko=; b=ykaDy1VhbUZN5jwCY3X0ew5+6grU3HbZLlGeD7jID8qiN646gdjR9vb5gX++P2OUuI iNdIik32nOmpS5b3XCiiZGzKS71NcxZT5RNcgtvpJqPwaxTdeg075h9+B7clN9EKRxa4 WwCJriKxdI8zcgJAN2CVPrbnKnXPgfx+S1kr0bEQvnQJNhXx8qRsXcen+bXUvLJ8Tmds taQP8XS0gClI4fuo+9IF3BRp95R1tzjliFU8ZZl9CrMTMSiXNovB4wLqCcGZI8BIXakV pyerDqVeahoVwtaW06iZxyxuuamsDVz+JD4BhWn974s+EXTT3PkIAepwOgtsT6rPzJiF dgxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742855699; x=1743460499; 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=ElJ2vHXmu+8BFmjOSMBFYzJE6czzTLhTmjrbpJ1kYko=; b=dCcciMZOiqkriYMIGIXRVoGYoz3psijYWycxvc+QqTUDGzJ5Lt8p3WTU0n7GM/FQUd LW3Tz/EgIfXFN8KEzgcFvXURENw2HBjnbHckY7mDGn7ntQYU21hd9hYeEeUkFgWV4r0n rDK8KIDiJkMIbTWvTglTeHTDZn+mvexU5rFzShNk/Yi4Idm964pV8bYamQa94FVtaraC 6RDuYgJ4bQT0sR9mw6BCT6b2tgxiay5EggaRYDT7Z9fMCIC8dFCy9yiHA+zkuqm1SbeR vui6014iXT+48OrnP2qapK6nubRMp9YykRq5PsXPGsNdFUM7o6vNfYM1pke36VOlUp+Q vgZA== X-Forwarded-Encrypted: i=1; AJvYcCUAXHEKiR7csJ1r82p+GPd2JsrAI2ebP7N9SpaG3x4RGkTksAaA8LkTEv9jrvwbcvhI6FXhKS3yE+ZLoTw=@vger.kernel.org X-Gm-Message-State: AOJu0Yx7uV2/ix58xuWyxetkTqrSToyGrfjtoB3ZAh8YWq287sX6H9yC H8lhXmARZUJtCS+uhrbDAuwBd/CCRFt0QLA77PZLZs6Je7Wz+Zvzq5hHTCCsWIsjD/44B0JN4Qu AhqqOgQ== X-Google-Smtp-Source: AGHT+IEnNH3RKdFoCflDCnsGBhUKHdODz4nzYGEOJhKeyuWPq9Up7F1CddDsmGctnCkl6aL4xQ9/GS6elFAD X-Received: from pfun23.prod.google.com ([2002:a05:6a00:7d7:b0:736:a134:94ad]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:230e:b0:223:5645:8e26 with SMTP id d9443c01a7336-22780d7fb17mr179400475ad.20.1742855698710; Mon, 24 Mar 2025 15:34:58 -0700 (PDT) Date: Mon, 24 Mar 2025 15:34:39 -0700 In-Reply-To: <20250324223452.208081-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: <20250324223452.208081-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.395.g12beb8f557-goog Message-ID: <20250324223452.208081-2-irogers@google.com> Subject: [PATCH v1 01/14] 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 2c421b475b3b..fb28aa211a63 100644 --- a/tools/perf/util/intel-tpebs.c +++ b/tools/perf/util/intel-tpebs.c @@ -27,11 +27,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; @@ -82,16 +81,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) { @@ -109,10 +98,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; @@ -155,14 +144,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 @@ -188,12 +176,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; } @@ -218,7 +206,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)); @@ -283,10 +271,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; @@ -415,18 +404,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.395.g12beb8f557-goog From nobody Tue Dec 16 23:41:40 2025 Received: from mail-oa1-f73.google.com (mail-oa1-f73.google.com [209.85.160.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9D4761F03DA for ; Mon, 24 Mar 2025 22:35:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742855703; cv=none; b=YuT7Ve1vGNkPscKWt77kcgsw7yIoaTRUrq/xW9GKaxCqAR1Ctnz+DATTjgejAWXJfcOkcpWoXwogXtlDdFnpkP8wQg8WgU8ASksGxr7t6QtDYiyN9sjpJhmKE1F4k4KWMZ+gVZCUkh6Uu0fQw+Mo564wXF0cIWS9P5R+gWF5Ew4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742855703; c=relaxed/simple; bh=aQ94fNPaOZE6PYvgPCW5WSHPBQdQVUZq24pj9KnKwC0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=NbsruffHyVaKrS7clicYvtfzDRy7GCPtASYe73bGOK7MXb7dmGVGWrroJLwJg2wW6bvNB6iKeuibtHdFXTW4wOQ7g/dSD0WEVVAJTDGMZewqfTDdyDVH8ureYQiHF7dNEdjDI8zGIOmfYrM0YhXw0iZfDjepYKRcSRk9ERhvfPs= 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=SbkaN98r; arc=none smtp.client-ip=209.85.160.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="SbkaN98r" Received: by mail-oa1-f73.google.com with SMTP id 586e51a60fabf-2c23beea898so3255127fac.0 for ; Mon, 24 Mar 2025 15:35:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1742855701; x=1743460501; 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=ZY9q8axMcgGZoMAQk8YvUirygGOk3Mm/VWg06jUJcG8=; b=SbkaN98rslRAbA4JV0AazdZCuGNcnEIugMItbI5jWzrlkjHZt6Sxjlz5VN/GlB6Z2D VbUMaCkM+gElpnQ2ZwNfWzD4KZTFzurfq8FLrJz/997FZ8jygsdmOFwm+5WTst9Fdmrr doUvVJ5OmfNjQjO1O3m+nlTu9MP4MpW9wkPOZpfGJOzd44ZOB8mZJwxZPqZIrgm+Xj/i 0ZSdyDUUbxh5QnGltJGi4q923XJEagLbiYIIxIayBAzboPhrgZrqAJCbxri3N9ExAejx 3W0lHnjW5vBnWdLG0A7Ji9qx80b9mxgqijIElJKFdMWjd9meHyCHJXMYKHQgklyct3CO CwYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742855701; x=1743460501; 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=ZY9q8axMcgGZoMAQk8YvUirygGOk3Mm/VWg06jUJcG8=; b=RhSKWpmMDkiFuEEKwFi9jWtWHS3Py2Xv1OkH4EmDnXHeC9aFqJWfTzpukWpIdWNQg7 hndLN+ey0KLsw+6q2qkK6QXDaKFZSHkWKNo44xrmisC1JLoCp1qPBb692hm9P5MwuGhp QxKjCV3uWntIO5yVNV6PvcBxs/wLW+P0SmbVBeN6Y8kJCC1DogW1vzTUurYBc7yFtVQE aLbtUXpa0nP9AqyDF8EWMcxUFvKdCa4pZCRAIkhtvJX8HMZyzzylkwBHkDRqh70eNdJi 3EwpJgaZgj38wJtzDtiJa4Dxp24BscS1XqFiSWTADiwF9TPBfge6pmrfsO3/4oC6Of4J qB1Q== X-Forwarded-Encrypted: i=1; AJvYcCU1UXJWRpj1mbn0cvr0KV4NoAsAuV7COySJ8PO2/E1TCmt7QadTTNHKq73bT4fTkI2rhFXPg2ulSGmNAxs=@vger.kernel.org X-Gm-Message-State: AOJu0YxPog52sFNpZ/YvKxCDiIxqfo6aEjT5YRumpE5lHSnMVsz6FzP6 aXPpdWMD4rN8cNoUZoJnOmNR7+j4/HOFWdNbUsFF7LbaNKqUOej+yv/zojoaKd8EjPl1FXzNYzG Hys59hA== X-Google-Smtp-Source: AGHT+IHQY8KHThvchOZrihJb0/lyvXHFRemQHry7URlGvL+rdisr9TeUoaJpCLuUYjxiuiQ10J6XLEvR/aJh X-Received: from oacqc9.prod.google.com ([2002:a05:6871:e7c9:b0:2b8:4497:1ce5]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6871:1c2:b0:29d:c832:7ef6 with SMTP id 586e51a60fabf-2c78051a29bmr8800315fac.39.1742855700650; Mon, 24 Mar 2025 15:35:00 -0700 (PDT) Date: Mon, 24 Mar 2025 15:34:40 -0700 In-Reply-To: <20250324223452.208081-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: <20250324223452.208081-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.395.g12beb8f557-goog Message-ID: <20250324223452.208081-3-irogers@google.com> Subject: [PATCH v1 02/14] 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 | 7 +++---- 3 files changed, 20 insertions(+), 22 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 fb28aa211a63..2b2f4b28e8ef 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" @@ -188,18 +189,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 /* @@ -214,25 +213,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; @@ -246,7 +245,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 766b3fbd79f1..88d70bb37971 100644 --- a/tools/perf/util/intel-tpebs.h +++ b/tools/perf/util/intel-tpebs.h @@ -5,19 +5,18 @@ #ifndef INCLUDE__PERF_INTEL_TPEBS_H__ #define INCLUDE__PERF_INTEL_TPEBS_H__ =20 -#include "stat.h" -#include "evsel.h" +struct evsel; =20 #ifdef HAVE_ARCH_X86_64_SUPPORT =20 extern bool tpebs_recording; -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 #else =20 -static inline int tpebs_start(struct evlist *evsel_list __maybe_unused) +static inline int evsel__tpebs_open(struct evsel *evsel __maybe_unused) { return 0; } --=20 2.49.0.395.g12beb8f557-goog From nobody Tue Dec 16 23:41:40 2025 Received: from mail-oa1-f74.google.com (mail-oa1-f74.google.com [209.85.160.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8BEC71F0E2A for ; Mon, 24 Mar 2025 22:35:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742855705; cv=none; b=AVr2bSnUNkATOD8AFGNSI3dmOhBjwlDzY/ApiIlqB016m8Ql86vr7owAjl9ALEePHQJAIc7wnj2iMxgMXEPdfkZQJ9aRBMe8bA2THilGwL3cD4WHEqeW39xG5ogQYfBrSa0C1yoGilrXj/Zpi3wxibnVhGMXDFqDTzEsiW7fHB0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742855705; c=relaxed/simple; bh=/B7cAvSrRfNXbB5b3SzCIR4ejZKLzspf1N2+U2b5jiY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=Ii2EzI/hbo9rEeb2W5YosFdr/05Ma8oXZN+03/xdFTMqc53oLw2g0ayRYdvjRpPfU253HDpeZmOIHAioKGFZLrCbcudqt7O6aLp7//mVK+bDBDds08fSpfopXVNpRA8mo9a5CUfVS5y4KlDNAZqlpM9G6GiMOxUWgTEb6YGhk+o= 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=IOUuK1Up; arc=none smtp.client-ip=209.85.160.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="IOUuK1Up" Received: by mail-oa1-f74.google.com with SMTP id 586e51a60fabf-2c70bdbbb1bso3943491fac.3 for ; Mon, 24 Mar 2025 15:35:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1742855702; x=1743460502; 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=22SmbJgPWD6WV+8wjcChVtc8LFfVPThDvnKhbyYVaoQ=; b=IOUuK1Up9/FB/KKlL/hGxjRX9JLZzFyQ8pOO1cFU5hpwCgxogKqYuQKwob2huvglGU Jb/kNnhvTMRgNMCDieWE5NgXVRCc2ZutzJpI9JR16aqE4A4vi6NNHcLEcDvf8QhxUEsW suNFQ88jSXW6+NKz0d+0oEeNA2e1ZfKaQYqpmuBxFpGtQyvp3F8iI8FCSVjhfmtHICUz tjI7RCK2MqNGun1xwbENZPyr7DY3HzpX9U6Vbw8LnHN1AIXIh82wBk0vPGNjFuL2xUMH A9eI8YgUlgpsdwLFhleZE0xqIVaGcLt8ifDKpMU3FJUYLNllh4bqO2w3BkXhU0JruJhL vHMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742855702; x=1743460502; 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=22SmbJgPWD6WV+8wjcChVtc8LFfVPThDvnKhbyYVaoQ=; b=aYV3QJ2Qpny+TNMzDOiSkulqRWTWLGE+Q/T6j8H6C3hUinpVCOsOzIWCYQLGul4G5P g7kMlGTofijIVw4Y+sgoghAJrtFtVubQDVwpvxmjOZyt9uwoIo1AqYEAw84qL4ynWQNr OcKx7w7pYJMAD85wmPiA0pL//kUp8fPv08Di78fHm+AnKD4pGW6rGxYItfG0JIAO5Ko3 FvO5//R68Pnz0d+VY5YO5MrbGCxcR6PUoErvIhkiwWWA6qtpa+vAprpEzYl/nyxnenVh reJJ8P7B+ZODJcjbB5/CBVSTkC4Q0Pa7E4CipGbXuaAmB4uGcYlH3w15gD6qZxsrtKnC RZ0A== X-Forwarded-Encrypted: i=1; AJvYcCVsCo/QiPNjiF1QM7fQsdEnJqvh12oTp/lJbweX2nPdY6mTsJWh8GDKSk1DLpTNmEh0cDarfcXU3W0vV7Q=@vger.kernel.org X-Gm-Message-State: AOJu0YzK9yLw1GaORFqrL0LOjRpOEiN6U8RzQHwWEUhelMQ9b2l1805w otb/dEL7xywV4qU62kH5M6RcQWrjfpL2u43fMUm2TkW7iChjzJm7RF5xwPiU3mLueysnLRDq05y xGX4Zrw== X-Google-Smtp-Source: AGHT+IFOVJXVRtCGs0SgsEjxtHiADU1/akT31/WAh+aLJp4gwRJS1cn3i/NzT/QM8DFuam9wWbBlVfvwjFds X-Received: from oabpu4.prod.google.com ([2002:a05:6870:9e84:b0:2b8:1fa:4ac5]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6871:2313:b0:2c1:ade0:26a0 with SMTP id 586e51a60fabf-2c7802cfa69mr9471444fac.10.1742855702718; Mon, 24 Mar 2025 15:35:02 -0700 (PDT) Date: Mon, 24 Mar 2025 15:34:41 -0700 In-Reply-To: <20250324223452.208081-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: <20250324223452.208081-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.395.g12beb8f557-goog Message-ID: <20250324223452.208081-4-irogers@google.com> Subject: [PATCH v1 03/14] 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 2b2f4b28e8ef..e218e435c1d7 100644 --- a/tools/perf/util/intel-tpebs.c +++ b/tools/perf/util/intel-tpebs.c @@ -36,7 +36,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 */ @@ -189,6 +189,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 @@ -196,10 +272,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. @@ -208,49 +281,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]; @@ -267,6 +304,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; @@ -320,7 +360,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.395.g12beb8f557-goog From nobody Tue Dec 16 23:41:40 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 690941F12F3 for ; Mon, 24 Mar 2025 22:35:05 +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=1742855706; cv=none; b=ZfdjgZzt1TAEhQ/aOP6IcoyLFVu91c2KqJObhA2Un4cwQ+4UYFagpYxi9giw4XXvAt9Z8irqE/5PHxJjdR6wVGVOnA/ZA6xnfx/UufiTrn2qjpdSAFSo3gzMYDkCyU8jgtTzEdVBMhACo4zRU+DT7IP2ecmpm2IZeA6oMdn4N+I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742855706; c=relaxed/simple; bh=0PuLW2FPtefhiw76QU+wIv2pk1vi0X0kvqP1oszrRx4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=pU3U+qNjTdOppY+Tc/IhC8ZdMgnEqhTYP1SAtsV5OAOcqUMLBN67/LK0In883JEGtyT1ostmnQ94xlaIbHh1ofSAWXi7Ib5M/wNAnxuYeAKuzKp+UrcxVYR4nnvGRharDOnM7yhRSUvVF1iyU9Y83F7Efj8mgp+MAjGgeIuQqUo= 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=n2KvQnzQ; 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="n2KvQnzQ" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-2fec3e38c2dso13138634a91.2 for ; Mon, 24 Mar 2025 15:35:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1742855705; x=1743460505; 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=ShE09qRnaQIhfbh3jWHOYmVGf4wtxAeWzaDmf4WjLjo=; b=n2KvQnzQRElU9iRFYE3xFMLrTo4RgG+egkII90syM+zeeBXBiAoPU0778aH87YAxCS 1WpaQRNaU0gWQc+xvyv6aQpmBCyTDT8+7TXOCxRUA7fWjUtc0eIvdZqa0AJadDIXQdfr hJ/d7VWnINk5PNI3D8Ll/rd95uZfCryq60V9eVcTUwIDnSP9Xr9JpfwmbrJLRTzcZ3+C eLCch8YDiFsUfFkT8W3EUCRf+MZRdELUW+8x+/H8zy1HIH/SaDQFqJYYtsromcufITEv IIGK/abMQKBA5sBk2aEPcSG8PxwbDf5Qp2zPPEDOgYD0tDE4kNKmHfujl0VOoRRn0eMK WYpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742855705; x=1743460505; 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=ShE09qRnaQIhfbh3jWHOYmVGf4wtxAeWzaDmf4WjLjo=; b=wT3vczGbNXxXhRBPfBYP2m5GrFx5QIeyvjnezNq4WQY96z1/uhlnFCAYS4g8rY7CX7 HbhkH+P/0OVVxjAWk2h2soRYW51xRYLtOSrj0zJzfjcWcEGn38Ln49MUHbhoD149Hkk8 +8rE/Lm4YeSTYRHAVr3+2HEe8S/JfWb9nRQqICmhjlOSFSd3ITfILzmE5rDvJVWVD1QF A55LBMh4Vgml0bMcQNQ8qiW/XBcUNJq50Yr2bhjU5xV6NzkbneodJS25txs4KiHI4I0m zkuJog7lEIJlMCEFKUqeYiIpEqjOUzRDRQrJwxAJRDMIJUzfMcDIKroICLHcpsXh7nZt 8dDA== X-Forwarded-Encrypted: i=1; AJvYcCV5SLF1Qd3eMP0mlJcmt2eKuLsJZ2WwiaDSnVjNcynmPLUvvn6t4bjzYECdWkNM4DEj5ILvldwKtsBirAg=@vger.kernel.org X-Gm-Message-State: AOJu0Yw8CyRjTt+X37QkPT5BtqIGxeJcHwLeHggywlUVuY7he+UN8SBV m3a3qkamvKusBa7+DfvV0QbAg3rEoZHN3aJZMVuLx3A5scT1AlCKsBUyB/mVEo5V9VMoVHMuMme dfhwcxA== X-Google-Smtp-Source: AGHT+IGBJPlRZuMF/hNE2Ag6zo6DkH258TkFOSESeENLzqeDl5XLLkCm8BnoBOyMKFz6tnfDo0FI8glEBxUN X-Received: from pfhq19.prod.google.com ([2002:a62:e113:0:b0:730:90b2:dab]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:748f:b0:1f5:a3e8:64c8 with SMTP id adf61e73a8af0-1fe43435c04mr28981137637.36.1742855704576; Mon, 24 Mar 2025 15:35:04 -0700 (PDT) Date: Mon, 24 Mar 2025 15:34:42 -0700 In-Reply-To: <20250324223452.208081-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: <20250324223452.208081-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.395.g12beb8f557-goog Message-ID: <20250324223452.208081-5-irogers@google.com> Subject: [PATCH v1 04/14] 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 e218e435c1d7..13d70c6bd44b 100644 --- a/tools/perf/util/intel-tpebs.c +++ b/tools/perf/util/intel-tpebs.c @@ -82,12 +82,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 @@ -286,8 +289,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]; @@ -304,10 +305,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.395.g12beb8f557-goog From nobody Tue Dec 16 23:41:40 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 C308F1F1931 for ; Mon, 24 Mar 2025 22:35:07 +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=1742855709; cv=none; b=Mwmjcl/9bDAZ+rCBdkAlaU/QuByjLoZqMygPEceZD/GknpEfxA5NtMs0498KdasWH5n1FSICzWvRhORMsauwYu5ZwuClnxSgtWH9aOQ0WLq5dlKFBTZHrQzvN3/ng4a2QhbxGGzXfld+B9IYXpryEZVdS8WeFeiNs4yok4jzIAw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742855709; c=relaxed/simple; bh=ie26b2RyksuReoq3CaWAWU5urfeVKfBweu+iRLyCrp4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=Wn8gdLTWuEfP0urHkIbucpOcSl4Ynp3pXH+cOIKhyFFCaTStkapbUKeLqxs/BQnci9uvQEbJ3J/Orl4Cg72rem6SSlKStN7M+1cU0Fe+XRjrkhLw2NfFI6pu+FWa3jio+91JtLHLJz+UtsDVQJqH4JGqifgyDkSgt8M+MvRq08s= 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=goyuoU6/; 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="goyuoU6/" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-300fefb8e05so6277382a91.3 for ; Mon, 24 Mar 2025 15:35:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1742855707; x=1743460507; 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=2UQH7oGCzJ0WNTA83Vjhjs3RZyEx+gk9Fkp49zJCF0U=; b=goyuoU6/LuDHXoHYtsRTTajw4+JsrWyok+bL8EOgV166PakhdydURwGgyZ+6qUDs77 GTY5Otdl2ep24wmcq1bKofEEo5WSalAu6uCEyirqUAYKdFep/vYH0ThGWBAHCl1WGl3W /9Z6f8pN5CrJJrK74zsiFfZmkzdX3GuPOMoUkQdOXtxXxIo7N64TOFml5Q25eNJn97zv G69t/Tocix7Tw4g6IUAs1YebeEzaFHvENKpfyQ0PJob07JjJz9CY/XVdulsCFU9friV5 1+Qe+uxP8HHqUqG/RPnX0/18lwPFofxuXyHmRulhrc3mEbCwbOTWDTVPgOE1jQ0bWlVi ZIqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742855707; x=1743460507; 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=2UQH7oGCzJ0WNTA83Vjhjs3RZyEx+gk9Fkp49zJCF0U=; b=msnvgiC2XVos0puESb4v2hi4fr68M4HRc6y+HTWFpeTi4qyZATQSIHw1Ww+iBeZOcA IcAn2+hF1gKOsjlVA44EtTujCLwAG+kOVDKk2toYuwLtzfyJHmsqbkThes+IKX3b/KEZ NvnThUh+5E4oDzXFW+4bmgC4lPzM4tzFpMpqVjMmNxil0ahEk4IA6HSjsSYQae0L4u9W MTYsiUL+e8M+EtitVeUyM/pRsdikkz6D+zDwaR6bOw59OhC6o/25xuo+yu0RjQfIZgn0 /gFP04jaGMWxWG1HpU6JMTUoXqc2yclRRZiUrmyXr7QiF7udZqZbvnh5gpB4+WcEuZzG 9nHg== X-Forwarded-Encrypted: i=1; AJvYcCWme5Bh6sEKwCaDHHS+aWzrVdfYG/K+ClTg+gSD2Jz4OFa0QvCnyHaeqpClLxYkcjKSTjslaqwWhQJ0Kes=@vger.kernel.org X-Gm-Message-State: AOJu0YwD3v4Nnb7oFw8pEU9SVaR/jouZB9kn1RaUC5vl5/uNx7uSCThs PstFaQeq+nqAerOjnoVohSnQIsEeY60w0LhgxVKp0BWvxy8y04rU42DvWcGPhOnAByQIjTwyP31 RNGkM0A== X-Google-Smtp-Source: AGHT+IGFLKGJaI5bECm8GfE6E/ktNhg/Uw8ybtyoGREwW3ADT2dnJDRNCo4vlwbZHy3oU/U1f9nA6LgLIxMV X-Received: from pgjh4.prod.google.com ([2002:a63:df44:0:b0:af5:91a1:e217]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:7116:b0:1f5:9961:c40 with SMTP id adf61e73a8af0-1fe42f26554mr25357292637.8.1742855706986; Mon, 24 Mar 2025 15:35:06 -0700 (PDT) Date: Mon, 24 Mar 2025 15:34:43 -0700 In-Reply-To: <20250324223452.208081-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: <20250324223452.208081-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.395.g12beb8f557-goog Message-ID: <20250324223452.208081-6-irogers@google.com> Subject: [PATCH v1 05/14] 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 13d70c6bd44b..e5ca58599b5f 100644 --- a/tools/perf/util/intel-tpebs.c +++ b/tools/perf/util/intel-tpebs.c @@ -28,7 +28,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; @@ -85,15 +84,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; @@ -225,7 +229,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 @@ -288,7 +291,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.395.g12beb8f557-goog From nobody Tue Dec 16 23:41:40 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 9C0511F30D1 for ; Mon, 24 Mar 2025 22:35:09 +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=1742855712; cv=none; b=LNWDfpnfb10++9Q5TdDGLWrhj6Ev7H+J+OBCWQFJRkszOn1GLcIr+/0HojTfHR8lL6A/9eE2ZzMl6jBebnfZ73/TRi0RqpCOvLJr8f8gtD15Idmb+k5tiICdyqop/BqURFN8swRpPSZsoXYMa/ijtjuZQFc2LabQsnGCs340plE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742855712; c=relaxed/simple; bh=jq5PjJ/ugYrx4xcRpoE6fLhSyd7TK8mfub7jd04bhO0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=UNcfTTCUWuhxaBQAN65GOXwtXZg7Q/EcVuDc1p3e+zzJt/xPUnliGKMFCR/TMIzr7R6COnQdKUV883WSFw7Ye+SEPrNCUPj7p7ak4ZYqvZsxKGbjZyYCuhzZntgpEIDoKdVOS08OSZJ5RlqiI00Avxeir59rhzCrmX6VRxxEmqE= 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=STSKn9zx; 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="STSKn9zx" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-225505d1ca5so77962735ad.2 for ; Mon, 24 Mar 2025 15:35:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1742855709; x=1743460509; 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=Hi9qV/98s3GAaLJGCI97xHdsmqnmvPcBtjZEurAgWmA=; b=STSKn9zx6+srrxS9qyjWdUA0eBvYKEvCd8GOYBRTp/d/v/gVi3lj7xAK1UaZo7Jrq3 YnmWdwTsaBq0xDA2+hJ4o4i2Kjt9iqC2ETNadjwLrsDDTSHU8wSud42r3Z4Cc59rNzjB mJHUlmayxvP9wwSaahj1FjW6mXD6A3TWVP20xF1kC+zWMhpKbZyesk5bFSbMh2SbnuPf 0b3E/7lLUmZuolVUmAxNJHfUyFYjPORT2QbSutBIt1gbJ2ljnVKz9fUNKlK/A2JhCJC5 P+DxTo99NZXOlVcw8Zp88CS2iimY4ZX44neE3XgFq3lkRNUaVi+7ReFosF/EOKfyjVBO rbRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742855709; x=1743460509; 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=Hi9qV/98s3GAaLJGCI97xHdsmqnmvPcBtjZEurAgWmA=; b=u1yG88XamMXtDzQmz0IcYWFskLNuOm5V7zyEcWqkto1u5j2cCIo+vv55w4Jq6ciML8 o6zC4fPuFZlvv5U+7CB9RihnvL9NdhFQQ959DzwVBM/dHYXpiQKwgr66JZ27HFwt3nQ8 96Ar9NiwvHpVBt1zIIdnGQxEpHREbXHGcnVQV6grtGUcG9eQIG6mM6oW7zJPS7p2kG8i Ccms9f8G2GvbKqr7wWXp8vkiBQ4UL2t3GBOQgF8+/b/rWzopyM0KvABJXBzFBDspix8u G0tax1WDna90QPxRIHIghTzlTq/4pA1TlKsx667x0K875hHmWIflNRJBVoFflBraegJT C4rQ== X-Forwarded-Encrypted: i=1; AJvYcCWWKjhC4TpkQKwxYgzPyEFTSG7rAWNYKrvTD7Ki3EtzPjgdAlALpj42vEsDMsMq0ppvEJl+9tN6BrSz4WM=@vger.kernel.org X-Gm-Message-State: AOJu0Yy0wU8RJd1huK0UXzQ046PWz1GQaemTTmHD5tCE5rokSbmMpUZB SorBjsib43SgwiippvqCs3+o/voq9GoSARQQ41/BU+DnAxsMnooJDzFqySk+xNoKYRpFUT0KJ3m pQS3x3w== X-Google-Smtp-Source: AGHT+IGFxmafsPpLyD17+00wez3sX1EFe8IKkFijnkrwpG/ZYSYE6tSXfbTvjzfIcsV17fEt155JaIjS1hm6 X-Received: from pgbdo14.prod.google.com ([2002:a05:6a02:e8e:b0:af2:48c3:360f]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:3d84:b0:1f5:7f2e:5c3c with SMTP id adf61e73a8af0-1fe42f0920bmr20802083637.1.1742855708807; Mon, 24 Mar 2025 15:35:08 -0700 (PDT) Date: Mon, 24 Mar 2025 15:34:44 -0700 In-Reply-To: <20250324223452.208081-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: <20250324223452.208081-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.395.g12beb8f557-goog Message-ID: <20250324223452.208081-7-irogers@google.com> Subject: [PATCH v1 06/14] 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 e5ca58599b5f..3141b7d2e94f 100644 --- a/tools/perf/util/intel-tpebs.c +++ b/tools/perf/util/intel-tpebs.c @@ -46,72 +46,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.395.g12beb8f557-goog From nobody Tue Dec 16 23:41:40 2025 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 753CF1F37DA for ; Mon, 24 Mar 2025 22:35:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742855713; cv=none; b=SoqOLJUAzp4HZhIehrroU9uNi9653G+3GfxIIkbJOUcfWBek5l2nnJG6VsR/5IvxBKm8DU44bghEkh0HON7VuPFWflojrW1dBthmkqDaGZLMblSemwlzOfZa7y+4prGVusKMFPPF1nVL78D3ZdR7HYycMEhy38yeRIDb66l0DiE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742855713; c=relaxed/simple; bh=Lpq4G5yo+Ga+DGva72uN3LJa5rLWCEW0itHD5ZQBGxk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=qtWC0L2ov3WX4MUQgITz1c3WVkv2rMC11Dtm1XdnBvsdbvRHZ8A331JX6OpzX8f5HC7FVz7WO53UWQypqJw6MXm76bF7V3UWfpmTFFLRd3OJms9E3917KE2g92gpI57cwrtV6ik5QmYCW3vSTG2YXQuTdMv8fUxYrlZqrBTU1rk= 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=JlWP3DU/; arc=none smtp.client-ip=209.85.216.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="JlWP3DU/" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-2ff53a4754aso13732583a91.2 for ; Mon, 24 Mar 2025 15:35:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1742855711; x=1743460511; 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=JOA/OGGxNBcRColJQpK6PG8JVFiW2q78VM7qIIThxrQ=; b=JlWP3DU/4TBTHmgb9h7R5jiTk64DLMA6rMPwa6o22Ku+h6gfP+gvHKgB6druXu62XF O+EdiYdEDvvOwOXoFDB+e4U5Cubzxc3AF8NTdEpxZSfvH6JrLs8zHhpoqN02oF0gBmah tZ2HV54oevgWYo1fFU+CK4pRfUKZ7hhKe3mUIZgnc0EKSgL1eWaiS6Bxd89tgfORluJm CzNVbO81GhFiRxK5qqgIazxvk28KYGr8xKiBOyZZpaEuNJAW9H3l8VVoGGnZUJf5DKNo YXUXa/DR19fWFw5vle+i6kA/w5pDLthshC1X22kXmrjwaVdDHmFnlZlynNl2Evy0XHlJ ng0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742855711; x=1743460511; 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=JOA/OGGxNBcRColJQpK6PG8JVFiW2q78VM7qIIThxrQ=; b=Imfk07CtIm3e7wQELs+oAL43qdrWIC5X5eEeRFQ7JvbstYhzgf6t3ddPtPm7ZpBYHc IPjNv1SaYX2kjvuZY5eXtLhezMYm8QWkUcLj/i+JYsrOHyGqDIJJeebAX6E+FgsWMh10 xE0lZHccGTikpwpeQ6kz58xnG1P/VPPdkepmqtxlPTz7K5w4awjlIJ5tEj3O4u5bnYS/ bZGbEo9q0Qfap017MEtd4tV0IGkWqhrV7V6s5wmdAqQz+MwqiQfD+fAS7yo9hghEmFva ZRzXxNEfaxYcWqLM7YT/kPe3WF8uxxh7oTTtqNAcRrSMZq8y+MSsqxrwcTXcy4AiHxEN LcEA== X-Forwarded-Encrypted: i=1; AJvYcCUGYtrAL6hbq7sqW0UIn8/M+iJGudwe1+QTb/vCuzdW+kNOhanOrjptoUWfbYggoesu49DnnQ/EFMZ6gNM=@vger.kernel.org X-Gm-Message-State: AOJu0YwoF6wKBkqW3P2zlfwPdYn8EXo7LT4wn8Z7+sXIevlpN5cg8ClF aA2h6N3pQvBZwiG0brPw0BUzM55m4sL/HVTuecwsdK4Tw2FRsmFqAE3+C578rDLy4DkZ7RA5BN7 JSVQlSg== X-Google-Smtp-Source: AGHT+IGIqJJ2nEjL+FUKqko6r9rKHylvKIdqkCyeFkdN0iwjG9G8AupV+mWrnGgRrnDhqwCmYkw7fzWmhBRZ X-Received: from pfbcq25.prod.google.com ([2002:a05:6a00:3319:b0:732:51fc:618f]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:7889:b0:1f5:8153:9407 with SMTP id adf61e73a8af0-1fe42f996a9mr23579460637.20.1742855710813; Mon, 24 Mar 2025 15:35:10 -0700 (PDT) Date: Mon, 24 Mar 2025 15:34:45 -0700 In-Reply-To: <20250324223452.208081-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: <20250324223452.208081-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.395.g12beb8f557-goog Message-ID: <20250324223452.208081-8-irogers@google.com> Subject: [PATCH v1 07/14] 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 3141b7d2e94f..9116cdc6981e 100644 --- a/tools/perf/util/intel-tpebs.c +++ b/tools/perf/util/intel-tpebs.c @@ -44,6 +44,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[]) @@ -93,6 +95,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 @@ -213,6 +218,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. @@ -220,16 +238,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) @@ -261,12 +274,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) @@ -351,7 +371,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 @@ -366,19 +385,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.395.g12beb8f557-goog From nobody Tue Dec 16 23:41:40 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 6A37A1F3BA8 for ; Mon, 24 Mar 2025 22:35:13 +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=1742855715; cv=none; b=Rl5tN84aPn+5AEkV3gipdMp56GZNHosngMlfHIVGFss7gOB70yVb6D/zx5ZHHKN7g07TEzsPBaihJrAWmYzS1DeJgiBPujWdEkXRze2bRUUMqYKq9G5i+5Sipq+w1RFkop19TvW60n/G1m/stNjFHzepw8XdlI6B1DFxt0RMYQI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742855715; c=relaxed/simple; bh=NOwsl0wEuL5koR3NXHep7k7Xz0LqWmUdBTPVtZ/ePi4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=NnXr8Tfqg0z70vzX0oc0pwimPaQIE5O3xPDDZzaYfxxfgW5cUjT2Ik7eAs2sMnG/k7B83q5mQqJuKB0r7EML3wRn7fRpzGf7nQ8W5mHYAZ2IA5DsKt5kAt7EmlFujoalPYEiHvTOwQ4Qvr/HoW6wEV/HylDF32ic9Eyia0DZ0Rs= 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=Q7VTGG4b; 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="Q7VTGG4b" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-22647ff3cf5so69297965ad.0 for ; Mon, 24 Mar 2025 15:35:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1742855713; x=1743460513; 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=xG9Nmmv36pxRcjjEqaCPf9FJZsaOcmEhpQ4zx8j/rkI=; b=Q7VTGG4bNM1ImOXBVkZvdFX4F4gUmNDX1777FSNDRaAdKHshQSnEf/Y+4RgwgcqWi6 i1xy4LEvaMzYQjOn9YMzZb4VRySx4FmnT5CsOop7z3AhFZEOrhRyY4N9wFRoRT+boi2D Q+uuliqDoFQQstXCY7pQGPb+mFmKTvxq9r3aAgq/Smci6+gwmmzkKeLrMoO99x4w8erk 702yFgJA6vCSGTGWVj3s6PIxUesqaAR2EQty//kZuzUdCShwX6cURcUUHM3pR4wMby3D fLfDPbIpBkbOBLMoH/khBp6xMcn5rLkzc+uT64x1RbTGs/yCvM0ddzrf/D0uV/h9Ma/d OWUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742855713; x=1743460513; 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=xG9Nmmv36pxRcjjEqaCPf9FJZsaOcmEhpQ4zx8j/rkI=; b=PK7VHvIK7jK/WAWor12zxbhKBUDBehRdeY1yasLmRr8lDp8FOdDSO+4uvBM7sEjILI z6pjYcebRWCofBa274Ea/W78gP0x8FU4IdqZku9eL8vXVVDItcJwIBDr+g0m5YKHIDzN DctGz8g6DBXCsU00gnLJlX/Cws4jibwyfMfaA158s/M6LN/nV6LpixRhFVWhxLXFknhs iMPKy89u0yQZupneQ3D/a4W3Ngp4mXbDUdcyUgVLu6Png5LWApFwHKVGqx/G4c3U+49G z37aLVPkQYvMl/G7+fqQYsSP1yT5lGvwSeg7ujKCo1KYNJUZqYgsRFjEDyeAamuhQ0sR P60A== X-Forwarded-Encrypted: i=1; AJvYcCUFo9h2wGy4X6uacxYFdQlahFuzmCmGUAvfGohvNbf8LjxQKU6eaPRio6LH9+5jLGY36qyTb+ZYToYOLIQ=@vger.kernel.org X-Gm-Message-State: AOJu0YxNzq4WFG5+cshI1nHtUYNZfnNVyVOmgl4J8fMnNBmdSQVUHEeE 9NZY/08dH2k/I4Lt3AhuU5GCTMYJJwFMZW+U6FW630R76ouJaztZwsP94Q1IjPlA4qzU4jOWLpl U+P3V2w== X-Google-Smtp-Source: AGHT+IEF9FZXzvHy0V0vOJKqofApvJzXbXsG6N9/WfJN4q/K2ePlAkMljkL6PeMHdQ9rJKW/Yt82ONv5kZRR X-Received: from pffk14.prod.google.com ([2002:aa7:88ce:0:b0:730:8e17:ed13]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:ce82:b0:223:525b:2a7 with SMTP id d9443c01a7336-22780d7c73bmr200774775ad.15.1742855712732; Mon, 24 Mar 2025 15:35:12 -0700 (PDT) Date: Mon, 24 Mar 2025 15:34:46 -0700 In-Reply-To: <20250324223452.208081-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: <20250324223452.208081-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.395.g12beb8f557-goog Message-ID: <20250324223452.208081-9-irogers@google.com> Subject: [PATCH v1 08/14] 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 | 147 ++++++++++++++++++++-------------- tools/perf/util/intel-tpebs.h | 4 +- 5 files changed, 90 insertions(+), 66 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 9116cdc6981e..500c472f7059 100644 --- a/tools/perf/util/intel-tpebs.c +++ b/tools/perf/util/intel-tpebs.c @@ -34,10 +34,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 */ @@ -48,6 +48,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; @@ -84,7 +86,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); @@ -107,27 +109,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, @@ -182,50 +177,93 @@ static int tpebs_stop(void) return ret; } =20 -static char *evsel__tpebs_name(struct evsel *evsel) +/** + * evsel__tpebs_event() - Create string event encoding to pass to `perf re= cord`. + */ +static int evsel__tpebs_event(struct evsel *evsel, char **event) { char *name, *modifier; + int ret; =20 name =3D strdup(evsel->name); - if (!name) - return NULL; + if (!*name) + return -ENOMEM; =20 modifier =3D strrchr(name, 'R'); if (!modifier) { - pr_err("Tpebs event missing modifier '%s'\n", name); - free(name); - return NULL; + ret =3D -EINVAL; + goto out; } - *modifier =3D 'p'; - return name; + modifier =3D strchr(name, ':'); + if (!modifier) + modifier =3D strrchr(name, '/'); + if (!modifier) { + ret =3D -EINVAL; + goto out; + } + *modifier =3D '\0'; + if (asprintf(event, "%s/name=3Dtpebs_event_%p/%s", name, evsel, modifier = + 1) > 0) + ret =3D 0; + else + ret =3D -ENOMEM; +out: + if (ret) + pr_err("Tpebs event modifier broken '%s'\n", evsel->name); + free(name); + return ret; } =20 static struct tpebs_retire_lat *tpebs_retire_lat__new(struct evsel *evsel) { struct tpebs_retire_lat *result =3D zalloc(sizeof(*result)); + int ret; =20 if (!result) return NULL; =20 - result->tpebs_name =3D evsel->name; - result->name =3D evsel__tpebs_name(evsel); - if (!result->name) { + ret =3D evsel__tpebs_event(evsel, &result->event); + if (ret) { free(result); return NULL; } + result->evsel =3D evsel; list_add_tail(&result->nd, &tpebs_results); return result; } =20 +static void tpebs_retire_lat__delete(struct tpebs_retire_lat *r) +{ + zfree(&r->event); + free(r); +} + static struct tpebs_retire_lat *tpebs_retire_lat__find(struct evsel *evsel) { struct tpebs_retire_lat *t; + uint64_t num; =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; + } + assert(!strncmp(evsel->name, "tpebs_event_", 12)); + 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; @@ -362,8 +400,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 @@ -413,34 +455,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 88d70bb37971..6ff92f5de9b4 100644 --- a/tools/perf/util/intel-tpebs.h +++ b/tools/perf/util/intel-tpebs.h @@ -11,7 +11,7 @@ struct evsel; =20 extern bool tpebs_recording; 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 #else @@ -21,7 +21,7 @@ static inline int evsel__tpebs_open(struct evsel *evsel _= _maybe_unused) return 0; } =20 -static inline void tpebs_delete(void) {}; +static inline void evsel__tpebs_close(struct evsel *evsed __maybe_unused) = {}; =20 static inline int tpebs_set_evsel(struct evsel *evsel __maybe_unused, int cpu_map_idx __maybe_unused, --=20 2.49.0.395.g12beb8f557-goog From nobody Tue Dec 16 23:41:40 2025 Received: from mail-oo1-f73.google.com (mail-oo1-f73.google.com [209.85.161.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A218A1F3FC8 for ; Mon, 24 Mar 2025 22:35:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742855717; cv=none; b=Sgtty9gr40TcH6raeqtJy+60EuxHFm2YFL8a1vwjmSUQuYn1mXJqTbWInDdQJooUv4CVU5Jm5uW61k8UzuPYCpISko/O4bFaY0Wf7nlmcdgKx9ZpvO/UgPlKfkJyTkKX36/9z3DW+79qjOohAy2zYJWJcra8kmvDH9zb+addqHY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742855717; c=relaxed/simple; bh=rIoxBTutYw9EVXlG55qzB96t9LkfdQ51B8mxe3NCbFY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=XeWtl+OlSWJyMu8QseL+3/q1MYdUdSNktiq5HT6A/dzjZK5yoiPtdxMKoFDBkTqvWQ/E1w+I4qFvI2tN+kXZHuQZmiB2v7enLIin3UWddHzFCwuXK9L1q7248w8EW3ioE4KWuKMSguFyUi7as9/5RfrYFWe1yhPnlXKcUuBLmyU= 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=dH/R2PeI; arc=none smtp.client-ip=209.85.161.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="dH/R2PeI" Received: by mail-oo1-f73.google.com with SMTP id 006d021491bc7-601f0dc8663so3779754eaf.0 for ; Mon, 24 Mar 2025 15:35:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1742855714; x=1743460514; 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=82mQ+1IXaR2VMHbas+zrTy9HH/vkv5hKIyVlatfq+jQ=; b=dH/R2PeI5smgBy7GOpN11paUmyt3Dxpp0mwElC2ebseOtVoFOnypII2KPj3DMNHJ34 ng10bWHYKMPjQ/NBYeWCXT0P72edwkgzXGJLGqDnIkdzNuJ3cje1k82/LKVZLEZxAH2n DX/zDL5V5mhDxyn5mqond+Y3QliIq173URiXNS5jeT+TvBpeluOJFMOtJGTx8FQHlUx7 YVvWiiZQj8CW3C308iF5YRtSu8sS3laP32ss8u5Puzg/oiZeRDBvDPdQezZ2tpHHctZD lny/m5Q546KLC1m6ZvqvZ/3T/JucnusaYXUeleVWn9SBX/BCwFAfKHwmaMrEvj0Pm6OC zElg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742855714; x=1743460514; 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=82mQ+1IXaR2VMHbas+zrTy9HH/vkv5hKIyVlatfq+jQ=; b=hx8LpPphKYaoUlNsO6DgClhCGXGWinqt0uUENbSwmuuwDAomsK0KWsRBos2pjxwoDZ XemIX368Nz5lIhrjwFC5m0DaoqHbd0SgZyKhE/qG61/Xm9/cGUOwbtaKNKXeuMqjAAjU G6VFTun+xY5HsVkFgMgK1piSeJ5Uj26r7khXqLzpOksLwer8Yvhm9FbNAk9YP5KSRP6e ahKoSO9KEAQuDjupnmrXj8MZz/S2LDJg7yIRCLEi8DUTBT9lwMnke6aVq75/61QAZ85o 1vpvw7C3SGYEdmDcGAvz2MDiFH6QAQUzuqTiS6JF7seCW+mZp5KSCRAKz9jQQaM02nue kTxQ== X-Forwarded-Encrypted: i=1; AJvYcCXHnkbe6srU583tAWYzXtenFADj4J8mPv4UUd6RmazKVcHmX+bzllr0Y7plnJi1JJYf8BOcrjHRFMX6V7c=@vger.kernel.org X-Gm-Message-State: AOJu0YzdA7e3ET4wdaSBmD9naxjKyg3+vFZ6YwllWB7I2bO5m7nWoQ07 uQc9R4zMmaK/8elvl30CodtBtzrwx+pyonOBsJ5ANjwB5UMnummdZr65JtMfBy6M3r69hw6fL9O OUe2WCw== X-Google-Smtp-Source: AGHT+IGMonSv07nS2wp2+XCCHzVmYpXNUlojv8r3liVHzTEgZqvcA1ToLi0TGOEDOuu91o5vEOFn9a/03W2i X-Received: from oabsf6.prod.google.com ([2002:a05:6871:2306:b0:2c4:3490:8790]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6870:a711:b0:29e:8485:197b with SMTP id 586e51a60fabf-2c780243a61mr9913650fac.2.1742855714663; Mon, 24 Mar 2025 15:35:14 -0700 (PDT) Date: Mon, 24 Mar 2025 15:34:47 -0700 In-Reply-To: <20250324223452.208081-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: <20250324223452.208081-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.395.g12beb8f557-goog Message-ID: <20250324223452.208081-10-irogers@google.com> Subject: [PATCH v1 09/14] 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 | 8 +++--- 3 files changed, 28 insertions(+), 43 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 500c472f7059..486218757872 100644 --- a/tools/perf/util/intel-tpebs.c +++ b/tools/perf/util/intel-tpebs.c @@ -409,49 +409,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 6ff92f5de9b4..fa9e4b047e8d 100644 --- a/tools/perf/util/intel-tpebs.h +++ b/tools/perf/util/intel-tpebs.h @@ -12,7 +12,7 @@ struct evsel; extern bool tpebs_recording; 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 #else =20 @@ -23,9 +23,9 @@ static inline int evsel__tpebs_open(struct evsel *evsel _= _maybe_unused) =20 static inline void evsel__tpebs_close(struct evsel *evsed __maybe_unused) = {}; =20 -static inline int tpebs_set_evsel(struct evsel *evsel __maybe_unused, - int cpu_map_idx __maybe_unused, - int thread __maybe_unused) +static inline int evsel__tpebs_read(struct evsel *evsel __maybe_unused, + int cpu_map_idx __maybe_unused, + int thread __maybe_unused) { return 0; } --=20 2.49.0.395.g12beb8f557-goog From nobody Tue Dec 16 23:41:40 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 2BCE31F416B for ; Mon, 24 Mar 2025 22:35:16 +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=1742855719; cv=none; b=eP3kVOZlQt24LiJMX0xOMj7gjrI5wm9XYSzUcYoI4QKN0R1khEHuWeLBCQi75arzqcmCOf+h0lnUthPBYm10aEm/AK3DiKsi6tTPn+5o1DYhe6rL8kdmNudK0koSpmBQcqQ+xF/BcCXJ5+KCHrsCd9AVGeccZlKCooBo+qCDEtg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742855719; c=relaxed/simple; bh=/LfS5vvH7BDvXT1ZxYvfdUx210V73ZgYJ/XIaS8om8U=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=h09qPJr45Ooh4y1n9LPbmlb3UIhfhSMrZ3nTeBtQtupjVftiD+PcGrdnXpoAHeoOueGRPJArIlEETw0c4rnKfD82nPT7fuNXDVQnkmQkXXylQ4FbmpB5eXj6g1wYBP8WZknBZm8BTGJIoE27cuB0dMipUejrY4zAB12+fA15BLE= 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=eYj44wEF; 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="eYj44wEF" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-2240a96112fso133996755ad.2 for ; Mon, 24 Mar 2025 15:35:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1742855716; x=1743460516; 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=7Tug84NNGxWWUCgp7kdrw30UYr/sdQhmVez8IuJKNko=; b=eYj44wEFcu4iupMeY9byennsgUI3RZx/EtWhMyKRfs5FGlClpjcD/NEE5GlEDIXroO ISRRQybSpE99NFP3BZuYDZJfTe6pi6o3xp7Y6Z5Nisl+hUJ/WkH0sK58wTRFF+Tb8VaU zsG7U7nuXe4JTHtAh8vvdc6vcWqYHCqORas8toNa6edBxXz3ci+kQvPj8BXUtxsRykji f6c9ly5ZJ4DudGQQfAc/3ChBsS81yjwQUFV48RTA13vrql3MQYarKRR8+Z9Fd0G1DFG3 2xqEG0jJl3hm/CiPlCJo8J46EtrdGRbHBjDP8f071QfCsgi75mO5pO/2/gQ5PHbm5NRh citg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742855716; x=1743460516; 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=7Tug84NNGxWWUCgp7kdrw30UYr/sdQhmVez8IuJKNko=; b=B2R3hvImlofUhLcWRFXHR2BldM8ABxV1xaBR8LGt7UjrN0SdSZomLE4L8U6zyPV+UF svEIrS/ohy1hjeBekkUEatALv4GRn2yQB24+4X9tTfVDhlMk0uDWu63yRQCTg5SURmmi U7Aak7pQcegCpU3PBi0nVGoi4VdKwGUHKZhnP4kFCO6clF9yorFarO30ENxIzfFdKNjI /tZ/TSozxl6Pd/Y9adddFlYEqMtkuZcAe146grXGgusXruvZ6jrmhSKWysqO4Ucof2O/ ykbHKB00KuvFjv0+h/KOw7eBLQ2PN+rRDNOC06T6jdY3KaAwPv+KbIuTagYU8zY3XBT5 D8rA== X-Forwarded-Encrypted: i=1; AJvYcCWR0AAxF6yY6WNSmynZLrFaLnfrHaxw1fYjiee4iGpxLB0VAKgCLBBrcU8e7zmFaXLEz96hT3cDbH7FmOI=@vger.kernel.org X-Gm-Message-State: AOJu0Yw3K2GOt7YJdfkrjr+WKxvPfeDLEk8U3nU7L5p4dLJG42Nq93lc uV7HVHZDe1cl8jju33mOWaTmZVBuNV2qt+PXgmtQeGTzQDh6yatODSPKdld1O2TT6zoctzC7Zmh 6Ry8G2w== X-Google-Smtp-Source: AGHT+IHPv+hUXkIYxiKXGAJ7LMWSFQLfSJP6JUWOGvhjOKn95LIYO7mLPmSdDgffDoI2oy24qzTYLpO1Fk96 X-Received: from pjk16.prod.google.com ([2002:a17:90b:5590:b0:2ea:29de:af10]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:e5c6:b0:215:7421:262 with SMTP id d9443c01a7336-22780c78291mr242123945ad.12.1742855716519; Mon, 24 Mar 2025 15:35:16 -0700 (PDT) Date: Mon, 24 Mar 2025 15:34:48 -0700 In-Reply-To: <20250324223452.208081-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: <20250324223452.208081-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.395.g12beb8f557-goog Message-ID: <20250324223452.208081-11-irogers@google.com> Subject: [PATCH v1 10/14] 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 486218757872..05e1a0a296c5 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" @@ -31,6 +32,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; @@ -50,6 +52,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; @@ -58,13 +73,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"; @@ -100,6 +117,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 @@ -111,9 +129,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 @@ -122,6 +143,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 @@ -228,7 +250,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 @@ -276,16 +297,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. @@ -311,6 +338,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) @@ -330,7 +358,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]; @@ -430,8 +461,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; @@ -454,9 +487,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.395.g12beb8f557-goog From nobody Tue Dec 16 23:41:40 2025 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 922731F417D for ; Mon, 24 Mar 2025 22:35:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742855721; cv=none; b=e3bWTElia6x7Xn90PW09BQM0iZZaOIyw+qYz9L8dgbck+i1J3KLZpiRMRGXUmzkz8SUeTz6Q449p1kt5m7v1vFtR1yn1HG3n3GqmyVEKwLsFSE/rY/OGJP1JM0syR9kHWMvvDeBLdBNKTPDxWcYOPLXIkddx3/PBXnSGAhpoOlk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742855721; c=relaxed/simple; bh=4O4dekXK68t6Gt55wyny8704RH4HlLK2oFqx5BnNkpk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=OBm7uZcm4blHrNUHzhSy9/NpMJY4De6qmm2VYZ0eb3YLUxymdr/jPEfdgDanDjboPjBtMRksGKpGmT3iu68OIb4H4sc5r3nseu6HOtNra5rQ1x1gLBNq0mlw9uMX9Hbo1ljmyvKic5d7MAJA6A1Fv1aJtilslGKpGgZoinfZAcs= 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=wC/bUrQA; arc=none smtp.client-ip=209.85.216.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="wC/bUrQA" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-2ff8c5d185aso14663079a91.1 for ; Mon, 24 Mar 2025 15:35:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1742855719; x=1743460519; 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=NDN/A2l/bsrOFeh/EugE420zHj+1Q5W4wwehjEZQXYc=; b=wC/bUrQAoCYRoFduxghgdPytbWuhUorUHmgDvppWaXazMcXe79t29WprTR+RiJJKfg COCdcB2qiTWSdzry0OpNwlWy5iJQGD0uwM1zdNmyQCKVuH1B785NXObWhtdrciTVnbw1 3H7rYu5eULryACgylNigr9Fo+cb7aN6Lgw4WMho/lA4ZMLYur93i25Kf7lvlvVTWos7G bCCckfAd9brCwVjqNVrIKzeMuODz5eOwueRBWEVKeulgLUodDMfK5e0PJjvTm8mGTDgw BLLtDeAlMR0C1sjoUI1z+isKn8QvTWMgf/UAoHhah63zgXNRoD6sQ6fVwYcU9DmWKsUE NZeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742855719; x=1743460519; 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=NDN/A2l/bsrOFeh/EugE420zHj+1Q5W4wwehjEZQXYc=; b=QHsZezZYtGFNrKev3VN1R7meYzQvdsDGqPS+J5JMAMvYT9UrAK1zSmVYp16LRnWr/3 7Zo4pay0cRhYmxbu5JLllV+Lxu+q9ItboXmL4cp/7fBkwGvrDAaTLxQ9IdOMvRx2aGcZ RmP+mNU90VlMx/q6Yeb8DzisINdo5c29+Lgk9TYSksdPtYvQmhNKwUgk+C+m4F/Jj+Q8 kKTXofBYM17VPoyHDoi3EusPfltgWQXJEUnbWtWQal4bqvNibfsBxP2u3BSC4sGxmegf XxkSlip6HgJGuR+j+Rp1Sf9lpe/cSjtxkEvcGd7UjMQGiek0GpxgLJ0+yNSFVqDnrgKS FDrQ== X-Forwarded-Encrypted: i=1; AJvYcCUTGuf93rMgKpodVJR5XtO7XV6ed/bu80Ah5HexjrxO1dXychNT1ZkNKOfDpbXGk74MbKXmCGRkRtG8jW8=@vger.kernel.org X-Gm-Message-State: AOJu0YzL1canwZbDdXPRy0xqrK7ElOchsxPUn9IembQ0i4d0KVDD4shp gt4XtBbMgsh9lFJv9/vvW+JqskD9Yacbgeh675Nv5y3JLrALzommuapKRbIXLleFNmpEWP0aiih IoF91EA== X-Google-Smtp-Source: AGHT+IFwIr3pAnykXDGtQHw0rQzKoJgbfmJPqVunqKAW1zxPUPb4uqLARH7aKSBHx7eysLM3xfNR/G7cYjYU X-Received: from pgmt1.prod.google.com ([2002:a63:2241:0:b0:af2:2287:e91c]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:6315:b0:1f5:87dc:a315 with SMTP id adf61e73a8af0-1fe42f3572bmr23176579637.12.1742855718804; Mon, 24 Mar 2025 15:35:18 -0700 (PDT) Date: Mon, 24 Mar 2025 15:34:49 -0700 In-Reply-To: <20250324223452.208081-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: <20250324223452.208081-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.395.g12beb8f557-goog Message-ID: <20250324223452.208081-12-irogers@google.com> Subject: [PATCH v1 11/14] 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 05e1a0a296c5..4d51dc8f74ea 100644 --- a/tools/perf/util/intel-tpebs.c +++ b/tools/perf/util/intel-tpebs.c @@ -32,6 +32,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 { @@ -50,8 +51,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); @@ -65,7 +64,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; @@ -73,15 +75,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"; @@ -117,7 +117,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 @@ -130,6 +129,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()); @@ -179,17 +183,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; @@ -307,9 +392,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 @@ -345,13 +431,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); @@ -360,12 +448,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"); @@ -378,7 +461,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 @@ -390,53 +473,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 @@ -445,6 +491,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) @@ -455,14 +502,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 @@ -491,10 +544,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.395.g12beb8f557-goog From nobody Tue Dec 16 23:41:40 2025 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1A2431F419B for ; Mon, 24 Mar 2025 22:35:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742855722; cv=none; b=RpS+KWagJrnw4svvYBjCZaGGkxP1U7lCiB9/87CALiSy978S4Mt5gDnLNTg7FArcy14E/AhUGebra3HV1USc+E5jzrY3semBgPBWK7ono7/k5hp4cB/NOYyTn0rE/WR7/ws35THpaaNEujErlAZ1I25g1QhP61cFsdcQzhhj9OU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742855722; c=relaxed/simple; bh=01JMQWMyaAKM/J1u47irZKwxTPCpRuPzr2nvkfArrYc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=PKH61qPzK/t/NFQBOWNA32FHx5Jtcpqb3P21TKbamnMVhCirTDl60dq0UGyi4QCs7qtJScvSrhVBFCoy4qqB/ncCVmx5sJnl9DwBZXPym+fXVNSO/vaRBBb+zeutJzO5FsAfEi/4IZxLw1bKSA2MKV85mBcyt0UXWxnD02r9h+4= 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=XNsscKms; arc=none smtp.client-ip=209.85.216.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="XNsscKms" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-2ff798e8c3bso8249051a91.2 for ; Mon, 24 Mar 2025 15:35:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1742855720; x=1743460520; 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=0wcJAbivJu1k/AjUyHUQjxQAmzqPSg8uRDSrH0bdtXw=; b=XNsscKmsxoRA9fj12uz3rKXeiyoVNYrUF6aZ4+uvwkOUuiXQ4tXqfa4TH66utJLfnQ UfPfht5nuBYJTEqnU9q6QDEV5PUyBaFr5O4oMQnaVLgzBghJnpQ9Zx1lf9R6rFi/GC2U s84O9MN5HBRlo7GC3mexmodsni4HT7hOQILcdXfhl2F0P1AnyGYFVFDaVLz8FY1FDSx+ ZwYtSH3S1lRcZsC3EEdeggVI5VDgtb8JQ50X3jd7uql3/hpPIGOkb6fjjc7GDOFcbW5n zh47rixcBjLmeOi07uqOEw9FKN7WB1rZba+8bEmIrB6BPuFNftEhlR8MQQCskPdVxXNr YMig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742855720; x=1743460520; 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=0wcJAbivJu1k/AjUyHUQjxQAmzqPSg8uRDSrH0bdtXw=; b=cR46fOlFzyNExm2ltBWfpdy8AeLqqyIl1bjU8JX3yCZ/yH8wXIYl8mfvffr5MCWT+I GknWxH2N384OugyrU7WU91Q3d9KbQroVBO7gX5dvU7GjwoRinDZAkyi75QqOpBYREBb4 4QA5UDO34nVY4HhHvvX8jp2bMrbW0e6Aw7JTDndsYHujNC52onuX8nuduNPCwu2+Wf7f wHQkK1KiWZaMAaKbPfkYdJ4XyDR9nOtswBe1s01Y8LlZNFVJ8gXyK+yhEGruo0d8awqd 5T4rIXw8mjBMYz5XPic2fxwAjTbuRNsXpIOAKWB4bl0E+qWUBUNAgUdyNfvb1E5LsU81 yNJA== X-Forwarded-Encrypted: i=1; AJvYcCW1aKjaH4Ltq2fd0LDwivL+4AfQSCdFW96/9/dCFQMpZ9CHtlQ2StCfiOMABMXePCTOnbIFT57Ds5JF3FQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yy7JIvv9Uf5yiVQm89GlYYNpWr8SP3LKnzv7o93HEIY43BXiKyW AS2ctDE14jznnLehBTw3dXtFO9uDGPWrbwRFBnnYA76zOw32QM6mQidtbkRPWE2oxFpdINYGkeV JNSN5ew== X-Google-Smtp-Source: AGHT+IFYuCJ9A2bIFu0gRLO3Foa6xQQF8TLQYdnDE54OfHdgTTAnAgbtY0BgiO0AmrNp+D7M4pcI1WvbmHID X-Received: from pgbdp8.prod.google.com ([2002:a05:6a02:f08:b0:adf:4827:b70e]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:4d8b:b0:1f3:194b:30ae with SMTP id adf61e73a8af0-1fe42f090d1mr23333406637.1.1742855720436; Mon, 24 Mar 2025 15:35:20 -0700 (PDT) Date: Mon, 24 Mar 2025 15:34:50 -0700 In-Reply-To: <20250324223452.208081-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: <20250324223452.208081-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.395.g12beb8f557-goog Message-ID: <20250324223452.208081-13-irogers@google.com> Subject: [PATCH v1 12/14] 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 4d51dc8f74ea..0def3419b1e5 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" @@ -41,12 +42,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; }; @@ -144,9 +141,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; } @@ -516,7 +511,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.395.g12beb8f557-goog From nobody Tue Dec 16 23:41:40 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 39FDE1F461A for ; Mon, 24 Mar 2025 22:35: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=1742855724; cv=none; b=V1j+XXt9yCTkUGNkVnLe1CDI9rn4WcZeVNBkMgEJ5tPUIE8rgzn5UVfVugw9AZF+e0wxJw/T56tlJW9QbvZvyzAAWx/LL4DcINpzTE+FipVe6yNWFG29vYrwkZhweNmrAXpEpB+CXk01CRBsMKGtll2poFsoJIbW/H+3joVLBwI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742855724; c=relaxed/simple; bh=mWIG94RX7F1dn+zKyyhSyvgD24VQRvJZ1y/5BreQhLM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=qdhtpI8i1l3GBYwJlJa5iU0tiaomNrUtueczPrUT0PTZWGaDkKQra7ZPPadg9Ag5JFTlAwSV9NRLziNP+ay0L69jG6hDkYNv5zu49b5a0wTTW3hi+Rlkq/Eay4zSRq5A+EWfrbe7d6XVSlexFKqvzGq4obSNvmeqsJQ1Hf8wGYM= 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=uVDhdX0b; 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="uVDhdX0b" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-2242ca2a4a5so58028665ad.2 for ; Mon, 24 Mar 2025 15:35:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1742855722; x=1743460522; 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=1fWiVshzRT1OlcqEg0fIi6VxUb2Z3joclrwIJtBaApg=; b=uVDhdX0bZK5Y3ctAEE3XYktBytWqBKMIwttd7ZZ8V+BX+e9/+w4nlrqlN3lukcofM9 /b7sNqEKmYVCPU5zLjVLmXgl+wvRdDDXPTgAD8RPUj7FHFGEDDXCJBjtLc4hucS6NHqV yIEHQL1LZjIK4YQMVj2TTWM38mA8iMU2JcN77iCtx6ohn52dDYmfCUQekOJ6HC1vYS/T 4mifGkepcNc0tq7My9Rbjmg363t0Znarxx+7imZW8fLQx8oWZ8tSSbnsQRGJVo9C1Z+Z mwOb3OO2Zf8/VXkn8mCNJLb69GvYi/J9VrLyV/b+q4LTC2uWIO+57M5g+RsMkV/fdg3B s5QA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742855722; x=1743460522; 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=1fWiVshzRT1OlcqEg0fIi6VxUb2Z3joclrwIJtBaApg=; b=tK3m/63xpPl/hgPz/ZwCDuV8q5c5gClgb4WYoyWcjlqt3ajGzsqMqZF2NDpVFIaNag S6Jen++3zIRRxiWt6+v/mYZ1ZUFF0QXTWeFukGoUeBdxAaxYUZOIh441dITCoP0DHKDs YAZGqM3TUu93E/FigVCAbSagwjT1/3wI7LEVYIoTMvAk6MX12qtkhcoXM2i1sPsMXRBN B0sr9T3xbBhVZfna/02fGVk9rh5ZQCHgzPjp7abW2N/R+g0pN+/sQNiLz7SfWkP1yRnP bZ5qUnXaJQgbAn+skj+gMRCR7yKyafrXDYWBtckAsLGD3sZoFAuFbewMNQYsAqbhfJ/t dDLQ== X-Forwarded-Encrypted: i=1; AJvYcCWI9raXyLG0WXaK+DPe9/FEr7JHZSrcuo+OCV9E4WfZw4xgESpZa185mIhV6SuU/Octwc+yrmhZv+Xowr8=@vger.kernel.org X-Gm-Message-State: AOJu0YyaPnTAvh3/9woPp1+o/Fl8WKYYat2/C9cOjhP5pbw/dqai+iGF g78X/tir0WzYym5ARel6VjV9rGD4I3kUBsvPu7J1grefwSqukw2z4vwt5FLd54GMvhO7jcZAxEm ppcE3hw== X-Google-Smtp-Source: AGHT+IFZaRi6pFLVQDhCP2dFjHAi9+j6YTuOnyYcQ6VxSF3qhonUx+/UvuMpMFOip71GMSPUNq6IDDnBl9xw X-Received: from pfbfe25.prod.google.com ([2002:a05:6a00:2f19:b0:736:b2a2:5bfe]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:b96:b0:736:4a5b:7f08 with SMTP id d2e1a72fcca58-73905a27818mr21905414b3a.22.1742855722480; Mon, 24 Mar 2025 15:35:22 -0700 (PDT) Date: Mon, 24 Mar 2025 15:34:51 -0700 In-Reply-To: <20250324223452.208081-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: <20250324223452.208081-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.395.g12beb8f557-goog Message-ID: <20250324223452.208081-14-irogers@google.com> Subject: [PATCH v1 13/14] 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 | 9 +++++++++ 4 files changed, 62 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 0def3419b1e5..5a255eb4f057 100644 --- a/tools/perf/util/intel-tpebs.c +++ b/tools/perf/util/intel-tpebs.c @@ -30,6 +30,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; @@ -44,6 +45,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; }; @@ -141,6 +144,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; @@ -511,7 +515,21 @@ int evsel__tpebs_read(struct evsel *evsel, int cpu_map= _idx, int thread) return ret; mutex_lock(tpebs_mtx_get()); } - val =3D rint(t->stats.mean); + switch (tpebs_mode) { + case TPEBS_MODE__MIN: + val =3D rint(t->stats.mean); + break; + case TPEBS_MODE__MAX: + val =3D rint(t->stats.mean); + break; + case TPEBS_MODE__LAST: + val =3D t->last; + break; + default: + case TPEBS_MODE__MEAN: + val =3D rint(t->stats.mean); + break; + } mutex_unlock(tpebs_mtx_get()); =20 if (old_count) { diff --git a/tools/perf/util/intel-tpebs.h b/tools/perf/util/intel-tpebs.h index fa9e4b047e8d..a47a778be46c 100644 --- a/tools/perf/util/intel-tpebs.h +++ b/tools/perf/util/intel-tpebs.h @@ -9,7 +9,16 @@ struct evsel; =20 #ifdef HAVE_ARCH_X86_64_SUPPORT =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; + int evsel__tpebs_open(struct evsel *evsel); void evsel__tpebs_close(struct evsel *evsel); int evsel__tpebs_read(struct evsel *evsel, int cpu_map_idx, int thread); --=20 2.49.0.395.g12beb8f557-goog From nobody Tue Dec 16 23:41:40 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 25DC01F4723 for ; Mon, 24 Mar 2025 22:35:25 +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=1742855727; cv=none; b=LkWQEtdJXzbqMnBawGxYCcREHHI6z8mh9s9gx8CE9GyuwNDJCZKpQRp5Qm4hl1ftJbQwZhy5Zpz54WrVuxS+11GCtJYmv8q3g5+MjAw1VMhTnhvWN3q5YK4TFstQBwa7BD1OR8Ns567kCmD9Q/hnT2eLNQdA2UEP5HJdF1jS/hc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742855727; c=relaxed/simple; bh=74WwQeFCGLbI2R+hYeqlsCP5OmpIHKxlT8IYyGzAGr4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=JXuwMxUOvA9h4gXLM+o9L/8z3wEq4h5DywFSwzQW3jJfrox/XDwVCyKqilhD8aE1oexFxi4hG2LSMYLLOyQ1u9Jva9TRM7UB5GdlGPZZHf0MkKNbRIcvkYXnF5WonvMj7hYOPN6iUSalHAei3n5RzIjUZxC8SlNzLjmtoUfjflA= 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=KZ9oOp5S; 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="KZ9oOp5S" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-2ff78dd28ecso10271193a91.1 for ; Mon, 24 Mar 2025 15:35:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1742855724; x=1743460524; 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=A2kcx43GYb17OkM62jnuDjuuWuz+qR5zN9CzHk0g1/0=; b=KZ9oOp5S1wI4KjwSWdgMiKRENzwGvXHIOpzc9WKuTvdaw/axwDZ3HYt0PEp4+lz/sR RXwd041xDL7PLmy40nFkvFXeA0v8ixHLtWQFmGFNn/eqJh2AJIc1UdrYOu1dciNv6C94 Z2c1UPozuzctUmML8ZrnHWtpwHHM7HQiDO36K5o3+NudtqV0N2xHxbQKtrjV+N53tKZk JveNs8Byn1g1ZE7LSOo+smw4fow7a5Eqmg8KC3l0oISoB+PMRjuOcPe280nZZPqc3hAx lAlXOp+vewehA2cDx0Y1x3Zv/pRdx3ITo85Ox3saMAln8Sy+pX+I/Y1kQ5VQFhcA8Q3p JnHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742855724; x=1743460524; 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=A2kcx43GYb17OkM62jnuDjuuWuz+qR5zN9CzHk0g1/0=; b=h3gIeIjenQnwj0Oz9EBG/rHn9dclIj4GcUvkXgHLm8cok7rJI3zAucdT6KhkTyjxbw 24VSIPSrwgrfIqyLS8i7zX4g+bRtbldIE0Ao+MAEC3ZveZ2jjDJTpXX5y7oMeZJhomTQ zuOAq7ktYPCKojB+f7uRyxA7p5JJhq9czXLhAJXLqo4cCqwl4s1w2krJ6W6pVPsysfs7 o2rFlXjTgw2Lcwc4f/0AvOTsBcmwrhfuGzWkBT0PW8T8O0l6QQrDlth0qSVQAART/Qwj Y/u1Yo4K81tDwEkbVyvnIAl5DrrkYgRgjz39v0kcTCPE3OjTEP5xm2bFx01NnFzMFiz6 gA8A== X-Forwarded-Encrypted: i=1; AJvYcCVn1GNAqTJt68uJOhATiT04PvsufPrEqH5MINkW6JwDUvhE5qC+6hlM31DCGoOnDjZGjkk0J33zwK2j2hw=@vger.kernel.org X-Gm-Message-State: AOJu0YzEXRpnPyTgPa170ttqWN5gd52mj7OoMlL0ba8c2BgFOb8XI5GW aNWoa+11pxr8kDTnLhuZ42Q+uxlbx1VWZXLv241vot2VFZ1XMe9aR9WoOhu0jGf6MFo52Bm/M2i v0nAwAw== X-Google-Smtp-Source: AGHT+IGmcnxUJzeu7IpkDm134j5qUKKbNTUwVYZk9ohHyEs1waw10nEos7DXITH6yJBnQ+0B4PppROjM2Z4w X-Received: from pfuv10.prod.google.com ([2002:a05:6a00:148a:b0:736:3cd5:ba3a]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:113:b0:1f5:874c:c987 with SMTP id adf61e73a8af0-1fe42f2c872mr23857321637.15.1742855724488; Mon, 24 Mar 2025 15:35:24 -0700 (PDT) Date: Mon, 24 Mar 2025 15:34:52 -0700 In-Reply-To: <20250324223452.208081-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: <20250324223452.208081-1-irogers@google.com> X-Mailer: git-send-email 2.49.0.395.g12beb8f557-goog Message-ID: <20250324223452.208081-15-irogers@google.com> Subject: [PATCH v1 14/14] perf pmu-events: Add retirement latency to JSON events inside of perf From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , Weilin Wang , James Clark , Xu Yang , John Garry , Howard Chu , Levi Yun , Dominique Martinet , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The updated Intel vendor events add retirement latency for graniterapids: https://lore.kernel.org/lkml/20250322063403.364981-14-irogers@google.com/ This change makes those values available within an alias/event within a PMU and saves them into the evsel at event parse time. When no TPEBS data is available the default values are substituted in for TMA metrics that are using retirement latency events - currently just those on graniterapids. Signed-off-by: Ian Rogers --- tools/perf/pmu-events/empty-pmu-events.c | 216 ++++++++++++----------- tools/perf/pmu-events/jevents.py | 6 + tools/perf/pmu-events/pmu-events.h | 3 + tools/perf/util/evsel.h | 6 + tools/perf/util/intel-tpebs.c | 51 ++++-- tools/perf/util/parse-events.c | 4 + tools/perf/util/pmu.c | 52 +++++- tools/perf/util/pmu.h | 3 + 8 files changed, 218 insertions(+), 123 deletions(-) diff --git a/tools/perf/pmu-events/empty-pmu-events.c b/tools/perf/pmu-even= ts/empty-pmu-events.c index 0cb7ba7912e8..0361bcc1eb58 100644 --- a/tools/perf/pmu-events/empty-pmu-events.c +++ b/tools/perf/pmu-events/empty-pmu-events.c @@ -20,73 +20,73 @@ struct pmu_table_entry { =20 static const char *const big_c_string =3D /* offset=3D0 */ "tool\000" -/* offset=3D5 */ "duration_time\000tool\000Wall clock interval time in nan= oseconds\000config=3D1\000\00000\000\000" -/* offset=3D78 */ "user_time\000tool\000User (non-kernel) time in nanoseco= nds\000config=3D2\000\00000\000\000" -/* offset=3D145 */ "system_time\000tool\000System/kernel time in nanosecon= ds\000config=3D3\000\00000\000\000" -/* offset=3D210 */ "has_pmem\000tool\0001 if persistent memory installed o= therwise 0\000config=3D4\000\00000\000\000" -/* offset=3D283 */ "num_cores\000tool\000Number of cores. A core consists = of 1 or more thread, with each thread being associated with a logical Linux= CPU\000config=3D5\000\00000\000\000" -/* offset=3D425 */ "num_cpus\000tool\000Number of logical Linux CPUs. Ther= e may be multiple such CPUs on a core\000config=3D6\000\00000\000\000" -/* offset=3D525 */ "num_cpus_online\000tool\000Number of online logical Li= nux CPUs. There may be multiple such CPUs on a core\000config=3D7\000\00000= \000\000" -/* offset=3D639 */ "num_dies\000tool\000Number of dies. Each die has 1 or = more cores\000config=3D8\000\00000\000\000" -/* offset=3D712 */ "num_packages\000tool\000Number of packages. Each packa= ge has 1 or more die\000config=3D9\000\00000\000\000" -/* offset=3D795 */ "slots\000tool\000Number of functional units that in pa= rallel can execute parts of an instruction\000config=3D0xa\000\00000\000\00= 0" -/* offset=3D902 */ "smt_on\000tool\0001 if simultaneous multithreading (ak= a hyperthreading) is enable otherwise 0\000config=3D0xb\000\00000\000\000" -/* offset=3D1006 */ "system_tsc_freq\000tool\000The amount a Time Stamp Co= unter (TSC) increases per second\000config=3D0xc\000\00000\000\000" -/* offset=3D1102 */ "default_core\000" -/* offset=3D1115 */ "bp_l1_btb_correct\000branch\000L1 BTB Correction\000e= vent=3D0x8a\000\00000\000\000" -/* offset=3D1174 */ "bp_l2_btb_correct\000branch\000L2 BTB Correction\000e= vent=3D0x8b\000\00000\000\000" -/* offset=3D1233 */ "l3_cache_rd\000cache\000L3 cache access, read\000even= t=3D0x40\000\00000\000Attributable Level 3 cache access, read\000" -/* offset=3D1328 */ "segment_reg_loads.any\000other\000Number of segment r= egister loads\000event=3D6,period=3D200000,umask=3D0x80\000\00000\000\000" -/* offset=3D1427 */ "dispatch_blocked.any\000other\000Memory cluster signa= ls to block micro-op dispatch for any reason\000event=3D9,period=3D200000,u= mask=3D0x20\000\00000\000\000" -/* offset=3D1557 */ "eist_trans\000other\000Number of Enhanced Intel Speed= Step(R) Technology (EIST) transitions\000event=3D0x3a,period=3D200000\000\0= 0000\000\000" -/* offset=3D1672 */ "hisi_sccl,ddrc\000" -/* offset=3D1687 */ "uncore_hisi_ddrc.flux_wcmd\000uncore\000DDRC write co= mmands\000event=3D2\000\00000\000DDRC write commands\000" -/* offset=3D1773 */ "uncore_cbox\000" -/* offset=3D1785 */ "unc_cbo_xsnp_response.miss_eviction\000uncore\000A cr= oss-core snoop resulted from L3 Eviction which misses in some processor cor= e\000event=3D0x22,umask=3D0x81\000\00000\000A cross-core snoop resulted fro= m L3 Eviction which misses in some processor core\000" -/* offset=3D2016 */ "event-hyphen\000uncore\000UNC_CBO_HYPHEN\000event=3D0= xe0\000\00000\000UNC_CBO_HYPHEN\000" -/* offset=3D2081 */ "event-two-hyph\000uncore\000UNC_CBO_TWO_HYPH\000event= =3D0xc0\000\00000\000UNC_CBO_TWO_HYPH\000" -/* offset=3D2152 */ "hisi_sccl,l3c\000" -/* offset=3D2166 */ "uncore_hisi_l3c.rd_hit_cpipe\000uncore\000Total read = hits\000event=3D7\000\00000\000Total read hits\000" -/* offset=3D2246 */ "uncore_imc_free_running\000" -/* offset=3D2270 */ "uncore_imc_free_running.cache_miss\000uncore\000Total= cache misses\000event=3D0x12\000\00000\000Total cache misses\000" -/* offset=3D2365 */ "uncore_imc\000" -/* offset=3D2376 */ "uncore_imc.cache_hits\000uncore\000Total cache hits\0= 00event=3D0x34\000\00000\000Total cache hits\000" -/* offset=3D2454 */ "uncore_sys_ddr_pmu\000" -/* offset=3D2473 */ "sys_ddr_pmu.write_cycles\000uncore\000ddr write-cycle= s event\000event=3D0x2b\000v8\00000\000\000" -/* offset=3D2546 */ "uncore_sys_ccn_pmu\000" -/* offset=3D2565 */ "sys_ccn_pmu.read_cycles\000uncore\000ccn read-cycles = event\000config=3D0x2c\0000x01\00000\000\000" -/* offset=3D2639 */ "uncore_sys_cmn_pmu\000" -/* offset=3D2658 */ "sys_cmn_pmu.hnf_cache_miss\000uncore\000Counts total = cache misses in first lookup result (high priority)\000eventid=3D1,type=3D5= \000(434|436|43c|43a).*\00000\000\000" -/* offset=3D2798 */ "CPI\000\0001 / IPC\000\000\000\000\000\000\000\00000" -/* offset=3D2820 */ "IPC\000group1\000inst_retired.any / cpu_clk_unhalted.= thread\000\000\000\000\000\000\000\00000" -/* offset=3D2883 */ "Frontend_Bound_SMT\000\000idq_uops_not_delivered.core= / (4 * (cpu_clk_unhalted.thread / 2 * (1 + cpu_clk_unhalted.one_thread_act= ive / cpu_clk_unhalted.ref_xclk)))\000\000\000\000\000\000\000\00000" -/* offset=3D3049 */ "dcache_miss_cpi\000\000l1d\\-loads\\-misses / inst_re= tired.any\000\000\000\000\000\000\000\00000" -/* offset=3D3113 */ "icache_miss_cycles\000\000l1i\\-loads\\-misses / inst= _retired.any\000\000\000\000\000\000\000\00000" -/* offset=3D3180 */ "cache_miss_cycles\000group1\000dcache_miss_cpi + icac= he_miss_cycles\000\000\000\000\000\000\000\00000" -/* offset=3D3251 */ "DCache_L2_All_Hits\000\000l2_rqsts.demand_data_rd_hit= + l2_rqsts.pf_hit + l2_rqsts.rfo_hit\000\000\000\000\000\000\000\00000" -/* offset=3D3345 */ "DCache_L2_All_Miss\000\000max(l2_rqsts.all_demand_dat= a_rd - l2_rqsts.demand_data_rd_hit, 0) + l2_rqsts.pf_miss + l2_rqsts.rfo_mi= ss\000\000\000\000\000\000\000\00000" -/* offset=3D3479 */ "DCache_L2_All\000\000DCache_L2_All_Hits + DCache_L2_A= ll_Miss\000\000\000\000\000\000\000\00000" -/* offset=3D3543 */ "DCache_L2_Hits\000\000d_ratio(DCache_L2_All_Hits, DCa= che_L2_All)\000\000\000\000\000\000\000\00000" -/* offset=3D3611 */ "DCache_L2_Misses\000\000d_ratio(DCache_L2_All_Miss, D= Cache_L2_All)\000\000\000\000\000\000\000\00000" -/* offset=3D3681 */ "M1\000\000ipc + M2\000\000\000\000\000\000\000\00000" -/* offset=3D3703 */ "M2\000\000ipc + M1\000\000\000\000\000\000\000\00000" -/* offset=3D3725 */ "M3\000\0001 / M3\000\000\000\000\000\000\000\00000" -/* offset=3D3745 */ "L1D_Cache_Fill_BW\000\00064 * l1d.replacement / 1e9 /= duration_time\000\000\000\000\000\000\000\00000" +/* offset=3D5 */ "duration_time\000tool\000Wall clock interval time in nan= oseconds\000config=3D1\000\00000\000\000\000\000\000" +/* offset=3D81 */ "user_time\000tool\000User (non-kernel) time in nanoseco= nds\000config=3D2\000\00000\000\000\000\000\000" +/* offset=3D151 */ "system_time\000tool\000System/kernel time in nanosecon= ds\000config=3D3\000\00000\000\000\000\000\000" +/* offset=3D219 */ "has_pmem\000tool\0001 if persistent memory installed o= therwise 0\000config=3D4\000\00000\000\000\000\000\000" +/* offset=3D295 */ "num_cores\000tool\000Number of cores. A core consists = of 1 or more thread, with each thread being associated with a logical Linux= CPU\000config=3D5\000\00000\000\000\000\000\000" +/* offset=3D440 */ "num_cpus\000tool\000Number of logical Linux CPUs. Ther= e may be multiple such CPUs on a core\000config=3D6\000\00000\000\000\000\0= 00\000" +/* offset=3D543 */ "num_cpus_online\000tool\000Number of online logical Li= nux CPUs. There may be multiple such CPUs on a core\000config=3D7\000\00000= \000\000\000\000\000" +/* offset=3D660 */ "num_dies\000tool\000Number of dies. Each die has 1 or = more cores\000config=3D8\000\00000\000\000\000\000\000" +/* offset=3D736 */ "num_packages\000tool\000Number of packages. Each packa= ge has 1 or more die\000config=3D9\000\00000\000\000\000\000\000" +/* offset=3D822 */ "slots\000tool\000Number of functional units that in pa= rallel can execute parts of an instruction\000config=3D0xa\000\00000\000\00= 0\000\000\000" +/* offset=3D932 */ "smt_on\000tool\0001 if simultaneous multithreading (ak= a hyperthreading) is enable otherwise 0\000config=3D0xb\000\00000\000\000\0= 00\000\000" +/* offset=3D1039 */ "system_tsc_freq\000tool\000The amount a Time Stamp Co= unter (TSC) increases per second\000config=3D0xc\000\00000\000\000\000\000\= 000" +/* offset=3D1138 */ "default_core\000" +/* offset=3D1151 */ "bp_l1_btb_correct\000branch\000L1 BTB Correction\000e= vent=3D0x8a\000\00000\000\000\000\000\000" +/* offset=3D1213 */ "bp_l2_btb_correct\000branch\000L2 BTB Correction\000e= vent=3D0x8b\000\00000\000\000\000\000\000" +/* offset=3D1275 */ "l3_cache_rd\000cache\000L3 cache access, read\000even= t=3D0x40\000\00000\000\000\000\000Attributable Level 3 cache access, read\0= 00" +/* offset=3D1373 */ "segment_reg_loads.any\000other\000Number of segment r= egister loads\000event=3D6,period=3D200000,umask=3D0x80\000\00000\000\000\0= 00\000\000" +/* offset=3D1475 */ "dispatch_blocked.any\000other\000Memory cluster signa= ls to block micro-op dispatch for any reason\000event=3D9,period=3D200000,u= mask=3D0x20\000\00000\000\000\000\000\000" +/* offset=3D1608 */ "eist_trans\000other\000Number of Enhanced Intel Speed= Step(R) Technology (EIST) transitions\000event=3D0x3a,period=3D200000\000\0= 0000\000\000\000\000\000" +/* offset=3D1726 */ "hisi_sccl,ddrc\000" +/* offset=3D1741 */ "uncore_hisi_ddrc.flux_wcmd\000uncore\000DDRC write co= mmands\000event=3D2\000\00000\000\000\000\000DDRC write commands\000" +/* offset=3D1830 */ "uncore_cbox\000" +/* offset=3D1842 */ "unc_cbo_xsnp_response.miss_eviction\000uncore\000A cr= oss-core snoop resulted from L3 Eviction which misses in some processor cor= e\000event=3D0x22,umask=3D0x81\000\00000\000\000\000\000A cross-core snoop = resulted from L3 Eviction which misses in some processor core\000" +/* offset=3D2076 */ "event-hyphen\000uncore\000UNC_CBO_HYPHEN\000event=3D0= xe0\000\00000\000\000\000\000UNC_CBO_HYPHEN\000" +/* offset=3D2144 */ "event-two-hyph\000uncore\000UNC_CBO_TWO_HYPH\000event= =3D0xc0\000\00000\000\000\000\000UNC_CBO_TWO_HYPH\000" +/* offset=3D2218 */ "hisi_sccl,l3c\000" +/* offset=3D2232 */ "uncore_hisi_l3c.rd_hit_cpipe\000uncore\000Total read = hits\000event=3D7\000\00000\000\000\000\000Total read hits\000" +/* offset=3D2315 */ "uncore_imc_free_running\000" +/* offset=3D2339 */ "uncore_imc_free_running.cache_miss\000uncore\000Total= cache misses\000event=3D0x12\000\00000\000\000\000\000Total cache misses\0= 00" +/* offset=3D2437 */ "uncore_imc\000" +/* offset=3D2448 */ "uncore_imc.cache_hits\000uncore\000Total cache hits\0= 00event=3D0x34\000\00000\000\000\000\000Total cache hits\000" +/* offset=3D2529 */ "uncore_sys_ddr_pmu\000" +/* offset=3D2548 */ "sys_ddr_pmu.write_cycles\000uncore\000ddr write-cycle= s event\000event=3D0x2b\000v8\00000\000\000\000\000\000" +/* offset=3D2624 */ "uncore_sys_ccn_pmu\000" +/* offset=3D2643 */ "sys_ccn_pmu.read_cycles\000uncore\000ccn read-cycles = event\000config=3D0x2c\0000x01\00000\000\000\000\000\000" +/* offset=3D2720 */ "uncore_sys_cmn_pmu\000" +/* offset=3D2739 */ "sys_cmn_pmu.hnf_cache_miss\000uncore\000Counts total = cache misses in first lookup result (high priority)\000eventid=3D1,type=3D5= \000(434|436|43c|43a).*\00000\000\000\000\000\000" +/* offset=3D2882 */ "CPI\000\0001 / IPC\000\000\000\000\000\000\000\00000" +/* offset=3D2904 */ "IPC\000group1\000inst_retired.any / cpu_clk_unhalted.= thread\000\000\000\000\000\000\000\00000" +/* offset=3D2967 */ "Frontend_Bound_SMT\000\000idq_uops_not_delivered.core= / (4 * (cpu_clk_unhalted.thread / 2 * (1 + cpu_clk_unhalted.one_thread_act= ive / cpu_clk_unhalted.ref_xclk)))\000\000\000\000\000\000\000\00000" +/* offset=3D3133 */ "dcache_miss_cpi\000\000l1d\\-loads\\-misses / inst_re= tired.any\000\000\000\000\000\000\000\00000" +/* offset=3D3197 */ "icache_miss_cycles\000\000l1i\\-loads\\-misses / inst= _retired.any\000\000\000\000\000\000\000\00000" +/* offset=3D3264 */ "cache_miss_cycles\000group1\000dcache_miss_cpi + icac= he_miss_cycles\000\000\000\000\000\000\000\00000" +/* offset=3D3335 */ "DCache_L2_All_Hits\000\000l2_rqsts.demand_data_rd_hit= + l2_rqsts.pf_hit + l2_rqsts.rfo_hit\000\000\000\000\000\000\000\00000" +/* offset=3D3429 */ "DCache_L2_All_Miss\000\000max(l2_rqsts.all_demand_dat= a_rd - l2_rqsts.demand_data_rd_hit, 0) + l2_rqsts.pf_miss + l2_rqsts.rfo_mi= ss\000\000\000\000\000\000\000\00000" +/* offset=3D3563 */ "DCache_L2_All\000\000DCache_L2_All_Hits + DCache_L2_A= ll_Miss\000\000\000\000\000\000\000\00000" +/* offset=3D3627 */ "DCache_L2_Hits\000\000d_ratio(DCache_L2_All_Hits, DCa= che_L2_All)\000\000\000\000\000\000\000\00000" +/* offset=3D3695 */ "DCache_L2_Misses\000\000d_ratio(DCache_L2_All_Miss, D= Cache_L2_All)\000\000\000\000\000\000\000\00000" +/* offset=3D3765 */ "M1\000\000ipc + M2\000\000\000\000\000\000\000\00000" +/* offset=3D3787 */ "M2\000\000ipc + M1\000\000\000\000\000\000\000\00000" +/* offset=3D3809 */ "M3\000\0001 / M3\000\000\000\000\000\000\000\00000" +/* offset=3D3829 */ "L1D_Cache_Fill_BW\000\00064 * l1d.replacement / 1e9 /= duration_time\000\000\000\000\000\000\000\00000" ; =20 static const struct compact_pmu_event pmu_events__common_tool[] =3D { -{ 5 }, /* duration_time\000tool\000Wall clock interval time in nanoseconds= \000config=3D1\000\00000\000\000 */ -{ 210 }, /* has_pmem\000tool\0001 if persistent memory installed otherwise= 0\000config=3D4\000\00000\000\000 */ -{ 283 }, /* num_cores\000tool\000Number of cores. A core consists of 1 or = more thread, with each thread being associated with a logical Linux CPU\000= config=3D5\000\00000\000\000 */ -{ 425 }, /* num_cpus\000tool\000Number of logical Linux CPUs. There may be= multiple such CPUs on a core\000config=3D6\000\00000\000\000 */ -{ 525 }, /* num_cpus_online\000tool\000Number of online logical Linux CPUs= . There may be multiple such CPUs on a core\000config=3D7\000\00000\000\000= */ -{ 639 }, /* num_dies\000tool\000Number of dies. Each die has 1 or more cor= es\000config=3D8\000\00000\000\000 */ -{ 712 }, /* num_packages\000tool\000Number of packages. Each package has 1= or more die\000config=3D9\000\00000\000\000 */ -{ 795 }, /* slots\000tool\000Number of functional units that in parallel c= an execute parts of an instruction\000config=3D0xa\000\00000\000\000 */ -{ 902 }, /* smt_on\000tool\0001 if simultaneous multithreading (aka hypert= hreading) is enable otherwise 0\000config=3D0xb\000\00000\000\000 */ -{ 145 }, /* system_time\000tool\000System/kernel time in nanoseconds\000co= nfig=3D3\000\00000\000\000 */ -{ 1006 }, /* system_tsc_freq\000tool\000The amount a Time Stamp Counter (T= SC) increases per second\000config=3D0xc\000\00000\000\000 */ -{ 78 }, /* user_time\000tool\000User (non-kernel) time in nanoseconds\000c= onfig=3D2\000\00000\000\000 */ +{ 5 }, /* duration_time\000tool\000Wall clock interval time in nanoseconds= \000config=3D1\000\00000\000\000\000\000\000 */ +{ 219 }, /* has_pmem\000tool\0001 if persistent memory installed otherwise= 0\000config=3D4\000\00000\000\000\000\000\000 */ +{ 295 }, /* num_cores\000tool\000Number of cores. A core consists of 1 or = more thread, with each thread being associated with a logical Linux CPU\000= config=3D5\000\00000\000\000\000\000\000 */ +{ 440 }, /* num_cpus\000tool\000Number of logical Linux CPUs. There may be= multiple such CPUs on a core\000config=3D6\000\00000\000\000\000\000\000 */ +{ 543 }, /* num_cpus_online\000tool\000Number of online logical Linux CPUs= . There may be multiple such CPUs on a core\000config=3D7\000\00000\000\000= \000\000\000 */ +{ 660 }, /* num_dies\000tool\000Number of dies. Each die has 1 or more cor= es\000config=3D8\000\00000\000\000\000\000\000 */ +{ 736 }, /* num_packages\000tool\000Number of packages. Each package has 1= or more die\000config=3D9\000\00000\000\000\000\000\000 */ +{ 822 }, /* slots\000tool\000Number of functional units that in parallel c= an execute parts of an instruction\000config=3D0xa\000\00000\000\000\000\00= 0\000 */ +{ 932 }, /* smt_on\000tool\0001 if simultaneous multithreading (aka hypert= hreading) is enable otherwise 0\000config=3D0xb\000\00000\000\000\000\000\0= 00 */ +{ 151 }, /* system_time\000tool\000System/kernel time in nanoseconds\000co= nfig=3D3\000\00000\000\000\000\000\000 */ +{ 1039 }, /* system_tsc_freq\000tool\000The amount a Time Stamp Counter (T= SC) increases per second\000config=3D0xc\000\00000\000\000\000\000\000 */ +{ 81 }, /* user_time\000tool\000User (non-kernel) time in nanoseconds\000c= onfig=3D2\000\00000\000\000\000\000\000 */ =20 }; =20 @@ -99,29 +99,29 @@ const struct pmu_table_entry pmu_events__common[] =3D { }; =20 static const struct compact_pmu_event pmu_events__test_soc_cpu_default_cor= e[] =3D { -{ 1115 }, /* bp_l1_btb_correct\000branch\000L1 BTB Correction\000event=3D0= x8a\000\00000\000\000 */ -{ 1174 }, /* bp_l2_btb_correct\000branch\000L2 BTB Correction\000event=3D0= x8b\000\00000\000\000 */ -{ 1427 }, /* dispatch_blocked.any\000other\000Memory cluster signals to bl= ock micro-op dispatch for any reason\000event=3D9,period=3D200000,umask=3D0= x20\000\00000\000\000 */ -{ 1557 }, /* eist_trans\000other\000Number of Enhanced Intel SpeedStep(R) = Technology (EIST) transitions\000event=3D0x3a,period=3D200000\000\00000\000= \000 */ -{ 1233 }, /* l3_cache_rd\000cache\000L3 cache access, read\000event=3D0x40= \000\00000\000Attributable Level 3 cache access, read\000 */ -{ 1328 }, /* segment_reg_loads.any\000other\000Number of segment register = loads\000event=3D6,period=3D200000,umask=3D0x80\000\00000\000\000 */ +{ 1151 }, /* bp_l1_btb_correct\000branch\000L1 BTB Correction\000event=3D0= x8a\000\00000\000\000\000\000\000 */ +{ 1213 }, /* bp_l2_btb_correct\000branch\000L2 BTB Correction\000event=3D0= x8b\000\00000\000\000\000\000\000 */ +{ 1475 }, /* dispatch_blocked.any\000other\000Memory cluster signals to bl= ock micro-op dispatch for any reason\000event=3D9,period=3D200000,umask=3D0= x20\000\00000\000\000\000\000\000 */ +{ 1608 }, /* eist_trans\000other\000Number of Enhanced Intel SpeedStep(R) = Technology (EIST) transitions\000event=3D0x3a,period=3D200000\000\00000\000= \000\000\000\000 */ +{ 1275 }, /* l3_cache_rd\000cache\000L3 cache access, read\000event=3D0x40= \000\00000\000\000\000\000Attributable Level 3 cache access, read\000 */ +{ 1373 }, /* segment_reg_loads.any\000other\000Number of segment register = loads\000event=3D6,period=3D200000,umask=3D0x80\000\00000\000\000\000\000\0= 00 */ }; static const struct compact_pmu_event pmu_events__test_soc_cpu_hisi_sccl_d= drc[] =3D { -{ 1687 }, /* uncore_hisi_ddrc.flux_wcmd\000uncore\000DDRC write commands\0= 00event=3D2\000\00000\000DDRC write commands\000 */ +{ 1741 }, /* uncore_hisi_ddrc.flux_wcmd\000uncore\000DDRC write commands\0= 00event=3D2\000\00000\000\000\000\000DDRC write commands\000 */ }; static const struct compact_pmu_event pmu_events__test_soc_cpu_hisi_sccl_l= 3c[] =3D { -{ 2166 }, /* uncore_hisi_l3c.rd_hit_cpipe\000uncore\000Total read hits\000= event=3D7\000\00000\000Total read hits\000 */ +{ 2232 }, /* uncore_hisi_l3c.rd_hit_cpipe\000uncore\000Total read hits\000= event=3D7\000\00000\000\000\000\000Total read hits\000 */ }; static const struct compact_pmu_event pmu_events__test_soc_cpu_uncore_cbox= [] =3D { -{ 2016 }, /* event-hyphen\000uncore\000UNC_CBO_HYPHEN\000event=3D0xe0\000\= 00000\000UNC_CBO_HYPHEN\000 */ -{ 2081 }, /* event-two-hyph\000uncore\000UNC_CBO_TWO_HYPH\000event=3D0xc0\= 000\00000\000UNC_CBO_TWO_HYPH\000 */ -{ 1785 }, /* unc_cbo_xsnp_response.miss_eviction\000uncore\000A cross-core= snoop resulted from L3 Eviction which misses in some processor core\000eve= nt=3D0x22,umask=3D0x81\000\00000\000A cross-core snoop resulted from L3 Evi= ction which misses in some processor core\000 */ +{ 2076 }, /* event-hyphen\000uncore\000UNC_CBO_HYPHEN\000event=3D0xe0\000\= 00000\000\000\000\000UNC_CBO_HYPHEN\000 */ +{ 2144 }, /* event-two-hyph\000uncore\000UNC_CBO_TWO_HYPH\000event=3D0xc0\= 000\00000\000\000\000\000UNC_CBO_TWO_HYPH\000 */ +{ 1842 }, /* unc_cbo_xsnp_response.miss_eviction\000uncore\000A cross-core= snoop resulted from L3 Eviction which misses in some processor core\000eve= nt=3D0x22,umask=3D0x81\000\00000\000\000\000\000A cross-core snoop resulted= from L3 Eviction which misses in some processor core\000 */ }; static const struct compact_pmu_event pmu_events__test_soc_cpu_uncore_imc[= ] =3D { -{ 2376 }, /* uncore_imc.cache_hits\000uncore\000Total cache hits\000event= =3D0x34\000\00000\000Total cache hits\000 */ +{ 2448 }, /* uncore_imc.cache_hits\000uncore\000Total cache hits\000event= =3D0x34\000\00000\000\000\000\000Total cache hits\000 */ }; static const struct compact_pmu_event pmu_events__test_soc_cpu_uncore_imc_= free_running[] =3D { -{ 2270 }, /* uncore_imc_free_running.cache_miss\000uncore\000Total cache m= isses\000event=3D0x12\000\00000\000Total cache misses\000 */ +{ 2339 }, /* uncore_imc_free_running.cache_miss\000uncore\000Total cache m= isses\000event=3D0x12\000\00000\000\000\000\000Total cache misses\000 */ =20 }; =20 @@ -129,51 +129,51 @@ const struct pmu_table_entry pmu_events__test_soc_cpu= [] =3D { { .entries =3D pmu_events__test_soc_cpu_default_core, .num_entries =3D ARRAY_SIZE(pmu_events__test_soc_cpu_default_core), - .pmu_name =3D { 1102 /* default_core\000 */ }, + .pmu_name =3D { 1138 /* default_core\000 */ }, }, { .entries =3D pmu_events__test_soc_cpu_hisi_sccl_ddrc, .num_entries =3D ARRAY_SIZE(pmu_events__test_soc_cpu_hisi_sccl_ddrc), - .pmu_name =3D { 1672 /* hisi_sccl,ddrc\000 */ }, + .pmu_name =3D { 1726 /* hisi_sccl,ddrc\000 */ }, }, { .entries =3D pmu_events__test_soc_cpu_hisi_sccl_l3c, .num_entries =3D ARRAY_SIZE(pmu_events__test_soc_cpu_hisi_sccl_l3c), - .pmu_name =3D { 2152 /* hisi_sccl,l3c\000 */ }, + .pmu_name =3D { 2218 /* hisi_sccl,l3c\000 */ }, }, { .entries =3D pmu_events__test_soc_cpu_uncore_cbox, .num_entries =3D ARRAY_SIZE(pmu_events__test_soc_cpu_uncore_cbox), - .pmu_name =3D { 1773 /* uncore_cbox\000 */ }, + .pmu_name =3D { 1830 /* uncore_cbox\000 */ }, }, { .entries =3D pmu_events__test_soc_cpu_uncore_imc, .num_entries =3D ARRAY_SIZE(pmu_events__test_soc_cpu_uncore_imc), - .pmu_name =3D { 2365 /* uncore_imc\000 */ }, + .pmu_name =3D { 2437 /* uncore_imc\000 */ }, }, { .entries =3D pmu_events__test_soc_cpu_uncore_imc_free_running, .num_entries =3D ARRAY_SIZE(pmu_events__test_soc_cpu_uncore_imc_free_= running), - .pmu_name =3D { 2246 /* uncore_imc_free_running\000 */ }, + .pmu_name =3D { 2315 /* uncore_imc_free_running\000 */ }, }, }; =20 static const struct compact_pmu_event pmu_metrics__test_soc_cpu_default_co= re[] =3D { -{ 2798 }, /* CPI\000\0001 / IPC\000\000\000\000\000\000\000\00000 */ -{ 3479 }, /* DCache_L2_All\000\000DCache_L2_All_Hits + DCache_L2_All_Miss\= 000\000\000\000\000\000\000\00000 */ -{ 3251 }, /* DCache_L2_All_Hits\000\000l2_rqsts.demand_data_rd_hit + l2_rq= sts.pf_hit + l2_rqsts.rfo_hit\000\000\000\000\000\000\000\00000 */ -{ 3345 }, /* DCache_L2_All_Miss\000\000max(l2_rqsts.all_demand_data_rd - l= 2_rqsts.demand_data_rd_hit, 0) + l2_rqsts.pf_miss + l2_rqsts.rfo_miss\000\0= 00\000\000\000\000\000\00000 */ -{ 3543 }, /* DCache_L2_Hits\000\000d_ratio(DCache_L2_All_Hits, DCache_L2_A= ll)\000\000\000\000\000\000\000\00000 */ -{ 3611 }, /* DCache_L2_Misses\000\000d_ratio(DCache_L2_All_Miss, DCache_L2= _All)\000\000\000\000\000\000\000\00000 */ -{ 2883 }, /* Frontend_Bound_SMT\000\000idq_uops_not_delivered.core / (4 * = (cpu_clk_unhalted.thread / 2 * (1 + cpu_clk_unhalted.one_thread_active / cp= u_clk_unhalted.ref_xclk)))\000\000\000\000\000\000\000\00000 */ -{ 2820 }, /* IPC\000group1\000inst_retired.any / cpu_clk_unhalted.thread\0= 00\000\000\000\000\000\000\00000 */ -{ 3745 }, /* L1D_Cache_Fill_BW\000\00064 * l1d.replacement / 1e9 / duratio= n_time\000\000\000\000\000\000\000\00000 */ -{ 3681 }, /* M1\000\000ipc + M2\000\000\000\000\000\000\000\00000 */ -{ 3703 }, /* M2\000\000ipc + M1\000\000\000\000\000\000\000\00000 */ -{ 3725 }, /* M3\000\0001 / M3\000\000\000\000\000\000\000\00000 */ -{ 3180 }, /* cache_miss_cycles\000group1\000dcache_miss_cpi + icache_miss_= cycles\000\000\000\000\000\000\000\00000 */ -{ 3049 }, /* dcache_miss_cpi\000\000l1d\\-loads\\-misses / inst_retired.an= y\000\000\000\000\000\000\000\00000 */ -{ 3113 }, /* icache_miss_cycles\000\000l1i\\-loads\\-misses / inst_retired= .any\000\000\000\000\000\000\000\00000 */ +{ 2882 }, /* CPI\000\0001 / IPC\000\000\000\000\000\000\000\00000 */ +{ 3563 }, /* DCache_L2_All\000\000DCache_L2_All_Hits + DCache_L2_All_Miss\= 000\000\000\000\000\000\000\00000 */ +{ 3335 }, /* DCache_L2_All_Hits\000\000l2_rqsts.demand_data_rd_hit + l2_rq= sts.pf_hit + l2_rqsts.rfo_hit\000\000\000\000\000\000\000\00000 */ +{ 3429 }, /* DCache_L2_All_Miss\000\000max(l2_rqsts.all_demand_data_rd - l= 2_rqsts.demand_data_rd_hit, 0) + l2_rqsts.pf_miss + l2_rqsts.rfo_miss\000\0= 00\000\000\000\000\000\00000 */ +{ 3627 }, /* DCache_L2_Hits\000\000d_ratio(DCache_L2_All_Hits, DCache_L2_A= ll)\000\000\000\000\000\000\000\00000 */ +{ 3695 }, /* DCache_L2_Misses\000\000d_ratio(DCache_L2_All_Miss, DCache_L2= _All)\000\000\000\000\000\000\000\00000 */ +{ 2967 }, /* Frontend_Bound_SMT\000\000idq_uops_not_delivered.core / (4 * = (cpu_clk_unhalted.thread / 2 * (1 + cpu_clk_unhalted.one_thread_active / cp= u_clk_unhalted.ref_xclk)))\000\000\000\000\000\000\000\00000 */ +{ 2904 }, /* IPC\000group1\000inst_retired.any / cpu_clk_unhalted.thread\0= 00\000\000\000\000\000\000\00000 */ +{ 3829 }, /* L1D_Cache_Fill_BW\000\00064 * l1d.replacement / 1e9 / duratio= n_time\000\000\000\000\000\000\000\00000 */ +{ 3765 }, /* M1\000\000ipc + M2\000\000\000\000\000\000\000\00000 */ +{ 3787 }, /* M2\000\000ipc + M1\000\000\000\000\000\000\000\00000 */ +{ 3809 }, /* M3\000\0001 / M3\000\000\000\000\000\000\000\00000 */ +{ 3264 }, /* cache_miss_cycles\000group1\000dcache_miss_cpi + icache_miss_= cycles\000\000\000\000\000\000\000\00000 */ +{ 3133 }, /* dcache_miss_cpi\000\000l1d\\-loads\\-misses / inst_retired.an= y\000\000\000\000\000\000\000\00000 */ +{ 3197 }, /* icache_miss_cycles\000\000l1i\\-loads\\-misses / inst_retired= .any\000\000\000\000\000\000\000\00000 */ =20 }; =20 @@ -181,18 +181,18 @@ const struct pmu_table_entry pmu_metrics__test_soc_cp= u[] =3D { { .entries =3D pmu_metrics__test_soc_cpu_default_core, .num_entries =3D ARRAY_SIZE(pmu_metrics__test_soc_cpu_default_core), - .pmu_name =3D { 1102 /* default_core\000 */ }, + .pmu_name =3D { 1138 /* default_core\000 */ }, }, }; =20 static const struct compact_pmu_event pmu_events__test_soc_sys_uncore_sys_= ccn_pmu[] =3D { -{ 2565 }, /* sys_ccn_pmu.read_cycles\000uncore\000ccn read-cycles event\00= 0config=3D0x2c\0000x01\00000\000\000 */ +{ 2643 }, /* sys_ccn_pmu.read_cycles\000uncore\000ccn read-cycles event\00= 0config=3D0x2c\0000x01\00000\000\000\000\000\000 */ }; static const struct compact_pmu_event pmu_events__test_soc_sys_uncore_sys_= cmn_pmu[] =3D { -{ 2658 }, /* sys_cmn_pmu.hnf_cache_miss\000uncore\000Counts total cache mi= sses in first lookup result (high priority)\000eventid=3D1,type=3D5\000(434= |436|43c|43a).*\00000\000\000 */ +{ 2739 }, /* sys_cmn_pmu.hnf_cache_miss\000uncore\000Counts total cache mi= sses in first lookup result (high priority)\000eventid=3D1,type=3D5\000(434= |436|43c|43a).*\00000\000\000\000\000\000 */ }; static const struct compact_pmu_event pmu_events__test_soc_sys_uncore_sys_= ddr_pmu[] =3D { -{ 2473 }, /* sys_ddr_pmu.write_cycles\000uncore\000ddr write-cycles event\= 000event=3D0x2b\000v8\00000\000\000 */ +{ 2548 }, /* sys_ddr_pmu.write_cycles\000uncore\000ddr write-cycles event\= 000event=3D0x2b\000v8\00000\000\000\000\000\000 */ =20 }; =20 @@ -200,17 +200,17 @@ const struct pmu_table_entry pmu_events__test_soc_sys= [] =3D { { .entries =3D pmu_events__test_soc_sys_uncore_sys_ccn_pmu, .num_entries =3D ARRAY_SIZE(pmu_events__test_soc_sys_uncore_sys_ccn_p= mu), - .pmu_name =3D { 2546 /* uncore_sys_ccn_pmu\000 */ }, + .pmu_name =3D { 2624 /* uncore_sys_ccn_pmu\000 */ }, }, { .entries =3D pmu_events__test_soc_sys_uncore_sys_cmn_pmu, .num_entries =3D ARRAY_SIZE(pmu_events__test_soc_sys_uncore_sys_cmn_p= mu), - .pmu_name =3D { 2639 /* uncore_sys_cmn_pmu\000 */ }, + .pmu_name =3D { 2720 /* uncore_sys_cmn_pmu\000 */ }, }, { .entries =3D pmu_events__test_soc_sys_uncore_sys_ddr_pmu, .num_entries =3D ARRAY_SIZE(pmu_events__test_soc_sys_uncore_sys_ddr_p= mu), - .pmu_name =3D { 2454 /* uncore_sys_ddr_pmu\000 */ }, + .pmu_name =3D { 2529 /* uncore_sys_ddr_pmu\000 */ }, }, }; =20 @@ -316,6 +316,12 @@ static void decompress_event(int offset, struct pmu_ev= ent *pe) p++; pe->unit =3D (*p =3D=3D '\0' ? NULL : p); while (*p++); + pe->retirement_latency_mean =3D (*p =3D=3D '\0' ? NULL : p); + while (*p++); + pe->retirement_latency_min =3D (*p =3D=3D '\0' ? NULL : p); + while (*p++); + pe->retirement_latency_max =3D (*p =3D=3D '\0' ? NULL : p); + while (*p++); pe->long_desc =3D (*p =3D=3D '\0' ? NULL : p); } =20 diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jeven= ts.py index 7499a35bfadd..e3a55486c08e 100755 --- a/tools/perf/pmu-events/jevents.py +++ b/tools/perf/pmu-events/jevents.py @@ -47,6 +47,9 @@ _json_event_attributes =3D [ 'event', # Short things in alphabetical order. 'compat', 'deprecated', 'perpkg', 'unit', + # Retirement latency specific to Intel granite rapids currently. + 'retirement_latency_mean', 'retirement_latency_min', + 'retirement_latency_max', # Longer things (the last won't be iterated over during decompress). 'long_desc' ] @@ -341,6 +344,9 @@ class JsonEvent: self.perpkg =3D jd.get('PerPkg') self.aggr_mode =3D convert_aggr_mode(jd.get('AggregationMode')) self.deprecated =3D jd.get('Deprecated') + self.retirement_latency_mean =3D jd.get('RetirementLatencyMean') + self.retirement_latency_min =3D jd.get('RetirementLatencyMin') + self.retirement_latency_max =3D jd.get('RetirementLatencyMax') self.metric_name =3D jd.get('MetricName') self.metric_group =3D jd.get('MetricGroup') self.metricgroup_no_group =3D jd.get('MetricgroupNoGroup') diff --git a/tools/perf/pmu-events/pmu-events.h b/tools/perf/pmu-events/pmu= -events.h index 675562e6f770..a95fee561622 100644 --- a/tools/perf/pmu-events/pmu-events.h +++ b/tools/perf/pmu-events/pmu-events.h @@ -47,6 +47,9 @@ struct pmu_event { const char *long_desc; const char *pmu; const char *unit; + const char *retirement_latency_mean; + const char *retirement_latency_min; + const char *retirement_latency_max; bool perpkg; bool deprecated; }; diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index aae431d63d64..42dcadfef8ce 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -177,6 +177,12 @@ struct evsel { /* For tool events */ /* Beginning time subtracted when the counter is read. */ union { + /* Defaults for retirement latency events. */ + struct _retirement_latency { + double mean; + double min; + double max; + } retirement_latency; /* duration_time is a single global time. */ __u64 start_time; /* diff --git a/tools/perf/util/intel-tpebs.c b/tools/perf/util/intel-tpebs.c index 5a255eb4f057..6295103400ee 100644 --- a/tools/perf/util/intel-tpebs.c +++ b/tools/perf/util/intel-tpebs.c @@ -508,29 +508,48 @@ int evsel__tpebs_read(struct evsel *evsel, int cpu_ma= p_idx, int thread) * process. Allow the sample reader a chance to read by releasing and * reacquiring the lock. */ - if (&t->nd =3D=3D tpebs_results.next) { + if (t && &t->nd =3D=3D tpebs_results.next) { ret =3D tpebs_send_record_cmd(EVLIST_CTL_CMD_PING_TAG); mutex_unlock(tpebs_mtx_get()); if (ret) return ret; mutex_lock(tpebs_mtx_get()); } - switch (tpebs_mode) { - case TPEBS_MODE__MIN: - val =3D rint(t->stats.mean); - break; - case TPEBS_MODE__MAX: - val =3D rint(t->stats.mean); - break; - case TPEBS_MODE__LAST: - val =3D t->last; - break; - default: - case TPEBS_MODE__MEAN: - val =3D rint(t->stats.mean); - break; + if (t =3D=3D NULL || t->stats.n !=3D 0) { + /* No sample data, use default. */ + mutex_unlock(tpebs_mtx_get()); + val =3D 0; + switch (tpebs_mode) { + case TPEBS_MODE__MIN: + val =3D rint(evsel->retirement_latency.min); + break; + case TPEBS_MODE__MAX: + val =3D rint(evsel->retirement_latency.max); + break; + default: + case TPEBS_MODE__LAST: + case TPEBS_MODE__MEAN: + val =3D rint(evsel->retirement_latency.mean); + break; + } + } else { + switch (tpebs_mode) { + case TPEBS_MODE__MIN: + val =3D rint(t->stats.mean); + break; + case TPEBS_MODE__MAX: + val =3D rint(t->stats.mean); + break; + case TPEBS_MODE__LAST: + val =3D t->last; + break; + default: + case TPEBS_MODE__MEAN: + val =3D rint(t->stats.mean); + break; + } + mutex_unlock(tpebs_mtx_get()); } - mutex_unlock(tpebs_mtx_get()); =20 if (old_count) { count->val =3D old_count->val + val; diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 5152fd5a6ead..89708d1769c8 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -1539,6 +1539,10 @@ static int parse_events_add_pmu(struct parse_events_= state *parse_state, evsel->scale =3D info.scale; evsel->per_pkg =3D info.per_pkg; evsel->snapshot =3D info.snapshot; + evsel->retirement_latency.mean =3D info.retirement_latency_mean; + evsel->retirement_latency.min =3D info.retirement_latency_min; + evsel->retirement_latency.max =3D info.retirement_latency_max; + return 0; } =20 diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index b7ebac5ab1d1..bbb906bb2159 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -77,6 +77,12 @@ struct perf_pmu_alias { char unit[UNIT_MAX_LEN+1]; /** @scale: Value to scale read counter values by. */ double scale; + /** @retirement_latency_mean: Value to be given for unsampled retirement = latency mean. */ + double retirement_latency_mean; + /** @retirement_latency_min: Value to be given for unsampled retirement l= atency min. */ + double retirement_latency_min; + /** @retirement_latency_max: Value to be given for unsampled retirement l= atency max. */ + double retirement_latency_max; /** * @per_pkg: Does the file * /bus/event_source/devices//events/.per-pkg or @@ -257,7 +263,7 @@ static int pmu_format(struct perf_pmu *pmu, int dirfd, = const char *name, bool ea return 0; } =20 -int perf_pmu__convert_scale(const char *scale, char **end, double *sval) +static int parse_double(const char *scale, char **end, double *sval) { char *lc; int ret =3D 0; @@ -294,6 +300,11 @@ int perf_pmu__convert_scale(const char *scale, char **= end, double *sval) return ret; } =20 +int perf_pmu__convert_scale(const char *scale, char **end, double *sval) +{ + return parse_double(scale, end, sval); +} + static int perf_pmu__parse_scale(struct perf_pmu *pmu, struct perf_pmu_ali= as *alias) { struct stat st; @@ -525,6 +536,18 @@ static int update_alias(const struct pmu_event *pe, if (!ret) snprintf(data->alias->unit, sizeof(data->alias->unit), "%s", unit); } + if (!ret && pe->retirement_latency_mean) { + ret =3D parse_double(pe->retirement_latency_mean, NULL, + &data->alias->retirement_latency_mean); + } + if (!ret && pe->retirement_latency_min) { + ret =3D parse_double(pe->retirement_latency_min, NULL, + &data->alias->retirement_latency_min); + } + if (!ret && pe->retirement_latency_max) { + ret =3D parse_double(pe->retirement_latency_max, NULL, + &data->alias->retirement_latency_max); + } return ret; } =20 @@ -533,7 +556,7 @@ static int perf_pmu__new_alias(struct perf_pmu *pmu, co= nst char *name, const struct pmu_event *pe, enum event_source src) { struct perf_pmu_alias *alias; - int ret; + int ret =3D 0; const char *long_desc =3D NULL, *topic =3D NULL, *unit =3D NULL, *pmu_nam= e =3D NULL; bool deprecated =3D false, perpkg =3D false; =20 @@ -562,6 +585,24 @@ static int perf_pmu__new_alias(struct perf_pmu *pmu, c= onst char *name, alias->per_pkg =3D perpkg; alias->snapshot =3D false; alias->deprecated =3D deprecated; + alias->retirement_latency_mean =3D 0.0; + alias->retirement_latency_min =3D 0.0; + alias->retirement_latency_max =3D 0.0; + + if (!ret && pe && pe->retirement_latency_mean) { + ret =3D parse_double(pe->retirement_latency_mean, NULL, + &alias->retirement_latency_mean); + } + if (!ret && pe && pe->retirement_latency_min) { + ret =3D parse_double(pe->retirement_latency_min, NULL, + &alias->retirement_latency_min); + } + if (!ret && pe && pe->retirement_latency_max) { + ret =3D parse_double(pe->retirement_latency_max, NULL, + &alias->retirement_latency_max); + } + if (ret) + return ret; =20 ret =3D parse_events_terms(&alias->terms, val, val_fd); if (ret) { @@ -1678,6 +1719,9 @@ int perf_pmu__check_alias(struct perf_pmu *pmu, struc= t parse_events_terms *head_ info->unit =3D NULL; info->scale =3D 0.0; info->snapshot =3D false; + info->retirement_latency_mean =3D 0.0; + info->retirement_latency_min =3D 0.0; + info->retirement_latency_max =3D 0.0; =20 if (perf_pmu__is_hwmon(pmu)) { ret =3D hwmon_pmu__check_alias(head_terms, info, err); @@ -1711,6 +1755,10 @@ int perf_pmu__check_alias(struct perf_pmu *pmu, stru= ct parse_events_terms *head_ if (term->alternate_hw_config) *alternate_hw_config =3D term->val.num; =20 + info->retirement_latency_mean =3D alias->retirement_latency_mean; + info->retirement_latency_min =3D alias->retirement_latency_min; + info->retirement_latency_max =3D alias->retirement_latency_max; + list_del_init(&term->list); parse_events_term__delete(term); } diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index b93014cc3670..13dd3511f504 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -194,6 +194,9 @@ struct perf_pmu { struct perf_pmu_info { const char *unit; double scale; + double retirement_latency_mean; + double retirement_latency_min; + double retirement_latency_max; bool per_pkg; bool snapshot; }; --=20 2.49.0.395.g12beb8f557-goog