-
Notifications
You must be signed in to change notification settings - Fork 996
runtime (scheduler): add revised arm scheduler with support for atsamd21 #1010
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e64f876
internal/task: add interrupt-safe queue
niaow a24937d
runtime (scheduler): generalize scheduler beyond timers
niaow 27781d4
Merge branch 'intq' into schedatsamd21
niaow f95bd6b
runtime (scheduler): add revised arm scheduler with support for atsamd21
niaow File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,66 @@ | ||
| package task | ||
|
|
||
| import "runtime/volatile" | ||
|
|
||
| // InterruptQueue is a specialized version of Queue, designed for working with interrupts. | ||
| // It can be safely pushed to from an interrupt (assuming that a memory reference to the task remains elsewhere), and popped outside of an interrupt. | ||
| // It cannot be pushed to outside of an interrupt or popped inside an interrupt. | ||
| type InterruptQueue struct { | ||
| // This implementation uses a double-buffer of queues. | ||
| // bufSelect contains the index of the queue currently available for pop operations. | ||
| // The opposite queue is available for push operations. | ||
| bufSelect volatile.Register8 | ||
| queues [2]Queue | ||
| } | ||
|
|
||
| // Push a task onto the queue. | ||
| // This can only be safely called from inside an interrupt. | ||
| func (q *InterruptQueue) Push(t *Task) { | ||
| // Avoid nesting interrupts inside here. | ||
| var nest nonest | ||
| nest.Lock() | ||
| defer nest.Unlock() | ||
|
|
||
| // Push to inactive queue. | ||
| q.queues[1-q.bufSelect.Get()].Push(t) | ||
| } | ||
|
|
||
| // Check if the queue is empty. | ||
| // This will return false if any tasks were pushed strictly before this call. | ||
| // If any pushes occur during the call, the queue may or may not be marked as empty. | ||
| // This cannot be safely called inside an interrupt. | ||
| func (q *InterruptQueue) Empty() bool { | ||
| // Check currently active queue. | ||
| active := q.bufSelect.Get() & 1 | ||
| if !q.queues[active].Empty() { | ||
| return false | ||
| } | ||
|
|
||
| // Swap to other queue. | ||
| active ^= 1 | ||
| q.bufSelect.Set(active) | ||
|
|
||
| // Check other queue. | ||
| return q.queues[active].Empty() | ||
| } | ||
|
|
||
| // Pop removes a single task from the queue. | ||
| // This will return nil if the queue is empty (with the same semantics as Empty). | ||
| // This cannot be safely called inside an interrupt. | ||
| func (q *InterruptQueue) Pop() *Task { | ||
| // Select non-empty queue if one exists. | ||
| if q.Empty() { | ||
| return nil | ||
| } | ||
|
|
||
| // Pop from active queue. | ||
| return q.queues[q.bufSelect.Get()&1].Pop() | ||
| } | ||
|
|
||
| // AppendTo pops all tasks from this queue and pushes them to another queue. | ||
| // This operation has the same semantics as repeated calls to pop. | ||
| func (q *InterruptQueue) AppendTo(other *Queue) { | ||
| for !q.Empty() { | ||
| q.queues[q.bufSelect.Get()&1].AppendTo(other) | ||
| } | ||
| } |
This file contains hidden or 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,20 @@ | ||
| // +build arm,baremetal,!avr | ||
|
|
||
| package task | ||
|
|
||
| import "device/arm" | ||
|
|
||
| // nonest is a sync.Locker that blocks nested interrupts while held. | ||
| type nonest struct { | ||
| state uintptr | ||
| } | ||
|
|
||
| //go:inline | ||
| func (n *nonest) Lock() { | ||
| n.state = arm.DisableInterrupts() | ||
| } | ||
|
|
||
| //go:inline | ||
| func (n *nonest) Unlock() { | ||
| arm.EnableInterrupts(n.state) | ||
| } |
This file contains hidden or 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,10 @@ | ||
| // +build !arm !baremetal avr | ||
|
|
||
| package task | ||
|
|
||
| // nonest is a sync.Locker that blocks nested interrupts while held. | ||
| // On non-ARM platforms, this is a no-op. | ||
| type nonest struct{} | ||
|
|
||
| func (n nonest) Lock() {} | ||
| func (n nonest) Unlock() {} |
This file contains hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.