qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Alex Bligh <alex@alex.org.uk>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
	Anthony Liguori <aliguori@us.ibm.com>,
	Alex Bligh <alex@alex.org.uk>,
	Jan Kiszka <jan.kiszka@siemens.com>,
	liu ping fan <qemulist@gmail.com>,
	Stefan Hajnoczi <stefanha@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>,
	rth@twiddle.net
Subject: [Qemu-devel] [RFC] [PATCH] aio / timers pt2: Replace main_loop_tlg with qemu_dummy_timer_ctx
Date: Sat, 10 Aug 2013 11:54:06 +0100	[thread overview]
Message-ID: <1376132046-31499-1-git-send-email-alex@alex.org.uk> (raw)

Currently we use a separate timer list group (main_loop_tlg)
for the main loop. This patch replaces this with a dummy AioContext
used just for timers in the main loop.

Signed-off-by: Alex Bligh <alex@alex.org.uk>
---
 include/block/aio.h  |    3 +++
 include/qemu/timer.h |    9 ++-------
 main-loop.c          |    2 +-
 qemu-timer.c         |   27 +++++++++++++++++++++------
 4 files changed, 27 insertions(+), 14 deletions(-)

diff --git a/include/block/aio.h b/include/block/aio.h
index b08de19..50a064d 100644
--- a/include/block/aio.h
+++ b/include/block/aio.h
@@ -81,6 +81,9 @@ typedef struct AioContext {
 /* Returns 1 if there are still outstanding AIO requests; 0 otherwise */
 typedef int (AioFlushEventNotifierHandler)(EventNotifier *e);
 
+/* Dummy AioContext for main loop timers */
+extern AioContext *qemu_dummy_timer_ctx;
+
 /**
  * aio_context_new: Allocate a new AioContext.
  *
diff --git a/include/qemu/timer.h b/include/qemu/timer.h
index 716f50b..aac3141 100644
--- a/include/qemu/timer.h
+++ b/include/qemu/timer.h
@@ -58,8 +58,6 @@ typedef struct QEMUTimer {
     int scale;
 } QEMUTimer;
 
-extern QEMUTimerListGroup main_loop_tlg;
-
 /*
  * QEMUClockType
  */
@@ -437,11 +435,8 @@ static inline QEMUTimer *timer_new_tl(QEMUTimerList *timer_list,
  *
  * Returns: a pointer to the timer
  */
-static inline QEMUTimer *timer_new(QEMUClockType type, int scale,
-                                   QEMUTimerCB *cb, void *opaque)
-{
-    return timer_new_tl(main_loop_tlg[type], scale, cb, opaque);
-}
+QEMUTimer *timer_new(QEMUClockType type, int scale,
+                     QEMUTimerCB *cb, void *opaque);
 
 /**
  * timer_new_ns:
diff --git a/main-loop.c b/main-loop.c
index 1f24ac1..f1ee0e5 100644
--- a/main-loop.c
+++ b/main-loop.c
@@ -479,7 +479,7 @@ int main_loop_wait(int nonblocking)
 
     timeout_ns = qemu_soonest_timeout(timeout_ns,
                                       timerlistgroup_deadline_ns(
-                                          main_loop_tlg));
+                                          qemu_dummy_timer_ctx->tlg));
 
     ret = os_host_main_loop_wait(timeout_ns);
     qemu_iohandler_poll(gpollfds, ret);
diff --git a/qemu-timer.c b/qemu-timer.c
index 0d36a21..1d1dcea 100644
--- a/qemu-timer.c
+++ b/qemu-timer.c
@@ -54,7 +54,8 @@ typedef struct QEMUClock {
     bool enabled;
 } QEMUClock;
 
-QEMUTimerListGroup main_loop_tlg;
+AioContext *qemu_dummy_timer_ctx;
+
 QEMUClock qemu_clocks[QEMU_CLOCK_MAX];
 
 /* A QEMUTimerList is a list of timers attached to a clock. More
@@ -123,7 +124,6 @@ static void qemu_clock_init(QEMUClockType type)
     clock->last = INT64_MIN;
     QLIST_INIT(&clock->timerlists);
     notifier_list_init(&clock->reset_notifiers);
-    main_loop_tlg[type] = timerlist_new(type, NULL, NULL);
 }
 
 bool qemu_clock_use_for_deadline(QEMUClockType type)
@@ -158,7 +158,7 @@ bool timerlist_has_timers(QEMUTimerList *timer_list)
 bool qemu_clock_has_timers(QEMUClockType type)
 {
     return timerlist_has_timers(
-        main_loop_tlg[type]);
+        qemu_dummy_timer_ctx->tlg[type]);
 }
 
 bool timerlist_expired(QEMUTimerList *timer_list)
@@ -171,7 +171,7 @@ bool timerlist_expired(QEMUTimerList *timer_list)
 bool qemu_clock_expired(QEMUClockType type)
 {
     return timerlist_expired(
-        main_loop_tlg[type]);
+        qemu_dummy_timer_ctx->tlg[type]);
 }
 
 /*
@@ -221,7 +221,7 @@ QEMUClockType timerlist_get_clock(QEMUTimerList *timer_list)
 
 QEMUTimerList *qemu_clock_get_main_loop_timerlist(QEMUClockType type)
 {
-    return main_loop_tlg[type];
+    return qemu_dummy_timer_ctx->tlg[type];
 }
 
 void timerlist_notify(QEMUTimerList *timer_list)
@@ -291,6 +291,19 @@ void timer_init(QEMUTimer *ts,
     ts->scale = scale;
 }
 
+QEMUTimer *timer_new(QEMUClockType type, int scale,
+                     QEMUTimerCB *cb, void *opaque)
+{
+    /* If this assert triggers, this is likely to mean
+     * that a timer is allocated prior to the dummy
+     * timer context being set up
+     */
+    assert(qemu_dummy_timer_ctx);
+
+    return timer_new_tl(qemu_dummy_timer_ctx->tlg[type],
+                        scale, cb, opaque);
+}
+
 void timer_free(QEMUTimer *ts)
 {
     g_free(ts);
@@ -397,7 +410,7 @@ bool timerlist_run_timers(QEMUTimerList *timer_list)
 
 bool qemu_clock_run_timers(QEMUClockType type)
 {
-    return timerlist_run_timers(main_loop_tlg[type]);
+    return timerlist_run_timers(qemu_dummy_timer_ctx->tlg[type]);
 }
 
 void timerlistgroup_init(QEMUTimerListGroup tlg,
@@ -486,6 +499,8 @@ void init_clocks(void)
         qemu_clock_init(type);
     }
 
+    qemu_dummy_timer_ctx = aio_context_new();
+
 #ifdef CONFIG_PRCTL_PR_SET_TIMERSLACK
     prctl(PR_SET_TIMERSLACK, 1, 0, 0, 0);
 #endif
-- 
1.7.9.5

                 reply	other threads:[~2013-08-10 10:54 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1376132046-31499-1-git-send-email-alex@alex.org.uk \
    --to=alex@alex.org.uk \
    --cc=aliguori@us.ibm.com \
    --cc=jan.kiszka@siemens.com \
    --cc=kwolf@redhat.com \
    --cc=morita.kazutaka@lab.ntt.co.jp \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemulist@gmail.com \
    --cc=rth@twiddle.net \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).