cpu: Replace qemu_for_each_cpu()
It was introduced to loop over CPUs from target-independent code, but
since commit 182735efaf
target-independent
CPUState is used.
A loop can be considered more efficient than function calls in a loop,
and CPU_FOREACH() hides implementation details just as well, so use that
instead.
Suggested-by: Markus Armbruster <armbru@redhat.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
This commit is contained in:
parent
bdc44640cb
commit
38fcbd3f08
11
arch_init.c
11
arch_init.c
@ -1196,15 +1196,14 @@ static void mig_sleep_cpu(void *opq)
|
|||||||
much time in the VM. The migration thread will try to catchup.
|
much time in the VM. The migration thread will try to catchup.
|
||||||
Workload will experience a performance drop.
|
Workload will experience a performance drop.
|
||||||
*/
|
*/
|
||||||
static void mig_throttle_cpu_down(CPUState *cpu, void *data)
|
|
||||||
{
|
|
||||||
async_run_on_cpu(cpu, mig_sleep_cpu, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void mig_throttle_guest_down(void)
|
static void mig_throttle_guest_down(void)
|
||||||
{
|
{
|
||||||
|
CPUState *cpu;
|
||||||
|
|
||||||
qemu_mutex_lock_iothread();
|
qemu_mutex_lock_iothread();
|
||||||
qemu_for_each_cpu(mig_throttle_cpu_down, NULL);
|
CPU_FOREACH(cpu) {
|
||||||
|
async_run_on_cpu(cpu, mig_sleep_cpu, NULL);
|
||||||
|
}
|
||||||
qemu_mutex_unlock_iothread();
|
qemu_mutex_unlock_iothread();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
11
cpus.c
11
cpus.c
@ -854,12 +854,6 @@ static void *qemu_dummy_cpu_thread_fn(void *arg)
|
|||||||
|
|
||||||
static void tcg_exec_all(void);
|
static void tcg_exec_all(void);
|
||||||
|
|
||||||
static void tcg_signal_cpu_creation(CPUState *cpu, void *data)
|
|
||||||
{
|
|
||||||
cpu->thread_id = qemu_get_thread_id();
|
|
||||||
cpu->created = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void *qemu_tcg_cpu_thread_fn(void *arg)
|
static void *qemu_tcg_cpu_thread_fn(void *arg)
|
||||||
{
|
{
|
||||||
CPUState *cpu = arg;
|
CPUState *cpu = arg;
|
||||||
@ -868,7 +862,10 @@ static void *qemu_tcg_cpu_thread_fn(void *arg)
|
|||||||
qemu_thread_get_self(cpu->thread);
|
qemu_thread_get_self(cpu->thread);
|
||||||
|
|
||||||
qemu_mutex_lock(&qemu_global_mutex);
|
qemu_mutex_lock(&qemu_global_mutex);
|
||||||
qemu_for_each_cpu(tcg_signal_cpu_creation, NULL);
|
CPU_FOREACH(cpu) {
|
||||||
|
cpu->thread_id = qemu_get_thread_id();
|
||||||
|
cpu->created = true;
|
||||||
|
}
|
||||||
qemu_cond_signal(&qemu_cpu_cond);
|
qemu_cond_signal(&qemu_cpu_cond);
|
||||||
|
|
||||||
/* wait for initial kick-off after machine start */
|
/* wait for initial kick-off after machine start */
|
||||||
|
9
exec.c
9
exec.c
@ -362,15 +362,6 @@ CPUState *qemu_get_cpu(int index)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void qemu_for_each_cpu(void (*func)(CPUState *cpu, void *data), void *data)
|
|
||||||
{
|
|
||||||
CPUState *cpu;
|
|
||||||
|
|
||||||
CPU_FOREACH(cpu) {
|
|
||||||
func(cpu, data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void cpu_exec_init(CPUArchState *env)
|
void cpu_exec_init(CPUArchState *env)
|
||||||
{
|
{
|
||||||
CPUState *cpu = ENV_GET_CPU(env);
|
CPUState *cpu = ENV_GET_CPU(env);
|
||||||
|
@ -667,22 +667,14 @@ static void piix4_cpu_added_req(Notifier *n, void *opaque)
|
|||||||
piix4_cpu_hotplug_req(s, CPU(opaque), PLUG);
|
piix4_cpu_hotplug_req(s, CPU(opaque), PLUG);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void piix4_init_cpu_status(CPUState *cpu, void *data)
|
|
||||||
{
|
|
||||||
CPUStatus *g = (CPUStatus *)data;
|
|
||||||
CPUClass *k = CPU_GET_CLASS(cpu);
|
|
||||||
int64_t id = k->get_arch_id(cpu);
|
|
||||||
|
|
||||||
g_assert((id / 8) < PIIX4_PROC_LEN);
|
|
||||||
g->sts[id / 8] |= (1 << (id % 8));
|
|
||||||
}
|
|
||||||
|
|
||||||
static int piix4_device_hotplug(DeviceState *qdev, PCIDevice *dev,
|
static int piix4_device_hotplug(DeviceState *qdev, PCIDevice *dev,
|
||||||
PCIHotplugState state);
|
PCIHotplugState state);
|
||||||
|
|
||||||
static void piix4_acpi_system_hot_add_init(MemoryRegion *parent,
|
static void piix4_acpi_system_hot_add_init(MemoryRegion *parent,
|
||||||
PCIBus *bus, PIIX4PMState *s)
|
PCIBus *bus, PIIX4PMState *s)
|
||||||
{
|
{
|
||||||
|
CPUState *cpu;
|
||||||
|
|
||||||
memory_region_init_io(&s->io_gpe, OBJECT(s), &piix4_gpe_ops, s,
|
memory_region_init_io(&s->io_gpe, OBJECT(s), &piix4_gpe_ops, s,
|
||||||
"acpi-gpe0", GPE_LEN);
|
"acpi-gpe0", GPE_LEN);
|
||||||
memory_region_add_subregion(parent, GPE_BASE, &s->io_gpe);
|
memory_region_add_subregion(parent, GPE_BASE, &s->io_gpe);
|
||||||
@ -693,7 +685,13 @@ static void piix4_acpi_system_hot_add_init(MemoryRegion *parent,
|
|||||||
&s->io_pci);
|
&s->io_pci);
|
||||||
pci_bus_hotplug(bus, piix4_device_hotplug, DEVICE(s));
|
pci_bus_hotplug(bus, piix4_device_hotplug, DEVICE(s));
|
||||||
|
|
||||||
qemu_for_each_cpu(piix4_init_cpu_status, &s->gpe_cpu);
|
CPU_FOREACH(cpu) {
|
||||||
|
CPUClass *cc = CPU_GET_CLASS(cpu);
|
||||||
|
int64_t id = cc->get_arch_id(cpu);
|
||||||
|
|
||||||
|
g_assert((id / 8) < PIIX4_PROC_LEN);
|
||||||
|
s->gpe_cpu.sts[id / 8] |= (1 << (id % 8));
|
||||||
|
}
|
||||||
memory_region_init_io(&s->io_cpu, OBJECT(s), &cpu_hotplug_ops, s,
|
memory_region_init_io(&s->io_cpu, OBJECT(s), &cpu_hotplug_ops, s,
|
||||||
"acpi-cpu-hotplug", PIIX4_PROC_LEN);
|
"acpi-cpu-hotplug", PIIX4_PROC_LEN);
|
||||||
memory_region_add_subregion(parent, PIIX4_PROC_BASE, &s->io_cpu);
|
memory_region_add_subregion(parent, PIIX4_PROC_BASE, &s->io_cpu);
|
||||||
|
@ -402,15 +402,6 @@ void run_on_cpu(CPUState *cpu, void (*func)(void *data), void *data);
|
|||||||
*/
|
*/
|
||||||
void async_run_on_cpu(CPUState *cpu, void (*func)(void *data), void *data);
|
void async_run_on_cpu(CPUState *cpu, void (*func)(void *data), void *data);
|
||||||
|
|
||||||
/**
|
|
||||||
* qemu_for_each_cpu:
|
|
||||||
* @func: The function to be executed.
|
|
||||||
* @data: Data to pass to the function.
|
|
||||||
*
|
|
||||||
* Executes @func for each CPU.
|
|
||||||
*/
|
|
||||||
void qemu_for_each_cpu(void (*func)(CPUState *cpu, void *data), void *data);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* qemu_get_cpu:
|
* qemu_get_cpu:
|
||||||
* @index: The CPUState@cpu_index value of the CPU to obtain.
|
* @index: The CPUState@cpu_index value of the CPU to obtain.
|
||||||
|
30
qom/cpu.c
30
qom/cpu.c
@ -25,30 +25,18 @@
|
|||||||
#include "qemu/log.h"
|
#include "qemu/log.h"
|
||||||
#include "sysemu/sysemu.h"
|
#include "sysemu/sysemu.h"
|
||||||
|
|
||||||
typedef struct CPUExistsArgs {
|
|
||||||
int64_t id;
|
|
||||||
bool found;
|
|
||||||
} CPUExistsArgs;
|
|
||||||
|
|
||||||
static void cpu_exist_cb(CPUState *cpu, void *data)
|
|
||||||
{
|
|
||||||
CPUClass *klass = CPU_GET_CLASS(cpu);
|
|
||||||
CPUExistsArgs *arg = data;
|
|
||||||
|
|
||||||
if (klass->get_arch_id(cpu) == arg->id) {
|
|
||||||
arg->found = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool cpu_exists(int64_t id)
|
bool cpu_exists(int64_t id)
|
||||||
{
|
{
|
||||||
CPUExistsArgs data = {
|
CPUState *cpu;
|
||||||
.id = id,
|
|
||||||
.found = false,
|
|
||||||
};
|
|
||||||
|
|
||||||
qemu_for_each_cpu(cpu_exist_cb, &data);
|
CPU_FOREACH(cpu) {
|
||||||
return data.found;
|
CPUClass *cc = CPU_GET_CLASS(cpu);
|
||||||
|
|
||||||
|
if (cc->get_arch_id(cpu) == id) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cpu_paging_enabled(const CPUState *cpu)
|
bool cpu_paging_enabled(const CPUState *cpu)
|
||||||
|
Loading…
Reference in New Issue
Block a user