From: Vinod Koul <vinod.koul@intel.com>
To: Takashi Iwai <tiwai@suse.de>
Cc: alsa-devel@alsa-project.org, broonie@kernel.org, lgirdwood@gmail.com
Subject: Re: [PATCH 2/9] ALSA: compress: use mutex in drain
Date: Tue, 27 Aug 2013 19:40:51 +0530 [thread overview]
Message-ID: <20130827141051.GF2748@intel.com> (raw)
In-Reply-To: <s5hy57ni63s.wl%tiwai@suse.de>
On Tue, Aug 27, 2013 at 04:03:03PM +0200, Takashi Iwai wrote:
> > > An ops callback must be defined either to be locked or unlocked.
> > > Calling in the unlocked context only for some case doesn't sound
> > > right.
> > well all the callbacks except drain is called with lock held from framework...
>
> You're calling the same ops with and without the lock.
> I'd understand better if you created a new ops for drain, but in the
> current patch, it's still the same ops...
yup but cant different callbacks in the ops have different conditions. Anyway
all except drain ones are supposed to NOT block.
>
> > > > > > The point of lock is to sync
> > > > > > the stream states here.
> > > > >
> > > > > Without the lock, it's racy. What if another thread calls the same
> > > > > function at the same time?
> > > > that part can be checked by seeing if we are already draining.
> > >
> > > But how? The place you're calling trigger is unlocked.
> > > Suppose another thread calling trigger_stop just between
> > > mutex_unlock() and stream->ops->trigger(DRAIN) call in the above.
> > > The state check doesn't work there.
> > the framework does this with lock held and then calls the driver
> > something like this will ensure this while making sync right...
>
> It's still racy. In your code below:
>
> > mutex_lock(&lock);
> > if (state == DRAINING) {
> > mutex_unlock(&lock);
> > return -EPERM;
> > } else
> > state = DRAINING;
> > mutex_unlock(&lock);
>
> Suppose that another thread calls stop at this point before
> ops->drain() is called. It'll change the state to STOP, call
> ops->trigger(STOP). And ops->drain() (or ops->trigger(DRAIN)) may be
> called at the same time because there is no protection without knowing
> that it's being stopped.
yup...
>
> > ops->drain(substream);
> >
> > mutex_lock(&lock);
> > state = DRAINED;
> > mutex_unlock(&lock);
>
> Takashi
>
>
> > > > > > We are not modfying anything. During drain and partial
> > > > > > drain we need to allow other trigger ops like pause, stop tog o thru so drop the
> > > > > > lock here for these two ops only!
> > > > >
> > > > > Well, the biggest problem is that there is no proper design for which
> > > > > ops take a lock and which not. The trigger callback is basically to
> > > > > trigger the action. There should be no long-time blocking there.
> > > > > (Otherwise you'll definitely loose a gunfight :)
> > > > The reason for blocked implementation is to treat return of the call as
> > > > notifcation that draining is completed.
> > > >
> > > > For example user has written all the buffers, lets says worth 3 secs and now has
> > > > triggered drain. User needs to wait till drain is complete before closing the
> > > > device etc. So he waits on drain to compelete..
> > > >
> > > > Do you have a better way to manage this?
> > >
> > > Split the drain action in two parts, trigger and synchronization:
> > >
> > > lock();
> > > ...
> > > trigger(pause);
> > > while (!pause_finished) {
> > > unlock();
> > > schedule_or_sleep_or_whatever();
> > > lock();
> > > }
> > > ...
> > > unlock();
with this am thinking of handling it differently now on the above lines and
split the drain action and drain blocking parts. Trigger and action.
How about making the drain and partial drain triggers calls NOT blocking.
This will take care of sync issues etc.
But we also need to have notification for when drain completes.
IMO this can be handled in two ways
a) like in above we sleep and wake up on notification from driver.
Driver can call the drain_complete() which wakes up and we return to user
b) we call the driver for drain and then call blocking new callback which
returns when action is complete
~Vinod
--
next prev parent reply other threads:[~2013-08-27 14:56 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-27 6:40 [PATCH 0/9] ALSA: compress offfload fixes Vinod Koul
2013-08-27 6:40 ` [PATCH 1/9] ALSA: Compress - dont use lock for all ioctls Vinod Koul
2013-08-27 10:22 ` Takashi Iwai
2013-08-27 9:44 ` Vinod Koul
2013-08-27 11:00 ` Takashi Iwai
2013-08-27 6:40 ` [PATCH 2/9] ALSA: compress: use mutex in drain Vinod Koul
2013-08-27 10:25 ` Takashi Iwai
2013-08-27 9:47 ` Vinod Koul
2013-08-27 10:53 ` Takashi Iwai
2013-08-27 10:16 ` Vinod Koul
2013-08-27 12:23 ` Takashi Iwai
2013-08-27 13:09 ` Vinod Koul
2013-08-27 14:03 ` Takashi Iwai
2013-08-27 14:10 ` Vinod Koul [this message]
2013-08-27 6:40 ` [PATCH 3/9] ASoC: compress: dont aquire lock for draining states Vinod Koul
2013-08-27 6:40 ` [PATCH 4/9] ALSA: compress: use snprint instread of sprintf Vinod Koul
2013-08-27 6:40 ` [PATCH 5/9] ALSA: compres: wakeup the poll thread on pause Vinod Koul
2013-08-27 6:40 ` [PATCH 6/9] ALSA: compress: dont write when stream is paused Vinod Koul
2013-08-27 6:40 ` [PATCH 7/9] ALSA: compress: allow write when stream is setup Vinod Koul
2013-08-27 6:40 ` [PATCH 8/9] ALSA: compress: call pointer callback and updates under a lock Vinod Koul
2013-08-27 10:31 ` Takashi Iwai
2013-08-27 9:48 ` Vinod Koul
2013-08-27 11:03 ` Takashi Iwai
2013-08-27 6:40 ` [PATCH 9/9] ALSA: compress: use rate values for passing sampling rates Vinod Koul
2013-08-27 10:30 ` Takashi Iwai
2013-08-27 13:29 ` Mark Brown
2013-08-27 13:26 ` Vinod Koul
2013-08-27 14:27 ` Mark Brown
2013-08-27 10:46 ` [PATCH 0/9] ALSA: compress offfload fixes Takashi Iwai
2013-08-27 10:09 ` Vinod Koul
2013-08-27 12:32 ` Takashi Iwai
2013-08-27 13:14 ` Vinod Koul
2013-08-27 14:05 ` Takashi Iwai
2013-08-27 13:30 ` Vinod Koul
2013-08-27 14:22 ` Takashi Iwai
2013-08-27 13:41 ` Vinod Koul
2013-08-27 14:41 ` Takashi Iwai
2013-08-27 14:11 ` Vinod Koul
2013-08-27 13:28 ` Mark Brown
2013-08-27 13:18 ` Vinod Koul
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=20130827141051.GF2748@intel.com \
--to=vinod.koul@intel.com \
--cc=alsa-devel@alsa-project.org \
--cc=broonie@kernel.org \
--cc=lgirdwood@gmail.com \
--cc=tiwai@suse.de \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).