2
votes

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?

2

2 Answers

3
votes

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
0
votes

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: