blk-mq-tag.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef INT_BLK_MQ_TAG_H
  3. #define INT_BLK_MQ_TAG_H
  4. #include "blk-mq.h"
  5. /*
  6. * Tag address space map.
  7. */
  8. struct blk_mq_tags {
  9. unsigned int nr_tags;
  10. unsigned int nr_reserved_tags;
  11. atomic_t active_queues;
  12. struct sbitmap_queue bitmap_tags;
  13. struct sbitmap_queue breserved_tags;
  14. struct request **rqs;
  15. struct request **static_rqs;
  16. struct list_head page_list;
  17. };
  18. extern struct blk_mq_tags *blk_mq_init_tags(unsigned int nr_tags, unsigned int reserved_tags, int node, int alloc_policy);
  19. extern void blk_mq_free_tags(struct blk_mq_tags *tags);
  20. extern unsigned int blk_mq_get_tag(struct blk_mq_alloc_data *data);
  21. extern void blk_mq_put_tag(struct blk_mq_hw_ctx *hctx, struct blk_mq_tags *tags,
  22. struct blk_mq_ctx *ctx, unsigned int tag);
  23. extern bool blk_mq_has_free_tags(struct blk_mq_tags *tags);
  24. extern int blk_mq_tag_update_depth(struct blk_mq_hw_ctx *hctx,
  25. struct blk_mq_tags **tags,
  26. unsigned int depth, bool can_grow);
  27. extern void blk_mq_tag_wakeup_all(struct blk_mq_tags *tags, bool);
  28. void blk_mq_queue_tag_busy_iter(struct request_queue *q, busy_iter_fn *fn,
  29. void *priv);
  30. static inline struct sbq_wait_state *bt_wait_ptr(struct sbitmap_queue *bt,
  31. struct blk_mq_hw_ctx *hctx)
  32. {
  33. if (!hctx)
  34. return &bt->ws[0];
  35. return sbq_wait_ptr(bt, &hctx->wait_index);
  36. }
  37. enum {
  38. BLK_MQ_TAG_CACHE_MIN = 1,
  39. BLK_MQ_TAG_CACHE_MAX = 64,
  40. };
  41. enum {
  42. BLK_MQ_TAG_FAIL = -1U,
  43. BLK_MQ_TAG_MIN = BLK_MQ_TAG_CACHE_MIN,
  44. BLK_MQ_TAG_MAX = BLK_MQ_TAG_FAIL - 1,
  45. };
  46. extern bool __blk_mq_tag_busy(struct blk_mq_hw_ctx *);
  47. extern void __blk_mq_tag_idle(struct blk_mq_hw_ctx *);
  48. static inline bool blk_mq_tag_busy(struct blk_mq_hw_ctx *hctx)
  49. {
  50. if (!(hctx->flags & BLK_MQ_F_TAG_SHARED))
  51. return false;
  52. return __blk_mq_tag_busy(hctx);
  53. }
  54. static inline void blk_mq_tag_idle(struct blk_mq_hw_ctx *hctx)
  55. {
  56. if (!(hctx->flags & BLK_MQ_F_TAG_SHARED))
  57. return;
  58. __blk_mq_tag_idle(hctx);
  59. }
  60. /*
  61. * This helper should only be used for flush request to share tag
  62. * with the request cloned from, and both the two requests can't be
  63. * in flight at the same time. The caller has to make sure the tag
  64. * can't be freed.
  65. */
  66. static inline void blk_mq_tag_set_rq(struct blk_mq_hw_ctx *hctx,
  67. unsigned int tag, struct request *rq)
  68. {
  69. hctx->tags->rqs[tag] = rq;
  70. }
  71. static inline bool blk_mq_tag_is_reserved(struct blk_mq_tags *tags,
  72. unsigned int tag)
  73. {
  74. return tag < tags->nr_reserved_tags;
  75. }
  76. #endif