xref: /openbmc/linux/block/blk-stat.h (revision 8730046c)
1 #ifndef BLK_STAT_H
2 #define BLK_STAT_H
3 
4 /*
5  * ~0.13s window as a power-of-2 (2^27 nsecs)
6  */
7 #define BLK_STAT_NSEC		134217728ULL
8 #define BLK_STAT_NSEC_MASK	~(BLK_STAT_NSEC - 1)
9 
10 /*
11  * Upper 3 bits can be used elsewhere
12  */
13 #define BLK_STAT_RES_BITS	3
14 #define BLK_STAT_SHIFT		(64 - BLK_STAT_RES_BITS)
15 #define BLK_STAT_TIME_MASK	((1ULL << BLK_STAT_SHIFT) - 1)
16 #define BLK_STAT_MASK		~BLK_STAT_TIME_MASK
17 
18 enum {
19 	BLK_STAT_READ	= 0,
20 	BLK_STAT_WRITE,
21 };
22 
23 void blk_stat_add(struct blk_rq_stat *, struct request *);
24 void blk_hctx_stat_get(struct blk_mq_hw_ctx *, struct blk_rq_stat *);
25 void blk_queue_stat_get(struct request_queue *, struct blk_rq_stat *);
26 void blk_stat_clear(struct request_queue *);
27 void blk_stat_init(struct blk_rq_stat *);
28 bool blk_stat_is_current(struct blk_rq_stat *);
29 void blk_stat_set_issue_time(struct blk_issue_stat *);
30 bool blk_stat_enable(struct request_queue *);
31 
32 static inline u64 __blk_stat_time(u64 time)
33 {
34 	return time & BLK_STAT_TIME_MASK;
35 }
36 
37 static inline u64 blk_stat_time(struct blk_issue_stat *stat)
38 {
39 	return __blk_stat_time(stat->time);
40 }
41 
42 #endif
43