From: Ian Rogers <irogers@google.com>
To: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Namhyung Kim <namhyung@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>, Ian Rogers <irogers@google.com>,
Adrian Hunter <adrian.hunter@intel.com>,
James Clark <james.clark@linaro.org>,
linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v1 17/26] perf hwmon_pmu: Use generic hashmap for hwmon events
Date: Fri, 13 Nov 2026 13:48:41 -0800 [thread overview]
Message-ID: <20261113214850.3329699-18-irogers@google.com> (raw)
In-Reply-To: <20261113214850.3329699-1-irogers@google.com>
Convert hwmon_pmu::events in util/hwmon_pmu.c to
DECLARE_HASHMAP(hwmon_pmu_events_map, long, struct hwmon_pmu_event_value *)
and use hashmap__for_each{,_safe}().
Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/perf/util/hwmon_pmu.c | 57 +++++++++++++++++--------------------
1 file changed, 26 insertions(+), 31 deletions(-)
diff --git a/tools/perf/util/hwmon_pmu.c b/tools/perf/util/hwmon_pmu.c
index c150fc0d7bd3..95049f5fead3 100644
--- a/tools/perf/util/hwmon_pmu.c
+++ b/tools/perf/util/hwmon_pmu.c
@@ -101,9 +101,12 @@ static const char *const hwmon_units[HWMON_TYPE_MAX] = {
"'C", /* temp */
};
+struct hwmon_pmu_event_value;
+DECLARE_HASHMAP(hwmon_pmu_events_map, long, struct hwmon_pmu_event_value *);
+
struct hwmon_pmu {
struct perf_pmu pmu;
- struct hashmap events;
+ struct hwmon_pmu_events_map events;
char *hwmon_dir;
};
@@ -237,8 +240,8 @@ static void fix_name(char *p)
static int hwmon_pmu__read_events(struct hwmon_pmu *pmu)
{
int err = 0;
- struct hashmap_entry *cur, *tmp;
- size_t bkt;
+ long key_val;
+ struct hwmon_pmu_event_value *value;
struct io_dirent64 *ent;
struct io_dir dir;
@@ -257,7 +260,6 @@ static int hwmon_pmu__read_events(struct hwmon_pmu *pmu)
enum hwmon_item item;
bool alarm;
union hwmon_pmu_event_key key = { .type_and_num = 0 };
- struct hwmon_pmu_event_value *value;
if (ent->d_type != DT_REG)
continue;
@@ -324,16 +326,15 @@ static int hwmon_pmu__read_events(struct hwmon_pmu *pmu)
if (hashmap__size(&pmu->events) == 0)
pr_debug2("hwmon_pmu: %s has no events\n", pmu->pmu.name);
- hashmap__for_each_entry_safe((&pmu->events), cur, tmp, bkt) {
+ hashmap__for_each_safe(&pmu->events, key_val, value) {
union hwmon_pmu_event_key key = {
- .type_and_num = cur->key,
+ .type_and_num = key_val,
};
- struct hwmon_pmu_event_value *value = cur->pvalue;
if (!test_bit(HWMON_ITEM_INPUT, value->items)) {
pr_debug("hwmon_pmu: %s removing event '%s%d' that has no input file\n",
pmu->pmu.name, hwmon_type_strs[key.type], key.num);
- hashmap__delete(&pmu->events, key.type_and_num, &key, &value);
+ hashmap__delete(&pmu->events, key_val, NULL, NULL);
zfree(&value->label);
zfree(&value->name);
free(value);
@@ -397,12 +398,10 @@ struct perf_pmu *hwmon_pmu__new(struct list_head *pmus, const char *hwmon_dir,
void hwmon_pmu__exit(struct perf_pmu *pmu)
{
struct hwmon_pmu *hwm = container_of(pmu, struct hwmon_pmu, pmu);
- struct hashmap_entry *cur, *tmp;
- size_t bkt;
-
- hashmap__for_each_entry_safe((&hwm->events), cur, tmp, bkt) {
- struct hwmon_pmu_event_value *value = cur->pvalue;
+ long key;
+ struct hwmon_pmu_event_value *value;
+ hashmap__for_each_safe(&hwm->events, key, value) {
zfree(&value->label);
zfree(&value->name);
free(value);
@@ -463,13 +462,13 @@ static size_t hwmon_pmu__describe_items(struct hwmon_pmu *hwm, char *out_buf, si
int hwmon_pmu__for_each_event(struct perf_pmu *pmu, void *state, pmu_event_callback cb)
{
struct hwmon_pmu *hwm = container_of(pmu, struct hwmon_pmu, pmu);
- struct hashmap_entry *cur;
- size_t bkt;
+ long key_val;
+ struct hwmon_pmu_event_value *value;
if (hwmon_pmu__read_events(hwm))
return false;
- hashmap__for_each_entry((&hwm->events), cur, bkt) {
+ hashmap__for_each(&hwm->events, key_val, value) {
static const char *const hwmon_scale_units[HWMON_TYPE_MAX] = {
NULL,
"0.001V", /* cpu */
@@ -500,9 +499,8 @@ int hwmon_pmu__for_each_event(struct perf_pmu *pmu, void *state, pmu_event_callb
char desc_buf[256];
char encoding_buf[128];
union hwmon_pmu_event_key key = {
- .type_and_num = cur->key,
+ .type_and_num = key_val,
};
- struct hwmon_pmu_event_value *value = cur->pvalue;
struct pmu_event_info info = {
.pmu = pmu,
.name = value->name,
@@ -537,7 +535,7 @@ int hwmon_pmu__for_each_event(struct perf_pmu *pmu, void *state, pmu_event_callb
key, value->alarm_items, /*is_alarm=*/true);
snprintf(encoding_buf, sizeof(encoding_buf), "%s/config=0x%lx/",
- pmu->name, cur->key);
+ pmu->name, key_val);
ret = cb(state, &info);
if (ret)
@@ -560,8 +558,8 @@ bool hwmon_pmu__have_event(struct perf_pmu *pmu, const char *name)
enum hwmon_type type;
int number;
union hwmon_pmu_event_key key = { .type_and_num = 0 };
- struct hashmap_entry *cur;
- size_t bkt;
+ long key_val;
+ struct hwmon_pmu_event_value *value;
if (!parse_hwmon_filename(name, &type, &number, /*item=*/NULL, /*is_alarm=*/NULL))
return false;
@@ -571,15 +569,13 @@ bool hwmon_pmu__have_event(struct perf_pmu *pmu, const char *name)
key.type = type;
key.num = number;
- if (hashmap__find(&hwm->events, key.type_and_num, /*value=*/NULL))
+ if (hashmap__find(&hwm->events, key.type_and_num, /*value_ptr=*/NULL))
return true;
if (key.num != -1)
return false;
/* Item is of form <type>_ which means we should match <type>_<label>. */
- hashmap__for_each_entry((&hwm->events), cur, bkt) {
- struct hwmon_pmu_event_value *value = cur->pvalue;
-
- key.type_and_num = cur->key;
+ hashmap__for_each(&hwm->events, key_val, value) {
+ key.type_and_num = key_val;
if (key.type == type && value->name && !strcasecmp(name, value->name))
return true;
}
@@ -602,15 +598,14 @@ static int hwmon_pmu__config_term(const struct hwmon_pmu *hwm,
* Item is of form <type>_ which means we should
* match <type>_<label>.
*/
- struct hashmap_entry *cur;
- size_t bkt;
+ long key_val;
+ struct hwmon_pmu_event_value *value;
attr->config = 0;
- hashmap__for_each_entry((&hwm->events), cur, bkt) {
+ hashmap__for_each(&hwm->events, key_val, value) {
union hwmon_pmu_event_key key = {
- .type_and_num = cur->key,
+ .type_and_num = key_val,
};
- struct hwmon_pmu_event_value *value = cur->pvalue;
if (key.type == type && value->name &&
!strcasecmp(term->config, value->name)) {
--
2.56.1.703.gf848ed807c-goog
next prev parent reply other threads:[~2026-11-13 21:49 UTC|newest]
Thread overview: 53+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-13 21:48 [PATCH v1 00/26] perf hashmap: Fix undefined behavior, remove ERR_PTR, and add type-safe generic hashmaps Ian Rogers
2026-11-13 21:48 ` [PATCH v1 01/26] perf threads: Fix uninitialized pointer put when thread removal misses Ian Rogers
2026-11-13 21:56 ` sashiko-bot
2026-11-13 21:48 ` [PATCH v1 02/26] perf annotate: Fix sym_hist_entry memory leak when zeroing histograms Ian Rogers
2026-11-13 21:59 ` sashiko-bot
2026-11-13 21:48 ` [PATCH v1 03/26] perf stat: Fix per_pkg_mask key leak on hashmap__add failure Ian Rogers
2026-11-13 21:55 ` sashiko-bot
2026-11-13 21:48 ` [PATCH v1 04/26] perf build: Don't check difference of perf and libbpf hashmap Ian Rogers
2026-11-13 21:54 ` sashiko-bot
2026-11-13 21:48 ` [PATCH v1 05/26] perf hashmap: Always build perf's hashmap and avoid libbpf symbol conflict Ian Rogers
2026-11-13 21:55 ` sashiko-bot
2026-11-13 21:48 ` [PATCH v1 06/26] perf hashmap: Fix strict aliasing violations in hashmap Ian Rogers
2026-11-13 21:56 ` sashiko-bot
2026-11-13 21:48 ` [PATCH v1 07/26] perf hashmap: Remove errptr usage from hashmap Ian Rogers
2026-11-13 22:01 ` sashiko-bot
2026-11-13 21:48 ` [PATCH v1 08/26] perf hashmap: Introduce generic types and macros Ian Rogers
2026-11-13 22:01 ` sashiko-bot
2026-11-13 21:48 ` [PATCH v1 09/26] perf fncache: Use generic hashmap for fncache Ian Rogers
2026-11-13 21:56 ` sashiko-bot
2026-11-13 21:48 ` [PATCH v1 10/26] perf ftrace: Use generic hashmap for profile_hash Ian Rogers
2026-11-13 21:57 ` sashiko-bot
2026-11-13 21:48 ` [PATCH v1 11/26] perf trace: Use generic hashmap for syscall_stats Ian Rogers
2026-11-13 22:04 ` sashiko-bot
2026-11-13 21:48 ` [PATCH v1 12/26] perf trace: Use generic hashmap for bpf-trace-summary Ian Rogers
2026-11-13 21:58 ` sashiko-bot
2026-11-13 21:48 ` [PATCH v1 13/26] perf lock: Use generic hashmap for slab_hash Ian Rogers
2026-11-13 21:57 ` sashiko-bot
2026-11-13 21:48 ` [PATCH v1 14/26] perf stat: Use generic hashmap for per_pkg_mask Ian Rogers
2026-11-13 21:57 ` sashiko-bot
2026-11-13 21:48 ` [PATCH v1 15/26] perf expr: Use generic hashmap for expr_ids Ian Rogers
2026-11-13 22:02 ` sashiko-bot
2026-11-13 21:48 ` [PATCH v1 16/26] perf pmu: Use generic hashmap for pmu aliases Ian Rogers
2026-11-13 22:04 ` sashiko-bot
2026-11-13 21:48 ` Ian Rogers [this message]
2026-11-13 21:58 ` [PATCH v1 17/26] perf hwmon_pmu: Use generic hashmap for hwmon events sashiko-bot
2026-11-13 21:48 ` [PATCH v1 18/26] perf s390: Use generic hashmap for counter name cache Ian Rogers
2026-11-13 21:59 ` sashiko-bot
2026-11-13 21:48 ` [PATCH v1 19/26] perf threads: Use generic hashmap for thread shards Ian Rogers
2026-11-13 22:01 ` sashiko-bot
2026-11-13 21:48 ` [PATCH v1 20/26] perf annotate: Use generic hashmap for sym_samples Ian Rogers
2026-11-13 22:08 ` sashiko-bot
2026-11-13 21:48 ` [PATCH v1 21/26] perf annotate: Use generic hashmap for browser type_hash Ian Rogers
2026-11-13 21:59 ` sashiko-bot
2026-11-13 21:48 ` [PATCH v1 22/26] perf annotate-data: Use generic hashmap for type_hist samples Ian Rogers
2026-11-13 22:00 ` sashiko-bot
2026-11-13 21:48 ` [PATCH v1 23/26] perf inject: Use generic hashmap for aslr remap_addresses Ian Rogers
2026-11-13 21:59 ` sashiko-bot
2026-11-13 21:48 ` [PATCH v1 24/26] perf inject: Use generic hashmap for aslr top_addresses Ian Rogers
2026-11-13 21:59 ` sashiko-bot
2026-11-13 21:48 ` [PATCH v1 25/26] perf inject: Use generic hashmap for aslr evsel_orig_attrs Ian Rogers
2026-11-13 22:00 ` sashiko-bot
2026-11-13 21:48 ` [PATCH v1 26/26] perf hashmap: Remove untyped struct hashmap API Ian Rogers
2026-11-13 22:01 ` sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261113214850.3329699-18-irogers@google.com \
--to=irogers@google.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=james.clark@linaro.org \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox