2 * Copyright (C) 2017 Facebook
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public
6 * License v2 as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 #include <linux/kernel.h>
18 #include <linux/blkdev.h>
19 #include <linux/debugfs.h>
21 #include <linux/blk-mq.h>
24 #include "blk-mq-tag.h"
26 struct blk_mq_debugfs_attr
{
29 const struct file_operations
*fops
;
32 static int blk_mq_debugfs_seq_open(struct inode
*inode
, struct file
*file
,
33 const struct seq_operations
*ops
)
38 ret
= seq_open(file
, ops
);
40 m
= file
->private_data
;
41 m
->private = inode
->i_private
;
46 static int blk_flags_show(struct seq_file
*m
, const unsigned long flags
,
47 const char *const *flag_name
, int flag_name_count
)
52 for (i
= 0; i
< sizeof(flags
) * BITS_PER_BYTE
; i
++) {
53 if (!(flags
& BIT(i
)))
58 if (i
< flag_name_count
&& flag_name
[i
])
59 seq_puts(m
, flag_name
[i
]);
61 seq_printf(m
, "%d", i
);
66 #define QUEUE_FLAG_NAME(name) [QUEUE_FLAG_##name] = #name
67 static const char *const blk_queue_flag_name
[] = {
68 QUEUE_FLAG_NAME(QUEUED
),
69 QUEUE_FLAG_NAME(STOPPED
),
70 QUEUE_FLAG_NAME(SYNCFULL
),
71 QUEUE_FLAG_NAME(ASYNCFULL
),
72 QUEUE_FLAG_NAME(DYING
),
73 QUEUE_FLAG_NAME(BYPASS
),
74 QUEUE_FLAG_NAME(BIDI
),
75 QUEUE_FLAG_NAME(NOMERGES
),
76 QUEUE_FLAG_NAME(SAME_COMP
),
77 QUEUE_FLAG_NAME(FAIL_IO
),
78 QUEUE_FLAG_NAME(STACKABLE
),
79 QUEUE_FLAG_NAME(NONROT
),
80 QUEUE_FLAG_NAME(IO_STAT
),
81 QUEUE_FLAG_NAME(DISCARD
),
82 QUEUE_FLAG_NAME(NOXMERGES
),
83 QUEUE_FLAG_NAME(ADD_RANDOM
),
84 QUEUE_FLAG_NAME(SECERASE
),
85 QUEUE_FLAG_NAME(SAME_FORCE
),
86 QUEUE_FLAG_NAME(DEAD
),
87 QUEUE_FLAG_NAME(INIT_DONE
),
88 QUEUE_FLAG_NAME(NO_SG_MERGE
),
89 QUEUE_FLAG_NAME(POLL
),
92 QUEUE_FLAG_NAME(FLUSH_NQ
),
94 QUEUE_FLAG_NAME(STATS
),
95 QUEUE_FLAG_NAME(POLL_STATS
),
96 QUEUE_FLAG_NAME(REGISTERED
),
98 #undef QUEUE_FLAG_NAME
100 static int blk_queue_flags_show(struct seq_file
*m
, void *v
)
102 struct request_queue
*q
= m
->private;
104 blk_flags_show(m
, q
->queue_flags
, blk_queue_flag_name
,
105 ARRAY_SIZE(blk_queue_flag_name
));
110 static ssize_t
blk_queue_flags_store(struct file
*file
, const char __user
*buf
,
111 size_t count
, loff_t
*ppos
)
113 struct request_queue
*q
= file_inode(file
)->i_private
;
114 char opbuf
[16] = { }, *op
;
116 if (count
>= sizeof(opbuf
)) {
117 pr_err("%s: operation too long\n", __func__
);
121 if (copy_from_user(opbuf
, buf
, count
))
123 op
= strstrip(opbuf
);
124 if (strcmp(op
, "run") == 0) {
125 blk_mq_run_hw_queues(q
, true);
126 } else if (strcmp(op
, "start") == 0) {
127 blk_mq_start_stopped_hw_queues(q
, true);
129 pr_err("%s: unsupported operation '%s'\n", __func__
, op
);
131 pr_err("%s: use either 'run' or 'start'\n", __func__
);
137 static int blk_queue_flags_open(struct inode
*inode
, struct file
*file
)
139 return single_open(file
, blk_queue_flags_show
, inode
->i_private
);
142 static const struct file_operations blk_queue_flags_fops
= {
143 .open
= blk_queue_flags_open
,
146 .release
= single_release
,
147 .write
= blk_queue_flags_store
,
150 static void print_stat(struct seq_file
*m
, struct blk_rq_stat
*stat
)
152 if (stat
->nr_samples
) {
153 seq_printf(m
, "samples=%d, mean=%lld, min=%llu, max=%llu",
154 stat
->nr_samples
, stat
->mean
, stat
->min
, stat
->max
);
156 seq_puts(m
, "samples=0");
160 static int queue_poll_stat_show(struct seq_file
*m
, void *v
)
162 struct request_queue
*q
= m
->private;
165 for (bucket
= 0; bucket
< BLK_MQ_POLL_STATS_BKTS
/2; bucket
++) {
166 seq_printf(m
, "read (%d Bytes): ", 1 << (9+bucket
));
167 print_stat(m
, &q
->poll_stat
[2*bucket
]);
170 seq_printf(m
, "write (%d Bytes): ", 1 << (9+bucket
));
171 print_stat(m
, &q
->poll_stat
[2*bucket
+1]);
177 static int queue_poll_stat_open(struct inode
*inode
, struct file
*file
)
179 return single_open(file
, queue_poll_stat_show
, inode
->i_private
);
182 static const struct file_operations queue_poll_stat_fops
= {
183 .open
= queue_poll_stat_open
,
186 .release
= single_release
,
189 #define HCTX_STATE_NAME(name) [BLK_MQ_S_##name] = #name
190 static const char *const hctx_state_name
[] = {
191 HCTX_STATE_NAME(STOPPED
),
192 HCTX_STATE_NAME(TAG_ACTIVE
),
193 HCTX_STATE_NAME(SCHED_RESTART
),
194 HCTX_STATE_NAME(TAG_WAITING
),
195 HCTX_STATE_NAME(START_ON_RUN
),
197 #undef HCTX_STATE_NAME
199 static int hctx_state_show(struct seq_file
*m
, void *v
)
201 struct blk_mq_hw_ctx
*hctx
= m
->private;
203 blk_flags_show(m
, hctx
->state
, hctx_state_name
,
204 ARRAY_SIZE(hctx_state_name
));
209 static int hctx_state_open(struct inode
*inode
, struct file
*file
)
211 return single_open(file
, hctx_state_show
, inode
->i_private
);
214 static const struct file_operations hctx_state_fops
= {
215 .open
= hctx_state_open
,
218 .release
= single_release
,
221 #define BLK_TAG_ALLOC_NAME(name) [BLK_TAG_ALLOC_##name] = #name
222 static const char *const alloc_policy_name
[] = {
223 BLK_TAG_ALLOC_NAME(FIFO
),
224 BLK_TAG_ALLOC_NAME(RR
),
226 #undef BLK_TAG_ALLOC_NAME
228 #define HCTX_FLAG_NAME(name) [ilog2(BLK_MQ_F_##name)] = #name
229 static const char *const hctx_flag_name
[] = {
230 HCTX_FLAG_NAME(SHOULD_MERGE
),
231 HCTX_FLAG_NAME(TAG_SHARED
),
232 HCTX_FLAG_NAME(SG_MERGE
),
233 HCTX_FLAG_NAME(BLOCKING
),
234 HCTX_FLAG_NAME(NO_SCHED
),
236 #undef HCTX_FLAG_NAME
238 static int hctx_flags_show(struct seq_file
*m
, void *v
)
240 struct blk_mq_hw_ctx
*hctx
= m
->private;
241 const int alloc_policy
= BLK_MQ_FLAG_TO_ALLOC_POLICY(hctx
->flags
);
243 seq_puts(m
, "alloc_policy=");
244 if (alloc_policy
< ARRAY_SIZE(alloc_policy_name
) &&
245 alloc_policy_name
[alloc_policy
])
246 seq_puts(m
, alloc_policy_name
[alloc_policy
]);
248 seq_printf(m
, "%d", alloc_policy
);
251 hctx
->flags
^ BLK_ALLOC_POLICY_TO_MQ_FLAG(alloc_policy
),
252 hctx_flag_name
, ARRAY_SIZE(hctx_flag_name
));
257 static int hctx_flags_open(struct inode
*inode
, struct file
*file
)
259 return single_open(file
, hctx_flags_show
, inode
->i_private
);
262 static const struct file_operations hctx_flags_fops
= {
263 .open
= hctx_flags_open
,
266 .release
= single_release
,
269 #define REQ_OP_NAME(name) [REQ_OP_##name] = #name
270 static const char *const op_name
[] = {
274 REQ_OP_NAME(DISCARD
),
275 REQ_OP_NAME(ZONE_REPORT
),
276 REQ_OP_NAME(SECURE_ERASE
),
277 REQ_OP_NAME(ZONE_RESET
),
278 REQ_OP_NAME(WRITE_SAME
),
279 REQ_OP_NAME(WRITE_ZEROES
),
280 REQ_OP_NAME(SCSI_IN
),
281 REQ_OP_NAME(SCSI_OUT
),
283 REQ_OP_NAME(DRV_OUT
),
287 #define CMD_FLAG_NAME(name) [__REQ_##name] = #name
288 static const char *const cmd_flag_name
[] = {
289 CMD_FLAG_NAME(FAILFAST_DEV
),
290 CMD_FLAG_NAME(FAILFAST_TRANSPORT
),
291 CMD_FLAG_NAME(FAILFAST_DRIVER
),
295 CMD_FLAG_NAME(NOMERGE
),
297 CMD_FLAG_NAME(INTEGRITY
),
299 CMD_FLAG_NAME(PREFLUSH
),
300 CMD_FLAG_NAME(RAHEAD
),
301 CMD_FLAG_NAME(BACKGROUND
),
302 CMD_FLAG_NAME(NOUNMAP
),
306 #define RQF_NAME(name) [ilog2((__force u32)RQF_##name)] = #name
307 static const char *const rqf_name
[] = {
311 RQF_NAME(SOFTBARRIER
),
313 RQF_NAME(MIXED_MERGE
),
314 RQF_NAME(MQ_INFLIGHT
),
326 RQF_NAME(SPECIAL_PAYLOAD
),
330 static int blk_mq_debugfs_rq_show(struct seq_file
*m
, void *v
)
332 struct request
*rq
= list_entry_rq(v
);
333 const struct blk_mq_ops
*const mq_ops
= rq
->q
->mq_ops
;
334 const unsigned int op
= rq
->cmd_flags
& REQ_OP_MASK
;
336 seq_printf(m
, "%p {.op=", rq
);
337 if (op
< ARRAY_SIZE(op_name
) && op_name
[op
])
338 seq_printf(m
, "%s", op_name
[op
]);
340 seq_printf(m
, "%d", op
);
341 seq_puts(m
, ", .cmd_flags=");
342 blk_flags_show(m
, rq
->cmd_flags
& ~REQ_OP_MASK
, cmd_flag_name
,
343 ARRAY_SIZE(cmd_flag_name
));
344 seq_puts(m
, ", .rq_flags=");
345 blk_flags_show(m
, (__force
unsigned int)rq
->rq_flags
, rqf_name
,
346 ARRAY_SIZE(rqf_name
));
347 seq_printf(m
, ", .tag=%d, .internal_tag=%d", rq
->tag
,
350 mq_ops
->show_rq(m
, rq
);
355 static void *hctx_dispatch_start(struct seq_file
*m
, loff_t
*pos
)
356 __acquires(&hctx
->lock
)
358 struct blk_mq_hw_ctx
*hctx
= m
->private;
360 spin_lock(&hctx
->lock
);
361 return seq_list_start(&hctx
->dispatch
, *pos
);
364 static void *hctx_dispatch_next(struct seq_file
*m
, void *v
, loff_t
*pos
)
366 struct blk_mq_hw_ctx
*hctx
= m
->private;
368 return seq_list_next(v
, &hctx
->dispatch
, pos
);
371 static void hctx_dispatch_stop(struct seq_file
*m
, void *v
)
372 __releases(&hctx
->lock
)
374 struct blk_mq_hw_ctx
*hctx
= m
->private;
376 spin_unlock(&hctx
->lock
);
379 static const struct seq_operations hctx_dispatch_seq_ops
= {
380 .start
= hctx_dispatch_start
,
381 .next
= hctx_dispatch_next
,
382 .stop
= hctx_dispatch_stop
,
383 .show
= blk_mq_debugfs_rq_show
,
386 static int hctx_dispatch_open(struct inode
*inode
, struct file
*file
)
388 return blk_mq_debugfs_seq_open(inode
, file
, &hctx_dispatch_seq_ops
);
391 static const struct file_operations hctx_dispatch_fops
= {
392 .open
= hctx_dispatch_open
,
395 .release
= seq_release
,
398 static int hctx_ctx_map_show(struct seq_file
*m
, void *v
)
400 struct blk_mq_hw_ctx
*hctx
= m
->private;
402 sbitmap_bitmap_show(&hctx
->ctx_map
, m
);
406 static int hctx_ctx_map_open(struct inode
*inode
, struct file
*file
)
408 return single_open(file
, hctx_ctx_map_show
, inode
->i_private
);
411 static const struct file_operations hctx_ctx_map_fops
= {
412 .open
= hctx_ctx_map_open
,
415 .release
= single_release
,
418 static void blk_mq_debugfs_tags_show(struct seq_file
*m
,
419 struct blk_mq_tags
*tags
)
421 seq_printf(m
, "nr_tags=%u\n", tags
->nr_tags
);
422 seq_printf(m
, "nr_reserved_tags=%u\n", tags
->nr_reserved_tags
);
423 seq_printf(m
, "active_queues=%d\n",
424 atomic_read(&tags
->active_queues
));
426 seq_puts(m
, "\nbitmap_tags:\n");
427 sbitmap_queue_show(&tags
->bitmap_tags
, m
);
429 if (tags
->nr_reserved_tags
) {
430 seq_puts(m
, "\nbreserved_tags:\n");
431 sbitmap_queue_show(&tags
->breserved_tags
, m
);
435 static int hctx_tags_show(struct seq_file
*m
, void *v
)
437 struct blk_mq_hw_ctx
*hctx
= m
->private;
438 struct request_queue
*q
= hctx
->queue
;
441 res
= mutex_lock_interruptible(&q
->sysfs_lock
);
445 blk_mq_debugfs_tags_show(m
, hctx
->tags
);
446 mutex_unlock(&q
->sysfs_lock
);
452 static int hctx_tags_open(struct inode
*inode
, struct file
*file
)
454 return single_open(file
, hctx_tags_show
, inode
->i_private
);
457 static const struct file_operations hctx_tags_fops
= {
458 .open
= hctx_tags_open
,
461 .release
= single_release
,
464 static int hctx_tags_bitmap_show(struct seq_file
*m
, void *v
)
466 struct blk_mq_hw_ctx
*hctx
= m
->private;
467 struct request_queue
*q
= hctx
->queue
;
470 res
= mutex_lock_interruptible(&q
->sysfs_lock
);
474 sbitmap_bitmap_show(&hctx
->tags
->bitmap_tags
.sb
, m
);
475 mutex_unlock(&q
->sysfs_lock
);
481 static int hctx_tags_bitmap_open(struct inode
*inode
, struct file
*file
)
483 return single_open(file
, hctx_tags_bitmap_show
, inode
->i_private
);
486 static const struct file_operations hctx_tags_bitmap_fops
= {
487 .open
= hctx_tags_bitmap_open
,
490 .release
= single_release
,
493 static int hctx_sched_tags_show(struct seq_file
*m
, void *v
)
495 struct blk_mq_hw_ctx
*hctx
= m
->private;
496 struct request_queue
*q
= hctx
->queue
;
499 res
= mutex_lock_interruptible(&q
->sysfs_lock
);
502 if (hctx
->sched_tags
)
503 blk_mq_debugfs_tags_show(m
, hctx
->sched_tags
);
504 mutex_unlock(&q
->sysfs_lock
);
510 static int hctx_sched_tags_open(struct inode
*inode
, struct file
*file
)
512 return single_open(file
, hctx_sched_tags_show
, inode
->i_private
);
515 static const struct file_operations hctx_sched_tags_fops
= {
516 .open
= hctx_sched_tags_open
,
519 .release
= single_release
,
522 static int hctx_sched_tags_bitmap_show(struct seq_file
*m
, void *v
)
524 struct blk_mq_hw_ctx
*hctx
= m
->private;
525 struct request_queue
*q
= hctx
->queue
;
528 res
= mutex_lock_interruptible(&q
->sysfs_lock
);
531 if (hctx
->sched_tags
)
532 sbitmap_bitmap_show(&hctx
->sched_tags
->bitmap_tags
.sb
, m
);
533 mutex_unlock(&q
->sysfs_lock
);
539 static int hctx_sched_tags_bitmap_open(struct inode
*inode
, struct file
*file
)
541 return single_open(file
, hctx_sched_tags_bitmap_show
, inode
->i_private
);
544 static const struct file_operations hctx_sched_tags_bitmap_fops
= {
545 .open
= hctx_sched_tags_bitmap_open
,
548 .release
= single_release
,
551 static int hctx_io_poll_show(struct seq_file
*m
, void *v
)
553 struct blk_mq_hw_ctx
*hctx
= m
->private;
555 seq_printf(m
, "considered=%lu\n", hctx
->poll_considered
);
556 seq_printf(m
, "invoked=%lu\n", hctx
->poll_invoked
);
557 seq_printf(m
, "success=%lu\n", hctx
->poll_success
);
561 static int hctx_io_poll_open(struct inode
*inode
, struct file
*file
)
563 return single_open(file
, hctx_io_poll_show
, inode
->i_private
);
566 static ssize_t
hctx_io_poll_write(struct file
*file
, const char __user
*buf
,
567 size_t count
, loff_t
*ppos
)
569 struct seq_file
*m
= file
->private_data
;
570 struct blk_mq_hw_ctx
*hctx
= m
->private;
572 hctx
->poll_considered
= hctx
->poll_invoked
= hctx
->poll_success
= 0;
576 static const struct file_operations hctx_io_poll_fops
= {
577 .open
= hctx_io_poll_open
,
579 .write
= hctx_io_poll_write
,
581 .release
= single_release
,
584 static int hctx_dispatched_show(struct seq_file
*m
, void *v
)
586 struct blk_mq_hw_ctx
*hctx
= m
->private;
589 seq_printf(m
, "%8u\t%lu\n", 0U, hctx
->dispatched
[0]);
591 for (i
= 1; i
< BLK_MQ_MAX_DISPATCH_ORDER
- 1; i
++) {
592 unsigned int d
= 1U << (i
- 1);
594 seq_printf(m
, "%8u\t%lu\n", d
, hctx
->dispatched
[i
]);
597 seq_printf(m
, "%8u+\t%lu\n", 1U << (i
- 1), hctx
->dispatched
[i
]);
601 static int hctx_dispatched_open(struct inode
*inode
, struct file
*file
)
603 return single_open(file
, hctx_dispatched_show
, inode
->i_private
);
606 static ssize_t
hctx_dispatched_write(struct file
*file
, const char __user
*buf
,
607 size_t count
, loff_t
*ppos
)
609 struct seq_file
*m
= file
->private_data
;
610 struct blk_mq_hw_ctx
*hctx
= m
->private;
613 for (i
= 0; i
< BLK_MQ_MAX_DISPATCH_ORDER
; i
++)
614 hctx
->dispatched
[i
] = 0;
618 static const struct file_operations hctx_dispatched_fops
= {
619 .open
= hctx_dispatched_open
,
621 .write
= hctx_dispatched_write
,
623 .release
= single_release
,
626 static int hctx_queued_show(struct seq_file
*m
, void *v
)
628 struct blk_mq_hw_ctx
*hctx
= m
->private;
630 seq_printf(m
, "%lu\n", hctx
->queued
);
634 static int hctx_queued_open(struct inode
*inode
, struct file
*file
)
636 return single_open(file
, hctx_queued_show
, inode
->i_private
);
639 static ssize_t
hctx_queued_write(struct file
*file
, const char __user
*buf
,
640 size_t count
, loff_t
*ppos
)
642 struct seq_file
*m
= file
->private_data
;
643 struct blk_mq_hw_ctx
*hctx
= m
->private;
649 static const struct file_operations hctx_queued_fops
= {
650 .open
= hctx_queued_open
,
652 .write
= hctx_queued_write
,
654 .release
= single_release
,
657 static int hctx_run_show(struct seq_file
*m
, void *v
)
659 struct blk_mq_hw_ctx
*hctx
= m
->private;
661 seq_printf(m
, "%lu\n", hctx
->run
);
665 static int hctx_run_open(struct inode
*inode
, struct file
*file
)
667 return single_open(file
, hctx_run_show
, inode
->i_private
);
670 static ssize_t
hctx_run_write(struct file
*file
, const char __user
*buf
,
671 size_t count
, loff_t
*ppos
)
673 struct seq_file
*m
= file
->private_data
;
674 struct blk_mq_hw_ctx
*hctx
= m
->private;
680 static const struct file_operations hctx_run_fops
= {
681 .open
= hctx_run_open
,
683 .write
= hctx_run_write
,
685 .release
= single_release
,
688 static int hctx_active_show(struct seq_file
*m
, void *v
)
690 struct blk_mq_hw_ctx
*hctx
= m
->private;
692 seq_printf(m
, "%d\n", atomic_read(&hctx
->nr_active
));
696 static int hctx_active_open(struct inode
*inode
, struct file
*file
)
698 return single_open(file
, hctx_active_show
, inode
->i_private
);
701 static const struct file_operations hctx_active_fops
= {
702 .open
= hctx_active_open
,
705 .release
= single_release
,
708 static void *ctx_rq_list_start(struct seq_file
*m
, loff_t
*pos
)
709 __acquires(&ctx
->lock
)
711 struct blk_mq_ctx
*ctx
= m
->private;
713 spin_lock(&ctx
->lock
);
714 return seq_list_start(&ctx
->rq_list
, *pos
);
717 static void *ctx_rq_list_next(struct seq_file
*m
, void *v
, loff_t
*pos
)
719 struct blk_mq_ctx
*ctx
= m
->private;
721 return seq_list_next(v
, &ctx
->rq_list
, pos
);
724 static void ctx_rq_list_stop(struct seq_file
*m
, void *v
)
725 __releases(&ctx
->lock
)
727 struct blk_mq_ctx
*ctx
= m
->private;
729 spin_unlock(&ctx
->lock
);
732 static const struct seq_operations ctx_rq_list_seq_ops
= {
733 .start
= ctx_rq_list_start
,
734 .next
= ctx_rq_list_next
,
735 .stop
= ctx_rq_list_stop
,
736 .show
= blk_mq_debugfs_rq_show
,
739 static int ctx_rq_list_open(struct inode
*inode
, struct file
*file
)
741 return blk_mq_debugfs_seq_open(inode
, file
, &ctx_rq_list_seq_ops
);
744 static const struct file_operations ctx_rq_list_fops
= {
745 .open
= ctx_rq_list_open
,
748 .release
= seq_release
,
751 static int ctx_dispatched_show(struct seq_file
*m
, void *v
)
753 struct blk_mq_ctx
*ctx
= m
->private;
755 seq_printf(m
, "%lu %lu\n", ctx
->rq_dispatched
[1], ctx
->rq_dispatched
[0]);
759 static int ctx_dispatched_open(struct inode
*inode
, struct file
*file
)
761 return single_open(file
, ctx_dispatched_show
, inode
->i_private
);
764 static ssize_t
ctx_dispatched_write(struct file
*file
, const char __user
*buf
,
765 size_t count
, loff_t
*ppos
)
767 struct seq_file
*m
= file
->private_data
;
768 struct blk_mq_ctx
*ctx
= m
->private;
770 ctx
->rq_dispatched
[0] = ctx
->rq_dispatched
[1] = 0;
774 static const struct file_operations ctx_dispatched_fops
= {
775 .open
= ctx_dispatched_open
,
777 .write
= ctx_dispatched_write
,
779 .release
= single_release
,
782 static int ctx_merged_show(struct seq_file
*m
, void *v
)
784 struct blk_mq_ctx
*ctx
= m
->private;
786 seq_printf(m
, "%lu\n", ctx
->rq_merged
);
790 static int ctx_merged_open(struct inode
*inode
, struct file
*file
)
792 return single_open(file
, ctx_merged_show
, inode
->i_private
);
795 static ssize_t
ctx_merged_write(struct file
*file
, const char __user
*buf
,
796 size_t count
, loff_t
*ppos
)
798 struct seq_file
*m
= file
->private_data
;
799 struct blk_mq_ctx
*ctx
= m
->private;
805 static const struct file_operations ctx_merged_fops
= {
806 .open
= ctx_merged_open
,
808 .write
= ctx_merged_write
,
810 .release
= single_release
,
813 static int ctx_completed_show(struct seq_file
*m
, void *v
)
815 struct blk_mq_ctx
*ctx
= m
->private;
817 seq_printf(m
, "%lu %lu\n", ctx
->rq_completed
[1], ctx
->rq_completed
[0]);
821 static int ctx_completed_open(struct inode
*inode
, struct file
*file
)
823 return single_open(file
, ctx_completed_show
, inode
->i_private
);
826 static ssize_t
ctx_completed_write(struct file
*file
, const char __user
*buf
,
827 size_t count
, loff_t
*ppos
)
829 struct seq_file
*m
= file
->private_data
;
830 struct blk_mq_ctx
*ctx
= m
->private;
832 ctx
->rq_completed
[0] = ctx
->rq_completed
[1] = 0;
836 static const struct file_operations ctx_completed_fops
= {
837 .open
= ctx_completed_open
,
839 .write
= ctx_completed_write
,
841 .release
= single_release
,
844 static const struct blk_mq_debugfs_attr blk_mq_debugfs_queue_attrs
[] = {
845 {"poll_stat", 0400, &queue_poll_stat_fops
},
846 {"state", 0600, &blk_queue_flags_fops
},
850 static const struct blk_mq_debugfs_attr blk_mq_debugfs_hctx_attrs
[] = {
851 {"state", 0400, &hctx_state_fops
},
852 {"flags", 0400, &hctx_flags_fops
},
853 {"dispatch", 0400, &hctx_dispatch_fops
},
854 {"ctx_map", 0400, &hctx_ctx_map_fops
},
855 {"tags", 0400, &hctx_tags_fops
},
856 {"tags_bitmap", 0400, &hctx_tags_bitmap_fops
},
857 {"sched_tags", 0400, &hctx_sched_tags_fops
},
858 {"sched_tags_bitmap", 0400, &hctx_sched_tags_bitmap_fops
},
859 {"io_poll", 0600, &hctx_io_poll_fops
},
860 {"dispatched", 0600, &hctx_dispatched_fops
},
861 {"queued", 0600, &hctx_queued_fops
},
862 {"run", 0600, &hctx_run_fops
},
863 {"active", 0400, &hctx_active_fops
},
867 static const struct blk_mq_debugfs_attr blk_mq_debugfs_ctx_attrs
[] = {
868 {"rq_list", 0400, &ctx_rq_list_fops
},
869 {"dispatched", 0600, &ctx_dispatched_fops
},
870 {"merged", 0600, &ctx_merged_fops
},
871 {"completed", 0600, &ctx_completed_fops
},
875 int blk_mq_debugfs_register(struct request_queue
*q
)
877 if (!blk_debugfs_root
)
880 q
->debugfs_dir
= debugfs_create_dir(kobject_name(q
->kobj
.parent
),
885 if (blk_mq_debugfs_register_mq(q
))
891 blk_mq_debugfs_unregister(q
);
895 void blk_mq_debugfs_unregister(struct request_queue
*q
)
897 debugfs_remove_recursive(q
->debugfs_dir
);
898 q
->mq_debugfs_dir
= NULL
;
899 q
->debugfs_dir
= NULL
;
902 static bool debugfs_create_files(struct dentry
*parent
, void *data
,
903 const struct blk_mq_debugfs_attr
*attr
)
905 for (; attr
->name
; attr
++) {
906 if (!debugfs_create_file(attr
->name
, attr
->mode
, parent
,
913 static int blk_mq_debugfs_register_ctx(struct request_queue
*q
,
914 struct blk_mq_ctx
*ctx
,
915 struct dentry
*hctx_dir
)
917 struct dentry
*ctx_dir
;
920 snprintf(name
, sizeof(name
), "cpu%u", ctx
->cpu
);
921 ctx_dir
= debugfs_create_dir(name
, hctx_dir
);
925 if (!debugfs_create_files(ctx_dir
, ctx
, blk_mq_debugfs_ctx_attrs
))
931 static int blk_mq_debugfs_register_hctx(struct request_queue
*q
,
932 struct blk_mq_hw_ctx
*hctx
)
934 struct blk_mq_ctx
*ctx
;
935 struct dentry
*hctx_dir
;
939 snprintf(name
, sizeof(name
), "%u", hctx
->queue_num
);
940 hctx_dir
= debugfs_create_dir(name
, q
->mq_debugfs_dir
);
944 if (!debugfs_create_files(hctx_dir
, hctx
, blk_mq_debugfs_hctx_attrs
))
947 hctx_for_each_ctx(hctx
, ctx
, i
) {
948 if (blk_mq_debugfs_register_ctx(q
, ctx
, hctx_dir
))
955 int blk_mq_debugfs_register_mq(struct request_queue
*q
)
957 struct blk_mq_hw_ctx
*hctx
;
963 q
->mq_debugfs_dir
= debugfs_create_dir("mq", q
->debugfs_dir
);
964 if (!q
->mq_debugfs_dir
)
967 if (!debugfs_create_files(q
->mq_debugfs_dir
, q
, blk_mq_debugfs_queue_attrs
))
970 queue_for_each_hw_ctx(q
, hctx
, i
) {
971 if (blk_mq_debugfs_register_hctx(q
, hctx
))
978 blk_mq_debugfs_unregister_mq(q
);
982 void blk_mq_debugfs_unregister_mq(struct request_queue
*q
)
984 debugfs_remove_recursive(q
->mq_debugfs_dir
);
985 q
->mq_debugfs_dir
= NULL
;