*/
#include "qemu/osdep.h"
+#include "qemu/host-utils.h"
+#include "qemu/atomic.h"
int qemu_icache_linesize = 0;
+int qemu_icache_linesize_log;
int qemu_dcache_linesize = 0;
+int qemu_dcache_linesize_log;
/*
* Operating system specific detection mechanisms.
g_free(buf);
}
-#elif defined(__APPLE__) \
- || defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+#elif defined(__APPLE__)
# include <sys/sysctl.h>
-# if defined(__APPLE__)
-# define SYSCTL_CACHELINE_NAME "hw.cachelinesize"
-# else
-# define SYSCTL_CACHELINE_NAME "machdep.cacheline_size"
-# endif
-
static void sys_cache_info(int *isize, int *dsize)
{
/* There's only a single sysctl for both I/D cache line sizes. */
long size;
size_t len = sizeof(size);
- if (!sysctlbyname(SYSCTL_CACHELINE_NAME, &size, &len, NULL, 0)) {
+ if (!sysctlbyname("hw.cachelinesize", &size, &len, NULL, 0)) {
+ *isize = *dsize = size;
+ }
+}
+#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+# include <sys/sysctl.h>
+static void sys_cache_info(int *isize, int *dsize)
+{
+ /* There's only a single sysctl for both I/D cache line sizes. */
+ int size;
+ size_t len = sizeof(size);
+ if (!sysctlbyname("machdep.cacheline_size", &size, &len, NULL, 0)) {
*isize = *dsize = size;
}
}
-
#else
/* POSIX */
static void sys_cache_info(int *isize, int *dsize)
{
# ifdef _SC_LEVEL1_ICACHE_LINESIZE
- *isize = sysconf(_SC_LEVEL1_ICACHE_LINESIZE);
+ int tmp_isize = (int) sysconf(_SC_LEVEL1_ICACHE_LINESIZE);
+ if (tmp_isize > 0) {
+ *isize = tmp_isize;
+ }
# endif
# ifdef _SC_LEVEL1_DCACHE_LINESIZE
- *dsize = sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
+ int tmp_dsize = (int) sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
+ if (tmp_dsize > 0) {
+ *dsize = tmp_dsize;
+ }
# endif
}
#endif /* sys_cache_info */
static void arch_cache_info(int *isize, int *dsize)
{
if (*isize == 0 || *dsize == 0) {
- unsigned long ctr;
+ uint64_t ctr;
/* The real cache geometry is in CCSIDR_EL1/CLIDR_EL1/CSSELR_EL1,
but (at least under Linux) these are marked protected by the
arch_cache_info(&isize, &dsize);
fallback_cache_info(&isize, &dsize);
+ assert((isize & (isize - 1)) == 0);
+ assert((dsize & (dsize - 1)) == 0);
+
qemu_icache_linesize = isize;
+ qemu_icache_linesize_log = ctz32(isize);
qemu_dcache_linesize = dsize;
+ qemu_dcache_linesize_log = ctz32(dsize);
+
+ qatomic64_init();
}