^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #if !defined(_MQ_DEADLINE_CGROUP_H_)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) #define _MQ_DEADLINE_CGROUP_H_
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <linux/blk-cgroup.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) struct request_queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * struct io_stats_per_prio - I/O statistics per I/O priority class.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * @inserted: Number of inserted requests.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * @merged: Number of merged requests.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * @dispatched: Number of dispatched requests.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * @completed: Number of I/O completions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) struct io_stats_per_prio {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) local_t inserted;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) local_t merged;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) local_t dispatched;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) local_t completed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) /* I/O statistics per I/O cgroup per I/O priority class (IOPRIO_CLASS_*). */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) struct blkcg_io_stats {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) struct io_stats_per_prio stats[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * struct dd_blkcg - Per cgroup data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * @cpd: blkcg_policy_data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * @stats: I/O statistics.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) struct dd_blkcg {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) struct blkcg_policy_data cpd; /* must be the first member */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) struct blkcg_io_stats __percpu *stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) * Count one event of type 'event_type' and with I/O priority class
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) * 'prio_class'.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #define ddcg_count(ddcg, event_type, prio_class) do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) if (ddcg) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) struct blkcg_io_stats *io_stats = get_cpu_ptr((ddcg)->stats); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) BUILD_BUG_ON(!__same_type((ddcg), struct dd_blkcg *)); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) BUILD_BUG_ON(!__same_type((prio_class), u8)); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) local_inc(&io_stats->stats[(prio_class)].event_type); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) put_cpu_ptr(io_stats); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) * Returns the total number of ddcg_count(ddcg, event_type, prio_class) calls
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) * across all CPUs. No locking or barriers since it is fine if the returned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) * sum is slightly outdated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) #define ddcg_sum(ddcg, event_type, prio) ({ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) unsigned int cpu; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) u32 sum = 0; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) BUILD_BUG_ON(!__same_type((ddcg), struct dd_blkcg *)); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) BUILD_BUG_ON(!__same_type((prio), u8)); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) for_each_present_cpu(cpu) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) sum += local_read(&per_cpu_ptr((ddcg)->stats, cpu)-> \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) stats[(prio)].event_type); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) sum; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) #ifdef CONFIG_BLK_CGROUP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) * struct dd_blkg - Per (cgroup, request queue) data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) * @pd: blkg_policy_data structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) struct dd_blkg {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) struct blkg_policy_data pd; /* must be the first member */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) struct dd_blkcg *dd_blkcg_from_bio(struct bio *bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) int dd_activate_policy(struct request_queue *q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) void dd_deactivate_policy(struct request_queue *q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) int __init dd_blkcg_init(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) void __exit dd_blkcg_exit(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) #else /* CONFIG_BLK_CGROUP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) static inline struct dd_blkcg *dd_blkcg_from_bio(struct bio *bio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) static inline int dd_activate_policy(struct request_queue *q)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) static inline void dd_deactivate_policy(struct request_queue *q)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) static inline int dd_blkcg_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) static inline void dd_blkcg_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) #endif /* CONFIG_BLK_CGROUP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) #endif /* _MQ_DEADLINE_CGROUP_H_ */