[PATCH 1/4] Hack: measure stack taken by vring from virtio_blk

From: Rusty Russell
Date: Thu May 29 2014 - 03:29:30 EST


Results (x86-64, Minchan's .config):

gcc 4.8.2: virtio_blk: stack used = 392
gcc 4.6.4: virtio_blk: stack used = 528

Signed-off-by: Rusty Russell <rusty@xxxxxxxxxxxxxxx>
---
drivers/block/virtio_blk.c | 11 ++++++++++-
drivers/virtio/virtio_ring.c | 11 +++++++++++
2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index cb9b1f8326c3..894e290b4bd2 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -151,15 +151,19 @@ static void virtblk_done(struct virtqueue *vq)
spin_unlock_irqrestore(&vblk->vq_lock, flags);
}

+extern struct task_struct *record_stack;
+extern unsigned long stack_top;
+
static int virtio_queue_rq(struct blk_mq_hw_ctx *hctx, struct request *req)
{
struct virtio_blk *vblk = hctx->queue->queuedata;
struct virtblk_req *vbr = req->special;
unsigned long flags;
unsigned int num;
+ unsigned long stack_bottom;
const bool last = (req->cmd_flags & REQ_END) != 0;
int err;
-
+
BUG_ON(req->nr_phys_segments + 2 > vblk->sg_elems);

vbr->req = req;
@@ -199,7 +203,12 @@ static int virtio_queue_rq(struct blk_mq_hw_ctx *hctx, struct request *req)
}

spin_lock_irqsave(&vblk->vq_lock, flags);
+ record_stack = current;
+ __asm__ __volatile__("movq %%rsp,%0" : "=g" (stack_bottom));
err = __virtblk_add_req(vblk->vq, vbr, vbr->sg, num);
+ record_stack = NULL;
+
+ printk("virtio_blk: stack used = %lu\n", stack_bottom - stack_top);
if (err) {
virtqueue_kick(vblk->vq);
blk_mq_stop_hw_queue(hctx);
diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index 4d08f45a9c29..f6ad99ffdc40 100644
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -54,6 +54,14 @@
#define END_USE(vq)
#endif

+extern struct task_struct *record_stack;
+struct task_struct *record_stack;
+EXPORT_SYMBOL(record_stack);
+
+extern unsigned long stack_top;
+unsigned long stack_top;
+EXPORT_SYMBOL(stack_top);
+
struct vring_virtqueue
{
struct virtqueue vq;
@@ -137,6 +145,9 @@ static inline int vring_add_indirect(struct vring_virtqueue *vq,
*/
gfp &= ~(__GFP_HIGHMEM | __GFP_HIGH);

+ if (record_stack == current)
+ __asm__ __volatile__("movq %%rsp,%0" : "=g" (stack_top));
+
desc = kmalloc(total_sg * sizeof(struct vring_desc), gfp);
if (!desc)
return -ENOMEM;
--
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/