blk-mq-tag.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. enum {
  47. BLK_MQ_TAG_CACHE_MIN = 1,
  48. BLK_MQ_TAG_CACHE_MAX = 64,
  49. };
  50. enum {
  51. BLK_MQ_TAG_FAIL = -1U,
  52. BLK_MQ_TAG_MIN = BLK_MQ_TAG_CACHE_MIN,
  53. BLK_MQ_TAG_MAX = BLK_MQ_TAG_FAIL - 1,
  54. };
  55. extern bool __blk_mq_tag_busy(struct blk_mq_hw_ctx *);
  56. extern void __blk_mq_tag_idle(struct blk_mq_hw_ctx *);
  57. static inline bool blk_mq_tag_busy(struct blk_mq_hw_ctx *hctx)
  58. {
  59. if (!(hctx->flags & BLK_MQ_F_TAG_SHARED))
  60. return false;
  61. return __blk_mq_tag_busy(hctx);
  62. }
  63. static inline void blk_mq_tag_idle(struct blk_mq_hw_ctx *hctx)
  64. {
  65. if (!(hctx->flags & BLK_MQ_F_TAG_SHARED))
  66. return;
  67. __blk_mq_tag_idle(hctx);
  68. }
  69. #endif