Re: [PATCH v3 1/7] perf pmu: Use file system cache to optimize sysfs access

Jiri Olsa
2019-10-28T22:01:46Z

On Fri, Oct 25, 2019 at 11:14:11AM -0700, Andi Kleen wrote:

SNIP

> if (pmu_aliases_parse(path, head))
> return -1;
> @@ -525,7 +524,6 @@ static int pmu_alias_terms(struct perf_pmu_alias *alias,
> */
> static int pmu_type(const char *name, __u32 *type)
> {
> - struct stat st;
> char path[PATH_MAX];
> FILE *file;
> int ret = 0;
> @@ -537,7 +535,7 @@ static int pmu_type(const char *name, __u32 *type)
> snprintf(path, PATH_MAX,
> "%s" EVENT_SOURCE_DEVICE_PATH "%s/type", sysfs, name);
>
> - if (stat(path, &st) < 0)
> + if (access(path, R_OK) < 0)

why not file_available call in here?

jirka

> return -1;
>
> file = fopen(path, "r");
> @@ -628,14 +626,11 @@ static struct perf_cpu_map *pmu_cpumask(const char *name)
> static bool pmu_is_uncore(const char *name)
> {
> char path[PATH_MAX];
> - struct perf_cpu_map *cpus;
> - const char *sysfs = sysfs__mountpoint();
> + const char *sysfs;
>
> + sysfs = sysfs__mountpoint();
> snprintf(path, PATH_MAX, CPUS_TEMPLATE_UNCORE, sysfs, name);

SNIP