Type error, change smp_cores to nr_cores and change smp_threads to nr_threads. But using smp_cores can work well. As it is not the same with explanatory note, so change it.
Signed-off-by: Jun Li <
address@hidden>
---
target-i386/topology.h | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/target-i386/topology.h b/target-i386/topology.h
index 07a6c5f..49c6331 100644
--- a/target-i386/topology.h
+++ b/target-i386/topology.h
@@ -117,6 +117,19 @@ static inline void x86_topo_ids_from_idx(unsigned nr_cores,
*pkg_id = core_index / nr_cores;
}
+/* This function will return whether @num is power of 2.
+ *
+ * Returns: 1 indicate @num is power of 2, 0 indicate @num is not.
+ */
+static int is_2_power(int num)
+{
+ if (num < 0 || num > 256) {
+ return 1;
+ }
+
+ return !(num & (num - 1));
+}
+
/* Make APIC ID for the CPU 'cpu_index'
*
* 'cpu_index' is a sequential, contiguous ID for the CPU.
@@ -126,6 +139,13 @@ static inline apic_id_t x86_apicid_from_cpu_idx(unsigned nr_cores,
unsigned cpu_index)
{
unsigned pkg_id, core_id, smt_id;
+
+ /* check whether nr_cores and nr_threads is a power of 2 */
+ if (!is_2_power(nr_cores) || !is_2_power(nr_threads)) {
+ nr_cores = 1;
+ nr_threads = 1;
+ }
+
x86_topo_ids_from_idx(nr_cores, nr_threads, cpu_index,
&pkg_id, &core_id, &smt_id);
return apicid_from_topo_ids(nr_cores, nr_threads, pkg_id, core_id, smt_id);
--
1.8.1.4