blk-cgroup.h 5.2 KB

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