Skip to content

Commit

Permalink
blk-stat: Optimise blk_stat_add()
Browse files Browse the repository at this point in the history
blk_stat_add() calls {get,put}_cpu_ptr() in a loop, which entails
overhead of disabling/enabling preemption. The loop is under RCU
(i.e.short) anyway, so do get_cpu() in advance.

Signed-off-by: Pavel Begunkov <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
isilence authored and axboe committed Oct 8, 2019
1 parent a2e80f6 commit 8148f0b
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions block/blk-stat.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,15 @@ void blk_stat_add(struct request *rq, u64 now)
struct request_queue *q = rq->q;
struct blk_stat_callback *cb;
struct blk_rq_stat *stat;
int bucket;
int bucket, cpu;
u64 value;

value = (now >= rq->io_start_time_ns) ? now - rq->io_start_time_ns : 0;

blk_throtl_stat_add(rq, value);

rcu_read_lock();
cpu = get_cpu();
list_for_each_entry_rcu(cb, &q->stats->callbacks, list) {
if (!blk_stat_is_active(cb))
continue;
Expand All @@ -69,10 +70,10 @@ void blk_stat_add(struct request *rq, u64 now)
if (bucket < 0)
continue;

stat = &get_cpu_ptr(cb->cpu_stat)[bucket];
stat = &per_cpu_ptr(cb->cpu_stat, cpu)[bucket];
blk_rq_stat_add(stat, value);
put_cpu_ptr(cb->cpu_stat);
}
put_cpu();
rcu_read_unlock();
}

Expand Down

0 comments on commit 8148f0b

Please sign in to comment.