All of lore.kernel.org
 help / color / mirror / Atom feed
From: Clemens Ladisch <clemens@ladisch.de>
To: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Cc: Takashi Iwai <tiwai@suse.de>,
	alsa-devel@alsa-project.org, ffado-devel@lists.sf.net
Subject: Re: [RFC][PATCH] ALSA: firewire-lib: permit process context only to	flush queued packets for better PCM period granularity
Date: Wed, 11 May 2016 09:31:41 +0200	[thread overview]
Message-ID: <5732DFDD.6000208@ladisch.de> (raw)
In-Reply-To: <1462625196-3640-1-git-send-email-o-takashi@sakamocchi.jp>

Sorry for the delay.

Takashi Sakamoto wrote:
> These three commits were merged to improve PCM pointer granularity.
> commit 76fb87894828 ("ALSA: firewire-lib: taskletize the snd_pcm_period_elapsed() call")
> commit e9148dddc3c7 ("ALSA: firewire-lib: flush completed packets when reading PCM position")
> commit 92b862c7d685 ("ALSA: firewire-lib: optimize packet flushing")
>
> The point of them is to handle queued packets not only in software IRQ
> context of IR/IT contexts, but also in process context. This idea
> introduced a cyclic call of 'struct snd_pcm_ops.pointer()'.

There is no recursion because of the tasklet.  The only problem is that
the tasklet could be scheduled repeatedly because new packets continue
to arrive.  But even when this happens, it's harmless.

> The last commit adds 'pointer_flush' member to 'struct amdtp_stream'
> to avoid the situation. On the other hand, This solution is weak at
> race condition between the process context and the software IRQ
> context of IR/IT contexts.
>
> Practically, this race is not so critical because it influences process
> context to skip flushing queued packets and to get worse granularity of
> PCM pointer.

When a race causes pointer_flush to be read as true although it should
be false, there is simply a superfluous call to flush_completions.

When pointer_flush is read as false although it should be true, then the
buffer_pointer value _might_ not be the most current one (due to the
missing flush), but this is unlikely to happen because the buffer_pointer
was just updated by update_pcm_pointers().  In any case, the just-
scheduled tasklet will inform the application about the new pointer.

> The similar solution can be achieved by 'in_interrupt()' macro. This
> commit applies the macro to solve the race condition against
> 'pointer_flush'.

>  unsigned long amdtp_stream_pcm_pointer(struct amdtp_stream *s)
>  {
> -	/* this optimization is allowed to be racy */
> -	if (s->pointer_flush && amdtp_stream_running(s))
> ...
> +	if (!in_interrupt() && amdtp_stream_running(s))
>  		fw_iso_context_flush_completions(s->context);
> -	else
> -		s->pointer_flush = true;
>
>  	return ACCESS_ONCE(s->pcm_buffer_pointer);
>  }

Looks good.

Acked-by: Clemens Ladisch <clemens@ladisch.de>


> And I think there's another race condition against processing each packets
> by calling out/in_stream_callback(), but I cannot observe the race.

As you already found out, fw_iso_context_flush_completions() is thread
safe.


Regards,
Clemens

  parent reply	other threads:[~2016-05-11  7:31 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-07 12:46 [RFC][PATCH] ALSA: firewire-lib: permit process context only to flush queued packets for better PCM period granularity Takashi Sakamoto
2016-05-10 14:07 ` Takashi Sakamoto
2016-05-10 15:03   ` Takashi Iwai
2016-05-10 22:56     ` Takashi Sakamoto
2016-05-11  5:35       ` Takashi Iwai
2016-05-11  6:05         ` Takashi Sakamoto
2016-05-11  7:31 ` Clemens Ladisch [this message]
2016-05-11 17:21   ` Takashi Sakamoto

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=5732DFDD.6000208@ladisch.de \
    --to=clemens@ladisch.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=ffado-devel@lists.sf.net \
    --cc=o-takashi@sakamocchi.jp \
    --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 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.