summary refs log tree commit diff stats
path: root/include/hw/i386/topology.h
diff options
context:
space:
mode:
authorIgor Mammedov <imammedo@redhat.com>2016-07-06 08:20:38 +0200
committerEduardo Habkost <ehabkost@redhat.com>2016-07-20 11:58:44 -0300
commit9f3aab58539b4cc716e42e772be8116dc2e7d159 (patch)
treec18681d78cac0b60a11e52a764ab6dd1088b3ef9 /include/hw/i386/topology.h
parentd9c84f196970f78d4b55ab87e03cbcad7c65f86f (diff)
downloadfocaccia-qemu-9f3aab58539b4cc716e42e772be8116dc2e7d159.tar.gz
focaccia-qemu-9f3aab58539b4cc716e42e772be8116dc2e7d159.zip
pc: Add x86_topo_ids_from_apicid()
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 <imammedo@redhat.com>
Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Diffstat (limited to 'include/hw/i386/topology.h')
-rw-r--r--include/hw/i386/topology.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/include/hw/i386/topology.h b/include/hw/i386/topology.h
index fc95572394..1ebaee0f76 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.