1 #include "qemu-common.h"
2 #include "qemu/cache-utils.h"
5 struct qemu_cache_conf qemu_cache_conf
= {
11 #include <sys/systemcfg.h>
13 void qemu_cache_utils_init(void)
15 qemu_cache_conf
.icache_bsize
= _system_configuration
.icache_line
;
16 qemu_cache_conf
.dcache_bsize
= _system_configuration
.dcache_line
;
19 #elif defined __linux__
20 #include "qemu/osdep.h"
23 void qemu_cache_utils_init(void)
25 unsigned long dsize
= qemu_getauxval(AT_DCACHEBSIZE
);
26 unsigned long isize
= qemu_getauxval(AT_ICACHEBSIZE
);
28 if (dsize
== 0 || isize
== 0) {
30 fprintf(stderr
, "getauxval AT_DCACHEBSIZE failed\n");
33 fprintf(stderr
, "getauxval AT_ICACHEBSIZE failed\n");
38 qemu_cache_conf
.dcache_bsize
= dsize
;
39 qemu_cache_conf
.icache_bsize
= isize
;
42 #elif defined __APPLE__
44 #include <sys/types.h>
45 #include <sys/sysctl.h>
47 void qemu_cache_utils_init(void)
51 int name
[2] = { CTL_HW
, HW_CACHELINE
};
53 len
= sizeof(cacheline
);
54 if (sysctl(name
, 2, &cacheline
, &len
, NULL
, 0)) {
55 perror("sysctl CTL_HW HW_CACHELINE failed");
57 qemu_cache_conf
.dcache_bsize
= cacheline
;
58 qemu_cache_conf
.icache_bsize
= cacheline
;
62 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
67 #include <sys/types.h>
68 #include <sys/sysctl.h>
70 void qemu_cache_utils_init(void)
75 if (sysctlbyname ("machdep.cacheline_size", &cacheline
, &len
, NULL
, 0)) {
76 fprintf(stderr
, "sysctlbyname machdep.cacheline_size failed: %s\n",
81 qemu_cache_conf
.dcache_bsize
= cacheline
;
82 qemu_cache_conf
.icache_bsize
= cacheline
;
86 #endif /* _ARCH_PPC */