Use KDE for audio stuff?

Optimize your system for ultimate performance.

Moderators: MattKingUSA, khz

Musicteacher
Established Member
Posts: 194
Joined: Mon Nov 13, 2017 5:54 am
Has thanked: 8 times
Been thanked: 4 times

Re: Use KDE for audio stuff?

Post by Musicteacher »

Hi Jack + Linuxmusician,

thank you for looking into this.

jack has a realtime priority, that is why one has to edit limits.conf and use the audio group and stuff like that. I had thought that the realtime-kernel would priorize threads with a realtime-priority even higher. So I understand now that it is still important do turn off non-audio stuff.

I have a pretty new notebook (Lenovo l380 yoga), the intention was to have a computer I can do everything with (I teach math, music and computer science, so there is quite a lot i do with my notebook).

I'm afraid that things get mixed up now with my other thread (about bad performance when power-plug is in), so I'll answer here to both, as you asked how things are going.

KDE runs really fast on my pc, and KDE is no longer "bloated" or what others still sometimes write about it. I really like it, especially dolphin, the file-manager. So I really do not intend to stop using kde for my everyday work, but I might use something else for audio stuff, if needed.

One problem was the system doing "behind-the-scene"-stuff. I guess with turning off networking and stopping file-indexing, this was widely fixed, I am not 100% sure that it is totally fixed.

The much bigger problem is that this notebook uses an "U"-processor. The general advice is to "turn off power-saving", but this is not so easy with modern processors. Simply using "performance" governor with cpupower ensures that the cpu is running at it's highest frequency while idle (!). As soon as it is really used, the frequency will be dropping, because the cpu cannot keep the highest turbo-boost frequency, it is not designed for that.

So I downloaded prime95 to make a stress test and see what frequency can be permanently kept up with my processor (intel Core i5-8250U, a very common processor in notebooks with 4 real cores). I watched the frequency with i7z, a very detailled tool designed for intel-processors. I saw that the frequency that can be kept up permanently is 1.8GHz. So now I use the following script:

Code: Select all

#!/bin/bash
for i in {4..7}; do
   echo "Disabling logical HT core $i."
   echo 0 > /sys/devices/system/cpu/cpu${i}/online;
done
cpupower frequency-set -u 1800MHz
cpupower frequency-set -d 1800MHz

The loop turns of the 4 logical cores (disables hyperthreading), I am not sure if this has any real impact. The two cpupower-lines set the frequency to vary between 1800MHz and 1800MHz (not vary at all, in other words).

This way I get good performance (though not as good as wich cpupower frequency-set -g performance as long as the machine is cool) and very stable. I still get an xrun every 5 or 15 minutes or so.

The last problem is that I use cpu-intensive stuff (pianoteq, guitarix) and need low-latency for live playing.

To get rid of the last xruns I plan the following two things:
- try turing pianoteq to 24kHz sample rate, I'll have to ask people if they hear a difference (I don't)
- disable processor c-states
I wonder if the second point is necessary, as the cores won't get much sleep when I do music anyway. But if one does accidently, this might provoke the occasional xrun.

All in all a low-voltage cpu seems to be ill-suited for audio. I had not realized this when I bought it. I have an old core2-quad desktop standing around which is more reliable in terms of xruns (but less powerful, of course).

Any hints for me? Sorry for the long post.

Andreas
User avatar
Linuxmusician01
Established Member
Posts: 1523
Joined: Mon Feb 23, 2015 2:38 pm
Location: Holland
Has thanked: 756 times
Been thanked: 134 times

Re: Use KDE for audio stuff?

Post by Linuxmusician01 »

Musicteacher wrote:I have a pretty new notebook (Lenovo l380 yoga), the intention was to have a computer I can do everything with (I teach math, music and computer science, so there is quite a lot i do with my notebook).
I have no experience w/ modern notebooks other than a Chromebook (I installed Linux w/ Crouton). I don't use that one for "heavy duty" work though.
Musicteacher wrote: - try turing pianoteq to 24kHz sample rate, I'll have to ask people if they hear a difference (I don't)
- disable processor c-states
[...]
All in all a low-voltage cpu seems to be ill-suited for audio. I had not realized this when I bought it. I have an old core2-quad desktop standing around which is more reliable in terms of xruns (but less powerful, of course).

Any hints for me? Sorry for the long post.

Andreas
I'm afraid I don't have any tips. I don't use Pianoteq, but using an audio app in 24 kHz seems a tiny bit drastic to me in 2019. Is it really that CPU/memory hungry? I use a Raspberry Pi sometimes for the Bristol synthesizer software. Even on the Pi I use Jack w/ 44.1 kHz then (via command line, no GUI). I do not know if I get many xruns in Jack then (I do not see its output) but If I activate polyphony on a synth on the Pi then I hear crackling sounds if I depress a lot of notes on the Midi keyboard (probably because of them xruns). And I can clearly hear the difference between 22.05 kHz and 44.1 kHz. The former results in noticeable "stepping" when I sweep the Filter of a synth (on low notes).

