From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34431) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bGTcX-0003gz-38 for qemu-devel@nongnu.org; Fri, 24 Jun 2016 12:06:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bGTcW-0000aF-5T for qemu-devel@nongnu.org; Fri, 24 Jun 2016 12:06:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40886) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bGTcW-0000aB-0R for qemu-devel@nongnu.org; Fri, 24 Jun 2016 12:06:16 -0400 From: Igor Mammedov Date: Fri, 24 Jun 2016 18:05:50 +0200 Message-Id: <1466784366-281935-3-git-send-email-imammedo@redhat.com> In-Reply-To: <1466784366-281935-1-git-send-email-imammedo@redhat.com> References: <1466784366-281935-1-git-send-email-imammedo@redhat.com> Subject: [Qemu-devel] [PATCH v2 02/18] pc: add x86_topo_ids_from_apicid() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, rth@twiddle.net, ehabkost@redhat.com, mst@redhat.com, armbru@redhat.com, eduardo.otubo@profitbricks.com, eblake@redhat.com, pkrempa@redhat.com, marcel@redhat.com it's reverse of apicid_from_topo_ids() and will be used in follow up patches to fill in data structures for query-hotpluggable-cpus and for user friendly error reporting Signed-off-by: Igor Mammedov --- include/hw/i386/topology.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/include/hw/i386/topology.h b/include/hw/i386/topology.h index fc95572..1ebaee0 100644 --- a/include/hw/i386/topology.h +++ b/include/hw/i386/topology.h @@ -117,6 +117,21 @@ static inline void x86_topo_ids_from_idx(unsigned nr_cores, topo->pkg_id = core_index / nr_cores; } +/* Calculate thread/core/package IDs for a specific topology, + * based on APIC ID + */ +static inline void x86_topo_ids_from_apicid(apic_id_t apicid, + unsigned nr_cores, + unsigned nr_threads, + X86CPUTopoInfo *topo) +{ + topo->smt_id = apicid & + ~(0xFFFFFFFFUL << apicid_smt_width(nr_cores, nr_threads)); + topo->core_id = (apicid >> apicid_core_offset(nr_cores, nr_threads)) & + ~(0xFFFFFFFFUL << apicid_core_width(nr_cores, nr_threads)); + topo->pkg_id = apicid >> apicid_pkg_offset(nr_cores, nr_threads); +} + /* Make APIC ID for the CPU 'cpu_index' * * 'cpu_index' is a sequential, contiguous ID for the CPU. -- 1.8.3.1