Richard Henderson | 664d2c4 | 2013-06-10 09:05:09 -0700 | [diff] [blame] | 1 | #include "qemu-common.h" |
Paolo Bonzini | 1de7afc | 2012-12-17 18:20:00 +0100 | [diff] [blame] | 2 | #include "qemu/cache-utils.h" |
malc | 902b3d5 | 2008-12-10 19:18:40 +0000 | [diff] [blame] | 3 | |
malc | e58ffeb | 2009-01-14 18:39:49 +0000 | [diff] [blame] | 4 | #if defined(_ARCH_PPC) |
malc | 902b3d5 | 2008-12-10 19:18:40 +0000 | [diff] [blame] | 5 | struct qemu_cache_conf qemu_cache_conf = { |
| 6 | .dcache_bsize = 16, |
| 7 | .icache_bsize = 16 |
| 8 | }; |
| 9 | |
| 10 | #if defined _AIX |
| 11 | #include <sys/systemcfg.h> |
| 12 | |
Richard Henderson | 664d2c4 | 2013-06-10 09:05:09 -0700 | [diff] [blame] | 13 | void qemu_cache_utils_init(void) |
malc | 902b3d5 | 2008-12-10 19:18:40 +0000 | [diff] [blame] | 14 | { |
| 15 | qemu_cache_conf.icache_bsize = _system_configuration.icache_line; |
| 16 | qemu_cache_conf.dcache_bsize = _system_configuration.dcache_line; |
| 17 | } |
| 18 | |
| 19 | #elif defined __linux__ |
Richard Henderson | 664d2c4 | 2013-06-10 09:05:09 -0700 | [diff] [blame] | 20 | #include "qemu/osdep.h" |
| 21 | #include "elf.h" |
malc | 4710036 | 2008-12-11 19:12:59 +0000 | [diff] [blame] | 22 | |
Richard Henderson | 664d2c4 | 2013-06-10 09:05:09 -0700 | [diff] [blame] | 23 | void qemu_cache_utils_init(void) |
malc | 902b3d5 | 2008-12-10 19:18:40 +0000 | [diff] [blame] | 24 | { |
Richard Henderson | 664d2c4 | 2013-06-10 09:05:09 -0700 | [diff] [blame] | 25 | unsigned long dsize = qemu_getauxval(AT_DCACHEBSIZE); |
| 26 | unsigned long isize = qemu_getauxval(AT_ICACHEBSIZE); |
malc | 902b3d5 | 2008-12-10 19:18:40 +0000 | [diff] [blame] | 27 | |
Richard Henderson | 664d2c4 | 2013-06-10 09:05:09 -0700 | [diff] [blame] | 28 | if (dsize == 0 || isize == 0) { |
| 29 | if (dsize == 0) { |
| 30 | fprintf(stderr, "getauxval AT_DCACHEBSIZE failed\n"); |
malc | 902b3d5 | 2008-12-10 19:18:40 +0000 | [diff] [blame] | 31 | } |
Richard Henderson | 664d2c4 | 2013-06-10 09:05:09 -0700 | [diff] [blame] | 32 | if (isize == 0) { |
| 33 | fprintf(stderr, "getauxval AT_ICACHEBSIZE failed\n"); |
| 34 | } |
| 35 | exit(1); |
| 36 | |
malc | 902b3d5 | 2008-12-10 19:18:40 +0000 | [diff] [blame] | 37 | } |
Richard Henderson | 664d2c4 | 2013-06-10 09:05:09 -0700 | [diff] [blame] | 38 | qemu_cache_conf.dcache_bsize = dsize; |
| 39 | qemu_cache_conf.icache_bsize = isize; |
malc | 902b3d5 | 2008-12-10 19:18:40 +0000 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | #elif defined __APPLE__ |
malc | 7344da0 | 2009-02-04 20:39:09 +0000 | [diff] [blame] | 43 | #include <stdio.h> |
malc | 902b3d5 | 2008-12-10 19:18:40 +0000 | [diff] [blame] | 44 | #include <sys/types.h> |
| 45 | #include <sys/sysctl.h> |
| 46 | |
Richard Henderson | 664d2c4 | 2013-06-10 09:05:09 -0700 | [diff] [blame] | 47 | void qemu_cache_utils_init(void) |
malc | 902b3d5 | 2008-12-10 19:18:40 +0000 | [diff] [blame] | 48 | { |
| 49 | size_t len; |
| 50 | unsigned cacheline; |
| 51 | int name[2] = { CTL_HW, HW_CACHELINE }; |
| 52 | |
malc | 7344da0 | 2009-02-04 20:39:09 +0000 | [diff] [blame] | 53 | len = sizeof(cacheline); |
malc | 902b3d5 | 2008-12-10 19:18:40 +0000 | [diff] [blame] | 54 | if (sysctl(name, 2, &cacheline, &len, NULL, 0)) { |
| 55 | perror("sysctl CTL_HW HW_CACHELINE failed"); |
| 56 | } else { |
| 57 | qemu_cache_conf.dcache_bsize = cacheline; |
| 58 | qemu_cache_conf.icache_bsize = cacheline; |
| 59 | } |
| 60 | } |
malc | 902b3d5 | 2008-12-10 19:18:40 +0000 | [diff] [blame] | 61 | |
Richard Henderson | 664d2c4 | 2013-06-10 09:05:09 -0700 | [diff] [blame] | 62 | #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) |
Juergen Lock | 4836a2b | 2010-03-12 22:50:15 +0100 | [diff] [blame] | 63 | #include <errno.h> |
Juergen Lock | e4ee916 | 2010-02-19 19:28:23 +0100 | [diff] [blame] | 64 | #include <stdio.h> |
Juergen Lock | 4836a2b | 2010-03-12 22:50:15 +0100 | [diff] [blame] | 65 | #include <stdlib.h> |
| 66 | #include <string.h> |
Juergen Lock | e4ee916 | 2010-02-19 19:28:23 +0100 | [diff] [blame] | 67 | #include <sys/types.h> |
| 68 | #include <sys/sysctl.h> |
| 69 | |
Richard Henderson | 664d2c4 | 2013-06-10 09:05:09 -0700 | [diff] [blame] | 70 | void qemu_cache_utils_init(void) |
Juergen Lock | e4ee916 | 2010-02-19 19:28:23 +0100 | [diff] [blame] | 71 | { |
| 72 | size_t len = 4; |
| 73 | unsigned cacheline; |
| 74 | |
| 75 | if (sysctlbyname ("machdep.cacheline_size", &cacheline, &len, NULL, 0)) { |
| 76 | fprintf(stderr, "sysctlbyname machdep.cacheline_size failed: %s\n", |
| 77 | strerror(errno)); |
| 78 | exit(1); |
| 79 | } |
| 80 | |
| 81 | qemu_cache_conf.dcache_bsize = cacheline; |
| 82 | qemu_cache_conf.icache_bsize = cacheline; |
| 83 | } |
malc | 12b6278 | 2010-11-01 00:53:19 +0300 | [diff] [blame] | 84 | #endif |
Juergen Lock | e4ee916 | 2010-02-19 19:28:23 +0100 | [diff] [blame] | 85 | |
malc | e58ffeb | 2009-01-14 18:39:49 +0000 | [diff] [blame] | 86 | #endif /* _ARCH_PPC */ |