If I were you then I'd try exactly the same things on that desktop PC as you are doing on the laptop. If the desktop performs better, then you know the low-voltage CPU might be a problem.

Good luck! :)
Musicteacher
Established Member
Posts: 194
Joined: Mon Nov 13, 2017 5:54 am
Has thanked: 8 times
Been thanked: 4 times

Re: Use KDE for audio stuff?

Post by Musicteacher »

They call it the "internal sample rate". The jack-sampling rate stays at 48 kHz. Piano does not have an awful lot of sound-energy above 10 kHz anyway.

But I think I found a good solution: I use 96 bit buffer for jack. If I choose 32 kHz internal sampling rate for pianoteq the warning "bad value" for buffer size goes away. 32 kHz seems to fit the 96 bit buffer better (obvious explanation: 3*32 = 96, but in detail I don't quite understand, even if I probably should).

I sure don't hear any difference between those internal sample rates, but I have bad hearing anyway. I'll ask my daughter later if she hears any difference. But remark, most important in the very high frequencies are cymbals and stuff like that, not piano.

I'll probably make some kind of stress-test with all I found out, play several guitar-tracks together with piano, drums, strings, maybe set-b-free organ. I hope I found a good compromise now!
Musicteacher
Established Member
Posts: 194
Joined: Mon Nov 13, 2017 5:54 am
Has thanked: 8 times
Been thanked: 4 times

Re: Use KDE for audio stuff?

Post by Musicteacher »

Hi,
I have made my stresstest. I began with the usual occasional xrun.

Then I decided to try to disable c-states.

This can be done with the kernel parameters

Code: Select all

intel_idle.max_cstate=0
processor.max_cstate=1
This improved my system dramatically. xruncounter now always goes to well over 95% (most of the time 98%).

I recorded a stress test in qtractor:
- two piano tracks (pianoteq)
- three guitar-tracks (with cream machine)
- 2 sampler tracks (staccato strings + legato strings via carla-rack)
- bass guitar (with cabinet simulation + compression)
- 2 vocal tracks
- 1 synth-track
- drums (black pearl)
- limiter and reverb on master out

I had just one single xrun during the whole recording session - when I took a look at a terminal window where i7z was running.

First I had disabled processor power management in bios. But this did not work, i7z was still reporting deeper c-states. So the kernel-driver overrode the bios setting (you can find in the internet that this sometimes happens).

I hope that this was not all coincidence or placebo. But those modern cpus have very "deep" cstates, and the deeper the sleep, the longer it takes to wake them up. If you encounter random xruns on an otherwise well-configured system, you might want to try to disable them.

I hope that I have now found a config that works well and reliably for me. Looking forward to the next rehearsal!
Jack Winter
Established Member
Posts: 381
Joined: Sun May 28, 2017 3:52 pm

Re: Use KDE for audio stuff?

Post by Jack Winter »

Musicteacher wrote:jack has a realtime priority, that is why one has to edit limits.conf and use the audio group and stuff like that. I had thought that the realtime-kernel would priorize threads with a realtime-priority even higher. So I understand now that it is still important do turn off non-audio stuff.
Well, no matter if you use a realtime kernel or not, threads can be run using realtime priority, but yes you normally have to tweak the system to give the user the right to do so. The realtime kernel will just start threads faster than the other kernels, that is really the only relevant difference.
The much bigger problem is that this notebook uses an "U"-processor. The general advice is to "turn off power-saving", but this is not so easy with modern processors. Simply using "performance" governor with cpupower ensures that the cpu is running at it's highest frequency while idle (!). As soon as it is really used, the frequency will be dropping, because the cpu cannot keep the highest turbo-boost frequency, it is not designed for that.
If you have /dev/cpu_dma_latency in your filesystem you can also try the following script which will limit what C states are allowed:

Code: Select all

#!/usr/bin/env python2

import os
import sys
import os.path
import signal
import struct

if not os.path.exists('/dev/cpu_dma_latency'):
        print "no PM QOS interface on this system!"
        sys.exit(1)

if len(sys.argv) == 1:
        qos_target = 0
elif len(sys.argv) == 2:
        qos_target=int(sys.argv[1])
else:
        print "Syntax is: pm_qos [maximum latency in usecs] (default is 0)"
        sys.exit(1)

try:
        fd = os.open('/dev/cpu_dma_latency', os.O_WRONLY)
        os.write(fd, struct.pack("i",qos_target))
        print "Writing", qos_target, "to /dev/cpu_dma_latency"
        print "Press ^C to close /dev/cpu_dma_latency and exit"
        signal.pause()

except KeyboardInterrupt:
        print "closing /dev/cpu_dma_latency"
        os.close(fd)
        sys.exit(0
Reaper/KDE/Archlinux. i7-2600k/16GB + i7-4700HQ/16GB, RME Multiface/Babyface, Behringer X32, WA273-EQ, 2 x WA-412, ADL-600, Tegeler TRC, etc 8) For REAPER on Linux information: https://wiki.cockos.com/wiki/index.php/REAPER_for_Linux
Musicteacher
Established Member
Posts: 194
Joined: Mon Nov 13, 2017 5:54 am
Has thanked: 8 times
Been thanked: 4 times

Re: Use KDE for audio stuff?

Post by Musicteacher »

Interesting. Looks easier than using kernel parameters. Are there any disadvantages when using the 0us default?
Jack Winter
Established Member
Posts: 381
Joined: Sun May 28, 2017 3:52 pm

Re: Use KDE for audio stuff?

Post by Jack Winter »

Not really. I don't think this device is available on all CPUs, but basically you are telling it that you don't want it to go into any deeper C state that will impact on thread scheduling. Of course it might make your cpu run hotter and use more battery. You could experiment with higher values to see if that gives you lower temps and still an acceptable result. Personally I just use the default when I use the script.

I've managed to even get it incorporated into reaper, so normally I don't need to run the script. :twisted:
Reaper/KDE/Archlinux. i7-2600k/16GB + i7-4700HQ/16GB, RME Multiface/Babyface, Behringer X32, WA273-EQ, 2 x WA-412, ADL-600, Tegeler TRC, etc 8) For REAPER on Linux information: https://wiki.cockos.com/wiki/index.php/REAPER_for_Linux
Musicteacher
Established Member
Posts: 194
Joined: Mon Nov 13, 2017 5:54 am
Has thanked: 8 times
Been thanked: 4 times

