Skip to content

Commit c3545c4

Browse files
authored
Move TSC checks into feature gated area.
1 parent 33c61dc commit c3545c4

File tree

1 file changed

+7
-17
lines changed

1 file changed

+7
-17
lines changed

src/lib.rs

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,13 @@ fn mul_div_po2_u64(value: u64, numer: u64, denom: u32) -> u64 {
544544
#[allow(dead_code)]
545545
#[cfg(all(target_arch = "x86_64", target_feature = "sse2"))]
546546
fn has_tsc_support() -> bool {
547-
read_cpuid_invariant_tsc() && read_cpuid_rdtscp_support()
547+
let cpuid = CpuId::new();
548+
let has_invariant_tsc = cpuid.get_advanced_power_mgmt_info()
549+
.map_or(false, |apm| apm.has_invariant_tsc());
550+
let has_rdtscp = cpuid.get_extended_processor_and_feature_identifiers()
551+
.map_or(false, |epf| epf.has_rdtscp());
552+
553+
has_invariant_tsc && has_rdtscp
548554
}
549555

550556
#[allow(dead_code)]
@@ -553,22 +559,6 @@ fn has_tsc_support() -> bool {
553559
false
554560
}
555561

556-
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
557-
fn read_cpuid_invariant_tsc() -> bool {
558-
let cpuid = CpuId::new();
559-
cpuid
560-
.get_advanced_power_mgmt_info()
561-
.map_or(false, |efi| efi.has_invariant_tsc())
562-
}
563-
564-
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
565-
fn read_cpuid_rdtscp_support() -> bool {
566-
let cpuid = CpuId::new();
567-
cpuid
568-
.get_extended_processor_and_feature_identifiers()
569-
.map_or(false, |efi| efi.has_rdtscp())
570-
}
571-
572562
#[cfg(test)]
573563
pub mod tests {
574564
use super::{Clock, Counter, Monotonic};

0 commit comments

Comments
 (0)