[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-stable] [PATCH 010/113] spapr: move VCPU calculation to core machi
From: |
Michael Roth |
Subject: |
[Qemu-stable] [PATCH 010/113] spapr: move VCPU calculation to core machine code |
Date: |
Mon, 18 Jun 2018 20:41:36 -0500 |
From: Greg Kurz <address@hidden>
The VCPU ids are currently computed and assigned to each individual
CPU threads in spapr_cpu_core_realize(). But the numbering logic
of VCPU ids is actually a machine-level concept, and many places
in hw/ppc/spapr.c also have to compute VCPU ids out of CPU indexes.
The current formula used in spapr_cpu_core_realize() is:
vcpu_id = (cc->core_id * spapr->vsmt / smp_threads) + i
where:
cc->core_id is a multiple of smp_threads
cpu_index = cc->core_id + i
0 <= i < smp_threads
So we have:
cpu_index % smp_threads == i
cc->core_id / smp_threads == cpu_index / smp_threads
hence:
vcpu_id =
(cpu_index / smp_threads) * spapr->vsmt + cpu_index % smp_threads;
This formula was used before VSMT at the time VCPU ids where computed
at the target emulation level. It has the advantage of being useable
to derive a VPCU id out of a CPU index only. It is fitted for all the
places where the machine code has to compute a VCPU id.
This patch introduces an accessor to set the VCPU id in a PowerPCCPU object
using the above formula. It is a first step to consolidate all the VCPU id
logic in a single place.
Signed-off-by: Greg Kurz <address@hidden>
Signed-off-by: David Gibson <address@hidden>
(cherry picked from commit 648edb64751ea0e550f36302fa66f9f11e480824)
Signed-off-by: Greg Kurz <address@hidden>
---
hw/ppc/spapr.c | 19 +++++++++++++++++++
hw/ppc/spapr_cpu_core.c | 9 ++-------
include/hw/ppc/spapr.h | 1 +
3 files changed, 22 insertions(+), 7 deletions(-)
diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index 094e75f97d..f9505d926d 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -3647,6 +3647,25 @@ int spapr_vcpu_id(PowerPCCPU *cpu)
}
}
+void spapr_set_vcpu_id(PowerPCCPU *cpu, int cpu_index, Error **errp)
+{
+ sPAPRMachineState *spapr = SPAPR_MACHINE(qdev_get_machine());
+ int vcpu_id;
+
+ vcpu_id =
+ (cpu_index / smp_threads) * spapr->vsmt + cpu_index % smp_threads;
+
+ if (kvm_enabled() && !kvm_vcpu_id_is_valid(vcpu_id)) {
+ error_setg(errp, "Can't create CPU with id %d in KVM", vcpu_id);
+ error_append_hint(errp, "Adjust the number of cpus to %d "
+ "or try to raise the number of threads per core\n",
+ vcpu_id * smp_threads / spapr->vsmt);
+ return;
+ }
+
+ cpu->vcpu_id = vcpu_id;
+}
+
PowerPCCPU *spapr_find_cpu(int vcpu_id)
{
CPUState *cs;
diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c
index e8b0ffb1b1..1c508022aa 100644
--- a/hw/ppc/spapr_cpu_core.c
+++ b/hw/ppc/spapr_cpu_core.c
@@ -176,13 +176,8 @@ static void spapr_cpu_core_realize(DeviceState *dev, Error
**errp)
cs = CPU(obj);
cpu = POWERPC_CPU(cs);
cs->cpu_index = cc->core_id + i;
- cpu->vcpu_id = (cc->core_id * spapr->vsmt / smp_threads) + i;
- if (kvm_enabled() && !kvm_vcpu_id_is_valid(cpu->vcpu_id)) {
- error_setg(&local_err, "Can't create CPU with id %d in KVM",
- cpu->vcpu_id);
- error_append_hint(&local_err, "Adjust the number of cpus to %d "
- "or try to raise the number of threads per
core\n",
- cpu->vcpu_id * smp_threads / spapr->vsmt);
+ spapr_set_vcpu_id(cpu, cs->cpu_index, &local_err);
+ if (local_err) {
goto err;
}
diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h
index 363ffd71c4..38a657426a 100644
--- a/include/hw/ppc/spapr.h
+++ b/include/hw/ppc/spapr.h
@@ -757,6 +757,7 @@ void spapr_do_system_reset_on_cpu(CPUState *cs,
run_on_cpu_data arg);
#define HTAB_SIZE(spapr) (1ULL << ((spapr)->htab_shift))
int spapr_vcpu_id(PowerPCCPU *cpu);
+void spapr_set_vcpu_id(PowerPCCPU *cpu, int cpu_index, Error **errp);
PowerPCCPU *spapr_find_cpu(int vcpu_id);
int spapr_caps_pre_load(void *opaque);
--
2.11.0
- [Qemu-stable] [PATCH 009/113] spapr: use spapr->vsmt to compute VCPU ids, (continued)
- [Qemu-stable] [PATCH 009/113] spapr: use spapr->vsmt to compute VCPU ids, Michael Roth, 2018/06/18
- [Qemu-stable] [PATCH 102/113] qcow2: Do not mark inactive images corrupt, Michael Roth, 2018/06/18
- [Qemu-stable] [PATCH 104/113] throttle: Fix crash on reopen, Michael Roth, 2018/06/18
- [Qemu-stable] [PATCH 103/113] iotests: Add case for a corrupted inactive image, Michael Roth, 2018/06/18
- [Qemu-stable] [PATCH 105/113] vga: fix region calculation, Michael Roth, 2018/06/18
- [Qemu-stable] [PATCH 106/113] i386: define the 'ssbd' CPUID feature bit (CVE-2018-3639), Michael Roth, 2018/06/18
- [Qemu-stable] [PATCH 107/113] i386: Define the Virt SSBD MSR and handling of it (CVE-2018-3639), Michael Roth, 2018/06/18
- [Qemu-stable] [PATCH 108/113] i386: define the AMD 'virt-ssbd' CPUID feature bit (CVE-2018-3639), Michael Roth, 2018/06/18
- [Qemu-stable] [PATCH 110/113] vhost-user: delete net client if necessary, Michael Roth, 2018/06/18
- [Qemu-stable] [PATCH 109/113] tap: set vhostfd passed from qemu cli to non-blocking, Michael Roth, 2018/06/18
- [Qemu-stable] [PATCH 010/113] spapr: move VCPU calculation to core machine code,
Michael Roth <=
- [Qemu-stable] [PATCH 111/113] qemu-img: Fix assert when mapping unaligned raw file, Michael Roth, 2018/06/18
- [Qemu-stable] [PATCH 113/113] arm_gicv3_kvm: kvm_dist_get/put_priority: skip the registers banked by GICR_IPRIORITYR, Michael Roth, 2018/06/18
- [Qemu-stable] [PATCH 112/113] iotests: Add test 221 to catch qemu-img map regression, Michael Roth, 2018/06/18
- [Qemu-stable] [PATCH 011/113] target/ppc: Clarify compat mode max_threads value, Michael Roth, 2018/06/18
- [Qemu-stable] [PATCH 012/113] spapr: rename spapr_vcpu_id() to spapr_get_vcpu_id(), Michael Roth, 2018/06/18
- [Qemu-stable] [PATCH 013/113] spapr: consolidate the VCPU id numbering logic in a single place, Michael Roth, 2018/06/18
- [Qemu-stable] [PATCH 015/113] spapr: register dummy ICPs later, Michael Roth, 2018/06/18
- [Qemu-stable] [PATCH 014/113] spapr: fix missing CPU core nodes in DT when running with TCG, Michael Roth, 2018/06/18
- [Qemu-stable] [PATCH 016/113] spapr: make pseries-2.11 the default machine type, Michael Roth, 2018/06/18
- [Qemu-stable] [PATCH 017/113] nbd: Honor server's advertised minimum block size, Michael Roth, 2018/06/18