Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 273213
b: refs/heads/master
c: 17e5b4f
h: refs/heads/master
i:
  273211: 1147be4
v: v3
  • Loading branch information
Amit Shah authored and Rusty Russell committed Nov 2, 2011
1 parent ff2683c commit a2a36c6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 2d24cdaa6e389f85dad51eda39f1c2684a4f15b0
refs/heads/master: 17e5b4f20adbe286fdf14b4d08f296564e97e545
24 changes: 24 additions & 0 deletions trunk/drivers/char/virtio_console.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ struct ports_device {
int chr_major;
};

struct port_stats {
unsigned long bytes_sent, bytes_received, bytes_discarded;
};

/* This struct holds the per-port data */
struct port {
/* Next port in the list, head is in the ports_device */
Expand Down Expand Up @@ -179,6 +183,13 @@ struct port {
/* File in the debugfs directory that exposes this port's information */
struct dentry *debugfs_file;

/*
* 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.
*/
struct port_stats stats;

/*
* The entries in this struct will be valid if this port is
* hooked up to an hvc console
Expand Down Expand Up @@ -360,6 +371,7 @@ static struct port_buffer *get_inbuf(struct port *port)
if (buf) {
buf->len = len;
buf->offset = 0;
port->stats.bytes_received += len;
}
return buf;
}
Expand Down Expand Up @@ -396,6 +408,7 @@ static void discard_port_data(struct port *port)

err = 0;
while (buf) {
port->stats.bytes_discarded += buf->len - buf->offset;
if (add_inbuf(port->in_vq, buf) < 0) {
err++;
free_buf(buf);
Expand Down Expand Up @@ -519,6 +532,8 @@ static ssize_t send_buf(struct port *port, void *in_buf, size_t in_count,
cpu_relax();
done:
spin_unlock_irqrestore(&port->outvq_lock, flags);

port->stats.bytes_sent += in_count;
/*
* We're expected to return the amount of data we wrote -- all
* of it
Expand Down Expand Up @@ -1048,6 +1063,14 @@ static ssize_t debugfs_read(struct file *filp, char __user *ubuf,
"host_connected: %d\n", port->host_connected);
out_offset += snprintf(buf + out_offset, out_count - out_offset,
"outvq_full: %d\n", port->outvq_full);
out_offset += snprintf(buf + out_offset, out_count - out_offset,
"bytes_sent: %lu\n", port->stats.bytes_sent);
out_offset += snprintf(buf + out_offset, out_count - out_offset,
"bytes_received: %lu\n",
port->stats.bytes_received);
out_offset += snprintf(buf + out_offset, out_count - out_offset,
"bytes_discarded: %lu\n",
port->stats.bytes_discarded);
out_offset += snprintf(buf + out_offset, out_count - out_offset,
"is_console: %s\n",
is_console_port(port) ? "yes" : "no");
Expand Down Expand Up @@ -1133,6 +1156,7 @@ static int add_port(struct ports_device *portdev, u32 id)
port->cons.ws.ws_row = port->cons.ws.ws_col = 0;

port->host_connected = port->guest_connected = false;
port->stats = (struct port_stats) { 0 };

port->outvq_full = false;

Expand Down

0 comments on commit a2a36c6

Please sign in to comment.