Skip to content

Commit d332ce0

Browse files
osandovaxboe
authored andcommitted
blk-mq-debugfs: allow schedulers to register debugfs attributes
This provides the infrastructure for schedulers to expose their internal state through debugfs. We add a list of queue attributes and a list of hctx attributes to struct elevator_type and wire them up when switching schedulers. Signed-off-by: Omar Sandoval <[email protected]> Reviewed-by: Hannes Reinecke <[email protected]> Add missing seq_file.h header in blk-mq-debugfs.h Signed-off-by: Jens Axboe <[email protected]>
1 parent 9c1051a commit d332ce0

File tree

6 files changed

+127
-17
lines changed

6 files changed

+127
-17
lines changed

block/blk-mq-debugfs.c

Lines changed: 65 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,6 @@
2424
#include "blk-mq-debugfs.h"
2525
#include "blk-mq-tag.h"
2626

27-
struct blk_mq_debugfs_attr {
28-
const char *name;
29-
umode_t mode;
30-
int (*show)(void *, struct seq_file *);
31-
ssize_t (*write)(void *, const char __user *, size_t, loff_t *);
32-
/* Set either .show or .seq_ops. */
33-
const struct seq_operations *seq_ops;
34-
};
35-
3627
static int blk_flags_show(struct seq_file *m, const unsigned long flags,
3728
const char *const *flag_name, int flag_name_count)
3829
{
@@ -725,6 +716,9 @@ int blk_mq_debugfs_register(struct request_queue *q)
725716
queue_for_each_hw_ctx(q, hctx, i) {
726717
if (!hctx->debugfs_dir && blk_mq_debugfs_register_hctx(q, hctx))
727718
goto err;
719+
if (q->elevator && !hctx->sched_debugfs_dir &&
720+
blk_mq_debugfs_register_sched_hctx(q, hctx))
721+
goto err;
728722
}
729723

730724
return 0;
@@ -737,6 +731,7 @@ int blk_mq_debugfs_register(struct request_queue *q)
737731
void blk_mq_debugfs_unregister(struct request_queue *q)
738732
{
739733
debugfs_remove_recursive(q->debugfs_dir);
734+
q->sched_debugfs_dir = NULL;
740735
q->debugfs_dir = NULL;
741736
}
742737

@@ -791,6 +786,7 @@ int blk_mq_debugfs_register_hctx(struct request_queue *q,
791786
void blk_mq_debugfs_unregister_hctx(struct blk_mq_hw_ctx *hctx)
792787
{
793788
debugfs_remove_recursive(hctx->debugfs_dir);
789+
hctx->sched_debugfs_dir = NULL;
794790
hctx->debugfs_dir = NULL;
795791
}
796792

@@ -815,3 +811,63 @@ void blk_mq_debugfs_unregister_hctxs(struct request_queue *q)
815811
queue_for_each_hw_ctx(q, hctx, i)
816812
blk_mq_debugfs_unregister_hctx(hctx);
817813
}
814+
815+
int blk_mq_debugfs_register_sched(struct request_queue *q)
816+
{
817+
struct elevator_type *e = q->elevator->type;
818+
819+
if (!q->debugfs_dir)
820+
return -ENOENT;
821+
822+
if (!e->queue_debugfs_attrs)
823+
return 0;
824+
825+
q->sched_debugfs_dir = debugfs_create_dir("sched", q->debugfs_dir);
826+
if (!q->sched_debugfs_dir)
827+
return -ENOMEM;
828+
829+
if (!debugfs_create_files(q->sched_debugfs_dir, q,
830+
e->queue_debugfs_attrs))
831+
goto err;
832+
833+
return 0;
834+
835+
err:
836+
blk_mq_debugfs_unregister_sched(q);
837+
return -ENOMEM;
838+
}
839+
840+
void blk_mq_debugfs_unregister_sched(struct request_queue *q)
841+
{
842+
debugfs_remove_recursive(q->sched_debugfs_dir);
843+
q->sched_debugfs_dir = NULL;
844+
}
845+
846+
int blk_mq_debugfs_register_sched_hctx(struct request_queue *q,
847+
struct blk_mq_hw_ctx *hctx)
848+
{
849+
struct elevator_type *e = q->elevator->type;
850+
851+
if (!hctx->debugfs_dir)
852+
return -ENOENT;
853+
854+
if (!e->hctx_debugfs_attrs)
855+
return 0;
856+
857+
hctx->sched_debugfs_dir = debugfs_create_dir("sched",
858+
hctx->debugfs_dir);
859+
if (!hctx->sched_debugfs_dir)
860+
return -ENOMEM;
861+
862+
if (!debugfs_create_files(hctx->sched_debugfs_dir, hctx,
863+
e->hctx_debugfs_attrs))
864+
return -ENOMEM;
865+
866+
return 0;
867+
}
868+
869+
void blk_mq_debugfs_unregister_sched_hctx(struct blk_mq_hw_ctx *hctx)
870+
{
871+
debugfs_remove_recursive(hctx->sched_debugfs_dir);
872+
hctx->sched_debugfs_dir = NULL;
873+
}

block/blk-mq-debugfs.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,31 @@
22
#define INT_BLK_MQ_DEBUGFS_H
33

44
#ifdef CONFIG_BLK_DEBUG_FS
5+
6+
#include <linux/seq_file.h>
7+
8+
struct blk_mq_debugfs_attr {
9+
const char *name;
10+
umode_t mode;
11+
int (*show)(void *, struct seq_file *);
12+
ssize_t (*write)(void *, const char __user *, size_t, loff_t *);
13+
/* Set either .show or .seq_ops. */
14+
const struct seq_operations *seq_ops;
15+
};
16+
517
int blk_mq_debugfs_register(struct request_queue *q);
618
void blk_mq_debugfs_unregister(struct request_queue *q);
719
int blk_mq_debugfs_register_hctx(struct request_queue *q,
820
struct blk_mq_hw_ctx *hctx);
921
void blk_mq_debugfs_unregister_hctx(struct blk_mq_hw_ctx *hctx);
1022
int blk_mq_debugfs_register_hctxs(struct request_queue *q);
1123
void blk_mq_debugfs_unregister_hctxs(struct request_queue *q);
24+
25+
int blk_mq_debugfs_register_sched(struct request_queue *q);
26+
void blk_mq_debugfs_unregister_sched(struct request_queue *q);
27+
int blk_mq_debugfs_register_sched_hctx(struct request_queue *q,
28+
struct blk_mq_hw_ctx *hctx);
29+
void blk_mq_debugfs_unregister_sched_hctx(struct blk_mq_hw_ctx *hctx);
1230
#else
1331
static inline int blk_mq_debugfs_register(struct request_queue *q)
1432
{
@@ -37,6 +55,25 @@ static inline int blk_mq_debugfs_register_hctxs(struct request_queue *q)
3755
static inline void blk_mq_debugfs_unregister_hctxs(struct request_queue *q)
3856
{
3957
}
58+
59+
static inline int blk_mq_debugfs_register_sched(struct request_queue *q)
60+
{
61+
return 0;
62+
}
63+
64+
static inline void blk_mq_debugfs_unregister_sched(struct request_queue *q)
65+
{
66+
}
67+
68+
static inline int blk_mq_debugfs_register_sched_hctx(struct request_queue *q,
69+
struct blk_mq_hw_ctx *hctx)
70+
{
71+
return 0;
72+
}
73+
74+
static inline void blk_mq_debugfs_unregister_sched_hctx(struct blk_mq_hw_ctx *hctx)
75+
{
76+
}
4077
#endif
4178

4279
#endif

block/blk-mq-sched.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include "blk.h"
1313
#include "blk-mq.h"
14+
#include "blk-mq-debugfs.h"
1415
#include "blk-mq-sched.h"
1516
#include "blk-mq-tag.h"
1617
#include "blk-wbt.h"
@@ -472,6 +473,8 @@ int blk_mq_sched_init_hctx(struct request_queue *q, struct blk_mq_hw_ctx *hctx,
472473
}
473474
}
474475

476+
blk_mq_debugfs_register_sched_hctx(q, hctx);
477+
475478
return 0;
476479
}
477480

