From owner-freebsd-smp Tue Mar 11 12:30:10 2003 Delivered-To: freebsd-smp@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 5B16137B401; Tue, 11 Mar 2003 12:30:07 -0800 (PST) Received: from murmeldjur.it.su.se (murmeldjur.it.su.se [130.237.95.79]) by mx1.FreeBSD.org (Postfix) with ESMTP id 0C5E543FCB; Tue, 11 Mar 2003 12:30:06 -0800 (PST) (envelope-from rnyberg@murmeldjur.it.su.se) Received: from murmeldjur.it.su.se (localhost [127.0.0.1]) by murmeldjur.it.su.se (8.12.8/8.12.7) with ESMTP id h2BKU3Gv000229; Tue, 11 Mar 2003 21:30:03 +0100 (CET) (envelope-from rnyberg@murmeldjur.it.su.se) Received: (from rnyberg@localhost) by murmeldjur.it.su.se (8.12.8/8.12.8/Submit) id h2BKU3KN000228; Tue, 11 Mar 2003 21:30:03 +0100 (CET) Date: Tue, 11 Mar 2003 21:30:03 +0100 From: Richard Nyberg To: John Baldwin Cc: freebsd-smp@FreeBSD.org Subject: Re: hyperthreading randomness Message-ID: <20030311203003.GA216@murmeldjur.it.su.se> Mail-Followup-To: Richard Nyberg , John Baldwin , freebsd-smp@freebsd.org References: <20030308121852.GA25380@murmeldjur.it.su.se> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="yrj/dFKFPuw6o+aM" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4i Sender: owner-freebsd-smp@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org --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