blk-cgroup.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. #ifndef _BLK_CGROUP_H
  2. #define _BLK_CGROUP_H
  3. /*
  4. * Common Block IO controller cgroup interface
  5. *
  6. * Based on ideas and code from CFQ, CFS and BFQ:
  7. * Copyright (C) 2003 Jens Axboe <axboe@kernel.dk>
  8. *
  9. * Copyright (C) 2008 Fabio Checconi <fabio@gandalf.sssup.it>
  10. * Paolo Valente <paolo.valente@unimore.it>
  11. *
  12. * Copyright (C) 2009 Vivek Goyal <vgoyal@redhat.com>
  13. * Nauman Rafique <nauman@google.com>
  14. */
  15. #include <linux/cgroup.h>
  16. #if defined(CONFIG_BLK_CGROUP) || defined(CONFIG_BLK_CGROUP_MODULE)
  17. #ifndef CONFIG_BLK_CGROUP
  18. /* When blk-cgroup is a module, its subsys_id isn't a compile-time constant */
  19. extern struct cgroup_subsys blkio_subsys;
  20. #define blkio_subsys_id blkio_subsys.subsys_id
  21. #endif
  22. enum stat_type {
  23. /* Total time spent (in ns) between request dispatch to the driver and
  24. * request completion for IOs doen by this cgroup. This may not be
  25. * accurate when NCQ is turned on. */
  26. BLKIO_STAT_SERVICE_TIME = 0,
  27. /* Total bytes transferred */
  28. BLKIO_STAT_SERVICE_BYTES,
  29. /* Total IOs serviced, post merge */
  30. BLKIO_STAT_SERVICED,
  31. /* Total time spent waiting in scheduler queue in ns */
  32. BLKIO_STAT_WAIT_TIME,
  33. /* Number of IOs merged */
  34. BLKIO_STAT_MERGED,
  35. /* Number of IOs queued up */
  36. BLKIO_STAT_QUEUED,
  37. /* All the single valued stats go below this */
  38. BLKIO_STAT_TIME,
  39. BLKIO_STAT_SECTORS,
  40. #ifdef CONFIG_DEBUG_BLK_CGROUP
  41. BLKIO_STAT_AVG_QUEUE_SIZE,
  42. BLKIO_STAT_DEQUEUE
  43. #endif
  44. };
  45. enum stat_sub_type {
  46. BLKIO_STAT_READ = 0,
  47. BLKIO_STAT_WRITE,
  48. BLKIO_STAT_SYNC,
  49. BLKIO_STAT_ASYNC,
  50. BLKIO_STAT_TOTAL
  51. };
  52. struct blkio_cgroup {
  53. struct cgroup_subsys_state css;
  54. unsigned int weight;
  55. spinlock_t lock;
  56. struct hlist_head blkg_list;
  57. };
  58. struct blkio_group_stats {
  59. /* total disk time and nr sectors dispatched by this group */
  60. uint64_t time;
  61. uint64_t sectors;
  62. uint64_t stat_arr[BLKIO_STAT_QUEUED + 1][BLKIO_STAT_TOTAL];
  63. #ifdef CONFIG_DEBUG_BLK_CGROUP
  64. /* Sum of number of IOs queued across all samples */
  65. uint64_t avg_queue_size_sum;
  66. /* Count of samples taken for average */
  67. uint64_t avg_queue_size_samples;
  68. /* How many times this group has been removed from service tree */
  69. unsigned long dequeue;
  70. #endif
  71. };
  72. struct blkio_group {
  73. /* An rcu protected unique identifier for the group */
  74. void *key;
  75. struct hlist_node blkcg_node;
  76. unsigned short blkcg_id;
  77. #ifdef CONFIG_DEBUG_BLK_CGROUP
  78. /* Store cgroup path */
  79. char path[128];
  80. #endif
  81. /* The device MKDEV(major, minor), this group has been created for */
  82. dev_t dev;
  83. /* Need to serialize the stats in the case of reset/update */
  84. spinlock_t stats_lock;
  85. struct blkio_group_stats stats;
  86. };
  87. typedef void (blkio_unlink_group_fn) (void *key, struct blkio_group *blkg);
  88. typedef void (blkio_update_group_weight_fn) (struct blkio_group *blkg,
  89. unsigned int weight);
  90. struct blkio_policy_ops {
  91. blkio_unlink_group_fn *blkio_unlink_group_fn;
  92. blkio_update_group_weight_fn *blkio_update_group_weight_fn;
  93. };
  94. struct blkio_policy_type {
  95. struct list_head list;
  96. struct blkio_policy_ops ops;
  97. };
  98. /* Blkio controller policy registration */
  99. extern void blkio_policy_register(struct blkio_policy_type *);
  100. extern void blkio_policy_unregister(struct blkio_policy_type *);
  101. #else
  102. struct blkio_group {
  103. };
  104. struct blkio_policy_type {
  105. };
  106. static inline void blkio_policy_register(struct blkio_policy_type *blkiop) { }
  107. static inline void blkio_policy_unregister(struct blkio_policy_type *blkiop) { }
  108. #endif
  109. #define BLKIO_WEIGHT_MIN 100
  110. #define BLKIO_WEIGHT_MAX 1000
  111. #define BLKIO_WEIGHT_DEFAULT 500
  112. #ifdef CONFIG_DEBUG_BLK_CGROUP
  113. static inline char *blkg_path(struct blkio_group *blkg)
  114. {
  115. return blkg->path;
  116. }
  117. void blkiocg_update_set_active_queue_stats(struct blkio_group *blkg);
  118. void blkiocg_update_dequeue_stats(struct blkio_group *blkg,
  119. unsigned long dequeue);
  120. #else
  121. static inline char *blkg_path(struct blkio_group *blkg) { return NULL; }
  122. static inline void blkiocg_update_set_active_queue_stats(
  123. struct blkio_group *blkg) {}
  124. static inline void blkiocg_update_dequeue_stats(struct blkio_group *blkg,
  125. unsigned long dequeue) {}
  126. #endif
  127. #if defined(CONFIG_BLK_CGROUP) || defined(CONFIG_BLK_CGROUP_MODULE)
  128. extern struct blkio_cgroup blkio_root_cgroup;
  129. extern struct blkio_cgroup *cgroup_to_blkio_cgroup(struct cgroup *cgroup);
  130. extern void blkiocg_add_blkio_group(struct blkio_cgroup *blkcg,
  131. struct blkio_group *blkg, void *key, dev_t dev);
  132. extern int blkiocg_del_blkio_group(struct blkio_group *blkg);
  133. extern struct blkio_group *blkiocg_lookup_group(struct blkio_cgroup *blkcg,
  134. void *key);
  135. void blkio_group_init(struct blkio_group *blkg);
  136. void blkiocg_update_timeslice_used(struct blkio_group *blkg,
  137. unsigned long time);
  138. void blkiocg_update_dispatch_stats(struct blkio_group *blkg, uint64_t bytes,
  139. bool direction, bool sync);
  140. void blkiocg_update_completion_stats(struct blkio_group *blkg,
  141. uint64_t start_time, uint64_t io_start_time, bool direction, bool sync);
  142. void blkiocg_update_io_merged_stats(struct blkio_group *blkg, bool direction,
  143. bool sync);
  144. void blkiocg_update_request_add_stats(struct blkio_group *blkg,
  145. struct blkio_group *curr_blkg, bool direction, bool sync);
  146. void blkiocg_update_request_remove_stats(struct blkio_group *blkg,
  147. bool direction, bool sync);
  148. #else
  149. struct cgroup;
  150. static inline struct blkio_cgroup *
  151. cgroup_to_blkio_cgroup(struct cgroup *cgroup) { return NULL; }
  152. static inline void blkio_group_init(struct blkio_group *blkg) {}
  153. static inline void blkiocg_add_blkio_group(struct blkio_cgroup *blkcg,
  154. struct blkio_group *blkg, void *key, dev_t dev) {}
  155. static inline int
  156. blkiocg_del_blkio_group(struct blkio_group *blkg) { return 0; }
  157. static inline struct blkio_group *
  158. blkiocg_lookup_group(struct blkio_cgroup *blkcg, void *key) { return NULL; }
  159. static inline void blkiocg_update_timeslice_used(struct blkio_group *blkg,
  160. unsigned long time) {}
  161. static inline void blkiocg_update_dispatch_stats(struct blkio_group *blkg,
  162. uint64_t bytes, bool direction, bool sync) {}
  163. static inline void blkiocg_update_completion_stats(struct blkio_group *blkg,
  164. uint64_t start_time, uint64_t io_start_time, bool direction,
  165. bool sync) {}
  166. static inline void blkiocg_update_io_merged_stats(struct blkio_group *blkg,
  167. bool direction, bool sync) {}
  168. static inline void blkiocg_update_request_add_stats(struct blkio_group *blkg,
  169. struct blkio_group *curr_blkg, bool direction, bool sync) {}
  170. static inline void blkiocg_update_request_remove_stats(struct blkio_group *blkg,
  171. bool direction, bool sync) {}
  172. #endif
  173. #endif /* _BLK_CGROUP_H */