Skip to content

Commit ceb3b39

Browse files
authored
Merge pull request #2535 from ddeidda/release-2.10_dd
Fix disable_hyperthreading tests
2 parents 619f242 + fc81be4 commit ceb3b39

File tree

2 files changed

+44
-8
lines changed

2 files changed

+44
-8
lines changed

tests/integration-tests/conftest.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
delete_s3_bucket,
4949
generate_stack_name,
5050
get_architecture_supported_by_instance_type,
51+
get_instance_info,
5152
get_vpc_snakecase_value,
5253
random_alphanumeric,
5354
set_credentials,
@@ -826,6 +827,24 @@ def architecture(request, instance, region):
826827
return supported_architecture
827828

828829

830+
@pytest.fixture()
831+
def default_threads_per_core(request, instance, region):
832+
"""Return the default threads per core for the given instance type."""
833+
# NOTE: currently, .metal instances do not contain the DefaultThreadsPerCore
834+
# attribute in their VCpuInfo section. This is a known limitation with the
835+
# ec2 DescribeInstanceTypes API. For these instance types an assumption
836+
# is made that if the instance's supported architectures list includes
837+
# x86_64 then the default is 2, otherwise it's 1.
838+
logging.info(f"Getting defaul threads per core for instance type {instance}")
839+
instance_type_data = get_instance_info(instance, region)
840+
threads_per_core = instance_type_data.get("VCpuInfo", {}).get("DefaultThreadsPerCore")
841+
if threads_per_core is None:
842+
supported_architectures = instance_type_data.get("ProcessorInfo", {}).get("SupportedArchitectures", [])
843+
threads_per_core = 2 if "x86_64" in supported_architectures else 1
844+
logging.info(f"Defaul threads per core for instance type {instance} : {threads_per_core}")
845+
return threads_per_core
846+
847+
829848
@pytest.fixture(scope="session")
830849
def key_name(request):
831850
"""Return the EC2 key pair name to be used."""

tests/integration-tests/tests/disable_hyperthreading/test_disable_hyperthreading.py

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,22 @@
2828
# HT disabled via CpuOptions
2929
@pytest.mark.dimensions("sa-east-1", "c5.xlarge", "alinux2", "sge")
3030
@pytest.mark.dimensions("sa-east-1", "c5.xlarge", "centos7", "torque")
31-
def test_sit_disable_hyperthreading(region, scheduler, instance, os, pcluster_config_reader, clusters_factory):
31+
def test_sit_disable_hyperthreading(
32+
region, scheduler, instance, os, pcluster_config_reader, clusters_factory, default_threads_per_core
33+
):
3234
"""Test Disable Hyperthreading for SIT clusters."""
3335
slots_per_instance = fetch_instance_slots(region, instance)
3436
cluster_config = pcluster_config_reader()
3537
cluster = clusters_factory(cluster_config)
3638
remote_command_executor = RemoteCommandExecutor(cluster)
3739
scheduler_commands = get_scheduler_commands(scheduler, remote_command_executor)
38-
_test_disable_hyperthreading_settings(remote_command_executor, scheduler_commands, slots_per_instance, scheduler)
40+
_test_disable_hyperthreading_settings(
41+
remote_command_executor,
42+
scheduler_commands,
43+
slots_per_instance,
44+
scheduler,
45+
default_threads_per_core=default_threads_per_core,
46+
)
3947

4048
assert_no_errors_in_logs(remote_command_executor, scheduler)
4149

@@ -47,7 +55,9 @@ def test_sit_disable_hyperthreading(region, scheduler, instance, os, pcluster_co
4755
@pytest.mark.dimensions("us-west-2", "m4.xlarge", "centos8", "slurm")
4856
# HT disabled via CpuOptions
4957
@pytest.mark.dimensions("us-west-1", "c5.xlarge", "ubuntu1804", "slurm")
50-
def test_hit_disable_hyperthreading(region, scheduler, instance, os, pcluster_config_reader, clusters_factory):
58+
def test_hit_disable_hyperthreading(
59+
region, scheduler, instance, os, pcluster_config_reader, clusters_factory, default_threads_per_core
60+
):
5161
"""Test Disable Hyperthreading for HIT clusters."""
5262
slots_per_instance = fetch_instance_slots(region, instance)
5363
cluster_config = pcluster_config_reader()
@@ -61,6 +71,7 @@ def test_hit_disable_hyperthreading(region, scheduler, instance, os, pcluster_co
6171
scheduler,
6272
hyperthreading_disabled=False,
6373
partition="ht-enabled",
74+
default_threads_per_core=default_threads_per_core,
6475
)
6576
_test_disable_hyperthreading_settings(
6677
remote_command_executor,
@@ -69,6 +80,7 @@ def test_hit_disable_hyperthreading(region, scheduler, instance, os, pcluster_co
6980
scheduler,
7081
hyperthreading_disabled=True,
7182
partition="ht-disabled",
83+
default_threads_per_core=default_threads_per_core,
7284
)
7385

7486
assert_no_errors_in_logs(remote_command_executor, scheduler)
@@ -81,17 +93,20 @@ def _test_disable_hyperthreading_settings(
8193
scheduler,
8294
hyperthreading_disabled=True,
8395
partition=None,
96+
default_threads_per_core=2,
8497
):
85-
expected_cpus_per_instance = slots_per_instance // 2 if hyperthreading_disabled else slots_per_instance
86-
expected_threads_per_core = 1 if hyperthreading_disabled else 2
98+
expected_cpus_per_instance = (
99+
slots_per_instance // default_threads_per_core if hyperthreading_disabled else slots_per_instance
100+
)
101+
expected_threads_per_core = 1 if hyperthreading_disabled else default_threads_per_core
87102

88103
# Test disable hyperthreading on head node
89104
logging.info("Test Disable Hyperthreading on head node")
90105
result = remote_command_executor.run_remote_command("lscpu")
91106
if partition:
92107
# If partition is supplied, assume this is HIT setting where ht settings are at the queue level
93108
# In this case, ht is not disabled on head node
94-
assert_that(result.stdout).matches(r"Thread\(s\) per core:\s+{0}".format(2))
109+
assert_that(result.stdout).matches(r"Thread\(s\) per core:\s+{0}".format(default_threads_per_core))
95110
_assert_active_cpus(result.stdout, slots_per_instance)
96111
else:
97112
assert_that(result.stdout).matches(r"Thread\(s\) per core:\s+{0}".format(expected_threads_per_core))
@@ -128,10 +143,12 @@ def _test_disable_hyperthreading_settings(
128143
# check scale up to 2 nodes
129144
if partition:
130145
result = scheduler_commands.submit_command(
131-
"hostname > /shared/hostname.out", slots=slots_per_instance, partition=partition
146+
"hostname > /shared/hostname.out", slots=2 * expected_cpus_per_instance, partition=partition
132147
)
133148
else:
134-
result = scheduler_commands.submit_command("hostname > /shared/hostname.out", slots=slots_per_instance)
149+
result = scheduler_commands.submit_command(
150+
"hostname > /shared/hostname.out", slots=2 * expected_cpus_per_instance
151+
)
135152
job_id = scheduler_commands.assert_job_submitted(result.stdout)
136153
scheduler_commands.wait_job_completed(job_id)
137154
scheduler_commands.assert_job_succeeded(job_id)

0 commit comments

Comments
 (0)