Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion boards/acrn/acrn/acrn_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ CONFIG_X2APIC=y
CONFIG_CONSOLE=y
CONFIG_SERIAL=y
CONFIG_UART_CONSOLE=y
CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC=25000000
CONFIG_BUILD_OUTPUT_BIN=y
CONFIG_SHELL_BACKEND_SERIAL_INTERRUPT_DRIVEN=n
CONFIG_KERNEL_VM_SIZE=0x1000000
CONFIG_BUILD_NO_GAP_FILL=y
CONFIG_TIMER_READS_ITS_FREQUENCY_AT_RUNTIME=y
2 changes: 1 addition & 1 deletion boards/acrn/acrn/acrn_ehl_crb_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ CONFIG_PCIE=y
CONFIG_CONSOLE=y
CONFIG_SERIAL=y
CONFIG_UART_CONSOLE=y
CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC=1900000000
CONFIG_BUILD_OUTPUT_BIN=y
CONFIG_SHELL_BACKEND_SERIAL_INTERRUPT_DRIVEN=n
CONFIG_KERNEL_VM_SIZE=0x1000000
CONFIG_BUILD_NO_GAP_FILL=y
CONFIG_APIC_TSC_DEADLINE_TIMER=y
CONFIG_APIC_TIMER_IRQ_PRIORITY=1
CONFIG_SMP=y
CONFIG_TIMER_READS_ITS_FREQUENCY_AT_RUNTIME=y
1 change: 0 additions & 1 deletion boards/intel/adl/intel_adl_crb_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ CONFIG_X2APIC=y
CONFIG_SMP=y
CONFIG_BUILD_OUTPUT_EFI=y
CONFIG_BUILD_NO_GAP_FILL=y
CONFIG_TIMER_READS_ITS_FREQUENCY_AT_RUNTIME=y
1 change: 0 additions & 1 deletion boards/intel/adl/intel_adl_rvp_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ CONFIG_X2APIC=y
CONFIG_SMP=y
CONFIG_BUILD_OUTPUT_EFI=y
CONFIG_BUILD_NO_GAP_FILL=y
CONFIG_TIMER_READS_ITS_FREQUENCY_AT_RUNTIME=y
1 change: 0 additions & 1 deletion boards/intel/ehl/intel_ehl_crb_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ CONFIG_SMP=y
CONFIG_BUILD_OUTPUT_EFI=y
CONFIG_BUILD_NO_GAP_FILL=y
CONFIG_PCIE_PRT=n
CONFIG_TIMER_READS_ITS_FREQUENCY_AT_RUNTIME=y
1 change: 0 additions & 1 deletion boards/intel/rpl/intel_rpl_p_crb_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@ CONFIG_X2APIC=y
CONFIG_SMP=y
CONFIG_BUILD_OUTPUT_EFI=y
CONFIG_BUILD_NO_GAP_FILL=y
CONFIG_TIMER_READS_ITS_FREQUENCY_AT_RUNTIME=y
1 change: 0 additions & 1 deletion boards/intel/rpl/intel_rpl_s_crb_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@ CONFIG_X2APIC=y
CONFIG_SMP=y
CONFIG_BUILD_OUTPUT_EFI=y
CONFIG_BUILD_NO_GAP_FILL=y
CONFIG_TIMER_READS_ITS_FREQUENCY_AT_RUNTIME=y
4 changes: 3 additions & 1 deletion boards/up-bridge-the-gap/up_squared/up_squared_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ CONFIG_X2APIC=y
CONFIG_SMP=y
CONFIG_BUILD_OUTPUT_EFI=y
CONFIG_BUILD_NO_GAP_FILL=y
CONFIG_TIMER_READS_ITS_FREQUENCY_AT_RUNTIME=y

CONFIG_APIC_TSC_DEADLINE_TIMER=n
CONFIG_HPET_TIMER=y
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ CONFIG_X2APIC=y
CONFIG_SMP=y
CONFIG_BUILD_OUTPUT_EFI=y
CONFIG_BUILD_NO_GAP_FILL=y
CONFIG_TIMER_READS_ITS_FREQUENCY_AT_RUNTIME=y
27 changes: 1 addition & 26 deletions drivers/timer/apic_tsc.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,12 @@
#include <zephyr/spinlock.h>
#include <zephyr/drivers/interrupt_controller/loapic.h>
#include <zephyr/irq.h>
#include <cpuid.h>

#define IA32_TSC_DEADLINE_MSR 0x6e0
#define IA32_TSC_ADJUST_MSR 0x03b

#ifdef CONFIG_TIMER_READS_ITS_FREQUENCY_AT_RUNTIME
static uint64_t CYC_PER_TICK;
extern int z_clock_hw_cycles_per_sec;
#else
#define CYC_PER_TICK (CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC \
/ (uint64_t) CONFIG_SYS_CLOCK_TICKS_PER_SEC)
#endif

