From 74644030098a0c4932e194fa1b2fa052226f3868 Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Mon, 27 Nov 2023 22:37:27 -0500 Subject: [PATCH] bcachefs: count_event() Small helper for event counters. Signed-off-by: Kent Overstreet --- fs/bcachefs/alloc_background.c | 2 +- fs/bcachefs/bcachefs.h | 4 +++- fs/bcachefs/data_update.c | 2 +- fs/bcachefs/move.c | 3 ++- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/fs/bcachefs/alloc_background.c b/fs/bcachefs/alloc_background.c index ccc3779dd366..6e719dd09e31 100644 --- a/fs/bcachefs/alloc_background.c +++ b/fs/bcachefs/alloc_background.c @@ -1674,7 +1674,7 @@ write: if (ret) goto out; - this_cpu_inc(c->counters[BCH_COUNTER_bucket_discard]); + count_event(c, bucket_discard); (*discarded)++; out: (*seen)++; diff --git a/fs/bcachefs/bcachefs.h b/fs/bcachefs/bcachefs.h index 4186779f1e44..06b5cea9980e 100644 --- a/fs/bcachefs/bcachefs.h +++ b/fs/bcachefs/bcachefs.h @@ -223,9 +223,11 @@ #define race_fault(...) dynamic_fault("bcachefs:race") +#define count_event(_c, _name) this_cpu_inc((_c)->counters[BCH_COUNTER_##_name]) + #define trace_and_count(_c, _name, ...) \ do { \ - this_cpu_inc((_c)->counters[BCH_COUNTER_##_name]); \ + count_event(_c, _name); \ trace_##_name(__VA_ARGS__); \ } while (0) diff --git a/fs/bcachefs/data_update.c b/fs/bcachefs/data_update.c index 488279b3d08e..59b558c25977 100644 --- a/fs/bcachefs/data_update.c +++ b/fs/bcachefs/data_update.c @@ -321,7 +321,7 @@ nowork: &m->stats->sectors_raced); } - this_cpu_inc(c->counters[BCH_COUNTER_move_extent_fail]); + count_event(c, move_extent_fail); bch2_btree_iter_advance(&iter); goto next; diff --git a/fs/bcachefs/move.c b/fs/bcachefs/move.c index eafa80c18ba4..a6db46a70f15 100644 --- a/fs/bcachefs/move.c +++ b/fs/bcachefs/move.c @@ -349,7 +349,8 @@ err: bch2_err_matches(ret, BCH_ERR_transaction_restart)) return ret; - this_cpu_inc(c->counters[BCH_COUNTER_move_extent_start_fail]); + count_event(c, move_extent_start_fail); + if (trace_move_extent_start_fail_enabled()) { struct printbuf buf = PRINTBUF; -- 2.39.5