From mboxrd@z Thu Jan 1 00:00:00 1970 From: Coly Li Subject: [PATCH 3/4] dm-latency: add sysfs interface Date: Thu, 26 Feb 2015 14:43:06 +0800 Message-ID: <54EEC07A.5050800@gmail.com> Reply-To: device-mapper development Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; Format="flowed" Content-Transfer-Encoding: 7bit Return-path: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com To: dm-devel@redhat.com Cc: Tao Ma , Robin Dong , Laurence Oberman , Alasdair Kergon List-Id: dm-devel.ids From: Coly Li This patch adds sysfs interface to display io latency statistic info. 3 files are used to export statistic info based on delay unit level, - /sys/block/dm-X/dm/io_latency_us - /sys/block/dm-X/dm/io_latency_ms - /sys/block/dm-X/dm/io_latency_s The statistic counter is increasing only, a user space application should calculate "delta" value for a sampling interval. Signed-off-by: Coly Li Reviewed-by: Robin Dong Reviewed-by: Tao Ma --- drivers/md/dm-sysfs.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/drivers/md/dm-sysfs.c b/drivers/md/dm-sysfs.c index c62c5ab..eab2dde 100644 --- a/drivers/md/dm-sysfs.c +++ b/drivers/md/dm-sysfs.c @@ -6,6 +6,7 @@ #include #include +#include #include "dm.h" struct dm_sysfs_attr { @@ -64,14 +65,83 @@ static ssize_t dm_attr_suspended_show(struct mapped_device *md, char *buf) return strlen(buf); } +static ssize_t dm_attr_io_latency_us_show(struct mapped_device *md, char *buf) +{ + int slot_base = 0; + int i, nr, ptr; + + for (ptr = 0, i = 0; i < DM_LATENCY_STATS_US_NR; i++) { + nr = sprintf(buf + ptr, + "%d-%d(us):%d\n", + slot_base, + slot_base + DM_LATENCY_STATS_US_GRAINSIZE - 1, + atomic_read(&md->latency_stats_us[i])); + if (nr < 0) + break; + + slot_base += DM_LATENCY_STATS_US_GRAINSIZE; + ptr += nr; + } + + return strlen(buf); +} + +static ssize_t dm_attr_io_latency_ms_show(struct mapped_device *md, char *buf) +{ + int slot_base = 0; + int i, nr, ptr; + + for (ptr = 0, i = 0; i < DM_LATENCY_STATS_MS_NR; i++) { + nr = sprintf(buf + ptr, + "%d-%d(ms):%d\n", + slot_base, + slot_base + DM_LATENCY_STATS_MS_GRAINSIZE - 1, + atomic_read(&(md->latency_stats_ms[i]))); + if (nr < 0) + break; + + slot_base += DM_LATENCY_STATS_MS_GRAINSIZE; + ptr += nr; + } + + return strlen(buf); +} + +static ssize_t dm_attr_io_latency_s_show(struct mapped_device *md, char *buf) +{ + int slot_base = 0; + int i, nr , ptr; + + for(ptr = 0, i = 0; i < DM_LATENCY_STATS_S_NR; i++) { + nr = sprintf(buf + ptr, + "%d-%d(s):%d\n", + slot_base, + slot_base + DM_LATENCY_STATS_S_GRAINSIZE - 1, + atomic_read(&(md->latency_stats_s[i]))); + if (nr < 0) + break; + + slot_base += DM_LATENCY_STATS_S_GRAINSIZE; + ptr += nr; + } + + return strlen(buf); +} + static DM_ATTR_RO(name); static DM_ATTR_RO(uuid); static DM_ATTR_RO(suspended); +static DM_ATTR_RO(io_latency_us); +static DM_ATTR_RO(io_latency_ms); +static DM_ATTR_RO(io_latency_s); static struct attribute *dm_attrs[] = { &dm_attr_name.attr, &dm_attr_uuid.attr, &dm_attr_suspended.attr, + &dm_attr_io_latency_us.attr, + &dm_attr_io_latency_ms.attr, + &dm_attr_io_latency_s.attr, NULL, };