All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
From: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
To: alsa-devel@alsa-project.org
Cc: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Subject: [RFC PATCH 3/4] ALSA: core: add report of max dma burst
Date: Wed,  8 Jul 2015 05:10:35 -0500	[thread overview]
Message-ID: <1436350236-17509-4-git-send-email-pierre-louis.bossart@linux.intel.com> (raw)
In-Reply-To: <1436350236-17509-1-git-send-email-pierre-louis.bossart@linux.intel.com>

Report how many bytes the DMA can burst before updating the hw_ptr.
This can help fix two issues with stale data discussed many times over
on the alsa-devel mailing list (refilling/reading ring buffer too late or
rewinding too close to the hw_ptr)

FIXME:
1. this was copy/pasted/edited based on the fifo_size fields, not
sure why we would need this IOCTL1
2. we also need the ability to set the actual fifo size, if suppported,
by the hardware, to negociate the prefetch amount between application
and driver. By default the default should be max buffering to allow
for lower power, but for low-latency use cases we may want to reduce
the amount of prefetching.

Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
---
 include/sound/pcm.h         |  2 ++
 include/uapi/sound/asound.h |  5 +++--
 sound/core/pcm_lib.c        | 19 +++++++++++++++++++
 sound/core/pcm_native.c     |  7 +++++++
 4 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/include/sound/pcm.h b/include/sound/pcm.h
index d5eff03..57c0571 100644
--- a/include/sound/pcm.h
+++ b/include/sound/pcm.h
@@ -56,6 +56,7 @@ struct snd_pcm_hardware {
 	unsigned int periods_min;	/* min # of periods */
 	unsigned int periods_max;	/* max # of periods */
 	size_t fifo_size;		/* fifo size in bytes */
+	unsigned int max_dma_burst;     /* max DMA in-flight bytes, linked to hw_ptr precision/fuzziness */
 };
 
 struct snd_pcm_substream;
