Skip to content

Commit

Permalink
Added benchmarks over mounting an unformatted disk
Browse files Browse the repository at this point in the history
These locally show the expected O(d(n)) growth of the block_size search
when block_count is known.

A rough estimate of runtime for a 1 GiB device with a 90 MiB/s read bandwidth
(using the mt25q for rough numbers):

  known bs/bc       => ~1.44 us
  known block_size  => ~1.44 us
  known block_count => ~125 us
  unknown bs/bc     => ~376 ms
  • Loading branch information
geky committed Dec 5, 2022
1 parent a1f325b commit efc4e18
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 14 deletions.
4 changes: 3 additions & 1 deletion bd/lfs_emubd.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,9 @@ int lfs_emubd_read(const struct lfs_config *cfg, lfs_block_t block,
lfs_emubd_t *bd = cfg->context;

// check if read is valid
LFS_ASSERT(block < bd->cfg->erase_count);
if (block >= bd->cfg->erase_count) {
return LFS_ERR_INVAL;
}
LFS_ASSERT(off % bd->cfg->read_size == 0);
LFS_ASSERT(size % bd->cfg->read_size == 0);
LFS_ASSERT(off+size <= bd->cfg->erase_size);
Expand Down
4 changes: 3 additions & 1 deletion bd/lfs_filebd.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ int lfs_filebd_read(const struct lfs_config *cfg, lfs_block_t block,
lfs_filebd_t *bd = cfg->context;

// check if read is valid
LFS_ASSERT(block < bd->cfg->erase_count);
if (block >= bd->cfg->erase_count) {
return LFS_ERR_INVAL;
}
LFS_ASSERT(off % bd->cfg->read_size == 0);
LFS_ASSERT(size % bd->cfg->read_size == 0);
LFS_ASSERT(off+size <= bd->cfg->erase_size);
Expand Down
4 changes: 3 additions & 1 deletion bd/lfs_rambd.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ int lfs_rambd_read(const struct lfs_config *cfg, lfs_block_t block,
lfs_rambd_t *bd = cfg->context;

// check if read is valid
LFS_ASSERT(block < bd->cfg->erase_count);
if (block >= bd->cfg->erase_count) {
return LFS_ERR_INVAL;
}
LFS_ASSERT(off % bd->cfg->read_size == 0);
LFS_ASSERT(size % bd->cfg->read_size == 0);
LFS_ASSERT(off+size <= bd->cfg->erase_size);
Expand Down
50 changes: 39 additions & 11 deletions benches/bench_superblock.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
[cases.bench_superblocks_found]
[cases.bench_superblocks_format]
code = '''
lfs_t lfs;
BENCH_START();
lfs_format(&lfs, cfg) => 0;
BENCH_STOP();
'''

[cases.bench_superblocks_mount]
defines.KNOWN_BLOCK_SIZE = [true, false]
defines.KNOWN_BLOCK_COUNT = [true, false]
# support benchmarking with files
defines.N = [0, 1024]
defines.FILE_SIZE = 8
Expand Down Expand Up @@ -28,29 +39,46 @@ code = '''
}
lfs_unmount(&lfs) => 0;
if (KNOWN_BLOCK_SIZE) {
cfg->block_size = BLOCK_SIZE;
} else {
cfg->block_size = 0;
}
if (KNOWN_BLOCK_COUNT) {
cfg->block_count = BLOCK_COUNT;
} else {
cfg->block_count = 0;
}
BENCH_START();
lfs_mount(&lfs, cfg) => 0;
BENCH_STOP();
lfs_unmount(&lfs) => 0;
'''

[cases.bench_superblocks_missing]
[cases.bench_superblocks_mount_missing]
defines.KNOWN_BLOCK_SIZE = [true, false]
defines.KNOWN_BLOCK_COUNT = [true, false]
code = '''
lfs_t lfs;
BENCH_START();
int err = lfs_mount(&lfs, cfg);
assert(err != 0);
BENCH_STOP();
'''
if (KNOWN_BLOCK_SIZE) {
cfg->block_size = BLOCK_SIZE;
} else {
cfg->block_size = 0;
}
[cases.bench_superblocks_format]
code = '''
lfs_t lfs;
if (KNOWN_BLOCK_COUNT) {
cfg->block_count = BLOCK_COUNT;
} else {
cfg->block_count = 0;
}
BENCH_START();
lfs_format(&lfs, cfg) => 0;
int err = lfs_mount(&lfs, cfg);
assert(err != 0);
BENCH_STOP();
'''

0 comments on commit efc4e18

Please sign in to comment.