- fix compile error on loongarch
- hw/loongarch: fix cpu hotplug reset
- hw/loongarch/boot: Use warn_report when no kernel filename
- hw/loongarch: clean code
- hw/loongarch: Add KVM pch msi device support
- hw/loongarch: Add KVM pch pic device support
- hw/loongarch: Add KVM extioi device support
- hw/loongarch: Add KVM IPI device support
- hw/loongarch/virt: Update the ACPI table for hotplug cpu
- hw/loongarch/virt: Add basic CPU plug support
- hw/loongarch/virt: Add CPU topology support
- accel/kvm/kvm-all: Fixes the missing break in vCPU unpark logic
- gdbstub: Add helper function to unregister GDB register space
- physmem: Add helper function to destroy CPU AddressSpace
- hw/acpi: Update CPUs AML with cpu-(ctrl)dev change
- hw/acpi: Update ACPI GED framework to support vCPU Hotplug
- hw/acpi: Move CPU ctrl-dev MMIO region len macro to common header file
- accel/kvm: Extract common KVM vCPU {creation,parking} code
- target/loongarch: Add steal time support on migration
- linux-headers: loongarch: Add kvm_para.h and unistd_64.h
- target/loongarch/kvm: Implement LoongArch PMU extension
- target/loongarch: Implement lbt registers save/restore function
- target/loongarch: Add loongson binary translation feature
- sync loongarch linux-headers
- target/loongarch: Avoid bits shift exceeding width of bool type
- target/loongarch: Use explicit little-endian LD/ST API
- target/loongarch: fix -Werror=maybe-uninitialized false-positive
- target/loongarch: Support QMP dump-guest-memory
- target/loongarch/kvm: Add vCPU reset function
- target/loongarch: Add compatible support about VM reboot
- target/loongarch: Fix cpu_reset set wrong CSR_CRMD
- target/loongarch: Set CSR_PRCFG1 and CSR_PRCFG2 values
- target/loongarch: Remove avail_64 in trans_srai_w() and simplify it
- target/loongarch/kvm: Add software breakpoint support
- target/loongarch: Add loongarch vector property unconditionally
- target/loongarch/kvm: Fix VM recovery from disk failures
- target/loongarch: Put cpucfg operation before CSR register
- target/loongarch: Add TCG macro in structure CPUArchState
- hw/arm/virt-acpi-build.c: Migrate SPCR creation to common location
- hw/loongarch/virt: Add FDT table support with acpi ged pm register
- hw/loongarch/virt: Add description for virt machine type
- hw/loongarch: Add acpi SPCR table support
- hw/loongarch: virt: pass random seed to fdt
- hw/loongarch: virt: support up to 4 serial ports
- hw/loongarch: Remove default enable with VIRTIO_VGA device
- hw/loongarch: Fix length for lowram in ACPI SRAT
- hw/loongarch/virt: Remove unused assignment
- hw/loongarch: Change the tpm support by default
- hw/loongarch/boot.c: fix out-of-bound reading
- hw/loongarch/virt: Use MemTxAttrs interface for misc ops
- tests/libqos: Add loongarch virt machine node
- hw/loongarch: Remove minimum and default memory size
- hw/loongarch: Refine system dram memory region
- hw/loongarch: Refine fwcfg memory map
- hw/loongarch: Refine fadt memory table for numa memory
- hw/loongarch: Refine acpi srat table for numa memory
- hw/loongarch: Add VM mode in IOCSR feature register in kvm mode
- hw/loongarch: Refine default numa id calculation
- hw/loongarch: Rename LoongArchMachineState with LoongArchVirtMachineState
- hw/loongarch: Rename LOONGARCH_MACHINE with LOONGARCH_VIRT_MACHINE
- hw/loongarch: move memory map to boot.c
- loongarch: switch boards to "default y"
- hw/loongarch: Add cells missing from rtc node
- hw/loongarch: Add cells missing from uart node
- hw/loongarch: fdt remove unused irqchip node
- hw/loongarch: fdt adds pcie irq_map node
- hw/loongarch: fdt adds pch_msi Controller
- hw/loongarch: fdt adds pch_pic Controller
- hw/loongarch: fdt adds Extend I/O Interrupt Controller
- hw/loongarch: fdt adds cpu interrupt controller node
- hw/loongarch: Init efi_fdt table
- hw/loongarch: Init efi_initrd table
- hw/loongarch: Init efi_boot_memmap table
- hw/loongarch: Init efi_system_table
- hw/loongarch: Add init_cmdline
- hw/loongarch: Add slave cpu boot_code
- hw/loongarch: Add load initrd
- hw/loongarch: Move boot functions to boot.c
Signed-off-by: Xianglai Li <lixianglai@loongson.cn>
(cherry picked from commit 04ca9e6c8ff19630116722240ae0136cea831c5c)
279 lines
10 KiB
Diff
279 lines
10 KiB
Diff
From 8d440efd992fd6be0aca55118a9b60c224f6eade Mon Sep 17 00:00:00 2001
|
|
From: Bibo Mao <maobibo@loongson.cn>
|
|
Date: Wed, 23 Oct 2024 15:13:10 +0800
|
|
Subject: [PATCH 69/78] hw/loongarch/virt: Add CPU topology support
|
|
|
|
Add topological relationships for Loongarch VCPU and initialize
|
|
topology member variables. Also physical cpu id calculation
|
|
method comes from its topo information.
|
|
|
|
Co-developed-by: Xianglai Li <lixianglai@loongson.cn>
|
|
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
|
|
Message-ID: <20241023071312.881866-2-maobibo@loongson.cn>
|
|
Signed-off-by: Xianglai Li <lixianglai@loongson.cn>
|
|
---
|
|
docs/system/loongarch/virt.rst | 31 +++++++++++++
|
|
hw/loongarch/virt.c | 82 ++++++++++++++++++++++++++++------
|
|
target/loongarch/cpu.c | 12 +++++
|
|
target/loongarch/cpu.h | 11 +++++
|
|
4 files changed, 122 insertions(+), 14 deletions(-)
|
|
|
|
diff --git a/docs/system/loongarch/virt.rst b/docs/system/loongarch/virt.rst
|
|
index c37268b404..aa4719d4bd 100644
|
|
--- a/docs/system/loongarch/virt.rst
|
|
+++ b/docs/system/loongarch/virt.rst
|
|
@@ -28,6 +28,37 @@ The ``qemu-system-loongarch64`` provides emulation for virt
|
|
machine. You can specify the machine type ``virt`` and
|
|
cpu type ``la464``.
|
|
|
|
+CPU Topology
|
|
+------------
|
|
+
|
|
+The ``LA464`` type CPUs have the concept of Socket Core and Thread.
|
|
+
|
|
+For example:
|
|
+
|
|
+``-smp 1,maxcpus=M,sockets=S,cores=C,threads=T``
|
|
+
|
|
+The above parameters indicate that the machine has a maximum of ``M`` vCPUs and
|
|
+``S`` sockets, each socket has ``C`` cores, each core has ``T`` threads,
|
|
+and each thread corresponds to a vCPU.
|
|
+
|
|
+Then ``M`` ``S`` ``C`` ``T`` has the following relationship:
|
|
+
|
|
+``M = S * C * T``
|
|
+
|
|
+In the CPU topology relationship, When we know the ``socket_id`` ``core_id``
|
|
+and ``thread_id`` of the CPU, we can calculate its ``arch_id``:
|
|
+
|
|
+``arch_id = (socket_id * S) + (core_id * C) + (thread_id * T)``
|
|
+
|
|
+Similarly, when we know the ``arch_id`` of the CPU,
|
|
+we can also get its ``socket_id`` ``core_id`` and ``thread_id``:
|
|
+
|
|
+``socket_id = arch_id / (C * T)``
|
|
+
|
|
+``core_id = (arch_id / T) % C``
|
|
+
|
|
+``thread_id = arch_id % T``
|
|
+
|
|
Boot options
|
|
------------
|
|
|
|
diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c
|
|
index 9510aa7a7e..8d1e53ff62 100644
|
|
--- a/hw/loongarch/virt.c
|
|
+++ b/hw/loongarch/virt.c
|
|
@@ -1123,9 +1123,7 @@ static void virt_init(MachineState *machine)
|
|
LoongArchVirtMachineState *lvms = LOONGARCH_VIRT_MACHINE(machine);
|
|
int i;
|
|
hwaddr base, size, ram_size = machine->ram_size;
|
|
- const CPUArchIdList *possible_cpus;
|
|
MachineClass *mc = MACHINE_GET_CLASS(machine);
|
|
- CPUState *cpu;
|
|
|
|
if (!cpu_model) {
|
|
cpu_model = LOONGARCH_CPU_TYPE_NAME("la464");
|
|
@@ -1143,14 +1141,39 @@ static void virt_init(MachineState *machine)
|
|
memory_region_add_subregion(&lvms->system_iocsr, 0, &lvms->iocsr_mem);
|
|
|
|
/* Init CPUs */
|
|
- possible_cpus = mc->possible_cpu_arch_ids(machine);
|
|
- for (i = 0; i < possible_cpus->len; i++) {
|
|
- cpu = cpu_create(machine->cpu_type);
|
|
- cpu->cpu_index = i;
|
|
- machine->possible_cpus->cpus[i].cpu = OBJECT(cpu);
|
|
- lacpu = LOONGARCH_CPU(cpu);
|
|
+ mc->possible_cpu_arch_ids(machine);
|
|
+ for (i = 0; i < machine->smp.cpus; i++) {
|
|
+ Object *cpuobj;
|
|
+ cpuobj = object_new(machine->cpu_type);
|
|
+ lacpu = LOONGARCH_CPU(cpuobj);
|
|
+
|
|
lacpu->phy_id = machine->possible_cpus->cpus[i].arch_id;
|
|
+ object_property_set_int(cpuobj, "socket-id",
|
|
+ machine->possible_cpus->cpus[i].props.socket_id,
|
|
+ NULL);
|
|
+ object_property_set_int(cpuobj, "core-id",
|
|
+ machine->possible_cpus->cpus[i].props.core_id,
|
|
+ NULL);
|
|
+ object_property_set_int(cpuobj, "thread-id",
|
|
+ machine->possible_cpus->cpus[i].props.thread_id,
|
|
+ NULL);
|
|
+ /*
|
|
+ * The CPU in place at the time of machine startup will also enter
|
|
+ * the CPU hot-plug process when it is created, but at this time,
|
|
+ * the GED device has not been created, resulting in exit in the CPU
|
|
+ * hot-plug process, which can avoid the incumbent CPU repeatedly
|
|
+ * applying for resources.
|
|
+ *
|
|
+ * The interrupt resource of the in-place CPU will be requested at
|
|
+ * the current function call loongarch_irq_init().
|
|
+ *
|
|
+ * The interrupt resource of the subsequently inserted CPU will be
|
|
+ * requested in the CPU hot-plug process.
|
|
+ */
|
|
+ qdev_realize(DEVICE(cpuobj), NULL, &error_fatal);
|
|
+ object_unref(cpuobj);
|
|
}
|
|
+
|
|
fdt_add_cpu_nodes(lvms);
|
|
fdt_add_memory_nodes(machine);
|
|
fw_cfg_add_memory(machine);
|
|
@@ -1266,6 +1289,27 @@ static void virt_initfn(Object *obj)
|
|
virt_flash_create(lvms);
|
|
}
|
|
|
|
+static int virt_get_arch_id_from_topo(MachineState *ms, LoongArchCPUTopo *topo)
|
|
+{
|
|
+ int arch_id, sock_vcpu_num, core_vcpu_num;
|
|
+
|
|
+ /*
|
|
+ * calculate total logical cpus across socket/core/thread.
|
|
+ * For more information on how to calculate the arch_id,
|
|
+ * you can refer to the CPU Topology chapter of the
|
|
+ * docs/system/loongarch/virt.rst document.
|
|
+ */
|
|
+ sock_vcpu_num = topo->socket_id * (ms->smp.threads * ms->smp.cores);
|
|
+ core_vcpu_num = topo->core_id * ms->smp.threads;
|
|
+
|
|
+ /* get vcpu-id(logical cpu index) for this vcpu from this topology */
|
|
+ arch_id = (sock_vcpu_num + core_vcpu_num) + topo->thread_id;
|
|
+
|
|
+ assert(arch_id >= 0 && arch_id < ms->possible_cpus->len);
|
|
+
|
|
+ return arch_id;
|
|
+}
|
|
+
|
|
static bool memhp_type_supported(DeviceState *dev)
|
|
{
|
|
/* we only support pc dimm now */
|
|
@@ -1363,10 +1407,19 @@ static HotplugHandler *virt_get_hotplug_handler(MachineState *machine,
|
|
return NULL;
|
|
}
|
|
|
|
+static void virt_get_cpu_topo_from_index(MachineState *ms,
|
|
+ LoongArchCPUTopo *topo, int index)
|
|
+{
|
|
+ topo->socket_id = index / (ms->smp.cores * ms->smp.threads);
|
|
+ topo->core_id = index / ms->smp.threads % ms->smp.cores;
|
|
+ topo->thread_id = index % ms->smp.threads;
|
|
+}
|
|
+
|
|
static const CPUArchIdList *virt_possible_cpu_arch_ids(MachineState *ms)
|
|
{
|
|
int n;
|
|
unsigned int max_cpus = ms->smp.max_cpus;
|
|
+ LoongArchCPUTopo topo;
|
|
|
|
if (ms->possible_cpus) {
|
|
assert(ms->possible_cpus->len == max_cpus);
|
|
@@ -1377,17 +1430,18 @@ static const CPUArchIdList *virt_possible_cpu_arch_ids(MachineState *ms)
|
|
sizeof(CPUArchId) * max_cpus);
|
|
ms->possible_cpus->len = max_cpus;
|
|
for (n = 0; n < ms->possible_cpus->len; n++) {
|
|
+ ms->possible_cpus->cpus[n].vcpus_count = ms->smp.threads;
|
|
ms->possible_cpus->cpus[n].type = ms->cpu_type;
|
|
- ms->possible_cpus->cpus[n].arch_id = n;
|
|
+ virt_get_cpu_topo_from_index(ms, &topo, n);
|
|
|
|
ms->possible_cpus->cpus[n].props.has_socket_id = true;
|
|
- ms->possible_cpus->cpus[n].props.socket_id =
|
|
- n / (ms->smp.cores * ms->smp.threads);
|
|
+ ms->possible_cpus->cpus[n].props.socket_id = topo.socket_id;
|
|
ms->possible_cpus->cpus[n].props.has_core_id = true;
|
|
- ms->possible_cpus->cpus[n].props.core_id =
|
|
- n / ms->smp.threads % ms->smp.cores;
|
|
+ ms->possible_cpus->cpus[n].props.core_id = topo.core_id;
|
|
ms->possible_cpus->cpus[n].props.has_thread_id = true;
|
|
- ms->possible_cpus->cpus[n].props.thread_id = n % ms->smp.threads;
|
|
+ ms->possible_cpus->cpus[n].props.thread_id = topo.thread_id;
|
|
+ ms->possible_cpus->cpus[n].arch_id =
|
|
+ virt_get_arch_id_from_topo(ms, &topo);
|
|
}
|
|
return ms->possible_cpus;
|
|
}
|
|
diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c
|
|
index 2ee1d63989..673ed8ea18 100644
|
|
--- a/target/loongarch/cpu.c
|
|
+++ b/target/loongarch/cpu.c
|
|
@@ -17,6 +17,7 @@
|
|
#include "kvm/kvm_loongarch.h"
|
|
#include "exec/exec-all.h"
|
|
#include "cpu.h"
|
|
+#include "hw/qdev-properties.h"
|
|
#include "internals.h"
|
|
#include "fpu/softfloat-helpers.h"
|
|
#include "cpu-csr.h"
|
|
@@ -860,6 +861,15 @@ static int64_t loongarch_cpu_get_arch_id(CPUState *cs)
|
|
}
|
|
#endif
|
|
|
|
+static Property loongarch_cpu_properties[] = {
|
|
+ DEFINE_PROP_INT32("socket-id", LoongArchCPU, socket_id, 0),
|
|
+ DEFINE_PROP_INT32("core-id", LoongArchCPU, core_id, 0),
|
|
+ DEFINE_PROP_INT32("thread-id", LoongArchCPU, thread_id, 0),
|
|
+ DEFINE_PROP_INT32("node-id", LoongArchCPU, node_id, CPU_UNSET_NUMA_NODE_ID),
|
|
+
|
|
+ DEFINE_PROP_END_OF_LIST()
|
|
+};
|
|
+
|
|
static void loongarch_cpu_class_init(ObjectClass *c, void *data)
|
|
{
|
|
LoongArchCPUClass *lacc = LOONGARCH_CPU_CLASS(c);
|
|
@@ -867,6 +877,7 @@ static void loongarch_cpu_class_init(ObjectClass *c, void *data)
|
|
DeviceClass *dc = DEVICE_CLASS(c);
|
|
ResettableClass *rc = RESETTABLE_CLASS(c);
|
|
|
|
+ device_class_set_props(dc, loongarch_cpu_properties);
|
|
device_class_set_parent_realize(dc, loongarch_cpu_realizefn,
|
|
&lacc->parent_realize);
|
|
resettable_class_set_parent_phases(rc, NULL, loongarch_cpu_reset_hold, NULL,
|
|
@@ -890,6 +901,7 @@ static void loongarch_cpu_class_init(ObjectClass *c, void *data)
|
|
#ifdef CONFIG_TCG
|
|
cc->tcg_ops = &loongarch_tcg_ops;
|
|
#endif
|
|
+ dc->user_creatable = true;
|
|
}
|
|
|
|
static const gchar *loongarch32_gdb_arch_name(CPUState *cs)
|
|
diff --git a/target/loongarch/cpu.h b/target/loongarch/cpu.h
|
|
index 4c90cf9ef3..9af622aba5 100644
|
|
--- a/target/loongarch/cpu.h
|
|
+++ b/target/loongarch/cpu.h
|
|
@@ -398,6 +398,12 @@ typedef struct CPUArchState {
|
|
} st;
|
|
} CPULoongArchState;
|
|
|
|
+typedef struct LoongArchCPUTopo {
|
|
+ int32_t socket_id; /* socket-id of this VCPU */
|
|
+ int32_t core_id; /* core-id of this VCPU */
|
|
+ int32_t thread_id; /* thread-id of this VCPU */
|
|
+} LoongArchCPUTopo;
|
|
+
|
|
/**
|
|
* LoongArchCPU:
|
|
* @env: #CPULoongArchState
|
|
@@ -412,6 +418,10 @@ struct ArchCPU {
|
|
uint32_t phy_id;
|
|
OnOffAuto lbt;
|
|
OnOffAuto pmu;
|
|
+ int32_t socket_id; /* socket-id of this VCPU */
|
|
+ int32_t core_id; /* core-id of this VCPU */
|
|
+ int32_t thread_id; /* thread-id of this VCPU */
|
|
+ int32_t node_id; /* NUMA node this CPU belongs to */
|
|
|
|
/* 'compatible' string for this CPU for Linux device trees */
|
|
const char *dtb_compatible;
|
|
@@ -430,6 +440,7 @@ struct LoongArchCPUClass {
|
|
CPUClass parent_class;
|
|
|
|
DeviceRealize parent_realize;
|
|
+ DeviceUnrealize parent_unrealize;
|
|
ResettablePhases parent_phases;
|
|
};
|
|
|
|
--
|
|
2.39.1
|
|
|