@@ -106,6 +107,7 @@ struct snd_pcm_ops {
 #define SNDRV_PCM_IOCTL1_CHANNEL_INFO	2
 #define SNDRV_PCM_IOCTL1_GSTATE		3
 #define SNDRV_PCM_IOCTL1_FIFO_SIZE	4
+#define SNDRV_PCM_IOCTL1_MAX_DMA_BURST	5
 
 #define SNDRV_PCM_TRIGGER_STOP		0
 #define SNDRV_PCM_TRIGGER_START		1
diff --git a/include/uapi/sound/asound.h b/include/uapi/sound/asound.h
index b62b162..3dc049a 100644
--- a/include/uapi/sound/asound.h
+++ b/include/uapi/sound/asound.h
@@ -386,8 +386,9 @@ struct snd_pcm_hw_params {
 	unsigned int msbits;		/* R: used most significant bits */
 	unsigned int rate_num;		/* R: rate numerator */
 	unsigned int rate_den;		/* R: rate denominator */
-	snd_pcm_uframes_t fifo_size;	/* R: chip FIFO size in frames */
-	unsigned char reserved[64];	/* reserved for future */
+	snd_pcm_uframes_t fifo_size;	/* R: chip FIFO size in frames, indicates buffering after hw_ptr */
+	unsigned int max_dma_burst;     /* R: max in-flight bytes, indicates buffering before hw_ptr */
+	unsigned char reserved[60];	/* reserved for future */
 };
 
 enum {
diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c
index 7d45645..dc89aa0 100644
--- a/sound/core/pcm_lib.c
+++ b/sound/core/pcm_lib.c
@@ -1826,6 +1826,22 @@ static int snd_pcm_lib_ioctl_fifo_size(struct snd_pcm_substream *substream,
 	return 0;
 }
 
+static int snd_pcm_lib_ioctl_max_dma_burst(struct snd_pcm_substream *substream,
+					      void *arg)
+{
+	struct snd_pcm_hw_params *params = arg;
+
+	/* FIXME: add sanity checks:
+	 * max burst < ring buffer
+	 * max burst >= min_period_size
+	 * not sure if we can check against period sizes?
+	 * any others ?
+	 */
+	params->max_dma_burst = substream->runtime->hw.max_dma_burst;
+
+	return 0;
+}
+
 /**
  * snd_pcm_lib_ioctl - a generic PCM ioctl callback
  * @substream: the pcm substream instance
@@ -1849,6 +1865,9 @@ int snd_pcm_lib_ioctl(struct snd_pcm_substream *substream,
 		return snd_pcm_lib_ioctl_channel_info(substream, arg);
 	case SNDRV_PCM_IOCTL1_FIFO_SIZE:
 		return snd_pcm_lib_ioctl_fifo_size(substream, arg);
+	case SNDRV_PCM_IOCTL1_MAX_DMA_BURST:
+		return snd_pcm_lib_ioctl_max_dma_burst(substream, arg);
+
 	}
 	return -ENXIO;
 }
diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
index dd519b8..3d379b8 100644
--- a/sound/core/pcm_native.c
+++ b/sound/core/pcm_native.c
@@ -280,6 +280,7 @@ int snd_pcm_hw_refine(struct snd_pcm_substream *substream,
 
 	params->info = 0;
 	params->fifo_size = 0;
+	params->max_dma_burst = 0;
 	if (params->rmask & (1 << SNDRV_PCM_HW_PARAM_SAMPLE_BITS))
 		params->msbits = 0;
 	if (params->rmask & (1 << SNDRV_PCM_HW_PARAM_RATE)) {
@@ -437,6 +438,12 @@ int snd_pcm_hw_refine(struct snd_pcm_substream *substream,
 				return changed;
 		}
 	}
+	if (!params->max_dma_burst) {
+		changed = substream->ops->ioctl(substream,
+						SNDRV_PCM_IOCTL1_MAX_DMA_BURST, params);
+		if (changed < 0)
+			return changed;
+	}
 	params->rmask = 0;
 	return 0;
 }
-- 
1.9.1

  parent reply	other threads:[~2015-07-08 10:10 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-08 10:10 [RFC PATCH 0/4] better support for bursty DMA usages Pierre-Louis Bossart
2015-07-08 10:10 ` [RFC PATCH 1/4] ALSA: core: let low-level driver or userspace disable rewinds Pierre-Louis Bossart
2015-07-08 14:21   ` Takashi Iwai
2015-07-08 16:58     ` Pierre-Louis Bossart
2015-07-11 17:06   ` Alexander E. Patrakov
2015-07-14  3:32     ` Raymond Yau
2015-07-14 17:39       ` Alexander E. Patrakov
2015-07-15  1:23         ` Raymond Yau
2015-07-15  4:51           ` Alexander E. Patrakov
2015-07-28 14:19     ` Pierre-Louis Bossart
2015-07-28 15:43       ` Alexander E. Patrakov
2015-07-29 17:46         ` Pierre-Louis Bossart
2015-07-30  6:11           ` Alexander E. Patrakov
2015-07-30 13:46             ` Pierre-Louis Bossart
2015-07-08 10:10 ` [RFC PATCH 2/4] ALSA: core: add .notify callback for pcm ops Pierre-Louis Bossart
2015-07-08 14:27   ` Takashi Iwai
2015-07-08 17:10     ` Pierre-Louis Bossart
2015-07-09 14:44       ` Takashi Iwai
2015-07-09  7:25     ` Raymond Yau
2015-07-09  7:35       ` Pierre-Louis Bossart
2015-07-08 10:10 ` Pierre-Louis Bossart [this message]
2015-07-08 14:37   ` [RFC PATCH 3/4] ALSA: core: add report of max dma burst Takashi Iwai
2015-07-08 17:46     ` Pierre-Louis Bossart
2015-07-10  2:35       ` Raymond Yau
2015-07-10 17:13         ` Lars-Peter Clausen
2015-07-11 17:46     ` Alexander E. Patrakov
2015-07-11 18:28       ` Jaroslav Kysela
2015-07-16  2:11         ` Raymond Yau
2015-07-08 10:10 ` [RFC PATCH 4/4] ALSA: hda: add default value for max_dma_burst Pierre-Louis Bossart
2015-07-08 14:31 ` [RFC PATCH 0/4] better support for bursty DMA usages Takashi Iwai
2015-07-08 17:50   ` Pierre-Louis Bossart
2015-07-15 10:14 ` Raymond Yau
2015-07-15 10:38   ` Alexander E. Patrakov
2015-07-22 14:44     ` Raymond Yau

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=1436350236-17509-4-git-send-email-pierre-louis.bossart@linux.intel.com \
    --to=pierre-louis.bossart@linux.intel.com \
    --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
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.