Increased internal flags 16 bits -> 32 bits

If we add CKMETA/CKDATA and eventually REPAIRMETA/REPAIRDATA to the file
open flags, we'll end up with 17 flags total (13 user-facing,
4 internal), which is a bit (heh) too much for a 16-bit flags field!

There are a few ways to solve this, dropping features for one, instead
I've decided to expand the fields flag to 32-bits. Fortunately this was
already the field size for all user-facing fields.

To avoid a RAM increase, I've also shoved the opened-file types and
traversal tstates into the same field.

We have various flags in quite a few places now, here's how
everything fits together:

              8     8     8     8
            .----++----++----++----.
            .----..---..--..-------.
  o_flags:  |type|| f ||t ||   o   |
            |----||---|:--:'-------'
            |----||---|:--:--------.
  d_flags:  |type|| f |:  :        |
            |----||---|:--:--------'
            |----||---|:--'--..----.
  t_flags:  |type|| f ||  t  ||tstt|
            '----''---'|-----|'----'
            .----------|-----|-----.
  gc_flags: |          |  t  |     |
            '----------|-----|-----'
            .-----.---.|-----|.----.
  m_flags:  |     | m ||  t  || m  |
            '-----|---|'-----'|----|
            .----.|---|-------|----|
  i_flags:  | i  || m |       | m  |
            '----''---'-------'----'

Unfortunately, using the full 32-bit flag space highlights that C99's
enum types are kind of garbage...

In C99 enums are strictly signed ints, which means attempting to use
them for 32-bit bit fields overflows. There is no way around this so
I've switched our flag definitions to #defines.

I've kept types as enums for now but I'm keeping my eye on them...

---

The tradeoff of merging the type/btype/tstate/flags fields is that it
takes more code to extract/encode the various subfields. Since these
fields our heavily used in our codebase, this really adds up:

           code          stack
  before: 35888           2696
  after:  36048 (+0.4%)   2696 (+0.0%)

