mirror of https://github.com/xqemu/xqemu.git
exec: Set cpu_index only if it's not been explictly set
It keeps the legacy behavior for all users that doesn't care about stable cpu_index value, but would allow boards that would support device_add/device_del to set stable cpu_index that won't depend on order in which cpus are created/destroyed. While at that simplify cpu_get_free_index() as cpu_index generated by USER_ONLY and softmmu variants is the same since none of the users support cpu-remove so far, except of not yet released spapr/x86 device_add/delr, which will be altered by follow up patches to set stable cpu_index manually. Signed-off-by: Igor Mammedov <imammedo@redhat.com> Reviewed-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
This commit is contained in:
parent
8b1b835035
commit
a07f953ef4
44
exec.c
44
exec.c
|
@ -598,30 +598,7 @@ AddressSpace *cpu_get_address_space(CPUState *cpu, int asidx)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef CONFIG_USER_ONLY
|
static int cpu_get_free_index(void)
|
||||||
static DECLARE_BITMAP(cpu_index_map, MAX_CPUMASK_BITS);
|
|
||||||
|
|
||||||
static int cpu_get_free_index(Error **errp)
|
|
||||||
{
|
|
||||||
int cpu = find_first_zero_bit(cpu_index_map, MAX_CPUMASK_BITS);
|
|
||||||
|
|
||||||
if (cpu >= MAX_CPUMASK_BITS) {
|
|
||||||
error_setg(errp, "Trying to use more CPUs than max of %d",
|
|
||||||
MAX_CPUMASK_BITS);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
bitmap_set(cpu_index_map, cpu, 1);
|
|
||||||
return cpu;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void cpu_release_index(CPUState *cpu)
|
|
||||||
{
|
|
||||||
bitmap_clear(cpu_index_map, cpu->cpu_index, 1);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
|
|
||||||
static int cpu_get_free_index(Error **errp)
|
|
||||||
{
|
{
|
||||||
CPUState *some_cpu;
|
CPUState *some_cpu;
|
||||||
int cpu_index = 0;
|
int cpu_index = 0;
|
||||||
|
@ -632,12 +609,6 @@ static int cpu_get_free_index(Error **errp)
|
||||||
return cpu_index;
|
return cpu_index;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cpu_release_index(CPUState *cpu)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void cpu_exec_exit(CPUState *cpu)
|
void cpu_exec_exit(CPUState *cpu)
|
||||||
{
|
{
|
||||||
CPUClass *cc = CPU_GET_CLASS(cpu);
|
CPUClass *cc = CPU_GET_CLASS(cpu);
|
||||||
|
@ -651,8 +622,7 @@ void cpu_exec_exit(CPUState *cpu)
|
||||||
|
|
||||||
QTAILQ_REMOVE(&cpus, cpu, node);
|
QTAILQ_REMOVE(&cpus, cpu, node);
|
||||||
cpu->node.tqe_prev = NULL;
|
cpu->node.tqe_prev = NULL;
|
||||||
cpu_release_index(cpu);
|
cpu->cpu_index = UNASSIGNED_CPU_INDEX;
|
||||||
cpu->cpu_index = -1;
|
|
||||||
cpu_list_unlock();
|
cpu_list_unlock();
|
||||||
|
|
||||||
if (cc->vmsd != NULL) {
|
if (cc->vmsd != NULL) {
|
||||||
|
@ -666,7 +636,7 @@ void cpu_exec_exit(CPUState *cpu)
|
||||||
void cpu_exec_init(CPUState *cpu, Error **errp)
|
void cpu_exec_init(CPUState *cpu, Error **errp)
|
||||||
{
|
{
|
||||||
CPUClass *cc ATTRIBUTE_UNUSED = CPU_GET_CLASS(cpu);
|
CPUClass *cc ATTRIBUTE_UNUSED = CPU_GET_CLASS(cpu);
|
||||||
Error *local_err = NULL;
|
Error *local_err ATTRIBUTE_UNUSED = NULL;
|
||||||
|
|
||||||
cpu->as = NULL;
|
cpu->as = NULL;
|
||||||
cpu->num_ases = 0;
|
cpu->num_ases = 0;
|
||||||
|
@ -690,11 +660,9 @@ void cpu_exec_init(CPUState *cpu, Error **errp)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
cpu_list_lock();
|
cpu_list_lock();
|
||||||
cpu->cpu_index = cpu_get_free_index(&local_err);
|
if (cpu->cpu_index == UNASSIGNED_CPU_INDEX) {
|
||||||
if (local_err) {
|
cpu->cpu_index = cpu_get_free_index();
|
||||||
error_propagate(errp, local_err);
|
assert(cpu->cpu_index != UNASSIGNED_CPU_INDEX);
|
||||||
cpu_list_unlock();
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
QTAILQ_INSERT_TAIL(&cpus, cpu, node);
|
QTAILQ_INSERT_TAIL(&cpus, cpu, node);
|
||||||
cpu_list_unlock();
|
cpu_list_unlock();
|
||||||
|
|
|
@ -883,4 +883,6 @@ extern const struct VMStateDescription vmstate_cpu_common;
|
||||||
.offset = 0, \
|
.offset = 0, \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define UNASSIGNED_CPU_INDEX -1
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -340,7 +340,7 @@ static void cpu_common_initfn(Object *obj)
|
||||||
CPUState *cpu = CPU(obj);
|
CPUState *cpu = CPU(obj);
|
||||||
CPUClass *cc = CPU_GET_CLASS(obj);
|
CPUClass *cc = CPU_GET_CLASS(obj);
|
||||||
|
|
||||||
cpu->cpu_index = -1;
|
cpu->cpu_index = UNASSIGNED_CPU_INDEX;
|
||||||
cpu->gdb_num_regs = cpu->gdb_num_g_regs = cc->gdb_num_core_regs;
|
cpu->gdb_num_regs = cpu->gdb_num_g_regs = cc->gdb_num_core_regs;
|
||||||
qemu_mutex_init(&cpu->work_mutex);
|
qemu_mutex_init(&cpu->work_mutex);
|
||||||
QTAILQ_INIT(&cpu->breakpoints);
|
QTAILQ_INIT(&cpu->breakpoints);
|
||||||
|
|
Loading…
Reference in New Issue