![]() |
|
|||
0001 /* SPDX-License-Identifier: GPL-2.0 */ 0002 #ifndef BLK_STAT_H 0003 #define BLK_STAT_H 0004 0005 #include <linux/kernel.h> 0006 #include <linux/blkdev.h> 0007 #include <linux/ktime.h> 0008 #include <linux/rcupdate.h> 0009 #include <linux/timer.h> 0010 0011 /** 0012 * struct blk_stat_callback - Block statistics callback. 0013 * 0014 * A &struct blk_stat_callback is associated with a &struct request_queue. While 0015 * @timer is active, that queue's request completion latencies are sorted into 0016 * buckets by @bucket_fn and added to a per-cpu buffer, @cpu_stat. When the 0017 * timer fires, @cpu_stat is flushed to @stat and @timer_fn is invoked. 0018 */ 0019 struct blk_stat_callback { 0020 /* 0021 * @list: RCU list of callbacks for a &struct request_queue. 0022 */ 0023 struct list_head list; 0024 0025 /** 0026 * @timer: Timer for the next callback invocation. 0027 */ 0028 struct timer_list timer; 0029 0030 /** 0031 * @cpu_stat: Per-cpu statistics buckets. 0032 */ 0033 struct blk_rq_stat __percpu *cpu_stat; 0034 0035 /** 0036 * @bucket_fn: Given a request, returns which statistics bucket it 0037 * should be accounted under. Return -1 for no bucket for this 0038 * request. 0039 */ 0040 int (*bucket_fn)(const struct request *); 0041 0042 /** 0043 * @buckets: Number of statistics buckets. 0044 */ 0045 unsigned int buckets; 0046 0047 /** 0048 * @stat: Array of statistics buckets. 0049 */ 0050 struct blk_rq_stat *stat; 0051 0052 /** 0053 * @fn: Callback function. 0054 */ 0055 void (*timer_fn)(struct blk_stat_callback *); 0056 0057 /** 0058 * @data: Private pointer for the user. 0059 */ 0060 void *data; 0061 0062 struct rcu_head rcu; 0063 }; 0064 0065 struct blk_queue_stats *blk_alloc_queue_stats(void); 0066 void blk_free_queue_stats(struct blk_queue_stats *); 0067 bool blk_stats_alloc_enable(struct request_queue *q); 0068 0069 void blk_stat_add(struct request *rq, u64 now); 0070 0071 /* record time/size info in request but not add a callback */ 0072 void blk_stat_enable_accounting(struct request_queue *q); 0073 void blk_stat_disable_accounting(struct request_queue *q); 0074 0075 /** 0076 * blk_stat_alloc_callback() - Allocate a block statistics callback. 0077 * @timer_fn: Timer callback function. 0078 * @bucket_fn: Bucket callback function. 0079 * @buckets: Number of statistics buckets. 0080 * @data: Value for the @data field of the &struct blk_stat_callback. 0081 * 0082 * See &struct blk_stat_callback for details on the callback functions. 0083 * 0084 * Return: &struct blk_stat_callback on success or NULL on ENOMEM. 0085 */ 0086 struct blk_stat_callback * 0087 blk_stat_alloc_callback(void (*timer_fn)(struct blk_stat_callback *), 0088 int (*bucket_fn)(const struct request *), 0089 unsigned int buckets, void *data); 0090 0091 /** 0092 * blk_stat_add_callback() - Add a block statistics callback to be run on a 0093 * request queue. 0094 * @q: The request queue. 0095 * @cb: The callback. 0096 * 0097 * Note that a single &struct blk_stat_callback can only be added to a single 0098 * &struct request_queue. 0099 */ 0100 void blk_stat_add_callback(struct request_queue *q, 0101 struct blk_stat_callback *cb); 0102 0103 /** 0104 * blk_stat_remove_callback() - Remove a block statistics callback from a 0105 * request queue. 0106 * @q: The request queue. 0107 * @cb: The callback. 0108 * 0109 * When this returns, the callback is not running on any CPUs and will not be 0110 * called again unless readded. 0111 */ 0112 void blk_stat_remove_callback(struct request_queue *q, 0113 struct blk_stat_callback *cb); 0114 0115 /** 0116 * blk_stat_free_callback() - Free a block statistics callback. 0117 * @cb: The callback. 0118 * 0119 * @cb may be NULL, in which case this does nothing. If it is not NULL, @cb must 0120 * not be associated with a request queue. I.e., if it was previously added with 0121 * blk_stat_add_callback(), it must also have been removed since then with 0122 * blk_stat_remove_callback(). 0123 */ 0124 void blk_stat_free_callback(struct blk_stat_callback *cb); 0125 0126 /** 0127 * blk_stat_is_active() - Check if a block statistics callback is currently 0128 * gathering statistics. 0129 * @cb: The callback. 0130 */ 0131 static inline bool blk_stat_is_active(struct blk_stat_callback *cb) 0132 { 0133 return timer_pending(&cb->timer); 0134 } 0135 0136 /** 0137 * blk_stat_activate_nsecs() - Gather block statistics during a time window in 0138 * nanoseconds. 0139 * @cb: The callback. 0140 * @nsecs: Number of nanoseconds to gather statistics for. 0141 * 0142 * The timer callback will be called when the window expires. 0143 */ 0144 static inline void blk_stat_activate_nsecs(struct blk_stat_callback *cb, 0145 u64 nsecs) 0146 { 0147 mod_timer(&cb->timer, jiffies + nsecs_to_jiffies(nsecs)); 0148 } 0149 0150 static inline void blk_stat_deactivate(struct blk_stat_callback *cb) 0151 { 0152 del_timer_sync(&cb->timer); 0153 } 0154 0155 /** 0156 * blk_stat_activate_msecs() - Gather block statistics during a time window in 0157 * milliseconds. 0158 * @cb: The callback. 0159 * @msecs: Number of milliseconds to gather statistics for. 0160 * 0161 * The timer callback will be called when the window expires. 0162 */ 0163 static inline void blk_stat_activate_msecs(struct blk_stat_callback *cb, 0164 unsigned int msecs) 0165 { 0166 mod_timer(&cb->timer, jiffies + msecs_to_jiffies(msecs)); 0167 } 0168 0169 void blk_rq_stat_add(struct blk_rq_stat *, u64); 0170 void blk_rq_stat_sum(struct blk_rq_stat *, struct blk_rq_stat *); 0171 void blk_rq_stat_init(struct blk_rq_stat *); 0172 0173 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |