4 #include "qemu/bitops.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,
56 * QEMU Timer attributes:
58 * An individual timer may be given one or multiple attributes when initialized.
59 * Each attribute corresponds to one bit. Attributes modify the processing
60 * of timers when they fire.
62 * The following attributes are available:
64 * QEMU_TIMER_ATTR_EXTERNAL: drives external subsystem
66 * Timers with this attribute do not recorded in rr mode, therefore it could be
67 * used for the subsystems that operate outside the guest core. Applicable only
68 * with virtual clock type.
71 #define QEMU_TIMER_ATTR_EXTERNAL BIT(0)
73 typedef struct QEMUTimerList QEMUTimerList
;
75 struct QEMUTimerListGroup
{
76 QEMUTimerList
*tl
[QEMU_CLOCK_MAX
];
79 typedef void QEMUTimerCB(void *opaque
);
80 typedef void QEMUTimerListNotifyCB(void *opaque
, QEMUClockType type
);
83 int64_t expire_time
; /* in nanoseconds */
84 QEMUTimerList
*timer_list
;
92 extern QEMUTimerListGroup main_loop_tlg
;
96 * @type: the clock type
98 * Get the nanosecond value of a clock with
101 * Returns: the clock value in nanoseconds
103 int64_t qemu_clock_get_ns(QEMUClockType type
);
107 * @type: the clock type
109 * Get the millisecond value of a clock with
112 * Returns: the clock value in milliseconds
114 static inline int64_t qemu_clock_get_ms(QEMUClockType type
)
116 return qemu_clock_get_ns(type
) / SCALE_MS
;
121 * @type: the clock type
123 * Get the microsecond value of a clock with
126 * Returns: the clock value in microseconds
128 static inline int64_t qemu_clock_get_us(QEMUClockType type
)
130 return qemu_clock_get_ns(type
) / SCALE_US
;
134 * qemu_clock_has_timers:
135 * @type: the clock type
137 * Determines whether a clock's default timer list
138 * has timers attached
140 * Note that this function should not be used when other threads also access
141 * the timer list. The return value may be outdated by the time it is acted
144 * Returns: true if the clock's default timer list
145 * has timers attached
147 bool qemu_clock_has_timers(QEMUClockType type
);
150 * qemu_clock_expired:
151 * @type: the clock type
153 * Determines whether a clock's default timer list
154 * has an expired timer.
156 * Returns: true if the clock's default timer list has
159 bool qemu_clock_expired(QEMUClockType type
);
162 * qemu_clock_use_for_deadline:
163 * @type: the clock type
165 * Determine whether a clock should be used for deadline
166 * calculations. Some clocks, for instance vm_clock with
167 * use_icount set, do not count in nanoseconds. Such clocks
168 * are not used for deadline calculations, and are presumed
169 * to interrupt any poll using qemu_notify/aio_notify
172 * Returns: true if the clock runs in nanoseconds and
173 * should be used for a deadline.
175 bool qemu_clock_use_for_deadline(QEMUClockType type
);
178 * qemu_clock_deadline_ns_all:
179 * @type: the clock type
181 * Calculate the deadline across all timer lists associated
182 * with a clock (as opposed to just the default one)
183 * in nanoseconds, or -1 if no timer is set to expire.
185 * Returns: time until expiry in nanoseconds or -1
187 int64_t qemu_clock_deadline_ns_all(QEMUClockType type
);
190 * qemu_clock_get_main_loop_timerlist:
191 * @type: the clock type
193 * Return the default timer list associated with a clock.
195 * Returns: the default timer list
197 QEMUTimerList
*qemu_clock_get_main_loop_timerlist(QEMUClockType type
);
201 * @type: the clock type
203 * Call the notifier callback connected with the default timer
204 * list linked to the clock, or qemu_notify() if none.
206 void qemu_clock_notify(QEMUClockType type
);
210 * @type: the clock type
211 * @enabled: true to enable, false to disable
213 * Enable or disable a clock
214 * Disabling the clock will wait for related timerlists to stop
215 * executing qemu_run_timers. Thus, this functions should not
216 * be used from the callback of a timer that is based on @clock.
217 * Doing so would cause a deadlock.
219 * Caller should hold BQL.
221 void qemu_clock_enable(QEMUClockType type
, bool enabled
);
224 * qemu_start_warp_timer:
226 * Starts a timer for virtual clock update
228 void qemu_start_warp_timer(void);
231 * qemu_clock_run_timers:
232 * @type: clock on which to operate
234 * Run all the timers associated with the default timer list
237 * Returns: true if any timer ran.
239 bool qemu_clock_run_timers(QEMUClockType type
);
242 * qemu_clock_run_all_timers:
244 * Run all the timers associated with the default timer list
247 * Returns: true if any timer ran.
249 bool qemu_clock_run_all_timers(void);
252 * qemu_clock_get_last:
254 * Returns last clock query time.
256 uint64_t qemu_clock_get_last(QEMUClockType type
);
258 * qemu_clock_set_last:
260 * Sets last clock query time.
262 void qemu_clock_set_last(QEMUClockType type
, uint64_t last
);
271 * @type: the clock type to associate with the timerlist
272 * @cb: the callback to call on notification
273 * @opaque: the opaque pointer to pass to the callback
275 * Create a new timerlist associated with the clock of
278 * Returns: a pointer to the QEMUTimerList created
280 QEMUTimerList
*timerlist_new(QEMUClockType type
,
281 QEMUTimerListNotifyCB
*cb
, void *opaque
);
285 * @timer_list: the timer list to free
287 * Frees a timer_list. It must have no active timers.
289 void timerlist_free(QEMUTimerList
*timer_list
);
292 * timerlist_has_timers:
293 * @timer_list: the timer list to operate on
295 * Determine whether a timer list has active timers
297 * Note that this function should not be used when other threads also access
298 * the timer list. The return value may be outdated by the time it is acted
301 * Returns: true if the timer list has timers.
303 bool timerlist_has_timers(QEMUTimerList
*timer_list
);
307 * @timer_list: the timer list to operate on
309 * Determine whether a timer list has any timers which
312 * Returns: true if the timer list has timers which
315 bool timerlist_expired(QEMUTimerList
*timer_list
);
318 * timerlist_deadline_ns:
319 * @timer_list: the timer list to operate on
321 * Determine the deadline for a timer_list, i.e.
322 * the number of nanoseconds until the first timer
323 * expires. Return -1 if there are no timers.
325 * Returns: the number of nanoseconds until the earliest
326 * timer expires -1 if none
328 int64_t timerlist_deadline_ns(QEMUTimerList
*timer_list
);
331 * timerlist_get_clock:
332 * @timer_list: the timer list to operate on
334 * Determine the clock type associated with a timer list.
336 * Returns: the clock type associated with the
339 QEMUClockType
timerlist_get_clock(QEMUTimerList
*timer_list
);
342 * timerlist_run_timers:
343 * @timer_list: the timer list to use
345 * Call all expired timers associated with the timer list.
347 * Returns: true if any timer expired
349 bool timerlist_run_timers(QEMUTimerList
*timer_list
);
353 * @timer_list: the timer list to use
355 * call the notifier callback associated with the timer list.
357 void timerlist_notify(QEMUTimerList
*timer_list
);
364 * timerlistgroup_init:
365 * @tlg: the timer list group
366 * @cb: the callback to call when a notify is required
367 * @opaque: the opaque pointer to be passed to the callback.
369 * Initialise a timer list group. This must already be
370 * allocated in memory and zeroed. The notifier callback is
371 * called whenever a clock in the timer list group is
372 * reenabled or whenever a timer associated with any timer
373 * list is modified. If @cb is specified as null, qemu_notify()
376 void timerlistgroup_init(QEMUTimerListGroup
*tlg
,
377 QEMUTimerListNotifyCB
*cb
, void *opaque
);
380 * timerlistgroup_deinit:
381 * @tlg: the timer list group
383 * Deinitialise a timer list group. This must already be
384 * initialised. Note the memory is not freed.
386 void timerlistgroup_deinit(QEMUTimerListGroup
*tlg
);
389 * timerlistgroup_run_timers:
390 * @tlg: the timer list group
392 * Run the timers associated with a timer list group.
393 * This will run timers on multiple clocks.
395 * Returns: true if any timer callback ran
397 bool timerlistgroup_run_timers(QEMUTimerListGroup
*tlg
);
400 * timerlistgroup_deadline_ns:
401 * @tlg: the timer list group
403 * Determine the deadline of the soonest timer to
404 * expire associated with any timer list linked to
405 * the timer list group. Only clocks suitable for
406 * deadline calculation are included.
408 * Returns: the deadline in nanoseconds or -1 if no
409 * timers are to expire.
411 int64_t timerlistgroup_deadline_ns(QEMUTimerListGroup
*tlg
);
419 * @ts: the timer to be initialised
420 * @timer_list_group: (optional) the timer list group to attach the timer to
421 * @type: the clock type to use
422 * @scale: the scale value for the timer
423 * @attributes: 0, or one or more OR'ed QEMU_TIMER_ATTR_<id> values
424 * @cb: the callback to be called when the timer expires
425 * @opaque: the opaque pointer to be passed to the callback
427 * Initialise a timer with the given scale and attributes,
428 * and associate it with timer list for given clock @type in @timer_list_group
429 * (or default timer list group, if NULL).
430 * The caller is responsible for allocating the memory.
432 * You need not call an explicit deinit call. Simply make
433 * sure it is not on a list with timer_del.
435 void timer_init_full(QEMUTimer
*ts
,
436 QEMUTimerListGroup
*timer_list_group
, QEMUClockType type
,
437 int scale
, int attributes
,
438 QEMUTimerCB
*cb
, void *opaque
);
442 * @ts: the timer to be initialised
443 * @type: the clock to associate with the timer
444 * @scale: the scale value for the timer
445 * @cb: the callback to call when the timer expires
446 * @opaque: the opaque pointer to pass to the callback
448 * Initialize a timer with the given scale on the default timer list
449 * associated with the clock.
450 * See timer_init_full for details.
452 static inline void timer_init(QEMUTimer
*ts
, QEMUClockType type
, int scale
,
453 QEMUTimerCB
*cb
, void *opaque
)
455 timer_init_full(ts
, NULL
, type
, scale
, 0, 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.
467 * See timer_init_full for details.
469 static inline void timer_init_ns(QEMUTimer
*ts
, QEMUClockType type
,
470 QEMUTimerCB
*cb
, void *opaque
)
472 timer_init(ts
, type
, SCALE_NS
, cb
, opaque
);
477 * @ts: the timer to be initialised
478 * @type: the clock to associate with the timer
479 * @cb: the callback to call when the timer expires
480 * @opaque: the opaque pointer to pass to the callback
482 * Initialize a timer with microsecond scale on the default timer list
483 * associated with the clock.
484 * See timer_init_full for details.
486 static inline void timer_init_us(QEMUTimer
*ts
, QEMUClockType type
,
487 QEMUTimerCB
*cb
, void *opaque
)
489 timer_init(ts
, type
, SCALE_US
, cb
, opaque
);
494 * @ts: the timer to be initialised
495 * @type: the clock to associate with the timer
496 * @cb: the callback to call when the timer expires
497 * @opaque: the opaque pointer to pass to the callback
499 * Initialize a timer with millisecond scale on the default timer list
500 * associated with the clock.
501 * See timer_init_full for details.
503 static inline void timer_init_ms(QEMUTimer
*ts
, QEMUClockType type
,
504 QEMUTimerCB
*cb
, void *opaque
)
506 timer_init(ts
, type
, SCALE_MS
, cb
, opaque
);
511 * @timer_list_group: (optional) the timer list group to attach the timer to
512 * @type: the clock type to use
513 * @scale: the scale value for the timer
514 * @attributes: 0, or one or more OR'ed QEMU_TIMER_ATTR_<id> values
515 * @cb: the callback to be called when the timer expires
516 * @opaque: the opaque pointer to be passed to the callback
518 * Create a new timer with the given scale and attributes,
519 * and associate it with timer list for given clock @type in @timer_list_group
520 * (or default timer list group, if NULL).
521 * The memory is allocated by the function.
523 * This is not the preferred interface unless you know you
524 * are going to call timer_free. Use timer_init or timer_init_full instead.
526 * The default timer list has one special feature: in icount mode,
527 * %QEMU_CLOCK_VIRTUAL timers are run in the vCPU thread. This is
528 * not true of other timer lists, which are typically associated
529 * with an AioContext---each of them runs its timer callbacks in its own
532 * Returns: a pointer to the timer
534 static inline QEMUTimer
*timer_new_full(QEMUTimerListGroup
*timer_list_group
,
536 int scale
, int attributes
,
537 QEMUTimerCB
*cb
, void *opaque
)
539 QEMUTimer
*ts
= g_malloc0(sizeof(QEMUTimer
));
540 timer_init_full(ts
, timer_list_group
, type
, scale
, attributes
, cb
, opaque
);
546 * @type: the clock type to use
547 * @scale: the scale value for the timer
548 * @cb: the callback to be called when the timer expires
549 * @opaque: the opaque pointer to be passed to the callback
551 * Create a new timer with the given scale,
552 * and associate it with the default timer list for the clock type @type.
553 * See timer_new_full for details.
555 * Returns: a pointer to the timer
557 static inline QEMUTimer
*timer_new(QEMUClockType type
, int scale
,
558 QEMUTimerCB
*cb
, void *opaque
)
560 return timer_new_full(NULL
, type
, scale
, 0, cb
, opaque
);
565 * @type: the clock type to associate with the timer
566 * @cb: the callback to call when the timer expires
567 * @opaque: the opaque pointer to pass to the callback
569 * Create a new timer with nanosecond scale on the default timer list
570 * associated with the clock.
571 * See timer_new_full for details.
573 * Returns: a pointer to the newly created timer
575 static inline QEMUTimer
*timer_new_ns(QEMUClockType type
, QEMUTimerCB
*cb
,
578 return timer_new(type
, SCALE_NS
, cb
, opaque
);
583 * @type: the clock type to associate with the timer
584 * @cb: the callback to call when the timer expires
585 * @opaque: the opaque pointer to pass to the callback
587 * Create a new timer with microsecond scale on the default timer list
588 * associated with the clock.
589 * See timer_new_full for details.
591 * Returns: a pointer to the newly created timer
593 static inline QEMUTimer
*timer_new_us(QEMUClockType type
, QEMUTimerCB
*cb
,
596 return timer_new(type
, SCALE_US
, cb
, opaque
);
601 * @type: the clock type to associate with the timer
602 * @cb: the callback to call when the timer expires
603 * @opaque: the opaque pointer to pass to the callback
605 * Create a new timer with millisecond scale on the default timer list
606 * associated with the clock.
607 * See timer_new_full for details.
609 * Returns: a pointer to the newly created timer
611 static inline QEMUTimer
*timer_new_ms(QEMUClockType type
, QEMUTimerCB
*cb
,
614 return timer_new(type
, SCALE_MS
, cb
, opaque
);
619 * @ts: the timer to be de-initialised
621 * Deassociate the timer from any timerlist. You should
622 * call timer_del before. After this call, any further
623 * timer_del call cannot cause dangling pointer accesses
624 * even if the previously used timerlist is freed.
626 void timer_deinit(QEMUTimer
*ts
);
632 * Free a timer (it must not be on the active list)
634 static inline void timer_free(QEMUTimer
*ts
)
643 * Delete a timer from the active list.
645 * This function is thread-safe but the timer and its timer list must not be
646 * freed while this function is running.
648 void timer_del(QEMUTimer
*ts
);
653 * @expire_time: the expiry time in nanoseconds
655 * Modify a timer to expire at @expire_time
657 * This function is thread-safe but the timer and its timer list must not be
658 * freed while this function is running.
660 void timer_mod_ns(QEMUTimer
*ts
, int64_t expire_time
);
663 * timer_mod_anticipate_ns:
665 * @expire_time: the expiry time in nanoseconds
667 * Modify a timer to expire at @expire_time or the current time,
668 * whichever comes earlier.
670 * This function is thread-safe but the timer and its timer list must not be
671 * freed while this function is running.
673 void timer_mod_anticipate_ns(QEMUTimer
*ts
, int64_t expire_time
);
678 * @expire_time: the expire time in the units associated with the timer
680 * Modify a timer to expiry at @expire_time, taking into
681 * account the scale associated with the timer.
683 * This function is thread-safe but the timer and its timer list must not be
684 * freed while this function is running.
686 void timer_mod(QEMUTimer
*ts
, int64_t expire_timer
);
689 * timer_mod_anticipate:
691 * @expire_time: the expiry time in nanoseconds
693 * Modify a timer to expire at @expire_time or the current time, whichever
694 * comes earlier, taking into account the scale associated with the timer.
696 * This function is thread-safe but the timer and its timer list must not be
697 * freed while this function is running.
699 void timer_mod_anticipate(QEMUTimer
*ts
, int64_t expire_time
);
705 * Determines whether a timer is pending (i.e. is on the
706 * active list of timers, whether or not it has not yet expired).
708 * Returns: true if the timer is pending
710 bool timer_pending(QEMUTimer
*ts
);
715 * @current_time: the current time
717 * Determines whether a timer has expired.
719 * Returns: true if the timer has expired
721 bool timer_expired(QEMUTimer
*timer_head
, int64_t current_time
);
724 * timer_expire_time_ns:
727 * Determine the expiry time of a timer
729 * Returns: the expiry time in nanoseconds
731 uint64_t timer_expire_time_ns(QEMUTimer
*ts
);
738 * Read a timer @ts from a file @f
740 void timer_get(QEMUFile
*f
, QEMUTimer
*ts
);
747 void timer_put(QEMUFile
*f
, QEMUTimer
*ts
);
750 * General utility functions
754 * qemu_timeout_ns_to_ms:
755 * @ns: nanosecond timeout value
757 * Convert a nanosecond timeout value (or -1) to
758 * a millisecond value (or -1), always rounding up.
760 * Returns: millisecond timeout value
762 int qemu_timeout_ns_to_ms(int64_t ns
);
766 * @fds: Array of file descriptors
767 * @nfds: number of file descriptors
768 * @timeout: timeout in nanoseconds
770 * Perform a poll like g_poll but with a timeout in nanoseconds.
771 * See g_poll documentation for further details.
773 * Returns: number of fds ready
775 int qemu_poll_ns(GPollFD
*fds
, guint nfds
, int64_t timeout
);
778 * qemu_soonest_timeout:
779 * @timeout1: first timeout in nanoseconds (or -1 for infinite)
780 * @timeout2: second timeout in nanoseconds (or -1 for infinite)
782 * Calculates the soonest of two timeout values. -1 means infinite, which
783 * is later than any other value.
785 * Returns: soonest timeout value in nanoseconds (or -1 for infinite)
787 static inline int64_t qemu_soonest_timeout(int64_t timeout1
, int64_t timeout2
)
789 /* we can abuse the fact that -1 (which means infinite) is a maximal
790 * value when cast to unsigned. As this is disgusting, it's kept in
791 * one inline function.
793 return ((uint64_t) timeout1
< (uint64_t) timeout2
) ? timeout1
: timeout2
;
799 * Initialise the clock & timer infrastructure
801 void init_clocks(QEMUTimerListNotifyCB
*notify_cb
);
803 int64_t cpu_get_ticks(void);
804 /* Caller must hold BQL */
805 void cpu_enable_ticks(void);
806 /* Caller must hold BQL */
807 void cpu_disable_ticks(void);
809 static inline int64_t get_max_clock_jump(void)
811 /* This should be small enough to prevent excessive interrupts from being
812 * generated by the RTC on clock jumps, but large enough to avoid frequent
813 * unnecessary resets in idle VMs.
815 return 60 * NANOSECONDS_PER_SECOND
;
819 * Low level clock functions
822 /* get host real time in nanosecond */
823 static inline int64_t get_clock_realtime(void)
827 gettimeofday(&tv
, NULL
);
828 return tv
.tv_sec
* 1000000000LL + (tv
.tv_usec
* 1000);
831 /* Warning: don't insert tracepoints into these functions, they are
832 also used by simpletrace backend and tracepoints would cause
833 an infinite recursion! */
835 extern int64_t clock_freq
;
837 static inline int64_t get_clock(void)
840 QueryPerformanceCounter(&ti
);
841 return muldiv64(ti
.QuadPart
, NANOSECONDS_PER_SECOND
, clock_freq
);
846 extern int use_rt_clock
;
848 static inline int64_t get_clock(void)
850 #ifdef CLOCK_MONOTONIC
853 clock_gettime(CLOCK_MONOTONIC
, &ts
);
854 return ts
.tv_sec
* 1000000000LL + ts
.tv_nsec
;
858 /* XXX: using gettimeofday leads to problems if the date
859 changes, so it should be avoided. */
860 return get_clock_realtime();
866 int64_t cpu_get_icount_raw(void);
867 int64_t cpu_get_icount(void);
868 int64_t cpu_get_clock(void);
869 int64_t cpu_icount_to_ns(int64_t icount
);
870 void cpu_update_icount(CPUState
*cpu
);
872 /*******************************************/
873 /* host CPU ticks (if available) */
875 #if defined(_ARCH_PPC)
877 static inline int64_t cpu_get_host_ticks(void)
881 /* This reads timebase in one 64bit go and includes Cell workaround from:
882 http://ozlabs.org/pipermail/linuxppc-dev/2006-October/027052.html
884 __asm__
__volatile__ ("mftb %0\n\t"
889 /* http://ozlabs.org/pipermail/linuxppc-dev/1999-October/003889.html */
891 __asm__
__volatile__ ("mfspr %1,269\n\t" /* mftbu */
892 "mfspr %L0,268\n\t" /* mftb */
893 "mfspr %0,269\n\t" /* mftbu */
896 : "=r" (retval
), "=r" (junk
));
901 #elif defined(__i386__)
903 static inline int64_t cpu_get_host_ticks(void)
906 asm volatile ("rdtsc" : "=A" (val
));
910 #elif defined(__x86_64__)
912 static inline int64_t cpu_get_host_ticks(void)
916 asm volatile("rdtsc" : "=a" (low
), "=d" (high
));
923 #elif defined(__hppa__)
925 static inline int64_t cpu_get_host_ticks(void)
928 asm volatile ("mfctl %%cr16, %0" : "=r"(val
));
932 #elif defined(__s390__)
934 static inline int64_t cpu_get_host_ticks(void)
937 asm volatile("stck 0(%1)" : "=m" (val
) : "a" (&val
) : "cc");
941 #elif defined(__sparc__)
943 static inline int64_t cpu_get_host_ticks (void)
947 asm volatile("rd %%tick,%0" : "=r"(rval
));
950 /* We need an %o or %g register for this. For recent enough gcc
951 there is an "h" constraint for that. Don't bother with that. */
959 asm volatile("rd %%tick,%%g1; srlx %%g1,32,%0; mov %%g1,%1"
960 : "=r"(rval
.i32
.high
), "=r"(rval
.i32
.low
) : : "g1");
965 #elif defined(__mips__) && \
966 ((defined(__mips_isa_rev) && __mips_isa_rev >= 2) || defined(__linux__))
968 * binutils wants to use rdhwr only on mips32r2
969 * but as linux kernel emulate it, it's fine
973 #define MIPS_RDHWR(rd, value) { \
974 __asm__ __volatile__ (".set push\n\t" \
975 ".set mips32r2\n\t" \
976 "rdhwr %0, "rd"\n\t" \
981 static inline int64_t cpu_get_host_ticks(void)
983 /* On kernels >= 2.6.25 rdhwr <reg>, $2 and $3 are emulated */
985 static uint32_t cyc_per_count
= 0;
987 if (!cyc_per_count
) {
988 MIPS_RDHWR("$3", cyc_per_count
);
991 MIPS_RDHWR("$2", count
);
992 return (int64_t)(count
* cyc_per_count
);
995 #elif defined(__alpha__)
997 static inline int64_t cpu_get_host_ticks(void)
1002 asm volatile("rpcc %0" : "=r"(cc
));
1009 /* The host CPU doesn't have an easily accessible cycle counter.
1010 Just return a monotonically increasing value. This will be
1011 totally wrong, but hopefully better than nothing. */
1012 static inline int64_t cpu_get_host_ticks(void)
1018 #ifdef CONFIG_PROFILER
1019 static inline int64_t profile_getclock(void)
1024 extern int64_t dev_time
;