postProcessingDataMemory.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. #include <linux/u64_stats_sync.h>
  17. #include <linux/seq_file.h>
  18. #include <linux/radix-tree.h>
  19. #include <linux/blkdev.h>
  20. /* Max limits for throttle policy */
  21. #define THROTL_IOPS_MAX UINT_MAX
  22. /* CFQ specific, out here for blkcg->cfq_weight */
  23. #define CFQ_WEIGHT_MIN 10
  24. #define CFQ_WEIGHT_MAX 1000
  25. #define CFQ_WEIGHT_DEFAULT 500
  26. #ifdef CONFIG_BLK_CGROUP
  27. enum blkg_rwstat_type {
  28. BLKG_RWSTAT_READ,
  29. BLKG_RWSTAT_WRITE,
  30. BLKG_RWSTAT_SYNC,
  31. BLKG_RWSTAT_ASYNC,
  32. BLKG_RWSTAT_NR,
  33. BLKG_RWSTAT_TOTAL = BLKG_RWSTAT_NR,
  34. };
  35. struct blkcg_gq;
  36. struct blkcg {
  37. struct cgroup_subsys_state css;
  38. spinlock_t lock;
  39. struct radix_tree_root blkg_tree;
  40. struct blkcg_gq *blkg_hint;
  41. struct hlist_head blkg_list;
  42. /* for policies to test whether associated blkcg has changed */
  43. uint64_t id;
  44. /* TODO: per-policy storage in blkcg */
  45. unsigned int cfq_weight; /* belongs to cfq */
  46. };
  47. struct blkg_stat {
  48. struct u64_stats_sync syncp;
  49. uint64_t cnt;
  50. };
  51. struct blkg_rwstat {
  52. struct u64_stats_sync syncp;
  53. uint64_t cnt[BLKG_RWSTAT_NR];
  54. };
  55. /*
  56. * A blkcg_gq (blkg) is association between a block cgroup (blkcg) and a
  57. * request_queue (q). This is used by blkcg policies which need to track
  58. * information per blkcg - q pair.
  59. *
  60. * There can be multiple active blkcg policies and each has its private
  61. * data on each blkg, the size of which is determined by
  62. * blkcg_policy->pd_size. blkcg core allocates and frees such areas
  63. * together with blkg and invokes pd_init/exit_fn() methods.
  64. *
  65. * Such private data must embed struct blkg_policy_data (pd) at the
  66. * beginning and pd_size can't be smaller than pd.
  67. */
  68. struct blkg_policy_data {
  69. /* the blkg this per-policy data belongs to */
  70. struct blkcg_gq *blkg;
  71. /* used during policy activation */
  72. struct list_head alloc_node;
  73. };
  74. /* association between a blk cgroup and a request queue */
  75. struct blkcg_gq {
  76. /* Pointer to the associated request_queue */
  77. struct request_queue *q;
  78. struct list_head q_node;
  79. struct hlist_node blkcg_node;
  80. struct blkcg *blkcg;
  81. /* request allocation list for this blkcg-q pair */
  82. struct request_list rl;
  83. /* reference count */
  84. int refcnt;
  85. struct blkg_policy_data *pd[BLKCG_MAX_POLS];
  86. struct rcu_head rcu_head;
  87. };
  88. typedef void (blkcg_pol_init_pd_fn)(struct blkcg_gq *blkg);
  89. typedef void (blkcg_pol_exit_pd_fn)(struct blkcg_gq *blkg);
  90. typedef void (blkcg_pol_reset_pd_stats_fn)(struct blkcg_gq *blkg);
  91. struct blkcg_policy {
  92. int plid;
  93. /* policy specific private data size */
  94. size_t pd_size;
  95. /* cgroup files for the policy */
  96. struct cftype *cftypes;
  97. /* operations */
  98. blkcg_pol_init_pd_fn *pd_init_fn;
  99. blkcg_pol_exit_pd_fn *pd_exit_fn;
  100. blkcg_pol_reset_pd_stats_fn *pd_reset_stats_fn;
  101. };
  102. extern struct blkcg blkcg_root;
  103. struct blkcg_gq *blkg_lookup(struct blkcg *blkcg, struct request_queue *q);
  104. struct blkcg_gq *blkg_lookup_create(struct blkcg *blkcg,
  105. struct request_queue *q);
  106. int blkcg_init_queue(struct request_queue *q);
  107. void blkcg_drain_queue(struct request_queue *q);
  108. void blkcg_exit_queue(struct request_queue *q);
  109. /* Blkio controller policy registration */
  110. int blkcg_policy_register(struct blkcg_policy *pol);
  111. void blkcg_policy_unregister(struct blkcg_policy *pol);
  112. int blkcg_activate_policy(struct request_queue *q,
  113. const struct blkcg_policy *pol);
  114. void blkcg_deactivate_policy(struct request_queue *q,
  115. const struct blkcg_policy *pol);
  116. void blkcg_print_blkgs(struct seq_file *sf, struct blkcg *blkcg,
  117. u64 (*prfill)(struct seq_file *,
  118. struct blkg_policy_data *, int),
  119. const struct blkcg_policy *pol, int data,
  120. bool show_total);
  121. u64 __blkg_prfill_u64(struct seq_file *sf, struct blkg_policy_data *pd, u64 v);
  122. u64 __blkg_prfill_rwstat(struct seq_file *sf, struct blkg_policy_data *pd,
  123. const struct blkg_rwstat *rwstat);
  124. u64 blkg_prfill_stat(struct seq_file *sf, struct blkg_policy_data *pd, int off);
  125. u64 blkg_prfill_rwstat(struct seq_file *sf, struct blkg_policy_data *pd,
  126. int off);
  127. struct blkg_conf_ctx {
  128. struct gendisk *disk;
  129. struct blkcg_gq *blkg;
  130. u64 v;
  131. };
  132. int blkg_conf_prep(struct blkcg *blkcg, const struct blkcg_policy *pol,
  133. const char *input, struct blkg_conf_ctx *ctx);
  134. void blkg_conf_finish(struct blkg_conf_ctx *ctx);
  135. static inline struct blkcg *cgroup_to_blkcg(struct cgroup *cgroup)
  136. {
  137. return container_of(cgroup_subsys_state(cgroup, blkio_subsys_id),
  138. struct blkcg, css);
  139. }
  140. static inline struct blkcg *task_blkcg(struct task_struct *tsk)
  141. {
  142. return container_of(task_subsys_state(tsk, blkio_subsys_id),
  143. struct blkcg, css);
  144. }
  145. static inline struct blkcg *bio_blkcg(struct bio *bio)
  146. {
  147. if (bio && bio->bi_css)
  148. return container_of(bio->bi_css, struct blkcg, css);
  149. return task_blkcg(current);
  150. }
  151. /**
  152. * blkg_to_pdata - get policy private data
  153. * @blkg: blkg of interest
  154. * @pol: policy of interest
  155. *
  156. * Return pointer to private data associated with the @blkg-@pol pair.
  157. */
  158. static inline struct blkg_policy_data *blkg_to_pd(struct blkcg_gq *blkg,
  159. struct blkcg_policy *pol)
  160. {
  161. return blkg ? blkg->pd[pol->plid] : NULL;
  162. }