qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Amit Shah <amit.shah@redhat.com>
To: Anthony Liguori <anthony@codemonkey.ws>
Cc: Amit Shah <amit.shah@redhat.com>,
	Juan Quintela <quintela@redhat.com>,
	qemu list <qemu-devel@nongnu.org>,
	Markus Armbruster <armbru@redhat.com>
Subject: [Qemu-devel] [PATCH 3/3] virtio-serial-bus: Add per-port stats for received, sent, discarded bytes
Date: Wed, 14 Sep 2011 12:59:07 +0530	[thread overview]
Message-ID: <ed20b527eb3abcff61946cb7111ead3ec8d8cc03.1315985199.git.amit.shah@redhat.com> (raw)
In-Reply-To: <cover.1315985199.git.amit.shah@redhat.com>
In-Reply-To: <cover.1315985199.git.amit.shah@redhat.com>

This commit adds port-specific stats for the number of bytes received,
sent and discarded.  They can be seen in the 'info qtree' monitor output
for the specific port.

This data can be used to check for data loss bugs (or disprove such
claims). It can also be used for accounting, if there's such a need.

The stats remain valid throughout the lifetime of the port. Unplugging a
port will reset the stats.  The numbers are not reset across port
opens/closes.

Signed-off-by: Amit Shah <amit.shah@redhat.com>
---
 hw/virtio-serial-bus.c |   24 ++++++++++++++++++++++--
 hw/virtio-serial.h     |   11 +++++++++++
 2 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/hw/virtio-serial-bus.c b/hw/virtio-serial-bus.c
index 2c84398..deefda4 100644
--- a/hw/virtio-serial-bus.c
+++ b/hw/virtio-serial-bus.c
@@ -108,6 +108,7 @@ static size_t write_to_port(VirtIOSerialPort *port,
         offset += len;
 
         virtqueue_push(vq, &elem, len);
+        port->stats.bytes_sent += len;
     }
 
     virtio_notify(&port->vser->vdev, vq);
@@ -123,10 +124,24 @@ static void discard_vq_data(VirtIOSerialPort *port, VirtQueue *vq,
         return;
     }
     if (port && port->elem.out_num) {
+        port->stats.bytes_discarded += (iov_size(port->elem.out_sg,
+                                                 elem.out_num)
+                                        - iov_size(port->elem.out_sg,
+                                                   port->iov_idx)
+                                        - port->iov_offset);
         virtqueue_push(vq, &port->elem, 0);
         port->elem.out_num = 0;
     }
     while (virtqueue_pop(vq, &elem)) {
+        if (port) {
+            unsigned long size;
+
+            size = iov_size(elem.out_sg, elem.out_num);
+
+            /* We haven't counted these bytes in the received stats yet. */
+            port->stats.bytes_received += size;
+            port->stats.bytes_discarded += size;
+        }
         virtqueue_push(vq, &elem, 0);
     }
     virtio_notify(vdev, vq);
@@ -152,6 +167,8 @@ static void do_flush_queued_data(VirtIOSerialPort *port, VirtQueue *vq,
             }
             port->iov_idx = 0;
             port->iov_offset = 0;
+            port->stats.bytes_received += iov_size(port->elem.out_sg,
+                                                   port->elem.out_num);
         }
 
         for (i = port->iov_idx; i < port->elem.out_num; i++) {
@@ -684,11 +701,14 @@ static void virtser_bus_dev_print(Monitor *mon, DeviceState *qdev, int indent)
 {
     VirtIOSerialPort *port = DO_UPCAST(VirtIOSerialPort, dev, qdev);
 
-    monitor_printf(mon, "%*sport %d, guest %s, host %s, throttle %s\n",
+    monitor_printf(mon, "%*sport %d, guest %s, host %s, throttle %s, bytes_sent %lu, bytes_received %lu, bytes_discarded: %lu\n",
                    indent, "", port->id,
                    port->guest_connected ? "on" : "off",
                    port->host_connected ? "on" : "off",
-                   port->throttled ? "on" : "off");
+                   port->throttled ? "on" : "off",
+                   port->stats.bytes_sent,
+                   port->stats.bytes_received,
+                   port->stats.bytes_discarded);
 }
 
 /* This function is only used if a port id is not provided by the user */
diff --git a/hw/virtio-serial.h b/hw/virtio-serial.h
index ab13803..34d36d7 100644
--- a/hw/virtio-serial.h
+++ b/hw/virtio-serial.h
@@ -67,6 +67,10 @@ typedef struct VirtIOSerialBus VirtIOSerialBus;
 typedef struct VirtIOSerialPort VirtIOSerialPort;
 typedef struct VirtIOSerialPortInfo VirtIOSerialPortInfo;
 
+typedef struct {
+    unsigned long bytes_sent, bytes_received, bytes_discarded;
+} PortStats;
+
 /*
  * This is the state that's shared between all the ports.  Some of the
  * state is configurable via command-line options. Some of it can be
@@ -87,6 +91,13 @@ struct VirtIOSerialPort {
     VirtQueue *ivq, *ovq;
 
     /*
+     * Keep count of the bytes sent, received and discarded for
+     * this port for accounting and debugging purposes.  These
+     * counts are not reset across port open / close events.
+     */
+    PortStats stats;
+
+    /*
      * This name is sent to the guest and exported via sysfs.
      * The guest could create symlinks based on this information.
      * The name is in the reverse fqdn format, like org.qemu.console.0
-- 
1.7.6

  parent reply	other threads:[~2011-09-14  7:29 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-14  7:29 [Qemu-devel] [PATCH 0/3] virtio-serial: Bug fix, add stats for bytes transferred Amit Shah
2011-09-14  7:29 ` [Qemu-devel] [PATCH 1/3] virtio-serial-bus: add port arg to discard_vq_data() Amit Shah
2011-09-14 12:52   ` Markus Armbruster
2011-09-14 13:36     ` Amit Shah
2011-09-14  7:29 ` [Qemu-devel] [PATCH 2/3] virtio-serial-bus: discard data in already popped-out elem Amit Shah
2011-09-14  7:29 ` Amit Shah [this message]
2011-09-14 13:07   ` [Qemu-devel] [PATCH 3/3] virtio-serial-bus: Add per-port stats for received, sent, discarded bytes Markus Armbruster
2011-09-28  9:09     ` Amit Shah

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=ed20b527eb3abcff61946cb7111ead3ec8d8cc03.1315985199.git.amit.shah@redhat.com \
    --to=amit.shah@redhat.com \
    --cc=anthony@codemonkey.ws \
    --cc=armbru@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@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).