Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 11 Mar 2003 21:30:03 +0100
From:      Richard Nyberg <rnyberg@it.su.se>
To:        John Baldwin <jhb@FreeBSD.org>
Cc:        freebsd-smp@FreeBSD.org
Subject:   Re: hyperthreading randomness
Message-ID:  <20030311203003.GA216@murmeldjur.it.su.se>
In-Reply-To: <XFMail.20030310130013.jhb@FreeBSD.org>
References:  <20030308121852.GA25380@murmeldjur.it.su.se> <XFMail.20030310130013.jhb@FreeBSD.org>

next in thread | previous in thread | raw e-mail | index | archive | help

--yrj/dFKFPuw6o+aM
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

On Mon, Mar 10, 2003 at 01:00:13PM -0500, John Baldwin wrote:
> 
> On 08-Mar-2003 Richard Nyberg wrote:
> > I have a Dell Precision 450 with 2 xeon CPU:s.
> > The weird thing is that it randomly boots up
> > with either 2 or 4 CPUs on the same 4-STABLE kernel.
> > 2 more often than 4. It seems a bit unpredictable :(
> 
> Hmm, I have no idea about that one.  Hmm, it seems to be a
> "feature" of the BIOS perhaps.  It seems that it may be listing
> the second CPU with an APIC ID of 3 (it's second core) instead
> of 2 (it's first core) in which case the HTT code sees that
> something is not right and doesn't start up any extra processors.
> 
This patch works for me ;) It allows the physical CPUs APIC ID to
be either the lowest (as is currently assumed) or the highest
number in the range of APIC IDs for the logical cores.

Happy hacking!
	-Richard

--yrj/dFKFPuw6o+aM
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="hyperquirk.diff"

--- sys/i386/i386/orig-mp_machdep.c	Tue Mar 11 20:46:06 2003
+++ sys/i386/i386/mp_machdep.c	Tue Mar 11 21:12:02 2003
@@ -973,10 +973,18 @@
 				 * enumerate the logical CPUs.
 				 */
 				proc.apic_id = ((proc_entry_ptr)position)->apic_id;
-				for (i = 1; i < logical_cpus; i++) {
-					proc.apic_id++;
-					(void)processor_entry(&proc, cpu);
-					cpu++;
+				if (proc.apic_id % logical_cpus == 0) {
+					for (i = 1; i < logical_cpus; i++) {
+						proc.apic_id++;
+						(void)processor_entry(&proc, cpu);
+						cpu++;
+					}
+				} else {
+					for (i = 1; i < logical_cpus; i++) {
+						proc.apic_id--;
+						(void)processor_entry(&proc, cpu);
+						cpu++;
+					}
 				}
 			}
 			break;
@@ -1020,8 +1028,9 @@
  * system have the same number of logical CPUs.
  *
  * XXX: We assume that APIC ID's are allocated such that
- * the APIC ID's for a physical processor are aligned
- * with the number of logical CPU's in the processor.
+ * the APIC ID's for a physical processor are either
+ * the lowest or the highest number in the group of
+ * logical cores.
  */
 static void
 mptable_hyperthread_fixup(u_int id_mask)
@@ -1044,12 +1053,17 @@
 	for (id = 0; id <= MAXCPU; id++) {
 		if ((id_mask & 1 << id) == 0)
 			continue;
-		/* First, make sure we are on a logical_cpus boundary. */
-		if (id % logical_cpus != 0)
-			return;
-		for (i = id + 1; i < id + logical_cpus; i++)
-			if ((id_mask & 1 << i) != 0)
-				return;
+		/* If we are on a logical_cpus boundary look upwards,
+		 * otherwise look downwards. */
+		if (id % logical_cpus == 0) {
+			for (i = id + 1; i < id + logical_cpus; i++)
+				if ((id_mask & 1 << i) != 0)
+					return;
+		} else {
+			for (i = id - 1; i < id - logical_cpus; i--)
+				if ((id_mask & 1 << i) != 0)
+					return;
+		}
 	}
 
 	/*

--yrj/dFKFPuw6o+aM--

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-smp" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030311203003.GA216>