All of lore.kernel.org
 help / color / mirror / Atom feed
* Thread spinning in kernel snd_pcm_link()/snd_pcm_unlink()
@ 2018-09-28 16:23 Rob Duncan
  2018-10-02 15:14 ` Takashi Iwai
  0 siblings, 1 reply; 3+ messages in thread
From: Rob Duncan @ 2018-09-28 16:23 UTC (permalink / raw)
  To: alsa-devel@alsa-project.org, Takashi Iwai

I'm trying to address a bug where we end up with a thread spinning and
consuming an entire cpu.  The issue seems to be this code in
sound/core/pcm_native.c:

    /* Writer in rwsem may block readers even during its waiting in queue,
     * and this may lead to a deadlock when the code path takes read sem
     * twice (e.g. one in snd_pcm_action_nonatomic() and another in
     * snd_pcm_stream_lock()).  As a (suboptimal) workaround, let writer to
     * spin until it gets the lock.
     */
    static inline void down_write_nonblock(struct rw_semaphore *lock)
    {
            while (!down_write_trylock(lock))
                    cond_resched();
    }

The original commit for this is 67ec1072b053c15564e6090ab30127895dc77a89

What we're suspecting is that a normal thread (SCHED_OTHER) has a reader
lock and a real-time thread using SCHED_RR or SCHED_FIFO is trying to
take the writer lock.  If both threads are pinned to the same CPU for
some reason then the reader thread will never get scheduled (because the
real-time writer thread is still runnable), and we will never make
progress.

Does this sound right?  What can we do to fix this?

Thanks,

Rob.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-10-02 16:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-09-28 16:23 Thread spinning in kernel snd_pcm_link()/snd_pcm_unlink() Rob Duncan
2018-10-02 15:14 ` Takashi Iwai
2018-10-02 16:55   ` Rob Duncan

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.