lib/find_bit_benchmark_rust.rs
Source file repositories/reference/linux-study-clean/lib/find_bit_benchmark_rust.rs
File Facts
- System
- Linux kernel
- Corpus path
lib/find_bit_benchmark_rust.rs- Extension
.rs- Size
- 2864 bytes
- Lines
- 105
- Domain
- Kernel Services
- Bucket
- lib
- Inferred role
- Kernel Services: implementation source
- Status
- source implementation candidate
Why This File Exists
Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
- No C-style include directives detected by the generator.
Detected Declarations
function test_next_bitfunction Somefunction test_next_zero_bitfunction Somefunction find_bit_test
Annotated Snippet
fn test_next_bit(bitmap: &BitmapVec) {
let time = Instant::<Monotonic>::now();
let mut cnt = 0;
let mut i = 0;
while let Some(index) = bitmap.next_bit(i) {
cnt += 1;
i = index + 1;
// CONFIG_RUST_BITMAP_HARDENED enforces strict bounds.
if i == BITMAP_LEN {
break;
}
}
let delta = time.elapsed();
pr_cont!(
"\nnext_bit: {:18} ns, {:6} iterations",
delta.as_nanos(),
cnt
);
}
fn test_next_zero_bit(bitmap: &BitmapVec) {
let time = Instant::<Monotonic>::now();
let mut cnt = 0;
let mut i = 0;
while let Some(index) = bitmap.next_zero_bit(i) {
cnt += 1;
i = index + 1;
// CONFIG_RUST_BITMAP_HARDENED enforces strict bounds.
if i == BITMAP_LEN {
break;
}
}
let delta = time.elapsed();
pr_cont!(
"\nnext_zero_bit: {:18} ns, {:6} iterations",
delta.as_nanos(),
cnt
);
}
fn find_bit_test() {
pr_err!("Benchmark");
pr_cont!("\nStart testing find_bit() Rust with random-filled bitmap");
let mut bitmap = BitmapVec::new(BITMAP_LEN, GFP_KERNEL).expect("alloc bitmap failed");
bitmap.fill_random();
test_next_bit(&bitmap);
test_next_zero_bit(&bitmap);
pr_cont!("\nStart testing find_bit() Rust with sparse bitmap");
let mut bitmap = BitmapVec::new(BITMAP_LEN, GFP_KERNEL).expect("alloc sparse bitmap failed");
let nbits = BITMAP_LEN / SPARSENESS;
for _i in 0..nbits {
// SAFETY: __get_random_u32_below is safe to call with any u32 argument.
let bit =
unsafe { bindings::__get_random_u32_below(BITMAP_LEN.try_into().unwrap()) as usize };
bitmap.set_bit(bit);
}
test_next_bit(&bitmap);
test_next_zero_bit(&bitmap);
pr_cont!("\n");
}
impl kernel::Module for Benchmark {
fn init(_module: &'static ThisModule) -> Result<Self> {
find_bit_test();
// Return error so test module can be inserted again without rmmod.
Err(code::EINVAL)
}
}
module! {
type: Benchmark,
name: "find_bit_benchmark_rust",
authors: ["Burak Emir <bqe@google.com>"],
description: "Module with benchmark for bitmap Rust API",
license: "GPL v2",
}
Annotation
- Detected declarations: `function test_next_bit`, `function Some`, `function test_next_zero_bit`, `function Some`, `function find_bit_test`.
- Atlas domain: Kernel Services / lib.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.