ia64/xen-unstable

changeset 14062:ad3ee81cc8c4

[BLKBACK/BLKTAP] add sysfs throughput profiling to blk{back/tap}
author Jake Wires <jwires@xensource.com>
date Wed Feb 21 11:42:04 2007 -0800 (2007-02-21)
parents 87f31a0db841
children b010e556fe2c
files linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c linux-2.6-xen-sparse/drivers/xen/blkback/common.h linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c linux-2.6-xen-sparse/drivers/xen/blktap/common.h linux-2.6-xen-sparse/drivers/xen/blktap/xenbus.c
line diff
     1.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c	Wed Feb 21 19:12:16 2007 +0000
     1.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c	Wed Feb 21 11:42:04 2007 -0800
     1.3 @@ -491,6 +491,12 @@ static void dispatch_rw_block_io(blkif_t
     1.4  	for (i = 0; i < nbio; i++)
     1.5  		submit_bio(operation, biolist[i]);
     1.6  
     1.7 +        if (operation == READ) {
     1.8 +                blkif->st_rd_sect += preq.nr_sects;
     1.9 +        } else if (operation == WRITE) {
    1.10 +                blkif->st_wr_sect += preq.nr_sects;
    1.11 +        }
    1.12 +
    1.13  	return;
    1.14  
    1.15   fail_put_bio:
     2.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/common.h	Wed Feb 21 19:12:16 2007 +0000
     2.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/common.h	Wed Feb 21 11:42:04 2007 -0800
     2.3 @@ -88,6 +88,8 @@ typedef struct blkif_st {
     2.4  	int                 st_wr_req;
     2.5  	int                 st_oo_req;
     2.6  	int                 st_br_req;
     2.7 +        int                 st_rd_sect;
     2.8 +        int                 st_wr_sect;
     2.9  
    2.10  	wait_queue_head_t waiting_to_free;
    2.11  
     3.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c	Wed Feb 21 19:12:16 2007 +0000
     3.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c	Wed Feb 21 11:42:04 2007 -0800
     3.3 @@ -111,16 +111,20 @@ static void update_blkif_status(blkif_t 
     3.4  	}								\
     3.5  	DEVICE_ATTR(name, S_IRUGO, show_##name, NULL)
     3.6  
     3.7 -VBD_SHOW(oo_req, "%d\n", be->blkif->st_oo_req);
     3.8 -VBD_SHOW(rd_req, "%d\n", be->blkif->st_rd_req);
     3.9 -VBD_SHOW(wr_req, "%d\n", be->blkif->st_wr_req);
    3.10 -VBD_SHOW(br_req, "%d\n", be->blkif->st_br_req);
    3.11 +VBD_SHOW(oo_req,  "%d\n", be->blkif->st_oo_req);
    3.12 +VBD_SHOW(rd_req,  "%d\n", be->blkif->st_rd_req);
    3.13 +VBD_SHOW(wr_req,  "%d\n", be->blkif->st_wr_req);
    3.14 +VBD_SHOW(br_req,  "%d\n", be->blkif->st_br_req);
    3.15 +VBD_SHOW(rd_sect, "%d\n", be->blkif->st_rd_sect);
    3.16 +VBD_SHOW(wr_sect, "%d\n", be->blkif->st_wr_sect);
    3.17  
    3.18  static struct attribute *vbdstat_attrs[] = {
    3.19  	&dev_attr_oo_req.attr,
    3.20  	&dev_attr_rd_req.attr,
    3.21  	&dev_attr_wr_req.attr,
    3.22  	&dev_attr_br_req.attr,
    3.23 +	&dev_attr_rd_sect.attr,
    3.24 +	&dev_attr_wr_sect.attr,
    3.25  	NULL
    3.26  };
    3.27  
     4.1 --- a/linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c	Wed Feb 21 19:12:16 2007 +0000
     4.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c	Wed Feb 21 11:42:04 2007 -0800
     4.3 @@ -1195,7 +1195,7 @@ static void dispatch_rw_block_io(blkif_t
     4.4  	int op, operation = (req->operation == BLKIF_OP_WRITE) ? WRITE : READ;
     4.5  	struct gnttab_map_grant_ref map[BLKIF_MAX_SEGMENTS_PER_REQUEST*2];
     4.6  	unsigned int nseg;
     4.7 -	int ret, i;
     4.8 +	int ret, i, nr_sects = 0;
     4.9  	tap_blkif_t *info;
    4.10  	uint64_t sector;
    4.11  	blkif_request_t *target;
    4.12 @@ -1291,6 +1291,9 @@ static void dispatch_rw_block_io(blkif_t
    4.13  					  req->seg[i].gref, blkif->domid);
    4.14  			op++;
    4.15  		}
    4.16 +
    4.17 +		nr_sects += (req->seg[i].last_sect - 
    4.18 +			     req->seg[i].first_sect + 1);
    4.19  	}
    4.20  
    4.21  	ret = HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, map, op);
    4.22 @@ -1403,6 +1406,13 @@ static void dispatch_rw_block_io(blkif_t
    4.23  	target->id = usr_idx;
    4.24  	wmb(); /* blktap_poll() reads req_prod_pvt asynchronously */
    4.25  	info->ufe_ring.req_prod_pvt++;
    4.26 +
    4.27 +	if (operation == READ) {
    4.28 +		blkif->st_rd_sect += nr_sects;
    4.29 +	} else if (operation == WRITE) {
    4.30 +		blkif->st_wr_sect += nr_sects;
    4.31 +	}
    4.32 +
    4.33  	return;
    4.34  
    4.35   fail_flush:
     5.1 --- a/linux-2.6-xen-sparse/drivers/xen/blktap/common.h	Wed Feb 21 19:12:16 2007 +0000
     5.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blktap/common.h	Wed Feb 21 11:42:04 2007 -0800
     5.3 @@ -76,6 +76,8 @@ typedef struct blkif_st {
     5.4  	int                 st_rd_req;
     5.5  	int                 st_wr_req;
     5.6  	int                 st_oo_req;
     5.7 +	int                 st_rd_sect;
     5.8 +	int                 st_wr_sect;
     5.9  
    5.10  	wait_queue_head_t waiting_to_free;
    5.11  
     6.1 --- a/linux-2.6-xen-sparse/drivers/xen/blktap/xenbus.c	Wed Feb 21 19:12:16 2007 +0000
     6.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blktap/xenbus.c	Wed Feb 21 11:42:04 2007 -0800
     6.3 @@ -112,6 +112,74 @@ static int blktap_name(blkif_t *blkif, c
     6.4  	return 0;
     6.5  }
     6.6  
     6.7 +/****************************************************************
     6.8 + *  sysfs interface for VBD I/O requests
     6.9 + */
    6.10 +
    6.11 +#define VBD_SHOW(name, format, args...)					\
    6.12 +	static ssize_t show_##name(struct device *_dev,			\
    6.13 +				   struct device_attribute *attr,	\
    6.14 +				   char *buf)				\
    6.15 +	{								\
    6.16 +		struct xenbus_device *dev = to_xenbus_device(_dev);	\
    6.17 +		struct backend_info *be = dev->dev.driver_data;		\
    6.18 +									\
    6.19 +		return sprintf(buf, format, ##args);			\
    6.20 +	}								\
    6.21 +	DEVICE_ATTR(name, S_IRUGO, show_##name, NULL)
    6.22 +
    6.23 +VBD_SHOW(tap_oo_req,  "%d\n", be->blkif->st_oo_req);
    6.24 +VBD_SHOW(tap_rd_req,  "%d\n", be->blkif->st_rd_req);
    6.25 +VBD_SHOW(tap_wr_req,  "%d\n", be->blkif->st_wr_req);
    6.26 +VBD_SHOW(tap_rd_sect, "%d\n", be->blkif->st_rd_sect);
    6.27 +VBD_SHOW(tap_wr_sect, "%d\n", be->blkif->st_wr_sect);
    6.28 +
    6.29 +static struct attribute *tapstat_attrs[] = {
    6.30 +	&dev_attr_tap_oo_req.attr,
    6.31 +	&dev_attr_tap_rd_req.attr,
    6.32 +	&dev_attr_tap_wr_req.attr,
    6.33 +	&dev_attr_tap_rd_sect.attr,
    6.34 +	&dev_attr_tap_wr_sect.attr,
    6.35 +	NULL
    6.36 +};
    6.37 +
    6.38 +static struct attribute_group tapstat_group = {
    6.39 +	.name = "statistics",
    6.40 +	.attrs = tapstat_attrs,
    6.41 +};
    6.42 +
    6.43 +int xentap_sysfs_addif(struct xenbus_device *dev)
    6.44 +{
    6.45 +	return sysfs_create_group(&dev->dev.kobj, &tapstat_group);
    6.46 +}
    6.47 +
    6.48 +void xentap_sysfs_delif(struct xenbus_device *dev)
    6.49 +{
    6.50 +	sysfs_remove_group(&dev->dev.kobj, &tapstat_group);
    6.51 +}
    6.52 +
    6.53 +static int blktap_remove(struct xenbus_device *dev)
    6.54 +{
    6.55 +	struct backend_info *be = dev->dev.driver_data;
    6.56 +
    6.57 +	if (be->backend_watch.node) {
    6.58 +		unregister_xenbus_watch(&be->backend_watch);
    6.59 +		kfree(be->backend_watch.node);
    6.60 +		be->backend_watch.node = NULL;
    6.61 +	}
    6.62 +	if (be->blkif) {
    6.63 +		if (be->blkif->xenblkd)
    6.64 +			kthread_stop(be->blkif->xenblkd);
    6.65 +		signal_tapdisk(be->blkif->dev_num);
    6.66 +		tap_blkif_free(be->blkif);
    6.67 +		be->blkif = NULL;
    6.68 +	}
    6.69 +	xentap_sysfs_delif(be->dev);
    6.70 +	kfree(be);
    6.71 +	dev->dev.driver_data = NULL;
    6.72 +	return 0;
    6.73 +}
    6.74 +
    6.75  static void tap_update_blkif_status(blkif_t *blkif)
    6.76  { 
    6.77  	int err;
    6.78 @@ -137,6 +205,13 @@ static void tap_update_blkif_status(blki
    6.79  		return;
    6.80  	}
    6.81  
    6.82 +	err = xentap_sysfs_addif(blkif->be->dev);
    6.83 +	if (err) {
    6.84 +		xenbus_dev_fatal(blkif->be->dev, err, 
    6.85 +				 "creating sysfs entries");
    6.86 +		return;
    6.87 +	}
    6.88 +
    6.89  	blkif->xenblkd = kthread_run(tap_blkif_schedule, blkif, name);
    6.90  	if (IS_ERR(blkif->xenblkd)) {
    6.91  		err = PTR_ERR(blkif->xenblkd);
    6.92 @@ -146,27 +221,6 @@ static void tap_update_blkif_status(blki
    6.93  	}
    6.94  }
    6.95  
    6.96 -static int blktap_remove(struct xenbus_device *dev)
    6.97 -{
    6.98 -	struct backend_info *be = dev->dev.driver_data;
    6.99 -
   6.100 -	if (be->backend_watch.node) {
   6.101 -		unregister_xenbus_watch(&be->backend_watch);
   6.102 -		kfree(be->backend_watch.node);
   6.103 -		be->backend_watch.node = NULL;
   6.104 -	}
   6.105 -	if (be->blkif) {
   6.106 -		if (be->blkif->xenblkd)
   6.107 -			kthread_stop(be->blkif->xenblkd);
   6.108 -		signal_tapdisk(be->blkif->dev_num);
   6.109 -		tap_blkif_free(be->blkif);
   6.110 -		be->blkif = NULL;
   6.111 -	}
   6.112 -	kfree(be);
   6.113 -	dev->dev.driver_data = NULL;
   6.114 -	return 0;
   6.115 -}
   6.116 -
   6.117  /**
   6.118   * Entry point to this code when a new device is created.  Allocate
   6.119   * the basic structures, and watch the store waiting for the