From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4AED4CD98C5 for ; Wed, 11 Oct 2023 03:30:10 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qqPu8-0004mq-MN; Tue, 10 Oct 2023 23:29:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qqPu6-0004l4-Fj for qemu-devel@nongnu.org; Tue, 10 Oct 2023 23:28:58 -0400 Received: from mail-ej1-x629.google.com ([2a00:1450:4864:20::629]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qqPu4-0006zH-Dm for qemu-devel@nongnu.org; Tue, 10 Oct 2023 23:28:58 -0400 Received: by mail-ej1-x629.google.com with SMTP id a640c23a62f3a-9b1ebc80d0aso1075068466b.0 for ; Tue, 10 Oct 2023 20:28:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696994934; x=1697599734; darn=nongnu.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=HBzh6cmR9bP8NGfM5wIAN0/yrJ14+owrdwmAF1l8nfw=; b=JHqJ01LTYFGCtMUwAm4I5qq4cVUa9LbfjXUq9OqKYwdEjVgR4m4esAVqdkz+bhYnri R/lsTelk6oD27o7G+LzDWxKAe521IyCEMQW3mFKQfgPGW4De8o3PiHsyEgZ/4Smea8RS ekFTJ/XvmSjcQI2E4zHu1SSkQqZz5dD6UTuH8VKYnCjJbZYdhScYpgvpMECSLbow82oE LiCtdFy7uYp/VYeKRfpQNtBSY9CfqmjJMgBfNDyDmt5tPNkHfrfBFRxkXAAKdSwCcfhw Bz4YDXRvPqosJeqKSixcfIWn/ZsUlAq6nfJtXdrySvshtWv0/sJLxBoRzo9QsvxO3WdD 7qZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696994934; x=1697599734; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=HBzh6cmR9bP8NGfM5wIAN0/yrJ14+owrdwmAF1l8nfw=; b=cCFSWowK/1WrsiCV/3bcqq8kl6NC6do2RhaiFINmahqhH4LvNX/Krkc26nhTbkvD1H vems4Sv88xnMnbA7Gxjj9NBGAAzTp/wXXz4+QIQ0AKCYmXUNSKjmKe1pT4lP0JfX8RAc AGCodQmDhduH2wNWK2lz6aE7t79R+QR9LQA1v0H5MaY1HNAybPcr7Gokn7CidqchNTyH IfMpAPd5tzirEUx2qlnTKyge3LIUatP2Xxr/TeeCL5OMEb15tOAfzDT9gpVnPEp1jSNL QMJ/9gTGPv6fLpJo0+OZaH9KeyYTwhmje/+Th6qzA/OV1j5IddIE887jjIStsqJxTa2X cr3A== X-Gm-Message-State: AOJu0Yy5KrDMLFvre0YkgPKpX9MKyhGpKmo3Wi2DXaCc1B6xWpWDbfzH b8jTJ3m4PHmHuE35uhmHPfIjhQ== X-Google-Smtp-Source: AGHT+IECc1y99idxfoWrlFnM9d9HJ0vosudzNOfJVXgacjeEvC68ADcvqGDxWAQuTmzRNraz8flyOg== X-Received: by 2002:a17:907:724b:b0:9b2:b9ff:dc35 with SMTP id ds11-20020a170907724b00b009b2b9ffdc35mr20067955ejc.70.1696994934156; Tue, 10 Oct 2023 20:28:54 -0700 (PDT) Received: from [192.168.69.115] (mdq11-h01-176-173-161-48.dsl.sta.abo.bbox.fr. [176.173.161.48]) by smtp.gmail.com with ESMTPSA id rn18-20020a170906d93200b0098ec690e6d7sm9218920ejb.73.2023.10.10.20.28.50 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 10 Oct 2023 20:28:53 -0700 (PDT) Message-ID: <676c81b6-ccaa-51a3-8d1a-65e71a7b2b92@linaro.org> Date: Wed, 11 Oct 2023 05:28:49 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: [PATCH 3/4] hw/cpu: Introduce CPUClass::cpu_resolving_type field Content-Language: en-US To: Gavin Shan , qemu-devel@nongnu.org, David Hildenbrand Cc: Chris Wulff , David Gibson , qemu-s390x@nongnu.org, Weiwei Li , qemu-arm@nongnu.org, Mark Cave-Ayland , Jiaxun Yang , Yoshinori Sato , Richard Henderson , Marcel Apfelbaum , Max Filippov , Nicholas Piggin , Eduardo Habkost , Ilya Leoshkevich , Bastian Koppelmann , Greg Kurz , "Edgar E. Iglesias" , qemu-ppc@nongnu.org, Daniel Henrique Barboza , Marek Vasut , Palmer Dabbelt , Michael Rolnik , Laurent Vivier , Peter Maydell , qemu-riscv@nongnu.org, Aurelien Jarno , Bin Meng , Xiaojuan Yang , Daniel Henrique Barboza , Aleksandar Rikalo , Artyom Tarasenko , Song Gao , Stafford Horne , Yanan Wang , Alistair Francis , Brian Cain , =?UTF-8?Q?C=c3=a9dric_Le_Goater?= , Thomas Huth , Liu Zhiwei References: <20230908112235.75914-1-philmd@linaro.org> <20230908112235.75914-4-philmd@linaro.org> <87cb0174-c652-aa44-be7c-49e78e0a5003@redhat.com> <35653f53-a977-02ea-28f6-6fe85b1efd5a@redhat.com> From: =?UTF-8?Q?Philippe_Mathieu-Daud=c3=a9?= In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2a00:1450:4864:20::629; envelope-from=philmd@linaro.org; helo=mail-ej1-x629.google.com X-Spam_score_int: -53 X-Spam_score: -5.4 X-Spam_bar: ----- X-Spam_report: (-5.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, NICE_REPLY_A=-3.339, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Hi Gavin, On 25/9/23 02:24, Gavin Shan wrote: > On 9/12/23 08:40, Gavin Shan wrote: >> On 9/11/23 19:43, Philippe Mathieu-Daudé wrote: >>> On 11/9/23 01:28, Gavin Shan wrote: >>>> On 9/8/23 21:22, Philippe Mathieu-Daudé wrote: >>>>> Add a field to return the QOM type name of a CPU class. >>>>> >>>>> Signed-off-by: Philippe Mathieu-Daudé >>>>> --- >>>>> diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h >>>>> index 129d179937..e469efd409 100644 >>>>> --- a/include/hw/core/cpu.h >>>>> +++ b/include/hw/core/cpu.h >>>>> @@ -100,6 +100,7 @@ struct SysemuCPUOps; >>>>>   /** >>>>>    * CPUClass: >>>>> + * @cpu_resolving_type: CPU QOM type name >>>>>    * @class_by_name: Callback to map -cpu command line model name >>>>> to an >>>>>    *                 instantiatable CPU type. >>>>>    * @parse_features: Callback to parse command line arguments. >>>>> @@ -148,6 +149,7 @@ struct CPUClass { >>>>>       DeviceClass parent_class; >>>>>       /*< public >*/ >>>>> +    const char *cpu_resolving_type; >>>>>       ObjectClass *(*class_by_name)(const char *cpu_model); >>>>>       void (*parse_features)(const char *typename, char *str, Error >>>>> **errp); >>>> >>>> The question is why not use CPU_RESOLVING_TYPE directly? It seems >>>> CPU_RESOLVING_TYPE >>>> is exactly what you want here. >>> >>> Unfortunately CPU_RESOLVING_TYPE is target-specific, we want >>> hw/core/cpu-common.c to be target-agnostic (build once for all >>> targets). This is particularly important in the context of >>> heterogeneous QEMU, where a single binary will be able to create >>> CPUs from different targets. >>> >> >> CPU_RESOLVING_TYPE and CPUClass::cpu_resolving_type is duplicate to >> each other. There are two options I can figure out to avoid the >> duplication. >> >> (a) move cpu_class_by_name() from hw/core/cpu-common.c to cpu.c, so that >>      CPU_RESOLVING_TYPE can be seen. cpu.c::list_cpus() is the example. >> >> (b) remove hw/core/cpu-common.c::cpu_calss_by_name() and squeeze its >>      logic to cpu.c::parse_cpu_option() since there are not too much >>      users for it. target/arm and target/s390 needs some tweaks so that >>      hw/core/cpu-common.c::cpu_calss_by_name() can be removed. >> >>      [gshan@gshan q]$ git grep \ cpu_class_by_name\( >>      cpu.c:    oc = cpu_class_by_name(CPU_RESOLVING_TYPE, >> model_pieces[0]); >>      target/arm/arm-qmp-cmds.c:    oc = >> cpu_class_by_name(TYPE_ARM_CPU, model->name); >>      target/s390x/cpu_models_sysemu.c:    oc = >> cpu_class_by_name(TYPE_S390_CPU, info->name); >> >> When option (b) is taken, this series to have the checks against @oc >> in hw/core/cpu-common.c::cpu_calss_by_name() becomes non-sense. Instead, >> we need the same (and complete) checks in CPUClass::class_by_name() for >> individual targets. Further more, an inline helper can be provided to do >> the check in CPUClass::class_by_name() for individual targets. >> >>     include/hw/core/cpu.h >> >>     static inline bool cpu_class_is_valid(ObjectClass *oc, const char >> *parent) >>     { >>         if (!object_class_dynamic_cast(oc, parent) || >>             object_class_is_abstract(oc)) { >>             return false; >>         } >> >>         return true; >>     } >> > > Since my series to make CPU type check unified depends on this series, > could > you please share your thoughts? If you don't have bandwidth for this, I can > improve the code based on your thoughts, and include your patches to my > series > so that they can be reviewed at once. Please just let me know. You seem to prove (b) is not useful, so we have to do (a). Unfortunately at this moment I feel hopeless with this topic. I don't want to delay your work further. If you find a way to integrate both series, please go ahead. Otherwise let's drop my approach and continue with your previous work. I apologize I kept you waiting that long. Regards, Phil.