From patchwork Mon Oct 3 20:43:20 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Weil X-Patchwork-Id: 117504 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 73BA9B6F7D for ; Tue, 4 Oct 2011 07:45:32 +1100 (EST) Received: from localhost ([::1]:46303 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RApO8-0006qA-DV for incoming@patchwork.ozlabs.org; Mon, 03 Oct 2011 16:45:24 -0400 Received: from eggs.gnu.org ([140.186.70.92]:43895) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RApNa-0005Vl-VR for qemu-devel@nongnu.org; Mon, 03 Oct 2011 16:44:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RApNZ-0001uL-27 for qemu-devel@nongnu.org; Mon, 03 Oct 2011 16:44:50 -0400 Received: from v220110690675601.yourvserver.net ([78.47.199.172]:55350) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RApNY-0001uH-KH; Mon, 03 Oct 2011 16:44:48 -0400 Received: from localhost (v220110690675601.yourvserver.net.local [127.0.0.1]) by v220110690675601.yourvserver.net (Postfix) with ESMTP id 2F7AF728327E; Mon, 3 Oct 2011 22:44:38 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at weilnetz.de Received: from v220110690675601.yourvserver.net ([127.0.0.1]) by localhost (v220110690675601.yourvserver.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 14NLdIGq7DSR; Mon, 3 Oct 2011 22:44:17 +0200 (CEST) Received: from flocke.weilnetz.de (p5086F1F7.dip.t-dialin.net [80.134.241.247]) by v220110690675601.yourvserver.net (Postfix) with ESMTPSA id 3CB487283280; Mon, 3 Oct 2011 22:44:01 +0200 (CEST) Received: from stefan by flocke.weilnetz.de with local (Exim 4.72) (envelope-from ) id 1RApMc-0004ys-Ef; Mon, 03 Oct 2011 22:43:50 +0200 From: Stefan Weil To: QEMU Developers Date: Mon, 3 Oct 2011 22:43:20 +0200 Message-Id: <1317674600-19083-3-git-send-email-sw@weilnetz.de> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1317674600-19083-1-git-send-email-sw@weilnetz.de> References: <1317674600-19083-1-git-send-email-sw@weilnetz.de> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 78.47.199.172 Cc: Stefan Weil , qemu-ppc@nongnu.org, Alexander Graf Subject: [Qemu-devel] [PATCH 2/2] tcg/ppc*: Move cache initialization to ppc specific code X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- 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 - -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 -#include -#include - -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 -#include -#include -#include -#include -#include - -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 + +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 +#include + +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 +#include + +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 + +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 +#include + +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 +#include + +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();