Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 20 Sep 2011 22:28:40 -0400
From:      "b. f." <bf1783@googlemail.com>
To:        freebsd-questions@FreeBSD.org, Jason Usher <jusher71@yahoo.com>
Cc:        avg@FreeBSD.org
Subject:   Re: How can I disable hyperthreads, but NOT smp ?
Message-ID:  <CAGFTUwNxCcTtZaE6SZwsxo=jWjTMq7uew6v=mxvKZUqYPUtY5A@mail.gmail.com>

next in thread | raw e-mail | index | archive | help
> On 20/09/2011 21:34, Jason Usher wrote:
> > FreeBSD 6.4-RELEASE system with two physical CPUs, each of which are HT=
 capable.  From dmesg:
> >
> > cpu0 (BSP): APIC ID: 0
> > cpu1 (AP): APIC ID: 1
> > cpu2 (AP): APIC ID: 6
> > cpu3 (AP): APIC ID: 7
> >
> > I also see this:
> >
> > machdep.hyperthreading_allowed: 0
> >
> > The problem is, I have reason to believe that my workload benefits grea=
tly from SMP, but is not playing nicely with hyperthreading.  That is, it i=
s trying to farm out 4 things at a time to a cpu setup that really is only =
able to do two things at a time.
> >
> > How can I disable HT completely, but still retain ALL the benefits of S=
MP ?

If you are sure about your machine's hardware, and that
machdep.hyperthreading_allowed is really set to 0 in loader.conf(5),
then you may want to glance at:

http://www.freebsd.org/cgi/cvsweb.cgi/src/sys/i386/i386/mp_machdep.c?annota=
te=3D1.252.2.16

to see where the enforcement of this tunable is failing, and file a
PR.  Although I have not tried to use them, there are supposed to be
alternative mechanisms to disable cpus, or at least to ignore them in
certain circumstances:

--on recent versions of FreeBSD (> 6) you could use cpuset(1) to
ignore some of them in certain circumstances;
--on older versions of FreeBSD (< 9) you could use the sysctl
machdep.hlt_logical_cpus=3D1 (see smp(4));
--on older versions of FreeBSD (< 9) you could use the sysctl
machdep.hlt_cpus to add a bitmap of the logical cpus that you want to
disable (see smp(4));
--you can use the loader hint hint.lapic.X.disable=3D1 to disable a cpu
with APIC ID X.

But note the warnings in the Andriy Gapon's commit message and
UPDATING entry for:

http://svnweb.FreeBSD.org/base?view=3Drevision&revision=3D222853



> It's usually a setting in the BIOS to disable Hyperthreading then
> reconfigure the kernel to only use 2 cores (which it might do
> automatically).
>
> Hyperthreading is outside the world of FreeBSD. As far as it knows there
> is still 4 "logical processors". Disabling hyperthreading it should see
> 2 LPs.

This isn't completely true.  Yes, many systems have a BIOS setting to
toggle hyperthreading on and off.  The loader tunable can be used for
those machines that don't have such a setting, or for remote machines
for which it is not convenient to change the setting.  But FreeBSD
attempts to determine if any of the logical cpus are hyperthreads, so
that the loader tunable machdep.hyperthreading_allowed can be enforced
(it was introduced a long time ago when a security hole was discovered
with some early hyperthread implementations), and also because
hyperthreads are treated differently from physical cpus with regard to
interrupt handling, scheduling (with ULE), ACPI, PMC, etc.  So FreeBSD
is supposed to be "hyperthread-aware".

b.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAGFTUwNxCcTtZaE6SZwsxo=jWjTMq7uew6v=mxvKZUqYPUtY5A>