]> git.sesse.net Git - bcachefs-tools-debian/blob - libbcache/stats.h
39877f9aa1327b15adde51187bd329fa2ab4fd7d
[bcachefs-tools-debian] / libbcache / stats.h
1 #ifndef _BCACHE_STATS_H_
2 #define _BCACHE_STATS_H_
3
4 #include "stats_types.h"
5
6 struct cache_set;
7 struct cached_dev;
8 struct bcache_device;
9
10 void bch_cache_accounting_init(struct cache_accounting *, struct closure *);
11 int bch_cache_accounting_add_kobjs(struct cache_accounting *, struct kobject *);
12 void bch_cache_accounting_clear(struct cache_accounting *);
13 void bch_cache_accounting_destroy(struct cache_accounting *);
14
15 static inline void mark_cache_stats(struct cache_stat_collector *stats,
16                                     bool hit, bool bypass)
17 {
18         atomic_inc(&stats->cache_hit_array[!bypass][!hit]);
19 }
20
21 static inline void bch_mark_cache_accounting(struct cache_set *c,
22                                              struct cached_dev *dc,
23                                              bool hit, bool bypass)
24 {
25         mark_cache_stats(&dc->accounting.collector, hit, bypass);
26         mark_cache_stats(&c->accounting.collector, hit, bypass);
27 }
28
29 static inline void bch_mark_sectors_bypassed(struct cache_set *c,
30                                              struct cached_dev *dc,
31                                              unsigned sectors)
32 {
33         atomic_add(sectors, &dc->accounting.collector.sectors_bypassed);
34         atomic_add(sectors, &c->accounting.collector.sectors_bypassed);
35 }
36
37 static inline void bch_mark_gc_write(struct cache_set *c, int sectors)
38 {
39         atomic_add(sectors, &c->accounting.collector.gc_write_sectors);
40 }
41
42 static inline void bch_mark_foreground_write(struct cache_set *c, int sectors)
43 {
44         atomic_add(sectors, &c->accounting.collector.foreground_write_sectors);
45 }
46
47 static inline void bch_mark_discard(struct cache_set *c, int sectors)
48 {
49         atomic_add(sectors, &c->accounting.collector.discard_sectors);
50 }
51
52 #endif /* _BCACHE_STATS_H_ */