aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--block/blk-cgroup.c100
-rw-r--r--block/blk-cgroup.h6
2 files changed, 56 insertions, 50 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);
diff --git a/block/blk-cgroup.h b/block/blk-cgroup.h
index 1fa3c5e8d87f..8bdcf504f94b 100644
--- a/block/blk-cgroup.h
+++ b/block/blk-cgroup.h
@@ -39,6 +39,7 @@ enum stat_type {
39 BLKIO_STAT_WAIT_TIME, 39 BLKIO_STAT_WAIT_TIME,
40 /* Number of IOs queued up */ 40 /* Number of IOs queued up */
41 BLKIO_STAT_QUEUED, 41 BLKIO_STAT_QUEUED,
42
42 /* All the single valued stats go below this */ 43 /* All the single valued stats go below this */
43 BLKIO_STAT_TIME, 44 BLKIO_STAT_TIME,
44#ifdef CONFIG_DEBUG_BLK_CGROUP 45#ifdef CONFIG_DEBUG_BLK_CGROUP
@@ -52,6 +53,9 @@ enum stat_type {
52#endif 53#endif
53}; 54};
54 55
56/* Types lower than this live in stat_arr and have subtypes */
57#define BLKIO_STAT_ARR_NR (BLKIO_STAT_QUEUED + 1)
58
55/* Per cpu stats */ 59/* Per cpu stats */
56enum stat_type_cpu { 60enum stat_type_cpu {
57 BLKIO_STAT_CPU_SECTORS, 61 BLKIO_STAT_CPU_SECTORS,
@@ -117,7 +121,7 @@ struct blkio_cgroup {
117struct blkio_group_stats { 121struct blkio_group_stats {
118 /* total disk time and nr sectors dispatched by this group */ 122 /* total disk time and nr sectors dispatched by this group */
119 uint64_t time; 123 uint64_t time;
120 uint64_t stat_arr[BLKIO_STAT_QUEUED + 1][BLKIO_STAT_TOTAL]; 124 uint64_t stat_arr[BLKIO_STAT_ARR_NR][BLKIO_STAT_TOTAL];
121#ifdef CONFIG_DEBUG_BLK_CGROUP 125#ifdef CONFIG_DEBUG_BLK_CGROUP
122 /* Time not charged to this cgroup */ 126 /* Time not charged to this cgroup */
123 uint64_t unaccounted_time; 127 uint64_t unaccounted_time;