Merge tag 'pull-request-2024-06-12' of https://gitlab.com/thuth/qemu into staging
[qemu/kevin.git] / include / sysemu / cpu-timers.h
blobd86738a378dbe9db6b8a78493f6d1fb255471e51
1 /*
2 * CPU timers state API
4 * Copyright 2020 SUSE LLC
6 * This work is licensed under the terms of the GNU GPL, version 2 or later.
7 * See the COPYING file in the top-level directory.
9 */
10 #ifndef SYSEMU_CPU_TIMERS_H
11 #define SYSEMU_CPU_TIMERS_H
13 #include "qemu/timer.h"
15 /* init the whole cpu timers API, including icount, ticks, and cpu_throttle */
16 void cpu_timers_init(void);
18 /* icount - Instruction Counter API */
20 /**
21 * ICountMode: icount enablement state:
23 * @ICOUNT_DISABLED: Disabled - Do not count executed instructions.
24 * @ICOUNT_PRECISE: Enabled - Fixed conversion of insn to ns via "shift" option
25 * @ICOUNT_ADAPTATIVE: Enabled - Runtime adaptive algorithm to compute shift
27 typedef enum {
28 ICOUNT_DISABLED = 0,
29 ICOUNT_PRECISE,
30 ICOUNT_ADAPTATIVE,
31 } ICountMode;
33 #if defined(CONFIG_TCG) && !defined(CONFIG_USER_ONLY)
34 extern ICountMode use_icount;
35 #define icount_enabled() (use_icount)
36 #else
37 #define icount_enabled() ICOUNT_DISABLED
38 #endif
41 * Update the icount with the executed instructions. Called by
42 * cpus-tcg vCPU thread so the main-loop can see time has moved forward.
44 void icount_update(CPUState *cpu);
46 /* get raw icount value */
47 int64_t icount_get_raw(void);
49 /* return the virtual CPU time in ns, based on the instruction counter. */
50 int64_t icount_get(void);
52 * convert an instruction counter value to ns, based on the icount shift.
53 * This shift is set as a fixed value with the icount "shift" option
54 * (precise mode), or it is constantly approximated and corrected at
55 * runtime in adaptive mode.
57 int64_t icount_to_ns(int64_t icount);
59 /**
60 * icount_configure: configure the icount options, including "shift"
61 * @opts: Options to parse
62 * @errp: pointer to a NULL-initialized error object
64 * Return: true on success, else false setting @errp with error
66 bool icount_configure(QemuOpts *opts, Error **errp);
68 /* used by tcg vcpu thread to calc icount budget */
69 int64_t icount_round(int64_t count);
71 /* if the CPUs are idle, start accounting real time to virtual clock. */
72 void icount_start_warp_timer(void);
73 void icount_account_warp_timer(void);
74 void icount_notify_exit(void);
77 * CPU Ticks and Clock
80 /* Caller must hold BQL */
81 void cpu_enable_ticks(void);
82 /* Caller must hold BQL */
83 void cpu_disable_ticks(void);
86 * return the time elapsed in VM between vm_start and vm_stop.
87 * cpu_get_ticks() uses units of the host CPU cycle counter.
89 int64_t cpu_get_ticks(void);
92 * Returns the monotonic time elapsed in VM, i.e.,
93 * the time between vm_start and vm_stop
95 int64_t cpu_get_clock(void);
97 void qemu_timer_notify_cb(void *opaque, QEMUClockType type);
99 /* get the VIRTUAL clock and VM elapsed ticks via the cpus accel interface */
100 int64_t cpus_get_virtual_clock(void);
101 int64_t cpus_get_elapsed_ticks(void);
103 #endif /* SYSEMU_CPU_TIMERS_H */