1. 12 Apr, 2008 30 commits
  2. 30 Mar, 2008 1 commit
  3. 27 Mar, 2008 1 commit
  4. 26 Mar, 2008 8 commits
    • Eric Wong's avatar
      notify: more cleanups, add error checking for pipe errors · 53be85e1
      Eric Wong authored
      Don't bother initializing the junk buffer, we really don't care.
      The array was also unnecessary and ugly.
      
      Also, avoid returning the byte count we read/wrote since it
      unnecessarily exposes internal details of the implementation to
      the callers.
      
      git-svn-id: https://svn.musicpd.org/mpd/trunk@7219 09075e82-0dd4-0310-85a5-a0d7c8717e4f
      53be85e1
    • Eric Wong's avatar
      interface: use a saner fdmax for select(2) when closing errored interfaces · 19d4f6df
      Eric Wong authored
      git-svn-id: https://svn.musicpd.org/mpd/trunk@7218 09075e82-0dd4-0310-85a5-a0d7c8717e4f
      19d4f6df
    • Eric Wong's avatar
      notify: cleanups · 232c9f6c
      Eric Wong authored
      * move set_nonblock{,ing}() into utils.c since we use it
      elsewhere, too
      * add proper error checking to set_nonblocking()
      * use os_compat.h instead of individually #includ-ing system headers
      
      git-svn-id: https://svn.musicpd.org/mpd/trunk@7217 09075e82-0dd4-0310-85a5-a0d7c8717e4f
      232c9f6c
    • Max Kellermann's avatar
      send notify signal after SIGCONT · 70dbc2b0
      Max Kellermann authored
      When the decoder receives SIGCONT during waitNotify(), the kernel
      restarts the read() system call.  This lets the decoder process block
      indefinitely, while the player process waits for it to react.  This
      should probably be solved with a proper signal handler which aborts
      the read() system call, but for now, we just write to the pipe to make
      it wake up.
      
      git-svn-id: https://svn.musicpd.org/mpd/trunk@7216 09075e82-0dd4-0310-85a5-a0d7c8717e4f
      70dbc2b0
    • Max Kellermann's avatar
      notify the decoder instead of polling 100hz · bf05ce16
      Max Kellermann authored
      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
      bf05ce16
    • Max Kellermann's avatar
      unsigned counters · 1d97bbbd
      Max Kellermann authored
      Use unsigned variables for storing the count of items or for iteration
      variables.  Since there can never be a negative number of items, it
      makes sense to use an unsigned data type here.  This change is safe
      because the unsigned values are only used for adddressing array items.
      
      git-svn-id: https://svn.musicpd.org/mpd/trunk@7214 09075e82-0dd4-0310-85a5-a0d7c8717e4f
      1d97bbbd
    • Max Kellermann's avatar
      don't repeat select() · e4779fa7
      Max Kellermann authored
      The interfaces main loop repeats the select() (non-blocking) after an
      event was handled.  I do not see any reason for that, since all events
      should be handled after the first select().  This double select() does
      nothing than consume more CPU cycles.
      
      git-svn-id: https://svn.musicpd.org/mpd/trunk@7213 09075e82-0dd4-0310-85a5-a0d7c8717e4f
      e4779fa7
    • Max Kellermann's avatar
      unlimited select() timeout · f9e317cc
      Max Kellermann authored
      mpd sets a 1s select() timeout for no reason.  This makes mpd wake up
      the CPU, consume some cycles just to see there is nothing to do.  We
      can save that by specifying NULL instead of a timeout.
      
      git-svn-id: https://svn.musicpd.org/mpd/trunk@7212 09075e82-0dd4-0310-85a5-a0d7c8717e4f
      f9e317cc