aboutsummaryrefslogtreecommitdiffstats
path: root/block/blk-cgroup.c
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2012-03-08 13:53:59 -0500
committerJens Axboe <axboe@kernel.dk>2012-03-20 07:45:37 -0400
commitc4c76a05382c7d05e0b911daa58a827399e9ba1a (patch)
treee89f1edb9890a4b857f75dbdb4a0fb77d9aafa59 /block/blk-cgroup.c
parent997a026c80c3cc05f82e589aced1f0011c17d376 (diff)
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: Tejun Heo <tj@kernel.org> Cc: Vivek Goyal <vgoyal@redhat.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'block/blk-cgroup.c')
-rw-r--r--block/blk-cgroup.c100
1 files changed, 51 insertions, 49 deletions
diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
index 759bc58154c2..80887bc3a049 100644
--- a/block/blk-cgroup.c
+++ b/block/blk-cgroup.c
@@ -868,15 +868,6 @@ static void blkio_get_key_name(enum stat_sub_type type, const char *dname,
868 } 868 }
869} 869}
870 870
871static uint64_t blkio_fill_stat(char *str, int chars_left, uint64_t val,
872 struct cgroup_map_cb *cb, const char *dname)
873{
874 blkio_get_key_name(0, dname, str, chars_left, true);
875 cb->fill(cb, str, val);
876 return val;
877}
878
879
880static uint64_t blkio_read_stat_cpu(struct blkio_group *blkg, int plid, 871static uint64_t blkio_read_stat_cpu(struct blkio_group *blkg, int plid,
881 enum stat_type_cpu type, enum stat_sub_type sub_type) 872 enum stat_type_cpu type, enum stat_sub_type sub_type)
882{ 873{
@@ -916,8 +907,9 @@ static uint64_t blkio_get_stat_cpu(struct blkio_group *blkg, int plid,
916 907
917 if (type == BLKIO_STAT_CPU_SECTORS) { 908 if (type == BLKIO_STAT_CPU_SECTORS) {
918 val = blkio_read_stat_cpu(blkg, plid, type, 0); 909 val = blkio_read_stat_cpu(blkg, plid, type, 0);
919 return blkio_fill_stat(key_str, MAX_KEY_LEN - 1, val, cb, 910 blkio_get_key_name(0, dname, key_str, MAX_KEY_LEN, true);
920 dname); 911 cb->fill(cb, key_str, val);
912 return val;
921 } 913 }
922 914
923 for (sub_type = BLKIO_STAT_READ; sub_type < BLKIO_STAT_TOTAL; 915 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 struct cgroup_map_cb *cb, const char *dname, 934 struct cgroup_map_cb *cb, const char *dname,
943 enum stat_type type) 935 enum stat_type type)
944{ 936{
945 struct blkg_policy_data *pd = blkg->pd[plid]; 937 struct blkio_group_stats *stats = &blkg->pd[plid]->stats;
946 uint64_t disk_total; 938 uint64_t v = 0, disk_total = 0;
947 char key_str[MAX_KEY_LEN]; 939 char key_str[MAX_KEY_LEN];
948 enum stat_sub_type sub_type; 940 int st;
949 941
950 if (type == BLKIO_STAT_TIME) 942 if (type >= BLKIO_STAT_ARR_NR) {
951 return blkio_fill_stat(key_str, MAX_KEY_LEN - 1, 943 switch (type) {
952 pd->stats.time, cb, dname); 944 case BLKIO_STAT_TIME:
945 v = stats->time;
946 break;
953#ifdef CONFIG_DEBUG_BLK_CGROUP 947#ifdef CONFIG_DEBUG_BLK_CGROUP
954 if (type == BLKIO_STAT_UNACCOUNTED_TIME) 948 case BLKIO_STAT_UNACCOUNTED_TIME:
955 return blkio_fill_stat(key_str, MAX_KEY_LEN - 1, 949 v = stats->unaccounted_time;
956 pd->stats.unaccounted_time, cb, dname); 950 break;
957 if (type == BLKIO_STAT_AVG_QUEUE_SIZE) { 951 case BLKIO_STAT_AVG_QUEUE_SIZE: {
958 uint64_t sum = pd->stats.avg_queue_size_sum; 952 uint64_t samples = stats->avg_queue_size_samples;
959 uint64_t samples = pd->stats.avg_queue_size_samples; 953
960 if (samples) 954 if (samples) {
961 do_div(sum, samples); 955 v = stats->avg_queue_size_sum;
962 else 956 do_div(v, samples);
963 sum = 0; 957 }
964 return blkio_fill_stat(key_str, MAX_KEY_LEN - 1, 958 break;
965 sum, cb, dname); 959 }
966 } 960 case BLKIO_STAT_IDLE_TIME:
967 if (type == BLKIO_STAT_GROUP_WAIT_TIME) 961 v = stats->idle_time;
968 return blkio_fill_stat(key_str, MAX_KEY_LEN - 1, 962 break;
969 pd->stats.group_wait_time, cb, dname); 963 case BLKIO_STAT_EMPTY_TIME:
970 if (type == BLKIO_STAT_IDLE_TIME) 964 v = stats->empty_time;
971 return blkio_fill_stat(key_str, MAX_KEY_LEN - 1, 965 break;
972 pd->stats.idle_time, cb, dname); 966 case BLKIO_STAT_DEQUEUE:
973 if (type == BLKIO_STAT_EMPTY_TIME) 967 v = stats->dequeue;
974 return blkio_fill_stat(key_str, MAX_KEY_LEN - 1, 968 break;
975 pd->stats.empty_time, cb, dname); 969 case BLKIO_STAT_GROUP_WAIT_TIME:
976 if (type == BLKIO_STAT_DEQUEUE) 970 v = stats->group_wait_time;
977 return blkio_fill_stat(key_str, MAX_KEY_LEN - 1, 971 break;
978 pd->stats.dequeue, cb, dname);
979#endif 972#endif
973 default:
974 WARN_ON_ONCE(1);
975 }
980 976
981 for (sub_type = BLKIO_STAT_READ; sub_type < BLKIO_STAT_TOTAL; 977 blkio_get_key_name(0, dname, key_str, MAX_KEY_LEN, true);
982 sub_type++) { 978 cb->fill(cb, key_str, v);
983 blkio_get_key_name(sub_type, dname, key_str, MAX_KEY_LEN, 979 return v;
984 false);
985 cb->fill(cb, key_str, pd->stats.stat_arr[type][sub_type]);
986 } 980 }
987 disk_total = pd->stats.stat_arr[type][BLKIO_STAT_READ] + 981
988 pd->stats.stat_arr[type][BLKIO_STAT_WRITE]; 982 for (st = BLKIO_STAT_READ; st < BLKIO_STAT_TOTAL; st++) {
983 v = stats->stat_arr[type][st];
984
985 blkio_get_key_name(st, dname, key_str, MAX_KEY_LEN, false);
986 cb->fill(cb, key_str, v);
987 if (st == BLKIO_STAT_READ || st == BLKIO_STAT_WRITE)
988 disk_total += v;
989 }
990
989 blkio_get_key_name(BLKIO_STAT_TOTAL, dname, key_str, MAX_KEY_LEN, 991 blkio_get_key_name(BLKIO_STAT_TOTAL, dname, key_str, MAX_KEY_LEN,
990 false); 992 false);
991 cb->fill(cb, key_str, disk_total); 993 cb->fill(cb, key_str, disk_total);