[{"id":1768768,"web_url":"http://patchwork.ozlabs.org/comment/1768768/","msgid":"<4cb8e4a1-ea7f-bcdd-f50e-3467c6a2ac36@amsat.org>","list_archive_url":null,"date":"2017-09-14T18:19:21","subject":"Re: [Qemu-devel] [PATCH v2 3/5] vl.c: convert cpu_model to cpu type\n\tand set of global properties before machine_init()","submitter":{"id":70924,"url":"http://patchwork.ozlabs.org/api/people/70924/","name":"Philippe Mathieu-Daudé","email":"f4bug@amsat.org"},"content":"On 09/13/2017 01:04 PM, Igor Mammedov wrote:\n> All machines that support user specified cpu_model either call\n> cpu_generic_init() or cpu_class_by_name()/CPUClass::parse_features\n> to parse feature string and to get CPU type to create.\n> \n> Which leads to code duplication and hard-codding default CPU model\n> within machine_foo_init() code. Which makes it impossible to\n> get CPU type before machine_init() is run.\n> \n> So instead of setting default CPUs models and doing parsing in\n> target specific machine_foo_init() in various ways, provide\n> a generic data driven cpu_model parsing before machine_init()\n> is called.\n> \n> in follow up per target patches, it will allow to:\n>    * define default CPU type in consistent/generic manner\n>      per machine type and drop custom code that fallbacks\n>      to default if cpu_model is NULL\n>    * drop custom features parsing in targets and do it\n>      in centralized way.\n>    * for cases of\n>        cpu_generic_init(TYPE_BASE/DEFAULT_CPU, \"some_cpu\")\n>      replace it with\n>        cpu_create(machine->cpu_type) || cpu_create(TYPE_FOO)\n>      depending if CPU type is user settable or not.\n>      not doing useless parsing and clearly documenting where\n>      CPU model is user settable or fixed one.\n> \n> Patch allows machine subclasses to define default CPU type\n> per machine class at class_init() time and if that is set\n> generic code will parse cpu_model into a MachineState::cpu_type\n> which will be used to create CPUs for that machine instance\n> and allows gradual per board conversion.\n> \n> Signed-off-by: Igor Mammedov <imammedo@redhat.com>\n\nAcked-by: Philippe Mathieu-Daudé <f4bug@amsat.org>\n\n> ---\n> Target specific changes will split into separate per target/machine\n> patches to make changes reviewable.\n> ---\n>   include/hw/boards.h |  6 ++++++\n>   vl.c                | 10 ++++++++++\n>   2 files changed, 16 insertions(+)\n> \n> diff --git a/include/hw/boards.h b/include/hw/boards.h\n> index 7f044d1..6b67ada 100644\n> --- a/include/hw/boards.h\n> +++ b/include/hw/boards.h\n> @@ -125,6 +125,10 @@ typedef struct {\n>    *    Caller is responsible for freeing returned list.\n>    * @has_hotpluggable_cpus:\n>    *    If true, board supports CPUs creation with -device/device_add.\n> + * @default_cpu_type:\n> + *    specifies default CPU_TYPE, which will be used for parsing target\n> + *    specific features and for creating CPUs if CPU name wasn't provided\n> + *    explicitly at CLI\n>    * @minimum_page_bits:\n>    *    If non-zero, the board promises never to create a CPU with a page size\n>    *    smaller than this, so QEMU can use a more efficient larger page\n> @@ -177,6 +181,7 @@ struct MachineClass {\n>       GArray *compat_props;\n>       const char *hw_version;\n>       ram_addr_t default_ram_size;\n> +    const char *default_cpu_type;\n>       bool option_rom_has_mr;\n>       bool rom_file_has_mr;\n>       int minimum_page_bits;\n> @@ -231,6 +236,7 @@ struct MachineState {\n>       char *kernel_cmdline;\n>       char *initrd_filename;\n>       const char *cpu_model;\n> +    const char *cpu_type;\n>       AccelState *accelerator;\n>       CPUArchIdList *possible_cpus;\n>   };\n> diff --git a/vl.c b/vl.c\n> index fb1f05b..034180f 100644\n> --- a/vl.c\n> +++ b/vl.c\n> @@ -4636,6 +4636,16 @@ int main(int argc, char **argv, char **envp)\n>       current_machine->boot_order = boot_order;\n>       current_machine->cpu_model = cpu_model;\n>   \n> +\n> +    /* parse features once if machine provides default cpu_type */\n> +    if (machine_class->default_cpu_type) {\n> +        current_machine->cpu_type = machine_class->default_cpu_type;\n> +        if (cpu_model) {\n> +            current_machine->cpu_type =\n> +                cpu_parse_cpu_model(machine_class->default_cpu_type, cpu_model);\n> +        }\n> +    }\n> +\n>       machine_run_board_init(current_machine);\n>   \n>       realtime_init();\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>)","ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=gmail.com header.i=@gmail.com\n\theader.b=\"XCp4PupM\"; dkim-atps=neutral"],"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 3xtRdf3y8Lz9s7p\n\tfor <incoming@patchwork.ozlabs.org>;\n\tFri, 15 Sep 2017 04:19:50 +1000 (AEST)","from localhost ([::1]:49379 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 1dsYjs-0000RG-Kw\n\tfor incoming@patchwork.ozlabs.org; Thu, 14 Sep 2017 14:19:48 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:40267)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <philippe.mathieu.daude@gmail.com>)\n\tid 1dsYjY-0000Pa-CU\n\tfor qemu-devel@nongnu.org; Thu, 14 Sep 2017 14:19:29 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <philippe.mathieu.daude@gmail.com>)\n\tid 1dsYjV-0003tK-62\n\tfor qemu-devel@nongnu.org; Thu, 14 Sep 2017 14:19:28 -0400","from mail-qk0-x243.google.com ([2607:f8b0:400d:c09::243]:38186)\n\tby eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16)\n\t(Exim 4.71) (envelope-from <philippe.mathieu.daude@gmail.com>)\n\tid 1dsYjU-0003si-VJ\n\tfor qemu-devel@nongnu.org; Thu, 14 Sep 2017 14:19:25 -0400","by mail-qk0-x243.google.com with SMTP id c69so92340qke.5\n\tfor <qemu-devel@nongnu.org>; Thu, 14 Sep 2017 11:19:24 -0700 (PDT)","from [192.168.1.10] ([181.93.89.178])\n\tby smtp.gmail.com with ESMTPSA id\n\tk51sm11802558qtc.46.2017.09.14.11.19.22\n\t(version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\n\tThu, 14 Sep 2017 11:19:23 -0700 (PDT)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;\n\th=sender:subject:to:references:from:message-id:date:user-agent\n\t:mime-version:in-reply-to:content-language:content-transfer-encoding; \n\tbh=ftTuTLig50ScQtlnWxYncZVnuqNpiflwMnOfI65EDo4=;\n\tb=XCp4PupMLq7Z8gDrLct6dB3TWwqFpqsJEJg5tj9sRkeHuN7/mzHrwLvNmk35/hkaPD\n\tXuy/tdU2wVpZ97zrf1kMzDFXXWDR7TM0/8pOBSsdgSogSsgeX/H4h6FMTMJrHEqVJcp2\n\tDaUx1iTmg3HWt8KAGPxFFVk/29kwisAw4vca6r+M4SCKHuaXcXQ3+6auxO3nZJTwDp+2\n\tqtRz924QEFThCuxwJ9F5+2nN+tGpfg947UETlqBDhbJF7m1w1PzeS5nYwg63zrMMJx7o\n\tRn4Rw3XK0cMdeiRxsATKx8NJ4hpcto10G6WwzbaKqNOZnpP9EN8jbqMi+Xtba483fYtZ\n\tt/lg==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:sender:subject:to:references:from:message-id\n\t:date:user-agent:mime-version:in-reply-to:content-language\n\t:content-transfer-encoding;\n\tbh=ftTuTLig50ScQtlnWxYncZVnuqNpiflwMnOfI65EDo4=;\n\tb=qYtZNC9OFxh66Bkoij5AObGYCYzr9lyxbwO1HMkY6sgbEXf0PuN2ezU7sjwOUSKUqN\n\t9Q8EvbAocp08h8hZlhReuC8FSuC4hZyP4StfbMduTsVRDjbaDU3CuOLeUkwIhqNCff8R\n\tjC/aTnJMvFCnJlMGc7EiENysTcUk91sZY3OS09Fr+xaSlSUU3pAHdWbMoMlZe/X7Me7L\n\tW1rwzAUb82M6D+zYHYXcdopvPFfyXQhwv8F3kPWZEyTFxZQwyHc1IXoLfYJIiLwL7lu3\n\tLiMXY26pHBtF5TxdIyi9ha0I/OgUiAb+c/SQFcT4GRDBZ5k7BZPUkGEhFz5bpuqgZD/j\n\tM7SQ==","X-Gm-Message-State":"AHPjjUhpEflPml0O3vKmhl7H3fYFFoUiwrIgab2J0iKqCF4u+z2PFyml\n\tEdKe2kvFDuhrsF7h+bU=","X-Google-Smtp-Source":"AOwi7QBDCQd+t9mNfSdHkecxIIJj3okJIjORdNWc7JSFAKRV02tTycSSB0+2v+kHNBtMXS6p3JxDUw==","X-Received":"by 10.55.103.14 with SMTP id b14mr3950470qkc.267.1505413164054; \n\tThu, 14 Sep 2017 11:19:24 -0700 (PDT)","To":"Igor Mammedov <imammedo@redhat.com>, qemu-devel@nongnu.org","References":"<1505318697-77161-1-git-send-email-imammedo@redhat.com>\n\t<1505318697-77161-4-git-send-email-imammedo@redhat.com>","From":"=?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= <f4bug@amsat.org>","Message-ID":"<4cb8e4a1-ea7f-bcdd-f50e-3467c6a2ac36@amsat.org>","Date":"Thu, 14 Sep 2017 15:19:21 -0300","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101\n\tThunderbird/52.3.0","MIME-Version":"1.0","In-Reply-To":"<1505318697-77161-4-git-send-email-imammedo@redhat.com>","Content-Type":"text/plain; charset=utf-8; format=flowed","Content-Language":"en-US","Content-Transfer-Encoding":"8bit","X-detected-operating-system":"by eggs.gnu.org: Genre and OS details not\n\trecognized.","X-Received-From":"2607:f8b0:400d:c09::243","Subject":"Re: [Qemu-devel] [PATCH v2 3/5] vl.c: convert cpu_model to cpu type\n\tand set of global properties before machine_init()","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>","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>"}}]