blk-cgroup.h 3.6 KB

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