Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The overhead of coroutine processes is fairly high. A clock driver implemented through a coroutine process is mostly overhead. This was partially addressed in commit 2398b79 by microoptimizing yielding. This commit eliminates the coroutine process overhead completely by introducing dedicated clock processes. It also simplifies the logic to a simple toggle. This change improves runtime by about 12% on Minerva SRAM SoC.
- Loading branch information
1 parent
c00219d
commit 9bc42cb
Showing
2 changed files
with
38 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import inspect | ||
|
||
from ._core import Process | ||
|
||
|
||
__all__ = ["PyClockProcess"] | ||
|
||
|
||
class PyClockProcess(Process): | ||
def __init__(self, state, signal, *, phase, period): | ||
assert len(signal) == 1 | ||
|
||
self.state = state | ||
self.slot = self.state.get_signal(signal) | ||
self.phase = phase | ||
self.period = period | ||
|
||
self.reset() | ||
|
||
def reset(self): | ||
self.runnable = True | ||
self.passive = True | ||
self.initial = True | ||
|
||
def run(self): | ||
if self.initial: | ||
self.initial = False | ||
self.state.timeline.delay(self.phase, self) | ||
|
||
else: | ||
clk_state = self.state.slots[self.slot] | ||
clk_state.set(not clk_state.curr) | ||
self.state.timeline.delay(self.period / 2, self) | ||
|
||
self.runnable = False |
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