Skip to content

Commit

Permalink
blk-stat: export helpers for modifying blk_rq_stat
Browse files Browse the repository at this point in the history
We need to use blk_rq_stat in the blkcg qos stuff, so export some of
these helpers so they can be used by other things.

Signed-off-by: Josef Bacik <jbacik@fb.com>
Acked-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
  • Loading branch information
Josef Bacik authored and Jens Axboe committed Jul 9, 2018
1 parent 2cf8558 commit 2ecbf45
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
16 changes: 8 additions & 8 deletions block/blk-stat.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ struct blk_queue_stats {
bool enable_accounting;
};

static void blk_stat_init(struct blk_rq_stat *stat)
void blk_rq_stat_init(struct blk_rq_stat *stat)
{
stat->min = -1ULL;
stat->max = stat->nr_samples = stat->mean = 0;
stat->batch = 0;
}

/* src is a per-cpu stat, mean isn't initialized */
static void blk_stat_sum(struct blk_rq_stat *dst, struct blk_rq_stat *src)
void blk_rq_stat_sum(struct blk_rq_stat *dst, struct blk_rq_stat *src)
{
if (!src->nr_samples)
return;
Expand All @@ -39,7 +39,7 @@ static void blk_stat_sum(struct blk_rq_stat *dst, struct blk_rq_stat *src)
dst->nr_samples += src->nr_samples;
}

static void __blk_stat_add(struct blk_rq_stat *stat, u64 value)
void blk_rq_stat_add(struct blk_rq_stat *stat, u64 value)
{
stat->min = min(stat->min, value);
stat->max = max(stat->max, value);
Expand Down Expand Up @@ -69,7 +69,7 @@ void blk_stat_add(struct request *rq, u64 now)
continue;

stat = &get_cpu_ptr(cb->cpu_stat)[bucket];
__blk_stat_add(stat, value);
blk_rq_stat_add(stat, value);
put_cpu_ptr(cb->cpu_stat);
}
rcu_read_unlock();
Expand All @@ -82,15 +82,15 @@ static void blk_stat_timer_fn(struct timer_list *t)
int cpu;

for (bucket = 0; bucket < cb->buckets; bucket++)
blk_stat_init(&cb->stat[bucket]);
blk_rq_stat_init(&cb->stat[bucket]);

for_each_online_cpu(cpu) {
struct blk_rq_stat *cpu_stat;

cpu_stat = per_cpu_ptr(cb->cpu_stat, cpu);
for (bucket = 0; bucket < cb->buckets; bucket++) {
blk_stat_sum(&cb->stat[bucket], &cpu_stat[bucket]);
blk_stat_init(&cpu_stat[bucket]);
blk_rq_stat_sum(&cb->stat[bucket], &cpu_stat[bucket]);
blk_rq_stat_init(&cpu_stat[bucket]);
}
}

Expand Down Expand Up @@ -143,7 +143,7 @@ void blk_stat_add_callback(struct request_queue *q,

cpu_stat = per_cpu_ptr(cb->cpu_stat, cpu);
for (bucket = 0; bucket < cb->buckets; bucket++)
blk_stat_init(&cpu_stat[bucket]);
blk_rq_stat_init(&cpu_stat[bucket]);
}

spin_lock(&q->stats->lock);
Expand Down
4 changes: 4 additions & 0 deletions block/blk-stat.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,8 @@ static inline void blk_stat_activate_msecs(struct blk_stat_callback *cb,
mod_timer(&cb->timer, jiffies + msecs_to_jiffies(msecs));
}

void blk_rq_stat_add(struct blk_rq_stat *, u64);
void blk_rq_stat_sum(struct blk_rq_stat *, struct blk_rq_stat *);
void blk_rq_stat_init(struct blk_rq_stat *);

#endif

0 comments on commit 2ecbf45

Please sign in to comment.