From b6ab323eb1314fb0d90ac000674e647e971cf444 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Fri, 10 Jan 2025 15:55:48 -0600 Subject: [PATCH] Dropped the q-bit (previous-perturb) from cksum tags Now that we perturb commit cksums with the odd-parity zero, the q-bit no longer serves a purpose other than extra debug info. But this is a double-edged sword, because redundant info just means another thing that can go wrong. For example, should we assert? If the q-bit doesn't reflect the previous-perturb state it's a bug, but the only thing that would break would be the q-bit itself. And if we don't assert what's the point of keeping the q-bit around? Dropping the q-bit avoids answering this question and saves a bit of code: code stack ctx before: 37772 2608 620 after: 37768 (-0.0%) 2608 (+0.0%) 620 (+0.0%) --- lfs.c | 12 +----------- scripts/dbgbmap.py | 3 +-- scripts/dbgbtree.py | 10 ++++------ scripts/dbglfs.py | 10 ++++------ scripts/dbgmtree.py | 10 ++++------ scripts/dbgrbyd.py | 12 ++++-------- scripts/dbgtag.py | 10 ++++------ 7 files changed, 22 insertions(+), 45 deletions(-) diff --git a/lfs.c b/lfs.c index cd402f27..341b528f 100644 --- a/lfs.c +++ b/lfs.c @@ -1157,7 +1157,6 @@ enum lfsr_tag { // checksum tags LFSR_TAG_CKSUM = 0x3000, LFSR_TAG_P = 0x0001, - LFSR_TAG_Q = 0x0002, LFSR_TAG_NOTE = 0x3100, LFSR_TAG_ECKSUM = 0x3200, @@ -1229,10 +1228,6 @@ static inline bool lfsr_tag_p(lfsr_tag_t tag) { return tag & LFSR_TAG_P; } -static inline bool lfsr_tag_q(lfsr_tag_t tag) { - return tag & LFSR_TAG_Q; -} - static inline bool lfsr_tag_isinternal(lfsr_tag_t tag) { return tag & LFSR_TAG_INTERNAL; } @@ -2821,9 +2816,6 @@ static int lfsr_rbyd_fetch(lfs_t *lfs, lfsr_rbyd_t *rbyd, break; } - // if checksums match, perturb bits should also match - LFS_ASSERT(lfsr_tag_q(tag) == lfsr_rbyd_isperturb(rbyd)); - // save what we've found so far rbyd->eoff = ((lfs_size_t)lfsr_tag_p(tag) @@ -4046,8 +4038,6 @@ static int lfsr_rbyd_appendcksum(lfs_t *lfs, lfsr_rbyd_t *rbyd) { // set the valid bit to the cksum parity | ((uint8_t)v << 7); cksum_buf[1] = (uint8_t)(LFSR_TAG_CKSUM >> 0) - // include the current perturb bit - | ((uint8_t)lfsr_rbyd_isperturb(rbyd) << 1) // set the perturb bit so next commit is invalid | ((uint8_t)perturb << 0); cksum_buf[2] = 0; @@ -4063,7 +4053,7 @@ static int lfsr_rbyd_appendcksum(lfs_t *lfs, lfsr_rbyd_t *rbyd) { // calculate the commit checksum cksum_ = lfs_crc32c(cksum_, cksum_buf, 2+1+4); // and perturb, perturbing the commit checksum avoids a perturb hole - // after the last valid bit without needing to manually validate q + // after the last valid bit // // note the odd-parity zero preserves our position in the crc32c // ring while only changing the parity diff --git a/scripts/dbgbmap.py b/scripts/dbgbmap.py index 49955898..7fb02563 100755 --- a/scripts/dbgbmap.py +++ b/scripts/dbgbmap.py @@ -50,9 +50,8 @@ TAG_B = 0x0000 TAG_R = 0x2000 TAG_LE = 0x0000 TAG_GT = 0x1000 -TAG_CKSUM = 0x3000 ## 0x3c0p v-11 cccc ---- --qp +TAG_CKSUM = 0x3000 ## 0x3c0p v-11 cccc ---- ---p TAG_P = 0x0001 -TAG_Q = 0x0002 TAG_NOTE = 0x3100 # 0x3100 v-11 ---1 ---- ---- TAG_ECKSUM = 0x3200 # 0x3200 v-11 --1- ---- ---- diff --git a/scripts/dbgbtree.py b/scripts/dbgbtree.py index deaae46f..4590030f 100755 --- a/scripts/dbgbtree.py +++ b/scripts/dbgbtree.py @@ -48,9 +48,8 @@ TAG_B = 0x0000 TAG_R = 0x2000 TAG_LE = 0x0000 TAG_GT = 0x1000 -TAG_CKSUM = 0x3000 ## 0x3c0p v-11 cccc ---- --qp +TAG_CKSUM = 0x3000 ## 0x3c0p v-11 cccc ---- ---p TAG_P = 0x0001 -TAG_Q = 0x0002 TAG_NOTE = 0x3100 # 0x3100 v-11 ---1 ---- ---- TAG_ECKSUM = 0x3200 # 0x3200 v-11 --1- ---- ---- @@ -239,10 +238,9 @@ def tagrepr(tag, w=None, size=None, off=None): else ' -%d' % size if size else '') elif (tag & 0x7f00) == TAG_CKSUM: - return 'cksum%s%s%s%s%s' % ( - 'q' if not tag & 0xfc and tag & TAG_Q else '', - 'p' if not tag & 0xfc and tag & TAG_P else '', - ' 0x%02x' % (tag & 0xff) if tag & 0xfc else '', + return 'cksum%s%s%s%s' % ( + 'p' if not tag & 0xfe and tag & TAG_P else '', + ' 0x%02x' % (tag & 0xff) if tag & 0xfe else '', ' w%d' % w if w else '', ' %s' % size if size is not None else '') elif (tag & 0x7f00) == TAG_NOTE: diff --git a/scripts/dbglfs.py b/scripts/dbglfs.py index bc000993..5690cf3e 100755 --- a/scripts/dbglfs.py +++ b/scripts/dbglfs.py @@ -49,9 +49,8 @@ TAG_B = 0x0000 TAG_R = 0x2000 TAG_LE = 0x0000 TAG_GT = 0x1000 -TAG_CKSUM = 0x3000 ## 0x3c0p v-11 cccc ---- --qp +TAG_CKSUM = 0x3000 ## 0x3c0p v-11 cccc ---- ---p TAG_P = 0x0001 -TAG_Q = 0x0002 TAG_NOTE = 0x3100 # 0x3100 v-11 ---1 ---- ---- TAG_ECKSUM = 0x3200 # 0x3200 v-11 --1- ---- ---- @@ -270,10 +269,9 @@ def tagrepr(tag, w=None, size=None, off=None): else ' -%d' % size if size else '') elif (tag & 0x7f00) == TAG_CKSUM: - return 'cksum%s%s%s%s%s' % ( - 'q' if not tag & 0xfc and tag & TAG_Q else '', - 'p' if not tag & 0xfc and tag & TAG_P else '', - ' 0x%02x' % (tag & 0xff) if tag & 0xfc else '', + return 'cksum%s%s%s%s' % ( + 'p' if not tag & 0xfe and tag & TAG_P else '', + ' 0x%02x' % (tag & 0xff) if tag & 0xfe else '', ' w%d' % w if w else '', ' %s' % size if size is not None else '') elif (tag & 0x7f00) == TAG_NOTE: diff --git a/scripts/dbgmtree.py b/scripts/dbgmtree.py index 3a199db8..a5a4f114 100755 --- a/scripts/dbgmtree.py +++ b/scripts/dbgmtree.py @@ -48,9 +48,8 @@ TAG_B = 0x0000 TAG_R = 0x2000 TAG_LE = 0x0000 TAG_GT = 0x1000 -TAG_CKSUM = 0x3000 ## 0x3c0p v-11 cccc ---- --qp +TAG_CKSUM = 0x3000 ## 0x3c0p v-11 cccc ---- ---p TAG_P = 0x0001 -TAG_Q = 0x0002 TAG_NOTE = 0x3100 # 0x3100 v-11 ---1 ---- ---- TAG_ECKSUM = 0x3200 # 0x3200 v-11 --1- ---- ---- @@ -254,10 +253,9 @@ def tagrepr(tag, w=None, size=None, off=None): else ' -%d' % size if size else '') elif (tag & 0x7f00) == TAG_CKSUM: - return 'cksum%s%s%s%s%s' % ( - 'q' if not tag & 0xfc and tag & TAG_Q else '', - 'p' if not tag & 0xfc and tag & TAG_P else '', - ' 0x%02x' % (tag & 0xff) if tag & 0xfc else '', + return 'cksum%s%s%s%s' % ( + 'p' if not tag & 0xfe and tag & TAG_P else '', + ' 0x%02x' % (tag & 0xff) if tag & 0xfe else '', ' w%d' % w if w else '', ' %s' % size if size is not None else '') elif (tag & 0x7f00) == TAG_NOTE: diff --git a/scripts/dbgrbyd.py b/scripts/dbgrbyd.py index ff18ebc5..f6320f64 100755 --- a/scripts/dbgrbyd.py +++ b/scripts/dbgrbyd.py @@ -58,9 +58,8 @@ TAG_B = 0x0000 TAG_R = 0x2000 TAG_LE = 0x0000 TAG_GT = 0x1000 -TAG_CKSUM = 0x3000 ## 0x3c0p v-11 cccc ---- --qp +TAG_CKSUM = 0x3000 ## 0x3c0p v-11 cccc ---- ---p TAG_P = 0x0001 -TAG_Q = 0x0002 TAG_NOTE = 0x3100 # 0x3100 v-11 ---1 ---- ---- TAG_ECKSUM = 0x3200 # 0x3200 v-11 --1- ---- ---- @@ -242,10 +241,9 @@ def tagrepr(tag, w=None, size=None, off=None): else ' -%d' % size if size else '') elif (tag & 0x7f00) == TAG_CKSUM: - return 'cksum%s%s%s%s%s' % ( - 'q' if not tag & 0xfc and tag & TAG_Q else '', - 'p' if not tag & 0xfc and tag & TAG_P else '', - ' 0x%02x' % (tag & 0xff) if tag & 0xfc else '', + return 'cksum%s%s%s%s' % ( + 'p' if not tag & 0xfe and tag & TAG_P else '', + ' 0x%02x' % (tag & 0xff) if tag & 0xfe else '', ' w%d' % w if w else '', ' %s' % size if size is not None else '') elif (tag & 0x7f00) == TAG_NOTE: @@ -557,8 +555,6 @@ def dbg_log(data, block_size, rev, eoff, weight, *, cksum__ = fromle32(data[j_:j_+4]) if cksum_ != cksum__: notes.append('cksum!=%08x' % cksum__) - if perturb != bool(tag & TAG_Q): - notes.append('q!=%x' % perturb) # update perturb bit perturb = tag & TAG_P # revert to data cksum and perturb diff --git a/scripts/dbgtag.py b/scripts/dbgtag.py index 714b83bc..98271da5 100755 --- a/scripts/dbgtag.py +++ b/scripts/dbgtag.py @@ -46,9 +46,8 @@ TAG_B = 0x0000 TAG_R = 0x2000 TAG_LE = 0x0000 TAG_GT = 0x1000 -TAG_CKSUM = 0x3000 ## 0x3c0p v-11 cccc ---- --qp +TAG_CKSUM = 0x3000 ## 0x3c0p v-11 cccc ---- ---p TAG_P = 0x0001 -TAG_Q = 0x0002 TAG_NOTE = 0x3100 # 0x3100 v-11 ---1 ---- ---- TAG_ECKSUM = 0x3200 # 0x3200 v-11 --1- ---- ---- @@ -196,10 +195,9 @@ def tagrepr(tag, w=None, size=None, off=None): else ' -%d' % size if size else '') elif (tag & 0x7f00) == TAG_CKSUM: - return 'cksum%s%s%s%s%s' % ( - 'q' if not tag & 0xfc and tag & TAG_Q else '', - 'p' if not tag & 0xfc and tag & TAG_P else '', - ' 0x%02x' % (tag & 0xff) if tag & 0xfc else '', + return 'cksum%s%s%s%s' % ( + 'p' if not tag & 0xfe and tag & TAG_P else '', + ' 0x%02x' % (tag & 0xff) if tag & 0xfe else '', ' w%d' % w if w else '', ' %s' % size if size is not None else '') elif (tag & 0x7f00) == TAG_NOTE: