xref: /linux/tools/perf/util/cacheline.c (revision 24168c5e6dfbdd5b414f048f47f75d64533296ca)
1 // SPDX-License-Identifier: GPL-2.0
2 #include "cacheline.h"
3 #include <unistd.h>
4 
5 #ifdef _SC_LEVEL1_DCACHE_LINESIZE
6 #define cache_line_size(cacheline_sizep) *cacheline_sizep = sysconf(_SC_LEVEL1_DCACHE_LINESIZE)
7 #else
8 #include <api/fs/fs.h>
9 #include "debug.h"
10 static void cache_line_size(int *cacheline_sizep)
11 {
12 	if (sysfs__read_int("devices/system/cpu/cpu0/cache/index0/coherency_line_size", cacheline_sizep))
13 		pr_debug("cannot determine cache line size");
14 }
15 #endif
16 
17 int cacheline_size(void)
18 {
19 	static int size;
20 
21 	if (!size)
22 		cache_line_size(&size);
23 
24 	return size;
25 }
26