From: Magnus Damm <magnus.damm@gmail.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH] CONFIG_MMU_MAP powerpc host support
Date: Mon, 20 Dec 2004 18:55:21 +0100 [thread overview]
Message-ID: <aec7e5c304122009555c1f820f@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 564 bytes --]
Hello,
This patch adds powerpc host support to the CONFIG_MMU_MAP patch
written by Piotrek. My patch should be applied on top of
v1-part[1-3].patch.gz. I have only tested the code with a x86 guest on
a ppc host running Linux - someone, please test on a host running OSX.
Performance gain reported by nbench:
Memory index: 50%
Integer index: 44%
Fp index: 4%
Right now each map-memory access consists of 5-6 powerpc instructions.
If a direct pointer to mem_map could be kept in a register then we
would be down to 3-4 instructions per memoy access...
/ magnus
[-- Attachment #2: qemu-mmap_20041217-ppc.patch --]
[-- Type: application/octet-stream, Size: 5338 bytes --]
diff -urN qemu-mmap_20041217/configure qemu-mmap_20041217-ppc/configure
--- qemu-mmap_20041217/configure 2004-12-19 00:01:12.000000000 +0100
+++ qemu-mmap_20041217-ppc/configure 2004-12-19 00:20:59.000000000 +0100
@@ -547,6 +547,10 @@
echo "CONFIG_MMU_MAP=yes" >> $config_mak
echo "#define CONFIG_MMU_MAP 1" >> $config_h
fi
+if test "$target_softmmu" = "yes" -a "$target_cpu" = "i386" -a "$cpu" = "powerpc" ; then
+ echo "CONFIG_MMU_MAP=yes" >> $config_mak
+ echo "#define CONFIG_MMU_MAP 1" >> $config_h
+fi
if test "$target_user_only" = "yes" ; then
echo "CONFIG_USER_ONLY=yes" >> $config_mak
echo "#define CONFIG_USER_ONLY 1" >> $config_h
diff -urN qemu-mmap_20041217/mmu_map.h qemu-mmap_20041217-ppc/mmu_map.h
--- qemu-mmap_20041217/mmu_map.h 2004-12-19 00:01:12.000000000 +0100
+++ qemu-mmap_20041217-ppc/mmu_map.h 2004-12-20 12:54:38.000000000 +0100
@@ -132,5 +132,44 @@
}
#else
+#if defined(__powerpc__)
+
+#ifdef linux
+#define R3 uc->uc_mcontext.regs->gpr[3]
+#endif
+
+#ifdef __APPLE__
+#include <sys/ucontext.h>
+#define R3 uc->uc_mcontext->ss.r3
+#endif
+
+#ifndef R3
+#error unsupported host operating system
+#endif
+
+static inline target_ulong mmu_map_fault_get_vaddr(ucontext_t *uc,
+ unsigned long addr)
+{
+ target_ulong vaddr;
+
+ vaddr = addr - R3;
+ return vaddr;
+}
+
+static inline void mmu_map_fault_update_uc(ucontext_t *uc, MmuMap *map,
+ unsigned long vaddr, int is_write)
+{
+ target_ulong vpage;
+
+ vpage = vaddr >> TARGET_PAGE_BITS;
+ if (is_write) {
+ R3 = map->add_write[vpage];
+ } else {
+ R3 = map->add_read[vpage];
+ }
+}
+
+#else
#error unsupported host CPU
#endif
+#endif
diff -urN qemu-mmap_20041217/mmu_map_templ.h qemu-mmap_20041217-ppc/mmu_map_templ.h
--- qemu-mmap_20041217/mmu_map_templ.h 2004-12-19 00:01:12.000000000 +0100
+++ qemu-mmap_20041217-ppc/mmu_map_templ.h 2004-12-20 18:23:40.000000000 +0100
@@ -125,9 +125,145 @@
}
#else
-#error unsupported host CPU
+#if defined(__powerpc__)
+
+/* this code assumes that the host ppc is running in big endian mode */
+
+#ifdef TARGET_I386
+#define ENDIAN_SWAP
+#endif
+
+#if 0
+ /* slow lookup, first shift right, then left */
+ "rlwinm 3, %1, 32 - %2, %2, 31\n"
+ "addis 4, %3, %4@ha\n"
+ "rlwinm 3, 3, 2, 0, 31 - 2\n"
+ "addi 4, 4, %4@l\n"
+ "lwzx 3, 4, 3\n"
+
+ /* current lookup, one shift and mask operation */
+ "addis 4, %3, %4@ha\n"
+ "rlwinm 3, %1, 32 - (%2 - 2), (%2 - 2), 31 - 2\n"
+ "addi 4, 4, %4@l\n"
+ "lwzx 3, 4, 3\n"
+
+ /* better lookup, one shift and mask operation, mmu_map in register */
+ "rlwinm 3, %1, 32 - (%2 - 2), (%2 - 2), 31 - 2\n"
+ "lwzx 3, %3, 3\n"
+#endif
+
+static inline RES_TYPE glue(glue(ld, USUFFIX), MEMSUFFIX)(void *ptr)
+{
+ RES_TYPE val;
+
+ asm volatile (
+ "addis 4, %3, %4@ha\n"
+ "rlwinm 3, %1, 32 - (%2 - 2), (%2 - 2), 31 - 2\n"
+ "addi 4, 4, %4@l\n"
+ "lwzx 3, 4, 3\n"
+
+#if DATA_SIZE == 1
+ "lbzx %0, %1, 3\n"
+#elif DATA_SIZE == 2
+#ifdef ENDIAN_SWAP
+ "lhbrx %0, %1, 3\n"
+#else
+ "lhzx %0, %1, 3\n"
+#endif
+#elif DATA_SIZE == 4
+#ifdef ENDIAN_SWAP
+ "lwbrx %0, %1, 3\n"
+#else
+ "lwzx %0, %1, 3\n"
#endif
+#else
+#error unsupported size
+#endif
+ : "=r" (val)
+ : "r" (ptr),
+ "I" (TARGET_PAGE_BITS),
+ "r" (env),
+ "i" (offsetof(CPUState, mmu_map[CPU_MEM_INDEX].add_read))
+ : "%r3", "%r4", "memory");
+ return val;
+}
+
+#if DATA_SIZE <= 2
+static inline int glue(glue(lds, SUFFIX), MEMSUFFIX)(void *ptr)
+{
+ int val;
+
+ asm volatile (
+ "addis 4, %3, %4@ha\n"
+ "rlwinm 3, %1, 32 - (%2 - 2), (%2 - 2), 31 - 2\n"
+ "addi 4, 4, %4@l\n"
+ "lwzx 3, 4, 3\n"
+
+#if DATA_SIZE == 1
+ "lbzx 4, %1, 3\n"
+ "extsb %0, 4\n"
+#elif DATA_SIZE == 2
+#ifdef ENDIAN_SWAP
+ "lhbrx 4, %1, 3\n"
+ "extsh %0, 4\n"
+#else
+ "lhax %0, %1, 3\n"
+#endif
+#else
+#error unsupported size
+#endif
+ : "=r" (val)
+ : "r" (ptr),
+ "I" (TARGET_PAGE_BITS),
+ "r" (env),
+ "i" (offsetof(CPUState, mmu_map[CPU_MEM_INDEX].add_read))
+ : "%r3", "%r4", "memory");
+
+ return val;
+}
+#endif
+
+static inline void glue(glue(st, SUFFIX), MEMSUFFIX)(void *ptr, RES_TYPE val)
+{
+
+ asm volatile (
+ "addis 4, %3, %4@ha\n"
+ "rlwinm 3, %1, 32 - (%2 - 2), (%2 - 2), 31 - 2\n"
+ "addi 4, 4, %4@l\n"
+ "lwzx 3, 4, 3\n"
+
+#if DATA_SIZE == 1
+ "stbx %0, %1, 3\n"
+#elif DATA_SIZE == 2
+#ifdef ENDIAN_SWAP
+ "sthbrx %0, %1, 3\n"
+#else
+ "sthx %0, %1, 3\n"
+#endif
+#elif DATA_SIZE == 4
+#ifdef ENDIAN_SWAP
+ "stwbrx %0, %1, 3\n"
+#else
+ "stwx %0, %1, 3\n"
+#endif
+#else
+#error unsupported size
+#endif
+ :
+ : "r" (val),
+ "r" (ptr),
+ "I" (TARGET_PAGE_BITS),
+ "r" (env),
+ "i" (offsetof(CPUState, mmu_map[CPU_MEM_INDEX].add_write))
+ : "%r3", "%r4", "memory");
+
+}
+
+#else
+#error unsupported host CPU
+#endif
+#endif
#undef RES_TYPE
#undef DATA_TYPE
next reply other threads:[~2004-12-20 18:32 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-12-20 17:55 Magnus Damm [this message]
2004-12-20 21:31 ` [Qemu-devel] Re: [PATCH] CONFIG_MMU_MAP powerpc host support Piotras
2004-12-20 22:12 ` Magnus Damm
2004-12-20 22:56 ` Daniel Serpell
2004-12-20 23:11 ` Fabrice Bellard
2004-12-25 0:04 ` [Qemu-devel] " Laurent Amon
2004-12-25 13:48 ` Norikatsu Shigemura
2004-12-27 16:06 ` Laurent Amon
2004-12-27 21:41 ` Pierre d'Herbemont
2004-12-27 23:43 ` Laurent Amon
2004-12-28 9:15 ` Daniel Egger
2004-12-28 9:55 ` Pierre d'Herbemont
2004-12-28 10:04 ` Daniel Egger
2004-12-28 11:18 ` Pierre d'Herbemont
2004-12-29 11:43 ` Piotras
2005-01-02 18:26 ` Daniel Egger
2005-01-02 20:18 ` Laurent Amon
2005-01-03 10:31 ` Daniel Egger
2005-01-03 12:08 ` Laurent Amon
2005-01-03 12:57 ` Daniel Egger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aec7e5c304122009555c1f820f@mail.gmail.com \
--to=magnus.damm@gmail.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).