Carved out ckreads, disabled at compile-time by default
This moves all ckread-related logic behind the new opt-in compile-time
LFS_CKREADS flag. So in order to use ckreads you need to 1. define
LFS_CKREADS at compile time, and 2. pass LFS_M_CKREADS during
lfsr_mount.
This was always the plan since, even if ckreads worked perfectly, it
adds a significant amount of baggage (stack mostly) to track the
ck context of all reads.
---
This is the first non-trivial opt-in define in littlefs, so more test
framework features!
test.py and build.py now support the optional ifdef attribute, which
makes it easy to indicate a test suite/case should not be compiled when
a feature is missing.
Also interesting to note is the addition of LFS_IFDEF_CKREADS, which
solves several issues (and general ugliness) related to #ifdefs in
expression. For example:
// does not compile :( (can't embed ifdefs in macros)
LFS_ASSERT(flags == (
LFS_M_CKPROGS
#ifdef LFS_CKREADS
| LFS_M_CKREADS
#endif
))
// does compile :)
LFS_ASSERT(flags == (
LFS_M_CKPROGS
| LFS_IFDEF_CKREADS(LFS_M_CKREADS, 0)));
---
This brings us way back down to our pre-ckread levels of code/stack:
code stack
before-ckreads: 36352 2672
ckreads: 38060 (+4.7%) 3056 (+14.4%)
after-ckreads: 36428 (+0.2%) 2680 (+0.3%)
Unfortunately, we do end up with a bit more code cost than where we
started. Mainly due to code moving around to support the ckread
infrastructure:
code stack
lfsr_bd_readtag: +52 (+23.2%) +8 (+10.0%)
lfsr_rbyd_fetch: +36 (+5.0%) +8 (+6.2%, cold)
lfs_toleb128: -12 (-25.0%) -4 (-20.0%, cold)
total: +76 (+0.2%) +8 (+0.3%)
But oh well. Note that some of these changes are good even without
ckreads, such as only parsing the last ecksum tag.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
after = ['test_traversal', 'test_gc', 'test_mount']
|
||||
|
||||
|
||||
|
||||
# Test filesystem-level checksum things
|
||||
|
||||
# test we can detect at least fully clobbered blocks
|
||||
@@ -804,6 +805,7 @@ defines.BADBLOCK_BEHAVIOR = [
|
||||
]
|
||||
# this should stay inlined
|
||||
defines.SIZE = 'BLOCK_SIZE/16'
|
||||
ifdef = 'LFS_CKREADS'
|
||||
code = '''
|
||||
// test all bad bits in the mroot
|
||||
for (lfs_size_t i = 0;
|
||||
@@ -915,6 +917,7 @@ defines.BADBLOCK_BEHAVIOR = [
|
||||
]
|
||||
# this should create a single block file
|
||||
defines.SIZE = 'BLOCK_SIZE'
|
||||
ifdef = 'LFS_CKREADS'
|
||||
code = '''
|
||||
// first we need to figure out where the data block will actually
|
||||
// end up, fortunately our block randomization is intentionally
|
||||
@@ -1048,6 +1051,7 @@ defines.INLINE_SIZE = 0
|
||||
defines.CRYSTAL_THRESH = -1
|
||||
defines.FRAGMENT_SIZE = 'BLOCK_SIZE/8'
|
||||
defines.SIZE = '2*FRAGMENT_SIZE'
|
||||
ifdef = 'LFS_CKREADS'
|
||||
code = '''
|
||||
// first we need to figure out where the btree block will actually
|
||||
// end up, fortunately our block randomization is intentionally
|
||||
|
||||
@@ -18,13 +18,14 @@ defines.CKPROGS = [false, true]
|
||||
defines.CKREADS = [false, true]
|
||||
defines.FLUSH = [false, true]
|
||||
defines.SYNC = [false, true]
|
||||
if = 'LFS_IFDEF_CKREADS(true, !CKREADS)'
|
||||
code = '''
|
||||
lfs_t lfs;
|
||||
lfsr_format(&lfs, CFG) => 0;
|
||||
lfsr_mount(&lfs,
|
||||
((RDONLY) ? LFS_M_RDONLY : LFS_M_RDWR)
|
||||
| ((CKPROGS) ? LFS_M_CKPROGS : 0)
|
||||
| ((CKREADS) ? LFS_M_CKREADS : 0)
|
||||
| ((CKREADS) ? LFS_IFDEF_CKREADS(LFS_M_CKREADS, 0) : 0)
|
||||
| ((FLUSH) ? LFS_M_FLUSH : 0)
|
||||
| ((SYNC) ? LFS_M_SYNC : 0),
|
||||
CFG) => 0;
|
||||
@@ -34,7 +35,7 @@ code = '''
|
||||
assert(fsinfo.flags == (
|
||||
((RDONLY) ? LFS_I_RDONLY : 0)
|
||||
| ((CKPROGS) ? LFS_I_CKPROGS : 0)
|
||||
| ((CKREADS) ? LFS_I_CKREADS : 0)
|
||||
| ((CKREADS) ? LFS_IFDEF_CKREADS(LFS_I_CKREADS, 0) : 0)
|
||||
| ((FLUSH) ? LFS_I_FLUSH : 0)
|
||||
| ((SYNC) ? LFS_I_SYNC : 0)
|
||||
| LFS_I_CANLOOKAHEAD
|
||||
|
||||
Reference in New Issue
Block a user