Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp1679351pxb; Thu, 7 Oct 2021 12:43:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzpdxg6lWzZlJhSMlXMV/2NvYXy0a9yHX2obwgJJiFG5y4/72kf2zRiyMObTPGZv3amJyqn X-Received: by 2002:aa7:8b56:0:b0:44c:10a:4ee9 with SMTP id i22-20020aa78b56000000b0044c010a4ee9mr5960329pfd.46.1633635782303; Thu, 07 Oct 2021 12:43:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633635782; cv=none; d=google.com; s=arc-20160816; b=Sns8jor4qJAMIHajgpY4xs/kllXjXiEHe1/kFBfi6JH3qxhoDLWKQVuiuymS/xPU4u DwzmL4amj8lPGxGlGL0ACnV7t5a9Fm6M+fM6th7VXZTe4DbLC2x/8ZM0+4SrxUR/Y91T nJXhK0VKQadvHvlZBDJTUTIu/l5OTuOwSLCVEhTFlg+iT1IhwHv0HssMaVml/Vqj2JM3 iAGaKA8MuRccIebvOeHFfIvFhBrL1XuoReuQmNnIDmtLptNOv15HXVQD7ufeMMUKm2ls 5AUCovx8jbb8EkYgsbYF+aCKd27ICsOUuFT4fcXk5TZxWw2NFizCbXIw7MzuxvNjsdLa 4OUA== 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=q25XIGRPo/AFEX2lGF/DA7ZdzHcC4jEovjpSXZwcoac=; b=bF9F3pdUszgZXE8SEdDbOZOUFaQgoKes0CRts8lu3CXUdaDpROh7xTxTqlNWrXdMej MTOF1nrp7MGWWIc4uQpc0tuxnDXpGQsAmGiAhFunIMjFmx5vjl+HtmsZqKDXl8Q2kZr5 4zHWI2wNVQVIY1f73dFhmc7mlWLq6JSGzCMLuwzOY8971njqZ4EhrUBZsSxY4mf6MrMm ku/Q3ghsD3AdCmWzbJ0EhmYJ2iAwDFxh5pp0SoOaeprkOHSm8NHegtjxJR/kCefxkyiy 9V8rX3O33/vc2uM1PwUIdmji35o2zepUKPmDH2Dk/0WZCykP2GXB09+Jp4YACRiAnOlT NZMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=lmn3fGiL; 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 i37si195905pgi.494.2021.10.07.12.42.49; Thu, 07 Oct 2021 12:43:02 -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=lmn3fGiL; 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 S242914AbhJGQ73 (ORCPT + 99 others); Thu, 7 Oct 2021 12:59:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242920AbhJGQ7Y (ORCPT ); Thu, 7 Oct 2021 12:59:24 -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 3FE00C061755 for ; Thu, 7 Oct 2021 09:57:30 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id b5-20020a251b05000000b005b575f23711so8764966ybb.4 for ; Thu, 07 Oct 2021 09:57:30 -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=q25XIGRPo/AFEX2lGF/DA7ZdzHcC4jEovjpSXZwcoac=; b=lmn3fGiLBLg4hDQpS+XPmshtIHewqmdfCcCdRgRKXFY8sL86lZAHy3664sc+bmw5WN BmS/xHodeuDNTBLWoI1XIgiAg2rY33RHm+oh97HzpwlJvvlNNSFVlFLc5iRiijHX1nFc 2LOm5TJu94nrSZ2Lu+hZpvr2J9XpWGVSK7/8ZjRr6ep1ZdaEX1FNtejdu1rFX16FEDKq Ilz0Dz7EG5AqX88orrM6zLTVSJ3O5FdJJ4+cwc7Eb1Aw/mCP5Txfovvwz6YUpcRohWvw BjSdPgqO26D7xjyhOZ2QZRqjDGfx5O9SYuuqv4BU3wIOJF4aEvhplnhr77wN9U7cD7Cl Vrww== 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=q25XIGRPo/AFEX2lGF/DA7ZdzHcC4jEovjpSXZwcoac=; b=mKHARzmGJAKw21KwmspMg1XGS2SvgOE2lbAGmGROmVg8ZhPO3YU92SmOT9qtke5sv8 jv2YYSlEBSMaqIXBfP8d2X41yJW7prY+GUBo2IYzc+eA6inWQNZZtVTIrhmD3E6TvJQv 9G0uOgDHy13t+gAb6T0CvIOzeMsyXg4xsW1Z70Wetr8czNMUy040C20FQVVXrlbac0l6 GEVvEjl/jKH1bUS4JIjOCVqlfvLxOSZMHyVpWXwBu/vHA5PcAObqQ6mcqka9kh0bvWMK 2qDbgzXmUFvOjAzZwesW0HkTdERvRmHdDZPTKa+E0mCH2N8CtRuf09wb+439nWki1EmV PvwQ== X-Gm-Message-State: AOAM53031/qPrSgHqdbwoQYzDN+OoNE23CN48oZvNeSgMzl+x9EY5T3h GiBU+sZ6H3KAr+l0TBbopLJ9i5FtaIlY X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:fe85:5e36:cb6f:76bc]) (user=irogers job=sendgmr) by 2002:a25:6185:: with SMTP id v127mr5930550ybb.151.1633625849408; Thu, 07 Oct 2021 09:57:29 -0700 (PDT) Date: Thu, 7 Oct 2021 09:56:26 -0700 Message-Id: <20211007165647.3514803-1-irogers@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.33.0.882.g93a45727a2-goog Subject: [PATCH 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 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. 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/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 | 1441 ++++++++++++++----------- 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/s390-sample-raw.c | 6 +- tools/perf/util/stat-shadow.c | 27 +- 30 files changed, 1448 insertions(+), 838 deletions(-) create mode 100644 tools/include/linux/list_sort.h create mode 100644 tools/lib/list_sort.c -- 2.33.0.882.g93a45727a2-goog