4 #include "qemu-common.h"
5 #include "qemu/notify.h"
6 #include "qemu/host-utils.h"
8 #define NANOSECONDS_PER_SECOND 1000000000LL
12 #define SCALE_MS 1000000
19 * The following clock types are available:
21 * @QEMU_CLOCK_REALTIME: Real time clock
23 * The real time clock should be used only for stuff which does not
24 * change the virtual machine state, as it runs even if the virtual
27 * @QEMU_CLOCK_VIRTUAL: virtual clock
29 * The virtual clock only runs during the emulation. It stops
30 * when the virtual machine is stopped.
32 * @QEMU_CLOCK_HOST: host clock
34 * The host clock should be used for device models that emulate accurate
35 * real time sources. It will continue to run when the virtual machine
36 * is suspended, and it will reflect system time changes the host may
37 * undergo (e.g. due to NTP).
39 * @QEMU_CLOCK_VIRTUAL_RT: realtime clock used for icount warp
41 * Outside icount mode, this clock is the same as @QEMU_CLOCK_VIRTUAL.
42 * In icount mode, this clock counts nanoseconds while the virtual
43 * machine is running. It is used to increase @QEMU_CLOCK_VIRTUAL
44 * while the CPUs are sleeping and thus not executing instructions.
48 QEMU_CLOCK_REALTIME
= 0,
49 QEMU_CLOCK_VIRTUAL
= 1,
51 QEMU_CLOCK_VIRTUAL_RT
= 3,
55 typedef struct QEMUTimerList QEMUTimerList
;
57 struct QEMUTimerListGroup
{
58 QEMUTimerList
*tl
[QEMU_CLOCK_MAX
];
61 typedef void QEMUTimerCB(void *opaque
);
62 typedef void QEMUTimerListNotifyCB(void *opaque
, QEMUClockType type
);
65 int64_t expire_time
; /* in nanoseconds */
66 QEMUTimerList
*timer_list
;
73 extern QEMUTimerListGroup main_loop_tlg
;
77 * @type: the clock type
79 * Get the nanosecond value of a clock with
82 * Returns: the clock value in nanoseconds
84 int64_t qemu_clock_get_ns(QEMUClockType type
);
88 * @type: the clock type
90 * Get the millisecond value of a clock with
93 * Returns: the clock value in milliseconds
95 static inline int64_t qemu_clock_get_ms(QEMUClockType type
)
97 return qemu_clock_get_ns(type
) / SCALE_MS
;
102 * @type: the clock type
104 * Get the microsecond value of a clock with
107 * Returns: the clock value in microseconds
109 static inline int64_t qemu_clock_get_us(QEMUClockType type
)
111 return qemu_clock_get_ns(type
) / SCALE_US
;
115 * qemu_clock_has_timers:
116 * @type: the clock type
118 * Determines whether a clock's default timer list
119 * has timers attached
121 * Note that this function should not be used when other threads also access
122 * the timer list. The return value may be outdated by the time it is acted
125 * Returns: true if the clock's default timer list
126 * has timers attached
128 bool qemu_clock_has_timers(QEMUClockType type
);
131 * qemu_clock_expired:
132 * @type: the clock type
134 * Determines whether a clock's default timer list
135 * has an expired timer.
137 * Returns: true if the clock's default timer list has
140 bool qemu_clock_expired(QEMUClockType type
);
143 * qemu_clock_use_for_deadline:
144 * @type: the clock type
146 * Determine whether a clock should be used for deadline
147 * calculations. Some clocks, for instance vm_clock with
148 * use_icount set, do not count in nanoseconds. Such clocks
149 * are not used for deadline calculations, and are presumed
150 * to interrupt any poll using qemu_notify/aio_notify
153 * Returns: true if the clock runs in nanoseconds and
154 * should be used for a deadline.
156 bool qemu_clock_use_for_deadline(QEMUClockType type
);
159 * qemu_clock_deadline_ns_all:
160 * @type: the clock type
162 * Calculate the deadline across all timer lists associated
163 * with a clock (as opposed to just the default one)
164 * in nanoseconds, or -1 if no timer is set to expire.
166 * Returns: time until expiry in nanoseconds or -1
168 int64_t qemu_clock_deadline_ns_all(QEMUClockType type
);
171 * qemu_clock_get_main_loop_timerlist:
172 * @type: the clock type
174 * Return the default timer list associated with a clock.
176 * Returns: the default timer list
178 QEMUTimerList
*qemu_clock_get_main_loop_timerlist(QEMUClockType type
);
182 * @type: the clock type
184 * Call the notifier callback connected with the default timer
185 * list linked to the clock, or qemu_notify() if none.
187 void qemu_clock_notify(QEMUClockType type
);
191 * @type: the clock type
192 * @enabled: true to enable, false to disable
194 * Enable or disable a clock
195 * Disabling the clock will wait for related timerlists to stop
196 * executing qemu_run_timers. Thus, this functions should not
197 * be used from the callback of a timer that is based on @clock.
198 * Doing so would cause a deadlock.
200 * Caller should hold BQL.
202 void qemu_clock_enable(QEMUClockType type
, bool enabled
);
205 * qemu_start_warp_timer:
207 * Starts a timer for virtual clock update
209 void qemu_start_warp_timer(void);
212 * qemu_clock_register_reset_notifier:
213 * @type: the clock type
214 * @notifier: the notifier function
216 * Register a notifier function to call when the clock
217 * concerned is reset.
219 void qemu_clock_register_reset_notifier(QEMUClockType type
,
223 * qemu_clock_unregister_reset_notifier:
224 * @type: the clock type
225 * @notifier: the notifier function
227 * Unregister a notifier function to call when the clock
228 * concerned is reset.
230 void qemu_clock_unregister_reset_notifier(QEMUClockType type
,
234 * qemu_clock_run_timers:
235 * @type: clock on which to operate
237 * Run all the timers associated with the default timer list
240 * Returns: true if any timer ran.
242 bool qemu_clock_run_timers(QEMUClockType type
);
245 * qemu_clock_run_all_timers:
247 * Run all the timers associated with the default timer list
250 * Returns: true if any timer ran.
252 bool qemu_clock_run_all_timers(void);
255 * qemu_clock_get_last:
257 * Returns last clock query time.
259 uint64_t qemu_clock_get_last(QEMUClockType type
);
261 * qemu_clock_set_last:
263 * Sets last clock query time.
265 void qemu_clock_set_last(QEMUClockType type
, uint64_t last
);
274 * @type: the clock type to associate with the timerlist
275 * @cb: the callback to call on notification
276 * @opaque: the opaque pointer to pass to the callback
278 * Create a new timerlist associated with the clock of
281 * Returns: a pointer to the QEMUTimerList created
283 QEMUTimerList
*timerlist_new(QEMUClockType type
,
284 QEMUTimerListNotifyCB
*cb
, void *opaque
);
288 * @timer_list: the timer list to free
290 * Frees a timer_list. It must have no active timers.
292 void timerlist_free(QEMUTimerList
*timer_list
);
295 * timerlist_has_timers:
296 * @timer_list: the timer list to operate on
298 * Determine whether a timer list has active timers
300 * Note that this function should not be used when other threads also access
301 * the timer list. The return value may be outdated by the time it is acted
304 * Returns: true if the timer list has timers.
306 bool timerlist_has_timers(QEMUTimerList
*timer_list
);
310 * @timer_list: the timer list to operate on
312 * Determine whether a timer list has any timers which
315 * Returns: true if the timer list has timers which
318 bool timerlist_expired(QEMUTimerList
*timer_list
);
321 * timerlist_deadline_ns:
322 * @timer_list: the timer list to operate on
324 * Determine the deadline for a timer_list, i.e.
325 * the number of nanoseconds until the first timer
326 * expires. Return -1 if there are no timers.
328 * Returns: the number of nanoseconds until the earliest
329 * timer expires -1 if none
331 int64_t timerlist_deadline_ns(QEMUTimerList
*timer_list
);
334 * timerlist_get_clock:
335 * @timer_list: the timer list to operate on
337 * Determine the clock type associated with a timer list.
339 * Returns: the clock type associated with the
342 QEMUClockType
timerlist_get_clock(QEMUTimerList
*timer_list
);
345 * timerlist_run_timers:
346 * @timer_list: the timer list to use
348 * Call all expired timers associated with the timer list.
350 * Returns: true if any timer expired
352 bool timerlist_run_timers(QEMUTimerList
*timer_list
);
356 * @timer_list: the timer list to use
358 * call the notifier callback associated with the timer list.
360 void timerlist_notify(QEMUTimerList
*timer_list
);
367 * timerlistgroup_init:
368 * @tlg: the timer list group
369 * @cb: the callback to call when a notify is required
370 * @opaque: the opaque pointer to be passed to the callback.
372 * Initialise a timer list group. This must already be
373 * allocated in memory and zeroed. The notifier callback is
374 * called whenever a clock in the timer list group is
375 * reenabled or whenever a timer associated with any timer
376 * list is modified. If @cb is specified as null, qemu_notify()
379 void timerlistgroup_init(QEMUTimerListGroup
*tlg
,
380 QEMUTimerListNotifyCB
*cb
, void *opaque
);
383 * timerlistgroup_deinit:
384 * @tlg: the timer list group
386 * Deinitialise a timer list group. This must already be
387 * initialised. Note the memory is not freed.
389 void timerlistgroup_deinit(QEMUTimerListGroup
*tlg
);
392 * timerlistgroup_run_timers:
393 * @tlg: the timer list group
395 * Run the timers associated with a timer list group.
396 * This will run timers on multiple clocks.
398 * Returns: true if any timer callback ran
400 bool timerlistgroup_run_timers(QEMUTimerListGroup
*tlg
);
403 * timerlistgroup_deadline_ns:
404 * @tlg: the timer list group
406 * Determine the deadline of the soonest timer to
407 * expire associated with any timer list linked to
408 * the timer list group. Only clocks suitable for
409 * deadline calculation are included.
411 * Returns: the deadline in nanoseconds or -1 if no
412 * timers are to expire.
414 int64_t timerlistgroup_deadline_ns(QEMUTimerListGroup
*tlg
);
422 * @ts: the timer to be initialised
423 * @timer_list: the timer list to attach the timer to
424 * @scale: the scale value for the timer
425 * @cb: the callback to be called when the timer expires
426 * @opaque: the opaque pointer to be passed to the callback
428 * Initialise a new timer and associate it with @timer_list.
429 * The caller is responsible for allocating the memory.
431 * You need not call an explicit deinit call. Simply make
432 * sure it is not on a list with timer_del.
434 void timer_init_tl(QEMUTimer
*ts
,
435 QEMUTimerList
*timer_list
, int scale
,
436 QEMUTimerCB
*cb
, void *opaque
);
440 * @ts: the timer to be initialised
441 * @type: the clock to associate with the timer
442 * @scale: the scale value for the timer
443 * @cb: the callback to call when the timer expires
444 * @opaque: the opaque pointer to pass to the callback
446 * Initialize a timer with the given scale on the default timer list
447 * associated with the clock.
449 * You need not call an explicit deinit call. Simply make
450 * sure it is not on a list with timer_del.
452 static inline void timer_init(QEMUTimer
*ts
, QEMUClockType type
, int scale
,
453 QEMUTimerCB
*cb
, void *opaque
)
455 timer_init_tl(ts
, main_loop_tlg
.tl
[type
], scale
, cb
, opaque
);
460 * @ts: the timer to be initialised
461 * @type: the clock to associate with the timer
462 * @cb: the callback to call when the timer expires
463 * @opaque: the opaque pointer to pass to the callback
465 * Initialize a timer with nanosecond scale on the default timer list
466 * associated with the clock.
468 * You need not call an explicit deinit call. Simply make
469 * sure it is not on a list with timer_del.
471 static inline void timer_init_ns(QEMUTimer
*ts
, QEMUClockType type
,
472 QEMUTimerCB
*cb
, void *opaque
)
474 timer_init(ts
, type
, SCALE_NS
, cb
, opaque
);
479 * @ts: the timer to be initialised
480 * @type: the clock to associate with the timer
481 * @cb: the callback to call when the timer expires
482 * @opaque: the opaque pointer to pass to the callback
484 * Initialize a timer with microsecond scale on the default timer list
485 * associated with the clock.
487 * You need not call an explicit deinit call. Simply make
488 * sure it is not on a list with timer_del.
490 static inline void timer_init_us(QEMUTimer
*ts
, QEMUClockType type
,
491 QEMUTimerCB
*cb
, void *opaque
)
493 timer_init(ts
, type
, SCALE_US
, cb
, opaque
);
498 * @ts: the timer to be initialised
499 * @type: the clock to associate with the timer
500 * @cb: the callback to call when the timer expires
501 * @opaque: the opaque pointer to pass to the callback
503 * Initialize a timer with millisecond scale on the default timer list
504 * associated with the clock.
506 * You need not call an explicit deinit call. Simply make
507 * sure it is not on a list with timer_del.
509 static inline void timer_init_ms(QEMUTimer
*ts
, QEMUClockType type
,
510 QEMUTimerCB
*cb
, void *opaque
)
512 timer_init(ts
, type
, SCALE_MS
, cb
, opaque
);
517 * @timer_list: the timer list to attach the timer to
518 * @scale: the scale value for the timer
519 * @cb: the callback to be called when the timer expires
520 * @opaque: the opaque pointer to be passed to the callback
522 * Create a new timer and associate it with @timer_list.
523 * The memory is allocated by the function.
525 * This is not the preferred interface unless you know you
526 * are going to call timer_free. Use timer_init instead.
528 * Returns: a pointer to the timer
530 static inline QEMUTimer
*timer_new_tl(QEMUTimerList
*timer_list
,
535 QEMUTimer
*ts
= g_malloc0(sizeof(QEMUTimer
));
536 timer_init_tl(ts
, timer_list
, scale
, cb
, opaque
);
542 * @type: the clock type to use
543 * @scale: the scale value for the timer
544 * @cb: the callback to be called when the timer expires
545 * @opaque: the opaque pointer to be passed to the callback
547 * Create a new timer and associate it with the default
548 * timer list for the clock type @type.
550 * The default timer list has one special feature: in icount mode,
551 * %QEMU_CLOCK_VIRTUAL timers are run in the vCPU thread. This is
552 * not true of other timer lists, which are typically associated
553 * with an AioContext---each of them runs its timer callbacks in its own
556 * Returns: a pointer to the timer
558 static inline QEMUTimer
*timer_new(QEMUClockType type
, int scale
,
559 QEMUTimerCB
*cb
, void *opaque
)
561 return timer_new_tl(main_loop_tlg
.tl
[type
], scale
, cb
, opaque
);
566 * @type: the clock type to associate with the timer
567 * @cb: the callback to call when the timer expires
568 * @opaque: the opaque pointer to pass to the callback
570 * Create a new timer with nanosecond scale on the default timer list
571 * associated with the clock.
573 * The default timer list has one special feature: in icount mode,
574 * %QEMU_CLOCK_VIRTUAL timers are run in the vCPU thread. This is
575 * not true of other timer lists, which are typically associated
576 * with an AioContext---each of them runs its timer callbacks in its own
579 * Returns: a pointer to the newly created timer
581 static inline QEMUTimer
*timer_new_ns(QEMUClockType type
, QEMUTimerCB
*cb
,
584 return timer_new(type
, SCALE_NS
, cb
, opaque
);
589 * @type: the clock type to associate with the timer
590 * @cb: the callback to call when the timer expires
591 * @opaque: the opaque pointer to pass to the callback
593 * The default timer list has one special feature: in icount mode,
594 * %QEMU_CLOCK_VIRTUAL timers are run in the vCPU thread. This is
595 * not true of other timer lists, which are typically associated
596 * with an AioContext---each of them runs its timer callbacks in its own
599 * Create a new timer with microsecond scale on the default timer list
600 * associated with the clock.
602 * Returns: a pointer to the newly created timer
604 static inline QEMUTimer
*timer_new_us(QEMUClockType type
, QEMUTimerCB
*cb
,
607 return timer_new(type
, SCALE_US
, cb
, opaque
);
612 * @type: the clock type to associate with the timer
613 * @cb: the callback to call when the timer expires
614 * @opaque: the opaque pointer to pass to the callback
616 * The default timer list has one special feature: in icount mode,
617 * %QEMU_CLOCK_VIRTUAL timers are run in the vCPU thread. This is
618 * not true of other timer lists, which are typically associated
619 * with an AioContext---each of them runs its timer callbacks in its own
622 * Create a new timer with millisecond scale on the default timer list
623 * associated with the clock.
625 * Returns: a pointer to the newly created timer
627 static inline QEMUTimer
*timer_new_ms(QEMUClockType type
, QEMUTimerCB
*cb
,
630 return timer_new(type
, SCALE_MS
, cb
, opaque
);
635 * @ts: the timer to be de-initialised
637 * Deassociate the timer from any timerlist. You should
638 * call timer_del before. After this call, any further
639 * timer_del call cannot cause dangling pointer accesses
640 * even if the previously used timerlist is freed.
642 void timer_deinit(QEMUTimer
*ts
);
648 * Free a timer (it must not be on the active list)
650 static inline void timer_free(QEMUTimer
*ts
)
659 * Delete a timer from the active list.
661 * This function is thread-safe but the timer and its timer list must not be
662 * freed while this function is running.
664 void timer_del(QEMUTimer
*ts
);
669 * @expire_time: the expiry time in nanoseconds
671 * Modify a timer to expire at @expire_time
673 * This function is thread-safe but the timer and its timer list must not be
674 * freed while this function is running.
676 void timer_mod_ns(QEMUTimer
*ts
, int64_t expire_time
);
679 * timer_mod_anticipate_ns:
681 * @expire_time: the expiry time in nanoseconds
683 * Modify a timer to expire at @expire_time or the current time,
684 * whichever comes earlier.
686 * This function is thread-safe but the timer and its timer list must not be
687 * freed while this function is running.
689 void timer_mod_anticipate_ns(QEMUTimer
*ts
, int64_t expire_time
);
694 * @expire_time: the expire time in the units associated with the timer
696 * Modify a timer to expiry at @expire_time, taking into
697 * account the scale associated with the timer.
699 * This function is thread-safe but the timer and its timer list must not be
700 * freed while this function is running.
702 void timer_mod(QEMUTimer
*ts
, int64_t expire_timer
);
705 * timer_mod_anticipate:
707 * @expire_time: the expiry time in nanoseconds
709 * Modify a timer to expire at @expire_time or the current time, whichever
710 * comes earlier, taking into account the scale associated with the timer.
712 * This function is thread-safe but the timer and its timer list must not be
713 * freed while this function is running.
715 void timer_mod_anticipate(QEMUTimer
*ts
, int64_t expire_time
);
721 * Determines whether a timer is pending (i.e. is on the
722 * active list of timers, whether or not it has not yet expired).
724 * Returns: true if the timer is pending
726 bool timer_pending(QEMUTimer
*ts
);
731 * @current_time: the current time
733 * Determines whether a timer has expired.
735 * Returns: true if the timer has expired
737 bool timer_expired(QEMUTimer
*timer_head
, int64_t current_time
);
740 * timer_expire_time_ns:
743 * Determine the expiry time of a timer
745 * Returns: the expiry time in nanoseconds
747 uint64_t timer_expire_time_ns(QEMUTimer
*ts
);
754 * Read a timer @ts from a file @f
756 void timer_get(QEMUFile
*f
, QEMUTimer
*ts
);
763 void timer_put(QEMUFile
*f
, QEMUTimer
*ts
);
766 * General utility functions
770 * qemu_timeout_ns_to_ms:
771 * @ns: nanosecond timeout value
773 * Convert a nanosecond timeout value (or -1) to
774 * a millisecond value (or -1), always rounding up.
776 * Returns: millisecond timeout value
778 int qemu_timeout_ns_to_ms(int64_t ns
);
782 * @fds: Array of file descriptors
783 * @nfds: number of file descriptors
784 * @timeout: timeout in nanoseconds
786 * Perform a poll like g_poll but with a timeout in nanoseconds.
787 * See g_poll documentation for further details.
789 * Returns: number of fds ready
791 int qemu_poll_ns(GPollFD
*fds
, guint nfds
, int64_t timeout
);
794 * qemu_soonest_timeout:
795 * @timeout1: first timeout in nanoseconds (or -1 for infinite)
796 * @timeout2: second timeout in nanoseconds (or -1 for infinite)
798 * Calculates the soonest of two timeout values. -1 means infinite, which
799 * is later than any other value.
801 * Returns: soonest timeout value in nanoseconds (or -1 for infinite)
803 static inline int64_t qemu_soonest_timeout(int64_t timeout1
, int64_t timeout2
)
805 /* we can abuse the fact that -1 (which means infinite) is a maximal
806 * value when cast to unsigned. As this is disgusting, it's kept in
807 * one inline function.
809 return ((uint64_t) timeout1
< (uint64_t) timeout2
) ? timeout1
: timeout2
;
815 * Initialise the clock & timer infrastructure
817 void init_clocks(QEMUTimerListNotifyCB
*notify_cb
);
819 int64_t cpu_get_ticks(void);
820 /* Caller must hold BQL */
821 void cpu_enable_ticks(void);
822 /* Caller must hold BQL */
823 void cpu_disable_ticks(void);
825 static inline int64_t get_max_clock_jump(void)
827 /* This should be small enough to prevent excessive interrupts from being
828 * generated by the RTC on clock jumps, but large enough to avoid frequent
829 * unnecessary resets in idle VMs.
831 return 60 * NANOSECONDS_PER_SECOND
;
835 * Low level clock functions
838 /* get host real time in nanosecond */
839 static inline int64_t get_clock_realtime(void)
843 gettimeofday(&tv
, NULL
);
844 return tv
.tv_sec
* 1000000000LL + (tv
.tv_usec
* 1000);
847 /* Warning: don't insert tracepoints into these functions, they are
848 also used by simpletrace backend and tracepoints would cause
849 an infinite recursion! */
851 extern int64_t clock_freq
;
853 static inline int64_t get_clock(void)
856 QueryPerformanceCounter(&ti
);
857 return muldiv64(ti
.QuadPart
, NANOSECONDS_PER_SECOND
, clock_freq
);
862 extern int use_rt_clock
;
864 static inline int64_t get_clock(void)
866 #ifdef CLOCK_MONOTONIC
869 clock_gettime(CLOCK_MONOTONIC
, &ts
);
870 return ts
.tv_sec
* 1000000000LL + ts
.tv_nsec
;
874 /* XXX: using gettimeofday leads to problems if the date
875 changes, so it should be avoided. */
876 return get_clock_realtime();
882 int64_t cpu_get_icount_raw(void);
883 int64_t cpu_get_icount(void);
884 int64_t cpu_get_clock(void);
885 int64_t cpu_icount_to_ns(int64_t icount
);
886 void cpu_update_icount(CPUState
*cpu
);
888 /*******************************************/
889 /* host CPU ticks (if available) */
891 #if defined(_ARCH_PPC)
893 static inline int64_t cpu_get_host_ticks(void)
897 /* This reads timebase in one 64bit go and includes Cell workaround from:
898 http://ozlabs.org/pipermail/linuxppc-dev/2006-October/027052.html
900 __asm__
__volatile__ ("mftb %0\n\t"
905 /* http://ozlabs.org/pipermail/linuxppc-dev/1999-October/003889.html */
907 __asm__
__volatile__ ("mfspr %1,269\n\t" /* mftbu */
908 "mfspr %L0,268\n\t" /* mftb */
909 "mfspr %0,269\n\t" /* mftbu */
912 : "=r" (retval
), "=r" (junk
));
917 #elif defined(__i386__)
919 static inline int64_t cpu_get_host_ticks(void)
922 asm volatile ("rdtsc" : "=A" (val
));
926 #elif defined(__x86_64__)
928 static inline int64_t cpu_get_host_ticks(void)
932 asm volatile("rdtsc" : "=a" (low
), "=d" (high
));
939 #elif defined(__hppa__)
941 static inline int64_t cpu_get_host_ticks(void)
944 asm volatile ("mfctl %%cr16, %0" : "=r"(val
));
948 #elif defined(__s390__)
950 static inline int64_t cpu_get_host_ticks(void)
953 asm volatile("stck 0(%1)" : "=m" (val
) : "a" (&val
) : "cc");
957 #elif defined(__sparc__)
959 static inline int64_t cpu_get_host_ticks (void)
963 asm volatile("rd %%tick,%0" : "=r"(rval
));
966 /* We need an %o or %g register for this. For recent enough gcc
967 there is an "h" constraint for that. Don't bother with that. */
975 asm volatile("rd %%tick,%%g1; srlx %%g1,32,%0; mov %%g1,%1"
976 : "=r"(rval
.i32
.high
), "=r"(rval
.i32
.low
) : : "g1");
981 #elif defined(__mips__) && \
982 ((defined(__mips_isa_rev) && __mips_isa_rev >= 2) || defined(__linux__))
984 * binutils wants to use rdhwr only on mips32r2
985 * but as linux kernel emulate it, it's fine
989 #define MIPS_RDHWR(rd, value) { \
990 __asm__ __volatile__ (".set push\n\t" \
991 ".set mips32r2\n\t" \
992 "rdhwr %0, "rd"\n\t" \
997 static inline int64_t cpu_get_host_ticks(void)
999 /* On kernels >= 2.6.25 rdhwr <reg>, $2 and $3 are emulated */
1001 static uint32_t cyc_per_count
= 0;
1003 if (!cyc_per_count
) {
1004 MIPS_RDHWR("$3", cyc_per_count
);
1007 MIPS_RDHWR("$2", count
);
1008 return (int64_t)(count
* cyc_per_count
);
1011 #elif defined(__alpha__)
1013 static inline int64_t cpu_get_host_ticks(void)
1018 asm volatile("rpcc %0" : "=r"(cc
));
1025 /* The host CPU doesn't have an easily accessible cycle counter.
1026 Just return a monotonically increasing value. This will be
1027 totally wrong, but hopefully better than nothing. */
1028 static inline int64_t cpu_get_host_ticks(void)
1034 #ifdef CONFIG_PROFILER
1035 static inline int64_t profile_getclock(void)
1040 extern int64_t tcg_time
;
1041 extern int64_t dev_time
;