From patchwork Tue May 17 21:50:29 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Callahan X-Patchwork-Id: 9115311 Return-Path: X-Original-To: patchwork-linux-block@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 386B69F1C1 for ; Tue, 17 May 2016 21:50:35 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 20FCD20254 for ; Tue, 17 May 2016 21:50:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C5BB8200D6 for ; Tue, 17 May 2016 21:50:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750940AbcEQVuc (ORCPT ); Tue, 17 May 2016 17:50:32 -0400 Received: from mail-lf0-f68.google.com ([209.85.215.68]:35892 "EHLO mail-lf0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750800AbcEQVub (ORCPT ); Tue, 17 May 2016 17:50:31 -0400 Received: by mail-lf0-f68.google.com with SMTP id y84so2051169lfc.3 for ; Tue, 17 May 2016 14:50:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:cc; bh=2Evjz3eBduAG81m9MmsnZrUEwAz5zkcY0I97Wp5n2ZM=; b=H2BGLd8YWp29/cWU7V0rVhxvJGIAjEJuv83EQPR/AQZ3JIcPu+gaiSq0OrMTpSHKiA Q2iWt27NVh6vA0X8wKNh0rXnYMab3CVhqVCdSirX+WM8pjQmgK1jg70uIwWT5PLQHYU0 Jsn/XjvAZd/VM48w1uRuCYKvyRefwdYSdlYvCFAjV1jy0mgnkwfzR0sR7+NBdRkyzR0Q bPexoJWRk6Cnfi61UMX/drjGbNH3iKEZfgJCRtYcp+S9fXhvzXpV37CZEmfV70xiWdRg EluC8QjjWohUkN+bqqMU1m1k7oWAPMKaWTSpVe0YQQ4WESQYWrDJ3PyNeIwLfuQ+/UQn GiGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:date:message-id:subject:from:to:cc; bh=2Evjz3eBduAG81m9MmsnZrUEwAz5zkcY0I97Wp5n2ZM=; b=eaOjXledFTC4Y53j7uBLAxMjrCYzhGmyKIwF6kMQjpP7uwzW5lW2C9QRKMFoeZF/KM l99uLtXuk2X8ttiXGmHbwUtOiM6QPrO3I4tOx3REtCAaAV9etC9n1z4cWh+eDcu+v6Rc QHArEhkJtswwACRUwMDrJQl0fQQYsnO1sJ5DndoWRyAeBmtQwrqvs2Tv6MPbJI2NhwX2 iNE4241kZTGKp+09kpLIH8KpekTtcSTznw5Uy3nCKLK5P6jnbtR9jfgD+6Xy8tE5uozT 9ziZI7z2CRnRQtYlebGOeugylVrLloftUGGrd1cmP75cvpuUQR3+PhkNlFPrp+zdlE/d rIlA== X-Gm-Message-State: AOPr4FWFt8v9epgKQTqoXPVfdk/7wTBaRVfJ6ZFOvrXE0mdoQEuzu8iuQ5qoUaXHIKSBgQhS9eoHJpC0dqtpqw== MIME-Version: 1.0 X-Received: by 10.25.42.147 with SMTP id q141mr1396309lfq.94.1463521829449; Tue, 17 May 2016 14:50:29 -0700 (PDT) Received: by 10.25.148.69 with HTTP; Tue, 17 May 2016 14:50:29 -0700 (PDT) Date: Tue, 17 May 2016 15:50:29 -0600 Message-ID: Subject: [PATCH v2 2/4] Define and use STAT_READ and STAT_WRITE From: Michael Callahan To: linux-block@vger.kernel.org Cc: Michael Callahan , Jens Axboe Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Spam-Status: No, score=-8.2 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add defines for STAT_READ and STAT_WRITE for indexing the partition stat entries. This clarifies some fs/ code which has hardcoded 1 for STAT_WRITE and will make it easier to extend the stats with additional fields. Signed-off-by: Michael Callahan block/genhd.c | 16 ++++++++-------- block/partition-generic.c | 16 ++++++++-------- fs/ext4/super.c | 5 +++-- fs/ext4/sysfs.c | 6 ++++-- fs/f2fs/f2fs.h | 2 +- fs/f2fs/super.c | 3 ++- include/linux/genhd.h | 9 ++++++--- 7 files changed, 32 insertions(+), 25 deletions(-) --- -- To unsubscribe from this list: send the line "unsubscribe linux-block" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/block/genhd.c b/block/genhd.c index 9f42526..b6f1dee 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -1199,14 +1199,14 @@ static int diskstats_show(struct seq_file *seqf, void *v) "%u %lu %lu %lu %u %u %u %u\n", MAJOR(part_devt(hd)), MINOR(part_devt(hd)), disk_name(gp, hd->partno, buf), - part_stat_read(hd, ios[READ]), - part_stat_read(hd, merges[READ]), - part_stat_read(hd, sectors[READ]), - jiffies_to_msecs(part_stat_read(hd, ticks[READ])), - part_stat_read(hd, ios[WRITE]), - part_stat_read(hd, merges[WRITE]), - part_stat_read(hd, sectors[WRITE]), - jiffies_to_msecs(part_stat_read(hd, ticks[WRITE])), + part_stat_read(hd, ios[STAT_READ]), + part_stat_read(hd, merges[STAT_READ]), + part_stat_read(hd, sectors[STAT_READ]), + jiffies_to_msecs(part_stat_read(hd, ticks[STAT_READ])), + part_stat_read(hd, ios[STAT_WRITE]), + part_stat_read(hd, merges[STAT_WRITE]), + part_stat_read(hd, sectors[STAT_WRITE]), + jiffies_to_msecs(part_stat_read(hd, ticks[STAT_WRITE])), part_in_flight(hd), jiffies_to_msecs(part_stat_read(hd, io_ticks)), jiffies_to_msecs(part_stat_read(hd, time_in_queue)) diff --git a/block/partition-generic.c b/block/partition-generic.c index d7eb77e..15bf298 100644 --- a/block/partition-generic.c +++ b/block/partition-generic.c @@ -123,14 +123,14 @@ ssize_t part_stat_show(struct device *dev, "%8lu %8lu %8llu %8u " "%8u %8u %8u" "\n", - part_stat_read(p, ios[READ]), - part_stat_read(p, merges[READ]), - (unsigned long long)part_stat_read(p, sectors[READ]), - jiffies_to_msecs(part_stat_read(p, ticks[READ])), - part_stat_read(p, ios[WRITE]), - part_stat_read(p, merges[WRITE]), - (unsigned long long)part_stat_read(p, sectors[WRITE]), - jiffies_to_msecs(part_stat_read(p, ticks[WRITE])), + part_stat_read(p, ios[STAT_READ]), + part_stat_read(p, merges[STAT_READ]), + (unsigned long long)part_stat_read(p, sectors[STAT_READ]), + jiffies_to_msecs(part_stat_read(p, ticks[STAT_READ])), + part_stat_read(p, ios[STAT_WRITE]), + part_stat_read(p, merges[STAT_WRITE]), + (unsigned long long)part_stat_read(p, sectors[STAT_WRITE]), + jiffies_to_msecs(part_stat_read(p, ticks[STAT_WRITE])), part_in_flight(p), jiffies_to_msecs(part_stat_read(p, io_ticks)), jiffies_to_msecs(part_stat_read(p, time_in_queue))); diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 304c712..3e7f205 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -3182,7 +3182,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) sbi->s_sb_block = sb_block; if (sb->s_bdev->bd_part) sbi->s_sectors_written_start = - part_stat_read(sb->s_bdev->bd_part, sectors[1]); + part_stat_read(sb->s_bdev->bd_part, sectors[STAT_WRITE]); /* Cleanup superblock name */ strreplace(sb->s_id, '/', '!'); @@ -4359,7 +4359,8 @@ static int ext4_commit_super(struct super_block *sb, int sync) if (sb->s_bdev->bd_part) es->s_kbytes_written = cpu_to_le64(EXT4_SB(sb)->s_kbytes_written + - ((part_stat_read(sb->s_bdev->bd_part, sectors[1]) - + ((part_stat_read(sb->s_bdev->bd_part, + sectors[STAT_WRITE]) - EXT4_SB(sb)->s_sectors_written_start) >> 1)); else es->s_kbytes_written = diff --git a/fs/ext4/sysfs.c b/fs/ext4/sysfs.c index 1420a3c..10ad87e 100644 --- a/fs/ext4/sysfs.c +++ b/fs/ext4/sysfs.c @@ -55,7 +55,8 @@ static ssize_t session_write_kbytes_show(struct ext4_attr *a, if (!sb->s_bdev->bd_part) return snprintf(buf, PAGE_SIZE, "0\n"); return snprintf(buf, PAGE_SIZE, "%lu\n", - (part_stat_read(sb->s_bdev->bd_part, sectors[1]) - + (part_stat_read(sb->s_bdev->bd_part, + sectors[STAT_WRITE]) - sbi->s_sectors_written_start) >> 1); } @@ -68,7 +69,8 @@ static ssize_t lifetime_write_kbytes_show(struct ext4_attr *a, return snprintf(buf, PAGE_SIZE, "0\n"); return snprintf(buf, PAGE_SIZE, "%llu\n", (unsigned long long)(sbi->s_kbytes_written + - ((part_stat_read(sb->s_bdev->bd_part, sectors[1]) - + ((part_stat_read(sb->s_bdev->bd_part, + sectors[STAT_WRITE]) - EXT4_SB(sb)->s_sectors_written_start) >> 1))); } diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 7a4558d..2b29afa 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -808,7 +808,7 @@ struct f2fs_sb_info { * and the return value is in kbytes. s is of struct f2fs_sb_info. */ #define BD_PART_WRITTEN(s) \ -(((u64)part_stat_read(s->sb->s_bdev->bd_part, sectors[1]) - \ +(((u64)part_stat_read(s->sb->s_bdev->bd_part, sectors[STAT_WRITE]) - \ s->sectors_written_start) >> 1) static inline void f2fs_update_time(struct f2fs_sb_info *sbi, int type) diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 006f87d..d5da3cc 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -1464,7 +1464,8 @@ try_onemore: /* For write statistics */ if (sb->s_bdev->bd_part) sbi->sectors_written_start = - (u64)part_stat_read(sb->s_bdev->bd_part, sectors[1]); + (u64)part_stat_read(sb->s_bdev->bd_part, + sectors[STAT_WRITE]); /* Read accumulated write IO statistics if exists */ seg_i = CURSEG_I(sbi, CURSEG_HOT_NODE); diff --git a/include/linux/genhd.h b/include/linux/genhd.h index b73559a..19e809c 100644 --- a/include/linux/genhd.h +++ b/include/linux/genhd.h @@ -59,6 +59,9 @@ enum { #define DISK_MAX_PARTS 256 #define DISK_NAME_LEN 32 +#define STAT_READ 0 +#define STAT_WRITE 1 + #include #include #include @@ -80,7 +83,7 @@ struct partition { } __attribute__((packed)); struct disk_stats { - unsigned long sectors[2]; /* READs and WRITEs */ + unsigned long sectors[2]; /* STAT_READs and STAT_WRITEs */ unsigned long ios[2]; unsigned long merges[2]; unsigned long ticks[2]; @@ -382,8 +385,8 @@ static inline void free_part_stats(struct hd_struct *part) #endif /* CONFIG_SMP */ #define part_stat_read_accum(part, field) \ - (part_stat_read(part, field[0]) + \ - part_stat_read(part, field[1])) + (part_stat_read(part, field[STAT_READ]) + \ + part_stat_read(part, field[STAT_WRITE])) #define part_stat_add(cpu, part, field, addnd) do { \ __part_stat_add((cpu), (part), field, addnd); \