4 #include "qemu-common.h"
5 #include "qemu/notify.h"
6 #include "qemu/host-utils.h"
7 #include "sysemu/cpus.h"
9 #define NANOSECONDS_PER_SECOND 1000000000LL
13 #define SCALE_MS 1000000
20 * The following clock types are available:
22 * @QEMU_CLOCK_REALTIME: Real time clock
24 * The real time clock should be used only for stuff which does not
25 * change the virtual machine state, as it runs even if the virtual
28 * @QEMU_CLOCK_VIRTUAL: virtual clock
30 * The virtual clock only runs during the emulation. It stops
31 * when the virtual machine is stopped.
33 * @QEMU_CLOCK_HOST: host clock
35 * The host clock should be used for device models that emulate accurate
36 * real time sources. It will continue to run when the virtual machine
37 * is suspended, and it will reflect system time changes the host may
38 * undergo (e.g. due to NTP).
40 * @QEMU_CLOCK_VIRTUAL_RT: realtime clock used for icount warp
42 * Outside icount mode, this clock is the same as @QEMU_CLOCK_VIRTUAL.
43 * In icount mode, this clock counts nanoseconds while the virtual
44 * machine is running. It is used to increase @QEMU_CLOCK_VIRTUAL
45 * while the CPUs are sleeping and thus not executing instructions.
49 QEMU_CLOCK_REALTIME
= 0,
50 QEMU_CLOCK_VIRTUAL
= 1,
52 QEMU_CLOCK_VIRTUAL_RT
= 3,
56 typedef struct QEMUTimerList QEMUTimerList
;
58 struct QEMUTimerListGroup
{
59 QEMUTimerList
*tl
[QEMU_CLOCK_MAX
];
62 typedef void QEMUTimerCB(void *opaque
);
63 typedef void QEMUTimerListNotifyCB(void *opaque
);
66 int64_t expire_time
; /* in nanoseconds */
67 QEMUTimerList
*timer_list
;
74 extern QEMUTimerListGroup main_loop_tlg
;
78 * @type: the clock type
80 * Get the nanosecond value of a clock with
83 * Returns: the clock value in nanoseconds
85 int64_t qemu_clock_get_ns(QEMUClockType type
);
89 * @type: the clock type
91 * Get the millisecond value of a clock with
94 * Returns: the clock value in milliseconds
96 static inline int64_t qemu_clock_get_ms(QEMUClockType type
)
98 return qemu_clock_get_ns(type
) / SCALE_MS
;
103 * @type: the clock type
105 * Get the microsecond value of a clock with
108 * Returns: the clock value in microseconds
110 static inline int64_t qemu_clock_get_us(QEMUClockType type
)
112 return qemu_clock_get_ns(type
) / SCALE_US
;
116 * qemu_clock_has_timers:
117 * @type: the clock type
119 * Determines whether a clock's default timer list
120 * has timers attached
122 * Note that this function should not be used when other threads also access
123 * the timer list. The return value may be outdated by the time it is acted
126 * Returns: true if the clock's default timer list
127 * has timers attached
129 bool qemu_clock_has_timers(QEMUClockType type
);
132 * qemu_clock_expired:
133 * @type: the clock type
135 * Determines whether a clock's default timer list
136 * has an expired timer.
138 * Returns: true if the clock's default timer list has
141 bool qemu_clock_expired(QEMUClockType type
);
144 * qemu_clock_use_for_deadline:
145 * @type: the clock type
147 * Determine whether a clock should be used for deadline
148 * calculations. Some clocks, for instance vm_clock with
149 * use_icount set, do not count in nanoseconds. Such clocks
150 * are not used for deadline calculations, and are presumed
151 * to interrupt any poll using qemu_notify/aio_notify
154 * Returns: true if the clock runs in nanoseconds and
155 * should be used for a deadline.
157 bool qemu_clock_use_for_deadline(QEMUClockType type
);
160 * qemu_clock_deadline_ns_all:
161 * @type: the clock type
163 * Calculate the deadline across all timer lists associated
164 * with a clock (as opposed to just the default one)
165 * in nanoseconds, or -1 if no timer is set to expire.
167 * Returns: time until expiry in nanoseconds or -1
169 int64_t qemu_clock_deadline_ns_all(QEMUClockType type
);
172 * qemu_clock_get_main_loop_timerlist:
173 * @type: the clock type
175 * Return the default timer list associated with a clock.
177 * Returns: the default timer list
179 QEMUTimerList
*qemu_clock_get_main_loop_timerlist(QEMUClockType type
);
183 * @type: the clock type
185 * Call the notifier callback connected with the default timer
186 * list linked to the clock, or qemu_notify() if none.
188 void qemu_clock_notify(QEMUClockType type
);
192 * @type: the clock type
193 * @enabled: true to enable, false to disable
195 * Enable or disable a clock
196 * Disabling the clock will wait for related timerlists to stop
197 * executing qemu_run_timers. Thus, this functions should not
198 * be used from the callback of a timer that is based on @clock.
199 * Doing so would cause a deadlock.
201 * Caller should hold BQL.
203 void qemu_clock_enable(QEMUClockType type
, bool enabled
);
206 * qemu_start_warp_timer:
208 * Starts a timer for virtual clock update
210 void qemu_start_warp_timer(void);
213 * qemu_clock_register_reset_notifier:
214 * @type: the clock type
215 * @notifier: the notifier function
217 * Register a notifier function to call when the clock
218 * concerned is reset.
220 void qemu_clock_register_reset_notifier(QEMUClockType type
,
224 * qemu_clock_unregister_reset_notifier:
225 * @type: the clock type
226 * @notifier: the notifier function
228 * Unregister a notifier function to call when the clock
229 * concerned is reset.
231 void qemu_clock_unregister_reset_notifier(QEMUClockType type
,
235 * qemu_clock_run_timers:
236 * @type: clock on which to operate
238 * Run all the timers associated with the default timer list
241 * Returns: true if any timer ran.
243 bool qemu_clock_run_timers(QEMUClockType type
);
246 * qemu_clock_run_all_timers:
248 * Run all the timers associated with the default timer list
251 * Returns: true if any timer ran.
253 bool qemu_clock_run_all_timers(void);
261 * @type: the clock type to associate with the timerlist
262 * @cb: the callback to call on notification
263 * @opaque: the opaque pointer to pass to the callback
265 * Create a new timerlist associated with the clock of
268 * Returns: a pointer to the QEMUTimerList created
270 QEMUTimerList
*timerlist_new(QEMUClockType type
,
271 QEMUTimerListNotifyCB
*cb
, void *opaque
);
275 * @timer_list: the timer list to free
277 * Frees a timer_list. It must have no active timers.
279 void timerlist_free(QEMUTimerList
*timer_list
);
282 * timerlist_has_timers:
283 * @timer_list: the timer list to operate on
285 * Determine whether a timer list has active timers
287 * Note that this function should not be used when other threads also access
288 * the timer list. The return value may be outdated by the time it is acted
291 * Returns: true if the timer list has timers.
293 bool timerlist_has_timers(QEMUTimerList
*timer_list
);
297 * @timer_list: the timer list to operate on
299 * Determine whether a timer list has any timers which
302 * Returns: true if the timer list has timers which
305 bool timerlist_expired(QEMUTimerList
*timer_list
);
308 * timerlist_deadline_ns:
309 * @timer_list: the timer list to operate on
311 * Determine the deadline for a timer_list, i.e.
312 * the number of nanoseconds until the first timer
313 * expires. Return -1 if there are no timers.
315 * Returns: the number of nanoseconds until the earliest
316 * timer expires -1 if none
318 int64_t timerlist_deadline_ns(QEMUTimerList
*timer_list
);
321 * timerlist_get_clock:
322 * @timer_list: the timer list to operate on
324 * Determine the clock type associated with a timer list.
326 * Returns: the clock type associated with the
329 QEMUClockType
timerlist_get_clock(QEMUTimerList
*timer_list
);
332 * timerlist_run_timers:
333 * @timer_list: the timer list to use
335 * Call all expired timers associated with the timer list.
337 * Returns: true if any timer expired
339 bool timerlist_run_timers(QEMUTimerList
*timer_list
);
343 * @timer_list: the timer list to use
345 * call the notifier callback associated with the timer list.
347 void timerlist_notify(QEMUTimerList
*timer_list
);
354 * timerlistgroup_init:
355 * @tlg: the timer list group
356 * @cb: the callback to call when a notify is required
357 * @opaque: the opaque pointer to be passed to the callback.
359 * Initialise a timer list group. This must already be
360 * allocated in memory and zeroed. The notifier callback is
361 * called whenever a clock in the timer list group is
362 * reenabled or whenever a timer associated with any timer
363 * list is modified. If @cb is specified as null, qemu_notify()
366 void timerlistgroup_init(QEMUTimerListGroup
*tlg
,
367 QEMUTimerListNotifyCB
*cb
, void *opaque
);
370 * timerlistgroup_deinit:
371 * @tlg: the timer list group
373 * Deinitialise a timer list group. This must already be
374 * initialised. Note the memory is not freed.
376 void timerlistgroup_deinit(QEMUTimerListGroup
*tlg
);
379 * timerlistgroup_run_timers:
380 * @tlg: the timer list group
382 * Run the timers associated with a timer list group.
383 * This will run timers on multiple clocks.
385 * Returns: true if any timer callback ran
387 bool timerlistgroup_run_timers(QEMUTimerListGroup
*tlg
);
390 * timerlistgroup_deadline_ns:
391 * @tlg: the timer list group
393 * Determine the deadline of the soonest timer to
394 * expire associated with any timer list linked to
395 * the timer list group. Only clocks suitable for
396 * deadline calculation are included.
398 * Returns: the deadline in nanoseconds or -1 if no
399 * timers are to expire.
401 int64_t timerlistgroup_deadline_ns(QEMUTimerListGroup
*tlg
);
409 * @ts: the timer to be initialised
410 * @timer_list: the timer list to attach the timer to
411 * @scale: the scale value for the timer
412 * @cb: the callback to be called when the timer expires
413 * @opaque: the opaque pointer to be passed to the callback
415 * Initialise a new timer and associate it with @timer_list.
416 * The caller is responsible for allocating the memory.
418 * You need not call an explicit deinit call. Simply make
419 * sure it is not on a list with timer_del.
421 void timer_init_tl(QEMUTimer
*ts
,
422 QEMUTimerList
*timer_list
, int scale
,
423 QEMUTimerCB
*cb
, void *opaque
);
427 * @ts: the timer to be initialised
428 * @type: the clock to associate with the timer
429 * @scale: the scale value for the timer
430 * @cb: the callback to call when the timer expires
431 * @opaque: the opaque pointer to pass to the callback
433 * Initialize a timer with the given scale on the default timer list
434 * associated with the clock.
436 * You need not call an explicit deinit call. Simply make
437 * sure it is not on a list with timer_del.
439 static inline void timer_init(QEMUTimer
*ts
, QEMUClockType type
, int scale
,
440 QEMUTimerCB
*cb
, void *opaque
)
442 timer_init_tl(ts
, main_loop_tlg
.tl
[type
], scale
, cb
, opaque
);
447 * @ts: the timer to be initialised
448 * @type: the clock to associate with the timer
449 * @cb: the callback to call when the timer expires
450 * @opaque: the opaque pointer to pass to the callback
452 * Initialize a timer with nanosecond scale on the default timer list
453 * associated with the clock.
455 * You need not call an explicit deinit call. Simply make
456 * sure it is not on a list with timer_del.
458 static inline void timer_init_ns(QEMUTimer
*ts
, QEMUClockType type
,
459 QEMUTimerCB
*cb
, void *opaque
)
461 timer_init(ts
, type
, SCALE_NS
, cb
, opaque
);
466 * @ts: the timer to be initialised
467 * @type: the clock to associate with the timer
468 * @cb: the callback to call when the timer expires
469 * @opaque: the opaque pointer to pass to the callback
471 * Initialize a timer with microsecond scale on the default timer list
472 * associated with the clock.
474 * You need not call an explicit deinit call. Simply make
475 * sure it is not on a list with timer_del.
477 static inline void timer_init_us(QEMUTimer
*ts
, QEMUClockType type
,
478 QEMUTimerCB
*cb
, void *opaque
)
480 timer_init(ts
, type
, SCALE_US
, cb
, opaque
);
485 * @ts: the timer to be initialised
486 * @type: the clock to associate with the timer
487 * @cb: the callback to call when the timer expires
488 * @opaque: the opaque pointer to pass to the callback
490 * Initialize a timer with millisecond scale on the default timer list
491 * associated with the clock.
493 * You need not call an explicit deinit call. Simply make
494 * sure it is not on a list with timer_del.
496 static inline void timer_init_ms(QEMUTimer
*ts
, QEMUClockType type
,
497 QEMUTimerCB
*cb
, void *opaque
)
499 timer_init(ts
, type
, SCALE_MS
, cb
, opaque
);
504 * @timer_list: the timer list to attach the timer to
505 * @scale: the scale value for the timer
506 * @cb: the callback to be called when the timer expires
507 * @opaque: the opaque pointer to be passed to the callback
509 * Create a new timer and associate it with @timer_list.
510 * The memory is allocated by the function.
512 * This is not the preferred interface unless you know you
513 * are going to call timer_free. Use timer_init instead.
515 * Returns: a pointer to the timer
517 static inline QEMUTimer
*timer_new_tl(QEMUTimerList
*timer_list
,
522 QEMUTimer
*ts
= g_malloc0(sizeof(QEMUTimer
));
523 timer_init_tl(ts
, timer_list
, scale
, cb
, opaque
);
529 * @type: the clock type to use
530 * @scale: the scale value for the timer
531 * @cb: the callback to be called when the timer expires
532 * @opaque: the opaque pointer to be passed to the callback
534 * Create a new timer and associate it with the default
535 * timer list for the clock type @type.
537 * Returns: a pointer to the timer
539 static inline QEMUTimer
*timer_new(QEMUClockType type
, int scale
,
540 QEMUTimerCB
*cb
, void *opaque
)
542 return timer_new_tl(main_loop_tlg
.tl
[type
], scale
, cb
, opaque
);
547 * @type: the clock type to associate with the timer
548 * @cb: the callback to call when the timer expires
549 * @opaque: the opaque pointer to pass to the callback
551 * Create a new timer with nanosecond scale on the default timer list
552 * associated with the clock.
554 * Returns: a pointer to the newly created timer
556 static inline QEMUTimer
*timer_new_ns(QEMUClockType type
, QEMUTimerCB
*cb
,
559 return timer_new(type
, SCALE_NS
, cb
, opaque
);
564 * @type: the clock type to associate with the timer
565 * @cb: the callback to call when the timer expires
566 * @opaque: the opaque pointer to pass to the callback
568 * Create a new timer with microsecond scale on the default timer list
569 * associated with the clock.
571 * Returns: a pointer to the newly created timer
573 static inline QEMUTimer
*timer_new_us(QEMUClockType type
, QEMUTimerCB
*cb
,
576 return timer_new(type
, SCALE_US
, cb
, opaque
);
581 * @type: the clock type to associate with the timer
582 * @cb: the callback to call when the timer expires
583 * @opaque: the opaque pointer to pass to the callback
585 * Create a new timer with millisecond scale on the default timer list
586 * associated with the clock.
588 * Returns: a pointer to the newly created timer
590 static inline QEMUTimer
*timer_new_ms(QEMUClockType type
, QEMUTimerCB
*cb
,
593 return timer_new(type
, SCALE_MS
, cb
, opaque
);
598 * @ts: the timer to be de-initialised
600 * Deassociate the timer from any timerlist. You should
601 * call timer_del before. After this call, any further
602 * timer_del call cannot cause dangling pointer accesses
603 * even if the previously used timerlist is freed.
605 void timer_deinit(QEMUTimer
*ts
);
611 * Free a timer (it must not be on the active list)
613 static inline void timer_free(QEMUTimer
*ts
)
622 * Delete a timer from the active list.
624 * This function is thread-safe but the timer and its timer list must not be
625 * freed while this function is running.
627 void timer_del(QEMUTimer
*ts
);
632 * @expire_time: the expiry time in nanoseconds
634 * Modify a timer to expire at @expire_time
636 * This function is thread-safe but the timer and its timer list must not be
637 * freed while this function is running.
639 void timer_mod_ns(QEMUTimer
*ts
, int64_t expire_time
);
642 * timer_mod_anticipate_ns:
644 * @expire_time: the expiry time in nanoseconds
646 * Modify a timer to expire at @expire_time or the current time,
647 * whichever comes earlier.
649 * This function is thread-safe but the timer and its timer list must not be
650 * freed while this function is running.
652 void timer_mod_anticipate_ns(QEMUTimer
*ts
, int64_t expire_time
);
657 * @expire_time: the expire time in the units associated with the timer
659 * Modify a timer to expiry at @expire_time, taking into
660 * account the scale associated with the timer.
662 * This function is thread-safe but the timer and its timer list must not be
663 * freed while this function is running.
665 void timer_mod(QEMUTimer
*ts
, int64_t expire_timer
);
668 * timer_mod_anticipate:
670 * @expire_time: the expiry time in nanoseconds
672 * Modify a timer to expire at @expire_time or the current time, whichever
673 * comes earlier, taking into account the scale associated with the timer.
675 * This function is thread-safe but the timer and its timer list must not be
676 * freed while this function is running.
678 void timer_mod_anticipate(QEMUTimer
*ts
, int64_t expire_time
);
684 * Determines whether a timer is pending (i.e. is on the
685 * active list of timers, whether or not it has not yet expired).
687 * Returns: true if the timer is pending
689 bool timer_pending(QEMUTimer
*ts
);
694 * @current_time: the current time
696 * Determines whether a timer has expired.
698 * Returns: true if the timer has expired
700 bool timer_expired(QEMUTimer
*timer_head
, int64_t current_time
);
703 * timer_expire_time_ns:
706 * Determine the expiry time of a timer
708 * Returns: the expiry time in nanoseconds
710 uint64_t timer_expire_time_ns(QEMUTimer
*ts
);
717 * Read a timer @ts from a file @f
719 void timer_get(QEMUFile
*f
, QEMUTimer
*ts
);
726 void timer_put(QEMUFile
*f
, QEMUTimer
*ts
);
729 * General utility functions
733 * qemu_timeout_ns_to_ms:
734 * @ns: nanosecond timeout value
736 * Convert a nanosecond timeout value (or -1) to
737 * a millisecond value (or -1), always rounding up.
739 * Returns: millisecond timeout value
741 int qemu_timeout_ns_to_ms(int64_t ns
);
745 * @fds: Array of file descriptors
746 * @nfds: number of file descriptors
747 * @timeout: timeout in nanoseconds
749 * Perform a poll like g_poll but with a timeout in nanoseconds.
750 * See g_poll documentation for further details.
752 * Returns: number of fds ready
754 int qemu_poll_ns(GPollFD
*fds
, guint nfds
, int64_t timeout
);
757 * qemu_soonest_timeout:
758 * @timeout1: first timeout in nanoseconds (or -1 for infinite)
759 * @timeout2: second timeout in nanoseconds (or -1 for infinite)
761 * Calculates the soonest of two timeout values. -1 means infinite, which
762 * is later than any other value.
764 * Returns: soonest timeout value in nanoseconds (or -1 for infinite)
766 static inline int64_t qemu_soonest_timeout(int64_t timeout1
, int64_t timeout2
)
768 /* we can abuse the fact that -1 (which means infinite) is a maximal
769 * value when cast to unsigned. As this is disgusting, it's kept in
770 * one inline function.
772 return ((uint64_t) timeout1
< (uint64_t) timeout2
) ? timeout1
: timeout2
;
778 * Initialise the clock & timer infrastructure
780 void init_clocks(void);
782 int64_t cpu_get_ticks(void);
783 /* Caller must hold BQL */
784 void cpu_enable_ticks(void);
785 /* Caller must hold BQL */
786 void cpu_disable_ticks(void);
788 static inline int64_t get_max_clock_jump(void)
790 /* This should be small enough to prevent excessive interrupts from being
791 * generated by the RTC on clock jumps, but large enough to avoid frequent
792 * unnecessary resets in idle VMs.
794 return 60 * NANOSECONDS_PER_SECOND
;
798 * Low level clock functions
801 /* get host real time in nanosecond */
802 static inline int64_t get_clock_realtime(void)
806 gettimeofday(&tv
, NULL
);
807 return tv
.tv_sec
* 1000000000LL + (tv
.tv_usec
* 1000);
810 /* Warning: don't insert tracepoints into these functions, they are
811 also used by simpletrace backend and tracepoints would cause
812 an infinite recursion! */
814 extern int64_t clock_freq
;
816 static inline int64_t get_clock(void)
819 QueryPerformanceCounter(&ti
);
820 return muldiv64(ti
.QuadPart
, NANOSECONDS_PER_SECOND
, clock_freq
);
825 extern int use_rt_clock
;
827 static inline int64_t get_clock(void)
829 #ifdef CLOCK_MONOTONIC
832 clock_gettime(CLOCK_MONOTONIC
, &ts
);
833 return ts
.tv_sec
* 1000000000LL + ts
.tv_nsec
;
837 /* XXX: using gettimeofday leads to problems if the date
838 changes, so it should be avoided. */
839 return get_clock_realtime();
845 int64_t cpu_get_icount_raw(void);
846 int64_t cpu_get_icount(void);
847 int64_t cpu_get_clock(void);
848 int64_t cpu_icount_to_ns(int64_t icount
);
850 /*******************************************/
851 /* host CPU ticks (if available) */
853 #if defined(_ARCH_PPC)
855 static inline int64_t cpu_get_host_ticks(void)
859 /* This reads timebase in one 64bit go and includes Cell workaround from:
860 http://ozlabs.org/pipermail/linuxppc-dev/2006-October/027052.html
862 __asm__
__volatile__ ("mftb %0\n\t"
867 /* http://ozlabs.org/pipermail/linuxppc-dev/1999-October/003889.html */
869 __asm__
__volatile__ ("mfspr %1,269\n\t" /* mftbu */
870 "mfspr %L0,268\n\t" /* mftb */
871 "mfspr %0,269\n\t" /* mftbu */
874 : "=r" (retval
), "=r" (junk
));
879 #elif defined(__i386__)
881 static inline int64_t cpu_get_host_ticks(void)
884 asm volatile ("rdtsc" : "=A" (val
));
888 #elif defined(__x86_64__)
890 static inline int64_t cpu_get_host_ticks(void)
894 asm volatile("rdtsc" : "=a" (low
), "=d" (high
));
901 #elif defined(__hppa__)
903 static inline int64_t cpu_get_host_ticks(void)
906 asm volatile ("mfctl %%cr16, %0" : "=r"(val
));
910 #elif defined(__ia64)
912 static inline int64_t cpu_get_host_ticks(void)
915 asm volatile ("mov %0 = ar.itc" : "=r"(val
) :: "memory");
919 #elif defined(__s390__)
921 static inline int64_t cpu_get_host_ticks(void)
924 asm volatile("stck 0(%1)" : "=m" (val
) : "a" (&val
) : "cc");
928 #elif defined(__sparc__)
930 static inline int64_t cpu_get_host_ticks (void)
934 asm volatile("rd %%tick,%0" : "=r"(rval
));
937 /* We need an %o or %g register for this. For recent enough gcc
938 there is an "h" constraint for that. Don't bother with that. */
946 asm volatile("rd %%tick,%%g1; srlx %%g1,32,%0; mov %%g1,%1"
947 : "=r"(rval
.i32
.high
), "=r"(rval
.i32
.low
) : : "g1");
952 #elif defined(__mips__) && \
953 ((defined(__mips_isa_rev) && __mips_isa_rev >= 2) || defined(__linux__))
955 * binutils wants to use rdhwr only on mips32r2
956 * but as linux kernel emulate it, it's fine
960 #define MIPS_RDHWR(rd, value) { \
961 __asm__ __volatile__ (".set push\n\t" \
962 ".set mips32r2\n\t" \
963 "rdhwr %0, "rd"\n\t" \
968 static inline int64_t cpu_get_host_ticks(void)
970 /* On kernels >= 2.6.25 rdhwr <reg>, $2 and $3 are emulated */
972 static uint32_t cyc_per_count
= 0;
974 if (!cyc_per_count
) {
975 MIPS_RDHWR("$3", cyc_per_count
);
978 MIPS_RDHWR("$2", count
);
979 return (int64_t)(count
* cyc_per_count
);
982 #elif defined(__alpha__)
984 static inline int64_t cpu_get_host_ticks(void)
989 asm volatile("rpcc %0" : "=r"(cc
));
996 /* The host CPU doesn't have an easily accessible cycle counter.
997 Just return a monotonically increasing value. This will be
998 totally wrong, but hopefully better than nothing. */
999 static inline int64_t cpu_get_host_ticks (void)
1001 static int64_t ticks
= 0;
1006 #ifdef CONFIG_PROFILER
1007 static inline int64_t profile_getclock(void)
1012 extern int64_t tcg_time
;
1013 extern int64_t dev_time
;