2021-04-08 17:36:12 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2021 Intel Corporation.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef ARCH_X86_TSC_H
|
|
|
|
#define ARCH_X86_TSC_H
|
|
|
|
|
|
|
|
#include <types.h>
|
|
|
|
|
|
|
|
#define TSC_PER_MS ((uint64_t)get_tsc_khz())
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Read Time Stamp Counter (TSC).
|
|
|
|
*
|
|
|
|
* @return TSC value
|
|
|
|
*/
|
|
|
|
static inline uint64_t rdtsc(void)
|
|
|
|
{
|
|
|
|
uint32_t lo, hi;
|
|
|
|
|
|
|
|
asm volatile("rdtsc" : "=a" (lo), "=d" (hi));
|
|
|
|
return ((uint64_t)hi << 32U) | lo;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Get Time Stamp Counter (TSC) frequency in KHz.
|
|
|
|
*
|
|
|
|
* @return TSC frequency in KHz
|
|
|
|
*/
|
|
|
|
uint32_t get_tsc_khz(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Calibrate Time Stamp Counter (TSC) frequency.
|
|
|
|
*
|
2021-05-31 11:10:02 +08:00
|
|
|
* @remark Generic time related routines, e.g., cpu_tickrate(), us_to_ticks(),
|
|
|
|
* udelay(), etc., relies on this function being called earlier during system initialization.
|
|
|
|
*
|
2021-04-08 17:36:12 +08:00
|
|
|
* @return None
|
|
|
|
*/
|
|
|
|
void calibrate_tsc(void);
|
|
|
|
|
|
|
|
#endif /* ARCH_X86_TSC_H */
|