linux/drivers/md/bcache/stats.c

// SPDX-License-Identifier: GPL-2.0
/*
 * bcache stats code
 *
 * Copyright 2012 Google, Inc.
 */

#include "bcache.h"
#include "stats.h"
#include "btree.h"
#include "sysfs.h"

/*
 * We keep absolute totals of various statistics, and addionally a set of three
 * rolling averages.
 *
 * Every so often, a timer goes off and rescales the rolling averages.
 * accounting_rescale[] is how many times the timer has to go off before we
 * rescale each set of numbers; that gets us half lives of 5 minutes, one hour,
 * and one day.
 *
 * accounting_delay is how often the timer goes off - 22 times in 5 minutes,
 * and accounting_weight is what we use to rescale:
 *
 * pow(31 / 32, 22) ~= 1/2
 *
 * So that we don't have to increment each set of numbers every time we (say)
 * get a cache hit, we increment a single atomic_t in acc->collector, and when
 * the rescale function runs it resets the atomic counter to 0 and adds its
 * old value to each of the exported numbers.
 *
 * To reduce rounding error, the numbers in struct cache_stats are all
 * stored left shifted by 16, and scaled back in the sysfs show() function.
 */

static const unsigned int DAY_RESCALE		=;
static const unsigned int HOUR_RESCALE		=;
static const unsigned int FIVE_MINUTE_RESCALE	=;
static const unsigned int accounting_delay	=;
static const unsigned int accounting_weight	=;

/* sysfs reading/writing */

read_attribute(cache_hits);
read_attribute(cache_misses);
read_attribute(cache_bypass_hits);
read_attribute(cache_bypass_misses);
read_attribute(cache_hit_ratio);
read_attribute(cache_miss_collisions);
read_attribute(bypassed);

SHOW(bch_stats)
{}

STORE(bch_stats)
{}

static void bch_stats_release(struct kobject *k)
{}

static struct attribute *bch_stats_attrs[] =;
ATTRIBUTE_GROUPS();
static KTYPE(bch_stats);

int bch_cache_accounting_add_kobjs(struct cache_accounting *acc,
				   struct kobject *parent)
{}

void bch_cache_accounting_clear(struct cache_accounting *acc)
{}

void bch_cache_accounting_destroy(struct cache_accounting *acc)
{}

/* EWMA scaling */

static void scale_stat(unsigned long *stat)
{}

static void scale_stats(struct cache_stats *stats, unsigned long rescale_at)
{}

static void scale_accounting(struct timer_list *t)
{}

static void mark_cache_stats(struct cache_stat_collector *stats,
			     bool hit, bool bypass)
{}

void bch_mark_cache_accounting(struct cache_set *c, struct bcache_device *d,
			       bool hit, bool bypass)
{}

void bch_mark_cache_miss_collision(struct cache_set *c, struct bcache_device *d)
{}

void bch_mark_sectors_bypassed(struct cache_set *c, struct cached_dev *dc,
			       int sectors)
{}

void bch_cache_accounting_init(struct cache_accounting *acc,
			       struct closure *parent)
{}