Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp270094lqb; Tue, 28 May 2024 15:17:20 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXv9epOT9yKmaL5Vyxvqw+HNEAhbE6/gsY1YAtB0zXG15lSNHCZNFnC578uX9j6+U3xVgtVs8HR3E8XbSACVREp+TE2NBq+TD0MvcMhHg== X-Google-Smtp-Source: AGHT+IH2GnUWiEVL9yi90sDI7J04vfuvXUlmLhSSrWTsuMQJPW/Aag2OJ4tN1i2O5etUJFckm1xO X-Received: by 2002:ac8:7c49:0:b0:43a:e066:b926 with SMTP id d75a77b69052e-43fb0e8d655mr138142941cf.65.1716934640673; Tue, 28 May 2024 15:17:20 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716934640; cv=pass; d=google.com; s=arc-20160816; b=zr2n9gO4HgxwGFaGgIGN5EyE5IAXnaGHgtKpBxPS0TiqjSKR2w/Xw5xpvrdW5KLCVD L19VXjjxSR77jBlp1gNoTeFsprLavQMOSuKigQlJvVXCtjeW8JjWrXAdDccOE6lhxs2J brhW33uJQikZhdomSxGPbzbEyCJJI563O5mujbNomBqe6wvKG5SZkE6/8Mm7Uc2fIgAs 6CFEiaWIRCh5Lzw/Y/0jrLiFVU1mVJXE31vN6ipUD8FM74IX0WA4YDa7sdoW1HR260A8 sIXj6FP9W8rAlT5vlN0nA8ZDN6pgJZfCzwidotILuCXGstUI951lZWRLlC8sl7UF5dBA Wzfw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=KKsx1Wjb37gHKeRHMU40MydeR/ELp98IEnmlde48+So=; fh=vYLQ8zZhvJ44dKeY/Aih8mJWrPp9tga7vfclyw5ZIqw=; b=Iov700v3Y+gq7G5r5Vhizu5/FElyoh7E59x/dpPrKLYtQoAzSJBrU0ZBCVpSokydEM m64l7/z/zEWRX4VtSgLu2Q2FLokQ7vYgMvgEo9Zk0hzvqFUQyxgCICTPcGt1R9vYgRrJ OfXj4XjFjolaIB42SRH8v5MafAGS2p1Ou3JNxW86FpbGtR3Au/Ap1E/SWOrOMXE3CtSc T1bDbC/huD9obnC0sqc+C7OhouYBGjq27X5h7+8L0CGeoXzG1yRtXgjxwfuXRDrj6MSU CxO2SvOfy2BhBjqWMjjOMnrW18PmRCRuxt+q5eqxtPD99TOgS5Mw666a53QUAuzAhmjp DtRA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=uhrsXZxN; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-193151-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-193151-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id d75a77b69052e-43fb18c7ef7si111179651cf.626.2024.05.28.15.17.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 15:17:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-193151-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=uhrsXZxN; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-193151-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-193151-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 586381C23524 for ; Tue, 28 May 2024 22:17:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 812BF13DDD1; Tue, 28 May 2024 22:17:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="uhrsXZxN" Received: from mail-qt1-f182.google.com (mail-qt1-f182.google.com [209.85.160.182]) (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 9D9F928DC7 for ; Tue, 28 May 2024 22:17:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716934633; cv=none; b=XA0E5fHdhIFEB8Ar47d9SYjS0lNeKEUKk/crEKtCGG5nhuqe+RVVT3jxjCbiTetScIv4gyQi/CCQNpcrewbdoDSi32SspKMF6Eo3ey4aFkCY2JZ0eDnJTsaicoKwUtxJDSoHtw07P6OPrnsdi8NT7zK9yUd+z+pqJTvl0sGZ9/Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716934633; c=relaxed/simple; bh=KgxKy3B9/bvHCk1XIcrOxAdTViZHUFvaiD1OLQpr4sE=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=vD4dMs1W9wY4X45RuJBbGuxY565f5AWpytRUnbfqilNyApIT2Dydt6ZKWp2itNf/GyFIDQz3Pdx56LJZaDkbnhYt2yVhjo76R1MDuLauRclfY6HVgZvz386B5q3w/4f/cN3elYekMpK9BCkOdCl1+npuwvPCVn7z+OZcP92rEDU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=uhrsXZxN; arc=none smtp.client-ip=209.85.160.182 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=google.com Received: by mail-qt1-f182.google.com with SMTP id d75a77b69052e-43dfe020675so193621cf.0 for ; Tue, 28 May 2024 15:17:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1716934630; x=1717539430; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=KKsx1Wjb37gHKeRHMU40MydeR/ELp98IEnmlde48+So=; b=uhrsXZxNa3RFXafIfe+U2Ltq6bS7DneRc5jPRc37O1O6XONs2lgWFsmXVbBVcs7nBY 6KHhcxVxXuy3I/1T3dyC/xBPnI/HO0m/4/a8/D6hTRsIScprEPKYxeAqqMzgPm6B1Xge jMak/ihiTv0r1wooaj8+tY4XaVUG2umuTGuVtPXDVqBAn4J8g9gGz9AYRNXGzDMTjIqV XX+T0kJ0euoLcy+n5GuOPYrw4UM263StVinX0ot4LwxcDK6Ji6fw6UCf7NTh0Lm8/25S Uh2wYXocCrXpSFT5PoEtTb2K0BBr+EOfPKFU37wgUdjhUt2TeWf3eajjqB4xGz1Gcqdq oGEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716934630; x=1717539430; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KKsx1Wjb37gHKeRHMU40MydeR/ELp98IEnmlde48+So=; b=cKDPCA9BxIH2V5McesLj0YmUmzYvyxCUzQ9/krBqv9F9NkSPNPLtLM8relUHUr5TDT SsDMZvayE5vNHqmGeogBJ2ZAHFFgkhbOaZ2EfWMVdNWTACBbuDwkg6lof/19TeG/zA7L kx8SmyU3VtFpLn27ZZBNyKBfWhhmc8MwpcoGZxMuToV22lz+fuojns9nRcT/8eFLoeSN rNG6ul9JyhUOUd6QRMJfLUw5KjEH8YlRdDVeX8Vz7weWSsg+AW0OTXM85B75Gh1YLfy5 OoDFVW8Ylm5bgQwArEeDLhyUKjHDCawtXJ+x6EzALbO3T6zwieN7IlrYq5ecnjqvf68T HHqw== X-Forwarded-Encrypted: i=1; AJvYcCVjI4C8i2cv8Mm1wAY9aQm+ahrqEtzFXLcEkzm1/8o5+LOHyGF3TS+YEJdOIPFS4EDMTP/UbcMnyMtZmUJulYRIKU0KHlGfpML+5loC X-Gm-Message-State: AOJu0YzHYsCc3Ew85gXBD4svwcXQAccsdWd8oH+gb0Qib+QfroquLyEd EviE00/5pUeZ1/IMFf/3bAilR52Hfo2bH4tVqm+LlHe+qA5jD4PmhKUywEFZmSXsoYKtZs5ejsx 3bee8wofq5XJoQhevIjfxmmb1dXr7ZOyEAtJ1 X-Received: by 2002:a05:622a:4819:b0:43f:bb44:bbb7 with SMTP id d75a77b69052e-43fe0f4cefamr851191cf.8.1716934630467; Tue, 28 May 2024 15:17:10 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240521173952.3397644-1-weilin.wang@intel.com> <20240521173952.3397644-5-weilin.wang@intel.com> In-Reply-To: From: Ian Rogers Date: Tue, 28 May 2024 15:16:58 -0700 Message-ID: Subject: Re: [RFC PATCH v9 4/7] perf stat: Plugin retire_lat value from sampled data to evsel To: Namhyung Kim Cc: "Wang, Weilin" , Arnaldo Carvalho de Melo , Peter Zijlstra , Ingo Molnar , Alexander Shishkin , Jiri Olsa , "Hunter, Adrian" , Kan Liang , "linux-perf-users@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "Taylor, Perry" , "Alt, Samantha" , "Biggers, Caleb" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sun, May 26, 2024 at 11:01=E2=80=AFAM Namhyung Kim = wrote: > > On Fri, May 24, 2024 at 4:52=E2=80=AFPM Wang, Weilin wrote: > > > > > > > > > -----Original Message----- > > > From: Namhyung Kim > > > Sent: Friday, May 24, 2024 4:17 PM > > > To: Wang, Weilin > > > Cc: Ian Rogers ; Arnaldo Carvalho de Melo > > > ; Peter Zijlstra ; Ingo Molnar > > > ; Alexander Shishkin > > > ; Jiri Olsa ; H= unter, > > > Adrian ; Kan Liang ; > > > linux-perf-users@vger.kernel.org; linux-kernel@vger.kernel.org; Taylo= r, Perry > > > ; Alt, Samantha ; Big= gers, > > > Caleb > > > Subject: Re: [RFC PATCH v9 4/7] perf stat: Plugin retire_lat value fr= om sampled > > > data to evsel > > > > > > On Tue, May 21, 2024 at 10:40=E2=80=AFAM wrot= e: > > > > > > > > From: Weilin Wang > > > > > > > > In current :R parsing implementation, the parser would recognize ev= ents > > > with > > > > retire_latency modifier and insert them into the evlist like a norm= al event. > > > > Ideally, we need to avoid counting these events. > > > > > > > > In this commit, at the time when a retire_latency evsel is read, se= t the retire > > > > latency value processed from the sampled data to count value. This = sampled > > > > retire latency value will be used for metric calculation and final = event count > > > > print out. > > > > > > I'm confused. Do you mean you don't count the event with 'R' modifie= r > > > (w/ perf stat) and just print the (average) retire latency (from perf= record)? > > > > In metric formulas, event without 'R' modifier is included as a normal = event already. > > So we don't need to count the event that with 'R' modifier. They only n= eed to be > > sampled. > > Oh, you have the event in the metric expression twice. I thought of one. > Then IIUC the metric looks something like this. > > myevent1 + (myevent2 * myevent1:R) > > I think you'll have 2 myevent1 in perf stat and 1 in perf record, right? > But the second one in perf stat is never used and the value is updated > from perf record. > > Then we can simply remove the event from the evlist (or replace it with > a dummy) to reduce the overheads (of open and read). > > > > > > > > > > > > > > Signed-off-by: Weilin Wang > > > > --- > > > > tools/perf/arch/x86/util/evlist.c | 6 +++++ > > > > tools/perf/util/evsel.c | 44 +++++++++++++++++++++++++++= ++++ > > > > tools/perf/util/evsel.h | 5 ++++ > > > > 3 files changed, 55 insertions(+) > > > > > > > > diff --git a/tools/perf/arch/x86/util/evlist.c > > > b/tools/perf/arch/x86/util/evlist.c > > > > index b1ce0c52d88d..cebdd483149e 100644 > > > > --- a/tools/perf/arch/x86/util/evlist.c > > > > +++ b/tools/perf/arch/x86/util/evlist.c > > > > @@ -89,6 +89,12 @@ int arch_evlist__cmp(const struct evsel *lhs, co= nst > > > struct evsel *rhs) > > > > return 1; > > > > } > > > > > > > > + /* Retire latency event should not be group leader*/ > > > > > > Hmm.. why? > > Because we don't want to count them. Make them the group leader would n= ot work. > > I don't understand. You'll read the event regardless of being a > leader or not. > > > > > > > > > > + if (lhs->retire_lat && !rhs->retire_lat) > > > > + return 1; > > > > + if (!lhs->retire_lat && rhs->retire_lat) > > > > + return -1; > > > > + > > > > /* Default ordering by insertion index. */ > > > > return lhs->core.idx - rhs->core.idx; > > > > } > > > > diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c > > > > index a0a8aee7d6b9..4d700338fc99 100644 > > > > --- a/tools/perf/util/evsel.c > > > > +++ b/tools/perf/util/evsel.c > > > > @@ -58,6 +58,7 @@ > > > > #include > > > > #include > > > > #include > > > > +#include "util/intel-tpebs.h" > > > > > > > > #include > > > > > > > > @@ -1523,6 +1524,40 @@ static int evsel__read_one(struct evsel *evs= el, > > > int cpu_map_idx, int thread) > > > > return perf_evsel__read(&evsel->core, cpu_map_idx, thread, = count); > > > > } > > > > > > > > +static int evsel__set_retire_lat(struct evsel *evsel, int cpu_map_= idx, int > > > thread) > > > > +{ > > > > + struct perf_counts_values *count; > > > > + struct tpebs_retire_lat *t; > > > > + bool found =3D false; > > > > + __u64 val; > > > > + > > > > + count =3D perf_counts(evsel->counts, cpu_map_idx, thread); > > > > + > > > > + list_for_each_entry(t, &tpebs_results, nd) { > > > > + if (!strcmp(t->tpebs_name, evsel->name)) { > > > > + found =3D true; > > > > + break; > > > > + } > > > > + } > > > > + > > > > + if (!found) > > > > + return -1; > > > > + > > > > + /* > > > > + * Only set retire_latency value to the first CPU and threa= d. > > > > + */ > > > > + if (cpu_map_idx =3D=3D 0 && thread =3D=3D 0) > > > > + val =3D t->val; > > > > + else > > > > + val =3D 0; > > > > + > > > > + count->val =3D val; > > > > + /* Set ena and run to non-zero */ > > > > + count->ena =3D count->run =3D 1; > > > > + count->lost =3D 0; > > > > > > So here it seems you discard the actual count of the events > > > and replace it with the retire latency. That means you don't > > > need to open the event in perf stat, and probably just have a > > > placeholder, right? > > > > > > Btw, I think it's better to move this logic to intel-tpebs.c file and > > > rename to tpebs_set_retire_lat(). > > > > Ian wants this to be here and also suggested me to rename this function= to > > evsel__read_retire_lat(). I'm ok with either way. > > I think it's better to have the tpebs logic together. I think the tpebs functions can be in a tpebs file. I'd rather have the retirement latency events (from the metric) be evsels for a few reasons: 1) I'd rather everything in a metric be evsels, so things like "num_cpus_online" should really be a tool event rather than a special literal kind of thing. I'd like to reduce special cases over time, in part as it should help with portability. For example, if only Intel x86 can parse :R then someone trying to parse an Intel x86 metric on ARM may get parser errors. 2) When we change from forking perf record to directly opening a sampling ring buffer then it makes sense that we use/update the evsel/evlist logic. Thanks, Ian > Thanks, > Namhyung > > > > > > > > > > > > > + return 0; > > > > +} > > > > + > > > > static void evsel__set_count(struct evsel *counter, int cpu_map_id= x, int > > > thread, > > > > u64 val, u64 ena, u64 run, u64 lost) > > > > { > > > > @@ -1530,6 +1565,12 @@ static void evsel__set_count(struct evsel > > > *counter, int cpu_map_idx, int thread, > > > > > > > > count =3D perf_counts(counter->counts, cpu_map_idx, thread)= ; > > > > > > > > + if (counter->retire_lat) { > > > > > > if (evsel__is_retire_lat(counter)) ? > > > > > > > > > > + evsel__set_retire_lat(counter, cpu_map_idx, thread)= ; > > > > + perf_counts__set_loaded(counter->counts, cpu_map_id= x, thread, > > > true); > > > > + return; > > > > + } > > > > + > > > > count->val =3D val; > > > > count->ena =3D ena; > > > > count->run =3D run; > > > > @@ -1778,6 +1819,9 @@ int evsel__read_counter(struct evsel *evsel, = int > > > cpu_map_idx, int thread) > > > > if (evsel__is_tool(evsel)) > > > > return evsel__read_tool(evsel, cpu_map_idx, thread)= ; > > > > > > > > + if (evsel__is_retire_lat(evsel)) > > > > + return evsel__set_retire_lat(evsel, cpu_map_idx, th= read); > > > > + > > > > > > I'm not sure if it works well with group event. Probably that's > > > why you wanted to prevent group leaders. But I guess you > > > can just check this after the PERF_FORMAT_GROUP, no? > > > > > > Thanks, > > > Namhyung > > > > > > > > > > if (evsel->core.attr.read_format & PERF_FORMAT_GROUP) > > > > return evsel__read_group(evsel, cpu_map_idx, thread= ); > > > > > > > > diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h > > > > index bd8e84954e34..aaf572317e92 100644 > > > > --- a/tools/perf/util/evsel.h > > > > +++ b/tools/perf/util/evsel.h > > > > @@ -303,6 +303,11 @@ static inline bool evsel__is_tool(const struct= evsel > > > *evsel) > > > > return evsel->tool_event !=3D PERF_TOOL_NONE; > > > > } > > > > > > > > +static inline bool evsel__is_retire_lat(const struct evsel *evsel) > > > > +{ > > > > + return evsel->retire_lat; > > > > +} > > > > + > > > > const char *evsel__group_name(struct evsel *evsel); > > > > int evsel__group_desc(struct evsel *evsel, char *buf, size_t size)= ; > > > > > > > > -- > > > > 2.43.0 > > > >