From nobody Tue Mar 11 19:42:45 2025 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (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 312C41FBF64 for ; Tue, 15 Oct 2024 21:06:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729026396; cv=none; b=sw6xjdljiwZ+p/JcfHs7MB83Yik+brAi6AOA+fCWwZ6lp4j6aNyr5n/bOpi9Ie9SUgw+UtaJ95E3v0xIV/f0WqTRT64V5Pvx5Ph4sR41HzbMLVJhhfYMr3whOHo4IDNcfjIRhHWNozdNwGx9v/+M3DZNcrHXd9W7VPtCgjqnRRM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729026396; c=relaxed/simple; bh=nL+nx8eM+rqkUV8ew1DRUX2aLO3Wr1hJhbV2g6JzRys=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=RV9BF8fc4RVqog8DvIsApFU/YioBT1H4kl2/gT8RXRO0UcQ1NXqAYyXxsmVm1UNc3BtpG4Gj4Jt6DXQ1DlrsjNcIln8/5YUiGS+WrhhEB5o6ZLDoc4JcefejmcVICFF8OJm8NKsGfJgr/f5XTuSCw7NLWYDDZexJndlKLKGiptQ= 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=ZUlhLEkv; arc=none smtp.client-ip=209.85.128.202 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="ZUlhLEkv" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6e32e8436adso72878457b3.0 for ; Tue, 15 Oct 2024 14:06:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729026394; x=1729631194; 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=3kpHcRKhB/eDsIrUXvJFBqC7jgWe4ELBkz9BuIOGSn0=; b=ZUlhLEkvPoKBXjITJWmYAFrRrYOgmCb0K6vxR6KMb0gvEGddhyD6+/T42/kYekO163 DOornIrfv2gCwIiyVXMTBFsweM4wC3CxhIzIFhhL66WL7Qd1Y30sx9lARn/hsrEw+FZm nU45greFwjimdYSx216Q7pR3e77Q3Jepa5FVA+ggkzAxYW1654ugjYU2s5XJTog+qAd/ QVjA54RNyQJiDJxkluT/mBP5CvorYiydjvaRBubP+gF3l1c14Cj1RmYRCv9jukFbNngQ rR1KZcrZbYCaMVoa6xKBKSL9iaHJUINjaI3E4l2LruVKzupiceJuqVxyoNGo2XKIAqCO UriQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729026394; x=1729631194; 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=3kpHcRKhB/eDsIrUXvJFBqC7jgWe4ELBkz9BuIOGSn0=; b=ZTkiBI3kBizUGeykRSMKAjnoieOKaQM5LlwvwwWDgahcxMq8p10ngEfafihzaZIH3C K0qqZqT6ZvdeXyCyorFIQxLMpXIovaquuBSMyyR1CKPU9HZfiu5ePqCXDvzpmWgV08no ZtnC6sAmscL9vu+uuBVwvpLi+fQS8D5IpX6O/SfcY1ozbhI6vaySbaMj+PvPcsIPdVye hXE5q4SfNs4snX30W/f8s+uMZzr/YYdWJeFf0ELo1PXiKoQWgoa7f2A038NtstLNHT71 BSTavaZ/GVTK9MhbFMLavMt5rhuI73IqWiXeeibBPwehIQVxUVDWNOJ07PCrlopSoDxf ZxZg== X-Forwarded-Encrypted: i=1; AJvYcCVpHuJSz1TGiCrZUqayzPJVeRN8OhQ7cEJ5o4mvIuJloPMUEkGwAeEgnm7ovEIhfuecHxSi+nFYunTVcbA=@vger.kernel.org X-Gm-Message-State: AOJu0YwC63S2N09vCRbNqxcvgYhkoXf+/s3EdVEH06RkuNQcQZAbIDZL Pipsk5qyzbHB89aFuI9KPmRiKaPByJw5rBDNeZyZ9o29FL8lDpuNmzLR7uTga3Rh4IdO7/unV4V YO5mNQw== X-Google-Smtp-Source: AGHT+IFJmgM3oL2Y1D8peANHPNTTxEWz1kxzSiZ0kcULhqmZppAMW6tFZZeMMS1KVAg5svVLJkuReCmayMp5 X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:61a1:4d9d:aca1:ada]) (user=irogers job=sendgmr) by 2002:a05:690c:6e0a:b0:6e3:14c3:379a with SMTP id 00721157ae682-6e3d3bdb366mr261977b3.0.1729026394060; Tue, 15 Oct 2024 14:06:34 -0700 (PDT) Date: Tue, 15 Oct 2024 14:06:24 -0700 In-Reply-To: <20241015210629.1150428-1-irogers@google.com> Message-Id: <20241015210629.1150428-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: <20241015210629.1150428-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Subject: [PATCH v4 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 , Yang Jihong , 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.rc1.288.g06298d1525-goog From nobody Tue Mar 11 19:42:45 2025 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 6BFBE1FE0E1 for ; Tue, 15 Oct 2024 21:06:37 +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=1729026399; cv=none; b=uINiGav3bg4Ens4wjJDIMqwrHRYmFroO6XpG/vH1iIz6a7WWDsKOqNKQMvtsSnyGM4ivbnM5v3PryyGnfhfwrPZY5esktCFk6nAKJVF2kcUAcxJ6lQgHSRN1gPgsbNLthLJsZtT+9qb6BGrkNj7baQjyPNVhybmrcsPcDelWxMc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729026399; c=relaxed/simple; bh=ebE3rElU8qnWqj9yug95dOoylZH4RT6sQlV6UkgfR0o=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=BkzQACvwN9xW/Ed4QpRihwzsmAvJnkrgBIp0DiO1+mC6UjHJHyAx0sly8xJmvvLa18OsTxbpz/9gvh9vSi31vd7Re9jgWNI/w46lCSY27+yTeoczPBHcDjrzOVJb6jGPIyjVNzfX0mRLHHl0J1wLzRTWVgkH+U1M52Yyy8BUQeQ= 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=JTEB286o; 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="JTEB286o" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6e3d6713619so7193517b3.2 for ; Tue, 15 Oct 2024 14:06:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729026396; x=1729631196; 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=FpNEFP1bOsQQDYJ3YsdKfoWX263ozEvdPgx8rw5Iv2s=; b=JTEB286oyjPIzQf+69MiUvEtTYdfrf+xG7w4GzdxPfDGeZUZn8QoDXYBa6HRdABsGM mDJ2Hckr3VGk7pJsa/qqa+1fUkakINAdTBjI7ThZlV4qULuGRYjuPYnwTCGwcrHJCbW0 ukPbYZGiCNZBJ/PMIS8Ggvv0SvcNsK3DqFzbQOgILrPdjwSggSJm0eNuyLhLArnl1cTM ui0CotYLSrjIOX6MeCjL3j7JCBbRD/Kbvx1kmDHv5cPbYzLKg0cXTJUh5gMSyRCBg3xR 6so0y/3kCKjND0xl8d6JLpnq/prreDY64ueIPfH0UBdEYUxvPXJIVn5n2kS8r90kc9sf 0V3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729026396; x=1729631196; 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=FpNEFP1bOsQQDYJ3YsdKfoWX263ozEvdPgx8rw5Iv2s=; b=e1Vq5ybdthFrgy5x8aS8bej+k8pO8nbljqPwZXYXz7UhDo6PGA7G51+BcltpodDRjC /b6pIa+PNLbPnvx184h+GIkQcgMNUdfZfIXt+hIcNwIy9P4PX3fUTwW98QuRT4g0iqli o9ZZaJgpCUWgArL9PS1YmRTzvTwcJfvS6i8iGkTEv0XbVTW/3dqx31SHUomsS2W/iwzP SYldAcyPd5zSK3phPLwle0Okh8vaK1xuBg+may9XoZMQyiIvXrjbba6exgtw4T/VmXCf i27J/hknzs//z1wCwi5H2OZo6vRenDEQ7v+kAx6lQYYJxdxNzSXDBnwBOsoHd+RM4vSd DYtw== X-Forwarded-Encrypted: i=1; AJvYcCWJXvd/SKK11vs4wXqhbqN+C5tzErPrZOr8DB8//yLgKpKxrHGYjyI+Qr6aM+YYfDEAdWHGgV40bDMk7iQ=@vger.kernel.org X-Gm-Message-State: AOJu0YxYe/b4z2qobDXVQJTK6ljTX6ZpUIFOCnXYDzWwuH5A7YavjzgR Svr4DS2v/bqJJrf5OHKCmTuPQ/aYUU6WBpvhH+ji8mzAY96ikId/vlZsN8cdds1qIQFDIGU5i6R 75+wUWQ== X-Google-Smtp-Source: AGHT+IGTS2e62bom4xk3I/LMdMoiZH1GODgb+AsOGdjQFQGr4M1Onm48wLFSXIL9xOxBaZGoWCsV4gzSCk1r X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:61a1:4d9d:aca1:ada]) (user=irogers job=sendgmr) by 2002:a05:690c:4b05:b0:648:fc8a:cd23 with SMTP id 00721157ae682-6e3d407c2a5mr312137b3.2.1729026396505; Tue, 15 Oct 2024 14:06:36 -0700 (PDT) Date: Tue, 15 Oct 2024 14:06:25 -0700 In-Reply-To: <20241015210629.1150428-1-irogers@google.com> Message-Id: <20241015210629.1150428-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: <20241015210629.1150428-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Subject: [PATCH v4 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 , Yang Jihong , 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..a8bc76721328 --- /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 _