Force lfsr_file_sync_ off the stack hot-path

This adds LFS_NOINLINE, and forces lfsr_file_sync_ (the commit logic in
lfsr_file_sync) off the stack hot-path.

This adds a bit of code, function calls are surprisingly expensive, but
saves a nice big chunk of stack:

           code          stack          ctx
  before: 35992           2408          636
  after:  36016 (+0.1%)   2296 (-4.7%)  636 (+0.0%)

Well, maybe not _real_ stack. The fact that this worked suggests the
real stack usage is less than our measured value.

The reason is because our stack.py script is relatively simple. It just
adds together stack frames based on the callgraph at compile time, which
misses shrinkwrapping and similar optimizations. Unfortunately that sort
of information is simply not available via GCC short of parsing the
disassembly.

But this is the number that will be used for statically allocated stacks,
and of course the number that will probably end up associated with
littlefs, so it still seems like a worthwhile number to "optimize" for.

Maybe in the future this will be different as tooling around stack
measurements improves.

---

The other benefit of moving lfsr_file_sync_ off the hot-path is that we
now no longer incorrectly include the sync commit context in the
hot-path. This tells a much different story for the cost of 1-commit
shrubs:

                     code          stack          ctx
  before 1c-shrubs: 35848           2296          636
  after 1c-shrubs:  36016 (+0.5%)   2296 (+0.0%)  636 (+0.0%)
This commit is contained in:
Christopher Haster
2025-05-16 13:24:25 -05:00
parent b6a0b7afe2
commit 930fe6e67c
2 changed files with 62 additions and 40 deletions
+7
View File
@@ -274,6 +274,13 @@
#define LFS_FORCEINLINE
#endif
// Force a function to _not_ be inlined
#if !defined(LFS_NO_BUILTINS) && defined(__GNUC__)
#define LFS_NOINLINE __attribute__((noinline))
#else
#define LFS_NOINLINE
#endif
// Builtin functions, these may be replaced by more efficient
// toolchain-specific implementations. LFS_NO_BUILTINS falls back to a more