1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef _BLK_CGROUP_H 3 #define _BLK_CGROUP_H 4 /* 5 * Common Block IO controller cgroup interface 6 * 7 * Based on ideas and code from CFQ, CFS and BFQ: 8 * Copyright (C) 2003 Jens Axboe <axboe@kernel.dk> 9 * 10 * Copyright (C) 2008 Fabio Checconi <fabio@gandalf.sssup.it> 11 * Paolo Valente <paolo.valente@unimore.it> 12 * 13 * Copyright (C) 2009 Vivek Goyal <vgoyal@redhat.com> 14 * Nauman Rafique <nauman@google.com> 15 */ 16 17 #include <linux/atomic.h> 18 #include <linux/compiler.h> 19 #include <linux/types.h> 20 21 struct bio; 22 struct cgroup_subsys_state; 23 struct gendisk; 24 25 #define FC_APPID_LEN 129 26 27 #ifdef CONFIG_BLK_CGROUP 28 extern struct cgroup_subsys_state * const blkcg_root_css; 29 extern atomic_t blkcg_nr_congested; 30 31 void blkcg_schedule_throttle(struct gendisk *disk, bool use_memdelay); 32 void blkcg_maybe_throttle_current(void); 33 bool __blk_cgroup_congested(void); 34 35 /** 36 * blk_cgroup_congested - is the current task in a throttled blkcg? 37 * 38 * Called from mm hot paths where the answer is almost always false, so keep 39 * that case to a load and a branch and only walk the hierarchy out of line 40 * when something in the system really is throttled. 41 * 42 * Return: %true if the current task's blkcg or any of its ancestors is 43 * throttled, %false otherwise. 44 */ blk_cgroup_congested(void)45static inline bool blk_cgroup_congested(void) 46 { 47 if (likely(!atomic_read(&blkcg_nr_congested))) 48 return false; 49 return __blk_cgroup_congested(); 50 } 51 52 void blkcg_pin_online(struct cgroup_subsys_state *blkcg_css); 53 void blkcg_unpin_online(struct cgroup_subsys_state *blkcg_css); 54 struct list_head *blkcg_get_cgwb_list(struct cgroup_subsys_state *css); 55 struct cgroup_subsys_state *bio_blkcg_css(struct bio *bio); 56 57 #else /* CONFIG_BLK_CGROUP */ 58 59 #define blkcg_root_css ((struct cgroup_subsys_state *)ERR_PTR(-EINVAL)) 60 blkcg_maybe_throttle_current(void)61static inline void blkcg_maybe_throttle_current(void) { } blk_cgroup_congested(void)62static inline bool blk_cgroup_congested(void) { return false; } bio_blkcg_css(struct bio * bio)63static inline struct cgroup_subsys_state *bio_blkcg_css(struct bio *bio) 64 { 65 return NULL; 66 } 67 #endif /* CONFIG_BLK_CGROUP */ 68 69 int blkcg_set_fc_appid(char *app_id, u64 cgrp_id, size_t app_id_len); 70 char *blkcg_get_fc_appid(struct bio *bio); 71 72 #endif /* _BLK_CGROUP_H */ 73