forked from cloud-hypervisor/cloud-hypervisor
-
Notifications
You must be signed in to change notification settings - Fork 4
cpu-profiles: Alternative implementation #10
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
Closed
olivereanderson
wants to merge
12
commits into
oanderson/cpu-profiles
from
oanderson/cpu-profiles-alternative-description
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
8a78043
build: Bump crate-ci/typos from 1.33.1 to 1.34.0
dependabot[bot] da5fae3
docs: Fix the chown command in macvtap-bridge.md
liuw 5c067fd
Start manual implementation of CPUID feature flag values
olivereanderson bc311d7
Add Feature flags with macros
olivereanderson 58502d0
constructor
olivereanderson 3f5c32d
Intersect feature flags
olivereanderson 241c412
Move CpuProfile into arch/src/lib.rs
olivereanderson 244a1ea
Make it compile with warnings
olivereanderson 644a0a0
Implement the restriction, improve documentation and some minor cleanup
olivereanderson 8815ae3
Adjust documentation
olivereanderson 405334f
Fix missing conditional compilation
olivereanderson 357ed77
Alternative implementation
olivereanderson 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| use hypervisor::arch::x86::CpuIdEntry; | ||
|
|
||
| use super::{CpuIdFeatureFlags, CpuidReg}; | ||
|
|
||
| pub(super) struct CascadeLakeServerV1CpuIdFeatures { | ||
| edx_1: CpuIdFeatureFlags<1, 0, { CpuidReg::EDX as u8 }>, | ||
| ecx_1: CpuIdFeatureFlags<1, 0, { CpuidReg::ECX as u8 }>, | ||
| edx_8000_0001h: CpuIdFeatureFlags<0x8000_0001, 0, { CpuidReg::EDX as u8 }>, | ||
| ecx_8000_0001h: CpuIdFeatureFlags<0x8000_0001, 0, { CpuidReg::ECX as u8 }>, | ||
| ebx_7_0: CpuIdFeatureFlags<7, 0, { CpuidReg::EBX as u8 }>, | ||
| ecx_7_0: CpuIdFeatureFlags<7, 0, { CpuidReg::ECX as u8 }>, | ||
| edx_7_0: CpuIdFeatureFlags<7, 0, { CpuidReg::EDX as u8 }>, | ||
| eax_0dh: CpuIdFeatureFlags<0xd, 1, { CpuidReg::EAX as u8 }>, | ||
| } | ||
|
|
||
| impl CascadeLakeServerV1CpuIdFeatures { | ||
| pub(super) const fn new() -> Self { | ||
| use CpuIdFeatureFlags as FF; | ||
| // Placing this in a const block ensures compile time evaluation and we get isntant feedback | ||
| // (even from the LSP) if the lists contain arguments that are not defined for the given | ||
| // function, index, register triple via `crate::x86_64::impl_cpuid_feature_flags!` | ||
| const { | ||
| Self { | ||
| edx_1: FF::<1, 0, { CpuidReg::EDX as u8 }>::from_names(&[ | ||
|
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. For better or worse: The compiler does not manage to infer the const generic parameters when they are left out here, even though we have specified them in the field declaration of the struct. |
||
| "vme", "sse2", "sse", "fxsr", "mmx", "clflush", "pse36", "pat", "cmov", "mca", | ||
| "pge", "mtrr", "sep", "apic", "cx8", "mce", "pae", "msr", "tsc", "pse", "de", | ||
| "fpu", | ||
| ]), | ||
|
|
||
| ecx_1: FF::<1, 0, { CpuidReg::ECX as u8 }>::from_names(&[ | ||
| "avx", | ||
| "xsave", | ||
| "aes", | ||
| "popcnt", | ||
| "x2apic", | ||
| "sse4.2", | ||
| "sse4.1", | ||
| "cx16", | ||
| "ssse3", | ||
| "pclmulqdq", | ||
| "pni", | ||
| "tsc-deadline", | ||
| "fma", | ||
| "movbe", | ||
| "pcid", | ||
| "f16c", | ||
| "rdrand", | ||
| ]), | ||
|
|
||
| edx_8000_0001h: FF::<0x8000_0001, 0, { CpuidReg::EDX as u8 }>::from_names(&[ | ||
| "lm", "pdpe1gb", "rdtscp", "nx", "syscall", | ||
| ]), | ||
| ecx_8000_0001h: FF::<0x8000_0001, 0, { CpuidReg::ECX as u8 }>::from_names(&[ | ||
| "abm", | ||
| "lahf-lm", | ||
| "3dnowprefetch", | ||
| ]), | ||
| ebx_7_0: FF::<7, 0, { CpuidReg::EBX as u8 }>::from_names(&[ | ||
| "fsgsbase", | ||
| "bmi1", | ||
| "hle", | ||
| "avx2", | ||
| "smep", | ||
| "bmi2", | ||
| "erms", | ||
| "invpcid", | ||
| "rtm", | ||
| "rdseed", | ||
| "adx", | ||
| "smap", | ||
| "clwb", | ||
| "avx512f", | ||
| "avx512dq", | ||
| "avx512bw", | ||
| "avx512cd", | ||
| "avx512vl", | ||
| "clflushopt", | ||
| ]), | ||
| ecx_7_0: FF::<7, 0, { CpuidReg::ECX as u8 }>::from_names(&["pku", "avx512vnni"]), | ||
| edx_7_0: FF::<7, 0, { CpuidReg::EDX as u8 }>::from_names(&["spec-ctrl", "ssbd"]), | ||
| eax_0dh: FF::<0xd, 1, { CpuidReg::EAX as u8 }>::from_names(&[ | ||
| "xsaveopt", "xsavec", "xgetbv1", | ||
| ]), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// Restricts the given entries by performing bitwise intersections of registers | ||
| /// per set of matching parameters. | ||
| pub(super) fn restrict(self, cpuid: &mut [CpuIdEntry]) { | ||
| // NOTE: This might get a bit repetetive when we get more structs in this module. | ||
| // Might be worth introducing a proc macro for this at some point... | ||
| let Self { | ||
| edx_1, | ||
| ecx_1, | ||
| edx_8000_0001h, | ||
| ecx_8000_0001h, | ||
| ebx_7_0, | ||
| ecx_7_0, | ||
| edx_7_0, | ||
| eax_0dh, | ||
| } = self; | ||
| edx_1.intersect_matching(cpuid); | ||
| ecx_1.intersect_matching(cpuid); | ||
| edx_8000_0001h.intersect_matching(cpuid); | ||
| ecx_8000_0001h.intersect_matching(cpuid); | ||
| ebx_7_0.intersect_matching(cpuid); | ||
| ecx_7_0.intersect_matching(cpuid); | ||
| edx_7_0.intersect_matching(cpuid); | ||
| eax_0dh.intersect_matching(cpuid); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I verified this statement by chance when developing 😄