From nobody Tue Oct 7 20:06:07 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1561687120; cv=none; d=zoho.com; s=zohoarc; b=d0kmDITTwNyCKmDSWMPLpt73pstMbbL9Y6gWxhP0M1sr8NNn4Hgxqd+6jLO3rkRKidOiwuU/H546ShslHPcjB3VryZeYCdWrNlxzmS7spt34k2A3XwrNDi9z3QS6RqbsDdpzKDN9O1BQy4JHIzFOTrXWIBdrFFtFnOGpu9ALZgQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1561687120; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=ymX9CjgianPd1XaY1cWhUVKaEFUiMBdv0yCmzdtTjeU=; b=Yn/H3gh+TnOI5TfPHWTEVdf7IEQfIgyab0EpvGYFJ4DY1+fVUoatijql9jmILZW38hjSxqF47O1/dkXEDPbUzEpPYSvfKixnPkTwVcIs7fNRrjBci9nx557qJ0tB/w6C6hrpePInABwPf+HKV/usssubJ/fnoTg/6dR9C9bluOY= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1561687120751783.0394325633586; Thu, 27 Jun 2019 18:58:40 -0700 (PDT) Received: from localhost ([::1]:55596 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hgg9p-0002PN-UJ for importer@patchew.org; Thu, 27 Jun 2019 21:58:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49747) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hgg7j-0008Rj-Ss for qemu-devel@nongnu.org; Thu, 27 Jun 2019 21:56:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hgg7h-0007R1-SD for qemu-devel@nongnu.org; Thu, 27 Jun 2019 21:56:23 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50875) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hgg7f-0007Gn-PP for qemu-devel@nongnu.org; Thu, 27 Jun 2019 21:56:19 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9E13A308FE8D; Fri, 28 Jun 2019 01:56:17 +0000 (UTC) Received: from localhost (ovpn-116-7.gru2.redhat.com [10.97.116.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id DEC955D9D2; Fri, 28 Jun 2019 01:56:16 +0000 (UTC) From: Eduardo Habkost To: Peter Maydell , qemu-devel@nongnu.org, Marcel Apfelbaum Date: Thu, 27 Jun 2019 22:55:39 -0300 Message-Id: <20190628015606.32107-3-ehabkost@redhat.com> In-Reply-To: <20190628015606.32107-1-ehabkost@redhat.com> References: <20190628015606.32107-1-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Fri, 28 Jun 2019 01:56:17 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 02/29] machine: Refactor smp-related call chains to pass MachineState 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: Paolo Bonzini , Like Xu , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Like Xu To get rid of the global smp_* variables we're currently using, it's recomm= ended to pass MachineState in the list of incoming parameters for functions that = use global smp variables, thus some redundant parameters are dropped. It's appl= ied for legacy smbios_*(), *_machine_reset(), hot_add_cpu() and mips *_create_c= pu(). Suggested-by: Igor Mammedov Signed-off-by: Like Xu Reviewed-by: Alistair Francis Message-Id: <20190518205428.90532-3-like.xu@linux.intel.com> Signed-off-by: Eduardo Habkost --- include/hw/boards.h | 4 ++-- include/hw/firmware/smbios.h | 5 +++-- include/hw/i386/pc.h | 2 +- hw/arm/virt.c | 2 +- hw/hppa/machine.c | 2 +- hw/i386/acpi-build.c | 2 +- hw/i386/pc.c | 9 ++++----- hw/mips/mips_malta.c | 22 +++++++++++----------- hw/ppc/pnv.c | 3 +-- hw/ppc/spapr.c | 3 +-- hw/s390x/s390-virtio-ccw.c | 6 +++--- hw/smbios/smbios.c | 26 +++++++++++++++----------- monitor/qmp-cmds.c | 2 +- vl.c | 2 +- 14 files changed, 46 insertions(+), 44 deletions(-) diff --git a/include/hw/boards.h b/include/hw/boards.h index 31dab77b4b..843d82c77d 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -172,8 +172,8 @@ struct MachineClass { const char *deprecation_reason; =20 void (*init)(MachineState *state); - void (*reset)(void); - void (*hot_add_cpu)(const int64_t id, Error **errp); + void (*reset)(MachineState *state); + void (*hot_add_cpu)(MachineState *state, const int64_t id, Error **err= p); int (*kvm_type)(MachineState *machine, const char *arg); =20 BlockInterfaceType block_default_type; diff --git a/include/hw/firmware/smbios.h b/include/hw/firmware/smbios.h index 6fef32a3c9..02a0ced0a0 100644 --- a/include/hw/firmware/smbios.h +++ b/include/hw/firmware/smbios.h @@ -268,8 +268,9 @@ void smbios_set_cpuid(uint32_t version, uint32_t featur= es); void smbios_set_defaults(const char *manufacturer, const char *product, const char *version, bool legacy_mode, bool uuid_encoded, SmbiosEntryPointType ep_type); -uint8_t *smbios_get_table_legacy(size_t *length); -void smbios_get_tables(const struct smbios_phys_mem_area *mem_array, +uint8_t *smbios_get_table_legacy(MachineState *ms, size_t *length); +void smbios_get_tables(MachineState *ms, + const struct smbios_phys_mem_area *mem_array, const unsigned int mem_array_size, uint8_t **tables, size_t *tables_len, uint8_t **anchor, size_t *anchor_len); diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index c54cc54a47..884e35b9b2 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -186,7 +186,7 @@ void pc_register_ferr_irq(qemu_irq irq); void pc_acpi_smi_interrupt(void *opaque, int irq, int level); =20 void pc_cpus_init(PCMachineState *pcms); -void pc_hot_add_cpu(const int64_t id, Error **errp); +void pc_hot_add_cpu(MachineState *ms, const int64_t id, Error **errp); =20 void pc_guest_info_init(PCMachineState *pcms); =20 diff --git a/hw/arm/virt.c b/hw/arm/virt.c index 431e2900fd..4a0ac3baf0 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -1344,7 +1344,7 @@ static void virt_build_smbios(VirtMachineState *vms) vmc->smbios_old_sys_ver ? "1.0" : mc->name, false, true, SMBIOS_ENTRY_POINT_30); =20 - smbios_get_tables(NULL, 0, &smbios_tables, &smbios_tables_len, + smbios_get_tables(MACHINE(vms), NULL, 0, &smbios_tables, &smbios_table= s_len, &smbios_anchor, &smbios_anchor_len); =20 if (smbios_anchor) { diff --git a/hw/hppa/machine.c b/hw/hppa/machine.c index d1b1d3caa4..416e67bab1 100644 --- a/hw/hppa/machine.c +++ b/hw/hppa/machine.c @@ -240,7 +240,7 @@ static void machine_hppa_init(MachineState *machine) cpu[0]->env.gr[21] =3D smp_cpus; } =20 -static void hppa_machine_reset(void) +static void hppa_machine_reset(MachineState *ms) { int i; =20 diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c index 31a1c1e3ad..8ae7d88b11 100644 --- a/hw/i386/acpi-build.c +++ b/hw/i386/acpi-build.c @@ -184,7 +184,7 @@ static void acpi_get_pm_info(AcpiPmInfo *pm) pm->pcihp_io_len =3D 0; =20 assert(obj); - init_common_fadt_data(obj, &pm->fadt); + init_common_fadt_data(machine, obj, &pm->fadt); if (piix) { /* w2k requires FADT(rev1) or it won't boot, keep PC compatible */ pm->fadt.rev =3D 1; diff --git a/hw/i386/pc.c b/hw/i386/pc.c index e96360b47a..da1cdd6853 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -958,7 +958,7 @@ static void pc_build_smbios(PCMachineState *pcms) /* tell smbios about cpuid version and features */ smbios_set_cpuid(cpu->env.cpuid_version, cpu->env.features[FEAT_1_EDX]= ); =20 - smbios_tables =3D smbios_get_table_legacy(&smbios_tables_len); + smbios_tables =3D smbios_get_table_legacy(ms, &smbios_tables_len); if (smbios_tables) { fw_cfg_add_bytes(pcms->fw_cfg, FW_CFG_SMBIOS_ENTRIES, smbios_tables, smbios_tables_len); @@ -975,7 +975,7 @@ static void pc_build_smbios(PCMachineState *pcms) array_count++; } } - smbios_get_tables(mem_array, array_count, + smbios_get_tables(ms, mem_array, array_count, &smbios_tables, &smbios_tables_len, &smbios_anchor, &smbios_anchor_len); g_free(mem_array); @@ -1530,9 +1530,8 @@ static void pc_new_cpu(const char *typename, int64_t = apic_id, Error **errp) error_propagate(errp, local_err); } =20 -void pc_hot_add_cpu(const int64_t id, Error **errp) +void pc_hot_add_cpu(MachineState *ms, const int64_t id, Error **errp) { - MachineState *ms =3D MACHINE(qdev_get_machine()); int64_t apic_id =3D x86_cpu_apic_id_from_index(id); Error *local_err =3D NULL; =20 @@ -2619,7 +2618,7 @@ static void pc_machine_initfn(Object *obj) pc_system_flash_create(pcms); } =20 -static void pc_machine_reset(void) +static void pc_machine_reset(MachineState *machine) { CPUState *cs; X86CPU *cpu; diff --git a/hw/mips/mips_malta.c b/hw/mips/mips_malta.c index 37ec89b07e..132127882d 100644 --- a/hw/mips/mips_malta.c +++ b/hw/mips/mips_malta.c @@ -1124,15 +1124,15 @@ static void main_cpu_reset(void *opaque) } } =20 -static void create_cpu_without_cps(const char *cpu_type, +static void create_cpu_without_cps(MachineState *ms, qemu_irq *cbus_irq, qemu_irq *i8259_irq) { CPUMIPSState *env; MIPSCPU *cpu; int i; =20 - for (i =3D 0; i < smp_cpus; i++) { - cpu =3D MIPS_CPU(cpu_create(cpu_type)); + for (i =3D 0; i < ms->smp.cpus; i++) { + cpu =3D MIPS_CPU(cpu_create(ms->cpu_type)); =20 /* Init internal devices */ cpu_mips_irq_init_cpu(cpu); @@ -1146,15 +1146,15 @@ static void create_cpu_without_cps(const char *cpu_= type, *cbus_irq =3D env->irq[4]; } =20 -static void create_cps(MaltaState *s, const char *cpu_type, +static void create_cps(MachineState *ms, MaltaState *s, qemu_irq *cbus_irq, qemu_irq *i8259_irq) { Error *err =3D NULL; =20 sysbus_init_child_obj(OBJECT(s), "cps", OBJECT(&s->cps), sizeof(s->cps= ), TYPE_MIPS_CPS); - object_property_set_str(OBJECT(&s->cps), cpu_type, "cpu-type", &err); - object_property_set_int(OBJECT(&s->cps), smp_cpus, "num-vp", &err); + object_property_set_str(OBJECT(&s->cps), ms->cpu_type, "cpu-type", &er= r); + object_property_set_int(OBJECT(&s->cps), ms->smp.cpus, "num-vp", &err); object_property_set_bool(OBJECT(&s->cps), true, "realized", &err); if (err !=3D NULL) { error_report("%s", error_get_pretty(err)); @@ -1167,13 +1167,13 @@ static void create_cps(MaltaState *s, const char *c= pu_type, *cbus_irq =3D NULL; } =20 -static void mips_create_cpu(MaltaState *s, const char *cpu_type, +static void mips_create_cpu(MachineState *ms, MaltaState *s, qemu_irq *cbus_irq, qemu_irq *i8259_irq) { - if ((smp_cpus > 1) && cpu_supports_cps_smp(cpu_type)) { - create_cps(s, cpu_type, cbus_irq, i8259_irq); + if ((ms->smp.cpus > 1) && cpu_supports_cps_smp(ms->cpu_type)) { + create_cps(ms, s, cbus_irq, i8259_irq); } else { - create_cpu_without_cps(cpu_type, cbus_irq, i8259_irq); + create_cpu_without_cps(ms, cbus_irq, i8259_irq); } } =20 @@ -1217,7 +1217,7 @@ void mips_malta_init(MachineState *machine) qdev_init_nofail(dev); =20 /* create CPU */ - mips_create_cpu(s, machine->cpu_type, &cbus_irq, &i8259_irq); + mips_create_cpu(machine, s, &cbus_irq, &i8259_irq); =20 /* allocate RAM */ if (ram_size > 2 * GiB) { diff --git a/hw/ppc/pnv.c b/hw/ppc/pnv.c index 9db43916ac..1cac1bd227 100644 --- a/hw/ppc/pnv.c +++ b/hw/ppc/pnv.c @@ -529,9 +529,8 @@ static void pnv_powerdown_notify(Notifier *n, void *opa= que) } } =20 -static void pnv_reset(void) +static void pnv_reset(MachineState *machine) { - MachineState *machine =3D MACHINE(qdev_get_machine()); PnvMachineState *pnv =3D PNV_MACHINE(machine); void *fdt; Object *obj; diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index b502fcac2e..6cf0ac400b 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -1691,9 +1691,8 @@ static int spapr_reset_drcs(Object *child, void *opaq= ue) return 0; } =20 -static void spapr_machine_reset(void) +static void spapr_machine_reset(MachineState *machine) { - MachineState *machine =3D MACHINE(qdev_get_machine()); SpaprMachineState *spapr =3D SPAPR_MACHINE(machine); PowerPCCPU *first_ppc_cpu; uint32_t rtas_limit; diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c index 87b2039f1b..e09bf8f1b6 100644 --- a/hw/s390x/s390-virtio-ccw.c +++ b/hw/s390x/s390-virtio-ccw.c @@ -339,7 +339,7 @@ static inline void s390_do_cpu_ipl(CPUState *cs, run_on= _cpu_data arg) s390_cpu_set_state(S390_CPU_STATE_OPERATING, cpu); } =20 -static void s390_machine_reset(void) +static void s390_machine_reset(MachineState *machine) { enum s390_reset reset_type; CPUState *cs, *t; @@ -440,9 +440,9 @@ static HotplugHandler *s390_get_hotplug_handler(Machine= State *machine, return NULL; } =20 -static void s390_hot_add_cpu(const int64_t id, Error **errp) +static void s390_hot_add_cpu(MachineState *machine, + const int64_t id, Error **errp) { - MachineState *machine =3D MACHINE(qdev_get_machine()); ObjectClass *oc; =20 g_assert(machine->possible_cpus->cpus[0].cpu); diff --git a/hw/smbios/smbios.c b/hw/smbios/smbios.c index a36448fc8d..7bcd67b098 100644 --- a/hw/smbios/smbios.c +++ b/hw/smbios/smbios.c @@ -27,6 +27,7 @@ #include "sysemu/cpus.h" #include "hw/firmware/smbios.h" #include "hw/loader.h" +#include "hw/boards.h" #include "exec/cpu-common.h" #include "smbios_build.h" =20 @@ -341,9 +342,10 @@ static void smbios_register_config(void) =20 opts_init(smbios_register_config); =20 -static void smbios_validate_table(void) +static void smbios_validate_table(MachineState *ms) { - uint32_t expect_t4_count =3D smbios_legacy ? smp_cpus : smbios_smp_soc= kets; + uint32_t expect_t4_count =3D smbios_legacy ? + ms->smp.cpus : smbios_smp_sockets; =20 if (smbios_type4_count && smbios_type4_count !=3D expect_t4_count) { error_report("Expected %d SMBIOS Type 4 tables, got %d instead", @@ -428,7 +430,7 @@ static void smbios_build_type_1_fields(void) } } =20 -uint8_t *smbios_get_table_legacy(size_t *length) +uint8_t *smbios_get_table_legacy(MachineState *ms, size_t *length) { if (!smbios_legacy) { *length =3D 0; @@ -438,7 +440,7 @@ uint8_t *smbios_get_table_legacy(size_t *length) if (!smbios_immutable) { smbios_build_type_0_fields(); smbios_build_type_1_fields(); - smbios_validate_table(); + smbios_validate_table(ms); smbios_immutable =3D true; } *length =3D smbios_entries_len; @@ -570,7 +572,7 @@ static void smbios_build_type_3_table(void) SMBIOS_BUILD_TABLE_POST; } =20 -static void smbios_build_type_4_table(unsigned instance) +static void smbios_build_type_4_table(MachineState *ms, unsigned instance) { char sock_str[128]; =20 @@ -597,8 +599,8 @@ static void smbios_build_type_4_table(unsigned instance) SMBIOS_TABLE_SET_STR(4, serial_number_str, type4.serial); SMBIOS_TABLE_SET_STR(4, asset_tag_number_str, type4.asset); SMBIOS_TABLE_SET_STR(4, part_number_str, type4.part); - t->core_count =3D t->core_enabled =3D smp_cores; - t->thread_count =3D smp_threads; + t->core_count =3D t->core_enabled =3D ms->smp.cores; + t->thread_count =3D ms->smp.threads; t->processor_characteristics =3D cpu_to_le16(0x02); /* Unknown */ t->processor_family2 =3D cpu_to_le16(0x01); /* Other */ =20 @@ -839,7 +841,8 @@ static void smbios_entry_point_setup(void) } } =20 -void smbios_get_tables(const struct smbios_phys_mem_area *mem_array, +void smbios_get_tables(MachineState *ms, + const struct smbios_phys_mem_area *mem_array, const unsigned int mem_array_size, uint8_t **tables, size_t *tables_len, uint8_t **anchor, size_t *anchor_len) @@ -858,11 +861,12 @@ void smbios_get_tables(const struct smbios_phys_mem_a= rea *mem_array, smbios_build_type_2_table(); smbios_build_type_3_table(); =20 - smbios_smp_sockets =3D DIV_ROUND_UP(smp_cpus, smp_cores * smp_thre= ads); + smbios_smp_sockets =3D DIV_ROUND_UP(ms->smp.cpus, + ms->smp.cores * ms->smp.threads); assert(smbios_smp_sockets >=3D 1); =20 for (i =3D 0; i < smbios_smp_sockets; i++) { - smbios_build_type_4_table(i); + smbios_build_type_4_table(ms, i); } =20 smbios_build_type_11_table(); @@ -888,7 +892,7 @@ void smbios_get_tables(const struct smbios_phys_mem_are= a *mem_array, smbios_build_type_38_table(); smbios_build_type_127_table(); =20 - smbios_validate_table(); + smbios_validate_table(ms); smbios_entry_point_setup(); smbios_immutable =3D true; } diff --git a/monitor/qmp-cmds.c b/monitor/qmp-cmds.c index 01ce77e129..27585cd743 100644 --- a/monitor/qmp-cmds.c +++ b/monitor/qmp-cmds.c @@ -124,7 +124,7 @@ void qmp_cpu_add(int64_t id, Error **errp) =20 mc =3D MACHINE_GET_CLASS(current_machine); if (mc->hot_add_cpu) { - mc->hot_add_cpu(id, errp); + mc->hot_add_cpu(current_machine, id, errp); } else { error_setg(errp, "Not supported"); } diff --git a/vl.c b/vl.c index e9698cb1b1..918e8413ef 100644 --- a/vl.c +++ b/vl.c @@ -1617,7 +1617,7 @@ void qemu_system_reset(ShutdownCause reason) cpu_synchronize_all_states(); =20 if (mc && mc->reset) { - mc->reset(); + mc->reset(current_machine); } else { qemu_devices_reset(); } --=20 2.18.0.rc1.1.g3f1ff2140