mirror of
https://github.com/zephyrproject-rtos/zephyr
synced 2025-08-26 06:45:58 +00:00
The boot time measurement sample was giving bogus values on x86: an assumption was made that the system timer is in sync with the CPU TSC, which is not the case on most x86 boards. Boot time measurements are no longer permitted unless the timer source is the local APIC. To avoid issues of TSC scaling, the startup datum has been forced to 0, which is in line with the ARM implementation (which is the only other platform which supports this feature). Cleanups along the way: As the datum is now assumed zero, some variables are removed and calculations simplified. The global variables involved in boot time measurements are moved to the kernel.h header rather than being redeclared in every place they are referenced. Since none of the measurements actually use 64-bit precision, the samples are reduced to 32-bit quantities. In addition, this feature has been enabled in long mode. Fixes: #19144 Signed-off-by: Charles E. Youse <charles.youse@intel.com>
84 lines
1.6 KiB
C
84 lines
1.6 KiB
C
/*
|
|
* Copyright (c) 2019 Intel Corp.
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
#ifndef ZEPHYR_INCLUDE_ARCH_X86_MSR_H_
|
|
#define ZEPHYR_INCLUDE_ARCH_X86_MSR_H_
|
|
|
|
/*
|
|
* Model specific registers (MSR). Access with z_x86_msr_read/write().
|
|
*/
|
|
|
|
#define X86_TIME_STAMP_COUNTER_MSR 0x00000010
|
|
|
|
#define X86_SPEC_CTRL_MSR 0x00000048
|
|
#define X86_SPEC_CTRL_MSR_IBRS BIT(0)
|
|
#define X86_SPEC_CTRL_MSR_SSBD BIT(2)
|
|
|
|
#define X86_APIC_BASE_MSR 0x0000001b
|
|
#define X86_APIC_BASE_MSR_X2APIC BIT(10)
|
|
|
|
#define X86_MTRR_DEF_TYPE_MSR 0x000002ff
|
|
#define X86_MTRR_DEF_TYPE_MSR_ENABLE BIT(11)
|
|
|
|
#define X86_X2APIC_BASE_MSR 0x00000800 /* .. thru 0x00000BFF */
|
|
|
|
#define X86_EFER_MSR 0xC0000080
|
|
#define X86_EFER_MSR_LME BIT(8)
|
|
|
|
#ifndef _ASMLANGUAGE
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/*
|
|
* z_x86_msr_write() is shared between 32- and 64-bit implementations, but
|
|
* due to ABI differences with long return values, z_x86_msr_read() is not.
|
|
*/
|
|
|
|
static inline void z_x86_msr_write(unsigned int msr, u64_t data)
|
|
{
|
|
u32_t high = data >> 32;
|
|
u32_t low = data & 0xFFFFFFFF;
|
|
|
|
__asm__ volatile ("wrmsr" : : "c"(msr), "a"(low), "d"(high));
|
|
}
|
|
|
|
#ifdef CONFIG_X86_LONGMODE
|
|
|
|
static inline u64_t z_x86_msr_read(unsigned int msr)
|
|
{
|
|
union {
|
|
struct {
|
|
u32_t lo;
|
|
u32_t hi;
|
|
};
|
|
u64_t value;
|
|
} rv;
|
|
|
|
__asm__ volatile ("rdmsr" : "=a" (rv.lo), "=d" (rv.hi) : "c" (msr));
|
|
|
|
return rv.value;
|
|
}
|
|
|
|
#else
|
|
|
|
static inline u64_t z_x86_msr_read(unsigned int msr)
|
|
{
|
|
u64_t ret;
|
|
|
|
__asm__ volatile("rdmsr" : "=A" (ret) : "c" (msr));
|
|
|
|
return ret;
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
#endif /* _ASMLANGUAGE */
|
|
|
|
#endif /* ZEPHYR_INCLUDE_ARCH_X86_MSR_H_ */
|