Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * bcache stats code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright 2012 Google, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include "bcache.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include "stats.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include "btree.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include "sysfs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  * We keep absolute totals of various statistics, and addionally a set of three
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  * rolling averages.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  * Every so often, a timer goes off and rescales the rolling averages.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  * accounting_rescale[] is how many times the timer has to go off before we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  * rescale each set of numbers; that gets us half lives of 5 minutes, one hour,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  * and one day.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  * accounting_delay is how often the timer goes off - 22 times in 5 minutes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  * and accounting_weight is what we use to rescale:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  * pow(31 / 32, 22) ~= 1/2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  * So that we don't have to increment each set of numbers every time we (say)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  * get a cache hit, we increment a single atomic_t in acc->collector, and when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  * the rescale function runs it resets the atomic counter to 0 and adds its
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  * old value to each of the exported numbers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)  * To reduce rounding error, the numbers in struct cache_stats are all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  * stored left shifted by 16, and scaled back in the sysfs show() function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) static const unsigned int DAY_RESCALE		= 288;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) static const unsigned int HOUR_RESCALE		= 12;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) static const unsigned int FIVE_MINUTE_RESCALE	= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) static const unsigned int accounting_delay	= (HZ * 300) / 22;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) static const unsigned int accounting_weight	= 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) /* sysfs reading/writing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) read_attribute(cache_hits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) read_attribute(cache_misses);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) read_attribute(cache_bypass_hits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) read_attribute(cache_bypass_misses);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) read_attribute(cache_hit_ratio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) read_attribute(cache_readaheads);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) read_attribute(cache_miss_collisions);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) read_attribute(bypassed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) SHOW(bch_stats)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	struct cache_stats *s =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 		container_of(kobj, struct cache_stats, kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) #define var(stat)		(s->stat >> 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	var_print(cache_hits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	var_print(cache_misses);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	var_print(cache_bypass_hits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	var_print(cache_bypass_misses);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	sysfs_print(cache_hit_ratio,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 		    DIV_SAFE(var(cache_hits) * 100,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 			     var(cache_hits) + var(cache_misses)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	var_print(cache_readaheads);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	var_print(cache_miss_collisions);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	sysfs_hprint(bypassed,	var(sectors_bypassed) << 9);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) #undef var
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) STORE(bch_stats)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	return size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) static void bch_stats_release(struct kobject *k)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) static struct attribute *bch_stats_files[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	&sysfs_cache_hits,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	&sysfs_cache_misses,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	&sysfs_cache_bypass_hits,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	&sysfs_cache_bypass_misses,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	&sysfs_cache_hit_ratio,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	&sysfs_cache_readaheads,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	&sysfs_cache_miss_collisions,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	&sysfs_bypassed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) static KTYPE(bch_stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) int bch_cache_accounting_add_kobjs(struct cache_accounting *acc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 				   struct kobject *parent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	int ret = kobject_add(&acc->total.kobj, parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 			      "stats_total");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	ret = ret ?: kobject_add(&acc->five_minute.kobj, parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 				 "stats_five_minute");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	ret = ret ?: kobject_add(&acc->hour.kobj, parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 				 "stats_hour");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	ret = ret ?: kobject_add(&acc->day.kobj, parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 				 "stats_day");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) void bch_cache_accounting_clear(struct cache_accounting *acc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	acc->total.cache_hits = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	acc->total.cache_misses = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	acc->total.cache_bypass_hits = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	acc->total.cache_bypass_misses = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	acc->total.cache_readaheads = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	acc->total.cache_miss_collisions = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	acc->total.sectors_bypassed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) void bch_cache_accounting_destroy(struct cache_accounting *acc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	kobject_put(&acc->total.kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	kobject_put(&acc->five_minute.kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	kobject_put(&acc->hour.kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	kobject_put(&acc->day.kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	atomic_set(&acc->closing, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	if (del_timer_sync(&acc->timer))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		closure_return(&acc->cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) /* EWMA scaling */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) static void scale_stat(unsigned long *stat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	*stat =  ewma_add(*stat, 0, accounting_weight, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) static void scale_stats(struct cache_stats *stats, unsigned long rescale_at)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	if (++stats->rescale == rescale_at) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		stats->rescale = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		scale_stat(&stats->cache_hits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		scale_stat(&stats->cache_misses);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		scale_stat(&stats->cache_bypass_hits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		scale_stat(&stats->cache_bypass_misses);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		scale_stat(&stats->cache_readaheads);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		scale_stat(&stats->cache_miss_collisions);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		scale_stat(&stats->sectors_bypassed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) static void scale_accounting(struct timer_list *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	struct cache_accounting *acc = from_timer(acc, t, timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) #define move_stat(name) do {						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	unsigned int t = atomic_xchg(&acc->collector.name, 0);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	t <<= 16;							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	acc->five_minute.name += t;					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	acc->hour.name += t;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	acc->day.name += t;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	acc->total.name += t;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	move_stat(cache_hits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	move_stat(cache_misses);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	move_stat(cache_bypass_hits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	move_stat(cache_bypass_misses);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	move_stat(cache_readaheads);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	move_stat(cache_miss_collisions);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	move_stat(sectors_bypassed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	scale_stats(&acc->total, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	scale_stats(&acc->day, DAY_RESCALE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	scale_stats(&acc->hour, HOUR_RESCALE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	scale_stats(&acc->five_minute, FIVE_MINUTE_RESCALE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	acc->timer.expires += accounting_delay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	if (!atomic_read(&acc->closing))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		add_timer(&acc->timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		closure_return(&acc->cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) static void mark_cache_stats(struct cache_stat_collector *stats,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 			     bool hit, bool bypass)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	if (!bypass)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		if (hit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 			atomic_inc(&stats->cache_hits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 			atomic_inc(&stats->cache_misses);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		if (hit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 			atomic_inc(&stats->cache_bypass_hits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 			atomic_inc(&stats->cache_bypass_misses);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) void bch_mark_cache_accounting(struct cache_set *c, struct bcache_device *d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 			       bool hit, bool bypass)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	struct cached_dev *dc = container_of(d, struct cached_dev, disk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	mark_cache_stats(&dc->accounting.collector, hit, bypass);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	mark_cache_stats(&c->accounting.collector, hit, bypass);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) void bch_mark_cache_readahead(struct cache_set *c, struct bcache_device *d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	struct cached_dev *dc = container_of(d, struct cached_dev, disk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	atomic_inc(&dc->accounting.collector.cache_readaheads);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	atomic_inc(&c->accounting.collector.cache_readaheads);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) void bch_mark_cache_miss_collision(struct cache_set *c, struct bcache_device *d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	struct cached_dev *dc = container_of(d, struct cached_dev, disk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	atomic_inc(&dc->accounting.collector.cache_miss_collisions);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	atomic_inc(&c->accounting.collector.cache_miss_collisions);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) void bch_mark_sectors_bypassed(struct cache_set *c, struct cached_dev *dc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 			       int sectors)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	atomic_add(sectors, &dc->accounting.collector.sectors_bypassed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	atomic_add(sectors, &c->accounting.collector.sectors_bypassed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) void bch_cache_accounting_init(struct cache_accounting *acc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 			       struct closure *parent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	kobject_init(&acc->total.kobj,		&bch_stats_ktype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	kobject_init(&acc->five_minute.kobj,	&bch_stats_ktype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	kobject_init(&acc->hour.kobj,		&bch_stats_ktype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	kobject_init(&acc->day.kobj,		&bch_stats_ktype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	closure_init(&acc->cl, parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	timer_setup(&acc->timer, scale_accounting, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	acc->timer.expires	= jiffies + accounting_delay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	add_timer(&acc->timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) }