From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57638) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WUg9K-0000Dm-KO for qemu-devel@nongnu.org; Mon, 31 Mar 2014 13:37:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WUg9C-0002RE-UM for qemu-devel@nongnu.org; Mon, 31 Mar 2014 13:37:30 -0400 Received: from cantor2.suse.de ([195.135.220.15]:45642 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WUg9C-0002Qx-Nx for qemu-devel@nongnu.org; Mon, 31 Mar 2014 13:37:22 -0400 Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 03F34ACE0 for ; Mon, 31 Mar 2014 17:37:22 +0000 (UTC) From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Mon, 31 Mar 2014 19:37:16 +0200 Message-Id: <1396287436-12696-3-git-send-email-afaerber@suse.de> In-Reply-To: <1396287436-12696-1-git-send-email-afaerber@suse.de> References: <1396287436-12696-1-git-send-email-afaerber@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PULL for-2.0 2/2] cpu: Avoid QOM casts for CPU() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Andreas=20F=C3=A4rber?= CPU address spaces touching load and store helpers as well as the movement of (almost) all fields from CPU_COMMON to CPUState have led to a noticeable increase of CPU() usage in "hot" paths for both TCG and KVM. While CPU()'s OBJECT_CHECK() might help detect development errors, i.e. in form of crashes due to QOM vs. non-QOM mismatches rather than QOM type mismatches, it is not really needed at runtime since mostly used in CPU-specific paths, coming from a target-specific CPU subtype. If that pointer is damaged, other errors are highly likely to occur elsewhere anyway. Keep the CPU() macro for a consistent developer experience and for flexibility to exchange its implementation, but turn it into a pure, unchecked C cast for now. Compare commit 6e42be7cd10260fd3a006d94f6c870692bf7a2c0. Reported-by: Laurent Desnogues Suggested-by: Paolo Bonzini Signed-off-by: Andreas F=C3=A4rber --- include/qom/cpu.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/include/qom/cpu.h b/include/qom/cpu.h index f99885a..df977c8 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -53,7 +53,12 @@ typedef uint64_t vaddr; =20 #define TYPE_CPU "cpu" =20 -#define CPU(obj) OBJECT_CHECK(CPUState, (obj), TYPE_CPU) +/* Since this macro is used a lot in hot code paths and in conjunction w= ith + * FooCPU *foo_env_get_cpu(), we deviate from usual QOM practice by usin= g + * an unchecked cast. + */ +#define CPU(obj) ((CPUState *)(obj)) + #define CPU_CLASS(class) OBJECT_CLASS_CHECK(CPUClass, (class), TYPE_CPU) #define CPU_GET_CLASS(obj) OBJECT_GET_CLASS(CPUClass, (obj), TYPE_CPU) =20 --=20 1.8.4.5