|
13 | 13 |
|
14 | 14 | #include "blk.h" |
15 | 15 | #include "blk-mq.h" |
| 16 | +#include "blk-wbt.h" |
16 | 17 |
|
17 | 18 | struct queue_sysfs_entry { |
18 | 19 | struct attribute attr; |
@@ -41,6 +42,19 @@ queue_var_store(unsigned long *var, const char *page, size_t count) |
41 | 42 | return count; |
42 | 43 | } |
43 | 44 |
|
| 45 | +static ssize_t queue_var_store64(u64 *var, const char *page) |
| 46 | +{ |
| 47 | + int err; |
| 48 | + u64 v; |
| 49 | + |
| 50 | + err = kstrtou64(page, 10, &v); |
| 51 | + if (err < 0) |
| 52 | + return err; |
| 53 | + |
| 54 | + *var = v; |
| 55 | + return 0; |
| 56 | +} |
| 57 | + |
44 | 58 | static ssize_t queue_requests_show(struct request_queue *q, char *page) |
45 | 59 | { |
46 | 60 | return queue_var_show(q->nr_requests, (page)); |
@@ -364,6 +378,32 @@ static ssize_t queue_poll_store(struct request_queue *q, const char *page, |
364 | 378 | return ret; |
365 | 379 | } |
366 | 380 |
|
| 381 | +static ssize_t queue_wb_lat_show(struct request_queue *q, char *page) |
| 382 | +{ |
| 383 | + if (!q->rq_wb) |
| 384 | + return -EINVAL; |
| 385 | + |
| 386 | + return sprintf(page, "%llu\n", div_u64(q->rq_wb->min_lat_nsec, 1000)); |
| 387 | +} |
| 388 | + |
| 389 | +static ssize_t queue_wb_lat_store(struct request_queue *q, const char *page, |
| 390 | + size_t count) |
| 391 | +{ |
| 392 | + ssize_t ret; |
| 393 | + u64 val; |
| 394 | + |
| 395 | + if (!q->rq_wb) |
| 396 | + return -EINVAL; |
| 397 | + |
| 398 | + ret = queue_var_store64(&val, page); |
| 399 | + if (ret < 0) |
| 400 | + return ret; |
| 401 | + |
| 402 | + q->rq_wb->min_lat_nsec = val * 1000ULL; |
| 403 | + wbt_update_limits(q->rq_wb); |
| 404 | + return count; |
| 405 | +} |
| 406 | + |
367 | 407 | static ssize_t queue_wc_show(struct request_queue *q, char *page) |
368 | 408 | { |
369 | 409 | if (test_bit(QUEUE_FLAG_WC, &q->queue_flags)) |
@@ -578,6 +618,12 @@ static struct queue_sysfs_entry queue_stats_entry = { |
578 | 618 | .show = queue_stats_show, |
579 | 619 | }; |
580 | 620 |
|
| 621 | +static struct queue_sysfs_entry queue_wb_lat_entry = { |
| 622 | + .attr = {.name = "wbt_lat_usec", .mode = S_IRUGO | S_IWUSR }, |
| 623 | + .show = queue_wb_lat_show, |
| 624 | + .store = queue_wb_lat_store, |
| 625 | +}; |
| 626 | + |
581 | 627 | static struct attribute *default_attrs[] = { |
582 | 628 | &queue_requests_entry.attr, |
583 | 629 | &queue_ra_entry.attr, |
@@ -608,6 +654,7 @@ static struct attribute *default_attrs[] = { |
608 | 654 | &queue_wc_entry.attr, |
609 | 655 | &queue_dax_entry.attr, |
610 | 656 | &queue_stats_entry.attr, |
| 657 | + &queue_wb_lat_entry.attr, |
611 | 658 | NULL, |
612 | 659 | }; |
613 | 660 |
|
@@ -682,6 +729,7 @@ static void blk_release_queue(struct kobject *kobj) |
682 | 729 | struct request_queue *q = |
683 | 730 | container_of(kobj, struct request_queue, kobj); |
684 | 731 |
|
| 732 | + wbt_exit(q); |
685 | 733 | bdi_exit(&q->backing_dev_info); |
686 | 734 | blkcg_exit_queue(q); |
687 | 735 |
|
@@ -722,6 +770,44 @@ struct kobj_type blk_queue_ktype = { |
722 | 770 | .release = blk_release_queue, |
723 | 771 | }; |
724 | 772 |
|
| 773 | +static void blk_wb_stat_get(void *data, struct blk_rq_stat *stat) |
| 774 | +{ |
| 775 | + blk_queue_stat_get(data, stat); |
| 776 | +} |
| 777 | + |
| 778 | +static void blk_wb_stat_clear(void *data) |
| 779 | +{ |
| 780 | + blk_stat_clear(data); |
| 781 | +} |
| 782 | + |
| 783 | +static bool blk_wb_stat_is_current(struct blk_rq_stat *stat) |
| 784 | +{ |
| 785 | + return blk_stat_is_current(stat); |
| 786 | +} |
| 787 | + |
| 788 | +static struct wb_stat_ops wb_stat_ops = { |
| 789 | + .get = blk_wb_stat_get, |
| 790 | + .is_current = blk_wb_stat_is_current, |
| 791 | + .clear = blk_wb_stat_clear, |
| 792 | +}; |
| 793 | + |
| 794 | +static void blk_wb_init(struct request_queue *q) |
| 795 | +{ |
| 796 | +#ifndef CONFIG_BLK_WBT_MQ |
| 797 | + if (q->mq_ops) |
| 798 | + return; |
| 799 | +#endif |
| 800 | +#ifndef CONFIG_BLK_WBT_SQ |
| 801 | + if (q->request_fn) |
| 802 | + return; |
| 803 | +#endif |
| 804 | + |
| 805 | + /* |
| 806 | + * If this fails, we don't get throttling |
| 807 | + */ |
| 808 | + wbt_init(q, &wb_stat_ops); |
| 809 | +} |
| 810 | + |
725 | 811 | int blk_register_queue(struct gendisk *disk) |
726 | 812 | { |
727 | 813 | int ret; |
@@ -761,6 +847,8 @@ int blk_register_queue(struct gendisk *disk) |
761 | 847 | if (q->mq_ops) |
762 | 848 | blk_mq_register_dev(dev, q); |
763 | 849 |
|
| 850 | + blk_wb_init(q); |
| 851 | + |
764 | 852 | if (!q->request_fn) |
765 | 853 | return 0; |
766 | 854 |
|
|
0 commit comments