Received: by 2002:a05:7412:1e0b:b0:fc:a2b0:25d7 with SMTP id kr11csp302321rdb; Wed, 14 Feb 2024 23:54:39 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXanZZqscdnztyY8iq704eJPGna3w9C8ApbSdbAzqtoDlQIonDcqr2D57bfWOJq4Dw/Fl3xhmZ5aoTSjCp0RWUUaNvmIu3uPwu+cGtzKg== X-Google-Smtp-Source: AGHT+IGeMgsebolbpVroHORpidwp0Lt7/y+Q4QEHSP0xw41JetZMnAMgq4GYEs5Q2fa1bkWohG+d X-Received: by 2002:a17:906:3414:b0:a3d:a63a:82a4 with SMTP id c20-20020a170906341400b00a3da63a82a4mr178652ejb.34.1707983679559; Wed, 14 Feb 2024 23:54:39 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707983679; cv=pass; d=google.com; s=arc-20160816; b=LdxHv4TRUS6uztGCCshmadJZ/7aNpLCTFL7Y25av2C4IFr0uFySFx0DyKzJxWuXEEY TOudro8kvSV4n6o2x/UvjJ5JBt8ZaxMpshe/8XJyV3rEFOHvGOYO+1Y8a+VHduCAj8sn IQOCPMbVKoA8T4WF51M1loLZxkUmppBV7GRQI+xvIMEphz7HJxKg0b2pIq2jCochmbwq JqeelUfGXLGd82rMYcVJH+mxOhqNz/HHSo2eDzvu47PKDCte7jR2JFAYZ3KwLcMuQpO/ yK+4tklNF1BxfzL2GiYNq7DzeZjgwLtk+wN0hjRPEKzgInPy9lcWWcfNw1POUmVF9Lnh Nm+Q== 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=rtgtlwF3ZegafmmTs7sJ+DY87IpwAYGQFQxo66uPYvY=; fh=0D8pTJBPAtDNwX9Vf1lvv7zu8cxvSytQXUfjFfuNH0Y=; b=BUFf/TTjwGQWTcoN+6J6bi5d2HUqzb3WtShBsFGVqe+4pxDkOGeqdtaiO1hLJeu7cq gGNLLiGuoEiqe6zYfDbU/Kct1g3cldsc1M0prvL6hyi1SK4GINQKK7FpkukehVkNngTN E1uraJoD7r+JqL/3sVLJMA8WdmO+MvH0nld/xayLehIS+SYDIq8wvBYGx/SD1/SVpzXb uCj8M26hhHnQLBmP3UyzFzpoYPXcisovQ71Wlm9qBF74b0fc/Ck4d/U/E/4dd7oNcgrn cpZ9UXlGA24bIndagTprc9xDUTPUKjjskAQVn0gx7FDPgzfP6BBcu5mX+TtgXv1bsAYV RsvQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=McNaqup1; 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-66379-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-66379-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id y4-20020a056402134400b005621bed346fsi418817edw.154.2024.02.14.23.54.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 23:54:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-66379-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=McNaqup1; 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-66379-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-66379-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 2706C1F2D7C0 for ; Thu, 15 Feb 2024 07:54:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0692211702; Thu, 15 Feb 2024 07:54:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="McNaqup1" Received: from mail-qt1-f179.google.com (mail-qt1-f179.google.com [209.85.160.179]) (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 64910DDD9 for ; Thu, 15 Feb 2024 07:54:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707983671; cv=none; b=IWeI44Dm1vcYtJDzrpIvsd95tpwWU/uav+WM2NC0B/JWCJ/lv5bqENh+Y0Q1NyA79qoQLp6B6z2A3hkJdQFj9ioouIBW5ov3ERU9/VAhrlovIfXxB84MvM44wXpLKT77hulo/Xt4knuCF246tcoHrJPw3aBxiEl3y48ukiXS2G0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707983671; c=relaxed/simple; bh=a0CrsUvrlzjtAIzYyECsZveq3IHuby4CWNqAo1/tuCQ=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=ceb8/TuY1HXTXAjpJWp+7ro/Bz5rCYmkLPhFsK7pFoYo7Qiymws4LYZKH9uyJDon9ko/NK71ppwW8kiCjSp2wA90nwapwUXNvoGMJtLUOH3dvPTY+ywa4n7En884geJ+Hj7rX8t2K42Ct7rUjcg/Fm6q9fbld6C5PTFrebpg2B4= 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=McNaqup1; arc=none smtp.client-ip=209.85.160.179 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-f179.google.com with SMTP id d75a77b69052e-42dc7306ca1so95801cf.0 for ; Wed, 14 Feb 2024 23:54:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707983668; x=1708588468; 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=rtgtlwF3ZegafmmTs7sJ+DY87IpwAYGQFQxo66uPYvY=; b=McNaqup1OEXkodmRxwhZvx4IHD7Mjm/eegbvwyIbquhLzuULdQPokXzwmGR7PucNgp 4frss6uIjYRBGenxAm4Fayel0QSxFGYIszMPBr5IUiXSx7UmT/eco0XTN8UWqIO5P+pN cMiX0Ws4tz6J98i2OjX+U1eG43fBwVwEd+CahWIjc1Nf+uY4VGiAH8qxAYX16NbkqDK8 MUKhbDurEUlcf4bJuI3nm+ugRQ2vFKXTLatEWOqSnWlT38Urhd8cxZWvHjKS16+O2u+z ZRKXIexSeqHVDi96UUEcZV5m4HLfRt2lK/kb6IISCxUqBA7HobT0RTFjHqiTVojfS2Qh R7MQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707983668; x=1708588468; 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=rtgtlwF3ZegafmmTs7sJ+DY87IpwAYGQFQxo66uPYvY=; b=A2CCNRkFG8JifRKQE93ckL5193A6LPkcJNOs6I0baIeB1zJcrFaz63SwbvM+/ACkxk X5OA+PSAJtEIXlMxDDdoNO2xFxkXXuG+yVcP6evAr51X58NkkvR21sxERvvicWD7WQof Gy62qS29MGatnRBvimNK4QWdTBcUGOrvR6dFDPwxotoFgmQU3MHsJkvRuD4FJgl8h7UP h0ozKmsmXzcLDUrzWlP4Mtw1wNWcocPbA7S6DI+/Ht2XPi+uH5zgclamj5YvGvhJ5+OR XrwV718ELpEttr1qta+EW64S9Aa8OiI1RDM8viZvTklvGl50YqDCgNr3tqg7o48GxDeZ xOrA== X-Forwarded-Encrypted: i=1; AJvYcCWWldNLrxSCKuDteTNgGF5n1v65iigVl8Q0rRKiOmfopQ1Pnu0hy+gk7jQE0pNtCHoiANhBwj3PH+6BHSXhsLW0AT1Wyc6NvjUoSs+l X-Gm-Message-State: AOJu0Yz/Mgh1ZpR9NnG/JGCG4whBq2CCIkB1pDDvZILAVQUt5kT9keyA KtFVxByLs4blnHvPGbHRN9Cv3gCXidON5l/WjudpoNuEJuaSLoW2ssOGwbadZRqnocYxJ6y2GXt Eazw4uQ65yHeo2yDtxgpE16UKkv95RRXf3khu X-Received: by 2002:a05:622a:85:b0:42d:a974:5b65 with SMTP id o5-20020a05622a008500b0042da9745b65mr583206qtw.17.1707983667966; Wed, 14 Feb 2024 23:54:27 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240213075256.1983638-1-namhyung@kernel.org> <20240213075256.1983638-4-namhyung@kernel.org> In-Reply-To: From: Ian Rogers Date: Wed, 14 Feb 2024 23:54:13 -0800 Message-ID: Subject: Re: [PATCH 3/4] perf hist: Do not use event index in hpp__fmt() To: Namhyung Kim Cc: Arnaldo Carvalho de Melo , Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Feb 14, 2024 at 9:26=E2=80=AFPM Namhyung Kim = wrote: > > On Wed, Feb 14, 2024 at 4:08=E2=80=AFPM Ian Rogers w= rote: > > > > On Mon, Feb 12, 2024 at 11:52=E2=80=AFPM Namhyung Kim wrote: > > > > > > The __hpp__fmt() is to print period values in a hist entry. It handl= es > > > event groups using linked pair entries. Until now, it used event ind= ex > > > to print values of group members. But we want to make it more robust > > > and support groups even if some members in the group were removed. > > > > I'm unclear how it breaks currently. The evsel idx is set the evlist > > nr_entries on creation and not updated by a remove. A remove may > > change a groups leader, should the remove also make the next entry's > > index idx that of the previous group leader? > > The evsel__group_idx() returns evsel->idx - leader->idx. > If it has a group event {A, B, C} then the index would be 0, 1, 2. > If it removes B, the group would be {A, C} with index 0 and 2. > The nr_members is 2 now so it cannot use index 2 for C. > > Note that we cannot change the index of C because some information > like annotation histogram relies on the index. Ugh, the whole index thing is just messy - perhaps these days we could have a hashmap with the evsel as a key instead. I remember that I also forced the idx here: https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/tr= ee/tools/perf/util/parse-events.c?h=3Dperf-tools-next#n2049 If it were invariant that the idx were always the position of an event in the evlist then I think life would be easier, but that won't help for the arrays of counters that need the index to be constant. I guess this is why the previous work to do this skipped evsels rather than removed them. Thanks, Ian > > > > > Let's use an index table from evsel to value array so that we can ski= p > > > dummy events in the output later. > > > > > > Signed-off-by: Namhyung Kim > > > --- > > > tools/perf/ui/hist.c | 34 ++++++++++++++++++++++++++++------ > > > 1 file changed, 28 insertions(+), 6 deletions(-) > > > > > > diff --git a/tools/perf/ui/hist.c b/tools/perf/ui/hist.c > > > index 5f4c110d840f..9c4c738edde1 100644 > > > --- a/tools/perf/ui/hist.c > > > +++ b/tools/perf/ui/hist.c > > > @@ -48,15 +48,30 @@ static int __hpp__fmt(struct perf_hpp *hpp, struc= t hist_entry *he, > > > if (evsel__is_group_event(evsel)) { > > > int idx; > > > struct hist_entry *pair; > > > - int nr_members =3D evsel->core.nr_members; > > > + int nr_members =3D evsel->core.nr_members - 1; > > > > A comment on the -1 would be useful. > > The 'nr_members' includes the leader which is already printed. > In this code, we want to print member events only, hence -1. > I'll add it to the comment. > > Thanks, > Namhyung > > > > > Thanks, > > Ian > > > > > > > union { > > > u64 period; > > > double percent; > > > } *val; > > > + struct evsel *member; > > > + struct evsel **idx_table; > > > > > > val =3D calloc(nr_members, sizeof(*val)); > > > if (val =3D=3D NULL) > > > - return 0; > > > + goto out; > > > + > > > + idx_table =3D calloc(nr_members, sizeof(*idx_table)); > > > + if (idx_table =3D=3D NULL) > > > + goto out; > > > + > > > + /* > > > + * Build an index table for each evsel to the val arr= ay. > > > + * It cannot use evsel->core.idx because removed even= ts might > > > + * create a hole so the index is not consecutive anym= ore. > > > + */ > > > + idx =3D 0; > > > + for_each_group_member(member, evsel) > > > + idx_table[idx++] =3D member; > > > > > > /* collect values in the group members */ > > > list_for_each_entry(pair, &he->pairs.head, pairs.node= ) { > > > @@ -66,8 +81,15 @@ static int __hpp__fmt(struct perf_hpp *hpp, struct= hist_entry *he, > > > if (!total) > > > continue; > > > > > > - evsel =3D hists_to_evsel(pair->hists); > > > - idx =3D evsel__group_idx(evsel); > > > + member =3D hists_to_evsel(pair->hists); > > > + for (idx =3D 0; idx < nr_members; idx++) { > > > + if (idx_table[idx] =3D=3D member) > > > + break; > > > + } > > > + > > > + /* this should not happen */ > > > + if (idx =3D=3D nr_members) > > > + continue; > > > > > > if (fmt_percent) > > > val[idx].percent =3D 100.0 * period /= total; > > > @@ -75,8 +97,7 @@ static int __hpp__fmt(struct perf_hpp *hpp, struct = hist_entry *he, > > > val[idx].period =3D period; > > > } > > > > > > - /* idx starts from 1 to skip the leader event */ > > > - for (idx =3D 1; idx < nr_members; idx++) { > > > + for (idx =3D 0; idx < nr_members; idx++) { > > > if (fmt_percent) { > > > ret +=3D hpp__call_print_fn(hpp, prin= t_fn, > > > fmt, len, v= al[idx].percent); > > > @@ -89,6 +110,7 @@ static int __hpp__fmt(struct perf_hpp *hpp, struct= hist_entry *he, > > > free(val); > > > } > > > > > > +out: > > > /* > > > * Restore original buf and size as it's where caller expects > > > * the result will be saved. > > > -- > > > 2.43.0.687.g38aa6559b0-goog > > >