mirror of
				https://github.com/projectacrn/acrn-hypervisor.git
				synced 2025-11-04 03:28:59 +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>
		
			
				
	
	
		
			32 lines
		
	
	
		
			550 B
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			32 lines
		
	
	
		
			550 B
		
	
	
	
		
			C
		
	
	
	
	
	
/*
 | 
						|
 * Copyright (C) 2021 Intel Corporation.
 | 
						|
 *
 | 
						|
 * SPDX-License-Identifier: BSD-3-Clause
 | 
						|
 */
 | 
						|
 | 
						|
#include <common/ticks.h>
 | 
						|
 | 
						|
/* cpu_ticks() and cpu_tickrate() are provided in arch specific modules */
 | 
						|
 | 
						|
uint64_t us_to_ticks(uint32_t us)
 | 
						|
{
 | 
						|
	return (((uint64_t)us * (uint64_t)cpu_tickrate()) / 1000UL);
 | 
						|
}
 | 
						|
 | 
						|
uint64_t ticks_to_us(uint64_t ticks)
 | 
						|
{
 | 
						|
	uint64_t us = 0UL;
 | 
						|
	uint64_t khz = cpu_tickrate();
 | 
						|
 | 
						|
	if (khz != 0U) {
 | 
						|
		us = (ticks * 1000UL) / (uint64_t)khz;
 | 
						|
	}
 | 
						|
 | 
						|
	return us;
 | 
						|
}
 | 
						|
 | 
						|
uint64_t ticks_to_ms(uint64_t ticks)
 | 
						|
{
 | 
						|
	return ticks / (uint64_t)cpu_tickrate();
 | 
						|
}
 |