5

I am doing some benchmarking tests and would like to disable hyper threading in an EC2 to see it's effect on my test application performance.

A single instance of my application uses only 1 thread during execution.

I understand that I can't access the BIOS of EC2 machines to disable hyper threading since they are all virtualised. But I have used the chcpu command to disable half the vCPUs(threads) available so that I could simulate a hyper threading disabled environment.

For this benchmark, I am using a C4.xlarge with 4vCPUs numbered logically from 0 to 3.

I run this command sudo chcpu -d 1,3 which disables vCPUs 1 and 3.

In doing this, I assume that vCPUs 0 and 1 come from a single underlying bare metal core and vCPUs 2 and 3 come from another core.

This is where I know that my assumptions are wrong since vCPUs 0 and 4 could be coming from the same bare metal core or all of them could be coming from different bare metal cores.

Does anybody have a better way to disable hyper-threading in EC2 instances?

Also does Amazon rearrange vCPUs so that they come from different cores when it detects half the vCPUs being disabled?

Sri Hari Vignesh
  • 256
  • 4
  • 11

2 Answers2

5

I found this question while searching for a solution.

AWS has instructions for this here

To find cpu info

Run lscpu --extended

And you will get a list of virtual CPUs, along with which core they map to:

[root@ip-172-31-1-32 ~]# lscpu --extended 
CPU NODE SOCKET CORE L1d:L1i:L2:L3 ONLINE 
0   0    0      0    0:0:0:0       yes 
1   0    0      1    1:1:1:0       yes 
2   0    0      2    2:2:2:0       yes 
3   0    0      3    3:3:3:0       yes 
4   0    0      0    0:0:0:0       yes 
5   0    0      1    1:1:1:0       yes 
6   0    0      2    2:2:2:0       yes 
7   0    0      3    3:3:3:0       yes 

To disable some of the virtual CPUs

(we'd want to disable 4-7), do:

echo 0 > /sys/devices/system/cpu/cpuN/online

where N is the virtual cpu number to disable.

So...

echo 0 > /sys/devices/system/cpu/cpu4/online
echo 0 > /sys/devices/system/cpu/cpu5/online
echo 0 > /sys/devices/system/cpu/cpu6/online
echo 0 > /sys/devices/system/cpu/cpu7/online

to disable the hyperthreads and leave you with 1 vCPU per physical core.

Or use this script:

#!/usr/bin/env bash

for cpunum in $(cat /sys/devices/system/cpu/cpu*/topology/thread_siblings_list | cut -s -d, -f2- | tr ',' '\n' | sort -un)
do
    echo 0 > /sys/devices/system/cpu/cpu$cpunum/online
done
Brandon
  • 38,310
  • 8
  • 82
  • 87
  • 1
    Let me add a script to enable again the hyperthreads: `for cpu in $(ls -d /sys/devices/system/cpu/cpu[1-9]* | xargs -n 1 basename); do echo 1 > /sys/devices/system/cpu/$cpu/online; done;` – gparis Feb 21 '20 at 11:53
0

The Amazon EC2 Instance Type page includes the definition:

Each vCPU is a hyperthread of an Intel Xeon core except for T2 and m3.medium.

Therefore, you possibly do not want to turn off hyperthreading.

See also:

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
  • So this means that each vCPU in my instance is a hyper thread right? And also by disabling 1 out of every 2 hyperthreads(vCPUs), I will be disabling hyper threading for that particular core. – Sri Hari Vignesh Jan 23 '17 at 22:50
  • My assumption is that if you use an EC2 instance with 4 vCPUs and you manage to somehow disable hyperthreading, you might get only 2 vCPUs. I could not find any mention to which vCPU maps to which core. – John Rotenstein Jan 24 '17 at 02:13
  • That is exactly my problem. I don't know which vCPU maps to which core and hence don't know which vCPUs to disable to simulate hyper threading disabled run time environment. Is there any way to find out the mapping? – Sri Hari Vignesh Jan 24 '17 at 02:25
  • Given the virtualization environment, I suspect that AWS does not intend users to modify the virtualization layer, nor the Hyperthreading configuration. You should benchmark Amazon EC2 using the instances in the way that they are provisioned. This would then be a reliable, reproducible environment for future workloads. – John Rotenstein Jan 24 '17 at 02:29
  • I don't know about in 2017, but now you can use EC2 CPU options to turn off HT. And in Linux, offlining every odd-numbered core/thread will disable HT because that's how the CPUs are enumerated. – ZiggyTheHamster Mar 16 '20 at 21:52