From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46666) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VsT11-0005V7-Ft for qemu-devel@nongnu.org; Mon, 16 Dec 2013 02:55:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VsT10-0006VU-Fs for qemu-devel@nongnu.org; Mon, 16 Dec 2013 02:54:59 -0500 Received: from mail-oa0-x231.google.com ([2607:f8b0:4003:c02::231]:38213) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VsT10-0006VP-AH for qemu-devel@nongnu.org; Mon, 16 Dec 2013 02:54:58 -0500 Received: by mail-oa0-f49.google.com with SMTP id i4so4534862oah.8 for ; Sun, 15 Dec 2013 23:54:57 -0800 (PST) MIME-Version: 1.0 Date: Mon, 16 Dec 2013 15:54:57 +0800 Message-ID: From: jun muzi Content-Type: multipart/alternative; boundary=089e0111c09acc3b1404eda220a2 Subject: Re: [Qemu-devel] [PATCH] qemu will core dump with "-smp 254, sockets=2, cores=3, threads=2" List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: blauwirbel@gmail.com, afaerber@suse.de, ehabkost@redhat.com, rth@twiddle.net --089e0111c09acc3b1404eda220a2 Content-Type: text/plain; charset=ISO-8859-1 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 --- 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 --089e0111c09acc3b1404eda220a2 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Type error, change smp_cores to nr_cores and change smp_th= reads to nr_threads. But using smp_cores can work well. As it is not the sa= me with explanatory note, so change it.

Signed-off-by: Jun Li <junmuzi@gmail.com>
---
=A0target-i386/topology.h | 20 ++++++++++++++++++++
=A01 file cha= nged, 20 insertions(+)

diff --git a/target-i386/topology.h b/target-= i386/topology.h
index 07a6c5f..49c6331 100644
--- a/target-i386/topol= ogy.h
+++ b/target-i386/topology.h
@@ -117,6 +117,19 @@ static inline void x86= _topo_ids_from_idx(unsigned nr_cores,
=A0=A0=A0=A0 *pkg_id =3D core_inde= x / nr_cores;
=A0}
=A0
+/* This function will return whether @num = is power of 2.
+ *
+ * Returns: 1 indicate @num is power of 2, 0 indicate @num is not.<= br>+ */
+static int is_2_power(int num)
+{
+=A0=A0=A0 if (num <= 0 || num > 256) {
+=A0=A0=A0=A0=A0=A0=A0 return 1;
+=A0=A0=A0 }+
+=A0=A0=A0 return !(num & (num - 1));
+}
+
=A0/* Make APIC ID for the CPU 'cpu_index'
=A0 *
= =A0 * '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,
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 unsig= ned cpu_index)
=A0{
=A0=A0=A0=A0 unsigned pkg_id, core_id, smt_id;+
+=A0=A0=A0 /* check whether nr_cores and nr_threads is a power of 2 *= /
+=A0=A0=A0 if (!is_2_power(nr_cores) || !is_2_power(nr_threads)) {
+=A0=A0=A0=A0=A0=A0=A0 nr_cores =3D 1;
+=A0=A0=A0=A0=A0=A0=A0 nr_threads= =3D 1;
+=A0=A0=A0 }
+
=A0=A0=A0=A0 x86_topo_ids_from_idx(nr_cores= , nr_threads, cpu_index,
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 &pkg_id, &core_id, &smt_id);<= br>=A0=A0=A0=A0 return apicid_from_topo_ids(nr_cores, nr_threads, pkg_id, c= ore_id, smt_id);
--
1.8.1.4
--089e0111c09acc3b1404eda220a2--