xref: /qemu/include/sysemu/cpu-timers-internal.h (revision ce32a9e9)
1 /*
2  * QEMU System Emulator
3  *
4  * Copyright (c) 2003-2008 Fabrice Bellard
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  */
24 
25 #ifndef TIMERS_STATE_H
26 #define TIMERS_STATE_H
27 
28 /* timers state, for sharing between icount and cpu-timers */
29 
30 typedef struct TimersState {
31     /* Protected by BQL.  */
32     int64_t cpu_ticks_prev;
33     int64_t cpu_ticks_offset;
34 
35     /*
36      * Protect fields that can be respectively read outside the
37      * BQL, and written from multiple threads.
38      */
39     QemuSeqLock vm_clock_seqlock;
40     QemuSpin vm_clock_lock;
41 
42     int16_t cpu_ticks_enabled;
43 
44     /* Conversion factor from emulated instructions to virtual clock ticks.  */
45     int16_t icount_time_shift;
46     /* Icount delta used for shift auto adjust. */
47     int64_t last_delta;
48 
49     /* Compensate for varying guest execution speed.  */
50     aligned_int64_t qemu_icount_bias;
51 
52     int64_t vm_clock_warp_start;
53     int64_t cpu_clock_offset;
54 
55     /* Only written by TCG thread */
56     int64_t qemu_icount;
57 
58     /* for adjusting icount */
59     QEMUTimer *icount_rt_timer;
60     QEMUTimer *icount_vm_timer;
61     QEMUTimer *icount_warp_timer;
62 } TimersState;
63 
64 extern TimersState timers_state;
65 
66 /*
67  * icount needs this internal from cpu-timers when adjusting the icount shift.
68  */
69 int64_t cpu_get_clock_locked(void);
70 
71 #endif /* TIMERS_STATE_H */
72