qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eduardo Habkost <ehabkost@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>,
	Paolo Bonzini <pbonzini@redhat.com>,
	qemu-devel@nongnu.org,
	Marcel Apfelbaum <marcel.apfelbaum@gmail.com>,
	Richard Henderson <rth@twiddle.net>
Cc: Like Xu <like.xu@linux.intel.com>
Subject: [Qemu-devel] [PULL v4 03/43] general: Replace global smp variables with smp machine properties
Date: Wed,  3 Jul 2019 15:06:46 -0300	[thread overview]
Message-ID: <20190703180726.31267-4-ehabkost@redhat.com> (raw)
In-Reply-To: <20190703180726.31267-1-ehabkost@redhat.com>

From: Like Xu <like.xu@linux.intel.com>

Basically, the context could get the MachineState reference via call
chains or unrecommended qdev_get_machine() in !CONFIG_USER_ONLY mode.

A local variable of the same name would be introduced in the declaration
phase out of less effort OR replace it on the spot if it's only used
once in the context. No semantic changes.

Signed-off-by: Like Xu <like.xu@linux.intel.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Message-Id: <20190518205428.90532-4-like.xu@linux.intel.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 accel/kvm/kvm-all.c          |  4 ++--
 backends/hostmem.c           |  6 ++++--
 cpus.c                       |  6 ++++--
 exec.c                       |  3 ++-
 gdbstub.c                    |  4 ++++
 hw/cpu/core.c                |  4 +++-
 migration/postcopy-ram.c     |  8 +++++++-
 numa.c                       |  1 +
 target/openrisc/sys_helper.c |  6 +++++-
 tcg/tcg.c                    | 13 ++++++++++++-
 10 files changed, 44 insertions(+), 11 deletions(-)

diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index e3cf72883b..3d86ae5052 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -1542,8 +1542,8 @@ static int kvm_init(MachineState *ms)
         const char *name;
         int num;
     } num_cpus[] = {
-        { "SMP",          smp_cpus },
-        { "hotpluggable", max_cpus },
+        { "SMP",          ms->smp.cpus },
+        { "hotpluggable", ms->smp.max_cpus },
         { NULL, }
     }, *nc = num_cpus;
     int soft_vcpus_limit, hard_vcpus_limit;
