MiSTer-devel / Linux-Kernel_MiSTer

Other
12 stars 17 forks source link

Add cpufreq/overclock driver #34

Closed coolbho3k closed 1 year ago

coolbho3k commented 1 year ago

This PR adds a cpufreq driver for the Cyclone V SOC FPGA as configured in the DE10 Nano/MiSTer, including the optional ability to overclock or underclock the HPS MPU, or optionally even enable CPU frequency scaling on the MPU clock.

The driver has been tested by some folks on the MiSTer forums for quite some time, and I feel confident enough to create a PR for it.

Why would we need this?

  1. The biggest practical use case is currently to run MUNT at full or near-full speed for MIDI without external hardware, which users have been doing for some time.
  2. Any future hybrid emulation efforts that are CPU-bound will be enhanced. Although hybrid emulation is mostly academic now, benchmarks have shown a linear improvement on software emulators as well as some of the initial hybrid Amiga efforts.
  3. Games have been shown to load slightly faster if the loading is CPU bound :)
  4. CPU frequency scaling and underclocking itself is of just a little value to MiSTer users; the user can save a bit of power. The use of cpufreq is mostly due to the functionality "belonging" there in the kernel. We can think of the ability to get frequency scaling as a freebie.

Features

Technical notes

  1. The driver does not touch any of the Cyclone V's registers by default! The kernel's behavior remains the same as before unless user action is taken to change it, making any overclock/underclock functionality 100% optional. The effect of the driver is the MPU is initialized at 800 MHz and stays there unless it's touched by the user - we can verify this by logging. This is because the performance cpufreq governor is selected by default by the kernel config and the maximum frequency is set to 800 MHz on boot, which causes cpufreq to lock the frequency at 800 MHz.
  2. The driver uses documented Clock Manager registers to read/set the current VCO clock, which affects the MPU clock. It also sets dividers to keep the main, dbgat, and cfgs2fuser0 clocks at default despite a different VCO clock.
  3. Safety: Active cooling, or very good passive cooling is highly recommended when overclocking. There is, of course, no temperature sensor on the Cyclone V, although the industrial SKU is very heat tolerant. The userspace scripts I've made available warn the user about cooling; if a user doesn't use the script and skips the warning, then we assume they're technical enough to know what they're doing :) Anecdotally, from extensive past experience, ARM cores of this generation at this process node do not generally risk significant heat/safety issues when overclocking in this manner.

Testing

I've put the driver through many hours of transition testing - randomly transitioning between frequencies - with good luck.

Power Consumption

With a few USB devices and a fan plugged in, on the main MiSTer menu, I measured the total system power consumption:

1200 MHz (150% overclock): 1.254 A ~= 6.27 W
800 MHz (stock): 1.223 A ~= 6.12 W
400 MHz (50% underclock): 1.195 A ~= 5.98 W
sorgelig commented 1 year ago

though, i'm not sure if it's good.. Neither MT32 nor GM won't work reliably even with this overclock. MT32pi should be used for good MIDI.

also, HPS has no power management. It means CPU uses only one frequency WHOLE time. So if you set 1.2GHz, then it will be always 1.2GHz regardless if CPU is busy or idle. Actually there is no such thing as "idle" in this CPU.

birdybro commented 1 year ago

The underclock to 400MHz option being tied to the menu video_off feature in MiSTer.ini would be nice to save power, if possible.

sorgelig commented 1 year ago

there is no point for that. Power consumption difference is meaningless. Slower CPU speed may affect some processes as well. It won't be official feature. You can use it in scripts but there is no plans to change the freq from Main.