Commit f375d6ca authored by Kent Overstreet's avatar Kent Overstreet

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: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 962210b2
...@@ -2850,6 +2850,7 @@ static noinline void bch2_trans_reset_srcu_lock(struct btree_trans *trans) ...@@ -2850,6 +2850,7 @@ static noinline void bch2_trans_reset_srcu_lock(struct btree_trans *trans)
u32 bch2_trans_begin(struct btree_trans *trans) u32 bch2_trans_begin(struct btree_trans *trans)
{ {
struct btree_path *path; struct btree_path *path;
u64 now;
bch2_trans_reset_updates(trans); bch2_trans_reset_updates(trans);
...@@ -2878,13 +2879,16 @@ u32 bch2_trans_begin(struct btree_trans *trans) ...@@ -2878,13 +2879,16 @@ u32 bch2_trans_begin(struct btree_trans *trans)
path->preserve = false; path->preserve = false;
} }
now = local_clock();
if (!trans->restarted && if (!trans->restarted &&
(need_resched() || (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); bch2_trans_unlock(trans);
cond_resched(); cond_resched();
bch2_trans_relock(trans); 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)))) if (unlikely(time_after(jiffies, trans->srcu_lock_time + msecs_to_jiffies(10))))
bch2_trans_reset_srcu_lock(trans); bch2_trans_reset_srcu_lock(trans);
...@@ -2895,7 +2899,6 @@ u32 bch2_trans_begin(struct btree_trans *trans) ...@@ -2895,7 +2899,6 @@ u32 bch2_trans_begin(struct btree_trans *trans)
trans->notrace_relock_fail = false; trans->notrace_relock_fail = false;
} }
trans->last_begin_time = local_clock();
return trans->restart_count; return trans->restart_count;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment