]>
Commit | Line | Data |
---|---|---|
07e4fead OS |
1 | /* |
2 | * Copyright (C) 2017 Facebook | |
3 | * | |
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. | |
7 | * | |
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. | |
12 | * | |
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/>. | |
15 | */ | |
16 | ||
17 | #include <linux/kernel.h> | |
18 | #include <linux/blkdev.h> | |
19 | #include <linux/debugfs.h> | |
20 | ||
21 | #include <linux/blk-mq.h> | |
18fbda91 | 22 | #include "blk.h" |
07e4fead | 23 | #include "blk-mq.h" |
d96b37c0 | 24 | #include "blk-mq-tag.h" |
07e4fead OS |
25 | |
26 | struct blk_mq_debugfs_attr { | |
27 | const char *name; | |
28 | umode_t mode; | |
29 | const struct file_operations *fops; | |
30 | }; | |
31 | ||
950cd7e9 OS |
32 | static int blk_mq_debugfs_seq_open(struct inode *inode, struct file *file, |
33 | const struct seq_operations *ops) | |
34 | { | |
35 | struct seq_file *m; | |
36 | int ret; | |
37 | ||
38 | ret = seq_open(file, ops); | |
39 | if (!ret) { | |
40 | m = file->private_data; | |
41 | m->private = inode->i_private; | |
42 | } | |
43 | return ret; | |
44 | } | |
45 | ||
91d68905 BVA |
46 | static int blk_flags_show(struct seq_file *m, const unsigned long flags, |
47 | const char *const *flag_name, int flag_name_count) | |
48 | { | |
49 | bool sep = false; | |
50 | int i; | |
51 | ||
52 | for (i = 0; i < sizeof(flags) * BITS_PER_BYTE; i++) { | |
53 | if (!(flags & BIT(i))) | |
54 | continue; | |
55 | if (sep) | |
56 | seq_puts(m, " "); | |
57 | sep = true; | |
58 | if (i < flag_name_count && flag_name[i]) | |
59 | seq_puts(m, flag_name[i]); | |
60 | else | |
61 | seq_printf(m, "%d", i); | |
62 | } | |
63 | seq_puts(m, "\n"); | |
64 | return 0; | |
65 | } | |
66 | ||
67 | static const char *const blk_queue_flag_name[] = { | |
68 | [QUEUE_FLAG_QUEUED] = "QUEUED", | |
69 | [QUEUE_FLAG_STOPPED] = "STOPPED", | |
70 | [QUEUE_FLAG_SYNCFULL] = "SYNCFULL", | |
71 | [QUEUE_FLAG_ASYNCFULL] = "ASYNCFULL", | |
72 | [QUEUE_FLAG_DYING] = "DYING", | |
73 | [QUEUE_FLAG_BYPASS] = "BYPASS", | |
74 | [QUEUE_FLAG_BIDI] = "BIDI", | |
75 | [QUEUE_FLAG_NOMERGES] = "NOMERGES", | |
76 | [QUEUE_FLAG_SAME_COMP] = "SAME_COMP", | |
77 | [QUEUE_FLAG_FAIL_IO] = "FAIL_IO", | |
78 | [QUEUE_FLAG_STACKABLE] = "STACKABLE", | |
79 | [QUEUE_FLAG_NONROT] = "NONROT", | |
80 | [QUEUE_FLAG_IO_STAT] = "IO_STAT", | |
81 | [QUEUE_FLAG_DISCARD] = "DISCARD", | |
82 | [QUEUE_FLAG_NOXMERGES] = "NOXMERGES", | |
83 | [QUEUE_FLAG_ADD_RANDOM] = "ADD_RANDOM", | |
84 | [QUEUE_FLAG_SECERASE] = "SECERASE", | |
85 | [QUEUE_FLAG_SAME_FORCE] = "SAME_FORCE", | |
86 | [QUEUE_FLAG_DEAD] = "DEAD", | |
87 | [QUEUE_FLAG_INIT_DONE] = "INIT_DONE", | |
88 | [QUEUE_FLAG_NO_SG_MERGE] = "NO_SG_MERGE", | |
89 | [QUEUE_FLAG_POLL] = "POLL", | |
90 | [QUEUE_FLAG_WC] = "WC", | |
91 | [QUEUE_FLAG_FUA] = "FUA", | |
92 | [QUEUE_FLAG_FLUSH_NQ] = "FLUSH_NQ", | |
93 | [QUEUE_FLAG_DAX] = "DAX", | |
94 | [QUEUE_FLAG_STATS] = "STATS", | |
95 | [QUEUE_FLAG_POLL_STATS] = "POLL_STATS", | |
96 | [QUEUE_FLAG_REGISTERED] = "REGISTERED", | |
97 | }; | |
98 | ||
99 | static int blk_queue_flags_show(struct seq_file *m, void *v) | |
100 | { | |
101 | struct request_queue *q = m->private; | |
102 | ||
103 | blk_flags_show(m, q->queue_flags, blk_queue_flag_name, | |
104 | ARRAY_SIZE(blk_queue_flag_name)); | |
105 | return 0; | |
106 | } | |
107 | ||
108 | static ssize_t blk_queue_flags_store(struct file *file, const char __user *ubuf, | |
109 | size_t len, loff_t *offp) | |
110 | { | |
111 | struct request_queue *q = file_inode(file)->i_private; | |
112 | char op[16] = { }, *s; | |
113 | ||
114 | len = min(len, sizeof(op) - 1); | |
115 | if (copy_from_user(op, ubuf, len)) | |
116 | return -EFAULT; | |
117 | s = op; | |
118 | strsep(&s, " \t\n"); /* strip trailing whitespace */ | |
119 | if (strcmp(op, "run") == 0) { | |
120 | blk_mq_run_hw_queues(q, true); | |
121 | } else if (strcmp(op, "start") == 0) { | |
122 | blk_mq_start_stopped_hw_queues(q, true); | |
123 | } else { | |
124 | pr_err("%s: unsupported operation %s. Use either 'run' or 'start'\n", | |
125 | __func__, op); | |
126 | return -EINVAL; | |
127 | } | |
128 | return len; | |
129 | } | |
130 | ||
131 | static int blk_queue_flags_open(struct inode *inode, struct file *file) | |
132 | { | |
133 | return single_open(file, blk_queue_flags_show, inode->i_private); | |
134 | } | |
135 | ||
136 | static const struct file_operations blk_queue_flags_fops = { | |
137 | .open = blk_queue_flags_open, | |
138 | .read = seq_read, | |
139 | .llseek = seq_lseek, | |
140 | .release = single_release, | |
141 | .write = blk_queue_flags_store, | |
142 | }; | |
143 | ||
144 | static const struct blk_mq_debugfs_attr blk_queue_attrs[] = { | |
145 | {"state", 0600, &blk_queue_flags_fops}, | |
146 | {}, | |
147 | }; | |
148 | ||
34dbad5d OS |
149 | static void print_stat(struct seq_file *m, struct blk_rq_stat *stat) |
150 | { | |
151 | if (stat->nr_samples) { | |
152 | seq_printf(m, "samples=%d, mean=%lld, min=%llu, max=%llu", | |
153 | stat->nr_samples, stat->mean, stat->min, stat->max); | |
154 | } else { | |
155 | seq_puts(m, "samples=0"); | |
156 | } | |
157 | } | |
158 | ||
159 | static int queue_poll_stat_show(struct seq_file *m, void *v) | |
160 | { | |
161 | struct request_queue *q = m->private; | |
162 | ||
163 | seq_puts(m, "read: "); | |
164 | print_stat(m, &q->poll_stat[READ]); | |
165 | seq_puts(m, "\n"); | |
166 | ||
167 | seq_puts(m, "write: "); | |
168 | print_stat(m, &q->poll_stat[WRITE]); | |
169 | seq_puts(m, "\n"); | |
170 | return 0; | |
171 | } | |
172 | ||
173 | static int queue_poll_stat_open(struct inode *inode, struct file *file) | |
174 | { | |
175 | return single_open(file, queue_poll_stat_show, inode->i_private); | |
176 | } | |
177 | ||
178 | static const struct file_operations queue_poll_stat_fops = { | |
179 | .open = queue_poll_stat_open, | |
180 | .read = seq_read, | |
181 | .llseek = seq_lseek, | |
182 | .release = single_release, | |
183 | }; | |
184 | ||
9abb2ad2 OS |
185 | static int hctx_state_show(struct seq_file *m, void *v) |
186 | { | |
187 | struct blk_mq_hw_ctx *hctx = m->private; | |
188 | ||
189 | seq_printf(m, "0x%lx\n", hctx->state); | |
190 | return 0; | |
191 | } | |
192 | ||
193 | static int hctx_state_open(struct inode *inode, struct file *file) | |
194 | { | |
195 | return single_open(file, hctx_state_show, inode->i_private); | |
196 | } | |
197 | ||
198 | static const struct file_operations hctx_state_fops = { | |
199 | .open = hctx_state_open, | |
200 | .read = seq_read, | |
201 | .llseek = seq_lseek, | |
202 | .release = single_release, | |
203 | }; | |
204 | ||
205 | static int hctx_flags_show(struct seq_file *m, void *v) | |
206 | { | |
207 | struct blk_mq_hw_ctx *hctx = m->private; | |
208 | ||
209 | seq_printf(m, "0x%lx\n", hctx->flags); | |
210 | return 0; | |
211 | } | |
212 | ||
213 | static int hctx_flags_open(struct inode *inode, struct file *file) | |
214 | { | |
215 | return single_open(file, hctx_flags_show, inode->i_private); | |
216 | } | |
217 | ||
218 | static const struct file_operations hctx_flags_fops = { | |
219 | .open = hctx_flags_open, | |
220 | .read = seq_read, | |
221 | .llseek = seq_lseek, | |
222 | .release = single_release, | |
223 | }; | |
224 | ||
950cd7e9 OS |
225 | static int blk_mq_debugfs_rq_show(struct seq_file *m, void *v) |
226 | { | |
227 | struct request *rq = list_entry_rq(v); | |
228 | ||
aebf526b | 229 | seq_printf(m, "%p {.cmd_flags=0x%x, .rq_flags=0x%x, .tag=%d, .internal_tag=%d}\n", |
a1ae0f74 | 230 | rq, rq->cmd_flags, (__force unsigned int)rq->rq_flags, |
7b393852 | 231 | rq->tag, rq->internal_tag); |
950cd7e9 OS |
232 | return 0; |
233 | } | |
234 | ||
235 | static void *hctx_dispatch_start(struct seq_file *m, loff_t *pos) | |
f3bcb0e6 | 236 | __acquires(&hctx->lock) |
950cd7e9 OS |
237 | { |
238 | struct blk_mq_hw_ctx *hctx = m->private; | |
239 | ||
240 | spin_lock(&hctx->lock); | |
241 | return seq_list_start(&hctx->dispatch, *pos); | |
242 | } | |
243 | ||
244 | static void *hctx_dispatch_next(struct seq_file *m, void *v, loff_t *pos) | |
245 | { | |
246 | struct blk_mq_hw_ctx *hctx = m->private; | |
247 | ||
248 | return seq_list_next(v, &hctx->dispatch, pos); | |
249 | } | |
250 | ||
251 | static void hctx_dispatch_stop(struct seq_file *m, void *v) | |
f3bcb0e6 | 252 | __releases(&hctx->lock) |
950cd7e9 OS |
253 | { |
254 | struct blk_mq_hw_ctx *hctx = m->private; | |
255 | ||
256 | spin_unlock(&hctx->lock); | |
257 | } | |
258 | ||
259 | static const struct seq_operations hctx_dispatch_seq_ops = { | |
260 | .start = hctx_dispatch_start, | |
261 | .next = hctx_dispatch_next, | |
262 | .stop = hctx_dispatch_stop, | |
263 | .show = blk_mq_debugfs_rq_show, | |
264 | }; | |
265 | ||
266 | static int hctx_dispatch_open(struct inode *inode, struct file *file) | |
267 | { | |
268 | return blk_mq_debugfs_seq_open(inode, file, &hctx_dispatch_seq_ops); | |
269 | } | |
270 | ||
271 | static const struct file_operations hctx_dispatch_fops = { | |
272 | .open = hctx_dispatch_open, | |
273 | .read = seq_read, | |
274 | .llseek = seq_lseek, | |
275 | .release = seq_release, | |
276 | }; | |
277 | ||
0bfa5288 OS |
278 | static int hctx_ctx_map_show(struct seq_file *m, void *v) |
279 | { | |
280 | struct blk_mq_hw_ctx *hctx = m->private; | |
281 | ||
282 | sbitmap_bitmap_show(&hctx->ctx_map, m); | |
283 | return 0; | |
284 | } | |
285 | ||
286 | static int hctx_ctx_map_open(struct inode *inode, struct file *file) | |
287 | { | |
288 | return single_open(file, hctx_ctx_map_show, inode->i_private); | |
289 | } | |
290 | ||
291 | static const struct file_operations hctx_ctx_map_fops = { | |
292 | .open = hctx_ctx_map_open, | |
293 | .read = seq_read, | |
294 | .llseek = seq_lseek, | |
295 | .release = single_release, | |
296 | }; | |
297 | ||
d96b37c0 OS |
298 | static void blk_mq_debugfs_tags_show(struct seq_file *m, |
299 | struct blk_mq_tags *tags) | |
300 | { | |
301 | seq_printf(m, "nr_tags=%u\n", tags->nr_tags); | |
302 | seq_printf(m, "nr_reserved_tags=%u\n", tags->nr_reserved_tags); | |
303 | seq_printf(m, "active_queues=%d\n", | |
304 | atomic_read(&tags->active_queues)); | |
305 | ||
306 | seq_puts(m, "\nbitmap_tags:\n"); | |
307 | sbitmap_queue_show(&tags->bitmap_tags, m); | |
308 | ||
309 | if (tags->nr_reserved_tags) { | |
310 | seq_puts(m, "\nbreserved_tags:\n"); | |
311 | sbitmap_queue_show(&tags->breserved_tags, m); | |
312 | } | |
313 | } | |
314 | ||
315 | static int hctx_tags_show(struct seq_file *m, void *v) | |
316 | { | |
317 | struct blk_mq_hw_ctx *hctx = m->private; | |
318 | struct request_queue *q = hctx->queue; | |
8c0f14ea | 319 | int res; |
d96b37c0 | 320 | |
8c0f14ea BVA |
321 | res = mutex_lock_interruptible(&q->sysfs_lock); |
322 | if (res) | |
323 | goto out; | |
d96b37c0 OS |
324 | if (hctx->tags) |
325 | blk_mq_debugfs_tags_show(m, hctx->tags); | |
326 | mutex_unlock(&q->sysfs_lock); | |
327 | ||
8c0f14ea BVA |
328 | out: |
329 | return res; | |
d96b37c0 OS |
330 | } |
331 | ||
332 | static int hctx_tags_open(struct inode *inode, struct file *file) | |
333 | { | |
334 | return single_open(file, hctx_tags_show, inode->i_private); | |
335 | } | |
336 | ||
337 | static const struct file_operations hctx_tags_fops = { | |
338 | .open = hctx_tags_open, | |
339 | .read = seq_read, | |
340 | .llseek = seq_lseek, | |
341 | .release = single_release, | |
342 | }; | |
343 | ||
d7e3621a OS |
344 | static int hctx_tags_bitmap_show(struct seq_file *m, void *v) |
345 | { | |
346 | struct blk_mq_hw_ctx *hctx = m->private; | |
347 | struct request_queue *q = hctx->queue; | |
8c0f14ea | 348 | int res; |
d7e3621a | 349 | |
8c0f14ea BVA |
350 | res = mutex_lock_interruptible(&q->sysfs_lock); |
351 | if (res) | |
352 | goto out; | |
d7e3621a OS |
353 | if (hctx->tags) |
354 | sbitmap_bitmap_show(&hctx->tags->bitmap_tags.sb, m); | |
355 | mutex_unlock(&q->sysfs_lock); | |
8c0f14ea BVA |
356 | |
357 | out: | |
358 | return res; | |
d7e3621a OS |
359 | } |
360 | ||
361 | static int hctx_tags_bitmap_open(struct inode *inode, struct file *file) | |
362 | { | |
363 | return single_open(file, hctx_tags_bitmap_show, inode->i_private); | |
364 | } | |
365 | ||
366 | static const struct file_operations hctx_tags_bitmap_fops = { | |
367 | .open = hctx_tags_bitmap_open, | |
368 | .read = seq_read, | |
369 | .llseek = seq_lseek, | |
370 | .release = single_release, | |
371 | }; | |
372 | ||
d96b37c0 OS |
373 | static int hctx_sched_tags_show(struct seq_file *m, void *v) |
374 | { | |
375 | struct blk_mq_hw_ctx *hctx = m->private; | |
376 | struct request_queue *q = hctx->queue; | |
8c0f14ea | 377 | int res; |
d96b37c0 | 378 | |
8c0f14ea BVA |
379 | res = mutex_lock_interruptible(&q->sysfs_lock); |
380 | if (res) | |
381 | goto out; | |
d96b37c0 OS |
382 | if (hctx->sched_tags) |
383 | blk_mq_debugfs_tags_show(m, hctx->sched_tags); | |
384 | mutex_unlock(&q->sysfs_lock); | |
385 | ||
8c0f14ea BVA |
386 | out: |
387 | return res; | |
d96b37c0 OS |
388 | } |
389 | ||
390 | static int hctx_sched_tags_open(struct inode *inode, struct file *file) | |
391 | { | |
392 | return single_open(file, hctx_sched_tags_show, inode->i_private); | |
393 | } | |
394 | ||
395 | static const struct file_operations hctx_sched_tags_fops = { | |
396 | .open = hctx_sched_tags_open, | |
397 | .read = seq_read, | |
398 | .llseek = seq_lseek, | |
399 | .release = single_release, | |
400 | }; | |
401 | ||
d7e3621a OS |
402 | static int hctx_sched_tags_bitmap_show(struct seq_file *m, void *v) |
403 | { | |
404 | struct blk_mq_hw_ctx *hctx = m->private; | |
405 | struct request_queue *q = hctx->queue; | |
8c0f14ea | 406 | int res; |
d7e3621a | 407 | |
8c0f14ea BVA |
408 | res = mutex_lock_interruptible(&q->sysfs_lock); |
409 | if (res) | |
410 | goto out; | |
d7e3621a OS |
411 | if (hctx->sched_tags) |
412 | sbitmap_bitmap_show(&hctx->sched_tags->bitmap_tags.sb, m); | |
413 | mutex_unlock(&q->sysfs_lock); | |
8c0f14ea BVA |
414 | |
415 | out: | |
416 | return res; | |
d7e3621a OS |
417 | } |
418 | ||
419 | static int hctx_sched_tags_bitmap_open(struct inode *inode, struct file *file) | |
420 | { | |
421 | return single_open(file, hctx_sched_tags_bitmap_show, inode->i_private); | |
422 | } | |
423 | ||
424 | static const struct file_operations hctx_sched_tags_bitmap_fops = { | |
425 | .open = hctx_sched_tags_bitmap_open, | |
426 | .read = seq_read, | |
427 | .llseek = seq_lseek, | |
428 | .release = single_release, | |
429 | }; | |
430 | ||
be215473 OS |
431 | static int hctx_io_poll_show(struct seq_file *m, void *v) |
432 | { | |
433 | struct blk_mq_hw_ctx *hctx = m->private; | |
434 | ||
435 | seq_printf(m, "considered=%lu\n", hctx->poll_considered); | |
436 | seq_printf(m, "invoked=%lu\n", hctx->poll_invoked); | |
437 | seq_printf(m, "success=%lu\n", hctx->poll_success); | |
438 | return 0; | |
439 | } | |
440 | ||
441 | static int hctx_io_poll_open(struct inode *inode, struct file *file) | |
442 | { | |
443 | return single_open(file, hctx_io_poll_show, inode->i_private); | |
444 | } | |
445 | ||
446 | static ssize_t hctx_io_poll_write(struct file *file, const char __user *buf, | |
447 | size_t count, loff_t *ppos) | |
448 | { | |
449 | struct seq_file *m = file->private_data; | |
450 | struct blk_mq_hw_ctx *hctx = m->private; | |
451 | ||
452 | hctx->poll_considered = hctx->poll_invoked = hctx->poll_success = 0; | |
453 | return count; | |
454 | } | |
455 | ||
456 | static const struct file_operations hctx_io_poll_fops = { | |
457 | .open = hctx_io_poll_open, | |
458 | .read = seq_read, | |
459 | .write = hctx_io_poll_write, | |
460 | .llseek = seq_lseek, | |
461 | .release = single_release, | |
462 | }; | |
463 | ||
be215473 OS |
464 | static int hctx_dispatched_show(struct seq_file *m, void *v) |
465 | { | |
466 | struct blk_mq_hw_ctx *hctx = m->private; | |
467 | int i; | |
468 | ||
469 | seq_printf(m, "%8u\t%lu\n", 0U, hctx->dispatched[0]); | |
470 | ||
471 | for (i = 1; i < BLK_MQ_MAX_DISPATCH_ORDER - 1; i++) { | |
472 | unsigned int d = 1U << (i - 1); | |
473 | ||
474 | seq_printf(m, "%8u\t%lu\n", d, hctx->dispatched[i]); | |
475 | } | |
476 | ||
477 | seq_printf(m, "%8u+\t%lu\n", 1U << (i - 1), hctx->dispatched[i]); | |
478 | return 0; | |
479 | } | |
480 | ||
481 | static int hctx_dispatched_open(struct inode *inode, struct file *file) | |
482 | { | |
483 | return single_open(file, hctx_dispatched_show, inode->i_private); | |
484 | } | |
485 | ||
486 | static ssize_t hctx_dispatched_write(struct file *file, const char __user *buf, | |
487 | size_t count, loff_t *ppos) | |
488 | { | |
489 | struct seq_file *m = file->private_data; | |
490 | struct blk_mq_hw_ctx *hctx = m->private; | |
491 | int i; | |
492 | ||
493 | for (i = 0; i < BLK_MQ_MAX_DISPATCH_ORDER; i++) | |
494 | hctx->dispatched[i] = 0; | |
495 | return count; | |
496 | } | |
497 | ||
498 | static const struct file_operations hctx_dispatched_fops = { | |
499 | .open = hctx_dispatched_open, | |
500 | .read = seq_read, | |
501 | .write = hctx_dispatched_write, | |
502 | .llseek = seq_lseek, | |
503 | .release = single_release, | |
504 | }; | |
505 | ||
4a46f05e OS |
506 | static int hctx_queued_show(struct seq_file *m, void *v) |
507 | { | |
508 | struct blk_mq_hw_ctx *hctx = m->private; | |
509 | ||
510 | seq_printf(m, "%lu\n", hctx->queued); | |
511 | return 0; | |
512 | } | |
513 | ||
514 | static int hctx_queued_open(struct inode *inode, struct file *file) | |
515 | { | |
516 | return single_open(file, hctx_queued_show, inode->i_private); | |
517 | } | |
518 | ||
519 | static ssize_t hctx_queued_write(struct file *file, const char __user *buf, | |
520 | size_t count, loff_t *ppos) | |
521 | { | |
522 | struct seq_file *m = file->private_data; | |
523 | struct blk_mq_hw_ctx *hctx = m->private; | |
524 | ||
525 | hctx->queued = 0; | |
526 | return count; | |
527 | } | |
528 | ||
529 | static const struct file_operations hctx_queued_fops = { | |
530 | .open = hctx_queued_open, | |
531 | .read = seq_read, | |
532 | .write = hctx_queued_write, | |
533 | .llseek = seq_lseek, | |
534 | .release = single_release, | |
535 | }; | |
536 | ||
537 | static int hctx_run_show(struct seq_file *m, void *v) | |
538 | { | |
539 | struct blk_mq_hw_ctx *hctx = m->private; | |
540 | ||
541 | seq_printf(m, "%lu\n", hctx->run); | |
542 | return 0; | |
543 | } | |
544 | ||
545 | static int hctx_run_open(struct inode *inode, struct file *file) | |
546 | { | |
547 | return single_open(file, hctx_run_show, inode->i_private); | |
548 | } | |
549 | ||
550 | static ssize_t hctx_run_write(struct file *file, const char __user *buf, | |
551 | size_t count, loff_t *ppos) | |
552 | { | |
553 | struct seq_file *m = file->private_data; | |
554 | struct blk_mq_hw_ctx *hctx = m->private; | |
555 | ||
556 | hctx->run = 0; | |
557 | return count; | |
558 | } | |
559 | ||
560 | static const struct file_operations hctx_run_fops = { | |
561 | .open = hctx_run_open, | |
562 | .read = seq_read, | |
563 | .write = hctx_run_write, | |
564 | .llseek = seq_lseek, | |
565 | .release = single_release, | |
566 | }; | |
567 | ||
568 | static int hctx_active_show(struct seq_file *m, void *v) | |
569 | { | |
570 | struct blk_mq_hw_ctx *hctx = m->private; | |
571 | ||
572 | seq_printf(m, "%d\n", atomic_read(&hctx->nr_active)); | |
573 | return 0; | |
574 | } | |
575 | ||
576 | static int hctx_active_open(struct inode *inode, struct file *file) | |
577 | { | |
578 | return single_open(file, hctx_active_show, inode->i_private); | |
579 | } | |
580 | ||
581 | static const struct file_operations hctx_active_fops = { | |
582 | .open = hctx_active_open, | |
583 | .read = seq_read, | |
584 | .llseek = seq_lseek, | |
585 | .release = single_release, | |
586 | }; | |
587 | ||
950cd7e9 | 588 | static void *ctx_rq_list_start(struct seq_file *m, loff_t *pos) |
f3bcb0e6 | 589 | __acquires(&ctx->lock) |
950cd7e9 OS |
590 | { |
591 | struct blk_mq_ctx *ctx = m->private; | |
592 | ||
593 | spin_lock(&ctx->lock); | |
594 | return seq_list_start(&ctx->rq_list, *pos); | |
595 | } | |
596 | ||
597 | static void *ctx_rq_list_next(struct seq_file *m, void *v, loff_t *pos) | |
598 | { | |
599 | struct blk_mq_ctx *ctx = m->private; | |
600 | ||
601 | return seq_list_next(v, &ctx->rq_list, pos); | |
602 | } | |
603 | ||
604 | static void ctx_rq_list_stop(struct seq_file *m, void *v) | |
f3bcb0e6 | 605 | __releases(&ctx->lock) |
950cd7e9 OS |
606 | { |
607 | struct blk_mq_ctx *ctx = m->private; | |
608 | ||
609 | spin_unlock(&ctx->lock); | |
610 | } | |
611 | ||
612 | static const struct seq_operations ctx_rq_list_seq_ops = { | |
613 | .start = ctx_rq_list_start, | |
614 | .next = ctx_rq_list_next, | |
615 | .stop = ctx_rq_list_stop, | |
616 | .show = blk_mq_debugfs_rq_show, | |
617 | }; | |
618 | ||
619 | static int ctx_rq_list_open(struct inode *inode, struct file *file) | |
620 | { | |
621 | return blk_mq_debugfs_seq_open(inode, file, &ctx_rq_list_seq_ops); | |
622 | } | |
623 | ||
624 | static const struct file_operations ctx_rq_list_fops = { | |
625 | .open = ctx_rq_list_open, | |
626 | .read = seq_read, | |
627 | .llseek = seq_lseek, | |
628 | .release = seq_release, | |
629 | }; | |
630 | ||
4a46f05e OS |
631 | static int ctx_dispatched_show(struct seq_file *m, void *v) |
632 | { | |
633 | struct blk_mq_ctx *ctx = m->private; | |
634 | ||
635 | seq_printf(m, "%lu %lu\n", ctx->rq_dispatched[1], ctx->rq_dispatched[0]); | |
636 | return 0; | |
637 | } | |
638 | ||
639 | static int ctx_dispatched_open(struct inode *inode, struct file *file) | |
640 | { | |
641 | return single_open(file, ctx_dispatched_show, inode->i_private); | |
642 | } | |
643 | ||
644 | static ssize_t ctx_dispatched_write(struct file *file, const char __user *buf, | |
645 | size_t count, loff_t *ppos) | |
646 | { | |
647 | struct seq_file *m = file->private_data; | |
648 | struct blk_mq_ctx *ctx = m->private; | |
649 | ||
650 | ctx->rq_dispatched[0] = ctx->rq_dispatched[1] = 0; | |
651 | return count; | |
652 | } | |
653 | ||
654 | static const struct file_operations ctx_dispatched_fops = { | |
655 | .open = ctx_dispatched_open, | |
656 | .read = seq_read, | |
657 | .write = ctx_dispatched_write, | |
658 | .llseek = seq_lseek, | |
659 | .release = single_release, | |
660 | }; | |
661 | ||
662 | static int ctx_merged_show(struct seq_file *m, void *v) | |
663 | { | |
664 | struct blk_mq_ctx *ctx = m->private; | |
665 | ||
666 | seq_printf(m, "%lu\n", ctx->rq_merged); | |
667 | return 0; | |
668 | } | |
669 | ||
670 | static int ctx_merged_open(struct inode *inode, struct file *file) | |
671 | { | |
672 | return single_open(file, ctx_merged_show, inode->i_private); | |
673 | } | |
674 | ||
675 | static ssize_t ctx_merged_write(struct file *file, const char __user *buf, | |
676 | size_t count, loff_t *ppos) | |
677 | { | |
678 | struct seq_file *m = file->private_data; | |
679 | struct blk_mq_ctx *ctx = m->private; | |
680 | ||
681 | ctx->rq_merged = 0; | |
682 | return count; | |
683 | } | |
684 | ||
685 | static const struct file_operations ctx_merged_fops = { | |
686 | .open = ctx_merged_open, | |
687 | .read = seq_read, | |
688 | .write = ctx_merged_write, | |
689 | .llseek = seq_lseek, | |
690 | .release = single_release, | |
691 | }; | |
692 | ||
693 | static int ctx_completed_show(struct seq_file *m, void *v) | |
694 | { | |
695 | struct blk_mq_ctx *ctx = m->private; | |
696 | ||
697 | seq_printf(m, "%lu %lu\n", ctx->rq_completed[1], ctx->rq_completed[0]); | |
698 | return 0; | |
699 | } | |
700 | ||
701 | static int ctx_completed_open(struct inode *inode, struct file *file) | |
702 | { | |
703 | return single_open(file, ctx_completed_show, inode->i_private); | |
704 | } | |
705 | ||
706 | static ssize_t ctx_completed_write(struct file *file, const char __user *buf, | |
707 | size_t count, loff_t *ppos) | |
708 | { | |
709 | struct seq_file *m = file->private_data; | |
710 | struct blk_mq_ctx *ctx = m->private; | |
711 | ||
712 | ctx->rq_completed[0] = ctx->rq_completed[1] = 0; | |
713 | return count; | |
714 | } | |
715 | ||
716 | static const struct file_operations ctx_completed_fops = { | |
717 | .open = ctx_completed_open, | |
718 | .read = seq_read, | |
719 | .write = ctx_completed_write, | |
720 | .llseek = seq_lseek, | |
721 | .release = single_release, | |
722 | }; | |
723 | ||
34dbad5d OS |
724 | static const struct blk_mq_debugfs_attr blk_mq_debugfs_queue_attrs[] = { |
725 | {"poll_stat", 0400, &queue_poll_stat_fops}, | |
726 | {}, | |
727 | }; | |
728 | ||
07e4fead | 729 | static const struct blk_mq_debugfs_attr blk_mq_debugfs_hctx_attrs[] = { |
9abb2ad2 OS |
730 | {"state", 0400, &hctx_state_fops}, |
731 | {"flags", 0400, &hctx_flags_fops}, | |
950cd7e9 | 732 | {"dispatch", 0400, &hctx_dispatch_fops}, |
0bfa5288 | 733 | {"ctx_map", 0400, &hctx_ctx_map_fops}, |
d96b37c0 | 734 | {"tags", 0400, &hctx_tags_fops}, |
d7e3621a | 735 | {"tags_bitmap", 0400, &hctx_tags_bitmap_fops}, |
d96b37c0 | 736 | {"sched_tags", 0400, &hctx_sched_tags_fops}, |
d7e3621a | 737 | {"sched_tags_bitmap", 0400, &hctx_sched_tags_bitmap_fops}, |
be215473 | 738 | {"io_poll", 0600, &hctx_io_poll_fops}, |
be215473 | 739 | {"dispatched", 0600, &hctx_dispatched_fops}, |
4a46f05e OS |
740 | {"queued", 0600, &hctx_queued_fops}, |
741 | {"run", 0600, &hctx_run_fops}, | |
742 | {"active", 0400, &hctx_active_fops}, | |
72f2f8f6 | 743 | {}, |
07e4fead OS |
744 | }; |
745 | ||
746 | static const struct blk_mq_debugfs_attr blk_mq_debugfs_ctx_attrs[] = { | |
950cd7e9 | 747 | {"rq_list", 0400, &ctx_rq_list_fops}, |
4a46f05e OS |
748 | {"dispatched", 0600, &ctx_dispatched_fops}, |
749 | {"merged", 0600, &ctx_merged_fops}, | |
750 | {"completed", 0600, &ctx_completed_fops}, | |
72f2f8f6 | 751 | {}, |
07e4fead OS |
752 | }; |
753 | ||
754 | int blk_mq_debugfs_register(struct request_queue *q, const char *name) | |
755 | { | |
18fbda91 | 756 | if (!blk_debugfs_root) |
07e4fead OS |
757 | return -ENOENT; |
758 | ||
18fbda91 | 759 | q->debugfs_dir = debugfs_create_dir(name, blk_debugfs_root); |
07e4fead OS |
760 | if (!q->debugfs_dir) |
761 | goto err; | |
762 | ||
763 | if (blk_mq_debugfs_register_hctxs(q)) | |
764 | goto err; | |
765 | ||
766 | return 0; | |
767 | ||
768 | err: | |
769 | blk_mq_debugfs_unregister(q); | |
770 | return -ENOMEM; | |
771 | } | |
772 | ||
773 | void blk_mq_debugfs_unregister(struct request_queue *q) | |
774 | { | |
775 | debugfs_remove_recursive(q->debugfs_dir); | |
776 | q->mq_debugfs_dir = NULL; | |
777 | q->debugfs_dir = NULL; | |
778 | } | |
779 | ||
72f2f8f6 BVA |
780 | static bool debugfs_create_files(struct dentry *parent, void *data, |
781 | const struct blk_mq_debugfs_attr *attr) | |
782 | { | |
783 | for (; attr->name; attr++) { | |
784 | if (!debugfs_create_file(attr->name, attr->mode, parent, | |
785 | data, attr->fops)) | |
786 | return false; | |
787 | } | |
788 | return true; | |
789 | } | |
790 | ||
07e4fead OS |
791 | static int blk_mq_debugfs_register_ctx(struct request_queue *q, |
792 | struct blk_mq_ctx *ctx, | |
793 | struct dentry *hctx_dir) | |
794 | { | |
795 | struct dentry *ctx_dir; | |
796 | char name[20]; | |
07e4fead OS |
797 | |
798 | snprintf(name, sizeof(name), "cpu%u", ctx->cpu); | |
799 | ctx_dir = debugfs_create_dir(name, hctx_dir); | |
800 | if (!ctx_dir) | |
801 | return -ENOMEM; | |
802 | ||
72f2f8f6 BVA |
803 | if (!debugfs_create_files(ctx_dir, ctx, blk_mq_debugfs_ctx_attrs)) |
804 | return -ENOMEM; | |
07e4fead OS |
805 | |
806 | return 0; | |
807 | } | |
808 | ||
809 | static int blk_mq_debugfs_register_hctx(struct request_queue *q, | |
810 | struct blk_mq_hw_ctx *hctx) | |
811 | { | |
812 | struct blk_mq_ctx *ctx; | |
813 | struct dentry *hctx_dir; | |
814 | char name[20]; | |
815 | int i; | |
816 | ||
817 | snprintf(name, sizeof(name), "%u", hctx->queue_num); | |
818 | hctx_dir = debugfs_create_dir(name, q->mq_debugfs_dir); | |
819 | if (!hctx_dir) | |
820 | return -ENOMEM; | |
821 | ||
72f2f8f6 BVA |
822 | if (!debugfs_create_files(hctx_dir, hctx, blk_mq_debugfs_hctx_attrs)) |
823 | return -ENOMEM; | |
07e4fead OS |
824 | |
825 | hctx_for_each_ctx(hctx, ctx, i) { | |
826 | if (blk_mq_debugfs_register_ctx(q, ctx, hctx_dir)) | |
827 | return -ENOMEM; | |
828 | } | |
829 | ||
830 | return 0; | |
831 | } | |
832 | ||
833 | int blk_mq_debugfs_register_hctxs(struct request_queue *q) | |
834 | { | |
835 | struct blk_mq_hw_ctx *hctx; | |
836 | int i; | |
837 | ||
838 | if (!q->debugfs_dir) | |
839 | return -ENOENT; | |
840 | ||
91d68905 BVA |
841 | if (!debugfs_create_files(q->debugfs_dir, q, blk_queue_attrs)) |
842 | goto err; | |
843 | ||
07e4fead OS |
844 | q->mq_debugfs_dir = debugfs_create_dir("mq", q->debugfs_dir); |
845 | if (!q->mq_debugfs_dir) | |
846 | goto err; | |
847 | ||
34dbad5d OS |
848 | if (!debugfs_create_files(q->mq_debugfs_dir, q, blk_mq_debugfs_queue_attrs)) |
849 | goto err; | |
850 | ||
07e4fead OS |
851 | queue_for_each_hw_ctx(q, hctx, i) { |
852 | if (blk_mq_debugfs_register_hctx(q, hctx)) | |
853 | goto err; | |
854 | } | |
855 | ||
856 | return 0; | |
857 | ||
858 | err: | |
859 | blk_mq_debugfs_unregister_hctxs(q); | |
860 | return -ENOMEM; | |
861 | } | |
862 | ||
863 | void blk_mq_debugfs_unregister_hctxs(struct request_queue *q) | |
864 | { | |
865 | debugfs_remove_recursive(q->mq_debugfs_dir); | |
866 | q->mq_debugfs_dir = NULL; | |
867 | } |