aboutsummaryrefslogtreecommitdiffstats
path: root/block/blk-core.c
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2008-08-25 06:56:14 -0400
committerJens Axboe <jens.axboe@oracle.com>2008-10-09 02:56:08 -0400
commit074a7aca7afa6f230104e8e65eba3420263714a5 (patch)
treef418313e45bd55be8156c8a3e8f9a216cf63058d /block/blk-core.c
parenteddb2e26b5ee3c5da68ba4bf1921ba20e2097bff (diff)
block: move stats from disk to part0
Move stats related fields - stamp, in_flight, dkstats - from disk to part0 and unify stat handling such that... * part_stat_*() now updates part0 together if the specified partition is not part0. ie. part_stat_*() are now essentially all_stat_*(). * {disk|all}_stat_*() are gone. * part_round_stats() is updated similary. It handles part0 stats automatically and disk_round_stats() is killed. * part_{inc|dec}_in_fligh() is implemented which automatically updates part0 stats for parts other than part0. * disk_map_sector_rcu() is updated to return part0 if no part matches. Combined with the above changes, this makes NULL special case handling in callers unnecessary. * Separate stats show code paths for disk are collapsed into part stats show code paths. * Rename disk_stat_lock/unlock() to part_stat_lock/unlock() While at it, reposition stat handling macros a bit and add missing parentheses around macro parameters. Signed-off-by: Tejun Heo <tj@kernel.org> Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
Diffstat (limited to 'block/blk-core.c')
-rw-r--r--block/blk-core.c84
1 files changed, 34 insertions, 50 deletions
diff --git a/block/blk-core.c b/block/blk-core.c
index 505ec61067df..98138f002524 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -61,21 +61,17 @@ static void drive_stat_acct(struct request *rq, int new_io)
61 if (!blk_fs_request(rq) || !rq->rq_disk) 61 if (!blk_fs_request(rq) || !rq->rq_disk)
62 return; 62 return;
63 63
64 cpu = disk_stat_lock(); 64 cpu = part_stat_lock();
65 part = disk_map_sector_rcu(rq->rq_disk, rq->sector); 65 part = disk_map_sector_rcu(rq->rq_disk, rq->sector);
66 66
67 if (!new_io) 67 if (!new_io)
68 all_stat_inc(cpu, rq->rq_disk, part, merges[rw], rq->sector); 68 part_stat_inc(cpu, part, merges[rw]);
69 else { 69 else {
70 disk_round_stats(cpu, rq->rq_disk); 70 part_round_stats(cpu, part);
71 rq->rq_disk->in_flight++; 71 part_inc_in_flight(part);
72 if (part) {
73 part_round_stats(cpu, part);
74 part->in_flight++;
75 }
76 } 72 }
77 73
78 disk_stat_unlock(); 74 part_stat_unlock();
79} 75}
80 76
81void blk_queue_congestion_threshold(struct request_queue *q) 77void blk_queue_congestion_threshold(struct request_queue *q)
@@ -983,8 +979,22 @@ static inline void add_request(struct request_queue *q, struct request *req)
983 __elv_add_request(q, req, ELEVATOR_INSERT_SORT, 0); 979 __elv_add_request(q, req, ELEVATOR_INSERT_SORT, 0);
984} 980}
985 981
986/* 982static void part_round_stats_single(int cpu, struct hd_struct *part,
987 * disk_round_stats() - Round off the performance stats on a struct 983 unsigned long now)
984{
985 if (now == part->stamp)
986 return;
987
988 if (part->in_flight) {
989 __part_stat_add(cpu, part, time_in_queue,
990 part->in_flight * (now - part->stamp));
991 __part_stat_add(cpu, part, io_ticks, (now - part->stamp));
992 }
993 part->stamp = now;
994}
995
996/**
997 * part_round_stats() - Round off the performance stats on a struct
988 * disk_stats. 998 * disk_stats.
989 * 999 *
990 * The average IO queue length and utilisation statistics are maintained 1000 * The average IO queue length and utilisation statistics are maintained
@@ -998,36 +1008,15 @@ static inline void add_request(struct request_queue *q, struct request *req)
998 * /proc/diskstats. This accounts immediately for all queue usage up to 1008 * /proc/diskstats. This accounts immediately for all queue usage up to
999 * the current jiffies and restarts the counters again. 1009 * the current jiffies and restarts the counters again.
1000 */ 1010 */
1001void disk_round_stats(int cpu, struct gendisk *disk)
1002{
1003 unsigned long now = jiffies;
1004
1005 if (now == disk->stamp)
1006 return;
1007
1008 if (disk->in_flight) {
1009 disk_stat_add(cpu, disk, time_in_queue,
1010 disk->in_flight * (now - disk->stamp));
1011 disk_stat_add(cpu, disk, io_ticks, (now - disk->stamp));
1012 }
1013 disk->stamp = now;
1014}
1015EXPORT_SYMBOL_GPL(disk_round_stats);
1016
1017void part_round_stats(int cpu, struct hd_struct *part) 1011void part_round_stats(int cpu, struct hd_struct *part)
1018{ 1012{
1019 unsigned long now = jiffies; 1013 unsigned long now = jiffies;
1020 1014
1021 if (now == part->stamp) 1015 if (part->partno)
1022 return; 1016 part_round_stats_single(cpu, &part_to_disk(part)->part0, now);
1023 1017 part_round_stats_single(cpu, part, now);
1024 if (part->in_flight) {
1025 part_stat_add(cpu, part, time_in_queue,
1026 part->in_flight * (now - part->stamp));
1027 part_stat_add(cpu, part, io_ticks, (now - part->stamp));
1028 }
1029 part->stamp = now;
1030} 1018}
1019EXPORT_SYMBOL_GPL(part_round_stats);
1031 1020
1032/* 1021/*
1033 * queue lock must be held 1022 * queue lock must be held
@@ -1567,11 +1556,10 @@ static int __end_that_request_first(struct request *req, int error,
1567 struct hd_struct *part; 1556 struct hd_struct *part;
1568 int cpu; 1557 int cpu;
1569 1558
1570 cpu = disk_stat_lock(); 1559 cpu = part_stat_lock();
1571 part = disk_map_sector_rcu(req->rq_disk, req->sector); 1560 part = disk_map_sector_rcu(req->rq_disk, req->sector);
1572 all_stat_add(cpu, req->rq_disk, part, sectors[rw], 1561 part_stat_add(cpu, part, sectors[rw], nr_bytes >> 9);
1573 nr_bytes >> 9, req->sector); 1562 part_stat_unlock();
1574 disk_stat_unlock();
1575 } 1563 }
1576 1564
1577 total_bytes = bio_nbytes = 0; 1565 total_bytes = bio_nbytes = 0;
@@ -1758,19 +1746,15 @@ static void end_that_request_last(struct request *req, int error)
1758 struct hd_struct *part; 1746 struct hd_struct *part;
1759 int cpu; 1747 int cpu;
1760 1748
1761 cpu = disk_stat_lock(); 1749 cpu = part_stat_lock();
1762 part = disk_map_sector_rcu(disk, req->sector); 1750 part = disk_map_sector_rcu(disk, req->sector);
1763 1751
1764 all_stat_inc(cpu, disk, part, ios[rw], req->sector); 1752 part_stat_inc(cpu, part, ios[rw]);
1765 all_stat_add(cpu, disk, part, ticks[rw], duration, req->sector); 1753 part_stat_add(cpu, part, ticks[rw], duration);
1766 disk_round_stats(cpu, disk); 1754 part_round_stats(cpu, part);
1767 disk->in_flight--; 1755 part_dec_in_flight(part);
1768 if (part) {
1769 part_round_stats(cpu, part);
1770 part->in_flight--;
1771 }
1772 1756
1773 disk_stat_unlock(); 1757 part_stat_unlock();
1774 } 1758 }
1775 1759
1776 if (req->end_io) 1760 if (req->end_io)