Skip to content

Commit

Permalink
perf hwmon_pmu: Use openat rather than dup to refresh directory
Browse files Browse the repository at this point in the history
The hwmon PMU test will make a temp directory, open the directory with
O_DIRECTORY then fill it with contents. As the open is before the
filling the contents the later fdopendir may reflect the initial empty
state, meaning no events are seen. Change to re-open the directory,
rather than dup the fd, so the latest contents are seen.

Minor tweaks/additions to debug messages.

Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: Arnaldo Carvalho de Melo <acme@kernel.org>
Link: https://lore.kernel.org/r/20241206042306.1055913-1-irogers@google.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
  • Loading branch information
Ian Rogers authored and Namhyung Kim committed Dec 9, 2024
1 parent 246dfe3 commit 3f61a12
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions tools/perf/util/hwmon_pmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,12 @@ static int hwmon_pmu__read_events(struct hwmon_pmu *pmu)
if (pmu->pmu.sysfs_aliases_loaded)
return 0;

/* Use a dup-ed fd as closedir will close it. */
dup_fd = dup(pmu->hwmon_dir_fd);
/*
* Use a dup-ed fd as closedir will close it. Use openat so that the
* directory contents are refreshed.
*/
dup_fd = openat(pmu->hwmon_dir_fd, ".", O_DIRECTORY);

if (dup_fd == -1)
return -ENOMEM;

Expand Down Expand Up @@ -336,15 +340,18 @@ static int hwmon_pmu__read_events(struct hwmon_pmu *pmu)
close(fd);
}
}
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) {
union hwmon_pmu_event_key key = {
.type_and_num = cur->key,
};
struct hwmon_pmu_event_value *value = cur->pvalue;

if (!test_bit(HWMON_ITEM_INPUT, value->items)) {
pr_debug("hwmon_pmu: removing event '%s%d' that has no input file\n",
hwmon_type_strs[key.type], key.num);
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);
zfree(&value->label);
zfree(&value->name);
Expand Down

0 comments on commit 3f61a12

Please sign in to comment.