blk.h 4.5 KB

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