blk-cgroup.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. typedef void (blkio_unlink_group_fn) (void *key, struct blkio_group *blkg);
  41. typedef void (blkio_update_group_weight_fn) (struct blkio_group *blkg,
  42. unsigned int weight);
  43. struct blkio_policy_ops {
  44. blkio_unlink_group_fn *blkio_unlink_group_fn;
  45. blkio_update_group_weight_fn *blkio_update_group_weight_fn;
  46. };
  47. struct blkio_policy_type {
  48. struct list_head list;
  49. struct blkio_policy_ops ops;
  50. };
  51. /* Blkio controller policy registration */
  52. extern void blkio_policy_register(struct blkio_policy_type *);
  53. extern void blkio_policy_unregister(struct blkio_policy_type *);
  54. #else
  55. struct blkio_group {
  56. };
  57. struct blkio_policy_type {
  58. };
  59. static inline void blkio_policy_register(struct blkio_policy_type *blkiop) { }
  60. static inline void blkio_policy_unregister(struct blkio_policy_type *blkiop) { }
  61. #endif
  62. #define BLKIO_WEIGHT_MIN 100
  63. #define BLKIO_WEIGHT_MAX 1000
  64. #define BLKIO_WEIGHT_DEFAULT 500
  65. #ifdef CONFIG_DEBUG_BLK_CGROUP
  66. static inline char *blkg_path(struct blkio_group *blkg)
  67. {
  68. return blkg->path;
  69. }
  70. void blkiocg_update_blkio_group_dequeue_stats(struct blkio_group *blkg,
  71. unsigned long dequeue);
  72. #else
  73. static inline char *blkg_path(struct blkio_group *blkg) { return NULL; }
  74. static inline void blkiocg_update_blkio_group_dequeue_stats(
  75. struct blkio_group *blkg, unsigned long dequeue) {}
  76. #endif
  77. #ifdef CONFIG_BLK_CGROUP
  78. extern struct blkio_cgroup blkio_root_cgroup;
  79. extern struct blkio_cgroup *cgroup_to_blkio_cgroup(struct cgroup *cgroup);
  80. extern void blkiocg_add_blkio_group(struct blkio_cgroup *blkcg,
  81. struct blkio_group *blkg, void *key, dev_t dev);
  82. extern int blkiocg_del_blkio_group(struct blkio_group *blkg);
  83. extern struct blkio_group *blkiocg_lookup_group(struct blkio_cgroup *blkcg,
  84. void *key);
  85. void blkiocg_update_blkio_group_stats(struct blkio_group *blkg,
  86. unsigned long time, unsigned long sectors);
  87. #else
  88. struct cgroup;
  89. static inline struct blkio_cgroup *
  90. cgroup_to_blkio_cgroup(struct cgroup *cgroup) { return NULL; }
  91. static inline void blkiocg_add_blkio_group(struct blkio_cgroup *blkcg,
  92. struct blkio_group *blkg, void *key, dev_t dev)
  93. {
  94. }
  95. static inline int
  96. blkiocg_del_blkio_group(struct blkio_group *blkg) { return 0; }
  97. static inline struct blkio_group *
  98. blkiocg_lookup_group(struct blkio_cgroup *blkcg, void *key) { return NULL; }
  99. static inline void blkiocg_update_blkio_group_stats(struct blkio_group *blkg,
  100. unsigned long time, unsigned long sectors)
  101. {
  102. }
  103. #endif
  104. #endif /* _BLK_CGROUP_H */