From patchwork Thu Mar 2 21:25:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 6053 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp100362wrd; Thu, 2 Mar 2023 14:27:53 -0800 (PST) X-Google-Smtp-Source: AK7set8nzP5Y12jkLFpMVB3s5YJmGLuxcdiQCi6xgvLWzy6rohHp1SEchtkWONS23aEEF8a0SdOQ X-Received: by 2002:aa7:c7d4:0:b0:4af:51dc:da5e with SMTP id o20-20020aa7c7d4000000b004af51dcda5emr10695277eds.38.1677796073303; Thu, 02 Mar 2023 14:27:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677796073; cv=none; d=google.com; s=arc-20160816; b=pAnei3I2W+gFA0VjiklnH12sIAQQz0nSnnD59myk9WoY7U+aRUvHjtYtT4w7MpTspI xxBZs8FAQGmPGbwkaVOj8jPGLvT4w0e5ZK/DVsUqUDj1aVIn0Wa0Q/LyRj+1rlIikslm oU9nAz+pQoeU6WDvzS0oXnEmuHfIO3dPQTMXbXBIhLqabEhB7lzS3oc8zPt7whwymJM1 YaJTpThebFzsjd2qPLqPYUxJJGbqVJY6rYFh2KaA9ZTVI0HsGHRpZy4zhuVbAUFwYkEi 0LjLFTTbHTOC3C1y1ZwWqvEH+0R4ozQ78B/TDvK99lAXPsC7+D/0NHd7t1bL+uuXR1ec jOSw== 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=ToIbaMj5AqTB1LrmzVhyr0yCG3hmCJZiHtcXsiBUWn0=; b=szp4VequH/MXXdxs2EtereE7YyUKC6gEm+lOUevkLr2AlqDDUoVX8e3Db2IPcVF1k8 Cs+H5UfOx+fF70BequqPqQVOX3ryUr9N6TM2AVTES+QW3XxENA+UZWULArThtfKUywnP LDVJwxYxsraVbm1ln2G13tfDfsA7ZU/8VN83P7bOjAA4DRgsAx1xZjLvX58KiV2+PHnm xxxZGqJ/EhK8enEsF9jDTpNsCFn+/Vlt/IiW+krMQUyPDvNrY+7u+/R64DBrANKxkH5U DH4HzZfWbTuC8R29fWAmLIPSCk48HFz5BcDhyj0/+ffNNceduaBAysmvPOHA/pF+f0qi LVGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="bK/Ou+Iv"; 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 w26-20020aa7da5a000000b004be3ac4797dsi748341eds.582.2023.03.02.14.27.30; Thu, 02 Mar 2023 14:27:53 -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="bK/Ou+Iv"; 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 S229960AbjCBWWN (ORCPT + 99 others); Thu, 2 Mar 2023 17:22:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229832AbjCBWWK (ORCPT ); Thu, 2 Mar 2023 17:22:10 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 66A4F47423 for ; Thu, 2 Mar 2023 14:22:05 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id x64-20020a25ce43000000b00ae6d5855d78so372470ybe.12 for ; Thu, 02 Mar 2023 14:22:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1677795724; h=cc:to:from:subject:mime-version:message-id:date:from:to:cc:subject :date:message-id:reply-to; bh=ToIbaMj5AqTB1LrmzVhyr0yCG3hmCJZiHtcXsiBUWn0=; b=bK/Ou+IvLW7si3X25Me0v/zKve3PMk5q3JVIBNXG+5bZjYHwevtKgqCOITdHRtomfs kqYzAXKVoNBF7KaqTg7+BpBH5dc/G1z+0B74qn3wGfRqRVmZE+nyyp9XBL+Aai2XJnJw Yc0aCxSaSUeZMPOOLxwe2ZLJop1u5Ib4NKTG5BA98kGZKwRNjz70ExMsZJ5DwJAWihCQ ektC4WRijV78PufKzYTHT3oxFIjn7zORbRMV5n/a5s2yP4yOHAxG9OuCy2SGOyqannFM oUW23lewgRwXliqM24/TBTEkUlQxZFkJtjpxi7PE6HSQKHW0Phhxpqelzef6wwrHX7Lc n+Vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677795724; h=cc:to:from:subject:mime-version:message-id:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=ToIbaMj5AqTB1LrmzVhyr0yCG3hmCJZiHtcXsiBUWn0=; b=oGzxmfPiMgLwzFBgk2DdDmLKzzvhkC1msMa4wtwh6K9gl4j8BSvFvbpt0n+flcjvFH cOlKW3t/GLx9N3pmIliT5U3EZAVIXMdHfSQxKbSZ7IWoLx6Xyz0EoUAlqYSPk9mi1sg0 Yp6LXA0doZXfE+wCh+QQZ3bG/sB2IS1lYEpMowmUNYBUlEyzz5cIIaXv21tmBF0qjoBi CXVEXLxb/Q4mdO5JsDyZFVauVS/u7uy7lIUPcAlJXkAM+jDaBqa32V3lnagNokEumn8Y josmFfeT6196D0DCo5WofaoFn6rf7B4UM+tddUzqs632BMpqxf0uGTkx7/MEaW00EfvB ul/Q== X-Gm-Message-State: AO0yUKW4XghuwOhDx0APAKHgHygswIHs+VnGkAc3yx/SFOViI/l37HpJ /9WrinlQ4wGQRT525rcN0hdy7CFcEVeI X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:5f50:6ef4:b4d0:568e]) (user=irogers job=sendgmr) by 2002:a5b:1cb:0:b0:9f5:af8a:3b61 with SMTP id f11-20020a5b01cb000000b009f5af8a3b61mr6433739ybp.4.1677792348374; Thu, 02 Mar 2023 13:25:48 -0800 (PST) Date: Thu, 2 Mar 2023 13:25:21 -0800 Message-Id: <20230302212531.1043318-1-irogers@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.40.0.rc0.216.gc4246ad0f0-goog Subject: [PATCH v2 00/10] Better fixes for grouping of 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 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?1759296695200018198?= X-GMAIL-MSGID: =?utf-8?q?1759296695200018198?= The rules for grouping events has 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__pmu_name logic as the code avoids breaking groups that are on the same PMU. The pmu_name is 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. 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 (10): libperf evlist: Avoid a use of evsel idx perf stat: Don't remove all grouped events when CPU maps disagree perf record: Early auxtrace initialization before event parsing perf stat: Modify the group test perf evsel: Allow const evsel for certain accesses perf evsel: Add function to compute 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 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 | 17 +- tools/perf/arch/x86/util/evlist.c | 39 ++-- tools/perf/builtin-record.c | 8 +- tools/perf/builtin-report.c | 2 +- tools/perf/builtin-stat.c | 24 ++- tools/perf/tests/bpf.c | 1 - tools/perf/tests/parse-events.c | 22 +- tools/perf/tests/pfm.c | 12 +- tools/perf/util/auxtrace.h | 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/parse-events.c | 254 +++++++++++------------ tools/perf/util/parse-events.h | 7 +- tools/perf/util/parse-events.y | 27 +-- 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 +- 24 files changed, 270 insertions(+), 237 deletions(-)