/* SPDX-License-Identifier: GPL-2.0 */ /* * bch2_time_stats - collect statistics on events that have a duration, with nicely * formatted textual output on demand * * - percpu buffering of event collection: cheap enough to shotgun * everywhere without worrying about overhead * * tracks: * - number of events * - maximum event duration ever seen * - sum of all event durations * - average event duration, standard and weighted * - standard deviation of event durations, standard and weighted * and analagous statistics for the frequency of events * * We provide both mean and weighted mean (exponentially weighted), and standard * deviation and weighted standard deviation, to give an efficient-to-compute * view of current behaviour versus. average behaviour - "did this event source * just become wonky, or is this typical?". * * Particularly useful for tracking down latency issues. */ #ifndef _BCACHEFS_TIME_STATS_H #define _BCACHEFS_TIME_STATS_H #include <linux/sched/clock.h> #include <linux/spinlock_types.h> #include <linux/string.h> #include "mean_and_variance.h" struct time_unit { … }; /* * given a nanosecond value, pick the preferred time units for printing: */ const struct time_unit *bch2_pick_time_units(u64 ns); /* * quantiles - do not use: * * Only enabled if bch2_time_stats->quantiles_enabled has been manually set - don't * use in new code. */ #define NR_QUANTILES … #define QUANTILE_IDX(i) … #define QUANTILE_FIRST … #define QUANTILE_LAST … struct quantiles { … }; struct time_stat_buffer { … }; struct bch2_time_stats { … }; struct bch2_time_stats_quantiles { … }; static inline struct quantiles *time_stats_to_quantiles(struct bch2_time_stats *stats) { … } void __bch2_time_stats_clear_buffer(struct bch2_time_stats *, struct time_stat_buffer *); void __bch2_time_stats_update(struct bch2_time_stats *stats, u64, u64); /** * time_stats_update - collect a new event being tracked * * @stats - bch2_time_stats to update * @start - start time of event, recorded with local_clock() * * The end duration of the event will be the current time */ static inline void bch2_time_stats_update(struct bch2_time_stats *stats, u64 start) { … } /** * track_event_change - track state change events * * @stats - bch2_time_stats to update * @v - new state, true or false * * Use this when tracking time stats for state changes, i.e. resource X becoming * blocked/unblocked. */ static inline bool track_event_change(struct bch2_time_stats *stats, bool v) { … } void bch2_time_stats_exit(struct bch2_time_stats *); void bch2_time_stats_init(struct bch2_time_stats *); static inline void bch2_time_stats_quantiles_exit(struct bch2_time_stats_quantiles *statq) { … } static inline void bch2_time_stats_quantiles_init(struct bch2_time_stats_quantiles *statq) { … } #endif /* _BCACHEFS_TIME_STATS_H */