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_register_reset_notifier:
232 * @type: the clock type
233 * @notifier: the notifier function
235 * Register a notifier function to call when the clock
236 * concerned is reset.
238 void qemu_clock_register_reset_notifier(QEMUClockType type
,
242 * qemu_clock_unregister_reset_notifier:
243 * @type: the clock type
244 * @notifier: the notifier function
246 * Unregister a notifier function to call when the clock
247 * concerned is reset.
249 void qemu_clock_unregister_reset_notifier(QEMUClockType type
,
253 * qemu_clock_run_timers:
254 * @type: clock on which to operate
256 * Run all the timers associated with the default timer list
259 * Returns: true if any timer ran.
261 bool qemu_clock_run_timers(QEMUClockType type
);
264 * qemu_clock_run_all_timers:
266 * Run all the timers associated with the default timer list
269 * Returns: true if any timer ran.
271 bool qemu_clock_run_all_timers(void);
274 * qemu_clock_get_last:
276 * Returns last clock query time.
278 uint64_t qemu_clock_get_last(QEMUClockType type
);
280 * qemu_clock_set_last:
282 * Sets last clock query time.
284 void qemu_clock_set_last(QEMUClockType type
, uint64_t last
);
293 * @type: the clock type to associate with the timerlist
294 * @cb: the callback to call on notification
295 * @opaque: the opaque pointer to pass to the callback
297 * Create a new timerlist associated with the clock of
300 * Returns: a pointer to the QEMUTimerList created
302 QEMUTimerList
*timerlist_new(QEMUClockType type
,
303 QEMUTimerListNotifyCB
*cb
, void *opaque
);
307 * @timer_list: the timer list to free
309 * Frees a timer_list. It must have no active timers.
311 void timerlist_free(QEMUTimerList
*timer_list
);
314 * timerlist_has_timers:
315 * @timer_list: the timer list to operate on
317 * Determine whether a timer list has active timers
319 * Note that this function should not be used when other threads also access
320 * the timer list. The return value may be outdated by the time it is acted
323 * Returns: true if the timer list has timers.
325 bool timerlist_has_timers(QEMUTimerList
*timer_list
);
329 * @timer_list: the timer list to operate on
331 * Determine whether a timer list has any timers which
334 * Returns: true if the timer list has timers which
337 bool timerlist_expired(QEMUTimerList
*timer_list
);
340 * timerlist_deadline_ns:
341 * @timer_list: the timer list to operate on
343 * Determine the deadline for a timer_list, i.e.
344 * the number of nanoseconds until the first timer
345 * expires. Return -1 if there are no timers.
347 * Returns: the number of nanoseconds until the earliest
348 * timer expires -1 if none
350 int64_t timerlist_deadline_ns(QEMUTimerList
*timer_list
);
353 * timerlist_get_clock:
354 * @timer_list: the timer list to operate on
356 * Determine the clock type associated with a timer list.
358 * Returns: the clock type associated with the
361 QEMUClockType
timerlist_get_clock(QEMUTimerList
*timer_list
);
364 * timerlist_run_timers:
365 * @timer_list: the timer list to use
367 * Call all expired timers associated with the timer list.
369 * Returns: true if any timer expired
371 bool timerlist_run_timers(QEMUTimerList
*timer_list
);
375 * @timer_list: the timer list to use
377 * call the notifier callback associated with the timer list.
379 void timerlist_notify(QEMUTimerList
*timer_list
);
386 * timerlistgroup_init:
387 * @tlg: the timer list group
388 * @cb: the callback to call when a notify is required
389 * @opaque: the opaque pointer to be passed to the callback.
391 * Initialise a timer list group. This must already be
392 * allocated in memory and zeroed. The notifier callback is
393 * called whenever a clock in the timer list group is
394 * reenabled or whenever a timer associated with any timer
395 * list is modified. If @cb is specified as null, qemu_notify()
398 void timerlistgroup_init(QEMUTimerListGroup
*tlg
,
399 QEMUTimerListNotifyCB
*cb
, void *opaque
);
402 * timerlistgroup_deinit:
403 * @tlg: the timer list group
405 * Deinitialise a timer list group. This must already be
406 * initialised. Note the memory is not freed.
408 void timerlistgroup_deinit(QEMUTimerListGroup
*tlg
);
411 * timerlistgroup_run_timers:
412 * @tlg: the timer list group
414 * Run the timers associated with a timer list group.
415 * This will run timers on multiple clocks.
417 * Returns: true if any timer callback ran
419 bool timerlistgroup_run_timers(QEMUTimerListGroup
*tlg
);
422 * timerlistgroup_deadline_ns:
423 * @tlg: the timer list group
425 * Determine the deadline of the soonest timer to
426 * expire associated with any timer list linked to
427 * the timer list group. Only clocks suitable for
428 * deadline calculation are included.
430 * Returns: the deadline in nanoseconds or -1 if no
431 * timers are to expire.
433 int64_t timerlistgroup_deadline_ns(QEMUTimerListGroup
*tlg
);
441 * @ts: the timer to be initialised
442 * @timer_list_group: (optional) the timer list group to attach the timer to
443 * @type: the clock type to use
444 * @scale: the scale value for the timer
445 * @attributes: 0, or one or more OR'ed QEMU_TIMER_ATTR_<id> values
446 * @cb: the callback to be called when the timer expires
447 * @opaque: the opaque pointer to be passed to the callback
449 * Initialise a timer with the given scale and attributes,
450 * and associate it with timer list for given clock @type in @timer_list_group
451 * (or default timer list group, if NULL).
452 * The caller is responsible for allocating the memory.
454 * You need not call an explicit deinit call. Simply make
455 * sure it is not on a list with timer_del.
457 void timer_init_full(QEMUTimer
*ts
,
458 QEMUTimerListGroup
*timer_list_group
, QEMUClockType type
,
459 int scale
, int attributes
,
460 QEMUTimerCB
*cb
, void *opaque
);
464 * @ts: the timer to be initialised
465 * @type: the clock to associate with the timer
466 * @scale: the scale value for the timer
467 * @cb: the callback to call when the timer expires
468 * @opaque: the opaque pointer to pass to the callback
470 * Initialize a timer with the given scale on the default timer list
471 * associated with the clock.
472 * See timer_init_full for details.
474 static inline void timer_init(QEMUTimer
*ts
, QEMUClockType type
, int scale
,
475 QEMUTimerCB
*cb
, void *opaque
)
477 timer_init_full(ts
, NULL
, type
, scale
, 0, cb
, opaque
);
482 * @ts: the timer to be initialised
483 * @type: the clock to associate with the timer
484 * @cb: the callback to call when the timer expires
485 * @opaque: the opaque pointer to pass to the callback
487 * Initialize a timer with nanosecond scale on the default timer list
488 * associated with the clock.
489 * See timer_init_full for details.
491 static inline void timer_init_ns(QEMUTimer
*ts
, QEMUClockType type
,
492 QEMUTimerCB
*cb
, void *opaque
)
494 timer_init(ts
, type
, SCALE_NS
, cb
, opaque
);
499 * @ts: the timer to be initialised
500 * @type: the clock to associate with the timer
501 * @cb: the callback to call when the timer expires
502 * @opaque: the opaque pointer to pass to the callback
504 * Initialize a timer with microsecond scale on the default timer list
505 * associated with the clock.
506 * See timer_init_full for details.
508 static inline void timer_init_us(QEMUTimer
*ts
, QEMUClockType type
,
509 QEMUTimerCB
*cb
, void *opaque
)
511 timer_init(ts
, type
, SCALE_US
, cb
, opaque
);
516 * @ts: the timer to be initialised
517 * @type: the clock to associate with the timer
518 * @cb: the callback to call when the timer expires
519 * @opaque: the opaque pointer to pass to the callback
521 * Initialize a timer with millisecond scale on the default timer list
522 * associated with the clock.
523 * See timer_init_full for details.
525 static inline void timer_init_ms(QEMUTimer
*ts
, QEMUClockType type
,
526 QEMUTimerCB
*cb
, void *opaque
)
528 timer_init(ts
, type
, SCALE_MS
, cb
, opaque
);
533 * @timer_list_group: (optional) the timer list group to attach the timer to
534 * @type: the clock type to use
535 * @scale: the scale value for the timer
536 * @attributes: 0, or one or more OR'ed QEMU_TIMER_ATTR_<id> values
537 * @cb: the callback to be called when the timer expires
538 * @opaque: the opaque pointer to be passed to the callback
540 * Create a new timer with the given scale and attributes,
541 * and associate it with timer list for given clock @type in @timer_list_group
542 * (or default timer list group, if NULL).
543 * The memory is allocated by the function.
545 * This is not the preferred interface unless you know you
546 * are going to call timer_free. Use timer_init or timer_init_full instead.
548 * The default timer list has one special feature: in icount mode,
549 * %QEMU_CLOCK_VIRTUAL timers are run in the vCPU thread. This is
550 * not true of other timer lists, which are typically associated
551 * with an AioContext---each of them runs its timer callbacks in its own
554 * Returns: a pointer to the timer
556 static inline QEMUTimer
*timer_new_full(QEMUTimerListGroup
*timer_list_group
,
558 int scale
, int attributes
,
559 QEMUTimerCB
*cb
, void *opaque
)
561 QEMUTimer
*ts
= g_malloc0(sizeof(QEMUTimer
));
562 timer_init_full(ts
, timer_list_group
, type
, scale
, attributes
, cb
, opaque
);
568 * @type: the clock type to use
569 * @scale: the scale value for the timer
570 * @cb: the callback to be called when the timer expires
571 * @opaque: the opaque pointer to be passed to the callback
573 * Create a new timer with the given scale,
574 * and associate it with the default timer list for the clock type @type.
575 * See timer_new_full for details.
577 * Returns: a pointer to the timer
579 static inline QEMUTimer
*timer_new(QEMUClockType type
, int scale
,
580 QEMUTimerCB
*cb
, void *opaque
)
582 return timer_new_full(NULL
, type
, scale
, 0, cb
, opaque
);
587 * @type: the clock type to associate with the timer
588 * @cb: the callback to call when the timer expires
589 * @opaque: the opaque pointer to pass to the callback
591 * Create a new timer with nanosecond scale on the default timer list
592 * associated with the clock.
593 * See timer_new_full for details.
595 * Returns: a pointer to the newly created timer
597 static inline QEMUTimer
*timer_new_ns(QEMUClockType type
, QEMUTimerCB
*cb
,
600 return timer_new(type
, SCALE_NS
, cb
, opaque
);
605 * @type: the clock type to associate with the timer
606 * @cb: the callback to call when the timer expires
607 * @opaque: the opaque pointer to pass to the callback
609 * Create a new timer with microsecond scale on the default timer list
610 * associated with the clock.
611 * See timer_new_full for details.
613 * Returns: a pointer to the newly created timer
615 static inline QEMUTimer
*timer_new_us(QEMUClockType type
, QEMUTimerCB
*cb
,
618 return timer_new(type
, SCALE_US
, cb
, opaque
);
623 * @type: the clock type to associate with the timer
624 * @cb: the callback to call when the timer expires
625 * @opaque: the opaque pointer to pass to the callback
627 * Create a new timer with millisecond scale on the default timer list
628 * associated with the clock.
629 * See timer_new_full for details.
631 * Returns: a pointer to the newly created timer
633 static inline QEMUTimer
*timer_new_ms(QEMUClockType type
, QEMUTimerCB
*cb
,
636 return timer_new(type
, SCALE_MS
, cb
, opaque
);
641 * @ts: the timer to be de-initialised
643 * Deassociate the timer from any timerlist. You should
644 * call timer_del before. After this call, any further
645 * timer_del call cannot cause dangling pointer accesses
646 * even if the previously used timerlist is freed.
648 void timer_deinit(QEMUTimer
*ts
);
654 * Free a timer (it must not be on the active list)
656 static inline void timer_free(QEMUTimer
*ts
)
665 * Delete a timer from the active list.
667 * This function is thread-safe but the timer and its timer list must not be
668 * freed while this function is running.
670 void timer_del(QEMUTimer
*ts
);
675 * @expire_time: the expiry time in nanoseconds
677 * Modify a timer to expire at @expire_time
679 * This function is thread-safe but the timer and its timer list must not be
680 * freed while this function is running.
682 void timer_mod_ns(QEMUTimer
*ts
, int64_t expire_time
);
685 * timer_mod_anticipate_ns:
687 * @expire_time: the expiry time in nanoseconds
689 * Modify a timer to expire at @expire_time or the current time,
690 * whichever comes earlier.
692 * This function is thread-safe but the timer and its timer list must not be
693 * freed while this function is running.
695 void timer_mod_anticipate_ns(QEMUTimer
*ts
, int64_t expire_time
);
700 * @expire_time: the expire time in the units associated with the timer
702 * Modify a timer to expiry at @expire_time, taking into
703 * account the scale associated with the timer.
705 * This function is thread-safe but the timer and its timer list must not be
706 * freed while this function is running.
708 void timer_mod(QEMUTimer
*ts
, int64_t expire_timer
);
711 * timer_mod_anticipate:
713 * @expire_time: the expiry time in nanoseconds
715 * Modify a timer to expire at @expire_time or the current time, whichever
716 * comes earlier, taking into account the scale associated with the timer.
718 * This function is thread-safe but the timer and its timer list must not be
719 * freed while this function is running.
721 void timer_mod_anticipate(QEMUTimer
*ts
, int64_t expire_time
);
727 * Determines whether a timer is pending (i.e. is on the
728 * active list of timers, whether or not it has not yet expired).
730 * Returns: true if the timer is pending
732 bool timer_pending(QEMUTimer
*ts
);
737 * @current_time: the current time
739 * Determines whether a timer has expired.
741 * Returns: true if the timer has expired
743 bool timer_expired(QEMUTimer
*timer_head
, int64_t current_time
);
746 * timer_expire_time_ns:
749 * Determine the expiry time of a timer
751 * Returns: the expiry time in nanoseconds
753 uint64_t timer_expire_time_ns(QEMUTimer
*ts
);
760 * Read a timer @ts from a file @f
762 void timer_get(QEMUFile
*f
, QEMUTimer
*ts
);
769 void timer_put(QEMUFile
*f
, QEMUTimer
*ts
);
772 * General utility functions
776 * qemu_timeout_ns_to_ms:
777 * @ns: nanosecond timeout value
779 * Convert a nanosecond timeout value (or -1) to
780 * a millisecond value (or -1), always rounding up.
782 * Returns: millisecond timeout value
784 int qemu_timeout_ns_to_ms(int64_t ns
);
788 * @fds: Array of file descriptors
789 * @nfds: number of file descriptors
790 * @timeout: timeout in nanoseconds
792 * Perform a poll like g_poll but with a timeout in nanoseconds.
793 * See g_poll documentation for further details.
795 * Returns: number of fds ready
797 int qemu_poll_ns(GPollFD
*fds
, guint nfds
, int64_t timeout
);
800 * qemu_soonest_timeout:
801 * @timeout1: first timeout in nanoseconds (or -1 for infinite)
802 * @timeout2: second timeout in nanoseconds (or -1 for infinite)
804 * Calculates the soonest of two timeout values. -1 means infinite, which
805 * is later than any other value.
807 * Returns: soonest timeout value in nanoseconds (or -1 for infinite)
809 static inline int64_t qemu_soonest_timeout(int64_t timeout1
, int64_t timeout2
)
811 /* we can abuse the fact that -1 (which means infinite) is a maximal
812 * value when cast to unsigned. As this is disgusting, it's kept in
813 * one inline function.
815 return ((uint64_t) timeout1
< (uint64_t) timeout2
) ? timeout1
: timeout2
;
821 * Initialise the clock & timer infrastructure
823 void init_clocks(QEMUTimerListNotifyCB
*notify_cb
);
825 int64_t cpu_get_ticks(void);
826 /* Caller must hold BQL */
827 void cpu_enable_ticks(void);
828 /* Caller must hold BQL */
829 void cpu_disable_ticks(void);
831 static inline int64_t get_max_clock_jump(void)
833 /* This should be small enough to prevent excessive interrupts from being
834 * generated by the RTC on clock jumps, but large enough to avoid frequent
835 * unnecessary resets in idle VMs.
837 return 60 * NANOSECONDS_PER_SECOND
;
841 * Low level clock functions
844 /* get host real time in nanosecond */
845 static inline int64_t get_clock_realtime(void)
849 gettimeofday(&tv
, NULL
);
850 return tv
.tv_sec
* 1000000000LL + (tv
.tv_usec
* 1000);
853 /* Warning: don't insert tracepoints into these functions, they are
854 also used by simpletrace backend and tracepoints would cause
855 an infinite recursion! */
857 extern int64_t clock_freq
;
859 static inline int64_t get_clock(void)
862 QueryPerformanceCounter(&ti
);
863 return muldiv64(ti
.QuadPart
, NANOSECONDS_PER_SECOND
, clock_freq
);
868 extern int use_rt_clock
;
870 static inline int64_t get_clock(void)
872 #ifdef CLOCK_MONOTONIC
875 clock_gettime(CLOCK_MONOTONIC
, &ts
);
876 return ts
.tv_sec
* 1000000000LL + ts
.tv_nsec
;
880 /* XXX: using gettimeofday leads to problems if the date
881 changes, so it should be avoided. */
882 return get_clock_realtime();
888 int64_t cpu_get_icount_raw(void);
889 int64_t cpu_get_icount(void);
890 int64_t cpu_get_clock(void);
891 int64_t cpu_icount_to_ns(int64_t icount
);
892 void cpu_update_icount(CPUState
*cpu
);
894 /*******************************************/
895 /* host CPU ticks (if available) */
897 #if defined(_ARCH_PPC)
899 static inline int64_t cpu_get_host_ticks(void)
903 /* This reads timebase in one 64bit go and includes Cell workaround from:
904 http://ozlabs.org/pipermail/linuxppc-dev/2006-October/027052.html
906 __asm__
__volatile__ ("mftb %0\n\t"
911 /* http://ozlabs.org/pipermail/linuxppc-dev/1999-October/003889.html */
913 __asm__
__volatile__ ("mfspr %1,269\n\t" /* mftbu */
914 "mfspr %L0,268\n\t" /* mftb */
915 "mfspr %0,269\n\t" /* mftbu */
918 : "=r" (retval
), "=r" (junk
));
923 #elif defined(__i386__)
925 static inline int64_t cpu_get_host_ticks(void)
928 asm volatile ("rdtsc" : "=A" (val
));
932 #elif defined(__x86_64__)
934 static inline int64_t cpu_get_host_ticks(void)
938 asm volatile("rdtsc" : "=a" (low
), "=d" (high
));
945 #elif defined(__hppa__)
947 static inline int64_t cpu_get_host_ticks(void)
950 asm volatile ("mfctl %%cr16, %0" : "=r"(val
));
954 #elif defined(__s390__)
956 static inline int64_t cpu_get_host_ticks(void)
959 asm volatile("stck 0(%1)" : "=m" (val
) : "a" (&val
) : "cc");
963 #elif defined(__sparc__)
965 static inline int64_t cpu_get_host_ticks (void)
969 asm volatile("rd %%tick,%0" : "=r"(rval
));
972 /* We need an %o or %g register for this. For recent enough gcc
973 there is an "h" constraint for that. Don't bother with that. */
981 asm volatile("rd %%tick,%%g1; srlx %%g1,32,%0; mov %%g1,%1"
982 : "=r"(rval
.i32
.high
), "=r"(rval
.i32
.low
) : : "g1");
987 #elif defined(__mips__) && \
988 ((defined(__mips_isa_rev) && __mips_isa_rev >= 2) || defined(__linux__))
990 * binutils wants to use rdhwr only on mips32r2
991 * but as linux kernel emulate it, it's fine
995 #define MIPS_RDHWR(rd, value) { \
996 __asm__ __volatile__ (".set push\n\t" \
997 ".set mips32r2\n\t" \
998 "rdhwr %0, "rd"\n\t" \
1003 static inline int64_t cpu_get_host_ticks(void)
1005 /* On kernels >= 2.6.25 rdhwr <reg>, $2 and $3 are emulated */
1007 static uint32_t cyc_per_count
= 0;
1009 if (!cyc_per_count
) {
1010 MIPS_RDHWR("$3", cyc_per_count
);
1013 MIPS_RDHWR("$2", count
);
1014 return (int64_t)(count
* cyc_per_count
);
1017 #elif defined(__alpha__)
1019 static inline int64_t cpu_get_host_ticks(void)
1024 asm volatile("rpcc %0" : "=r"(cc
));
1031 /* The host CPU doesn't have an easily accessible cycle counter.
1032 Just return a monotonically increasing value. This will be
1033 totally wrong, but hopefully better than nothing. */
1034 static inline int64_t cpu_get_host_ticks(void)
1040 #ifdef CONFIG_PROFILER
1041 static inline int64_t profile_getclock(void)
1046 extern int64_t dev_time
;