Skip to content

Instantly share code, notes, and snippets.

@dcui
Last active June 21, 2018 07:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dcui/d45a073b35d9d18c0320ce41b96b4448 to your computer and use it in GitHub Desktop.
Save dcui/d45a073b35d9d18c0320ce41b96b4448 to your computer and use it in GitHub Desktop.
channel_rb_show.patch
diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
index 64713ff..e51b080 100644
--- a/drivers/hv/vmbus_drv.c
+++ b/drivers/hv/vmbus_drv.c
@@ -476,6 +476,68 @@ static ssize_t channel_vp_mapping_show(struct device *dev,
}
static DEVICE_ATTR_RO(channel_vp_mapping);
+static ssize_t channel_rb_show(struct device *dev,
+ struct device_attribute *dev_attr,
+ char *buf)
+{
+ struct hv_device *hv_dev = device_to_hv_device(dev);
+ struct vmbus_channel *channel = hv_dev->channel, *cur_sc;
+ unsigned long flags;
+ int buf_size = PAGE_SIZE, n_written, tot_written;
+ struct list_head *cur;
+
+ struct hv_ring_buffer_debug_info inbound;
+ struct hv_ring_buffer_debug_info outbound;
+ int nr = 0;
+
+ if (!channel)
+ return -ENODEV;
+
+ hv_ringbuffer_get_debuginfo(&channel->inbound, &inbound);
+ hv_ringbuffer_get_debuginfo(&channel->outbound, &outbound);
+
+ tot_written = snprintf(buf, buf_size,
+"channel #[%d:%d]: in_intr_mask=%u, in_pending_send_sz=%u, in_read_bytes_avail=%u, in_write_bytes_avail=%u, in_read_index=%u, in_write_index=%u;out_intr_mask=%u, out_pending_send_sz=%u, out_read_bytes_avail=%u, out_write_bytes_avail=%u, out_read_index=%u, out_write_index=%u\n",
+ nr, channel->offermsg.child_relid, inbound.current_interrupt_mask,
+ channel->inbound.ring_buffer->pending_send_sz,
+ inbound.bytes_avail_toread, inbound.bytes_avail_towrite,
+ inbound.current_read_index, inbound.current_write_index,
+ outbound.current_interrupt_mask,
+ channel->outbound.ring_buffer->pending_send_sz,
+ outbound.bytes_avail_toread, outbound.bytes_avail_towrite,
+ outbound.current_read_index, outbound.current_write_index);
+
+ spin_lock_irqsave(&channel->lock, flags);
+
+ list_for_each(cur, &channel->sc_list) {
+ if (tot_written >= buf_size - 1)
+ break;
+
+ cur_sc = list_entry(cur, struct vmbus_channel, sc_list);
+ hv_ringbuffer_get_debuginfo(&cur_sc->inbound, &inbound);
+ hv_ringbuffer_get_debuginfo(&cur_sc->outbound, &outbound);
+
+ ++nr;
+ n_written = scnprintf(buf + tot_written,
+ buf_size - tot_written,
+"channel #[%d:%d]: in_intr_mask=%u, in_pending_send_sz=%u, in_read_bytes_avail=%u, in_write_bytes_avail=%u, in_read_index=%u, in_write_index=%u;out_intr_mask=%u, out_pending_send_sz=%u, out_read_bytes_avail=%u, out_write_bytes_avail=%u, out_read_index=%u, out_write_index=%u\n",
+ nr, cur_sc->offermsg.child_relid, inbound.current_interrupt_mask,
+ cur_sc->inbound.ring_buffer->pending_send_sz,
+ inbound.bytes_avail_toread, inbound.bytes_avail_towrite,
+ inbound.current_read_index, inbound.current_write_index,
+ outbound.current_interrupt_mask,
+ cur_sc->outbound.ring_buffer->pending_send_sz,
+ outbound.bytes_avail_toread, outbound.bytes_avail_towrite,
+ outbound.current_read_index, outbound.current_write_index);
+ tot_written += n_written;
+ }
+
+ spin_unlock_irqrestore(&channel->lock, flags);
+
+ return tot_written;
+}
+static DEVICE_ATTR_RO(channel_rb);
+
static ssize_t vendor_show(struct device *dev,
struct device_attribute *dev_attr,
char *buf)
@@ -519,6 +581,7 @@ static struct attribute *vmbus_attrs[] = {
&dev_attr_in_read_bytes_avail.attr,
&dev_attr_in_write_bytes_avail.attr,
&dev_attr_channel_vp_mapping.attr,
+ &dev_attr_channel_rb.attr,
&dev_attr_vendor.attr,
&dev_attr_device.attr,
NULL,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment