Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Sketch out MapCell type Starts to address Issue #178 where TakeCell actually moves data out of the option. This is a performance problem if the data in a TakeCell is large, but saves both cycles and memory if the data is small (like a pointer or slice) because the Option can be optimized in many cases and the code operates on registers as opposed to memory. To resolve this, just introducing a new Cell type called MapCell which keeps the data in the MapCell during a `map` operation. Otherwise the interface is the same so should be a dropin replacement. * Benchmark for TakeCell vs MapCell Utility test in the `hail` board that measures memory overhead of TakeCell and MapCell, as well as cycles for a no-op map operation on data of increasing sizes: | Type |Cycles | Bytes| |--------------|-------|------| |`&u32` | 3 | 4 | |`[[u8;256];1]`| 1655 | 257 | |`[[u8;256];2]`| 2795 | 513 | |`[[u8;256];3]`| 4365 | 769 | |`[[u8;256];4]`| 4838 | 1025 | |`[[u8;256];5]`| 6780 | 1281 | |`[[u8;256];6]`| 7706 | 1537 | |`[[u8;256];7]`| 10326 | 1793 | | Type | Cycles | Bytes| |--------------|--------|------| |`&u32` | 18 | 8 | |`[[u8;256];1]`| 20 | 257 | |`[[u8;256];2]`| 22 | 513 | |`[[u8;256];3]`| 20 | 769 | |`[[u8;256];4]`| 22 | 1025 | |`[[u8;256];5]`| 22 | 1281 | |`[[u8;256];6]`| 22 | 1537 | |`[[u8;256];7]`| 20 | 1793 | * Convert TakeCell to MapCell/Cell if appropriate Changes TakeCell to only admit mutable references. Other types should simply use Cell or MapCell. * docs * rustfmt * rustfmt
- Loading branch information
Showing
30 changed files
with
474 additions
and
292 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use kernel::common::take_cell::MapCell; | ||
|
||
pub unsafe fn test_take_map_cell() { | ||
static FOO: u32 = 1234; | ||
|
||
static mut mc_ref: MapCell<&'static u32> = MapCell::new(&FOO); | ||
test_map_cell(&mc_ref); | ||
|
||
static mut mc1: MapCell<[[u8; 256]; 1]> = MapCell::new([[125; 256]; 1]); | ||
test_map_cell(&mc1); | ||
|
||
static mut mc2: MapCell<[[u8; 256]; 2]> = MapCell::new([[125; 256]; 2]); | ||
test_map_cell(&mc2); | ||
|
||
static mut mc3: MapCell<[[u8; 256]; 3]> = MapCell::new([[125; 256]; 3]); | ||
test_map_cell(&mc3); | ||
|
||
static mut mc4: MapCell<[[u8; 256]; 4]> = MapCell::new([[125; 256]; 4]); | ||
test_map_cell(&mc4); | ||
|
||
static mut mc5: MapCell<[[u8; 256]; 5]> = MapCell::new([[125; 256]; 5]); | ||
test_map_cell(&mc5); | ||
|
||
static mut mc6: MapCell<[[u8; 256]; 6]> = MapCell::new([[125; 256]; 6]); | ||
test_map_cell(&mc6); | ||
|
||
static mut mc7: MapCell<[[u8; 256]; 7]> = MapCell::new([[125; 256]; 7]); | ||
test_map_cell(&mc7); | ||
} | ||
|
||
#[inline(never)] | ||
#[allow(unused_unsafe)] | ||
unsafe fn test_map_cell<'a, A>(tc: &MapCell<A>) { | ||
let dwt_ctl: *mut u32 = 0xE0001000 as *mut u32; | ||
let dwt_cycles: *mut u32 = 0xE0001004 as *mut u32; | ||
let demcr: *mut u32 = 0xE000EDFC as *mut u32; | ||
|
||
::core::ptr::write_volatile(demcr, 0x01000000); | ||
::core::ptr::write_volatile(dwt_cycles, 0); | ||
::core::ptr::write_volatile(dwt_ctl, ::core::ptr::read_volatile(dwt_ctl) | 1); | ||
tc.map(|_| ()); | ||
let end = ::core::ptr::read_volatile(dwt_cycles); | ||
println!("time: {}, size: {}", end, ::core::mem::size_of_val(tc)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.