Skip to content

Commit 3f61a12

Browse files
captain5050namhyung
authored andcommitted
perf hwmon_pmu: Use openat rather than dup to refresh directory
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 <[email protected]> Tested-by: Arnaldo Carvalho de Melo <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Namhyung Kim <[email protected]>
1 parent 246dfe3 commit 3f61a12

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

tools/perf/util/hwmon_pmu.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,12 @@ static int hwmon_pmu__read_events(struct hwmon_pmu *pmu)
258258
if (pmu->pmu.sysfs_aliases_loaded)
259259
return 0;
260260

261-
/* Use a dup-ed fd as closedir will close it. */
262-
dup_fd = dup(pmu->hwmon_dir_fd);
261+
/*
262+
* Use a dup-ed fd as closedir will close it. Use openat so that the
263+
* directory contents are refreshed.
264+
*/
265+
dup_fd = openat(pmu->hwmon_dir_fd, ".", O_DIRECTORY);
266+
263267
if (dup_fd == -1)
264268
return -ENOMEM;
265269

@@ -336,15 +340,18 @@ static int hwmon_pmu__read_events(struct hwmon_pmu *pmu)
336340
close(fd);
337341
}
338342
}
343+
if (hashmap__size(&pmu->events) == 0)
344+
pr_debug2("hwmon_pmu: %s has no events\n", pmu->pmu.name);
345+
339346
hashmap__for_each_entry_safe((&pmu->events), cur, tmp, bkt) {
340347
union hwmon_pmu_event_key key = {
341348
.type_and_num = cur->key,
342349
};
343350
struct hwmon_pmu_event_value *value = cur->pvalue;
344351

345352
if (!test_bit(HWMON_ITEM_INPUT, value->items)) {
346-
pr_debug("hwmon_pmu: removing event '%s%d' that has no input file\n",
347-
hwmon_type_strs[key.type], key.num);
353+
pr_debug("hwmon_pmu: %s removing event '%s%d' that has no input file\n",
354+
pmu->pmu.name, hwmon_type_strs[key.type], key.num);
348355
hashmap__delete(&pmu->events, key.type_and_num, &key, &value);
349356
zfree(&value->label);
350357
zfree(&value->name);

0 commit comments

Comments
 (0)