qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [5973] Introduce and use cache-utils.[ch]
@ 2008-12-10 19:18 malc
  2008-12-11 18:19 ` Hollis Blanchard
  0 siblings, 1 reply; 3+ messages in thread
From: malc @ 2008-12-10 19:18 UTC (permalink / raw)
  To: qemu-devel

Revision: 5973
          http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=5973
Author:   malc
Date:     2008-12-10 19:18:40 +0000 (Wed, 10 Dec 2008)

Log Message:
-----------
Introduce and use cache-utils.[ch]

Thanks to Segher Boessenkool and Holis Blanchard.

AIX and Darwin cache inquiry:
http://gcc.gnu.org/ml/gcc-patches/2007-08/msg00388.html

Auxiliary vectors:
http://manugarg.googlepages.com/aboutelfauxiliaryvectors

Modified Paths:
--------------
    trunk/Makefile
    trunk/linux-user/main.c
    trunk/tcg/ppc/tcg-target.h
    trunk/tcg/ppc64/tcg-target.h
    trunk/tcg/tcg.c
    trunk/vl.c

Added Paths:
-----------
    trunk/cache-utils.c
    trunk/cache-utils.h

Modified: trunk/Makefile
===================================================================
--- trunk/Makefile	2008-12-10 18:17:06 UTC (rev 5972)
+++ trunk/Makefile	2008-12-10 19:18:40 UTC (rev 5973)
@@ -79,7 +79,7 @@
 OBJS+=sd.o ssi-sd.o
 OBJS+=bt.o bt-host.o bt-vhci.o bt-l2cap.o bt-sdp.o bt-hci.o bt-hid.o usb-bt.o
 OBJS+=buffered_file.o migration.o migration-tcp.o net.o qemu-sockets.o
-OBJS+=qemu-char.o aio.o net-checksum.o savevm.o
+OBJS+=qemu-char.o aio.o net-checksum.o savevm.o cache-utils.o
 
 ifdef CONFIG_BRLAPI
 OBJS+= baum.o
@@ -178,7 +178,7 @@
 
 #######################################################################
 # USER_OBJS is code used by qemu userspace emulation
-USER_OBJS=cutils.o
+USER_OBJS=cutils.o  cache-utils.o
 
 libqemu_user.a: $(USER_OBJS)
 	rm -f $@ 

Added: trunk/cache-utils.c
===================================================================
--- trunk/cache-utils.c	                        (rev 0)
+++ trunk/cache-utils.c	2008-12-10 19:18:40 UTC (rev 5973)
@@ -0,0 +1,68 @@
+#include "cache-utils.h"
+
+#ifdef __powerpc__
+struct qemu_cache_conf qemu_cache_conf = {
+    .dcache_bsize = 16,
+    .icache_bsize = 16
+};
+
+#if defined _AIX
+#include <sys/systemcfg.h>
+
+static void ppc_init_cacheline_sizes(void)
+{
+    qemu_cache_conf.icache_bsize = _system_configuration.icache_line;
+    qemu_cache_conf.dcache_bsize = _system_configuration.dcache_line;
+}
+
+#elif defined __linux__
+#include <linux/auxvec.h>
+
+static void ppc_init_cacheline_sizes(char **envp)
+{
+    unsigned long *auxv;
+
+    while (*envp++);
+
+    for (auxv = (unsigned long *) envp; *auxv != AT_NULL; auxv += 2) {
+        switch (*auxv) {
+        case AT_DCACHEBSIZE: qemu_cache_conf.dcache_bsize = auxv[1]; break;
+        case AT_ICACHEBSIZE: qemu_cache_conf.icache_bsize = auxv[1]; break;
+        default: break;
+        }
+    }
+}
+
+#elif defined __APPLE__
+#include <sys/types.h>
+#include <sys/sysctl.h>
+
+static void ppc_init_cacheline_sizes(void)
+{
+    size_t len;
+    unsigned cacheline;
+    int name[2] = { CTL_HW, HW_CACHELINE };
+
+    if (sysctl(name, 2, &cacheline, &len, NULL, 0)) {
+        perror("sysctl CTL_HW HW_CACHELINE failed");
+    } else {
+        qemu_cache_conf.dcache_bsize = cacheline;
+        qemu_cache_conf.icache_bsize = cacheline;
+    }
+}
+#endif
+
+#ifdef __linux__
+void qemu_cache_utils_init(char **envp)
+{
+    ppc_init_cacheline_sizes(envp);
+}
+#else
+void qemu_cache_utils_init(char **envp)
+{
+    (void) envp;
+    ppc_init_cacheline_sizes();
+}
+#endif
+
+#endif /* __powerpc__ */

Added: trunk/cache-utils.h
===================================================================
--- trunk/cache-utils.h	                        (rev 0)
+++ trunk/cache-utils.h	2008-12-10 19:18:40 UTC (rev 5973)
@@ -0,0 +1,41 @@
+#ifndef QEMU_CACHE_UTILS_H
+#define QEMU_CACHE_UTILS_H
+
+#ifdef __powerpc__
+struct qemu_cache_conf {
+    unsigned long dcache_bsize;
+    unsigned long icache_bsize;
+};
+
+extern struct qemu_cache_conf qemu_cache_conf;
+
+extern void qemu_cache_utils_init(char **envp);
+
+/* mildly adjusted code from tcg-dyngen.c */
+static inline void flush_icache_range(unsigned long start, unsigned long stop)
+{
+    unsigned long p, start1, stop1;
+    unsigned long dsize = qemu_cache_conf.dcache_bsize;
+    unsigned long isize = qemu_cache_conf.icache_bsize;
+
+    start1 = start & ~(dsize - 1);
+    stop1 = (stop + dsize - 1) & ~(dsize - 1);
+    for (p = start1; p < stop1; p += dsize) {
+        asm volatile ("dcbst 0,%0" : : "r"(p) : "memory");
+    }
+    asm volatile ("sync" : : : "memory");
+
+    start &= start & ~(isize - 1);
+    stop1 = (stop + isize - 1) & ~(isize - 1);
+    for (p = start1; p < stop1; p += isize) {
+        asm volatile ("icbi 0,%0" : : "r"(p) : "memory");
+    }
+    asm volatile ("sync" : : : "memory");
+    asm volatile ("isync" : : : "memory");
+}
+
+#else
+#define qemu_cache_utils_init(envp) do { (void) (envp); } while (0)
+#endif
+
+#endif /* QEMU_CACHE_UTILS_H */

Modified: trunk/linux-user/main.c
===================================================================
--- trunk/linux-user/main.c	2008-12-10 18:17:06 UTC (rev 5972)
+++ trunk/linux-user/main.c	2008-12-10 19:18:40 UTC (rev 5973)
@@ -27,6 +27,7 @@
 
 #include "qemu.h"
 #include "qemu-common.h"
+#include "cache-utils.h"
 /* For tb_lock */
 #include "exec-all.h"
 
@@ -2214,7 +2215,7 @@
     ts->sigqueue_table[i].next = NULL;
 }
  
-int main(int argc, char **argv)
+int main(int argc, char **argv, char **envp)
 {
     const char *filename;
     const char *cpu_model;
@@ -2231,6 +2232,8 @@
     if (argc <= 1)
         usage();
 
+    qemu_cache_utils_init(envp);
+
     /* init debug */
     cpu_set_log_filename(DEBUG_LOGFILE);
 

Modified: trunk/tcg/ppc/tcg-target.h
===================================================================
--- trunk/tcg/ppc/tcg-target.h	2008-12-10 18:17:06 UTC (rev 5972)
+++ trunk/tcg/ppc/tcg-target.h	2008-12-10 19:18:40 UTC (rev 5973)
@@ -86,24 +86,3 @@
 #define TCG_AREG1 TCG_REG_R24
 #define TCG_AREG2 TCG_REG_R25
 #define TCG_AREG3 TCG_REG_R26
-
-/* taken directly from tcg-dyngen.c */
-#define MIN_CACHE_LINE_SIZE 8 /* conservative value */
-
-static inline void flush_icache_range(unsigned long start, unsigned long stop)
-{
-    unsigned long p;
-
-    start &= ~(MIN_CACHE_LINE_SIZE - 1);
-    stop = (stop + MIN_CACHE_LINE_SIZE - 1) & ~(MIN_CACHE_LINE_SIZE - 1);
-
-    for (p = start; p < stop; p += MIN_CACHE_LINE_SIZE) {
-        asm volatile ("dcbst 0,%0" : : "r"(p) : "memory");
-    }
-    asm volatile ("sync" : : : "memory");
-    for (p = start; p < stop; p += MIN_CACHE_LINE_SIZE) {
-        asm volatile ("icbi 0,%0" : : "r"(p) : "memory");
-    }
-    asm volatile ("sync" : : : "memory");
-    asm volatile ("isync" : : : "memory");
-}

Modified: trunk/tcg/ppc64/tcg-target.h
===================================================================
--- trunk/tcg/ppc64/tcg-target.h	2008-12-10 18:17:06 UTC (rev 5972)
+++ trunk/tcg/ppc64/tcg-target.h	2008-12-10 19:18:40 UTC (rev 5973)
@@ -82,24 +82,3 @@
 #define TCG_AREG1 TCG_REG_R24
 #define TCG_AREG2 TCG_REG_R25
 #define TCG_AREG3 TCG_REG_R26
-
-/* taken directly from tcg-dyngen.c */
-#define MIN_CACHE_LINE_SIZE 8 /* conservative value */
-
-static inline void flush_icache_range(unsigned long start, unsigned long stop)
-{
-    unsigned long p;
-
-    start &= ~(MIN_CACHE_LINE_SIZE - 1);
-    stop = (stop + MIN_CACHE_LINE_SIZE - 1) & ~(MIN_CACHE_LINE_SIZE - 1);
-
-    for (p = start; p < stop; p += MIN_CACHE_LINE_SIZE) {
-        asm volatile ("dcbst 0,%0" : : "r"(p) : "memory");
-    }
-    asm volatile ("sync" : : : "memory");
-    for (p = start; p < stop; p += MIN_CACHE_LINE_SIZE) {
-        asm volatile ("icbi 0,%0" : : "r"(p) : "memory");
-    }
-    asm volatile ("sync" : : : "memory");
-    asm volatile ("isync" : : : "memory");
-}

Modified: trunk/tcg/tcg.c
===================================================================
--- trunk/tcg/tcg.c	2008-12-10 18:17:06 UTC (rev 5972)
+++ trunk/tcg/tcg.c	2008-12-10 19:18:40 UTC (rev 5973)
@@ -43,6 +43,7 @@
 
 #include "config.h"
 #include "qemu-common.h"
+#include "cache-utils.h"
 
 /* Note: the long term plan is to reduce the dependancies on the QEMU
    CPU definitions. Currently they are used for qemu_ld/st

Modified: trunk/vl.c
===================================================================
--- trunk/vl.c	2008-12-10 18:17:06 UTC (rev 5972)
+++ trunk/vl.c	2008-12-10 19:18:40 UTC (rev 5973)
@@ -36,6 +36,7 @@
 #include "gdbstub.h"
 #include "qemu-timer.h"
 #include "qemu-char.h"
+#include "cache-utils.h"
 #include "block.h"
 #include "audio/audio.h"
 #include "migration.h"
@@ -4456,7 +4457,7 @@
 
 #endif
 
-int main(int argc, char **argv)
+int main(int argc, char **argv, char **envp)
 {
 #ifdef CONFIG_GDBSTUB
     int use_gdbstub;
@@ -4494,6 +4495,8 @@
     int autostart;
     const char *incoming = NULL;
 
+    qemu_cache_utils_init(envp);
+
     LIST_INIT (&vm_change_state_head);
 #ifndef _WIN32
     {

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [5973] Introduce and use cache-utils.[ch]
  2008-12-10 19:18 [Qemu-devel] [5973] Introduce and use cache-utils.[ch] malc
@ 2008-12-11 18:19 ` Hollis Blanchard
  2008-12-11 18:52   ` malc
  0 siblings, 1 reply; 3+ messages in thread
From: Hollis Blanchard @ 2008-12-11 18:19 UTC (permalink / raw)
  To: qemu-devel

On Wed, 2008-12-10 at 19:18 +0000, malc wrote:
> +#elif defined __linux__
> +#include <linux/auxvec.h>
> +
> +static void ppc_init_cacheline_sizes(char **envp)
> +{
> +    unsigned long *auxv;
> +
> +    while (*envp++);
> +
> +    for (auxv = (unsigned long *) envp; *auxv != AT_NULL; auxv += 2) {
> +        switch (*auxv) {
> +        case AT_DCACHEBSIZE: qemu_cache_conf.dcache_bsize = auxv[1]; break;
> +        case AT_ICACHEBSIZE: qemu_cache_conf.icache_bsize = auxv[1]; break;
> +        default: break;
> +        }
> +    }
> +}

I'm cross-compiling, and linux/auxvec.h was not installed with my glibc
headers. How about this:



Don't require linux/auxvec.h, which isn't always installed with libc.

Signed-off-by: Hollis Blanchard <hollisb@us.ibm.com>

diff --git a/cache-utils.c b/cache-utils.c
index 0b4a5ac..7c98144 100644
--- a/cache-utils.c
+++ b/cache-utils.c
@@ -16,7 +16,10 @@ static void ppc_init_cacheline_sizes(void)
 }
 
 #elif defined __linux__
-#include <linux/auxvec.h>
+
+#define QEMU_AT_NULL        0
+#define QEMU_AT_DCACHEBSIZE 19
+#define QEMU_AT_ICACHEBSIZE 20
 
 static void ppc_init_cacheline_sizes(char **envp)
 {
@@ -24,10 +27,10 @@ static void ppc_init_cacheline_sizes(char **envp)
 
     while (*envp++);
 
-    for (auxv = (unsigned long *) envp; *auxv != AT_NULL; auxv += 2) {
+    for (auxv = (unsigned long *) envp; *auxv != QEMU_AT_NULL; auxv += 2) {
         switch (*auxv) {
-        case AT_DCACHEBSIZE: qemu_cache_conf.dcache_bsize = auxv[1]; break;
-        case AT_ICACHEBSIZE: qemu_cache_conf.icache_bsize = auxv[1]; break;
+        case QEMU_AT_DCACHEBSIZE: qemu_cache_conf.dcache_bsize = auxv[1]; break
+        case QEMU_AT_ICACHEBSIZE: qemu_cache_conf.icache_bsize = auxv[1]; break
         default: break;
         }
     }


-- 
Hollis Blanchard
IBM Linux Technology Center

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [5973] Introduce and use cache-utils.[ch]
  2008-12-11 18:19 ` Hollis Blanchard
