Received: from eggs.gnu.org ([2001:4830:134:3::10]:35736) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bG8k2-0000Er-FG for qemu-devel@nongnu.org; Thu, 23 Jun 2016 13:48:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bG8jy-0004aP-99 for qemu-devel@nongnu.org; Thu, 23 Jun 2016 13:48:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51449) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bG8jx-0004aG-W4 for qemu-devel@nongnu.org; Thu, 23 Jun 2016 13:48:34 -0400 Date: Thu, 23 Jun 2016 19:48:24 +0200 From: Igor Mammedov Message-ID: <20160623194824.3a2c0811@igors-macbook-pro.local> In-Reply-To: <20160623171916.GB3332@thinpad.lan.raisama.net> References: <1466693669-139967-1-git-send-email-imammedo@redhat.com> <1466693669-139967-8-git-send-email-imammedo@redhat.com> <20160623171916.GB3332@thinpad.lan.raisama.net> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 07/11] pc: set APIC ID based on socket/core/thread ids if it's not been set yet List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eduardo Habkost Cc: qemu-devel@nongnu.org, pbonzini@redhat.com, rth@twiddle.net, mst@redhat.com, armbru@redhat.com, eduardo.otubo@profitbricks.com, zhugh.fnst@cn.fujitsu.com, eblake@redhat.com On Thu, 23 Jun 2016 14:19:16 -0300 Eduardo Habkost wrote: > On Thu, Jun 23, 2016 at 04:54:25PM +0200, Igor Mammedov wrote: > > CPU added with device_add help won't have APIC ID set, > > so set it according to socket/core/thread ids provided > > with device_add command. > > > > Signed-off-by: Igor Mammedov > > --- > > hw/i386/pc.c | 18 +++++++++++++----- > > 1 file changed, 13 insertions(+), 5 deletions(-) > > > > diff --git a/hw/i386/pc.c b/hw/i386/pc.c > > index 87352ae..63e9bb6 100644 > > --- a/hw/i386/pc.c > > +++ b/hw/i386/pc.c > > @@ -1758,13 +1758,23 @@ static void pc_cpu_pre_plug(HotplugHandler > > *hotplug_dev, DeviceState *dev, Error **errp) > > { > > int idx; > > + CPUArchId *cpu_slot; > > + X86CPUTopoInfo topo; > > X86CPU *cpu = X86_CPU(dev); > > PCMachineState *pcms = PC_MACHINE(hotplug_dev); > > - CPUArchId *cpu_slot = pc_find_cpu(pcms, CPU(dev), &idx); > > > > + if (cpu->apic_id == 0xFFFFFFFF) { > > + /* APIC ID not set, set it based on socket/core/thread > > properties */ > > + X86CPUTopoInfo topo = { cpu->socket, cpu->core, > > cpu->thread }; > > + cpu->apic_id = apicid_from_topo_ids(smp_cores, > > smp_threads, &topo); > > + } > > What happens if neither apic-id or socket/core/thread are set? > > apicid_from_topo_ids() needs the caller to ensure > core_id < nr_cores && smt_id < nr_threads. Do you do that? it will get wrong apic_id and error in "if (!cpu_slot)" will trigger, I can explicitly check for unset values report error saying that they must be set if you prefer. > > > + > > + cpu_slot = pc_find_cpu(pcms, CPU(dev), &idx); > > if (!cpu_slot) { > > - error_setg(errp, "Invalid CPU index with APIC ID (%" PRIu32 > > - "), valid range 0:%d", cpu->apic_id, > > + x86_topo_ids_from_apicid(cpu->apic_id, smp_cores, > > smp_threads, &topo); > > + error_setg(errp, "Invalid CPU[socket: %d, core: %d, > > thread: %d] with" > > + " APIC ID (%" PRIu32 "), valid index range 0:%d", > > + topo.pkg_id, topo.core_id, topo.smt_id, > > cpu->apic_id, pcms->possible_cpus->len - 1); > > The error message is a bit confusing: the interface is not based > on CPU index anymore, but it still says "valid index range 0:%d". it's still based on CPU index for cpu-add and -numa cpus, so until we get rid of index in there it still should be printed. > > > return; > > } > > @@ -1780,8 +1790,6 @@ static void pc_cpu_pre_plug(HotplugHandler > > *hotplug_dev, > > * added CPUs so that query_hotpluggable_cpus would show > > correct values */ > > if (cpu->thread == -1 || cpu->core == -1 || cpu->socket == -1) > > { > > - X86CPUTopoInfo topo; > > - > > x86_topo_ids_from_apicid(cpu->apic_id, smp_cores, > > smp_threads, &topo); cpu->thread = topo.smt_id; > > cpu->core = topo.core_id; > > -- > > 1.8.3.1 > > >