blk-cgroup.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. /* All the single valued stats go below this */
  36. BLKIO_STAT_TIME,
  37. BLKIO_STAT_SECTORS,
  38. #ifdef CONFIG_DEBUG_BLK_CGROUP
  39. BLKIO_STAT_DEQUEUE
  40. #endif
  41. };
  42. enum stat_sub_type {
  43. BLKIO_STAT_READ = 0,
  44. BLKIO_STAT_WRITE,
  45. BLKIO_STAT_SYNC,
  46. BLKIO_STAT_ASYNC,
  47. BLKIO_STAT_TOTAL
  48. };
  49. struct blkio_cgroup {
  50. struct cgroup_subsys_state css;
  51. unsigned int weight;
  52. spinlock_t lock;
  53. struct hlist_head blkg_list;
  54. };
  55. struct blkio_group_stats {
  56. /* total disk time and nr sectors dispatched by this group */
  57. uint64_t time;
  58. uint64_t sectors;
  59. uint64_t stat_arr[BLKIO_STAT_MERGED + 1][BLKIO_STAT_TOTAL];
  60. #ifdef CONFIG_DEBUG_BLK_CGROUP
  61. /* How many times this group has been removed from service tree */
  62. unsigned long dequeue;
  63. #endif
  64. };
  65. struct blkio_group {
  66. /* An rcu protected unique identifier for the group */
  67. void *key;
  68. struct hlist_node blkcg_node;
  69. unsigned short blkcg_id;
  70. #ifdef CONFIG_DEBUG_BLK_CGROUP
  71. /* Store cgroup path */
  72. char path[128];
  73. #endif
  74. /* The device MKDEV(major, minor), this group has been created for */
  75. dev_t dev;
  76. /* Need to serialize the stats in the case of reset/update */
  77. spinlock_t stats_lock;
  78. struct blkio_group_stats stats;
  79. };
  80. typedef void (blkio_unlink_group_fn) (void *key, struct blkio_group *blkg);
  81. typedef void (blkio_update_group_weight_fn) (struct blkio_group *blkg,
  82. unsigned int weight);
  83. struct blkio_policy_ops {
  84. blkio_unlink_group_fn *blkio_unlink_group_fn;
  85. blkio_update_group_weight_fn *blkio_update_group_weight_fn;
  86. };
  87. struct blkio_policy_type {
  88. struct list_head list;
  89. struct blkio_policy_ops ops;
  90. };
  91. /* Blkio controller policy registration */
  92. extern void blkio_policy_register(struct blkio_policy_type *);
  93. extern void blkio_policy_unregister(struct blkio_policy_type *);
  94. #else
  95. struct blkio_group {
  96. };
  97. struct blkio_policy_type {
  98. };
  99. static inline void blkio_policy_register(struct blkio_policy_type *blkiop) { }
  100. static inline void blkio_policy_unregister(struct blkio_policy_type *blkiop) { }
  101. #endif
  102. #define BLKIO_WEIGHT_MIN 100
  103. #define BLKIO_WEIGHT_MAX 1000
  104. #define BLKIO_WEIGHT_DEFAULT 500
  105. #ifdef CONFIG_DEBUG_BLK_CGROUP
  106. static inline char *blkg_path(struct blkio_group *blkg)
  107. {
  108. return blkg->path;
  109. }
  110. void blkiocg_update_dequeue_stats(struct blkio_group *blkg,
  111. unsigned long dequeue);
  112. #else
  113. static inline char *blkg_path(struct blkio_group *blkg) { return NULL; }
  114. static inline void blkiocg_update_dequeue_stats(struct blkio_group *blkg,
  115. unsigned long dequeue) {}
  116. #endif
  117. #if defined(CONFIG_BLK_CGROUP) || defined(CONFIG_BLK_CGROUP_MODULE)
  118. extern struct blkio_cgroup blkio_root_cgroup;
  119. extern struct blkio_cgroup *cgroup_to_blkio_cgroup(struct cgroup *cgroup);
  120. extern void blkiocg_add_blkio_group(struct blkio_cgroup *blkcg,
  121. struct blkio_group *blkg, void *key, dev_t dev);
  122. extern int blkiocg_del_blkio_group(struct blkio_group *blkg);
  123. extern struct blkio_group *blkiocg_lookup_group(struct blkio_cgroup *blkcg,
  124. void *key);
  125. void blkio_group_init(struct blkio_group *blkg);
  126. void blkiocg_update_timeslice_used(struct blkio_group *blkg,
  127. unsigned long time);
  128. void blkiocg_update_dispatch_stats(struct blkio_group *blkg, uint64_t bytes,
  129. bool direction, bool sync);
  130. void blkiocg_update_completion_stats(struct blkio_group *blkg,
  131. uint64_t start_time, uint64_t io_start_time, bool direction, bool sync);
  132. void blkiocg_update_io_merged_stats(struct blkio_group *blkg, bool direction,
  133. bool sync);
  134. #else
  135. struct cgroup;
  136. static inline struct blkio_cgroup *
  137. cgroup_to_blkio_cgroup(struct cgroup *cgroup) { return NULL; }
  138. static inline void blkio_group_init(struct blkio_group *blkg) {}
  139. static inline void blkiocg_add_blkio_group(struct blkio_cgroup *blkcg,
  140. struct blkio_group *blkg, void *key, dev_t dev) {}
  141. static inline int
  142. blkiocg_del_blkio_group(struct blkio_group *blkg) { return 0; }
  143. static inline struct blkio_group *
  144. blkiocg_lookup_group(struct blkio_cgroup *blkcg, void *key) { return NULL; }
  145. static inline void blkiocg_update_timeslice_used(struct blkio_group *blkg,
  146. unsigned long time) {}
  147. static inline void blkiocg_update_dispatch_stats(struct blkio_group *blkg,
  148. uint64_t bytes, bool direction, bool sync) {}
  149. static inline void blkiocg_update_completion_stats(struct blkio_group *blkg,
  150. uint64_t start_time, uint64_t io_start_time, bool direction,
  151. bool sync) {}
  152. static inline void blkiocg_update_io_merged_stats(struct blkio_group *blkg,
  153. bool direction, bool sync) {}
  154. #endif
  155. #endif /* _BLK_CGROUP_H */