Commit 307e3c13 authored by Kent Overstreet's avatar Kent Overstreet

bcachefs: Optimize bch2_trans_init()

Now we store the transaction's fn idx in a local variable, instead of
redoing the lookup every time we call bch2_trans_init().
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 29aa78f1
......@@ -929,7 +929,6 @@ mempool_t bio_bounce_pages;
struct bch2_time_stats times[BCH_TIME_STAT_NR];
const char *btree_transaction_fns[BCH_TRANSACTIONS_NR];
struct btree_transaction_stats btree_transaction_stats[BCH_TRANSACTIONS_NR];
};
......
......@@ -2841,15 +2841,16 @@ static void bch2_trans_alloc_paths(struct btree_trans *trans, struct bch_fs *c)
trans->updates = p; p += updates_bytes;
}
static inline unsigned bch2_trans_get_fn_idx(struct btree_trans *trans, struct bch_fs *c,
const char *fn)
const char *bch2_btree_transaction_fns[BCH_TRANSACTIONS_NR];
unsigned bch2_trans_get_fn_idx(const char *fn)
{
unsigned i;
for (i = 0; i < ARRAY_SIZE(c->btree_transaction_fns); i++)
if (!c->btree_transaction_fns[i] ||
c->btree_transaction_fns[i] == fn) {
c->btree_transaction_fns[i] = fn;
for (i = 0; i < ARRAY_SIZE(bch2_btree_transaction_fns); i++)
if (!bch2_btree_transaction_fns[i] ||
bch2_btree_transaction_fns[i] == fn) {
bch2_btree_transaction_fns[i] = fn;
return i;
}
......@@ -2857,16 +2858,17 @@ static inline unsigned bch2_trans_get_fn_idx(struct btree_trans *trans, struct b
return i;
}
void __bch2_trans_init(struct btree_trans *trans, struct bch_fs *c, const char *fn)
void __bch2_trans_init(struct btree_trans *trans, struct bch_fs *c, unsigned fn_idx)
__acquires(&c->btree_trans_barrier)
{
struct btree_transaction_stats *s;
memset(trans, 0, sizeof(*trans));
trans->c = c;
trans->fn = fn;
trans->fn = fn_idx < ARRAY_SIZE(bch2_btree_transaction_fns)
? bch2_btree_transaction_fns[fn_idx] : NULL;
trans->last_begin_time = local_clock();
trans->fn_idx = bch2_trans_get_fn_idx(trans, c, fn);
trans->fn_idx = fn_idx;
trans->locking_wait.task = current;
trans->journal_replay_not_finished =
!test_bit(JOURNAL_REPLAY_DONE, &c->journal.flags);
......
......@@ -587,10 +587,21 @@ void bch2_btree_path_to_text(struct printbuf *, struct btree_path *);
void bch2_trans_paths_to_text(struct printbuf *, struct btree_trans *);
void bch2_dump_trans_updates(struct btree_trans *);
void bch2_dump_trans_paths_updates(struct btree_trans *);
void __bch2_trans_init(struct btree_trans *, struct bch_fs *, const char *);
void __bch2_trans_init(struct btree_trans *, struct bch_fs *, unsigned);
void bch2_trans_exit(struct btree_trans *);
#define bch2_trans_init(_trans, _c, _nr_iters, _mem) __bch2_trans_init(_trans, _c, __func__)
extern const char *bch2_btree_transaction_fns[BCH_TRANSACTIONS_NR];
unsigned bch2_trans_get_fn_idx(const char *);
#define bch2_trans_init(_trans, _c, _nr_iters, _mem) \
do { \
static unsigned trans_fn_idx; \
\
if (unlikely(!trans_fn_idx)) \
trans_fn_idx = bch2_trans_get_fn_idx(__func__); \
\
__bch2_trans_init(_trans, _c, trans_fn_idx); \
} while (0)
void bch2_btree_trans_to_text(struct printbuf *, struct btree_trans *);
......
......@@ -638,11 +638,11 @@ static ssize_t lock_held_stats_read(struct file *file, char __user *buf,
if (!i->size)
break;
if (i->iter == ARRAY_SIZE(c->btree_transaction_fns) ||
!c->btree_transaction_fns[i->iter])
if (i->iter == ARRAY_SIZE(bch2_btree_transaction_fns) ||
!bch2_btree_transaction_fns[i->iter])
break;
prt_printf(&i->buf, "%s: ", c->btree_transaction_fns[i->iter]);
prt_printf(&i->buf, "%s: ", bch2_btree_transaction_fns[i->iter]);
prt_newline(&i->buf);
printbuf_indent_add(&i->buf, 2);
......
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