[edn/rtl] Synthesis: will clock gating be employed, or require design to directly control
The issue was brought up in the review of the EDN module, but is of a more general nature. The basic issue is will synthesis be set up to use clock gating (an automatic synthesis function) to save power. If this is not the case, then the design will have to have specific control logic to create various pulses to minimize power for static value propagation, or some other techniques.
@tjaychen please add others to this issue as appropriate.
@zi-v @arnonsha
could you guys comment a bit on the strategy you use on your end?
For example, in the following construction, if some_signal is always 1, does that end up clocking the flop forever?
Or is the power gating strategy in this case smart enough to know that the value is not changing and therefore okay?
I've definitely run into a fair number of cases where it wasn't smart enough. But not sure what to expect in this case.
always_ff @(posedge clk) begin
signal_q <= signal_d
...
end
assign signal_d = some_signal ? '0 : signal_q
Not sure what you mean by "therefore okay". if the enable signal some_signal is constant '1' then why put a clock gating cell ?
sorry i should have clarified. some_signal is not always constant, i just meant there are conditions in which the value is static and unchanging. If that is the case, i've seen implementations that still insert a cg, but the cg enable is just some_signal. This causes the relevant flops to basically clock for a long time instead of just a pulse (which is what we would get if the enable used an XOR of the next and current state).
So just wanted to check in your flow what you guys typically see and expect to happen?
Xor self gating is used usually when you want to bring down dynamic problem. The overhead is mainly congestion and area. For example a cluster of 8FFs will use extra 8 XOR2 and 7 OR2 (on top of the ICG cell). To allow xor self gating you need to specify a special synthesis flag in DC, or as a special optimization stage in ICC. Currently we don't use it at all due to the high overhead.
thanks @arnonsha , so is it reasonable to say then the situation i described will probably just result in constant clocking so long as some_signal is 1?
Somehow this didn't quite make it to top-of-queue for me when this thread happened before, so apologies for commenting very late. The XOR self-gate is generally very bad for anything processing keys as well, as it can behave like an SCA "amplifier" - so if there is any future consideration to enable this either in DC or ICC we need to be very careful about where it is allowed.
ah yes thanks for reviving this Chris. (it compeltely skipped my mind).
But coming back to the original question.. if we do not use XOR gating, doesn't that mean the below construction will do as i suggest...constantly clock if some_signal is just active high for an extended period of time?
It seems for power purposes (security aside), we would be better served making that a pulse correct?
always_ff @(posedge clk) begin
signal_q <= signal_d
...
end
assign signal_d = some_signal ? '0 : signal_q```
For at least the power aspect of the concern here, my experience is that the power consumption comes from the clock pulse, not the propagating a particular value. If DC automatic clock gating is enabled, it will gate the clock, not the data, based on whether the data is changing. So in this example, there is no savings between clocking a pulse or a static value. Interested to see if others have the same understanding.
Since this issue has been open about 6 months and did not see any feedback from my last comment, I think we should close this one. I am going to assign to @tjaychen to make the final call. Assign back if you still want it open, otherwise we should close.
For at least the power aspect of the concern here, my experience is that the power consumption comes from the clock pulse, not the propagating a particular value. If DC automatic clock gating is enabled, it will gate the clock, not the data, based on whether the data is changing. So in this example, there is no savings between clocking a pulse or a static value. Interested to see if others have the same understanding.
Ah, this one completely fell off my radar.
Without clock-gating enabled: there is power consumption for both parts of the process, almost all flops are still built as master-slave latch pairs (this is still the standard terminology so keeping it for now instead of host-device for the purposes of this comment thread). The clock pulse will activate some part of the master latch even if it's the same value. Then there is also power consumption on the output of the flops caused by the slave latch updating (both the output driver and the net load switching), if there is a new value propagating out. If Q is constant, there is no switching power here (obviously).
With clock-gating enabled, DC inserts logic that computes D^Q for the flop and uses that to inhibit/pass the clock pulse to the flop, so even the front-end of the master latch doesn't fire. The tools can do fancier things (maybe only in ICC when it actually has the CTS available to it), where it can compute D[n:0] ^ Q[n:0] for a wide value, and it will insert the inhibit/pass structure up one (or even two) levels higher from the leaf clock tree nodes, meaning that some clock buffer network power is saved too.
As far as the pulse concern - I think it works out to the same power consumption regardless of how you build it, basically that front-end of the master latch of the flop will be activated on every high phase of the clock. Inserting dynamic clock gates removes that (but adds the leakage power of the XOR, plus presents a possible SCA security issue depending on the sensitivity of the value in the reg).
@cdgori i think what @arnonsha was saying above is that they do not currently do the XOR compute for clock pulse inhibiting. So if we look at this purely from power perspective, i think feeding in the same value all the time might actually end up clocking that front element always as you say.
For some of my past projects, we had very explicit rules about coding the enable to be a pulse and never a level value, because the latter does not always achieve the intended goal. What @arnonsha seems to be saying is that the same is true here.
To your point about SCA, honestly I don't really know how to make that trade-off, since I don't have a good sense how much things would get worse. Specifically for the entropy blocks, I think I would argue that the trade-off is worth it since these blocks specifically are not hardened to start with.
Isn't fine-grain clock gating bad for SCA, even without the XOR self-gating? Are the SCA tools sophisticated enough to detect a bank of flops being loaded based on the clocks being ungated periodically?
@dsandrs I don't think I understand your scenario. @tjaychen I can speculate that pulse-based design is slightly more susceptible to fault attacks (just because killing a pulse is easier than killing a level). However, I don' think it is practical to avoid having pulse signals in the design. As for the "some_signal" related example above, I believe that when xor flag is not activated, the clock gate is open according to the signal level. Also note that some of the CG power comes from the fact that a single CG can replace multiple muxes. Referring again to the code example above, if signal_q and signal_d are each 100-bit wide busses, it would still need a single clock gate to gate all their transitions (instead of 100 muxes in the non-CG case).
@zi-v thanks ziv vof the input. Yes I agree with what you're saying, and yes my concern is as you say, if the xor flag is not there, the clock gate will just remain open all the time, thus consuming the 100-bit power.
To @dsandrs question, I think our thinking is that fine grained clock gating would amplify the signal of when a flop is loaded. So the worry is that this potentially creates more signal leakage for SCA. Is this something you guys have investigated?
Isn't fine-grain clock gating bad for SCA, even without the XOR self-gating? Are the SCA tools sophisticated enough to detect a bank of flops being loaded based on the clocks being ungated periodically?
In essence yes they are.
If you are doing something with two distinct power signatures (i.e. scenario 1) Dnext = Qcurrent = 0 (or 1), so gate clock, or scenario 2) Dnext != Qcurrent, so ungate) you are potentially leaking a lot of information. The only questions are: how many samples/traces it takes to divide the scenario 1 traces from the scenario 2 traces, and does the fact that in both scenarios Dnext could be either 0 or 1 help you enough to obscure the underlying value? If there is any way to observe the output - say it is ciphertext that is being transmitted off-chip, and the adversary can request this encryption many times, I would guess that you would have a problem (here, it depends on what you think "many" means).
@tjaychen given the discussion above, I have not sure if anything has been concluded. Given that we are coming into the range of tape out, I think we should close this issue unless there is new information to consider.
Closing by EOW if no new updates.
@arnonsha i did discuss with Arnon at some point. So the bottom line is, synthesis will insert clock gates. However it will only do so for the basic case.. ie
always_ff @(posedge clk or negedge rst_n) begin
....
if (en) begin
blah_q <= blah_d;
end
The tool will take the enable signal and use it to control a clock gate. However, what we will NOT do, is do a data consistency check (XOR) of the current data and the new data and use that to generate a clock gate.
Can you correct me if I mis-spoke Arnon?
Yes, I believe we have discussed this before: Simple clock gates will be inserted in synthesis. We are not using XOR gating because of area and because these XORs are enablers for SCA.
Ok, thanks. My take away is that for most flops (unless an enable is explicitly coded), there will be no clocking at all. For entropy complex blocks, it could the case that the system clock is relatively slow such that power is not a concern. We are taking that trade-off versus the XOR SCA exposure.