blk-mq-tag.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. };
  35. extern struct blk_mq_tags *blk_mq_init_tags(unsigned int nr_tags, unsigned int reserved_tags, int node);
  36. extern void blk_mq_free_tags(struct blk_mq_tags *tags);
  37. extern unsigned int blk_mq_get_tag(struct blk_mq_alloc_data *data);
  38. extern void blk_mq_put_tag(struct blk_mq_hw_ctx *hctx, unsigned int tag, unsigned int *last_tag);
  39. extern bool blk_mq_has_free_tags(struct blk_mq_tags *tags);
  40. extern ssize_t blk_mq_tag_sysfs_show(struct blk_mq_tags *tags, char *page);
  41. extern void blk_mq_tag_init_last_tag(struct blk_mq_tags *tags, unsigned int *last_tag);
  42. extern int blk_mq_tag_update_depth(struct blk_mq_tags *tags, unsigned int depth);
  43. enum {
  44. BLK_MQ_TAG_CACHE_MIN = 1,
  45. BLK_MQ_TAG_CACHE_MAX = 64,
  46. };
  47. enum {
  48. BLK_MQ_TAG_FAIL = -1U,
  49. BLK_MQ_TAG_MIN = BLK_MQ_TAG_CACHE_MIN,
  50. BLK_MQ_TAG_MAX = BLK_MQ_TAG_FAIL - 1,
  51. };
  52. extern bool __blk_mq_tag_busy(struct blk_mq_hw_ctx *);
  53. extern void __blk_mq_tag_idle(struct blk_mq_hw_ctx *);
  54. static inline bool blk_mq_tag_busy(struct blk_mq_hw_ctx *hctx)
  55. {
  56. if (!(hctx->flags & BLK_MQ_F_TAG_SHARED))
  57. return false;
  58. return __blk_mq_tag_busy(hctx);
  59. }
  60. static inline void blk_mq_tag_idle(struct blk_mq_hw_ctx *hctx)
  61. {
  62. if (!(hctx->flags & BLK_MQ_F_TAG_SHARED))
  63. return;
  64. __blk_mq_tag_idle(hctx);
  65. }
  66. #endif