From nobody Wed Nov 5 13:32:04 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1497418021217129.68846975208896; Tue, 13 Jun 2017 22:27:01 -0700 (PDT) Received: from localhost ([::1]:46461 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dL0pX-0004x1-NL for importer@patchew.org; Wed, 14 Jun 2017 01:26:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44929) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dL0m0-0001mI-4m for qemu-devel@nongnu.org; Wed, 14 Jun 2017 01:23:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dL0ly-0007K1-LD for qemu-devel@nongnu.org; Wed, 14 Jun 2017 01:23:20 -0400 Received: from mail-qk0-x244.google.com ([2607:f8b0:400d:c09::244]:36499) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dL0ly-0007Js-FK for qemu-devel@nongnu.org; Wed, 14 Jun 2017 01:23:18 -0400 Received: by mail-qk0-x244.google.com with SMTP id r62so6489389qkf.3 for ; Tue, 13 Jun 2017 22:23:18 -0700 (PDT) Received: from bigtime.twiddle.net.com (97-113-165-157.tukw.qwest.net. [97.113.165.157]) by smtp.gmail.com with ESMTPSA id 34sm10959480qtp.17.2017.06.13.22.23.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Jun 2017 22:23:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=mSXsaVTnyhyY7yqMOcq37Usptf55a8CzsMdbHZST7io=; b=tTL/EJBPmARoZcYh038gwt8XxHF0yi3WO3AV4SrLJls4zfvIZ5Za9DVnsM6f8QMkKV GzNBi+yF8YfI5q4UxvdZoQ9HZV1XO1/zjf4Bc1YGxbaxj7khGTuV9EwuX4ugSLjIvTC3 zq4/ng5KFyz3rvyJzHW3ZedagQNxLGQsEPcIcO/eMTPIwtwjyhtAjDmNSO/wjbLSoaVl LoDeFJ8kX/zQq1Em0a+fVzvSETnrpulJvMJitR2Q6woGdmBWBkYQP9FZZY/ZFBc3bv+G hnN07eV06AquY/RNoNvY3PRu6JR0p+WmyGMdkjuEj+Cy5mR9ZY3zRHSa6puMn25gUmOH F5Ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=mSXsaVTnyhyY7yqMOcq37Usptf55a8CzsMdbHZST7io=; b=SeqO1GlEU1zRyQk2M5I4m4P/NZAH+UBtmoMmCsGc2AYixhUi/IXM6oulcYm+NETnzZ BeLQHmHloMnbPRWThA7WPCNn6lWsl9TS5aZLMGOV9re2Q0+0C0xZpEygBAd9E+HsGQKe Du1kL7+uhTE3DZqpKyb6jfvrjyHsqdlSrbty62z4R8+p6St3cZZWrikmoFFjHno4jk59 xscvlxhuYiUhVUMzT1XvvC/ANk3HjhZM4MrkJkMHNRJsqcLJM+f3j9+SWPRQOCsHNnOU eyR0RleplDGiDf8K+2z7XI5bKeHDKnZS3X87n6waFDZ7blMaR1Rd+wCByOzJFWrfcIXx 07zA== X-Gm-Message-State: AKS2vOzGoLkc9qD2GM63IEvwLDQOgmd7DUfBvpf5TXnhcm/lGH+RekSJ n3h9qP1uqp7XwAAJCvM= X-Received: by 10.233.235.145 with SMTP id b139mr4489188qkg.208.1497417797513; Tue, 13 Jun 2017 22:23:17 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 13 Jun 2017 22:23:02 -0700 Message-Id: <20170614052311.13785-2-rth@twiddle.net> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170614052311.13785-1-rth@twiddle.net> References: <20170614052311.13785-1-rth@twiddle.net> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400d:c09::244 Subject: [Qemu-devel] [PULL 01/10] util: add cacheinfo X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, "Emilio G. Cota" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: "Emilio G. Cota" Add helpers to gather cache info from the host at init-time. For now, only export the host's I/D cache line sizes, which we will use to improve cache locality to avoid false sharing. Suggested-by: Richard Henderson Suggested-by: Geert Martin Ijewski Tested-by: Geert Martin Ijewski Signed-off-by: Emilio G. Cota Message-Id: <1496794624-4083-1-git-send-email-cota@braap.org> [rth: Move all implementations from tcg/ppc/] Signed-off-by: Richard Henderson --- include/qemu/osdep.h | 3 + tcg/ppc/tcg-target.inc.c | 71 +----------------- util/Makefile.objs | 1 + util/cacheinfo.c | 185 +++++++++++++++++++++++++++++++++++++++++++= ++++ 4 files changed, 191 insertions(+), 69 deletions(-) create mode 100644 util/cacheinfo.c diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index fb008a2..8559634 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -483,4 +483,7 @@ char *qemu_get_pid_name(pid_t pid); */ pid_t qemu_fork(Error **errp); =20 +extern int qemu_icache_linesize; +extern int qemu_dcache_linesize; + #endif diff --git a/tcg/ppc/tcg-target.inc.c b/tcg/ppc/tcg-target.inc.c index 8d50f18..1f690df 100644 --- a/tcg/ppc/tcg-target.inc.c +++ b/tcg/ppc/tcg-target.inc.c @@ -2820,14 +2820,11 @@ void tcg_register_jit(void *buf, size_t buf_size) } #endif /* __ELF__ */ =20 -static size_t dcache_bsize =3D 16; -static size_t icache_bsize =3D 16; - void flush_icache_range(uintptr_t start, uintptr_t stop) { uintptr_t p, start1, stop1; - size_t dsize =3D dcache_bsize; - size_t isize =3D icache_bsize; + size_t dsize =3D qemu_dcache_linesize; + size_t isize =3D qemu_icache_linesize; =20 start1 =3D start & ~(dsize - 1); stop1 =3D (stop + dsize - 1) & ~(dsize - 1); @@ -2844,67 +2841,3 @@ void flush_icache_range(uintptr_t start, uintptr_t s= top) asm volatile ("sync" : : : "memory"); asm volatile ("isync" : : : "memory"); } - -#if defined _AIX -#include - -static void __attribute__((constructor)) tcg_cache_init(void) -{ - icache_bsize =3D _system_configuration.icache_line; - dcache_bsize =3D _system_configuration.dcache_line; -} - -#elif defined __linux__ -static void __attribute__((constructor)) tcg_cache_init(void) -{ - unsigned long dsize =3D qemu_getauxval(AT_DCACHEBSIZE); - unsigned long isize =3D qemu_getauxval(AT_ICACHEBSIZE); - - if (dsize =3D=3D 0 || isize =3D=3D 0) { - if (dsize =3D=3D 0) { - fprintf(stderr, "getauxval AT_DCACHEBSIZE failed\n"); - } - if (isize =3D=3D 0) { - fprintf(stderr, "getauxval AT_ICACHEBSIZE failed\n"); - } - exit(1); - } - dcache_bsize =3D dsize; - icache_bsize =3D isize; -} - -#elif defined __APPLE__ -#include - -static void __attribute__((constructor)) tcg_cache_init(void) -{ - size_t len; - unsigned cacheline; - int name[2] =3D { CTL_HW, HW_CACHELINE }; - - len =3D sizeof(cacheline); - if (sysctl(name, 2, &cacheline, &len, NULL, 0)) { - perror("sysctl CTL_HW HW_CACHELINE failed"); - exit(1); - } - dcache_bsize =3D cacheline; - icache_bsize =3D cacheline; -} - -#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) -#include - -static void __attribute__((constructor)) tcg_cache_init(void) -{ - size_t len =3D 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); - } - dcache_bsize =3D cacheline; - icache_bsize =3D cacheline; -} -#endif diff --git a/util/Makefile.objs b/util/Makefile.objs index c6205eb..94d9477 100644 --- a/util/Makefile.objs +++ b/util/Makefile.objs @@ -20,6 +20,7 @@ util-obj-y +=3D host-utils.o util-obj-y +=3D bitmap.o bitops.o hbitmap.o util-obj-y +=3D fifo8.o util-obj-y +=3D acl.o +util-obj-y +=3D cacheinfo.o util-obj-y +=3D error.o qemu-error.o util-obj-y +=3D id.o util-obj-y +=3D iov.o qemu-config.o qemu-sockets.o uri.o notify.o diff --git a/util/cacheinfo.c b/util/cacheinfo.c new file mode 100644 index 0000000..f987522 --- /dev/null +++ b/util/cacheinfo.c @@ -0,0 +1,185 @@ +/* + * cacheinfo.c - helpers to query the host about its caches + * + * Copyright (C) 2017, Emilio G. Cota + * License: GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" + +int qemu_icache_linesize =3D 0; +int qemu_dcache_linesize =3D 0; + +/* + * Operating system specific detection mechanisms. + */ + +#if defined(_AIX) +# include + +static void sys_cache_info(int *isize, int *dsize) +{ + *isize =3D _system_configuration.icache_line; + *dsize =3D _system_configuration.dcache_line; +} + +#elif defined(_WIN32) + +static void sys_cache_info(int *isize, int *dsize) +{ + SYSTEM_LOGICAL_PROCESSOR_INFORMATION *buf; + DWORD size =3D 0; + BOOL success; + size_t i, n; + + /* Check for the required buffer size first. Note that if the zero + size we use for the probe results in success, then there is no + data available; fail in that case. */ + success =3D GetLogicalProcessorInformation(0, &size); + if (success || GetLastError() !=3D ERROR_INSUFFICIENT_BUFFER) { + return; + } + + n =3D size / sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION); + size =3D n * sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION); + buf =3D g_new0(SYSTEM_LOGICAL_PROCESSOR_INFORMATION, n); + if (!GetLogicalProcessorInformation(buf, &size)) { + goto fail; + } + + for (i =3D 0; i < n; i++) { + if (buf[i].Relationship =3D=3D RelationCache + && buf[i].Cache.Level =3D=3D 1) { + switch (buf[i].Cache.Type) { + case CacheUnified: + *isize =3D *dsize =3D buf[i].Cache.LineSize; + break; + case CacheInstruction: + *isize =3D buf[i].Cache.LineSize; + break; + case CacheData: + *dsize =3D buf[i].Cache.LineSize; + break; + default: + break; + } + } + } + fail: + g_free(buf); +} + +#elif defined(__APPLE__) \ + || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) +# include +# if defined(__APPLE__) +# define SYSCTL_CACHELINE_NAME "hw.cachelinesize" +# else +# define SYSCTL_CACHELINE_NAME "machdep.cacheline_size" +# endif + +static void sys_cache_info(int *isize, int *dsize) +{ + /* There's only a single sysctl for both I/D cache line sizes. */ + long size; + size_t len =3D sizeof(size); + if (!sysctlbyname(SYSCTL_CACHELINE_NAME, &size, &len, NULL, 0)) { + *isize =3D *dsize =3D size; + } +} + +#else +/* POSIX */ + +static void sys_cache_info(int *isize, int *dsize) +{ +# ifdef _SC_LEVEL1_ICACHE_LINESIZE + *isize =3D sysconf(_SC_LEVEL1_ICACHE_LINESIZE); +# endif +# ifdef _SC_LEVEL1_DCACHE_LINESIZE + *dsize =3D sysconf(_SC_LEVEL1_DCACHE_LINESIZE); +# endif +} +#endif /* sys_cache_info */ + +/* + * Architecture (+ OS) specific detection mechanisms. + */ + +#if defined(__aarch64__) + +static void arch_cache_info(int *isize, int *dsize) +{ + if (*isize =3D=3D 0 || *dsize =3D=3D 0) { + unsigned ctr; + + /* The real cache geometry is in CCSIDR_EL1/CLIDR_EL1/CSSELR_EL1, + but (at least under Linux) these are marked protected by the + kernel. However, CTR_EL0 contains the minimum linesize in the + entire hierarchy, and is used by userspace cache flushing. */ + asm volatile("mrs\t%0, ctr_el0" : "=3Dr"(ctr)); + if (*isize =3D=3D 0) { + *isize =3D 4 << (ctr & 0xf); + } + if (*dsize =3D=3D 0) { + *dsize =3D 4 << ((ctr >> 16) & 0xf); + } + } +} + +#elif defined(_ARCH_PPC) && defined(__linux__) + +static void arch_cache_info(int *isize, int *dsize) +{ + if (*isize =3D=3D 0) { + *isize =3D qemu_getauxval(AT_ICACHEBSIZE); + } + if (*dsize =3D=3D 0) { + *dsize =3D qemu_getauxval(AT_DCACHEBSIZE); + } +} + +#else +static void arch_cache_info(int *isize, int *dsize) { } +#endif /* arch_cache_info */ + +/* + * ... and if all else fails ... + */ + +static void fallback_cache_info(int *isize, int *dsize) +{ + /* If we can only find one of the two, assume they're the same. */ + if (*isize) { + if (*dsize) { + /* Success! */ + } else { + *dsize =3D *isize; + } + } else if (*dsize) { + *isize =3D *dsize; + } else { +#if defined(_ARCH_PPC) + /* For PPC, we're going to use the icache size computed for + flush_icache_range. Which means that we must use the + architecture minimum. */ + *isize =3D *dsize =3D 16; +#else + /* Otherwise, 64 bytes is not uncommon. */ + *isize =3D *dsize =3D 64; +#endif + } +} + +static void __attribute__((constructor)) init_cache_info(void) +{ + int isize =3D 0, dsize =3D 0; + + sys_cache_info(&isize, &dsize); + arch_cache_info(&isize, &dsize); + fallback_cache_info(&isize, &dsize); + + qemu_icache_linesize =3D isize; + qemu_dcache_linesize =3D dsize; +} --=20 2.9.4 From nobody Wed Nov 5 13:32:04 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1497418025304465.6538815001404; Tue, 13 Jun 2017 22:27:05 -0700 (PDT) Received: from localhost ([::1]:46462 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dL0pb-00050P-Ts for importer@patchew.org; Wed, 14 Jun 2017 01:27:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44952) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dL0m1-0001n6-H6 for qemu-devel@nongnu.org; Wed, 14 Jun 2017 01:23:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dL0lz-0007KL-TY for qemu-devel@nongnu.org; Wed, 14 Jun 2017 01:23:21 -0400 Received: from mail-qt0-x242.google.com ([2607:f8b0:400d:c0d::242]:35398) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dL0lz-0007KF-ON for qemu-devel@nongnu.org; Wed, 14 Jun 2017 01:23:19 -0400 Received: by mail-qt0-x242.google.com with SMTP id x58so39039332qtc.2 for ; Tue, 13 Jun 2017 22:23:19 -0700 (PDT) Received: from bigtime.twiddle.net.com (97-113-165-157.tukw.qwest.net. [97.113.165.157]) by smtp.gmail.com with ESMTPSA id 34sm10959480qtp.17.2017.06.13.22.23.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Jun 2017 22:23:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=AsCQswCx954j+sAL1Aci2LW/E9SdgngUR02mJs6IvBM=; b=A0YPB0Tc3659s9V06bwoeIJhf4QmULpdn5Ku8TrprJKOeI/1qmz8YIyGkT8i7k1cSV IbXVE1e+DRJd2anss1y/444ebiMqSihsMvwM92KweZLqteXWjvwqQU3H1wxY+YJSqwvs RP9STxBii1LrJYMas4qAeGod/e02aGGPRX6uUR2Uw5ZmyK2PO2wG8YEbBbOPcjKf0xYC djtI+H5gPx82OP9OtfbLp1jLvRHYmiAdRFb1XZ/mpErQYF8W/shHZ2kTNm0IUNWAQiPz dQz+bzmaZSx1XecLc+EMTSi3l5ydr8gltes+/JfEVBK4dzWg562EZcudiyu1+LyujalX bATA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=AsCQswCx954j+sAL1Aci2LW/E9SdgngUR02mJs6IvBM=; b=p1hejtNP2XUpSd5dJupFhs6QgvNVlUFKLWxwjIK6gMHsLdq5dRgSpvKj2QL8LLsbXN 8HJW69f96ZT5xl0dGC9Q+ybUmo3dtDMHIAeCp68A8Iz+o+9ZD2Nfg5vZvWhLc4JNEi8D DvP8Plvnv1CBCtW0CHwnJJhCjzuVuw8nuiV6nteZZROueqtN5ZTx+FXUOnFKPKV5sJ2w vnzHDP8rLvomylHvBLP7vBxq2Jqlt3lehsEkb2XUQPiCUteD62ZL9aS0AgCEa/PKVTDz bD9dR9sgg7sGyPR2b8lq5OBE/+aX4E6Mw0dO0NmlHOH7fhS8Fk5uvhJLwg4NcVgVfx2/ rOIw== X-Gm-Message-State: AKS2vOzFA6MHHFwJ6z1w/s+7oav+wVgV1CjbTNPyVQBWQPRM3+THDzSc XqNRWSAU/YVRnB+f35Y= X-Received: by 10.200.36.80 with SMTP id d16mr4537139qtd.42.1497417798884; Tue, 13 Jun 2017 22:23:18 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 13 Jun 2017 22:23:03 -0700 Message-Id: <20170614052311.13785-3-rth@twiddle.net> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170614052311.13785-1-rth@twiddle.net> References: <20170614052311.13785-1-rth@twiddle.net> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400d:c0d::242 Subject: [Qemu-devel] [PULL 02/10] tcg: allocate TB structs before the corresponding translated code X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, "Emilio G. Cota" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: "Emilio G. Cota" Allocating an arbitrarily-sized array of tbs results in either (a) a lot of memory wasted or (b) unnecessary flushes of the code cache when we run out of TB structs in the array. An obvious solution would be to just malloc a TB struct when needed, and keep the TB array as an array of pointers (recall that tb_find_pc() needs the TB array to run in O(log n)). Perhaps a better solution, which is implemented in this patch, is to allocate TB's right before the translated code they describe. This results in some memory waste due to padding to have code and TBs in separate cache lines--for instance, I measured 4.7% of padding in the used portion of code_gen_buffer when booting aarch64 Linux on a host with 64-byte cache lines. However, it can allow for optimizations in some host architectures, since TCG backends could safely assume that the TB and the corresponding translated code are very close to each other in memory. See this message by rth for a detailed explanation: https://lists.gnu.org/archive/html/qemu-devel/2017-03/msg05172.html Subject: Re: GSoC 2017 Proposal: TCG performance enhancements Message-ID: <1e67644b-4b30-887e-d329-1848e94c9484@twiddle.net> Suggested-by: Richard Henderson Reviewed-by: Pranith Kumar Signed-off-by: Emilio G. Cota Message-Id: <1496790745-314-3-git-send-email-cota@braap.org> [rth: Simplify the arithmetic in tcg_tb_alloc] Signed-off-by: Richard Henderson --- include/exec/tb-context.h | 3 ++- tcg/tcg.c | 20 ++++++++++++++++++++ tcg/tcg.h | 2 +- translate-all.c | 39 ++++++++++++++++++++++++--------------- 4 files changed, 47 insertions(+), 17 deletions(-) diff --git a/include/exec/tb-context.h b/include/exec/tb-context.h index c7f17f2..25c2afe 100644 --- a/include/exec/tb-context.h +++ b/include/exec/tb-context.h @@ -31,8 +31,9 @@ typedef struct TBContext TBContext; =20 struct TBContext { =20 - TranslationBlock *tbs; + TranslationBlock **tbs; struct qht htable; + size_t tbs_size; int nb_tbs; /* any access to the tbs or the page table must use this lock */ QemuMutex tb_lock; diff --git a/tcg/tcg.c b/tcg/tcg.c index 564292f..3559829 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -383,6 +383,26 @@ void tcg_context_init(TCGContext *s) } } =20 +/* + * Allocate TBs right before their corresponding translated code, making + * sure that TBs and code are on different cache lines. + */ +TranslationBlock *tcg_tb_alloc(TCGContext *s) +{ + uintptr_t align =3D qemu_icache_linesize; + TranslationBlock *tb; + void *next; + + tb =3D (void *)ROUND_UP((uintptr_t)s->code_gen_ptr, align); + next =3D (void *)ROUND_UP((uintptr_t)(tb + 1), align); + + if (unlikely(next > s->code_gen_highwater)) { + return NULL; + } + s->code_gen_ptr =3D next; + return tb; +} + void tcg_prologue_init(TCGContext *s) { size_t prologue_size, total_size; diff --git a/tcg/tcg.h b/tcg/tcg.h index 5ec48d1..9e37722 100644 --- a/tcg/tcg.h +++ b/tcg/tcg.h @@ -697,7 +697,6 @@ struct TCGContext { here, because there's too much arithmetic throughout that relies on addition and subtraction working on bytes. Rely on the GCC extension that allows arithmetic on void*. */ - int code_gen_max_blocks; void *code_gen_prologue; void *code_gen_epilogue; void *code_gen_buffer; @@ -756,6 +755,7 @@ static inline bool tcg_op_buf_full(void) /* tb_lock must be held for tcg_malloc_internal. */ void *tcg_malloc_internal(TCGContext *s, int size); void tcg_pool_reset(TCGContext *s); +TranslationBlock *tcg_tb_alloc(TCGContext *s); =20 void tb_lock(void); void tb_unlock(void); diff --git a/translate-all.c b/translate-all.c index b3ee876..bb094ad 100644 --- a/translate-all.c +++ b/translate-all.c @@ -781,12 +781,13 @@ static inline void code_gen_alloc(size_t tb_size) exit(1); } =20 - /* Estimate a good size for the number of TBs we can support. We - still haven't deducted the prologue from the buffer size here, - but that's minimal and won't affect the estimate much. */ - tcg_ctx.code_gen_max_blocks - =3D tcg_ctx.code_gen_buffer_size / CODE_GEN_AVG_BLOCK_SIZE; - tcg_ctx.tb_ctx.tbs =3D g_new(TranslationBlock, tcg_ctx.code_gen_max_bl= ocks); + /* size this conservatively -- realloc later if needed */ + tcg_ctx.tb_ctx.tbs_size =3D + tcg_ctx.code_gen_buffer_size / CODE_GEN_AVG_BLOCK_SIZE / 8; + if (unlikely(!tcg_ctx.tb_ctx.tbs_size)) { + tcg_ctx.tb_ctx.tbs_size =3D 64 * 1024; + } + tcg_ctx.tb_ctx.tbs =3D g_new(TranslationBlock *, tcg_ctx.tb_ctx.tbs_si= ze); =20 qemu_mutex_init(&tcg_ctx.tb_ctx.tb_lock); } @@ -828,13 +829,20 @@ bool tcg_enabled(void) static TranslationBlock *tb_alloc(target_ulong pc) { TranslationBlock *tb; + TBContext *ctx; =20 assert_tb_locked(); =20 - if (tcg_ctx.tb_ctx.nb_tbs >=3D tcg_ctx.code_gen_max_blocks) { + tb =3D tcg_tb_alloc(&tcg_ctx); + if (unlikely(tb =3D=3D NULL)) { return NULL; } - tb =3D &tcg_ctx.tb_ctx.tbs[tcg_ctx.tb_ctx.nb_tbs++]; + ctx =3D &tcg_ctx.tb_ctx; + if (unlikely(ctx->nb_tbs =3D=3D ctx->tbs_size)) { + ctx->tbs_size *=3D 2; + ctx->tbs =3D g_renew(TranslationBlock *, ctx->tbs, ctx->tbs_size); + } + ctx->tbs[ctx->nb_tbs++] =3D tb; tb->pc =3D pc; tb->cflags =3D 0; tb->invalid =3D false; @@ -850,8 +858,10 @@ void tb_free(TranslationBlock *tb) Ignore the hard cases and just back up if this TB happens to be the last one generated. */ if (tcg_ctx.tb_ctx.nb_tbs > 0 && - tb =3D=3D &tcg_ctx.tb_ctx.tbs[tcg_ctx.tb_ctx.nb_tbs - 1]) { - tcg_ctx.code_gen_ptr =3D tb->tc_ptr; + tb =3D=3D tcg_ctx.tb_ctx.tbs[tcg_ctx.tb_ctx.nb_tbs - 1]) { + size_t struct_size =3D ROUND_UP(sizeof(*tb), qemu_icache_linesize); + + tcg_ctx.code_gen_ptr =3D tb->tc_ptr - struct_size; tcg_ctx.tb_ctx.nb_tbs--; } } @@ -1666,7 +1676,7 @@ static TranslationBlock *tb_find_pc(uintptr_t tc_ptr) m_max =3D tcg_ctx.tb_ctx.nb_tbs - 1; while (m_min <=3D m_max) { m =3D (m_min + m_max) >> 1; - tb =3D &tcg_ctx.tb_ctx.tbs[m]; + tb =3D tcg_ctx.tb_ctx.tbs[m]; v =3D (uintptr_t)tb->tc_ptr; if (v =3D=3D tc_ptr) { return tb; @@ -1676,7 +1686,7 @@ static TranslationBlock *tb_find_pc(uintptr_t tc_ptr) m_min =3D m + 1; } } - return &tcg_ctx.tb_ctx.tbs[m_max]; + return tcg_ctx.tb_ctx.tbs[m_max]; } =20 #if !defined(CONFIG_USER_ONLY) @@ -1874,7 +1884,7 @@ void dump_exec_info(FILE *f, fprintf_function cpu_fpr= intf) direct_jmp_count =3D 0; direct_jmp2_count =3D 0; for (i =3D 0; i < tcg_ctx.tb_ctx.nb_tbs; i++) { - tb =3D &tcg_ctx.tb_ctx.tbs[i]; + tb =3D tcg_ctx.tb_ctx.tbs[i]; target_code_size +=3D tb->size; if (tb->size > max_target_code_size) { max_target_code_size =3D tb->size; @@ -1894,8 +1904,7 @@ void dump_exec_info(FILE *f, fprintf_function cpu_fpr= intf) cpu_fprintf(f, "gen code size %td/%zd\n", tcg_ctx.code_gen_ptr - tcg_ctx.code_gen_buffer, tcg_ctx.code_gen_highwater - tcg_ctx.code_gen_buffer); - cpu_fprintf(f, "TB count %d/%d\n", - tcg_ctx.tb_ctx.nb_tbs, tcg_ctx.code_gen_max_blocks); + cpu_fprintf(f, "TB count %d\n", tcg_ctx.tb_ctx.nb_tbs); cpu_fprintf(f, "TB avg target size %d max=3D%d bytes\n", tcg_ctx.tb_ctx.nb_tbs ? target_code_size / tcg_ctx.tb_ctx.nb_tbs : 0, --=20 2.9.4 From nobody Wed Nov 5 13:32:04 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 149741790130462.7783597384182; Tue, 13 Jun 2017 22:25:01 -0700 (PDT) Received: from localhost ([::1]:46451 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dL0nc-0003MQ-0K for importer@patchew.org; Wed, 14 Jun 2017 01:25:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44959) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dL0m1-0001nO-VP for qemu-devel@nongnu.org; Wed, 14 Jun 2017 01:23:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dL0m1-0007Kn-1S for qemu-devel@nongnu.org; Wed, 14 Jun 2017 01:23:22 -0400 Received: from mail-qt0-x242.google.com ([2607:f8b0:400d:c0d::242]:34130) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dL0m0-0007Kc-Tb for qemu-devel@nongnu.org; Wed, 14 Jun 2017 01:23:20 -0400 Received: by mail-qt0-x242.google.com with SMTP id o21so39043165qtb.1 for ; Tue, 13 Jun 2017 22:23:20 -0700 (PDT) Received: from bigtime.twiddle.net.com (97-113-165-157.tukw.qwest.net. [97.113.165.157]) by smtp.gmail.com with ESMTPSA id 34sm10959480qtp.17.2017.06.13.22.23.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Jun 2017 22:23:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=YWyN5gHo62UjLPOyvnzvpfJTn25ykV5dt8aXb/VMaAY=; b=nETnhCFKSEMa3yt8phDBlWQlTshz1ANVD/rkOFYOgzHaj+BBxhsAn85iC+SBRSd91L yD/Jg2xplTw0cg11Exw7pKFHTbDEPKiXcuIvDmPAeWyT8g7+eJNuUIWvAoc+Cj9z9RKS YY78paIRab7+Z55ZNCTu1y5g0TWYWnGKsZEDMWFythNrgO3EttZFxfHLMlKGFBW+5w0F KJNEa3JAXTcusIxngmwwh75rp92lpjn58lEhn9eBCuIR57JOsrGeesx7cLxnEj/pAqxs nnEKI232u6HIJvo6+4r8WooCfy3JzyjrQ5uf6K7vkW/zQGxD2VVbUo8wnLwxgTZtFf2Z S4Mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=YWyN5gHo62UjLPOyvnzvpfJTn25ykV5dt8aXb/VMaAY=; b=SKAqgpUeQ9O7ahyK5zPIGVxaT+sl/QyQQb5LUnEIuxivBf/kPq9Hzc39x043C8zyVm KXLSkDRwpQN6ke+h67J+2w3fYlcdTJLKG8VkmibM2CGZXqXiBYHmWaNs7zrdMMgxTG17 /vYk66KY14xeqR0J6Zl016t3L7ejat+tlxeb2IWlXtlEu0EsUZg+bs7/vxN7xbFdg6pF o3JH2Hj6BMJdRyhN0f92By24XM18fWZB5q/9vB/l2Y3X3TqPk4GjUUNieZURIj5ZibKC DZTkeiQc3pAfU0uqKsIj3LzSYq3HihmulX6axu6RjfoFYqLKqS47URFps4FjIjhHLJlB PRCw== X-Gm-Message-State: AKS2vOzScv2Y6NeKnRZ5Pk97FzRyIvkmDFW+JyumGfvTEhxKyYSUOLte 3qEd08oxUCVwTYyVVzo= X-Received: by 10.237.34.88 with SMTP id o24mr4695406qtc.217.1497417800268; Tue, 13 Jun 2017 22:23:20 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 13 Jun 2017 22:23:04 -0700 Message-Id: <20170614052311.13785-4-rth@twiddle.net> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170614052311.13785-1-rth@twiddle.net> References: <20170614052311.13785-1-rth@twiddle.net> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400d:c0d::242 Subject: [Qemu-devel] [PULL 03/10] translate-all: consolidate tb init in tb_gen_code X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, "Emilio G. Cota" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: "Emilio G. Cota" We are partially initializing tb in tb_alloc. Instead, fully initialize it in tb_gen_code, which is tb_alloc's only caller. This saves an unnecessary write to tb->cflags. Signed-off-by: Emilio G. Cota Message-Id: <1497038122-26364-1-git-send-email-cota@braap.org> Signed-off-by: Richard Henderson --- translate-all.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/translate-all.c b/translate-all.c index bb094ad..46c5592 100644 --- a/translate-all.c +++ b/translate-all.c @@ -843,9 +843,6 @@ static TranslationBlock *tb_alloc(target_ulong pc) ctx->tbs =3D g_renew(TranslationBlock *, ctx->tbs, ctx->tbs_size); } ctx->tbs[ctx->nb_tbs++] =3D tb; - tb->pc =3D pc; - tb->cflags =3D 0; - tb->invalid =3D false; return tb; } =20 @@ -1289,9 +1286,11 @@ TranslationBlock *tb_gen_code(CPUState *cpu, =20 gen_code_buf =3D tcg_ctx.code_gen_ptr; tb->tc_ptr =3D gen_code_buf; + tb->pc =3D pc; tb->cs_base =3D cs_base; tb->flags =3D flags; tb->cflags =3D cflags; + tb->invalid =3D false; =20 #ifdef CONFIG_PROFILER tcg_ctx.tb_count1++; /* includes aborted translations because of --=20 2.9.4 From nobody Wed Nov 5 13:32:04 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1497418129779729.8316587828674; Tue, 13 Jun 2017 22:28:49 -0700 (PDT) Received: from localhost ([::1]:46467 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dL0rI-00070v-Ah for importer@patchew.org; Wed, 14 Jun 2017 01:28:48 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44976) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dL0m3-0001oR-11 for qemu-devel@nongnu.org; Wed, 14 Jun 2017 01:23:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dL0m2-0007LF-7t for qemu-devel@nongnu.org; Wed, 14 Jun 2017 01:23:23 -0400 Received: from mail-qt0-x243.google.com ([2607:f8b0:400d:c0d::243]:34132) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dL0m2-0007L3-3x for qemu-devel@nongnu.org; Wed, 14 Jun 2017 01:23:22 -0400 Received: by mail-qt0-x243.google.com with SMTP id o21so39043200qtb.1 for ; Tue, 13 Jun 2017 22:23:22 -0700 (PDT) Received: from bigtime.twiddle.net.com (97-113-165-157.tukw.qwest.net. [97.113.165.157]) by smtp.gmail.com with ESMTPSA id 34sm10959480qtp.17.2017.06.13.22.23.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Jun 2017 22:23:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=suOvBjYsdyzgDadyYZ3dijcg+kPPRJEFebrn14pDwhU=; b=k+vaFbfCtqU7Ipvg8X+Nco5iUbU0nfssjFiO15Fm/6AGfZHgtZNfqUi/QPBxbYvCNF VUW0JcgRNdF1u8ap0pLIyOg2C+qA5SL/t/Hq7LDWBct/ltTDyfgUlJ2mRWV1neJ+dBrx w7hT7bcPd9t/AP8wwrtwfRbew3v4pBKSs96SEyO5vf3PvBaLP7KDY6t9HetAuGXNSAmQ SoDkKXYyQmqZ2DlQVHqAx2DnVHimXtgfKAcfSayaP2sgdm8U4CzzcIYa2J78gSsSTWVm FJniCqbzcirdzMsTogd+w3EbQHXarARtYslHaL599s2I6RAZwN5cnLOywwb5QYVGJrAT 7bpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=suOvBjYsdyzgDadyYZ3dijcg+kPPRJEFebrn14pDwhU=; b=pLT1WRouoeHcD4d+TavgWwZqSl6gFtDNoF+FBhAgxPSNVZ6ksnuuBoczMzrgC3/tHH 6pG5DsNHVc+u21C2PHlMAA3sIqT5rU03Zs+RhjqfhlaWp4JAzNTdxVX4zkSAJJvNJ9Jn tH2l8oXjuw0vKIHx2IOGTAHsMT4/1WUb+QV6y969EdGz+rJ0pmu7v6/uglf9FzCGirgJ P6bJ3hFhYtc7VejMLFU/3n1byYs165anNpv8TXLMpVddfWO7l+jOpqu9HLXHP96rm/A2 +Nez6vCCLTKlHK+E5jrtKgb2F3oFuUnAx2hY1zMAvqAWpKbxoY8q4HWUE0M3eqVWGLtC yspg== X-Gm-Message-State: AKS2vOy+t5De3N4IsqWXforxtwzOSMkYRQ1BVFef730pOfbeNIjNfKeo qSepsM+5vN8HaI74h90= X-Received: by 10.200.8.169 with SMTP id v38mr4592888qth.213.1497417801391; Tue, 13 Jun 2017 22:23:21 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 13 Jun 2017 22:23:05 -0700 Message-Id: <20170614052311.13785-5-rth@twiddle.net> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170614052311.13785-1-rth@twiddle.net> References: <20170614052311.13785-1-rth@twiddle.net> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400d:c0d::243 Subject: [Qemu-devel] [PULL 04/10] tcg/aarch64: Use ADR in tcg_out_movi X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The new placement of the TB means that we can use one insn to load the return value for exit_tb returning the TB pointer. Tested-by: Emilio G. Cota Signed-off-by: Richard Henderson --- tcg/aarch64/tcg-target.inc.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tcg/aarch64/tcg-target.inc.c b/tcg/aarch64/tcg-target.inc.c index 5f18545..1fa3bcc 100644 --- a/tcg/aarch64/tcg-target.inc.c +++ b/tcg/aarch64/tcg-target.inc.c @@ -616,7 +616,12 @@ static void tcg_out_movi(TCGContext *s, TCGType type, = TCGReg rd, /* Look for host pointer values within 4G of the PC. This happens often when loading pointers to QEMU's own data structures. */ if (type =3D=3D TCG_TYPE_I64) { - tcg_target_long disp =3D (value >> 12) - ((intptr_t)s->code_ptr >>= 12); + tcg_target_long disp =3D value - (intptr_t)s->code_ptr; + if (disp =3D=3D sextract64(disp, 0, 21)) { + tcg_out_insn(s, 3406, ADR, rd, disp); + return; + } + disp =3D (value >> 12) - ((intptr_t)s->code_ptr >> 12); if (disp =3D=3D sextract64(disp, 0, 21)) { tcg_out_insn(s, 3406, ADRP, rd, disp); if (value & 0xfff) { --=20 2.9.4 From nobody Wed Nov 5 13:32:04 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1497418204524814.4908502040885; Tue, 13 Jun 2017 22:30:04 -0700 (PDT) Received: from localhost ([::1]:46471 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dL0sV-0007nz-6m for importer@patchew.org; Wed, 14 Jun 2017 01:30:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44989) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dL0m4-0001pa-GQ for qemu-devel@nongnu.org; Wed, 14 Jun 2017 01:23:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dL0m3-0007LY-CK for qemu-devel@nongnu.org; Wed, 14 Jun 2017 01:23:24 -0400 Received: from mail-qt0-x243.google.com ([2607:f8b0:400d:c0d::243]:35402) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dL0m3-0007LQ-7r for qemu-devel@nongnu.org; Wed, 14 Jun 2017 01:23:23 -0400 Received: by mail-qt0-x243.google.com with SMTP id x58so39039419qtc.2 for ; Tue, 13 Jun 2017 22:23:23 -0700 (PDT) Received: from bigtime.twiddle.net.com (97-113-165-157.tukw.qwest.net. [97.113.165.157]) by smtp.gmail.com with ESMTPSA id 34sm10959480qtp.17.2017.06.13.22.23.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Jun 2017 22:23:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=v2veKfHhEayApjwYm11wqpDdF+adv8/+qfr6Y9YSduc=; b=ePXKF/b/Oyfct66AyYGPj6wJCo1Q/5MyNEchdAQ6beSPUOaDqQP4hEZle3tXSOsrTb oTzwPBhvLyaL5vFJCWafimuyqe13BMGYsLorBTb99R4+JqZV03Q8j913qWDAzpobNHOC MF5Nh9JPU0QkRVOR5YZ24DX+ppw0ictwlhWeF8zPxQfr8NbFLwDhNleRjAp/CcLTZ7QL 81EhrqCDgNScdWuvztAt5oF5G1fYkBK39wYH0ptzWs6bcPN/GCaee4jXkWiZ0YDArOP9 71bWZEU1eWOoVQ5rZ7X44QQUmSLsFM2M36hgtJ7tJg9vXi3ZqWRZwv4E3EqFgau/HhzQ /UYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=v2veKfHhEayApjwYm11wqpDdF+adv8/+qfr6Y9YSduc=; b=GTabBo0sarRklI2L2zmvLI76DwO0LzDHlKB/3IKTUK5q68dJYZEWn9UeUjL3N3mZLq l/j+b8eXKNUPTEGuk1TVONJLoC8zWo/CM8zy09zIppQftOC72Rcy5+MXB0tkEwN4w4sn FMPzHLuec637jTcrBps8HxXVYKqbtbIp2vPI0J9N5QxMK3e8JITYa3sds9XnXMFY4SPJ bLEviur2S8F82qPSVOm5UQRmcA0kJ7QfdO5gJAbnUPOaqlaGl5P36i5Dj3sFm6hIAm7N obLz2E4Dj8WpxKpe2fQjKg3LCmsHup0wIaCx6XP2lOHJ+VakAs/yUUFwhyN4HnEiO4vx Vdyw== X-Gm-Message-State: AKS2vOwjuPSOrbOlmfc/aT/cVutY/ZQWedpVMJjfbvdUzMORJNL6f6WJ 3kKGNAjq/meWDaNBuVQ= X-Received: by 10.237.37.228 with SMTP id y33mr4459975qtc.140.1497417802632; Tue, 13 Jun 2017 22:23:22 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 13 Jun 2017 22:23:06 -0700 Message-Id: <20170614052311.13785-6-rth@twiddle.net> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170614052311.13785-1-rth@twiddle.net> References: <20170614052311.13785-1-rth@twiddle.net> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400d:c0d::243 Subject: [Qemu-devel] [PULL 05/10] tcg/arm: Use indirect branch for goto_tb X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Richard Henderson --- include/exec/exec-all.h | 5 +---- tcg/arm/tcg-target.inc.c | 17 ++--------------- 2 files changed, 3 insertions(+), 19 deletions(-) diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h index 87ae10b..724ec73 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -301,7 +301,7 @@ static inline void tlb_flush_by_mmuidx_all_cpus_synced(= CPUState *cpu, #define CODE_GEN_AVG_BLOCK_SIZE 150 #endif =20 -#if defined(__arm__) || defined(_ARCH_PPC) \ +#if defined(_ARCH_PPC) \ || defined(__x86_64__) || defined(__i386__) \ || defined(__sparc__) || defined(__aarch64__) \ || defined(__s390x__) || defined(__mips__) \ @@ -401,9 +401,6 @@ static inline void tb_set_jmp_target1(uintptr_t jmp_add= r, uintptr_t addr) #elif defined(__aarch64__) void aarch64_tb_set_jmp_target(uintptr_t jmp_addr, uintptr_t addr); #define tb_set_jmp_target1 aarch64_tb_set_jmp_target -#elif defined(__arm__) -void arm_tb_set_jmp_target(uintptr_t jmp_addr, uintptr_t addr); -#define tb_set_jmp_target1 arm_tb_set_jmp_target #elif defined(__sparc__) || defined(__mips__) void tb_set_jmp_target1(uintptr_t jmp_addr, uintptr_t addr); #else diff --git a/tcg/arm/tcg-target.inc.c b/tcg/arm/tcg-target.inc.c index 9f5cb66..fce382f 100644 --- a/tcg/arm/tcg-target.inc.c +++ b/tcg/arm/tcg-target.inc.c @@ -1026,16 +1026,6 @@ static void tcg_out_call(TCGContext *s, tcg_insn_uni= t *addr) } } =20 -void arm_tb_set_jmp_target(uintptr_t jmp_addr, uintptr_t addr) -{ - tcg_insn_unit *code_ptr =3D (tcg_insn_unit *)jmp_addr; - tcg_insn_unit *target =3D (tcg_insn_unit *)addr; - - /* we could use a ldr pc, [pc, #-4] kind of branch and avoid the flush= */ - reloc_pc24_atomic(code_ptr, target); - flush_icache_range(jmp_addr, jmp_addr + 4); -} - static inline void tcg_out_goto_label(TCGContext *s, int cond, TCGLabel *l) { if (l->has_value) { @@ -1665,11 +1655,8 @@ static inline void tcg_out_op(TCGContext *s, TCGOpco= de opc, } break; case INDEX_op_goto_tb: - if (s->tb_jmp_insn_offset) { - /* Direct jump method */ - s->tb_jmp_insn_offset[args[0]] =3D tcg_current_code_size(s); - tcg_out_b_noaddr(s, COND_AL); - } else { + tcg_debug_assert(s->tb_jmp_insn_offset =3D=3D 0); + { /* Indirect jump method */ intptr_t ptr =3D (intptr_t)(s->tb_jmp_target_addr + args[0]); tcg_out_movi32(s, COND_AL, TCG_REG_R0, ptr & ~0xfff); --=20 2.9.4 From nobody Wed Nov 5 13:32:04 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1497418265941809.0716526926234; Tue, 13 Jun 2017 22:31:05 -0700 (PDT) Received: from localhost ([::1]:46478 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dL0tU-0008Qf-Gp for importer@patchew.org; Wed, 14 Jun 2017 01:31:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45001) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dL0m5-0001qW-HN for qemu-devel@nongnu.org; Wed, 14 Jun 2017 01:23:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dL0m4-0007Lo-No for qemu-devel@nongnu.org; Wed, 14 Jun 2017 01:23:25 -0400 Received: from mail-qt0-x244.google.com ([2607:f8b0:400d:c0d::244]:35962) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dL0m4-0007Le-K6 for qemu-devel@nongnu.org; Wed, 14 Jun 2017 01:23:24 -0400 Received: by mail-qt0-x244.google.com with SMTP id s33so39071450qtg.3 for ; Tue, 13 Jun 2017 22:23:24 -0700 (PDT) Received: from bigtime.twiddle.net.com (97-113-165-157.tukw.qwest.net. [97.113.165.157]) by smtp.gmail.com with ESMTPSA id 34sm10959480qtp.17.2017.06.13.22.23.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Jun 2017 22:23:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=L4u9mOJHRqRlsFhKbPNAX6M4Zf3hr6ReJz90aqEq6WQ=; b=b6nIl7hnZjUoTR2G87Wc9oWbCCuK+bBz6xfVeN5ePYLRtt7PkWbzB+zZ+9PV6w6gNi bImdbQSkxxfRSl8aM6JpKJA5L3ZlNci4BXewYs9efQVvLu6h1vMRRou6bOkUo23vw/Gm UQVPBtxZzD1JMCKvcXD1ehO/ifWpSzyW8cnoyaH2TBO6rW+rEynDK4LyCfgKcd1V13VE hxuWJj32+I1SPy92AmpWK3XmwnJCymtck+49+f7j8Lzh3ttIL/y8qkOXj0kCNBMbnskC 0oxtwZflDewZGRF7zGXXnIlvXP1J9G3iYPjDwgCLSdYb23CsAj5B7BmJCIACVzBnTCF9 squQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=L4u9mOJHRqRlsFhKbPNAX6M4Zf3hr6ReJz90aqEq6WQ=; b=nnGEKCyJjZQxwOqtM0gzlcPooSkSCUGISE+XSoOgikM8PQrYU6uAKgqGiFeGABrZRf Q1SzdfBxBCIFSN2HXbuICufsZtCABmTZirMOxu1s5UFn2Fx1dlhcOupggpMQSYrpl4Im PmrgGaC+ATNfWdJov+UlFg3CtQDugCC8Y+hsa41p3SO+SdyZ8wnuFpA2gTYfc4zTTprL XIKWO89Y+cDC1JhY3RydmMlUxmfDF7M2aQtd9Ml7w4VaDv0G81IT9U/1P9dZIbscIm+S QwRIG0+mmDipMGR77ixRYuPTX7wSEihMnbhxKDTTXsjp7KVQkq1yIET18qmC7m3ot3yi dijA== X-Gm-Message-State: AKS2vOxhJW4mOrzndmg/AKx4MDBhvETZYDP2O2iUgxl7+yp8WoJuoDPh um5OijPNYRi1K4Y0CME= X-Received: by 10.237.43.69 with SMTP id p63mr4698638qtd.200.1497417803866; Tue, 13 Jun 2017 22:23:23 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 13 Jun 2017 22:23:07 -0700 Message-Id: <20170614052311.13785-7-rth@twiddle.net> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170614052311.13785-1-rth@twiddle.net> References: <20170614052311.13785-1-rth@twiddle.net> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400d:c0d::244 Subject: [Qemu-devel] [PULL 06/10] tcg/arm: Remove limit on code buffer size X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Since we're no longer using a direct branch, we have no limit on the branch distance. Signed-off-by: Richard Henderson --- translate-all.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/translate-all.c b/translate-all.c index 46c5592..d4f364d 100644 --- a/translate-all.c +++ b/translate-all.c @@ -523,8 +523,6 @@ static inline PageDesc *page_find(tb_page_addr_t index) # define MAX_CODE_GEN_BUFFER_SIZE (32u * 1024 * 1024) #elif defined(__aarch64__) # define MAX_CODE_GEN_BUFFER_SIZE (128ul * 1024 * 1024) -#elif defined(__arm__) -# define MAX_CODE_GEN_BUFFER_SIZE (16u * 1024 * 1024) #elif defined(__s390x__) /* We have a +- 4GB range on the branches; leave some slop. */ # define MAX_CODE_GEN_BUFFER_SIZE (3ul * 1024 * 1024 * 1024) --=20 2.9.4 From nobody Wed Nov 5 13:32:04 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1497418136056226.76684575686772; Tue, 13 Jun 2017 22:28:56 -0700 (PDT) Received: from localhost ([::1]:46468 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dL0rO-00074p-NT for importer@patchew.org; Wed, 14 Jun 2017 01:28:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45013) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dL0m6-0001s0-N9 for qemu-devel@nongnu.org; Wed, 14 Jun 2017 01:23:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dL0m5-0007M2-S3 for qemu-devel@nongnu.org; Wed, 14 Jun 2017 01:23:26 -0400 Received: from mail-qt0-x244.google.com ([2607:f8b0:400d:c0d::244]:35963) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dL0m5-0007Lu-O6 for qemu-devel@nongnu.org; Wed, 14 Jun 2017 01:23:25 -0400 Received: by mail-qt0-x244.google.com with SMTP id s33so39071479qtg.3 for ; Tue, 13 Jun 2017 22:23:25 -0700 (PDT) Received: from bigtime.twiddle.net.com (97-113-165-157.tukw.qwest.net. [97.113.165.157]) by smtp.gmail.com with ESMTPSA id 34sm10959480qtp.17.2017.06.13.22.23.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Jun 2017 22:23:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=CR+HQBXWwwo3jOjl2EJ5uSCBnAkmH/RpZW4hX9VtpBc=; b=kwO1MbHibdijb16teI1ugH8Qsbs1pNxPv/Kdey4rgsekIiDrNilu+6kK9nzFMh0rj5 lEN4c/6qx/43Vqi3NaWuvALAifjCFXSv54ycvv38pAoUWMgNF9YXhbZ36BasrkxUUbLS HnLOI98wOcwLUTu5A4/tNbTULVjNLOWdVMf3WhSftmwlnarGs/P0H2XdJMx92lmBd+W5 JZFkqkumw02wQGTHHp1Enzo56STVUMv3P2LnSXRQouilRky7XUsiMtFVDbwabhEqzupj aFGwBJvU45nDeRsWLgDPSvheVGhAc33lN0cdRb14Rqm25HjUmvQmXqhskqcGQ5V8p+su AChQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=CR+HQBXWwwo3jOjl2EJ5uSCBnAkmH/RpZW4hX9VtpBc=; b=YE/0XNkDzZslUUvgqdt07wxgAh4mxLzAEcA+Uwfpuo35AmxNewCZPboOJyEV8raugf pxQZrZdmDP6a5R9lZgRF07CM3roXOpJ4I6e8/ea4PqTtdmugkGuBYTIasHDfVPU4LU/Z j+bCHp9UP+DCx5U5D/ZfZpTrWqkscxNcg/iNY90IdQhtRh4XGuzEtHpgBTeMH0p7Yz50 6wU+IBS5DBaLFpVZU5bfkQ/bU269+tRdZ1eXiqU4yR2dhpiAjUp/mZdxTXbRbDWlt8q+ vUUIVuRACTJ4H2UnWyk3UcyCmPjcHKiPv2YXqPjC/2twg+rW/g4LFuehV6onMAYqWGEv no8w== X-Gm-Message-State: AKS2vOzVc6uBI+ioGxmB8Z5F7nV9YNxQ88gaE4LF3rrjJHH14ZXbx8Rd 0gtYbOiLwvRjozsMySY= X-Received: by 10.237.58.164 with SMTP id o33mr4549483qte.134.1497417805088; Tue, 13 Jun 2017 22:23:25 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 13 Jun 2017 22:23:08 -0700 Message-Id: <20170614052311.13785-8-rth@twiddle.net> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170614052311.13785-1-rth@twiddle.net> References: <20170614052311.13785-1-rth@twiddle.net> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400d:c0d::244 Subject: [Qemu-devel] [PULL 07/10] tcg/arm: Try pc-relative addresses for movi X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Richard Henderson --- tcg/arm/tcg-target.inc.c | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/tcg/arm/tcg-target.inc.c b/tcg/arm/tcg-target.inc.c index fce382f..42370e5 100644 --- a/tcg/arm/tcg-target.inc.c +++ b/tcg/arm/tcg-target.inc.c @@ -418,23 +418,37 @@ static inline void tcg_out_dat_imm(TCGContext *s, =20 static void tcg_out_movi32(TCGContext *s, int cond, int rd, uint32_t arg) { - int rot, opc, rn; - - /* For armv7, make sure not to use movw+movt when mov/mvn would do. - Speed things up by only checking when movt would be required. - Prior to armv7, have one go at fully rotated immediates before - doing the decomposition thing below. */ - if (!use_armv7_instructions || (arg & 0xffff0000)) { - rot =3D encode_imm(arg); + int rot, opc, rn, diff; + + /* Check a single MOV/MVN before anything else. */ + rot =3D encode_imm(arg); + if (rot >=3D 0) { + tcg_out_dat_imm(s, cond, ARITH_MOV, rd, 0, + rotl(arg, rot) | (rot << 7)); + return; + } + rot =3D encode_imm(~arg); + if (rot >=3D 0) { + tcg_out_dat_imm(s, cond, ARITH_MVN, rd, 0, + rotl(~arg, rot) | (rot << 7)); + return; + } + + /* Check for a pc-relative address. This will usually be the TB, + or within the TB, which is immediately before the code block. */ + diff =3D arg - ((intptr_t)s->code_ptr + 8); + if (diff >=3D 0) { + rot =3D encode_imm(diff); if (rot >=3D 0) { - tcg_out_dat_imm(s, cond, ARITH_MOV, rd, 0, - rotl(arg, rot) | (rot << 7)); + tcg_out_dat_imm(s, cond, ARITH_ADD, rd, TCG_REG_PC, + rotl(diff, rot) | (rot << 7)); return; } - rot =3D encode_imm(~arg); + } else { + rot =3D encode_imm(-diff); if (rot >=3D 0) { - tcg_out_dat_imm(s, cond, ARITH_MVN, rd, 0, - rotl(~arg, rot) | (rot << 7)); + tcg_out_dat_imm(s, cond, ARITH_SUB, rd, TCG_REG_PC, + rotl(-diff, rot) | (rot << 7)); return; } } --=20 2.9.4 From nobody Wed Nov 5 13:32:04 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1497418333715731.8370153687076; Tue, 13 Jun 2017 22:32:13 -0700 (PDT) Received: from localhost ([::1]:46480 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dL0ua-0000Wg-AV for importer@patchew.org; Wed, 14 Jun 2017 01:32:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45036) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dL0m9-0001u0-VA for qemu-devel@nongnu.org; Wed, 14 Jun 2017 01:23:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dL0m7-0007MO-5G for qemu-devel@nongnu.org; Wed, 14 Jun 2017 01:23:30 -0400 Received: from mail-qt0-x242.google.com ([2607:f8b0:400d:c0d::242]:34135) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dL0m7-0007ME-0k for qemu-devel@nongnu.org; Wed, 14 Jun 2017 01:23:27 -0400 Received: by mail-qt0-x242.google.com with SMTP id o21so39043295qtb.1 for ; Tue, 13 Jun 2017 22:23:26 -0700 (PDT) Received: from bigtime.twiddle.net.com (97-113-165-157.tukw.qwest.net. [97.113.165.157]) by smtp.gmail.com with ESMTPSA id 34sm10959480qtp.17.2017.06.13.22.23.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Jun 2017 22:23:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=0JIyMTWEbgKNU/nXeGzvw+nCv+LbCnygH0rtWYHqaiw=; b=iniXKNOcU7o+09rkD/S88MmLDRrZHpoWaUPajItcryPkBaEo3/ycS0MWuZ3axs/MRR FMTn/2DuQoxhF3XBimm+3+jsfGUSebKNZ71hVxLIU24aRn/xYxidJUWmK2p60N8bAIET WcMZRT4XjmhXWuGWikV50K9CG4tYFQBReBoao48eSJCTHA/0fQXi0Z8i4I1CjDirw6wE Y9Fv9cQIBkqa/j0CFqwKyzeDqj9ikjSgQ7Ma51hL0W/wEu1c3AGvC4Q1tiXUyqDNZnw+ NZY79T6iIppw0JZDn2Am0IL2atc7Dsz2FoytcydiaDRUhLfzCt6/J9A82PuZJ3tADpbJ c+KQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=0JIyMTWEbgKNU/nXeGzvw+nCv+LbCnygH0rtWYHqaiw=; b=Rj58nSF0s6zqNp2Y6077eWXTaL9UGeN9pde7v0cnyf1wyBOqy+y/eaKtQZSVh7CD/7 dqkIuFFc/+6fjkWRlEqLJmus+2Ei9WboOq/M+qXTihXUsdktNB8FPiX5ek3ZPKxJomIZ nmosbOfkCQwUOUOjAgFXTs3BQStIh11y6Br8ptGF1CK9IvRef89omqAwpgXDpXis3D4i PUJdeL7ZSwLAdSqZULO0RCHY93UwV/GwnGuOv4q61G7agcEM4JDdYn9VmvNwBPzw7p0s 7kNk9tzwoyXR4le3pDz1snwPoNH0AV6qdlDjnm7veUPuxibxGl5zGBxtatfBpHJrnlZD x5kg== X-Gm-Message-State: AKS2vOyiql38n7LtKSJsvsjrW9t40GK2J9/iZw466vDkmU8wCpf280TS G+UVJm3pXml+htLLaS8= X-Received: by 10.237.45.3 with SMTP id h3mr4864594qtd.57.1497417806375; Tue, 13 Jun 2017 22:23:26 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 13 Jun 2017 22:23:09 -0700 Message-Id: <20170614052311.13785-9-rth@twiddle.net> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170614052311.13785-1-rth@twiddle.net> References: <20170614052311.13785-1-rth@twiddle.net> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400d:c0d::242 Subject: [Qemu-devel] [PULL 08/10] tcg/arm: Use ldr (literal) for goto_tb X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The new placement of the TB means that we can use one insn to load the goto_tb destination directly from the TB. Signed-off-by: Richard Henderson --- tcg/arm/tcg-target.inc.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/tcg/arm/tcg-target.inc.c b/tcg/arm/tcg-target.inc.c index 42370e5..d1793ec 100644 --- a/tcg/arm/tcg-target.inc.c +++ b/tcg/arm/tcg-target.inc.c @@ -1669,14 +1669,27 @@ static inline void tcg_out_op(TCGContext *s, TCGOpc= ode opc, } break; case INDEX_op_goto_tb: - tcg_debug_assert(s->tb_jmp_insn_offset =3D=3D 0); { /* Indirect jump method */ - intptr_t ptr =3D (intptr_t)(s->tb_jmp_target_addr + args[0]); - tcg_out_movi32(s, COND_AL, TCG_REG_R0, ptr & ~0xfff); - tcg_out_ld32_12(s, COND_AL, TCG_REG_PC, TCG_REG_R0, ptr & 0xff= f); + intptr_t ptr, dif, dil; + TCGReg base =3D TCG_REG_PC; + + tcg_debug_assert(s->tb_jmp_insn_offset =3D=3D 0); + ptr =3D (intptr_t)(s->tb_jmp_target_addr + args[0]); + dif =3D ptr - ((intptr_t)s->code_ptr + 8); + dil =3D sextract32(dif, 0, 12); + if (dif !=3D dil) { + /* The TB is close, but outside the 12 bits addressable by + the load. We can extend this to 20 bits with a sub of a + shifted immediate from pc. In the vastly unlikely event + the code requires more than 1MB, we'll use 2 insns and + be no worse off. */ + base =3D TCG_REG_R0; + tcg_out_movi32(s, COND_AL, base, ptr - dil); + } + tcg_out_ld32_12(s, COND_AL, TCG_REG_PC, base, dil); + s->tb_jmp_reset_offset[args[0]] =3D tcg_current_code_size(s); } - s->tb_jmp_reset_offset[args[0]] =3D tcg_current_code_size(s); break; case INDEX_op_goto_ptr: tcg_out_bx(s, COND_AL, args[0]); --=20 2.9.4 From nobody Wed Nov 5 13:32:04 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1497417933463534.5197237454644; Tue, 13 Jun 2017 22:25:33 -0700 (PDT) Received: from localhost ([::1]:46457 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dL0o7-0003r5-PP for importer@patchew.org; Wed, 14 Jun 2017 01:25:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45038) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dL0m9-0001u1-Vr for qemu-devel@nongnu.org; Wed, 14 Jun 2017 01:23:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dL0m8-0007Mp-F5 for qemu-devel@nongnu.org; Wed, 14 Jun 2017 01:23:30 -0400 Received: from mail-qt0-x242.google.com ([2607:f8b0:400d:c0d::242]:35972) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dL0m8-0007MV-BC for qemu-devel@nongnu.org; Wed, 14 Jun 2017 01:23:28 -0400 Received: by mail-qt0-x242.google.com with SMTP id s33so39071569qtg.3 for ; Tue, 13 Jun 2017 22:23:28 -0700 (PDT) Received: from bigtime.twiddle.net.com (97-113-165-157.tukw.qwest.net. [97.113.165.157]) by smtp.gmail.com with ESMTPSA id 34sm10959480qtp.17.2017.06.13.22.23.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Jun 2017 22:23:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=wiG993Dmr2WbZchGgyycyVU7tmNx7jtBm8MEugdJaTg=; b=Z8APxn5Z3pFbNjRBWf2O4tpWu55TFCKh9VNpXKz/vnWYvA2+WKTobKOm5SAjsa8b6U G2rqRa7wb1xMWFOhgC5cNaqaHJ73cg8M4e+PQVrLInPDceYceUnaXkNYhEKJ4iSU1dEv M9IX4Ew6kx37b6H+PZA6/xyBIqq878bUc9TMiFUQBBkKZ7IaZURI6N63NlFH0+B60vMm QK+qx+QuWu+UltLOw8a6OUjcGiqK9Xomf3UApYfEHtumV2U1OyB6ZhmBIh1m38pMj9jV ct09KrKcXIyp+OiXZwhtBubJ20x9xERD7CIvs/erIijZvEUT+qqQB4dzMOZWFfP4vpgg PQFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=wiG993Dmr2WbZchGgyycyVU7tmNx7jtBm8MEugdJaTg=; b=FI5wh2EKJSyperOI5pbX2RqZ+Bx2envdi5OhTVr1DgiclWxsOmwWguImR6HApEfp4K Bt1wB5wF8mWgcomOEcwgZ1wtxB3eR3N8mGWaugVB8hD4DE+fJhP68wNaRNutLXoVXbSy VvYhsBuiaIHnqFkqE95pW0dbablgQ1ZfSraIasuWH9v6FUWQX5KmWDDMjhhPpVZgpMeX LRUVBNpu7F5f8GDtJf3Drcrj0G/evFF6NK/CsIvVyg8TcdrzgHrQgW508jUoDG8cO8G4 Lw+AwgfBUip6+fizqLykRw5yGdjOVP8bygbpE0DwIxx4z67VVK/GNC1v+3u96C1TcEtg 7LbA== X-Gm-Message-State: AKS2vOwjKq5JPK5a3ogzE73m5H8rRk5E514nXvZ2n3Mb05bBKcbOAWWK hZ83kGJVtRer1SE/FWc= X-Received: by 10.237.52.198 with SMTP id x64mr2108037qtd.210.1497417807709; Tue, 13 Jun 2017 22:23:27 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 13 Jun 2017 22:23:10 -0700 Message-Id: <20170614052311.13785-10-rth@twiddle.net> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170614052311.13785-1-rth@twiddle.net> References: <20170614052311.13785-1-rth@twiddle.net> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400d:c0d::242 Subject: [Qemu-devel] [PULL 09/10] Revert "target/aarch64: optimize indirect branches" X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This reverts commit e75449a346bf558296966a44277bfd93412c6da6. This patch appears to induce lockups, or maybe livelocks, while booting a Linux kernel. The assumption is that there is a bug elsewhere within QEMU, but reverting the patch allows normal work to continue in the meantime. Signed-off-by: Richard Henderson --- target/arm/translate-a64.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c index 860e279..ab61d96 100644 --- a/target/arm/translate-a64.c +++ b/target/arm/translate-a64.c @@ -11367,7 +11367,8 @@ void gen_intermediate_code_a64(ARMCPU *cpu, Transla= tionBlock *tb) gen_a64_set_pc_im(dc->pc); /* fall through */ case DISAS_JUMP: - tcg_gen_lookup_and_goto_ptr(cpu_pc); + /* indicate that the hash table must be used to find the next = TB */ + tcg_gen_exit_tb(0); break; case DISAS_TB_JUMP: case DISAS_EXC: --=20 2.9.4 From nobody Wed Nov 5 13:32:04 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1497418054140114.29539411724875; Tue, 13 Jun 2017 22:27:34 -0700 (PDT) Received: from localhost ([::1]:46463 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dL0q4-0005Rp-Sa for importer@patchew.org; Wed, 14 Jun 2017 01:27:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45053) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dL0mA-0001ud-Ky for qemu-devel@nongnu.org; Wed, 14 Jun 2017 01:23:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dL0m9-0007P3-PP for qemu-devel@nongnu.org; Wed, 14 Jun 2017 01:23:30 -0400 Received: from mail-qt0-x242.google.com ([2607:f8b0:400d:c0d::242]:35973) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dL0m9-0007Om-L4 for qemu-devel@nongnu.org; Wed, 14 Jun 2017 01:23:29 -0400 Received: by mail-qt0-x242.google.com with SMTP id s33so39071596qtg.3 for ; Tue, 13 Jun 2017 22:23:29 -0700 (PDT) Received: from bigtime.twiddle.net.com (97-113-165-157.tukw.qwest.net. [97.113.165.157]) by smtp.gmail.com with ESMTPSA id 34sm10959480qtp.17.2017.06.13.22.23.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Jun 2017 22:23:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=BDeY2Hfy7TzSI98fi+mQOeW9gC39d9J3xKiiNJqZoXM=; b=ueK7r83g84md0/i5dWL8/d1Z6tQ0FSRw4DzaxbJWOlZqVmx3WR6Jp3vay0n4/7z7rE NK5+hpNORuNXdtp59f0TFo5uWKzZn0gsThvdtLpXDsrnC3AvedxYkDsu/gcF47hyVjJu BQv8n3SnUHOBYAmhAcajcWeigRgEwjVEdZqrA3xuh3UtZ4gdwCKxx07RJIiTbZfbLd5u /eyqpo/bqmNojLGv+XoJyQTZgnf2ygMrzpc5W7A/zjKbXWYWjpVDnikeJfR4ps+3A7AF WGl5ZL7g2AA4K6AT7vOvjI9eJUS5y9XVRypR7uQIMeqLmgTkUKXXOI5BkPu0mR77HupA TGoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=BDeY2Hfy7TzSI98fi+mQOeW9gC39d9J3xKiiNJqZoXM=; b=hK4zblN8VhUIS41mAvCd0uo8SFkNZ6YLBtzrDlwxYu0teN3LiF26KruwcH+qxjLV8y 92w1OBjgiguf2CKn9dNJU7REv1jVPfkYUMKvUGJwZIHGzy0JmLE6yS3bQFwffcVEj6ar nX+m11cjqDn9KrzUupEpAtV37ZsQwYaNId1F9c0vL3qzLfQfG9uzbQ7m0/DhxWNpnsvf yPLk8P/bBM7p46n9lIPViHWBYgaGN3+cULPWrNyqyk8wjv9XZv0pd18PFgDOdnWcJh+S vQsKYEdcYT7Y2gtxNkqjvVu1TgYbKRIdsE7CuGGGSwzN19HdEYtkYM+Hy7mCpxdagsid u88g== X-Gm-Message-State: AKS2vOziVzgtJ6gjm7cfLCmCem2mntY/YU/XvI8Lpm/5T66eUHkmiqNT Je6sIxeHerdq5o3615M= X-Received: by 10.200.48.162 with SMTP id v31mr4808602qta.84.1497417809003; Tue, 13 Jun 2017 22:23:29 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 13 Jun 2017 22:23:11 -0700 Message-Id: <20170614052311.13785-11-rth@twiddle.net> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170614052311.13785-1-rth@twiddle.net> References: <20170614052311.13785-1-rth@twiddle.net> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400d:c0d::242 Subject: [Qemu-devel] [PULL 10/10] tcg: Remove tb_htable_lookup from helper_lookup_tb_ptr X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This appears to induce lockups, or maybe livelocks, while booting an Alpha Linux kernel. The assumption is that there is a bug elsewhere within QEMU, but reverting the patch allows normal work to continue in the meantime. Signed-off-by: Richard Henderson --- tcg-runtime.c | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/tcg-runtime.c b/tcg-runtime.c index 7fa90ce..cc3bbaf 100644 --- a/tcg-runtime.c +++ b/tcg-runtime.c @@ -147,30 +147,24 @@ uint64_t HELPER(ctpop_i64)(uint64_t arg) void *HELPER(lookup_tb_ptr)(CPUArchState *env, target_ulong addr) { CPUState *cpu =3D ENV_GET_CPU(env); - TranslationBlock *tb; - target_ulong cs_base, pc; - uint32_t flags; + unsigned int hash =3D tb_jmp_cache_hash_func(addr); + TranslationBlock *tb =3D atomic_rcu_read(&cpu->tb_jmp_cache[hash]); + void *ret =3D tcg_ctx.code_gen_epilogue; =20 - tb =3D atomic_rcu_read(&cpu->tb_jmp_cache[tb_jmp_cache_hash_func(addr)= ]); if (likely(tb)) { + target_ulong cs_base, pc; + uint32_t flags; + cpu_get_tb_cpu_state(env, &pc, &cs_base, &flags); - if (likely(tb->pc =3D=3D addr && tb->cs_base =3D=3D cs_base && - tb->flags =3D=3D flags)) { - goto found; - } - tb =3D tb_htable_lookup(cpu, addr, cs_base, flags); - if (likely(tb)) { - atomic_set(&cpu->tb_jmp_cache[tb_jmp_cache_hash_func(addr)], t= b); - goto found; + if (tb->pc =3D=3D addr && tb->cs_base =3D=3D cs_base && tb->flags = =3D=3D flags) { + ret =3D tb->tc_ptr; + qemu_log_mask_and_addr(CPU_LOG_EXEC, addr, + "Chain %p [%d: " TARGET_FMT_lx "] %s\n", + ret, cpu->cpu_index, addr, + lookup_symbol(addr)); } } - return tcg_ctx.code_gen_epilogue; - found: - qemu_log_mask_and_addr(CPU_LOG_EXEC, addr, - "Chain %p [%d: " TARGET_FMT_lx "] %s\n", - tb->tc_ptr, cpu->cpu_index, addr, - lookup_symbol(addr)); - return tb->tc_ptr; + return ret; } =20 void HELPER(exit_atomic)(CPUArchState *env) --=20 2.9.4