From patchwork Tue Oct 2 21:29:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emilio Cota X-Patchwork-Id: 978053 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=braap.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=braap.org header.i=@braap.org header.b="HiL6LTQk"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="CkIUgBiF"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42Psy31vrQz9s3l for ; Wed, 3 Oct 2018 07:40:11 +1000 (AEST) Received: from localhost ([::1]:45803 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g7SOm-0007ye-NR for incoming@patchwork.ozlabs.org; Tue, 02 Oct 2018 17:40:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44068) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g7SEo-0007fs-Sh for qemu-devel@nongnu.org; Tue, 02 Oct 2018 17:29:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g7SEj-0001My-RH for qemu-devel@nongnu.org; Tue, 02 Oct 2018 17:29:50 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:49719) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g7SEj-0001LQ-Kw for qemu-devel@nongnu.org; Tue, 02 Oct 2018 17:29:45 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 6B48721E31; Tue, 2 Oct 2018 17:29:43 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Tue, 02 Oct 2018 17:29:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h=cc :date:from:message-id:subject:to:x-me-sender:x-me-sender :x-sasl-enc; s=mesmtp; bh=l2UbKlegWKcf9HHop0fDMI6hzhGR8ZFEDW31U7 WlQRc=; b=HiL6LTQk9LzbD2ANsz9662WWmDFya7Kvlg9pOfdYUSDN2PLryUHxux ebWnVI/ETXIfrfZ58AZL1CvlJZbCJgdtN0hUqmva0T9yFk1OdMOrHYmjfpj2r2ZA t3uS01cAt77+kdtKojrZwJTs3W1TVWEN+0onLIlBDvOmqIZLGT03A= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:message-id:subject:to :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=l2UbKlegWKcf9HHop 0fDMI6hzhGR8ZFEDW31U7WlQRc=; b=CkIUgBiFka86ouKK3zGG2588boQTMIp5S jMxzZPEhZzZGOJxRJLiEAB/nyrNuzgwvntDUtVMCELtrEknWLtrPQ2dEBVCVgeTF 61s9tY1a5pjciunujC4ogYoJWPTUmRkytGGNHaq4Bq3MVjK/Zfr2SU+3nTOh5Owv Adb/IRl3JWuaBsRj9e6FHs3Tay7pYDBuPpNjNe739L1y2YwyoStzhIGkpzWoW43m BASIVl57i8fF2+q1VEku3ud3CEL+oIhum2x/JFOeagofj8vFbY2iK5JULtRupqZi vD6QMokFweZ+n2giJDYcmspOZBPnOZGvib/oWBUS0o88vuh59iXxA== X-ME-Sender: X-ME-Proxy: Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 36583E4074; Tue, 2 Oct 2018 17:29:42 -0400 (EDT) From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Tue, 2 Oct 2018 17:29:18 -0400 Message-Id: <20181002212921.30982-1-cota@braap.org> X-Mailer: git-send-email 2.17.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.27 Subject: [Qemu-devel] [PATCH 0/3] per-TLB lock 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: Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , Richard Henderson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This series introduces a per-TLB lock. This removes existing UB (e.g. memset racing with cmpxchg on another thread while flushing), and in my opinion makes the TLB code simpler to understand. I had a bit of trouble finding the best place to initialize the mutex, since it has to be called before tlb_flush, and tlb_flush is called quite early during cpu initialization. I settled on cpu_exec_realizefn, since then cpu->env_ptr has been set but tlb_flush hasn't yet been called. Perf-wise this change does have a small impact (~2% slowdown for the aarch64 bootup+shutdown test; 1.2% comes from using atomic_read consistently), but I think this is a fair price for avoiding UB. Numbers below. Initially I tried using atomics instead of memset for flushing (i.e. no mutex), and the slowdown is close to 2X due to the repeated (full) memory barriers. That's when I turned to using a lock. Host: Intel(R) Core(TM) i7-6700K CPU @ 4.00GHz - Before this series: Performance counter stats for 'taskset -c 0 ../img/aarch64/die.sh' (10 runs): 7464.797838 task-clock (msec) # 0.998 CPUs utilized ( +- 0.14% ) 31,473,652,436 cycles # 4.216 GHz ( +- 0.14% ) 57,032,288,549 instructions # 1.81 insns per cycle ( +- 0.08% ) 10,239,975,873 branches # 1371.769 M/sec ( +- 0.07% ) 172,150,358 branch-misses # 1.68% of all branches ( +- 0.12% ) 7.482009203 seconds time elapsed ( +- 0.18% ) - After: Performance counter stats for 'taskset -c 0 ../img/aarch64/die.sh' (10 runs): 7621.625434 task-clock (msec) # 0.999 CPUs utilized ( +- 0.10% ) 32,149,898,976 cycles # 4.218 GHz ( +- 0.10% ) 58,168,454,452 instructions # 1.81 insns per cycle ( +- 0.10% ) 10,486,183,612 branches # 1375.846 M/sec ( +- 0.10% ) 173,900,633 branch-misses # 1.66% of all branches ( +- 0.11% ) 7.632067213 seconds time elapsed ( +- 0.10% ) This series is checkpatch-clean. You can fetch the code from: https://github.com/cota/qemu/tree/tlb-lock Thanks, Emilio