CDC detection with yosys #3956
Replies: 6 comments 1 reply
-
I'm disappointed this post didn't get any responses. Don't other people care about linting their designs? Here sift9.txt is an updated post-processing script. It separates the inputs of DFF, which squelched a couple of false-positives compared to the previous approach of combining them. It only applies the magic_cdc attribute to the D input. It also lists clocks by their net names instead of net number. |
Beta Was this translation helpful? Give feedback.
-
Oh, I also confirmed this process works on yosys-0.33. |
Beta Was this translation helpful? Give feedback.
-
I'm also currently working on implementing CDC detection, but as a yosys plugin. I saw this and was very interested in looking at your code but just didn't find the time yet! We might consider integrating some infrastructure for detecting clock domains upstream, it seems like something that would find a variety of uses. |
Beta Was this translation helpful? Give feedback.
-
I've been using this tool for a while now. Even with its limitations, I've found its analysis helpful in cleaning up a big design. The time spent in yosys seems excessive: 10 minutes on a pretty fast computer, working on a 14K LOC code base.
For the purposes of understanding where the time is spent, I processed stdout from yosys with a simple awk command
So the result is cumulative time (in seconds) vs. step. Ignoring the many sub-steps, my result was
.. showing that 79% of the time is spent in the OPT pass -- specifically |
Beta Was this translation helpful? Give feedback.
-
The python program is now called Documentation is posted at I did mess with the yosys OPT steps, and reduced compute time by about 3X. Comments and discussion are welcome. |
Beta Was this translation helpful? Give feedback.
-
For years, I've wished for a tool that can probe an HDL design for CDC (clock-domain-crossings), but never talked anyone into doing that work for me. Now I finally tried it myself with yosys, and I'm glad I did. I learned a few things, and it's already helping me find defects in my $DAYJOB code base.
Attached for your amusement is a 260-line python program that sifts through a yosys-output json file, looking for bad or unexpected CDC. Its strategy is to iterate through all the DFF, tracing backwards from a D port, through all combinational logic, looking for DFF Q source terms. It can collect all the C net indices from those source terms, compare them with the C net used for the original DFF, and draw conclusions about CDC. It handles block memories, too; it assues that they're used intentionally as part of a CDC mechanism.
Well, yes, of course it has issues. One need is to choose a real name (not "magic_cdc") for a Verilog attribute marking intentional CDC regs. And most fundamentally, it needs to move beyond the it-works-for-me stage. Maybe some people would like a less-strict handling of top-level-module input pins.
Before special-casing memories, the yosys commands I used would explode block memory into individual DFF plus decoders. When used to cross clock domains (e.g., in a FIFO), the output register of such an exploded block-memory depends on all the data bits of its slice (in the clka domain), and all the readout address decoders (in the clkb domain). Bad, by definition. Also, the data structures were huge.
I am still learning about yosys's capabilities of transforming the design. The yosys commands I use are given in the comments of the attached python.
Here's how to demo / replicate my work so far. Download the two attachments, sift8.py and hw_netlist.ys (and rename them from the txt suffix that github likes).
sift8.txt
hw_netlist.txt
On a general-issue Linux box (I use Debian Stable) with development tools, python3, iverilog, and yosys installed, do:
Expected output is one status line per DFF, followed by an index of clocks, and
If accessing the git repo and other tools involved are somehow a hardship for someone out there, I can provide a 36K tarball containing all the relevant files, preprocessed and ready for the yosys step.
Note that I use yosys 0.23 (comes with Debian Stable). It Would Be Nice if I could keep doing that, but I'd understand if you point me to a newer version.
And of course, if there's already a native yosys one-liner that does this, please tell me about it. Or features could be added to let yosys take over some of this functionality? Efficiency wouldn't be the motivation for such work. For a larger design (14K LOC), I spend 98% of my CPU time in yosys, 2% in the post-processor. I have no particular love for python+json.
In general, please treat this as a request-for-comments. Improvements? Criticisms? Pointers to related (open-source) work?
Beta Was this translation helpful? Give feedback.
All reactions