Commit c4c76a05 authored by Tejun Heo's avatar Tejun Heo Committed by Jens Axboe

blkcg: restructure blkio_get_stat()

Restructure blkio_get_stat() to prepare for removal of stats_lock.

* Define BLKIO_STAT_ARR_NR explicitly to denote which stats have
  subtypes instead of using BLKIO_STAT_QUEUED.

* Separate out stat acquisition and printing.  After this, there are
  only two users of blkio_fill_stat().  Just open code it.

* The code was mixing MAX_KEY_LEN and MAX_KEY_LEN - 1.  There's no
  need to subtract one.  Use MAX_KEY_LEN consistently.
Signed-off-by: default avatarTejun Heo <tj@kernel.org>
Cc: Vivek Goyal <vgoyal@redhat.com>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 997a026c
...@@ -868,15 +868,6 @@ static void blkio_get_key_name(enum stat_sub_type type, const char *dname, ...@@ -868,15 +868,6 @@ static void blkio_get_key_name(enum stat_sub_type type, const char *dname,
} }
} }
static uint64_t blkio_fill_stat(char *str, int chars_left, uint64_t val,
struct cgroup_map_cb *cb, const char *dname)
{
blkio_get_key_name(0, dname, str, chars_left, true);
cb->fill(cb, str, val);
return val;
}
static uint64_t blkio_read_stat_cpu(struct blkio_group *blkg, int plid, static uint64_t blkio_read_stat_cpu(struct blkio_group *blkg, int plid,
enum stat_type_cpu type, enum stat_sub_type sub_type) enum stat_type_cpu type, enum stat_sub_type sub_type)
{ {
...@@ -916,8 +907,9 @@ static uint64_t blkio_get_stat_cpu(struct blkio_group *blkg, int plid, ...@@ -916,8 +907,9 @@ static uint64_t blkio_get_stat_cpu(struct blkio_group *blkg, int plid,
if (type == BLKIO_STAT_CPU_SECTORS) { if (type == BLKIO_STAT_CPU_SECTORS) {
val = blkio_read_stat_cpu(blkg, plid, type, 0); val = blkio_read_stat_cpu(blkg, plid, type, 0);
return blkio_fill_stat(key_str, MAX_KEY_LEN - 1, val, cb, blkio_get_key_name(0, dname, key_str, MAX_KEY_LEN, true);
dname); cb->fill(cb, key_str, val);
return val;
} }
for (sub_type = BLKIO_STAT_READ; sub_type < BLKIO_STAT_TOTAL; for (sub_type = BLKIO_STAT_READ; sub_type < BLKIO_STAT_TOTAL;
...@@ -942,50 +934,60 @@ static uint64_t blkio_get_stat(struct blkio_group *blkg, int plid, ...@@ -942,50 +934,60 @@ static uint64_t blkio_get_stat(struct blkio_group *blkg, int plid,
struct cgroup_map_cb *cb, const char *dname, struct cgroup_map_cb *cb, const char *dname,
enum stat_type type) enum stat_type type)
{ {
struct blkg_policy_data *pd = blkg->pd[plid]; struct blkio_group_stats *stats = &blkg->pd[plid]->stats;
uint64_t disk_total; uint64_t v = 0, disk_total = 0;
char key_str[MAX_KEY_LEN]; char key_str[MAX_KEY_LEN];
enum stat_sub_type sub_type; int st;
if (type == BLKIO_STAT_TIME) if (type >= BLKIO_STAT_ARR_NR) {
return blkio_fill_stat(key_str, MAX_KEY_LEN - 1, switch (type) {
pd->stats.time, cb, dname); case BLKIO_STAT_TIME:
v = stats->time;
break;
#ifdef CONFIG_DEBUG_BLK_CGROUP #ifdef CONFIG_DEBUG_BLK_CGROUP
if (type == BLKIO_STAT_UNACCOUNTED_TIME) case BLKIO_STAT_UNACCOUNTED_TIME:
return blkio_fill_stat(key_str, MAX_KEY_LEN - 1, v = stats->unaccounted_time;
pd->stats.unaccounted_time, cb, dname); break;
if (type == BLKIO_STAT_AVG_QUEUE_SIZE) { case BLKIO_STAT_AVG_QUEUE_SIZE: {
uint64_t sum = pd->stats.avg_queue_size_sum; uint64_t samples = stats->avg_queue_size_samples;
uint64_t samples = pd->stats.avg_queue_size_samples;
if (samples) if (samples) {
do_div(sum, samples); v = stats->avg_queue_size_sum;
else do_div(v, samples);
sum = 0; }
return blkio_fill_stat(key_str, MAX_KEY_LEN - 1, break;
sum, cb, dname);
} }
if (type == BLKIO_STAT_GROUP_WAIT_TIME) case BLKIO_STAT_IDLE_TIME:
return blkio_fill_stat(key_str, MAX_KEY_LEN - 1, v = stats->idle_time;
pd->stats.group_wait_time, cb, dname); break;
if (type == BLKIO_STAT_IDLE_TIME) case BLKIO_STAT_EMPTY_TIME:
return blkio_fill_stat(key_str, MAX_KEY_LEN - 1, v = stats->empty_time;
pd->stats.idle_time, cb, dname); break;
if (type == BLKIO_STAT_EMPTY_TIME) case BLKIO_STAT_DEQUEUE:
return blkio_fill_stat(key_str, MAX_KEY_LEN - 1, v = stats->dequeue;
pd->stats.empty_time, cb, dname); break;
if (type == BLKIO_STAT_DEQUEUE) case BLKIO_STAT_GROUP_WAIT_TIME:
return blkio_fill_stat(key_str, MAX_KEY_LEN - 1, v = stats->group_wait_time;
pd->stats.dequeue, cb, dname); break;
#endif #endif
default:
WARN_ON_ONCE(1);
}
for (sub_type = BLKIO_STAT_READ; sub_type < BLKIO_STAT_TOTAL; blkio_get_key_name(0, dname, key_str, MAX_KEY_LEN, true);
sub_type++) { cb->fill(cb, key_str, v);
blkio_get_key_name(sub_type, dname, key_str, MAX_KEY_LEN, return v;
false);
cb->fill(cb, key_str, pd->stats.stat_arr[type][sub_type]);
} }
disk_total = pd->stats.stat_arr[type][BLKIO_STAT_READ] +
pd->stats.stat_arr[type][BLKIO_STAT_WRITE]; for (st = BLKIO_STAT_READ; st < BLKIO_STAT_TOTAL; st++) {
v = stats->stat_arr[type][st];
blkio_get_key_name(st, dname, key_str, MAX_KEY_LEN, false);
cb->fill(cb, key_str, v);
if (st == BLKIO_STAT_READ || st == BLKIO_STAT_WRITE)
disk_total += v;
}
blkio_get_key_name(BLKIO_STAT_TOTAL, dname, key_str, MAX_KEY_LEN, blkio_get_key_name(BLKIO_STAT_TOTAL, dname, key_str, MAX_KEY_LEN,
false); false);
cb->fill(cb, key_str, disk_total); cb->fill(cb, key_str, disk_total);
......
...@@ -39,6 +39,7 @@ enum stat_type { ...@@ -39,6 +39,7 @@ enum stat_type {
BLKIO_STAT_WAIT_TIME, BLKIO_STAT_WAIT_TIME,
/* Number of IOs queued up */ /* Number of IOs queued up */
BLKIO_STAT_QUEUED, BLKIO_STAT_QUEUED,
/* All the single valued stats go below this */ /* All the single valued stats go below this */
BLKIO_STAT_TIME, BLKIO_STAT_TIME,
#ifdef CONFIG_DEBUG_BLK_CGROUP #ifdef CONFIG_DEBUG_BLK_CGROUP
...@@ -52,6 +53,9 @@ enum stat_type { ...@@ -52,6 +53,9 @@ enum stat_type {
#endif #endif
}; };
/* Types lower than this live in stat_arr and have subtypes */
#define BLKIO_STAT_ARR_NR (BLKIO_STAT_QUEUED + 1)
/* Per cpu stats */ /* Per cpu stats */
enum stat_type_cpu { enum stat_type_cpu {
BLKIO_STAT_CPU_SECTORS, BLKIO_STAT_CPU_SECTORS,
...@@ -117,7 +121,7 @@ struct blkio_cgroup { ...@@ -117,7 +121,7 @@ struct blkio_cgroup {
struct blkio_group_stats { struct blkio_group_stats {
/* total disk time and nr sectors dispatched by this group */ /* total disk time and nr sectors dispatched by this group */
uint64_t time; uint64_t time;
uint64_t stat_arr[BLKIO_STAT_QUEUED + 1][BLKIO_STAT_TOTAL]; uint64_t stat_arr[BLKIO_STAT_ARR_NR][BLKIO_STAT_TOTAL];
#ifdef CONFIG_DEBUG_BLK_CGROUP #ifdef CONFIG_DEBUG_BLK_CGROUP
/* Time not charged to this cgroup */ /* Time not charged to this cgroup */
uint64_t unaccounted_time; uint64_t unaccounted_time;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment