[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 2/2] tcg/ppc*: Move cache initialization to ppc spec
From: |
Stefan Weil |
Subject: |
[Qemu-devel] [PATCH 2/2] tcg/ppc*: Move cache initialization to ppc specific code |
Date: |
Mon, 3 Oct 2011 22:43:20 +0200 |
qemu_cache_utils_init() is only used by ppc / ppc64 tcg targets
to initialize the cache before flush_icache_range() is called.
This patch moves the code to tcg/ppc and tcg/ppc64.
Initialisation is called from tcg_target_init() there.
Signed-off-by: Stefan Weil <address@hidden>
---
Makefile.objs | 4 +-
cache-utils.c | 97 -----------------------------------------
cache-utils.h | 41 -----------------
linux-user/main.c | 3 -
tcg/ppc/tcg-target.c | 113 ++++++++++++++++++++++++++++++++++++++++++++++++
tcg/ppc64/tcg-target.c | 113 ++++++++++++++++++++++++++++++++++++++++++++++++
tcg/tcg.c | 1 -
vl.c | 3 -
8 files changed, 228 insertions(+), 147 deletions(-)
delete mode 100644 cache-utils.c
delete mode 100644 cache-utils.h
diff --git a/Makefile.objs b/Makefile.objs
index 8d23fbb..011ccc6 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -23,7 +23,7 @@ coroutine-obj-$(CONFIG_WIN32) += coroutine-win32.o
#######################################################################
# block-obj-y is code used by both qemu system emulation and qemu-img
-block-obj-y = cutils.o cache-utils.o qemu-option.o module.o async.o
+block-obj-y = cutils.o qemu-option.o module.o async.o
block-obj-y += nbd.o block.o aio.o aes.o qemu-config.o qemu-progress.o
qemu-sockets.o
block-obj-y += $(coroutine-obj-y)
block-obj-$(CONFIG_POSIX) += posix-aio-compat.o
@@ -176,7 +176,7 @@ common-obj-$(CONFIG_XEN_BACKEND) += xen_console.o xenfb.o
xen_disk.o xen_nic.o
user-obj-y =
user-obj-y += envlist.o path.o
user-obj-y += tcg-runtime.o host-utils.o
-user-obj-y += cutils.o cache-utils.o
+user-obj-y += cutils.o
user-obj-y += $(trace-obj-y)
######################################################################
diff --git a/cache-utils.c b/cache-utils.c
deleted file mode 100644
index 2db5af2..0000000
--- a/cache-utils.c
+++ /dev/null
@@ -1,97 +0,0 @@
-#include "cache-utils.h"
-
-#if defined(_ARCH_PPC)
-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__
-
-#define QEMU_AT_NULL 0
-#define QEMU_AT_DCACHEBSIZE 19
-#define QEMU_AT_ICACHEBSIZE 20
-
-static void ppc_init_cacheline_sizes(char **envp)
-{
- unsigned long *auxv;
-
- while (*envp++);
-
- for (auxv = (unsigned long *) envp; *auxv != QEMU_AT_NULL; auxv += 2) {
- switch (*auxv) {
- 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;
- }
- }
-}
-
-#elif defined __APPLE__
-#include <stdio.h>
-#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 };
-
- len = sizeof(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
-
-#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/sysctl.h>
-
-static void ppc_init_cacheline_sizes(void)
-{
- size_t len = 4;
- unsigned cacheline;
-
- if (sysctlbyname ("machdep.cacheline_size", &cacheline, &len, NULL, 0)) {
- fprintf(stderr, "sysctlbyname machdep.cacheline_size failed: %s\n",
- strerror(errno));
- exit(1);
- }
-
- 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 /* _ARCH_PPC */
diff --git a/cache-utils.h b/cache-utils.h
deleted file mode 100644
index 0b65907..0000000
--- a/cache-utils.h
+++ /dev/null
@@ -1,41 +0,0 @@
-#ifndef QEMU_CACHE_UTILS_H
-#define QEMU_CACHE_UTILS_H
-
-#if defined(_ARCH_PPC)
-struct qemu_cache_conf {
- unsigned long dcache_bsize;
- unsigned long icache_bsize;
-};
-
-extern struct qemu_cache_conf qemu_cache_conf;
-
-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 */
diff --git a/linux-user/main.c b/linux-user/main.c
index 186358b..88135ce 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -28,7 +28,6 @@
#include "qemu.h"
#include "qemu-common.h"
-#include "cache-utils.h"
#include "cpu.h"
#include "tcg.h"
#include "qemu-timer.h"
@@ -3279,8 +3278,6 @@ int main(int argc, char **argv, char **envp)
if (argc <= 1)
usage();
- qemu_cache_utils_init(envp);
-
if ((envlist = envlist_create()) == NULL) {
(void) fprintf(stderr, "Unable to allocate envlist\n");
exit(1);
diff --git a/tcg/ppc/tcg-target.c b/tcg/ppc/tcg-target.c
index 87cc117..7a66dd2 100644
--- a/tcg/ppc/tcg-target.c
+++ b/tcg/ppc/tcg-target.c
@@ -167,6 +167,113 @@ static const int tcg_target_callee_save_regs[] = {
TCG_REG_R31
};
+struct qemu_cache_conf {
+ unsigned long dcache_bsize;
+ unsigned long icache_bsize;
+};
+
+static 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__
+
+#define QEMU_AT_NULL 0
+#define QEMU_AT_DCACHEBSIZE 19
+#define QEMU_AT_ICACHEBSIZE 20
+
+static void ppc_init_cacheline_sizes(char **envp)
+{
+ unsigned long *auxv;
+
+ while (*envp++) {
+ }
+
+ for (auxv = (unsigned long *)envp; *auxv != QEMU_AT_NULL; auxv += 2) {
+ switch (*auxv) {
+ 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;
+ }
+ }
+}
+
+#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 };
+
+ len = sizeof(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
+
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+#include <sys/types.h>
+#include <sys/sysctl.h>
+
+static void ppc_init_cacheline_sizes(void)
+{
+ size_t len = 4;
+ unsigned cacheline;
+
+ if (sysctlbyname("machdep.cacheline_size", &cacheline, &len, NULL, 0)) {
+ fprintf(stderr, "sysctlbyname machdep.cacheline_size failed: %s\n",
+ strerror(errno));
+ exit(1);
+ }
+
+ qemu_cache_conf.dcache_bsize = cacheline;
+ qemu_cache_conf.icache_bsize = cacheline;
+}
+#endif
+
+static inline void flush_icache_range(unsigned long start, unsigned long stop)
+{
+ unsigned long p;
+ unsigned long dsize = qemu_cache_conf.dcache_bsize;
+ unsigned long isize = qemu_cache_conf.icache_bsize;
+ unsigned long start1 = start & ~(dsize - 1);
+ unsigned long 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");
+}
+
static uint32_t reloc_pc24_val (void *pc, tcg_target_long target)
{
tcg_target_long disp;
@@ -1902,6 +2009,12 @@ static const TCGTargetOpDef ppc_op_defs[] = {
static void tcg_target_init(TCGContext *s)
{
+#ifdef __linux__
+ ppc_init_cacheline_sizes(envp);
+#else
+ ppc_init_cacheline_sizes();
+#endif
+
tcg_regset_set32(tcg_target_available_regs[TCG_TYPE_I32], 0, 0xffffffff);
tcg_regset_set32(tcg_target_call_clobber_regs, 0,
(1 << TCG_REG_R0) |
diff --git a/tcg/ppc64/tcg-target.c b/tcg/ppc64/tcg-target.c
index 3d24cd4..680ad5f 100644
--- a/tcg/ppc64/tcg-target.c
+++ b/tcg/ppc64/tcg-target.c
@@ -158,6 +158,113 @@ static const int tcg_target_callee_save_regs[] = {
TCG_REG_R31
};
+struct qemu_cache_conf {
+ unsigned long dcache_bsize;
+ unsigned long icache_bsize;
+};
+
+static 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__
+
+#define QEMU_AT_NULL 0
+#define QEMU_AT_DCACHEBSIZE 19
+#define QEMU_AT_ICACHEBSIZE 20
+
+static void ppc_init_cacheline_sizes(char **envp)
+{
+ unsigned long *auxv;
+
+ while (*envp++) {
+ }
+
+ for (auxv = (unsigned long *)envp; *auxv != QEMU_AT_NULL; auxv += 2) {
+ switch (*auxv) {
+ 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;
+ }
+ }
+}
+
+#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 };
+
+ len = sizeof(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
+
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+#include <sys/types.h>
+#include <sys/sysctl.h>
+
+static void ppc_init_cacheline_sizes(void)
+{
+ size_t len = 4;
+ unsigned cacheline;
+
+ if (sysctlbyname("machdep.cacheline_size", &cacheline, &len, NULL, 0)) {
+ fprintf(stderr, "sysctlbyname machdep.cacheline_size failed: %s\n",
+ strerror(errno));
+ exit(1);
+ }
+
+ qemu_cache_conf.dcache_bsize = cacheline;
+ qemu_cache_conf.icache_bsize = cacheline;
+}
+#endif
+
+static inline void flush_icache_range(unsigned long start, unsigned long stop)
+{
+ unsigned long p;
+ unsigned long dsize = qemu_cache_conf.dcache_bsize;
+ unsigned long isize = qemu_cache_conf.icache_bsize;
+ unsigned long start1 = start & ~(dsize - 1);
+ unsigned long 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");
+}
+
static uint32_t reloc_pc24_val (void *pc, tcg_target_long target)
{
tcg_target_long disp;
@@ -1681,6 +1788,12 @@ static const TCGTargetOpDef ppc_op_defs[] = {
static void tcg_target_init (TCGContext *s)
{
+#ifdef __linux__
+ ppc_init_cacheline_sizes(envp);
+#else
+ ppc_init_cacheline_sizes();
+#endif
+
tcg_regset_set32 (tcg_target_available_regs[TCG_TYPE_I32], 0, 0xffffffff);
tcg_regset_set32 (tcg_target_available_regs[TCG_TYPE_I64], 0, 0xffffffff);
tcg_regset_set32 (tcg_target_call_clobber_regs, 0,
diff --git a/tcg/tcg.c b/tcg/tcg.c
index 30f3aef..21e737f 100644
--- a/tcg/tcg.c
+++ b/tcg/tcg.c
@@ -46,7 +46,6 @@
#endif
#include "qemu-common.h"
-#include "cache-utils.h"
#include "host-utils.h"
#include "qemu-timer.h"
diff --git a/vl.c b/vl.c
index bd4a5ce..f15995f 100644
--- a/vl.c
+++ b/vl.c
@@ -135,7 +135,6 @@ int main(int argc, char **argv)
#include "gdbstub.h"
#include "qemu-timer.h"
#include "qemu-char.h"
-#include "cache-utils.h"
#include "block.h"
#include "blockdev.h"
#include "block-migration.h"
@@ -2323,8 +2322,6 @@ int main(int argc, char **argv, char **envp)
init_clocks();
- qemu_cache_utils_init(envp);
-
QLIST_INIT (&vm_change_state_head);
os_setup_early_signal_handling();
--
1.7.2.5
- [Qemu-devel] Clean cache related code which was used only by PPC hosts, Stefan Weil, 2011/10/03
- [Qemu-devel] [PATCH 1/2] linux-user: Remove unused code, Stefan Weil, 2011/10/03
- [Qemu-devel] [PATCH 2/2] tcg/ppc*: Move cache initialization to ppc specific code,
Stefan Weil <=
- Re: [Qemu-devel] [Qemu-ppc] [PATCH 2/2] tcg/ppc*: Move cache initialization to ppc specific code, Scott Wood, 2011/10/03
- Re: [Qemu-devel] [Qemu-ppc] [PATCH 2/2] tcg/ppc*: Move cache initialization to ppc specific code, Stefan Weil, 2011/10/03
- Re: [Qemu-devel] [Qemu-ppc] [PATCH 2/2] tcg/ppc*: Move cache initialization to ppc specific code, Alexander Graf, 2011/10/03
- Re: [Qemu-devel] [Qemu-ppc] [PATCH 2/2] tcg/ppc*: Move cache initialization to ppc specific code, Scott Wood, 2011/10/03
- Re: [Qemu-devel] [Qemu-ppc] [PATCH 2/2] tcg/ppc*: Move cache initialization to ppc specific code, Alexander Graf, 2011/10/03
- Re: [Qemu-devel] [Qemu-ppc] [PATCH 2/2] tcg/ppc*: Move cache initialization to ppc specific code, Scott Wood, 2011/10/03
- Re: [Qemu-devel] [Qemu-ppc] [PATCH 2/2] tcg/ppc*: Move cache initialization to ppc specific code, Alexander Graf, 2011/10/03
- Re: [Qemu-devel] [Qemu-ppc] [PATCH 2/2] tcg/ppc*: Move cache initialization to ppc specific code, Scott Wood, 2011/10/03
- Re: [Qemu-devel] [Qemu-ppc] [PATCH 2/2] tcg/ppc*: Move cache initialization to ppc specific code, Alexander Graf, 2011/10/03
- Re: [Qemu-devel] [Qemu-ppc] [PATCH 2/2] tcg/ppc*: Move cache initialization to ppc specific code, Scott Wood, 2011/10/03