Moved revision count noise behind ifdef LFS_NOISY

littlefs is intentionally designed to not rely on noise, even with cksum
collisions (hello, perturb bit!). So it makes sense for this to be an
optional feature, even if it's a small one.

Disabling revision count noise by default also helps with testing. The
whole point of revision count noise is to make cksum collisions less
likely, which is a bit counterproductive when that's something we want
to test!

This doesn't really change the revision count encoding:

  vvvvrrrr rrrrrrnn nnnnnnnn nnnnnnnn
  '-.''----.----''---------.--------'
    '------|---------------|---------- 4-bit relocation revision
           '---------------|---------- recycle-bits recycle counter
                           '---------- pseudorandom noise (optional)

I considered moving the recycle-bits down when we're not adding noise,
but the extra logic just isn't worth making the revision count a bit
more human-readable.

---

This saves a small bit of code in the default build, at the cost of some
code for the runtime checks in the LFS_NOISY build. Though I'm hoping
future config work will let users opt-out of these runtime checks:

                    code          stack          ctx
  before:          38548           2624          640
  default after:   38508 (-0.1%)   2624 (+0.0%)  640 (+0.0%)
  LFS_NOISY after: 38568 (+0.1%)   2624 (+0.0%)  640 (+0.0%)

Honestly the thing I'm more worried about is using one of our precious
mount flags for this... There's not that many bits left!
This commit is contained in:
Christopher Haster
2025-01-29 13:44:00 -06:00
parent 0aef3cbcde
commit 415e6325d1
6 changed files with 193 additions and 138 deletions
+9
View File
@@ -26,6 +26,9 @@
// LFS_BIGGEST enables all opt-in features
#ifdef LFS_BIGGEST
#ifndef LFS_NOISY
#define LFS_NOISY
#endif
#ifndef LFS_CKPROGS
#define LFS_CKPROGS
#endif
@@ -189,6 +192,12 @@ extern "C"
// Some ifdef conveniences
#ifdef LFS_NOISY
#define LFS_IFDEF_NOISY(a, b) (a)
#else
#define LFS_IFDEF_NOISY(a, b) (b)
#endif
#ifdef LFS_CKPROGS
#define LFS_IFDEF_CKPROGS(a, b) (a)
#else