From nobody Wed Nov 5 15:52:46 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 1496851059364788.1477288598802; Wed, 7 Jun 2017 08:57:39 -0700 (PDT) Received: from localhost ([::1]:44786 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIdKy-0001l7-QK for importer@patchew.org; Wed, 07 Jun 2017 11:57:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48424) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIdJL-0000ZD-If for qemu-devel@nongnu.org; Wed, 07 Jun 2017 11:55:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dIdJJ-0005Yq-3O for qemu-devel@nongnu.org; Wed, 07 Jun 2017 11:55:55 -0400 Received: from mail-qt0-x244.google.com ([2607:f8b0:400d:c0d::244]:36145) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dIdJI-0005Yj-U3 for qemu-devel@nongnu.org; Wed, 07 Jun 2017 11:55:53 -0400 Received: by mail-qt0-x244.google.com with SMTP id s33so1989851qtg.3 for ; Wed, 07 Jun 2017 08:55:52 -0700 (PDT) Received: from bigtime.twiddle.net.com (184-217-116-168.pools.spcsdns.net. [184.217.116.168]) by smtp.gmail.com with ESMTPSA id i28sm1272525qta.52.2017.06.07.08.55.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Jun 2017 08:55:51 -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=amvS1ivjZuFYPZtmgdCrw9JjiDMzqeQAqsFSZnbqlMM=; b=YS6km1luQOeriLuJ0FP7iFF2z8QgUl4BRJbumDIKK2UPGSKbcG6ee+fZ2cxDt1iSOX D9/r18Xdev9zGR0cM2ZKOwIeL2P83HYHkeiH2QCcatALqb/itX5u5Rw9cQ6TNCcOYlOW JuinkiMI/UxO9ao468ZdvrpSJMhVz4zz/cDdpUXS87WBM/D8IEUxtviK3K7woGKUfNz/ CFQtwwJtrIVuh2XrjNG6Vsh3sGVQLlykW1TnNDCEKJwM/kj43Cla4MOzpjVGXdC2Di3p xmkVxQX6CTNsihiVrtJPkTMrXr2djALb6Ogz1Gt1W9/ISBel4+rSsiMLmLSsrGfwbysX CWmA== 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=amvS1ivjZuFYPZtmgdCrw9JjiDMzqeQAqsFSZnbqlMM=; b=RwFqSyAaj3XPVT1YjoM/KehLMRk8Qo+oI9sJRMWpjT6/buNRhXA2DInwH6py+5fs6+ 9n7AyadZgIYl6GK1sXZDW3PHRtWjJM+Ln4RK6xVSpfnXaTHnxsKhiagbdUD6PpvaUEoS LGrgQ0ieZAUdJI2QC/jJGfcAnggkSrnnv5i7G7BbJ7/QnYOhsgkWwjBB/YnFk/UIvhfe Z1R9jB7b6j9xhKjEwlu8TrVEW3yogQYuZo+Q3/cFWr5Rx4t0kTh0nskTY9DL2z4N6Ovu hshmbkXrHU3yhnUsybml9IqEdo4cB6jxXIsVWbfiFx+RsKOGOst6lb2G8WjTFpECqdq+ IELQ== X-Gm-Message-State: AODbwcDynkVhtm6/eOO/yivA4xx98Hbng4YeDoO6yT4BwrJ3aKl04U3M zKQmQPciHpJ/9xk2C+s= X-Received: by 10.200.0.153 with SMTP id c25mr37964648qtg.28.1496850951909; Wed, 07 Jun 2017 08:55:51 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 7 Jun 2017 08:55:30 -0700 Message-Id: <20170607155536.1193-2-rth@twiddle.net> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170607155536.1193-1-rth@twiddle.net> References: <20170607155536.1193-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] [PATCH v4 1/7] 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: cota@braap.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" 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 | 174 +++++++++++++++++++++++++++++++++++++++++++= ++++ 4 files changed, 180 insertions(+), 69 deletions(-) create mode 100644 util/cacheinfo.c diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index 1c9f5e2..ee43521 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -470,4 +470,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..0238ca6 --- /dev/null +++ b/util/cacheinfo.c @@ -0,0 +1,174 @@ +/* + * 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; + +#if defined(_AIX) +# include + +static void sys_cache_info(void) +{ + qemu_icache_linesize =3D _system_configuration.icache_line; + qemu_dcache_linesize =3D _system_configuration.dcache_line; +} + +#elif defined(_WIN32) + +static void sys_cache_info(void) +{ + 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: + qemu_icache_linesize =3D buf[i].Cache.LineSize; + qemu_dcache_linesize =3D buf[i].Cache.LineSize; + break; + case CacheInstruction: + qemu_icache_linesize =3D buf[i].Cache.LineSize; + break; + case CacheData: + qemu_dcache_linesize =3D buf[i].Cache.LineSize; + 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(void) +{ + /* There's only a single sysctl for both I/D cache line sizes. */ + size_t len =3D sizeof(qemu_icache_linesize); + if (!sysctlbyname(SYSCTL_CACHELINE_NAME, &qemu_icache_linesize, + &len, NULL, 0)) { + qemu_dcache_linesize =3D qemu_icache_linesize; + } +} + +#else +/* POSIX, with extra Linux ifdefs. */ + +static int icache_info(void) +{ +# ifdef _SC_LEVEL1_ICACHE_LINESIZE + { + long x =3D sysconf(_SC_LEVEL1_ICACHE_LINESIZE); + if (x > 0) { + return x; + } + } +# endif +# ifdef AT_ICACHEBSIZE + /* glibc does not always export this through sysconf, e.g. on PPC */ + { + unsigned long x =3D qemu_getauxval(AT_ICACHEBSIZE); + if (x > 0) { + return x; + } + } +# endif + return 0; +} + +/* Similarly for the D cache. */ +static int dcache_info(void) +{ +# ifdef _SC_LEVEL1_DCACHE_LINESIZE + { + long x =3D sysconf(_SC_LEVEL1_DCACHE_LINESIZE); + if (x > 0) { + return x; + } + } +# endif +# ifdef AT_DCACHEBSIZE + { + unsigned long x =3D qemu_getauxval(AT_DCACHEBSIZE); + if (x > 0) { + return x; + } + } +# endif + return 0; +} + +static void sys_cache_info(void) +{ + qemu_icache_linesize =3D icache_info(); + qemu_dcache_linesize =3D dcache_info(); +} +#endif + +static void __attribute__((constructor)) init_cache_info(void) +{ + int isize, dsize; + + sys_cache_info(); + + isize =3D qemu_icache_linesize; + dsize =3D qemu_dcache_linesize; + + /* If we can only find one of the two, assume they're the same. */ + if (isize) { + if (dsize) { + /* Success! */ + return; + } 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 + } + + qemu_icache_linesize =3D isize; + qemu_dcache_linesize =3D dsize; +} --=20 2.9.4 From nobody Wed Nov 5 15:52:46 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 1496851060190108.69369572066375; Wed, 7 Jun 2017 08:57:40 -0700 (PDT) Received: from localhost ([::1]:44787 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIdL0-0001mk-FG for importer@patchew.org; Wed, 07 Jun 2017 11:57:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48453) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIdJM-0000aA-U7 for qemu-devel@nongnu.org; Wed, 07 Jun 2017 11:55:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dIdJL-0005ZM-7N for qemu-devel@nongnu.org; Wed, 07 Jun 2017 11:55:56 -0400 Received: from mail-qt0-x244.google.com ([2607:f8b0:400d:c0d::244]:33153) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dIdJL-0005Z9-0S for qemu-devel@nongnu.org; Wed, 07 Jun 2017 11:55:55 -0400 Received: by mail-qt0-x244.google.com with SMTP id w1so1992628qtg.0 for ; Wed, 07 Jun 2017 08:55:54 -0700 (PDT) Received: from bigtime.twiddle.net.com (184-217-116-168.pools.spcsdns.net. [184.217.116.168]) by smtp.gmail.com with ESMTPSA id i28sm1272525qta.52.2017.06.07.08.55.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Jun 2017 08:55:53 -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=MhxASwUZMqH4MhX/H5XzIE5waEQUp966mGXCnW8knF5oZaXLmtxgbAA8p5T4ZSzuJ0 EYI1OfmXdVp5218EnYttH/8gpDlsLypMx7VWgYZRkkjVNnFN3Fmg1CCAVZlE+iDK0r9R gBu9DzAkmunRDgZYgERc2axhJxvI+ylQ085vEzKuVqk7NqmtIdwWN4ZlXRGa32QDXujx Rey+TT6VM0R0jWX63Ds2aakJ0t6UcRfhRLoqKhw5SyQMHCHHJRi5oVTeUlWy8Uq4eZPQ 4EjaG1g9Pg+RqzLOYZaPsX8fDbd9ZwXC5f4IfY20iUhzCX0HNZgzD3CzlQ1MPH0dsjN9 2I3A== 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=dbP5AgSURSa0UXrVTWxYWbnZ4EFahNAUEyr9ymBEM3e3YxshTjuvA9sUx2+TXOCXpc Pn4Hv5v+xlKyUDsmRRnv3wowPR2QiTRyLO/O4lhBjBRVXwcPVL0juOldF5xNK2we+VtI xkTq9JQk7i9E25pkh0RsnD2AvS/Xw5z2kqOhOZdwxkuqaWXwQ5GlqzxiapuuhwoO1/yT h+f5dv6Cq19y25PeVYbJcoYHeCUGLFsq2UGSO5ZSgF2/UTyDcA4EYmGnZ5Exx6EXPVOy qLClASwibNAveHFJiDX8CKzcSwni3mNdra24j4vNWwxTj4SNtgsl8goCye052YZRGZab zEMg== X-Gm-Message-State: AODbwcAHOt/1tpNNGHiu9yGlMI89Ec8JoT004fKPfMMPKxDo5NPR2VNi /DzS56WQ+c0WPtJGGf8= X-Received: by 10.200.40.251 with SMTP id j56mr12366473qtj.186.1496850954150; Wed, 07 Jun 2017 08:55:54 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 7 Jun 2017 08:55:31 -0700 Message-Id: <20170607155536.1193-3-rth@twiddle.net> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170607155536.1193-1-rth@twiddle.net> References: <20170607155536.1193-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] [PATCH v4 2/7] 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: cota@braap.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" 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 15:52:46 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 1496851197232295.41626035990237; Wed, 7 Jun 2017 08:59:57 -0700 (PDT) Received: from localhost ([::1]:44796 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIdND-0003vJ-IN for importer@patchew.org; Wed, 07 Jun 2017 11:59:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48473) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIdJP-0000bK-3U for qemu-devel@nongnu.org; Wed, 07 Jun 2017 11:55:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dIdJN-0005aD-Ic for qemu-devel@nongnu.org; Wed, 07 Jun 2017 11:55:58 -0400 Received: from mail-qt0-x233.google.com ([2607:f8b0:400d:c0d::233]:33659) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dIdJN-0005a4-AC for qemu-devel@nongnu.org; Wed, 07 Jun 2017 11:55:57 -0400 Received: by mail-qt0-x233.google.com with SMTP id u12so10820666qth.0 for ; Wed, 07 Jun 2017 08:55:57 -0700 (PDT) Received: from bigtime.twiddle.net.com (184-217-116-168.pools.spcsdns.net. [184.217.116.168]) by smtp.gmail.com with ESMTPSA id i28sm1272525qta.52.2017.06.07.08.55.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Jun 2017 08:55:55 -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=K8HMCHx5zRvV1zQsB/GwCPAD9XZBUB9eJudAQ/eqQRc=; b=gBiB3JqFz70u30Uf2YQcegsqwTsJNSzuuGF6B4yK03H/F4liSEueexplCXd29mv/82 CVeYk/Fdpcz4pbP2YN+B1FTL7HPFyMJooVeUMTkedVCbC94qFhAz/CgrMnahuOC/p2W/ AapMoqgRWTz0j3xI5JtSB9MYWJkNS9ojaEgytkKCgt6Mm/SoF03z7aUF6BTT6tXZZHb7 133kABlXrK/5mpc4NBTrcfhQVqxv8KXos3Hcv6+3d+kgtmllc2yJMpIh4s5tmcsYBF2Y 1EjPJ3DY55YGJumrSpBlBc37wC7tOwyV9pTfk+Xmr8qkRoR4TQbYuvwncuMt64r9jBxg zzoQ== 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=K8HMCHx5zRvV1zQsB/GwCPAD9XZBUB9eJudAQ/eqQRc=; b=nk72J/mJAxs3mAjYeoDtdkG3AnyADEjac0HdaMgxClnbzdlbucjU04ddO6zInVIAhJ bfcvjesO3D9U1pt+8nZV6Ic5zRy6mxsd5HJU8BiXSiz+BgXx5nYUVjY9l3Wlq30xZuh9 e+A6NS2K+NFXbTCLA74dbHFQ9DYcMPQWtBJomYlpeD292w1TxUJPmAAfKrwF7QBBY1N8 T39S2B2qEfW0/s0ooqxdqAyXe2lDXRzzzkwFbQaigLUvbOwysEH7grzXsurOecVRDJdo yEy0NQmXb9svFJU1t1PKPeUwggvSaZ2Cflc9ESRCfLtDYhu6qB4A+j4IEtUmc1JdYxWC LFlQ== X-Gm-Message-State: AKS2vOxCxDNYrTXAZsrpZsdlMeDqcl3Pehy03V0AYMOk0Zusc67+YPMx 2f5VHBT70mnwu7EY9IE= X-Received: by 10.55.75.20 with SMTP id y20mr4673668qka.2.1496850956429; Wed, 07 Jun 2017 08:55:56 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 7 Jun 2017 08:55:32 -0700 Message-Id: <20170607155536.1193-4-rth@twiddle.net> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170607155536.1193-1-rth@twiddle.net> References: <20170607155536.1193-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::233 Subject: [Qemu-devel] [PATCH v4 3/7] 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: cota@braap.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. --- 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 15:52:46 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 1496851092384116.53053626613985; Wed, 7 Jun 2017 08:58:12 -0700 (PDT) Received: from localhost ([::1]:44788 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIdLW-0002J1-Ro for importer@patchew.org; Wed, 07 Jun 2017 11:58:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48493) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIdJQ-0000eN-QC for qemu-devel@nongnu.org; Wed, 07 Jun 2017 11:56:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dIdJP-0005cC-QG for qemu-devel@nongnu.org; Wed, 07 Jun 2017 11:56:00 -0400 Received: from mail-qt0-x243.google.com ([2607:f8b0:400d:c0d::243]:36155) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dIdJP-0005b9-JP for qemu-devel@nongnu.org; Wed, 07 Jun 2017 11:55:59 -0400 Received: by mail-qt0-x243.google.com with SMTP id s33so1990432qtg.3 for ; Wed, 07 Jun 2017 08:55:59 -0700 (PDT) Received: from bigtime.twiddle.net.com (184-217-116-168.pools.spcsdns.net. [184.217.116.168]) by smtp.gmail.com with ESMTPSA id i28sm1272525qta.52.2017.06.07.08.55.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Jun 2017 08:55:58 -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=vFgeln4HDqp4PQg1TDRM9uRCvpCrxo1FaeXd5IThhd3dPfulNiAioYCnoKOG9ome6m yTLXwCmYmjILdBjSJhJhk+Y2sXa2YQImKHD1IR8PL24wlLxsC6zrY1FLylh2yVXVje++ w09y8JjibOAJ3sMz0CEVWOj09fqhjTx6ZyD+RBxOp9tyJK8rZjWjmV7ZZarENhgw8bl6 IJav+B+hqWE+AfqI9TUr64yfZrH5bxKqpk2w6w/K2mC9Oj2UifGrA+GQXq/aqPAYIEoo fzlfxpq2T0tii1wd39wmdjaukrv39WgHHod798mV2ltht4wPiqrYnC+Vz/cmpwo36NYG ymMA== 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=pV2kzrwDISXA7ZmQ9QBmb/VCEdtD+9kPLJURP+N5iaVHK6OJTnJpv1WPDSnSONP+Ah O/d9+7xXLpDDC9pKuQdsxf4qPo361KOEnPcuNQ15pJwQ7Z3szmsMZP6OSPWxZPZvpzZ+ IlVQ6VXlJV9Szug5/Z/JIVcgLrhuBzm0JJtdohYchcHdVtBWwMp1Ap2Zjku6H9wmXUWB TcnMHmd9hGGopnfOUbg/i/cwWCKvdRYk8IctnvfE54xea29nHylxcMpO3qJuJqkivYnw YoEFraBpEvc1WhkjZpZcnQ20tDTf5ReHq4BUm6+et7oYySaciFx+cOPaT1U5KeHc8vAW Jjeg== X-Gm-Message-State: AKS2vOw5Y5bYdLvgY1ysyvtUZYCrinX2seXbGsZ1hhRluqYtKTRNWWIh lnFTYRxWwkiIAlknBjQ= X-Received: by 10.55.39.131 with SMTP id n125mr40449609qkn.223.1496850958686; Wed, 07 Jun 2017 08:55:58 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 7 Jun 2017 08:55:33 -0700 Message-Id: <20170607155536.1193-5-rth@twiddle.net> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170607155536.1193-1-rth@twiddle.net> References: <20170607155536.1193-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] [PATCH v4 4/7] target/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: cota@braap.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 15:52:46 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 1496851195462398.85619923675984; Wed, 7 Jun 2017 08:59:55 -0700 (PDT) Received: from localhost ([::1]:44795 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIdNB-0003uY-R7 for importer@patchew.org; Wed, 07 Jun 2017 11:59:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48512) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIdJU-0000i2-8r for qemu-devel@nongnu.org; Wed, 07 Jun 2017 11:56:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dIdJR-0005cV-3w for qemu-devel@nongnu.org; Wed, 07 Jun 2017 11:56:04 -0400 Received: from mail-qt0-x242.google.com ([2607:f8b0:400d:c0d::242]:33161) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dIdJQ-0005cM-Vg for qemu-devel@nongnu.org; Wed, 07 Jun 2017 11:56:01 -0400 Received: by mail-qt0-x242.google.com with SMTP id w1so1993202qtg.0 for ; Wed, 07 Jun 2017 08:56:00 -0700 (PDT) Received: from bigtime.twiddle.net.com (184-217-116-168.pools.spcsdns.net. [184.217.116.168]) by smtp.gmail.com with ESMTPSA id i28sm1272525qta.52.2017.06.07.08.55.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Jun 2017 08:55:59 -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=gtx8v0a7RDShL/b6uJTCkn6FjFgPVuofukKKY2oheps=; b=YSyTreQDQ1AugR55sIb3KQ+TneBfmhTXYw0n4OBA3MoXypFgYCBkvOTyiXt3KHG/og zM9I458ljfgNNjG+euTFJi20L+Q7efivGel07yflQOoGtfNrEsTnHiEIvVFZS664NgCR mdCLxSbgfXkYxnluS0pcBxmJGYpMTOGslg5zxS1LLKRqoqyjB6Rgzj6lGBzFc8Qu4LSD hjo4qV2mAeGLzKLu/uBkCJdPwoUUnQ3AWCF1h/xlRkhk6kvPgA6/xjbRVADjIF2FLvtA VbaWMZexgmHk23jdk8ELZ//pmEhUBciKWfgYKqgiO82Azk1Aay8UUL+eJ6qtDpjiEh/L DeDA== 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=gtx8v0a7RDShL/b6uJTCkn6FjFgPVuofukKKY2oheps=; b=unSYJXzY9N8RBIRP1W0wgn7pSE9lBuYrgSg6g/q8w8jjwbYfSqhaKO+V3oW+OGSIyC jZt5Au8Tq5QaP8E7Xwx7oK89Su/nDIZLeBGS4R1H1AL8yr3ZCYOFDpDOc4HDnIgM/0l6 FZsq0DT6ansvatCA5ljUXxvmzYi3ifeFPt4GYHxRs6szyq3bp73bmp3YEAvHYNNlAhOL d+hXrRO1JfKtBbomg6bJU8rTxZUDDCOu+12yUMO3kvNIWqgP0PPvi+6E4AH4EIXqY1ld SCZm7HoESIiOqfYYyUtYtSRXUNndpZ6F+vQrSZfaqo2m5KCX13R6WvQ4QYOci7Cl4z00 XU7Q== X-Gm-Message-State: AKS2vOySn8zfeZ3hYkb3ld3U0IypoqRr1TpofhE8kzH9XWkfnoZ9Txhl 73GpJmH3IvY4T+kXHE4= X-Received: by 10.237.42.99 with SMTP id k32mr25241431qtf.58.1496850960113; Wed, 07 Jun 2017 08:56:00 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 7 Jun 2017 08:55:34 -0700 Message-Id: <20170607155536.1193-6-rth@twiddle.net> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170607155536.1193-1-rth@twiddle.net> References: <20170607155536.1193-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] [PATCH v4 5/7] target/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: cota@braap.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 bb094ad..966747a 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 15:52:46 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 1496851360339290.46692387353653; Wed, 7 Jun 2017 09:02:40 -0700 (PDT) Received: from localhost ([::1]:44854 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIdPo-0006FM-F5 for importer@patchew.org; Wed, 07 Jun 2017 12:02:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48513) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIdJU-0000i3-8s for qemu-devel@nongnu.org; Wed, 07 Jun 2017 11:56:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dIdJT-0005dh-2Z for qemu-devel@nongnu.org; Wed, 07 Jun 2017 11:56:04 -0400 Received: from mail-qt0-x241.google.com ([2607:f8b0:400d:c0d::241]:33167) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dIdJS-0005dc-Qm for qemu-devel@nongnu.org; Wed, 07 Jun 2017 11:56:02 -0400 Received: by mail-qt0-x241.google.com with SMTP id w1so1993363qtg.0 for ; Wed, 07 Jun 2017 08:56:02 -0700 (PDT) Received: from bigtime.twiddle.net.com (184-217-116-168.pools.spcsdns.net. [184.217.116.168]) by smtp.gmail.com with ESMTPSA id i28sm1272525qta.52.2017.06.07.08.56.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Jun 2017 08:56:01 -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=lLjU86hOuYj5usrE9MTf7p6U4d883mbdUoUP9fm2UWU=; b=Qn7zigQ4JePj4rS0z86bLZLfsreZec2whGKz5dT27XxqGYYo/3CR+2cAZ4pB3tTnAF xtctjv5jL3cQoqwJMR8FF5vop8fZ+7MCZYOt5R3BMhqwSJxssm8LPUExlkgKGMIrdUwU lW3hubOZodruXOB/uxTfliw5wpz43QCQbhSkOt3DiIbgmqSGg4xlBq9ER2jZSZGC7aC1 3vlN0WUIrEP/51DAlev9+i2BMFcCR79hOwLr8YhKIOXy7dqLxeWSwX+cQSNEaJbnrjnf lLpgN0HAJgBplgxOvNq5H117/78/eN6ZSbDXiY7/5f2mQaOCumANfb7ZztCi5ZU2whji UuJw== 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=lLjU86hOuYj5usrE9MTf7p6U4d883mbdUoUP9fm2UWU=; b=ITCOfsNHQBv7UWuea9+s2EYaKeG0lhbR5cdU8p6rQVueDUVSz0nE0ppvtNNGZRn0cn kgC72E7qtBedDKqSs4n7GOBSGXkI3lj+tY9wuhcE90VQ3InU5eqmuVvKyznDhwvxaFWt duauTt4UBZ9Z9OTSMZM/lqNhT2MLH7yJGDhsVLc6che/ilyFNMp7jyniiqoGN1EDfP+n fqHROLslq56tuoyklR+9Lah/p2o6N9jKnKeyg6nhFuoEAz2ZlXaSvVrRKUdiTzeOpK29 XxjTSRNtO91nYlWwYsgWIcDUzujEtpzRbBtER30yVZtxlykcoFhzg5jAn2HZlTKhM+Fr 2Crw== X-Gm-Message-State: AODbwcBAmIpNiURvURRRpAHx8JplTsaHxyYCMlfLfTRw5O4dtXMIM8Tn WhAIg/7gGI7nsDW0YvY= X-Received: by 10.200.45.35 with SMTP id n32mr10540127qta.15.1496850961954; Wed, 07 Jun 2017 08:56:01 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 7 Jun 2017 08:55:35 -0700 Message-Id: <20170607155536.1193-7-rth@twiddle.net> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170607155536.1193-1-rth@twiddle.net> References: <20170607155536.1193-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::241 Subject: [Qemu-devel] [PATCH v4 6/7] target/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: cota@braap.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 | 44 +++++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/tcg/arm/tcg-target.inc.c b/tcg/arm/tcg-target.inc.c index fce382f..18708b1 100644 --- a/tcg/arm/tcg-target.inc.c +++ b/tcg/arm/tcg-target.inc.c @@ -418,25 +418,39 @@ 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 /* Use movw + movt. */ --=20 2.9.4 From nobody Wed Nov 5 15:52:46 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 1496851192207963.6644838100078; Wed, 7 Jun 2017 08:59:52 -0700 (PDT) Received: from localhost ([::1]:44794 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIdN8-0003rb-G9 for importer@patchew.org; Wed, 07 Jun 2017 11:59:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48530) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIdJV-0000jS-LI for qemu-devel@nongnu.org; Wed, 07 Jun 2017 11:56:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dIdJU-0005fh-MY for qemu-devel@nongnu.org; Wed, 07 Jun 2017 11:56:05 -0400 Received: from mail-qt0-x241.google.com ([2607:f8b0:400d:c0d::241]:35642) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dIdJU-0005f7-Hl for qemu-devel@nongnu.org; Wed, 07 Jun 2017 11:56:04 -0400 Received: by mail-qt0-x241.google.com with SMTP id x58so1991084qtc.2 for ; Wed, 07 Jun 2017 08:56:04 -0700 (PDT) Received: from bigtime.twiddle.net.com (184-217-116-168.pools.spcsdns.net. [184.217.116.168]) by smtp.gmail.com with ESMTPSA id i28sm1272525qta.52.2017.06.07.08.56.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Jun 2017 08:56:03 -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=CZuOQA8z7S/McZqGqhuzohMvsuyDE6ISLie/MXe2Pzg=; b=SpmOuu3wfgNYt11L3ETQ9RvJdEYiWHTnNGIKNXpxyzPfytSU+Rnaz+vA0LHUlESbyJ 6chhKxMGZ9vAN7L7BdsnWsmffkYcTaSTpY5WGGYdNlHNVnGJxUZ0doj3vrCtIGnGtvRj 4IfIHkHIlQXTaeyLLS4csBAnO+nECb40ccmpXReuuWBNxCG4x6aPChgWrt7ia/4ymjN2 ncZn4sH9YazdwEFgcTkBtoCeqmjBb6OqgqHA/KDCqYWWVXfx/5rXhuiOoE/9LTGZZbnG Sb9/hDbo0wOzosHloqXo5Q8LwbIge9dJiwCKQoHEoCO93guxEB/cz+qP/jL1HdeOkKra uEdQ== 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=CZuOQA8z7S/McZqGqhuzohMvsuyDE6ISLie/MXe2Pzg=; b=p7qzv2qpTzbODI//lAsIN9vw+TcselJKynm4gbUMxB7F3VpT3XMMWrmSZp4KLZO5TC cmw3sV3aSpEG8CutbCgGnNjTqnPXYh9+B6F6cUd4N52TKkWLCdJT3nlNYL4dIe4veNor 4LZGnVIlFjt46bobFDHnL+5mQrQESit9SHBfxTUfeuRExDzKqW7YtaXiLFpiXsPRFMXI lbVBN3qCdUE4CPtjPMtU9T3gC51F9yk87DliTpvKhzgCmiAX06oKTvCkZCPDqCmmF+Ku drQiJcn2qnc1Du53VGFbyMfz/dFrlx3oAgjDqprGzMIZ6ESaCD4WfyYCUd7zl5a3Issn 7+Ig== X-Gm-Message-State: AKS2vOwvsQaYgpfqQI77RBaHsUJY+pEOCkcEump3WNBFgIw+3h5DGHEz qGpLlqWfnyR1ZjqnSYo= X-Received: by 10.55.55.207 with SMTP id e198mr39894599qka.44.1496850963760; Wed, 07 Jun 2017 08:56:03 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 7 Jun 2017 08:55:36 -0700 Message-Id: <20170607155536.1193-8-rth@twiddle.net> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170607155536.1193-1-rth@twiddle.net> References: <20170607155536.1193-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::241 Subject: [Qemu-devel] [PATCH v4 7/7] target/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: cota@braap.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 18708b1..b640fb9 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