Your SoC runs. The next question an architect asks is where its time goes. In cvsoc every cycle has a reason you can name: an instruction, a taken branch, the pipeline filling, or the core waiting for the bus. This article puts those reasons together into one equation, checks it against all six test programs, splits the waiting by the block that caused it, and uses the result to answer the usual what-if questions: what a faster SRAM, a faster bridge or a faster UART would buy. There is no graded exercise; the lab task at the end is a prediction you check against a report.
8 min read | Intermediate
What You'll Learn
- Account for every cycle of a program on the SoC with one equation
- Split the waiting cycles by target from the system report's access counts
- Estimate the effect of a faster memory, bridge or peripheral before building it
- Tell a program that is bound by the core from one bound by the bus or a device
Before You Start
This section needs Verilog: see the Verilog Tutorial, although this article asks you to calculate, not to write code. It helps to have passed S16 (The Complete SoC). Running Programs on an SoC explains the system report, Your Core Learns to Wait the cycle rule, and Latency and Bandwidth and System Performance Modeling the wider method.
One Equation for Every Cycle
The 3-stage core completes one instruction per cycle, loses one cycle for each taken branch or jump, needs two cycles to fill the pipeline at the start, and stands still for each cycle in which a memory is not ready. On the SoC that gives:
cycles = instructions + taken branches and jumps + 2 + wait cycles
The system report on the reference design counts each term, and the equation holds exactly for every program:
| Program | Instructions | Branches and jumps | Fill | Waits | Cycles |
|---|---|---|---|---|---|
hello | 7,666 | 1,551 | 2 | 7,046 | 16,265 |
copy_tcm | 21,522 | 3,071 | 2 | 5 | 24,600 |
copy_sram | 21,522 | 3,071 | 2 | 6,149 | 30,744 |
stream_div16 | 15,899 | 4,014 | 2 | 21,360 | 41,275 |
stream_div4 | 5,660 | 601 | 2 | 4,295 | 10,558 |
badaddr | 16 | 2 | 2 | 15 | 35 |
Each program has its own shape. copy_tcm is almost pure computation: it uses the bus only for its final store. copy_sram waits in a fifth of its cycles. The stream programs and hello wait in roughly 40 to 50 percent of theirs, and as the next section shows, that time is spent on one peripheral.
Splitting the Waits by Target
The waiting cycles are not a mystery either. Each access to a target costs a fixed number of cycles in cvsoc, and the core waits for all but one of them:
| Target | Cycles per access | Waiting cycles per access |
|---|---|---|
| TCM | 1 | 0 |
| SRAM | 4 | 3 |
| a peripheral (behind the bridge) | 6 | 5 |
So the waits follow from the access counts in the report. For hello: 512 SRAM accesses x 3 = 1,536 cycles, and 1,102 peripheral accesses (1,097 to the UART, 2 to the timer, 2 to GPIO, 1 to simulation control) x 5 = 5,510 cycles. Together 7,046, exactly the report's figure. Of those, the UART accounts for 1,097 x 5 = 5,485 cycles, a third of the whole run: the cost of polling STATUS that Running Programs on an SoC pointed out.
Quick Check
Q: copy_sram waits 6,149 cycles. It makes 2,048 SRAM accesses and one peripheral access (the store to EXIT). Do the numbers agree?
Show Answer
Yes: 2,048 x 3 = 6,144 for the SRAM, plus 1 x 5 = 5 for the EXIT store, is 6,149. That last store is also the only wait in copy_tcm, which waits exactly 5 cycles.
What-If Questions
With every cycle accounted for, you can estimate a change before building it, by changing one term:
- A 2-cycle SRAM (one waiting cycle instead of three):
copy_sramsaves 2,048 x 2 = 4,096 cycles, about 13 percent of its run.hellosaves 512 x 2 = 1,024, about 6 percent. - A bridge one cycle faster (5 cycles per peripheral access):
hellosaves 1,102 cycles. But most of those are STATUS reads in the polling loop, and the program would simply poll more often while waiting for the line; the real saving is close to nothing. The same is true ofstream. - A faster UART line: this is what helps the streaming programs.
streamruns at the line's pace, as The UART showed: from DIV = 16 to DIV = 4 the run drops from 41,275 to 10,558 cycles, almost exactly a quarter. - A faster core: for
copy_tcm, yes; for the stream programs and most ofhello, almost nothing, because their time is set by the bus and the line.
The second point is the important lesson. A program that polls a device is not limited by the bus or the core but by the device; making the path to it faster only makes the polling loop spin faster. That is the case for interrupts and DMA made in Polling, Interrupts and DMA: let the core do something useful, or nothing at low power, while the device works.
Bandwidth With One Transaction at a Time
One more limit is visible here. The manager port has one transaction in flight at a time, and an SRAM access takes 4 cycles, so the core can move at most one 32-bit word every 4 cycles to or from the SRAM: one byte per cycle, however fast the SRAM itself is. Real interfaces overlap transactions, issuing the next address before the previous data has returned, which is how they approach one word per cycle on the same bus; Outstanding Transactions and Bursts explains how.
Where Does This Matter?
Cycle accounting like this is how performance architects work long before RTL exists: a spreadsheet or a small model splits time into compute, stalls and waiting per target, and every proposed change is costed by changing one term. The model is then checked against the RTL, exactly as you checked the equation against the reports here. System Performance Modeling describes how those models are built and validated.
Common Mistakes
Mistake #1: Treating cycles per instruction as a property of the core
The core is the same in every program here, yet the cycles per instruction range from about 1.1 (copy_tcm) to about 2.6 (stream_div16). CPI on an SoC describes the program and the system together.
Mistake #2: Speeding up the path to a polled device
Cycles spent polling STATUS look like bus cost in the report, but they are waiting for the device. A faster bridge turns them into more polls, not into a shorter run. Look at what the program is waiting for before deciding what to speed up.
Your Turn in the Lab
A prediction to check. The report of stream_div4 shows 5,660 instructions, 601 taken branches and jumps, 601 reads and 257 writes to the UART, and one write to simulation control. Predict its wait cycles and its total cycles from the per-access costs above, then compare with the table at the top. If you passed S16 with your own blocks, also think about which of your blocks would change the prediction if it took an extra cycle per access.
Show Answer
Peripheral accesses: 601 + 257 + 1 = 859, each with 5 waiting cycles: 4,295 waits. Cycles: 5,660 + 601 + 2 + 4,295 = 10,558, exactly the report. A bridge or a peripheral with one extra cycle per access would add 859 cycles; an interconnect with one extra cycle would add one cycle to every bus access, here the same 859.
Summary
- On
cvsoc, cycles = instructions + taken branches and jumps + 2 + wait cycles, and the reports confirm it exactly for all six programs. - Waits follow from the access counts: 3 waiting cycles per SRAM access, 5 per peripheral access, none for the TCM.
- In
hello, polling the UART costs 5,485 cycles, a third of the run; a faster bridge would not shorten it, a program that did not poll would. - Changing one term of the equation estimates a design change before it is built; checking the equation against the RTL is what makes those estimates trustworthy.
- With one transaction in flight, the core moves at most one word every 4 cycles to the SRAM; overlapping transactions is how real systems go faster.