Re: [PATCH v2 3/9] perf pmu: Use file system cache to optimize sysfs access

From: Jiri Olsa
Date: Wed Oct 23 2019 - 05:47:37 EST


On Sun, Oct 20, 2019 at 10:51:56AM -0700, Andi Kleen wrote:

SNIP

> @@ -92,8 +93,12 @@ static int pmu_format(const char *name, struct list_head *format)
> snprintf(path, PATH_MAX,
> "%s" EVENT_SOURCE_DEVICE_PATH "%s/format", sysfs, name);
>
> - if (stat(path, &st) < 0)
> + if (lookup_fncache(path, &res) && !res)
> + return 0;
> +
> + if (!res && access(path, R_OK) < 0)
> return 0; /* no error if format does not exist */
> + update_fncache(path, true);
>
> if (perf_pmu__format_parse(path, format))
> return -1;
> @@ -470,9 +475,9 @@ static int pmu_aliases_parse(char *dir, struct list_head *head)
> */
> static int pmu_aliases(const char *name, struct list_head *head)
> {
> - struct stat st;
> char path[PATH_MAX];
> const char *sysfs = sysfs__mountpoint();
> + bool res = false;
>
> if (!sysfs)
> return -1;
> @@ -480,8 +485,11 @@ static int pmu_aliases(const char *name, struct list_head *head)
> snprintf(path, PATH_MAX,
> "%s/bus/event_source/devices/%s/events", sysfs, name);
>
> - if (stat(path, &st) < 0)
> - return 0; /* no error if 'events' does not exist */
> + if (lookup_fncache(path, &res) && !res)
> + return 0;
> + if (!res && access(path, R_OK) < 0)
> + return 0;
> + update_fncache(path, true);

I was thinking that maybe you dont need to have the fncache::res,
but then I realized we have 2 kind of information in here:
- we processed this file
- is present file present

so I think you should update the result on each update_fncache call,
not only when it's succesful


also, could you please make single function API for this?
sonething like:

is_the_file_there(path)

that would encapsulate those calls

thanks,
jirka