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:
Liang Yi
2021-04-08 17:36:12 +08:00
committed by wenlingz
parent c2df3f7940
commit 5a2b89b0a4
23 changed files with 301 additions and 209 deletions

View File

@@ -9,6 +9,7 @@
#include <uart16550.h>
#include <shell.h>
#include <asm/timer.h>
#include <ticks.h>
#include <vuart.h>
#include <logmsg.h>
#include <acrn_hv_defs.h>
@@ -161,8 +162,8 @@ void console_setup_timer(void)
{
uint64_t period_in_cycle, fire_tsc;
period_in_cycle = CYCLES_PER_MS * CONSOLE_KICK_TIMER_TIMEOUT;
fire_tsc = rdtsc() + period_in_cycle;
period_in_cycle = TICKS_PER_MS * CONSOLE_KICK_TIMER_TIMEOUT;
fire_tsc = cpu_ticks() + period_in_cycle;
initialize_timer(&console_timer,
console_timer_callback, NULL,
fire_tsc, TICK_MODE_PERIODIC, period_in_cycle);

View File

@@ -11,6 +11,7 @@
#include <asm/per_cpu.h>
#include <npk_log.h>
#include <logmsg.h>
#include <ticks.h>
/* buf size should be identical to the size in hvlog option, which is
* transfered to SOS:
@@ -53,7 +54,7 @@ void do_logmsg(uint32_t severity, const char *fmt, ...)
}
/* Get time-stamp value */
timestamp = rdtsc();
timestamp = cpu_ticks();
/* Scale time-stamp appropriately */
timestamp = ticks_to_us(timestamp);

View File

@@ -15,6 +15,7 @@
#include <asm/guest/vm.h>
#include <sprintf.h>
#include <logmsg.h>
#include <ticks.h>
#define DBG_LEVEL_PROFILING 5U
#define DBG_LEVEL_ERR_PROFILING 3U
@@ -339,7 +340,7 @@ static int32_t profiling_generate_data(int32_t collector, uint32_t type)
clac();
/* populate the data header */
pkt_header.tsc = rdtsc();
pkt_header.tsc = cpu_ticks();
pkt_header.collector_id = collector;
pkt_header.cpu_id = get_pcpu_id();
pkt_header.data_type = 1U << type;
@@ -411,7 +412,7 @@ static int32_t profiling_generate_data(int32_t collector, uint32_t type)
clac();
/* populate the data header */
pkt_header.tsc = rdtsc();
pkt_header.tsc = cpu_ticks();
pkt_header.collector_id = collector;
pkt_header.cpu_id = get_pcpu_id();
pkt_header.data_type = (uint16_t)type;
@@ -1307,7 +1308,7 @@ void profiling_vmenter_handler(__unused struct acrn_vcpu *vcpu)
((socwatch_collection_switch &
(1UL << (uint64_t)SOCWATCH_VM_SWITCH_TRACING)) > 0UL))) {
get_cpu_var(profiling_info.vm_info).vmenter_tsc = rdtsc();
get_cpu_var(profiling_info.vm_info).vmenter_tsc = cpu_ticks();
}
}
@@ -1323,7 +1324,7 @@ void profiling_pre_vmexit_handler(struct acrn_vcpu *vcpu)
if ((get_cpu_var(profiling_info.s_state).pmu_state == PMU_RUNNING) ||
(get_cpu_var(profiling_info.soc_state) == SW_RUNNING)) {
get_cpu_var(profiling_info.vm_info).vmexit_tsc = rdtsc();
get_cpu_var(profiling_info.vm_info).vmexit_tsc = cpu_ticks();
get_cpu_var(profiling_info.vm_info).vmexit_reason
= exit_reason;
if (exit_reason == VMX_EXIT_REASON_EXTERNAL_INTERRUPT) {

View File

@@ -6,6 +6,7 @@
#include <types.h>
#include <asm/per_cpu.h>
#include <ticks.h>
#include <trace.h>
#define TRACE_CUSTOM 0xFCU
@@ -51,7 +52,7 @@ static inline void trace_put(uint16_t cpu_id, uint32_t evid, uint32_t n_data, st
{
struct shared_buf *sbuf = per_cpu(sbuf, cpu_id)[ACRN_TRACE];
entry->tsc = rdtsc();
entry->tsc = cpu_ticks();
entry->id = evid;
entry->n_data = (uint8_t)n_data;
entry->cpu = (uint8_t)cpu_id;