Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <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>

authored by

Ian Rogers and committed by
Namhyung Kim
3f61a12b 246dfe3d

+11 -4
+11 -4
tools/perf/util/hwmon_pmu.c
··· 258 258 if (pmu->pmu.sysfs_aliases_loaded) 259 259 return 0; 260 260 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 + 263 267 if (dup_fd == -1) 264 268 return -ENOMEM; 265 269 ··· 340 336 close(fd); 341 337 } 342 338 } 339 + if (hashmap__size(&pmu->events) == 0) 340 + pr_debug2("hwmon_pmu: %s has no events\n", pmu->pmu.name); 341 + 343 342 hashmap__for_each_entry_safe((&pmu->events), cur, tmp, bkt) { 344 343 union hwmon_pmu_event_key key = { 345 344 .type_and_num = cur->key, ··· 350 343 struct hwmon_pmu_event_value *value = cur->pvalue; 351 344 352 345 if (!test_bit(HWMON_ITEM_INPUT, value->items)) { 353 - pr_debug("hwmon_pmu: removing event '%s%d' that has no input file\n", 354 - hwmon_type_strs[key.type], key.num); 346 + pr_debug("hwmon_pmu: %s removing event '%s%d' that has no input file\n", 347 + pmu->pmu.name, hwmon_type_strs[key.type], key.num); 355 348 hashmap__delete(&pmu->events, key.type_and_num, &key, &value); 356 349 zfree(&value->label); 357 350 zfree(&value->name);