Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp2100992pxb; Sun, 17 Oct 2021 06:00:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyGuh1ktLzmYtG+5ThKlr1Nr1dXt3ltnjKyOIYxfiKw6B81gJaUBHa/34pkNGEy7APTVK+u X-Received: by 2002:a17:902:b716:b0:13f:b2d1:f316 with SMTP id d22-20020a170902b71600b0013fb2d1f316mr3410580pls.24.1634475615095; Sun, 17 Oct 2021 06:00:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634475615; cv=none; d=google.com; s=arc-20160816; b=OMvaUE7UbdCCVq2NsnuEBr3cRWBpPPxaAH/ZCdPUrBPYLWzy9IKwaGcqXCr7SaUO8C 1qD+n2oKxVjejdCMpOg2BVd83gmVHG3NZrcgHvKtrmxZRjcMRfrrpSIAC0Cyan8sUgxh BwTfYMEgsl1Fc7n8/W3jeSwDckxp1DMLhzO35VYeVHD2YSFrBPq31oU65PkLsBJ+RnVu zd2YP/Jyu976l01wMg1lVCBfQjDygYf+50pWd3f+69TEmcNj61futzk9UAM4Tgns4ECp BEHUzNwRwU3AWrahy6TEQNLHemtACNXSAW85TvNlB6zXTBQ2cRQ+A47WAaDbbw64qEjW 20xw== 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=/nDYakaYxbaZyFecc8yKJArWXyue+4iCPN+vHLxVtm8=; b=diUvrgjndbgYmhI58nufpGZpjFT0Lj91oxhSdAMYbGR0/ZaYcWyoCbO8FI8febioR3 xrPJ4ljx1tVVizpm3HmShPXzQ+yR2QaDWEAmYI91DWto6+Qrv7Ulce2CEHPTccYZ9guR 5u7FtdDZxY9pVcfMr6QS9Rg74FGehohPYTZ8uT4V475K9RS9SVxLjupnoFfMU2ygv8Rf 9Nbg4j+c2ovJ6YOct3LVWeaIc4M4PsKPF+zB3qcWGFHdWX/zm5HR0NaU8VuVoUsBFm9o BaWFbgR0XdrN8VHqMz43TFPHqRIik76sN690YdRjZ3Z6mZCngHpnXzPrlgH1phDb1z8p B6Ug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=XmoWQqvt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l185si17274270pge.3.2021.10.17.06.00.01; Sun, 17 Oct 2021 06:00:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=XmoWQqvt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S242113AbhJORXq (ORCPT + 99 others); Fri, 15 Oct 2021 13:23:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237969AbhJORXo (ORCPT ); Fri, 15 Oct 2021 13:23:44 -0400 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 4D506C061762 for ; Fri, 15 Oct 2021 10:21:38 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id f8-20020a2585480000b02905937897e3daso11985665ybn.2 for ; Fri, 15 Oct 2021 10:21:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:message-id:mime-version:subject:from:to:cc; bh=/nDYakaYxbaZyFecc8yKJArWXyue+4iCPN+vHLxVtm8=; b=XmoWQqvtNFAnC5n3qHx2qxnIzT/lAJ3vqMh2+Y5AFYiZuFEXjIUIYEonLUunixL318 H0ee/WTxT/JZghvOXvp4P8ievcQt7y+xZhIpgseQrLnNpRwzwGKCM6eOETch3oNK1YMn qPZnax1FHsNdoSx2irt8F79E0yUWGTyz4CuQHMk+f5vRc3N2Rv10sk0EjRvsyreUr0TR ugItKRl9iCkmtx8ipyHS+YCt38w6cin9bnFTLvzlrzVTTLmdqfhsBOOuADQUrkR/851e sWhNZFvjyhglxz7DZ+dPBaSilVsOAKALFDmVUokE2bbcxmvLqN8rWPMuwQavZ6oUOIt2 hZHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=/nDYakaYxbaZyFecc8yKJArWXyue+4iCPN+vHLxVtm8=; b=msTjngrORuT5pvVWmzHFzoC2W3+G21FeiahNi82+a2ImFeyXVnZyhe7x46eTEHrMKU KE60QSKJEXVSn/Oz5uZURsIzB6CxtDzy5hpPpoU8rJfH7EfNobzDHA4Ai390rRgqmI5u 1wDMKmJ8ZeXMwIJT9RjYD1ntFDQCcg+CL0AFxCxwGJrYfZrg1X2gTVrefD7lrh6Fhlra kI7WYshfWhk4ZhmoHisE4i9R1wFN/xIE3AZ7t+y6FQDySdkxRu0Qelp05ReJIJoecAgE Z/PMsjkDxktFCqJPaNVvQi0IPJk0tLL0xO5JgQuUO32bYWtnHNIy8owFnoYm6vnHeRVZ DGQg== X-Gm-Message-State: AOAM531SgpFd5Ugi6uNroKN+AkZS8XnOO+oHEoVv6furidQqFH/xRyFf 7AcxLrkhWcF4fVFUfN9VsBGqkEr7Ei7F X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:69bc:7451:58ad:6585]) (user=irogers job=sendgmr) by 2002:a25:6e06:: with SMTP id j6mr14669326ybc.311.1634318497453; Fri, 15 Oct 2021 10:21:37 -0700 (PDT) Date: Fri, 15 Oct 2021 10:21:11 -0700 Message-Id: <20211015172132.1162559-1-irogers@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.33.0.1079.g6e70778dc9-goog Subject: [PATCH v2 00/21] perf metric: Fixes and allow modifiers From: Ian Rogers To: Andi Kleen , Jiri Olsa , Jin Yao , Namhyung Kim , John Garry , Kajol Jain , "Paul A . Clarke" , Arnaldo Carvalho de Melo , Riccardo Mancini , Kan Liang , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Kees Cook , Sami Tolvanen , Nick Desaulniers , Andrew Morton , Jacob Keller , Zhen Lei , ToastC , Joakim Zhang , Felix Fietkau , Jiapeng Chong , Song Liu , Fabian Hemmer , Alexander Antonov , Nicholas Fraser , Adrian Hunter , Denys Zagorui , Wan Jiabing , Thomas Richter , Sumanth Korikkar , Heiko Carstens , Changbin Du , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Andrew Kilroy Cc: Stephane Eranian , Ian Rogers Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There are 4 main changes in this patch set: - perf metric: Modify resolution and recursion check. - perf parse-events: Add new "metric-id" term. - perf metrics: Modify setup and deduplication - perf metric: Allow modifiers on metrics. In overview the changes start by trying to simplify the metric code, then it fixes various bugs and finally it builds a new feature of allowing metrics like: $ perf stat -M IPC:u,IPC:k -a sleep 1 Performance counter stats for 'system wide': 93,269,988 inst_retired.any:k # 0.26 IPC:k 352,037,460 cpu_clk_unhalted.thread:k 70,317,865 inst_retired.any:u # 0.76 IPC:u 92,762,220 cpu_clk_unhalted.thread:u 1.003754577 seconds time elapsed Previous complexity came from using the evsel->name as the identifier for events in metrics, however, this name isn't stable and has issues around wildcard expansion. These changes fix this by adding a dedicated metric_id to evsels, performing deduplication on IDs before event parsing and not handling all evsels on a single evlist. The recursion and metric_ref logic is simplified, the first by moving data from the heap to the stack, the latter by building in an array rather than a linked list. This logic is integral to metric set up and simplification makes the effects of the changes easier to follow, in particular as there are fewer structs being maintained. Event parsing is modified to allow qualifiers on kernel PMU events, this is necessary to allow the metric-id to be added, but allows qualifiers in other cases like specifying callgraph or a name. There is a certain amount of comment adding and const-ification, this is with a view to making the code more intention revealing and to aid following its logic. For example, the pmu event tables should never change and it'd be a bug if they ever did, it's therefore strange to access it using non-const pointers. The kernel list_sort.c/h are added for use sorting metrics in order to deduplicate/reuse events from a larger group in a smaller one. This was previously done by inserting in size order, but that only worked within a metric group. Some of the commit messages show the TopDownL1 metrics being used on a SkylakeX machine. These metrics were removed by c4ad8fabd03f76ed3a2a4c8aef6baf6cd4f24542 ("perf vendor events: Update metrics for SkyLake Server") and the data was gathered with this patch reverted. v2. Add METADATA fixes to 'Add list_sort' suggested by Arnaldo Carvalho de Melo . Fix arm64 function declaration in 'Add const to pmu_events_map' found by Andrew Kilroy . Add a static in 'Make pmu_event tables const' suggested by John Garry . Add acked-by: Andi Kleen . Fix/handle 0 events case in 'Modify setup and deduplication'. Fix a missed strdup that resulted in a double free in 'Allow modifiers on metrics.' Ian Rogers (21): tools lib: Add list_sort. perf pmu: Add const to pmu_events_map. perf pmu: Make pmu_sys_event_tables const. perf pmu: Make pmu_event tables const. perf metric: Move runtime value to the expr context perf metric: Add documentation and rename a variable. perf metric: Add metric new and free perf metric: Only add a referenced metric once perf metric: Modify resolution and recursion check. perf metric: Comment data structures. perf metric: Document the internal 'struct metric' perf metric: Simplify metric_refs calculation. perf parse-events: Add const to evsel name perf parse-events: Add new "metric-id" term. perf parse-events: Allow config on kernel PMU events perf metric: Encode and use metric-id as qualifier perf expr: Add subset utility. perf metrics: Modify setup and deduplication perf metric: Switch fprintf to pr_err. perf parse-events: Identify broken modifiers. perf metric: Allow modifiers on metrics. tools/include/linux/list_sort.h | 14 + tools/lib/list_sort.c | 252 +++++ tools/perf/MANIFEST | 1 + tools/perf/arch/arm64/util/pmu.c | 2 +- tools/perf/arch/powerpc/util/header.c | 2 +- tools/perf/check-headers.sh | 2 + tools/perf/pmu-events/jevents.c | 6 +- tools/perf/pmu-events/pmu-events.h | 8 +- tools/perf/tests/expand-cgroup.c | 2 +- tools/perf/tests/expr.c | 29 +- tools/perf/tests/parse-metric.c | 2 +- tools/perf/tests/pmu-events.c | 59 +- tools/perf/util/Build | 5 + tools/perf/util/evsel.c | 17 + tools/perf/util/evsel.h | 2 + tools/perf/util/expr.c | 56 +- tools/perf/util/expr.h | 16 +- tools/perf/util/expr.l | 6 +- tools/perf/util/expr.y | 2 +- tools/perf/util/metricgroup.c | 1461 ++++++++++++++----------- tools/perf/util/metricgroup.h | 35 +- tools/perf/util/parse-events-hybrid.c | 34 +- tools/perf/util/parse-events-hybrid.h | 6 +- tools/perf/util/parse-events.c | 166 +-- tools/perf/util/parse-events.h | 11 +- tools/perf/util/parse-events.l | 18 +- tools/perf/util/parse-events.y | 27 +- tools/perf/util/pfm.c | 3 +- tools/perf/util/pmu.c | 22 +- tools/perf/util/pmu.h | 10 +- tools/perf/util/python-ext-sources | 1 + tools/perf/util/s390-sample-raw.c | 6 +- tools/perf/util/stat-shadow.c | 27 +- 33 files changed, 1470 insertions(+), 840 deletions(-) create mode 100644 tools/include/linux/list_sort.h create mode 100644 tools/lib/list_sort.c -- 2.33.0.1079.g6e70778dc9-goog