From patchwork Mon Nov 9 17:27:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudio Fontana X-Patchwork-Id: 11892035 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9375A139F for ; Mon, 9 Nov 2020 17:34:26 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 4EA812083B for ; Mon, 9 Nov 2020 17:34:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4EA812083B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:45490 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kcB3h-0000kD-84 for patchwork-qemu-devel@patchwork.kernel.org; Mon, 09 Nov 2020 12:34:25 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:38302) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kcAxo-0002ur-As for qemu-devel@nongnu.org; Mon, 09 Nov 2020 12:28:20 -0500 Received: from mx2.suse.de ([195.135.220.15]:56768) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kcAxm-0005SS-8R for qemu-devel@nongnu.org; Mon, 09 Nov 2020 12:28:19 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id E658AAD2D; Mon, 9 Nov 2020 17:28:06 +0000 (UTC) From: Claudio Fontana To: Paolo Bonzini , Thomas Huth , Richard Henderson , Stefano Stabellini , Wenchao Wang , Roman Bolshakov , Sunil Muthuswamy , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= Subject: [RFC v1 10/10] module: add priority to module_init Date: Mon, 9 Nov 2020 18:27:55 +0100 Message-Id: <20201109172755.16500-11-cfontana@suse.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201109172755.16500-1-cfontana@suse.de> References: <20201109172755.16500-1-cfontana@suse.de> MIME-Version: 1.0 Received-SPF: pass client-ip=195.135.220.15; envelope-from=cfontana@suse.de; helo=mx2.suse.de X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/08 21:17:38 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x (no timestamps) [generic] X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Eduardo Habkost , Paul Durrant , Jason Wang , Marcelo Tosatti , qemu-devel@nongnu.org, Peter Xu , Dario Faggioli , Cameron Esfahani , haxm-team@intel.com, Claudio Fontana , Anthony Perard , Bruce Rogers , Colin Xu Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" add a new version of module_init that also takes a priority argument, and use it to be able to run a constructor last for INIT_ACCEL_CPU, and thus avoid the manual work of keeping track how to conditionalize the generic x86 cpu models registration. Signed-off-by: Claudio Fontana --- include/qemu/module.h | 17 ++++++++++++++++- target/i386/cpu.c | 16 ++++++++++++---- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/include/qemu/module.h b/include/qemu/module.h index 485eda986a..1f4fac6791 100644 --- a/include/qemu/module.h +++ b/include/qemu/module.h @@ -30,6 +30,13 @@ static void __attribute__((constructor)) do_qemu_init_ ## function(void) \ { \ register_dso_module_init(function, type); \ } + +#define module_init_prio(function, type, prio) \ +static void __attribute__((constructor(prio))) do_qemu_init_ ## function(void) \ +{ \ + register_dso_module_init(function, type); \ +} + #else /* This should not be used directly. Use block_init etc. instead. */ #define module_init(function, type) \ @@ -37,6 +44,11 @@ static void __attribute__((constructor)) do_qemu_init_ ## function(void) \ { \ register_module_init(function, type); \ } +#define module_init_prio(function, type, prio) \ +static void __attribute__((constructor(prio))) do_qemu_init_ ## function(void) \ +{ \ + register_module_init(function, type); \ +} #endif typedef enum { @@ -55,7 +67,10 @@ typedef enum { #define block_init(function) module_init(function, MODULE_INIT_BLOCK) #define opts_init(function) module_init(function, MODULE_INIT_OPTS) #define type_init(function) module_init(function, MODULE_INIT_QOM) -#define accel_cpu_init(function) module_init(function, MODULE_INIT_ACCEL_CPU) +#define accel_cpu_init(function) \ + module_init_prio(function, MODULE_INIT_ACCEL_CPU, 101) +#define accel_cpu_init_last(function) \ + module_init_prio(function, MODULE_INIT_ACCEL_CPU, 65535) #define trace_init(function) module_init(function, MODULE_INIT_TRACE) #define xen_backend_init(function) module_init(function, \ MODULE_INIT_XEN_BACKEND) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index b547c9d39d..aeaebfde02 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -7050,8 +7050,16 @@ static TypeInfo x86_base_cpu_type_info = { */ void x86_cpu_register_cpu_models(const char *parent_type) { + static bool x86_cpu_models_registered; int i; + if (x86_cpu_models_registered) { + /* + * already registered by an accelerator-specific specialization + * of x86_cpu + */ + return; + } for (i = 0; i < ARRAY_SIZE(builtin_x86_defs); i++) { x86_register_cpudef(&builtin_x86_defs[i], parent_type); } @@ -7060,6 +7068,8 @@ void x86_cpu_register_cpu_models(const char *parent_type) x86_base_cpu_type_info.parent = parent_type; type_register(&x86_base_cpu_type_info); + + x86_cpu_models_registered = true; } static void x86_cpu_register_base_type(void) @@ -7077,9 +7087,7 @@ static void x86_cpu_type_init(void) /* * I would like something better than this check. */ - if (!tcg_enabled() && !kvm_enabled() && !hvf_enabled()) { - x86_cpu_register_cpu_models(TYPE_X86_CPU); - } + x86_cpu_register_cpu_models(TYPE_X86_CPU); } -accel_cpu_init(x86_cpu_type_init); +accel_cpu_init_last(x86_cpu_type_init);