Omar Sandoval | 07e4fea | 2017-01-25 08:06:40 -0800 | [diff] [blame] | 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> |
Omar Sandoval | 18fbda9 | 2017-01-31 14:53:20 -0800 | [diff] [blame] | 22 | #include "blk.h" |
Omar Sandoval | 07e4fea | 2017-01-25 08:06:40 -0800 | [diff] [blame] | 23 | #include "blk-mq.h" |
Omar Sandoval | d173a25 | 2017-05-04 00:31:30 -0700 | [diff] [blame^] | 24 | #include "blk-mq-debugfs.h" |
Omar Sandoval | d96b37c | 2017-01-25 08:06:46 -0800 | [diff] [blame] | 25 | #include "blk-mq-tag.h" |
Omar Sandoval | 07e4fea | 2017-01-25 08:06:40 -0800 | [diff] [blame] | 26 | |
| 27 | struct blk_mq_debugfs_attr { |
| 28 | const char *name; |
| 29 | umode_t mode; |
Omar Sandoval | f57de23 | 2017-05-04 00:31:28 -0700 | [diff] [blame] | 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; |
Omar Sandoval | 07e4fea | 2017-01-25 08:06:40 -0800 | [diff] [blame] | 34 | }; |
| 35 | |
Bart Van Assche | 91d6890 | 2017-04-10 16:13:15 -0600 | [diff] [blame] | 36 | static int blk_flags_show(struct seq_file *m, const unsigned long flags, |
| 37 | const char *const *flag_name, int flag_name_count) |
| 38 | { |
| 39 | bool sep = false; |
| 40 | int i; |
| 41 | |
| 42 | for (i = 0; i < sizeof(flags) * BITS_PER_BYTE; i++) { |
| 43 | if (!(flags & BIT(i))) |
| 44 | continue; |
| 45 | if (sep) |
Omar Sandoval | bec03d6 | 2017-05-04 00:31:23 -0700 | [diff] [blame] | 46 | seq_puts(m, "|"); |
Bart Van Assche | 91d6890 | 2017-04-10 16:13:15 -0600 | [diff] [blame] | 47 | sep = true; |
| 48 | if (i < flag_name_count && flag_name[i]) |
| 49 | seq_puts(m, flag_name[i]); |
| 50 | else |
| 51 | seq_printf(m, "%d", i); |
| 52 | } |
Bart Van Assche | 91d6890 | 2017-04-10 16:13:15 -0600 | [diff] [blame] | 53 | return 0; |
| 54 | } |
| 55 | |
Omar Sandoval | 1a43511 | 2017-05-04 00:31:24 -0700 | [diff] [blame] | 56 | #define QUEUE_FLAG_NAME(name) [QUEUE_FLAG_##name] = #name |
Bart Van Assche | 91d6890 | 2017-04-10 16:13:15 -0600 | [diff] [blame] | 57 | static const char *const blk_queue_flag_name[] = { |
Omar Sandoval | 1a43511 | 2017-05-04 00:31:24 -0700 | [diff] [blame] | 58 | QUEUE_FLAG_NAME(QUEUED), |
| 59 | QUEUE_FLAG_NAME(STOPPED), |
| 60 | QUEUE_FLAG_NAME(SYNCFULL), |
| 61 | QUEUE_FLAG_NAME(ASYNCFULL), |
| 62 | QUEUE_FLAG_NAME(DYING), |
| 63 | QUEUE_FLAG_NAME(BYPASS), |
| 64 | QUEUE_FLAG_NAME(BIDI), |
| 65 | QUEUE_FLAG_NAME(NOMERGES), |
| 66 | QUEUE_FLAG_NAME(SAME_COMP), |
| 67 | QUEUE_FLAG_NAME(FAIL_IO), |
| 68 | QUEUE_FLAG_NAME(STACKABLE), |
| 69 | QUEUE_FLAG_NAME(NONROT), |
| 70 | QUEUE_FLAG_NAME(IO_STAT), |
| 71 | QUEUE_FLAG_NAME(DISCARD), |
| 72 | QUEUE_FLAG_NAME(NOXMERGES), |
| 73 | QUEUE_FLAG_NAME(ADD_RANDOM), |
| 74 | QUEUE_FLAG_NAME(SECERASE), |
| 75 | QUEUE_FLAG_NAME(SAME_FORCE), |
| 76 | QUEUE_FLAG_NAME(DEAD), |
| 77 | QUEUE_FLAG_NAME(INIT_DONE), |
| 78 | QUEUE_FLAG_NAME(NO_SG_MERGE), |
| 79 | QUEUE_FLAG_NAME(POLL), |
| 80 | QUEUE_FLAG_NAME(WC), |
| 81 | QUEUE_FLAG_NAME(FUA), |
| 82 | QUEUE_FLAG_NAME(FLUSH_NQ), |
| 83 | QUEUE_FLAG_NAME(DAX), |
| 84 | QUEUE_FLAG_NAME(STATS), |
| 85 | QUEUE_FLAG_NAME(POLL_STATS), |
| 86 | QUEUE_FLAG_NAME(REGISTERED), |
Bart Van Assche | 91d6890 | 2017-04-10 16:13:15 -0600 | [diff] [blame] | 87 | }; |
Omar Sandoval | 1a43511 | 2017-05-04 00:31:24 -0700 | [diff] [blame] | 88 | #undef QUEUE_FLAG_NAME |
Bart Van Assche | 91d6890 | 2017-04-10 16:13:15 -0600 | [diff] [blame] | 89 | |
Omar Sandoval | f57de23 | 2017-05-04 00:31:28 -0700 | [diff] [blame] | 90 | static int queue_state_show(void *data, struct seq_file *m) |
Bart Van Assche | 91d6890 | 2017-04-10 16:13:15 -0600 | [diff] [blame] | 91 | { |
Omar Sandoval | f57de23 | 2017-05-04 00:31:28 -0700 | [diff] [blame] | 92 | struct request_queue *q = data; |
Bart Van Assche | 91d6890 | 2017-04-10 16:13:15 -0600 | [diff] [blame] | 93 | |
| 94 | blk_flags_show(m, q->queue_flags, blk_queue_flag_name, |
| 95 | ARRAY_SIZE(blk_queue_flag_name)); |
Bart Van Assche | fd07dc8 | 2017-04-26 13:47:54 -0700 | [diff] [blame] | 96 | seq_puts(m, "\n"); |
Bart Van Assche | 91d6890 | 2017-04-10 16:13:15 -0600 | [diff] [blame] | 97 | return 0; |
| 98 | } |
| 99 | |
Omar Sandoval | f57de23 | 2017-05-04 00:31:28 -0700 | [diff] [blame] | 100 | static ssize_t queue_state_write(void *data, const char __user *buf, |
| 101 | size_t count, loff_t *ppos) |
Bart Van Assche | 91d6890 | 2017-04-10 16:13:15 -0600 | [diff] [blame] | 102 | { |
Omar Sandoval | f57de23 | 2017-05-04 00:31:28 -0700 | [diff] [blame] | 103 | struct request_queue *q = data; |
Omar Sandoval | 71b9051 | 2017-05-04 00:31:26 -0700 | [diff] [blame] | 104 | char opbuf[16] = { }, *op; |
Bart Van Assche | 91d6890 | 2017-04-10 16:13:15 -0600 | [diff] [blame] | 105 | |
Bart Van Assche | 18d4d7d | 2017-05-04 00:31:29 -0700 | [diff] [blame] | 106 | /* |
| 107 | * The "state" attribute is removed after blk_cleanup_queue() has called |
| 108 | * blk_mq_free_queue(). Return if QUEUE_FLAG_DEAD has been set to avoid |
| 109 | * triggering a use-after-free. |
| 110 | */ |
| 111 | if (blk_queue_dead(q)) |
| 112 | return -ENOENT; |
| 113 | |
Omar Sandoval | 71b9051 | 2017-05-04 00:31:26 -0700 | [diff] [blame] | 114 | if (count >= sizeof(opbuf)) { |
Omar Sandoval | c7e4145 | 2017-05-04 00:31:25 -0700 | [diff] [blame] | 115 | pr_err("%s: operation too long\n", __func__); |
| 116 | goto inval; |
| 117 | } |
| 118 | |
Omar Sandoval | 71b9051 | 2017-05-04 00:31:26 -0700 | [diff] [blame] | 119 | if (copy_from_user(opbuf, buf, count)) |
Bart Van Assche | 91d6890 | 2017-04-10 16:13:15 -0600 | [diff] [blame] | 120 | return -EFAULT; |
Omar Sandoval | 71b9051 | 2017-05-04 00:31:26 -0700 | [diff] [blame] | 121 | op = strstrip(opbuf); |
Bart Van Assche | 91d6890 | 2017-04-10 16:13:15 -0600 | [diff] [blame] | 122 | if (strcmp(op, "run") == 0) { |
| 123 | blk_mq_run_hw_queues(q, true); |
| 124 | } else if (strcmp(op, "start") == 0) { |
| 125 | blk_mq_start_stopped_hw_queues(q, true); |
| 126 | } else { |
Omar Sandoval | c7e4145 | 2017-05-04 00:31:25 -0700 | [diff] [blame] | 127 | pr_err("%s: unsupported operation '%s'\n", __func__, op); |
| 128 | inval: |
| 129 | pr_err("%s: use either 'run' or 'start'\n", __func__); |
Bart Van Assche | 91d6890 | 2017-04-10 16:13:15 -0600 | [diff] [blame] | 130 | return -EINVAL; |
| 131 | } |
Omar Sandoval | c7e4145 | 2017-05-04 00:31:25 -0700 | [diff] [blame] | 132 | return count; |
Bart Van Assche | 91d6890 | 2017-04-10 16:13:15 -0600 | [diff] [blame] | 133 | } |
| 134 | |
Omar Sandoval | 34dbad5 | 2017-03-21 08:56:08 -0700 | [diff] [blame] | 135 | static void print_stat(struct seq_file *m, struct blk_rq_stat *stat) |
| 136 | { |
| 137 | if (stat->nr_samples) { |
| 138 | seq_printf(m, "samples=%d, mean=%lld, min=%llu, max=%llu", |
| 139 | stat->nr_samples, stat->mean, stat->min, stat->max); |
| 140 | } else { |
| 141 | seq_puts(m, "samples=0"); |
| 142 | } |
| 143 | } |
| 144 | |
Omar Sandoval | f57de23 | 2017-05-04 00:31:28 -0700 | [diff] [blame] | 145 | static int queue_poll_stat_show(void *data, struct seq_file *m) |
Omar Sandoval | 34dbad5 | 2017-03-21 08:56:08 -0700 | [diff] [blame] | 146 | { |
Omar Sandoval | f57de23 | 2017-05-04 00:31:28 -0700 | [diff] [blame] | 147 | struct request_queue *q = data; |
Stephen Bates | 0206319 | 2017-04-20 16:59:11 -0600 | [diff] [blame] | 148 | int bucket; |
Omar Sandoval | 34dbad5 | 2017-03-21 08:56:08 -0700 | [diff] [blame] | 149 | |
Stephen Bates | 0206319 | 2017-04-20 16:59:11 -0600 | [diff] [blame] | 150 | for (bucket = 0; bucket < BLK_MQ_POLL_STATS_BKTS/2; bucket++) { |
| 151 | seq_printf(m, "read (%d Bytes): ", 1 << (9+bucket)); |
| 152 | print_stat(m, &q->poll_stat[2*bucket]); |
| 153 | seq_puts(m, "\n"); |
Omar Sandoval | 34dbad5 | 2017-03-21 08:56:08 -0700 | [diff] [blame] | 154 | |
Stephen Bates | 0206319 | 2017-04-20 16:59:11 -0600 | [diff] [blame] | 155 | seq_printf(m, "write (%d Bytes): ", 1 << (9+bucket)); |
| 156 | print_stat(m, &q->poll_stat[2*bucket+1]); |
| 157 | seq_puts(m, "\n"); |
| 158 | } |
Omar Sandoval | 34dbad5 | 2017-03-21 08:56:08 -0700 | [diff] [blame] | 159 | return 0; |
| 160 | } |
| 161 | |
Omar Sandoval | 1a43511 | 2017-05-04 00:31:24 -0700 | [diff] [blame] | 162 | #define HCTX_STATE_NAME(name) [BLK_MQ_S_##name] = #name |
Bart Van Assche | f5c0b091 | 2017-03-30 11:21:27 -0700 | [diff] [blame] | 163 | static const char *const hctx_state_name[] = { |
Omar Sandoval | 1a43511 | 2017-05-04 00:31:24 -0700 | [diff] [blame] | 164 | HCTX_STATE_NAME(STOPPED), |
| 165 | HCTX_STATE_NAME(TAG_ACTIVE), |
| 166 | HCTX_STATE_NAME(SCHED_RESTART), |
| 167 | HCTX_STATE_NAME(TAG_WAITING), |
| 168 | HCTX_STATE_NAME(START_ON_RUN), |
Bart Van Assche | f5c0b091 | 2017-03-30 11:21:27 -0700 | [diff] [blame] | 169 | }; |
Omar Sandoval | 1a43511 | 2017-05-04 00:31:24 -0700 | [diff] [blame] | 170 | #undef HCTX_STATE_NAME |
| 171 | |
Omar Sandoval | f57de23 | 2017-05-04 00:31:28 -0700 | [diff] [blame] | 172 | static int hctx_state_show(void *data, struct seq_file *m) |
Omar Sandoval | 9abb2ad | 2017-01-25 08:06:41 -0800 | [diff] [blame] | 173 | { |
Omar Sandoval | f57de23 | 2017-05-04 00:31:28 -0700 | [diff] [blame] | 174 | struct blk_mq_hw_ctx *hctx = data; |
Omar Sandoval | 9abb2ad | 2017-01-25 08:06:41 -0800 | [diff] [blame] | 175 | |
Bart Van Assche | f5c0b091 | 2017-03-30 11:21:27 -0700 | [diff] [blame] | 176 | blk_flags_show(m, hctx->state, hctx_state_name, |
| 177 | ARRAY_SIZE(hctx_state_name)); |
Bart Van Assche | fd07dc8 | 2017-04-26 13:47:54 -0700 | [diff] [blame] | 178 | seq_puts(m, "\n"); |
Omar Sandoval | 9abb2ad | 2017-01-25 08:06:41 -0800 | [diff] [blame] | 179 | return 0; |
| 180 | } |
| 181 | |
Omar Sandoval | 1a43511 | 2017-05-04 00:31:24 -0700 | [diff] [blame] | 182 | #define BLK_TAG_ALLOC_NAME(name) [BLK_TAG_ALLOC_##name] = #name |
Bart Van Assche | f5c0b091 | 2017-03-30 11:21:27 -0700 | [diff] [blame] | 183 | static const char *const alloc_policy_name[] = { |
Omar Sandoval | 1a43511 | 2017-05-04 00:31:24 -0700 | [diff] [blame] | 184 | BLK_TAG_ALLOC_NAME(FIFO), |
| 185 | BLK_TAG_ALLOC_NAME(RR), |
Bart Van Assche | f5c0b091 | 2017-03-30 11:21:27 -0700 | [diff] [blame] | 186 | }; |
Omar Sandoval | 1a43511 | 2017-05-04 00:31:24 -0700 | [diff] [blame] | 187 | #undef BLK_TAG_ALLOC_NAME |
Bart Van Assche | f5c0b091 | 2017-03-30 11:21:27 -0700 | [diff] [blame] | 188 | |
Omar Sandoval | 1a43511 | 2017-05-04 00:31:24 -0700 | [diff] [blame] | 189 | #define HCTX_FLAG_NAME(name) [ilog2(BLK_MQ_F_##name)] = #name |
Bart Van Assche | f5c0b091 | 2017-03-30 11:21:27 -0700 | [diff] [blame] | 190 | static const char *const hctx_flag_name[] = { |
Omar Sandoval | 1a43511 | 2017-05-04 00:31:24 -0700 | [diff] [blame] | 191 | HCTX_FLAG_NAME(SHOULD_MERGE), |
| 192 | HCTX_FLAG_NAME(TAG_SHARED), |
| 193 | HCTX_FLAG_NAME(SG_MERGE), |
| 194 | HCTX_FLAG_NAME(BLOCKING), |
| 195 | HCTX_FLAG_NAME(NO_SCHED), |
Bart Van Assche | f5c0b091 | 2017-03-30 11:21:27 -0700 | [diff] [blame] | 196 | }; |
Omar Sandoval | 1a43511 | 2017-05-04 00:31:24 -0700 | [diff] [blame] | 197 | #undef HCTX_FLAG_NAME |
Bart Van Assche | f5c0b091 | 2017-03-30 11:21:27 -0700 | [diff] [blame] | 198 | |
Omar Sandoval | f57de23 | 2017-05-04 00:31:28 -0700 | [diff] [blame] | 199 | static int hctx_flags_show(void *data, struct seq_file *m) |
Omar Sandoval | 9abb2ad | 2017-01-25 08:06:41 -0800 | [diff] [blame] | 200 | { |
Omar Sandoval | f57de23 | 2017-05-04 00:31:28 -0700 | [diff] [blame] | 201 | struct blk_mq_hw_ctx *hctx = data; |
Bart Van Assche | f5c0b091 | 2017-03-30 11:21:27 -0700 | [diff] [blame] | 202 | const int alloc_policy = BLK_MQ_FLAG_TO_ALLOC_POLICY(hctx->flags); |
Omar Sandoval | 9abb2ad | 2017-01-25 08:06:41 -0800 | [diff] [blame] | 203 | |
Bart Van Assche | f5c0b091 | 2017-03-30 11:21:27 -0700 | [diff] [blame] | 204 | seq_puts(m, "alloc_policy="); |
| 205 | if (alloc_policy < ARRAY_SIZE(alloc_policy_name) && |
| 206 | alloc_policy_name[alloc_policy]) |
| 207 | seq_puts(m, alloc_policy_name[alloc_policy]); |
| 208 | else |
| 209 | seq_printf(m, "%d", alloc_policy); |
| 210 | seq_puts(m, " "); |
| 211 | blk_flags_show(m, |
| 212 | hctx->flags ^ BLK_ALLOC_POLICY_TO_MQ_FLAG(alloc_policy), |
| 213 | hctx_flag_name, ARRAY_SIZE(hctx_flag_name)); |
Bart Van Assche | fd07dc8 | 2017-04-26 13:47:54 -0700 | [diff] [blame] | 214 | seq_puts(m, "\n"); |
Omar Sandoval | 9abb2ad | 2017-01-25 08:06:41 -0800 | [diff] [blame] | 215 | return 0; |
| 216 | } |
| 217 | |
Omar Sandoval | 1a43511 | 2017-05-04 00:31:24 -0700 | [diff] [blame] | 218 | #define REQ_OP_NAME(name) [REQ_OP_##name] = #name |
Bart Van Assche | 8658dca | 2017-04-26 13:47:55 -0700 | [diff] [blame] | 219 | static const char *const op_name[] = { |
Omar Sandoval | 1a43511 | 2017-05-04 00:31:24 -0700 | [diff] [blame] | 220 | REQ_OP_NAME(READ), |
| 221 | REQ_OP_NAME(WRITE), |
| 222 | REQ_OP_NAME(FLUSH), |
| 223 | REQ_OP_NAME(DISCARD), |
| 224 | REQ_OP_NAME(ZONE_REPORT), |
| 225 | REQ_OP_NAME(SECURE_ERASE), |
| 226 | REQ_OP_NAME(ZONE_RESET), |
| 227 | REQ_OP_NAME(WRITE_SAME), |
| 228 | REQ_OP_NAME(WRITE_ZEROES), |
| 229 | REQ_OP_NAME(SCSI_IN), |
| 230 | REQ_OP_NAME(SCSI_OUT), |
| 231 | REQ_OP_NAME(DRV_IN), |
| 232 | REQ_OP_NAME(DRV_OUT), |
Bart Van Assche | 8658dca | 2017-04-26 13:47:55 -0700 | [diff] [blame] | 233 | }; |
Omar Sandoval | 1a43511 | 2017-05-04 00:31:24 -0700 | [diff] [blame] | 234 | #undef REQ_OP_NAME |
Bart Van Assche | 8658dca | 2017-04-26 13:47:55 -0700 | [diff] [blame] | 235 | |
Omar Sandoval | 1a43511 | 2017-05-04 00:31:24 -0700 | [diff] [blame] | 236 | #define CMD_FLAG_NAME(name) [__REQ_##name] = #name |
Bart Van Assche | 8658dca | 2017-04-26 13:47:55 -0700 | [diff] [blame] | 237 | static const char *const cmd_flag_name[] = { |
Omar Sandoval | 1a43511 | 2017-05-04 00:31:24 -0700 | [diff] [blame] | 238 | CMD_FLAG_NAME(FAILFAST_DEV), |
| 239 | CMD_FLAG_NAME(FAILFAST_TRANSPORT), |
| 240 | CMD_FLAG_NAME(FAILFAST_DRIVER), |
| 241 | CMD_FLAG_NAME(SYNC), |
| 242 | CMD_FLAG_NAME(META), |
| 243 | CMD_FLAG_NAME(PRIO), |
| 244 | CMD_FLAG_NAME(NOMERGE), |
| 245 | CMD_FLAG_NAME(IDLE), |
| 246 | CMD_FLAG_NAME(INTEGRITY), |
| 247 | CMD_FLAG_NAME(FUA), |
| 248 | CMD_FLAG_NAME(PREFLUSH), |
| 249 | CMD_FLAG_NAME(RAHEAD), |
| 250 | CMD_FLAG_NAME(BACKGROUND), |
| 251 | CMD_FLAG_NAME(NOUNMAP), |
Bart Van Assche | 8658dca | 2017-04-26 13:47:55 -0700 | [diff] [blame] | 252 | }; |
Omar Sandoval | 1a43511 | 2017-05-04 00:31:24 -0700 | [diff] [blame] | 253 | #undef CMD_FLAG_NAME |
Bart Van Assche | 8658dca | 2017-04-26 13:47:55 -0700 | [diff] [blame] | 254 | |
Omar Sandoval | 1a43511 | 2017-05-04 00:31:24 -0700 | [diff] [blame] | 255 | #define RQF_NAME(name) [ilog2((__force u32)RQF_##name)] = #name |
Bart Van Assche | 8658dca | 2017-04-26 13:47:55 -0700 | [diff] [blame] | 256 | static const char *const rqf_name[] = { |
Omar Sandoval | 1a43511 | 2017-05-04 00:31:24 -0700 | [diff] [blame] | 257 | RQF_NAME(SORTED), |
| 258 | RQF_NAME(STARTED), |
| 259 | RQF_NAME(QUEUED), |
| 260 | RQF_NAME(SOFTBARRIER), |
| 261 | RQF_NAME(FLUSH_SEQ), |
| 262 | RQF_NAME(MIXED_MERGE), |
| 263 | RQF_NAME(MQ_INFLIGHT), |
| 264 | RQF_NAME(DONTPREP), |
| 265 | RQF_NAME(PREEMPT), |
| 266 | RQF_NAME(COPY_USER), |
| 267 | RQF_NAME(FAILED), |
| 268 | RQF_NAME(QUIET), |
| 269 | RQF_NAME(ELVPRIV), |
| 270 | RQF_NAME(IO_STAT), |
| 271 | RQF_NAME(ALLOCED), |
| 272 | RQF_NAME(PM), |
| 273 | RQF_NAME(HASHED), |
| 274 | RQF_NAME(STATS), |
| 275 | RQF_NAME(SPECIAL_PAYLOAD), |
Bart Van Assche | 8658dca | 2017-04-26 13:47:55 -0700 | [diff] [blame] | 276 | }; |
Omar Sandoval | 1a43511 | 2017-05-04 00:31:24 -0700 | [diff] [blame] | 277 | #undef RQF_NAME |
Bart Van Assche | 8658dca | 2017-04-26 13:47:55 -0700 | [diff] [blame] | 278 | |
Omar Sandoval | 950cd7e | 2017-01-25 08:06:42 -0800 | [diff] [blame] | 279 | static int blk_mq_debugfs_rq_show(struct seq_file *m, void *v) |
| 280 | { |
| 281 | struct request *rq = list_entry_rq(v); |
Bart Van Assche | 2836ee4 | 2017-04-26 13:47:56 -0700 | [diff] [blame] | 282 | const struct blk_mq_ops *const mq_ops = rq->q->mq_ops; |
Bart Van Assche | 8658dca | 2017-04-26 13:47:55 -0700 | [diff] [blame] | 283 | const unsigned int op = rq->cmd_flags & REQ_OP_MASK; |
Omar Sandoval | 950cd7e | 2017-01-25 08:06:42 -0800 | [diff] [blame] | 284 | |
Bart Van Assche | 8658dca | 2017-04-26 13:47:55 -0700 | [diff] [blame] | 285 | seq_printf(m, "%p {.op=", rq); |
| 286 | if (op < ARRAY_SIZE(op_name) && op_name[op]) |
| 287 | seq_printf(m, "%s", op_name[op]); |
| 288 | else |
| 289 | seq_printf(m, "%d", op); |
| 290 | seq_puts(m, ", .cmd_flags="); |
| 291 | blk_flags_show(m, rq->cmd_flags & ~REQ_OP_MASK, cmd_flag_name, |
| 292 | ARRAY_SIZE(cmd_flag_name)); |
| 293 | seq_puts(m, ", .rq_flags="); |
| 294 | blk_flags_show(m, (__force unsigned int)rq->rq_flags, rqf_name, |
| 295 | ARRAY_SIZE(rqf_name)); |
Bart Van Assche | 2836ee4 | 2017-04-26 13:47:56 -0700 | [diff] [blame] | 296 | seq_printf(m, ", .tag=%d, .internal_tag=%d", rq->tag, |
Bart Van Assche | 8658dca | 2017-04-26 13:47:55 -0700 | [diff] [blame] | 297 | rq->internal_tag); |
Bart Van Assche | 2836ee4 | 2017-04-26 13:47:56 -0700 | [diff] [blame] | 298 | if (mq_ops->show_rq) |
| 299 | mq_ops->show_rq(m, rq); |
| 300 | seq_puts(m, "}\n"); |
Omar Sandoval | 950cd7e | 2017-01-25 08:06:42 -0800 | [diff] [blame] | 301 | return 0; |
| 302 | } |
| 303 | |
| 304 | static void *hctx_dispatch_start(struct seq_file *m, loff_t *pos) |
Bart Van Assche | f3bcb0e | 2017-02-01 10:20:56 -0800 | [diff] [blame] | 305 | __acquires(&hctx->lock) |
Omar Sandoval | 950cd7e | 2017-01-25 08:06:42 -0800 | [diff] [blame] | 306 | { |
| 307 | struct blk_mq_hw_ctx *hctx = m->private; |
| 308 | |
| 309 | spin_lock(&hctx->lock); |
| 310 | return seq_list_start(&hctx->dispatch, *pos); |
| 311 | } |
| 312 | |
| 313 | static void *hctx_dispatch_next(struct seq_file *m, void *v, loff_t *pos) |
| 314 | { |
| 315 | struct blk_mq_hw_ctx *hctx = m->private; |
| 316 | |
| 317 | return seq_list_next(v, &hctx->dispatch, pos); |
| 318 | } |
| 319 | |
| 320 | static void hctx_dispatch_stop(struct seq_file *m, void *v) |
Bart Van Assche | f3bcb0e | 2017-02-01 10:20:56 -0800 | [diff] [blame] | 321 | __releases(&hctx->lock) |
Omar Sandoval | 950cd7e | 2017-01-25 08:06:42 -0800 | [diff] [blame] | 322 | { |
| 323 | struct blk_mq_hw_ctx *hctx = m->private; |
| 324 | |
| 325 | spin_unlock(&hctx->lock); |
| 326 | } |
| 327 | |
| 328 | static const struct seq_operations hctx_dispatch_seq_ops = { |
| 329 | .start = hctx_dispatch_start, |
| 330 | .next = hctx_dispatch_next, |
| 331 | .stop = hctx_dispatch_stop, |
| 332 | .show = blk_mq_debugfs_rq_show, |
| 333 | }; |
| 334 | |
Omar Sandoval | f57de23 | 2017-05-04 00:31:28 -0700 | [diff] [blame] | 335 | static int hctx_ctx_map_show(void *data, struct seq_file *m) |
Omar Sandoval | 950cd7e | 2017-01-25 08:06:42 -0800 | [diff] [blame] | 336 | { |
Omar Sandoval | f57de23 | 2017-05-04 00:31:28 -0700 | [diff] [blame] | 337 | struct blk_mq_hw_ctx *hctx = data; |
Omar Sandoval | 0bfa528 | 2017-01-25 08:06:45 -0800 | [diff] [blame] | 338 | |
| 339 | sbitmap_bitmap_show(&hctx->ctx_map, m); |
| 340 | return 0; |
| 341 | } |
| 342 | |
Omar Sandoval | d96b37c | 2017-01-25 08:06:46 -0800 | [diff] [blame] | 343 | static void blk_mq_debugfs_tags_show(struct seq_file *m, |
| 344 | struct blk_mq_tags *tags) |
| 345 | { |
| 346 | seq_printf(m, "nr_tags=%u\n", tags->nr_tags); |
| 347 | seq_printf(m, "nr_reserved_tags=%u\n", tags->nr_reserved_tags); |
| 348 | seq_printf(m, "active_queues=%d\n", |
| 349 | atomic_read(&tags->active_queues)); |
| 350 | |
| 351 | seq_puts(m, "\nbitmap_tags:\n"); |
| 352 | sbitmap_queue_show(&tags->bitmap_tags, m); |
| 353 | |
| 354 | if (tags->nr_reserved_tags) { |
| 355 | seq_puts(m, "\nbreserved_tags:\n"); |
| 356 | sbitmap_queue_show(&tags->breserved_tags, m); |
| 357 | } |
| 358 | } |
| 359 | |
Omar Sandoval | f57de23 | 2017-05-04 00:31:28 -0700 | [diff] [blame] | 360 | static int hctx_tags_show(void *data, struct seq_file *m) |
Omar Sandoval | d96b37c | 2017-01-25 08:06:46 -0800 | [diff] [blame] | 361 | { |
Omar Sandoval | f57de23 | 2017-05-04 00:31:28 -0700 | [diff] [blame] | 362 | struct blk_mq_hw_ctx *hctx = data; |
Omar Sandoval | d96b37c | 2017-01-25 08:06:46 -0800 | [diff] [blame] | 363 | struct request_queue *q = hctx->queue; |
Bart Van Assche | 8c0f14e | 2017-02-01 10:20:58 -0800 | [diff] [blame] | 364 | int res; |
Omar Sandoval | d96b37c | 2017-01-25 08:06:46 -0800 | [diff] [blame] | 365 | |
Bart Van Assche | 8c0f14e | 2017-02-01 10:20:58 -0800 | [diff] [blame] | 366 | res = mutex_lock_interruptible(&q->sysfs_lock); |
| 367 | if (res) |
| 368 | goto out; |
Omar Sandoval | d96b37c | 2017-01-25 08:06:46 -0800 | [diff] [blame] | 369 | if (hctx->tags) |
| 370 | blk_mq_debugfs_tags_show(m, hctx->tags); |
| 371 | mutex_unlock(&q->sysfs_lock); |
| 372 | |
Bart Van Assche | 8c0f14e | 2017-02-01 10:20:58 -0800 | [diff] [blame] | 373 | out: |
| 374 | return res; |
Omar Sandoval | d96b37c | 2017-01-25 08:06:46 -0800 | [diff] [blame] | 375 | } |
| 376 | |
Omar Sandoval | f57de23 | 2017-05-04 00:31:28 -0700 | [diff] [blame] | 377 | static int hctx_tags_bitmap_show(void *data, struct seq_file *m) |
Omar Sandoval | d96b37c | 2017-01-25 08:06:46 -0800 | [diff] [blame] | 378 | { |
Omar Sandoval | f57de23 | 2017-05-04 00:31:28 -0700 | [diff] [blame] | 379 | struct blk_mq_hw_ctx *hctx = data; |
Omar Sandoval | d7e3621 | 2017-01-25 08:06:47 -0800 | [diff] [blame] | 380 | struct request_queue *q = hctx->queue; |
Bart Van Assche | 8c0f14e | 2017-02-01 10:20:58 -0800 | [diff] [blame] | 381 | int res; |
Omar Sandoval | d7e3621 | 2017-01-25 08:06:47 -0800 | [diff] [blame] | 382 | |
Bart Van Assche | 8c0f14e | 2017-02-01 10:20:58 -0800 | [diff] [blame] | 383 | res = mutex_lock_interruptible(&q->sysfs_lock); |
| 384 | if (res) |
| 385 | goto out; |
Omar Sandoval | d7e3621 | 2017-01-25 08:06:47 -0800 | [diff] [blame] | 386 | if (hctx->tags) |
| 387 | sbitmap_bitmap_show(&hctx->tags->bitmap_tags.sb, m); |
| 388 | mutex_unlock(&q->sysfs_lock); |
Bart Van Assche | 8c0f14e | 2017-02-01 10:20:58 -0800 | [diff] [blame] | 389 | |
| 390 | out: |
| 391 | return res; |
Omar Sandoval | d7e3621 | 2017-01-25 08:06:47 -0800 | [diff] [blame] | 392 | } |
| 393 | |
Omar Sandoval | f57de23 | 2017-05-04 00:31:28 -0700 | [diff] [blame] | 394 | static int hctx_sched_tags_show(void *data, struct seq_file *m) |
Omar Sandoval | d7e3621 | 2017-01-25 08:06:47 -0800 | [diff] [blame] | 395 | { |
Omar Sandoval | f57de23 | 2017-05-04 00:31:28 -0700 | [diff] [blame] | 396 | struct blk_mq_hw_ctx *hctx = data; |
Omar Sandoval | d96b37c | 2017-01-25 08:06:46 -0800 | [diff] [blame] | 397 | struct request_queue *q = hctx->queue; |
Bart Van Assche | 8c0f14e | 2017-02-01 10:20:58 -0800 | [diff] [blame] | 398 | int res; |
Omar Sandoval | d96b37c | 2017-01-25 08:06:46 -0800 | [diff] [blame] | 399 | |
Bart Van Assche | 8c0f14e | 2017-02-01 10:20:58 -0800 | [diff] [blame] | 400 | res = mutex_lock_interruptible(&q->sysfs_lock); |
| 401 | if (res) |
| 402 | goto out; |
Omar Sandoval | d96b37c | 2017-01-25 08:06:46 -0800 | [diff] [blame] | 403 | if (hctx->sched_tags) |
| 404 | blk_mq_debugfs_tags_show(m, hctx->sched_tags); |
| 405 | mutex_unlock(&q->sysfs_lock); |
| 406 | |
Bart Van Assche | 8c0f14e | 2017-02-01 10:20:58 -0800 | [diff] [blame] | 407 | out: |
| 408 | return res; |
Omar Sandoval | d96b37c | 2017-01-25 08:06:46 -0800 | [diff] [blame] | 409 | } |
| 410 | |
Omar Sandoval | f57de23 | 2017-05-04 00:31:28 -0700 | [diff] [blame] | 411 | static int hctx_sched_tags_bitmap_show(void *data, struct seq_file *m) |
Omar Sandoval | d96b37c | 2017-01-25 08:06:46 -0800 | [diff] [blame] | 412 | { |
Omar Sandoval | f57de23 | 2017-05-04 00:31:28 -0700 | [diff] [blame] | 413 | struct blk_mq_hw_ctx *hctx = data; |
Omar Sandoval | d7e3621 | 2017-01-25 08:06:47 -0800 | [diff] [blame] | 414 | struct request_queue *q = hctx->queue; |
Bart Van Assche | 8c0f14e | 2017-02-01 10:20:58 -0800 | [diff] [blame] | 415 | int res; |
Omar Sandoval | d7e3621 | 2017-01-25 08:06:47 -0800 | [diff] [blame] | 416 | |
Bart Van Assche | 8c0f14e | 2017-02-01 10:20:58 -0800 | [diff] [blame] | 417 | res = mutex_lock_interruptible(&q->sysfs_lock); |
| 418 | if (res) |
| 419 | goto out; |
Omar Sandoval | d7e3621 | 2017-01-25 08:06:47 -0800 | [diff] [blame] | 420 | if (hctx->sched_tags) |
| 421 | sbitmap_bitmap_show(&hctx->sched_tags->bitmap_tags.sb, m); |
| 422 | mutex_unlock(&q->sysfs_lock); |
Bart Van Assche | 8c0f14e | 2017-02-01 10:20:58 -0800 | [diff] [blame] | 423 | |
| 424 | out: |
| 425 | return res; |
Omar Sandoval | d7e3621 | 2017-01-25 08:06:47 -0800 | [diff] [blame] | 426 | } |
| 427 | |
Omar Sandoval | f57de23 | 2017-05-04 00:31:28 -0700 | [diff] [blame] | 428 | static int hctx_io_poll_show(void *data, struct seq_file *m) |
Omar Sandoval | d7e3621 | 2017-01-25 08:06:47 -0800 | [diff] [blame] | 429 | { |
Omar Sandoval | f57de23 | 2017-05-04 00:31:28 -0700 | [diff] [blame] | 430 | struct blk_mq_hw_ctx *hctx = data; |
Omar Sandoval | be21547 | 2017-01-25 08:06:48 -0800 | [diff] [blame] | 431 | |
| 432 | seq_printf(m, "considered=%lu\n", hctx->poll_considered); |
| 433 | seq_printf(m, "invoked=%lu\n", hctx->poll_invoked); |
| 434 | seq_printf(m, "success=%lu\n", hctx->poll_success); |
| 435 | return 0; |
| 436 | } |
| 437 | |
Omar Sandoval | f57de23 | 2017-05-04 00:31:28 -0700 | [diff] [blame] | 438 | static ssize_t hctx_io_poll_write(void *data, const char __user *buf, |
Omar Sandoval | be21547 | 2017-01-25 08:06:48 -0800 | [diff] [blame] | 439 | size_t count, loff_t *ppos) |
| 440 | { |
Omar Sandoval | f57de23 | 2017-05-04 00:31:28 -0700 | [diff] [blame] | 441 | struct blk_mq_hw_ctx *hctx = data; |
Omar Sandoval | be21547 | 2017-01-25 08:06:48 -0800 | [diff] [blame] | 442 | |
| 443 | hctx->poll_considered = hctx->poll_invoked = hctx->poll_success = 0; |
| 444 | return count; |
| 445 | } |
| 446 | |
Omar Sandoval | f57de23 | 2017-05-04 00:31:28 -0700 | [diff] [blame] | 447 | static int hctx_dispatched_show(void *data, struct seq_file *m) |
Omar Sandoval | be21547 | 2017-01-25 08:06:48 -0800 | [diff] [blame] | 448 | { |
Omar Sandoval | f57de23 | 2017-05-04 00:31:28 -0700 | [diff] [blame] | 449 | struct blk_mq_hw_ctx *hctx = data; |
Omar Sandoval | be21547 | 2017-01-25 08:06:48 -0800 | [diff] [blame] | 450 | int i; |
| 451 | |
| 452 | seq_printf(m, "%8u\t%lu\n", 0U, hctx->dispatched[0]); |
| 453 | |
| 454 | for (i = 1; i < BLK_MQ_MAX_DISPATCH_ORDER - 1; i++) { |
| 455 | unsigned int d = 1U << (i - 1); |
| 456 | |
| 457 | seq_printf(m, "%8u\t%lu\n", d, hctx->dispatched[i]); |
| 458 | } |
| 459 | |
| 460 | seq_printf(m, "%8u+\t%lu\n", 1U << (i - 1), hctx->dispatched[i]); |
| 461 | return 0; |
| 462 | } |
| 463 | |
Omar Sandoval | f57de23 | 2017-05-04 00:31:28 -0700 | [diff] [blame] | 464 | static ssize_t hctx_dispatched_write(void *data, const char __user *buf, |
Omar Sandoval | be21547 | 2017-01-25 08:06:48 -0800 | [diff] [blame] | 465 | size_t count, loff_t *ppos) |
| 466 | { |
Omar Sandoval | f57de23 | 2017-05-04 00:31:28 -0700 | [diff] [blame] | 467 | struct blk_mq_hw_ctx *hctx = data; |
Omar Sandoval | be21547 | 2017-01-25 08:06:48 -0800 | [diff] [blame] | 468 | int i; |
| 469 | |
| 470 | for (i = 0; i < BLK_MQ_MAX_DISPATCH_ORDER; i++) |
| 471 | hctx->dispatched[i] = 0; |
| 472 | return count; |
| 473 | } |
| 474 | |
Omar Sandoval | f57de23 | 2017-05-04 00:31:28 -0700 | [diff] [blame] | 475 | static int hctx_queued_show(void *data, struct seq_file *m) |
Omar Sandoval | 4a46f05 | 2017-01-25 08:06:49 -0800 | [diff] [blame] | 476 | { |
Omar Sandoval | f57de23 | 2017-05-04 00:31:28 -0700 | [diff] [blame] | 477 | struct blk_mq_hw_ctx *hctx = data; |
Omar Sandoval | 4a46f05 | 2017-01-25 08:06:49 -0800 | [diff] [blame] | 478 | |
| 479 | seq_printf(m, "%lu\n", hctx->queued); |
| 480 | return 0; |
| 481 | } |
| 482 | |
Omar Sandoval | f57de23 | 2017-05-04 00:31:28 -0700 | [diff] [blame] | 483 | static ssize_t hctx_queued_write(void *data, const char __user *buf, |
Omar Sandoval | 4a46f05 | 2017-01-25 08:06:49 -0800 | [diff] [blame] | 484 | size_t count, loff_t *ppos) |
| 485 | { |
Omar Sandoval | f57de23 | 2017-05-04 00:31:28 -0700 | [diff] [blame] | 486 | struct blk_mq_hw_ctx *hctx = data; |
Omar Sandoval | 4a46f05 | 2017-01-25 08:06:49 -0800 | [diff] [blame] | 487 | |
| 488 | hctx->queued = 0; |
| 489 | return count; |
| 490 | } |
| 491 | |
Omar Sandoval | f57de23 | 2017-05-04 00:31:28 -0700 | [diff] [blame] | 492 | static int hctx_run_show(void *data, struct seq_file *m) |
Omar Sandoval | 4a46f05 | 2017-01-25 08:06:49 -0800 | [diff] [blame] | 493 | { |
Omar Sandoval | f57de23 | 2017-05-04 00:31:28 -0700 | [diff] [blame] | 494 | struct blk_mq_hw_ctx *hctx = data; |
Omar Sandoval | 4a46f05 | 2017-01-25 08:06:49 -0800 | [diff] [blame] | 495 | |
| 496 | seq_printf(m, "%lu\n", hctx->run); |
| 497 | return 0; |
| 498 | } |
| 499 | |
Omar Sandoval | f57de23 | 2017-05-04 00:31:28 -0700 | [diff] [blame] | 500 | static ssize_t hctx_run_write(void *data, const char __user *buf, size_t count, |
| 501 | loff_t *ppos) |
Omar Sandoval | 4a46f05 | 2017-01-25 08:06:49 -0800 | [diff] [blame] | 502 | { |
Omar Sandoval | f57de23 | 2017-05-04 00:31:28 -0700 | [diff] [blame] | 503 | struct blk_mq_hw_ctx *hctx = data; |
Omar Sandoval | 4a46f05 | 2017-01-25 08:06:49 -0800 | [diff] [blame] | 504 | |
| 505 | hctx->run = 0; |
| 506 | return count; |
| 507 | } |
| 508 | |
Omar Sandoval | f57de23 | 2017-05-04 00:31:28 -0700 | [diff] [blame] | 509 | static int hctx_active_show(void *data, struct seq_file *m) |
Omar Sandoval | 4a46f05 | 2017-01-25 08:06:49 -0800 | [diff] [blame] | 510 | { |
Omar Sandoval | f57de23 | 2017-05-04 00:31:28 -0700 | [diff] [blame] | 511 | struct blk_mq_hw_ctx *hctx = data; |
Omar Sandoval | 4a46f05 | 2017-01-25 08:06:49 -0800 | [diff] [blame] | 512 | |
| 513 | seq_printf(m, "%d\n", atomic_read(&hctx->nr_active)); |
| 514 | return 0; |
| 515 | } |
| 516 | |
Omar Sandoval | 950cd7e | 2017-01-25 08:06:42 -0800 | [diff] [blame] | 517 | static void *ctx_rq_list_start(struct seq_file *m, loff_t *pos) |
Bart Van Assche | f3bcb0e | 2017-02-01 10:20:56 -0800 | [diff] [blame] | 518 | __acquires(&ctx->lock) |
Omar Sandoval | 950cd7e | 2017-01-25 08:06:42 -0800 | [diff] [blame] | 519 | { |
| 520 | struct blk_mq_ctx *ctx = m->private; |
| 521 | |
| 522 | spin_lock(&ctx->lock); |
| 523 | return seq_list_start(&ctx->rq_list, *pos); |
| 524 | } |
| 525 | |
| 526 | static void *ctx_rq_list_next(struct seq_file *m, void *v, loff_t *pos) |
| 527 | { |
| 528 | struct blk_mq_ctx *ctx = m->private; |
| 529 | |
| 530 | return seq_list_next(v, &ctx->rq_list, pos); |
| 531 | } |
| 532 | |
| 533 | static void ctx_rq_list_stop(struct seq_file *m, void *v) |
Bart Van Assche | f3bcb0e | 2017-02-01 10:20:56 -0800 | [diff] [blame] | 534 | __releases(&ctx->lock) |
Omar Sandoval | 950cd7e | 2017-01-25 08:06:42 -0800 | [diff] [blame] | 535 | { |
| 536 | struct blk_mq_ctx *ctx = m->private; |
| 537 | |
| 538 | spin_unlock(&ctx->lock); |
| 539 | } |
| 540 | |
| 541 | static const struct seq_operations ctx_rq_list_seq_ops = { |
| 542 | .start = ctx_rq_list_start, |
| 543 | .next = ctx_rq_list_next, |
| 544 | .stop = ctx_rq_list_stop, |
| 545 | .show = blk_mq_debugfs_rq_show, |
| 546 | }; |
Omar Sandoval | f57de23 | 2017-05-04 00:31:28 -0700 | [diff] [blame] | 547 | static int ctx_dispatched_show(void *data, struct seq_file *m) |
Omar Sandoval | 950cd7e | 2017-01-25 08:06:42 -0800 | [diff] [blame] | 548 | { |
Omar Sandoval | f57de23 | 2017-05-04 00:31:28 -0700 | [diff] [blame] | 549 | struct blk_mq_ctx *ctx = data; |
Omar Sandoval | 4a46f05 | 2017-01-25 08:06:49 -0800 | [diff] [blame] | 550 | |
| 551 | seq_printf(m, "%lu %lu\n", ctx->rq_dispatched[1], ctx->rq_dispatched[0]); |
| 552 | return 0; |
| 553 | } |
| 554 | |
Omar Sandoval | f57de23 | 2017-05-04 00:31:28 -0700 | [diff] [blame] | 555 | static ssize_t ctx_dispatched_write(void *data, const char __user *buf, |
Omar Sandoval | 4a46f05 | 2017-01-25 08:06:49 -0800 | [diff] [blame] | 556 | size_t count, loff_t *ppos) |
| 557 | { |
Omar Sandoval | f57de23 | 2017-05-04 00:31:28 -0700 | [diff] [blame] | 558 | struct blk_mq_ctx *ctx = data; |
Omar Sandoval | 4a46f05 | 2017-01-25 08:06:49 -0800 | [diff] [blame] | 559 | |
| 560 | ctx->rq_dispatched[0] = ctx->rq_dispatched[1] = 0; |
| 561 | return count; |
| 562 | } |
| 563 | |
Omar Sandoval | f57de23 | 2017-05-04 00:31:28 -0700 | [diff] [blame] | 564 | static int ctx_merged_show(void *data, struct seq_file *m) |
Omar Sandoval | 4a46f05 | 2017-01-25 08:06:49 -0800 | [diff] [blame] | 565 | { |
Omar Sandoval | f57de23 | 2017-05-04 00:31:28 -0700 | [diff] [blame] | 566 | struct blk_mq_ctx *ctx = data; |
Omar Sandoval | 4a46f05 | 2017-01-25 08:06:49 -0800 | [diff] [blame] | 567 | |
| 568 | seq_printf(m, "%lu\n", ctx->rq_merged); |
| 569 | return 0; |
| 570 | } |
| 571 | |
Omar Sandoval | f57de23 | 2017-05-04 00:31:28 -0700 | [diff] [blame] | 572 | static ssize_t ctx_merged_write(void *data, const char __user *buf, |
| 573 | size_t count, loff_t *ppos) |
Omar Sandoval | 4a46f05 | 2017-01-25 08:06:49 -0800 | [diff] [blame] | 574 | { |
Omar Sandoval | f57de23 | 2017-05-04 00:31:28 -0700 | [diff] [blame] | 575 | struct blk_mq_ctx *ctx = data; |
Omar Sandoval | 4a46f05 | 2017-01-25 08:06:49 -0800 | [diff] [blame] | 576 | |
| 577 | ctx->rq_merged = 0; |
| 578 | return count; |
| 579 | } |
| 580 | |
Omar Sandoval | f57de23 | 2017-05-04 00:31:28 -0700 | [diff] [blame] | 581 | static int ctx_completed_show(void *data, struct seq_file *m) |
Omar Sandoval | 4a46f05 | 2017-01-25 08:06:49 -0800 | [diff] [blame] | 582 | { |
Omar Sandoval | f57de23 | 2017-05-04 00:31:28 -0700 | [diff] [blame] | 583 | struct blk_mq_ctx *ctx = data; |
Omar Sandoval | 4a46f05 | 2017-01-25 08:06:49 -0800 | [diff] [blame] | 584 | |
| 585 | seq_printf(m, "%lu %lu\n", ctx->rq_completed[1], ctx->rq_completed[0]); |
| 586 | return 0; |
| 587 | } |
| 588 | |
Omar Sandoval | f57de23 | 2017-05-04 00:31:28 -0700 | [diff] [blame] | 589 | static ssize_t ctx_completed_write(void *data, const char __user *buf, |
Omar Sandoval | 4a46f05 | 2017-01-25 08:06:49 -0800 | [diff] [blame] | 590 | size_t count, loff_t *ppos) |
| 591 | { |
Omar Sandoval | f57de23 | 2017-05-04 00:31:28 -0700 | [diff] [blame] | 592 | struct blk_mq_ctx *ctx = data; |
Omar Sandoval | 4a46f05 | 2017-01-25 08:06:49 -0800 | [diff] [blame] | 593 | |
| 594 | ctx->rq_completed[0] = ctx->rq_completed[1] = 0; |
| 595 | return count; |
| 596 | } |
| 597 | |
Omar Sandoval | f57de23 | 2017-05-04 00:31:28 -0700 | [diff] [blame] | 598 | static int blk_mq_debugfs_show(struct seq_file *m, void *v) |
| 599 | { |
| 600 | const struct blk_mq_debugfs_attr *attr = m->private; |
| 601 | void *data = d_inode(m->file->f_path.dentry->d_parent)->i_private; |
| 602 | |
| 603 | return attr->show(data, m); |
| 604 | } |
| 605 | |
| 606 | static ssize_t blk_mq_debugfs_write(struct file *file, const char __user *buf, |
| 607 | size_t count, loff_t *ppos) |
| 608 | { |
| 609 | struct seq_file *m = file->private_data; |
| 610 | const struct blk_mq_debugfs_attr *attr = m->private; |
| 611 | void *data = d_inode(file->f_path.dentry->d_parent)->i_private; |
| 612 | |
| 613 | if (!attr->write) |
| 614 | return -EPERM; |
| 615 | |
| 616 | return attr->write(data, buf, count, ppos); |
| 617 | } |
| 618 | |
| 619 | static int blk_mq_debugfs_open(struct inode *inode, struct file *file) |
| 620 | { |
| 621 | const struct blk_mq_debugfs_attr *attr = inode->i_private; |
| 622 | void *data = d_inode(file->f_path.dentry->d_parent)->i_private; |
| 623 | struct seq_file *m; |
| 624 | int ret; |
| 625 | |
| 626 | if (attr->seq_ops) { |
| 627 | ret = seq_open(file, attr->seq_ops); |
| 628 | if (!ret) { |
| 629 | m = file->private_data; |
| 630 | m->private = data; |
| 631 | } |
| 632 | return ret; |
| 633 | } |
| 634 | |
| 635 | if (WARN_ON_ONCE(!attr->show)) |
| 636 | return -EPERM; |
| 637 | |
| 638 | return single_open(file, blk_mq_debugfs_show, inode->i_private); |
| 639 | } |
| 640 | |
| 641 | static int blk_mq_debugfs_release(struct inode *inode, struct file *file) |
| 642 | { |
| 643 | const struct blk_mq_debugfs_attr *attr = inode->i_private; |
| 644 | |
| 645 | if (attr->show) |
| 646 | return single_release(inode, file); |
| 647 | else |
| 648 | return seq_release(inode, file); |
| 649 | } |
| 650 | |
| 651 | const struct file_operations blk_mq_debugfs_fops = { |
| 652 | .open = blk_mq_debugfs_open, |
Omar Sandoval | 4a46f05 | 2017-01-25 08:06:49 -0800 | [diff] [blame] | 653 | .read = seq_read, |
Omar Sandoval | f57de23 | 2017-05-04 00:31:28 -0700 | [diff] [blame] | 654 | .write = blk_mq_debugfs_write, |
Omar Sandoval | 4a46f05 | 2017-01-25 08:06:49 -0800 | [diff] [blame] | 655 | .llseek = seq_lseek, |
Omar Sandoval | f57de23 | 2017-05-04 00:31:28 -0700 | [diff] [blame] | 656 | .release = blk_mq_debugfs_release, |
Omar Sandoval | 4a46f05 | 2017-01-25 08:06:49 -0800 | [diff] [blame] | 657 | }; |
| 658 | |
Omar Sandoval | 34dbad5 | 2017-03-21 08:56:08 -0700 | [diff] [blame] | 659 | static const struct blk_mq_debugfs_attr blk_mq_debugfs_queue_attrs[] = { |
Omar Sandoval | f57de23 | 2017-05-04 00:31:28 -0700 | [diff] [blame] | 660 | {"poll_stat", 0400, queue_poll_stat_show}, |
| 661 | {"state", 0600, queue_state_show, queue_state_write}, |
Omar Sandoval | 34dbad5 | 2017-03-21 08:56:08 -0700 | [diff] [blame] | 662 | {}, |
| 663 | }; |
| 664 | |
Omar Sandoval | 07e4fea | 2017-01-25 08:06:40 -0800 | [diff] [blame] | 665 | static const struct blk_mq_debugfs_attr blk_mq_debugfs_hctx_attrs[] = { |
Omar Sandoval | f57de23 | 2017-05-04 00:31:28 -0700 | [diff] [blame] | 666 | {"state", 0400, hctx_state_show}, |
| 667 | {"flags", 0400, hctx_flags_show}, |
| 668 | {"dispatch", 0400, .seq_ops = &hctx_dispatch_seq_ops}, |
| 669 | {"ctx_map", 0400, hctx_ctx_map_show}, |
| 670 | {"tags", 0400, hctx_tags_show}, |
| 671 | {"tags_bitmap", 0400, hctx_tags_bitmap_show}, |
| 672 | {"sched_tags", 0400, hctx_sched_tags_show}, |
| 673 | {"sched_tags_bitmap", 0400, hctx_sched_tags_bitmap_show}, |
| 674 | {"io_poll", 0600, hctx_io_poll_show, hctx_io_poll_write}, |
| 675 | {"dispatched", 0600, hctx_dispatched_show, hctx_dispatched_write}, |
| 676 | {"queued", 0600, hctx_queued_show, hctx_queued_write}, |
| 677 | {"run", 0600, hctx_run_show, hctx_run_write}, |
| 678 | {"active", 0400, hctx_active_show}, |
Bart Van Assche | 72f2f8f | 2017-02-01 10:20:59 -0800 | [diff] [blame] | 679 | {}, |
Omar Sandoval | 07e4fea | 2017-01-25 08:06:40 -0800 | [diff] [blame] | 680 | }; |
| 681 | |
| 682 | static const struct blk_mq_debugfs_attr blk_mq_debugfs_ctx_attrs[] = { |
Omar Sandoval | f57de23 | 2017-05-04 00:31:28 -0700 | [diff] [blame] | 683 | {"rq_list", 0400, .seq_ops = &ctx_rq_list_seq_ops}, |
| 684 | {"dispatched", 0600, ctx_dispatched_show, ctx_dispatched_write}, |
| 685 | {"merged", 0600, ctx_merged_show, ctx_merged_write}, |
| 686 | {"completed", 0600, ctx_completed_show, ctx_completed_write}, |
Bart Van Assche | 72f2f8f | 2017-02-01 10:20:59 -0800 | [diff] [blame] | 687 | {}, |
Omar Sandoval | 07e4fea | 2017-01-25 08:06:40 -0800 | [diff] [blame] | 688 | }; |
| 689 | |
Bart Van Assche | 4c9e401 | 2017-04-26 13:47:49 -0700 | [diff] [blame] | 690 | int blk_mq_debugfs_register(struct request_queue *q) |
Omar Sandoval | 07e4fea | 2017-01-25 08:06:40 -0800 | [diff] [blame] | 691 | { |
Omar Sandoval | 18fbda9 | 2017-01-31 14:53:20 -0800 | [diff] [blame] | 692 | if (!blk_debugfs_root) |
Omar Sandoval | 07e4fea | 2017-01-25 08:06:40 -0800 | [diff] [blame] | 693 | return -ENOENT; |
| 694 | |
Bart Van Assche | 4c9e401 | 2017-04-26 13:47:49 -0700 | [diff] [blame] | 695 | q->debugfs_dir = debugfs_create_dir(kobject_name(q->kobj.parent), |
| 696 | blk_debugfs_root); |
Omar Sandoval | 07e4fea | 2017-01-25 08:06:40 -0800 | [diff] [blame] | 697 | if (!q->debugfs_dir) |
| 698 | goto err; |
| 699 | |
Bart Van Assche | 62d6c94 | 2017-04-26 13:47:50 -0700 | [diff] [blame] | 700 | if (blk_mq_debugfs_register_mq(q)) |
Omar Sandoval | 07e4fea | 2017-01-25 08:06:40 -0800 | [diff] [blame] | 701 | goto err; |
| 702 | |
| 703 | return 0; |
| 704 | |
| 705 | err: |
| 706 | blk_mq_debugfs_unregister(q); |
| 707 | return -ENOMEM; |
| 708 | } |
| 709 | |
| 710 | void blk_mq_debugfs_unregister(struct request_queue *q) |
| 711 | { |
| 712 | debugfs_remove_recursive(q->debugfs_dir); |
| 713 | q->mq_debugfs_dir = NULL; |
| 714 | q->debugfs_dir = NULL; |
| 715 | } |
| 716 | |
Bart Van Assche | 72f2f8f | 2017-02-01 10:20:59 -0800 | [diff] [blame] | 717 | static bool debugfs_create_files(struct dentry *parent, void *data, |
Omar Sandoval | f57de23 | 2017-05-04 00:31:28 -0700 | [diff] [blame] | 718 | const struct blk_mq_debugfs_attr *attr) |
Bart Van Assche | 72f2f8f | 2017-02-01 10:20:59 -0800 | [diff] [blame] | 719 | { |
Omar Sandoval | f57de23 | 2017-05-04 00:31:28 -0700 | [diff] [blame] | 720 | d_inode(parent)->i_private = data; |
| 721 | |
Bart Van Assche | 72f2f8f | 2017-02-01 10:20:59 -0800 | [diff] [blame] | 722 | for (; attr->name; attr++) { |
| 723 | if (!debugfs_create_file(attr->name, attr->mode, parent, |
Omar Sandoval | f57de23 | 2017-05-04 00:31:28 -0700 | [diff] [blame] | 724 | (void *)attr, &blk_mq_debugfs_fops)) |
Bart Van Assche | 72f2f8f | 2017-02-01 10:20:59 -0800 | [diff] [blame] | 725 | return false; |
| 726 | } |
| 727 | return true; |
| 728 | } |
| 729 | |
Omar Sandoval | 07e4fea | 2017-01-25 08:06:40 -0800 | [diff] [blame] | 730 | static int blk_mq_debugfs_register_ctx(struct request_queue *q, |
| 731 | struct blk_mq_ctx *ctx, |
| 732 | struct dentry *hctx_dir) |
| 733 | { |
| 734 | struct dentry *ctx_dir; |
| 735 | char name[20]; |
Omar Sandoval | 07e4fea | 2017-01-25 08:06:40 -0800 | [diff] [blame] | 736 | |
| 737 | snprintf(name, sizeof(name), "cpu%u", ctx->cpu); |
| 738 | ctx_dir = debugfs_create_dir(name, hctx_dir); |
| 739 | if (!ctx_dir) |
| 740 | return -ENOMEM; |
| 741 | |
Bart Van Assche | 72f2f8f | 2017-02-01 10:20:59 -0800 | [diff] [blame] | 742 | if (!debugfs_create_files(ctx_dir, ctx, blk_mq_debugfs_ctx_attrs)) |
| 743 | return -ENOMEM; |
Omar Sandoval | 07e4fea | 2017-01-25 08:06:40 -0800 | [diff] [blame] | 744 | |
| 745 | return 0; |
| 746 | } |
| 747 | |
| 748 | static int blk_mq_debugfs_register_hctx(struct request_queue *q, |
| 749 | struct blk_mq_hw_ctx *hctx) |
| 750 | { |
| 751 | struct blk_mq_ctx *ctx; |
| 752 | struct dentry *hctx_dir; |
| 753 | char name[20]; |
| 754 | int i; |
| 755 | |
Omar Sandoval | 88aabbd | 2017-05-04 00:31:27 -0700 | [diff] [blame] | 756 | snprintf(name, sizeof(name), "hctx%u", hctx->queue_num); |
Omar Sandoval | 07e4fea | 2017-01-25 08:06:40 -0800 | [diff] [blame] | 757 | hctx_dir = debugfs_create_dir(name, q->mq_debugfs_dir); |
| 758 | if (!hctx_dir) |
| 759 | return -ENOMEM; |
| 760 | |
Bart Van Assche | 72f2f8f | 2017-02-01 10:20:59 -0800 | [diff] [blame] | 761 | if (!debugfs_create_files(hctx_dir, hctx, blk_mq_debugfs_hctx_attrs)) |
| 762 | return -ENOMEM; |
Omar Sandoval | 07e4fea | 2017-01-25 08:06:40 -0800 | [diff] [blame] | 763 | |
| 764 | hctx_for_each_ctx(hctx, ctx, i) { |
| 765 | if (blk_mq_debugfs_register_ctx(q, ctx, hctx_dir)) |
| 766 | return -ENOMEM; |
| 767 | } |
| 768 | |
| 769 | return 0; |
| 770 | } |
| 771 | |
Bart Van Assche | 62d6c94 | 2017-04-26 13:47:50 -0700 | [diff] [blame] | 772 | int blk_mq_debugfs_register_mq(struct request_queue *q) |
Omar Sandoval | 07e4fea | 2017-01-25 08:06:40 -0800 | [diff] [blame] | 773 | { |
| 774 | struct blk_mq_hw_ctx *hctx; |
| 775 | int i; |
| 776 | |
| 777 | if (!q->debugfs_dir) |
| 778 | return -ENOENT; |
| 779 | |
| 780 | q->mq_debugfs_dir = debugfs_create_dir("mq", q->debugfs_dir); |
| 781 | if (!q->mq_debugfs_dir) |
| 782 | goto err; |
| 783 | |
Omar Sandoval | 34dbad5 | 2017-03-21 08:56:08 -0700 | [diff] [blame] | 784 | if (!debugfs_create_files(q->mq_debugfs_dir, q, blk_mq_debugfs_queue_attrs)) |
| 785 | goto err; |
| 786 | |
Omar Sandoval | 07e4fea | 2017-01-25 08:06:40 -0800 | [diff] [blame] | 787 | queue_for_each_hw_ctx(q, hctx, i) { |
| 788 | if (blk_mq_debugfs_register_hctx(q, hctx)) |
| 789 | goto err; |
| 790 | } |
| 791 | |
| 792 | return 0; |
| 793 | |
| 794 | err: |
Bart Van Assche | 62d6c94 | 2017-04-26 13:47:50 -0700 | [diff] [blame] | 795 | blk_mq_debugfs_unregister_mq(q); |
Omar Sandoval | 07e4fea | 2017-01-25 08:06:40 -0800 | [diff] [blame] | 796 | return -ENOMEM; |
| 797 | } |
| 798 | |
Bart Van Assche | 62d6c94 | 2017-04-26 13:47:50 -0700 | [diff] [blame] | 799 | void blk_mq_debugfs_unregister_mq(struct request_queue *q) |
Omar Sandoval | 07e4fea | 2017-01-25 08:06:40 -0800 | [diff] [blame] | 800 | { |
| 801 | debugfs_remove_recursive(q->mq_debugfs_dir); |
| 802 | q->mq_debugfs_dir = NULL; |
| 803 | } |