[{"id":1766876,"web_url":"http://patchwork.ozlabs.org/comment/1766876/","msgid":"<7dc9925e-5a66-786b-6798-d42ad20b2d0a@de.ibm.com>","list_archive_url":null,"date":"2017-09-12T10:51:57","subject":"Re: [Qemu-devel] [PATCH v4 15/21] s390x: print CPU definitions in\n\tsorted order","submitter":{"id":590,"url":"http://patchwork.ozlabs.org/api/people/590/","name":"Christian Borntraeger","email":"borntraeger@de.ibm.com"},"content":"On 09/11/2017 05:21 PM, David Hildenbrand wrote:\n> Other architectures provide nicely sorted lists, let's do it similarly on\n> s390x.\n> \n> While at it, clean up the code we have to touch either way.\n> \n> Signed-off-by: David Hildenbrand <david@redhat.com>\n\nlooks much nicer now, with the most important ones (new ones) still on screen. \n\n\nAcked-by: Christian Borntraeger <borntraeger@de.ibm.com>\n\n\n> ---\n>  target/s390x/cpu_models.c | 56 ++++++++++++++++++++++++++++++++++-------------\n>  1 file changed, 41 insertions(+), 15 deletions(-)\n> \n> diff --git a/target/s390x/cpu_models.c b/target/s390x/cpu_models.c\n> index 8e20e7637b..c295e641e6 100644\n> --- a/target/s390x/cpu_models.c\n> +++ b/target/s390x/cpu_models.c\n> @@ -270,16 +270,11 @@ const S390CPUDef *s390_find_cpu_def(uint16_t type, uint8_t gen, uint8_t ec_ga,\n>      return last_compatible;\n>  }\n> \n> -struct S390PrintCpuListInfo {\n> -    FILE *f;\n> -    fprintf_function print;\n> -};\n> -\n> -static void print_cpu_model_list(ObjectClass *klass, void *opaque)\n> +static void s390_print_cpu_model_list_entry(gpointer data, gpointer user_data)\n>  {\n> -    struct S390PrintCpuListInfo *info = opaque;\n> -    S390CPUClass *scc = S390_CPU_CLASS(klass);\n> -    char *name = g_strdup(object_class_get_name(klass));\n> +    CPUListState *s = user_data;\n> +    const S390CPUClass *scc = S390_CPU_CLASS((ObjectClass *)data);\n> +    char *name = g_strdup(object_class_get_name((ObjectClass *)data));\n>      const char *details = \"\";\n> \n>      if (scc->is_static) {\n> @@ -290,21 +285,52 @@ static void print_cpu_model_list(ObjectClass *klass, void *opaque)\n> \n>      /* strip off the -s390-cpu */\n>      g_strrstr(name, \"-\" TYPE_S390_CPU)[0] = 0;\n> -    (*info->print)(info->f, \"s390 %-15s %-35s %s\\n\", name, scc->desc,\n> -                   details);\n> +    (*s->cpu_fprintf)(s->file, \"s390 %-15s %-35s %s\\n\", name, scc->desc,\n> +                      details);\n>      g_free(name);\n>  }\n> \n> +static gint s390_cpu_list_compare(gconstpointer a, gconstpointer b)\n> +{\n> +    const S390CPUClass *cc_a = S390_CPU_CLASS((ObjectClass *)a);\n> +    const S390CPUClass *cc_b = S390_CPU_CLASS((ObjectClass *)b);\n> +    const char *name_a = object_class_get_name((ObjectClass *)a);\n> +    const char *name_b = object_class_get_name((ObjectClass *)b);\n> +\n> +    /* move qemu and host to the top of the list, qemu first, host second */\n> +    if (name_a[0] == 'q') {\n> +        return -1;\n> +    } else if (name_b[0] == 'q') {\n> +        return 1;\n> +    } else if (name_a[0] == 'h') {\n> +        return -1;\n> +    } else if (name_b[0] == 'h') {\n> +        return 1;\n> +    }\n> +\n> +    /* keep the same order we have in our table (sorted by release date) */\n> +    if (cc_a->cpu_def != cc_b->cpu_def) {\n> +        return cc_a->cpu_def - cc_b->cpu_def;\n> +    }\n> +\n> +    /* exact same definition - list base model first */\n> +    return cc_a->is_static ? -1 : 1;\n> +}\n> +\n>  void s390_cpu_list(FILE *f, fprintf_function print)\n>  {\n> -    struct S390PrintCpuListInfo info = {\n> -        .f = f,\n> -        .print = print,\n> +    CPUListState s = {\n> +        .file = f,\n> +        .cpu_fprintf = print,\n>      };\n>      S390FeatGroup group;\n>      S390Feat feat;\n> +    GSList *list;\n> \n> -    object_class_foreach(print_cpu_model_list, TYPE_S390_CPU, false, &info);\n> +    list = object_class_get_list(TYPE_S390_CPU, false);\n> +    list = g_slist_sort(list, s390_cpu_list_compare);\n> +    g_slist_foreach(list, s390_print_cpu_model_list_entry, &s);\n> +    g_slist_free(list);\n> \n>      (*print)(f, \"\\nRecognized feature flags:\\n\");\n>      for (feat = 0; feat < S390_FEAT_MAX; feat++) {\n>","headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":"ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)","Received":["from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xs1pk1znXz9sRg\n\tfor <incoming@patchwork.ozlabs.org>;\n\tTue, 12 Sep 2017 20:52:46 +1000 (AEST)","from localhost ([::1]:34879 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1drio8-0008Bt-6t\n\tfor incoming@patchwork.ozlabs.org; Tue, 12 Sep 2017 06:52:44 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:43465)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <borntraeger@de.ibm.com>) id 1drina-00089k-69\n\tfor qemu-devel@nongnu.org; Tue, 12 Sep 2017 06:52:11 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <borntraeger@de.ibm.com>) id 1drinV-0002GO-6G\n\tfor qemu-devel@nongnu.org; Tue, 12 Sep 2017 06:52:10 -0400","from mx0a-001b2d01.pphosted.com ([148.163.156.1]:34680)\n\tby eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32)\n\t(Exim 4.71) (envelope-from <borntraeger@de.ibm.com>)\n\tid 1drinU-0002Fr-TY\n\tfor qemu-devel@nongnu.org; Tue, 12 Sep 2017 06:52:05 -0400","from pps.filterd (m0098396.ppops.net [127.0.0.1])\n\tby mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id\n\tv8CApp8J128872\n\tfor <qemu-devel@nongnu.org>; Tue, 12 Sep 2017 06:52:03 -0400","from e06smtp15.uk.ibm.com (e06smtp15.uk.ibm.com [195.75.94.111])\n\tby mx0a-001b2d01.pphosted.com with ESMTP id 2cxb829spw-1\n\t(version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT)\n\tfor <qemu-devel@nongnu.org>; Tue, 12 Sep 2017 06:52:03 -0400","from localhost\n\tby e06smtp15.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use\n\tOnly! Violators will be prosecuted\n\tfor <qemu-devel@nongnu.org> from <borntraeger@de.ibm.com>;\n\tTue, 12 Sep 2017 11:52:01 +0100","from b06cxnps4074.portsmouth.uk.ibm.com (9.149.109.196)\n\tby e06smtp15.uk.ibm.com (192.168.101.145) with IBM ESMTP SMTP\n\tGateway: Authorized Use Only! Violators will be prosecuted; \n\tTue, 12 Sep 2017 11:51:58 +0100","from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com\n\t[9.149.105.61])\n\tby b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with\n\tESMTP id v8CApvms25624582; Tue, 12 Sep 2017 10:51:57 GMT","from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1])\n\tby IMSVA (Postfix) with ESMTP id 0865A11C050;\n\tTue, 12 Sep 2017 11:48:11 +0100 (BST)","from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1])\n\tby IMSVA (Postfix) with ESMTP id AD55711C04A;\n\tTue, 12 Sep 2017 11:48:10 +0100 (BST)","from oc7330422307.ibm.com (unknown [9.152.224.40])\n\tby d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP;\n\tTue, 12 Sep 2017 11:48:10 +0100 (BST)"],"To":"David Hildenbrand <david@redhat.com>, qemu-devel@nongnu.org","References":"<20170911152150.12535-1-david@redhat.com>\n\t<20170911152150.12535-16-david@redhat.com>","From":"Christian Borntraeger <borntraeger@de.ibm.com>","Date":"Tue, 12 Sep 2017 12:51:57 +0200","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101\n\tThunderbird/52.2.0","MIME-Version":"1.0","In-Reply-To":"<20170911152150.12535-16-david@redhat.com>","Content-Type":"text/plain; charset=utf-8","Content-Language":"en-US","Content-Transfer-Encoding":"7bit","X-TM-AS-GCONF":"00","x-cbid":"17091210-0020-0000-0000-000003B751E3","X-IBM-AV-DETECTION":"SAVI=unused REMOTE=unused XFE=unused","x-cbparentid":"17091210-0021-0000-0000-00004248B8F6","Message-Id":"<7dc9925e-5a66-786b-6798-d42ad20b2d0a@de.ibm.com>","X-Proofpoint-Virus-Version":"vendor=fsecure engine=2.50.10432:, ,\n\tdefinitions=2017-09-12_04:, , signatures=0","X-Proofpoint-Spam-Details":"rule=outbound_notspam policy=outbound score=0\n\tspamscore=0 suspectscore=2\n\tmalwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam\n\tadjust=0 reason=mlx scancount=1 engine=8.0.1-1707230000\n\tdefinitions=main-1709120151","X-detected-operating-system":"by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy]","X-Received-From":"148.163.156.1","Subject":"Re: [Qemu-devel] [PATCH v4 15/21] s390x: print CPU definitions in\n\tsorted order","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"<qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<http://lists.nongnu.org/archive/html/qemu-devel/>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Cc":"Matthew Rosato <mjrosato@linux.vnet.ibm.com>, thuth@redhat.com,\n\tEduardo Habkost <ehabkost@redhat.com>, cohuck@redhat.com,\n\tRichard Henderson <richard.henderson@linaro.org>,\n\tAlexander Graf <agraf@suse.de>, Markus Armbruster <armbru@redhat.com>,\n\tPaolo Bonzini <pbonzini@redhat.com>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"}}]