From patchwork Fri May 10 18:47:55 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Anthony Liguori X-Patchwork-Id: 243055 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 4BF6B2C00D8 for ; Sat, 11 May 2013 04:48:42 +1000 (EST) Received: from localhost ([::1]:39714 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UasMy-0004cW-7o for incoming@patchwork.ozlabs.org; Fri, 10 May 2013 14:48:40 -0400 Received: from eggs.gnu.org ([208.118.235.92]:37356) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UasMi-0004cQ-Iq for qemu-devel@nongnu.org; Fri, 10 May 2013 14:48:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UasMg-0007UK-Gz for qemu-devel@nongnu.org; Fri, 10 May 2013 14:48:24 -0400 Received: from e23smtp05.au.ibm.com ([202.81.31.147]:49542) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UasMf-0007SW-Th for qemu-devel@nongnu.org; Fri, 10 May 2013 14:48:22 -0400 Received: from /spool/local by e23smtp05.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Sat, 11 May 2013 04:42:46 +1000 Received: from d23dlp01.au.ibm.com (202.81.31.203) by e23smtp05.au.ibm.com (202.81.31.211) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Sat, 11 May 2013 04:42:44 +1000 Received: from d23relay03.au.ibm.com (d23relay03.au.ibm.com [9.190.235.21]) by d23dlp01.au.ibm.com (Postfix) with ESMTP id 5A9AC2CE804A for ; Sat, 11 May 2013 04:48:01 +1000 (EST) Received: from d23av03.au.ibm.com (d23av03.au.ibm.com [9.190.234.97]) by d23relay03.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r4AIlr8m23396538 for ; Sat, 11 May 2013 04:47:54 +1000 Received: from d23av03.au.ibm.com (loopback [127.0.0.1]) by d23av03.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r4AIlx1J008320 for ; Sat, 11 May 2013 04:48:00 +1000 Received: from titi.austin.rr.com (sig-9-48-118-123.mts.ibm.com [9.48.118.123]) by d23av03.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id r4AIluCS008230; Sat, 11 May 2013 04:47:57 +1000 From: Anthony Liguori To: qemu-devel@nongnu.org Date: Fri, 10 May 2013 13:47:55 -0500 Message-Id: <1368211675-2912-1-git-send-email-aliguori@us.ibm.com> X-Mailer: git-send-email 1.8.0 MIME-Version: 1.0 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13051018-1396-0000-0000-000002F3E317 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 202.81.31.147 Cc: Paolo Bonzini , Anthony Liguori , =?UTF-8?q?Andreas=20F=C3=A4rber?= , Aurelien Jarno Subject: [Qemu-devel] [PATCH for-1.5] qom: optimize casting to leaf class and parent class X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Most QOM types use type_register_static but we still strdup the passed data. However, the original pointers are useful because GCC is pretty good about collapsing strings so its very likely any use of the pointer will end up being that same address. IOW, with a little trickery, we can compare types by just comparing strings and in fact that's what we do here. We do this for the two most common cases, casting to a leaf class or to the parent class. With these two changes, I see a decrease from around 2 hash table lookups to only a thousand with no run time lookups at all. Cc: Paolo Bonzini Cc: Aurelien Jarno Cc: Andreas Färber Reported-by: Aurelien Jarno Signed-off-by: Anthony Liguori --- Aurelien, could you please try this patch with your PPC test case? --- qom/object.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/qom/object.c b/qom/object.c index 75e6aac..5ecfd28 100644 --- a/qom/object.c +++ b/qom/object.c @@ -132,7 +132,13 @@ TypeImpl *type_register(const TypeInfo *info) TypeImpl *type_register_static(const TypeInfo *info) { - return type_register(info); + TypeImpl *impl; + + impl = type_register(info); + impl->name = info->name; + impl->parent = info->parent; + + return impl; } static TypeImpl *type_get_by_name(const char *name) @@ -449,10 +455,16 @@ Object *object_dynamic_cast_assert(Object *obj, const char *typename) ObjectClass *object_class_dynamic_cast(ObjectClass *class, const char *typename) { - TypeImpl *target_type = type_get_by_name(typename); + TypeImpl *target_type; TypeImpl *type = class->type; ObjectClass *ret = NULL; + if (type->name == typename || type->parent == typename) { + return class; + } + + target_type = type_get_by_name(typename); + if (!target_type) { /* target class type unknown, so fail the cast */ return NULL;