static void pc_cpu_pre_plug(HotplugHandler *hotplug_dev,
                            DeviceState *dev, Error **errp)
{
    int idx;
    CPUState *cs;
    CPUArchId *cpu_slot;
    X86CPUTopoInfo topo;
    X86CPU *cpu = X86_CPU(dev);
    PCMachineState *pcms = PC_MACHINE(hotplug_dev);
    /* if APIC ID is not set, set it based on socket/core/thread properties */
    if (cpu->apic_id == UNASSIGNED_APIC_ID) {
        int max_socket = (max_cpus - 1) / smp_threads / smp_cores;
        if (cpu->socket_id < 0) {
            error_setg(errp, "CPU socket-id is not set");
        } else if (cpu->socket_id > max_socket) {
            error_setg(errp, "Invalid CPU socket-id: %u must be in range 0:%u",
                       cpu->socket_id, max_socket);
        if (cpu->core_id < 0) {
            error_setg(errp, "CPU core-id is not set");
        } else if (cpu->core_id > (smp_cores - 1)) {
            error_setg(errp, "Invalid CPU core-id: %u must be in range 0:%u",
                       cpu->core_id, smp_cores - 1);
        if (cpu->thread_id < 0) {
            error_setg(errp, "CPU thread-id is not set");
        } else if (cpu->thread_id > (smp_threads - 1)) {
            error_setg(errp, "Invalid CPU thread-id: %u must be in range 0:%u",
                       cpu->thread_id, smp_threads - 1);
        topo.pkg_id = cpu->socket_id;
        topo.core_id = cpu->core_id;
        topo.smt_id = cpu->thread_id;
        cpu->apic_id = apicid_from_topo_ids(smp_cores, smp_threads, &topo);
    cpu_slot = pc_find_cpu_slot(MACHINE(pcms), cpu->apic_id, &idx);
    if (!cpu_slot) {
        MachineState *ms = MACHINE(pcms);
        x86_topo_ids_from_apicid(cpu->apic_id, smp_cores, smp_threads, &topo);
        error_setg(errp, "Invalid CPU [socket: %u, core: %u, thread: %u] with"
                  " APIC ID %" PRIu32 ", valid index range 0:%d",
                   topo.pkg_id, topo.core_id, topo.smt_id, cpu->apic_id,
                   ms->possible_cpus->len - 1);
    if (cpu_slot->cpu) {
        error_setg(errp, "CPU[%d] with APIC ID %" PRIu32 " exists",
                   idx, cpu->apic_id);
    /* if 'address' properties socket-id/core-id/thread-id are not set, set them
     * so that machine_query_hotpluggable_cpus would show correct values
     */
    /* TODO: move socket_id/core_id/thread_id checks into x86_cpu_realizefn()
     * once -smp refactoring is complete and there will be CPU private
     * CPUState::nr_cores and CPUState::nr_threads fields instead of globals */
    x86_topo_ids_from_apicid(cpu->apic_id, smp_cores, smp_threads, &topo);
    if (cpu->socket_id != -1 && cpu->socket_id != topo.pkg_id) {
        error_setg(errp, "property socket-id: %u doesn't match set apic-id:"
            " 0x%x (socket-id: %u)", cpu->socket_id, cpu->apic_id, topo.pkg_id);
    cpu->socket_id = topo.pkg_id;
    if (cpu->core_id != -1 && cpu->core_id != topo.core_id) {
        error_setg(errp, "property core-id: %u doesn't match set apic-id:"
            " 0x%x (core-id: %u)", cpu->core_id, cpu->apic_id, topo.core_id);
    cpu->core_id = topo.core_id;
    if (cpu->thread_id != -1 && cpu->thread_id != topo.smt_id) {
        error_setg(errp, "property thread-id: %u doesn't match set apic-id:"
            " 0x%x (thread-id: %u)", cpu->thread_id, cpu->apic_id, topo.smt_id);
    cpu->thread_id = topo.smt_id;
    cs = CPU(cpu);
    cs->cpu_index = idx;
    numa_cpu_pre_plug(cpu_slot, dev, errp);
static void pc_cpu_pre_plug(HotplugHandler *hotplug_dev,
                            DeviceState *dev, Error **errp)
{
    int idx;
    CPUState *cs;
    CPUArchId *cpu_slot;
    X86CPUTopoInfo topo;
    X86CPU *cpu = X86_CPU(dev);
    PCMachineState *pcms = PC_MACHINE(hotplug_dev);
    
    if (cpu->apic_id == UNASSIGNED_APIC_ID) {
        int max_socket = (max_cpus - 1) / smp_threads / smp_cores;
        if (cpu->socket_id < 0) {
            error_setg(errp, "CPU socket-id is not set");
        } else if (cpu->socket_id > max_socket) {
            error_setg(errp, "Invalid CPU socket-id: %u must be in range 0:%u",
                       cpu->socket_id, max_socket);
        if (cpu->core_id < 0) {
            error_setg(errp, "CPU core-id is not set");
        } else if (cpu->core_id > (smp_cores - 1)) {
            error_setg(errp, "Invalid CPU core-id: %u must be in range 0:%u",
                       cpu->core_id, smp_cores - 1);
        if (cpu->thread_id < 0) {
            error_setg(errp, "CPU thread-id is not set");
        } else if (cpu->thread_id > (smp_threads - 1)) {
            error_setg(errp, "Invalid CPU thread-id: %u must be in range 0:%u",
                       cpu->thread_id, smp_threads - 1);
        topo.pkg_id = cpu->socket_id;
        topo.core_id = cpu->core_id;
        topo.smt_id = cpu->thread_id;
        cpu->apic_id = apicid_from_topo_ids(smp_cores, smp_threads, &topo);
    cpu_slot = pc_find_cpu_slot(MACHINE(pcms), cpu->apic_id, &idx);
    if (!cpu_slot) {
        MachineState *ms = MACHINE(pcms);
        x86_topo_ids_from_apicid(cpu->apic_id, smp_cores, smp_threads, &topo);
        error_setg(errp, "Invalid CPU [socket: %u, core: %u, thread: %u] with"
                  " APIC ID %" PRIu32 ", valid index range 0:%d",
                   topo.pkg_id, topo.core_id, topo.smt_id, cpu->apic_id,
                   ms->possible_cpus->len - 1);
    if (cpu_slot->cpu) {
        error_setg(errp, "CPU[%d] with APIC ID %" PRIu32 " exists",
                   idx, cpu->apic_id);
    


    


    x86_topo_ids_from_apicid(cpu->apic_id, smp_cores, smp_threads, &topo);
    if (cpu->socket_id != -1 && cpu->socket_id != topo.pkg_id) {
        error_setg(errp, "property socket-id: %u doesn't match set apic-id:"
            " 0x%x (socket-id: %u)", cpu->socket_id, cpu->apic_id, topo.pkg_id);
    cpu->socket_id = topo.pkg_id;
    if (cpu->core_id != -1 && cpu->core_id != topo.core_id) {
        error_setg(errp, "property core-id: %u doesn't match set apic-id:"
            " 0x%x (core-id: %u)", cpu->core_id, cpu->apic_id, topo.core_id);
    cpu->core_id = topo.core_id;
    if (cpu->thread_id != -1 && cpu->thread_id != topo.smt_id) {
        error_setg(errp, "property thread-id: %u doesn't match set apic-id:"
            " 0x%x (thread-id: %u)", cpu->thread_id, cpu->apic_id, topo.smt_id);
    cpu->thread_id = topo.smt_id;
    cs = CPU(cpu);
    cs->cpu_index = idx;
    numa_cpu_pre_plug(cpu_slot, dev, errp);
static void FUNC_0(HotplugHandler *VAR_0,
                            DeviceState *VAR_1, Error **VAR_2)
{
    int VAR_3;
    CPUState *cs;
    CPUArchId *cpu_slot;
    X86CPUTopoInfo topo;
    X86CPU *cpu = X86_CPU(VAR_1);
    PCMachineState *pcms = PC_MACHINE(VAR_0);
    
    if (cpu->apic_id == UNASSIGNED_APIC_ID) {
        int VAR_4 = (max_cpus - 1) / smp_threads / smp_cores;
        if (cpu->socket_id < 0) {
            error_setg(VAR_2, "CPU socket-id is not set");
        } else if (cpu->socket_id > VAR_4) {
            error_setg(VAR_2, "Invalid CPU socket-id: %u must be in range 0:%u",
                       cpu->socket_id, VAR_4);
        if (cpu->core_id < 0) {
            error_setg(VAR_2, "CPU core-id is not set");
        } else if (cpu->core_id > (smp_cores - 1)) {
            error_setg(VAR_2, "Invalid CPU core-id: %u must be in range 0:%u",
                       cpu->core_id, smp_cores - 1);
        if (cpu->thread_id < 0) {
            error_setg(VAR_2, "CPU thread-id is not set");
        } else if (cpu->thread_id > (smp_threads - 1)) {
            error_setg(VAR_2, "Invalid CPU thread-id: %u must be in range 0:%u",
                       cpu->thread_id, smp_threads - 1);
        topo.pkg_id = cpu->socket_id;
        topo.core_id = cpu->core_id;
        topo.smt_id = cpu->thread_id;
        cpu->apic_id = apicid_from_topo_ids(smp_cores, smp_threads, &topo);
    cpu_slot = pc_find_cpu_slot(MACHINE(pcms), cpu->apic_id, &VAR_3);
    if (!cpu_slot) {
        MachineState *ms = MACHINE(pcms);
        x86_topo_ids_from_apicid(cpu->apic_id, smp_cores, smp_threads, &topo);
        error_setg(VAR_2, "Invalid CPU [socket: %u, core: %u, thread: %u] with"
                  " APIC ID %" PRIu32 ", valid index range 0:%d",
                   topo.pkg_id, topo.core_id, topo.smt_id, cpu->apic_id,
                   ms->possible_cpus->len - 1);
    if (cpu_slot->cpu) {
        error_setg(VAR_2, "CPU[%d] with APIC ID %" PRIu32 " exists",
                   VAR_3, cpu->apic_id);
    


    


    x86_topo_ids_from_apicid(cpu->apic_id, smp_cores, smp_threads, &topo);
    if (cpu->socket_id != -1 && cpu->socket_id != topo.pkg_id) {
        error_setg(VAR_2, "property socket-id: %u doesn't match set apic-id:"
            " 0x%x (socket-id: %u)", cpu->socket_id, cpu->apic_id, topo.pkg_id);
    cpu->socket_id = topo.pkg_id;
    if (cpu->core_id != -1 && cpu->core_id != topo.core_id) {
        error_setg(VAR_2, "property core-id: %u doesn't match set apic-id:"
            " 0x%x (core-id: %u)", cpu->core_id, cpu->apic_id, topo.core_id);
    cpu->core_id = topo.core_id;
    if (cpu->thread_id != -1 && cpu->thread_id != topo.smt_id) {
        error_setg(VAR_2, "property thread-id: %u doesn't match set apic-id:"
            " 0x%x (thread-id: %u)", cpu->thread_id, cpu->apic_id, topo.smt_id);
    cpu->thread_id = topo.smt_id;
    cs = CPU(cpu);
    cs->cpu_index = VAR_3;
    numa_cpu_pre_plug(cpu_slot, VAR_1, VAR_2);
static void FUNC_0(HotplugHandler *VAR_0,
DeviceState *VAR_1, Error **VAR_2)
{ int VAR_3; CPUState *cs; CPUArchId *cpu_slot; X86CPUTopoInfo topo; X86CPU *cpu = X86_CPU(VAR_1); PCMachineState *pcms = PC_MACHINE(VAR_0); if (cpu->apic_id == UNASSIGNED_APIC_ID) { int VAR_4 = (max_cpus - 1) / smp_threads / smp_cores; if (cpu->socket_id < 0) { error_setg(VAR_2, "CPU socket-id is not set"); } else if (cpu->socket_id > VAR_4) { error_setg(VAR_2, "Invalid CPU socket-id: %u must be in range 0:%u",
cpu->socket_id, VAR_4); if (cpu->core_id < 0) { error_setg(VAR_2, "CPU core-id is not set"); } else if (cpu->core_id > (smp_cores - 1)) { error_setg(VAR_2, "Invalid CPU core-id: %u must be in range 0:%u",
cpu->core_id, smp_cores - 1); if (cpu->thread_id < 0) { error_setg(VAR_2, "CPU thread-id is not set"); } else if (cpu->thread_id > (smp_threads - 1)) { error_setg(VAR_2, "Invalid CPU thread-id: %u must be in range 0:%u",
cpu->thread_id, smp_threads - 1); topo.pkg_id = cpu->socket_id; topo.core_id = cpu->core_id; topo.smt_id = cpu->thread_id; cpu->apic_id = apicid_from_topo_ids(smp_cores, smp_threads, &topo); cpu_slot = pc_find_cpu_slot(MACHINE(pcms), cpu->apic_id, &VAR_3); if (!cpu_slot) { MachineState *ms = MACHINE(pcms); x86_topo_ids_from_apicid(cpu->apic_id, smp_cores, smp_threads, &topo); error_setg(VAR_2, "Invalid CPU [socket: %u, core: %u, thread: %u] with"
" APIC ID %" PRIu32 ", valid index range 0:%d",
topo.pkg_id, topo.core_id, topo.smt_id, cpu->apic_id,
ms->possible_cpus->len - 1); if (cpu_slot->cpu) { error_setg(VAR_2, "CPU[%d] with APIC ID %" PRIu32 " exists",
VAR_3, cpu->apic_id); x86_topo_ids_from_apicid(cpu->apic_id, smp_cores, smp_threads, &topo); if (cpu->socket_id != -1 && cpu->socket_id != topo.pkg_id) { error_setg(VAR_2, "property socket-id: %u doesn't match set apic-id:"
" 0x%x (socket-id: %u)", cpu->socket_id, cpu->apic_id, topo.pkg_id); cpu->socket_id = topo.pkg_id; if (cpu->core_id != -1 && cpu->core_id != topo.core_id) { error_setg(VAR_2, "property core-id: %u doesn't match set apic-id:"
" 0x%x (core-id: %u)", cpu->core_id, cpu->apic_id, topo.core_id); cpu->core_id = topo.core_id; if (cpu->thread_id != -1 && cpu->thread_id != topo.smt_id) { error_setg(VAR_2, "property thread-id: %u doesn't match set apic-id:"
" 0x%x (thread-id: %u)", cpu->thread_id, cpu->apic_id, topo.smt_id); cpu->thread_id = topo.smt_id; cs = CPU(cpu); cs->cpu_index = VAR_3; numa_cpu_pre_plug(cpu_slot, VAR_1, VAR_2);