Skip to content
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

Investigate high frequency clock muxing as an alternative to an858, an909, an959 #44

Closed
martijnbastiaan opened this issue Apr 7, 2022 · 8 comments

Comments

@martijnbastiaan
Copy link
Contributor

A crucial part of a Bittide system is that each node can adjust its frequency based on its neighbors, thereby building a "synchronous enough" system. Eventually, we'll be able to use a DCO described in an858, an909, and an959 to very precisely step through frequencies. Off-the-shelve FPGA boards don't have this component though, so we'll either have to wait for a custom board or only test this behavior in simulation.

However, I think we might be able to implement the following clock muxing strategy, where BUFGMUX is a glitch-free clock mux available on Xilinx's 7-series FPGAs:

Untitled Diagram drawio(2)

By selecting clk_L half of the time while selecting clk_H the other half, we'll achieve an effective frequency of (freq(clk_l) + freq(clk_h)) / 2. This ratio can be changed by the frequency manager to achieve an arbitrary frequency bounded by the frequencies of the slow and fast clock.

In practice this will be slightly more complicated due to the way a BUFGMUX obtains a glitch free clock on its output:

Screenshot 2022-04-07 at 10-28-33 7 Series FPGAs Clocking Resources User Guide (UG472) - content

I.e., depending on the phase difference between clk_L and clk_H it might effectively skip a clock cycle. My gut feeling is that this doesn't really matter; if the mux introduces too many skips, this will picked up as a hint to run a little bit quicker. In fact; this is the whole point of this construction - to deal with clock drift.


A few variables affect this construction:

  1. The minimum difference between freq(clk_L) and freq(clk_H). Although on average we'll reach some desired frequency, at any given point we'll either run quickly or slowly. This needs to accounted for in the size of our elastic buffers (or some other buffer).
  2. How often the frequency manager can/will switch between clocks. Longer periods mean more fine-grained control over the average clock frequency, but like (1) this needs to be accounted for in buffer sizes.

Resources:

@martijnbastiaan
Copy link
Contributor Author

martijnbastiaan commented Apr 19, 2022

I just discussed this with Martin; the custom boards are unlikely to arrive any time soon, as no one has started working on them yet. For this year's implementation a very coarse clock correction mechanism with big buffers is perfectly fine.

@martijnbastiaan
Copy link
Contributor Author

This would affect #42. Divergence could now only be measured across long periods.

@vmchale
Copy link
Contributor

vmchale commented Apr 20, 2022

If I may ask, what's the story for simulating the custom boards? Or do we already have that.

@martijnbastiaan
Copy link
Contributor Author

@martijnbastiaan
Copy link
Contributor Author

If I may ask, what's the story for simulating the custom boards? Or do we already have that.

So for prosperity: this is one of the Clash SOWs. Basically we'd want to add a Signal to a Clock, indicating how long each period of a clock cycle is. This would allow things like unsafeSynchronizer to simulate the behavior of signals with a varying clock frequency (like clk in the diagram).

@martijnbastiaan
Copy link
Contributor Author

martijnbastiaan commented Apr 29, 2022

It looks like around the 200 MHz mark we can expect a PLL/MCMM to generate clock frequencies differing by ~10 MHz. Thinking out loud a bit about the precision we might achieve and how it affects buffer sizes..:

  • A precision of 1 Hz using a counter :: Index 10_000_000_000 and a threshold :: Index 10_000_000_000 and clk_select = counter <= threshold.
  • To make the math a bit easier, let's use counter :: Unsigned 30 and threshold :: Unsigned 30.
  • If we're unlucky, our threshold is exactly half, and two connected nodes switch their clocks in opposite direction. Thus, the FIFO would need to store 2^29 elements or 2^29 * 8 ~ 40000000000 bytes ~ 37 GiB when storing 64-bit elements. This is slightly 🤏 more than we have in blockrams.
  • We can do better by switching four times every 2**30 cycles (instead of two times). Now we count twice with counter :: Unsigned 29:
    • We do clk_select = counter <= threshold / 2 until the counter saturates, then:
    • We do clk_select = counter <= (threshold / 2) + (threshold % 2) until the counter saturates
    • Repeat
  • This would basically look like:

