-
Notifications
You must be signed in to change notification settings - Fork 2.6k
vmm: x86_64: synchronize TSC offsets after restoring vCPUs #6200
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ | |
| import platform | ||
| import re | ||
| import shutil | ||
| import textwrap | ||
| import time | ||
| import uuid | ||
| from pathlib import Path | ||
|
|
@@ -743,6 +744,32 @@ def read_guest_clocksource(vm): | |
| return stdout.strip() | ||
|
|
||
|
|
||
| def check_guest_monotonic_across_vcpus(vm): | ||
| """Check clock monotonicity as a task migrates between restored vCPUs.""" | ||
| _, stdout, _ = vm.ssh.check_output( | ||
| textwrap.dedent("""\ | ||
| python3 - <<'PY' | ||
| import os | ||
| import time | ||
|
|
||
| cpus = sorted(os.sched_getaffinity(0)) | ||
| assert len(cpus) == 2, cpus | ||
| previous = time.monotonic_ns() | ||
| for _ in range(10_000): | ||
| for cpu in cpus: | ||
| os.sched_setaffinity(0, {cpu}) | ||
| current = time.monotonic_ns() | ||
| assert current >= previous, (cpu, previous, current) | ||
| previous = current | ||
|
|
||
| print("20,000 clock samples across vCPU migrations: no regressions") | ||
| PY | ||
| """), | ||
| timeout=30, | ||
| ) | ||
| print(stdout.strip()) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("clocksource", CLOCK_SOURCES) | ||
| @pytest.mark.parametrize("clock_realtime", [False, True]) | ||
| def test_clocksource_snapshot_restore( | ||
|
|
@@ -804,6 +831,8 @@ def test_clocksource_snapshot_restore( | |
| # If guest_delta is close to host_delta, the clock jumped forward | ||
| # (suspend/resume behavior). If it's near 0, it resumed from where | ||
| # it left off. | ||
| if not clock_realtime: | ||
| assert 0 <= guest_delta < 5.0, f"Unexpected clock delta: {guest_delta:.6f}s" | ||
|
Comment on lines
+834
to
+835
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do we want to ensure with this? How is this related to the TSC offset synchronization between vCPUs?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I left it in while asserting the behaviour before and after this change. I can remove if we want
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the assertion itself is useful, but could we move it below the diagnostic prints, next to |
||
| jumped = abs(guest_delta - host_delta) < 5.0 | ||
|
|
||
| jumped_str = "JUMPED" if jumped else "RESUMED" | ||
|
|
@@ -820,3 +849,7 @@ def test_clocksource_snapshot_restore( | |
| assert ( | ||
| jumped == clock_realtime | ||
| ), f"Clock {jumped_str} but clock_realtime was {"not" if clock_realtime else ""} set." | ||
|
|
||
| if clocksource == "tsc": | ||
| check_guest_monotonic_across_vcpus(restored_vm) | ||
| assert read_guest_clocksource(restored_vm) == "tsc" | ||
Uh oh!
There was an error while loading. Please reload this page.