From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43871) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WVEoy-0002JO-GY for qemu-devel@nongnu.org; Wed, 02 Apr 2014 02:38:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WVEox-0007sW-JK for qemu-devel@nongnu.org; Wed, 02 Apr 2014 02:38:48 -0400 Received: from mail-oa0-x231.google.com ([2607:f8b0:4003:c02::231]:60223) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WVEox-0007sO-E8 for qemu-devel@nongnu.org; Wed, 02 Apr 2014 02:38:47 -0400 Received: by mail-oa0-f49.google.com with SMTP id o6so2018818oag.36 for ; Tue, 01 Apr 2014 23:38:46 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <1396287436-12696-3-git-send-email-afaerber@suse.de> References: <1396287436-12696-1-git-send-email-afaerber@suse.de> <1396287436-12696-3-git-send-email-afaerber@suse.de> Date: Wed, 2 Apr 2014 08:38:46 +0200 Message-ID: From: Laurent Desnogues Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [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: =?ISO-8859-1?Q?Andreas_F=E4rber?= Cc: "qemu-devel@nongnu.org" On Mon, Mar 31, 2014 at 7:37 PM, Andreas F=E4rber wrote: > 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=E4rber It works fine here. Tested-by: Laurent Desnogues Thanks, Laurent > --- > 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; > > #define TYPE_CPU "cpu" > > -#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) > > -- > 1.8.4.5 > >