From nobody Sat Apr 11 07:08:07 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9EDF9C6FA8E for ; Thu, 2 Mar 2023 21:56:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229894AbjCBV4d (ORCPT ); Thu, 2 Mar 2023 16:56:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229681AbjCBV4V (ORCPT ); Thu, 2 Mar 2023 16:56:21 -0500 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A6F55D457 for ; Thu, 2 Mar 2023 13:56:18 -0800 (PST) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-536a5a0b6e3so4161507b3.10 for ; Thu, 02 Mar 2023 13:56:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1677794177; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=ywTh5n03SqFTSvl6jepwvheFrqPaSHAy7v4KxsLV2lY=; b=STUCW2gWCheT4kjcqAtawNvWVMVPKCuiUgda3XMABvovl8zbU9GDaLL/KP6CP1833R Bdr9f7yUo7HUGuyZPS/MQofVjfG40EHrlPEhvTwkIoveD6zxOrcczyjdAtgFpbngNUnQ hDRDIVoPwgaf0wdKhG1MaD/MPrHhqhd5JQ/Dgz+Ew/pCHl+jMMS0faHQ5mc9MpkZy+eH e3h2XO6OY4tutXUw3ob1pRexWvzCy4Hxh7WlGnpeILRyGT/qrtqFIhk4Vo4NVUTpil+x W9hNbLmMMi2hxCvIIYBQHyR6Hw+/F/ytQBGHGrvo57gw6c+rwPQwQYMDkgdo4RB2uQod jo0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677794177; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ywTh5n03SqFTSvl6jepwvheFrqPaSHAy7v4KxsLV2lY=; b=SdAy+GltYQCKM4Sy+n+y4JQIGbcuWwLRdNRafeC/49GfSm8bvv0sPZV/d/1zscLU22 V3FcQEff0ea0HWtW4UMmbKtHQbMhcpbeGc8M9diYD44lxrtebyI6Osd9kyegjote5w+V hQ91phP10p/fa7cQBFyG9LUgVSMepcb394Ve7WI/seEM0EgUXmm0Pe506dt+JlgW3Jxv UEkDlRXnGvHFNs4h1GBq9V1+vAVrY8evbLI6iZe3cnLPLSA72k5YfC3DzGJnZOhIJPz8 xGVlyMh8N41iT4Rndl6bm8idigG3GDkIc7oXEXbNT+M4qo/D21A3GR685azgm2Y2zTbs pUpQ== X-Gm-Message-State: AO0yUKWSdNuwbafyFuk5Ez42bXQva+O1hXElZ48yYdt2Jvn7QQd2AVw5 EeNTVTZV1c7Ag8l0R+eB6aXzuwt+PxzU X-Google-Smtp-Source: AK7set+rCgX2CZtYsyNOpnPcTnPyatlq0OsTFID9T30qC/qUpHHpo3m0ptqs2gLK4HuXN1OA8yF0VE8ih5Ah X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:5f50:6ef4:b4d0:568e]) (user=irogers job=sendgmr) by 2002:a81:8414:0:b0:52f:1c60:923 with SMTP id u20-20020a818414000000b0052f1c600923mr25ywf.149.1677792356226; Thu, 02 Mar 2023 13:25:56 -0800 (PST) Date: Thu, 2 Mar 2023 13:25:22 -0800 In-Reply-To: <20230302212531.1043318-1-irogers@google.com> Message-Id: <20230302212531.1043318-2-irogers@google.com> Mime-Version: 1.0 References: <20230302212531.1043318-1-irogers@google.com> X-Mailer: git-send-email 2.40.0.rc0.216.gc4246ad0f0-goog Subject: [PATCH v2 01/10] libperf evlist: Avoid a use of evsel idx From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Kan Liang , Zhengjun Xing , Ravi Bangoria , Adrian Hunter , "Steinar H. Gunderson" , Kim Phillips , Florian Fischer , James Clark , Suzuki Poulouse , Sean Christopherson , Leo Yan , John Garry , Kajol Jain , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Stephane Eranian , Ian Rogers Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Setting the leader iterates the list, so rather than use idx (which may be changed through list reordering) just count the elements and set afterwards. Signed-off-by: Ian Rogers --- tools/lib/perf/evlist.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/tools/lib/perf/evlist.c b/tools/lib/perf/evlist.c index 61b637f29b82..2d6121e89ccb 100644 --- a/tools/lib/perf/evlist.c +++ b/tools/lib/perf/evlist.c @@ -687,15 +687,14 @@ perf_evlist__next_mmap(struct perf_evlist *evlist, st= ruct perf_mmap *map, =20 void __perf_evlist__set_leader(struct list_head *list, struct perf_evsel *= leader) { - struct perf_evsel *first, *last, *evsel; - - first =3D list_first_entry(list, struct perf_evsel, node); - last =3D list_last_entry(list, struct perf_evsel, node); - - leader->nr_members =3D last->idx - first->idx + 1; + struct perf_evsel *evsel; + int n =3D 0; =20 - __perf_evlist__for_each_entry(list, evsel) + __perf_evlist__for_each_entry(list, evsel) { evsel->leader =3D leader; + n++; + } + leader->nr_members =3D n; } =20 void perf_evlist__set_leader(struct perf_evlist *evlist) --=20 2.40.0.rc0.216.gc4246ad0f0-goog From nobody Sat Apr 11 07:08:07 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7CE21C678D4 for ; Thu, 2 Mar 2023 22:25:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230026AbjCBWZv (ORCPT ); Thu, 2 Mar 2023 17:25:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230020AbjCBWZs (ORCPT ); Thu, 2 Mar 2023 17:25:48 -0500 Received: from mail-oi1-x24a.google.com (mail-oi1-x24a.google.com [IPv6:2607:f8b0:4864:20::24a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 029351EBDC for ; Thu, 2 Mar 2023 14:25:48 -0800 (PST) Received: by mail-oi1-x24a.google.com with SMTP id cb5-20020a056808320500b003848c5da32eso234569oib.7 for ; Thu, 02 Mar 2023 14:25:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1677795947; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=dvqLbFbIa5Th4hLVJzIhGZ3VgrtC26zZgF3M8vwaoio=; b=rZijt3Yx2sv0qazNjKmSENaCWQCuL6oHZlInKQisJCAXXyB9MBoew7x24yXzFFX6/X fOLNPR4rafmVmS+2FYLhTMIhHiTK9tMZxKx4IjI17mq3VGV2WVOPSSUfLrz9pnPkW+Qn Xr/kUsibWvHj+pNRYUfqNCxhO92tr3UsOpw0C/Kv7PZmUAQP0i0u46TEbAqOV1yUTxzn Ic77SNqoY80nyCHMoi3tJ8OnegCAC8EoqIjm5lRLDoaiB8+Y0/Ea63LNEq3YIsOB47Jh T1wLvaqXTYe+Vw5nX+4KBclL42tHjdUkRVx1gf43glaD62/ZwQ+XHxoFKD6FdQRCan2f jrNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677795947; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=dvqLbFbIa5Th4hLVJzIhGZ3VgrtC26zZgF3M8vwaoio=; b=l+AF4ifHLqyXoH5cdimwV4d8p7zuf6PGi9ZOuA/juXs9TUt4W9qnD62o+vog/H9f8b PqydA1LMlyxrdZYnXYPHjZxm2XVifYblqbtk5yaF1EBicrNe/GflQitamHzXZR/cBuj2 V1menqs3OiZCEuDfy0mT6zRkYZk2OB3V4KEccLtGXORnwfCQkT1TKmInEihsIEICAsIv 2wZL17AVwtIjlZJ8Q0VvAHYYz9lqIZBkJLjI9F3ycEkleo9lZxOEMI1BmIAHQx0+Fn3T ZlAkgHIcmnkt8etoRrKoE4FawVSFzmZLWYhG/CZUi1gbtoBCBWiVonkYF1bzJzHpGEDV NuDw== X-Gm-Message-State: AO0yUKXhud3wgzSRZDHq4UfJmEE7h8tIBNM5vS5ml+adO0Qwrk5+P3te P0qg+ogv1aScfKzSWqokxebXx14HVkI1 X-Google-Smtp-Source: AK7set/77hq2nbjz3JZillK85E2ztOk6/zaHwTy51JirFxWAWfnzXGB75tCD+P3ovof7qkUcsCy8lqK3pepL X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:5f50:6ef4:b4d0:568e]) (user=irogers job=sendgmr) by 2002:a05:6902:101:b0:a4e:4575:f3ec with SMTP id o1-20020a056902010100b00a4e4575f3ecmr5273607ybh.0.1677792363948; Thu, 02 Mar 2023 13:26:03 -0800 (PST) Date: Thu, 2 Mar 2023 13:25:23 -0800 In-Reply-To: <20230302212531.1043318-1-irogers@google.com> Message-Id: <20230302212531.1043318-3-irogers@google.com> Mime-Version: 1.0 References: <20230302212531.1043318-1-irogers@google.com> X-Mailer: git-send-email 2.40.0.rc0.216.gc4246ad0f0-goog Subject: [PATCH v2 02/10] perf stat: Don't remove all grouped events when CPU maps disagree From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Kan Liang , Zhengjun Xing , Ravi Bangoria , Adrian Hunter , "Steinar H. Gunderson" , Kim Phillips , Florian Fischer , James Clark , Suzuki Poulouse , Sean Christopherson , Leo Yan , John Garry , Kajol Jain , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Stephane Eranian , Ian Rogers Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" If the events in an evlist's CPU map differ then the entire group is removed. For example: ``` $ perf stat -e '{imc_free_running/data_read/,imc_free_running/data_write/,c= s}' -a sleep 1 WARNING: grouped events cpus do not match, disabling group: anon group { imc_free_running/data_read/, imc_free_running/data_write/, c= s } ``` Change the behavior so that just the events not matching the leader are removed. So in the example above, just 'cs' will be removed. Modify the warning so that it is produced once for each group, rather than once for the entire evlist. Shrink the scope and size of the warning text buffer. Signed-off-by: Ian Rogers --- tools/perf/builtin-stat.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index d70b1ec88594..5c12ae5efce5 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -181,14 +181,13 @@ static bool cpus_map_matched(struct evsel *a, struct = evsel *b) =20 static void evlist__check_cpu_maps(struct evlist *evlist) { - struct evsel *evsel, *pos, *leader; - char buf[1024]; + struct evsel *evsel, *warned_leader =3D NULL; =20 if (evlist__has_hybrid(evlist)) evlist__warn_hybrid_group(evlist); =20 evlist__for_each_entry(evlist, evsel) { - leader =3D evsel__leader(evsel); + struct evsel *leader =3D evsel__leader(evsel); =20 /* Check that leader matches cpus with each member. */ if (leader =3D=3D evsel) @@ -197,19 +196,26 @@ static void evlist__check_cpu_maps(struct evlist *evl= ist) continue; =20 /* If there's mismatch disable the group and warn user. */ - WARN_ONCE(1, "WARNING: grouped events cpus do not match, disabling group= :\n"); - evsel__group_desc(leader, buf, sizeof(buf)); - pr_warning(" %s\n", buf); - + if (warned_leader !=3D leader) { + char buf[200]; + + pr_warning("WARNING: grouped events cpus do not match.\n" + "Events with CPUs not matching the leader will " + "be removed from the group.\n"); + evsel__group_desc(leader, buf, sizeof(buf)); + pr_warning(" %s\n", buf); + warned_leader =3D leader; + } if (verbose > 0) { + char buf[200]; + cpu_map__snprint(leader->core.cpus, buf, sizeof(buf)); pr_warning(" %s: %s\n", leader->name, buf); cpu_map__snprint(evsel->core.cpus, buf, sizeof(buf)); pr_warning(" %s: %s\n", evsel->name, buf); } =20 - for_each_group_evsel(pos, leader) - evsel__remove_from_group(pos, leader); + evsel__remove_from_group(evsel, leader); } } =20 --=20 2.40.0.rc0.216.gc4246ad0f0-goog From nobody Sat Apr 11 07:08:07 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6375AC678D4 for ; Thu, 2 Mar 2023 22:34:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230145AbjCBWdw (ORCPT ); Thu, 2 Mar 2023 17:33:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230152AbjCBWdq (ORCPT ); Thu, 2 Mar 2023 17:33:46 -0500 Received: from mail-pf1-x449.google.com (mail-pf1-x449.google.com [IPv6:2607:f8b0:4864:20::449]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B856A1E2A4 for ; Thu, 2 Mar 2023 14:33:41 -0800 (PST) Received: by mail-pf1-x449.google.com with SMTP id p36-20020a056a000a2400b005f72df7d97bso280230pfh.19 for ; Thu, 02 Mar 2023 14:33:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1677796421; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=sLp16thdoL8gYxkkfhRZgItEDw/VHlYRuSQJ2A/KjWw=; b=FHHelEMUWiU4Z1GYSeeAuC/PG0LpTrXj2X0KzSfI0aP8qS0YsCb84rIgGnj6+twg9E WK07h1t1EpGcjYn+EnWdZLv9ExjZpX8cybG4U515GrFVkdO7CcgNPCav61CCEuVm3IHw 3v+cJnCk1pelQNJxz/8X0S5pR7d/b6bB7nk0ySAKJvLxFZsX23c8MHrXCMrdLepN4LGn CRpkNrQUD558f65BOCA2rXDSPG9YvTYHY2wCSG2uENW3yWOH53I03ZH/j/J5g0tMgEtq mtE9Iib+wob7GyHkUPufCPjHTbWGe3GRs8TSlEPOlWaOSgsR4hKkGh8sqIPEdLAC+sSC 3DrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677796421; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=sLp16thdoL8gYxkkfhRZgItEDw/VHlYRuSQJ2A/KjWw=; b=Mz9/y6Cwi5x3Mr8Au6kTasEeZZNVAV8tKF4gjingZ9iScP1vpOsS+3sTmBtAD0xIdr vI0tLY7Q5z/jmnQUj9OyF8LdX46hY6DQ/ALfifsySYLWvUObPWb+eWaS3AadJTaQ+5JH Nwb5/NL98F8OgJia/z58Vgwb6PjmNnQs540YaX5s+fPHVPpWQzK6UMgiclFPKQ6DXIDz kYm61v6g1O3r5QGxpAt+oWPpjVOIURpJm8O28BzUBQ6/K/6J1keLN+kpGTJCN6C4K6h5 b2t3SGDl1jouBkKwejXKiCSHjVpAWqXC5Sgi+9tu1JwZxcv3gej+Z44sfl8hXkUwX6Kp wnHA== X-Gm-Message-State: AO0yUKWS6bChxRYGO+fn7mk+rLUlWF9h5wYoQy03ThRNcKkxVJDxR/7C gUGs7FlNLzHjBHQfEYyH8AN+Vt1TF+cZ X-Google-Smtp-Source: AK7set8IDse27H7uhs55+lpktQZD5WFfNUIFhEks3/sxyTroAWqTYmsTORr1cgwGdzOx42qWESc0pbtFHcKQ X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:5f50:6ef4:b4d0:568e]) (user=irogers job=sendgmr) by 2002:a25:9112:0:b0:9fe:1493:8bb with SMTP id v18-20020a259112000000b009fe149308bbmr4926485ybl.13.1677792371865; Thu, 02 Mar 2023 13:26:11 -0800 (PST) Date: Thu, 2 Mar 2023 13:25:24 -0800 In-Reply-To: <20230302212531.1043318-1-irogers@google.com> Message-Id: <20230302212531.1043318-4-irogers@google.com> Mime-Version: 1.0 References: <20230302212531.1043318-1-irogers@google.com> X-Mailer: git-send-email 2.40.0.rc0.216.gc4246ad0f0-goog Subject: [PATCH v2 03/10] perf record: Early auxtrace initialization before event parsing From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Kan Liang , Zhengjun Xing , Ravi Bangoria , Adrian Hunter , "Steinar H. Gunderson" , Kim Phillips , Florian Fischer , James Clark , Suzuki Poulouse , Sean Christopherson , Leo Yan , John Garry , Kajol Jain , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Stephane Eranian , Ian Rogers Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This allows event parsing to use the evsel__is_aux_event function, which is important when determining event grouping. Signed-off-by: Ian Rogers --- tools/perf/arch/x86/util/auxtrace.c | 17 +++++++++++++---- tools/perf/builtin-record.c | 6 ++++++ tools/perf/util/auxtrace.h | 2 ++ 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/tools/perf/arch/x86/util/auxtrace.c b/tools/perf/arch/x86/util= /auxtrace.c index 3da506e13f49..de1e4842ea2e 100644 --- a/tools/perf/arch/x86/util/auxtrace.c +++ b/tools/perf/arch/x86/util/auxtrace.c @@ -15,6 +15,19 @@ #include "../../../util/intel-bts.h" #include "../../../util/evlist.h" =20 +void auxtrace__early_init(void) +{ + struct perf_pmu *intel_pt_pmu; + struct perf_pmu *intel_bts_pmu; + + intel_pt_pmu =3D perf_pmu__find(INTEL_PT_PMU_NAME); + if (intel_pt_pmu) + intel_pt_pmu->auxtrace =3D true; + intel_bts_pmu =3D perf_pmu__find(INTEL_BTS_PMU_NAME); + if (intel_bts_pmu) + intel_bts_pmu->auxtrace =3D true; +} + static struct auxtrace_record *auxtrace_record__init_intel(struct evlist *evlist, int *err) @@ -26,11 +39,7 @@ struct auxtrace_record *auxtrace_record__init_intel(stru= ct evlist *evlist, bool found_bts =3D false; =20 intel_pt_pmu =3D perf_pmu__find(INTEL_PT_PMU_NAME); - if (intel_pt_pmu) - intel_pt_pmu->auxtrace =3D true; intel_bts_pmu =3D perf_pmu__find(INTEL_BTS_PMU_NAME); - if (intel_bts_pmu) - intel_bts_pmu->auxtrace =3D true; =20 evlist__for_each_entry(evlist, evsel) { if (intel_pt_pmu && evsel->core.attr.type =3D=3D intel_pt_pmu->type) diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 8374117e66f6..a0870c076dc0 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -3940,6 +3940,10 @@ static int record__init_thread_masks(struct record *= rec) return ret; } =20 +__weak void auxtrace__early_init(void) +{ +} + int cmd_record(int argc, const char **argv) { int err; @@ -3985,6 +3989,8 @@ int cmd_record(int argc, const char **argv) if (err) return err; =20 + auxtrace__early_init(); + argc =3D parse_options(argc, argv, record_options, record_usage, PARSE_OPT_STOP_AT_NON_OPTION); if (quiet) diff --git a/tools/perf/util/auxtrace.h b/tools/perf/util/auxtrace.h index 29eb82dff574..49a86aa6ac94 100644 --- a/tools/perf/util/auxtrace.h +++ b/tools/perf/util/auxtrace.h @@ -457,6 +457,8 @@ struct addr_filters { =20 struct auxtrace_cache; =20 +void auxtrace__early_init(void); + #ifdef HAVE_AUXTRACE_SUPPORT =20 u64 compat_auxtrace_mmap__read_head(struct auxtrace_mmap *mm); --=20 2.40.0.rc0.216.gc4246ad0f0-goog From nobody Sat Apr 11 07:08:07 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 62ABDC678D4 for ; Thu, 2 Mar 2023 22:18:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229940AbjCBWS6 (ORCPT ); Thu, 2 Mar 2023 17:18:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229901AbjCBWSw (ORCPT ); Thu, 2 Mar 2023 17:18:52 -0500 Received: from mail-io1-xd4a.google.com (mail-io1-xd4a.google.com [IPv6:2607:f8b0:4864:20::d4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 215C09EE1 for ; Thu, 2 Mar 2023 14:18:51 -0800 (PST) Received: by mail-io1-xd4a.google.com with SMTP id z5-20020a6b5c05000000b007447572f3f8so327234ioh.3 for ; Thu, 02 Mar 2023 14:18:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1677795530; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=pBjmM/9ZxcY4QPw1OT563S/xkYBM1O7yZVKEKyXWS5g=; b=W+2xG7D+dZqUJ1WZDQJCtpRA9ITAxO7RSg/G+jVBFVMM0PgFMVfZi+WA78iFXOZuiH PaOnSKAHaXsm3puQ+b3wf9LpxqVKN1ykwwQc2XHQOgfbXrFr9Rv3LRsU2qdyX22f99Yh joaYML8N3uQovYrIiCxNRlDHiJWJlhChf4LTboRcGvM1Rk1X7C/TtA+iXrBWyIp/VvZ3 qR4/Lvwkb7uh+HZn9WhwAVp0SZrm58mJzdO8Mm6i0hUFCTwUoFCyb8cz2bj7w24ddAFt sjeRE9Q5uQA2dEQG+S0gDnAFdys6JFnPFwx8uRg55hYCU+FgF0fj+5D9TYerLgdaGEB3 ODlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677795530; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=pBjmM/9ZxcY4QPw1OT563S/xkYBM1O7yZVKEKyXWS5g=; b=4QBARcdZmUvVK2tj0O2ciBvW1ks3DN9Nc5u3xjWvRw9iUjsGvau0MDZzpFH4SCT2kj dY7uSgc10366lMDNHSyBs4Y82K+526cYiDJwh4xtWH4gRDPm8zFUfNztDKdiQMF6rKI5 Di0ArBrBUXyOoLIhkScAN3XNr8hBlFjZfXRX0B5bXPR2vvRjn/bU95gDKqOhQJ/jRo3R EQDgD2ArbomqdPx39l4Dq7spA9g/RyRVzqKp9A0tA1gzmcWEVHjfhkAuMPdEbWhUGVsm z8PrElqIX8qhrj8W30APCf4so3EstvL2x/3S6C72nIcBpzj6n2wGQlKOpPS8i4rbP6jl GziA== X-Gm-Message-State: AO0yUKVl9Zv7s7HveBj71qPSPPpfeuYeM/EN4INTuQmZgkrGLN9OkQGd LEp01F3mCZduYGiPiRXiXtbIdNJgQmY8 X-Google-Smtp-Source: AK7set/VsA1HeM14pe/4lFMqpkMj6EPzo21Zf4W04XTdb1j3BgpGJ06CGU154fyiO+ld8pTCysXaZZgkXxmf X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:5f50:6ef4:b4d0:568e]) (user=irogers job=sendgmr) by 2002:a5b:1cf:0:b0:a43:52fe:c36f with SMTP id f15-20020a5b01cf000000b00a4352fec36fmr5200622ybp.7.1677792379741; Thu, 02 Mar 2023 13:26:19 -0800 (PST) Date: Thu, 2 Mar 2023 13:25:25 -0800 In-Reply-To: <20230302212531.1043318-1-irogers@google.com> Message-Id: <20230302212531.1043318-5-irogers@google.com> Mime-Version: 1.0 References: <20230302212531.1043318-1-irogers@google.com> X-Mailer: git-send-email 2.40.0.rc0.216.gc4246ad0f0-goog Subject: [PATCH v2 04/10] perf stat: Modify the group test From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Kan Liang , Zhengjun Xing , Ravi Bangoria , Adrian Hunter , "Steinar H. Gunderson" , Kim Phillips , Florian Fischer , James Clark , Suzuki Poulouse , Sean Christopherson , Leo Yan , John Garry , Kajol Jain , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Stephane Eranian , Ian Rogers Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Currently nr_members is 0 for an event with no group, however, they are always a leader of their own group. A later change will make that count 1 because the event is its own leader. Make the find_stat logic consistent with this, an improvement suggested by Namhyung Kim. Suggested-by: Namhyung Kim Signed-off-by: Ian Rogers --- tools/perf/util/stat-shadow.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/util/stat-shadow.c b/tools/perf/util/stat-shadow.c index ef85f1ae1ab2..eeccab6751d7 100644 --- a/tools/perf/util/stat-shadow.c +++ b/tools/perf/util/stat-shadow.c @@ -163,7 +163,7 @@ static double find_stat(const struct evsel *evsel, int = aggr_idx, enum stat_type continue; =20 /* Ignore evsels that are part of different groups. */ - if (evsel->core.leader->nr_members && + if (evsel->core.leader->nr_members > 1 && evsel->core.leader !=3D cur->core.leader) continue; /* Ignore evsels with mismatched modifiers. */ --=20 2.40.0.rc0.216.gc4246ad0f0-goog From nobody Sat Apr 11 07:08:07 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DB697C6FA8E for ; Thu, 2 Mar 2023 22:01:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229712AbjCBV5h (ORCPT ); Thu, 2 Mar 2023 16:57:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42446 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229723AbjCBV5C (ORCPT ); Thu, 2 Mar 2023 16:57:02 -0500 Received: from mail-oi1-x249.google.com (mail-oi1-x249.google.com [IPv6:2607:f8b0:4864:20::249]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A66E05F6F2 for ; Thu, 2 Mar 2023 13:56:55 -0800 (PST) Received: by mail-oi1-x249.google.com with SMTP id cb5-20020a056808320500b003848c5da32eso203337oib.7 for ; Thu, 02 Mar 2023 13:56:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1677794215; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=mSc6zWu+gp18coqfyQ+Fs9l1x/Sawfb5L2ZQMm92/Ks=; b=UIVqwK5jBbR0oRflZcHSzDAzwP72SoIRImEYiaWbClPHJPQlLnrvHoH/OO94ylhzhe 6jStH2U4CmVZdMbY2nXUwFAjOFf1jUrJZP0NZi+gz5RvO98zIqEtrT0E5fqR8zvomk8l guZ8OSCA1sahf2Av76kjQUDE6+50TBkBNwAe9Yp03Ab2EuckGVQeVZHAsXjHTSrItyOC YzBv+u/5aoisXBwQOycguap9/bzao4rlooFEEaBKbbYCXQS84lLIhMMq/gRtdHy/zNoq A7JFT/9RRB439SCRE1rsVq8xeMUscS6GWrujrF/x08HWuHymg2gmsLaYQzhEiqCwNFQL 9UFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677794215; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=mSc6zWu+gp18coqfyQ+Fs9l1x/Sawfb5L2ZQMm92/Ks=; b=Pzpn4donHWXjRMkO4nCM3FOQJ03wrd64YwbiVtrCm0Q8H6UVU3IBRZI1pdmXWw0rpH Vhn/5y/LoP+zpDlNwy3bWKc2jnviK8EEJdmy/wMMFgLE06dNFh1nwli/YsZlQl87nGnS KHr9rBSEHbWZqrVs6Hd9I7eZzl7CZF5nDQvBmr6NGaSGKrfNt1KwRk0BWFRflaZwPYfd GLtznGvFv2bMx5698Nyjdmn1Uy0csYnOsVpW036ulXssKddl9W6ahETDhAnIv7lK1uNU l1bZ+6d4QIYXePO1RBvhAfxoxIhvcw32HjZXXyv7GUBq4w8Gm8IGAT6au4//3/wOt9B4 LhBA== X-Gm-Message-State: AO0yUKUVzGZEDI2MQPdPb0prEOnLipA+s8UQN606g4k4HQiFO9ZQwHeH B7GBEkQd03ZkDN8dtTmohdQp0MRt7A5V X-Google-Smtp-Source: AK7set8EG+2QHSnGl+SsrkplMEsrRkrZK6RrmEtHNWM0JmQIeq0WDAJIcmhe259f39B7PGTkhwzUnyILVerf X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:5f50:6ef4:b4d0:568e]) (user=irogers job=sendgmr) by 2002:a05:6902:343:b0:aa9:bd2e:3744 with SMTP id e3-20020a056902034300b00aa9bd2e3744mr5222936ybs.9.1677792387767; Thu, 02 Mar 2023 13:26:27 -0800 (PST) Date: Thu, 2 Mar 2023 13:25:26 -0800 In-Reply-To: <20230302212531.1043318-1-irogers@google.com> Message-Id: <20230302212531.1043318-6-irogers@google.com> Mime-Version: 1.0 References: <20230302212531.1043318-1-irogers@google.com> X-Mailer: git-send-email 2.40.0.rc0.216.gc4246ad0f0-goog Subject: [PATCH v2 05/10] perf evsel: Allow const evsel for certain accesses From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Kan Liang , Zhengjun Xing , Ravi Bangoria , Adrian Hunter , "Steinar H. Gunderson" , Kim Phillips , Florian Fischer , James Clark , Suzuki Poulouse , Sean Christopherson , Leo Yan , John Garry , Kajol Jain , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Stephane Eranian , Ian Rogers Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" List sorting, added later to evlist, passes const elements requiring helper functions to also be const. Make the argument to evsel__find_pmu, evsel__is_aux_event and evsel__leader const. Signed-off-by: Ian Rogers --- tools/perf/util/evsel.c | 2 +- tools/perf/util/evsel.h | 6 +++--- tools/perf/util/pmu.c | 6 +++--- tools/perf/util/python.c | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 51e8ce6edddc..2dc2c24252bb 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -3139,7 +3139,7 @@ bool evsel__is_hybrid(const struct evsel *evsel) return evsel->pmu_name && perf_pmu__is_hybrid(evsel->pmu_name); } =20 -struct evsel *evsel__leader(struct evsel *evsel) +struct evsel *evsel__leader(const struct evsel *evsel) { return container_of(evsel->core.leader, struct evsel, core); } diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index 814a49ebb7e3..676c499323e9 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -212,8 +212,8 @@ int evsel__object_config(size_t object_size, int (*init)(struct evsel *evsel), void (*fini)(struct evsel *evsel)); =20 -struct perf_pmu *evsel__find_pmu(struct evsel *evsel); -bool evsel__is_aux_event(struct evsel *evsel); +struct perf_pmu *evsel__find_pmu(const struct evsel *evsel); +bool evsel__is_aux_event(const struct evsel *evsel); =20 struct evsel *evsel__new_idx(struct perf_event_attr *attr, int idx); =20 @@ -505,7 +505,7 @@ int evsel__store_ids(struct evsel *evsel, struct evlist= *evlist); =20 void evsel__zero_per_pkg(struct evsel *evsel); bool evsel__is_hybrid(const struct evsel *evsel); -struct evsel *evsel__leader(struct evsel *evsel); +struct evsel *evsel__leader(const struct evsel *evsel); bool evsel__has_leader(struct evsel *evsel, struct evsel *leader); bool evsel__is_leader(struct evsel *evsel); void evsel__set_leader(struct evsel *evsel, struct evsel *leader); diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 43b6182d96b7..45d9b8e28e16 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -988,7 +988,7 @@ struct perf_pmu *perf_pmu__scan(struct perf_pmu *pmu) return NULL; } =20 -struct perf_pmu *evsel__find_pmu(struct evsel *evsel) +struct perf_pmu *evsel__find_pmu(const struct evsel *evsel) { struct perf_pmu *pmu =3D NULL; =20 @@ -1000,11 +1000,11 @@ struct perf_pmu *evsel__find_pmu(struct evsel *evse= l) break; } =20 - evsel->pmu =3D pmu; + ((struct evsel *)evsel)->pmu =3D pmu; return pmu; } =20 -bool evsel__is_aux_event(struct evsel *evsel) +bool evsel__is_aux_event(const struct evsel *evsel) { struct perf_pmu *pmu =3D evsel__find_pmu(evsel); =20 diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index 42e8b813d010..ab48ffbb6448 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -83,7 +83,7 @@ const char *perf_env__arch(struct perf_env *env __maybe_u= nused) * far, for the perf python binding known usecases, revisit if this become * necessary. */ -struct perf_pmu *evsel__find_pmu(struct evsel *evsel __maybe_unused) +struct perf_pmu *evsel__find_pmu(const struct evsel *evsel __maybe_unused) { return NULL; } --=20 2.40.0.rc0.216.gc4246ad0f0-goog From nobody Sat Apr 11 07:08:07 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C93BBC678D4 for ; Thu, 2 Mar 2023 21:56:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229686AbjCBV4N (ORCPT ); Thu, 2 Mar 2023 16:56:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229555AbjCBV4J (ORCPT ); Thu, 2 Mar 2023 16:56:09 -0500 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2EFA559C2 for ; Thu, 2 Mar 2023 13:56:05 -0800 (PST) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-536b7eb9117so3948667b3.14 for ; Thu, 02 Mar 2023 13:56:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1677794157; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=pFZEua8oTOpEy63/43z9gHKJd5DuGh8paDEjQxW2aig=; b=JQjrH4wMa1a61Rm/qB8rOzj+BqFXZs/vcxRoNqjZIwzsrx4DFMYTCx+XOZnmbaTMo7 5LPywruZvRi0HY0nf16Z1M25zPquhObLBKtK4LmcZywG3EvrimeCZbofFDP1Gch04u0i bbTsilLDfF8pwp2ngnRvUW+lZC2tXBm9rCehDV3LqTR8EZpyq8/BC6IIVPJVSO+p33q2 LMzvsD25ajJIiap+LCNqmIV4yztBL/JhtijuXvROu/vOZaQo4ZKC3h2Cx8Faov0dIDwI 8/JJscO2dJbJaVAYXia7hEz9VZBDpo7dXB5PJiY30aIlHU7UUQjTabb4lQ+4NVYci77r YBLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677794157; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=pFZEua8oTOpEy63/43z9gHKJd5DuGh8paDEjQxW2aig=; b=LdFN9lMTdqPG5OrEfkkAVWGMKh/pNtt+m/RGNKNfZaz6aOAxpIIpwDgmFGwDXSWF66 OKDLYagjPDKLnW++w5lhhdIFQyLhd+yZza2zkb5JqJ05RBijRNE7dm1inZiFwumSx0Rr S7LudYg+/Gupt1UKvH3M8KYMNs64DaJR4lNmKRs681MkaBcucnR7YkKXvgpImWRbfC9j kPiUCHXpiP0Ju3RnHnzw0U+cOOTcC0HlCEhw4nk72hRTMxmgveFxP9otg5kqfE0vq7It SQYmHkyHd7AymzyUzLo0ZnkPHVD0n0YEGU0ZLpgQHDSABO5RQPxxspjXI1sN+EVXJRij 0LDA== X-Gm-Message-State: AO0yUKX2ByCYRS7R90pO/9ONuQ3M72K+OZ8+yAaHlquZuNYDt01Cnq+H FcT0TQ9BB7yb8C1CHoFPjdHWj0tRW7Ds X-Google-Smtp-Source: AK7set9TS9AIzk17qdo6XO2UQeX7T5f+JoZlvnDu9vwkLALw4z4bmxPkvoTtgbCu8K9raAkgAtQEfYVer3Cy X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:5f50:6ef4:b4d0:568e]) (user=irogers job=sendgmr) by 2002:a81:5d89:0:b0:536:4aec:295d with SMTP id r131-20020a815d89000000b005364aec295dmr28ywb.453.1677792395505; Thu, 02 Mar 2023 13:26:35 -0800 (PST) Date: Thu, 2 Mar 2023 13:25:27 -0800 In-Reply-To: <20230302212531.1043318-1-irogers@google.com> Message-Id: <20230302212531.1043318-7-irogers@google.com> Mime-Version: 1.0 References: <20230302212531.1043318-1-irogers@google.com> X-Mailer: git-send-email 2.40.0.rc0.216.gc4246ad0f0-goog Subject: [PATCH v2 06/10] perf evsel: Add function to compute pmu_name From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Kan Liang , Zhengjun Xing , Ravi Bangoria , Adrian Hunter , "Steinar H. Gunderson" , Kim Phillips , Florian Fischer , James Clark , Suzuki Poulouse , Sean Christopherson , Leo Yan , John Garry , Kajol Jain , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Stephane Eranian , Ian Rogers Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The computed pmu_name respects software events and aux event groups, such that the pmu_name is changed to be that of the aux event leader or group leader for software events. This is done as a later change will split events that are in different PMUs into different groups. Signed-off-by: Ian Rogers --- tools/perf/util/evsel.c | 24 ++++++++++++++++++++++++ tools/perf/util/evsel.h | 1 + 2 files changed, 25 insertions(+) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 2dc2c24252bb..9c6b486f8bd4 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -821,6 +821,30 @@ const char *evsel__name(struct evsel *evsel) return "unknown"; } =20 +const char *evsel__pmu_name(const struct evsel *evsel) +{ + const struct evsel *leader; + + /* If the pmu_name is set use it. pmu_name isn't set for CPU and software= events. */ + if (evsel->pmu_name) + return evsel->pmu_name; + /* + * Software events may be in a group with other uncore PMU events. Use + * the pmu_name of the group leader to avoid breaking the software event + * out of the group. + * + * Aux event leaders, like intel_pt, expect a group with events from + * other PMUs, so substitute the AUX event's PMU in this case. + */ + leader =3D evsel__leader(evsel); + if ((evsel->core.attr.type =3D=3D PERF_TYPE_SOFTWARE || evsel__is_aux_eve= nt(leader)) && + leader->pmu_name) { + return leader->pmu_name; + } + + return "cpu"; +} + const char *evsel__metric_id(const struct evsel *evsel) { if (evsel->metric_id) diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index 676c499323e9..72121194d3b1 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -280,6 +280,7 @@ int arch_evsel__hw_name(struct evsel *evsel, char *bf, = size_t size); =20 int __evsel__hw_cache_type_op_res_name(u8 type, u8 op, u8 result, char *bf= , size_t size); const char *evsel__name(struct evsel *evsel); +const char *evsel__pmu_name(const struct evsel *evsel); const char *evsel__metric_id(const struct evsel *evsel); =20 static inline bool evsel__is_tool(const struct evsel *evsel) --=20 2.40.0.rc0.216.gc4246ad0f0-goog From nobody Sat Apr 11 07:08:07 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 19E14C7EE45 for ; Thu, 2 Mar 2023 22:01:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229740AbjCBWAc (ORCPT ); Thu, 2 Mar 2023 17:00:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229806AbjCBWA3 (ORCPT ); Thu, 2 Mar 2023 17:00:29 -0500 Received: from mail-oa1-f73.google.com (mail-oa1-f73.google.com [209.85.160.73]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C22F95A6C2 for ; Thu, 2 Mar 2023 14:00:20 -0800 (PST) Received: by mail-oa1-f73.google.com with SMTP id 586e51a60fabf-172a051bbcfso438908fac.14 for ; Thu, 02 Mar 2023 14:00:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1677794360; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=dcvWMdLTJ1iuXhAaTLlBF3OqMzr4/MuwhIZh3sQrcPM=; b=a0EFQEXvTO9IIE/LbOtPkcXViHfv9dEzXj8KSiVYaUh/sfzCdbrhhP8l0pmjo5LgoH iCQfdg0jkNGGbXMATVpflZsd6HJpzPtVA1RFhbgExab2unqHTMW+rwt4K15tYs0KAi9P 80tyGzoWONd8IGNIjajpRKV5M0A9LxLjHwysi8kKGR/fhjc7VvEYGbD8Pe4UcTGGzIv2 g/OGbLCIz53lSA3DZgvMoMNXLR8Rb/wj2BCmi0GL496xDFIL2WodN3XWa6IUkLqS2RZf H7IbtmT/9RE39P2lQmVmT3Tmojo+52+37FcMlryUdsk+qA0JyGACrkFdm+ao1lnecuUy wpmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677794360; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=dcvWMdLTJ1iuXhAaTLlBF3OqMzr4/MuwhIZh3sQrcPM=; b=YS6DYVKIoMbvlpYW0YUNAdawnL2guvHqHRKku4gG/deEbw7d//6yDs1x9aGA+SEX0b 0unNJDvYB+iCcDj/IKjAqyK3NxO33f55Cal5NHCs0Ou/xW7f1/LUz9WVmyPiU94Vr39d JozPMte2gnhdnW+8eaDolYzjPGmPs5zcP6X/3I3h6wwvLFTvOV2fY4FxARRDooizK8N1 Cr6lSxuXlsjoAMsK3CoQaNRbRXU2psd3qgDMovSubY6TWTY7O2tmc7YvIC9sKZvMOErK vyh6E9fqN4KSbW9P4bienmV2+Dp8vbKDh7mROOIpd3H8dBnzhKoWt76cuKpbx2l9WI/a pMQA== X-Gm-Message-State: AO0yUKXTaVZIY9J5oJ3hC0y0dtY2ygQBRjWc4RbEYuXdq7glGSOI2UI0 FAGwv29oRFZw0JOL/KgMwIn+YiDddQfC X-Google-Smtp-Source: AK7set+J7xhJXlPokHx7LXJwm2IqRttp6kpC4gGTiT8erLWQVPEcFhFcT67z288CpJXfg3wHvD28CGfNiln2 X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:5f50:6ef4:b4d0:568e]) (user=irogers job=sendgmr) by 2002:a05:6902:4f0:b0:a9d:be6e:3340 with SMTP id w16-20020a05690204f000b00a9dbe6e3340mr6135153ybs.1.1677792402429; Thu, 02 Mar 2023 13:26:42 -0800 (PST) Date: Thu, 2 Mar 2023 13:25:28 -0800 In-Reply-To: <20230302212531.1043318-1-irogers@google.com> Message-Id: <20230302212531.1043318-8-irogers@google.com> Mime-Version: 1.0 References: <20230302212531.1043318-1-irogers@google.com> X-Mailer: git-send-email 2.40.0.rc0.216.gc4246ad0f0-goog Subject: [PATCH v2 07/10] perf parse-events: Pass ownership of the group name From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Kan Liang , Zhengjun Xing , Ravi Bangoria , Adrian Hunter , "Steinar H. Gunderson" , Kim Phillips , Florian Fischer , James Clark , Suzuki Poulouse , Sean Christopherson , Leo Yan , John Garry , Kajol Jain , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Stephane Eranian , Ian Rogers Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Pass ownership of the group name rather than copying and freeing the original. This saves a memory allocation and copy. Signed-off-by: Ian Rogers --- tools/perf/util/parse-events.c | 3 ++- tools/perf/util/parse-events.y | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 0336ff27c15f..1be454697d57 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -1761,6 +1761,7 @@ parse_events__set_leader_for_uncore_aliase(char *name= , struct list_head *list, =20 handled: ret =3D 1; + free(name); out: free(leaders); return ret; @@ -1786,7 +1787,7 @@ void parse_events__set_leader(char *name, struct list= _head *list, =20 leader =3D arch_evlist__leader(list); __perf_evlist__set_leader(list, &leader->core); - leader->group_name =3D name ? strdup(name) : NULL; + leader->group_name =3D name; list_move(&leader->core.node, list); } =20 diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y index be8c51770051..541b8dde2063 100644 --- a/tools/perf/util/parse-events.y +++ b/tools/perf/util/parse-events.y @@ -202,8 +202,8 @@ PE_NAME '{' events '}' struct list_head *list =3D $3; =20 inc_group_count(list, _parse_state); + /* Takes ownership of $1. */ parse_events__set_leader($1, list, _parse_state); - free($1); $$ =3D list; } | --=20 2.40.0.rc0.216.gc4246ad0f0-goog From nobody Sat Apr 11 07:08:07 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2886BC6FA8E for ; Thu, 2 Mar 2023 22:30:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230081AbjCBWaD (ORCPT ); Thu, 2 Mar 2023 17:30:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47436 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230135AbjCBW37 (ORCPT ); Thu, 2 Mar 2023 17:29:59 -0500 Received: from mail-qt1-x84a.google.com (mail-qt1-x84a.google.com [IPv6:2607:f8b0:4864:20::84a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A2ED30B33 for ; Thu, 2 Mar 2023 14:29:58 -0800 (PST) Received: by mail-qt1-x84a.google.com with SMTP id c5-20020ac85185000000b003bfae3b8051so494066qtn.0 for ; Thu, 02 Mar 2023 14:29:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1677796197; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=g0jlEMBakJd81khWC3QW7IrApk6xNYL1VTloNWEkJVI=; b=iM02p2m8PYb0bCkztLh0Mh/D/T5NSZxetgqvZpdv4CfGV2EfsCqYanW6sbExxTB9m7 J/4umurzt7C2CKwhjJAJCxVTr4AvFt6s90dEuBJOO6jw1Ag9ghUtVmnA3p28Dvm7wNWU QzHtI5VoB5VBc/+f1JzyiL2AIYXGz1XUh0Wull2Ib4ZDl6fBGdg21j/Au98Jxgc91NcG tCkEuAilWGQmJ0nYxQcJZg6kZ+g4wiQSFd8HVuWmYHirOS8tmGW2kW0SvaqdG7DrSP9P EUWahSDyNf+WVImAlGQ3RYCV/y2anjqks46vseH0Jk7/zNRtBeeej7Nhl0oLoX/GogB5 U8yQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677796197; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=g0jlEMBakJd81khWC3QW7IrApk6xNYL1VTloNWEkJVI=; b=Dw43VzU60cEInYJETO1aoFRL+ty0zGKRzYoFb5fYPFrUSd0XLWKfoGdzzkoVz1GiR3 gkrNGB4mo1TOeNSHVNZ7FaXtle1k7p32dCB64NH4WCe74Otog2hdLe2xDMdrjzuv9YFs pNeksZQn+DvfYWkA/F/qemN9DE9owjAsUwLz4C9FpmpXrp+LCfx8C1qO09fpX7YKVWIu j26bYvV3YmsgPI60A2oWtTOu3o/qH/TOfXztV5J5qpKC8trrC3WqvQZSjcaX+HFRiTzR cAr3viTyHOpEPpzE/9uIn0OTQvcb74GJvgi0Ce0cc/AoDlAIdWzV2EilvT9KHQEcI+uS b73g== X-Gm-Message-State: AO0yUKUTYBggnuKXN9rRj3KgufcKG2WT61ZFYmFnYDbe1DfQkj28eh/I zTmF3WajhQlc20X0Nn6UUOxM9dn4za1M X-Google-Smtp-Source: AK7set/SqQ08lU+52ZjXhfuDGzA0eY94bDLs6OOwSv2m5Qv+bcRAT36ykFY05Uh+hyChaWXjxycybDuacudI X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:5f50:6ef4:b4d0:568e]) (user=irogers job=sendgmr) by 2002:a05:6902:4f0:b0:a9d:be6e:3340 with SMTP id w16-20020a05690204f000b00a9dbe6e3340mr6135290ybs.1.1677792410039; Thu, 02 Mar 2023 13:26:50 -0800 (PST) Date: Thu, 2 Mar 2023 13:25:29 -0800 In-Reply-To: <20230302212531.1043318-1-irogers@google.com> Message-Id: <20230302212531.1043318-9-irogers@google.com> Mime-Version: 1.0 References: <20230302212531.1043318-1-irogers@google.com> X-Mailer: git-send-email 2.40.0.rc0.216.gc4246ad0f0-goog Subject: [PATCH v2 08/10] perf parse-events: Sort and group parsed events From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Kan Liang , Zhengjun Xing , Ravi Bangoria , Adrian Hunter , "Steinar H. Gunderson" , Kim Phillips , Florian Fischer , James Clark , Suzuki Poulouse , Sean Christopherson , Leo Yan , John Garry , Kajol Jain , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Stephane Eranian , Ian Rogers Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This change is intended to be a no-op for most current cases, the default sort order is the order the events were parsed. Where it varies is in how groups are handled. Previously an uncore and core event that are grouped would most often cause the group to be removed: ``` $ perf stat -e '{instructions,uncore_imc_free_running_0/data_total/}' -a sl= eep 1 WARNING: grouped events cpus do not match, disabling group: anon group { instructions, uncore_imc_free_running_0/data_total/ } ... ``` However, when wildcards are used the events should be re-sorted and re-grouped in parse_events__set_leader, but this currently fails for simple examples: ``` $ perf stat -e '{uncore_imc_free_running/data_read/,uncore_imc_free_running= /data_write/}' -a sleep 1 Performance counter stats for 'system wide': MiB uncore_imc_free_running/data_read/ MiB uncore_imc_free_running/data_write/ 1.000996992 seconds time elapsed ``` A futher failure mode, fixed in this patch, is to force topdown events into a group. This change moves sorting the evsels in the evlist after parsing. It requires parsing to set up groups. First the evsels are sorted respecting the existing groupings and parse order, but also reordering to ensure evsels of the same PMU and group appear together. So that software and aux events respect groups, their pmu_name is taken from the group leader. The sorting is done with list_sort removing a memory allocation. After sorting a pass is done to correct the group leaders and for topdown events ensuring they have a group leader. This fixes the problems seen before: ``` $ perf stat -e '{uncore_imc_free_running/data_read/,uncore_imc_free_running= /data_write/}' -a sleep 1 Performance counter stats for 'system wide': 727.42 MiB uncore_imc_free_running/data_read/ 81.84 MiB uncore_imc_free_running/data_write/ 1.000948615 seconds time elapsed ``` As well as making groups not fail for cases like: ``` $ perf stat -e '{imc_free_running_0/data_total/,imc_free_running_1/data_tot= al/}' -a sleep 1 Performance counter stats for 'system wide': 256.47 MiB imc_free_running_0/data_total/ 256.48 MiB imc_free_running_1/data_total/ 1.001165442 seconds time elapsed ``` Signed-off-by: Ian Rogers --- tools/perf/arch/x86/util/evlist.c | 39 ++--- tools/perf/util/evlist.h | 2 +- tools/perf/util/parse-events.c | 240 +++++++++++++++--------------- tools/perf/util/parse-events.h | 3 +- tools/perf/util/parse-events.y | 4 +- 5 files changed, 136 insertions(+), 152 deletions(-) diff --git a/tools/perf/arch/x86/util/evlist.c b/tools/perf/arch/x86/util/e= vlist.c index 8a7ae4162563..d4193479a364 100644 --- a/tools/perf/arch/x86/util/evlist.c +++ b/tools/perf/arch/x86/util/evlist.c @@ -65,29 +65,22 @@ int arch_evlist__add_default_attrs(struct evlist *evlis= t, return ___evlist__add_default_attrs(evlist, attrs, nr_attrs); } =20 -struct evsel *arch_evlist__leader(struct list_head *list) +int arch_evlist__cmp(const struct evsel *lhs, const struct evsel *rhs) { - struct evsel *evsel, *first, *slots =3D NULL; - bool has_topdown =3D false; - - first =3D list_first_entry(list, struct evsel, core.node); - - if (!topdown_sys_has_perf_metrics()) - return first; - - /* If there is a slots event and a topdown event then the slots event com= es first. */ - __evlist__for_each_entry(list, evsel) { - if (evsel->pmu_name && !strncmp(evsel->pmu_name, "cpu", 3) && evsel->nam= e) { - if (strcasestr(evsel->name, "slots")) { - slots =3D evsel; - if (slots =3D=3D first) - return first; - } - if (strcasestr(evsel->name, "topdown")) - has_topdown =3D true; - if (slots && has_topdown) - return slots; - } + if (topdown_sys_has_perf_metrics() && + (!lhs->pmu_name || !strncmp(lhs->pmu_name, "cpu", 3))) { + /* Ensure the topdown slots comes first. */ + if (strcasestr(lhs->name, "slots")) + return -1; + if (strcasestr(rhs->name, "slots")) + return 1; + /* Followed by topdown events. */ + if (strcasestr(lhs->name, "topdown") && !strcasestr(rhs->name, "topdown"= )) + return -1; + if (!strcasestr(lhs->name, "topdown") && strcasestr(rhs->name, "topdown"= )) + return 1; } - return first; + + /* Default ordering by insertion index. */ + return lhs->core.idx - rhs->core.idx; } diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h index 01fa9d592c5a..d89d8f92802b 100644 --- a/tools/perf/util/evlist.h +++ b/tools/perf/util/evlist.h @@ -119,7 +119,7 @@ int arch_evlist__add_default_attrs(struct evlist *evlis= t, #define evlist__add_default_attrs(evlist, array) \ arch_evlist__add_default_attrs(evlist, array, ARRAY_SIZE(array)) =20 -struct evsel *arch_evlist__leader(struct list_head *list); +int arch_evlist__cmp(const struct evsel *lhs, const struct evsel *rhs); =20 int evlist__add_dummy(struct evlist *evlist); struct evsel *evlist__add_aux_dummy(struct evlist *evlist, bool system_wid= e); diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 1be454697d57..d6eb0a54dd2d 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 #include #include +#include #include #include #include @@ -1655,125 +1656,7 @@ int parse_events__modifier_group(struct list_head *= list, return parse_events__modifier_event(list, event_mod, true); } =20 -/* - * Check if the two uncore PMUs are from the same uncore block - * The format of the uncore PMU name is uncore_#blockname_#pmuidx - */ -static bool is_same_uncore_block(const char *pmu_name_a, const char *pmu_n= ame_b) -{ - char *end_a, *end_b; - - end_a =3D strrchr(pmu_name_a, '_'); - end_b =3D strrchr(pmu_name_b, '_'); - - if (!end_a || !end_b) - return false; - - if ((end_a - pmu_name_a) !=3D (end_b - pmu_name_b)) - return false; - - return (strncmp(pmu_name_a, pmu_name_b, end_a - pmu_name_a) =3D=3D 0); -} - -static int -parse_events__set_leader_for_uncore_aliase(char *name, struct list_head *l= ist, - struct parse_events_state *parse_state) -{ - struct evsel *evsel, *leader; - uintptr_t *leaders; - bool is_leader =3D true; - int i, nr_pmu =3D 0, total_members, ret =3D 0; - - leader =3D list_first_entry(list, struct evsel, core.node); - evsel =3D list_last_entry(list, struct evsel, core.node); - total_members =3D evsel->core.idx - leader->core.idx + 1; - - leaders =3D calloc(total_members, sizeof(uintptr_t)); - if (WARN_ON(!leaders)) - return 0; - - /* - * Going through the whole group and doing sanity check. - * All members must use alias, and be from the same uncore block. - * Also, storing the leader events in an array. - */ - __evlist__for_each_entry(list, evsel) { - - /* Only split the uncore group which members use alias */ - if (!evsel->use_uncore_alias) - goto out; - - /* The events must be from the same uncore block */ - if (!is_same_uncore_block(leader->pmu_name, evsel->pmu_name)) - goto out; - - if (!is_leader) - continue; - /* - * If the event's PMU name starts to repeat, it must be a new - * event. That can be used to distinguish the leader from - * other members, even they have the same event name. - */ - if ((leader !=3D evsel) && - !strcmp(leader->pmu_name, evsel->pmu_name)) { - is_leader =3D false; - continue; - } - - /* Store the leader event for each PMU */ - leaders[nr_pmu++] =3D (uintptr_t) evsel; - } - - /* only one event alias */ - if (nr_pmu =3D=3D total_members) { - parse_state->nr_groups--; - goto handled; - } - - /* - * An uncore event alias is a joint name which means the same event - * runs on all PMUs of a block. - * Perf doesn't support mixed events from different PMUs in the same - * group. The big group has to be split into multiple small groups - * which only include the events from the same PMU. - * - * Here the uncore event aliases must be from the same uncore block. - * The number of PMUs must be same for each alias. The number of new - * small groups equals to the number of PMUs. - * Setting the leader event for corresponding members in each group. - */ - i =3D 0; - __evlist__for_each_entry(list, evsel) { - if (i >=3D nr_pmu) - i =3D 0; - evsel__set_leader(evsel, (struct evsel *) leaders[i++]); - } - - /* The number of members and group name are same for each group */ - for (i =3D 0; i < nr_pmu; i++) { - evsel =3D (struct evsel *) leaders[i]; - evsel->core.nr_members =3D total_members / nr_pmu; - evsel->group_name =3D name ? strdup(name) : NULL; - } - - /* Take the new small groups into account */ - parse_state->nr_groups +=3D nr_pmu - 1; - -handled: - ret =3D 1; - free(name); -out: - free(leaders); - return ret; -} - -__weak struct evsel *arch_evlist__leader(struct list_head *list) -{ - return list_first_entry(list, struct evsel, core.node); -} - -void parse_events__set_leader(char *name, struct list_head *list, - struct parse_events_state *parse_state) +void parse_events__set_leader(char *name, struct list_head *list) { struct evsel *leader; =20 @@ -1782,13 +1665,9 @@ void parse_events__set_leader(char *name, struct lis= t_head *list, return; } =20 - if (parse_events__set_leader_for_uncore_aliase(name, list, parse_state)) - return; - - leader =3D arch_evlist__leader(list); + leader =3D list_first_entry(list, struct evsel, core.node); __perf_evlist__set_leader(list, &leader->core); leader->group_name =3D name; - list_move(&leader->core.node, list); } =20 /* list_event is assumed to point to malloc'ed memory */ @@ -2245,6 +2124,117 @@ static int parse_events__with_hybrid_pmu(struct par= se_events_state *parse_state, return ret; } =20 +__weak int arch_evlist__cmp(const struct evsel *lhs, const struct evsel *r= hs) +{ + /* Order by insertion index. */ + return lhs->core.idx - rhs->core.idx; +} + +static int evlist__cmp(void *state, const struct list_head *l, const struc= t list_head *r) +{ + const struct perf_evsel *lhs_core =3D container_of(l, struct perf_evsel, = node); + const struct evsel *lhs =3D container_of(lhs_core, struct evsel, core); + const struct perf_evsel *rhs_core =3D container_of(r, struct perf_evsel, = node); + const struct evsel *rhs =3D container_of(rhs_core, struct evsel, core); + int *leader_idx =3D state; + int lhs_leader_idx =3D *leader_idx, rhs_leader_idx =3D *leader_idx, ret; + const char *lhs_pmu_name, *rhs_pmu_name; + + /* + * First sort by grouping/leader. Read the leader idx only if the evsel + * is part of a group, as -1 indicates no group. + */ + if (lhs_core->leader !=3D lhs_core || lhs_core->nr_members > 1) + lhs_leader_idx =3D lhs_core->leader->idx; + if (rhs_core->leader !=3D rhs_core || rhs_core->nr_members > 1) + rhs_leader_idx =3D rhs_core->leader->idx; + + if (lhs_leader_idx !=3D rhs_leader_idx) + return lhs_leader_idx - rhs_leader_idx; + + /* Group by PMU. Groups can't span PMUs. */ + lhs_pmu_name =3D evsel__pmu_name(lhs); + rhs_pmu_name =3D evsel__pmu_name(rhs); + ret =3D strcmp(lhs_pmu_name, rhs_pmu_name); + if (ret) + return ret; + + /* Architecture specific sorting. */ + return arch_evlist__cmp(lhs, rhs); +} + +static void parse_events__sort_events_and_fix_groups(struct list_head *lis= t) +{ + int idx =3D -1; + struct evsel *pos, *cur_leader =3D NULL; + struct perf_evsel *cur_leaders_grp =3D NULL; + + /* + * Compute index to insert ungrouped events at. Place them where the + * first ungrouped event appears. + */ + list_for_each_entry(pos, list, core.node) { + const struct evsel *pos_leader =3D evsel__leader(pos); + + if (pos !=3D pos_leader || pos->core.nr_members > 1) + continue; + + idx =3D pos->core.idx; + break; + } + + /* Sort events. */ + list_sort(&idx, list, evlist__cmp); + + /* + * Recompute groups, splitting for PMUs and adding groups for events + * that require them. + */ + idx =3D 0; + list_for_each_entry(pos, list, core.node) { + const struct evsel *pos_leader =3D evsel__leader(pos); + const char *pos_pmu_name =3D evsel__pmu_name(pos); + const char *cur_leader_pmu_name, *pos_leader_pmu_name; + bool force_grouped =3D arch_evsel__must_be_in_group(pos); + + /* Reset index and nr_members. */ + pos->core.idx =3D idx++; + pos->core.nr_members =3D 0; + + /* + * Set the group leader respecting the given groupings and that + * groups can't span PMUs. + */ + if (!cur_leader) + cur_leader =3D pos; + + cur_leader_pmu_name =3D evsel__pmu_name(cur_leader); + if ((cur_leaders_grp !=3D pos->core.leader && !force_grouped) || + strcmp(cur_leader_pmu_name, pos_pmu_name)) { + /* Event is for a different group/PMU than last. */ + cur_leader =3D pos; + /* + * Remember the leader's group before it is overwritten, + * so that later events match as being in the same + * group. + */ + cur_leaders_grp =3D pos->core.leader; + } + pos_leader_pmu_name =3D evsel__pmu_name(pos_leader); + if (strcmp(pos_leader_pmu_name, pos_pmu_name) || force_grouped) { + /* + * Event's PMU differs from its leader's. Groups can't + * span PMUs, so update leader from the group/PMU + * tracker. + */ + evsel__set_leader(pos, cur_leader); + } + } + list_for_each_entry(pos, list, core.node) { + pos->core.leader->nr_members++; + } +} + int __parse_events(struct evlist *evlist, const char *str, struct parse_events_error *err, struct perf_pmu *fake_pmu) { @@ -2266,6 +2256,8 @@ int __parse_events(struct evlist *evlist, const char = *str, return -1; } =20 + parse_events__sort_events_and_fix_groups(&parse_state.list); + /* * Add list to the evlist even with errors to allow callers to clean up. */ diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h index 428e72eaafcc..22fc11b0bd59 100644 --- a/tools/perf/util/parse-events.h +++ b/tools/perf/util/parse-events.h @@ -200,8 +200,7 @@ int parse_events_copy_term_list(struct list_head *old, =20 enum perf_pmu_event_symbol_type perf_pmu__parse_check(const char *name); -void parse_events__set_leader(char *name, struct list_head *list, - struct parse_events_state *parse_state); +void parse_events__set_leader(char *name, struct list_head *list); void parse_events_update_lists(struct list_head *list_event, struct list_head *list_all); void parse_events_evlist_error(struct parse_events_state *parse_state, diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y index 541b8dde2063..90d12f2bc8be 100644 --- a/tools/perf/util/parse-events.y +++ b/tools/perf/util/parse-events.y @@ -203,7 +203,7 @@ PE_NAME '{' events '}' =20 inc_group_count(list, _parse_state); /* Takes ownership of $1. */ - parse_events__set_leader($1, list, _parse_state); + parse_events__set_leader($1, list); $$ =3D list; } | @@ -212,7 +212,7 @@ PE_NAME '{' events '}' struct list_head *list =3D $2; =20 inc_group_count(list, _parse_state); - parse_events__set_leader(NULL, list, _parse_state); + parse_events__set_leader(NULL, list); $$ =3D list; } =20 --=20 2.40.0.rc0.216.gc4246ad0f0-goog From nobody Sat Apr 11 07:08:07 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 263F1C7EE33 for ; Thu, 2 Mar 2023 22:01:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229802AbjCBV5i (ORCPT ); Thu, 2 Mar 2023 16:57:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229818AbjCBV5C (ORCPT ); Thu, 2 Mar 2023 16:57:02 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 913655D46F for ; Thu, 2 Mar 2023 13:56:57 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id c192-20020a25c0c9000000b0092aabd4fa90so288211ybf.18 for ; Thu, 02 Mar 2023 13:56:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1677794217; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Ad9Nr5+r5OwXptIHZFIm1qSb+Ko8YJARAL8GzdEg8mM=; b=FDqE4ZeZBRaCmVWEHIjZIMUcmxU9E1z+xEHKFIuPtDzkrrOC8tGYC4d2LVs4HWOQIy uLfF1pyWIfNRm47J1hAfPUYDIMZiZ3ejolaxUZGEwadFQiC4IDI82AgA/Hd3FN5RIeaY bHPhb7bPKHmffgArJws7i/vRo6yeWuSxC1HOPjZziEcg9Dm+XQKX1EahEVKbBGPRz+jA zlBoi28MPk234qOMXeRRvGwaGDlkHehcoaOGaH7lpobMlcBR7gSED6pHJJXqgrQUZ04L PjigUnM/E8TnDMKG9T0b0f6vzep/jI2kJ8M7bYalY65tUFRPXfmkxVix+3OyU04uZ+mn nyTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677794217; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Ad9Nr5+r5OwXptIHZFIm1qSb+Ko8YJARAL8GzdEg8mM=; b=eztey0UUTNq9hUIvw7oSIP3zp+PEXwW1gq2fmGezkzuG865FbTdX/DMwvfNb4DBj5U kGsGpMnoeiyCWz1gnXXpT67KXGYQuWJ2+Woud2DG2ZRg7R6TWdgzxzR4FtSKawZmSMVO MlnvpjSumcdePdSgdM9qTb/oZ5p3m6ESoAxvQi1d0R9CoR8aTPRywHO9GgwEIfa0tUjK mAbCTvtfGfnrhTWE1WKawsY8pBkbXmoXHkD/PlCIgnUrpR5YVzUVxjhqAtMoN6zP4dVh +RfhnQFUkeASEdPT69O8k4fm58/C9KfQ4r6O18GlmexgOVQvj1Y8658iylku4+J9FlLS YPHw== X-Gm-Message-State: AO0yUKXxiJxIzrw/w4OVxZLv+U8PTAGcKBDHDaJxGMvUMttGLF4g5lct 6XdUH7bUfbBj+zvBx8qh1GHWqJvp9eYk X-Google-Smtp-Source: AK7set/uMoZ6jPJ0j66IhDj9ZIVg60IlLUjFoyrs2T71SZiv9SWR1oEFupyX4cKf1xzSNGXR82f11ynIKe3c X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:5f50:6ef4:b4d0:568e]) (user=irogers job=sendgmr) by 2002:a05:6902:28d:b0:ac6:9d3d:c2c5 with SMTP id v13-20020a056902028d00b00ac69d3dc2c5mr4ybh.633.1677792416877; Thu, 02 Mar 2023 13:26:56 -0800 (PST) Date: Thu, 2 Mar 2023 13:25:30 -0800 In-Reply-To: <20230302212531.1043318-1-irogers@google.com> Message-Id: <20230302212531.1043318-10-irogers@google.com> Mime-Version: 1.0 References: <20230302212531.1043318-1-irogers@google.com> X-Mailer: git-send-email 2.40.0.rc0.216.gc4246ad0f0-goog Subject: [PATCH v2 09/10] perf evsel: Remove use_uncore_alias From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Kan Liang , Zhengjun Xing , Ravi Bangoria , Adrian Hunter , "Steinar H. Gunderson" , Kim Phillips , Florian Fischer , James Clark , Suzuki Poulouse , Sean Christopherson , Leo Yan , John Garry , Kajol Jain , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Stephane Eranian , Ian Rogers Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This flag used to be used when regrouping uncore events in particular due to wildcard matches. This is now handled by sorting evlist and so the flag is redundant. Signed-off-by: Ian Rogers --- tools/perf/util/evsel.c | 1 - tools/perf/util/evsel.h | 1 - tools/perf/util/parse-events.c | 12 +++--------- tools/perf/util/parse-events.h | 3 +-- tools/perf/util/parse-events.y | 11 +++++++---- 5 files changed, 11 insertions(+), 17 deletions(-) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 9c6b486f8bd4..5446128be03b 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -458,7 +458,6 @@ struct evsel *evsel__clone(struct evsel *orig) evsel->per_pkg =3D orig->per_pkg; evsel->percore =3D orig->percore; evsel->precise_max =3D orig->precise_max; - evsel->use_uncore_alias =3D orig->use_uncore_alias; evsel->is_libpfm_event =3D orig->is_libpfm_event; =20 evsel->exclude_GH =3D orig->exclude_GH; diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index 72121194d3b1..9a8d08fcad1c 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -89,7 +89,6 @@ struct evsel { bool per_pkg; bool percore; bool precise_max; - bool use_uncore_alias; bool is_libpfm_event; bool auto_merge_stats; bool collect_stat; diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index d6eb0a54dd2d..ac7709c1c5b7 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -1445,15 +1445,13 @@ static int parse_events__inside_hybrid_pmu(struct p= arse_events_state *parse_stat int parse_events_add_pmu(struct parse_events_state *parse_state, struct list_head *list, char *name, struct list_head *head_config, - bool auto_merge_stats, - bool use_alias) + bool auto_merge_stats) { struct perf_event_attr attr; struct perf_pmu_info info; struct perf_pmu *pmu; struct evsel *evsel; struct parse_events_error *err =3D parse_state->error; - bool use_uncore_alias; LIST_HEAD(config_terms); =20 pmu =3D parse_state->fake_pmu ?: perf_pmu__find(name); @@ -1488,8 +1486,6 @@ int parse_events_add_pmu(struct parse_events_state *p= arse_state, memset(&attr, 0, sizeof(attr)); } =20 - use_uncore_alias =3D (pmu->is_uncore && use_alias); - if (!head_config) { attr.type =3D pmu->type; evsel =3D __add_event(list, &parse_state->idx, &attr, @@ -1499,7 +1495,6 @@ int parse_events_add_pmu(struct parse_events_state *p= arse_state, /*cpu_list=3D*/NULL); if (evsel) { evsel->pmu_name =3D name ? strdup(name) : NULL; - evsel->use_uncore_alias =3D use_uncore_alias; return 0; } else { return -ENOMEM; @@ -1560,7 +1555,6 @@ int parse_events_add_pmu(struct parse_events_state *p= arse_state, evsel->use_config_name =3D true; =20 evsel->pmu_name =3D name ? strdup(name) : NULL; - evsel->use_uncore_alias =3D use_uncore_alias; evsel->percore =3D config_term_percore(&evsel->config_terms); =20 if (parse_state->fake_pmu) @@ -1622,7 +1616,7 @@ int parse_events_multi_pmu_add(struct parse_events_st= ate *parse_state, parse_events_copy_term_list(head, &orig_head); if (!parse_events_add_pmu(parse_state, list, pmu->name, orig_head, - true, true)) { + /*auto_merge_stats=3D*/true)) { pr_debug("%s -> %s/%s/\n", str, pmu->name, alias->str); ok++; @@ -1634,7 +1628,7 @@ int parse_events_multi_pmu_add(struct parse_events_st= ate *parse_state, =20 if (parse_state->fake_pmu) { if (!parse_events_add_pmu(parse_state, list, str, head, - true, true)) { + /*auto_merge_stats=3D*/true)) { pr_debug("%s -> %s/%s/\n", str, "fake_pmu", str); ok++; } diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h index 22fc11b0bd59..fdac44dc696b 100644 --- a/tools/perf/util/parse-events.h +++ b/tools/perf/util/parse-events.h @@ -183,8 +183,7 @@ int parse_events_add_breakpoint(struct list_head *list,= int *idx, int parse_events_add_pmu(struct parse_events_state *parse_state, struct list_head *list, char *name, struct list_head *head_config, - bool auto_merge_stats, - bool use_alias); + bool auto_merge_stats); =20 struct evsel *parse_events__add_event(int idx, struct perf_event_attr *att= r, const char *name, const char *metric_id, diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y index 90d12f2bc8be..f1b153c72d67 100644 --- a/tools/perf/util/parse-events.y +++ b/tools/perf/util/parse-events.y @@ -313,7 +313,7 @@ event_pmu_name opt_pmu_config list =3D alloc_list(); if (!list) CLEANUP_YYABORT; - if (parse_events_add_pmu(_parse_state, list, $1, $2, false, false)) { + if (parse_events_add_pmu(_parse_state, list, $1, $2, /*auto_merge_stats= =3D*/false)) { struct perf_pmu *pmu =3D NULL; int ok =3D 0; =20 @@ -330,8 +330,10 @@ event_pmu_name opt_pmu_config !perf_pmu__match(pattern, pmu->alias_name, $1)) { if (parse_events_copy_term_list(orig_terms, &terms)) CLEANUP_YYABORT; - if (!parse_events_add_pmu(_parse_state, list, pmu->name, terms, true, = false)) + if (!parse_events_add_pmu(_parse_state, list, pmu->name, terms, + /*auto_merge_stats=3D*/true)) { ok++; + } parse_events_terms__delete(terms); } } @@ -407,7 +409,8 @@ PE_PMU_EVENT_FAKE sep_dc if (!list) YYABORT; =20 - err =3D parse_events_add_pmu(_parse_state, list, $1, NULL, false, false); + err =3D parse_events_add_pmu(_parse_state, list, $1, /*head_config=3D*/NU= LL, + /*auto_merge_stats=3D*/false); free($1); if (err < 0) { free(list); @@ -425,7 +428,7 @@ PE_PMU_EVENT_FAKE opt_pmu_config if (!list) YYABORT; =20 - err =3D parse_events_add_pmu(_parse_state, list, $1, $2, false, false); + err =3D parse_events_add_pmu(_parse_state, list, $1, $2, /*auto_merge_sta= ts=3D*/false); free($1); parse_events_terms__delete($2); if (err < 0) { --=20 2.40.0.rc0.216.gc4246ad0f0-goog From nobody Sat Apr 11 07:08:07 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0BC91C7EE30 for ; Thu, 2 Mar 2023 21:56:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229752AbjCBV4a (ORCPT ); Thu, 2 Mar 2023 16:56:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41742 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229651AbjCBV4U (ORCPT ); Thu, 2 Mar 2023 16:56:20 -0500 Received: from mail-oo1-xc49.google.com (mail-oo1-xc49.google.com [IPv6:2607:f8b0:4864:20::c49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2350F5F6C2 for ; Thu, 2 Mar 2023 13:56:17 -0800 (PST) Received: by mail-oo1-xc49.google.com with SMTP id l11-20020a4aa78b000000b005254a9621e1so359938oom.8 for ; Thu, 02 Mar 2023 13:56:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1677794176; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=E96OmbD6esMdVAtwUHbvFeWPJekq95TF7L8EUqDfMw0=; b=jZSJc76dDwid3Au6BtEir7m0jXc+TZrz7uVlyPg2igAgDJ7p2WpFLJtCx4iOKZ9YTt krYgs/eK/rskZqMmRQ8lNufHKHaodvoY42oUxWqQAbCN21OJuuIhrKIP3OUPkIB89l8S jwFnkbbRbCwV8BfRA82n7QQ0AtavwjvMuwFXlwfzW/1s4YXFPKyOgvY/l3TIivsedTxF tBa7dlEWmGEUV3CyA8WRfi5qX2sKWRfaKZTB1DYpDtJNA4o8DfWF6WPjyvTezOehpYtk KtsuoITnC//5gbgMd6nWJGTi+i9m4DzmU4MU0cb9dnnJo05GtdXhDtntoAz6KbDMgVMY uVOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677794176; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=E96OmbD6esMdVAtwUHbvFeWPJekq95TF7L8EUqDfMw0=; b=Pfw6Q6ZyjsXODbYVscCgii7Aqx5ndJ3HfK5Poejcxzy2tOw0T+NKUMONuG6slmgMYa 47G4YAmgMUervj1QmxqqaVyZKT4KnQZ1+SsbBXl6IPPgdYCnRdFPsVLD2fdx3J2dXFUT oqD9oSU4xSzBBCaHflGqu7Gpv/yQ9JQnyc3D1swyLeUSItCPdScqLU0RyhNlhX4I/pdL FrMAKiG9xoDEl8vH4NAr8MK4vhg+zzS9nKSMRp2PkJfg/VX+b2uwP49zpJrQ6Wwqsk+I UZjL9zxsnJPaqVg7idNK6RWVRkgMPnd2n3qV5l5XwKyiIMX8+IkW6CZUFqHWx0u5W6Mi 0HVg== X-Gm-Message-State: AO0yUKWNGJU8mLKoXycmDrz6lU0zutby2pe5fEfOGs3ycVXp+FhRHvrl YldMKKfsC5bbEE3nH/GzTAx1edEsqEuv X-Google-Smtp-Source: AK7set9plTppjtkpAS+TuXxvvvv5zLYzd11C+TI9Fa4U2o1LMY7iR5GeAm2cZlPw6kGtjPkNW90+J8DaP1VV X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:5f50:6ef4:b4d0:568e]) (user=irogers job=sendgmr) by 2002:a25:9b86:0:b0:a8a:a652:2a69 with SMTP id v6-20020a259b86000000b00a8aa6522a69mr5055941ybo.10.1677792425056; Thu, 02 Mar 2023 13:27:05 -0800 (PST) Date: Thu, 2 Mar 2023 13:25:31 -0800 In-Reply-To: <20230302212531.1043318-1-irogers@google.com> Message-Id: <20230302212531.1043318-11-irogers@google.com> Mime-Version: 1.0 References: <20230302212531.1043318-1-irogers@google.com> X-Mailer: git-send-email 2.40.0.rc0.216.gc4246ad0f0-goog Subject: [PATCH v2 10/10] perf evlist: Remove nr_groups From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Kan Liang , Zhengjun Xing , Ravi Bangoria , Adrian Hunter , "Steinar H. Gunderson" , Kim Phillips , Florian Fischer , James Clark , Suzuki Poulouse , Sean Christopherson , Leo Yan , John Garry , Kajol Jain , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Stephane Eranian , Ian Rogers Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Maintaining the number of groups during event parsing is problematic and since changing to sort/regroup events can only be computed by a linear pass over the evlist. As the value is generally only used in tests, rather than hold it in a variable compute it by passing over the evlist when necessary. This change highlights that libpfm's counting of groups with a single entry disagreed with regular event parsing. The libpfm tests are updated accordingly. Signed-off-by: Ian Rogers --- tools/lib/perf/evlist.c | 18 +++++++++++++++++- tools/lib/perf/include/internal/evlist.h | 1 - tools/lib/perf/include/perf/evlist.h | 1 + tools/perf/builtin-record.c | 2 +- tools/perf/builtin-report.c | 2 +- tools/perf/tests/bpf.c | 1 - tools/perf/tests/parse-events.c | 22 +++++++++++----------- tools/perf/tests/pfm.c | 12 ++++++------ tools/perf/util/evlist.c | 2 +- tools/perf/util/evlist.h | 6 ++++++ tools/perf/util/header.c | 3 +-- tools/perf/util/parse-events.c | 1 - tools/perf/util/parse-events.h | 1 - tools/perf/util/parse-events.y | 10 ---------- tools/perf/util/pfm.c | 1 - 15 files changed, 45 insertions(+), 38 deletions(-) diff --git a/tools/lib/perf/evlist.c b/tools/lib/perf/evlist.c index 2d6121e89ccb..81e8b5fcd8ba 100644 --- a/tools/lib/perf/evlist.c +++ b/tools/lib/perf/evlist.c @@ -703,7 +703,23 @@ void perf_evlist__set_leader(struct perf_evlist *evlis= t) struct perf_evsel *first =3D list_entry(evlist->entries.next, struct perf_evsel, node); =20 - evlist->nr_groups =3D evlist->nr_entries > 1 ? 1 : 0; __perf_evlist__set_leader(&evlist->entries, first); } } + +int perf_evlist__nr_groups(struct perf_evlist *evlist) +{ + struct perf_evsel *evsel; + int nr_groups =3D 0; + + perf_evlist__for_each_evsel(evlist, evsel) { + /* + * evsels by default have a nr_members of 1, and they are their + * own leader. If the nr_members is >1 then this is an + * indication of a group. + */ + if (evsel->leader =3D=3D evsel && evsel->nr_members > 1) + nr_groups++; + } + return nr_groups; +} diff --git a/tools/lib/perf/include/internal/evlist.h b/tools/lib/perf/incl= ude/internal/evlist.h index 850f07070036..3339bc2f1765 100644 --- a/tools/lib/perf/include/internal/evlist.h +++ b/tools/lib/perf/include/internal/evlist.h @@ -17,7 +17,6 @@ struct perf_mmap_param; struct perf_evlist { struct list_head entries; int nr_entries; - int nr_groups; bool has_user_cpus; bool needs_map_propagation; /** diff --git a/tools/lib/perf/include/perf/evlist.h b/tools/lib/perf/include/= perf/evlist.h index 9ca399d49bb4..e894b770779e 100644 --- a/tools/lib/perf/include/perf/evlist.h +++ b/tools/lib/perf/include/perf/evlist.h @@ -47,4 +47,5 @@ LIBPERF_API struct perf_mmap *perf_evlist__next_mmap(stru= ct perf_evlist *evlist, (pos) =3D perf_evlist__next_mmap((evlist), (pos), overwrite)) =20 LIBPERF_API void perf_evlist__set_leader(struct perf_evlist *evlist); +LIBPERF_API int perf_evlist__nr_groups(struct perf_evlist *evlist); #endif /* __LIBPERF_EVLIST_H */ diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index a0870c076dc0..234b371b7b9f 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -2474,7 +2474,7 @@ static int __cmd_record(struct record *rec, int argc,= const char **argv) rec->tool.ordered_events =3D false; } =20 - if (!rec->evlist->core.nr_groups) + if (evlist__nr_groups(rec->evlist) =3D=3D 0) perf_header__clear_feat(&session->header, HEADER_GROUP_DESC); =20 if (data->is_pipe) { diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index 2ee2ecca208e..6400615b5e98 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c @@ -1481,7 +1481,7 @@ int cmd_report(int argc, const char **argv) =20 setup_forced_leader(&report, session->evlist); =20 - if (symbol_conf.group_sort_idx && !session->evlist->core.nr_groups) { + if (symbol_conf.group_sort_idx && evlist__nr_groups(session->evlist) =3D= =3D 0) { parse_options_usage(NULL, options, "group-sort-idx", 0); ret =3D -EINVAL; goto error; diff --git a/tools/perf/tests/bpf.c b/tools/perf/tests/bpf.c index ae9223f27cfb..8beb46066034 100644 --- a/tools/perf/tests/bpf.c +++ b/tools/perf/tests/bpf.c @@ -153,7 +153,6 @@ static int do_test(struct bpf_object *obj, int (*func)(= void), } =20 evlist__splice_list_tail(evlist, &parse_state.list); - evlist->core.nr_groups =3D parse_state.nr_groups; =20 evlist__config(evlist, &opts, NULL); =20 diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-event= s.c index 71a5cb343311..ffa6f0a90741 100644 --- a/tools/perf/tests/parse-events.c +++ b/tools/perf/tests/parse-events.c @@ -53,7 +53,7 @@ static int test__checkevent_tracepoint(struct evlist *evl= ist) struct evsel *evsel =3D evlist__first(evlist); =20 TEST_ASSERT_VAL("wrong number of entries", 1 =3D=3D evlist->core.nr_entri= es); - TEST_ASSERT_VAL("wrong number of groups", 0 =3D=3D evlist->core.nr_groups= ); + TEST_ASSERT_VAL("wrong number of groups", 0 =3D=3D evlist__nr_groups(evli= st)); TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT =3D=3D evsel->core.att= r.type); TEST_ASSERT_VAL("wrong sample_type", PERF_TP_SAMPLE_TYPE =3D=3D evsel->core.attr.sample_type); @@ -66,7 +66,7 @@ static int test__checkevent_tracepoint_multi(struct evlis= t *evlist) struct evsel *evsel; =20 TEST_ASSERT_VAL("wrong number of entries", evlist->core.nr_entries > 1); - TEST_ASSERT_VAL("wrong number of groups", 0 =3D=3D evlist->core.nr_groups= ); + TEST_ASSERT_VAL("wrong number of groups", 0 =3D=3D evlist__nr_groups(evli= st)); =20 evlist__for_each_entry(evlist, evsel) { TEST_ASSERT_VAL("wrong type", @@ -677,7 +677,7 @@ static int test__group1(struct evlist *evlist) struct evsel *evsel, *leader; =20 TEST_ASSERT_VAL("wrong number of entries", 2 =3D=3D evlist->core.nr_entri= es); - TEST_ASSERT_VAL("wrong number of groups", 1 =3D=3D evlist->core.nr_groups= ); + TEST_ASSERT_VAL("wrong number of groups", 1 =3D=3D evlist__nr_groups(evli= st)); =20 /* instructions:k */ evsel =3D leader =3D evlist__first(evlist); @@ -719,7 +719,7 @@ static int test__group2(struct evlist *evlist) struct evsel *evsel, *leader; =20 TEST_ASSERT_VAL("wrong number of entries", 3 =3D=3D evlist->core.nr_entri= es); - TEST_ASSERT_VAL("wrong number of groups", 1 =3D=3D evlist->core.nr_groups= ); + TEST_ASSERT_VAL("wrong number of groups", 1 =3D=3D evlist__nr_groups(evli= st)); =20 /* faults + :ku modifier */ evsel =3D leader =3D evlist__first(evlist); @@ -775,7 +775,7 @@ static int test__group3(struct evlist *evlist __maybe_u= nused) struct evsel *evsel, *leader; =20 TEST_ASSERT_VAL("wrong number of entries", 5 =3D=3D evlist->core.nr_entri= es); - TEST_ASSERT_VAL("wrong number of groups", 2 =3D=3D evlist->core.nr_groups= ); + TEST_ASSERT_VAL("wrong number of groups", 2 =3D=3D evlist__nr_groups(evli= st)); =20 /* group1 syscalls:sys_enter_openat:H */ evsel =3D leader =3D evlist__first(evlist); @@ -868,7 +868,7 @@ static int test__group4(struct evlist *evlist __maybe_u= nused) struct evsel *evsel, *leader; =20 TEST_ASSERT_VAL("wrong number of entries", 2 =3D=3D evlist->core.nr_entri= es); - TEST_ASSERT_VAL("wrong number of groups", 1 =3D=3D evlist->core.nr_groups= ); + TEST_ASSERT_VAL("wrong number of groups", 1 =3D=3D evlist__nr_groups(evli= st)); =20 /* cycles:u + p */ evsel =3D leader =3D evlist__first(evlist); @@ -912,7 +912,7 @@ static int test__group5(struct evlist *evlist __maybe_u= nused) struct evsel *evsel, *leader; =20 TEST_ASSERT_VAL("wrong number of entries", 5 =3D=3D evlist->core.nr_entri= es); - TEST_ASSERT_VAL("wrong number of groups", 2 =3D=3D evlist->core.nr_groups= ); + TEST_ASSERT_VAL("wrong number of groups", 2 =3D=3D evlist__nr_groups(evli= st)); =20 /* cycles + G */ evsel =3D leader =3D evlist__first(evlist); @@ -998,7 +998,7 @@ static int test__group_gh1(struct evlist *evlist) struct evsel *evsel, *leader; =20 TEST_ASSERT_VAL("wrong number of entries", 2 =3D=3D evlist->core.nr_entri= es); - TEST_ASSERT_VAL("wrong number of groups", 1 =3D=3D evlist->core.nr_groups= ); + TEST_ASSERT_VAL("wrong number of groups", 1 =3D=3D evlist__nr_groups(evli= st)); =20 /* cycles + :H group modifier */ evsel =3D leader =3D evlist__first(evlist); @@ -1038,7 +1038,7 @@ static int test__group_gh2(struct evlist *evlist) struct evsel *evsel, *leader; =20 TEST_ASSERT_VAL("wrong number of entries", 2 =3D=3D evlist->core.nr_entri= es); - TEST_ASSERT_VAL("wrong number of groups", 1 =3D=3D evlist->core.nr_groups= ); + TEST_ASSERT_VAL("wrong number of groups", 1 =3D=3D evlist__nr_groups(evli= st)); =20 /* cycles + :G group modifier */ evsel =3D leader =3D evlist__first(evlist); @@ -1078,7 +1078,7 @@ static int test__group_gh3(struct evlist *evlist) struct evsel *evsel, *leader; =20 TEST_ASSERT_VAL("wrong number of entries", 2 =3D=3D evlist->core.nr_entri= es); - TEST_ASSERT_VAL("wrong number of groups", 1 =3D=3D evlist->core.nr_groups= ); + TEST_ASSERT_VAL("wrong number of groups", 1 =3D=3D evlist__nr_groups(evli= st)); =20 /* cycles:G + :u group modifier */ evsel =3D leader =3D evlist__first(evlist); @@ -1118,7 +1118,7 @@ static int test__group_gh4(struct evlist *evlist) struct evsel *evsel, *leader; =20 TEST_ASSERT_VAL("wrong number of entries", 2 =3D=3D evlist->core.nr_entri= es); - TEST_ASSERT_VAL("wrong number of groups", 1 =3D=3D evlist->core.nr_groups= ); + TEST_ASSERT_VAL("wrong number of groups", 1 =3D=3D evlist__nr_groups(evli= st)); =20 /* cycles:G + :uG group modifier */ evsel =3D leader =3D evlist__first(evlist); diff --git a/tools/perf/tests/pfm.c b/tools/perf/tests/pfm.c index 71b76deb1f92..2e38dfa34b6c 100644 --- a/tools/perf/tests/pfm.c +++ b/tools/perf/tests/pfm.c @@ -76,7 +76,7 @@ static int test__pfm_events(struct test_suite *test __may= be_unused, count_pfm_events(&evlist->core), table[i].nr_events); TEST_ASSERT_EQUAL(table[i].events, - evlist->core.nr_groups, + evlist__nr_groups(evlist), 0); =20 evlist__delete(evlist); @@ -103,22 +103,22 @@ static int test__pfm_group(struct test_suite *test __= maybe_unused, { .events =3D "{instructions}", .nr_events =3D 1, - .nr_groups =3D 1, + .nr_groups =3D 0, }, { .events =3D "{instructions},{}", .nr_events =3D 1, - .nr_groups =3D 1, + .nr_groups =3D 0, }, { .events =3D "{},{instructions}", .nr_events =3D 1, - .nr_groups =3D 1, + .nr_groups =3D 0, }, { .events =3D "{instructions},{instructions}", .nr_events =3D 2, - .nr_groups =3D 2, + .nr_groups =3D 0, }, { .events =3D "{instructions,cycles},{instructions,cycles}", @@ -161,7 +161,7 @@ static int test__pfm_group(struct test_suite *test __ma= ybe_unused, count_pfm_events(&evlist->core), table[i].nr_events); TEST_ASSERT_EQUAL(table[i].events, - evlist->core.nr_groups, + evlist__nr_groups(evlist), table[i].nr_groups); =20 evlist__delete(evlist); diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 817df2504a1e..a5f406c468f8 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -1777,7 +1777,7 @@ bool evlist__exclude_kernel(struct evlist *evlist) */ void evlist__force_leader(struct evlist *evlist) { - if (!evlist->core.nr_groups) { + if (evlist__nr_groups(evlist) =3D=3D 0) { struct evsel *leader =3D evlist__first(evlist); =20 evlist__set_leader(evlist); diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h index d89d8f92802b..46cf402add93 100644 --- a/tools/perf/util/evlist.h +++ b/tools/perf/util/evlist.h @@ -9,6 +9,7 @@ #include #include #include +#include #include "events_stats.h" #include "evsel.h" #include @@ -255,6 +256,11 @@ static inline struct evsel *evlist__last(struct evlist= *evlist) return container_of(evsel, struct evsel, core); } =20 +static inline int evlist__nr_groups(struct evlist *evlist) +{ + return perf_evlist__nr_groups(&evlist->core); +} + int evlist__strerror_open(struct evlist *evlist, int err, char *buf, size_= t size); int evlist__strerror_mmap(struct evlist *evlist, int err, char *buf, size_= t size); =20 diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 404d816ca124..276870221ce0 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -786,7 +786,7 @@ static int write_pmu_mappings(struct feat_fd *ff, static int write_group_desc(struct feat_fd *ff, struct evlist *evlist) { - u32 nr_groups =3D evlist->core.nr_groups; + u32 nr_groups =3D evlist__nr_groups(evlist); struct evsel *evsel; int ret; =20 @@ -2807,7 +2807,6 @@ static int process_group_desc(struct feat_fd *ff, voi= d *data __maybe_unused) * Rebuild group relationship based on the group_desc */ session =3D container_of(ff->ph, struct perf_session, header); - session->evlist->core.nr_groups =3D nr_groups; =20 i =3D nr =3D 0; evlist__for_each_entry(session->evlist, evsel) { diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index ac7709c1c5b7..c63ec035ecfa 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -2260,7 +2260,6 @@ int __parse_events(struct evlist *evlist, const char = *str, if (!ret) { struct evsel *last; =20 - evlist->core.nr_groups +=3D parse_state.nr_groups; last =3D evlist__last(evlist); last->cmdline_group_boundary =3D true; =20 diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h index fdac44dc696b..767ad1729228 100644 --- a/tools/perf/util/parse-events.h +++ b/tools/perf/util/parse-events.h @@ -122,7 +122,6 @@ struct parse_events_error { struct parse_events_state { struct list_head list; int idx; - int nr_groups; struct parse_events_error *error; struct evlist *evlist; struct list_head *terms; diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y index f1b153c72d67..3a04602d2982 100644 --- a/tools/perf/util/parse-events.y +++ b/tools/perf/util/parse-events.y @@ -49,14 +49,6 @@ static void free_list_evsel(struct list_head* list_evsel) free(list_evsel); } =20 -static void inc_group_count(struct list_head *list, - struct parse_events_state *parse_state) -{ - /* Count groups only have more than 1 members */ - if (!list_is_last(list->next, list)) - parse_state->nr_groups++; -} - %} =20 %token PE_START_EVENTS PE_START_TERMS @@ -201,7 +193,6 @@ PE_NAME '{' events '}' { struct list_head *list =3D $3; =20 - inc_group_count(list, _parse_state); /* Takes ownership of $1. */ parse_events__set_leader($1, list); $$ =3D list; @@ -211,7 +202,6 @@ PE_NAME '{' events '}' { struct list_head *list =3D $2; =20 - inc_group_count(list, _parse_state); parse_events__set_leader(NULL, list); $$ =3D list; } diff --git a/tools/perf/util/pfm.c b/tools/perf/util/pfm.c index b59ba825ddc9..6c11914c179f 100644 --- a/tools/perf/util/pfm.c +++ b/tools/perf/util/pfm.c @@ -112,7 +112,6 @@ int parse_libpfm_events_option(const struct option *opt= , const char *str, "cannot close a non-existing event group\n"); goto error; } - evlist->core.nr_groups++; grp_leader =3D NULL; grp_evt =3D -1; } --=20 2.40.0.rc0.216.gc4246ad0f0-goog