[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 10/17] timer: extract timer_mod_ns_locked and timerli
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 10/17] timer: extract timer_mod_ns_locked and timerlist_rearm |
Date: |
Thu, 17 Oct 2013 17:48:48 +0200 |
These will be reused in timer_mod_anticipate functions.
Reviewed-by: Alex Bligh <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
qemu-timer.c | 51 ++++++++++++++++++++++++++++++++-------------------
1 file changed, 32 insertions(+), 19 deletions(-)
diff --git a/qemu-timer.c b/qemu-timer.c
index 2b533da..0305ad5 100644
--- a/qemu-timer.c
+++ b/qemu-timer.c
@@ -355,6 +355,34 @@ static void timer_del_locked(QEMUTimerList *timer_list,
QEMUTimer *ts)
}
}
+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. */
+ qemu_clock_warp(timer_list->clock->type);
+ timerlist_notify(timer_list);
+}
+
/* stop a timer, but do not dealloc it */
void timer_del(QEMUTimer *ts)
{
@@ -370,30 +398,15 @@ void timer_del(QEMUTimer *ts)
void timer_mod_ns(QEMUTimer *ts, int64_t expire_time)
{
QEMUTimerList *timer_list = ts->timer_list;
- QEMUTimer **pt, *t;
+ bool rearm;
qemu_mutex_lock(&timer_list->active_timers_lock);
timer_del_locked(timer_list, ts);
-
- /* 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;
+ rearm = timer_mod_ns_locked(timer_list, ts, expire_time);
qemu_mutex_unlock(&timer_list->active_timers_lock);
- /* Rearm if necessary */
- if (pt == &timer_list->active_timers) {
- /* Interrupt execution to force deadline recalculation. */
- qemu_clock_warp(timer_list->clock->type);
- timerlist_notify(timer_list);
+ if (rearm) {
+ timerlist_rearm(timer_list);
}
}
--
1.8.3.1
- [Qemu-devel] [PULL 00/17] Memory/threading changes for 1.7, Paolo Bonzini, 2013/10/17
- [Qemu-devel] [PULL 01/17] memory: fix 128 arithmetic in info mtree, Paolo Bonzini, 2013/10/17
- [Qemu-devel] [PULL 02/17] compatfd: switch to QemuThread, Paolo Bonzini, 2013/10/17
- [Qemu-devel] [PULL 04/17] cirrus: Mark vga io region as coalesced MMIO flushing, Paolo Bonzini, 2013/10/17
- [Qemu-devel] [PULL 05/17] vga: Mark relevant portio lists regions as coalesced MMIO flushing, Paolo Bonzini, 2013/10/17
- [Qemu-devel] [PULL 03/17] portio: Allow to mark portio lists as coalesced MMIO flushing, Paolo Bonzini, 2013/10/17
- [Qemu-devel] [PULL 10/17] timer: extract timer_mod_ns_locked and timerlist_rearm,
Paolo Bonzini <=
- [Qemu-devel] [PULL 11/17] timer: add timer_mod_anticipate and timer_mod_anticipate_ns, Paolo Bonzini, 2013/10/17
- [Qemu-devel] [PULL 07/17] timer: protect timers_state's clock with seqlock, Paolo Bonzini, 2013/10/17
- [Qemu-devel] [PULL 06/17] seqlock: introduce read-write seqlock, Paolo Bonzini, 2013/10/17
- [Qemu-devel] [PULL 08/17] qemu-thread: add QemuEvent, Paolo Bonzini, 2013/10/17
- [Qemu-devel] [PULL 12/17] icount: use cpu_get_icount() directly, Paolo Bonzini, 2013/10/17
- [Qemu-devel] [PULL 09/17] timer: make qemu_clock_enable sync between disable and timer's cb, Paolo Bonzini, 2013/10/17
- [Qemu-devel] [PULL 15/17] icount: document (future) locking rules for icount, Paolo Bonzini, 2013/10/17
- [Qemu-devel] [PULL 13/17] icount: reorganize icount_warp_rt, Paolo Bonzini, 2013/10/17
- [Qemu-devel] [PULL 14/17] icount: prepare the code for future races in calling qemu_clock_warp, Paolo Bonzini, 2013/10/17
- [Qemu-devel] [PULL 16/17] icount: make it thread-safe, Paolo Bonzini, 2013/10/17