Alsa-Devel Archive on lore.kernel.org
 help / color / Atom feed
From: Mark Hills <mark@xwax.org>
To: alsa-devel@alsa-project.org
Subject: alsa-lib: snd_pcm_plugin_status() recently broken
Date: Tue, 12 Jan 2021 11:35:26 +0000 (GMT)
Message-ID: <2101121120040.30404@stax.localdomain> (raw)

The following assertion:

  relay: pcm_plugin.c:570: snd_pcm_plugin_status: Assertion `status->appl_ptr == *pcm->appl.ptr' failed.

It bisects to 28cc099, the introduction of that assertion.

  #4  0x00007ffff7d0dd03 in snd_pcm_plugin_status (pcm=0x633560, 
      status=0x7fffffffe1e0) at pcm_plugin.c:570
  570                     assert(status->appl_ptr == *pcm->appl.ptr);
  (gdb) print status->appl_ptr
  $1 = 0
  (gdb) print pcm->appl.ptr
  $2 = (volatile snd_pcm_uframes_t *) 0x6334f8
  (gdb) print *pcm->appl.ptr
  $3 = 47936

The calling code is single threaded on a dmix device, with these 
operations in order:

  snd_pcm_avail_update();
  snd_pcm_status();
  snd_pcm_mmap_begin();

Commenting out the assertion leaves me with a credible result from the 
function as it did previously; snd_pcm_status_get_delay() == 64.

-- 
Mark


From 28cc099d9ea3962b033cb1cb9c3e07db828d9ff7 Mon Sep 17 00:00:00 2001
From: Jaroslav Kysela <perex@perex.cz>
Date: Sun, 3 Jan 2021 16:41:29 +0100
Subject: [PATCH] pcm: plugin - optimize sync in snd_pcm_plugin_status()

Do hw_ptr sync only once after the status call. This avoids
double update.

Also, the application pointer must not change when
the status is called. Add assert() call for this condition.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
---
 src/pcm/pcm_plugin.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/src/pcm/pcm_plugin.c b/src/pcm/pcm_plugin.c
index 83793397..6a815145 100644
--- a/src/pcm/pcm_plugin.c
+++ b/src/pcm/pcm_plugin.c
@@ -553,14 +553,11 @@ static int snd_pcm_plugin_status(snd_pcm_t *pcm, snd_pcm_status_t * status)
 	snd_pcm_plugin_t *plugin = pcm->private_data;
 	snd_pcm_sframes_t err;
 
-	/* sync with the latest hw and appl ptrs */
-	snd_pcm_plugin_avail_update(pcm);
-
 	err = snd_pcm_status(plugin->gen.slave, status);
 	if (err < 0)
 		return err;
-	status->appl_ptr = *pcm->appl.ptr;
-	status->hw_ptr = *pcm->hw.ptr;
+	assert(status->appl_ptr == *pcm->appl.ptr);
+	snd_pcm_plugin_sync_hw_ptr(pcm, status->hw_ptr, status->avail);
 	return 0;
 }
 
-- 
2.17.5


                 reply index

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=2101121120040.30404@stax.localdomain \
    --to=mark@xwax.org \
    --cc=alsa-devel@alsa-project.org \
    /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

Alsa-Devel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/alsa-devel/0 alsa-devel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 alsa-devel alsa-devel/ https://lore.kernel.org/alsa-devel \
		alsa-devel@alsa-project.org
	public-inbox-index alsa-devel

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.alsa-project.alsa-devel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git