From: "Andreas Färber" <afaerber@suse.de>
To: Alexander Graf <agraf@suse.de>
Cc: Blue Swirl <blauwirbel@gmail.com>,
qemu-ppc@nongnu.org, qemu-devel@nongnu.org,
Aurelien Jarno <aurelien@aurel32.net>
Subject: Re: [Qemu-devel] [PATCH 27/32] PPC: Introduce an alias cache for faster lookups
Date: Sun, 30 Jun 2013 08:25:02 +0200 [thread overview]
Message-ID: <51CFCF3E.1020100@suse.de> (raw)
In-Reply-To: <1372556709-23868-28-git-send-email-agraf@suse.de>
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.
>
> 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 class
> pointer.
>
> This patch brings -cpu "?" to reasonable times again.
>
> Before:
> real 0m4.716s
>
> After:
> real 0m0.025s
>
> Signed-off-by: Alexander Graf <agraf@suse.de>
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(-)
>
> 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 */
>
> -const PowerPCCPUAlias ppc_cpu_aliases[] = {
> +PowerPCCPUAlias ppc_cpu_aliases[] = {
> { "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;
>
> -extern const PowerPCCPUAlias ppc_cpu_aliases[];
> +extern PowerPCCPUAlias ppc_cpu_aliases[];
>
> /*****************************************************************************/
> /* 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(gconstpointer a, gconstpointer b)
>
> #include <ctype.h>
>
> +static ObjectClass *ppc_cpu_class_by_name(const char *name);
> +
> +static ObjectClass *ppc_cpu_class_by_alias(PowerPCCPUAlias *alias)
> +{
> + ObjectClass *invalid_class = (void*)ppc_cpu_class_by_alias;
> +
> + /* Cache target class lookups in the alias table */
> + if (!alias->klass) {
> + alias->klass = ppc_cpu_class_by_name(alias->model);
> + if (!alias->klass) {
> + /* Fast check for non-existing aliases */
> + alias->klass = invalid_class;
> + }
> + }
> +
> + if (alias->klass == 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 char *name)
>
> for (i = 0; ppc_cpu_aliases[i].alias != NULL; i++) {
> if (strcmp(ppc_cpu_aliases[i].alias, name) == 0) {
> - return ppc_cpu_class_by_name(ppc_cpu_aliases[i].model);
> + return ppc_cpu_class_by_alias(&ppc_cpu_aliases[i]);
> }
> }
>
> @@ -8051,8 +8073,8 @@ static void ppc_cpu_list_entry(gpointer data, gpointer user_data)
> (*s->cpu_fprintf)(s->file, "PowerPC %-16s PVR %08x\n",
> name, pcc->pvr);
> for (i = 0; ppc_cpu_aliases[i].alias != NULL; i++) {
> - const PowerPCCPUAlias *alias = &ppc_cpu_aliases[i];
> - ObjectClass *alias_oc = ppc_cpu_class_by_name(alias->model);
> + PowerPCCPUAlias *alias = &ppc_cpu_aliases[i];
> + ObjectClass *alias_oc = ppc_cpu_class_by_alias(alias);
>
> if (alias_oc != oc) {
> continue;
> @@ -8119,12 +8141,12 @@ CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp)
> g_slist_free(list);
>
> for (i = 0; ppc_cpu_aliases[i].alias != NULL; i++) {
> - const PowerPCCPUAlias *alias = &ppc_cpu_aliases[i];
> + PowerPCCPUAlias *alias = &ppc_cpu_aliases[i];
> ObjectClass *oc;
> CpuDefinitionInfoList *entry;
> CpuDefinitionInfo *info;
>
> - oc = ppc_cpu_class_by_name(alias->model);
> + oc = ppc_cpu_class_by_alias(alias);
> if (oc == NULL) {
> continue;
> }
>
--
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
next prev parent reply other threads:[~2013-06-30 6:25 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-30 1:44 [Qemu-devel] [PULL 00/32] ppc patch queue 2013-06-30 Alexander Graf
2013-06-30 1:44 ` [Qemu-devel] [PATCH 01/32] KVM: Don't assume that mpstate exists with in-kernel PIC always Alexander Graf
2013-06-30 1:44 ` [Qemu-devel] [PATCH 02/32] KVM: Export kvm_init_irq_routing Alexander Graf
2013-06-30 1:44 ` [Qemu-devel] [PATCH 03/32] KVM: MSI: Swap payload to native endianness Alexander Graf
2013-06-30 1:44 ` [Qemu-devel] [PATCH 04/32] openpic: factor out some common defines into openpic.h Alexander Graf
2013-06-30 1:44 ` [Qemu-devel] [PATCH 05/32] PPC: e500: factor out mpic init code Alexander Graf
2013-06-30 1:44 ` [Qemu-devel] [PATCH 06/32] KVM: PIC: Only commit irq routing when necessary Alexander Graf
2013-06-30 1:44 ` [Qemu-devel] [PATCH 07/32] PPC: Add non-kvm stub file Alexander Graf
2013-06-30 1:44 ` [Qemu-devel] [PATCH 08/32] kvm/openpic: in-kernel mpic support Alexander Graf
2013-06-30 6:13 ` Andreas Färber
2013-06-30 23:01 ` Alexander Graf
2013-06-30 23:18 ` Andreas Färber
2013-07-01 11:17 ` Andreas Färber
2013-06-30 1:44 ` [Qemu-devel] [PATCH 09/32] intc/openpic: QOM'ify Alexander Graf
2013-06-30 1:44 ` [Qemu-devel] [PATCH 10/32] intc/openpic: Convert to QOM realize Alexander Graf
2013-06-30 1:44 ` [Qemu-devel] [PATCH 11/32] intc/openpic_kvm: Fix QOM and build issues Alexander Graf
2013-06-30 1:44 ` [Qemu-devel] [PATCH 12/32] mpc8544_guts: Fix MemoryRegion name Alexander Graf
2013-06-30 1:44 ` [Qemu-devel] [PATCH 13/32] mpc8544_guts: QOM'ify Alexander Graf
2013-06-30 1:44 ` [Qemu-devel] [PATCH 14/32] mpc8544_guts: Turn qdev initfn into instance_init Alexander Graf
2013-06-30 1:44 ` [Qemu-devel] [PATCH 15/32] target-ppc: Drop redundant flags assignments from CPU families Alexander Graf
2013-06-30 1:44 ` [Qemu-devel] [PATCH 16/32] ppc: do not register IABR SPR twice for 603e Alexander Graf
2013-06-30 1:44 ` [Qemu-devel] [PATCH 17/32] target-ppc: Change default machine for 64-bit Alexander Graf
2013-06-30 1:44 ` [Qemu-devel] [PATCH 18/32] spapr-rtas: add CPU argument to RTAS calls Alexander Graf
2013-06-30 1:44 ` [Qemu-devel] [PATCH 19/32] pseries: Fix compiler warning (conversion of pointer to integral value) Alexander Graf
2013-06-30 1:44 ` [Qemu-devel] [PATCH 20/32] target-ppc kvm: save cr register Alexander Graf
2013-06-30 1:44 ` [Qemu-devel] [PATCH 21/32] pseries: Update MAINTAINERS information Alexander Graf
2013-06-30 1:44 ` [Qemu-devel] [PATCH 22/32] Graphics: Switch to 800x600x32 as default mode Alexander Graf
2013-06-30 1:45 ` [Qemu-devel] [PATCH 23/32] booke_ppc: limit booke timer to max when timeout overflow Alexander Graf
2013-06-30 1:45 ` [Qemu-devel] [PATCH 24/32] target-ppc: Introduce unrealizefn for PowerPCCPU Alexander Graf
2013-06-30 1:45 ` [Qemu-devel] [PATCH 25/32] PPC: Add dump_mmu() for 6xx Alexander Graf
2013-06-30 1:45 ` [Qemu-devel] [PATCH 26/32] PPC: Fix GDB read on code area for PPC6xx Alexander Graf
2013-06-30 1:45 ` [Qemu-devel] [PATCH 27/32] PPC: Introduce an alias cache for faster lookups Alexander Graf
2013-06-30 6:25 ` Andreas Färber [this message]
2013-06-30 23:08 ` Alexander Graf
2013-06-30 1:45 ` [Qemu-devel] [PATCH 28/32] PPC: Add clock-frequency export for Mac machines Alexander Graf
2013-06-30 1:45 ` [Qemu-devel] [PATCH 29/32] PPC: Newworld: Add uninorth token register Alexander Graf
2013-06-30 1:45 ` [Qemu-devel] [PATCH 30/32] PPC: Newworld: Add second uninorth control register set Alexander Graf
2013-06-30 1:45 ` [Qemu-devel] [PATCH 31/32] mac-io: Add escc-legacy memory alias region Alexander Graf
2013-06-30 1:45 ` [Qemu-devel] [PATCH 32/32] PPC: Ignore writes to L2CR Alexander Graf
2013-09-06 12:54 ` Julio Guerra
2013-09-25 13:00 ` Alexander Graf
2013-09-25 13:40 ` Julio Guerra
2013-06-30 23:14 ` [Qemu-devel] [Qemu-ppc] [PULL 00/32] ppc patch queue 2013-06-30 Alexander Graf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=51CFCF3E.1020100@suse.de \
--to=afaerber@suse.de \
--cc=agraf@suse.de \
--cc=aurelien@aurel32.net \
--cc=blauwirbel@gmail.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).