Skip to content

Add make perf and fd table constant lookup test#70

Draft
ChuWeiChang wants to merge 3 commits into
sysprog21:mainfrom
ChuWeiChang:Add-make-perf-and-fd-table-constant-lookup-test
Draft

Add make perf and fd table constant lookup test#70
ChuWeiChang wants to merge 3 commits into
sysprog21:mainfrom
ChuWeiChang:Add-make-perf-and-fd-table-constant-lookup-test

Conversation

@ChuWeiChang
Copy link
Copy Markdown
Contributor

@ChuWeiChang ChuWeiChang commented May 28, 2026

(This PR is built on top of #68. Please review/merge that one first)

This PR serve as the reference for #38 (comment)


Resolve test gap 3 in #38:

  • Add a check-perf build target that compiles the unit test suite with -O2 -DKBOX_PERF_ONLY in a separate
    binary (test-perf), keeping it independent from the check-unit artifact. Sanitizer and debug flags are stripped from PERF_TEST_CFLAGS so timings reflect optimized production code.

  • Add a benchmark that exercises kbox_fd_table_find_by_host_fd for both present and absent host FDs across table sizes {64, 256, 1024, 4096, 16384} and asserts that per-lookup latency stays within 2x of the N=64 baseline.

Results

--- O(1) Characteristic Perf Test ---
N = 64    | Present:   1.65 ns/op | Absent:   1.39 ns/op
N = 256   | Present:   1.87 ns/op | Absent:   1.38 ns/op
N = 1024  | Present:   1.60 ns/op | Absent:   1.29 ns/op
N = 4096  | Present:   1.63 ns/op | Absent:   1.31 ns/op
N = 16384 | Present:   1.59 ns/op | Absent:   1.39 ns/op
ok

The lookup time is flat across all table sizes — present lookups stay in the 1.59–1.87 ns range and absent lookups stay in the 1.29–1.39 ns range regardless of whether the table has 64 or 16384 entries, adhering to O(1) signature.


Summary by cubic

Adds a perf-only test runner (check-perf) and an O(1) reverse-lookup benchmark for the FD table, plus a fix that correctly downgrades MULTI mappings when aliases close. Covers test gap 3 in #38 and runs in CI without sanitizers to reflect production timing.

  • New Features

    • make check-perf: builds a separate tests/unit/test-perf with -O2 -DKBOX_PERF_ONLY (no sanitizers/debug) so only perf benchmarks run; included in make check and a new CI perf-tests job.
    • O(1) benchmark for kbox_fd_table_find_by_host_fd across {64, 256, 1024, 4096, 16384}; asserts present/absent lookups stay ≤2x the N=64 baseline.
  • Bug Fixes

    • Add host_fd_refs[] and update rev_host_set/clear to maintain counts and downgrade from MULTI to the surviving VFD when one alias remains; counters initialized in kbox_fd_table_init.
    • New regression test (test-fd-table-refcount.c) ensures reverse lookup returns the survivor after other aliases close.

Written for commit 0000542. Summary will update on new commits.

Review in cubic

ChuWeiChang and others added 2 commits May 28, 2026 20:08
host_to_vfd stayed MULTI even after all but one VFD aliasing a host FD
had closed, breaking reverse lookups for the survivor. Add host_fd_refs
to track share counts: on close, decrement and, when the count falls to
1, search for the surviving VFD and restore a direct mapping instead of
leaving MULTI in place.

Change-Id: I196608b0dfe31492786928f71ba4a1e4801fc532
Introduce a dedicated check-perf build target that compiles the unit
test runner with -O2 -DKBOX_PERF_ONLY, suppressing TEST_REGISTER so only
PERF_REGISTER benchmarks execute. The perf binary is kept separate from
the unit test binary (test-perf vs test-runner) so running check-perf
does not invalidate check-unit's build artifact.

Change-Id: I55d7ff64b981dbbcf248b6ab675fd2c86147b165
@ChuWeiChang ChuWeiChang force-pushed the Add-make-perf-and-fd-table-constant-lookup-test branch from 00004d6 to 000098f Compare May 28, 2026 13:29
Benchmark kbox_fd_table_find_by_host_fd across table sizes of 64 to
16384 entries. Assert that per-lookup latency stays within 2x of the
baseline at N=64, verifying that the host_to_vfd reverse map added in
the O(1) refactor holds its constant-time characteristic.

Change-Id: Ibcb7188e2c444f4636f669e73aeacd3980f04b84
@ChuWeiChang ChuWeiChang force-pushed the Add-make-perf-and-fd-table-constant-lookup-test branch from 000098f to 0000542 Compare May 28, 2026 13:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant