From 6ede8afffe32a8bda7757380a25a09a6b2d44251 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Tue, 20 Feb 2024 01:22:16 -0600 Subject: [PATCH] Changed lfsr_bd_set to hijack the rcache This is a compromise between using a small hardcoded buffer and cache-access during progs. Instead of getting direct access to the pcache during progs, we just hijack the rcache, forcefully evicting any contents it might have. This gets us cache-access (of at least some cache) without needing to rewrite lfsr_bd_prog. The downside is this may result in more rcache misses. Though the use of lfsr_bd_set is fairly niche in littlefs, so hopefully this doesn't become a problem. Code changes: code stack before: 33796 2880 after: 33792 (-0.0%) 2872 (-0.3%) --- lfs.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lfs.c b/lfs.c index 039abf3f..b3ef6932 100644 --- a/lfs.c +++ b/lfs.c @@ -528,15 +528,13 @@ static int lfsr_bd_cpy(lfs_t *lfs, static int lfsr_bd_set(lfs_t *lfs, lfs_block_t block, lfs_size_t off, uint8_t c, lfs_size_t size, uint32_t *cksum_, uint32_t *flcksum_) { - // just use a small hardcoded buffer - // - // this function is quite a bit more niche than the read-related utils - uint8_t buf[4]; - memset(buf, c, sizeof(buf)); + // hijack the rcache + lfsr_cache_drop(&lfs->rcache); + memset(lfs->rcache.buffer, c, lfs_min(size, lfs->cfg->cache_size)); while (size > 0) { - lfs_size_t d = lfs_min(size, sizeof(buf)); - int err = lfsr_bd_prog(lfs, block, off, buf, d, + lfs_size_t d = lfs_min(size, lfs->cfg->cache_size); + int err = lfsr_bd_prog(lfs, block, off, lfs->rcache.buffer, d, cksum_, flcksum_); if (err) { return err;