Home | History | Annotate | Download | only in util
      1 #include "qemu-common.h"
      2 #include "qemu/cache-utils.h"
      3 
      4 #if defined(_ARCH_PPC)
      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 
     13 void qemu_cache_utils_init(void)
     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__
     20 #include "qemu/osdep.h"
     21 #include "elf.h"
     22 
     23 void qemu_cache_utils_init(void)
     24 {
     25     unsigned long dsize = qemu_getauxval(AT_DCACHEBSIZE);
     26     unsigned long isize = qemu_getauxval(AT_ICACHEBSIZE);
     27 
     28     if (dsize == 0 || isize == 0) {
     29         if (dsize == 0) {
     30             fprintf(stderr, "getauxval AT_DCACHEBSIZE failed\n");
     31         }
     32         if (isize == 0) {
     33             fprintf(stderr, "getauxval AT_ICACHEBSIZE failed\n");
     34         }
     35         exit(1);
     36 
     37     }
     38     qemu_cache_conf.dcache_bsize = dsize;
     39     qemu_cache_conf.icache_bsize = isize;
     40 }
     41 
     42 #elif defined __APPLE__
     43 #include <stdio.h>
     44 #include <sys/types.h>
     45 #include <sys/sysctl.h>
     46 
     47 void qemu_cache_utils_init(void)
     48 {
     49     size_t len;
     50     unsigned cacheline;
     51     int name[2] = { CTL_HW, HW_CACHELINE };
     52 
     53     len = sizeof(cacheline);
     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 }
     61 
     62 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
     63 #include <errno.h>
     64 #include <stdio.h>
     65 #include <stdlib.h>
     66 #include <string.h>
     67 #include <sys/types.h>
     68 #include <sys/sysctl.h>
     69 
     70 void qemu_cache_utils_init(void)
     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 }
     84 #endif
     85 
     86 #endif /* _ARCH_PPC */
     87