From 273960b8f374b95ebd234a99607b7887f515c791 Mon Sep 17 00:00:00 2001 From: "Darrick J. Wong" Date: Thu, 1 Feb 2024 12:41:42 -0800 Subject: bcachefs: time_stats: split stats-with-quantiles into a separate structure Currently, struct time_stats has the optional ability to quantize the information that it collects. This is /probably/ useful for callers who want to see quantized information, but it more than doubles the size of the structure from 224 bytes to 464. For users who don't care about that (e.g. upcoming xfs patches) and want to avoid wasting 240 bytes per counter, split the two into separate pieces. Signed-off-by: Darrick J. Wong Signed-off-by: Kent Overstreet --- fs/bcachefs/time_stats.h | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'fs/bcachefs/time_stats.h') diff --git a/fs/bcachefs/time_stats.h b/fs/bcachefs/time_stats.h index fd6e442443f9..ed6c03c436c0 100644 --- a/fs/bcachefs/time_stats.h +++ b/fs/bcachefs/time_stats.h @@ -26,6 +26,7 @@ #include #include +#include #include "mean_and_variance.h" @@ -68,7 +69,7 @@ struct time_stat_buffer { struct bch2_time_stats { spinlock_t lock; - bool quantiles_enabled; + bool have_quantiles; /* all fields are in nanoseconds */ u64 min_duration; u64 max_duration; @@ -77,7 +78,6 @@ struct bch2_time_stats { u64 min_freq; u64 last_event; u64 last_event_start; - struct quantiles quantiles; struct mean_and_variance duration_stats; struct mean_and_variance freq_stats; @@ -90,6 +90,18 @@ struct bch2_time_stats { struct time_stat_buffer __percpu *buffer; }; +struct bch2_time_stats_quantiles { + struct bch2_time_stats stats; + struct quantiles quantiles; +}; + +static inline struct quantiles *time_stats_to_quantiles(struct bch2_time_stats *stats) +{ + return stats->have_quantiles + ? &container_of(stats, struct bch2_time_stats_quantiles, stats)->quantiles + : NULL; +} + 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); @@ -133,4 +145,15 @@ 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) +{ + bch2_time_stats_exit(&statq->stats); +} +static inline void bch2_time_stats_quantiles_init(struct bch2_time_stats_quantiles *statq) +{ + bch2_time_stats_init(&statq->stats); + statq->stats.have_quantiles = true; + memset(&statq->quantiles, 0, sizeof(statq->quantiles)); +} + #endif /* _BCACHEFS_TIME_STATS_H */ -- cgit v1.2.3