alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: Eldad Zack <eldad@fogrefinery.com>
Cc: Nikolay Martynov <mar.kolya@gmail.com>,
	Clemens Ladisch <clemens@ladisch.de>,
	alsa-devel@alsa-project.org, Daniel Mack <zonque@gmail.com>
Subject: Re: [PATCH v4 14/15] ALSA: usb-audio: always wait in start_endpoints
Date: Mon, 07 Oct 2013 11:26:00 +0200	[thread overview]
Message-ID: <s5hfvsdsa8n.wl%tiwai@suse.de> (raw)
In-Reply-To: <1381091480-23636-15-git-send-email-eldad@fogrefinery.com>

At Sun,  6 Oct 2013 22:31:19 +0200,
Eldad Zack wrote:
> 
> Start the endpoints at prepare also for capture endpoints,
> since it might be needed to wait for the URBs to be unlinked.
> 
> If an implicit feedback source endpoint stops being used by its
> sink endpoint, but immediately used as a data endpoint, usb_submit_urb
> will return -EBUSY.
> 
> Merge two trigger cases since they are now the same.

This change worries me about the timing.  This change means that the
capture stream isn't started at the moment the trigger callback is
called but at the next urb handling.  It means a possible regression
in the case of realtime usage.

Is there any reason to do this except for clean up?  IOW, does this
fix any problem by itself?


Takashi

