blk-mq-tag.h 2.6 KB

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