Skip to content

Add cpu policy helper and test#504

Merged
stormi merged 2 commits into
masterfrom
teddy/cpu-policy
Jun 4, 2026
Merged

Add cpu policy helper and test#504
stormi merged 2 commits into
masterfrom
teddy/cpu-policy

Conversation

@TSnake41

Copy link
Copy Markdown
Member

Add a CPU policy tooling to be able to check for certain CPU feature.
The test_cpu_policy also logs hosts CPU policies for debugging purposes (especially around live migrations).

Required by #393

@TSnake41 TSnake41 requested a review from a team as a code owner April 27, 2026 14:21

@glehmann glehmann left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test doesn't seem actually to validate anything. Am I missing something?

Comment thread tests/misc/test_cpu_policy.py Outdated
@TSnake41

Copy link
Copy Markdown
Member Author

The test doesn't seem actually to validate anything. Am I missing something?

There's nothing to validate aside that it doesn't errors.

Comment thread lib/cpu_policy.py Outdated
Comment thread lib/cpu_policy.py Outdated
Comment thread jobs.py Outdated
Comment thread lib/cpu_policy.py Outdated
Comment thread lib/cpu_policy.py Outdated
# msr -> val
msr: dict[int, int]

def __init__(self, cpuid: dict[(int, int), int], msr: dict[int, int]):

@glehmann glehmann Apr 28, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def __init__(self, cpuid: dict[(int, int), int], msr: dict[int, int]):
def __init__(self, cpuid: dict[tuple[int, int], tuple[int, int, int, int]], msr: dict[int, int]):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@glehmann, is the current recommendation to use native types for typing or the ones from the typing module?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tuple[int, int, int, int] might be better represented with

@dataclass(frozen=True)
class CpuidRegisters:
    eax: int
    ebx: int
    ecx: int
    edx: int

and used as

def __init__(self, cpuid: dict[tuple[int, int], CpuidRegisters], msr: dict[int, int]):
                current_policy.cpuid[key] = CpuidRegisters(
                    int(eax, 16),
                    int(ebx, 16),
                    int(ecx, 16),
                    int(edx, 16)
                )

Each element can then be accessed by name:

current_policy.cpuid[key].eax

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@glehmann, is the current recommendation to use native types for typing or the ones from the typing module?

No, we had diverging opinions on that last time we discussed it.
I'm proposing to go with builtin types in #460

Comment thread lib/cpu_policy.py Outdated
Comment thread lib/cpu_policy.py Outdated
@TSnake41 TSnake41 requested a review from a team as a code owner April 28, 2026 11:47

@dinhngtu dinhngtu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix the checkers first.

@TSnake41 TSnake41 force-pushed the teddy/cpu-policy branch 3 times, most recently from a31a080 to 8842d6b Compare May 11, 2026 15:09
@stormi

stormi commented May 11, 2026

Copy link
Copy Markdown
Member

@TSnake41 After a force push, if your PR is ready for re-review, always ask the reviewers who commented for a re-review.

Comment thread tests/xen/test_cpu_policy.py Outdated
Comment thread tests/xen/test_cpu_policy_collection.py
Add a CPU policy tooling to be able to check for certain CPU feature.
The test_cpu_policy also logs hosts CPU policies for debugging purposes.

Signed-off-by: Teddy Astie <teddy.astie@vates.tech>
@TSnake41 TSnake41 force-pushed the teddy/cpu-policy branch from 8842d6b to 184bd3d Compare May 22, 2026 12:38
@TSnake41 TSnake41 requested review from dinhngtu, glehmann and stormi May 22, 2026 12:39
Comment thread tests/xen/test_cpu_policy.py Outdated
Signed-off-by: Samuel Verschelde <stormi-xcp@ylix.fr>
@stormi stormi requested review from dinhngtu and glehmann June 4, 2026 14:52
@stormi stormi merged commit 696b2ba into master Jun 4, 2026
9 checks passed
@stormi stormi deleted the teddy/cpu-policy branch June 4, 2026 16:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants