The default cpu scaling governor in Fedora Linux is powersafe. It means that CPUs work at different frequencies depending on the current CPU load.
For example, my i7-8700K works at 800Mhz when it idle and speeds up to 4600-5200Mhz under load.
When I play GO with a lot of stops enabled, maximum reveberation time and high polyphony level, the sound distortion occurs (I use jackd 48000 sample rate, 5 buffers of 64 samples). The reason is that intel_pstate scaling driver does not look at jack dsp load as cpu load and the cpu speed remains 800-1200Mhz.
The old solution of this problem jackfreqd http://rg42.org/oss/jackfreqd/start is not compatible with recent linux kernels.
System-wide setting cpu scaling governor to performance (according the recommendation of https://wiki.linuxaudio.org/wiki/system_configuration ) also solves the problem but it is not desired, because I'd like to drop CPU speed when I don't play GO.
A few years ago I started a discussion with realtime kernel developers and proposed a patch to intel_pstate https://cm-mail.stanford.edu/pipermail/planetccrma/2014-September/018396.html But the problem disappeared when I switched to the normal kernel. And now it appears again.
As a workaround I start a special terminal session with "while true; do echo ; done" bash command that keeps CPU load and prevents CPU frequency from dropping down and there are no sound distortion occuring.
Could you introduce another workaround in GO itself: a special thread that would create a cpu load when I play GO instead of rinning "while true; do echo ; done" in a separate window? The simplest implementation of this thread would be an infinite loop with manual enebling and disabling. A smarter implementation would be a thread work depending on the used polyphony counter at the current time, that would stop working when no sound is played.
You can remove/reduce the wxMilliSleep in GOrgueMemoryPool::Entry() - this should do what you want.
But generating some load to fool the performance management driver is a broken solution. Just switch the govenor, while GO is running. Your setup must already have a startup script to coordinate the startup of jack, GO and other things. Why don't you add a sudo command to change the policy at startup and a switchback sudo command at stopping the stack? If you don't have got a stop section, start a shell script instead of GO:
powermanagement just complicates things without providing benefits. GO should run in high-performance mode - possibly as real time application.
I agree with "generating some load to fool the performance management driver is a broken solution", so it is just a temporary workaround. Enabling performance mode is another temporary workaround.
A better solution would be enchancing intel_pstate powermanagement. My patch proposed 4 years ago makes dropping cpu freq less aggressive. But more better - make the agressivity controlled via sysfs.
The best solution would be making intel_pstate controlled externally and integrate jackfreqd with it.
I'll will some testing with GOrgueMemoryPool::Entry() now
Hi, Martin.
I have tested excluding wxMilliSleep from GOrgueMemoryPool::Entry(): it works fine for me except it raises the CPU freq all the time when GO is loaded instead of raising only when I play. But it is sufficient for temporary solution.
Could you make the value of wxMilliSleep together with Polyphony limit in the "Advanced" tab of Audio/Midi?
I will think on making jackfreqd + intel_pstate to work together.
The whole thing just works for you, because probably all cores are locked to using the same speed and blocks some percent of one CPU core.
Some CPUs also feature individually adjustable CPU speed.
In regard to power management, the only task of GO should be to signal: I'm a real time application, which dislikes power saving.
You should look at: https://github.com/FeralInteractive/gamemode
Are you going to use gamemode in GO?
The software looks like a better solution than your "busy-loop" thread. It can be used with LD_PRELOAD without modifying software.
It a possible option for GO, if it is picked up by the various Linux distributions.
I've modified jackfreqd to be compatible with intel_pstate. The new version is available at https://github.com/oleg68/jackfreqd
With jackfreqd running it is safe now to play GO with the default "powersave" governor if GU uses jack sound output. There are no more XRuns and sound distortions.