From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35786) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UtB4P-0005LF-48 for qemu-devel@nongnu.org; Sun, 30 Jun 2013 02:25:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UtB4N-00062G-LB for qemu-devel@nongnu.org; Sun, 30 Jun 2013 02:25:09 -0400 Message-ID: <51CFCF3E.1020100@suse.de> Date: Sun, 30 Jun 2013 08:25:02 +0200 From: =?ISO-8859-15?Q?Andreas_F=E4rber?= MIME-Version: 1.0 References: <1372556709-23868-1-git-send-email-agraf@suse.de> <1372556709-23868-28-git-send-email-agraf@suse.de> In-Reply-To: <1372556709-23868-28-git-send-email-agraf@suse.de> Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH 27/32] PPC: Introduce an alias cache for faster lookups List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Alexander Graf Cc: Blue Swirl , qemu-ppc@nongnu.org, qemu-devel@nongnu.org, Aurelien Jarno Am 30.06.2013 03:45, schrieb Alexander Graf: > When running QEMU with "-cpu ?" we walk through every alias for every > target CPU we know about. This takes several seconds on my very fast > host system. >=20 > Let's introduce a class object cache in the alias table. Using that we > don't have to go through the tedious work of finding our target class. > Instead, we can just go directly from the alias name to the target clas= s > pointer. >=20 > This patch brings -cpu "?" to reasonable times again. >=20 > Before: > real 0m4.716s >=20 > After: > real 0m0.025s >=20 > Signed-off-by: Alexander Graf I had objected to this patch being not the right solution to the problem. > --- > target-ppc/cpu-models.c | 2 +- > target-ppc/cpu-models.h | 3 ++- > target-ppc/translate_init.c | 32 +++++++++++++++++++++++++++----- > 3 files changed, 30 insertions(+), 7 deletions(-) >=20 > diff --git a/target-ppc/cpu-models.c b/target-ppc/cpu-models.c > index 17f56b7..9bb68c8 100644 > --- a/target-ppc/cpu-models.c > +++ b/target-ppc/cpu-models.c > @@ -1227,7 +1227,7 @@ > /*********************************************************************= ******/ > /* PowerPC CPU aliases = */ > =20 > -const PowerPCCPUAlias ppc_cpu_aliases[] =3D { > +PowerPCCPUAlias ppc_cpu_aliases[] =3D { > { "403", "403GC" }, > { "405", "405D4" }, > { "405CR", "405CRc" }, > diff --git a/target-ppc/cpu-models.h b/target-ppc/cpu-models.h > index a94f835..262ca47 100644 > --- a/target-ppc/cpu-models.h > +++ b/target-ppc/cpu-models.h > @@ -31,9 +31,10 @@ > typedef struct PowerPCCPUAlias { > const char *alias; > const char *model; > + ObjectClass *klass; And please don't spread this deliberate misspelling. When I did, I was flamed and the solution was to use oc for ObjectClass, cc for CPUClass, etc. Your patch still keeps traversing the class list with O(n). > } PowerPCCPUAlias; > =20 > -extern const PowerPCCPUAlias ppc_cpu_aliases[]; > +extern PowerPCCPUAlias ppc_cpu_aliases[]; > =20 > /*********************************************************************= ********/ > /* PVR definitions for most known PowerPC = */ > diff --git a/target-ppc/translate_init.c b/target-ppc/translate_init.c > index f01e9e7..45b4053 100644 > --- a/target-ppc/translate_init.c > +++ b/target-ppc/translate_init.c > @@ -7934,6 +7934,28 @@ static gint ppc_cpu_compare_class_name(gconstpoi= nter a, gconstpointer b) > =20 > #include > =20 > +static ObjectClass *ppc_cpu_class_by_name(const char *name); > + > +static ObjectClass *ppc_cpu_class_by_alias(PowerPCCPUAlias *alias) > +{ > + ObjectClass *invalid_class =3D (void*)ppc_cpu_class_by_alias; > + > + /* Cache target class lookups in the alias table */ > + if (!alias->klass) { > + alias->klass =3D ppc_cpu_class_by_name(alias->model); > + if (!alias->klass) { > + /* Fast check for non-existing aliases */ > + alias->klass =3D invalid_class; > + } > + } > + > + if (alias->klass =3D=3D invalid_class) { > + return NULL; > + } else { > + return alias->klass; > + } > +} Instead of saving bogus values with meaning "no class" we should drop the ifdef'fery and make all types available. Our plan was to add one or more flags to PowerPCCPUClass. Andreas > + > static ObjectClass *ppc_cpu_class_by_name(const char *name) > { > GSList *list, *item; > @@ -7961,7 +7983,7 @@ static ObjectClass *ppc_cpu_class_by_name(const c= har *name) > =20 > for (i =3D 0; ppc_cpu_aliases[i].alias !=3D NULL; i++) { > if (strcmp(ppc_cpu_aliases[i].alias, name) =3D=3D 0) { > - return ppc_cpu_class_by_name(ppc_cpu_aliases[i].model); > + return ppc_cpu_class_by_alias(&ppc_cpu_aliases[i]); > } > } > =20 > @@ -8051,8 +8073,8 @@ static void ppc_cpu_list_entry(gpointer data, gpo= inter user_data) > (*s->cpu_fprintf)(s->file, "PowerPC %-16s PVR %08x\n", > name, pcc->pvr); > for (i =3D 0; ppc_cpu_aliases[i].alias !=3D NULL; i++) { > - const PowerPCCPUAlias *alias =3D &ppc_cpu_aliases[i]; > - ObjectClass *alias_oc =3D ppc_cpu_class_by_name(alias->model); > + PowerPCCPUAlias *alias =3D &ppc_cpu_aliases[i]; > + ObjectClass *alias_oc =3D ppc_cpu_class_by_alias(alias); > =20 > if (alias_oc !=3D oc) { > continue; > @@ -8119,12 +8141,12 @@ CpuDefinitionInfoList *arch_query_cpu_definitio= ns(Error **errp) > g_slist_free(list); > =20 > for (i =3D 0; ppc_cpu_aliases[i].alias !=3D NULL; i++) { > - const PowerPCCPUAlias *alias =3D &ppc_cpu_aliases[i]; > + PowerPCCPUAlias *alias =3D &ppc_cpu_aliases[i]; > ObjectClass *oc; > CpuDefinitionInfoList *entry; > CpuDefinitionInfo *info; > =20 > - oc =3D ppc_cpu_class_by_name(alias->model); > + oc =3D ppc_cpu_class_by_alias(alias); > if (oc =3D=3D NULL) { > continue; > } >=20 --=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