-
Notifications
You must be signed in to change notification settings - Fork 36
Description of cpuid.rs Readme #22
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
Open
Laxman824
wants to merge
2
commits into
codenet:main
Choose a base branch
from
Laxman824:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| Firstly in this code they strongly suggest that the 'cpuid' be derived from the supported CPUID of the host machine that is currently operating. | ||
codenet marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| use kvm_bindings::CpuId; | ||
| use kvm_ioctls::{Cap::TscDeadlineTimer, Kvm}; | ||
|
|
||
|
|
||
codenet marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| They have defined cpuid and used it with kvm_bindings and kvm_iocontrols .we are defining some variables with the cpuid bits in ebx,ecx and edx registers .all most every varibale is unsigned int of 32 bit ex: EBX_CLFLUSH_CACHELINE: u32,EBX_CPU_COUNT_SHIFT: u32 ,ECX_TSC_DEADLINE_TIMER_SHIFT: u32 etc | ||
|
|
||
| ### const EBX_CLFLUSH_CACHELINE: u32 = 8; // Flush a cache line size. | ||
| const EBX_CLFLUSH_SIZE_SHIFT: u32 = 8; // Bytes flushed when executing CLFLUSH. | ||
| const EBX_CPU_COUNT_SHIFT: u32 = 16; // Index of this CPU. | ||
| const EBX_CPUID_SHIFT: u32 = 24; // Index of this CPU. | ||
| const ECX_EPB_SHIFT: u32 = 3; // "Energy Performance Bias" bit. | ||
| const ECX_TSC_DEADLINE_TIMER_SHIFT: u32 = 24; // TSC deadline mode of APIC timer | ||
| const ECX_HYPERVISOR_SHIFT: u32 = 31; // Flag to be set when the cpu is running on a hypervisor. | ||
| const EDX_HTT_SHIFT: u32 = 28; // Hyper Threading Enabled. | ||
|
|
||
| pub fn filter_cpuid(kvm: &Kvm, vcpu_id: u8, cpu_count: u8, cpuid: &mut CpuId) { | ||
| for entry in cpuid.as_mut_slice().iter_mut() { | ||
| match entry.function { | ||
| 0x01 => { | ||
| // X86 hypervisor feature. | ||
| if entry.index == 0 { | ||
| entry.ecx |= 1 << ECX_HYPERVISOR_SHIFT; | ||
| } | ||
| if kvm.check_extension(TscDeadlineTimer) { | ||
| entry.ecx |= 1 << ECX_TSC_DEADLINE_TIMER_SHIFT; | ||
| } | ||
| entry.ebx = ((vcpu_id as u32) << EBX_CPUID_SHIFT) as u32 | ||
| | (EBX_CLFLUSH_CACHELINE << EBX_CLFLUSH_SIZE_SHIFT); | ||
| if cpu_count > 1 { | ||
| entry.ebx |= (cpu_count as u32) << EBX_CPU_COUNT_SHIFT; | ||
| entry.edx |= 1 << EDX_HTT_SHIFT; | ||
| } | ||
| } | ||
| 0x06 => { | ||
| // Clear X86 EPB feature. No frequency selection in the hypervisor. | ||
| entry.ecx &= !(1 << ECX_EPB_SHIFT); | ||
| } | ||
| 0x0B => { | ||
| // EDX bits 31..0 contain x2APIC ID of current logical processor. | ||
| entry.edx = vcpu_id as u32; | ||
| } | ||
| _ => (), | ||
| } | ||
| } | ||
|
|
||
| ##They have written a funciton for filter_cpuid which takes input of vcpu_id and cpu_count,cpuid and for each entry in cpuid we are checking/matching the address(0x06) of x86 hypervisor feature . | ||
| here we are using the temporary registers for data storing and memory access like edx,ebx,ecx etc. | ||
| if address matches then it will execute the clear the x86 EPB feature and no frequency selection in the hypervisor is done.In other case if address is (0x0B) then edx 32 bit contains the X2APIC ID of current logical processor as vcpu_id. | ||
|
|
||
| In other case of address(0x01) then as we will check the index ,if it is equal to 0,then shift the ECX_HYPERVISOR_SHIFT and in the same address if check_extension is TscDeadlineTimer accordingly as we have declared above the function is performing TSC deadline mode of APIC timer. | ||
| IF ebx register is equals to ,we are flusing the byte which are stored in CACHELINE | ||
| In the other case of address (0x01) if cpu_count is greater than one then we are shifting the EBX_CPU_COUNT_SHIFT to the ebx register and EDX_HTT_SHIFT is shifted to edx register accordingly. | ||
|
|
||
| At last a bit of an artificial test is given to validate at unit test level. | ||
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.