@@ -483,6 +486,8 @@ void blk_mq_sched_exit_hctx(struct request_queue *q, struct blk_mq_hw_ctx *hctx,
483486
if (!e)
484487
return;
485488

489+
blk_mq_debugfs_unregister_sched_hctx(hctx);
490+
486491
if (e->type->ops.mq.exit_hctx && hctx->sched_data) {
487492
e->type->ops.mq.exit_hctx(hctx, hctx_idx);
488493
hctx->sched_data = NULL;
@@ -519,8 +524,10 @@ int blk_mq_init_sched(struct request_queue *q, struct elevator_type *e)
519524
if (ret)
520525
goto err;
521526

522-
if (e->ops.mq.init_hctx) {
523-
queue_for_each_hw_ctx(q, hctx, i) {
527+
blk_mq_debugfs_register_sched(q);
528+
529+
queue_for_each_hw_ctx(q, hctx, i) {
530+
if (e->ops.mq.init_hctx) {
524531
ret = e->ops.mq.init_hctx(hctx, i);
525532
if (ret) {
526533
eq = q->elevator;
@@ -529,6 +536,7 @@ int blk_mq_init_sched(struct request_queue *q, struct elevator_type *e)
529536
return ret;
530537
}
531538
}
539+
blk_mq_debugfs_register_sched_hctx(q, hctx);
532540
}
533541

534542
return 0;
@@ -544,14 +552,14 @@ void blk_mq_exit_sched(struct request_queue *q, struct elevator_queue *e)
544552
struct blk_mq_hw_ctx *hctx;
545553
unsigned int i;
546554

547-
if (e->type->ops.mq.exit_hctx) {
548-
queue_for_each_hw_ctx(q, hctx, i) {
549-
if (hctx->sched_data) {
550-
e->type->ops.mq.exit_hctx(hctx, i);
551-
hctx->sched_data = NULL;
552-
}
555+
queue_for_each_hw_ctx(q, hctx, i) {
556+
blk_mq_debugfs_unregister_sched_hctx(hctx);
557+
if (e->type->ops.mq.exit_hctx && hctx->sched_data) {
558+
e->type->ops.mq.exit_hctx(hctx, i);
559+
hctx->sched_data = NULL;
553560
}
554561
}
562+
blk_mq_debugfs_unregister_sched(q);
555563
if (e->type->ops.mq.exit_sched)
556564
e->type->ops.mq.exit_sched(e);
557565
blk_mq_sched_tags_teardown(q);

include/linux/blk-mq.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ struct blk_mq_hw_ctx {
6060

6161
#ifdef CONFIG_BLK_DEBUG_FS
6262
struct dentry *debugfs_dir;
63+
struct dentry *sched_debugfs_dir;
6364
#endif
6465
};
6566

include/linux/blkdev.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,7 @@ struct request_queue {
579579

580580
#ifdef CONFIG_BLK_DEBUG_FS
581581
struct dentry *debugfs_dir;
582+
struct dentry *sched_debugfs_dir;
582583
#endif
583584

584585
bool mq_sysfs_init_done;

include/linux/elevator.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
struct io_cq;
1010
struct elevator_type;
11+
#ifdef CONFIG_BLK_DEBUG_FS
12+
struct blk_mq_debugfs_attr;
13+
#endif
1114

1215
/*
1316
* Return values from elevator merger
@@ -144,6 +147,10 @@ struct elevator_type
144147
char elevator_name[ELV_NAME_MAX];
145148
struct module *elevator_owner;
146149
bool uses_mq;
150+
#ifdef CONFIG_BLK_DEBUG_FS
151+
const struct blk_mq_debugfs_attr *queue_debugfs_attrs;
152+
const struct blk_mq_debugfs_attr *hctx_debugfs_attrs;
153+
#endif
147154

148155
/* managed by elevator core */
149156
char icq_cache_name[ELV_NAME_MAX + 5]; /* elvname + "_io_cq" */

0 commit comments

Comments
 (0)