2020-08-19 14:17:19 +03:00
|
|
|
/*
|
|
|
|
* CPU timers state API
|
|
|
|
*
|
|
|
|
* Copyright 2020 SUSE LLC
|
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
|
|
|
* See the COPYING file in the top-level directory.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#ifndef SYSEMU_CPU_TIMERS_H
|
|
|
|
#define SYSEMU_CPU_TIMERS_H
|
|
|
|
|
|
|
|
#include "qemu/timer.h"
|
|
|
|
|
|
|
|
/* init the whole cpu timers API, including icount, ticks, and cpu_throttle */
|
|
|
|
void cpu_timers_init(void);
|
|
|
|
|
|
|
|
/* icount - Instruction Counter API */
|
|
|
|
|
2023-12-08 14:35:25 +03:00
|
|
|
/**
|
|
|
|
* ICountMode: icount enablement state:
|
2020-08-19 14:17:19 +03:00
|
|
|
*
|
2023-12-08 14:35:25 +03:00
|
|
|
* @ICOUNT_DISABLED: Disabled - Do not count executed instructions.
|
|
|
|
* @ICOUNT_PRECISE: Enabled - Fixed conversion of insn to ns via "shift" option
|
|
|
|
* @ICOUNT_ADAPTATIVE: Enabled - Runtime adaptive algorithm to compute shift
|
2020-08-19 14:17:19 +03:00
|
|
|
*/
|
2023-12-08 14:35:25 +03:00
|
|
|
typedef enum {
|
|
|
|
ICOUNT_DISABLED = 0,
|
|
|
|
ICOUNT_PRECISE,
|
|
|
|
ICOUNT_ADAPTATIVE,
|
|
|
|
} ICountMode;
|
|
|
|
|
2024-01-06 02:23:37 +03:00
|
|
|
#if defined(CONFIG_TCG) && !defined(CONFIG_USER_ONLY)
|
2023-12-08 14:35:25 +03:00
|
|
|
extern ICountMode use_icount;
|
2020-08-19 14:17:19 +03:00
|
|
|
#define icount_enabled() (use_icount)
|
|
|
|
#else
|
2023-12-08 14:35:25 +03:00
|
|
|
#define icount_enabled() ICOUNT_DISABLED
|
2020-08-19 14:17:19 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Update the icount with the executed instructions. Called by
|
|
|
|
* cpus-tcg vCPU thread so the main-loop can see time has moved forward.
|
|
|
|
*/
|
2020-08-31 17:18:34 +03:00
|
|
|
void icount_update(CPUState *cpu);
|
2020-08-19 14:17:19 +03:00
|
|
|
|
|
|
|
/* get raw icount value */
|
2020-08-31 17:18:34 +03:00
|
|
|
int64_t icount_get_raw(void);
|
2020-08-19 14:17:19 +03:00
|
|
|
|
|
|
|
/* return the virtual CPU time in ns, based on the instruction counter. */
|
2020-08-31 17:18:34 +03:00
|
|
|
int64_t icount_get(void);
|
2020-08-19 14:17:19 +03:00
|
|
|
/*
|
|
|
|
* convert an instruction counter value to ns, based on the icount shift.
|
|
|
|
* This shift is set as a fixed value with the icount "shift" option
|
|
|
|
* (precise mode), or it is constantly approximated and corrected at
|
|
|
|
* runtime in adaptive mode.
|
|
|
|
*/
|
2020-08-31 17:18:34 +03:00
|
|
|
int64_t icount_to_ns(int64_t icount);
|
2020-08-19 14:17:19 +03:00
|
|
|
|
2023-12-08 14:35:23 +03:00
|
|
|
/**
|
|
|
|
* icount_configure: configure the icount options, including "shift"
|
|
|
|
* @opts: Options to parse
|
|
|
|
* @errp: pointer to a NULL-initialized error object
|
|
|
|
*
|
|
|
|
* Return: true on success, else false setting @errp with error
|
|
|
|
*/
|
|
|
|
bool icount_configure(QemuOpts *opts, Error **errp);
|
2020-08-19 14:17:19 +03:00
|
|
|
|
|
|
|
/* used by tcg vcpu thread to calc icount budget */
|
2020-08-31 17:18:34 +03:00
|
|
|
int64_t icount_round(int64_t count);
|
2020-08-19 14:17:19 +03:00
|
|
|
|
|
|
|
/* if the CPUs are idle, start accounting real time to virtual clock. */
|
2020-08-31 17:18:34 +03:00
|
|
|
void icount_start_warp_timer(void);
|
|
|
|
void icount_account_warp_timer(void);
|
2022-05-27 13:46:13 +03:00
|
|
|
void icount_notify_exit(void);
|
2020-08-19 14:17:19 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* CPU Ticks and Clock
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Caller must hold BQL */
|
|
|
|
void cpu_enable_ticks(void);
|
|
|
|
/* Caller must hold BQL */
|
|
|
|
void cpu_disable_ticks(void);
|
|
|
|
|
|
|
|
/*
|
2020-07-31 13:23:42 +03:00
|
|
|
* return the time elapsed in VM between vm_start and vm_stop.
|
|
|
|
* cpu_get_ticks() uses units of the host CPU cycle counter.
|
2020-08-19 14:17:19 +03:00
|
|
|
*/
|
|
|
|
int64_t cpu_get_ticks(void);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Returns the monotonic time elapsed in VM, i.e.,
|
|
|
|
* the time between vm_start and vm_stop
|
|
|
|
*/
|
|
|
|
int64_t cpu_get_clock(void);
|
|
|
|
|
|
|
|
void qemu_timer_notify_cb(void *opaque, QEMUClockType type);
|
|
|
|
|
2020-07-31 13:23:42 +03:00
|
|
|
/* get the VIRTUAL clock and VM elapsed ticks via the cpus accel interface */
|
|
|
|
int64_t cpus_get_virtual_clock(void);
|
|
|
|
int64_t cpus_get_elapsed_ticks(void);
|
|
|
|
|
2020-08-19 14:17:19 +03:00
|
|
|
#endif /* SYSEMU_CPU_TIMERS_H */
|