From patchwork Sat Sep 7 05:08:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13795073 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4C0A2E6FE47 for ; Sat, 7 Sep 2024 05:10:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:To:From:Subject :Mime-Version:Message-Id:Date:Reply-To:Cc:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=LHcvOjafmqzQD8jBi1RccAQdk8Mr4rwIBj8z7AkCRow=; b=PlZwBI+Ct3RZku0Op6iOS7q6fm 1j+j0HdtE3DDTC8YDHIg9nfGYmJwieeOufzueQ6Xvx87MsoLuyyeUzEFTGUdPPoG7Wz/Ne0n7Lv7k cY74Uf5yQlKDipSZpt6mNkkBJiFQDuXILvzuc+xmnK0lNRoY7EDMlwvlRBHboVaVn6wBLGbe9c3RO xb61MUrYY5ug+2CVs6mPvYYOS9H9zyEWN5ye2GkV/o8ZAQ5He4JtDeCWMXoAG2neySoUPdBQmYsiL l3RbCxrxfcMIwHzhYliQkjppZiqA1ZEQsmoy8tVdHuB/8WShapfalYcWhLHkwbqargCCpG85o9Cel f8iV+wlw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1smnhk-0000000EMZQ-3dHa; Sat, 07 Sep 2024 05:09:48 +0000 Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1smngg-0000000EMCq-1xbX for linux-arm-kernel@lists.infradead.org; Sat, 07 Sep 2024 05:08:44 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-6d7124939beso86709607b3.2 for ; Fri, 06 Sep 2024 22:08:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1725685720; x=1726290520; darn=lists.infradead.org; h=to:from:subject:mime-version:message-id:date:from:to:cc:subject :date:message-id:reply-to; bh=LHcvOjafmqzQD8jBi1RccAQdk8Mr4rwIBj8z7AkCRow=; b=bDuLqqvbPLCY+iDVwXvnS15gb34gDpDsWg6urTQEs7zIQ2Na/pNFC6KSfuNNZdYBsk LepIMlA/nltcTBqfUJ2ENKUoPVVwFzs/QRbdDwtlQpDO+5ZvjVKTNBHrHJdPoiPqZSJP SXFJpsn9LAzN6EecutwdbTY0td34tiEfdnOa229SG34bTVW9nhuy4X/IjAQ4VNT/CzHG LQjcaNh+cdaqEz6ZxoZQPgVdqfb3sYYUOCFuQhfnK6M+a14zZTmJGAGHhD0iWpidH9gH QlAGwGJ27fTtC9UJJwAYKQB8Doy7ulmdHg6SbDEBWuEGYIGzfbUw7d5B4PVUQb7KZRnd 1fPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725685720; x=1726290520; h=to:from:subject:mime-version:message-id:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=LHcvOjafmqzQD8jBi1RccAQdk8Mr4rwIBj8z7AkCRow=; b=rEyWv8uv8KPZSmas12lYcu/pZ0R+505i5bahiy7k/vww3Ov1G8NQoLf1StXqUdiIb7 yvh2VNIftzTgtaJK0j3m10wr/21qenZzOu/fidjk1jpwqyVHrVXjLpJuGOMXF55u6FVl GuKu6I+ZEA1udEGKoRfSY8M0JDIcG1rd173NmxxcJqZwYE6QcCkI8sRq2JfB16Twjzdg sQJvhetB4Cyk10Hy4oXcTSNQWbaAdRtVRlinZloBaR3LeOBQulmFyvEe23bu4A81OC3X 1xRxkLYC1jsfctuY7Jf0bbYyEPAbhvttQV0TYu1uW7GbhO5IwQPa+df+TxwL5mD79Acf ByVg== X-Forwarded-Encrypted: i=1; AJvYcCUl8G35WcNWxKPIrvAki5RNAin/YpURF5124vS3kxMmSiCO0LFidVk/2GyWYsQtYcUkzV70Mwv/eGe5tJqW+C2I@lists.infradead.org X-Gm-Message-State: AOJu0Yy/cW0spCYwbXxVf4F+5rnUyzP6s/CqcciHNxa3h0MKBioB+eER inW6AHrAXraGQ0M76ty39eqxYqgAiRXdZbsXqAdig1ubyUQcKkb4nRoV0O7h4EEXILqY3wHAejr QYW0ZLA== X-Google-Smtp-Source: AGHT+IEtgAgfvs12M62wi88Td4qZurVos4yaA4Bgge34jqEggk4Uvx3mHSsHiWJcAnGgvQwiFrblT6CG66LM X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:90e5:a813:c3d3:daed]) (user=irogers job=sendgmr) by 2002:a25:268d:0:b0:e11:ade7:ba56 with SMTP id 3f1490d57ef6-e1d34a38a43mr56558276.7.1725685720434; Fri, 06 Sep 2024 22:08:40 -0700 (PDT) Date: Fri, 6 Sep 2024 22:08:15 -0700 Message-Id: <20240907050830.6752-1-irogers@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog Subject: [PATCH v1 00/15] Tool and hwmon PMUs From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , John Garry , Will Deacon , James Clark , Mike Leach , Leo Yan , Ravi Bangoria , Weilin Wang , Jing Zhang , Xu Yang , Sandipan Das , Benjamin Gray , Athira Jajeev , Howard Chu , Dominique Martinet , Yang Jihong , Colin Ian King , Veronika Molnarova , "Dr. David Alan Gilbert" , Oliver Upton , Changbin Du , Ze Gao , Andi Kleen , " =?utf-8?q?Cl=C3=A9ment_Le_Goffic?= " , Sun Haiyong , Junhao He , Tiezhu Yang , Yicong Yang , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-arm-kernel@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240906_220842_534004_ACD8DAE2 X-CRM114-Status: GOOD ( 17.08 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Rather than have fake and tool PMUs being special flags in an evsel, create special PMUs. This allows, for example, duration_time to also be tool/duration_time/. Once adding events to the tools PMU is just adding to an array, add events for nearly all the expr literals like num_cpus_online. Rather than create custom logic for finding and describing the tool events use json and add a notion of common json for the tool events. Following the convention of the tool PMU, create a hwmon PMU that exposes hwmon data for reading. For example, the following shows reading the CPU temperature and 2 fan speeds alongside the uncore frequency: ``` $ perf stat -e temp_cpu,fan1,hwmon_thinkpad/fan2/,tool/num_cpus_online/ -M UNCORE_FREQ -I 1000 1.001153138 52.00 'C temp_cpu 1.001153138 2,588 rpm fan1 1.001153138 2,482 rpm hwmon_thinkpad/fan2/ 1.001153138 8 tool/num_cpus_online/ 1.001153138 1,077,101,397 UNC_CLOCK.SOCKET # 1.08 UNCORE_FREQ 1.001153138 1,012,773,595 duration_time ... ``` Additional data on the hwmon events is in perf list: ``` $ perf list ... hwmon: ... temp_core_0 OR temp2 [Temperature in unit coretemp named Core 0. crit=100'C,max=100'C crit_alarm=0'C. Unit: hwmon_coretemp] ... ``` Ian Rogers (15): perf list: Avoid potential out of bounds memory read perf pmus: Fake PMU clean up perf evsel: Add accessor for tool_event perf pmu: To info add event_type_desc perf pmu: Allow hardcoded terms to be applied to attributes perf parse-events: Expose/rename config_term_name perf tool_pmu: Factor tool events into their own PMU perf tool_pmu: Rename enum perf_tool_event to tool_pmu_event perf tool_pmu: Rename perf_tool_event__* to tool_pmu__* perf tool_pmu: Move expr literals to tool_pmu perf jevents: Add tool event json under a common architecture perf tool_pmu: Switch to standard pmu functions and json descriptions perf tests: Add tool PMU test perf hwmon_pmu: Add a tool PMU exposing events from hwmon in sysfs perf docs: Document tool and hwmon events tools/perf/Documentation/perf-list.txt | 15 + tools/perf/arch/arm64/util/pmu.c | 5 +- tools/perf/arch/x86/util/intel-pt.c | 3 +- tools/perf/arch/x86/util/tsc.c | 16 +- tools/perf/builtin-list.c | 15 +- tools/perf/builtin-stat.c | 7 +- .../pmu-events/arch/common/common/tool.json | 74 ++ tools/perf/pmu-events/empty-pmu-events.c | 208 +++-- tools/perf/pmu-events/jevents.py | 16 +- tools/perf/tests/Build | 1 + tools/perf/tests/builtin-test.c | 1 + tools/perf/tests/parse-events.c | 4 +- tools/perf/tests/pmu-events.c | 12 +- tools/perf/tests/pmu.c | 3 +- tools/perf/tests/tests.h | 1 + tools/perf/tests/tool_pmu.c | 111 +++ tools/perf/util/Build | 2 + tools/perf/util/evsel.c | 287 +----- tools/perf/util/evsel.h | 23 +- tools/perf/util/expr.c | 93 +- tools/perf/util/hwmon_pmu.c | 879 ++++++++++++++++++ tools/perf/util/hwmon_pmu.h | 30 + tools/perf/util/metricgroup.c | 45 +- tools/perf/util/parse-events.c | 92 +- tools/perf/util/parse-events.h | 13 +- tools/perf/util/parse-events.l | 11 - tools/perf/util/parse-events.y | 16 - tools/perf/util/pmu.c | 108 ++- tools/perf/util/pmu.h | 17 +- tools/perf/util/pmus.c | 25 +- tools/perf/util/pmus.h | 1 + tools/perf/util/print-events.c | 36 +- tools/perf/util/print-events.h | 1 - tools/perf/util/stat-display.c | 14 +- tools/perf/util/stat-shadow.c | 24 +- tools/perf/util/tool_pmu.c | 508 ++++++++++ tools/perf/util/tool_pmu.h | 56 ++ tools/perf/util/tsc.h | 2 +- 38 files changed, 2116 insertions(+), 659 deletions(-) create mode 100644 tools/perf/pmu-events/arch/common/common/tool.json create mode 100644 tools/perf/tests/tool_pmu.c create mode 100644 tools/perf/util/hwmon_pmu.c create mode 100644 tools/perf/util/hwmon_pmu.h create mode 100644 tools/perf/util/tool_pmu.c create mode 100644 tools/perf/util/tool_pmu.h