Received: from eggs.gnu.org ([208.118.235.92]:34642) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TgfUO-0005nG-6s for qemu-devel@nongnu.org; Thu, 06 Dec 2012 12:44:01 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TgfUJ-0006n2-20 for qemu-devel@nongnu.org; Thu, 06 Dec 2012 12:44:00 -0500 Received: from mx1.redhat.com ([209.132.183.28]:52336) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TgfUI-0006mo-Q8 for qemu-devel@nongnu.org; Thu, 06 Dec 2012 12:43:54 -0500 Date: Thu, 6 Dec 2012 15:45:25 -0200 From: Eduardo Habkost Message-ID: <20121206174525.GV4255@otherpad.lan.raisama.net> References: <1351652644-18687-1-git-send-email-afaerber@suse.de> <1351652644-18687-4-git-send-email-afaerber@suse.de> <20121206153725.GH4986@otherpad.lan.raisama.net> <50C0BCF8.60504@suse.de> <50C0C1AC.40301@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <50C0C1AC.40301@suse.de> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH 3/7] target-alpha: Add support for -cpu ? List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Andreas =?iso-8859-1?Q?F=E4rber?= Cc: qemu-devel@nongnu.org, Anthony Liguori , rth@twiddle.net On Thu, Dec 06, 2012 at 05:02:52PM +0100, Andreas F=E4rber wrote: > Am 06.12.2012 16:42, schrieb Andreas F=E4rber: > > Am 06.12.2012 16:37, schrieb Eduardo Habkost: > >> On Wed, Oct 31, 2012 at 04:04:00AM +0100, Andreas F=E4rber wrote: > >>> Implement alphabetical listing of CPU subclasses. > >>> > >>> Signed-off-by: Andreas F=E4rber > >>> --- > >>> target-alpha/cpu.c | 41 ++++++++++++++++++++++++++++++++++++++++= + > >>> target-alpha/cpu.h | 4 +++- > >>> 2 Dateien ge=E4ndert, 44 Zeilen hinzugef=FCgt(+), 1 Zeile entfernt= (-) > >>> > >>> diff --git a/target-alpha/cpu.c b/target-alpha/cpu.c > >>> index e1a5739..ab25c44 100644 > >>> --- a/target-alpha/cpu.c > >>> +++ b/target-alpha/cpu.c > >>> @@ -23,6 +23,47 @@ > >>> #include "qemu-common.h" > >>> =20 > >>> =20 > >>> +typedef struct AlphaCPUListState { > >>> + fprintf_function cpu_fprintf; > >>> + FILE *file; > >>> +} AlphaCPUListState; > >>> + > >>> +/* Sort alphabetically by type name. */ > >>> +static gint alpha_cpu_list_compare(gconstpointer a, gconstpointer = b) > >>> +{ > >>> + ObjectClass *class_a =3D (ObjectClass *)a; > >>> + ObjectClass *class_b =3D (ObjectClass *)b; > >>> + const char *name_a, *name_b; > >>> + > >>> + name_a =3D object_class_get_name(class_a); > >>> + name_b =3D object_class_get_name(class_b); > >>> + return strcmp(name_a, name_b); > >>> +} > >>> + > >>> +static void alpha_cpu_list_entry(gpointer data, gpointer user_data= ) > >>> +{ > >>> + ObjectClass *oc =3D data; > >>> + AlphaCPUListState *s =3D user_data; > >>> + > >>> + (*s->cpu_fprintf)(s->file, " %s\n", > >>> + object_class_get_name(oc)); > >>> +} > >>> + > >>> +void alpha_cpu_list(FILE *f, fprintf_function cpu_fprintf) > >>> +{ > >>> + AlphaCPUListState s =3D { > >>> + .file =3D f, > >>> + .cpu_fprintf =3D cpu_fprintf, > >>> + }; > >>> + GSList *list; > >>> + > >>> + list =3D object_class_get_list(TYPE_ALPHA_CPU, false); > >>> + list =3D g_slist_sort(list, alpha_cpu_list_compare); > >>> + (*cpu_fprintf)(f, "Available CPUs:\n"); > >>> + g_slist_foreach(list, alpha_cpu_list_entry, &s); > >>> + g_slist_free(list); > >>> +} > >> > >> target-arm has very similar code. Isn't it better to first write a > >> common reusable function to list CPU models using the list of > >> subclasses, instead of adding very similar functions to all > >> architectures? > >=20 > > Most ordering functions vary slightly (target-arm for "any"). It woul= d > > be possible to generalize the struct and provide a wrapper with type = and > > callback arguments, >=20 > Just remembered Anthony being against callbacks in this context: >=20 > http://lists.gnu.org/archive/html/qemu-devel/2012-02/msg02944.html >=20 > The RFC was for specifically for implementing the CPU lists. So I used > g_slist_* instead as suggested, which duplicates a few lines FWIW. > If someone has suggestions how else to share more code, I'm all ears. We could simply reuse the existing arch_query_cpu_definitions() interface= to implement cpu_list(), and the target-specific arch_query_cpu_definitions(= ) could reorder the list any way it wants. The list could then be used for = both cpu_list() and the the QMP query-cpu-definitions command. If necessary, we can add a "description" field to CpuDefinitionInfo, so t= argets can optionally return a description of each CPU model, too (that's the ca= se for the current x86 cpu_list() output). =20 > Andreas >=20 > > but then again some functions add a header line like > > here, some don't, and some even hardcode some options like "host". Fo= r > > the targets that already had -cpu ? support before QOM I tried to kee= p > > output identical apart from possibly the order. > >=20 > > Andreas >=20 > --=20 > SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 N=FCrnberg, Germany > GF: Jeff Hawn, Jennifer Guild, Felix Imend=F6rffer; HRB 16746 AG N=FCrn= berg --=20 Eduardo