blk-cgroup.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. #else
  43. struct blkio_group {
  44. };
  45. #endif
  46. #define BLKIO_WEIGHT_MIN 100
  47. #define BLKIO_WEIGHT_MAX 1000
  48. #define BLKIO_WEIGHT_DEFAULT 500
  49. #ifdef CONFIG_DEBUG_BLK_CGROUP
  50. static inline char *blkg_path(struct blkio_group *blkg)
  51. {
  52. return blkg->path;
  53. }
  54. void blkiocg_update_blkio_group_dequeue_stats(struct blkio_group *blkg,
  55. unsigned long dequeue);
  56. #else
  57. static inline char *blkg_path(struct blkio_group *blkg) { return NULL; }
  58. static inline void blkiocg_update_blkio_group_dequeue_stats(
  59. struct blkio_group *blkg, unsigned long dequeue) {}
  60. #endif
  61. #ifdef CONFIG_BLK_CGROUP
  62. extern struct blkio_cgroup blkio_root_cgroup;
  63. extern struct blkio_cgroup *cgroup_to_blkio_cgroup(struct cgroup *cgroup);
  64. extern void blkiocg_add_blkio_group(struct blkio_cgroup *blkcg,
  65. struct blkio_group *blkg, void *key, dev_t dev);
  66. extern int blkiocg_del_blkio_group(struct blkio_group *blkg);
  67. extern struct blkio_group *blkiocg_lookup_group(struct blkio_cgroup *blkcg,
  68. void *key);
  69. void blkiocg_update_blkio_group_stats(struct blkio_group *blkg,
  70. unsigned long time, unsigned long sectors);
  71. #else
  72. struct cgroup;
  73. static inline struct blkio_cgroup *
  74. cgroup_to_blkio_cgroup(struct cgroup *cgroup) { return NULL; }
  75. static inline void blkiocg_add_blkio_group(struct blkio_cgroup *blkcg,
  76. struct blkio_group *blkg, void *key, dev_t dev)
  77. {
  78. }
  79. static inline int
  80. blkiocg_del_blkio_group(struct blkio_group *blkg) { return 0; }
  81. static inline struct blkio_group *
  82. blkiocg_lookup_group(struct blkio_cgroup *blkcg, void *key) { return NULL; }
  83. static inline void blkiocg_update_blkio_group_stats(struct blkio_group *blkg,
  84. unsigned long time, unsigned long sectors)
  85. {
  86. }
  87. #endif
  88. #endif /* _BLK_CGROUP_H */