blk-cgroup.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. struct blkio_cgroup {
  23. struct cgroup_subsys_state css;
  24. unsigned int weight;
  25. spinlock_t lock;
  26. struct hlist_head blkg_list;
  27. };
  28. struct blkio_group {
  29. /* An rcu protected unique identifier for the group */
  30. void *key;
  31. struct hlist_node blkcg_node;
  32. unsigned short blkcg_id;
  33. #ifdef CONFIG_DEBUG_BLK_CGROUP
  34. /* Store cgroup path */
  35. char path[128];
  36. /* How many times this group has been removed from service tree */
  37. unsigned long dequeue;
  38. #endif
  39. /* The device MKDEV(major, minor), this group has been created for */
  40. dev_t dev;
  41. /* total disk time and nr sectors dispatched by this group */
  42. unsigned long time;
  43. unsigned long sectors;
  44. };
  45. typedef void (blkio_unlink_group_fn) (void *key, struct blkio_group *blkg);
  46. typedef void (blkio_update_group_weight_fn) (struct blkio_group *blkg,
  47. unsigned int weight);
  48. struct blkio_policy_ops {
  49. blkio_unlink_group_fn *blkio_unlink_group_fn;
  50. blkio_update_group_weight_fn *blkio_update_group_weight_fn;
  51. };
  52. struct blkio_policy_type {
  53. struct list_head list;
  54. struct blkio_policy_ops ops;
  55. };
  56. /* Blkio controller policy registration */
  57. extern void blkio_policy_register(struct blkio_policy_type *);
  58. extern void blkio_policy_unregister(struct blkio_policy_type *);
  59. #else
  60. struct blkio_group {
  61. };
  62. struct blkio_policy_type {
  63. };
  64. static inline void blkio_policy_register(struct blkio_policy_type *blkiop) { }
  65. static inline void blkio_policy_unregister(struct blkio_policy_type *blkiop) { }
  66. #endif
  67. #define BLKIO_WEIGHT_MIN 100
  68. #define BLKIO_WEIGHT_MAX 1000
  69. #define BLKIO_WEIGHT_DEFAULT 500
  70. #ifdef CONFIG_DEBUG_BLK_CGROUP
  71. static inline char *blkg_path(struct blkio_group *blkg)
  72. {
  73. return blkg->path;
  74. }
  75. void blkiocg_update_blkio_group_dequeue_stats(struct blkio_group *blkg,
  76. unsigned long dequeue);
  77. #else
  78. static inline char *blkg_path(struct blkio_group *blkg) { return NULL; }
  79. static inline void blkiocg_update_blkio_group_dequeue_stats(
  80. struct blkio_group *blkg, unsigned long dequeue) {}
  81. #endif
  82. #if defined(CONFIG_BLK_CGROUP) || defined(CONFIG_BLK_CGROUP_MODULE)
  83. extern struct blkio_cgroup blkio_root_cgroup;
  84. extern struct blkio_cgroup *cgroup_to_blkio_cgroup(struct cgroup *cgroup);
  85. extern void blkiocg_add_blkio_group(struct blkio_cgroup *blkcg,
  86. struct blkio_group *blkg, void *key, dev_t dev);
  87. extern int blkiocg_del_blkio_group(struct blkio_group *blkg);
  88. extern struct blkio_group *blkiocg_lookup_group(struct blkio_cgroup *blkcg,
  89. void *key);
  90. void blkiocg_update_blkio_group_stats(struct blkio_group *blkg,
  91. unsigned long time, unsigned long sectors);
  92. #else
  93. struct cgroup;
  94. static inline struct blkio_cgroup *
  95. cgroup_to_blkio_cgroup(struct cgroup *cgroup) { return NULL; }
  96. static inline void blkiocg_add_blkio_group(struct blkio_cgroup *blkcg,
  97. struct blkio_group *blkg, void *key, dev_t dev)
  98. {
  99. }
  100. static inline int
  101. blkiocg_del_blkio_group(struct blkio_group *blkg) { return 0; }
  102. static inline struct blkio_group *
  103. blkiocg_lookup_group(struct blkio_cgroup *blkcg, void *key) { return NULL; }
  104. static inline void blkiocg_update_blkio_group_stats(struct blkio_group *blkg,
  105. unsigned long time, unsigned long sectors)
  106. {
  107. }
  108. #endif
  109. #endif /* _BLK_CGROUP_H */