Skip to contentSkip to conversation

ASoC: Apply msbits constraint for sample size bigger than the msbits

PATCH Superseded Peter Ujfalusi 3 participants 11 messages Jan 18, 2012 – Jan 19, 2012

Subsystems (2)

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v5 1/1 ASoC: Apply msbits constraint for sample size bigger than the msbits

In order to avoid confusing the applications with msbits bigger than the selected sample size apply the msbits constraint only to sample seze bigger than the requested msbits.

---

Hi Mark,

Converted to use while loop.
We run the loop as long as the sample size is bigger than the requested msbits.
Most of the drivers require 24/32 configuration, so not point of looping for smaller sample sizes.

Regards,
Peter

 sound/soc/soc-pcm.c |   17 +++++++++--------
 1 files changed, 9 insertions(+), 8 deletions(-)
sound/soc/soc-pcm.c +9 -8
index 8bb1793..ef41a39 100644
@@ -68,13 +68,14 @@ static int soc_pcm_apply_symmetry(struct snd_pcm_substream *substream,
  * like the DAC/ADC resolution to use but there isn't right now.
  */
 static int sample_sizes[] = {
-	8, 16, 24, 32,
+	32, 24, 16, 8,
 };
 
 static void soc_pcm_apply_msb(struct snd_pcm_substream *substream,
 			      struct snd_soc_dai *dai)
 {
-	int ret, i, bits;
+	int ret, bits;
+	int i = 0;
 
 	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
 		bits = dai->driver->playback.sig_bits;
@@ -84,14 +85,14 @@ static void soc_pcm_apply_msb(struct snd_pcm_substream *substream,
 	if (!bits)
 		return;
 
-	for (i = 0; i < ARRAY_SIZE(sample_sizes); i++) {
-		ret = snd_pcm_hw_constraint_msbits(substream->runtime,
-						   0, sample_sizes[i],
-						   bits);
+	/* Apply constraint only for sample size bigger than requested msbits */
+	while (sample_sizes[i] > bits && i < ARRAY_SIZE(sample_sizes)) {
+		ret = snd_pcm_hw_constraint_msbits(substream->runtime, 0,
+						   sample_sizes[i], bits);
 		if (ret != 0)
-			dev_warn(dai->dev,
-				 "Failed to set MSB %d/%d: %d\n",
+			dev_warn(dai->dev, "Failed to set MSB %d/%d: %d\n",
 				 bits, sample_sizes[i], ret);
+		i++;
 	}
 }
 
Signature · 1 line
1.7.8.3
#1 lore raw
Quoted 3 lines · Peter Ujfalusi

Converted to use while loop.
We run the loop as long as the sample size is bigger than the requested msbits.

I'm not sure this is actually a legibility improvement, if anything it's probably less clear than the original as now the setup of the loop is spread even further around the function.

Quoted 2 lines

Most of the drivers require 24/32 configuration, so not point of looping for smaller sample sizes.

Performance isn't really a concern in this path unless we do something totally insane. Thinking time on the part of the reader needs to be considered too...

#2 lore raw
Quoted 3 lines · Mark Brown

I'm not sure this is actually a legibility improvement, if anything it's probably less clear than the original as now the setup of the loop is spread even further around the function.

Would it make it clearer if I set i to 0 right before the while?

Quoted 6 lines
Quoted 2 lines

Most of the drivers require 24/32 configuration, so not point of looping for smaller sample sizes.

Performance isn't really a concern in this path unless we do something totally insane. Thinking time on the part of the reader needs to be considered too...

Sure it is not a concern. These small 'Performance isn't really a concern in this path' at the end ads up that we need faster CPUs to have the same perceived perfomrance.

Signature · 1 line
Péter
#3 lore raw
Quoted 6 lines · Peter Ujfalusi
Quoted 3 lines · Mark Brown

I'm not sure this is actually a legibility improvement, if anything it's probably less clear than the original as now the setup of the loop is spread even further around the function.

Would it make it clearer if I set i to 0 right before the while?

That'd help a bit. Though I'd just go with a for loop, the while clearly doesn't look any better - I was just suggesting it without actually having tried writing it out.

Quoted 7 lines
Quoted 3 lines

Performance isn't really a concern in this path unless we do something totally insane. Thinking time on the part of the reader needs to be considered too...

Sure it is not a concern. These small 'Performance isn't really a concern in this path' at the end ads up that we need faster CPUs to have the same perceived perfomrance.

Yeah, but if that percieved performance is already instantaneous there's no need to worry :) My first thought would've been to just continue on sample rates we don't like rather than trying to break out of an iteration of 4 steps early.

#4 lore raw
Quoted 3 lines · Mark Brown

That'd help a bit. Though I'd just go with a for loop, the while clearly doesn't look any better - I was just suggesting it without actually having tried writing it out.

Are you going to take the for version of patch, or should I resend it? I can add a comment to explain that we bail out, and not checking the sample sizes lower than the requested msbits, if it helps.

Signature · 1 line
Péter
#5 lore raw
Quoted 3 lines · Peter Ujfalusi

Are you going to take the for version of patch, or should I resend it? I can add a comment to explain that we bail out, and not checking the sample sizes lower than the requested msbits, if it helps.

I'd just replace it with a continue on sizes we don't want, much simpler.

#6 lore raw
Quoted 8 lines · Mark Brown
Quoted 3 lines · Peter Ujfalusi

Are you going to take the for version of patch, or should I resend it? I can add a comment to explain that we bail out, and not checking the sample sizes lower than the requested msbits, if it helps.

I'd just replace it with a continue on sizes we don't want, much simpler.

If I can do this (bits == 24):
i = 0
check (i < ARRAY_SIZE(sample_sizes)) check (sample_sizes[i] <= bits)
apply constraint
i++
check (i < ARRAY_SIZE(sample_sizes)) check (sample_sizes[i] <= bits)
go out

--------------------------------------
I will not do this (bits == 24):

static int sample_sizes[] = {
	8, 16, 24, 32,
};

i = 0
check (i < ARRAY_SIZE(sample_sizes)) check (sample_sizes[i] > bits) i++
check (i < ARRAY_SIZE(sample_sizes)) check (sample_sizes[i] > bits) i++
check (i < ARRAY_SIZE(sample_sizes)) check (sample_sizes[i] > bits) i++
check (i < ARRAY_SIZE(sample_sizes)) check (sample_sizes[i] > bits)
apply constraint
i++
check (i < ARRAY_SIZE(sample_sizes))
go out

--------------------------------------
nor this (bits == 24):

static int sample_sizes[] = {
	32, 24, 16, 8,
};

i = 0
check (i < ARRAY_SIZE(sample_sizes)) check (sample_sizes[i] <= bits)
apply constraint
i++
check (i < ARRAY_SIZE(sample_sizes)) check (sample_sizes[i] <= bits) i++
check (i < ARRAY_SIZE(sample_sizes)) check (sample_sizes[i] <= bits) i++
check (i < ARRAY_SIZE(sample_sizes)) check (sample_sizes[i] <= bits) i++
check (i < ARRAY_SIZE(sample_sizes))
go out

Signature · 1 line
Péter
#7 lore raw
Quoted 6 lines · Peter Ujfalusi
Quoted 2 lines · Mark Brown

I'd just replace it with a continue on sizes we don't want, much simpler.

If I can do this (bits == 24):

This mail took me a little while to parse but I think you're trying to say you insist on the microoptimisation. Unless you can come up with a microoptimisation which doesn't take effort to read please write something simple. The reason I wasn't happy with the original patch was that what should be a trivial bit of code took far too long to check. Maintainability is vastly more important than microoptimising a slow path, having to read things again later was the whole reason I didn't do any filtering in the first place.

#8 lore raw
In reply to Peter Ujfalusi

sound/soc/soc-pcm.c static void soc_pcm_apply_msb(struct snd_pcm_substream *substream, · line 89

Quoted 4 lines · Peter Ujfalusi

We run the loop as long as the sample size is bigger than the requested msbits.

sound/soc/soc-pcm.c +1 -0
+	while (sample_sizes[i] > bits && i < ARRAY_SIZE(sample_sizes)) {

This will overrun sample_sizes[] if bits < 8.

Regards,
Clemens

#9 lore raw
Quoted 7 lines · Clemens Ladisch

sound/soc/soc-pcm.c static void soc_pcm_apply_msb(struct snd_pcm_substream *substream, · line 89

Quoted 4 lines · Peter Ujfalusi

We run the loop as long as the sample size is bigger than the requested msbits.

sound/soc/soc-pcm.c +1 -0
+	while (sample_sizes[i] > bits && i < ARRAY_SIZE(sample_sizes)) {

This will overrun sample_sizes[] if bits < 8.

which is prevented by the: && i < ARRAY_SIZE(sample_sizes)

Signature · 1 line
Péter
#10 lore raw
Quoted 10 lines · Peter Ujfalusi
Quoted 7 lines · Clemens Ladisch

sound/soc/soc-pcm.c static void soc_pcm_apply_msb(struct snd_pcm_substream *substream, · line 89

Quoted 4 lines · Peter Ujfalusi

We run the loop as long as the sample size is bigger than the requested msbits.

sound/soc/soc-pcm.c +1 -0
+	while (sample_sizes[i] > bits && i < ARRAY_SIZE(sample_sizes)) {

This will overrun sample_sizes[] if bits < 8.

which is prevented by the: && i < ARRAY_SIZE(sample_sizes)

I take it back. True, we overrun. These need to be swapped.

Signature · 1 line
Péter