diff options
Diffstat (limited to 'rust/kernel')
-rw-r--r-- | rust/kernel/bitmap.rs | 15 |
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 { |