From patchwork Mon Jun 5 22:49:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emilio Cota X-Patchwork-Id: 9767641 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 24BEA602B6 for ; Mon, 5 Jun 2017 22:52:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 162F726538 for ; Mon, 5 Jun 2017 22:52:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0990E28437; Mon, 5 Jun 2017 22:52:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6018226538 for ; Mon, 5 Jun 2017 22:52:44 +0000 (UTC) Received: from localhost ([::1]:35453 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dI0rb-0000Wb-9T for patchwork-qemu-devel@patchwork.kernel.org; Mon, 05 Jun 2017 18:52:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38516) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dI0ou-0007nE-Fr for qemu-devel@nongnu.org; Mon, 05 Jun 2017 18:49:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dI0or-0000GC-Bn for qemu-devel@nongnu.org; Mon, 05 Jun 2017 18:49:56 -0400 Received: from out1-smtp.messagingengine.com ([66.111.4.25]:44383) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dI0or-0000FB-0v for qemu-devel@nongnu.org; Mon, 05 Jun 2017 18:49:53 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 79FE420AAC; Mon, 5 Jun 2017 18:49:49 -0400 (EDT) Received: from frontend1 ([10.202.2.160]) by compute4.internal (MEProxy); Mon, 05 Jun 2017 18:49:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h=cc :date:from:in-reply-to:message-id:references:subject:to :x-me-sender:x-me-sender:x-sasl-enc:x-sasl-enc; s=mesmtp; bh=FLh TyJBOZersxyftd24rGuhU92rGn4BnyZ0n0thUGgA=; b=SsuU6CODnDTvIW+CLz2 ZLeuzYK4yFPYXxWAOVIladcSdpRUzayX4l8L3n/7cs4UxiNVdQ/I+lIZPeaUZzL7 C49hZ9Hy+jP+sWI8laOtnzm+9V0WyISw1iENvwk0jfK/cDN5lMg6MYq9Fqr9lVL+ YR3Qn+a5JwFNSnIIsjpmXKOA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc :x-sasl-enc; s=fm1; bh=FLhTyJBOZersxyftd24rGuhU92rGn4BnyZ0n0thUG gA=; b=gMJYAxaR/rE4G0nnAC264VAUNV2s6f9E+e3zbsjyG88tJwaeipUIp3KYo ZsMiNrikCa7Vk6CpQwtdpQT3S5JZ31GLtKi1hv5di7BLF3fLu5aTlKJ5SIIQFe4X f+5gTEJgqK28C5Ww3CCQtUv1cM7lPEd/W3WxAnMTDg2m+aPFgIgbY/CdRWsl0ivh ybd3lxhvq5sOV1JeGOFEzG2TDP2lhUI+rg4kaDrih3fVd/lMqJ5b5F+YBRw2RrFr altzDJmw7IQ5rdpa154Xu3I3TtJLDazwalCBNQW4woTINhv1sLcn7maAG/ATP0SR TpMvYMrXXYcKSvzgVcZR9sTkVKamA== X-ME-Sender: X-Sasl-enc: Pk4pFwf4v3EJDLBX5awr2UXfOjUWpvSD7Ptyy2h+Cc0y 1496702989 Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 3C6AF7E263; Mon, 5 Jun 2017 18:49:49 -0400 (EDT) From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Mon, 5 Jun 2017 18:49:37 -0400 Message-Id: <1496702979-26132-2-git-send-email-cota@braap.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1496702979-26132-1-git-send-email-cota@braap.org> References: <1496702979-26132-1-git-send-email-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.111.4.25 Subject: [Qemu-devel] [PATCH v2 1/3] compiler: define QEMU_CACHELINE_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 , Pranith Kumar , Paolo Bonzini , alex.bennee@linaro.org, Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This is a constant used as a hint for padding structs to hopefully avoid false cache line sharing. The constant can be set at configure time by defining QEMU_CACHELINE_SIZE via --extra-cflags. If not set there, we try to obtain the value from the machine running the configure script. If we fail, we default to reasonable values, i.e. 128 bytes for ppc64 and 64 bytes for all others. Note: the configure script only picks up the cache line size when run on Linux hosts because I have no other platforms (e.g. Windows, BSD's) to test on. Signed-off-by: Emilio G. Cota Tested-by: Geert Martin Ijewski --- configure | 38 ++++++++++++++++++++++++++++++++++++++ include/qemu/compiler.h | 17 +++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/configure b/configure index 13e040d..6a68cb2 100755 --- a/configure +++ b/configure @@ -4832,6 +4832,41 @@ EOF fi fi +# Find out the size of a cache line on the host +# TODO: support more platforms +cat > $TMPC< + +#define SYSFS "/sys/devices/system/cpu/cpu0/cache/index0/coherency_line_size" + +int main(int argc, char *argv[]) +{ + unsigned int size; + FILE *fp; + + fp = fopen(SYSFS, "r"); + if (fp == NULL) { + return -1; + } + if (!fscanf(fp, "%u", &size)) { + return -1; + } + return size; +} +#else +#error Cannot find host cache line size +#endif +EOF + +host_cacheline_size=0 +if compile_prog "" "" ; then + ./$TMPE + host_cacheline_size=$? +fi + + ########################################## # check for _Static_assert() @@ -5284,6 +5319,9 @@ fi if test "$bigendian" = "yes" ; then echo "HOST_WORDS_BIGENDIAN=y" >> $config_host_mak fi +if test "$host_cacheline_size" -gt 0 ; then + echo "HOST_CACHELINE_SIZE=$host_cacheline_size" >> $config_host_mak +fi if test "$mingw32" = "yes" ; then echo "CONFIG_WIN32=y" >> $config_host_mak rc_version=$(cat $source_path/VERSION) diff --git a/include/qemu/compiler.h b/include/qemu/compiler.h index 340e5fd..178d831 100644 --- a/include/qemu/compiler.h +++ b/include/qemu/compiler.h @@ -40,6 +40,23 @@ # define QEMU_PACKED __attribute__((packed)) #endif +/* + * Cache line size of the host. Can be overriden. + * Note that this is just a compile-time hint to hopefully avoid false sharing + * of cache lines; code must be correct regardless of the constant's value. + */ +#ifndef QEMU_CACHELINE_SIZE +# ifdef HOST_CACHELINE_SIZE +# define QEMU_CACHELINE_SIZE HOST_CACHELINE_SIZE +# else +# if defined(__powerpc64__) +# define QEMU_CACHELINE_SIZE 128 +# else +# define QEMU_CACHELINE_SIZE 64 +# endif +# endif +#endif + #define QEMU_ALIGNED(X) __attribute__((aligned(X))) #ifndef glue