IBM Cloud: VSI for VPCでHyper-Threadingを無効にしてみた


# 1. はじめに

IBM Cloud docsにはHyper-Threadingを無効にする手順が書かれてある。
https://cloud.ibm.com/docs/vpc?topic=vpc-disabling-hyper-threading&interface=ui
今回は、VSI for VPCのRHEL9を利用して、その手順に沿って動作を確認してみる。

注意: この手順はOS機能で一方の仮想CPUをオフラインにしているだけだとも捉えられます。もしライセンス削減のために本設定を利用しようと考えている場合は、ソフトウェア業者に確認してもらってください。

```
[root@syasuda-vpc-tok1 ~]# cat /etc/redhat-release
Red Hat Enterprise Linux release 9.0 (Plow)

[root@syasuda-vpc-tok1 ~]# uname -a
Linux syasuda-vpc-tok1 5.14.0-70.50.2.el9_0.x86_64 #1 SMP PREEMPT Wed Mar 15 20:04:37 EDT 2023 x86_64 x86_64 x86_64 GNU/Linux
```

# 2. デフォルト構成の確認
今回は、以下のように`bx2-2x8`というプロファイルで確認してみた。この環境では2vCPU環境であり、デフォルトではVSI for VPCではハイパースレディングは有効になっている。
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/62127/2b416771-6cae-095e-d472-92846865c8d2.png)

```txt:Socket(s)が1でCore(s) per socketが1のため物理コアが1個で有ることが分かる。そしてThread(s) per coreが2であるため、Hyper-Threadingが有効であることが分かる。CPU(s)が2なので全部で2個の仮想CPUが動いている。
[root@syasuda-vpc-tok1 ~]# lscpu
Architecture:            x86_64
  CPU op-mode(s):        32-bit, 64-bit
  Address sizes:         40 bits physical, 48 bits virtual
  Byte Order:            Little Endian
CPU(s):                  2
  On-line CPU(s) list:   0,1
Vendor ID:               GenuineIntel
  BIOS Vendor ID:        QEMU
  Model name:            Intel Xeon Processor (Cascadelake)
    BIOS Model name:     pc-i440fx-4.2
    CPU family:          6
    Model:               85
    Thread(s) per core:  2
    Core(s) per socket:  1
    Socket(s):           1
    Stepping:            6
    BogoMIPS:            4988.08
    Flags:               fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm co
                         nstant_tsc rep_good nopl xtopology cpuid tsc_known_freq pni pclmulqdq vmx ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_dea
                         dline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch cpuid_fault invpcid_single ssbd ibrs ibpb stibp ibrs_enhance
                         d tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid avx512f avx512dq rdseed adx smap cl
                         flushopt clwb avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves arat pku ospke avx512_vnni md_clear arch_capabilities
Virtualization features:
  Virtualization:        VT-x
  Hypervisor vendor:     KVM
  Virtualization type:   full
Caches (sum of all):
  L1d:                   64 KiB (2 instances)
  L1i:                   64 KiB (2 instances)
  L2:                    4 MiB (1 instance)
  L3:                    16 MiB (1 instance)
NUMA:
  NUMA node(s):          1
  NUMA node0 CPU(s):     0,1
Vulnerabilities:
  Itlb multihit:         Not affected
  L1tf:                  Not affected
  Mds:                   Not affected
  Meltdown:              Not affected
  Mmio stale data:       Vulnerable: Clear CPU buffers attempted, no microcode; SMT Host state unknown
  Retbleed:              Mitigation; Enhanced IBRS
  Spec store bypass:     Mitigation; Speculative Store Bypass disabled via prctl
  Spectre v1:            Mitigation; usercopy/swapgs barriers and __user pointer sanitization
  Spectre v2:            Mitigation; Enhanced IBRS, IBPB conditional, RSB filling, PBRSB-eIBRS SW sequence
  Srbds:                 Not affected
  Tsx async abort:       Not affected
```
```
[root@syasuda-vpc-tok1 ~]# lscpu --extended
CPU NODE SOCKET CORE L1d:L1i:L2:L3 ONLINE
  0    0      0    0 0:0:0:0          yes
  1    0      0    0 1:1:0:0          yes
```
```
[root@syasuda-vpc-tok1 ~]# cat /sys/devices/system/cpu/cpu*/topology/thread_siblings_list
0-1
0-1
```
```
[root@syasuda-vpc-tok1 ~]# cat /sys/devices/system/cpu/cpu0/online
1
[root@syasuda-vpc-tok1 ~]# cat /sys/devices/system/cpu/cpu1/online
1
```

