From 9d4b4d25576b74ad89fd821e69fc4ae4a2526a6f Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Mon, 12 Aug 2024 00:10:39 -0500 Subject: [PATCH] (Re?)adopted read hints in lfsr_bd_cmp/cmpck I'm not entirely sure what I was thinking when I thought we couldn't use read hints in lfsr_bd_cmp. It's true read hints will just be clobbered when ckprogs are enabled, but if ckprogs aren't enabled, and, perhaps more rarely, rcache_size > pcache_size, we should still be able to benefit from read hints in lfsr_bd_cmp. This has a bigger effect on ckreads, where we likely need to read trailing data to validate checksums/parity bits and can benefit from earlier reads keeping more data in the rcache. Curiously this actually saves a bit a code, not sure why that is: code stack before: 36428 2680 after: 36424 (-0.0%) 2680 (+0.0%) --- lfs.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/lfs.c b/lfs.c index 8a70ad71..260bc84a 100644 --- a/lfs.c +++ b/lfs.c @@ -616,8 +616,6 @@ static int lfsr_bd_cpy(lfs_t *lfs, lfs_block_t src_block, lfs_size_t src_off, lfs_size_t hint, lfs_size_t size, uint32_t *cksum, bool align) { - // we don't really use hint here because we go through our pcache - (void)hint; // must be in-bounds LFS_ASSERT(dst_block < lfs->block_count); LFS_ASSERT(dst_off+size <= lfs->cfg->block_size); @@ -626,6 +624,7 @@ static int lfsr_bd_cpy(lfs_t *lfs, lfs_size_t dst_off_ = dst_off; lfs_size_t src_off_ = src_off; + lfs_size_t hint_ = lfs_max(hint, size); // make sure hint >= size lfs_size_t size_ = size; while (size_ > 0) { // prefer the pcache here to avoid rcache conflicts with prog @@ -640,7 +639,7 @@ static int lfsr_bd_cpy(lfs_t *lfs, return err; } - err = lfsr_bd_read(lfs, src_block, src_off_, 0, + err = lfsr_bd_read(lfs, src_block, src_off_, hint_, buffer__, size__); if (err) { return err; @@ -653,6 +652,7 @@ static int lfsr_bd_cpy(lfs_t *lfs, dst_off_ += size__; src_off_ += size__; + hint_ -= size__; size_ -= size__; } @@ -1068,8 +1068,6 @@ static int lfsr_bd_cpyck_(lfs_t *lfs, lfs_size_t size, lfsr_ck_t ck, uint32_t *cksum, bool align) { - // we don't really use hint here because we go through our pcache - (void)hint; // must be in-bounds LFS_ASSERT(dst_block < lfs->block_count); LFS_ASSERT(dst_off+size <= lfs->cfg->block_size); @@ -1087,11 +1085,10 @@ static int lfsr_bd_cpyck_(lfs_t *lfs, return hint_; } - // TODO wait, why aren't we using hint here? - // copy the data while simultaneously updating our checksum lfs_size_t dst_off_ = dst_off; lfs_size_t src_off_ = src_off; + lfs_size_t hint__ = hint_; lfs_size_t size_ = size; while (size_ > 0) { // prefer the pcache here to avoid rcache conflicts with prog @@ -1106,7 +1103,7 @@ static int lfsr_bd_cpyck_(lfs_t *lfs, return err; } - err = lfsr_bd_read(lfs, src_block, src_off_, 0, + err = lfsr_bd_read(lfs, src_block, src_off_, hint__, buffer__, size__); if (err) { return err; @@ -1121,6 +1118,7 @@ static int lfsr_bd_cpyck_(lfs_t *lfs, dst_off_ += size__; src_off_ += size__; + hint__ -= size__; size_ -= size__; }