.githooks/
compiler/
kernel/
lib/
scripts/
seed/
sublime/
test/
boot/
bootstrap/
compiler/
cycles/
dispatch/
format/
host/
integration/
kernel/
loader/
manifests/
mmio/
native/
packages/
runtime/
scheduling/
shared/
slots/
smp/
kernel/
cases.rad
1.6 KiB
machine.ras
1.5 KiB
spin.rad
3.9 KiB
std/
sync/
termination/
tests/
trap/
verify/
Makefile
9.2 KiB
kernel.rad
776 B
runner.rad
11.6 KiB
vim/
.gitignore
333 B
.gitsigners
224 B
AGENTS.md
8.3 KiB
CONTRIBUTING
2.1 KiB
LICENSE
1.1 KiB
Makefile
2.5 KiB
README
3.4 KiB
STYLE
3.2 KiB
std.lib
2.1 KiB
std.lib.test
1.1 KiB
test/smp/spin.rad
raw
| 1 | //! Concurrent user contexts with shared private state and separate call |
| 2 | //! buffers. |
| 3 | export mod cases; |
| 4 | export mod abi; |
| 5 | export mod sys; |
| 6 | |
| 7 | /// Completed allocation transactions, indexed by the executing hart. |
| 8 | export unsafe static count: [u64; 8] = [0; 8]; |
| 9 | |
| 10 | /// Future budget handles assigned to callers on the preceding online hart. |
| 11 | export unsafe static windows: [u64; 8] = [0; 8]; |
| 12 | |
| 13 | /// Capability used to notify the shared domain from each online hart. |
| 14 | export unsafe static notification: u64 = 0; |
| 15 | |
| 16 | /// Shared-domain capability for the injected physical interrupt source. |
| 17 | export unsafe static interrupt: u64 = 0; |
| 18 | |
| 19 | /// Observed destination hart plus one after each context changes budget. |
| 20 | export unsafe static migrations: [u64; 8] = [0; 8]; |
| 21 | |
| 22 | /// Progress shared with the machine fixture for waits and interrupted |
| 23 | /// allocation. |
| 24 | export unsafe static wakeState: u64 = 0; |
| 25 | |
| 26 | /// Nonzero selects the independently activated idle-wakeup context. |
| 27 | export unsafe static idle: u64 = 0; |
| 28 | |
| 29 | /// Check hart identity and shared-table allocation through repeated direct |
| 30 | /// calls. |
| 31 | unsafe fn run(hart: u64) { |
| 32 | let source = sys::queryInterrupt(abi::Handle(interrupt)); |
| 33 | assert source.number == cases::IRQ_SOURCE; |
| 34 | let original = (try! sys::queryContext(abi::Handle(0), abi::CURRENT_CONTEXT)); |
| 35 | assert original.hart == hart; |
| 36 | let budget = abi::Handle(windows[hart as u32]); |
| 37 | let before = try! sys::queryBudget(budget); |
| 38 | let right = try! sys::budgetSplit(budget, before.start + 1000); |
| 39 | let leftInfo = try! sys::queryBudget(budget); |
| 40 | let rightInfo = try! sys::queryBudget(right); |
| 41 | assert leftInfo.start == before.start and leftInfo.end == rightInfo.start; |
| 42 | assert rightInfo.end == before.end and rightInfo.hart == before.hart; |
| 43 | let merged = try! sys::budgetMerge(budget, right); |
| 44 | assert merged == budget; |
| 45 | let after = try! sys::queryBudget(merged); |
| 46 | assert after.start == before.start and after.end == before.end; |
| 47 | try! sys::capabilityDrop(merged); |
| 48 | try! sys::wakeup(abi::Handle(notification), hart as u32); |
| 49 | for i in 0 .. cases::TRANSACTIONS { |
| 50 | let page = try! sys::pageAllocate(abi::Handle(0), 1); |
| 51 | let info = sys::queryPage(page); |
| 52 | assert info.count == 1 and info.base <> 0; |
| 53 | try! sys::capabilityDrop(page); |
| 54 | let current = (try! sys::queryContext(abi::Handle(0), abi::CURRENT_CONTEXT)); |
| 55 | assert current.context == original.context and current.hart == hart; |
| 56 | set count[hart as u32] += 1; |
| 57 | } |
| 58 | while true { |
| 59 | let current = (try! sys::queryContext(abi::Handle(0), abi::CURRENT_CONTEXT)); |
| 60 | assert current.context == original.context; |
| 61 | if current.budget <> original.budget { |
| 62 | set migrations[hart as u32] = current.hart + 1; |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | /// Start an additional context with its physical hart index as a data argument. |
| 68 | export unsafe fn worker(hart: u64, size: u64) { |
| 69 | assert size == 8; |
| 70 | run(hart); |
| 71 | } |
| 72 | |
| 73 | /// The initial context owns hart zero's window. |
| 74 | @default unsafe fn main(env: *abi::Env) { |
| 75 | if idle <> 0 { |
| 76 | set wakeState = cases::WakeStage::BeforeWakeWait as u64; |
| 77 | sys::wait(); |
| 78 | set wakeState = cases::WakeStage::WakeResumed as u64; |
| 79 | while wakeState <> cases::WakeStage::AllowTimeout as u64 {} |
| 80 | set wakeState = cases::WakeStage::BeforeTimeoutWait as u64; |
| 81 | sys::wait(); |
| 82 | set wakeState = cases::WakeStage::TimeoutResumed as u64; |
| 83 | while wakeState <> cases::WakeStage::AllowTerminalWait as u64 {} |
| 84 | set wakeState = cases::WakeStage::BeforeTerminalWait as u64; |
| 85 | sys::wait(); |
| 86 | set wakeState = cases::WakeStage::TerminalResumed as u64; |
| 87 | while wakeState <> cases::WakeStage::AllowAllocation as u64 {} |
| 88 | set wakeState = cases::WakeStage::BeforeAllocation as u64; |
| 89 | let allocation = try! sys::pageAllocate( |
| 90 | abi::Handle(0), cases::ALLOCATION_PAGES as u64 |
| 91 | ); |
| 92 | set wakeState = cases::WakeStage::AllocationComplete as u64; |
| 93 | while true {} |
| 94 | } |
| 95 | run(0); |
| 96 | } |