From: Kent Overstreet Date: Fri, 16 Jun 2023 22:55:07 +0000 (-0400) Subject: bcachefs: Don't call local_clock() twice in trans_begin() X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=f375d6ca58d5f28b9c0a3af449a0dd640ddcc6a1;p=linux.git bcachefs: Don't call local_clock() twice in trans_begin() local_clock() is not as cheap as we'd like it to be, alas Signed-off-by: Kent Overstreet --- diff --git a/fs/bcachefs/btree_iter.c b/fs/bcachefs/btree_iter.c index 0a62f55a3aa8a..d906bfb6754de 100644 --- a/fs/bcachefs/btree_iter.c +++ b/fs/bcachefs/btree_iter.c @@ -2850,6 +2850,7 @@ static noinline void bch2_trans_reset_srcu_lock(struct btree_trans *trans) u32 bch2_trans_begin(struct btree_trans *trans) { struct btree_path *path; + u64 now; bch2_trans_reset_updates(trans); @@ -2878,13 +2879,16 @@ u32 bch2_trans_begin(struct btree_trans *trans) path->preserve = false; } + now = local_clock(); if (!trans->restarted && (need_resched() || - local_clock() - trans->last_begin_time > BTREE_TRANS_MAX_LOCK_HOLD_TIME_NS)) { + now - trans->last_begin_time > BTREE_TRANS_MAX_LOCK_HOLD_TIME_NS)) { bch2_trans_unlock(trans); cond_resched(); bch2_trans_relock(trans); + now = local_clock(); } + trans->last_begin_time = now; if (unlikely(time_after(jiffies, trans->srcu_lock_time + msecs_to_jiffies(10)))) bch2_trans_reset_srcu_lock(trans); @@ -2895,7 +2899,6 @@ u32 bch2_trans_begin(struct btree_trans *trans) trans->notrace_relock_fail = false; } - trans->last_begin_time = local_clock(); return trans->restart_count; }