> 
> Signed-off-by: Eldad Zack <eldad@fogrefinery.com>
> ---
>  sound/usb/endpoint.c |  8 +++-----
>  sound/usb/endpoint.h |  2 +-
>  sound/usb/pcm.c      | 28 ++++++++++++----------------
>  3 files changed, 16 insertions(+), 22 deletions(-)
> 
> diff --git a/sound/usb/endpoint.c b/sound/usb/endpoint.c
> index 8379989..81056b6 100644
> --- a/sound/usb/endpoint.c
> +++ b/sound/usb/endpoint.c
> @@ -884,18 +884,17 @@ int snd_usb_endpoint_set_params(struct snd_usb_endpoint *ep,
>   * snd_usb_endpoint_start: start an snd_usb_endpoint
>   *
>   * @ep:		the endpoint to start
> - * @can_sleep:	flag indicating whether the operation is executed in
> - * 		non-atomic context
>   *
>   * A call to this function will increment the use count of the endpoint.
>   * In case it is not already running, the URBs for this endpoint will be
>   * submitted. Otherwise, this function does nothing.
>   *
>   * Must be balanced to calls of snd_usb_endpoint_stop().
> + * This operation can sleep and must not be executed in atomic context.
>   *
>   * Returns an error if the URB submission failed, 0 in all other cases.
>   */
> -int snd_usb_endpoint_start(struct snd_usb_endpoint *ep, bool can_sleep)
> +int snd_usb_endpoint_start(struct snd_usb_endpoint *ep)
>  {
>  	int err;
>  	unsigned int i;
> @@ -909,8 +908,7 @@ int snd_usb_endpoint_start(struct snd_usb_endpoint *ep, bool can_sleep)
>  
>  	/* just to be sure */
>  	deactivate_urbs(ep, false);
> -	if (can_sleep)
> -		wait_clear_urbs(ep);
> +	wait_clear_urbs(ep);
>  
>  	ep->active_mask = 0;
>  	ep->unlink_mask = 0;
> diff --git a/sound/usb/endpoint.h b/sound/usb/endpoint.h
> index 188675d..22baec8 100644
> --- a/sound/usb/endpoint.h
> +++ b/sound/usb/endpoint.h
> @@ -19,7 +19,7 @@ int snd_usb_endpoint_set_params(struct snd_usb_endpoint *ep,
>  				struct snd_usb_endpoint *sync_ep,
>  				struct snd_usb_substream *subs);
>  
> -int  snd_usb_endpoint_start(struct snd_usb_endpoint *ep, bool can_sleep);
> +int  snd_usb_endpoint_start(struct snd_usb_endpoint *ep);
>  void snd_usb_endpoint_stop(struct snd_usb_endpoint *ep);
>  void snd_usb_endpoint_sync_pending_stop(struct snd_usb_endpoint *ep);
>  int  snd_usb_endpoint_activate(struct snd_usb_endpoint *ep);
> diff --git a/sound/usb/pcm.c b/sound/usb/pcm.c
> index 7ca9b47..f3d48d4 100644
> --- a/sound/usb/pcm.c
> +++ b/sound/usb/pcm.c
> @@ -270,7 +270,7 @@ static int subs_set_interface(struct snd_usb_substream *subs, int ifnum,
>  	return 0;
>  }
>  
> -static int start_endpoints(struct snd_usb_substream *subs, bool can_sleep)
> +static int start_endpoints(struct snd_usb_substream *subs)
>  {
>  	int err;
>  
> @@ -283,7 +283,7 @@ static int start_endpoints(struct snd_usb_substream *subs, bool can_sleep)
>  		snd_printdd(KERN_DEBUG "Starting data EP @%p\n", ep);
>  
>  		ep->data_subs = subs;
> -		err = snd_usb_endpoint_start(ep, can_sleep);
> +		err = snd_usb_endpoint_start(ep);
>  		if (err < 0) {
>  			clear_bit(SUBSTREAM_FLAG_DATA_EP_STARTED, &subs->flags);
>  			return err;
> @@ -313,7 +313,7 @@ static int start_endpoints(struct snd_usb_substream *subs, bool can_sleep)
>  		snd_printdd(KERN_DEBUG "Starting sync EP @%p\n", ep);
>  
>  		ep->sync_slave = subs->data_endpoint;
> -		err = snd_usb_endpoint_start(ep, can_sleep);
> +		err = snd_usb_endpoint_start(ep);
>  		if (err < 0) {
>  			clear_bit(SUBSTREAM_FLAG_SYNC_EP_STARTED, &subs->flags);
>  			return err;
> @@ -893,10 +893,14 @@ static int snd_usb_pcm_prepare(struct snd_pcm_substream *substream)
>  	subs->last_frame_number = 0;
>  	runtime->delay = 0;
>  
> -	/* for playback, submit the URBs now; otherwise, the first hwptr_done
> -	 * updates for all URBs would happen at the same time when starting */
> -	if (subs->direction == SNDRV_PCM_STREAM_PLAYBACK)
> -		ret = start_endpoints(subs, true);
> +	/*
> +	 * for playback, submit the URBs now; otherwise, the first hwptr_done
> +	 * updates for all URBs would happen at the same time when starting.
> +	 * for capture, waiting is required in case the endpoint is an implicit
> +	 * feedback source and it is has just been stopped (by the playback
> +	 * substream).
> +	 */
> +	ret = start_endpoints(subs);
>  
>   unlock:
>  	up_read(&subs->stream->chip->shutdown_rwsem);
> @@ -1660,15 +1664,11 @@ static int snd_usb_substream_playback_trigger(struct snd_pcm_substream *substrea
>  static int snd_usb_substream_capture_trigger(struct snd_pcm_substream *substream,
>  					     int cmd)
>  {
> -	int err;
>  	struct snd_usb_substream *subs = substream->runtime->private_data;
>  
>  	switch (cmd) {
>  	case SNDRV_PCM_TRIGGER_START:
> -		err = start_endpoints(subs, false);
> -		if (err < 0)
> -			return err;
> -
> +	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
>  		subs->data_endpoint->retire_data_urb = retire_capture_urb;
>  		subs->running = 1;
>  		return 0;
> @@ -1681,10 +1681,6 @@ static int snd_usb_substream_capture_trigger(struct snd_pcm_substream *substream
>  		subs->data_endpoint->retire_data_urb = NULL;
>  		subs->running = 0;
>  		return 0;
> -	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
> -		subs->data_endpoint->retire_data_urb = retire_capture_urb;
> -		subs->running = 1;
> -		return 0;
>  	}
>  
>  	return -EINVAL;
> -- 
> 1.8.1.5
> 

  reply	other threads:[~2013-10-07  9:23 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-06 20:31 [PATCH v4 00/15] ALSA: usb-audio: fix playback/capture concurrent usage Eldad Zack
2013-10-06 20:31 ` [PATCH v4 01/15] ALSA: usb-audio: remove unused parameter from sync_ep_set_params Eldad Zack
2013-10-06 20:31 ` [PATCH v4 02/15] ALSA: usb-audio: remove deactivate_endpoints() Eldad Zack
2013-10-06 20:31 ` [PATCH v4 03/15] ALSA: usb-audio: prevent NULL dereference on stop trigger Eldad Zack
2013-10-07  8:57   ` Takashi Iwai
2013-10-06 20:31 ` [PATCH v4 04/15] ALSA: usb-audio: don't deactivate URBs on in-use EP Eldad Zack
2013-10-06 20:31 ` [PATCH v4 05/15] ALSA: usb-audio: void return type of snd_usb_endpoint_deactivate() Eldad Zack
2013-10-06 20:31 ` [PATCH v4 06/15] ALSA: usb-audio: clear SUBSTREAM_FLAG_SYNC_EP_STARTED on error Eldad Zack
2013-10-06 20:31 ` [PATCH v4 07/15] ALSA: usb-audio: correct ep use_count semantics (add set_param flag) Eldad Zack
2013-10-07  9:21   ` Takashi Iwai
2013-10-07 19:31     ` Eldad Zack
2013-10-08  7:01       ` Takashi Iwai
2013-10-06 20:31 ` [PATCH v4 08/15] ALSA: usb-audio: rename alt_idx to altsetting Eldad Zack
2013-10-06 20:31 ` [PATCH v4 09/15] ALSA: usb-audio: conditional interface altsetting Eldad Zack
2013-10-07 10:34   ` Takashi Iwai
2013-10-07 18:00     ` Eldad Zack
2013-10-07 18:23       ` Clemens Ladisch
2013-10-07 19:31         ` Takashi Iwai
2013-10-06 20:31 ` [PATCH v4 10/15] ALSA: usb-audio: conditional concurrent usage of endpoint Eldad Zack
2013-10-06 20:31 ` [PATCH v4 11/15] ALSA: usb-audio: remove altset_idx from snd_usb_substream Eldad Zack
2013-10-06 20:31 ` [PATCH v4 12/15] ALSA: usb-audio: remove unused endpoint flag EP_FLAG_ACTIVATED Eldad Zack
2013-10-06 20:31 ` [PATCH v4 13/15] ALSA: usb-audio: clear sync subs hw_params Eldad Zack
2013-10-06 20:31 ` [PATCH v4 14/15] ALSA: usb-audio: always wait in start_endpoints Eldad Zack
2013-10-07  9:26   ` Takashi Iwai [this message]
2013-10-07 19:26     ` Eldad Zack
2013-10-08  7:05       ` Takashi Iwai
2013-10-08 19:25         ` Eldad Zack
2013-10-06 20:31 ` [PATCH v4 15/15] ALSA: usb-audio: improve logging messages Eldad Zack
2013-10-07  9:23   ` Takashi Iwai
2013-10-07  9:30 ` [PATCH v4 00/15] ALSA: usb-audio: fix playback/capture concurrent usage Takashi Iwai
2013-10-07 17:20   ` Eldad Zack
2013-10-28 17:45 ` Nikolay Martynov

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=s5hfvsdsa8n.wl%tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=clemens@ladisch.de \
    --cc=eldad@fogrefinery.com \
    --cc=mar.kolya@gmail.com \
    --cc=zonque@gmail.com \
    /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).