mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-09-22 17:27:53 +00:00
hv/mod_timer: split tsc handling code from timer.
Generalize and split basic cpu cycle/tick routines from x86/timer: - Instead of rdstc(), use cpu_ticks() in generic code. - Instead of get_tsc_khz(), use cpu_tickrate() in generic code. - Include "common/ticks.h" instead of "x86/timer.h" in generic code. - CYCLES_PER_MS is renamed to TICKS_PER_MS. The x86 specific API rdstc() and get_tsc_khz(), as well as TSC_PER_MS are still available in arch/x86/tsc.h but only for x86 specific usage. Tracked-On: #5920 Signed-off-by: Rong Liu <rong2.liu@intel.com> Signed-off-by: Yi Liang <yi.liang@intel.com>
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
#define TIMER_H
|
||||
|
||||
#include <list.h>
|
||||
#include <asm/tsc.h>
|
||||
|
||||
/**
|
||||
* @brief Timer
|
||||
@@ -47,38 +48,8 @@ struct hv_timer {
|
||||
|
||||
/* External Interfaces */
|
||||
|
||||
#define CYCLES_PER_MS us_to_ticks(1000U)
|
||||
|
||||
void udelay(uint32_t us);
|
||||
|
||||
/**
|
||||
* @brief convert us to ticks.
|
||||
*
|
||||
* @return ticks
|
||||
*/
|
||||
uint64_t us_to_ticks(uint32_t us);
|
||||
|
||||
/**
|
||||
* @brief convert ticks to us.
|
||||
*
|
||||
* @return microsecond
|
||||
*/
|
||||
uint64_t ticks_to_us(uint64_t ticks);
|
||||
|
||||
/**
|
||||
* @brief convert ticks to ms.
|
||||
*
|
||||
* @return millisecond
|
||||
*/
|
||||
uint64_t ticks_to_ms(uint64_t ticks);
|
||||
|
||||
/**
|
||||
* @brief read tsc.
|
||||
*
|
||||
* @return tsc value
|
||||
*/
|
||||
uint64_t rdtsc(void);
|
||||
|
||||
/**
|
||||
* @brief Initialize a timer structure.
|
||||
*
|
||||
@@ -162,20 +133,6 @@ void del_timer(struct hv_timer *timer);
|
||||
*/
|
||||
void timer_init(void);
|
||||
|
||||
/**
|
||||
* @brief Calibrate tsc.
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
void calibrate_tsc(void);
|
||||
|
||||
/**
|
||||
* @brief Get tsc.
|
||||
*
|
||||
* @return tsc(KHz)
|
||||
*/
|
||||
uint32_t get_tsc_khz(void);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
41
hypervisor/include/arch/x86/asm/tsc.h
Normal file
41
hypervisor/include/arch/x86/asm/tsc.h
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
void calibrate_tsc(void);
|
||||
|
||||
#endif /* ARCH_X86_TSC_H */
|
Reference in New Issue
Block a user