music player daemon (fork)
Go to file
Max Kellermann bf05ce161f notify the decoder instead of polling 100hz
When the decoder process is faster than the player process, all
decodedd buffers are full at some point in time.  The decoder has to
wait for buffers to become free (finished playing).  It used to do
this by polling the buffer status 100 times a second.

This generates a lot of unnecessary CPU wakeups.  This patch adds a
way for the player process to notify the decoder process that it may
continue its work.

We could use pthread_cond for that, unfortunately inter-process
mutexes/conds are not supported by some kernels (Linux), so we cannot
use this light-weight method until mpd moves to using threads instead
of processes.  The other method would be semaphores, which
historically are global resources with a unique name; this historic
API is cumbersome, and I wanted to avoid it.

I came up with a quite naive solution for now: I create an anonymous
pipe with pipe(), and the decoder process reads on that pipe.  Until
the player process sends data on it as a signal, the decoder process
blocks.

This can be optimized in a number of ways:

- if the decoder process is still working (instead of waiting for
buffers), we could save the write() system call, since there is
nobody waiting for the notification.
[ew: I tried this using a counter in shared memory, didn't help]

- the pipe buffer will be full at some point, when the decoder thread
is too slow.  For this reason, the writer side of the pipe is
non-blocking, and mpd can ignore the resulting EWOULDBLOCK.

- since we have shared memory, we could check whether somebody is
actually waiting without a context switch, and we could just not
write the notification byte.
[ew: tried same method/result as first point above]

- if there is already a notification in the pipe, we could also not
write another one.
[ew: tried same method/result as first/third points above]

- the decoder will only consume 64 bytes at a time.  If the pipe
buffer is full, this will result in a lot of read() invocations.
This does not hurt badly, but on a heavily loaded system, this might
add a little bit more load.  The preceding optimizations however
are able eliminate the this.

- finally, we should use another method for inter process
notifications - maybe kill() or just make mpd use threads, finally.

In spite of all these possibilities to optimize this code further,
this pipe notification trick is faster than the 100 Hz poll.  On my
machine, it reduced the number of wakeups to less than 30%.

git-svn-id: https://svn.musicpd.org/mpd/trunk@7215 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2008-03-26 10:38:54 +00:00
doc Adding FIFO audio output. This is pretty much identical to the old one, 2007-06-13 14:15:30 +00:00
m4 Updating libFLAC.m4 so that -L isn't erroneously specified without an 2007-05-28 13:01:08 +00:00
scripts scripts/mpd-indent.sh: fixup goto label indentation 2007-12-16 21:47:48 +00:00
src notify the decoder instead of polling 100hz 2008-03-26 10:38:54 +00:00
AUTHORS Updating Kodest's name/email. 2007-06-25 12:13:45 +00:00
autogen.sh autogen.sh: support for newer autoconf versions (2.60, 2.61) 2008-01-27 23:10:37 +00:00
ChangeLog Update ChangeLog and TODO 2008-02-25 00:19:14 +00:00
configure.ac Check for pkg-config unconditionally. It might not be needed if we disable 2007-06-24 21:31:08 +00:00
COPYING import from SF CVS 2004-02-23 23:41:20 +00:00
INSTALL Updating INSTALL. 2007-05-27 13:38:52 +00:00
Makefile.am Merge branches/ew r7104 2007-12-28 02:56:25 +00:00
README Doc updates for 0.13.0 2007-03-31 15:20:39 +00:00
TODO Update ChangeLog and TODO 2008-02-25 00:19:14 +00:00
UPGRADING Updating UPGRADING. 2007-05-27 13:30:46 +00:00

                       Music Player Daemon (MPD)
                        http://www.musicpd.org

A daemon for playing music of various formats.  Music is played through the 
server's audio device.  The daemon stores info about all available music, 
and this info can be easily searched and retrieved.  Player control, info
retrieval, and playlist management can all be managed remotely.

To install MPD, see INSTALL.

MPD includes mp4ff in the source, due to licensing issues of the newer 
version and includes bugfixes with the properly licensed version.  mp4ff is 
released under the GPL and copyrighted by M. Bakker, Ahead Software AG 
(http://www.nero.com) and is distributed as a part of the FAAD2 - Freeware 
Advance Audio (AAC) Decoder.

MPD is released under the GNU Public License.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
For the full license, see COPYING.