aboutsummaryrefslogtreecommitdiff
path: root/include/sysemu/cpu-timers.h
blob: 4b621fea51ab8ed484ab0dcf662a3a817fb2826f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
 * 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 */

/*
 * icount enablement state:
 *
 * 0 = Disabled - Do not count executed instructions.
 * 1 = Enabled - Fixed conversion of insn to ns via "shift" option
 * 2 = Enabled - Runtime adaptive algorithm to compute shift
 */
#ifdef CONFIG_TCG
extern int use_icount;
#define icount_enabled() (use_icount)
#else
#define icount_enabled() 0
#endif

/*
 * Update the icount with the executed instructions. Called by
 * cpus-tcg vCPU thread so the main-loop can see time has moved forward.
 */
void cpu_update_icount(CPUState *cpu);

/* get raw icount value */
int64_t cpu_get_icount_raw(void);

/* return the virtual CPU time in ns, based on the instruction counter. */
int64_t cpu_get_icount(void);
/*
 * 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.
 */
int64_t cpu_icount_to_ns(int64_t icount);

/* configure the icount options, including "shift" */
void configure_icount(QemuOpts *opts, Error **errp);

/* used by tcg vcpu thread to calc icount budget */
int64_t qemu_icount_round(int64_t count);

/* if the CPUs are idle, start accounting real time to virtual clock. */
void qemu_start_warp_timer(void);
void qemu_account_warp_timer(void);

/*
 * CPU Ticks and Clock
 */

/* Caller must hold BQL */
void cpu_enable_ticks(void);
/* Caller must hold BQL */
void cpu_disable_ticks(void);

/*
 * return the time elapsed in VM between vm_start and vm_stop.  Unless
 * icount is active, cpu_get_ticks() uses units of the host CPU cycle
 * counter.
 */
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);

#endif /* SYSEMU_CPU_TIMERS_H */