diff --git a/backends/hostmem.c b/backends/hostmem.c
index 04baf479a1..463102aa15 100644
--- a/backends/hostmem.c
+++ b/backends/hostmem.c
@@ -222,6 +222,7 @@ static void host_memory_backend_set_prealloc(Object *obj, bool value,
 {
     Error *local_err = NULL;
     HostMemoryBackend *backend = MEMORY_BACKEND(obj);
+    MachineState *ms = MACHINE(qdev_get_machine());
 
     if (backend->force_prealloc) {
         if (value) {
@@ -241,7 +242,7 @@ static void host_memory_backend_set_prealloc(Object *obj, bool value,
         void *ptr = memory_region_get_ram_ptr(&backend->mr);
         uint64_t sz = memory_region_size(&backend->mr);
 
-        os_mem_prealloc(fd, ptr, sz, smp_cpus, &local_err);
+        os_mem_prealloc(fd, ptr, sz, ms->smp.cpus, &local_err);
         if (local_err) {
             error_propagate(errp, local_err);
             return;
@@ -311,6 +312,7 @@ host_memory_backend_memory_complete(UserCreatable *uc, Error **errp)
 {
     HostMemoryBackend *backend = MEMORY_BACKEND(uc);
     HostMemoryBackendClass *bc = MEMORY_BACKEND_GET_CLASS(uc);
+    MachineState *ms = MACHINE(qdev_get_machine());
     Error *local_err = NULL;
     void *ptr;
     uint64_t sz;
@@ -375,7 +377,7 @@ host_memory_backend_memory_complete(UserCreatable *uc, Error **errp)
          */
         if (backend->prealloc) {
             os_mem_prealloc(memory_region_get_fd(&backend->mr), ptr, sz,
-                            smp_cpus, &local_err);
+                            ms->smp.cpus, &local_err);
             if (local_err) {
                 goto out;
             }
diff --git a/cpus.c b/cpus.c
index 1af51b73dd..86b91fcd56 100644
--- a/cpus.c
+++ b/cpus.c
@@ -2078,8 +2078,10 @@ static void qemu_dummy_start_vcpu(CPUState *cpu)
 
 void qemu_init_vcpu(CPUState *cpu)
 {
-    cpu->nr_cores = smp_cores;
-    cpu->nr_threads = smp_threads;
+    MachineState *ms = MACHINE(qdev_get_machine());
+
+    cpu->nr_cores = ms->smp.cores;
+    cpu->nr_threads =  ms->smp.threads;
     cpu->stopped = true;
     cpu->random_seed = qemu_guest_random_seed_thread_part1();
 
diff --git a/exec.c b/exec.c
index e7622d1956..50ea9c5aaa 100644
--- a/exec.c
+++ b/exec.c
@@ -1874,6 +1874,7 @@ static void *file_ram_alloc(RAMBlock *block,
                             bool truncate,
                             Error **errp)
 {
+    MachineState *ms = MACHINE(qdev_get_machine());
     void *area;
 
     block->page_size = qemu_fd_getpagesize(fd);
@@ -1930,7 +1931,7 @@ static void *file_ram_alloc(RAMBlock *block,
     }
 
     if (mem_prealloc) {
-        os_mem_prealloc(fd, area, memory, smp_cpus, errp);
+        os_mem_prealloc(fd, area, memory, ms->smp.cpus, errp);
         if (errp && *errp) {
             qemu_ram_munmap(fd, area, memory);
             return NULL;
diff --git a/gdbstub.c b/gdbstub.c
index 8618e34311..687c02e598 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -34,6 +34,7 @@
 #include "sysemu/sysemu.h"
 #include "exec/gdbstub.h"
 #include "hw/cpu/cluster.h"
+#include "hw/boards.h"
 #endif
 
 #define MAX_PACKET_LENGTH 4096
@@ -1171,6 +1172,9 @@ static int gdb_handle_vcont(GDBState *s, const char *p)
     CPU_FOREACH(cpu) {
         max_cpus = max_cpus <= cpu->cpu_index ? cpu->cpu_index + 1 : max_cpus;
     }
+#else
+    MachineState *ms = MACHINE(qdev_get_machine());
+    unsigned int max_cpus = ms->smp.max_cpus;
 #endif
     /* uninitialised CPUs stay 0 */
     newstates = g_new0(char, max_cpus);
diff --git a/hw/cpu/core.c b/hw/cpu/core.c
index e57c73f0ce..9874c5c870 100644
--- a/hw/cpu/core.c
+++ b/hw/cpu/core.c
@@ -13,6 +13,7 @@
 #include "qemu/module.h"
 #include "qapi/error.h"
 #include "sysemu/cpus.h"
+#include "hw/boards.h"
 
 static void core_prop_get_core_id(Object *obj, Visitor *v, const char *name,
                                   void *opaque, Error **errp)
@@ -71,13 +72,14 @@ static void core_prop_set_nr_threads(Object *obj, Visitor *v, const char *name,
 
 static void cpu_core_instance_init(Object *obj)
 {
+    MachineState *ms = MACHINE(qdev_get_machine());
     CPUCore *core = CPU_CORE(obj);
 
     object_property_add(obj, "core-id", "int", core_prop_get_core_id,
                         core_prop_set_core_id, NULL, NULL, NULL);
     object_property_add(obj, "nr-threads", "int", core_prop_get_nr_threads,
                         core_prop_set_nr_threads, NULL, NULL, NULL);
-    core->nr_threads = smp_threads;
+    core->nr_threads = ms->smp.threads;
 }
 
 static void cpu_core_class_init(ObjectClass *oc, void *data)
diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c
index e2aa57a701..9faacacc9e 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"
 
 /* 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)
 
 static struct PostcopyBlocktimeContext *blocktime_context_new(void)
 {
+    MachineState *ms = MACHINE(qdev_get_machine());
+    unsigned int smp_cpus = ms->smp.cpus;
     PostcopyBlocktimeContext *ctx = g_new0(PostcopyBlocktimeContext, 1);
     ctx->page_fault_vcpu_time = g_new0(uint32_t, smp_cpus);
     ctx->vcpu_addr = g_new0(uintptr_t, smp_cpus);
@@ -141,10 +144,11 @@ static struct PostcopyBlocktimeContext *blocktime_context_new(void)
 
 static uint32List *get_vcpu_blocktime_list(PostcopyBlocktimeContext *ctx)
 {
+    MachineState *ms = MACHINE(qdev_get_machine());
     uint32List *list = NULL, *entry = NULL;
     int i;
 
-    for (i = smp_cpus - 1; i >= 0; i--) {
+    for (i = ms->smp.cpus - 1; i >= 0; i--) {
         entry = g_new0(uint32List, 1);
         entry->value = ctx->vcpu_blocktime[i];
         entry->next = list;
@@ -807,6 +811,8 @@ static void mark_postcopy_blocktime_end(uintptr_t addr)
 {
     MigrationIncomingState *mis = migration_incoming_get_current();
     PostcopyBlocktimeContext *dc = mis->blocktime_ctx;
+    MachineState *ms = MACHINE(qdev_get_machine());
+    unsigned int smp_cpus = ms->smp.cpus;
     int i, affected_cpu = 0;
     bool vcpu_total_blocktime = false;
     uint32_t read_vcpu_time, low_time_offset;
diff --git a/numa.c b/numa.c
index 955ec0c830..7594eb5a7e 100644
--- a/numa.c
+++ b/numa.c
@@ -64,6 +64,7 @@ static void parse_numa_node(MachineState *ms, NumaNodeOptions *node,
     uint16_t nodenr;
     uint16List *cpus = NULL;
     MachineClass *mc = MACHINE_GET_CLASS(ms);
+    unsigned int max_cpus = ms->smp.max_cpus;
 
     if (node->has_nodeid) {
         nodenr = node->nodeid;
diff --git a/target/openrisc/sys_helper.c b/target/openrisc/sys_helper.c
index 8f11cb8202..1053409a04 100644
--- a/target/openrisc/sys_helper.c
+++ b/target/openrisc/sys_helper.c
@@ -24,6 +24,9 @@
 #include "exec/helper-proto.h"
 #include "exception.h"
 #include "sysemu/sysemu.h"
+#ifndef CONFIG_USER_ONLY
+#include "hw/boards.h"
+#endif
 
 #define TO_SPR(group, number) (((group) << 11) + (number))
 
@@ -194,6 +197,7 @@ target_ulong HELPER(mfspr)(CPUOpenRISCState *env, target_ulong rd,
                            target_ulong spr)
 {
 #ifndef CONFIG_USER_ONLY
+    MachineState *ms = MACHINE(qdev_get_machine());
     OpenRISCCPU *cpu = env_archcpu(env);
     CPUState *cs = env_cpu(env);
     int idx;
@@ -241,7 +245,7 @@ target_ulong HELPER(mfspr)(CPUOpenRISCState *env, target_ulong rd,
         return cpu->parent_obj.cpu_index;
 
     case TO_SPR(0, 129): /* NUMCORES */
-        return max_cpus;
+        return ms->smp.max_cpus;
 
     case TO_SPR(0, 1024) ... TO_SPR(0, 1024 + (16 * 32)): /* Shadow GPRs */
         idx = (spr - 1024);
diff --git a/tcg/tcg.c b/tcg/tcg.c
index 02a2680169..be2c33c400 100644
--- a/tcg/tcg.c
+++ b/tcg/tcg.c
@@ -45,6 +45,10 @@
 #include "exec/cpu-common.h"
 #include "exec/exec-all.h"
 
+#if !defined(CONFIG_USER_ONLY)
+#include "hw/boards.h"
+#endif
+
 #include "tcg-op.h"
 
 #if UINTPTR_MAX == UINT32_MAX
@@ -620,6 +624,10 @@ static size_t tcg_n_regions(void)
     size_t i;
 
     /* Use a single region if all we have is one vCPU thread */
+#if !defined(CONFIG_USER_ONLY)
+    MachineState *ms = MACHINE(qdev_get_machine());
+    unsigned int max_cpus = ms->smp.max_cpus;
+#endif
     if (max_cpus == 1 || !qemu_tcg_mttcg_enabled()) {
         return 1;
     }
@@ -752,6 +760,7 @@ void tcg_register_thread(void)
 #else
 void tcg_register_thread(void)
 {
+    MachineState *ms = MACHINE(qdev_get_machine());
     TCGContext *s = g_malloc(sizeof(*s));
     unsigned int i, n;
     bool err;
@@ -769,7 +778,7 @@ void tcg_register_thread(void)
 
     /* Claim an entry in tcg_ctxs */
     n = atomic_fetch_inc(&n_tcg_ctxs);
-    g_assert(n < max_cpus);
+    g_assert(n < ms->smp.max_cpus);
     atomic_set(&tcg_ctxs[n], s);
 
     tcg_ctx = s;
@@ -979,6 +988,8 @@ void tcg_context_init(TCGContext *s)
     tcg_ctxs = &tcg_ctx;
     n_tcg_ctxs = 1;
 #else
+    MachineState *ms = MACHINE(qdev_get_machine());
+    unsigned int max_cpus = ms->smp.max_cpus;
     tcg_ctxs = g_new(TCGContext *, max_cpus);
 #endif
 
-- 
2.18.0.rc1.1.g3f1ff2140



  parent reply	other threads:[~2019-07-03 18:09 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-03 18:06 [Qemu-devel] [PULL v4 00/43] Machine and x86 queue, 2019-07-03 Eduardo Habkost
2019-07-03 18:06 ` [Qemu-devel] [PULL v4 01/43] hw/boards: Add struct CpuTopology to MachineState Eduardo Habkost
2019-07-03 18:06 ` [Qemu-devel] [PULL v4 02/43] machine: Refactor smp-related call chains to pass MachineState Eduardo Habkost
2019-07-03 18:06 ` Eduardo Habkost [this message]
2019-07-03 18:06 ` [Qemu-devel] [PULL v4 04/43] hw/ppc: Replace global smp variables with machine smp properties Eduardo Habkost
2019-07-03 18:06 ` [Qemu-devel] [PULL v4 05/43] hw/riscv: " Eduardo Habkost
2019-07-03 18:06 ` [Qemu-devel] [PULL v4 06/43] hw/s390x: " Eduardo Habkost
2019-07-03 18:06 ` [Qemu-devel] [PULL v4 07/43] hw/i386: " Eduardo Habkost
2019-07-03 18:06 ` [Qemu-devel] [PULL v4 08/43] hw/arm: " Eduardo Habkost
2019-07-03 18:06 ` [Qemu-devel] [PULL v4 09/43] hw: Replace global smp variables with MachineState for all remaining archs Eduardo Habkost
2019-07-03 18:06 ` [Qemu-devel] [PULL v4 10/43] vl.c: Replace smp global variables with smp machine properties Eduardo Habkost
2019-07-03 18:06 ` [Qemu-devel] [PULL v4 11/43] i386: Add die-level cpu topology to x86CPU on PCMachine Eduardo Habkost
2019-07-03 18:06 ` [Qemu-devel] [PULL v4 12/43] hw/i386: Adjust nr_dies with configured smp_dies for PCMachine Eduardo Habkost
2019-07-03 18:06 ` [Qemu-devel] [PULL v4 13/43] i386/cpu: Consolidate die-id validity in smp context Eduardo Habkost
2019-07-03 18:06 ` [Qemu-devel] [PULL v4 14/43] i386: Update new x86_apicid parsing rules with die_offset support Eduardo Habkost
2019-07-03 18:06 ` [Qemu-devel] [PULL v4 15/43] pc: fix possible NULL pointer dereference in pc_machine_get_device_memory_region_size() Eduardo Habkost
2019-07-03 18:06 ` [Qemu-devel] [PULL v4 16/43] machine: show if CLI option '-numa node, mem' is supported in QAPI schema Eduardo Habkost
2019-07-03 18:07 ` [Qemu-devel] [PULL v4 17/43] numa: deprecate 'mem' parameter of '-numa node' option Eduardo Habkost
2019-07-03 18:07 ` [Qemu-devel] [PULL v4 18/43] numa: deprecate implict memory distribution between nodes Eduardo Habkost
2019-07-03 18:07 ` [Qemu-devel] [PULL v4 19/43] hppa: Delete unused hppa_cpu_list() function Eduardo Habkost
2019-07-03 18:07 ` [Qemu-devel] [PULL v4 20/43] target/i386: fix feature check in hyperv-stub.c Eduardo Habkost
2019-07-03 18:07 ` [Qemu-devel] [PULL v4 21/43] deprecate -mem-path fallback to anonymous RAM Eduardo Habkost
2019-07-03 18:07 ` [Qemu-devel] [PULL v4 22/43] i386: Don't print warning if phys-bits was set automatically Eduardo Habkost
2019-07-03 18:07 ` [Qemu-devel] [PULL v4 23/43] i386: Fix signedness of hyperv_spinlock_attempts Eduardo Habkost
2019-07-03 18:07 ` [Qemu-devel] [PULL v4 24/43] i386: make 'hv-spinlocks' a regular uint32 property Eduardo Habkost
2019-07-03 18:07 ` [Qemu-devel] [PULL v4 25/43] x86/cpu: use FeatureWordArray to define filtered_features Eduardo Habkost
2019-07-03 18:07 ` [Qemu-devel] [PULL v4 26/43] i386: Remove unused host_cpudef variable Eduardo Habkost
2019-07-03 18:07 ` [Qemu-devel] [PULL v4 27/43] target/i386: Add CPUID.1F generation support for multi-dies PCMachine Eduardo Habkost
2019-07-03 18:07 ` [Qemu-devel] [PULL v4 28/43] machine: Refactor smp_parse() in vl.c as MachineClass::smp_parse() Eduardo Habkost
2019-07-03 18:07 ` [Qemu-devel] [PULL v4 29/43] vl.c: Add -smp, dies=* command line support and update doc Eduardo Habkost
2019-07-03 18:07 ` [Qemu-devel] [PULL v4 30/43] qmp: Add deprecation information to query-machines Eduardo Habkost
2019-07-03 18:07 ` [Qemu-devel] [PULL v4 31/43] i386: Introduce SnowRidge CPU model Eduardo Habkost
2019-07-03 18:07 ` [Qemu-devel] [PULL v4 32/43] qmp: Add "alias-of" field to query-cpu-definitions Eduardo Habkost
2019-07-03 18:07 ` [Qemu-devel] [PULL v4 33/43] i386: Add x-force-features option for testing Eduardo Habkost
2019-07-03 18:07 ` [Qemu-devel] [PULL v4 34/43] i386: Get model-id from CPU object on "-cpu help" Eduardo Habkost
2019-07-03 18:07 ` [Qemu-devel] [PULL v4 35/43] i386: Register versioned CPU models Eduardo Habkost
2019-07-03 18:07 ` [Qemu-devel] [PULL v4 36/43] i386: Define -IBRS, -noTSX, -IBRS versions of " Eduardo Habkost
2019-07-03 18:07 ` [Qemu-devel] [PULL v4 37/43] i386: Replace -noTSX, -IBRS, -IBPB CPU models with aliases Eduardo Habkost
2019-07-03 18:07 ` [Qemu-devel] [PULL v4 38/43] i386: Make unversioned CPU models be aliases Eduardo Habkost
2019-07-03 18:07 ` [Qemu-devel] [PULL v4 39/43] docs: Deprecate CPU model runnability guarantees Eduardo Habkost
2019-07-03 18:07 ` [Qemu-devel] [PULL v4 40/43] i386: Add Cascadelake-Server-v2 CPU model Eduardo Habkost
2019-07-03 18:07 ` [Qemu-devel] [PULL v4 41/43] numa: Make deprecation warnings conditional on !qtest_enabled() Eduardo Habkost
2019-07-03 18:07 ` [Qemu-devel] [PULL v4 42/43] numa: allow memory-less nodes when using memdev as backend Eduardo Habkost
2019-07-03 18:07 ` [Qemu-devel] [PULL v4 43/43] tests: use -numa memdev option in tests instead of legacy 'mem' option Eduardo Habkost
2019-07-03 18:49 ` [Qemu-devel] [PULL v4 00/43] Machine and x86 queue, 2019-07-03 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=20190703180726.31267-4-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).