From patchwork Fri Jun 30 14:55:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emilio Cota X-Patchwork-Id: 782996 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wzppM4VPTz9sRV for ; Sat, 1 Jul 2017 07:00:42 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=braap.org header.i=@braap.org header.b="n7HEvffp"; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="sGQvz6G2"; dkim-atps=neutral Received: from localhost ([::1]:45933 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dR31p-0007IC-PG for incoming@patchwork.ozlabs.org; Fri, 30 Jun 2017 17:00:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38377) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dR31X-0007Hz-PQ for qemu-devel@nongnu.org; Fri, 30 Jun 2017 17:00:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dR31U-0005ua-I2 for qemu-devel@nongnu.org; Fri, 30 Jun 2017 17:00:19 -0400 Received: from out1-smtp.messagingengine.com ([66.111.4.25]:43327) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dR31U-0005t8-6n for qemu-devel@nongnu.org; Fri, 30 Jun 2017 17:00:16 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 4320721AE3; Fri, 30 Jun 2017 17:00:15 -0400 (EDT) Received: from frontend2 ([10.202.2.161]) by compute4.internal (MEProxy); Fri, 30 Jun 2017 17:00:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h=cc :content-type:date:from:in-reply-to:message-id:mime-version :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc :x-sasl-enc; s=mesmtp; bh=Dupd44zBDK1AZNOEaSjwAUgMs54a8b0pMT12Hs 8ZpnA=; b=n7HEvffplkfE4UL+IjwjhQl68VaI+CT6DBayVWsFI7Lpb3kqVEOInj qmEOvenG+slsd3dgolXSnlP7p5dP92+2f6U72MdTwIdntGp3VQp/DI3Cq/oBJM5p 0i37cvxx6tNPsr/Wd0lsb4Rcjr0RywRGEAeMXWQMn3oHTyBNOrnDA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc:x-sasl-enc; s=fm1; bh=Dupd44zBDK1AZNOEaS jwAUgMs54a8b0pMT12Hs8ZpnA=; b=sGQvz6G2aRbhSYzJk5DHkrzwmM4j2+x1sD y2Tw5Y1jpFjntNhmjPJIu57GUiS3xrr3NfzUEexyjTF9+Bz/vrzfmq92jNbtYFZ1 ey+SJxG81MLOjNWJwjb9VMOWaaXvsMxiFa3xxKTG6U7Zf4K6vJ1Q0sL0i8ZoSyx2 9WhgoGw72qvO8LoYNx11wAj/xo7fw3DtTpJBYZMHiR/1Nr9pPCsSjFi7Jv/JlyEE FBrXVW3M9iEdAiRJZ9/gXS/3SY3HzErIAX3wRLh4CDqOAK9fU0t7ZAMSaa/JHXAU 4G0pN7cw+T6BsSflexTsmvr2Ng9dQqwomGJwlcnd0+ks42rR932g== X-ME-Sender: X-Sasl-enc: us3IIq6MKwAAv13buLENX/exQg4yHSwmu2lYd3L6+rCP 1498856415 Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 074F92424E; Fri, 30 Jun 2017 17:00:15 -0400 (EDT) Date: Fri, 30 Jun 2017 10:55:57 -0400 From: "Emilio G. Cota" To: Richard Henderson Message-ID: <20170630145557.GA19722@flamenco> References: <1498768109-4092-1-git-send-email-cota@braap.org> <1498768109-4092-4-git-send-email-cota@braap.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) 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: Re: [Qemu-devel] [RFC 3/7] translate-all: use a binary search tree to track TBs in TBContext 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: qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" On Fri, Jun 30, 2017 at 00:49:37 -0700, Richard Henderson wrote: > On 06/30/2017 12:41 AM, Richard Henderson wrote: > >On 06/29/2017 01:28 PM, Emilio G. Cota wrote: > >>+/* @key is already in the tree so it's safe to use container_of on it */ > >>+static gint tc_ptr_cmp(gconstpointer candidate, gconstpointer key) > >>+{ > >>+ uintptr_t a = *(uintptr_t *)candidate; > >>+ const TranslationBlock *tb = container_of(key, TranslationBlock, tc_ptr); > > > >This I'm not keen on. It'd be one thing if it was our own datastructure, > >but I see nothing in the GTree documentation that says that the comparison > >must always be done this way. I also checked for this. Couldn't find anything in the docs -- the only guarantee I could find is the implicit one that since the g_tree module was created, the 2nd pointer ("b" above) has consistenly been the in-node one. I don't think they'd ever change this, but yes relying on this assumption is a bit risky. If we prefer using our own we could bring the AVL tree from CCAN: http://git.ozlabs.org/?p=ccan;a=tree;f=ccan/avl > What if we bundle tc_ptr + tc_size into a struct and only reference that? > We'd embed that struct into the TB. In tb_find_pc, create that struct on > the stack, setting tc_size = 0. This is clean and safe, but we'd add a 4-byte hole for 64-on-64bit. However, we could bring other fields into the embedded struct to plug the hole. Also, using an anonymous struct would hide this from the calling code: We also move invalid to the 2nd cache line, which I'm not sure it would matter much (I liked having out_size there because it's fairly slow path). Also I'd rename out_size to tc_size. E. diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h index 4b4c143..07f1f50 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -319,16 +319,18 @@ struct TranslationBlock { uint16_t size; /* size of target code for this block (1 <= size <= TARGET_PAGE_SIZE) */ uint16_t icount; - uint32_t cflags; /* compile flags */ + + struct { + void *tc_ptr; /* pointer to the translated code */ + int32_t out_size; /* size of host code for this block */ + uint32_t cflags; /* compile flags */ #define CF_COUNT_MASK 0x7fff #define CF_LAST_IO 0x8000 /* Last insn may be an IO access. */ #define CF_NOCACHE 0x10000 /* To be freed after execution */ #define CF_USE_ICOUNT 0x20000 #define CF_IGNORE_ICOUNT 0x40000 /* Do not generate icount code */ + }; - uint16_t invalid; - - void *tc_ptr; /* pointer to the translated code */ uint8_t *tc_search; /* pointer to search data */ /* original tb when cflags has CF_NOCACHE */ struct TranslationBlock *orig_tb; @@ -365,7 +367,7 @@ struct TranslationBlock { */ uintptr_t jmp_list_next[2]; uintptr_t jmp_list_first; - int32_t out_size; /* size of host code for this block */ + uint16_t invalid; }; That is 122 bytes, with all 6 bytes of padding at the end.