From patchwork Sun Mar 12 02:15:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 6477 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp538018wrd; Sat, 11 Mar 2023 18:17:41 -0800 (PST) X-Google-Smtp-Source: AK7set92YqOTLZPeGy5lcVVUW4u7W2TwR1XjjjJeIzZgx/cZ9vIXwL1FgdTN3mHaz0/ihHmA14I7 X-Received: by 2002:a62:79cb:0:b0:623:1402:4550 with SMTP id u194-20020a6279cb000000b0062314024550mr2050103pfc.12.1678587461512; Sat, 11 Mar 2023 18:17:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678587461; cv=none; d=google.com; s=arc-20160816; b=tbtZyz9wNCPrqEP5lt5LH3DFR069yNob7fJ3y2VO28VZXIYnuO52rAr5aefWbfpzVM 1TGq9VccY4m28rBJnSaas6bzJsyWznfB/jxkP0X3/o33+La53yDTXgS7rsnEb8dGPQTA hkU1MjDxphWnhvE/SFW7UIoiQPZwxv82xceb6KvDYshMrTIvDuA3N5mIqUFNrXsWrJoQ B/oH07YTfA8gndhyd16AdqMurSHc//W9rkoLuQca4mLPQTd0u+H1wMd2vAP53KMNXK+k bQdLi2+4M3vI1c7TQdm8Z1hXaNzu3tIuHn6qe9vkR8lVihk1wpogn25FupVOx72FyiUm OD7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:mime-version:message-id:date :dkim-signature; bh=DiqHA2sh2qjdCAr0BvIE9FBHTrsJoQpwQKJS30o1Ors=; b=NWuulqIhgOZrjYEXPC1uV6VJOLpO6onpX2BtGhQ2dNUeSsczKC4rnsCu8TvvzNK/RV F00NDamdqxlCM15QiNt/xLrvT4EC1p1e2MzhqiXxO7vy774P3QRgG9HEAf8zf9gAkJkt uHPBXEMEU45uXrUPeh/kWU6W2IMB5MOwFgN2hSKnHHDT6Vlp6p/aAYcHqaYDrqNj/8U+ Iq3YQT7doN1p9uuOmAD0gDASJRT0de1gFQSIINOPT46o7la3z9x2C4toltCFxjWdp6PY Y0vhjQtYl1Tpb7SaCjsHgY1iyI1Z/X7kJq356iA6FMxdxIJB6oRzd5FLSldT4T+4Te87 NcrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=oKgHsOgp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w12-20020aa79a0c000000b005a9abc063e3si3105587pfj.113.2023.03.11.18.17.26; Sat, 11 Mar 2023 18:17:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=oKgHsOgp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229665AbjCLCP6 (ORCPT + 99 others); Sat, 11 Mar 2023 21:15:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229534AbjCLCP4 (ORCPT ); Sat, 11 Mar 2023 21:15:56 -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 B99B138B61 for ; Sat, 11 Mar 2023 18:15:55 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id e20-20020a25d314000000b00b33355abd3dso4564872ybf.14 for ; Sat, 11 Mar 2023 18:15:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1678587355; h=cc:to:from:subject:mime-version:message-id:date:from:to:cc:subject :date:message-id:reply-to; bh=DiqHA2sh2qjdCAr0BvIE9FBHTrsJoQpwQKJS30o1Ors=; b=oKgHsOgp/LJThxtOOD0BmOMUoxa9vj7/aLhUxYKjIbC+sQBspp+SbeZUjwaK3aR3xQ iPRiDp6PNbENy8fnbsYvJHvXSRmsGNHrqrAr0eoVzSJwV+u8ylib2UySB1/nQbERcSeO AXXpfYnOm6YaoCLJkjprvjW2+nDkYnfgxFd8P8H1msyGG/RMe1yAw/jxxD2Q5Sxh5TNU L54mIw6mL/cbafd4xoXpi22zf73afZwjVnTd3MFxqqMMGhi07pOnHvykYR0vK9VuI+wR 3H94gjSUI05Prvb3SJOJ0LC4Zl6VmJ3mkzkKAyewdx6b54rbDayKDYE51zlD7gzw0wOc +ffg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678587355; h=cc:to:from:subject:mime-version:message-id:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=DiqHA2sh2qjdCAr0BvIE9FBHTrsJoQpwQKJS30o1Ors=; b=bUgIU8CwZ3ogK8Qp+lyabLJpEmTOGYbu5z5GghUW2k3dEW7KR/FOabq2jccTW4oNju R8lDGsPHlJz/xWxkB0VQox+qi1LdrCQlnPFKzfEAWaYjFDOeZC2HAdl9Nj36ULsQiHTz z0kjVA8PE+mQVulX2m0lf59GeS0Tu7/sR1hgGRitF9Wx/oc8i5Il2r7ID+L85mkbLgrc /vmpWnterERAlQIos7CeaTSlR8LrJiKDstm74O8qeAECdo8AX6yZB5pnZp43WPxcfKmH taCyuaClxdQB6h/btYtTDV5AZzTSSndbTQIOYsuqsrHAQRupoi5xa0zg95diysgtUkqn 1FQA== X-Gm-Message-State: AO0yUKUZDtRVxqOJ8TnfB7jR4rHkRiQZCp8UtReX82kVq3zxxBwWz05u 6c7y6S8obewikggC/ggISwDGvDiZGHdJ X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:b42b:2e07:afb:877e]) (user=irogers job=sendgmr) by 2002:a81:7bd5:0:b0:52e:f77a:c3c with SMTP id w204-20020a817bd5000000b0052ef77a0c3cmr7ywc.454.1678587354723; Sat, 11 Mar 2023 18:15:54 -0800 (PST) Date: Sat, 11 Mar 2023 18:15:32 -0800 Message-Id: <20230312021543.3060328-1-irogers@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.40.0.rc1.284.g88254d51c5-goog Subject: [PATCH v5 00/11] Better fixes for grouping of events From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Mark Rutland , Adrian Hunter , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Kan Liang , Zhengjun Xing , Ravi Bangoria , "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 X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760126525917621664?= X-GMAIL-MSGID: =?utf-8?q?1760126525917621664?= The rules for grouping events have grown more complex. Topdown events must be grouped, but flags like --metric-no-group and flags on metrics don't respect this. Uncore events may be expanded using wild cards for PMU names, but then the events need reordering so the group members are adjacent. Rather than fixing metrics, this change fixes the main event parsing code to first sort and then regroup evsels. As this is shared functionality changes to it should cause concern. The change is done with the intent of simplifying and making more robust the grouping logic, examples are given. If additional changes are necessary, they are most likely necessary to the evsel__group_pmu_name logic as the code avoids breaking groups that are on the same "group" PMU. The group_pmu_name is a variant of the pmu_name tweaked in the case of software and aux events, that use groups in a slightly different manner to conventional events. The code was manually tested as well as passing perf test on a Intel tigerlake CPU with intel-pt. v5. Add Adrian's Acked-by on patch 3, add a fix to the warning logic for multiple event groups as reported by Adrian. v4. Move the Intel pmu->auxtrace initialization to the existing perf_pmu__get_default_config as suggested by Adrian Hunter. v3. Rename pmu_name to group_pmu_name and add patch to warn when events are regrouped as requested by Namhyung. v2. Fix up the commit message on 4/10 (thanks Arnaldo). Drop unnecessary v1 5/10 (thanks Kan). evlist->core.nr_groups wasn't being correctly maintained after the sort/regrouping and so the new patch 10/10 removes that variable and computes it from the evlist when necessary, generally just tests. Ian Rogers (11): libperf evlist: Avoid a use of evsel idx perf stat: Don't remove all grouped events when CPU maps disagree perf pmu: Earlier PMU auxtrace initialization perf stat: Modify the group test perf evsel: Allow const evsel for certain accesses perf evsel: Add function to compute group PMU name perf parse-events: Pass ownership of the group name perf parse-events: Sort and group parsed events perf evsel: Remove use_uncore_alias perf evlist: Remove nr_groups perf parse-events: Warn when events are regrouped tools/lib/perf/evlist.c | 31 ++- tools/lib/perf/include/internal/evlist.h | 1 - tools/lib/perf/include/perf/evlist.h | 1 + tools/perf/arch/x86/util/auxtrace.c | 4 - tools/perf/arch/x86/util/evlist.c | 39 ++-- tools/perf/arch/x86/util/pmu.c | 8 +- tools/perf/builtin-record.c | 2 +- tools/perf/builtin-report.c | 2 +- tools/perf/builtin-stat.c | 24 +- tools/perf/tests/bpf.c | 1 - tools/perf/tests/parse-events.c | 24 +- tools/perf/tests/pfm.c | 12 +- tools/perf/tests/pmu-events.c | 2 +- tools/perf/util/evlist.c | 2 +- tools/perf/util/evlist.h | 8 +- tools/perf/util/evsel.c | 27 ++- tools/perf/util/evsel.h | 8 +- tools/perf/util/header.c | 3 +- tools/perf/util/metricgroup.c | 3 +- tools/perf/util/parse-events.c | 275 ++++++++++++----------- tools/perf/util/parse-events.h | 14 +- tools/perf/util/parse-events.y | 28 +-- tools/perf/util/pfm.c | 1 - tools/perf/util/pmu.c | 6 +- tools/perf/util/python.c | 2 +- tools/perf/util/stat-shadow.c | 2 +- 26 files changed, 284 insertions(+), 246 deletions(-)