summaryrefslogtreecommitdiff
path: root/rust/kernel/bitmap.rs
diff options
context:
space:
mode:
Diffstat (limited to 'rust/kernel/bitmap.rs')
-rw-r--r--rust/kernel/bitmap.rs15
1 files changed, 15 insertions, 0 deletions
diff --git a/rust/kernel/bitmap.rs b/rust/kernel/bitmap.rs
index f349b1eb59f9..f45915694454 100644
--- a/rust/kernel/bitmap.rs
+++ b/rust/kernel/bitmap.rs
@@ -252,6 +252,21 @@ impl BitmapVec {
pub fn len(&self) -> usize {
self.nbits
}
+
+ /// Fills this `Bitmap` with random bits.
+ #[cfg(CONFIG_FIND_BIT_BENCHMARK_RUST)]
+ pub fn fill_random(&mut self) {
+ // SAFETY: `self.as_mut_ptr` points to either an array of the
+ // appropriate length or one usize.
+ unsafe {
+ bindings::get_random_bytes(
+ self.as_mut_ptr().cast::<ffi::c_void>(),
+ usize::div_ceil(self.nbits, bindings::BITS_PER_LONG as usize)
+ * bindings::BITS_PER_LONG as usize
+ / 8,
+ );
+ }
+ }
}
impl Bitmap {