From nobody Sat Nov 23 23:09:10 2024 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.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 0D07D79CF for ; Sat, 9 Nov 2024 00:34:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731112446; cv=none; b=c7/EcfRP2QYEQnOSQZiAVUU24cH5dKRFwKbhLB4V+8JPGOW/DKA9K1lCqpfwz1UkXefWOrkk0JvU0kblrvHNHJYNJDhoDo6bXYyJeLTriHCDCNRl2okU99d0HZnuKqVWFr5p5GcvPUgM03RpuzfDwMZ/49Di1j5Duw6+OjRE+P0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731112446; c=relaxed/simple; bh=JR2W9BY58B7KI+DPucllOVM9yijzERRopT+DlqMeLCU=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=BxBKh8m6cg+3Nu2j3/d314jVTkTmrqMENpUwI7w6IjjX2GZrAqmPd4dUr2QTTH1Pwi5Cs96/6NciqMoXOSZz3JnB0u+sxgN+UWjmiU7NGbePitoV1qFvWybl0r+qo1TlQoim/zHe5QLQqTIPn2DpFLlgiQuyfgb9W4sU070kCEk= 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=NN9g01zn; arc=none smtp.client-ip=209.85.219.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="NN9g01zn" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e30df8dbfd4so5582052276.0 for ; Fri, 08 Nov 2024 16:34:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731112444; x=1731717244; 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=3SPWlc2lPTGFJEvFedKLB5LrjZb1UnFHbKvI0m+mSBo=; b=NN9g01znbIBzhADNo0L0gn6pbVE1FcOtPk+4Q3X5HAIYQq1JbvbR5nZaDUcUZ/syD9 inpm8niVFmsc4Pwh2+V0cfbPRmyN8St4Qc9TCV9Kbq/iYVRjs0Ngfq+jZr7mFRHryRCU nw8r2BCMh80Ym8F9VDq+5d1ULDOixihVBJDwVqmyLBzllYCRWjjHCNxO/gTfmSNb5Q3P AKW3ABAdrmRXMTIVKfqW8OchobM/KMahRXKOGMWparefnJmzilV1Dg8dtJq/DgosMjJQ A/KPDtVwgJHzfcGFd+pP0as8tkG62umZej2qKmc6sUxzF+TTFitrip6l2AWYMK1c5WGa yGrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731112444; x=1731717244; 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=3SPWlc2lPTGFJEvFedKLB5LrjZb1UnFHbKvI0m+mSBo=; b=atOTvY3rb/c2ERcid+ym1syrVu1M/+uQWCow3m/UHwXNQmQ+D77KM+NaxCG3mOVlfG mzT/Z1gSlFhyp0InDJ6JFH3AhvDOepPbX7x5GkYejSJMcHZ4UnvtE+aoudM1JTGTC/jv NpyAu6Aw0o/7cEHRZWHFq1aLUK9psgs69ulQ6koLdUGIEslgNisXd3DOeTpKEdp4SCUW 4+Y/kH9iNAfeiyqGgbTMciW+H4JCSHLeWcG/UmF4DRVwvB/wtiR7aJOSasyxaR/SwUzT 0PvLviuPf9OEpoFOimRz6NuEBQnzBnzojjxrxBTqQWfVJEiAErhsmwv9ZBhB+cGMxCHp 3a6A== X-Forwarded-Encrypted: i=1; AJvYcCVTkwW7AtknxSHPyh7/au1e1/WBZ6jFDUtiybTaHFPZ5O2uAzS8PtOaFf0TJJ2DMAlzGO6FC/CVEj7302Q=@vger.kernel.org X-Gm-Message-State: AOJu0YxFSVEc3EMkkmqoh5qizpGLOeTLiNKhsu+8whoIcPUOfHQG2a+m 0oSd87Ul2dx0nZ41yCN0iZhjAa0jy7eZYY7wFm0wdAJiEWGBdk/9pMzQ7Tc0euIvFkSaGXyfS4B quL0sKg== X-Google-Smtp-Source: AGHT+IFPezKGEklr++nG5H/4/AeOE+yWUxDwLwnQft/snPRaDbCVYhzMwgPF847otz3H/KeF3sq9zCTHNjhL X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:6fd2:1e36:6d8c:7c49]) (user=irogers job=sendgmr) by 2002:a25:264d:0:b0:e25:d46a:a6b6 with SMTP id 3f1490d57ef6-e337f8d405emr6111276.8.1731112444057; Fri, 08 Nov 2024 16:34:04 -0800 (PST) Date: Fri, 8 Nov 2024 16:33:52 -0800 In-Reply-To: <20241109003358.461437-1-irogers@google.com> Message-Id: <20241109003358.461437-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: <20241109003358.461437-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog Subject: [PATCH v8 1/7] 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.277.g8800431eea-goog From nobody Sat Nov 23 23:09:10 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 238A81BC20 for ; Sat, 9 Nov 2024 00:34:06 +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=1731112448; cv=none; b=buO3663UBS+LMfanezM8ISJQj8FA7EDxJUM53Zpp18SSQ9q/umF8b+XX5/q+IzWWdlCZzVo5fP0DmvMj17HlbQjjFAivm3PdTFeDofBwqqmScQstmyU037cub6D8eP1BNaSHPjwe9rvN9/+xAH+ykGKfU4MVNgVUsWdtNfxooD8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731112448; c=relaxed/simple; bh=EPHABW4Dal5OoWmB5VB9qYe0tkW5pDWGRMOxZWg45/8=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=WWYT7Dk0pE4z2oyWsIE2KBdg7AgkZBHj9+BpTAiwoT6SHzoYvBqYWRhnKUsSvk1itkHLtqjGbEhQrX8ajobraPzUXWx0SUGjwSQBN9CTC/8OEi5ZUQ4vQP8zIOgcomm8IUtSAs6aUpwr2ZttjKC5Z/ZsakZvP95Qkz5kohcy8Ew= 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=ihJgv2dH; 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="ihJgv2dH" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e297a366304so4416148276.2 for ; Fri, 08 Nov 2024 16:34:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731112446; x=1731717246; 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=HTiUHf6g81o8sTIu2Q+yefZ91ahAjUlTz9BdmD6fp2A=; b=ihJgv2dHFWaWTe7uU0Sr+lok+mH50iAii+NLUU6CX6vN61KEgvs4ihX0nujveC6dG3 8TV3Wzp8DuWXBQDmkexTweyKrXdN6IKqp7Un5W7d6VeUIvK4QkrwOidVYQ0O7cWF2EgR jK5W5uhM92Ya9aB4N+RaCHE6+QVcfonVc9fSPUn2qMyVY29r7WsXL+D6e0ilyUYSdDXG 8VC+fHKd60gnO9hHen0DFdhvVn3p0lX2D1PFuUFh/wNL3/DMY8OQkm8Ls/RxKolhPw3y ahHocBrWmoQuTa/FiWm0Y/I1+npJGM/uLqLNFvPZErgFYIb/eYkZcASey3f19B4/R+ff 1A1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731112446; x=1731717246; 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=HTiUHf6g81o8sTIu2Q+yefZ91ahAjUlTz9BdmD6fp2A=; b=BdYCm5WKd3YnWZaf2LifcMqjCrUvGdSu6fp6HfnfzGOqS98bh48lElEpuGtFNR1HMi xpN6sXzrrAyLzWXXbd2VR3Iy3N3w1vzjx3Mcl9371qO0wyw+HS5Lh3DEMEFf46gfrEdm IfF6YcupWUdC7UOiWzRqvguYdH1x2gBQjrTuiXs2gcwtQTO53nGXqDS9TINXOkF6KAMC ionAG/5DWL+8txAlNypRXmtDtEVSFxxcvswqQtRH2J79paFNxHUjG3rgoI7Ex+i5HqE/ DgepxuSPH0VlezeGL8ByxRocOqXRg9SmzCKe8lEcXSXmbyhigfs1OFHzeaZYO+GEbGWy f5RA== X-Forwarded-Encrypted: i=1; AJvYcCUXXREL/h6lmM8dnPJxxsHuNZsspvcxQhU3izH/BTzwJHG0+dTeiaSVbwQpZbWRkY7u8vK4bJb0K1EvpXM=@vger.kernel.org X-Gm-Message-State: AOJu0YxsquAnF7hDnqI5mEatoL4CExQG3m0mRv/hqwgXXhxafJ8Uh3sV h5dkM+itqtVT+wx5da35K4YXYmeyCwWiARH/4d1nKQd5+L22IngpwNsMrXTJBxomHogBLhyuIDg Qww0f+A== X-Google-Smtp-Source: AGHT+IE4cB8PT7bkoGH3JsC2DE9E89y2luWO0qOJLStXp9p+yJjl/IXAAdniSBn4c0JeURMQ0Jwu9Yuw4vd2 X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:6fd2:1e36:6d8c:7c49]) (user=irogers job=sendgmr) by 2002:a25:8241:0:b0:e0b:958a:3344 with SMTP id 3f1490d57ef6-e337f8f4b1amr8129276.10.1731112446202; Fri, 08 Nov 2024 16:34:06 -0800 (PST) Date: Fri, 8 Nov 2024 16:33:53 -0800 In-Reply-To: <20241109003358.461437-1-irogers@google.com> Message-Id: <20241109003358.461437-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: <20241109003358.461437-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog Subject: [PATCH v8 2/7] perf hwmon_pmu: Add hwmon filename parser 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" hwmon filenames have a specific encoding that will be used to give a config value. The encoding is described in: Documentation/hwmon/sysfs-interface.rst Add a function to parse the filename into consituent enums/ints that will then be amenable to config encoding. Note, things are done this way to allow mapping names to config and back without the use of hash/dynamic lookup tables. Signed-off-by: Ian Rogers --- tools/perf/util/Build | 1 + tools/perf/util/hwmon_pmu.c | 144 ++++++++++++++++++++++++++++++++++++ tools/perf/util/hwmon_pmu.h | 111 +++++++++++++++++++++++++++ 3 files changed, 256 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 1eedead5f2f2..78b990c04f71 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..8791e55097dc --- /dev/null +++ b/tools/perf/util/hwmon_pmu.c @@ -0,0 +1,144 @@ +// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) +#include "debug.h" +#include "hwmon_pmu.h" +#include +#include +#include +#include +#include + +/** Strings that correspond to enum hwmon_type. */ +static 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" + +/** Strings that correspond to enum hwmon_item. */ +static 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" + +static int hwmon_strcmp(const void *a, const void *b) +{ + const char *sa =3D a; + const char * const *sb =3D b; + + return strcmp(sa, *sb); +} + +bool parse_hwmon_filename(const char *filename, + enum hwmon_type *type, + int *number, + enum hwmon_item *item, + bool *alarm) +{ + char fn_type[24]; + const char **elem; + const char *fn_item =3D NULL; + size_t fn_item_len; + + assert(strlen(LONGEST_HWMON_TYPE_STR) < sizeof(fn_type)); + strlcpy(fn_type, filename, sizeof(fn_type)); + for (size_t i =3D 0; fn_type[i] !=3D '\0'; i++) { + if (fn_type[i] >=3D '0' && fn_type[i] <=3D '9') { + fn_type[i] =3D '\0'; + *number =3D strtoul(&filename[i], (char **)&fn_item, 10); + if (*fn_item =3D=3D '_') + fn_item++; + break; + } + if (fn_type[i] =3D=3D '_') { + fn_type[i] =3D '\0'; + *number =3D -1; + fn_item =3D &filename[i + 1]; + break; + } + } + if (fn_item =3D=3D NULL || fn_type[0] =3D=3D '\0' || (item !=3D NULL && f= n_item[0] =3D=3D '\0')) { + pr_debug("hwmon_pmu: not a hwmon file '%s'\n", filename); + return false; + } + elem =3D bsearch(&fn_type, hwmon_type_strs + 1, ARRAY_SIZE(hwmon_type_str= s) - 1, + sizeof(hwmon_type_strs[0]), hwmon_strcmp); + if (!elem) { + pr_debug("hwmon_pmu: not a hwmon type '%s' in file name '%s'\n", + fn_type, filename); + return false; + } + + *type =3D elem - &hwmon_type_strs[0]; + if (!item) + return true; + + *alarm =3D false; + fn_item_len =3D strlen(fn_item); + if (fn_item_len > 6 && !strcmp(&fn_item[fn_item_len - 6], "_alarm")) { + assert(strlen(LONGEST_HWMON_ITEM_STR) < sizeof(fn_type)); + strlcpy(fn_type, fn_item, fn_item_len - 5); + fn_item =3D fn_type; + *alarm =3D true; + } + elem =3D bsearch(fn_item, hwmon_item_strs + 1, ARRAY_SIZE(hwmon_item_strs= ) - 1, + sizeof(hwmon_item_strs[0]), hwmon_strcmp); + if (!elem) { + pr_debug("hwmon_pmu: not a hwmon item '%s' in file name '%s'\n", + fn_item, filename); + return false; + } + *item =3D elem - &hwmon_item_strs[0]; + return true; +} diff --git a/tools/perf/util/hwmon_pmu.h b/tools/perf/util/hwmon_pmu.h new file mode 100644 index 000000000000..df0ab5ff7534 --- /dev/null +++ b/tools/perf/util/hwmon_pmu.h @@ -0,0 +1,111 @@ +/* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */ +#ifndef __HWMON_PMU_H +#define __HWMON_PMU_H + +#include + +/** + * enum hwmon_type: + * + * As described in Documentation/hwmon/sysfs-interface.rst hwmon events are + * defined over multiple files of the form _. This enum + * captures potential values. + * + * This enum is exposed for testing. + */ +enum hwmon_type { + HWMON_TYPE_NONE, + + HWMON_TYPE_CPU, + HWMON_TYPE_CURR, + HWMON_TYPE_ENERGY, + HWMON_TYPE_FAN, + HWMON_TYPE_HUMIDITY, + HWMON_TYPE_IN, + HWMON_TYPE_INTRUSION, + HWMON_TYPE_POWER, + HWMON_TYPE_PWM, + HWMON_TYPE_TEMP, + + HWMON_TYPE_MAX +}; + +/** + * enum hwmon_item: + * + * Similar to enum hwmon_type but describes the item part of a a sysfs fil= ename. + * + * This enum is exposed for testing. + */ +enum hwmon_item { + HWMON_ITEM_NONE, + + HWMON_ITEM_ACCURACY, + HWMON_ITEM_ALARM, + HWMON_ITEM_AUTO_CHANNELS_TEMP, + HWMON_ITEM_AVERAGE, + HWMON_ITEM_AVERAGE_HIGHEST, + HWMON_ITEM_AVERAGE_INTERVAL, + HWMON_ITEM_AVERAGE_INTERVAL_MAX, + HWMON_ITEM_AVERAGE_INTERVAL_MIN, + HWMON_ITEM_AVERAGE_LOWEST, + HWMON_ITEM_AVERAGE_MAX, + HWMON_ITEM_AVERAGE_MIN, + HWMON_ITEM_BEEP, + HWMON_ITEM_CAP, + HWMON_ITEM_CAP_HYST, + HWMON_ITEM_CAP_MAX, + HWMON_ITEM_CAP_MIN, + HWMON_ITEM_CRIT, + HWMON_ITEM_CRIT_HYST, + HWMON_ITEM_DIV, + HWMON_ITEM_EMERGENCY, + HWMON_ITEM_EMERGENCY_HIST, + HWMON_ITEM_ENABLE, + HWMON_ITEM_FAULT, + HWMON_ITEM_FREQ, + HWMON_ITEM_HIGHEST, + HWMON_ITEM_INPUT, + HWMON_ITEM_LABEL, + HWMON_ITEM_LCRIT, + HWMON_ITEM_LCRIT_HYST, + HWMON_ITEM_LOWEST, + HWMON_ITEM_MAX, + HWMON_ITEM_MAX_HYST, + HWMON_ITEM_MIN, + HWMON_ITEM_MIN_HYST, + HWMON_ITEM_MOD, + HWMON_ITEM_OFFSET, + HWMON_ITEM_PULSES, + HWMON_ITEM_RATED_MAX, + HWMON_ITEM_RATED_MIN, + HWMON_ITEM_RESET_HISTORY, + HWMON_ITEM_TARGET, + HWMON_ITEM_TYPE, + HWMON_ITEM_VID, + + HWMON_ITEM__MAX, +}; + +/** + * parse_hwmon_filename() - Parse filename into constituent parts. + * + * @filename: To be parsed, of the form _. + * @type: The type defined from the parsed file name. + * @number: The number of the type, for example there may be more than 1 f= an. + * @item: A hwmon may have multiple associated items. + * @alarm: Is the filename for an alarm value? + * + * An example of a hwmon filename is "temp1_input". The type is temp for a + * temperature value. The number is 1. The item within the file is an input + * value - the temperature itself. This file doesn't contain an alarm valu= e. + * + * Exposed for testing. + */ +bool parse_hwmon_filename(const char *filename, + enum hwmon_type *type, + int *number, + enum hwmon_item *item, + bool *alarm); + +#endif /* __HWMON_PMU_H */ --=20 2.47.0.277.g8800431eea-goog From nobody Sat Nov 23 23:09:10 2024 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 5B54C364A9 for ; Sat, 9 Nov 2024 00:34:09 +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=1731112450; cv=none; b=lbsc6rwH015cgnnj5El65VlWTCfgu3+4IihsgqNU61RdfvRBiFv67nFWw6NSb7EVgbAyva3hwNON4/oa49XHcsivtF3nHHdn6HaC6ZWToEGGeEDGhSajKefSK5h7o12uK0QsXAE2zTyzV6MWxE5g4BEl2uKhVnwZmTTy561eoRc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731112450; c=relaxed/simple; bh=cJXlLHhPm/MxqQ001SlGf6LhXjO0VbFH7y7+7Dv6k6s=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=PlQgIu8vWljsHFJeyr9EL+L4/leIUY1lCizFS6yATQZGezZMTTlD2ORVaBUeJr8rCGQRsFZSG45NH489RyvYfIE1xryJL5AtYRGPeStznNZZDq6gU9MW1u22Bd9eIeBI/7MRhbBwdrGElUHf0hNzv1l91lq3KzEyef8draSx5eA= 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=e35YxJu/; 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="e35YxJu/" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6ea8a5e862eso34006367b3.0 for ; Fri, 08 Nov 2024 16:34:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731112448; x=1731717248; 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=sMRp4SArakG3qttQ7Acj4+yjGFvVzfYJdi2BB3ubp6I=; b=e35YxJu/8ONoiAqd8b44cdEqmB75Cs1vGTbpwxzw6c/JRXGPx2XHbeJw4bXGciOGRi mgyETlFn1H+k5QsKanOeMDalkZOdLLQPnJcAgtw1deugISf0SF1aUqUiOJ6SX+TRpHc8 P+RKpyOi54Jcx/dvt0vDXA8w9QYaFIzq/XamiCEDVF+kgUSYEcQtf+KXb8dpbsiajAYl XEFb0ygsYEibLk1UJn/vRJmYk8A/+J3jlurKNajHbhS7z/BjEU0F1ABa9pmvd+CyD3EJ eQ+udEunsQWXJGq4zoRAI8sY8to5CGc5GvnNw/YXMwDeBRIsExCNC2neU/KpH3usYpza hggg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731112448; x=1731717248; 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=sMRp4SArakG3qttQ7Acj4+yjGFvVzfYJdi2BB3ubp6I=; b=mRz1I/rONtSe5AQe1d18OjdsJ6z/3IIMgJYZgaFmjZMo8rEgc2sSh8vjzptvWZS3eY 8bhCkzDV6ZG+IrUc7pymkavMxZSPsznnb5zAwyHGORkI4dmbSgSskqc4JTMMkHu8xl91 1FhDjedRLRxkQCmIxIPBEbHDeNV1EfkSRwqRJJlJe5HgY8cffLZdi1xNZhqqd2VhN7Io 2pkwT6BWRXX7Ei9CeztilxO4fWxlMEUxY3XzRPn4+pk9DOA18eSZ7mdiUZyrmGse4bkI gj5pUeAbIln7XbgZdS9ENQhlJbyd8IIVYjmAPNztUYeW16VsA6qf13vWz+BheDOJI63R EWxg== X-Forwarded-Encrypted: i=1; AJvYcCVzsPW5m6nr/5Ux1zrzTYXwDDDiY+LixFR3c23BHDPrIl0mISffNt02c69Z66q7r+N+FHjmEyFXfTU5Gy4=@vger.kernel.org X-Gm-Message-State: AOJu0Yyue/B89an1mRDRGGClelw5F41SclzDoeH4MPr+CMiJEkdDZ6z9 H6M0H4m6p1UrBcxYwsaYJ3TRJ6UOEpJ8dZnGrnlDHCewwH9nZtL4XqervHG9RTsuCoN4TtJ4aRb +1uCmAg== X-Google-Smtp-Source: AGHT+IHWSPxvpPMbsE3XQO9hnnV7WweWqhHir2An9HkzqLRz4gVpezpyygCtEd3uv2Ei/uFmPRlSzP2EJLjO X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:6fd2:1e36:6d8c:7c49]) (user=irogers job=sendgmr) by 2002:a81:c844:0:b0:6e2:c1c7:ec27 with SMTP id 00721157ae682-6eadc006feemr465077b3.1.1731112448330; Fri, 08 Nov 2024 16:34:08 -0800 (PST) Date: Fri, 8 Nov 2024 16:33:54 -0800 In-Reply-To: <20241109003358.461437-1-irogers@google.com> Message-Id: <20241109003358.461437-4-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241109003358.461437-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog Subject: [PATCH v8 3/7] perf test: Add hwmon filename parser test 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" Filename parsing maps a hwmon filename to constituent parts enum/int parts for the hwmon config value. Add a test case for the parsing. Signed-off-by: Ian Rogers --- tools/perf/tests/Build | 1 + tools/perf/tests/builtin-test.c | 1 + tools/perf/tests/hwmon_pmu.c | 110 ++++++++++++++++++++++++++++++++ tools/perf/tests/tests.h | 1 + 4 files changed, 113 insertions(+) create mode 100644 tools/perf/tests/hwmon_pmu.c diff --git a/tools/perf/tests/Build b/tools/perf/tests/Build index 01ed9335db4d..ec4e1f034742 100644 --- a/tools/perf/tests/Build +++ b/tools/perf/tests/Build @@ -66,6 +66,7 @@ perf-test-y +=3D sigtrap.o perf-test-y +=3D event_groups.o perf-test-y +=3D symbols.o perf-test-y +=3D util.o +perf-test-y +=3D hwmon_pmu.o perf-test-y +=3D tool_pmu.o =20 ifeq ($(SRCARCH),$(filter $(SRCARCH),x86 arm arm64 powerpc)) diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-tes= t.c index d2cabaa8ad92..8dcf74d3c0a3 100644 --- a/tools/perf/tests/builtin-test.c +++ b/tools/perf/tests/builtin-test.c @@ -71,6 +71,7 @@ static struct test_suite *generic_tests[] =3D { &suite__PERF_RECORD, &suite__pmu, &suite__pmu_events, + &suite__hwmon_pmu, &suite__tool_pmu, &suite__dso_data, &suite__perf_evsel__roundtrip_name_test, diff --git a/tools/perf/tests/hwmon_pmu.c b/tools/perf/tests/hwmon_pmu.c new file mode 100644 index 000000000000..f5b58486d8d3 --- /dev/null +++ b/tools/perf/tests/hwmon_pmu.c @@ -0,0 +1,110 @@ +// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) +#include "debug.h" +#include "hwmon_pmu.h" +#include "tests.h" +#include +#include + +static int test__parse_hwmon_filename(struct test_suite *test __maybe_unus= ed, + int subtest __maybe_unused) +{ + const struct hwmon_parse_test { + const char *filename; + enum hwmon_type type; + int number; + enum hwmon_item item; + bool alarm; + bool parse_ok; + } tests[] =3D { + { + .filename =3D "cpu0_accuracy", + .type =3D HWMON_TYPE_CPU, + .number =3D 0, + .item =3D HWMON_ITEM_ACCURACY, + .alarm =3D false, + .parse_ok =3D true, + }, + { + .filename =3D "temp1_input", + .type =3D HWMON_TYPE_TEMP, + .number =3D 1, + .item =3D HWMON_ITEM_INPUT, + .alarm =3D false, + .parse_ok =3D true, + }, + { + .filename =3D "fan2_vid", + .type =3D HWMON_TYPE_FAN, + .number =3D 2, + .item =3D HWMON_ITEM_VID, + .alarm =3D false, + .parse_ok =3D true, + }, + { + .filename =3D "power3_crit_alarm", + .type =3D HWMON_TYPE_POWER, + .number =3D 3, + .item =3D HWMON_ITEM_CRIT, + .alarm =3D true, + .parse_ok =3D true, + }, + { + .filename =3D "intrusion4_average_interval_min_alarm", + .type =3D HWMON_TYPE_INTRUSION, + .number =3D 4, + .item =3D HWMON_ITEM_AVERAGE_INTERVAL_MIN, + .alarm =3D true, + .parse_ok =3D true, + }, + { + .filename =3D "badtype5_baditem", + .type =3D HWMON_TYPE_NONE, + .number =3D 5, + .item =3D HWMON_ITEM_NONE, + .alarm =3D false, + .parse_ok =3D false, + }, + { + .filename =3D "humidity6_baditem", + .type =3D HWMON_TYPE_NONE, + .number =3D 6, + .item =3D HWMON_ITEM_NONE, + .alarm =3D false, + .parse_ok =3D false, + }, + }; + + for (size_t i =3D 0; i < ARRAY_SIZE(tests); i++) { + enum hwmon_type type; + int number; + enum hwmon_item item; + bool alarm; + + TEST_ASSERT_EQUAL("parse_hwmon_filename", + parse_hwmon_filename( + tests[i].filename, + &type, + &number, + &item, + &alarm), + tests[i].parse_ok + ); + if (tests[i].parse_ok) { + TEST_ASSERT_EQUAL("parse_hwmon_filename type", type, tests[i].type); + TEST_ASSERT_EQUAL("parse_hwmon_filename number", number, tests[i].numbe= r); + TEST_ASSERT_EQUAL("parse_hwmon_filename item", item, tests[i].item); + TEST_ASSERT_EQUAL("parse_hwmon_filename alarm", alarm, tests[i].alarm); + } + } + return TEST_OK; +} + +static struct test_case tests__hwmon_pmu[] =3D { + TEST_CASE("Basic parsing test", parse_hwmon_filename), + { .name =3D NULL, } +}; + +struct test_suite suite__hwmon_pmu =3D { + .desc =3D "Hwmon PMU", + .test_cases =3D tests__hwmon_pmu, +}; diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h index af284dd47e5c..cb58b43aa063 100644 --- a/tools/perf/tests/tests.h +++ b/tools/perf/tests/tests.h @@ -92,6 +92,7 @@ DECLARE_SUITE(perf_evsel__tp_sched_test); DECLARE_SUITE(syscall_openat_tp_fields); DECLARE_SUITE(pmu); DECLARE_SUITE(pmu_events); +DECLARE_SUITE(hwmon_pmu); DECLARE_SUITE(tool_pmu); DECLARE_SUITE(attr); DECLARE_SUITE(dso_data); --=20 2.47.0.277.g8800431eea-goog From nobody Sat Nov 23 23:09:10 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 90E1842A99 for ; Sat, 9 Nov 2024 00:34:11 +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=1731112454; cv=none; b=a/sMV5CustEaar+H2cv3+PjqqdWh+BdAVPHnI6nWWZEmBk0mFaH9eMjO4uGxipguWB0jwHIMf8tyjBySloWndPhkxkBiZVQq6kQsRn2LltzWH3bot/4/4vAshXiAH/SAxw4TD9N01IGsW+szJ/1NZCp+c6YhWX16YH0v2BLngno= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731112454; c=relaxed/simple; bh=F49j8iPVS4mZoFjCeNmstYjRig50K2qsMwH5MLT4vqY=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=fcW+AwaACl0UfpIkdzqRdH2hVmsaO6ROAjIYIIDLxer+jw5/fZgfp90bDPBUTTowEDArwzQHqv1EelReJiz+vuO+sy+XSx69QSTqz6eVNTQUlUWDWBX6PA6mJlPt0xzqNuEi5+9qoOYE+Zs6sQkktKy/q5t3bHWPdMUsj9hpv8s= 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=nrzW3VhN; 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="nrzW3VhN" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6e35199eb2bso54476137b3.3 for ; Fri, 08 Nov 2024 16:34:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731112450; x=1731717250; 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=AXDQVRXXi7GhtlogEkOsn5+xFkonI/XEJS+nPwR0BE0=; b=nrzW3VhNuuAThR0uThFFW2+Bp4FPJA5wb54hn2VYDB/rftW6gpNmBgENz6L5UMfOcY gVEp7L9yfQTpAqqDpmFm/ZA+SLMHQyMVa5cGpuEfjhsOyvt3skklxm0A1BYBoMp1b7vd cMP86PiGnsfCrtptnxdFFK4aynAGLWAokTl42Fx3gHVcEImccT0YdqzbFA22bHvlvnYb fIbuXs46GxifMFi4jy3vcEyqIuZf6NLJzpvKIwlZXwAbq91VcPO+GBqY9/zAB+qmsvXq lNsjBzri7xwcXakJisPxeU4/HcJy5InSspX5enezVCIrVr36XCJ5WNKlrNBA0nSA9En7 Zj4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731112450; x=1731717250; 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=AXDQVRXXi7GhtlogEkOsn5+xFkonI/XEJS+nPwR0BE0=; b=bg5HpCD4vGKlYTELqzYMonDUVtv9FJ5Dl2HrSal5bGOWeBdcKSao3pmWyKahJcO7LC gN2bWpHfF8CZGM4XJbRQO+O23tsqCM9P3m0eJVuZ2lYE49zykdW2Ys19zqIRpMM5L/vn Mk3S4QFeEJ7SwPNd2iS45MDnuXe0ypzT5DJNnDhVfDO94F2UaalRb055jiP7Cl10CRJT SIp5/P313APWUD5Pkl9lZF5V3EOcoKjML00707oRrVMUg91Xr53Ycn+BOK8zCI0MzBxs Cek32aHeK+cYNQaElImtaDgoHqW85LM6QBVMYALaEp5jGQe73K3bxBOXapUIiun1tv1g W9Qg== X-Forwarded-Encrypted: i=1; AJvYcCUWw6zqM7xpov04nqaBMmDzcbsyGa+wz0wzou1lvN/8ZtMW1hZXBo+nmZO8fNQZKsX0Gxcqigt4fQQq70I=@vger.kernel.org X-Gm-Message-State: AOJu0YwnUfUHQJQY6qLLIXnYHlkSK0/ncQ7WH7EML5qVI39G8KG9b7o9 c2sfrVxdstFLwxysdQdk6U2EOMFX1hrtrcdoQnNOLitnxxugKTWuFgOIZk6PrZS+0UA5gACruJ9 FYTzUvA== X-Google-Smtp-Source: AGHT+IGx72gPBQu7YGyXhqbaXD0iAzuq8187mORAdS8bRXDogiQk4QKZOY2xThc8f7Nl1KQckyluIj8xF9oZ X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:6fd2:1e36:6d8c:7c49]) (user=irogers job=sendgmr) by 2002:a05:690c:c08:b0:6c1:298e:5a7 with SMTP id 00721157ae682-6eaddfb88bcmr855757b3.5.1731112450689; Fri, 08 Nov 2024 16:34:10 -0800 (PST) Date: Fri, 8 Nov 2024 16:33:55 -0800 In-Reply-To: <20241109003358.461437-1-irogers@google.com> Message-Id: <20241109003358.461437-5-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241109003358.461437-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog Subject: [PATCH v8 4/7] 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/hwmon_pmu.c | 682 ++++++++++++++++++++++++++++++++++++ tools/perf/util/hwmon_pmu.h | 45 +++ tools/perf/util/pmu.h | 2 + 3 files changed, 729 insertions(+) diff --git a/tools/perf/util/hwmon_pmu.c b/tools/perf/util/hwmon_pmu.c index 8791e55097dc..89acc19347c8 100644 --- a/tools/perf/util/hwmon_pmu.c +++ b/tools/perf/util/hwmon_pmu.c @@ -1,11 +1,25 @@ // 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 #include +#include +#include #include +#include =20 /** Strings that correspond to enum hwmon_type. */ static const char * const hwmon_type_strs[HWMON_TYPE_MAX] =3D { @@ -72,6 +86,79 @@ static const char * const hwmon_item_strs[HWMON_ITEM__MA= X] =3D { }; #define LONGEST_HWMON_ITEM_STR "average_interval_max" =20 +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 */ +}; + +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 _