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 op
[16] = { }, *s
;
116 if (count
>= sizeof(op
)) {
117 pr_err("%s: operation too long\n", __func__
);
121 if (copy_from_user(op
, buf
, count
))
124 strsep(&s
, " \t\n"); /* strip trailing whitespace */
125 if (strcmp(op
, "run") == 0) {
126 blk_mq_run_hw_queues(q
, true);
127 } else if (strcmp(op
, "start") == 0) {
128 blk_mq_start_stopped_hw_queues(q
, true);
130 pr_err("%s: unsupported operation '%s'\n", __func__
, op
);
132 pr_err("%s: use either 'run' or 'start'\n", __func__
);
138 static int blk_queue_flags_open(struct inode
*inode
, struct file
*file
)
140 return single_open(file
, blk_queue_flags_show
, inode
->i_private
);
143 static const struct file_operations blk_queue_flags_fops
= {
144 .open
= blk_queue_flags_open
,
147 .release
= single_release
,
148 .write
= blk_queue_flags_store
,
151 static void print_stat(struct seq_file
*m
, struct blk_rq_stat
*stat
)
153 if (stat
->nr_samples
) {
154 seq_printf(m
, "samples=%d, mean=%lld, min=%llu, max=%llu",
155 stat
->nr_samples
, stat
->mean
, stat
->min
, stat
->max
);
157 seq_puts(m
, "samples=0");
161 static int queue_poll_stat_show(struct seq_file
*m
, void *v
)
163 struct request_queue
*q
= m
->private;
166 for (bucket
= 0; bucket
< BLK_MQ_POLL_STATS_BKTS
/2; bucket
++) {
167 seq_printf(m
, "read (%d Bytes): ", 1 << (9+bucket
));
168 print_stat(m
, &q
->poll_stat
[2*bucket
]);
171 seq_printf(m
, "write (%d Bytes): ", 1 << (9+bucket
));
172 print_stat(m
, &q
->poll_stat
[2*bucket
+1]);
178 static int queue_poll_stat_open(struct inode
*inode
, struct file
*file
)
180 return single_open(file
, queue_poll_stat_show
, inode
->i_private
);
183 static const struct file_operations queue_poll_stat_fops
= {
184 .open
= queue_poll_stat_open
,
187 .release
= single_release
,
190 #define HCTX_STATE_NAME(name) [BLK_MQ_S_##name] = #name
191 static const char *const hctx_state_name
[] = {
192 HCTX_STATE_NAME(STOPPED
),
193 HCTX_STATE_NAME(TAG_ACTIVE
),
194 HCTX_STATE_NAME(SCHED_RESTART
),
195 HCTX_STATE_NAME(TAG_WAITING
),
196 HCTX_STATE_NAME(START_ON_RUN
),
198 #undef HCTX_STATE_NAME
200 static int hctx_state_show(struct seq_file
*m
, void *v
)
202 struct blk_mq_hw_ctx
*hctx
= m
->private;
204 blk_flags_show(m
, hctx
->state
, hctx_state_name
,
205 ARRAY_SIZE(hctx_state_name
));
210 static int hctx_state_open(struct inode
*inode
, struct file
*file
)
212 return single_open(file
, hctx_state_show
, inode
->i_private
);
215 static const struct file_operations hctx_state_fops
= {
216 .open
= hctx_state_open
,
219 .release
= single_release
,
222 #define BLK_TAG_ALLOC_NAME(name) [BLK_TAG_ALLOC_##name] = #name
223 static const char *const alloc_policy_name
[] = {
224 BLK_TAG_ALLOC_NAME(FIFO
),
225 BLK_TAG_ALLOC_NAME(RR
),
227 #undef BLK_TAG_ALLOC_NAME
229 #define HCTX_FLAG_NAME(name) [ilog2(BLK_MQ_F_##name)] = #name
230 static const char *const hctx_flag_name
[] = {
231 HCTX_FLAG_NAME(SHOULD_MERGE
),
232 HCTX_FLAG_NAME(TAG_SHARED
),
233 HCTX_FLAG_NAME(SG_MERGE
),
234 HCTX_FLAG_NAME(BLOCKING
),
235 HCTX_FLAG_NAME(NO_SCHED
),
237 #undef HCTX_FLAG_NAME
239 static int hctx_flags_show(struct seq_file
*m
, void *v
)
241 struct blk_mq_hw_ctx
*hctx
= m
->private;
242 const int alloc_policy
= BLK_MQ_FLAG_TO_ALLOC_POLICY(hctx
->flags
);
244 seq_puts(m
, "alloc_policy=");
245 if (alloc_policy
< ARRAY_SIZE(alloc_policy_name
) &&
246 alloc_policy_name
[alloc_policy
])
247 seq_puts(m
, alloc_policy_name
[alloc_policy
]);
249 seq_printf(m
, "%d", alloc_policy
);
252 hctx
->flags
^ BLK_ALLOC_POLICY_TO_MQ_FLAG(alloc_policy
),
253 hctx_flag_name
, ARRAY_SIZE(hctx_flag_name
));
258 static int hctx_flags_open(struct inode
*inode
, struct file
*file
)
260 return single_open(file
, hctx_flags_show
, inode
->i_private
);
263 static const struct file_operations hctx_flags_fops
= {
264 .open
= hctx_flags_open
,
267 .release
= single_release
,
270 #define REQ_OP_NAME(name) [REQ_OP_##name] = #name
271 static const char *const op_name
[] = {
275 REQ_OP_NAME(DISCARD
),
276 REQ_OP_NAME(ZONE_REPORT
),
277 REQ_OP_NAME(SECURE_ERASE
),
278 REQ_OP_NAME(ZONE_RESET
),
279 REQ_OP_NAME(WRITE_SAME
),
280 REQ_OP_NAME(WRITE_ZEROES
),
281 REQ_OP_NAME(SCSI_IN
),
282 REQ_OP_NAME(SCSI_OUT
),
284 REQ_OP_NAME(DRV_OUT
),
288 #define CMD_FLAG_NAME(name) [__REQ_##name] = #name
289 static const char *const cmd_flag_name
[] = {
290 CMD_FLAG_NAME(FAILFAST_DEV
),
291 CMD_FLAG_NAME(FAILFAST_TRANSPORT
),
292 CMD_FLAG_NAME(FAILFAST_DRIVER
),
296 CMD_FLAG_NAME(NOMERGE
),
298 CMD_FLAG_NAME(INTEGRITY
),
300 CMD_FLAG_NAME(PREFLUSH
),
301 CMD_FLAG_NAME(RAHEAD
),
302 CMD_FLAG_NAME(BACKGROUND
),
303 CMD_FLAG_NAME(NOUNMAP
),
307 #define RQF_NAME(name) [ilog2((__force u32)RQF_##name)] = #name
308 static const char *const rqf_name
[] = {
312 RQF_NAME(SOFTBARRIER
),
314 RQF_NAME(MIXED_MERGE
),
315 RQF_NAME(MQ_INFLIGHT
),
327 RQF_NAME(SPECIAL_PAYLOAD
),
331 static int blk_mq_debugfs_rq_show(struct seq_file
*m
, void *v
)
333 struct request
*rq
= list_entry_rq(v
);
334 const struct blk_mq_ops
*const mq_ops
= rq
->q
->mq_ops
;
335 const unsigned int op
= rq
->cmd_flags
& REQ_OP_MASK
;
337 seq_printf(m
, "%p {.op=", rq
);
338 if (op
< ARRAY_SIZE(op_name
) && op_name
[op
])
339 seq_printf(m
, "%s", op_name
[op
]);
341 seq_printf(m
, "%d", op
);
342 seq_puts(m
, ", .cmd_flags=");
343 blk_flags_show(m
, rq
->cmd_flags
& ~REQ_OP_MASK
, cmd_flag_name
,
344 ARRAY_SIZE(cmd_flag_name
));
345 seq_puts(m
, ", .rq_flags=");
346 blk_flags_show(m
, (__force
unsigned int)rq
->rq_flags
, rqf_name
,
347 ARRAY_SIZE(rqf_name
));
348 seq_printf(m
, ", .tag=%d, .internal_tag=%d", rq
->tag
,
351 mq_ops
->show_rq(m
, rq
);
356 static void *hctx_dispatch_start(struct seq_file
*m
, loff_t
*pos
)
357 __acquires(&hctx
->lock
)
359 struct blk_mq_hw_ctx
*hctx
= m
->private;
361 spin_lock(&hctx
->lock
);
362 return seq_list_start(&hctx
->dispatch
, *pos
);
365 static void *hctx_dispatch_next(struct seq_file
*m
, void *v
, loff_t
*pos
)
367 struct blk_mq_hw_ctx
*hctx
= m
->private;
369 return seq_list_next(v
, &hctx
->dispatch
, pos
);
372 static void hctx_dispatch_stop(struct seq_file
*m
, void *v
)
373 __releases(&hctx
->lock
)
375 struct blk_mq_hw_ctx
*hctx
= m
->private;
377 spin_unlock(&hctx
->lock
);
380 static const struct seq_operations hctx_dispatch_seq_ops
= {
381 .start
= hctx_dispatch_start
,
382 .next
= hctx_dispatch_next
,
383 .stop
= hctx_dispatch_stop
,
384 .show
= blk_mq_debugfs_rq_show
,
387 static int hctx_dispatch_open(struct inode
*inode
, struct file
*file
)
389 return blk_mq_debugfs_seq_open(inode
, file
, &hctx_dispatch_seq_ops
);
392 static const struct file_operations hctx_dispatch_fops
= {
393 .open
= hctx_dispatch_open
,
396 .release
= seq_release
,
399 static int hctx_ctx_map_show(struct seq_file
*m
, void *v
)
401 struct blk_mq_hw_ctx
*hctx
= m
->private;
403 sbitmap_bitmap_show(&hctx
->ctx_map
, m
);
407 static int hctx_ctx_map_open(struct inode
*inode
, struct file
*file
)
409 return single_open(file
, hctx_ctx_map_show
, inode
->i_private
);
412 static const struct file_operations hctx_ctx_map_fops
= {
413 .open
= hctx_ctx_map_open
,
416 .release
= single_release
,
419 static void blk_mq_debugfs_tags_show(struct seq_file
*m
,
420 struct blk_mq_tags
*tags
)
422 seq_printf(m
, "nr_tags=%u\n", tags
->nr_tags
);
423 seq_printf(m
, "nr_reserved_tags=%u\n", tags
->nr_reserved_tags
);
424 seq_printf(m
, "active_queues=%d\n",
425 atomic_read(&tags
->active_queues
));
427 seq_puts(m
, "\nbitmap_tags:\n");
428 sbitmap_queue_show(&tags
->bitmap_tags
, m
);
430 if (tags
->nr_reserved_tags
) {
431 seq_puts(m
, "\nbreserved_tags:\n");
432 sbitmap_queue_show(&tags
->breserved_tags
, m
);
436 static int hctx_tags_show(struct seq_file
*m
, void *v
)
438 struct blk_mq_hw_ctx
*hctx
= m
->private;
439 struct request_queue
*q
= hctx
->queue
;
442 res
= mutex_lock_interruptible(&q
->sysfs_lock
);
446 blk_mq_debugfs_tags_show(m
, hctx
->tags
);
447 mutex_unlock(&q
->sysfs_lock
);
453 static int hctx_tags_open(struct inode
*inode
, struct file
*file
)
455 return single_open(file
, hctx_tags_show
, inode
->i_private
);
458 static const struct file_operations hctx_tags_fops
= {
459 .open
= hctx_tags_open
,
462 .release
= single_release
,
465 static int hctx_tags_bitmap_show(struct seq_file
*m
, void *v
)
467 struct blk_mq_hw_ctx
*hctx
= m
->private;
468 struct request_queue
*q
= hctx
->queue
;
471 res
= mutex_lock_interruptible(&q
->sysfs_lock
);
475 sbitmap_bitmap_show(&hctx
->tags
->bitmap_tags
.sb
, m
);
476 mutex_unlock(&q
->sysfs_lock
);
482 static int hctx_tags_bitmap_open(struct inode
*inode
, struct file
*file
)
484 return single_open(file
, hctx_tags_bitmap_show
, inode
->i_private
);
487 static const struct file_operations hctx_tags_bitmap_fops
= {
488 .open
= hctx_tags_bitmap_open
,
491 .release
= single_release
,
494 static int hctx_sched_tags_show(struct seq_file
*m
, void *v
)
496 struct blk_mq_hw_ctx
*hctx
= m
->private;
497 struct request_queue
*q
= hctx
->queue
;
500 res
= mutex_lock_interruptible(&q
->sysfs_lock
);
503 if (hctx
->sched_tags
)
504 blk_mq_debugfs_tags_show(m
, hctx
->sched_tags
);
505 mutex_unlock(&q
->sysfs_lock
);
511 static int hctx_sched_tags_open(struct inode
*inode
, struct file
*file
)
513 return single_open(file
, hctx_sched_tags_show
, inode
->i_private
);
516 static const struct file_operations hctx_sched_tags_fops
= {
517 .open
= hctx_sched_tags_open
,
520 .release
= single_release
,
523 static int hctx_sched_tags_bitmap_show(struct seq_file
*m
, void *v
)
525 struct blk_mq_hw_ctx
*hctx
= m
->private;
526 struct request_queue
*q
= hctx
->queue
;
529 res
= mutex_lock_interruptible(&q
->sysfs_lock
);
532 if (hctx
->sched_tags
)
533 sbitmap_bitmap_show(&hctx
->sched_tags
->bitmap_tags
.sb
, m
);
534 mutex_unlock(&q
->sysfs_lock
);
540 static int hctx_sched_tags_bitmap_open(struct inode
*inode
, struct file
*file
)
542 return single_open(file
, hctx_sched_tags_bitmap_show
, inode
->i_private
);
545 static const struct file_operations hctx_sched_tags_bitmap_fops
= {
546 .open
= hctx_sched_tags_bitmap_open
,
549 .release
= single_release
,
552 static int hctx_io_poll_show(struct seq_file
*m
, void *v
)
554 struct blk_mq_hw_ctx
*hctx
= m
->private;
556 seq_printf(m
, "considered=%lu\n", hctx
->poll_considered
);
557 seq_printf(m
, "invoked=%lu\n", hctx
->poll_invoked
);
558 seq_printf(m
, "success=%lu\n", hctx
->poll_success
);
562 static int hctx_io_poll_open(struct inode
*inode
, struct file
*file
)
564 return single_open(file
, hctx_io_poll_show
, inode
->i_private
);
567 static ssize_t
hctx_io_poll_write(struct file
*file
, const char __user
*buf
,
568 size_t count
, loff_t
*ppos
)
570 struct seq_file
*m
= file
->private_data
;
571 struct blk_mq_hw_ctx
*hctx
= m
->private;
573 hctx
->poll_considered
= hctx
->poll_invoked
= hctx
->poll_success
= 0;
577 static const struct file_operations hctx_io_poll_fops
= {
578 .open
= hctx_io_poll_open
,
580 .write
= hctx_io_poll_write
,
582 .release
= single_release
,
585 static int hctx_dispatched_show(struct seq_file
*m
, void *v
)
587 struct blk_mq_hw_ctx
*hctx
= m
->private;
590 seq_printf(m
, "%8u\t%lu\n", 0U, hctx
->dispatched
[0]);
592 for (i
= 1; i
< BLK_MQ_MAX_DISPATCH_ORDER
- 1; i
++) {
593 unsigned int d
= 1U << (i
- 1);
595 seq_printf(m
, "%8u\t%lu\n", d
, hctx
->dispatched
[i
]);
598 seq_printf(m
, "%8u+\t%lu\n", 1U << (i
- 1), hctx
->dispatched
[i
]);
602 static int hctx_dispatched_open(struct inode
*inode
, struct file
*file
)
604 return single_open(file
, hctx_dispatched_show
, inode
->i_private
);
607 static ssize_t
hctx_dispatched_write(struct file
*file
, const char __user
*buf
,
608 size_t count
, loff_t
*ppos
)
610 struct seq_file
*m
= file
->private_data
;
611 struct blk_mq_hw_ctx
*hctx
= m
->private;
614 for (i
= 0; i
< BLK_MQ_MAX_DISPATCH_ORDER
; i
++)
615 hctx
->dispatched
[i
] = 0;
619 static const struct file_operations hctx_dispatched_fops
= {
620 .open
= hctx_dispatched_open
,
622 .write
= hctx_dispatched_write
,
624 .release
= single_release
,
627 static int hctx_queued_show(struct seq_file
*m
, void *v
)
629 struct blk_mq_hw_ctx
*hctx
= m
->private;
631 seq_printf(m
, "%lu\n", hctx
->queued
);
635 static int hctx_queued_open(struct inode
*inode
, struct file
*file
)
637 return single_open(file
, hctx_queued_show
, inode
->i_private
);
640 static ssize_t
hctx_queued_write(struct file
*file
, const char __user
*buf
,
641 size_t count
, loff_t
*ppos
)
643 struct seq_file
*m
= file
->private_data
;
644 struct blk_mq_hw_ctx
*hctx
= m
->private;
650 static const struct file_operations hctx_queued_fops
= {
651 .open
= hctx_queued_open
,
653 .write
= hctx_queued_write
,
655 .release
= single_release
,
658 static int hctx_run_show(struct seq_file
*m
, void *v
)
660 struct blk_mq_hw_ctx
*hctx
= m
->private;
662 seq_printf(m
, "%lu\n", hctx
->run
);
666 static int hctx_run_open(struct inode
*inode
, struct file
*file
)
668 return single_open(file
, hctx_run_show
, inode
->i_private
);
671 static ssize_t
hctx_run_write(struct file
*file
, const char __user
*buf
,
672 size_t count
, loff_t
*ppos
)
674 struct seq_file
*m
= file
->private_data
;
675 struct blk_mq_hw_ctx
*hctx
= m
->private;
681 static const struct file_operations hctx_run_fops
= {
682 .open
= hctx_run_open
,
684 .write
= hctx_run_write
,
686 .release
= single_release
,
689 static int hctx_active_show(struct seq_file
*m
, void *v
)
691 struct blk_mq_hw_ctx
*hctx
= m
->private;
693 seq_printf(m
, "%d\n", atomic_read(&hctx
->nr_active
));
697 static int hctx_active_open(struct inode
*inode
, struct file
*file
)
699 return single_open(file
, hctx_active_show
, inode
->i_private
);
702 static const struct file_operations hctx_active_fops
= {
703 .open
= hctx_active_open
,
706 .release
= single_release
,
709 static void *ctx_rq_list_start(struct seq_file
*m
, loff_t
*pos
)
710 __acquires(&ctx
->lock
)
712 struct blk_mq_ctx
*ctx
= m
->private;
714 spin_lock(&ctx
->lock
);
715 return seq_list_start(&ctx
->rq_list
, *pos
);
718 static void *ctx_rq_list_next(struct seq_file
*m
, void *v
, loff_t
*pos
)
720 struct blk_mq_ctx
*ctx
= m
->private;
722 return seq_list_next(v
, &ctx
->rq_list
, pos
);
725 static void ctx_rq_list_stop(struct seq_file
*m
, void *v
)
726 __releases(&ctx
->lock
)
728 struct blk_mq_ctx
*ctx
= m
->private;
730 spin_unlock(&ctx
->lock
);
733 static const struct seq_operations ctx_rq_list_seq_ops
= {
734 .start
= ctx_rq_list_start
,
735 .next
= ctx_rq_list_next
,
736 .stop
= ctx_rq_list_stop
,
737 .show
= blk_mq_debugfs_rq_show
,
740 static int ctx_rq_list_open(struct inode
*inode
, struct file
*file
)
742 return blk_mq_debugfs_seq_open(inode
, file
, &ctx_rq_list_seq_ops
);
745 static const struct file_operations ctx_rq_list_fops
= {
746 .open
= ctx_rq_list_open
,
749 .release
= seq_release
,
752 static int ctx_dispatched_show(struct seq_file
*m
, void *v
)
754 struct blk_mq_ctx
*ctx
= m
->private;
756 seq_printf(m
, "%lu %lu\n", ctx
->rq_dispatched
[1], ctx
->rq_dispatched
[0]);
760 static int ctx_dispatched_open(struct inode
*inode
, struct file
*file
)
762 return single_open(file
, ctx_dispatched_show
, inode
->i_private
);
765 static ssize_t
ctx_dispatched_write(struct file
*file
, const char __user
*buf
,
766 size_t count
, loff_t
*ppos
)
768 struct seq_file
*m
= file
->private_data
;
769 struct blk_mq_ctx
*ctx
= m
->private;
771 ctx
->rq_dispatched
[0] = ctx
->rq_dispatched
[1] = 0;
775 static const struct file_operations ctx_dispatched_fops
= {
776 .open
= ctx_dispatched_open
,
778 .write
= ctx_dispatched_write
,
780 .release
= single_release
,
783 static int ctx_merged_show(struct seq_file
*m
, void *v
)
785 struct blk_mq_ctx
*ctx
= m
->private;
787 seq_printf(m
, "%lu\n", ctx
->rq_merged
);
791 static int ctx_merged_open(struct inode
*inode
, struct file
*file
)
793 return single_open(file
, ctx_merged_show
, inode
->i_private
);
796 static ssize_t
ctx_merged_write(struct file
*file
, const char __user
*buf
,
797 size_t count
, loff_t
*ppos
)
799 struct seq_file
*m
= file
->private_data
;
800 struct blk_mq_ctx
*ctx
= m
->private;
806 static const struct file_operations ctx_merged_fops
= {
807 .open
= ctx_merged_open
,
809 .write
= ctx_merged_write
,
811 .release
= single_release
,
814 static int ctx_completed_show(struct seq_file
*m
, void *v
)
816 struct blk_mq_ctx
*ctx
= m
->private;
818 seq_printf(m
, "%lu %lu\n", ctx
->rq_completed
[1], ctx
->rq_completed
[0]);
822 static int ctx_completed_open(struct inode
*inode
, struct file
*file
)
824 return single_open(file
, ctx_completed_show
, inode
->i_private
);
827 static ssize_t
ctx_completed_write(struct file
*file
, const char __user
*buf
,
828 size_t count
, loff_t
*ppos
)
830 struct seq_file
*m
= file
->private_data
;
831 struct blk_mq_ctx
*ctx
= m
->private;
833 ctx
->rq_completed
[0] = ctx
->rq_completed
[1] = 0;
837 static const struct file_operations ctx_completed_fops
= {
838 .open
= ctx_completed_open
,
840 .write
= ctx_completed_write
,
842 .release
= single_release
,
845 static const struct blk_mq_debugfs_attr blk_mq_debugfs_queue_attrs
[] = {
846 {"poll_stat", 0400, &queue_poll_stat_fops
},
847 {"state", 0600, &blk_queue_flags_fops
},
851 static const struct blk_mq_debugfs_attr blk_mq_debugfs_hctx_attrs
[] = {
852 {"state", 0400, &hctx_state_fops
},
853 {"flags", 0400, &hctx_flags_fops
},
854 {"dispatch", 0400, &hctx_dispatch_fops
},
855 {"ctx_map", 0400, &hctx_ctx_map_fops
},
856 {"tags", 0400, &hctx_tags_fops
},
857 {"tags_bitmap", 0400, &hctx_tags_bitmap_fops
},
858 {"sched_tags", 0400, &hctx_sched_tags_fops
},
859 {"sched_tags_bitmap", 0400, &hctx_sched_tags_bitmap_fops
},
860 {"io_poll", 0600, &hctx_io_poll_fops
},
861 {"dispatched", 0600, &hctx_dispatched_fops
},
862 {"queued", 0600, &hctx_queued_fops
},
863 {"run", 0600, &hctx_run_fops
},
864 {"active", 0400, &hctx_active_fops
},
868 static const struct blk_mq_debugfs_attr blk_mq_debugfs_ctx_attrs
[] = {
869 {"rq_list", 0400, &ctx_rq_list_fops
},
870 {"dispatched", 0600, &ctx_dispatched_fops
},
871 {"merged", 0600, &ctx_merged_fops
},
872 {"completed", 0600, &ctx_completed_fops
},
876 int blk_mq_debugfs_register(struct request_queue
*q
)
878 if (!blk_debugfs_root
)
881 q
->debugfs_dir
= debugfs_create_dir(kobject_name(q
->kobj
.parent
),
886 if (blk_mq_debugfs_register_mq(q
))
892 blk_mq_debugfs_unregister(q
);
896 void blk_mq_debugfs_unregister(struct request_queue
*q
)
898 debugfs_remove_recursive(q
->debugfs_dir
);
899 q
->mq_debugfs_dir
= NULL
;
900 q
->debugfs_dir
= NULL
;
903 static bool debugfs_create_files(struct dentry
*parent
, void *data
,
904 const struct blk_mq_debugfs_attr
*attr
)
906 for (; attr
->name
; attr
++) {
907 if (!debugfs_create_file(attr
->name
, attr
->mode
, parent
,
914 static int blk_mq_debugfs_register_ctx(struct request_queue
*q
,
915 struct blk_mq_ctx
*ctx
,
916 struct dentry
*hctx_dir
)
918 struct dentry
*ctx_dir
;
921 snprintf(name
, sizeof(name
), "cpu%u", ctx
->cpu
);
922 ctx_dir
= debugfs_create_dir(name
, hctx_dir
);
926 if (!debugfs_create_files(ctx_dir
, ctx
, blk_mq_debugfs_ctx_attrs
))
932 static int blk_mq_debugfs_register_hctx(struct request_queue
*q
,
933 struct blk_mq_hw_ctx
*hctx
)
935 struct blk_mq_ctx
*ctx
;
936 struct dentry
*hctx_dir
;
940 snprintf(name
, sizeof(name
), "%u", hctx
->queue_num
);
941 hctx_dir
= debugfs_create_dir(name
, q
->mq_debugfs_dir
);
945 if (!debugfs_create_files(hctx_dir
, hctx
, blk_mq_debugfs_hctx_attrs
))
948 hctx_for_each_ctx(hctx
, ctx
, i
) {
949 if (blk_mq_debugfs_register_ctx(q
, ctx
, hctx_dir
))
956 int blk_mq_debugfs_register_mq(struct request_queue
*q
)
958 struct blk_mq_hw_ctx
*hctx
;
964 q
->mq_debugfs_dir
= debugfs_create_dir("mq", q
->debugfs_dir
);
965 if (!q
->mq_debugfs_dir
)
968 if (!debugfs_create_files(q
->mq_debugfs_dir
, q
, blk_mq_debugfs_queue_attrs
))
971 queue_for_each_hw_ctx(q
, hctx
, i
) {
972 if (blk_mq_debugfs_register_hctx(q
, hctx
))
979 blk_mq_debugfs_unregister_mq(q
);
983 void blk_mq_debugfs_unregister_mq(struct request_queue
*q
)
985 debugfs_remove_recursive(q
->mq_debugfs_dir
);
986 q
->mq_debugfs_dir
= NULL
;