From nobody Tue Nov 26 15:18:26 2024 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0B62B2F36 for ; Thu, 17 Oct 2024 06:36:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729146967; cv=none; b=VmDZCbaCSAY6FiHQ5cD/PNLmIAWuRNo3CRhVsIx6+8B1pKNiIEIpOEXlqocsCWH+1RG9B6M1hRlE0nr9HxnIPj5Bghq9Tg4XLPGJOImadtksZqFmbmudBzlK8OfvHApcxOYNOuxmR4zEWpfyzZAYFVCRBfpf78PYEOGYncgSkho= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729146967; c=relaxed/simple; bh=UZxFlv7Wbh48yYOEZRihECZBjQeatmsIoMNyRLNwtEo=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=aQ0Hxyd0rMgJJxzQPni6a+UuXUjG/9v22/jrh1N8v82+mJ2GbPp5u+wEn/gwSm1quEqgDrnwJ8inkUD5iL0LPLzw5y4m6zuwEaqgMWf6ViI90pOLTFqspkUwk6nma0qN6WP3TmIX69FU8CUOB9RpkCnFrqtro7XsajYk5GeMYzQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=mYo/WKx7; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="mYo/WKx7" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6e390b164c7so11943117b3.1 for ; Wed, 16 Oct 2024 23:36:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729146965; x=1729751765; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=h7GW1eQklKySTp+dOjr8wiuaU6Yze5XmZBYV8OINt5I=; b=mYo/WKx7YXoOaAGIdhUnOVoof7ry09ptdcGGpUs0jYddQR4m2NxuYZvh4laVCcBAqd 49v+y5KjsZNT7HCnh5E5airaE0X0kFL7BM8SI2Vsg+oJRAky/JNOVOpuUeZYQyy894oo sWKl0A/lbWgji3WOZyo8cHr03vOe4IVU7+6dSFUz5KC2pJ+eUt7GTLKG3I0qoGsAT7cy sLc8UXzQbUs7In8utZbNf6XAKwoYLGtMJeSQaM8WUsdHvqJKRVl7ZaXwYKAuLHBeqjV/ 9goq2Y2vaVg7CclZlipI8jteob2hqXfWJ81pBBhB9n7rr+KU1FaXBEvQlsUNg3Gfj1PG dGDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729146965; x=1729751765; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=h7GW1eQklKySTp+dOjr8wiuaU6Yze5XmZBYV8OINt5I=; b=QYWT084MJRVKZSRpTOfoXdokhjAmV+s8DrQ8MY0ohw1oPP9q5KOTc22skoOw00Y0uP LPe1pKK+fxq1WJExwP49REsw9/gGmjDl9LH/vimV5h2SXaRA4r1i9dnDiDH/epWj7yW+ WsU1S42VWoSp2ogw/VA0TwLAxkT3AUHpjIZE2dQVTQNwpYJ1rp6qSMH+ZoEfTatvrkgc 6BajozGgFhuSaNczcXl6oKfF8mF9eH13PAfidL8n8gi4YNLHJq3RmEGZAV318JPpiT/n MlV97CAFJVfMFLS2EOL/wGiQEZjNFCCalrDBvcI0Zg9c8uMX3xE/um4zr97omi3bE+5E 48Xg== X-Forwarded-Encrypted: i=1; AJvYcCUPjpKlxKPVWjBLswVd+4boPhqBeFiHNFjUoS/92jR9CRCohEOLBno2rAhjj4a4zmz5vciCbQAW251FVDk=@vger.kernel.org X-Gm-Message-State: AOJu0Yx5fq7N1XNnqHXK31hLF4ufh+u3mHzDTQDF4mKU6OC/2ksrGU5Y HJjOR05hhUe+Ure0jBhhZIERndqzojpAee3ARcELQpPSs5ZWbvzGERXl5OYgX9TobozWKA7m04U RgmjR6Q== X-Google-Smtp-Source: AGHT+IEcdJa5UVv1eVKpTFGesNHv9d2XL0B7hT3B0R31fQH+7/ATODeYafpxjIDzuui8OctpbTv9II/gNUkx X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:98a5:142e:8c2e:e9e5]) (user=irogers job=sendgmr) by 2002:a05:690c:6504:b0:6db:b2ed:7625 with SMTP id 00721157ae682-6e3d3bdfc62mr1002657b3.0.1729146964829; Wed, 16 Oct 2024 23:36:04 -0700 (PDT) Date: Wed, 16 Oct 2024 23:35:51 -0700 In-Reply-To: <20241017063555.366065-1-irogers@google.com> Message-Id: <20241017063555.366065-2-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241017063555.366065-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.105.g07ac214952-goog Subject: [PATCH v5 1/5] tools api io: Ensure line_len_out is always initialized 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 , Ravi Bangoria , Weilin Wang , Yoshihiro Furudera , James Clark , Athira Jajeev , Howard Chu , Oliver Upton , Changbin Du , Ze Gao , Junhao He , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Ensure initialization to avoid compiler warnings about potential use of uninitialized variables. Signed-off-by: Ian Rogers --- tools/lib/api/io.h | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/lib/api/io.h b/tools/lib/api/io.h index d3eb04d1bc89..1731996b2c32 100644 --- a/tools/lib/api/io.h +++ b/tools/lib/api/io.h @@ -189,6 +189,7 @@ static inline ssize_t io__getdelim(struct io *io, char = **line_out, size_t *line_ err_out: free(line); *line_out =3D NULL; + *line_len_out =3D 0; return -ENOMEM; } =20 --=20 2.47.0.105.g07ac214952-goog From nobody Tue Nov 26 15:18:26 2024 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 31A82193400 for ; Thu, 17 Oct 2024 06:36:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729146971; cv=none; b=krrsECXTzZya26ovAlDGt8hV0CMs3ZqU+p+QOQduraVCe1zesFYKkXUBRHY2Zq55zaJv2xO8Fyb6dSPDkuxTKDxH1lQaIBhkf0/JrN75R/7pN+i1iMACUrlWcNEMmOdMBQHUtAJuitHyS26IESYNh/VAhrXUV+KJoQ97qKCAcew= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729146971; c=relaxed/simple; bh=t9sa9LQxPmh5kL1QdbtgFWmtTt658se79zHW2ccDEPw=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=DbYlWwQoU/pVURl3KjIYxhyDKPu82Ghsuq9+yoRHpMp2noZ/CierBZdXhe00NONOXPEgRdvx3co3szxpn3baBUXYgsSN5pHjdON62gq6w9MQvAKy99JboL6twnLsM85aYO4ajmj71oBmmWyJHG475726xH6SzJug2fFeVmc/6Ro= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=PBD7LaPs; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="PBD7LaPs" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e0b8fa94718so880544276.0 for ; Wed, 16 Oct 2024 23:36:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729146967; x=1729751767; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=yq5h4A0hQMoKQ94RpVZO1+aGwmqcwcBNihv9Pn7fn5M=; b=PBD7LaPsBJpVa4Ndse3AxsNy2837k9dm/F+eO05ZGB0bPDVC08m3jRjyrnLRyfZps5 YkYXo/zGvpPBMwS7wnzh2ofRTJrqYh/VQ0DmqUddyOVizqqBJ1D1wDy9U8UBkSuoSQtT XCErNYO2+oxAWMJtFlQuxyPkSfelveCUbYXP3ZqtoPpsRbIEdBu2EsaYEI7/O6gf3LzF 1//nj3nGSK5b6z6mM/9Y9f5/cet9CzZ6vKo+ppYCm1jKkkTurRlrKj77ZhVAG8UV0IjA EVx3oZ/G/nuI00bM9TtPlu+iXNUh0yJfLe98Uc99+9sIQmf6LsbqOTfnBc27c4w42fLH EgUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729146967; x=1729751767; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=yq5h4A0hQMoKQ94RpVZO1+aGwmqcwcBNihv9Pn7fn5M=; b=JnNIWfpDadGmXGEuHUJxnzxCsZgu+jwG9AM1ESr2wVp15b/lBrtHfWyxI/Ysw6HHXC JyM1zHsKgddQsL6V2hNfsElO1TcUdgHm0/B/vZkcpmhEyG5bK94eltzqzHSR4Wm8x/LR PJ8SdHUaJPQmOe+xvX167kR0x0L3uOUoCghyia8m7JcOfuAsVFCC0HnmfkHyyONY4tCT qsD9QyowKyGQTOVvjgv7BaBP7T5EXwIW4EApTyrovVDDItoa8UXhO4Upi9rFeAqIApzG NhKsI4hCyy9o010iNOyox+L70OiI5pwd9dKd1RrE4RielhdOnyRl6dCDdw410qB143sV RMrA== X-Forwarded-Encrypted: i=1; AJvYcCX+dNW27/uVH0Zrs2x9UEauFnO2UqClBoxlQOlvxncbmZL+P7dZfqzDWWy4ZE2UnpbR32Hj/87nqZl9I7c=@vger.kernel.org X-Gm-Message-State: AOJu0YwAFWHWwfSvIwuohcV6ewqHKiuzrL1gGdxn9XrZxcr5VXdutIsW gqClz0DD7rDWzhXREsEK2zCaWU7dfFbI5wVCDEBAEnAiJ742qHhe+BSJ/WezO1kQ28PnnO7AgJO /TPOy2w== X-Google-Smtp-Source: AGHT+IEmQMfYQR4qS0NY44UCMPFzryy86aUKBIW928fIrhz4sP1aD9HmV3s3wzfGmaC9yuH1pE15snvW9SI2 X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:98a5:142e:8c2e:e9e5]) (user=irogers job=sendgmr) by 2002:a25:9703:0:b0:e29:115d:5773 with SMTP id 3f1490d57ef6-e297856ac39mr5299276.9.1729146966871; Wed, 16 Oct 2024 23:36:06 -0700 (PDT) Date: Wed, 16 Oct 2024 23:35:52 -0700 In-Reply-To: <20241017063555.366065-1-irogers@google.com> Message-Id: <20241017063555.366065-3-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241017063555.366065-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.105.g07ac214952-goog Subject: [PATCH v5 2/5] perf hwmon_pmu: Add a tool PMU exposing events from hwmon in sysfs 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 , Ravi Bangoria , Weilin Wang , Yoshihiro Furudera , James Clark , Athira Jajeev , Howard Chu , Oliver Upton , Changbin Du , Ze Gao , Junhao He , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a tool PMU for hwmon events but don't enable. The hwmon sysfs ABI is defined in Documentation/hwmon/sysfs-interface.rst. Create a PMU that reads the hwmon input and can be used in `perf stat` and metrics much as an uncore PMU can. For example, when enabled by a later patch, 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 ... ``` The PMUs are named from /sys/class/hwmon/hwmon/name and have an alias of hwmon. Hwmon data is presented in multiple _ files. The is used to identify the event as is the followed by the contents of the _label file if it exists. The _input file gives the data read by perf. When enabled by a later patch, in `perf list` the other hwmon files are used to give a richer description, for example: ``` hwmon: temp1 [Temperature in unit acpitz named temp1. Unit: hwmon_acpitz] in0 [Voltage in unit bat0 named in0. Unit: hwmon_bat0] temp_core_0 OR temp2 [Temperature in unit coretemp named Core 0. crit=3D100'C,max=3D100'C= crit_alarm=3D0'C. Unit: hwmon_coretemp] temp_core_1 OR temp3 [Temperature in unit coretemp named Core 1. crit=3D100'C,max=3D100'C= crit_alarm=3D0'C. Unit: hwmon_coretemp] ... temp_package_id_0 OR temp1 [Temperature in unit coretemp named Package id 0. crit=3D100'C,max= =3D100'C crit_alarm=3D0'C. Unit: hwmon_coretemp] temp1 [Temperature in unit iwlwifi_1 named temp1. Unit: hwmon_iwlwifi_1] temp_composite OR temp1 [Temperature in unit nvme named Composite. alarm=3D0'C,crit=3D86.85'= C,max=3D75.85'C, min=3D-273.15'C. Unit: hwmon_nvme] temp_sensor_1 OR temp2 [Temperature in unit nvme named Sensor 1. max=3D65261.8'C,min=3D-273= .15'C. Unit: hwmon_nvme] temp_sensor_2 OR temp3 [Temperature in unit nvme named Sensor 2. max=3D65261.8'C,min=3D-273= .15'C. Unit: hwmon_nvme] fan1 [Fan in unit thinkpad named fan1. Unit: hwmon_thinkpad] fan2 [Fan in unit thinkpad named fan2. Unit: hwmon_thinkpad] ... temp_cpu OR temp1 [Temperature in unit thinkpad named CPU. Unit: hwmon_thinkpad] temp_gpu OR temp2 [Temperature in unit thinkpad named GPU. Unit: hwmon_thinkpad] curr1 [Current in unit ucsi_source_psy_usbc000_0 named curr1. max=3D1.5A. = Unit: hwmon_ucsi_source_psy_usbc000_0] in0 [Voltage in unit ucsi_source_psy_usbc000_0 named in0. max=3D5V,min= =3D5V. Unit: hwmon_ucsi_source_psy_usbc000_0] ``` As there may be multiple hwmon devices a range of PMU types are reserved for their use and to identify the PMU as belonging to the hwmon types. Signed-off-by: Ian Rogers --- tools/perf/util/Build | 1 + tools/perf/util/hwmon_pmu.c | 820 ++++++++++++++++++++++++++++++++++++ tools/perf/util/hwmon_pmu.h | 154 +++++++ tools/perf/util/pmu.h | 2 + 4 files changed, 977 insertions(+) create mode 100644 tools/perf/util/hwmon_pmu.c create mode 100644 tools/perf/util/hwmon_pmu.h diff --git a/tools/perf/util/Build b/tools/perf/util/Build index fa508e113dd0..9eb8b1c3df94 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build @@ -83,6 +83,7 @@ perf-util-y +=3D pmu.o perf-util-y +=3D pmus.o perf-util-y +=3D pmu-flex.o perf-util-y +=3D pmu-bison.o +perf-util-y +=3D hwmon_pmu.o perf-util-y +=3D tool_pmu.o perf-util-y +=3D svghelper.o perf-util-$(CONFIG_LIBTRACEEVENT) +=3D trace-event-info.o diff --git a/tools/perf/util/hwmon_pmu.c b/tools/perf/util/hwmon_pmu.c new file mode 100644 index 000000000000..2ef08940a12c --- /dev/null +++ b/tools/perf/util/hwmon_pmu.c @@ -0,0 +1,820 @@ +// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) +#include "counts.h" +#include "debug.h" +#include "evsel.h" +#include "hashmap.h" +#include "hwmon_pmu.h" +#include "pmu.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +const char * const hwmon_type_strs[HWMON_TYPE_MAX] =3D { + NULL, + "cpu", + "curr", + "energy", + "fan", + "humidity", + "in", + "intrusion", + "power", + "pwm", + "temp", +}; +#define LONGEST_HWMON_TYPE_STR "intrusion" + +static const char *const hwmon_units[HWMON_TYPE_MAX] =3D { + NULL, + "V", /* cpu */ + "A", /* curr */ + "J", /* energy */ + "rpm", /* fan */ + "%", /* humidity */ + "V", /* in */ + "", /* intrusion */ + "W", /* power */ + "Hz", /* pwm */ + "'C", /* temp */ +}; + +const char * const hwmon_item_strs[HWMON_ITEM__MAX] =3D { + NULL, + "accuracy", + "alarm", + "auto_channels_temp", + "average", + "average_highest", + "average_interval", + "average_interval_max", + "average_interval_min", + "average_lowest", + "average_max", + "average_min", + "beep", + "cap", + "cap_hyst", + "cap_max", + "cap_min", + "crit", + "crit_hyst", + "div", + "emergency", + "emergency_hist", + "enable", + "fault", + "freq", + "highest", + "input", + "label", + "lcrit", + "lcrit_hyst", + "lowest", + "max", + "max_hyst", + "min", + "min_hyst", + "mod", + "offset", + "pulses", + "rated_max", + "rated_min", + "reset_history", + "target", + "type", + "vid", +}; +#define LONGEST_HWMON_ITEM_STR "average_interval_max" + +struct hwmon_pmu { + struct perf_pmu pmu; + struct hashmap events; + int hwmon_dir_fd; +}; + +/** + * union hwmon_pmu_event_key: Key for hwmon_pmu->events as such each key + * represents an event. + * + * Related hwmon files start that this key represents. + */ +union hwmon_pmu_event_key { + long type_and_num; + struct { + int num :16; + enum hwmon_type type :8; + }; +}; + +/** + * struct hwmon_pmu_event_value: Value in hwmon_pmu->events. + * + * Hwmon files are of the form _ and may have a suffix + * _alarm. + */ +struct hwmon_pmu_event_value { + /** @items: which item files are present. */ + DECLARE_BITMAP(items, HWMON_ITEM__MAX); + /** @alarm_items: which item files are present. */ + DECLARE_BITMAP(alarm_items, HWMON_ITEM__MAX); + /** @label: contents of _label if present. */ + char *label; + /** @name: name computed from label of the form _