struct apic_timer_lvt {
uint8_t vector : 8;
Expand Down Expand Up @@ -164,11 +158,9 @@ static inline void cpuid(uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *

static int sys_clock_driver_init(void)
{
#if defined(CONFIG_ASSERT) || defined(CONFIG_TIMER_READS_ITS_FREQUENCY_AT_RUNTIME)
#ifdef CONFIG_ASSERT
uint32_t eax, ebx, ecx, edx;
#endif

#ifdef CONFIG_ASSERT
eax = 1; ecx = 0;
cpuid(&eax, &ebx, &ecx, &edx);
__ASSERT((ecx & BIT(24)) != 0, "No TSC Deadline support");
Expand All @@ -182,23 +174,6 @@ static int sys_clock_driver_init(void)
__ASSERT((ebx & BIT(1)) != 0, "No TSC_ADJUST MSR support");
#endif

#ifdef CONFIG_TIMER_READS_ITS_FREQUENCY_AT_RUNTIME
int tsc_freq;

eax = 0;
ebx = 0;
ecx = 0;
if (!__get_cpuid(0x15, &eax, &ebx, &ecx, &edx)) {
__ASSERT(false, "error cpuid leaf 0x15\n");
}

__ASSERT((ebx != 0) && (ecx != 0), "No TSC/core crystal clock ratio is enumerated");

tsc_freq = (uint32_t)((ecx * (uint64_t)ebx) / eax);
z_clock_hw_cycles_per_sec = tsc_freq;
CYC_PER_TICK = tsc_freq/CONFIG_SYS_CLOCK_TICKS_PER_SEC;
#endif

clear_tsc_adjust();

/* Timer interrupt number is runtime-fetched, so can't use
Expand Down
8 changes: 4 additions & 4 deletions include/zephyr/sys_clock.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ typedef struct {

/** @endcond */

#if defined(CONFIG_SYS_CLOCK_EXISTS) && !defined(CONFIG_TIMER_READS_ITS_FREQUENCY_AT_RUNTIME)
BUILD_ASSERT(CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC != 0,
"SYS_CLOCK_HW_CYCLES_PER_SEC must be non-zero!");
#if defined(CONFIG_SYS_CLOCK_EXISTS) && \
(CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC == 0)
#error "SYS_CLOCK_HW_CYCLES_PER_SEC must be non-zero!"
#endif


Expand All @@ -164,7 +164,7 @@ BUILD_ASSERT(CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC != 0,
* @{
*/

#if defined(CONFIG_SYS_CLOCK_EXISTS) && !defined(CONFIG_TIMER_READS_ITS_FREQUENCY_AT_RUNTIME)
#ifdef CONFIG_SYS_CLOCK_EXISTS

#if defined(CONFIG_TIMER_READS_ITS_FREQUENCY_AT_RUNTIME) || \
(MSEC_PER_SEC % CONFIG_SYS_CLOCK_TICKS_PER_SEC) || \
Expand Down
1 change: 0 additions & 1 deletion kernel/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,6 @@ config SYS_CLOCK_TICKS_PER_SEC

config SYS_CLOCK_HW_CYCLES_PER_SEC
int "System clock's h/w timer frequency"
depends on !TIMER_READS_ITS_FREQUENCY_AT_RUNTIME
help
This option specifies the frequency of the hardware timer used for the
system clock (in Hz). This option is set by the SOC's or board's Kconfig file
Expand Down
2 changes: 1 addition & 1 deletion kernel/timeout.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ static struct k_spinlock timeout_lock;
static int announce_remaining;

#if defined(CONFIG_TIMER_READS_ITS_FREQUENCY_AT_RUNTIME)
int z_clock_hw_cycles_per_sec;
int z_clock_hw_cycles_per_sec = CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC;

#ifdef CONFIG_USERSPACE
static inline int z_vrfy_sys_clock_hw_cycles_per_sec_runtime_get(void)
Expand Down
2 changes: 1 addition & 1 deletion tests/kernel/common/src/boot_delay.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
ZTEST(boot_delay, test_bootdelay)
{
if (sys_clock_hw_cycles_per_sec() > 1000000000) {
if (CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC > 1000000000) {
/* Systems with very fast counters (like the x86 TSC)
* and long firmware startup (often 10+ seconds on a
* EFI PC!) can easily roll this over during startup,
Expand Down
2 changes: 1 addition & 1 deletion tests/kernel/threads/no-multithreading/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
ZTEST(no_multithreading, test_k_busy_wait)
{
int64_t now = k_uptime_get();
uint32_t watchdog = sys_clock_hw_cycles_per_sec();
uint32_t watchdog = CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC;

while (k_uptime_get() != now) {
/* Wait until uptime progresses */
Expand Down