Skip to content

Commit 167400d

Browse files
jteravestJens Axboe
authored andcommitted
blk-cgroup: Add unaccounted time to timeslice_used.
There are two kind of times that tasks are not charged for: the first seek and the extra time slice used over the allocated timeslice. Both of these exported as a new unaccounted_time stat. I think it would be good to have this reported in 'time' as well, but that is probably a separate discussion. Signed-off-by: Justin TerAvest <teravest@google.com> Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
1 parent 1f940bd commit 167400d

4 files changed

Lines changed: 41 additions & 14 deletions

File tree

‎block/blk-cgroup.c‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,12 +371,14 @@ void blkiocg_update_io_remove_stats(struct blkio_group *blkg,
371371
}
372372
EXPORT_SYMBOL_GPL(blkiocg_update_io_remove_stats);
373373

374-
void blkiocg_update_timeslice_used(struct blkio_group *blkg, unsigned long time)
374+
void blkiocg_update_timeslice_used(struct blkio_group *blkg, unsigned long time,
375+
unsigned long unaccounted_time)
375376
{
376377
unsigned long flags;
377378

378379
spin_lock_irqsave(&blkg->stats_lock, flags);
379380
blkg->stats.time += time;
381+
blkg->stats.unaccounted_time += unaccounted_time;
380382
spin_unlock_irqrestore(&blkg->stats_lock, flags);
381383
}
382384
EXPORT_SYMBOL_GPL(blkiocg_update_timeslice_used);
@@ -603,6 +605,9 @@ static uint64_t blkio_get_stat(struct blkio_group *blkg,
603605
if (type == BLKIO_STAT_SECTORS)
604606
return blkio_fill_stat(key_str, MAX_KEY_LEN - 1,
605607
blkg->stats.sectors, cb, dev);
608+
if (type == BLKIO_STAT_UNACCOUNTED_TIME)
609+
return blkio_fill_stat(key_str, MAX_KEY_LEN - 1,
610+
blkg->stats.unaccounted_time, cb, dev);
606611
#ifdef CONFIG_DEBUG_BLK_CGROUP
607612
if (type == BLKIO_STAT_AVG_QUEUE_SIZE) {
608613
uint64_t sum = blkg->stats.avg_queue_size_sum;
@@ -1106,6 +1111,9 @@ static int blkiocg_file_read_map(struct cgroup *cgrp, struct cftype *cft,
11061111
case BLKIO_PROP_sectors:
11071112
return blkio_read_blkg_stats(blkcg, cft, cb,
11081113
BLKIO_STAT_SECTORS, 0);
1114+
case BLKIO_PROP_unaccounted_time:
1115+
return blkio_read_blkg_stats(blkcg, cft, cb,
1116+
BLKIO_STAT_UNACCOUNTED_TIME, 0);
11091117
case BLKIO_PROP_io_service_bytes:
11101118
return blkio_read_blkg_stats(blkcg, cft, cb,
11111119
BLKIO_STAT_SERVICE_BYTES, 1);
@@ -1261,6 +1269,12 @@ struct cftype blkio_files[] = {
12611269
BLKIO_PROP_sectors),
12621270
.read_map = blkiocg_file_read_map,
12631271
},
1272+
{
1273+
.name = "unaccounted_time",
1274+
.private = BLKIOFILE_PRIVATE(BLKIO_POLICY_PROP,
1275+
BLKIO_PROP_unaccounted_time),
1276+
.read_map = blkiocg_file_read_map,
1277+
},
12641278
{
12651279
.name = "io_service_bytes",
12661280
.private = BLKIOFILE_PRIVATE(BLKIO_POLICY_PROP,

‎block/blk-cgroup.h‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ enum stat_type {
4949
/* All the single valued stats go below this */
5050
BLKIO_STAT_TIME,
5151
BLKIO_STAT_SECTORS,
52+
/* Time not charged to this cgroup */
53+
BLKIO_STAT_UNACCOUNTED_TIME,
5254
#ifdef CONFIG_DEBUG_BLK_CGROUP
5355
BLKIO_STAT_AVG_QUEUE_SIZE,
5456
BLKIO_STAT_IDLE_TIME,
@@ -81,6 +83,7 @@ enum blkcg_file_name_prop {
8183
BLKIO_PROP_io_serviced,
8284
BLKIO_PROP_time,
8385
BLKIO_PROP_sectors,
86+
BLKIO_PROP_unaccounted_time,
8487
BLKIO_PROP_io_service_time,
8588
BLKIO_PROP_io_wait_time,
8689
BLKIO_PROP_io_merged,
@@ -114,6 +117,8 @@ struct blkio_group_stats {
114117
/* total disk time and nr sectors dispatched by this group */
115118
uint64_t time;
116119
uint64_t sectors;
120+
/* Time not charged to this cgroup */
121+
uint64_t unaccounted_time;
117122
uint64_t stat_arr[BLKIO_STAT_QUEUED + 1][BLKIO_STAT_TOTAL];
118123
#ifdef CONFIG_DEBUG_BLK_CGROUP
119124
/* Sum of number of IOs queued across all samples */
@@ -293,7 +298,8 @@ extern int blkiocg_del_blkio_group(struct blkio_group *blkg);
293298
extern struct blkio_group *blkiocg_lookup_group(struct blkio_cgroup *blkcg,
294299
void *key);
295300
void blkiocg_update_timeslice_used(struct blkio_group *blkg,
296-
unsigned long time);
301+
unsigned long time,
302+
unsigned long unaccounted_time);
297303
void blkiocg_update_dispatch_stats(struct blkio_group *blkg, uint64_t bytes,
298304
bool direction, bool sync);
299305
void blkiocg_update_completion_stats(struct blkio_group *blkg,
@@ -319,7 +325,9 @@ blkiocg_del_blkio_group(struct blkio_group *blkg) { return 0; }
319325
static inline struct blkio_group *
320326
blkiocg_lookup_group(struct blkio_cgroup *blkcg, void *key) { return NULL; }
321327
static inline void blkiocg_update_timeslice_used(struct blkio_group *blkg,
322-
unsigned long time) {}
328+
unsigned long time,
329+
unsigned long unaccounted_time)
330+
{}
323331
static inline void blkiocg_update_dispatch_stats(struct blkio_group *blkg,
324332
uint64_t bytes, bool direction, bool sync) {}
325333
static inline void blkiocg_update_completion_stats(struct blkio_group *blkg,

‎block/cfq-iosched.c‎

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,8 @@ cfq_group_service_tree_del(struct cfq_data *cfqd, struct cfq_group *cfqg)
899899
cfq_blkiocg_update_dequeue_stats(&cfqg->blkg, 1);
900900
}
901901

902-
static inline unsigned int cfq_cfqq_slice_usage(struct cfq_queue *cfqq)
902+
static inline unsigned int cfq_cfqq_slice_usage(struct cfq_queue *cfqq,
903+
unsigned int *unaccounted_time)
903904
{
904905
unsigned int slice_used;
905906

@@ -918,8 +919,13 @@ static inline unsigned int cfq_cfqq_slice_usage(struct cfq_queue *cfqq)
918919
1);
919920
} else {
920921
slice_used = jiffies - cfqq->slice_start;
921-
if (slice_used > cfqq->allocated_slice)
922+
if (slice_used > cfqq->allocated_slice) {
923+
*unaccounted_time = slice_used - cfqq->allocated_slice;
922924
slice_used = cfqq->allocated_slice;
925+
}
926+
if (time_after(cfqq->slice_start, cfqq->dispatch_start))
927+
*unaccounted_time += cfqq->slice_start -
928+
cfqq->dispatch_start;
923929
}
924930

925931
return slice_used;
@@ -929,12 +935,12 @@ static void cfq_group_served(struct cfq_data *cfqd, struct cfq_group *cfqg,
929935
struct cfq_queue *cfqq)
930936
{
931937
struct cfq_rb_root *st = &cfqd->grp_service_tree;
932-
unsigned int used_sl, charge;
938+
unsigned int used_sl, charge, unaccounted_sl = 0;
933939
int nr_sync = cfqg->nr_cfqq - cfqg_busy_async_queues(cfqd, cfqg)
934940
- cfqg->service_tree_idle.count;
935941

936942
BUG_ON(nr_sync < 0);
937-
used_sl = charge = cfq_cfqq_slice_usage(cfqq);
943+
used_sl = charge = cfq_cfqq_slice_usage(cfqq, &unaccounted_sl);
938944

939945
if (iops_mode(cfqd))
940946
charge = cfqq->slice_dispatch;
@@ -960,7 +966,8 @@ static void cfq_group_served(struct cfq_data *cfqd, struct cfq_group *cfqg,
960966
cfq_log_cfqq(cfqq->cfqd, cfqq, "sl_used=%u disp=%u charge=%u iops=%u"
961967
" sect=%u", used_sl, cfqq->slice_dispatch, charge,
962968
iops_mode(cfqd), cfqq->nr_sectors);
963-
cfq_blkiocg_update_timeslice_used(&cfqg->blkg, used_sl);
969+
cfq_blkiocg_update_timeslice_used(&cfqg->blkg, used_sl,
970+
unaccounted_sl);
964971
cfq_blkiocg_set_start_empty_time(&cfqg->blkg);
965972
}
966973

@@ -3296,9 +3303,7 @@ static void cfq_preempt_queue(struct cfq_data *cfqd, struct cfq_queue *cfqq)
32963303
BUG_ON(!cfq_cfqq_on_rr(cfqq));
32973304

32983305
cfq_service_tree_add(cfqd, cfqq, 1);
3299-
3300-
cfqq->slice_end = 0;
3301-
cfq_mark_cfqq_slice_new(cfqq);
3306+
__cfq_set_active_queue(cfqd, cfqq);
33023307
}
33033308

33043309
/*

‎block/cfq.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ static inline void cfq_blkiocg_update_dequeue_stats(struct blkio_group *blkg,
1616
}
1717

1818
static inline void cfq_blkiocg_update_timeslice_used(struct blkio_group *blkg,
19-
unsigned long time)
19+
unsigned long time, unsigned long unaccounted_time)
2020
{
21-
blkiocg_update_timeslice_used(blkg, time);
21+
blkiocg_update_timeslice_used(blkg, time, unaccounted_time);
2222
}
2323

2424
static inline void cfq_blkiocg_set_start_empty_time(struct blkio_group *blkg)
@@ -85,7 +85,7 @@ static inline void cfq_blkiocg_update_dequeue_stats(struct blkio_group *blkg,
8585
unsigned long dequeue) {}
8686

8787
static inline void cfq_blkiocg_update_timeslice_used(struct blkio_group *blkg,
88-
unsigned long time) {}
88+
unsigned long time, unsigned long unaccounted_time) {}
8989
static inline void cfq_blkiocg_set_start_empty_time(struct blkio_group *blkg) {}
9090
static inline void cfq_blkiocg_update_io_remove_stats(struct blkio_group *blkg,
9191
bool direction, bool sync) {}

0 commit comments

Comments
 (0)