qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCHv1 1/4] Timers: add debugging macros wrapping timer f


From: Alex Bligh
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

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 <address@hidden>
---
 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 via email to

[Prev in Thread] Current Thread [Next in Thread]