Repository: firecracker-microvm/firecracker
File: src/vmm/src/cpu_config/x86_64/cpuid/intel/normalize.rs (Rust)

Code before:
    /// fit.
    #[inline]
    pub fn normalize(
        &mut self,
        // The index of the current logical CPU in the range [0..cpu_count].
        _cpu_index: u8,
        // The total number of logical CPUs.
        cpu_count: u8,
        // The number of logical CPUs per core.
        cpus_per_core: u8,
    ) -> Result<(), NormalizeCpuidError> {
        self.update_deterministic_cache_entry(cpu_count, cpus_per_core)?;
        self.update_power_management_entry()?;
        self.update_extended_feature_flags_entry()?;
        self.update_performance_monitoring_entry()?;
        self.update_extended_topology_v2_entry();
        self.update_brand_string_entry()?;
        self.update_frequency_information();

        Ok(())
    }

    /// Passes through the host value of cpuid leaves 15h and 16h if they
    /// are zero.
    fn update_frequency_information(&mut self) {
        let Some(leaf_15h) = self.get_mut(&CpuidKey::leaf(0x15)) else {
            return;
        };

        if leaf_15h.result != CpuidRegisters::default() {
            let host_leaf_15 = cpuid(0x15);

            leaf_15h.result.eax = host_leaf_15.eax;
            leaf_15h.result.ebx = host_leaf_15.ebx;
            leaf_15h.result.ecx = host_leaf_15.ecx;
            // edx is reserved
        }

        let Some(leaf_16h) = self.get_mut(&CpuidKey::leaf(0x16)) else {
            return;
        };

        if leaf_16h.result != CpuidRegisters::default() {
            let host_leaf_16 = cpuid(0x16);

            leaf_16h.result.eax = host_leaf_16.eax;
            leaf_16h.result.ebx = host_leaf_16.ebx;
            leaf_16h.result.ecx = host_leaf_16.ecx;
            // edx is reserved
        }
    }

Review comment (performance):
can you add a comment like below?
```
                // CPUID.04H:EAX[7:5]
                // Cache Level (Starts at 1)
```

Code after:
    /// fit.
    #[inline]
    pub fn normalize(
        &mut self,
        // The index of the current logical CPU in the range [0..cpu_count].
        _cpu_index: u8,
        // The total number of logical CPUs.
        cpu_count: u8,
        // The number of logical CPUs per core.
        cpus_per_core: u8,
    ) -> Result<(), NormalizeCpuidError> {
        self.update_deterministic_cache_entry(cpu_count, cpus_per_core)?;
        self.update_power_management_entry()?;
        self.update_extended_feature_flags_entry()?;
        self.update_performance_monitoring_entry()?;
        self.update_extended_topology_v2_entry();
        self.update_brand_string_entry()?;
        self.update_frequency_information();

        Ok(())
    }

    /// Passes through the host value of cpuid leaves 15h and 16h if they
    /// are not already configured via cpu template.
    fn update_frequency_information(&mut self) {
        let Some(leaf_15h) = self.get_mut(&CpuidKey::leaf(0x15)) else {
            return;
        };

        if leaf_15h.result == CpuidRegisters::default() {
            let host_leaf_15 = cpuid(0x15);

            // CPUID.15H:EAX[31:0]
            // Ratio of TSC frequency to Core Crystal Clock frequency, denominator
            leaf_15h.result.eax = host_leaf_15.eax;
            // CPUID.15H:EBX[31:0]
            // Ratio of TSC frequency to Core Crystal Clock frequency, numerator
            leaf_15h.result.ebx = host_leaf_15.ebx;
            // CPUID.15H:ECX[31:0]
            // Core Crystal Clock frequency, in units of Hz
            leaf_15h.result.ecx = host_leaf_15.ecx;
            // edx is reserved
        }

        let Some(leaf_16h) = self.get_mut(&CpuidKey::leaf(0x16)) else {
            return;
        };

        if leaf_16h.result == CpuidRegisters::default() {
            let host_leaf_16 = cpuid(0x16);