-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add Steal Time support in ARM #5139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
# Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
"""Tests for verifying the PVTime device behavior under contention and across snapshots.""" | ||
|
||
import time | ||
|
||
import pytest | ||
|
||
from framework.properties import global_props | ||
|
||
|
||
def get_steal_time_ms(vm): | ||
"""Returns total steal time of vCPUs in VM in milliseconds""" | ||
_, out, _ = vm.ssh.run("grep -w '^cpu' /proc/stat") | ||
steal_time_tck = int(out.strip().split()[8]) | ||
clk_tck = int(vm.ssh.run("getconf CLK_TCK").stdout) | ||
return steal_time_tck / clk_tck * 1000 | ||
|
||
|
||
@pytest.mark.skipif( | ||
global_props.cpu_architecture != "aarch64", reason="Only run in aarch64" | ||
) | ||
def test_guest_has_pvtime_enabled(uvm_plain): | ||
""" | ||
Check that the guest kernel has enabled PV steal time. | ||
""" | ||
vm = uvm_plain | ||
vm.spawn() | ||
vm.basic_config() | ||
vm.add_net_iface() | ||
vm.start() | ||
|
||
_, stdout, _ = vm.ssh.run("dmesg | grep 'stolen time PV'") | ||
assert ( | ||
"stolen time PV" in stdout | ||
), "Guest kernel did not report PV steal time enabled" | ||
|
||
|
||
def test_pvtime_steal_time_increases(uvm_plain): | ||
""" | ||
Test that PVTime steal time increases when both vCPUs are contended on the same pCPU. | ||
""" | ||
vm = uvm_plain | ||
vm.spawn() | ||
vm.basic_config() | ||
vm.add_net_iface() | ||
vm.start() | ||
|
||
# Pin both vCPUs to the same physical CPU to induce contention | ||
vm.pin_vcpu(0, 0) | ||
vm.pin_vcpu(1, 0) | ||
|
||
# Start two infinite loops to hog CPU time | ||
hog_cmd = "nohup bash -c 'while true; do :; done' >/dev/null 2>&1 &" | ||
vm.ssh.run(hog_cmd) | ||
vm.ssh.run(hog_cmd) | ||
|
||
# Measure before and after steal time | ||
steal_before = get_steal_time_ms(vm) | ||
time.sleep(2) | ||
steal_after = get_steal_time_ms(vm) | ||
|
||
# Require increase in steal time | ||
assert ( | ||
steal_after > steal_before | ||
), f"Steal time did not increase as expected. Before: {steal_before}, After: {steal_after}" | ||
|
||
|
||
def test_pvtime_snapshot(uvm_plain, microvm_factory): | ||
""" | ||
Test that PVTime steal time is preserved across snapshot/restore | ||
and continues increasing post-resume. | ||
""" | ||
vm = uvm_plain | ||
vm.spawn() | ||
vm.basic_config() | ||
vm.add_net_iface() | ||
vm.start() | ||
|
||
vm.pin_vcpu(0, 0) | ||
vm.pin_vcpu(1, 0) | ||
|
||
hog_cmd = "nohup bash -c 'while true; do :; done' >/dev/null 2>&1 &" | ||
vm.ssh.run(hog_cmd) | ||
vm.ssh.run(hog_cmd) | ||
|
||
# Snapshot pre-steal time | ||
steal_before = get_steal_time_ms(vm) | ||
|
||
snapshot = vm.snapshot_full() | ||
vm.kill() | ||
|
||
# Restore microVM from snapshot and resume | ||
restored_vm = microvm_factory.build() | ||
restored_vm.spawn() | ||
restored_vm.restore_from_snapshot(snapshot, resume=False) | ||
snapshot.delete() | ||
|
||
restored_vm.pin_vcpu(0, 0) | ||
restored_vm.pin_vcpu(1, 0) | ||
restored_vm.resume() | ||
|
||
# Steal time just after restoring | ||
steal_after_snap = get_steal_time_ms(restored_vm) | ||
|
||
time.sleep(2) | ||
|
||
# Steal time after running resumed VM | ||
steal_after_resume = get_steal_time_ms(restored_vm) | ||
|
||
# Ensure steal time persisted and continued increasing | ||
tolerance = 2000 # 2.0 seconds tolerance for persistence check | ||
persisted = ( | ||
steal_before < steal_after_snap and steal_after_snap - steal_before < tolerance | ||
) | ||
increased = steal_after_resume > steal_after_snap | ||
|
||
assert ( | ||
persisted and increased | ||
), "Steal time did not persist through snapshot or failed to increase after resume" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.