aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/cacheline.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf/util/cacheline.c')
-rw-r--r--tools/perf/util/cacheline.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/tools/perf/util/cacheline.c b/tools/perf/util/cacheline.c
new file mode 100644
index 000000000000..9361d3f61f75
--- /dev/null
+++ b/tools/perf/util/cacheline.c
@@ -0,0 +1,26 @@
1// SPDX-License-Identifier: GPL-2.0
2#include "cacheline.h"
3#include "../perf.h"
4#include <unistd.h>
5
6#ifdef _SC_LEVEL1_DCACHE_LINESIZE
7#define cache_line_size(cacheline_sizep) *cacheline_sizep = sysconf(_SC_LEVEL1_DCACHE_LINESIZE)
8#else
9#include <api/fs/fs.h>
10#include "debug.h"
11static void cache_line_size(int *cacheline_sizep)
12{
13 if (sysfs__read_int("devices/system/cpu/cpu0/cache/index0/coherency_line_size", cacheline_sizep))
14 pr_debug("cannot determine cache line size");
15}
16#endif
17
18int cacheline_size(void)
19{
20 static int size;
21
22 if (!size)
23 cache_line_size(&size);
24
25 return size;
26}