At least in theory the type fields can be optimized to a byte load, but
not btype/tstate. Also accessing bits in higher positions may be adding
cost.
This commit is contained in:
Christopher Haster
2024-07-25 14:05:04 -05:00
parent 35db3bc97f
commit 0893c1f6be
3 changed files with 318 additions and 296 deletions
+20 -20
View File
@@ -2598,7 +2598,7 @@ code = '''
lfs_alloc_ckpoint(&lfs);
// setup our neighbors
lfsr_omdir_t left = {.type=0};
lfsr_omdir_t left = {.flags=0};
lfsr_mtree_namelookup(&lfs, 0, "a", 1,
&left.mdir, NULL, NULL) => LFS_ERR_NOENT;
lfsr_mdir_commit(&lfs, &left.mdir, LFSR_ATTRS(
@@ -2606,7 +2606,7 @@ code = '''
assert(left.mdir.rbyd.weight == 2);
lfsr_omdir_open(&lfs, &left);
lfsr_omdir_t right = {.type=0};
lfsr_omdir_t right = {.flags=0};
lfsr_mtree_namelookup(&lfs, 0, "c", 1,
&right.mdir, NULL, NULL) => LFS_ERR_NOENT;
lfsr_mdir_commit(&lfs, &right.mdir, LFSR_ATTRS(
@@ -2657,7 +2657,7 @@ code = '''
lfs_alloc_ckpoint(&lfs);
// setup our neighbors
lfsr_omdir_t left = {.type=0};
lfsr_omdir_t left = {.flags=0};
lfsr_mtree_namelookup(&lfs, 0, "a", 1,
&left.mdir, NULL, NULL) => LFS_ERR_NOENT;
lfsr_mdir_commit(&lfs, &left.mdir, LFSR_ATTRS(
@@ -2665,7 +2665,7 @@ code = '''
assert(left.mdir.rbyd.weight == 2);
lfsr_omdir_open(&lfs, &left);
lfsr_omdir_t right = {.type=0};
lfsr_omdir_t right = {.flags=0};
lfsr_mtree_namelookup(&lfs, 0, "b", 1,
&right.mdir, NULL, NULL) => LFS_ERR_NOENT;
lfsr_mdir_commit(&lfs, &right.mdir, LFSR_ATTRS(
@@ -2707,7 +2707,7 @@ code = '''
lfs_alloc_ckpoint(&lfs);
// setup our neighbors
lfsr_omdir_t left = {.type=0};
lfsr_omdir_t left = {.flags=0};
lfsr_mtree_namelookup(&lfs, 0, "a", 1,
&left.mdir, NULL, NULL) => LFS_ERR_NOENT;
lfsr_mdir_commit(&lfs, &left.mdir, LFSR_ATTRS(
@@ -2715,7 +2715,7 @@ code = '''
assert(left.mdir.rbyd.weight == 2);
lfsr_omdir_open(&lfs, &left);
lfsr_omdir_t right = {.type=0};
lfsr_omdir_t right = {.flags=0};
lfsr_mtree_namelookup(&lfs, 0, "b", 1,
&right.mdir, NULL, NULL) => LFS_ERR_NOENT;
lfsr_mdir_commit(&lfs, &right.mdir, LFSR_ATTRS(
@@ -2759,7 +2759,7 @@ code = '''
lfs_alloc_ckpoint(&lfs);
// setup our neighbors
lfsr_omdir_t left = {.type=0};
lfsr_omdir_t left = {.flags=0};
lfsr_mtree_namelookup(&lfs, 0, "a", 1,
&left.mdir, NULL, NULL) => LFS_ERR_NOENT;
lfsr_mdir_commit(&lfs, &left.mdir, LFSR_ATTRS(
@@ -2767,7 +2767,7 @@ code = '''
assert(left.mdir.rbyd.weight == 2);
lfsr_omdir_open(&lfs, &left);
lfsr_omdir_t right = {.type=0};
lfsr_omdir_t right = {.flags=0};
lfsr_mtree_namelookup(&lfs, 0, "d", 1,
&right.mdir, NULL, NULL) => LFS_ERR_NOENT;
lfsr_mdir_commit(&lfs, &right.mdir, LFSR_ATTRS(
@@ -2832,7 +2832,7 @@ code = '''
lfs_alloc_ckpoint(&lfs);
// setup our neighbors
lfsr_omdir_t left = {.type=0};
lfsr_omdir_t left = {.flags=0};
lfsr_mtree_namelookup(&lfs, 0, "a", 1,
&left.mdir, NULL, NULL) => LFS_ERR_NOENT;
lfsr_mdir_commit(&lfs, &left.mdir, LFSR_ATTRS(
@@ -2840,7 +2840,7 @@ code = '''
assert(left.mdir.rbyd.weight == 2);
lfsr_omdir_open(&lfs, &left);
lfsr_omdir_t right = {.type=0};
lfsr_omdir_t right = {.flags=0};
lfsr_mtree_namelookup(&lfs, 0, "e", 1,
&right.mdir, NULL, NULL) => LFS_ERR_NOENT;
lfsr_mdir_commit(&lfs, &right.mdir, LFSR_ATTRS(
@@ -2917,7 +2917,7 @@ code = '''
lfs_alloc_ckpoint(&lfs);
// setup our neighbors
lfsr_omdir_t left = {.type=0};
lfsr_omdir_t left = {.flags=0};
lfsr_mtree_namelookup(&lfs, 0, "a", 1,
&left.mdir, NULL, NULL) => LFS_ERR_NOENT;
lfsr_mdir_commit(&lfs, &left.mdir, LFSR_ATTRS(
@@ -2925,7 +2925,7 @@ code = '''
assert(left.mdir.rbyd.weight == 2);
lfsr_omdir_open(&lfs, &left);
lfsr_omdir_t right = {.type=0};
lfsr_omdir_t right = {.flags=0};
lfsr_mtree_namelookup(&lfs, 0, "b", 1,
&right.mdir, NULL, NULL) => LFS_ERR_NOENT;
lfsr_mdir_commit(&lfs, &right.mdir, LFSR_ATTRS(
@@ -2975,7 +2975,7 @@ code = '''
lfs_alloc_ckpoint(&lfs);
// setup our neighbors
lfsr_omdir_t left = {.type=0};
lfsr_omdir_t left = {.flags=0};
lfsr_mtree_namelookup(&lfs, 0, "a", 1,
&left.mdir, NULL, NULL) => LFS_ERR_NOENT;
lfsr_mdir_commit(&lfs, &left.mdir, LFSR_ATTRS(
@@ -2983,7 +2983,7 @@ code = '''
assert(left.mdir.rbyd.weight == 2);
lfsr_omdir_open(&lfs, &left);
lfsr_omdir_t right = {.type=0};
lfsr_omdir_t right = {.flags=0};
lfsr_mtree_namelookup(&lfs, 0, "d", 1,
&right.mdir, NULL, NULL) => LFS_ERR_NOENT;
lfsr_mdir_commit(&lfs, &right.mdir, LFSR_ATTRS(
@@ -3064,7 +3064,7 @@ code = '''
lfs_alloc_ckpoint(&lfs);
// setup our neighbors
lfsr_omdir_t left = {.type=0};
lfsr_omdir_t left = {.flags=0};
lfsr_mtree_namelookup(&lfs, 0, "a", 1,
&left.mdir, NULL, NULL) => LFS_ERR_NOENT;
lfsr_mdir_commit(&lfs, &left.mdir, LFSR_ATTRS(
@@ -3072,7 +3072,7 @@ code = '''
assert(left.mdir.rbyd.weight == 2);
lfsr_omdir_open(&lfs, &left);
lfsr_omdir_t right = {.type=0};
lfsr_omdir_t right = {.flags=0};
lfsr_mtree_namelookup(&lfs, 0, "d", 1,
&right.mdir, NULL, NULL) => LFS_ERR_NOENT;
lfsr_mdir_commit(&lfs, &right.mdir, LFSR_ATTRS(
@@ -3151,7 +3151,7 @@ code = '''
lfs_alloc_ckpoint(&lfs);
// setup our neighbors
lfsr_omdir_t left = {.type=0};
lfsr_omdir_t left = {.flags=0};
lfsr_mtree_namelookup(&lfs, 0, "a", 1,
&left.mdir, NULL, NULL) => LFS_ERR_NOENT;
lfsr_mdir_commit(&lfs, &left.mdir, LFSR_ATTRS(
@@ -3159,7 +3159,7 @@ code = '''
assert(left.mdir.rbyd.weight == 2);
lfsr_omdir_open(&lfs, &left);
lfsr_omdir_t right = {.type=0};
lfsr_omdir_t right = {.flags=0};
lfsr_mtree_namelookup(&lfs, 0, "f", 1,
&right.mdir, NULL, NULL) => LFS_ERR_NOENT;
lfsr_mdir_commit(&lfs, &right.mdir, LFSR_ATTRS(
@@ -3253,7 +3253,7 @@ code = '''
lfs_alloc_ckpoint(&lfs);
// setup our neighbors
lfsr_omdir_t left = {.type=0};
lfsr_omdir_t left = {.flags=0};
lfsr_mtree_namelookup(&lfs, 0, "a", 1,
&left.mdir, NULL, NULL) => LFS_ERR_NOENT;
lfsr_mdir_commit(&lfs, &left.mdir, LFSR_ATTRS(
@@ -3261,7 +3261,7 @@ code = '''
assert(left.mdir.rbyd.weight == 2);
lfsr_omdir_open(&lfs, &left);
lfsr_omdir_t right = {.type=0};
lfsr_omdir_t right = {.flags=0};
lfsr_mtree_namelookup(&lfs, 0, "e", 1,
&right.mdir, NULL, NULL) => LFS_ERR_NOENT;
lfsr_mdir_commit(&lfs, &right.mdir, LFSR_ATTRS(