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] [PATCHv1 1/4] Timers: add debugging macros wrapping timer functions and debug structures
Date: Fri, 25 Oct 2013 23:30:31 +0100	[thread overview]
Message-ID: <1382740234-21345-2-git-send-email-alex@alex.org.uk> (raw)
In-Reply-To: <1382740234-21345-1-git-send-email-alex@alex.org.uk>

Add debugging versions of functions creating timers to record the
file and line number that they were called from. Add macros to
call these transparently. Add fields to timer struct to store
debugging information.

Note this patch contains one checkpatch.pl warning (space before
parenthesis) and a rather arcane double stringify macro. These
are copied from audio_int.h and I believe are to work around
compiler incompatibilities.

Signed-off-by: Alex Bligh <alex@alex.org.uk>
---
 include/block/aio.h  |   20 ++++++++++-----
 include/qemu/timer.h |   69 ++++++++++++++++++++++++++++++++++++--------------
 qemu-timer.c         |    8 +++---
 3 files changed, 69 insertions(+), 28 deletions(-)

diff --git a/include/block/aio.h b/include/block/aio.h
index 2efdf41..199728f 100644
--- a/include/block/aio.h
+++ b/include/block/aio.h
@@ -262,13 +262,17 @@ void qemu_aio_set_fd_handler(int fd,
  *
  * Returns: a pointer to the new timer
  */
-static inline QEMUTimer *aio_timer_new(AioContext *ctx, QEMUClockType type,
-                                       int scale,
-                                       QEMUTimerCB *cb, void *opaque)
+static inline QEMUTimer *aio_timer_new_dbg(AioContext *ctx, QEMUClockType type,
+                                           int scale,
+                                           QEMUTimerCB *cb, void *opaque,
+                                           const char *dbg)
 {
-    return timer_new_tl(ctx->tlg.tl[type], scale, cb, opaque);
+    return timer_new_tl_dbg(ctx->tlg.tl[type], scale, cb, opaque, dbg);
 }
 
+#define aio_timer_new(ctx, type, scale, opaque) \
+    aio_timer_new_dbg(ctx, type, scale, opaque, TIMER_DBG)
+
 /**
  * aio_timer_init:
  * @ctx: the aio context
@@ -284,9 +288,13 @@ static inline QEMUTimer *aio_timer_new(AioContext *ctx, QEMUClockType type,
 static inline void aio_timer_init(AioContext *ctx,
                                   QEMUTimer *ts, QEMUClockType type,
                                   int scale,
-                                  QEMUTimerCB *cb, void *opaque)
+                                  QEMUTimerCB *cb, void *opaque,
+                                  const char *dbg)
 {
-    timer_init(ts, ctx->tlg.tl[type], scale, cb, opaque);
+    timer_init_dbg(ts, ctx->tlg.tl[type], scale, cb, opaque, dbg);
 }
 
+#define aio_timer_init(ctx, ts, type, scale, cb, opaque) \
+    aio_timer_init(ctx, ts, type, scale, cb, opaque, TIMER_DBG)
+
 #endif
diff --git a/include/qemu/timer.h b/include/qemu/timer.h
index 5afcffc..d3ab5b0 100644
--- a/include/qemu/timer.h
+++ b/include/qemu/timer.h
@@ -11,6 +11,11 @@
 #define SCALE_US 1000
 #define SCALE_NS 1
 
+/* debugging macros */
+#define TIMER_STRINGIFY_(n) #n
+#define TIMER_STRINGIFY(n) TIMER_STRINGIFY_(n)
+#define TIMER_DBG __FILE__ ":" TIMER_STRINGIFY (__LINE__)
+
 /**
  * QEMUClockType:
  *
@@ -61,6 +66,12 @@ struct QEMUTimer {
     void *opaque;
     QEMUTimer *next;
     int scale;
+
+    /* these items are only used when debugging */
+    const char *dbg;
+    int64_t tot_deltas;
+    int64_t num_deltas;
+    int64_t num_short;
 };
 
 extern QEMUTimerListGroup main_loop_tlg;
@@ -415,9 +426,13 @@ int64_t timerlistgroup_deadline_ns(QEMUTimerListGroup *tlg);
  * 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);
+void timer_init_dbg(QEMUTimer *ts,
+                    QEMUTimerList *timer_list, int scale,
+                    QEMUTimerCB *cb, void *opaque,
+                    const char *dbg);
+
+#define timer_init(ts, timer_list, scale, cb, opaque) \
+    timer_init_dbg(ts, timer_list, scale, cb, opaque, TIMER_DBG)
 
 /**
  * timer_new_tl:
@@ -434,16 +449,20 @@ void timer_init(QEMUTimer *ts,
  *
  * Returns: a pointer to the timer
  */
-static inline QEMUTimer *timer_new_tl(QEMUTimerList *timer_list,
-                                      int scale,
-                                      QEMUTimerCB *cb,
-                                      void *opaque)
+static inline QEMUTimer *timer_new_tl_dbg(QEMUTimerList *timer_list,
+                                          int scale,
+                                          QEMUTimerCB *cb,
+                                          void *opaque,
+                                          const char *dbg)
 {
     QEMUTimer *ts = g_malloc0(sizeof(QEMUTimer));
-    timer_init(ts, timer_list, scale, cb, opaque);
+    timer_init_dbg(ts, timer_list, scale, cb, opaque, dbg);
     return ts;
 }
 
