CPU usage spikes to 30% regularly during playback, no PulseAudio involved, just ALSA

Bug #368121 reported by mathew on 2009-04-27
4
Affects Status Importance Assigned to Milestone
mpd (Ubuntu)
Undecided
Unassigned

Bug Description

Binary package hint: mpd

Opening another bug report for this, because none of the stuff in #221951 applies.

I've got Ubuntu running headless on a 1GHz M10000. It was fine with 8.04 and 8.10, but since upgrading to 9.04 MPD is chewing CPU. Every few seconds it spikes to 30% CPU usage.

I'm not running PulseAudio, so it's not that. (I have libpulse0 installed because MPD demands it, but no other packages matching *pulse*.)

I've tried explicitly stating that I want ALSA output in /etc/mpd.conf, and that doesn't help. Right now it's:
audio_output {
  type "alsa"
  format 44100:16:2
  name "audio out"
}

The MP3 files are sourced from 44.1kHz 16 bit rips of CDs, so it's not a sample rate issue.

/var/log/mpd/errors.log says
Apr 27 13:17 : problems opening audio device while playing "meta/Orchestral_Manoeuvres_in_the_Da/Organisation_Remastered/08-Promise.mp3"
Apr 27 13:17 : problems opening audio device while playing "meta/Orchestral_Manoeuvres_in_the_Da/Organisation_Remastered/08-Promise.mp3"
Apr 27 13:17 : problems opening audio device while playing "meta/Orchestral_Manoeuvres_in_the_Da/Organisation_Remastered/09-Stanlow.mp3"
etc.

The CPU usage peaks so badly that the audio is glitching. I upped the audio_buffer_size to 16384 to get something listenable. Suggestions?

[Update]
Also:

# cat pcm0p/sub0/hw_params
access: RW_INTERLEAVED
format: S16_LE
subformat: STD
channels: 2
rate: 44100 (44100/1)
period_size: 2048
buffer_size: 16384

while playing, so it's not a 44.1->48kHz conversion problem.

mathew (meta23) on 2009-04-28
description: updated
mathew (meta23) wrote :

Did some more research. /etc/mpd.conf now reads

audio_output {
  type "alsa"
  format 44100:16:2
  name "audio out"
  period_time 50000
  auto_resample "no"
  use_mmap "yes"
  device "hw:0,0"
}

i.e. lock sample rate at native value bypass dmix according to http://mpd.wikia.com/wiki/Tuning

This has gotten the CPU usage down to around 20%, and made it less spiky. I've been able to drop audio_buffer_size to 4192 and max_output_buffer_size back to the default.

Might try OSS as a regrettable workaround.

drapsag (drapsag) wrote :

same behaviour here, without alsa and pulse...

I use MPD for streaming to icecast. When I activate ogg streaming, cpu peaks 40%, when I use mp3 cpu falls back to 19%. But that is far more than previous version Ubuntu does.

Before I used 8.10 with a compiled version of mpd 0.14.1 and then cpu hits no more of 2%

Hardware is T2400 and 3gig Ram. Ubuntu 9.04 amd64

drapsag (drapsag) wrote :

After some research I see this is normal behaviour:

http://mpd.wikia.com/wiki/Tuning

mathew (meta23) wrote :

Your behavior may be normal, drapsag, but there's no sample rate conversion involved with my setup.

I ran oprofile to see what was chewing the CPU, and here are the top entries from the log...

CPU: CPU with timer interrupt, speed 0 MHz (estimated)
Profiling through timer interrupt
samples % linenr info image name app name symbol name
16416 68.4485 (no location information) no-vmlinux no-vmlinux (no symbols)
6129 25.5556 (no location information) libmad.so.0.2.1 libmad.so.0.2.1 (no symbols)
413 1.7221 pcm_dither.c:75 mpd mpd pcm_dither_24_to_16
367 1.5303 (no location information) libc-2.9.so libc-2.9.so (no symbols)
94 0.3919 (no location information) libglib-2.0.so.0.2000.1 libglib-2.0.so.0.2000.1 (no symbols)
89 0.3711 mp3_plugin.c:1061 mpd mpd mp3_decode
74 0.3086 (no location information) libasound.so.2.0.0 libasound.so.2.0.0

So looks like it's either a kernel problem, or libmad. My sound card is snd_via82xx.

(Not sure how Ubuntu has libmad 0.2.1, given that the current version on the MAD web site is 0.15.1b.)

mathew (meta23) wrote :

More investigation:

Ripped out ALSA, installed OSS4. CPU usage went down slightly, sound quality improved.

Installed glib 2.18 from source, then installed mpd 0.15 from source, turning off everything except MP3, MP4 and OSS. CPU usage went down a bit more, glitching stopped even with the buffer size turned back down to the default.

So I have something that works again (installed via checkinstall so I can go back to provided packages when the problem is fixed).

Looks as if it's an MPD problem, not an ALSA problem; and it's somewhat improved in 0.15, but you'll have trouble building that for Ubuntu because it needs a much newer glib than Ubuntu has in the repos.

(To save you some time, the configure script for mpd says it needs glib 2.6, but glib 2.6 is incompatible with GCC 4.3, so you'll want something even more up to date. I had success with glib 2.18, which is the current non-development release.)

((Quite why Ubuntu still ships a version of glib that's about 5 years old, I don't know.))

mathew (meta23) wrote :

Well, 9.10 seems to have some major improvements in the kernel. I'm now running ALSA again, and CPU usage is stable at around 20%. Still excessive, but it's not spiking and causing dropouts all the time.

Changed in mpd (Ubuntu):
status: New → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers