How can I disable hyperthreads, but NOT smp ?

b. f. bf1783 at
Wed Sep 21 02:28:42 UTC 2011

> 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 greatly from SMP, but is not playing nicely with hyperthreading.  That is, it is 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 SMP ?

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:

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=1 (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=1 to disable a cpu
with APIC ID X.

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

> 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".


More information about the freebsd-questions mailing list