bma_benchmark#[macro_use]
extern crate bma_benchmark;
use std::sync::Mutex;
let n = 100_000_000;
let mutex = Mutex::new(0);
benchmark_start!();
for _ in 0..n {
let _a = mutex.lock().unwrap();
}
benchmark_print!(n);
benchmark!#[macro_use]
extern crate bma_benchmark;
use std::sync::Mutex;
let mutex = Mutex::new(0);
benchmark!(100_000_000, {
let _a = mutex.lock().unwrap();
});

use selfe_sys;
use ferros::alloc::{self, micro_alloc, smart_alloc};
use ferros::userland::{root_cnode, BootInfo};
// The raw boot info is provided by the sel4_start library
let raw_boot_info: &'static selfe_sys::seL4_BootInfo = unsafe { &*sel4_start::BOOTINFO };
// Utility for finding and claiming `Untyped` instances supplied by the boot info.
let mut allocator = micro_alloc::Allocator::bootstrap(&raw_boot_info)?;
let initial_untyped = allocator
.get_untyped::<U20>() // The size of the Untyped instance, as bits
.expect("Couldn't find an untyped instance of the desired size");
// Create the top-level CNode wrapper with type-level-tracked remaining slot capacity
let (root_cnode, local_slots) = root_cnode(&raw_boot_info);
// Once we have an initial Untyped instance, memory distribution from it
// can be tracked with compile-time checks. The smart_alloc macro synthesizes
// the allocation code, and the capacity bounds are statically verified by
// the type checker. The effect is that you can write 'slots' in the macro body
// anywhere you need some slots, and you'll get the right number allocated
// with type inference. A reference to 'ut' does the same for untyped memory.
smart_alloc!(|slots from local_slots, ut from uts| {
// Create a page table seL4 kernel object and return a capability pointer to it.
// Here we use a variable binding type annotation and Rust's type system can figure out
// if it can allocate a large enough Untyped instance and enough cnode slots
// to represent this particular kernel object.
let example_page_table: LocalCap<UnmappedPageTable> = retype(ut, slots)?;
// Create a resource-tracking wrapper around the raw boot info to assist in
// virtual memory related operations.
let boot_info = BootInfo::wrap(raw_boot_info, ut, slots);
let (root_page_table, boot_info) = boot_info.map_page_table(root_page_table)?;
});
From 日报小组 洋芋
原文作者:Rust语言中文社区;如有侵权,请联系管理员删除。