]> git.sesse.net Git - bcachefs-tools-debian/blob - libbcache/stats.h
Delete more unused shim code, update bcache code
[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 #ifndef NO_BCACHE_ACCOUNTING
11
12 void bch_cache_accounting_init(struct cache_accounting *, struct closure *);
13 int bch_cache_accounting_add_kobjs(struct cache_accounting *, struct kobject *);
14 void bch_cache_accounting_clear(struct cache_accounting *);
15 void bch_cache_accounting_destroy(struct cache_accounting *);
16
17 #else
18
19 static inline void bch_cache_accounting_init(struct cache_accounting *acc,
20                                              struct closure *cl) {}
21 static inline int bch_cache_accounting_add_kobjs(struct cache_accounting *acc,
22                                                  struct kobject *cl)
23 {
24         return 0;
25 }
26 static inline void bch_cache_accounting_clear(struct cache_accounting *acc) {}
27 static inline void bch_cache_accounting_destroy(struct cache_accounting *acc) {}
28
29 #endif
30
31 static inline void mark_cache_stats(struct cache_stat_collector *stats,
32                                     bool hit, bool bypass)
33 {
34         atomic_inc(&stats->cache_hit_array[!bypass][!hit]);
35 }
36
37 static inline void bch_mark_cache_accounting(struct cache_set *c,
38                                              struct cached_dev *dc,
39                                              bool hit, bool bypass)
40 {
41         mark_cache_stats(&dc->accounting.collector, hit, bypass);
42         mark_cache_stats(&c->accounting.collector, hit, bypass);
43 }
44
45 static inline void bch_mark_sectors_bypassed(struct cache_set *c,
46                                              struct cached_dev *dc,
47                                              unsigned sectors)
48 {
49         atomic_add(sectors, &dc->accounting.collector.sectors_bypassed);
50         atomic_add(sectors, &c->accounting.collector.sectors_bypassed);
51 }
52
53 static inline void bch_mark_gc_write(struct cache_set *c, int sectors)
54 {
55         atomic_add(sectors, &c->accounting.collector.gc_write_sectors);
56 }
57
58 static inline void bch_mark_foreground_write(struct cache_set *c, int sectors)
59 {
60         atomic_add(sectors, &c->accounting.collector.foreground_write_sectors);
61 }
62
63 static inline void bch_mark_discard(struct cache_set *c, int sectors)
64 {
65         atomic_add(sectors, &c->accounting.collector.discard_sectors);
66 }
67
68 #endif /* _BCACHE_STATS_H_ */