Staging
v0.8.1
swh:1:snp:a902887e4be9191b7c6c4406aa06b31c1ce2c7cc
Raw File
Tip revision: 7c53f6b671f4aba70ff15e1b05148b10d58c2837 authored by Linus Torvalds on 10 January 2021, 22:34:50 UTC
Linux 5.11-rc3
Tip revision: 7c53f6b
cacheline.c
// SPDX-License-Identifier: GPL-2.0
#include "cacheline.h"
#include <unistd.h>

#ifdef _SC_LEVEL1_DCACHE_LINESIZE
#define cache_line_size(cacheline_sizep) *cacheline_sizep = sysconf(_SC_LEVEL1_DCACHE_LINESIZE)
#else
#include <api/fs/fs.h>
#include "debug.h"
static void cache_line_size(int *cacheline_sizep)
{
	if (sysfs__read_int("devices/system/cpu/cpu0/cache/index0/coherency_line_size", cacheline_sizep))
		pr_debug("cannot determine cache line size");
}
#endif

int cacheline_size(void)
{
	static int size;

	if (!size)
		cache_line_size(&size);

	return size;
}
back to top