@ 2008-12-11 18:52   ` malc
  0 siblings, 0 replies; 3+ messages in thread
From: malc @ 2008-12-11 18:52 UTC (permalink / raw)
  To: Hollis Blanchard; +Cc: qemu-devel

On Thu, 11 Dec 2008, Hollis Blanchard wrote:

> On Wed, 2008-12-10 at 19:18 +0000, malc wrote:
>> +#elif defined __linux__
>> +#include <linux/auxvec.h>
>> +
>> +static void ppc_init_cacheline_sizes(char **envp)
>> +{
>> +    unsigned long *auxv;
>> +
>> +    while (*envp++);
>> +
>> +    for (auxv = (unsigned long *) envp; *auxv != AT_NULL; auxv += 2) {
>> +        switch (*auxv) {
>> +        case AT_DCACHEBSIZE: qemu_cache_conf.dcache_bsize = auxv[1]; break;
>> +        case AT_ICACHEBSIZE: qemu_cache_conf.icache_bsize = auxv[1]; break;
>> +        default: break;
>> +        }
>> +    }
>> +}
>
> I'm cross-compiling, and linux/auxvec.h was not installed with my glibc
> headers. How about this:
>
>
>
> Don't require linux/auxvec.h, which isn't always installed with libc.
>
> Signed-off-by: Hollis Blanchard <hollisb@us.ibm.com>

Funny you mention it.. My initial code was exactly like this only
the defines where called QAT_...
[..snip..]

-- 
mailto:av1474@comtv.ru

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-12-11 18:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-12-10 19:18 [Qemu-devel] [5973] Introduce and use cache-utils.[ch] malc
2008-12-11 18:19 ` Hollis Blanchard
2008-12-11 18:52   ` malc

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).