summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2012-09-01 10:55:56 -0700
committerJens Axboe <axboe@kernel.dk>2012-10-04 11:04:38 +0200
commitefaf8b5858fb06a920a4bf7479716d3f418ca655 (patch)
treed164ba9c053ed39438ebdc2de13dcb9d087735e0
parent99350471ae4c627404e77f67587ff4a44a9a5ca1 (diff)
block: cleanup IO accounting interface
Use a sane prefixed name for all the related functions, and put them close together in the blk-core.c file. Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r--block/blk-core.c83
-rw-r--r--block/blk-mq.c3
-rw-r--r--block/blk.h4
3 files changed, 46 insertions, 44 deletions
diff --git a/block/blk-core.c b/block/blk-core.c
index dfc4b646c16f..66f72eb4a67f 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -59,42 +59,6 @@ struct kmem_cache *blk_requestq_cachep;
*/
static struct workqueue_struct *kblockd_workqueue;
-void drive_stat_acct(struct request *rq, int new_io)
-{
- struct hd_struct *part;
- int rw = rq_data_dir(rq);
- int cpu;
-
- if (!blk_do_io_stat(rq))
- return;
-
- cpu = part_stat_lock();
-
- if (!new_io) {
- part = rq->part;
- part_stat_inc(cpu, part, merges[rw]);
- } else {
- part = disk_map_sector_rcu(rq->rq_disk, blk_rq_pos(rq));
- if (!hd_struct_try_get(part)) {
- /*
- * The partition is already being removed,
- * the request will be accounted on the disk only
- *
- * We take a reference on disk->part0 although that
- * partition will never be deleted, so we can treat
- * it as any other partition.
- */
- part = &rq->rq_disk->part0;
- hd_struct_get(part);
- }
- part_round_stats(cpu, part);
- part_inc_in_flight(part, rw);
- rq->part = part;
- }
-
- part_stat_unlock();
-}
-
void blk_queue_congestion_threshold(struct request_queue *q)
{
int nr;
@@ -1192,7 +1156,7 @@ EXPORT_SYMBOL(blk_requeue_request);
static void add_acct_request(struct request_queue *q, struct request *rq,
int where)
{
- drive_stat_acct(rq, 1);
+ blk_account_io_start(rq, true);
__elv_add_request(q, rq, where);
}
@@ -1330,7 +1294,7 @@ bool bio_attempt_back_merge(struct request_queue *q, struct request *req,
req->__data_len += bio->bi_size;
req->ioprio = ioprio_best(req->ioprio, bio_prio(bio));
- drive_stat_acct(req, 0);
+ blk_account_io_start(req, false);
return true;
}
@@ -1360,7 +1324,7 @@ bool bio_attempt_front_merge(struct request_queue *q, struct request *req,
req->__data_len += bio->bi_size;
req->ioprio = ioprio_best(req->ioprio, bio_prio(bio));
- drive_stat_acct(req, 0);
+ blk_account_io_start(req, false);
return true;
}
@@ -1533,7 +1497,7 @@ get_rq:
}
}
list_add_tail(&req->queuelist, &plug->list);
- drive_stat_acct(req, 1);
+ blk_account_io_start(req, true);
} else {
spin_lock_irq(q->queue_lock);
add_acct_request(q, req, where);
@@ -1996,7 +1960,7 @@ void blk_account_io_completion(struct request *req, unsigned int bytes)
}
}
-static void blk_account_io_done(struct request *req)
+void blk_account_io_done(struct request *req)
{
/*
* Account IO completion. flush_rq isn't accounted as a
@@ -2022,6 +1986,42 @@ static void blk_account_io_done(struct request *req)
}
}
+void blk_account_io_start(struct request *rq, bool new_io)
+{
+ struct hd_struct *part;
+ int rw = rq_data_dir(rq);
+ int cpu;
+
+ if (!blk_do_io_stat(rq))
+ return;
+
+ cpu = part_stat_lock();
+
+ if (!new_io) {
+ part = rq->part;
+ part_stat_inc(cpu, part, merges[rw]);
+ } else {
+ part = disk_map_sector_rcu(rq->rq_disk, blk_rq_pos(rq));
+ if (!hd_struct_try_get(part)) {
+ /*
+ * The partition is already being removed,
+ * the request will be accounted on the disk only
+ *
+ * We take a reference on disk->part0 although that
+ * partition will never be deleted, so we can treat
+ * it as any other partition.
+ */
+ part = &rq->rq_disk->part0;
+ hd_struct_get(part);
+ }
+ part_round_stats(cpu, part);
+ part_inc_in_flight(part, rw);
+ rq->part = part;
+ }
+
+ part_stat_unlock();
+}
+
/**
* blk_peek_request - peek at the top of a request queue
* @q: request queue to peek at
@@ -2429,7 +2429,6 @@ static void blk_finish_request(struct request *req, int error)
if (req->cmd_flags & REQ_DONTPREP)
blk_unprep_request(req);
-
blk_account_io_done(req);
if (req->end_io)
diff --git a/block/blk-mq.c b/block/blk-mq.c
index cc656e6434f9..ded74891602d 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -160,6 +160,7 @@ static void __blk_mq_end_io(struct request *rq, int error)
}
blk_account_io_completion(rq, bytes);
+ blk_account_io_done(rq);
blk_mq_free_request(rq);
}
@@ -519,7 +520,7 @@ static struct request *blk_mq_bio_to_request(struct request_queue *q,
has_lock);
if (rq) {
init_request_from_bio(rq, bio);
- drive_stat_acct(rq, 1);
+ blk_account_io_start(rq, 1);
}
return rq;
diff --git a/block/blk.h b/block/blk.h
index 054f034c8e95..194c8334379f 100644
--- a/block/blk.h
+++ b/block/blk.h
@@ -48,8 +48,10 @@ bool bio_attempt_back_merge(struct request_queue *q, struct request *req,
struct bio *bio);
bool blk_attempt_plug_merge(struct request_queue *q, struct bio *bio,
unsigned int *request_count);
-void drive_stat_acct(struct request *rq, int new_io);
+
+void blk_account_io_start(struct request *req, bool new_io);
void blk_account_io_completion(struct request *req, unsigned int bytes);
+void blk_account_io_done(struct request *req);
/*
* Internal atomic flags for request handling