<commit_before>///! x86 timing functions.

use raw_cpuid::CpuId;
use x86_64::instructions::port::Port;
use core::arch::x86_64::_rdtsc;

/// Frequency of the PIT
const PIT_FREQUENCY: u64 = 1193182;

/// PIT port definition
const PIT_PORT_MODE: u16 = 0x43;
const PIT_PORT_CHANNEL_0: u16 = 0x40;

/// PIT mode bit definitions
const PIT_MODE_CHANNEL_0: u8 = 0 << 6;
const PIT_MODE_RATE_GENERATOR: u8 = 2 << 1;
const PIT_MODE_ACCESS_LATCH: u8 = 0 << 4;
const PIT_MODE_ACCESS_BOTH: u8 = 3 << 4;

/// Type used to store a time value in milliseconds.
pub type msTime = u64;

/// This a manager for all time functions
pub struct TimeManager {
    /// TSC cycles per milliseconds
    tsc_cycles_per_msec: u64,

    /// Initial TSC start time
    tsc_start_time: u64,
}

impl TimeManager {
    /// Create a new time manger instance.
    pub fn new() -> Self {
        TimeManager {
            tsc_cycles_per_msec: 0,
            tsc_start_time: 0,
        }
    }

    /// Get the number of cycles per second
    pub fn get_cycles_per_msec(&self) -> u64 {
        self.tsc_cycles_per_msec
    }

    /// Get the current internal time.
    pub fn current_time(&self) -> msTime {
        let current = unsafe { _rdtsc() };
        (current - self.get_cycles_per_msec()) / self.tsc_cycles_per_msec
    }

    /// Initialize the TSC
    pub fn init(&mut self) {
        let cpuid = CpuId::new();

        // Check TSC support
        {
            let has_tsc = match cpuid.get_feature_info() {
                Some(finfo) => finfo.has_tsc(),
                None => false,
            };

            if !has_tsc {
                panic!("CPU does not support TSC");
            }
        }
<commit_msg>chore: rename msTime to MsTime<commit_after>///! x86 timing functions.

use raw_cpuid::CpuId;
use x86_64::instructions::port::Port;
use core::arch::x86_64::_rdtsc;

/// Frequency of the PIT
const PIT_FREQUENCY: u64 = 1193182;

/// PIT port definition
const PIT_PORT_MODE: u16 = 0x43;
const PIT_PORT_CHANNEL_0: u16 = 0x40;

/// PIT mode bit definitions
const PIT_MODE_CHANNEL_0: u8 = 0 << 6;
const PIT_MODE_RATE_GENERATOR: u8 = 2 << 1;
const PIT_MODE_ACCESS_LATCH: u8 = 0 << 4;
const PIT_MODE_ACCESS_BOTH: u8 = 3 << 4;

/// Type used to store a time value in milliseconds.
pub type MsTime = u64;

/// This a manager for all time functions
pub struct TimeManager {
    /// TSC cycles per milliseconds
    tsc_cycles_per_msec: u64,

    /// Initial TSC start time
    tsc_start_time: u64,
}

impl TimeManager {
    /// Create a new time manger instance.
    pub fn new() -> Self {
        TimeManager {
            tsc_cycles_per_msec: 0,
            tsc_start_time: 0,
        }
    }

    /// Get the number of cycles per second
    pub fn get_cycles_per_msec(&self) -> u64 {
        self.tsc_cycles_per_msec
    }

    /// Get the current internal time.
    pub fn current_time(&self) -> MsTime {
        let current = unsafe { _rdtsc() };
        (current - self.get_cycles_per_msec()) / self.tsc_cycles_per_msec
    }

    /// Initialize the TSC
    pub fn init(&mut self) {
        let cpuid = CpuId::new();

        // Check TSC support
        {
            let has_tsc = match cpuid.get_feature_info(){
                Some(finfo) => finfo.has_tsc(),
                None => false,
            };

            if !has_tsc {
                panic!("CPU does not support TSC");
            }
        }

{'fraction_non_alphanumeric': 0.1068904593639576, 'fraction_numerical': 0.03121319199057715, 'mean_word_length': 2.1807116104868913, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6778655', 'n_tokens_mistral': 1255, 'n_tokens_neox': 1157, 'n_words': 326}