From patchwork Thu Nov 30 14:41:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhao Liu X-Patchwork-Id: 13474529 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="exK3TbKc" Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5778F85 for ; Thu, 30 Nov 2023 06:36:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701354999; x=1732890999; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=lndGadsp6lchipVix45sBuugJYcXf54DoIQPmPepLjo=; b=exK3TbKcCs0owewPv/WFz2vsMLYUmyYVEKIyhJFkeGt/8DTAJjQbAF6I +8fJzfd+eyeCnnZWxFgCNDG9Fhppf5tOhm1Jww6p18kB9kZ15sfx3f3za hOJ5J+0y5FisNJttHJe9/zPrOmMBMz4l7wmzVVM01QH6hIx+uUEHQ8B1k Jw229EED8E8JwdApsUkp1OU3vAUH5W6YdJuNjb9ymwC6yHxrdT3+6r89p ca9EgBOe2CLTnHse9nnPKp3BmVHXzOGQtmMg4YdgL1B6rvzyH7Vy+UBnY K3N+TPkK9ZzLTBWtvmra3oFnYSH1qxGhfof1mB3JaygykfeowSEHkGuez g==; X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="479532681" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="479532681" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2023 06:36:24 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10910"; a="942730506" X-IronPort-AV: E=Sophos;i="6.04,239,1695711600"; d="scan'208";a="942730506" Received: from liuzhao-optiplex-7080.sh.intel.com ([10.239.160.36]) by orsmga005.jf.intel.com with ESMTP; 30 Nov 2023 06:36:14 -0800 From: Zhao Liu To: Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_M?= =?utf-8?q?athieu-Daud=C3=A9?= , Eduardo Habkost , Marcel Apfelbaum , Yanan Wang , Richard Henderson , "Michael S . Tsirkin" , Jason Wang , Nicholas Piggin , Daniel Henrique Barboza , Igor Mammedov , =?utf-8?q?C=C3=A9dric_Le_Goater?= , =?utf-8?b?RnLDqWTDqXJp?= =?utf-8?b?YyBCYXJyYXQ=?= , David Gibson , Harsh Prateek Bora , Stefano Stabellini , Anthony Perard , Paul Durrant , Gerd Hoffmann , Peter Maydell , Alistair Francis , "Edgar E . Iglesias" , =?utf-8?q?Daniel_P_=2E_Ber?= =?utf-8?q?rang=C3=A9?= , Bin Meng , Palmer Dabbelt , Weiwei Li , Liu Zhiwei , qemu-devel@nongnu.org, kvm@vger.kernel.org, qemu-ppc@nongnu.org, xen-devel@lists.xenproject.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org Cc: Nina Schoetterl-Glausch , Thomas Huth , Zhiyuan Lv , Zhenyu Wang , Yongwei Ma , Zhao Liu Subject: [RFC 37/41] hw/i386: Allow i386 to create new CPUs from QOM topology Date: Thu, 30 Nov 2023 22:41:59 +0800 Message-Id: <20231130144203.2307629-38-zhao1.liu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> References: <20231130144203.2307629-1-zhao1.liu@linux.intel.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Zhao Liu For QOM topology, maximum number of CPUs and the number of plugged CPUs are configured in core level. Iterate through all the cpu-cores to determine how many CPUs should be created in each cpu-core. Signed-off-by: Zhao Liu --- hw/i386/x86.c | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/hw/i386/x86.c b/hw/i386/x86.c index 3c99f4c3ab51..febffed92a83 100644 --- a/hw/i386/x86.c +++ b/hw/i386/x86.c @@ -152,9 +152,35 @@ void x86_cpus_init(X86MachineState *x86ms, int default_cpu_version) } possible_cpus = mc->possible_cpu_arch_ids(ms); - for (i = 0; i < ms->smp.cpus; i++) { - x86_cpu_new(x86ms, possible_cpus->cpus[i].arch_id, - NULL, i, &error_fatal); + + /* + * possible_cpus_qom_granu means the QOM topology support. + * + * TODO: Drop the "!mc->smp_props.possible_cpus_qom_granu" case when + * i386 completes QOM topology support. + */ + if (mc->smp_props.possible_cpus_qom_granu) { + CPUCore *core; + int cpu_index = 0; + int core_idx = 0; + + MACHINE_CORE_FOREACH(ms, core) { + for (i = 0; i < core->plugged_threads; i++) { + x86_cpu_new(x86ms, possible_cpus->cpus[cpu_index].arch_id, + OBJECT(core), cpu_index, &error_fatal); + cpu_index++; + } + + if (core->plugged_threads < core->nr_threads) { + cpu_index += core->nr_threads - core->plugged_threads; + } + core_idx++; + } + } else { + for (i = 0; i < ms->smp.cpus; i++) { + x86_cpu_new(x86ms, possible_cpus->cpus[i].arch_id, + NULL, i, &error_fatal); + } } }