1. 50

  2. 12

    I like being able to toggle SMT without a visit to the BIOS. Very cool! Works without a reboot:

    $ sysctl hw.smt
    $ ls -laR /
    $ echo in another terminal
    $ top
    load averages:  0.25,  0.16,  0.09                       openbsd 08:32:39
    64 processes: 62 idle, 2 on processor                                            up  0:09
    CPU0 states: 59.1% user,  0.0% nice, 17.4% sys,  4.2% spin,  1.6% intr, 17.8% idle
    CPU1 states:  0.0% user,  0.0% nice,  0.0% sys,  0.0% spin,  0.0% intr,  100% idle
    CPU2 states: 49.7% user,  0.0% nice, 21.4% sys,  4.8% spin,  0.0% intr, 24.2% idle
    CPU3 states:  0.0% user,  0.0% nice,  0.0% sys,  0.0% spin,  0.0% intr,  100% idle
    Memory: Real: 465M/1302M act/tot Free: 6268M Cache: 477M Swap: 0K/8129M
    $ doas sysctl hw.smt=1
    hw.smt: 0 -> 1
    $ ls -laR /
    $ echo in another terminal
    $ top
    load averages:  0.16,  0.17,  0.10                       OpenBSD 08:33:49
    64 processes: 61 idle, 3 on processor                                            up  0:10
    CPU0 states: 19.0% user,  0.0% nice, 10.4% sys,  5.4% spin,  1.6% intr, 63.7% idle
    CPU1 states: 15.2% user,  0.0% nice, 10.0% sys,  6.8% spin,  0.0% intr, 68.1% idle
    CPU2 states: 25.3% user,  0.0% nice, 12.4% sys,  5.4% spin,  0.0% intr, 56.9% idle
    CPU3 states: 21.0% user,  0.0% nice, 14.0% sys,  6.0% spin,  0.0% intr, 59.1% idle
    Memory: Real: 464M/1311M act/tot Free: 6259M Cache: 477M Swap: 0K/8129M
    1. 11

      Note that SMT doesn’t necessarily have a posive effect on performance; it highly depends on the workload. In all likelyhood it will actually slow down most workloads if you have a CPU with more than two cores.

      In case you’re wondering, this refers to OpenBSD’s giant-locked kernel. Some parts of this kernel are now unlocked (e.g. network stack) but for some workloads 2 CPUs can be faster than 3 or more due to lock contention.

      1. 1

        Per my understanding, every “physical” CPU can have many cores, and each core can have multiple hardware thread if SMT is supported. So every “hardware thread” is a “logical” CPU. For OpenBSD kernel, does it do special operations according to physical CPU, core and hardware thread? Or just consider “logic” CPU? Thanks!

        1. 2

          As far as I know the SMT threads were simply exposed as additional CPUs to the scheduler.

          1. 1

            @stsp Thanks for your response!

            If I understand correctly, disable SMT means cut half the “logical” CPU, right? For example, if the server has one CPU, 2 cores, and every core has 2 hardware threads, in theory, the server has 4 “logical” CPUs. Assume my workload has 4 thread, and every thread is independent and computing-intensive (mostly user-space computation, not involved kernel part, such as syscall, or accessing network, etc.). Currently the workload can occupy the whole 4 “logical” CPUs. But now, if the count of “logical” CPU is halved, and my workload’s 4 thread need to contend for 2 “logical” CPUs. So in this scenario, the workload’s performance should be downgraded.

            Is it correct? Thanks in advance!

            1. 3

              At least when HT was new, it also meant the caches would be halved unless you disabled HT in bios. So if your threads are doing different things they might suffer from it.

              1. 1

                As far as I understand, it doesn’t mean that all 4 threads can progress in parallel, it will depend on which unit in the CPU each thread is utilizing.