blk.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. #ifndef BLK_INTERNAL_H
  2. #define BLK_INTERNAL_H
  3. /* Amount of time in which a process may batch requests */
  4. #define BLK_BATCH_TIME (HZ/50UL)
  5. /* Number of requests a "batching" process may submit */
  6. #define BLK_BATCH_REQ 32
  7. extern struct kmem_cache *blk_requestq_cachep;
  8. extern struct kobj_type blk_queue_ktype;
  9. void init_request_from_bio(struct request *req, struct bio *bio);
  10. void blk_rq_bio_prep(struct request_queue *q, struct request *rq,
  11. struct bio *bio);
  12. int blk_rq_append_bio(struct request_queue *q, struct request *rq,
  13. struct bio *bio);
  14. void blk_dequeue_request(struct request *rq);
  15. void __blk_queue_free_tags(struct request_queue *q);
  16. void blk_rq_timed_out_timer(unsigned long data);
  17. void blk_delete_timer(struct request *);
  18. void blk_add_timer(struct request *);
  19. void __generic_unplug_device(struct request_queue *);
  20. void blk_run_queue_async(struct request_queue *q);
  21. /*
  22. * Internal atomic flags for request handling
  23. */
  24. enum rq_atomic_flags {
  25. REQ_ATOM_COMPLETE = 0,
  26. };
  27. /*
  28. * EH timer and IO completion will both attempt to 'grab' the request, make
  29. * sure that only one of them succeeds
  30. */
  31. static inline int blk_mark_rq_complete(struct request *rq)
  32. {
  33. return test_and_set_bit(REQ_ATOM_COMPLETE, &rq->atomic_flags);
  34. }
  35. static inline void blk_clear_rq_complete(struct request *rq)
  36. {
  37. clear_bit(REQ_ATOM_COMPLETE, &rq->atomic_flags);
  38. }
  39. /*
  40. * Internal elevator interface
  41. */
  42. #define ELV_ON_HASH(rq) (!hlist_unhashed(&(rq)->hash))
  43. void blk_insert_flush(struct request *rq);
  44. void blk_abort_flushes(struct request_queue *q);
  45. static inline struct request *__elv_next_request(struct request_queue *q)
  46. {
  47. struct request *rq;
  48. while (1) {
  49. if (!list_empty(&q->queue_head)) {
  50. rq = list_entry_rq(q->queue_head.next);
  51. return rq;
  52. }
  53. if (!q->elevator->ops->elevator_dispatch_fn(q, 0))
  54. return NULL;
  55. }
  56. }
  57. static inline void elv_activate_rq(struct request_queue *q, struct request *rq)
  58. {
  59. struct elevator_queue *e = q->elevator;
  60. if (e->ops->elevator_activate_req_fn)
  61. e->ops->elevator_activate_req_fn(q, rq);
  62. }
  63. static inline void elv_deactivate_rq(struct request_queue *q, struct request *rq)
  64. {
  65. struct elevator_queue *e = q->elevator;
  66. if (e->ops->elevator_deactivate_req_fn)
  67. e->ops->elevator_deactivate_req_fn(q, rq);
  68. }
  69. #ifdef CONFIG_FAIL_IO_TIMEOUT
  70. int blk_should_fake_timeout(struct request_queue *);
  71. ssize_t part_timeout_show(struct device *, struct device_attribute *, char *);
  72. ssize_t part_timeout_store(struct device *, struct device_attribute *,
  73. const char *, size_t);
  74. #else
  75. static inline int blk_should_fake_timeout(struct request_queue *q)
  76. {
  77. return 0;
  78. }
  79. #endif
  80. struct io_context *current_io_context(gfp_t gfp_flags, int node);
  81. int ll_back_merge_fn(struct request_queue *q, struct request *req,
  82. struct bio *bio);
  83. int ll_front_merge_fn(struct request_queue *q, struct request *req,
  84. struct bio *bio);
  85. int attempt_back_merge(struct request_queue *q, struct request *rq);
  86. int attempt_front_merge(struct request_queue *q, struct request *rq);
  87. int blk_attempt_req_merge(struct request_queue *q, struct request *rq,
  88. struct request *next);
  89. void blk_recalc_rq_segments(struct request *rq);
  90. void blk_rq_set_mixed_merge(struct request *rq);
  91. void blk_queue_congestion_threshold(struct request_queue *q);
  92. int blk_dev_init(void);
  93. void elv_quiesce_start(struct request_queue *q);
  94. void elv_quiesce_end(struct request_queue *q);
  95. /*
  96. * Return the threshold (number of used requests) at which the queue is
  97. * considered to be congested. It include a little hysteresis to keep the
  98. * context switch rate down.
  99. */
  100. static inline int queue_congestion_on_threshold(struct request_queue *q)
  101. {
  102. return q->nr_congestion_on;
  103. }
  104. /*
  105. * The threshold at which a queue is considered to be uncongested
  106. */
  107. static inline int queue_congestion_off_threshold(struct request_queue *q)
  108. {
  109. return q->nr_congestion_off;
  110. }
  111. static inline int blk_cpu_to_group(int cpu)
  112. {
  113. int group = NR_CPUS;
  114. #ifdef CONFIG_SCHED_MC
  115. const struct cpumask *mask = cpu_coregroup_mask(cpu);
  116. group = cpumask_first(mask);
  117. #elif defined(CONFIG_SCHED_SMT)
  118. group = cpumask_first(topology_thread_cpumask(cpu));
  119. #else
  120. return cpu;
  121. #endif
  122. if (likely(group < NR_CPUS))
  123. return group;
  124. return cpu;
  125. }
  126. /*
  127. * Contribute to IO statistics IFF:
  128. *
  129. * a) it's attached to a gendisk, and
  130. * b) the queue had IO stats enabled when this request was started, and
  131. * c) it's a file system request or a discard request
  132. */
  133. static inline int blk_do_io_stat(struct request *rq)
  134. {
  135. return rq->rq_disk &&
  136. (rq->cmd_flags & REQ_IO_STAT) &&
  137. (rq->cmd_type == REQ_TYPE_FS ||
  138. (rq->cmd_flags & REQ_DISCARD));
  139. }
  140. #endif