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