mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-05-02 21:46:58 +00:00
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>
54 lines
920 B
C
54 lines
920 B
C
/*
|
|
* Copyright (C) 2021 Intel Corporation.
|
|
*
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
*/
|
|
|
|
#ifndef COMMON_TICKS_H
|
|
#define COMMON_TICKS_H
|
|
|
|
#include <types.h>
|
|
|
|
#define TICKS_PER_MS us_to_ticks(1000U)
|
|
|
|
/**
|
|
* @brief Read current CPU tick count.
|
|
*
|
|
* @return CPU ticks
|
|
*/
|
|
uint64_t cpu_ticks(void);
|
|
|
|
/**
|
|
* @brief Get CPU tick frequency in KHz.
|
|
*
|
|
* @return CPU frequency (KHz)
|
|
*/
|
|
uint32_t cpu_tickrate(void);
|
|
|
|
/**
|
|
* @brief Convert micro seconds to CPU ticks.
|
|
*
|
|
* @param[in] us micro seconds to convert
|
|
* @return CPU ticks
|
|
*/
|
|
uint64_t us_to_ticks(uint32_t us);
|
|
|
|
/**
|
|
* @brief Convert CPU cycles to micro seconds.
|
|
*
|
|
* @param[in] ticks CPU ticks to convert
|
|
* @return microsecond
|
|
*/
|
|
uint64_t ticks_to_us(uint64_t ticks);
|
|
|
|
/**
|
|
* @brief Convert CPU cycles to milli seconds.
|
|
*
|
|
* @param[in] ticks CPU ticks to convert
|
|
* @return millisecond
|
|
*/
|
|
uint64_t ticks_to_ms(uint64_t ticks);
|
|
|
|
#endif /* COMMON_TICKS_H */
|
|
|