mirror of
https://github.com/yuzu-emu/unicorn.git
synced 2025-06-29 11:29:39 +00:00
timer is redundant
This commit is contained in:
parent
6daa8581cd
commit
fff532fc20
|
@ -178,11 +178,13 @@ static void apic_pre_save(APICCommonState *s)
|
||||||
|
|
||||||
static void apic_post_load(APICCommonState *s)
|
static void apic_post_load(APICCommonState *s)
|
||||||
{
|
{
|
||||||
|
#if 0
|
||||||
if (s->timer_expiry != -1) {
|
if (s->timer_expiry != -1) {
|
||||||
timer_mod(s->timer, s->timer_expiry);
|
timer_mod(s->timer, s->timer_expiry);
|
||||||
} else {
|
} else {
|
||||||
timer_del(s->timer);
|
timer_del(s->timer);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static int apic_realize(struct uc_struct *uc, DeviceState *dev, Error **errp)
|
static int apic_realize(struct uc_struct *uc, DeviceState *dev, Error **errp)
|
||||||
|
|
|
@ -152,7 +152,7 @@ void apic_init_reset(struct uc_struct *uc, DeviceState *dev)
|
||||||
s->wait_for_sipi = !cpu_is_bsp(s->cpu);
|
s->wait_for_sipi = !cpu_is_bsp(s->cpu);
|
||||||
|
|
||||||
if (s->timer) {
|
if (s->timer) {
|
||||||
timer_del(s->timer);
|
// timer_del(s->timer);
|
||||||
}
|
}
|
||||||
s->timer_expiry = -1;
|
s->timer_expiry = -1;
|
||||||
|
|
||||||
|
|
|
@ -105,314 +105,6 @@ static inline int64_t qemu_clock_get_us(QEMUClockType type)
|
||||||
return qemu_clock_get_ns(type) / SCALE_US;
|
return qemu_clock_get_ns(type) / SCALE_US;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* QEMUTimerList
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* timerlist_new:
|
|
||||||
* @type: the clock type to associate with the timerlist
|
|
||||||
* @cb: the callback to call on notification
|
|
||||||
* @opaque: the opaque pointer to pass to the callback
|
|
||||||
*
|
|
||||||
* Create a new timerlist associated with the clock of
|
|
||||||
* type @type.
|
|
||||||
*
|
|
||||||
* Returns: a pointer to the QEMUTimerList created
|
|
||||||
*/
|
|
||||||
QEMUTimerList *timerlist_new(QEMUClockType type,
|
|
||||||
QEMUTimerListNotifyCB *cb, void *opaque);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* timerlist_has_timers:
|
|
||||||
* @timer_list: the timer list to operate on
|
|
||||||
*
|
|
||||||
* Determine whether a timer list has active timers
|
|
||||||
*
|
|
||||||
* Note that this function should not be used when other threads also access
|
|
||||||
* the timer list. The return value may be outdated by the time it is acted
|
|
||||||
* upon.
|
|
||||||
*
|
|
||||||
* Returns: true if the timer list has timers.
|
|
||||||
*/
|
|
||||||
bool timerlist_has_timers(QEMUTimerList *timer_list);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* timerlist_expired:
|
|
||||||
* @timer_list: the timer list to operate on
|
|
||||||
*
|
|
||||||
* Determine whether a timer list has any timers which
|
|
||||||
* are expired.
|
|
||||||
*
|
|
||||||
* Returns: true if the timer list has timers which
|
|
||||||
* have expired.
|
|
||||||
*/
|
|
||||||
bool timerlist_expired(QEMUTimerList *timer_list);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* timerlist_deadline_ns:
|
|
||||||
* @timer_list: the timer list to operate on
|
|
||||||
*
|
|
||||||
* Determine the deadline for a timer_list, i.e.
|
|
||||||
* the number of nanoseconds until the first timer
|
|
||||||
* expires. Return -1 if there are no timers.
|
|
||||||
*
|
|
||||||
* Returns: the number of nanoseconds until the earliest
|
|
||||||
* timer expires -1 if none
|
|
||||||
*/
|
|
||||||
int64_t timerlist_deadline_ns(QEMUTimerList *timer_list);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* timerlist_get_clock:
|
|
||||||
* @timer_list: the timer list to operate on
|
|
||||||
*
|
|
||||||
* Determine the clock type associated with a timer list.
|
|
||||||
*
|
|
||||||
* Returns: the clock type associated with the
|
|
||||||
* timer list.
|
|
||||||
*/
|
|
||||||
QEMUClockType timerlist_get_clock(QEMUTimerList *timer_list);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* timerlist_run_timers:
|
|
||||||
* @timer_list: the timer list to use
|
|
||||||
*
|
|
||||||
* Call all expired timers associated with the timer list.
|
|
||||||
*
|
|
||||||
* Returns: true if any timer expired
|
|
||||||
*/
|
|
||||||
bool timerlist_run_timers(QEMUTimerList *timer_list);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* timerlist_notify:
|
|
||||||
* @timer_list: the timer list to use
|
|
||||||
*
|
|
||||||
* call the notifier callback associated with the timer list.
|
|
||||||
*/
|
|
||||||
void timerlist_notify(QEMUTimerList *timer_list);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* QEMUTimerListGroup
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* timerlistgroup_init:
|
|
||||||
* @tlg: the timer list group
|
|
||||||
* @cb: the callback to call when a notify is required
|
|
||||||
* @opaque: the opaque pointer to be passed to the callback.
|
|
||||||
*
|
|
||||||
* Initialise a timer list group. This must already be
|
|
||||||
* allocated in memory and zeroed. The notifier callback is
|
|
||||||
* called whenever a clock in the timer list group is
|
|
||||||
* reenabled or whenever a timer associated with any timer
|
|
||||||
* list is modified. If @cb is specified as null, qemu_notify()
|
|
||||||
* is used instead.
|
|
||||||
*/
|
|
||||||
void timerlistgroup_init(QEMUTimerListGroup *tlg,
|
|
||||||
QEMUTimerListNotifyCB *cb, void *opaque);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* timerlistgroup_deinit:
|
|
||||||
* @tlg: the timer list group
|
|
||||||
*
|
|
||||||
* Deinitialise a timer list group. This must already be
|
|
||||||
* initialised. Note the memory is not freed.
|
|
||||||
*/
|
|
||||||
void timerlistgroup_deinit(QEMUTimerListGroup *tlg);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* timerlistgroup_run_timers:
|
|
||||||
* @tlg: the timer list group
|
|
||||||
*
|
|
||||||
* Run the timers associated with a timer list group.
|
|
||||||
* This will run timers on multiple clocks.
|
|
||||||
*
|
|
||||||
* Returns: true if any timer callback ran
|
|
||||||
*/
|
|
||||||
bool timerlistgroup_run_timers(QEMUTimerListGroup *tlg);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* timerlistgroup_deadline_ns:
|
|
||||||
* @tlg: the timer list group
|
|
||||||
*
|
|
||||||
* Determine the deadline of the soonest timer to
|
|
||||||
* expire associated with any timer list linked to
|
|
||||||
* the timer list group. Only clocks suitable for
|
|
||||||
* deadline calculation are included.
|
|
||||||
*
|
|
||||||
* Returns: the deadline in nanoseconds or -1 if no
|
|
||||||
* timers are to expire.
|
|
||||||
*/
|
|
||||||
int64_t timerlistgroup_deadline_ns(QEMUTimerListGroup *tlg);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* QEMUTimer
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* timer_init:
|
|
||||||
* @ts: the timer to be initialised
|
|
||||||
* @timer_list: the timer list to attach the timer to
|
|
||||||
* @scale: the scale value for the timer
|
|
||||||
* @cb: the callback to be called when the timer expires
|
|
||||||
* @opaque: the opaque pointer to be passed to the callback
|
|
||||||
*
|
|
||||||
* Initialise a new timer and associate it with @timer_list.
|
|
||||||
* The caller is responsible for allocating the memory.
|
|
||||||
*
|
|
||||||
* You need not call an explicit deinit call. Simply make
|
|
||||||
* sure it is not on a list with timer_del.
|
|
||||||
*/
|
|
||||||
void timer_init(QEMUTimer *ts,
|
|
||||||
QEMUTimerList *timer_list, int scale,
|
|
||||||
QEMUTimerCB *cb, void *opaque);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* timer_new_tl:
|
|
||||||
* @timer_list: the timer list to attach the timer to
|
|
||||||
* @scale: the scale value for the timer
|
|
||||||
* @cb: the callback to be called when the timer expires
|
|
||||||
* @opaque: the opaque pointer to be passed to the callback
|
|
||||||
*
|
|
||||||
* Creeate a new timer and associate it with @timer_list.
|
|
||||||
* The memory is allocated by the function.
|
|
||||||
*
|
|
||||||
* This is not the preferred interface unless you know you
|
|
||||||
* are going to call timer_free. Use timer_init instead.
|
|
||||||
*
|
|
||||||
* Returns: a pointer to the timer
|
|
||||||
*/
|
|
||||||
static inline QEMUTimer *timer_new_tl(QEMUTimerList *timer_list,
|
|
||||||
int scale,
|
|
||||||
QEMUTimerCB *cb,
|
|
||||||
void *opaque)
|
|
||||||
{
|
|
||||||
QEMUTimer *ts = g_malloc0(sizeof(QEMUTimer));
|
|
||||||
timer_init(ts, timer_list, scale, cb, opaque);
|
|
||||||
return ts;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* timer_free:
|
|
||||||
* @ts: the timer
|
|
||||||
*
|
|
||||||
* Free a timer (it must not be on the active list)
|
|
||||||
*/
|
|
||||||
void timer_free(QEMUTimer *ts);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* timer_del:
|
|
||||||
* @ts: the timer
|
|
||||||
*
|
|
||||||
* Delete a timer from the active list.
|
|
||||||
*
|
|
||||||
* This function is thread-safe but the timer and its timer list must not be
|
|
||||||
* freed while this function is running.
|
|
||||||
*/
|
|
||||||
void timer_del(QEMUTimer *ts);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* timer_mod_ns:
|
|
||||||
* @ts: the timer
|
|
||||||
* @expire_time: the expiry time in nanoseconds
|
|
||||||
*
|
|
||||||
* Modify a timer to expire at @expire_time
|
|
||||||
*
|
|
||||||
* This function is thread-safe but the timer and its timer list must not be
|
|
||||||
* freed while this function is running.
|
|
||||||
*/
|
|
||||||
void timer_mod_ns(QEMUTimer *ts, int64_t expire_time);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* timer_mod_anticipate_ns:
|
|
||||||
* @ts: the timer
|
|
||||||
* @expire_time: the expiry time in nanoseconds
|
|
||||||
*
|
|
||||||
* Modify a timer to expire at @expire_time or the current time,
|
|
||||||
* whichever comes earlier.
|
|
||||||
*
|
|
||||||
* This function is thread-safe but the timer and its timer list must not be
|
|
||||||
* freed while this function is running.
|
|
||||||
*/
|
|
||||||
void timer_mod_anticipate_ns(QEMUTimer *ts, int64_t expire_time);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* timer_mod:
|
|
||||||
* @ts: the timer
|
|
||||||
* @expire_time: the expire time in the units associated with the timer
|
|
||||||
*
|
|
||||||
* Modify a timer to expiry at @expire_time, taking into
|
|
||||||
* account the scale associated with the timer.
|
|
||||||
*
|
|
||||||
* This function is thread-safe but the timer and its timer list must not be
|
|
||||||
* freed while this function is running.
|
|
||||||
*/
|
|
||||||
void timer_mod(QEMUTimer *ts, int64_t expire_timer);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* timer_mod_anticipate:
|
|
||||||
* @ts: the timer
|
|
||||||
* @expire_time: the expiry time in nanoseconds
|
|
||||||
*
|
|
||||||
* Modify a timer to expire at @expire_time or the current time, whichever
|
|
||||||
* comes earlier, taking into account the scale associated with the timer.
|
|
||||||
*
|
|
||||||
* This function is thread-safe but the timer and its timer list must not be
|
|
||||||
* freed while this function is running.
|
|
||||||
*/
|
|
||||||
void timer_mod_anticipate(QEMUTimer *ts, int64_t expire_time);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* timer_pending:
|
|
||||||
* @ts: the timer
|
|
||||||
*
|
|
||||||
* Determines whether a timer is pending (i.e. is on the
|
|
||||||
* active list of timers, whether or not it has not yet expired).
|
|
||||||
*
|
|
||||||
* Returns: true if the timer is pending
|
|
||||||
*/
|
|
||||||
bool timer_pending(QEMUTimer *ts);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* timer_expired:
|
|
||||||
* @ts: the timer
|
|
||||||
*
|
|
||||||
* Determines whether a timer has expired.
|
|
||||||
*
|
|
||||||
* Returns: true if the timer has expired
|
|
||||||
*/
|
|
||||||
bool timer_expired(QEMUTimer *timer_head, int64_t current_time);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* timer_expire_time_ns:
|
|
||||||
* @ts: the timer
|
|
||||||
*
|
|
||||||
* Determine the expiry time of a timer
|
|
||||||
*
|
|
||||||
* Returns: the expiry time in nanoseconds
|
|
||||||
*/
|
|
||||||
uint64_t timer_expire_time_ns(QEMUTimer *ts);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* timer_get:
|
|
||||||
* @f: the file
|
|
||||||
* @ts: the timer
|
|
||||||
*
|
|
||||||
* Read a timer @ts from a file @f
|
|
||||||
*/
|
|
||||||
void timer_get(QEMUFile *f, QEMUTimer *ts);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* timer_put:
|
|
||||||
* @f: the file
|
|
||||||
* @ts: the timer
|
|
||||||
*/
|
|
||||||
void timer_put(QEMUFile *f, QEMUTimer *ts);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* General utility functions
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* qemu_timeout_ns_to_ms:
|
* qemu_timeout_ns_to_ms:
|
||||||
* @ns: nanosecond timeout value
|
* @ns: nanosecond timeout value
|
||||||
|
|
|
@ -55,21 +55,6 @@ typedef struct QEMUClock {
|
||||||
|
|
||||||
static QEMUClock qemu_clocks[QEMU_CLOCK_MAX];
|
static QEMUClock qemu_clocks[QEMU_CLOCK_MAX];
|
||||||
|
|
||||||
/* A QEMUTimerList is a list of timers attached to a clock. More
|
|
||||||
* than one QEMUTimerList can be attached to each clock, for instance
|
|
||||||
* used by different AioContexts / threads. Each clock also has
|
|
||||||
* a list of the QEMUTimerLists associated with it, in order that
|
|
||||||
* reenabling the clock can call all the notifiers.
|
|
||||||
*/
|
|
||||||
|
|
||||||
struct QEMUTimerList {
|
|
||||||
QEMUClock *clock;
|
|
||||||
QEMUTimer *active_timers;
|
|
||||||
QLIST_ENTRY(QEMUTimerList) list;
|
|
||||||
QEMUTimerListNotifyCB *notify_cb;
|
|
||||||
void *notify_opaque;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* qemu_clock_ptr:
|
* qemu_clock_ptr:
|
||||||
* @type: type of clock
|
* @type: type of clock
|
||||||
|
@ -83,117 +68,6 @@ static inline QEMUClock *qemu_clock_ptr(QEMUClockType type)
|
||||||
return &qemu_clocks[type];
|
return &qemu_clocks[type];
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool timer_expired_ns(QEMUTimer *timer_head, int64_t current_time)
|
|
||||||
{
|
|
||||||
return timer_head && (timer_head->expire_time <= current_time);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool timerlist_has_timers(QEMUTimerList *timer_list)
|
|
||||||
{
|
|
||||||
return !!timer_list->active_timers;
|
|
||||||
}
|
|
||||||
|
|
||||||
void timerlist_notify(QEMUTimerList *timer_list)
|
|
||||||
{
|
|
||||||
if (timer_list->notify_cb) {
|
|
||||||
timer_list->notify_cb(timer_list->notify_opaque);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void timer_init(QEMUTimer *ts,
|
|
||||||
QEMUTimerList *timer_list, int scale,
|
|
||||||
QEMUTimerCB *cb, void *opaque)
|
|
||||||
{
|
|
||||||
ts->timer_list = timer_list;
|
|
||||||
ts->cb = cb;
|
|
||||||
ts->opaque = opaque;
|
|
||||||
ts->scale = scale;
|
|
||||||
ts->expire_time = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void timer_del_locked(QEMUTimerList *timer_list, QEMUTimer *ts)
|
|
||||||
{
|
|
||||||
QEMUTimer **pt, *t;
|
|
||||||
|
|
||||||
ts->expire_time = -1;
|
|
||||||
pt = &timer_list->active_timers;
|
|
||||||
for(;;) {
|
|
||||||
t = *pt;
|
|
||||||
if (!t)
|
|
||||||
break;
|
|
||||||
if (t == ts) {
|
|
||||||
*pt = t->next;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
pt = &t->next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool timer_mod_ns_locked(QEMUTimerList *timer_list,
|
|
||||||
QEMUTimer *ts, int64_t expire_time)
|
|
||||||
{
|
|
||||||
QEMUTimer **pt, *t;
|
|
||||||
|
|
||||||
/* add the timer in the sorted list */
|
|
||||||
pt = &timer_list->active_timers;
|
|
||||||
for (;;) {
|
|
||||||
t = *pt;
|
|
||||||
if (!timer_expired_ns(t, expire_time)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
pt = &t->next;
|
|
||||||
}
|
|
||||||
ts->expire_time = MAX(expire_time, 0);
|
|
||||||
ts->next = *pt;
|
|
||||||
*pt = ts;
|
|
||||||
|
|
||||||
return pt == &timer_list->active_timers;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void timerlist_rearm(QEMUTimerList *timer_list)
|
|
||||||
{
|
|
||||||
/* Interrupt execution to force deadline recalculation. */
|
|
||||||
timerlist_notify(timer_list);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* stop a timer, but do not dealloc it */
|
|
||||||
void timer_del(QEMUTimer *ts)
|
|
||||||
{
|
|
||||||
QEMUTimerList *timer_list = ts->timer_list;
|
|
||||||
|
|
||||||
timer_del_locked(timer_list, ts);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* modify the current timer so that it will be fired when current_time
|
|
||||||
>= expire_time. The corresponding callback will be called. */
|
|
||||||
void timer_mod_ns(QEMUTimer *ts, int64_t expire_time)
|
|
||||||
{
|
|
||||||
QEMUTimerList *timer_list = ts->timer_list;
|
|
||||||
bool rearm;
|
|
||||||
|
|
||||||
timer_del_locked(timer_list, ts);
|
|
||||||
rearm = timer_mod_ns_locked(timer_list, ts, expire_time);
|
|
||||||
|
|
||||||
if (rearm) {
|
|
||||||
timerlist_rearm(timer_list);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void timer_mod(QEMUTimer *ts, int64_t expire_time)
|
|
||||||
{
|
|
||||||
timer_mod_ns(ts, expire_time * ts->scale);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool timer_pending(QEMUTimer *ts)
|
|
||||||
{
|
|
||||||
return ts->expire_time >= 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint64_t timer_expire_time_ns(QEMUTimer *ts)
|
|
||||||
{
|
|
||||||
return timer_pending(ts) ? ts->expire_time : -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* return the host CPU cycle counter and handle stop/restart */
|
/* return the host CPU cycle counter and handle stop/restart */
|
||||||
int64_t cpu_get_ticks(void)
|
int64_t cpu_get_ticks(void)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue