xref: /linux/drivers/md/bcache/stats.h (revision 24bce201d79807b668bf9d9e0aca801c5c0d5f78)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _BCACHE_STATS_H_
3 #define _BCACHE_STATS_H_
4 
5 struct cache_stat_collector {
6 	atomic_t cache_hits;
7 	atomic_t cache_misses;
8 	atomic_t cache_bypass_hits;
9 	atomic_t cache_bypass_misses;
10 	atomic_t cache_miss_collisions;
11 	atomic_t sectors_bypassed;
12 };
13 
14 struct cache_stats {
15 	struct kobject		kobj;
16 
17 	unsigned long cache_hits;
18 	unsigned long cache_misses;
19 	unsigned long cache_bypass_hits;
20 	unsigned long cache_bypass_misses;
21 	unsigned long cache_readaheads;
22 	unsigned long cache_miss_collisions;
23 	unsigned long sectors_bypassed;
24 
25 	unsigned int		rescale;
26 };
27 
28 struct cache_accounting {
29 	struct closure		cl;
30 	struct timer_list	timer;
31 	atomic_t		closing;
32 
33 	struct cache_stat_collector collector;
34 
35 	struct cache_stats total;
36 	struct cache_stats five_minute;
37 	struct cache_stats hour;
38 	struct cache_stats day;
39 };
40 
41 struct cache_set;
42 struct cached_dev;
43 struct bcache_device;
44 
45 void bch_cache_accounting_init(struct cache_accounting *acc,
46 			       struct closure *parent);
47 
48 int bch_cache_accounting_add_kobjs(struct cache_accounting *acc,
49 				   struct kobject *parent);
50 
51 void bch_cache_accounting_clear(struct cache_accounting *acc);
52 
53 void bch_cache_accounting_destroy(struct cache_accounting *acc);
54 
55 void bch_mark_cache_accounting(struct cache_set *c, struct bcache_device *d,
56 			       bool hit, bool bypass);
57 void bch_mark_cache_readahead(struct cache_set *c, struct bcache_device *d);
58 void bch_mark_cache_miss_collision(struct cache_set *c,
59 				   struct bcache_device *d);
60 void bch_mark_sectors_bypassed(struct cache_set *c,
61 			       struct cached_dev *dc,
62 			       int sectors);
63 
64 #endif /* _BCACHE_STATS_H_ */
65