How it was measured

The figures on these pages come from small test programs run on a PSP with firmware 6.61, over PSPLink. They're kernel modules, because they read the CPU's hardware profiler, which user mode can't reach.

The hardware profiler

The Allegrex has a set of performance counters at 0xBC400000: twenty 32-bit registers, laid out as PSPSDK's PspDebugProfilerRegs. Write 0 to the first register and zero the others to reset them, and write 1 to the first to start counting.

offsetnamewhat it counts
0x00enablewrite 1 to count, 0 to stop
0x04systemckclock cycles of the PLL. The same as cpuck at 222 and 333 MHz, 1.5 times it when the CPU runs at 222 MHz from a 333 MHz PLL
0x08cpuckCPU cycles while the CPU is running. It stops while the CPU sleeps waiting for an event, for example while a thread waits for a DMA copy
0x0Cinternalcycles stalled inside the pipeline: load-use stalls, back-to-back stores
0x10memorycycles stalled waiting for memory: misses and uncached accesses
0x14copzcycles stalled on the FPU (for example waiting for an add.s result)
0x18vfpucycles stalled on the VFPU *
0x1Csleepcycles asleep *
0x20bus_accessroughly the bus cycles spent on uncached accesses and misses, the scratchpad's included
0x24uncached_loaduncached loads
0x28uncached_storeuncached stores
0x2Ccached_loadcached loads, the scratchpad's included
0x30cached_storecached stores, the scratchpad's included
0x34i_missI-cache line misses
0x38d_missD-cache line misses
0x3Cd_writebackdirty D-cache lines written back
0x40cop0_instCOP0 instructions *
0x44fpu_instFPU instructions *
0x48vfpu_instVFPU instructions *
0x4Clocal_busalways 0 in everything tried

The counters marked * go by their names and weren't checked against a known count. The miss and writeback counts are exact, which makes the profiler good for checking a cache model line by line, not just for timing.

The tests

Each measurement turns interrupts off, resets and starts the profiler, runs a loop, and stops the profiler. The counts of an empty loop are subtracted. Most tests run each loop twice, once with warm caches and once after sceKernelDcacheWritebackInvalidateAll.

The instruction and pipeline tests are generated: each test is a loop whose body repeats one pattern several times, such as eight dependent add.s, eight independent ones, or a producer, N nops and a consumer for N from 0 upwards. The point where adding a nop starts costing a cycle is the latency.

A kernel module and the file it was loaded from both have to fit in about 236 KB of free kernel memory, which the generated tests don't. They're linked as flat binaries at a fixed address in user memory instead, read from the host by a small kernel module, and called after a D-cache writeback and an I-cache invalidate. Kernel-mode code runs fine from user memory.

The DMA tests measure wall time with sceKernelGetSystemTimeWide, because the thread sleeps while the copy runs and cpuck stops with it. The GE tests use hand-built display lists and wait for them with sceGeListSync in polling mode, with interrupts on and a time limit.

Things to avoid

These wedged the PSP during testing, needing a manual restart:

  • Running VFPU code in a kernel module's main thread. It hangs on the first VFPU instruction. Create a thread with PSP_THREAD_ATTR_VFPU (0x4000) for it.
  • Waiting for the GE with interrupts off. The kernel finishes a display list in the GE interrupt, so with interrupts off the queue stands still at the list's FINISH, and a wait never returns.
  • sceGeBreak with a list queued. It leaves the GE driver paused, later lists never run, and PSPLink's reset hangs.
  • Loading from a pointer that a test might overwrite. An address error in a kernel module takes down the whole PSP, not just the test.