perf pmu: Use file system cache to optimize sysfs access
authorAndi Kleen <ak@linux.intel.com>
Thu, 21 Nov 2019 00:15:11 +0000 (16:15 -0800)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 28 Nov 2019 11:08:38 +0000 (08:08 -0300)
commitd96645821e940bddff3fc5290656f83bf70d4c92
tree879409141d525cc6996d212afcfe5c01fe6d77be
parent5b596e0ff0e1852197d4c82d3314db5e43126bf7
perf pmu: Use file system cache to optimize sysfs access

pmu.c does a lot of redundant /sys accesses while parsing aliases
and probing for PMUs. On large systems with a lot of PMUs this
can get expensive (>2s):

  % time     seconds  usecs/call     calls    errors syscall
  ------ ----------- ----------- --------- --------- ----------------
   27.25    1.227847           8    160888     16976 openat
   26.42    1.190481           7    164224    164077 stat

Add a cache to remember if specific file names exist or don't
exist, which eliminates most of this overhead.

Also optimize some stat() calls to be slightly cheaper access()

Resulting in:

    0.18    0.004166           2      1851       305 open
    0.08    0.001970           2       829       622 access

Signed-off-by: Andi Kleen <ak@linux.intel.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Link: http://lore.kernel.org/lkml/20191121001522.180827-2-andi@firstfloor.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/Build
tools/perf/util/fncache.c [new file with mode: 0644]
tools/perf/util/fncache.h [new file with mode: 0644]
tools/perf/util/pmu.c
tools/perf/util/srccode.c