Untitled Diagram drawio(4)

  • The (threshold % 2) is there to make sure we don't lose accuracy. With even more counter "steps" we need to make sure we distribute this remainder over time (instead of appending it to the last counter cycle).
  • If we want to get it down to a more reasonable 1 MiB, we'd need to half about ~7 times. That is 128 count "steps".

The math is all very approximate, I'm sure there's at least one off-by-one error in there.

@martijnbastiaan
Copy link
Contributor Author

The diagram is supposed to read:

  • switching thrice => switching four times
  • switching four times => switching eight times

But drawio doesn't let me edit it anymore for some reason.. :-|

@martijnbastiaan
Copy link
Contributor Author

We're not going to do this, given that we now have the clock multiplier boards :).

lmbollen added a commit that referenced this issue Jan 8, 2025
68886c88 Merge pull request #46 from clash-lang/run-clang-format
a32dbc98 Add `clang-format-check` to ci
68ca4d0e Format with `clang-format`
9a676aa6 Add `clang` to nix shell
0d4be0e0 Merge pull request #45 from clash-lang/lucas/bump-jtag-interface
61c7719d Bump GHC versions on Docker images and rebuild
5f9a53c9 Add `.scala-build` to `.gitignore`
2c1ec3a3 Remove `openocd-vexriscv` from `nix` and `docker`
deabc085 Switch to `openocd-vexriscv` and use `remote-bitbang`
d987e396 Replace `DebugPlugin` with `EmbeddedRiscvJtag`
59298429 Add `nix` derivation for `openocv-riscv`
2dfda13f Add `.metals` to `.gitignore`
554f4af1 Bump scala and spinal version
720e5d44 Add execute permissions to `update-vexriscv.pu`
ad6edb75 Merge pull request #44 from clash-lang/lucas/add-docker-readme
636ac968 Extend readme with CI info
ac10433d Bump GHA actions (#43)
59215117 Merge pull request #42 from clash-lang/add-all-check
e697bfdd Fix typo: ouput -> output
e7e8e29c Add all check to CI

git-subtree-dir: clash-vexriscv
git-subtree-split: 68886c8879d3df885e977a658f245a8a782079e8
lmbollen added a commit that referenced this issue Jan 9, 2025
ca418fcb Merge pull request #47 from clash-lang/lucas/move-stoptime-ndmreset
27c82690 Move `ndmreset` and `stoptime` from `JtagOut` to `CpuOut`
68886c88 Merge pull request #46 from clash-lang/run-clang-format
a32dbc98 Add `clang-format-check` to ci
68ca4d0e Format with `clang-format`
9a676aa6 Add `clang` to nix shell
0d4be0e0 Merge pull request #45 from clash-lang/lucas/bump-jtag-interface
61c7719d Bump GHC versions on Docker images and rebuild
5f9a53c9 Add `.scala-build` to `.gitignore`
2c1ec3a3 Remove `openocd-vexriscv` from `nix` and `docker`
deabc085 Switch to `openocd-vexriscv` and use `remote-bitbang`
d987e396 Replace `DebugPlugin` with `EmbeddedRiscvJtag`
59298429 Add `nix` derivation for `openocv-riscv`
2dfda13f Add `.metals` to `.gitignore`
554f4af1 Bump scala and spinal version
720e5d44 Add execute permissions to `update-vexriscv.pu`
ad6edb75 Merge pull request #44 from clash-lang/lucas/add-docker-readme
636ac968 Extend readme with CI info
ac10433d Bump GHA actions (#43)
59215117 Merge pull request #42 from clash-lang/add-all-check
e697bfdd Fix typo: ouput -> output
e7e8e29c Add all check to CI

git-subtree-dir: clash-vexriscv
git-subtree-split: ca418fcb0024e12b4b2f9340d34aad47eaca370d
lmbollen added a commit that referenced this issue Jan 10, 2025
3a26b8bd Correcetly simulate passed time before first clock edge in verilator (#50)
51239127 Add post fetch step that removes `.git` (#48)
ca418fcb Merge pull request #47 from clash-lang/lucas/move-stoptime-ndmreset
27c82690 Move `ndmreset` and `stoptime` from `JtagOut` to `CpuOut`
68886c88 Merge pull request #46 from clash-lang/run-clang-format
a32dbc98 Add `clang-format-check` to ci
68ca4d0e Format with `clang-format`
9a676aa6 Add `clang` to nix shell
0d4be0e0 Merge pull request #45 from clash-lang/lucas/bump-jtag-interface
61c7719d Bump GHC versions on Docker images and rebuild
5f9a53c9 Add `.scala-build` to `.gitignore`
2c1ec3a3 Remove `openocd-vexriscv` from `nix` and `docker`
deabc085 Switch to `openocd-vexriscv` and use `remote-bitbang`
d987e396 Replace `DebugPlugin` with `EmbeddedRiscvJtag`
59298429 Add `nix` derivation for `openocv-riscv`
2dfda13f Add `.metals` to `.gitignore`
554f4af1 Bump scala and spinal version
720e5d44 Add execute permissions to `update-vexriscv.pu`
ad6edb75 Merge pull request #44 from clash-lang/lucas/add-docker-readme
636ac968 Extend readme with CI info
ac10433d Bump GHA actions (#43)
59215117 Merge pull request #42 from clash-lang/add-all-check
e697bfdd Fix typo: ouput -> output
e7e8e29c Add all check to CI

git-subtree-dir: clash-vexriscv
git-subtree-split: 3a26b8bdd1a1863030b89943d4bf229c2ce97831
lmbollen added a commit that referenced this issue Jan 13, 2025
3a26b8bd Correcetly simulate passed time before first clock edge in verilator (#50)
51239127 Add post fetch step that removes `.git` (#48)
ca418fcb Merge pull request #47 from clash-lang/lucas/move-stoptime-ndmreset
27c82690 Move `ndmreset` and `stoptime` from `JtagOut` to `CpuOut`
68886c88 Merge pull request #46 from clash-lang/run-clang-format
a32dbc98 Add `clang-format-check` to ci
68ca4d0e Format with `clang-format`
9a676aa6 Add `clang` to nix shell
0d4be0e0 Merge pull request #45 from clash-lang/lucas/bump-jtag-interface
61c7719d Bump GHC versions on Docker images and rebuild
5f9a53c9 Add `.scala-build` to `.gitignore`
2c1ec3a3 Remove `openocd-vexriscv` from `nix` and `docker`
deabc085 Switch to `openocd-vexriscv` and use `remote-bitbang`
d987e396 Replace `DebugPlugin` with `EmbeddedRiscvJtag`
59298429 Add `nix` derivation for `openocv-riscv`
2dfda13f Add `.metals` to `.gitignore`
554f4af1 Bump scala and spinal version
720e5d44 Add execute permissions to `update-vexriscv.pu`
ad6edb75 Merge pull request #44 from clash-lang/lucas/add-docker-readme
636ac968 Extend readme with CI info
ac10433d Bump GHA actions (#43)
59215117 Merge pull request #42 from clash-lang/add-all-check
e697bfdd Fix typo: ouput -> output
e7e8e29c Add all check to CI

git-subtree-dir: clash-vexriscv
git-subtree-split: 3a26b8bdd1a1863030b89943d4bf229c2ce97831
lmbollen added a commit that referenced this issue Jan 15, 2025
3a26b8bd Correcetly simulate passed time before first clock edge in verilator (#50)
51239127 Add post fetch step that removes `.git` (#48)
ca418fcb Merge pull request #47 from clash-lang/lucas/move-stoptime-ndmreset
27c82690 Move `ndmreset` and `stoptime` from `JtagOut` to `CpuOut`
68886c88 Merge pull request #46 from clash-lang/run-clang-format
a32dbc98 Add `clang-format-check` to ci
68ca4d0e Format with `clang-format`
9a676aa6 Add `clang` to nix shell
0d4be0e0 Merge pull request #45 from clash-lang/lucas/bump-jtag-interface
61c7719d Bump GHC versions on Docker images and rebuild
5f9a53c9 Add `.scala-build` to `.gitignore`
2c1ec3a3 Remove `openocd-vexriscv` from `nix` and `docker`
deabc085 Switch to `openocd-vexriscv` and use `remote-bitbang`
d987e396 Replace `DebugPlugin` with `EmbeddedRiscvJtag`
59298429 Add `nix` derivation for `openocv-riscv`
2dfda13f Add `.metals` to `.gitignore`
554f4af1 Bump scala and spinal version
720e5d44 Add execute permissions to `update-vexriscv.pu`
ad6edb75 Merge pull request #44 from clash-lang/lucas/add-docker-readme
636ac968 Extend readme with CI info
ac10433d Bump GHA actions (#43)
59215117 Merge pull request #42 from clash-lang/add-all-check
e697bfdd Fix typo: ouput -> output
e7e8e29c Add all check to CI

git-subtree-dir: clash-vexriscv
git-subtree-split: 3a26b8bdd1a1863030b89943d4bf229c2ce97831
lmbollen added a commit that referenced this issue Jan 22, 2025
3a26b8bd Correcetly simulate passed time before first clock edge in verilator (#50)
51239127 Add post fetch step that removes `.git` (#48)
ca418fcb Merge pull request #47 from clash-lang/lucas/move-stoptime-ndmreset
27c82690 Move `ndmreset` and `stoptime` from `JtagOut` to `CpuOut`
68886c88 Merge pull request #46 from clash-lang/run-clang-format
a32dbc98 Add `clang-format-check` to ci
68ca4d0e Format with `clang-format`
9a676aa6 Add `clang` to nix shell
0d4be0e0 Merge pull request #45 from clash-lang/lucas/bump-jtag-interface
61c7719d Bump GHC versions on Docker images and rebuild
5f9a53c9 Add `.scala-build` to `.gitignore`
2c1ec3a3 Remove `openocd-vexriscv` from `nix` and `docker`
deabc085 Switch to `openocd-vexriscv` and use `remote-bitbang`
d987e396 Replace `DebugPlugin` with `EmbeddedRiscvJtag`
59298429 Add `nix` derivation for `openocv-riscv`
2dfda13f Add `.metals` to `.gitignore`
554f4af1 Bump scala and spinal version
720e5d44 Add execute permissions to `update-vexriscv.pu`
ad6edb75 Merge pull request #44 from clash-lang/lucas/add-docker-readme
636ac968 Extend readme with CI info
ac10433d Bump GHA actions (#43)
59215117 Merge pull request #42 from clash-lang/add-all-check
e697bfdd Fix typo: ouput -> output
e7e8e29c Add all check to CI

git-subtree-dir: clash-vexriscv
git-subtree-split: 3a26b8bdd1a1863030b89943d4bf229c2ce97831
lmbollen added a commit that referenced this issue Jan 23, 2025
3a26b8bd Correcetly simulate passed time before first clock edge in verilator (#50)
51239127 Add post fetch step that removes `.git` (#48)
ca418fcb Merge pull request #47 from clash-lang/lucas/move-stoptime-ndmreset
27c82690 Move `ndmreset` and `stoptime` from `JtagOut` to `CpuOut`
68886c88 Merge pull request #46 from clash-lang/run-clang-format
a32dbc98 Add `clang-format-check` to ci
68ca4d0e Format with `clang-format`
9a676aa6 Add `clang` to nix shell
0d4be0e0 Merge pull request #45 from clash-lang/lucas/bump-jtag-interface
61c7719d Bump GHC versions on Docker images and rebuild
5f9a53c9 Add `.scala-build` to `.gitignore`
2c1ec3a3 Remove `openocd-vexriscv` from `nix` and `docker`
deabc085 Switch to `openocd-vexriscv` and use `remote-bitbang`
d987e396 Replace `DebugPlugin` with `EmbeddedRiscvJtag`
59298429 Add `nix` derivation for `openocv-riscv`
2dfda13f Add `.metals` to `.gitignore`
554f4af1 Bump scala and spinal version
720e5d44 Add execute permissions to `update-vexriscv.pu`
ad6edb75 Merge pull request #44 from clash-lang/lucas/add-docker-readme
636ac968 Extend readme with CI info
ac10433d Bump GHA actions (#43)
59215117 Merge pull request #42 from clash-lang/add-all-check
e697bfdd Fix typo: ouput -> output
e7e8e29c Add all check to CI

git-subtree-dir: clash-vexriscv
git-subtree-split: 3a26b8bdd1a1863030b89943d4bf229c2ce97831
lmbollen added a commit that referenced this issue Jan 24, 2025
3a26b8bd Correcetly simulate passed time before first clock edge in verilator (#50)
51239127 Add post fetch step that removes `.git` (#48)
ca418fcb Merge pull request #47 from clash-lang/lucas/move-stoptime-ndmreset
27c82690 Move `ndmreset` and `stoptime` from `JtagOut` to `CpuOut`
68886c88 Merge pull request #46 from clash-lang/run-clang-format
a32dbc98 Add `clang-format-check` to ci
68ca4d0e Format with `clang-format`
9a676aa6 Add `clang` to nix shell
0d4be0e0 Merge pull request #45 from clash-lang/lucas/bump-jtag-interface
61c7719d Bump GHC versions on Docker images and rebuild
5f9a53c9 Add `.scala-build` to `.gitignore`
2c1ec3a3 Remove `openocd-vexriscv` from `nix` and `docker`
deabc085 Switch to `openocd-vexriscv` and use `remote-bitbang`
d987e396 Replace `DebugPlugin` with `EmbeddedRiscvJtag`
59298429 Add `nix` derivation for `openocv-riscv`
2dfda13f Add `.metals` to `.gitignore`
554f4af1 Bump scala and spinal version
720e5d44 Add execute permissions to `update-vexriscv.pu`
ad6edb75 Merge pull request #44 from clash-lang/lucas/add-docker-readme
636ac968 Extend readme with CI info
ac10433d Bump GHA actions (#43)
59215117 Merge pull request #42 from clash-lang/add-all-check
e697bfdd Fix typo: ouput -> output
e7e8e29c Add all check to CI

git-subtree-dir: clash-vexriscv
git-subtree-split: 3a26b8bdd1a1863030b89943d4bf229c2ce97831
lmbollen added a commit that referenced this issue Feb 19, 2025
da3b01a2 Set cache path to Cabal store set in `shell.nix` (#65)
3f9758a1 Check whether Nix shell works on CI (#61)
9363f8d4 Merge pull request #63 from clash-lang/improve-expect-functions
79c5e34a Add timeout to expect functions
ed39928d Add call stack to `waitForLine`
f1d76ead Use `tail` instead of `streaming` to follow files (#64)
e86580bf Remove enable from `cpu` (#58)
c69899c2 Drop register on wishbone bus (#59)
1715fc73 Print `JTAG bridge ready` and wait for it to prevent race conditions (#57)
1ca5a69d Merge pull request #53 from clash-lang/add-fourmolu
5e11a6f6 Add `.git-blame-ignore-revs`
2bd141e6 Add fourmolu formatting
96ad7244 Use `HasCallStack` instead of manual source line tracking (#52)
3900cb07 Bump OpenOCD (#54)
3a26b8bd Correcetly simulate passed time before first clock edge in verilator (#50)
51239127 Add post fetch step that removes `.git` (#48)
ca418fcb Merge pull request #47 from clash-lang/lucas/move-stoptime-ndmreset
27c82690 Move `ndmreset` and `stoptime` from `JtagOut` to `CpuOut`
68886c88 Merge pull request #46 from clash-lang/run-clang-format
a32dbc98 Add `clang-format-check` to ci
68ca4d0e Format with `clang-format`
9a676aa6 Add `clang` to nix shell
0d4be0e0 Merge pull request #45 from clash-lang/lucas/bump-jtag-interface
61c7719d Bump GHC versions on Docker images and rebuild
5f9a53c9 Add `.scala-build` to `.gitignore`
2c1ec3a3 Remove `openocd-vexriscv` from `nix` and `docker`
deabc085 Switch to `openocd-vexriscv` and use `remote-bitbang`
d987e396 Replace `DebugPlugin` with `EmbeddedRiscvJtag`
59298429 Add `nix` derivation for `openocv-riscv`
2dfda13f Add `.metals` to `.gitignore`
554f4af1 Bump scala and spinal version
720e5d44 Add execute permissions to `update-vexriscv.pu`
ad6edb75 Merge pull request #44 from clash-lang/lucas/add-docker-readme
636ac968 Extend readme with CI info
ac10433d Bump GHA actions (#43)
59215117 Merge pull request #42 from clash-lang/add-all-check
e697bfdd Fix typo: ouput -> output
e7e8e29c Add all check to CI

git-subtree-dir: clash-vexriscv
git-subtree-split: da3b01a2fc91f55cec7fa33c1f07f88631d02ecf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants