From: Eduardo Habkost <ehabkost@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>,
qemu-devel@nongnu.org,
Marcel Apfelbaum <marcel.apfelbaum@gmail.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
Like Xu <like.xu@linux.intel.com>,
Richard Henderson <rth@twiddle.net>
Subject: [Qemu-devel] [PULL 07/29] hw/i386: Replace global smp variables with machine smp properties
Date: Thu, 27 Jun 2019 22:55:44 -0300 [thread overview]
Message-ID: <20190628015606.32107-8-ehabkost@redhat.com> (raw)
In-Reply-To: <20190628015606.32107-1-ehabkost@redhat.com>
From: Like Xu <like.xu@linux.intel.com>
The global smp variables in i386 are replaced with smp machine properties.
To avoid calling qdev_get_machine() as much as possible, some related funtions
for acpi data generations are refactored. No semantic changes.
A local variable of the same name would be introduced in the declaration
phase if it's used widely in the context OR replace it on the spot if it's
only used once. No semantic changes.
Signed-off-by: Like Xu <like.xu@linux.intel.com>
Message-Id: <20190518205428.90532-8-like.xu@linux.intel.com>
Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
hw/i386/acpi-build.c | 11 +++++++----
hw/i386/kvmvapic.c | 7 +++++--
hw/i386/pc.c | 24 +++++++++++++++---------
hw/i386/xen/xen-hvm.c | 4 ++++
target/i386/cpu.c | 4 +++-
5 files changed, 34 insertions(+), 16 deletions(-)
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 8ae7d88b11..d281ffa89e 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -43,6 +43,7 @@
#include "sysemu/tpm.h"
#include "hw/acpi/tpm.h"
#include "hw/acpi/vmgenid.h"
+#include "hw/boards.h"
#include "sysemu/tpm_backend.h"
#include "hw/timer/mc146818rtc_regs.h"
#include "hw/mem/memory-device.h"
@@ -123,7 +124,8 @@ typedef struct FwCfgTPMConfig {
static bool acpi_get_mcfg(AcpiMcfgInfo *mcfg);
-static void init_common_fadt_data(Object *o, AcpiFadtData *data)
+static void init_common_fadt_data(MachineState *ms, Object *o,
+ AcpiFadtData *data)
{
uint32_t io = object_property_get_uint(o, ACPI_PM_PROP_PM_IO_BASE, NULL);
AmlAddressSpace as = AML_AS_SYSTEM_IO;
@@ -139,7 +141,8 @@ static void init_common_fadt_data(Object *o, AcpiFadtData *data)
* CPUs for more than 8 CPUs, "Clustered Logical" mode has to be
* used
*/
- ((max_cpus > 8) ? (1 << ACPI_FADT_F_FORCE_APIC_CLUSTER_MODEL) : 0),
+ ((ms->smp.max_cpus > 8) ?
+ (1 << ACPI_FADT_F_FORCE_APIC_CLUSTER_MODEL) : 0),
.int_model = 1 /* Multiple APIC */,
.rtc_century = RTC_CENTURY,
.plvl2_lat = 0xfff /* C2 state not supported */,
@@ -173,7 +176,7 @@ static Object *object_resolve_type_unambiguous(const char *typename)
return o;
}
-static void acpi_get_pm_info(AcpiPmInfo *pm)
+static void acpi_get_pm_info(MachineState *machine, AcpiPmInfo *pm)
{
Object *piix = object_resolve_type_unambiguous(TYPE_PIIX4_PM);
Object *lpc = object_resolve_type_unambiguous(TYPE_ICH9_LPC_DEVICE);
@@ -2612,7 +2615,7 @@ void acpi_build(AcpiBuildTables *tables, MachineState *machine)
AcpiSlicOem slic_oem = { .id = NULL, .table_id = NULL };
Object *vmgenid_dev;
- acpi_get_pm_info(&pm);
+ acpi_get_pm_info(machine, &pm);
acpi_get_misc_info(&misc);
acpi_get_pci_holes(&pci_hole, &pci_hole64);
acpi_get_slic_oem(&slic_oem);
diff --git a/hw/i386/kvmvapic.c b/hw/i386/kvmvapic.c
index ca8df462b6..9c2ab4aac5 100644
--- a/hw/i386/kvmvapic.c
+++ b/hw/i386/kvmvapic.c
@@ -18,6 +18,7 @@
#include "sysemu/kvm.h"
#include "hw/i386/apic_internal.h"
#include "hw/sysbus.h"
+#include "hw/boards.h"
#include "tcg/tcg.h"
#define VAPIC_IO_PORT 0x7e
@@ -442,11 +443,12 @@ static void do_patch_instruction(CPUState *cs, run_on_cpu_data data)
static void patch_instruction(VAPICROMState *s, X86CPU *cpu, target_ulong ip)
{
+ MachineState *ms = MACHINE(qdev_get_machine());
CPUState *cs = CPU(cpu);
VAPICHandlers *handlers;
PatchInfo *info;
- if (smp_cpus == 1) {
+ if (ms->smp.cpus == 1) {
handlers = &s->rom_state.up;
} else {
handlers = &s->rom_state.mp;
@@ -747,6 +749,7 @@ static void do_vapic_enable(CPUState *cs, run_on_cpu_data data)
static void kvmvapic_vm_state_change(void *opaque, int running,
RunState state)
{
+ MachineState *ms = MACHINE(qdev_get_machine());
VAPICROMState *s = opaque;
uint8_t *zero;
@@ -755,7 +758,7 @@ static void kvmvapic_vm_state_change(void *opaque, int running,
}
if (s->state == VAPIC_ACTIVE) {
- if (smp_cpus == 1) {
+ if (ms->smp.cpus == 1) {
run_on_cpu(first_cpu, do_vapic_enable, RUN_ON_CPU_HOST_PTR(s));
} else {
zero = g_malloc0(s->rom_state.vapic_size);
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index da1cdd6853..73de30cc20 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -928,12 +928,14 @@ void enable_compat_apic_id_mode(void)
* no concept of "CPU index", and the NUMA tables on fw_cfg need the APIC ID of
* all CPUs up to max_cpus.
*/
-static uint32_t x86_cpu_apic_id_from_index(unsigned int cpu_index)
+static uint32_t x86_cpu_apic_id_from_index(MachineState *ms,
+ unsigned int cpu_index)
{
uint32_t correct_id;
static bool warned;
- correct_id = x86_apicid_from_cpu_idx(smp_cores, smp_threads, cpu_index);
+ correct_id = x86_apicid_from_cpu_idx(ms->smp.cores,
+ ms->smp.threads, cpu_index);
if (compat_apic_id_mode) {
if (cpu_index != correct_id && !warned && !qtest_enabled()) {
error_report("APIC IDs set in compatibility mode, "
@@ -1532,7 +1534,7 @@ static void pc_new_cpu(const char *typename, int64_t apic_id, Error **errp)
void pc_hot_add_cpu(MachineState *ms, const int64_t id, Error **errp)
{
- int64_t apic_id = x86_cpu_apic_id_from_index(id);
+ int64_t apic_id = x86_cpu_apic_id_from_index(ms, id);
Error *local_err = NULL;
if (id < 0) {
@@ -1568,9 +1570,10 @@ void pc_cpus_init(PCMachineState *pcms)
*
* This is used for FW_CFG_MAX_CPUS. See comments on bochs_bios_init().
*/
- pcms->apic_id_limit = x86_cpu_apic_id_from_index(max_cpus - 1) + 1;
+ pcms->apic_id_limit = x86_cpu_apic_id_from_index(ms,
+ ms->smp.max_cpus - 1) + 1;
possible_cpus = mc->possible_cpu_arch_ids(ms);
- for (i = 0; i < smp_cpus; i++) {
+ for (i = 0; i < ms->smp.cpus; i++) {
pc_new_cpu(possible_cpus->cpus[i].type, possible_cpus->cpus[i].arch_id,
&error_fatal);
}
@@ -2294,6 +2297,8 @@ static void pc_cpu_pre_plug(HotplugHandler *hotplug_dev,
X86CPU *cpu = X86_CPU(dev);
MachineState *ms = MACHINE(hotplug_dev);
PCMachineState *pcms = PC_MACHINE(hotplug_dev);
+ unsigned int smp_cores = ms->smp.cores;
+ unsigned int smp_threads = ms->smp.threads;
if(!object_dynamic_cast(OBJECT(cpu), ms->cpu_type)) {
error_setg(errp, "Invalid CPU type, expected cpu type: '%s'",
@@ -2303,7 +2308,7 @@ static void pc_cpu_pre_plug(HotplugHandler *hotplug_dev,
/* if APIC ID is not set, set it based on socket/core/thread properties */
if (cpu->apic_id == UNASSIGNED_APIC_ID) {
- int max_socket = (max_cpus - 1) / smp_threads / smp_cores;
+ int max_socket = (ms->smp.max_cpus - 1) / smp_threads / smp_cores;
if (cpu->socket_id < 0) {
error_setg(errp, "CPU socket-id is not set");
@@ -2653,13 +2658,14 @@ static int64_t pc_get_default_cpu_node_id(const MachineState *ms, int idx)
assert(idx < ms->possible_cpus->len);
x86_topo_ids_from_apicid(ms->possible_cpus->cpus[idx].arch_id,
- smp_cores, smp_threads, &topo);
+ ms->smp.cores, ms->smp.threads, &topo);
return topo.pkg_id % nb_numa_nodes;
}
static const CPUArchIdList *pc_possible_cpu_arch_ids(MachineState *ms)
{
int i;
+ unsigned int max_cpus = ms->smp.max_cpus;
if (ms->possible_cpus) {
/*
@@ -2678,9 +2684,9 @@ static const CPUArchIdList *pc_possible_cpu_arch_ids(MachineState *ms)
ms->possible_cpus->cpus[i].type = ms->cpu_type;
ms->possible_cpus->cpus[i].vcpus_count = 1;
- ms->possible_cpus->cpus[i].arch_id = x86_cpu_apic_id_from_index(i);
+ ms->possible_cpus->cpus[i].arch_id = x86_cpu_apic_id_from_index(ms, i);
x86_topo_ids_from_apicid(ms->possible_cpus->cpus[i].arch_id,
- smp_cores, smp_threads, &topo);
+ ms->smp.cores, ms->smp.threads, &topo);
ms->possible_cpus->cpus[i].props.has_socket_id = true;
ms->possible_cpus->cpus[i].props.socket_id = topo.pkg_id;
ms->possible_cpus->cpus[i].props.has_core_id = true;
diff --git a/hw/i386/xen/xen-hvm.c b/hw/i386/xen/xen-hvm.c
index 2939122e7c..941bd25e66 100644
--- a/hw/i386/xen/xen-hvm.c
+++ b/hw/i386/xen/xen-hvm.c
@@ -750,6 +750,8 @@ static ioreq_t *cpu_get_ioreq_from_shared_memory(XenIOState *state, int vcpu)
/* retval--the number of ioreq packet */
static ioreq_t *cpu_get_ioreq(XenIOState *state)
{
+ MachineState *ms = MACHINE(qdev_get_machine());
+ unsigned int max_cpus = ms->smp.max_cpus;
int i;
evtchn_port_t port;
@@ -1377,6 +1379,8 @@ static int xen_map_ioreq_server(XenIOState *state)
void xen_hvm_init(PCMachineState *pcms, MemoryRegion **ram_memory)
{
+ MachineState *ms = MACHINE(pcms);
+ unsigned int max_cpus = ms->smp.max_cpus;
int i, rc;
xen_pfn_t ioreq_pfn;
XenIOState *state;
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index da6eb67cfb..78830d403a 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -56,6 +56,7 @@
#include "hw/hw.h"
#include "hw/xen/xen.h"
#include "hw/i386/apic_internal.h"
+#include "hw/boards.h"
#endif
#include "disas/capstone.h"
@@ -5384,9 +5385,10 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
}
#ifndef CONFIG_USER_ONLY
+ MachineState *ms = MACHINE(qdev_get_machine());
qemu_register_reset(x86_cpu_machine_reset_cb, cpu);
- if (cpu->env.features[FEAT_1_EDX] & CPUID_APIC || smp_cpus > 1) {
+ if (cpu->env.features[FEAT_1_EDX] & CPUID_APIC || ms->smp.cpus > 1) {
x86_cpu_apic_create(cpu, &local_err);
if (local_err != NULL) {
goto out;
--
2.18.0.rc1.1.g3f1ff2140
next prev parent reply other threads:[~2019-06-28 2:11 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-28 1:55 [Qemu-devel] [PULL 00/29] Machine next patches Eduardo Habkost
2019-06-28 1:55 ` [Qemu-devel] [PULL 01/29] hw/boards: Add struct CpuTopology to MachineState Eduardo Habkost
2019-06-28 1:55 ` [Qemu-devel] [PULL 02/29] machine: Refactor smp-related call chains to pass MachineState Eduardo Habkost
2019-06-28 1:55 ` [Qemu-devel] [PULL 03/29] general: Replace global smp variables with smp machine properties Eduardo Habkost
2019-06-28 1:55 ` [Qemu-devel] [PULL 04/29] hw/ppc: Replace global smp variables with machine smp properties Eduardo Habkost
2019-06-28 1:55 ` [Qemu-devel] [PULL 05/29] hw/riscv: " Eduardo Habkost
2019-06-28 1:55 ` [Qemu-devel] [PULL 06/29] hw/s390x: " Eduardo Habkost
2019-06-28 1:55 ` Eduardo Habkost [this message]
2019-06-28 1:55 ` [Qemu-devel] [PULL 08/29] hw/arm: " Eduardo Habkost
2019-06-28 1:55 ` [Qemu-devel] [PULL 09/29] hw: Replace global smp variables with MachineState for all remaining archs Eduardo Habkost
2019-06-28 1:55 ` [Qemu-devel] [PULL 10/29] vl.c: Replace smp global variables with smp machine properties Eduardo Habkost
2019-06-28 1:55 ` [Qemu-devel] [PULL 11/29] i386: Add die-level cpu topology to x86CPU on PCMachine Eduardo Habkost
2019-06-28 1:55 ` [Qemu-devel] [PULL 12/29] hw/i386: Adjust nr_dies with configured smp_dies for PCMachine Eduardo Habkost
2019-06-28 1:55 ` [Qemu-devel] [PULL 13/29] i386/cpu: Consolidate die-id validity in smp context Eduardo Habkost
2019-06-28 1:55 ` [Qemu-devel] [PULL 14/29] i386: Update new x86_apicid parsing rules with die_offset support Eduardo Habkost
2019-06-28 1:55 ` [Qemu-devel] [PULL 15/29] pc: fix possible NULL pointer dereference in pc_machine_get_device_memory_region_size() Eduardo Habkost
2019-06-28 1:55 ` [Qemu-devel] [PULL 16/29] machine: show if CLI option '-numa node, mem' is supported in QAPI schema Eduardo Habkost
2019-06-28 1:55 ` [Qemu-devel] [PULL 17/29] numa: deprecate 'mem' parameter of '-numa node' option Eduardo Habkost
2019-06-28 1:55 ` [Qemu-devel] [PULL 18/29] numa: deprecate implict memory distribution between nodes Eduardo Habkost
2019-06-28 1:55 ` [Qemu-devel] [PULL 19/29] hppa: Delete unused hppa_cpu_list() function Eduardo Habkost
2019-06-28 1:55 ` [Qemu-devel] [PULL 20/29] target/i386: fix feature check in hyperv-stub.c Eduardo Habkost
2019-06-28 1:55 ` [Qemu-devel] [PULL 21/29] deprecate -mem-path fallback to anonymous RAM Eduardo Habkost
2019-06-28 1:55 ` [Qemu-devel] [PULL 22/29] i386: Don't print warning if phys-bits was set automatically Eduardo Habkost
2019-06-28 1:56 ` [Qemu-devel] [PULL 23/29] i386: Fix signedness of hyperv_spinlock_attempts Eduardo Habkost
2019-06-28 1:56 ` [Qemu-devel] [PULL 24/29] i386: make 'hv-spinlocks' a regular uint32 property Eduardo Habkost
2019-06-28 1:56 ` [Qemu-devel] [PULL 25/29] x86/cpu: use FeatureWordArray to define filtered_features Eduardo Habkost
2019-06-28 1:56 ` [Qemu-devel] [PULL 26/29] i386: Remove unused host_cpudef variable Eduardo Habkost
2019-06-28 1:56 ` [Qemu-devel] [PULL 27/29] target/i386: Add CPUID.1F generation support for multi-dies PCMachine Eduardo Habkost
2019-06-28 1:56 ` [Qemu-devel] [PULL 28/29] machine: Refactor smp_parse() in vl.c as MachineClass::smp_parse() Eduardo Habkost
2019-06-28 1:56 ` [Qemu-devel] [PULL 29/29] vl.c: Add -smp, dies=* command line support and update doc Eduardo Habkost
2019-06-28 2:49 ` [Qemu-devel] [PULL 00/29] Machine next patches no-reply
2019-06-28 18:49 ` Eduardo Habkost
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190628015606.32107-8-ehabkost@redhat.com \
--to=ehabkost@redhat.com \
--cc=like.xu@linux.intel.com \
--cc=marcel.apfelbaum@gmail.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=rth@twiddle.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).