blob: 0d0640d38a06244bb12dbc53b555bd59df981326 [file] [log] [blame]
Jens Axboe320ae512013-10-24 09:20:05 +01001#include <linux/kernel.h>
2#include <linux/module.h>
Jens Axboe4bb659b2014-05-09 09:36:49 -06003#include <linux/random.h>
Jens Axboe320ae512013-10-24 09:20:05 +01004
5#include <linux/blk-mq.h>
6#include "blk.h"
7#include "blk-mq.h"
8#include "blk-mq-tag.h"
9
Jens Axboe4bb659b2014-05-09 09:36:49 -060010static bool bt_has_free_tags(struct blk_mq_bitmap_tags *bt)
11{
12 int i;
13
14 for (i = 0; i < bt->map_nr; i++) {
Jens Axboee93ecf62014-05-19 09:17:48 -060015 struct blk_align_bitmap *bm = &bt->map[i];
Jens Axboe4bb659b2014-05-09 09:36:49 -060016 int ret;
17
18 ret = find_first_zero_bit(&bm->word, bm->depth);
19 if (ret < bm->depth)
20 return true;
21 }
22
23 return false;
Jens Axboe320ae512013-10-24 09:20:05 +010024}
25
26bool blk_mq_has_free_tags(struct blk_mq_tags *tags)
27{
Jens Axboe4bb659b2014-05-09 09:36:49 -060028 if (!tags)
29 return true;
30
31 return bt_has_free_tags(&tags->bitmap_tags);
Jens Axboe320ae512013-10-24 09:20:05 +010032}
33
Jens Axboe0d2602c2014-05-13 15:10:52 -060034static inline void bt_index_inc(unsigned int *index)
35{
36 *index = (*index + 1) & (BT_WAIT_QUEUES - 1);
37}
38
39/*
40 * If a previously inactive queue goes active, bump the active user count.
41 */
42bool __blk_mq_tag_busy(struct blk_mq_hw_ctx *hctx)
43{
44 if (!test_bit(BLK_MQ_S_TAG_ACTIVE, &hctx->state) &&
45 !test_and_set_bit(BLK_MQ_S_TAG_ACTIVE, &hctx->state))
46 atomic_inc(&hctx->tags->active_queues);
47
48 return true;
49}
50
51/*
Jens Axboee3a2b3f2014-05-20 11:49:02 -060052 * Wakeup all potentially sleeping on normal (non-reserved) tags
Jens Axboe0d2602c2014-05-13 15:10:52 -060053 */
Jens Axboee3a2b3f2014-05-20 11:49:02 -060054static void blk_mq_tag_wakeup_all(struct blk_mq_tags *tags)
Jens Axboe0d2602c2014-05-13 15:10:52 -060055{
Jens Axboe0d2602c2014-05-13 15:10:52 -060056 struct blk_mq_bitmap_tags *bt;
57 int i, wake_index;
58
Jens Axboe0d2602c2014-05-13 15:10:52 -060059 bt = &tags->bitmap_tags;
60 wake_index = bt->wake_index;
61 for (i = 0; i < BT_WAIT_QUEUES; i++) {
62 struct bt_wait_state *bs = &bt->bs[wake_index];
63
64 if (waitqueue_active(&bs->wait))
65 wake_up(&bs->wait);
66
67 bt_index_inc(&wake_index);
68 }
69}
70
71/*
Jens Axboee3a2b3f2014-05-20 11:49:02 -060072 * If a previously busy queue goes inactive, potential waiters could now
73 * be allowed to queue. Wake them up and check.
74 */
75void __blk_mq_tag_idle(struct blk_mq_hw_ctx *hctx)
76{
77 struct blk_mq_tags *tags = hctx->tags;
78
79 if (!test_and_clear_bit(BLK_MQ_S_TAG_ACTIVE, &hctx->state))
80 return;
81
82 atomic_dec(&tags->active_queues);
83
84 blk_mq_tag_wakeup_all(tags);
85}
86
87/*
Jens Axboe0d2602c2014-05-13 15:10:52 -060088 * For shared tag users, we track the number of currently active users
89 * and attempt to provide a fair share of the tag depth for each of them.
90 */
91static inline bool hctx_may_queue(struct blk_mq_hw_ctx *hctx,
92 struct blk_mq_bitmap_tags *bt)
93{
94 unsigned int depth, users;
95
96 if (!hctx || !(hctx->flags & BLK_MQ_F_TAG_SHARED))
97 return true;
98 if (!test_bit(BLK_MQ_S_TAG_ACTIVE, &hctx->state))
99 return true;
100
101 /*
102 * Don't try dividing an ant
103 */
104 if (bt->depth == 1)
105 return true;
106
107 users = atomic_read(&hctx->tags->active_queues);
108 if (!users)
109 return true;
110
111 /*
112 * Allow at least some tags
113 */
114 depth = max((bt->depth + users - 1) / users, 4U);
115 return atomic_read(&hctx->nr_active) < depth;
116}
117
Jens Axboee93ecf62014-05-19 09:17:48 -0600118static int __bt_get_word(struct blk_align_bitmap *bm, unsigned int last_tag)
Jens Axboe4bb659b2014-05-09 09:36:49 -0600119{
120 int tag, org_last_tag, end;
121
Jens Axboe59d13bf2014-05-09 13:41:15 -0600122 org_last_tag = last_tag;
Jens Axboe4bb659b2014-05-09 09:36:49 -0600123 end = bm->depth;
124 do {
125restart:
126 tag = find_next_zero_bit(&bm->word, end, last_tag);
127 if (unlikely(tag >= end)) {
128 /*
129 * We started with an offset, start from 0 to
130 * exhaust the map.
131 */
132 if (org_last_tag && last_tag) {
133 end = last_tag;
134 last_tag = 0;
135 goto restart;
136 }
137 return -1;
138 }
139 last_tag = tag + 1;
140 } while (test_and_set_bit_lock(tag, &bm->word));
141
142 return tag;
143}
144
145/*
146 * Straight forward bitmap tag implementation, where each bit is a tag
147 * (cleared == free, and set == busy). The small twist is using per-cpu
148 * last_tag caches, which blk-mq stores in the blk_mq_ctx software queue
149 * contexts. This enables us to drastically limit the space searched,
150 * without dirtying an extra shared cacheline like we would if we stored
151 * the cache value inside the shared blk_mq_bitmap_tags structure. On top
152 * of that, each word of tags is in a separate cacheline. This means that
153 * multiple users will tend to stick to different cachelines, at least
154 * until the map is exhausted.
155 */
Jens Axboe0d2602c2014-05-13 15:10:52 -0600156static int __bt_get(struct blk_mq_hw_ctx *hctx, struct blk_mq_bitmap_tags *bt,
157 unsigned int *tag_cache)
Jens Axboe4bb659b2014-05-09 09:36:49 -0600158{
159 unsigned int last_tag, org_last_tag;
160 int index, i, tag;
161
Jens Axboe0d2602c2014-05-13 15:10:52 -0600162 if (!hctx_may_queue(hctx, bt))
163 return -1;
164
Jens Axboe4bb659b2014-05-09 09:36:49 -0600165 last_tag = org_last_tag = *tag_cache;
Jens Axboe59d13bf2014-05-09 13:41:15 -0600166 index = TAG_TO_INDEX(bt, last_tag);
Jens Axboe4bb659b2014-05-09 09:36:49 -0600167
168 for (i = 0; i < bt->map_nr; i++) {
Jens Axboe59d13bf2014-05-09 13:41:15 -0600169 tag = __bt_get_word(&bt->map[index], TAG_TO_BIT(bt, last_tag));
Jens Axboe4bb659b2014-05-09 09:36:49 -0600170 if (tag != -1) {
Jens Axboe59d13bf2014-05-09 13:41:15 -0600171 tag += (index << bt->bits_per_word);
Jens Axboe4bb659b2014-05-09 09:36:49 -0600172 goto done;
173 }
174
175 last_tag = 0;
176 if (++index >= bt->map_nr)
177 index = 0;
178 }
179
180 *tag_cache = 0;
181 return -1;
182
183 /*
184 * Only update the cache from the allocation path, if we ended
185 * up using the specific cached tag.
186 */
187done:
188 if (tag == org_last_tag) {
189 last_tag = tag + 1;
190 if (last_tag >= bt->depth - 1)
191 last_tag = 0;
192
193 *tag_cache = last_tag;
194 }
195
196 return tag;
197}
198
Jens Axboe4bb659b2014-05-09 09:36:49 -0600199static struct bt_wait_state *bt_wait_ptr(struct blk_mq_bitmap_tags *bt,
200 struct blk_mq_hw_ctx *hctx)
201{
202 struct bt_wait_state *bs;
203
204 if (!hctx)
205 return &bt->bs[0];
206
207 bs = &bt->bs[hctx->wait_index];
208 bt_index_inc(&hctx->wait_index);
209 return bs;
210}
211
212static int bt_get(struct blk_mq_bitmap_tags *bt, struct blk_mq_hw_ctx *hctx,
213 unsigned int *last_tag, gfp_t gfp)
214{
215 struct bt_wait_state *bs;
216 DEFINE_WAIT(wait);
217 int tag;
218
Jens Axboe0d2602c2014-05-13 15:10:52 -0600219 tag = __bt_get(hctx, bt, last_tag);
Jens Axboe4bb659b2014-05-09 09:36:49 -0600220 if (tag != -1)
221 return tag;
222
223 if (!(gfp & __GFP_WAIT))
224 return -1;
225
226 bs = bt_wait_ptr(bt, hctx);
227 do {
228 bool was_empty;
229
230 was_empty = list_empty(&wait.task_list);
231 prepare_to_wait(&bs->wait, &wait, TASK_UNINTERRUPTIBLE);
232
Jens Axboe0d2602c2014-05-13 15:10:52 -0600233 tag = __bt_get(hctx, bt, last_tag);
Jens Axboe4bb659b2014-05-09 09:36:49 -0600234 if (tag != -1)
235 break;
236
237 if (was_empty)
238 atomic_set(&bs->wait_cnt, bt->wake_cnt);
239
240 io_schedule();
241 } while (1);
242
243 finish_wait(&bs->wait, &wait);
244 return tag;
245}
246
247static unsigned int __blk_mq_get_tag(struct blk_mq_tags *tags,
248 struct blk_mq_hw_ctx *hctx,
249 unsigned int *last_tag, gfp_t gfp)
Jens Axboe320ae512013-10-24 09:20:05 +0100250{
251 int tag;
252
Jens Axboe4bb659b2014-05-09 09:36:49 -0600253 tag = bt_get(&tags->bitmap_tags, hctx, last_tag, gfp);
254 if (tag >= 0)
255 return tag + tags->nr_reserved_tags;
256
257 return BLK_MQ_TAG_FAIL;
Jens Axboe320ae512013-10-24 09:20:05 +0100258}
259
260static unsigned int __blk_mq_get_reserved_tag(struct blk_mq_tags *tags,
261 gfp_t gfp)
262{
Jens Axboe4bb659b2014-05-09 09:36:49 -0600263 int tag, zero = 0;
Jens Axboe320ae512013-10-24 09:20:05 +0100264
265 if (unlikely(!tags->nr_reserved_tags)) {
266 WARN_ON_ONCE(1);
267 return BLK_MQ_TAG_FAIL;
268 }
269
Jens Axboe4bb659b2014-05-09 09:36:49 -0600270 tag = bt_get(&tags->breserved_tags, NULL, &zero, gfp);
Jens Axboe320ae512013-10-24 09:20:05 +0100271 if (tag < 0)
272 return BLK_MQ_TAG_FAIL;
Jens Axboe4bb659b2014-05-09 09:36:49 -0600273
Jens Axboe320ae512013-10-24 09:20:05 +0100274 return tag;
275}
276
Jens Axboe0d2602c2014-05-13 15:10:52 -0600277unsigned int blk_mq_get_tag(struct blk_mq_hw_ctx *hctx, unsigned int *last_tag,
Jens Axboe4bb659b2014-05-09 09:36:49 -0600278 gfp_t gfp, bool reserved)
Jens Axboe320ae512013-10-24 09:20:05 +0100279{
280 if (!reserved)
Jens Axboe0d2602c2014-05-13 15:10:52 -0600281 return __blk_mq_get_tag(hctx->tags, hctx, last_tag, gfp);
Jens Axboe320ae512013-10-24 09:20:05 +0100282
Jens Axboe0d2602c2014-05-13 15:10:52 -0600283 return __blk_mq_get_reserved_tag(hctx->tags, gfp);
Jens Axboe320ae512013-10-24 09:20:05 +0100284}
285
Jens Axboe4bb659b2014-05-09 09:36:49 -0600286static struct bt_wait_state *bt_wake_ptr(struct blk_mq_bitmap_tags *bt)
287{
288 int i, wake_index;
289
290 wake_index = bt->wake_index;
291 for (i = 0; i < BT_WAIT_QUEUES; i++) {
292 struct bt_wait_state *bs = &bt->bs[wake_index];
293
294 if (waitqueue_active(&bs->wait)) {
295 if (wake_index != bt->wake_index)
296 bt->wake_index = wake_index;
297
298 return bs;
299 }
300
301 bt_index_inc(&wake_index);
302 }
303
304 return NULL;
305}
306
307static void bt_clear_tag(struct blk_mq_bitmap_tags *bt, unsigned int tag)
308{
Jens Axboe59d13bf2014-05-09 13:41:15 -0600309 const int index = TAG_TO_INDEX(bt, tag);
Jens Axboe4bb659b2014-05-09 09:36:49 -0600310 struct bt_wait_state *bs;
311
Ming Lei0289b2e2014-05-11 01:01:48 +0800312 /*
313 * The unlock memory barrier need to order access to req in free
314 * path and clearing tag bit
315 */
316 clear_bit_unlock(TAG_TO_BIT(bt, tag), &bt->map[index].word);
Jens Axboe4bb659b2014-05-09 09:36:49 -0600317
318 bs = bt_wake_ptr(bt);
319 if (bs && atomic_dec_and_test(&bs->wait_cnt)) {
Jens Axboe4bb659b2014-05-09 09:36:49 -0600320 atomic_set(&bs->wait_cnt, bt->wake_cnt);
321 bt_index_inc(&bt->wake_index);
322 wake_up(&bs->wait);
323 }
324}
325
Jens Axboe320ae512013-10-24 09:20:05 +0100326static void __blk_mq_put_tag(struct blk_mq_tags *tags, unsigned int tag)
327{
328 BUG_ON(tag >= tags->nr_tags);
329
Jens Axboe4bb659b2014-05-09 09:36:49 -0600330 bt_clear_tag(&tags->bitmap_tags, tag);
Jens Axboe320ae512013-10-24 09:20:05 +0100331}
332
333static void __blk_mq_put_reserved_tag(struct blk_mq_tags *tags,
334 unsigned int tag)
335{
336 BUG_ON(tag >= tags->nr_reserved_tags);
337
Jens Axboe4bb659b2014-05-09 09:36:49 -0600338 bt_clear_tag(&tags->breserved_tags, tag);
Jens Axboe320ae512013-10-24 09:20:05 +0100339}
340
Jens Axboe0d2602c2014-05-13 15:10:52 -0600341void blk_mq_put_tag(struct blk_mq_hw_ctx *hctx, unsigned int tag,
Jens Axboe4bb659b2014-05-09 09:36:49 -0600342 unsigned int *last_tag)
Jens Axboe320ae512013-10-24 09:20:05 +0100343{
Jens Axboe0d2602c2014-05-13 15:10:52 -0600344 struct blk_mq_tags *tags = hctx->tags;
345
Jens Axboe4bb659b2014-05-09 09:36:49 -0600346 if (tag >= tags->nr_reserved_tags) {
347 const int real_tag = tag - tags->nr_reserved_tags;
348
349 __blk_mq_put_tag(tags, real_tag);
350 *last_tag = real_tag;
351 } else
Jens Axboe320ae512013-10-24 09:20:05 +0100352 __blk_mq_put_reserved_tag(tags, tag);
353}
354
Jens Axboe4bb659b2014-05-09 09:36:49 -0600355static void bt_for_each_free(struct blk_mq_bitmap_tags *bt,
356 unsigned long *free_map, unsigned int off)
Jens Axboe320ae512013-10-24 09:20:05 +0100357{
Jens Axboe4bb659b2014-05-09 09:36:49 -0600358 int i;
359
360 for (i = 0; i < bt->map_nr; i++) {
Jens Axboee93ecf62014-05-19 09:17:48 -0600361 struct blk_align_bitmap *bm = &bt->map[i];
Jens Axboe4bb659b2014-05-09 09:36:49 -0600362 int bit = 0;
363
364 do {
365 bit = find_next_zero_bit(&bm->word, bm->depth, bit);
366 if (bit >= bm->depth)
367 break;
368
369 __set_bit(bit + off, free_map);
370 bit++;
371 } while (1);
372
Jens Axboe59d13bf2014-05-09 13:41:15 -0600373 off += (1 << bt->bits_per_word);
Jens Axboe4bb659b2014-05-09 09:36:49 -0600374 }
Jens Axboe320ae512013-10-24 09:20:05 +0100375}
376
377void blk_mq_tag_busy_iter(struct blk_mq_tags *tags,
378 void (*fn)(void *, unsigned long *), void *data)
379{
380 unsigned long *tag_map;
381 size_t map_size;
382
383 map_size = ALIGN(tags->nr_tags, BITS_PER_LONG) / BITS_PER_LONG;
384 tag_map = kzalloc(map_size * sizeof(unsigned long), GFP_ATOMIC);
385 if (!tag_map)
386 return;
387
Jens Axboe4bb659b2014-05-09 09:36:49 -0600388 bt_for_each_free(&tags->bitmap_tags, tag_map, tags->nr_reserved_tags);
Jens Axboe320ae512013-10-24 09:20:05 +0100389 if (tags->nr_reserved_tags)
Jens Axboe4bb659b2014-05-09 09:36:49 -0600390 bt_for_each_free(&tags->breserved_tags, tag_map, 0);
Jens Axboe320ae512013-10-24 09:20:05 +0100391
392 fn(data, tag_map);
393 kfree(tag_map);
394}
Sam Bradshawedf866b2014-05-23 13:30:16 -0600395EXPORT_SYMBOL(blk_mq_tag_busy_iter);
Jens Axboe320ae512013-10-24 09:20:05 +0100396
Jens Axboe4bb659b2014-05-09 09:36:49 -0600397static unsigned int bt_unused_tags(struct blk_mq_bitmap_tags *bt)
398{
399 unsigned int i, used;
400
401 for (i = 0, used = 0; i < bt->map_nr; i++) {
Jens Axboee93ecf62014-05-19 09:17:48 -0600402 struct blk_align_bitmap *bm = &bt->map[i];
Jens Axboe4bb659b2014-05-09 09:36:49 -0600403
404 used += bitmap_weight(&bm->word, bm->depth);
405 }
406
407 return bt->depth - used;
408}
409
Jens Axboee3a2b3f2014-05-20 11:49:02 -0600410static void bt_update_count(struct blk_mq_bitmap_tags *bt,
411 unsigned int depth)
412{
413 unsigned int tags_per_word = 1U << bt->bits_per_word;
414 unsigned int map_depth = depth;
415
416 if (depth) {
417 int i;
418
419 for (i = 0; i < bt->map_nr; i++) {
420 bt->map[i].depth = min(map_depth, tags_per_word);
421 map_depth -= bt->map[i].depth;
422 }
423 }
424
425 bt->wake_cnt = BT_WAIT_BATCH;
426 if (bt->wake_cnt > depth / 4)
427 bt->wake_cnt = max(1U, depth / 4);
428
429 bt->depth = depth;
430}
431
Jens Axboe4bb659b2014-05-09 09:36:49 -0600432static int bt_alloc(struct blk_mq_bitmap_tags *bt, unsigned int depth,
433 int node, bool reserved)
434{
435 int i;
436
Jens Axboe59d13bf2014-05-09 13:41:15 -0600437 bt->bits_per_word = ilog2(BITS_PER_LONG);
438
Jens Axboe4bb659b2014-05-09 09:36:49 -0600439 /*
440 * Depth can be zero for reserved tags, that's not a failure
441 * condition.
442 */
443 if (depth) {
Jens Axboee3a2b3f2014-05-20 11:49:02 -0600444 unsigned int nr, tags_per_word;
Jens Axboe4bb659b2014-05-09 09:36:49 -0600445
Jens Axboe59d13bf2014-05-09 13:41:15 -0600446 tags_per_word = (1 << bt->bits_per_word);
447
448 /*
449 * If the tag space is small, shrink the number of tags
450 * per word so we spread over a few cachelines, at least.
451 * If less than 4 tags, just forget about it, it's not
452 * going to work optimally anyway.
453 */
454 if (depth >= 4) {
455 while (tags_per_word * 4 > depth) {
456 bt->bits_per_word--;
457 tags_per_word = (1 << bt->bits_per_word);
458 }
459 }
460
461 nr = ALIGN(depth, tags_per_word) / tags_per_word;
Jens Axboee93ecf62014-05-19 09:17:48 -0600462 bt->map = kzalloc_node(nr * sizeof(struct blk_align_bitmap),
Jens Axboe4bb659b2014-05-09 09:36:49 -0600463 GFP_KERNEL, node);
464 if (!bt->map)
465 return -ENOMEM;
466
467 bt->map_nr = nr;
Jens Axboe4bb659b2014-05-09 09:36:49 -0600468 }
469
470 bt->bs = kzalloc(BT_WAIT_QUEUES * sizeof(*bt->bs), GFP_KERNEL);
471 if (!bt->bs) {
472 kfree(bt->map);
473 return -ENOMEM;
474 }
475
476 for (i = 0; i < BT_WAIT_QUEUES; i++)
477 init_waitqueue_head(&bt->bs[i].wait);
478
Jens Axboee3a2b3f2014-05-20 11:49:02 -0600479 bt_update_count(bt, depth);
Jens Axboe4bb659b2014-05-09 09:36:49 -0600480 return 0;
481}
482
483static void bt_free(struct blk_mq_bitmap_tags *bt)
484{
485 kfree(bt->map);
486 kfree(bt->bs);
487}
488
489static struct blk_mq_tags *blk_mq_init_bitmap_tags(struct blk_mq_tags *tags,
490 int node)
491{
492 unsigned int depth = tags->nr_tags - tags->nr_reserved_tags;
493
494 if (bt_alloc(&tags->bitmap_tags, depth, node, false))
495 goto enomem;
496 if (bt_alloc(&tags->breserved_tags, tags->nr_reserved_tags, node, true))
497 goto enomem;
498
499 return tags;
500enomem:
501 bt_free(&tags->bitmap_tags);
502 kfree(tags);
503 return NULL;
504}
505
Jens Axboe320ae512013-10-24 09:20:05 +0100506struct blk_mq_tags *blk_mq_init_tags(unsigned int total_tags,
507 unsigned int reserved_tags, int node)
508{
Jens Axboe320ae512013-10-24 09:20:05 +0100509 struct blk_mq_tags *tags;
Jens Axboe320ae512013-10-24 09:20:05 +0100510
511 if (total_tags > BLK_MQ_TAG_MAX) {
512 pr_err("blk-mq: tag depth too large\n");
513 return NULL;
514 }
515
516 tags = kzalloc_node(sizeof(*tags), GFP_KERNEL, node);
517 if (!tags)
518 return NULL;
519
Jens Axboe320ae512013-10-24 09:20:05 +0100520 tags->nr_tags = total_tags;
521 tags->nr_reserved_tags = reserved_tags;
Jens Axboe320ae512013-10-24 09:20:05 +0100522
Jens Axboe4bb659b2014-05-09 09:36:49 -0600523 return blk_mq_init_bitmap_tags(tags, node);
Jens Axboe320ae512013-10-24 09:20:05 +0100524}
525
526void blk_mq_free_tags(struct blk_mq_tags *tags)
527{
Jens Axboe4bb659b2014-05-09 09:36:49 -0600528 bt_free(&tags->bitmap_tags);
529 bt_free(&tags->breserved_tags);
Jens Axboe320ae512013-10-24 09:20:05 +0100530 kfree(tags);
531}
532
Jens Axboe4bb659b2014-05-09 09:36:49 -0600533void blk_mq_tag_init_last_tag(struct blk_mq_tags *tags, unsigned int *tag)
534{
535 unsigned int depth = tags->nr_tags - tags->nr_reserved_tags;
536
Ming Lei9d3d21a2014-05-10 15:43:14 -0600537 *tag = prandom_u32() % depth;
Jens Axboe4bb659b2014-05-09 09:36:49 -0600538}
539
Jens Axboee3a2b3f2014-05-20 11:49:02 -0600540int blk_mq_tag_update_depth(struct blk_mq_tags *tags, unsigned int tdepth)
541{
542 tdepth -= tags->nr_reserved_tags;
543 if (tdepth > tags->nr_tags)
544 return -EINVAL;
545
546 /*
547 * Don't need (or can't) update reserved tags here, they remain
548 * static and should never need resizing.
549 */
550 bt_update_count(&tags->bitmap_tags, tdepth);
551 blk_mq_tag_wakeup_all(tags);
552 return 0;
553}
554
Jens Axboe320ae512013-10-24 09:20:05 +0100555ssize_t blk_mq_tag_sysfs_show(struct blk_mq_tags *tags, char *page)
556{
557 char *orig_page = page;
Jens Axboe4bb659b2014-05-09 09:36:49 -0600558 unsigned int free, res;
Jens Axboe320ae512013-10-24 09:20:05 +0100559
560 if (!tags)
561 return 0;
562
Jens Axboe59d13bf2014-05-09 13:41:15 -0600563 page += sprintf(page, "nr_tags=%u, reserved_tags=%u, "
564 "bits_per_word=%u\n",
565 tags->nr_tags, tags->nr_reserved_tags,
566 tags->bitmap_tags.bits_per_word);
Jens Axboe320ae512013-10-24 09:20:05 +0100567
Jens Axboe4bb659b2014-05-09 09:36:49 -0600568 free = bt_unused_tags(&tags->bitmap_tags);
569 res = bt_unused_tags(&tags->breserved_tags);
Jens Axboe320ae512013-10-24 09:20:05 +0100570
Jens Axboe4bb659b2014-05-09 09:36:49 -0600571 page += sprintf(page, "nr_free=%u, nr_reserved=%u\n", free, res);
Jens Axboe0d2602c2014-05-13 15:10:52 -0600572 page += sprintf(page, "active_queues=%u\n", atomic_read(&tags->active_queues));
Jens Axboe320ae512013-10-24 09:20:05 +0100573
574 return page - orig_page;
575}