Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp1662465lqb; Sun, 26 May 2024 11:02:04 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW/qDtmtyfb5DIPfhtxvpdE06bRScGY8ABr4nNlBwMg53tAp0LW0/+DRurqJ2ghd/D9oy2YNNxBgQqLmbkBw7W25VZZBLQvnhAbblIuaw== X-Google-Smtp-Source: AGHT+IFxQHjm+kbCqmVL63N9GotMQhUR3ICP252/pQBYv0wUNPF8wmHLB9kXpZtrxzXPrZynG6uU X-Received: by 2002:a05:6a21:3183:b0:1af:cf12:c7ac with SMTP id adf61e73a8af0-1b212d3ab5bmr8610709637.34.1716746524020; Sun, 26 May 2024 11:02:04 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716746524; cv=pass; d=google.com; s=arc-20160816; b=ZTFCbaZp8BSxbo9KIRJRymW2iDO4xaUA9DvWYgCdmh6bv7Sl3J/0jpXjhux1bB2HZJ 2tVPogKRCdCu1ZSEOnWpxpuvO0GzTsY1NRxugRe3ANtXVTREdJ+323e69O8KCGJ4wI5N yMQe0d8TDIEGtfxO4crMHDHYkYHCCO7wuiF6ob32TeOHK/CUDO8AFg6p9ssvpbWrxKR/ mmxn8lVv+PSXDDX8Y4OuoANee0HQ2JyTNeLXtH0IWL/iNDucm2FpQWUdLYY0S+T0Wnl9 KzsqCqODhuZPzQA7eAWtx9g9tmVID3FqT52AIawJmrGaVpU4CusWSuiK2oI3YdVSxX+X 2COQ== 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; bh=nXPh7TFYjYz1hkCYmis26EZXSF/Y7T5SQc05dmlFt2E=; fh=41n4UdD+UDp+jnNIJ7BG9TgbKnoQCuaMEHBQzf/yi2E=; b=I1uCPLyvFr91tDj3/cMxaN2pE97Wm5dpgY/aaRkDnr++PAINHg46cALZPssv6LvG9H UMfOUwgx7cGWSwGWo+A13mtTR3gthHDt8MagvG0x3t6RHi1AublgK+kA94HY65m4tVfc DYflpe7hW8pZCSLh+R2UELMUyi5hEIkaUG5fn6mYJ6lxyv+9dOyPXj4zIGMfn/PMKuK+ 7JmmWV3bydm0uFCY0yWZ6lfhchv9kkiA/yKZaPqowf3LnhX5sgo2EAI0/apPIox0K0+H cjeJOYeyBehxhkHcjb39k0cFbgNKSmBkXO+RHF3QcDCOzyH9/QjZu9D+xCcyZG31QUy3 iWGw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-189810-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-189810-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-68229937358si4995454a12.630.2024.05.26.11.02.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 May 2024 11:02:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-189810-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-189810-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-189810-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id A006F28100C for ; Sun, 26 May 2024 18:02:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C55DE12B14F; Sun, 26 May 2024 18:01:53 +0000 (UTC) Received: from mail-pg1-f172.google.com (mail-pg1-f172.google.com [209.85.215.172]) (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 740BA9449; Sun, 26 May 2024 18:01:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716746513; cv=none; b=VajcjtFKtWamjqQ9seXbeXGe2R6MWELhqjCqvi/q3nzTOQzlsm1lfzyTM29+gZH4XAEMFSvwwBrFlbHKf9Sgm4Gk1IbJXfILr+EZSP8gKNCFPROHnXpMZSCi2n2Nj5yJHzMFfaR7qutITnsqWQ2wpAdavBF3mV71GcRjQNfqDgA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716746513; c=relaxed/simple; bh=GeM7l3n9b7yfTNpVAlxn4n6ZhpD0CYVFaOUjUxaGrJM=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=q2xXnH1JrTVqg1z+jPexQdHexWO8T3FeDydC+EZROr6fapAmHiKOg0I40spq34tsQH7wqkoSj31qmQ0VnUJ28dZ3xW0yujpjLtXrcIZTS4jX3ikYzqpV/BOWkTQQdXWfMubjiQmVn7Bk+w6VgjeVS1gyyN1RGEORHrSW3/0JH54= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.215.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pg1-f172.google.com with SMTP id 41be03b00d2f7-6570bd6c3d7so3419360a12.0; Sun, 26 May 2024 11:01:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716746511; x=1717351311; 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=nXPh7TFYjYz1hkCYmis26EZXSF/Y7T5SQc05dmlFt2E=; b=bvLe2lFZX9zKBWPh3ULirdsPQKbkVpoaz959JEm/AH+GGlE5qfrG7jLNQ6aROh3VM1 xExQfn29N71KQN3MioGGnbWCkG5o8mCGUu/6JWXZ/tpHXMq/HDlAYU5qU7h9+Yy2iYNb xzrqQrWLVYmoLGUEsWxgVAxhVC708zkUt7WvWKd8VtHh5oP7ItMOzDTi2k4KYV2FvOGm uNRKnbA/qN9hixnWk9xzlvrOKilMIB/Te+Sswsorg/DzUou/pDO6hijVMDYZuStBNsU4 eqPzE/ie5txeeqbq3EuHewJnM86VhI7v0xZhE7Nn7i83X2IBt1lKF4BEz2btTm/gUy3K dMXQ== X-Forwarded-Encrypted: i=1; AJvYcCWCZfilaFBcOXWAZXvZUaFfjP/xoxNycRhmuH9vRGU04s5XOq6WGj/FOYFwjneRTSsD57cCTPAnIAL4UE5nBKQLPwl9CKSyvppILGJiwj9SKeCJlF5HBz/jT+BJC9kOtDUhJmmapoDh2Ns/wSAj5Q== X-Gm-Message-State: AOJu0YxSYZLoWsKSVxQKiAbkAdbKWO5i/+S/EuWn20R2SwBYuKG1OiJ7 Ig3EPpac62AsCeTMzvkuxmmTfq+VM1YFRZQz2HK44B7R/40PkCjyNYbdpbjfWuz//3cIGig+dMm 3hmTcNr4hLDsm7vVRfOpW2b9JOMY8Tw== X-Received: by 2002:a17:90b:fd3:b0:2b5:4ee8:e5e8 with SMTP id 98e67ed59e1d1-2bf5e189092mr6262469a91.16.1716746510638; Sun, 26 May 2024 11:01:50 -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: Namhyung Kim Date: Sun, 26 May 2024 11:01:39 -0700 Message-ID: Subject: Re: [RFC PATCH v9 4/7] perf stat: Plugin retire_lat value from sampled data to evsel To: "Wang, Weilin" Cc: Ian Rogers , 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 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 ; Hun= ter, > > Adrian ; Kan Liang = ; > > linux-perf-users@vger.kernel.org; linux-kernel@vger.kernel.org; Taylor,= Perry > > ; Alt, Samantha ; Bigge= rs, > > Caleb > > Subject: Re: [RFC PATCH v9 4/7] perf stat: Plugin retire_lat value from= sampled > > data to evsel > > > > On Tue, May 21, 2024 at 10:40=E2=80=AFAM wrote: > > > > > > From: Weilin Wang > > > > > > In current :R parsing implementation, the parser would recognize even= ts > > with > > > retire_latency modifier and insert them into the evlist like a normal= event. > > > Ideally, we need to avoid counting these events. > > > > > > In this commit, at the time when a retire_latency evsel is read, set = the retire > > > latency value processed from the sampled data to count value. This sa= mpled > > > retire latency value will be used for metric calculation and final ev= ent count > > > print out. > > > > I'm confused. Do you mean you don't count the event with 'R' modifier > > (w/ perf stat) and just print the (average) retire latency (from perf r= ecord)? > > In metric formulas, event without 'R' modifier is included as a normal ev= ent already. > So we don't need to count the event that with 'R' modifier. They only nee= d 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, cons= t > > 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 not= 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 *evsel= , > > int cpu_map_idx, int thread) > > > return perf_evsel__read(&evsel->core, cpu_map_idx, thread, co= unt); > > > } > > > > > > +static int evsel__set_retire_lat(struct evsel *evsel, int cpu_map_id= x, 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 thread. > > > + */ > > > + 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 t= o > evsel__read_retire_lat(). I'm ok with either way. I think it's better to have the tpebs logic together. Thanks, Namhyung > > > > > > > > + return 0; > > > +} > > > + > > > static void evsel__set_count(struct evsel *counter, int cpu_map_idx,= 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_idx,= 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, in= t > > 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, thre= ad); > > > + > > > > 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 e= vsel > > *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 > > >