From nobody Sat Nov 23 23:59:15 2024 Received: from mail-ot1-f74.google.com (mail-ot1-f74.google.com [209.85.210.74]) (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 EC9CE1C1F09 for ; Fri, 8 Nov 2024 17:55:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731088554; cv=none; b=K3Ls6xkKM1HTMe6z7oRAqWKK+iDgigZHl5I6yGoGQluT0uLyPtY4uGxIuP6whI3hBMO0aO768sFEN7c6RylYN8oqQbpZ0jCHp/CdsjHPcwWgjnzdJP0Qs3lpq78tJSkVT43obPbs3IAS9yRz+uu6Cjsh67YeRqk7hFcMfAoq+n8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731088554; c=relaxed/simple; bh=JR2W9BY58B7KI+DPucllOVM9yijzERRopT+DlqMeLCU=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=BYj4qd8y0yH0Sd6NnufA6vZFJBm8Sdt/ONvkF+pEZR5jMk+hiUzTMJiJaaEiuEju7+Pjsto8zjLPFTLNytcCfmdb4dUJI839qHAfxXncrekPuibbGofwczeRCCyL82KBZXeRVOBbLnFi5tNfVtDif+orqchCiuLmOoib1mOVVP8= 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=fT1cD7jw; arc=none smtp.client-ip=209.85.210.74 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="fT1cD7jw" Received: by mail-ot1-f74.google.com with SMTP id 46e09a7af769-71817b35f3fso2126479a34.2 for ; Fri, 08 Nov 2024 09:55:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731088552; x=1731693352; 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=fT1cD7jwLWA7tYaJn8v1+GiQJ/iVEhBlcMx+erME+SKldW2QJJTsq4WqyALiESauTE uyiAntZHgnK6qAbqagZ5LuhXluMfdF4vBix0I5y2cKm5SchLqAgf5x1QzI1jmN6Gcv5/ Dx7tGVp4LaG/qf5AAw9bQ0MY+6hla2xPwQJU2gmsAS32jyZiBi/AjTSLdxynXqZ0cR/K EAfVmxD73PUfV8CGTTAtOtK3JyUA7FYg6bc1EEbgqjC6fcgJ199z/a038uT/gml26bHe xEgo41w38RdhW/Kw6ldxdjWBd+1o54o0Axov6tBCth4Xw9T5Hf5ynJdXWyB/7JxHd6pH 9cMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731088552; x=1731693352; 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=kzgTJ/oo9H4WhXZfkbms6QY9Vep38Q2ytLkDljD42b4/XvAMh85ckVVBq+5BOD1s2z 5o7uOioVNlPRM4j6C8PN4c9Tyc6W2lPPfMM+x/e8rrDOLcT2xsatzKLDw5kSPPAUOxeN fhfZFWmZKOHx0CMd6xtFK2IrLarqXhW6MekV12vUbncRC9giSgAIcxBRU/B41qpGVP38 hY+72SXPWVWkUFkQZF89x5YOvnu0fZ8bF/x0OD9mEbukubR8gScopHjGf4zzqlVHNdNR 7Jaupke0bMJBg1LTrcWi1wtiq9bBJfiYCroVY9PRbZAqalt5ytdcm59gMT0Vbh3SBUaR vrCA== X-Forwarded-Encrypted: i=1; AJvYcCW0th5y81UOUlkWHAAhU4dcv7Ovtzgtli/5AsuyxaOjaf1YAMgArHSzvVPPiipL7dexWEU3te9VLx4NWdk=@vger.kernel.org X-Gm-Message-State: AOJu0Yyh7U8LymwLSiMy2Oa5+P7HCwB8LFwYrTxBK01VQb/aRqrID8lM n5i+H2fwEnECtGgvx6LkSdtLdZi8C9y+Dc8Gav3n9KYNK8jYF0h1OoDpzVuka9xjfrNeV8wFsS/ C6dI2/g== X-Google-Smtp-Source: AGHT+IEAWTZOnwTQFoToY0xNhAjfb0Ia0T03EjU5HdYouUS56VsfaPEHa+Wy7A6wb8fWps+6s7hfhOFdAc5/ X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:6fd2:1e36:6d8c:7c49]) (user=irogers job=sendgmr) by 2002:a25:d885:0:b0:e1c:ed3d:7bb7 with SMTP id 3f1490d57ef6-e337f844041mr2415276.1.1731088188463; Fri, 08 Nov 2024 09:49:48 -0800 (PST) Date: Fri, 8 Nov 2024 09:49:30 -0800 In-Reply-To: <20241108174936.262704-1-irogers@google.com> Message-Id: <20241108174936.262704-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: <20241108174936.262704-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog Subject: [PATCH v7 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:59:15 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 A8EE421C17D for ; Fri, 8 Nov 2024 17:49:51 +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=1731088193; cv=none; b=ipgmCOq6G6EboBsj7ypxGado7tO9x/qm8TsI7iGKwsGPDqNmKCZQ06beZFnXW/0kxxHYWZx2stoiMcQ93T3h6dbTlveTYrfjFBIFzk5qJmYZ8NgKPNMa+ATrL3MsuhlG5nV/XgIg8VKHZXgbrTiW6nZJ4wYPk0cQUVjHKi+B2LE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731088193; c=relaxed/simple; bh=L6pOiD4jKgzV5+KYGW+7iTCHyYZAx+lj5n0yb8rBdBc=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=N0npQwGNepTYxVgyn0XnEOwE4Tm5GUu6f9aI4KLlJ6d4lnQef7Er+Q25OT/sONz232KnVEqFT5A9LNuOfMLELIh1wfOonO0ZC1yZOYL1n5B+XYE1HS8jE1IBRhawkRIN8g+Oc4ojx3TrzZvbeKm7oRQejkePPBT71oC4l7UREUE= 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=wlZFcFPb; 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="wlZFcFPb" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6ea82a5480fso47359977b3.0 for ; Fri, 08 Nov 2024 09:49:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731088190; x=1731692990; 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=SDIyviz98J/CmWwLugR7njULcwnF8B9nxrC4SqsKgXQ=; b=wlZFcFPbX2X7zHEiq5FJhIeTg9GSug4Mr3Ymv4Eif3ImxDk8zImLzN992V8+MllEEg p1IGSXGMGh+c6MfHNwQyLzzDTuv/jeUbnOuv3H9gk9v9wourB3q6plh9z7UPyhwUyqIn y+ExK9E/aa9jONWCeavYWXVGP08BxBTlwn2BGZuON01//TkM+C7wGBGn8ROBvjmsJsEl QhROY5ARbs5BjBbX085VKkBjuRLmeoYpnF3bcFcA3dLDjeJIgypk1VSYTFR8gb57PWRI hl3xkI99FSbaqAPm0gIabP3nd+cwuLH6egq8GFUAMP2CymZA7Ifi9XAcJCySUsSb37yk v1Pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731088191; x=1731692991; 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=SDIyviz98J/CmWwLugR7njULcwnF8B9nxrC4SqsKgXQ=; b=abuS7Rq6ogStYzg/6Yj0n14gon5USUCoE9pStArzhwGF5Uxia3bJL/HKi/2aTTDErz pHDEJXmbAczIb2iT43BwHbVlPA/2WkzXQh8R9kCHy/MW+RUfQS3Frq8DbCoLslhsIAXd XWw641khUpYjKNg+lLNMXz6T/znQPUMZShVwBzriXBjA18cC/1zhQ0I43DZgoswhHgXO pI7uyrQyqplsVRtAReUYYopC37BCs5gJ7ONAB3OK8wFHSYgjI6hBFs9ldOj19iMzFNMq oILpclILLofy4QmMA5ISocLyjqp6/+3GKj3CXA91/l9QiT0AuojcyQ+hboXaFUe0MOFc 9MTQ== X-Forwarded-Encrypted: i=1; AJvYcCWO8UNrBaSU93IU2FvugAcI3KChfyXtlJzeg4c88f1ji3TBcztOeOfHeI5eYWAlMXmvlF/I2+Nt1J3iE98=@vger.kernel.org X-Gm-Message-State: AOJu0YzyOBGpa9Uu4go4OxCkcfBZOTjayO+A27hUgid1AMWve+VdfBO/ pXK6Cu4CDlPAkR8WmjeDnlFBh5X4218zWV+9VtRU4idJ71zJgW21U72QJjGd1tPJ/2okO97EGoc hIfYM5w== X-Google-Smtp-Source: AGHT+IFDzWlDy3EQsGeWrogov1a7VZPvpTz6fsHLZqPy7ePjXupfLxE0/dAJNI3mXqdOfWQxjMp9hkkWq1o1 X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:6fd2:1e36:6d8c:7c49]) (user=irogers job=sendgmr) by 2002:a25:660c:0:b0:e25:cea9:b0e with SMTP id 3f1490d57ef6-e337f910e06mr2491276.9.1731088190654; Fri, 08 Nov 2024 09:49:50 -0800 (PST) Date: Fri, 8 Nov 2024 09:49:31 -0800 In-Reply-To: <20241108174936.262704-1-irogers@google.com> Message-Id: <20241108174936.262704-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: <20241108174936.262704-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog Subject: [PATCH v7 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 | 142 ++++++++++++++++++++++++++++++++++++ tools/perf/util/hwmon_pmu.h | 111 ++++++++++++++++++++++++++++ 3 files changed, 254 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..ee5fb1c41da3 --- /dev/null +++ b/tools/perf/util/hwmon_pmu.c @@ -0,0 +1,142 @@ +// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) +#include "debug.h" +#include "hwmon_pmu.h" +#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" + +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 - 6); + 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:59:15 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 04CA01A9B28 for ; Fri, 8 Nov 2024 17:49:53 +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=1731088196; cv=none; b=s2DMZqJMfgWxqT2pV+nAqEQ8J+nCBRYUQrZQdVShHI3CGj2srWP7++eB7vDn+DyhqPas6Lel67qJIw3ToUBZpZoZgmg60rgNlM0MxxYGD71XwpnOc7VuA5994amH7HeIgXqrDoQGV4OKlIZqITGrTwNENydepqzFo/zeK2E5XRI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731088196; c=relaxed/simple; bh=NKbShQvwHgvwfpa9vU/9CUtrorWgMpA+fuT3dsm8tiw=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=prMOFEzc4sIS1KRkd7Cu/5F9visiB4ts2UGV6AWrk+vnTj8Pbd3sGZ1SzH2LsfQ1L7KESKuutEkW+ABmUzA29kk9fL3d8ZQ7a0pD2jD9SwdXy5xU3CiJrwtxFAkpMg8LUEy7XjyffDjajApZ6lWjfPGAFffGuSeO7udbY+gnJZo= 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=12U/qiqB; 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="12U/qiqB" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6ea8a5e83a3so48125287b3.2 for ; Fri, 08 Nov 2024 09:49:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731088193; x=1731692993; 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=U29VnNAdGfcDQYAQsqPFX5iA64VqRhVFXyadfuAtcAQ=; b=12U/qiqBwuzrJ2tD8l9GJCi78C8dnKPojWzmwn+LEjZbRUd1aXE4xuegjHKJxXE+Pd vi+rU6KjR84i5Fdnx+c5H5meJuI7s3FEtcmvlWr+ts6R2LT7ImHmZPxNQYTFeFRyq6jX oDEE2xWAkzjq8s+SPmMNVqFnQiD7BH3ZvH2y/yPdbzxW1zW59+wnBoY86xt6rRsVvYeP mufDMxmwRyZy2R9GS7vchhEPZq9BRGtTcX23h+ar5wAq9ltWrKSagppEvoFWUeyfTeWm QxLFlaoELD9EjTmsnhAGc9eryp4VleXsEfRJCfWC8/sQgfdoX6NtA9M3AUdqFGxaUCRd Sd9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731088193; x=1731692993; 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=U29VnNAdGfcDQYAQsqPFX5iA64VqRhVFXyadfuAtcAQ=; b=C6YmPlZ4Cr7h7vCMvIyHz7B4WLZksWqSagL3Gd1nps00QDfDu+FRIiADhN9FZp8463 4ZkxCoysSOme6hXG2xMO/POCXwkblr1r1lc5SpL68vLilJgB6O/SAC0V8pmiUQmcZkX+ Nr9S8IUERDl/kgZZ3zRkSWMajWyFikBPPbBApoQCnztshFw3Bu4jgMHjHZk6GS6Kfakz lqgTenjQIn40ZVEd/zPXWtYNtC0HR81lbo8VlYZtF7+9FWanrNuXp+vOxl/LNAm7P7+4 3vCI6g/CMzU1t8kbaQsampzKx6Vk+J9rsDe8aqjSc0BxvdHdiBoD/JCAWIolefAH1It2 UWPA== X-Forwarded-Encrypted: i=1; AJvYcCU7/c95v8NQSOEhi35tugD5pYtv0pb9nVS3kviJz1o8Xptj+MbTGcY/ano5ymRrg425WFTm+8LYacjyxjQ=@vger.kernel.org X-Gm-Message-State: AOJu0YwufVa3Gi5yAXLVMcg0BLzbD/81UbAeGu8CBe0SatNP4VjP/Btb doaYi6RDSOmWWXtl8mZ0aHfpEkCFwuo2hPgcfCF2y42c/5NGeDmAXnrNKK+toiAMlVIg4rRUipW nBFqCTg== X-Google-Smtp-Source: AGHT+IEfV+T366mI7dWlMLWxQa/MdgOP3+nlG9w8nkhQHhM9EQOoTVfZRzQEA2XOw0C0dD2GGRP4uqSSUgJQ X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:6fd2:1e36:6d8c:7c49]) (user=irogers job=sendgmr) by 2002:a05:690c:4a13:b0:6e3:b93:3ae2 with SMTP id 00721157ae682-6eaddd704d6mr196847b3.1.1731088193078; Fri, 08 Nov 2024 09:49:53 -0800 (PST) Date: Fri, 8 Nov 2024 09:49:32 -0800 In-Reply-To: <20241108174936.262704-1-irogers@google.com> Message-Id: <20241108174936.262704-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: <20241108174936.262704-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog Subject: [PATCH v7 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 + tools/perf/util/hwmon_pmu.c | 2 +- 5 files changed, 114 insertions(+), 1 deletion(-) 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); diff --git a/tools/perf/util/hwmon_pmu.c b/tools/perf/util/hwmon_pmu.c index ee5fb1c41da3..f4b7b3b6a052 100644 --- a/tools/perf/util/hwmon_pmu.c +++ b/tools/perf/util/hwmon_pmu.c @@ -126,7 +126,7 @@ bool parse_hwmon_filename(const char *filename, 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 - 6); + strlcpy(fn_type, fn_item, fn_item_len - 5); fn_item =3D fn_type; *alarm =3D true; } --=20 2.47.0.277.g8800431eea-goog From nobody Sat Nov 23 23:59:15 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 32BEC21D227 for ; Fri, 8 Nov 2024 17:49:56 +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=1731088200; cv=none; b=fyae9NPOh5frIhtEoR1JaiAQ+q7ors9TwHo5XDpPl1doQ7mgBboVW4rzM2wR3sZOdzPmT2JbinJDBJnnq39MHtZz8J6hWBhRhE4+XQGs5cyncryYfn4ONzq45FPbJ6WT2nuSMXvGpZWuvSk+UFCsQ9pzGjAGJGu6oDHbICn3JCg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731088200; c=relaxed/simple; bh=43myz6R1hR1QvqV9v0qpuE1koTwSzrw41axa1num1KY=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=TDaYeN1yelEDyX5WWaknoAmL/Ax6BEZnmSoOctDhfHKEw1D4XDPdEYum1wCmpQdwycDabnIaud7N2xf0hqqB6fN+CQmLbEn0WCIKNgTHHgamipDO+VFoBmpGO2v34O+lAj9rZHAWV9IZ8agwah0DD44krXciFhQy/mFhubJ/yp4= 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=uUk5n7xC; 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="uUk5n7xC" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6ea82a5480fso47361717b3.0 for ; Fri, 08 Nov 2024 09:49:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731088195; x=1731692995; 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=0mO/4HznBn2zrBXMmk82cKPWExqmZHhZNXi2p60NjLE=; b=uUk5n7xCPbFJXb0eHc6GWohNL+VIMQpLTZs0UZ43QoKhhESoprCFFgDAHppKhgFXmB YFOYNzcJ8bLiv82+zs4floos4f0tmt77OQLbmbkkiTT7jh144sHgR/UaOUkkAARyhZdV v/LuHaNVz/UwvxRWfSL/LJi5AMi5Y4KWZ9FlfHRtTNalJDZ4G5FQPYBCRsUJTOPiAxG7 8OoqI/EgQrG7FrqXyXmAZkheBYpTXUhmNJvkyciclBoTWNlB09dhf91y2res3VD9M5VU RyEEwBd9NWPazMFv2aZP7qZLGNjbmxPYzx9IsSmbS69iqIzvP8bjzVLcuSUKR9SQiv/Q wsNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731088195; x=1731692995; 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=0mO/4HznBn2zrBXMmk82cKPWExqmZHhZNXi2p60NjLE=; b=M2Mv3LOJCfwuIL1kzU7JQzengPFAeElJf0ISM8K118svsKgnMl2vFZPyaHz3xU8O43 /nYfuyINvlEE+5HjD4+a1WpV2395AZw/IfRXYQYQ5PSLPKsRgghww63kdSiyROsRXtLf 05K9r/QGqfoqi2psRSeyFOxr0clWu1rcI1Ps/yryJXQf01KfRnZL/RFndWCRDecJsJ7h V/sHOtylgc3mTwjQRo4thalfyuCx8ufgVUrrhKKKO+nJ2aHQh5drR5dfetZ0PDBg8jvB bSMUHRLw8kbvn3lHvXuVtORQwKINZiXf+2yTsN/78FS0QCa6J3P3ycJHgsMjAm1rH2b2 D8lA== X-Forwarded-Encrypted: i=1; AJvYcCX5L/mGqy5FcHO5TY3UFQWwGpSMpJlW+On471DXZcLKij+MP1kd/L7wtmLHHAGBjegamNgSFMCgwsNmXtw=@vger.kernel.org X-Gm-Message-State: AOJu0Yx+laVyntIj4lSQejV+L0oNl7oaLSAY1y6kAaInz8AI16dGBz9Q m+2Sma7saGYvaAlBBPx96eL57W1U6sOt5aiRXEMvMPSqUD4v4qGbpKY+pdaYYTi8o206GGCCW4y VNrZ5Jw== X-Google-Smtp-Source: AGHT+IGjX8vzKzduBTujE/wJwFTkW/q56gShF+lORiyusE4sElhbaLVJqjem7Nz7zfrNiqazsKXdmKnZVEOK X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:6fd2:1e36:6d8c:7c49]) (user=irogers job=sendgmr) by 2002:a05:690c:338e:b0:6dd:fda3:6568 with SMTP id 00721157ae682-6eaddf7e61emr293347b3.3.1731088195242; Fri, 08 Nov 2024 09:49:55 -0800 (PST) Date: Fri, 8 Nov 2024 09:49:33 -0800 In-Reply-To: <20241108174936.262704-1-irogers@google.com> Message-Id: <20241108174936.262704-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: <20241108174936.262704-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.277.g8800431eea-goog Subject: [PATCH v7 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 | 683 ++++++++++++++++++++++++++++++++++++ tools/perf/util/hwmon_pmu.h | 45 +++ tools/perf/util/pmu.h | 2 + 3 files changed, 730 insertions(+) diff --git a/tools/perf/util/hwmon_pmu.c b/tools/perf/util/hwmon_pmu.c index f4b7b3b6a052..3f1bf9a9cfdf 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 const char * const hwmon_type_strs[HWMON_TYPE_MAX] =3D { NULL, @@ -22,6 +36,20 @@ const char * const hwmon_type_strs[HWMON_TYPE_MAX] =3D { }; #define LONGEST_HWMON_TYPE_STR "intrusion" =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 */ +}; + const char * const hwmon_item_strs[HWMON_ITEM__MAX] =3D { NULL, "accuracy", @@ -70,6 +98,65 @@ const char * const hwmon_item_strs[HWMON_ITEM__MAX] =3D { }; #define LONGEST_HWMON_ITEM_STR "average_interval_max" =20 +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 _