diff mbox

[2/2] trace: Trace write requests in virtio-blk, multiwrite, and paio_submit

Message ID 1274434947-2863-3-git-send-email-stefanha@linux.vnet.ibm.com
State New
Headers show

Commit Message

Stefan Hajnoczi May 21, 2010, 9:42 a.m. UTC
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
---
 block.c            |    7 +++++++
 hw/virtio-blk.c    |    6 ++++++
 posix-aio-compat.c |    2 ++
 trace.h            |   42 +++++++++++++++++++++++++++++++++++++++++-
 trace.py           |    8 ++++++++
 5 files changed, 64 insertions(+), 1 deletions(-)
diff mbox

Patch

diff --git a/block.c b/block.c
index bfe46e3..a7fb040 100644
--- a/block.c
+++ b/block.c
@@ -27,6 +27,7 @@ 
 #include "block_int.h"
 #include "module.h"
 #include "qemu-objects.h"
+#include "trace.h"
 
 #ifdef CONFIG_BSD
 #include <sys/types.h>
@@ -1913,6 +1914,8 @@  static void multiwrite_cb(void *opaque, int ret)
 {
     MultiwriteCB *mcb = opaque;
 
+    trace_multiwrite_cb(mcb, ret);
+
     if (ret < 0 && !mcb->error) {
         mcb->error = ret;
         multiwrite_user_cb(mcb);
@@ -2044,6 +2047,8 @@  int bdrv_aio_multiwrite(BlockDriverState *bs, BlockRequest *reqs, int num_reqs)
     // Check for mergable requests
     num_reqs = multiwrite_merge(bs, reqs, num_reqs, mcb);
 
+    trace_bdrv_aio_multiwrite(mcb, mcb->num_callbacks, num_reqs);
+
     // Run the aio requests
     for (i = 0; i < num_reqs; i++) {
         acb = bdrv_aio_writev(bs, reqs[i].sector, reqs[i].qiov,
@@ -2054,9 +2059,11 @@  int bdrv_aio_multiwrite(BlockDriverState *bs, BlockRequest *reqs, int num_reqs)
             // submitted yet. Otherwise we'll wait for the submitted AIOs to
             // complete and report the error in the callback.
             if (mcb->num_requests == 0) {
+                trace_bdrv_aio_multiwrite_earlyfail(mcb);
                 reqs[i].error = -EIO;
                 goto fail;
             } else {
+                trace_bdrv_aio_multiwrite_latefail(mcb, i);
                 mcb->num_requests++;
                 multiwrite_cb(mcb, -EIO);
                 break;
diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
index b05d15e..73b873e 100644
--- a/hw/virtio-blk.c
+++ b/hw/virtio-blk.c
@@ -13,6 +13,7 @@ 
 
 #include <qemu-common.h>
 #include <sysemu.h>
+#include "trace.h"
 #include "virtio-blk.h"
 #include "block_int.h"
 #ifdef __linux__
@@ -50,6 +51,8 @@  static void virtio_blk_req_complete(VirtIOBlockReq *req, int status)
 {
     VirtIOBlock *s = req->dev;
 
+    trace_virtio_blk_req_complete(req, status);
+
     req->in->status = status;
     virtqueue_push(s->vq, &req->elem, req->qiov.size + sizeof(*req->in));
     virtio_notify(&s->vdev, s->vq);
@@ -87,6 +90,8 @@  static void virtio_blk_rw_complete(void *opaque, int ret)
 {
     VirtIOBlockReq *req = opaque;
 
+    trace_virtio_blk_rw_complete(req, ret);
+
     if (ret) {
         int is_read = !(req->out->type & VIRTIO_BLK_T_OUT);
         if (virtio_blk_handle_rw_error(req, -ret, is_read))
@@ -270,6 +275,7 @@  static void virtio_blk_handle_write(BlockRequest *blkreq, int *num_writes,
     blkreq[*num_writes].cb = virtio_blk_rw_complete;
     blkreq[*num_writes].opaque = req;
     blkreq[*num_writes].error = 0;
+    trace_virtio_blk_handle_write(req, req->out->sector, req->qiov.size / 512);
 
     (*num_writes)++;
 }
diff --git a/posix-aio-compat.c b/posix-aio-compat.c
index b43c531..57d83f0 100644
--- a/posix-aio-compat.c
+++ b/posix-aio-compat.c
@@ -23,6 +23,7 @@ 
 #include <stdio.h>
 
 #include "qemu-queue.h"
+#include "trace.h"
 #include "osdep.h"
 #include "qemu-common.h"
 #include "block_int.h"
@@ -583,6 +584,7 @@  BlockDriverAIOCB *paio_submit(BlockDriverState *bs, int fd,
     acb->next = posix_aio_state->first_aio;
     posix_aio_state->first_aio = acb;
 
+    trace_paio_submit(acb, opaque, sector_num, nb_sectors, type);
     qemu_paio_submit(acb);
     return &acb->common;
 }
diff --git a/trace.h b/trace.h
index 144aa1e..3c4564f 100644
--- a/trace.h
+++ b/trace.h
@@ -1,5 +1,12 @@ 
 typedef enum {
-    TRACE_MAX
+    TRACE_MULTIWRITE_CB,
+    TRACE_BDRV_AIO_MULTIWRITE,
+    TRACE_BDRV_AIO_MULTIWRITE_EARLYFAIL,
+    TRACE_BDRV_AIO_MULTIWRITE_LATEFAIL,
+    TRACE_VIRTIO_BLK_REQ_COMPLETE,
+    TRACE_VIRTIO_BLK_RW_COMPLETE,
+    TRACE_VIRTIO_BLK_HANDLE_WRITE,
+    TRACE_PAIO_SUBMIT,
 } TraceEvent;
 
 void trace1(TraceEvent event, unsigned long x1);
@@ -7,3 +14,36 @@  void trace2(TraceEvent event, unsigned long x1, unsigned long x2);
 void trace3(TraceEvent event, unsigned long x1, unsigned long x2, unsigned long x3);
 void trace4(TraceEvent event, unsigned long x1, unsigned long x2, unsigned long x3, unsigned long x4);
 void trace5(TraceEvent event, unsigned long x1, unsigned long x2, unsigned long x3, unsigned long x4, unsigned long x5);
+
+static inline void trace_multiwrite_cb(void *mcb, int ret) {
+    trace2(TRACE_MULTIWRITE_CB, (unsigned long)mcb, ret);
+}
+
+static inline void trace_bdrv_aio_multiwrite(void *mcb, int num_callbacks, int num_reqs) {
+    trace3(TRACE_BDRV_AIO_MULTIWRITE, (unsigned long)mcb, num_callbacks, num_reqs);
+}
+
+static inline void trace_bdrv_aio_multiwrite_earlyfail(void *mcb) {
+    trace1(TRACE_BDRV_AIO_MULTIWRITE_EARLYFAIL, (unsigned long)mcb);
+}
+
+static inline void trace_bdrv_aio_multiwrite_latefail(void *mcb, int i) {
+    trace2(TRACE_BDRV_AIO_MULTIWRITE_LATEFAIL, (unsigned long)mcb, i);
+}
+
+static inline void trace_virtio_blk_req_complete(void *req, int status) {
+    trace2(TRACE_VIRTIO_BLK_REQ_COMPLETE, (unsigned long)req, status);
+}
+
+static inline void trace_virtio_blk_rw_complete(void *req, int ret) {
+    trace2(TRACE_VIRTIO_BLK_RW_COMPLETE, (unsigned long)req, ret);
+}
+
+static inline void trace_virtio_blk_handle_write(void *req, unsigned long sector, unsigned long nsectors) {
+    trace3(TRACE_VIRTIO_BLK_HANDLE_WRITE, (unsigned long)req, sector, nsectors);
+}
+
+static inline void trace_paio_submit(void *acb, void *opaque, unsigned long sector_num, unsigned long nb_sectors, unsigned long type)
+{
+    trace5(TRACE_PAIO_SUBMIT, (unsigned long)acb, (unsigned long)opaque, sector_num, nb_sectors, type);
+}
diff --git a/trace.py b/trace.py
index f38ab6b..ba4476c 100755
--- a/trace.py
+++ b/trace.py
@@ -6,6 +6,14 @@  trace_fmt = 'LLLLLL'
 trace_len = struct.calcsize(trace_fmt)
 
 events = {
+    0: ('multiwrite_cb', 'mcb', 'ret'),
+    1: ('bdrv_aio_multiwrite', 'mcb', 'num_callbacks', 'num_reqs'),
+    2: ('bdrv_aio_multiwrite_earlyfail', 'mcb'),
+    3: ('bdrv_aio_multiwrite_latefail', 'mcb', 'i'),
+    4: ('virtio_blk_req_complete', 'req', 'status'),
+    5: ('virtio_blk_rw_complete', 'req', 'ret'),
+    6: ('virtio_blk_handle_write', 'req', 'sector', 'nsectors'),
+    7: ('paio_submit', 'acb', 'opaque', 'sector_num', 'nb_sectors', 'type'),
 }
 
 def read_record(fobj):