Re: Use KDE for audio stuff?

Post by Musicteacher »

I've tried it. It works, but (big but): When run with default value, not only the cpus don't sleep anymore, but cpu clock goes up to max as well.

Within seconds (about 10) cpu temp went up by 20 degrees on my machine.

The kernel parameters I showed earlier do not affect cpu speed (this might be because I allowed c1 to happen, I don't know if lower clock equals halting the cpu inbetween, do you know that?).

I tried writing 10, this allows for c1, cpu speed stays low, temperature too, so this might be a good value for everyday stuff.
Jack Winter
Established Member
Posts: 381
Joined: Sun May 28, 2017 3:52 pm

Re: Use KDE for audio stuff?

Post by Jack Winter »

IIRC C0 & C1 states are ok, I don't think you should let it go below that.

I don't think CPU speed is related in any way to the CPU halting.

The kernel documentation contains some relevant information and explains this interface way better than I can do :) https://www.kernel.org/doc/html/latest/ ... ma_latency
Reaper/KDE/Archlinux. i7-2600k/16GB + i7-4700HQ/16GB, RME Multiface/Babyface, Behringer X32, WA273-EQ, 2 x WA-412, ADL-600, Tegeler TRC, etc 8) For REAPER on Linux information: https://wiki.cockos.com/wiki/index.php/REAPER_for_Linux
Musicteacher
Established Member
Posts: 194
Joined: Mon Nov 13, 2017 5:54 am
Has thanked: 8 times
Been thanked: 4 times

Re: Use KDE for audio stuff?

Post by Musicteacher »

Hm, also if I start that script (with value 10, for instance, as I said), the cpupower frequency-set does no longer work. Seems to be quite a difficult matter, but important! I'll have a look at your link later, thank you!
Jack Winter
Established Member
Posts: 381
Joined: Sun May 28, 2017 3:52 pm

Re: Use KDE for audio stuff?

Post by Jack Winter »

You might also want to turn off SMT (hyper threading). I've thought that it wasn't a problem on my i7, but it can cause xruns in some situations. I've noticed that the DSP load goes up while running a CPU heavy program in the background while reaper is running. That problem goes away when I disable the sibling CPUs. This is the first time I've really noticed this on an i7. I think it's normally not a problem, and I guess one has to balance the usefulness of more CPU power vs the DSP load and possible xruns, so a big YMMW :)

Maybe this is one reason that some people prefer a light environment, while others prefer something like KDE.
Reaper/KDE/Archlinux. i7-2600k/16GB + i7-4700HQ/16GB, RME Multiface/Babyface, Behringer X32, WA273-EQ, 2 x WA-412, ADL-600, Tegeler TRC, etc 8) For REAPER on Linux information: https://wiki.cockos.com/wiki/index.php/REAPER_for_Linux
Post Reply