```
[root@syasuda-vpc-tok1 ~]# yum install -y git
[root@syasuda-vpc-tok1 ~]# git clone https://github.com/seelam/Manage_Hyperthreading.sh
[root@syasuda-vpc-tok1 ~]# cd Manage_Hyperthreading.sh/
[root@syasuda-vpc-tok1 Manage_Hyperthreading.sh]# ./manage_hyperthreading.sh --show
Hyper-threading is ENABLED!
```

# 3. Hyper-threadingを無効にする。

```
[root@syasuda-vpc-tok1 ~]# echo 0 > /sys/devices/system/cpu/cpu1/online
```

```txt:Socket(s)が1でCore(s) per socketが1のため物理コアが1個で有ることが分かる。そしてThread(s) per coreが1であるため、Hyper-Threadingが無効であることが分かる。CPU(s)が2なので仮想CPUが2個あるが、1方がオフラインになっている。
[root@syasuda-vpc-tok1 ~]# lscpu
Architecture:            x86_64
  CPU op-mode(s):        32-bit, 64-bit
  Address sizes:         40 bits physical, 48 bits virtual
  Byte Order:            Little Endian
CPU(s):                  2
  On-line CPU(s) list:   0
  Off-line CPU(s) list:  1
Vendor ID:               GenuineIntel
  BIOS Vendor ID:        QEMU
  Model name:            Intel Xeon Processor (Cascadelake)
    BIOS Model name:     pc-i440fx-4.2
    CPU family:          6
    Model:               85
    Thread(s) per core:  1
    Core(s) per socket:  1
    Socket(s):           1
    Stepping:            6
    BogoMIPS:            4988.08
    Flags:               fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm co
                         nstant_tsc rep_good nopl xtopology cpuid tsc_known_freq pni pclmulqdq vmx ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_dea
                         dline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch cpuid_fault invpcid_single ssbd ibrs ibpb stibp ibrs_enhance
                         d tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid avx512f avx512dq rdseed adx smap cl
                         flushopt clwb avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves arat pku ospke avx512_vnni md_clear arch_capabilities
Virtualization features:
  Virtualization:        VT-x
  Hypervisor vendor:     KVM
  Virtualization type:   full
Caches (sum of all):
  L1d:                   32 KiB (1 instance)
  L1i:                   32 KiB (1 instance)
  L2:                    4 MiB (1 instance)
  L3:                    16 MiB (1 instance)
NUMA:
  NUMA node(s):          1
  NUMA node0 CPU(s):     0
Vulnerabilities:
  Itlb multihit:         Not affected
  L1tf:                  Not affected
  Mds:                   Not affected
  Meltdown:              Not affected
  Mmio stale data:       Vulnerable: Clear CPU buffers attempted, no microcode; SMT Host state unknown
  Retbleed:              Mitigation; Enhanced IBRS
  Spec store bypass:     Mitigation; Speculative Store Bypass disabled via prctl
  Spectre v1:            Mitigation; usercopy/swapgs barriers and __user pointer sanitization
  Spectre v2:            Mitigation; Enhanced IBRS, IBPB conditional, RSB filling, PBRSB-eIBRS SW sequence
  Srbds:                 Not affected
  Tsx async abort:       Not affected
```
```
[root@syasuda-vpc-tok1 ~]# lscpu --extended
CPU NODE SOCKET CORE L1d:L1i:L2:L3 ONLINE
  0    0      0    0 0:0:0:0          yes
  1    -      -    - -                 no
```
```
[root@syasuda-vpc-tok1 ~]# cat /sys/devices/system/cpu/cpu*/topology/thread_siblings_list
0
```
```
[root@syasuda-vpc-tok1 ~]# cd Manage_Hyperthreading.sh/
[root@syasuda-vpc-tok1 Manage_Hyperthreading.sh]# ./manage_hyperthreading.sh --show
Hyper-threading NOT enabled:
On-line CPU(s) list:             0
Off-line CPU(s) list:            1
```