+#define timer_new_tl(timer_list, scale, cb, opaque) \
+    timer_new_tl_dbg(timer_list, scale, cb, opaque, TIMER_DBG)
+
 /**
  * timer_new:
  * @type: the clock type to use
@@ -456,12 +475,16 @@ 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)
+static inline QEMUTimer *timer_new_dbg(QEMUClockType type, int scale,
+                                       QEMUTimerCB *cb, void *opaque,
+                                       const char *dbg)
 {
-    return timer_new_tl(main_loop_tlg.tl[type], scale, cb, opaque);
+    return timer_new_tl_dbg(main_loop_tlg.tl[type], scale, cb, opaque, dbg);
 }
 
+#define timer_new(type, scale, cb, opaque) \
+    timer_new_dbg(type, scale, cb, opaque, TIMER_DBG)
+
 /**
  * timer_new_ns:
  * @clock: the clock to associate with the timer
@@ -473,12 +496,15 @@ static inline QEMUTimer *timer_new(QEMUClockType type, int scale,
  *
  * Returns: a pointer to the newly created timer
  */
-static inline QEMUTimer *timer_new_ns(QEMUClockType type, QEMUTimerCB *cb,
-                                      void *opaque)
+static inline QEMUTimer *timer_new_ns_dbg(QEMUClockType type, QEMUTimerCB *cb,
+                                          void *opaque, const char *dbg)
 {
-    return timer_new(type, SCALE_NS, cb, opaque);
+    return timer_new_dbg(type, SCALE_NS, cb, opaque, dbg);
 }
 
+#define timer_new_ns(type, cb, opaque) \
+    timer_new_ns_dbg(type, cb, opaque, TIMER_DBG)
+
 /**
  * timer_new_us:
  * @clock: the clock to associate with the timer
@@ -491,11 +517,14 @@ static inline QEMUTimer *timer_new_ns(QEMUClockType type, QEMUTimerCB *cb,
  * Returns: a pointer to the newly created timer
  */
 static inline QEMUTimer *timer_new_us(QEMUClockType type, QEMUTimerCB *cb,
-                                      void *opaque)
+                                      void *opaque, const char *dbg)
 {
-    return timer_new(type, SCALE_US, cb, opaque);
+    return timer_new_dbg(type, SCALE_US, cb, opaque, dbg);
 }
 
+#define timer_new_us(type, cb, opaque) \
+    timer_new_us_dbg(type, cb, opaque, TIMER_DBG)
+
 /**
  * timer_new_ms:
  * @clock: the clock to associate with the timer
@@ -507,11 +536,13 @@ static inline QEMUTimer *timer_new_us(QEMUClockType type, QEMUTimerCB *cb,
  *
  * Returns: a pointer to the newly created timer
  */
-static inline QEMUTimer *timer_new_ms(QEMUClockType type, QEMUTimerCB *cb,
-                                      void *opaque)
+static inline QEMUTimer *timer_new_ms_dbg(QEMUClockType type, QEMUTimerCB *cb,
+                                          void *opaque, const char *dbg)
 {
-    return timer_new(type, SCALE_MS, cb, opaque);
+    return timer_new_dbg(type, SCALE_MS, cb, opaque, dbg);
 }
+#define timer_new_ms(type, cb, opaque) \
+    timer_new_ms_dbg(type, cb, opaque, TIMER_DBG)
 
 /**
  * timer_free:
diff --git a/qemu-timer.c b/qemu-timer.c
index e15ce47..0e358ac 100644
--- a/qemu-timer.c
+++ b/qemu-timer.c
@@ -321,15 +321,17 @@ int qemu_poll_ns(GPollFD *fds, guint nfds, int64_t timeout)
 }
 
 
-void timer_init(QEMUTimer *ts,
-                QEMUTimerList *timer_list, int scale,
-                QEMUTimerCB *cb, void *opaque)
+void timer_init_dbg(QEMUTimer *ts,
+                    QEMUTimerList *timer_list, int scale,
+                    QEMUTimerCB *cb, void *opaque,
+                    const char *dbg)
 {
     ts->timer_list = timer_list;
     ts->cb = cb;
     ts->opaque = opaque;
     ts->scale = scale;
     ts->expire_time = -1;
+    ts->dbg = dbg;
 }
 
 void timer_free(QEMUTimer *ts)
-- 
1.7.9.5

  reply	other threads:[~2013-10-25 22:30 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-25 22:30 [Qemu-devel] [PATCHv1 0/4] Timers: add timer debugging through -timer-debug-log Alex Bligh
2013-10-25 22:30 ` Alex Bligh [this message]
2013-10-25 22:30 ` [Qemu-devel] [PATCHv1 2/4] Timers: add command line option -timer-debug-log Alex Bligh
2013-10-25 22:30 ` [Qemu-devel] [PATCHv1 3/4] Timers: Instrument timer_mod Alex Bligh
2013-10-25 22:30 ` [Qemu-devel] [PATCHv1 4/4] Timers: produce timer-debug-log file Alex Bligh
2013-10-25 23:00 ` [Qemu-devel] [PATCHv1 0/4] Timers: add timer debugging through -timer-debug-log Paolo Bonzini
2013-10-26  5:52   ` Alex Bligh
2013-10-26  7:18     ` Paolo Bonzini
2013-10-26  8:24       ` Alex Bligh
2013-10-26 17:11         ` Paolo Bonzini

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=1382740234-21345-2-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).