All of lore.kernel.org
 help / color / mirror / Atom feed
From: Abramo Bagnara <abramo.bagnara@libero.it>
To: Jaroslav Kysela <perex@suse.cz>
Cc: Jeremy Hall <jhall@maoz.com>,
	"paul@linuxaudiosystems.com" <paul@linuxaudiosystems.com>,
	"alsa-devel@lists.sourceforge.net"
	<alsa-devel@lists.sourceforge.net>
Subject: Re: rme9652: possible deadlock
Date: Mon, 28 Apr 2003 21:15:00 +0200	[thread overview]
Message-ID: <3EAD7DB4.6060105@libero.it> (raw)
In-Reply-To: <Pine.LNX.4.44.0304282013310.1603-100000@pnote.perex-int.cz>

Jaroslav Kysela ha scritto:
> On Mon, 28 Apr 2003, Abramo Bagnara wrote:
> 
> 
>>Jaroslav Kysela ha scritto:
>>
>>>>CPU1:
>>>>
>>>>read_lock(link_manager);	read_lock(link_manager);
>>>>spin_lock(s1);			spin_lock(s2);
>>>>if (stream_in_group)		if (stream_in_group)
>>>>	spin_lock(group);		spin_lock(group); /* Waiting */
>>>>spin_lock(s2); /* BOOM! */
>>>>
>>>>I guess that 3rd version will be the one I propose ;-)
>>>
>>>
>>>Yep, it is in CVS now ;-) Except I don't use trylock...
>>>
>>>read_lock(link_manager);
>>>spin_lock(stream);
>>>....
>>>if (stream_in_group) {
>>>    spin_lock(group);
>>>    spin_unlock(stream);
>>>}
>>>....
>>>link_for_each(s) {	/* note that streams are locked in defined order now */
>>>    if (stream_in_group)
>>>        spin_lock(s);
>>>}
>>>....
>>>list_for_each(s) {
>>>    if (stream_in_group)
>>>        spin_unlock(s);
>>>}
>>>....
>>>if (stream_in_group) {
>>>    spin_lock(stream);
>>>    spin_unlock(group);
>>>}
>>>....
>>>spin_unlock(stream);
>>>read_unlock(link_manager);
>>
>>CPU1:				CPU2:
>>read_lock(link_manager);	read_lock(link_manager);
>>spin_lock(s1);			spin_lock(s2);
>>spin_lock(group);		spin_lock(group); // waiting
>>spin_unlock(s1);
>>//inside list_for_each
>>spin_lock(s1);
>>spin_lock(s2); // BOOM!
>>
>>I fear you cannot avoid trylock ;-)
> 
> 
> And this scenario:
> 
> read_lock(link_manager);
> spin_lock(s1);
> if (stream_in_lock) {
>   spin_unlock(s1);
>   spin_lock(group);
> }

It's unsafe (just like my solution) but without a way to knows that 
stream state might be changed (unlike my solution).

An example: on enter of snd_pcm_update_hw_ptr_interrupt stream state is 
RUNNING but on exit it might be XRUN.

The only way to solve all that is to accurately invalid any implicitly 
cached info across call to functions that promoting a single stream lock 
to a group lock have waited on group lock.

Of course you might enlarge this criteria to "across call to functions 
that might promote a single stream lock to a group lock". In this case 
your solution is fine too.

As a side note I've noted that almost all calls to SND_PCM_ACTION take 
the single lock just before. This is definitely a non sense: taking the 
group lock at 1st is the right solution. This imply to have two 
SND_PCM_ACTION: one for already locked groups and another for lock 
promotion.

-- 
Abramo Bagnara                       mailto:abramo.bagnara@libero.it

Opera Unica                          Phone: +39.546.656023
Via Emilia Interna, 140
48014 Castel Bolognese (RA) - Italy



-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf

  reply	other threads:[~2003-04-28 19:15 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-04-14 18:47 rme9652: possible deadlock Jeremy Hall
2003-04-22 14:16 ` Jaroslav Kysela
2003-04-22 19:22   ` Jeremy Hall
2003-04-22 19:42     ` Jaroslav Kysela
2003-04-22 22:04       ` Jeremy Hall
2003-04-23  9:51         ` Jaroslav Kysela
2003-04-23 15:06           ` Jeremy Hall
2003-04-23 19:19             ` Jaroslav Kysela
2003-04-24 10:03               ` Abramo Bagnara
2003-04-28  8:23                 ` Jeremy Hall
2003-04-28  8:58                   ` Abramo Bagnara
2003-04-28  9:58                     ` Jaroslav Kysela
2003-04-28 10:11                       ` Abramo Bagnara
2003-04-28 12:27                         ` Jaroslav Kysela
2003-04-28 12:47                           ` Abramo Bagnara
2003-04-28 18:16                             ` Jaroslav Kysela
2003-04-28 19:15                               ` Abramo Bagnara [this message]
2003-04-28  8:25                 ` Jeremy Hall
2003-04-28  8:44               ` Jeremy Hall

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3EAD7DB4.6060105@libero.it \
    --to=abramo.bagnara@libero.it \
    --cc=alsa-devel@lists.sourceforge.net \
    --cc=jhall@maoz.com \
    --cc=paul@linuxaudiosystems.com \
    --cc=perex@suse.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.