From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:54385) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uapxj-0005VH-E9 for qemu-devel@nongnu.org; Fri, 10 May 2013 12:14:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Uapxi-0007is-0Z for qemu-devel@nongnu.org; Fri, 10 May 2013 12:14:27 -0400 Message-ID: <518D1CDD.4060705@suse.de> Date: Fri, 10 May 2013 18:14:21 +0200 From: =?ISO-8859-1?Q?Andreas_F=E4rber?= MIME-Version: 1.0 References: <1368196799-19982-1-git-send-email-afaerber@suse.de> <87obcizxgk.fsf@codemonkey.ws> <518D10E3.4080001@suse.de> <14CF0363-E558-4387-A401-14C940131BDB@suse.de> In-Reply-To: <14CF0363-E558-4387-A401-14C940131BDB@suse.de> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH for-1.5?] target-ppc: Drop unnecessary dynamic cast in ppc_env_get_cpu() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Alexander Graf Cc: pbonzini@redhat.com, Anthony Liguori , PowerPC , qemu-devel@nongnu.org, aurelien@aurel32.net Am 10.05.2013 17:32, schrieb Alexander Graf: >=20 > On 10.05.2013, at 17:23, Andreas F=E4rber wrote: >=20 >> Am 10.05.2013 17:06, schrieb Anthony Liguori: >>> Andreas F=E4rber writes: >>> >>>> A transition from CPUPPCState to PowerPCCPU can be considered safe, >>>> just like PowerPCCPU::env access in the opposite direction. >>>> >>>> This should slightly improve interrupt performance. >>>> >>>> Reported-by: Anthony Liguori >>>> Signed-off-by: Andreas F=E4rber >>> >>> Another option would be to leave it and do something like: >>> >>> diff --git a/qom/object.c b/qom/object.c >>> index 75e6aac..cba1d88 100644 >>> --- a/qom/object.c >>> +++ b/qom/object.c >>> @@ -126,8 +126,13 @@ static TypeImpl *type_register_internal(const Ty= peInfo *info) >>> >>> TypeImpl *type_register(const TypeInfo *info) >>> { >>> + TypeImpl *impl; >>> + >>> assert(info->parent); >>> - return type_register_internal(info); >>> + impl =3D type_register_internal(info); >>> + g_free(impl->name); >>> + impl->name =3D info->name; >>> + return impl; >>> } >>> >>> TypeImpl *type_register_static(const TypeInfo *info) >>> @@ -449,10 +490,16 @@ Object *object_dynamic_cast_assert(Object *obj,= const char *typename) >>> ObjectClass *object_class_dynamic_cast(ObjectClass *class, >>> const char *typename) >>> { >>> - TypeImpl *target_type =3D type_get_by_name(typename); >>> + TypeImpl *target_type; >>> TypeImpl *type =3D class->type; >>> ObjectClass *ret =3D NULL; >>> >>> + if (type->name =3D=3D typename) { >>> + return class; >>> + } >>> + >>> + target_type =3D type_get_by_name(typename); >>> + >>> if (!target_type) { >>> /* target class type unknown, so fail the cast */ >>> return NULL; >>> >>> Which makes casting an object to it's concrete class free. >> >> Doesn't help here since concrete class is POWER7_v2.1-ppc64-cpu wherea= s >> we're casting to ppc64-cpu, with two-level hierarchy by now: >> POWER7_v2.1 -> POWER7 -> ppc64 -> device -> object. >=20 > How much performance penalty do we get from this? Not sure which "this" you are referring to, but in general dynamic_cast does a check for interfaces (which we don't have) and then iterates through the hierarchy with string comparisons, i.e. negative, negative, positive for POWERPC_CPU(). My original patch here dropped this penalty for ppc_env_get_cpu(); CPU() would still result in negative, negative, negative, positive. Personally I wouldn't oppose dropping these checks for release builds as proposed by Paolo in his series; for me, the value of POWERPC_CPU() is being closer to an OO cast than any container_of()-style expressions. But I can also see Anthony's point that we should try to optimize dynamic_cast rather than circumventing it. Andreas --=20 SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 N=FCrnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imend=F6rffer; HRB 16746 AG N=FCrnbe= rg