From nobody Mon Feb 9 08:28:08 2026 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=linux.intel.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1553849748841639.2504858961423; Fri, 29 Mar 2019 01:55:48 -0700 (PDT) Received: from localhost ([127.0.0.1]:48910 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9nIf-0004ti-Sw for importer@patchew.org; Fri, 29 Mar 2019 04:55:45 -0400 Received: from eggs.gnu.org ([209.51.188.92]:48194) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9nCu-0007jP-Uh for qemu-devel@nongnu.org; Fri, 29 Mar 2019 04:49:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h9nCs-0006Xb-T0 for qemu-devel@nongnu.org; Fri, 29 Mar 2019 04:49:48 -0400 Received: from mga06.intel.com ([134.134.136.31]:30614) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h9nCn-0006Ts-Pk; Fri, 29 Mar 2019 04:49:42 -0400 Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Mar 2019 01:49:37 -0700 Received: from xulike-server.sh.intel.com ([10.239.48.134]) by orsmga008.jf.intel.com with ESMTP; 29 Mar 2019 01:49:36 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,283,1549958400"; d="scan'208";a="129706910" From: Like Xu To: qemu-trivial@nongnu.org Date: Fri, 29 Mar 2019 16:48:38 +0800 Message-Id: <1553849325-44201-3-git-send-email-like.xu@linux.intel.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1553849325-44201-1-git-send-email-like.xu@linux.intel.com> References: <1553849325-44201-1-git-send-email-like.xu@linux.intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 134.134.136.31 Subject: [Qemu-devel] [PATCH 2/9] cpu/topology: add general support for machine properties X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , like.xu@intel.com, qemu-devel@nongnu.org, Paolo Bonzini , Igor Mammedov 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" Signed-off-by: Like Xu --- accel/kvm/kvm-all.c | 3 +++ backends/hostmem.c | 4 ++++ cpus.c | 4 ++++ exec.c | 2 ++ gdbstub.c | 7 ++++++- hw/cpu/core.c | 3 +++ hw/smbios/smbios.c | 11 +++++++++++ migration/postcopy-ram.c | 7 +++++++ numa.c | 1 + tcg/tcg.c | 15 +++++++++++++++ 10 files changed, 56 insertions(+), 1 deletion(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 241db49..5385218 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -1526,6 +1526,9 @@ bool kvm_vcpu_id_is_valid(int vcpu_id) static int kvm_init(MachineState *ms) { MachineClass *mc =3D MACHINE_GET_CLASS(ms); + unsigned int smp_cpus =3D ms->topo.smp_cpus; + unsigned int max_cpus =3D ms->topo.max_cpus; + static const char upgrade_note[] =3D "Please upgrade to at least kernel 2.6.29 or recent kvm-kmod\n" "(see http://sourceforge.net/projects/kvm).\n"; diff --git a/backends/hostmem.c b/backends/hostmem.c index 04baf47..cecdfd5 100644 --- a/backends/hostmem.c +++ b/backends/hostmem.c @@ -222,6 +222,8 @@ static void host_memory_backend_set_prealloc(Object *ob= j, bool value, { Error *local_err =3D NULL; HostMemoryBackend *backend =3D MEMORY_BACKEND(obj); + MachineState *ms =3D MACHINE(qdev_get_machine()); + unsigned int smp_cpus =3D ms->topo.smp_cpus; =20 if (backend->force_prealloc) { if (value) { @@ -311,6 +313,8 @@ host_memory_backend_memory_complete(UserCreatable *uc, = Error **errp) { HostMemoryBackend *backend =3D MEMORY_BACKEND(uc); HostMemoryBackendClass *bc =3D MEMORY_BACKEND_GET_CLASS(uc); + MachineState *ms =3D MACHINE(qdev_get_machine()); + unsigned int smp_cpus =3D ms->topo.smp_cpus; Error *local_err =3D NULL; void *ptr; uint64_t sz; diff --git a/cpus.c b/cpus.c index e83f72b..834a697 100644 --- a/cpus.c +++ b/cpus.c @@ -2067,6 +2067,10 @@ static void qemu_dummy_start_vcpu(CPUState *cpu) =20 void qemu_init_vcpu(CPUState *cpu) { + MachineState *ms =3D MACHINE(qdev_get_machine()); + unsigned int smp_cores =3D ms->topo.smp_cores; + unsigned int smp_threads =3D ms->topo.smp_threads; + cpu->nr_cores =3D smp_cores; cpu->nr_threads =3D smp_threads; cpu->stopped =3D true; diff --git a/exec.c b/exec.c index 86a38d3..a3c3db7 100644 --- a/exec.c +++ b/exec.c @@ -1829,6 +1829,8 @@ static void *file_ram_alloc(RAMBlock *block, bool truncate, Error **errp) { + MachineState *ms =3D MACHINE(qdev_get_machine()); + unsigned int smp_cpus =3D ms->topo.smp_cpus; void *area; =20 block->page_size =3D qemu_fd_getpagesize(fd); diff --git a/gdbstub.c b/gdbstub.c index d54abd1..35f6bbc 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -30,6 +30,7 @@ #include "sysemu/sysemu.h" #include "exec/gdbstub.h" #include "hw/cpu/cluster.h" +#include "hw/boards.h" #endif =20 #define MAX_PACKET_LENGTH 4096 @@ -1154,11 +1155,15 @@ static int gdb_handle_vcont(GDBState *s, const char= *p) CPUState *cpu; GDBThreadIdKind kind; #ifdef CONFIG_USER_ONLY - int max_cpus =3D 1; /* global variable max_cpus exists only in system = mode */ + /* global variable max_cpus exists only in system mode */ + unsigned int max_cpus =3D 1; =20 CPU_FOREACH(cpu) { max_cpus =3D max_cpus <=3D cpu->cpu_index ? cpu->cpu_index + 1 : m= ax_cpus; } +#else + MachineState *ms =3D MACHINE(qdev_get_machine()); + unsigned int max_cpus =3D ms->topo.max_cpus; #endif /* uninitialised CPUs stay 0 */ newstates =3D g_new0(char, max_cpus); diff --git a/hw/cpu/core.c b/hw/cpu/core.c index 7e42e2c..b75ffbb 100644 --- a/hw/cpu/core.c +++ b/hw/cpu/core.c @@ -11,6 +11,7 @@ #include "qapi/visitor.h" #include "qapi/error.h" #include "sysemu/cpus.h" +#include "hw/boards.h" =20 static void core_prop_get_core_id(Object *obj, Visitor *v, const char *nam= e, void *opaque, Error **errp) @@ -69,6 +70,8 @@ static void core_prop_set_nr_threads(Object *obj, Visitor= *v, const char *name, =20 static void cpu_core_instance_init(Object *obj) { + MachineState *ms =3D MACHINE(qdev_get_machine()); + unsigned int smp_threads =3D ms->topo.smp_threads; CPUCore *core =3D CPU_CORE(obj); =20 object_property_add(obj, "core-id", "int", core_prop_get_core_id, diff --git a/hw/smbios/smbios.c b/hw/smbios/smbios.c index 47be907..a5eabe7 100644 --- a/hw/smbios/smbios.c +++ b/hw/smbios/smbios.c @@ -28,6 +28,7 @@ #include "hw/loader.h" #include "exec/cpu-common.h" #include "smbios_build.h" +#include "hw/boards.h" =20 /* legacy structures and constants for <=3D 2.0 machines */ struct smbios_header { @@ -342,6 +343,9 @@ opts_init(smbios_register_config); =20 static void smbios_validate_table(void) { + MachineState *ms =3D MACHINE(qdev_get_machine()); + unsigned int smp_cpus =3D ms->topo.smp_cpus; + uint32_t expect_t4_count =3D smbios_legacy ? smp_cpus : smbios_smp_soc= kets; =20 if (smbios_type4_count && smbios_type4_count !=3D expect_t4_count) { @@ -571,6 +575,9 @@ static void smbios_build_type_3_table(void) =20 static void smbios_build_type_4_table(unsigned instance) { + MachineState *ms =3D MACHINE(qdev_get_machine()); + unsigned int smp_threads =3D ms->topo.smp_threads; + unsigned int smp_cores =3D ms->topo.smp_cores; char sock_str[128]; =20 SMBIOS_BUILD_TABLE_PRE(4, 0x400 + instance, true); /* required */ @@ -843,7 +850,11 @@ void smbios_get_tables(const struct smbios_phys_mem_ar= ea *mem_array, uint8_t **tables, size_t *tables_len, uint8_t **anchor, size_t *anchor_len) { + MachineState *ms =3D MACHINE(qdev_get_machine()); unsigned i, dimm_cnt; + unsigned int smp_cpus =3D ms->topo.smp_cpus; + unsigned int smp_cores =3D ms->topo.smp_cores; + unsigned int smp_threads =3D ms->topo.smp_threads; =20 if (smbios_legacy) { *tables =3D *anchor =3D NULL; diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index e2aa57a..ae92f6e 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -29,6 +29,7 @@ #include "sysemu/balloon.h" #include "qemu/error-report.h" #include "trace.h" +#include "hw/boards.h" =20 /* Arbitrary limit on size of each discard command, * keeps them around ~200 bytes @@ -128,6 +129,8 @@ static void migration_exit_cb(Notifier *n, void *data) =20 static struct PostcopyBlocktimeContext *blocktime_context_new(void) { + MachineState *ms =3D MACHINE(qdev_get_machine()); + unsigned int smp_cpus =3D ms->topo.smp_cpus; PostcopyBlocktimeContext *ctx =3D g_new0(PostcopyBlocktimeContext, 1); ctx->page_fault_vcpu_time =3D g_new0(uint32_t, smp_cpus); ctx->vcpu_addr =3D g_new0(uintptr_t, smp_cpus); @@ -141,6 +144,8 @@ static struct PostcopyBlocktimeContext *blocktime_conte= xt_new(void) =20 static uint32List *get_vcpu_blocktime_list(PostcopyBlocktimeContext *ctx) { + MachineState *ms =3D MACHINE(qdev_get_machine()); + unsigned int smp_cpus =3D ms->topo.smp_cpus; uint32List *list =3D NULL, *entry =3D NULL; int i; =20 @@ -806,8 +811,10 @@ static void mark_postcopy_blocktime_begin(uintptr_t ad= dr, uint32_t ptid, static void mark_postcopy_blocktime_end(uintptr_t addr) { MigrationIncomingState *mis =3D migration_incoming_get_current(); + MachineState *ms =3D MACHINE(qdev_get_machine()); PostcopyBlocktimeContext *dc =3D mis->blocktime_ctx; int i, affected_cpu =3D 0; + unsigned int smp_cpus =3D ms->topo.smp_cpus; bool vcpu_total_blocktime =3D false; uint32_t read_vcpu_time, low_time_offset; =20 diff --git a/numa.c b/numa.c index 3875e1e..127ddbe 100644 --- a/numa.c +++ b/numa.c @@ -64,6 +64,7 @@ static void parse_numa_node(MachineState *ms, NumaNodeOpt= ions *node, uint16_t nodenr; uint16List *cpus =3D NULL; MachineClass *mc =3D MACHINE_GET_CLASS(ms); + unsigned int max_cpus =3D ms->topo.max_cpus; =20 if (node->has_nodeid) { nodenr =3D node->nodeid; diff --git a/tcg/tcg.c b/tcg/tcg.c index 9b2bf7f..d1501eb 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -44,6 +44,10 @@ #include "exec/cpu-common.h" #include "exec/exec-all.h" =20 +#if !defined(CONFIG_USER_ONLY) +#include "hw/boards.h" +#endif + #include "tcg-op.h" =20 #if UINTPTR_MAX =3D=3D UINT32_MAX @@ -602,6 +606,10 @@ static size_t tcg_n_regions(void) size_t i; =20 /* Use a single region if all we have is one vCPU thread */ +#if !defined(CONFIG_USER_ONLY) + MachineState *ms =3D MACHINE(qdev_get_machine()); + unsigned int max_cpus =3D ms->topo.max_cpus; +#endif if (max_cpus =3D=3D 1 || !qemu_tcg_mttcg_enabled()) { return 1; } @@ -751,7 +759,12 @@ void tcg_register_thread(void) =20 /* Claim an entry in tcg_ctxs */ n =3D atomic_fetch_inc(&n_tcg_ctxs); +#if !defined(CONFIG_USER_ONLY) + MachineState *ms =3D MACHINE(qdev_get_machine()); + g_assert(n < ms->topo.max_cpus); +#elif g_assert(n < max_cpus); +#endif atomic_set(&tcg_ctxs[n], s); =20 tcg_ctx =3D s; @@ -961,6 +974,8 @@ void tcg_context_init(TCGContext *s) tcg_ctxs =3D &tcg_ctx; n_tcg_ctxs =3D 1; #else + MachineState *ms =3D MACHINE(qdev_get_machine()); + unsigned int max_cpus =3D ms->topo.max_cpus; tcg_ctxs =3D g_new(TCGContext *, max_cpus); #endif =20 --=20 1.8.3.1