Skip to contentSkip to conversation

ASoC: max98090: fix PLL unlocked workaround-related

PATCH Superseded Tzung-Bi Shih 2 participants 14 messages Nov 20, 2019 – Nov 22, 2019

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover ASoC: max98090: fix PLL unlocked workaround-related

This series is a follow up fix for the question:
https://mailman.alsa-project.org/pipermail/alsa-devel/2019-October/157364.html

Tzung-Bi Shih (3):
ASoC: max98090: remove msleep in PLL unlocked workaround
ASoC: max98090: exit workaround earlier if PLL is locked
ASoC: max98090: fix possible race conditions

 sound/soc/codecs/max98090.c | 23 ++++++++++++++---------
 sound/soc/codecs/max98090.h |  1 -
 2 files changed, 14 insertions(+), 10 deletions(-)
Signature · 6 lines
2.24.0.432.g9d3f5f5b63-goog

_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
#1 lore raw

PATCH 1/3 ASoC: max98090: remove msleep in PLL unlocked workaround

It was observed Baytrail-based chromebooks could cause continuous PLL unlocked when using playback stream and capture stream simultaneously. Specifically, starting a capture stream after started a playback stream. As a result, the audio data could corrupt or turn completely silent.

As the datasheet suggested, the maximum PLL lock time should be 7 msec. The workaround resets the codec softly by toggling SHDN off and on if PLL failed to lock for 10 msec. Notably, there is no suggested hold time for SHDN off.

On Baytrail-based chromebooks, it would easily happen continuous PLL unlocked if there is a 10 msec delay between SHDN off and on. Removes the msleep().

---
 sound/soc/codecs/max98090.c | 1 -
 1 file changed, 1 deletion(-)
sound/soc/codecs/max98090.c +0 -1
index f6bf4cfbea23..8382a77586ee 100644
@@ -2117,7 +2117,6 @@ static void max98090_pll_work(struct work_struct *work)
 	/* Toggle shutdown OFF then ON */
 	snd_soc_component_update_bits(component, M98090_REG_DEVICE_SHUTDOWN,
 			    M98090_SHDNN_MASK, 0);
-	msleep(10);
 	snd_soc_component_update_bits(component, M98090_REG_DEVICE_SHUTDOWN,
 			    M98090_SHDNN_MASK, M98090_SHDNN_MASK);
 
Signature · 6 lines
2.24.0.432.g9d3f5f5b63-goog

_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
#2 lore raw

Re: [alsa-devel] [PATCH 1/3] ASoC: max98090: remove msleep in PLL unlocked workaround

Quoted 24 lines · Tzung-Bi Shih

It was observed Baytrail-based chromebooks could cause continuous PLL unlocked when using playback stream and capture stream simultaneously. Specifically, starting a capture stream after started a playback stream. As a result, the audio data could corrupt or turn completely silent.

As the datasheet suggested, the maximum PLL lock time should be 7 msec. The workaround resets the codec softly by toggling SHDN off and on if PLL failed to lock for 10 msec. Notably, there is no suggested hold time for SHDN off.

On Baytrail-based chromebooks, it would easily happen continuous PLL unlocked if there is a 10 msec delay between SHDN off and on. Removes the msleep().

---
  sound/soc/codecs/max98090.c | 1 -
  1 file changed, 1 deletion(-)
sound/soc/codecs/max98090.c +0 -0
index f6bf4cfbea23..8382a77586ee 100644

sound/soc/codecs/max98090.c static void max98090_pll_work(struct work_struct *work) · line 2120

Quoted 4 lines
sound/soc/codecs/max98090.c +0 -1
@@ -2117,7 +2117,6 @@ static void max98090_pll_work(struct work_struct *work)
  	/* Toggle shutdown OFF then ON */
  	snd_soc_component_update_bits(component, M98090_REG_DEVICE_SHUTDOWN,
  			    M98090_SHDNN_MASK, 0);
-	msleep(10);

maybe add a comment here that the off/on sequence is done on purpose (as stated in the commit message)?

sound/soc/codecs/max98090.c static void max98090_pll_work(struct work_struct *work) · line 2122

Quoted 4 lines
sound/soc/codecs/max98090.c +0 -0
  	snd_soc_component_update_bits(component, M98090_REG_DEVICE_SHUTDOWN,
  			    M98090_SHDNN_MASK, M98090_SHDNN_MASK);
 

_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#4 lore raw

PATCH 2/3 ASoC: max98090: exit workaround earlier if PLL is locked

In reply to Tzung-Bi Shih

According to the datasheet, PLL lock time typically takes 2 msec and at most takes 7 msec.

Check the lock status every 1 msec and exit the workaround if PLL is locked.

---
 sound/soc/codecs/max98090.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
sound/soc/codecs/max98090.c +12 -2
index 8382a77586ee..2ccdfb2383b7 100644
@@ -2108,6 +2108,8 @@ static void max98090_pll_work(struct work_struct *work)
 	struct max98090_priv *max98090 =
 		container_of(work, struct max98090_priv, pll_work);
 	struct snd_soc_component *component = max98090->component;
+	unsigned int pll;
+	int i;
 
 	if (!snd_soc_component_is_active(component))
 		return;
@@ -2120,8 +2122,16 @@ static void max98090_pll_work(struct work_struct *work)
 	snd_soc_component_update_bits(component, M98090_REG_DEVICE_SHUTDOWN,
 			    M98090_SHDNN_MASK, M98090_SHDNN_MASK);
 
-	/* Give PLL time to lock */
-	msleep(10);
+	for (i = 0; i < 10; ++i) {
+		/* Check lock status */
+		pll = snd_soc_component_read32(
+				component, M98090_REG_DEVICE_STATUS);
+		if (!(pll & M98090_ULK_MASK))
+			break;
+
+		/* Give PLL time to lock */
+		usleep_range(1000, 1200);
+	}
 }
 
 static void max98090_jack_work(struct work_struct *work)
Signature · 6 lines
2.24.0.432.g9d3f5f5b63-goog

_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
#5 lore raw

PATCH 3/3 ASoC: max98090: fix possible race conditions

In reply to Tzung-Bi Shih

max98090_interrupt() and max98090_pll_work() run in 2 different threads. There are 2 possible races:

Note: M98090_REG_DEVICE_STATUS = 0x01.
Note: ULK == 0, PLL is locked; ULK == 1, PLL is unlocked.

max98090_interrupt max98090_pll_work
----------------------------------------------
schedule max98090_pll_work
restart max98090 codec
receive ULK INT

                        assert ULK == 0

schedule max98090_pll_work (1).

In the case (1), the PLL is locked but max98090_interrupt unnecessarily schedules another max98090_pll_work.

max98090_interrupt max98090_pll_work max98090 codec
----------------------------------------------------------------------

                                               ULK = 1

receive ULK INT
read 0x01
ULK = 0 (clear on read)
schedule max98090_pll_work
restart max98090 codec
ULK = 1
receive ULK INT
read 0x01

                                               ULK = 0 (clear on read)
                        read 0x1
                        assert ULK == 0 (2).

In the case (2), both max98090_interrupt and max98090_pll_work read the same clear-on-read register. max98090_pll_work would falsely thought PLL is locked.

There are 2 possible options:
A. turn off ULK interrupt before scheduling max98090_pll_work; and turn on again before exiting max98090_pll_work.
B. remove the second thread of execution.

Adopts option B which is more straightforward.

---
 sound/soc/codecs/max98090.c | 8 ++------
 sound/soc/codecs/max98090.h | 1 -
 2 files changed, 2 insertions(+), 7 deletions(-)
sound/soc/codecs/max98090.c +2 -6
index 2ccdfb2383b7..75abe98dfc44 100644
@@ -2103,10 +2103,8 @@ static void max98090_pll_det_disable_work(struct work_struct *work)
 			    M98090_IULK_MASK, 0);
 }
 
-static void max98090_pll_work(struct work_struct *work)
+static void max98090_pll_work(struct max98090_priv *max98090)
 {
-	struct max98090_priv *max98090 =
-		container_of(work, struct max98090_priv, pll_work);
 	struct snd_soc_component *component = max98090->component;
 	unsigned int pll;
 	int i;
@@ -2268,7 +2266,7 @@ static irqreturn_t max98090_interrupt(int irq, void *data)
 
 	if (active & M98090_ULK_MASK) {
 		dev_dbg(component->dev, "M98090_ULK_MASK\n");
-		schedule_work(&max98090->pll_work);
+		max98090_pll_work(max98090);
 	}
 
 	if (active & M98090_JDET_MASK) {
@@ -2431,7 +2429,6 @@ static int max98090_probe(struct snd_soc_component *component)
 			  max98090_pll_det_enable_work);
 	INIT_WORK(&max98090->pll_det_disable_work,
 		  max98090_pll_det_disable_work);
-	INIT_WORK(&max98090->pll_work, max98090_pll_work);
 
 	/* Enable jack detection */
 	snd_soc_component_write(component, M98090_REG_JACK_DETECT,
@@ -2484,7 +2481,6 @@ static void max98090_remove(struct snd_soc_component *component)
 	cancel_delayed_work_sync(&max98090->jack_work);
 	cancel_delayed_work_sync(&max98090->pll_det_enable_work);
 	cancel_work_sync(&max98090->pll_det_disable_work);
-	cancel_work_sync(&max98090->pll_work);
 	max98090->component = NULL;
 }
 
sound/soc/codecs/max98090.h +0 -1
index 57965cd678b4..a197114b0dad 100644
@@ -1530,7 +1530,6 @@ struct max98090_priv {
 	struct delayed_work jack_work;
 	struct delayed_work pll_det_enable_work;
 	struct work_struct pll_det_disable_work;
-	struct work_struct pll_work;
 	struct snd_soc_jack *jack;
 	unsigned int dai_fmt;
 	int tdm_slots;
Signature · 6 lines
2.24.0.432.g9d3f5f5b63-goog

_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
#6 lore raw

Re: [alsa-devel] [PATCH 3/3] ASoC: max98090: fix possible race conditions

Quoted 11 lines · Tzung-Bi Shih

max98090_interrupt() and max98090_pll_work() run in 2 different threads. There are 2 possible races:

Note: M98090_REG_DEVICE_STATUS = 0x01.
Note: ULK == 0, PLL is locked; ULK == 1, PLL is unlocked.

max98090_interrupt max98090_pll_work
----------------------------------------------
schedule max98090_pll_work
restart max98090 codec
receive ULK INT

Quoted 5 lines
                         assert ULK == 0

schedule max98090_pll_work (1).

In the case (1), the PLL is locked but max98090_interrupt unnecessarily schedules another max98090_pll_work.

if you re-test that the PLL is already running, then you can exit the work function immediately without redoing the sequence?

maybe also play with the masks so that the PLL unlock is masked in the interrupt and unmasked after the PLL locks?

Quoted 12 lines

max98090_interrupt max98090_pll_work max98090 codec
----------------------------------------------------------------------

                                                ULK = 1

receive ULK INT
read 0x01
ULK = 0 (clear on read)
schedule max98090_pll_work
restart max98090 codec
ULK = 1
receive ULK INT
read 0x01

Quoted 3 lines
                                                ULK = 0 (clear on read)
                         read 0x1
                         assert ULK == 0 (2).

what are those 0x01 and 0x1? is the second a typo possibly?

Quoted 11 lines

In the case (2), both max98090_interrupt and max98090_pll_work read the same clear-on-read register. max98090_pll_work would falsely thought PLL is locked.

There are 2 possible options:
A. turn off ULK interrupt before scheduling max98090_pll_work; and turn on again before exiting max98090_pll_work.
B. remove the second thread of execution.

Adopts option B which is more straightforward.

but has the side effect of possibly adding a 10ms delay in the interrupt thread?

_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#7 lore raw

Re: [alsa-devel] [PATCH 3/3] ASoC: max98090: fix possible race conditions

Quoted 15 lines · Pierre-Louis Bossart
Quoted 14 lines · Tzung-Bi Shih

max98090_interrupt() and max98090_pll_work() run in 2 different threads. There are 2 possible races:

Note: M98090_REG_DEVICE_STATUS = 0x01.
Note: ULK == 0, PLL is locked; ULK == 1, PLL is unlocked.

max98090_interrupt max98090_pll_work
----------------------------------------------
schedule max98090_pll_work
restart max98090 codec
receive ULK INT

                         assert ULK == 0

schedule max98090_pll_work (1).

Quoted 5 lines
Quoted 2 lines

In the case (1), the PLL is locked but max98090_interrupt unnecessarily schedules another max98090_pll_work.

if you re-test that the PLL is already running, then you can exit the work function immediately without redoing the sequence?

ACK.

Quoted 2 lines

maybe also play with the masks so that the PLL unlock is masked in the interrupt and unmasked after the PLL locks?

ACK, this is our option A mentioned below.

Quoted 15 lines
Quoted 11 lines

max98090_interrupt max98090_pll_work max98090 codec
----------------------------------------------------------------------

                                                ULK = 1

receive ULK INT
read 0x01
ULK = 0 (clear on read)
schedule max98090_pll_work
restart max98090 codec
ULK = 1
receive ULK INT
read 0x01

Quoted 3 lines
                                                ULK = 0 (clear on read)
                         read 0x1
                         assert ULK == 0 (2).
Quoted 1 line

what are those 0x01 and 0x1? is the second a typo possibly?

ACK, a typo.

Quoted 9 lines
Quoted 9 lines

In the case (2), both max98090_interrupt and max98090_pll_work read the same clear-on-read register. max98090_pll_work would falsely thought PLL is locked.

There are 2 possible options:
A. turn off ULK interrupt before scheduling max98090_pll_work; and turn on again before exiting max98090_pll_work.
B. remove the second thread of execution.

Quoted 4 lines
Quoted 1 line

Adopts option B which is more straightforward.

but has the side effect of possibly adding a 10ms delay in the interrupt thread?

(forgot to mention) Option A cannot fix the case (2) race condition:
there would be 2 threads read the same clear-on-read register. In theory, the hardware should faster than CPUs' accesses via I2C. max98090 should returns ULK=1 any time if PLL is unlocked. Shall we ignore the case (2) and adopt option A?
_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#8 lore raw

Re: [alsa-devel] [PATCH 3/3] ASoC: max98090: fix possible race conditions

Quoted 32 lines
Quoted 17 lines
Quoted 13 lines

max98090_interrupt max98090_pll_work max98090 codec
----------------------------------------------------------------------

                                                 ULK = 1

receive ULK INT
read 0x01
ULK = 0 (clear on read)
schedule max98090_pll_work
restart max98090 codec
ULK = 1
receive ULK INT
read 0x01

Quoted 3 lines
                                                 ULK = 0 (clear on read)
                          read 0x1
                          assert ULK == 0 (2).
Quoted 1 line

what are those 0x01 and 0x1? is the second a typo possibly?

ACK, a typo.

Quoted 11 lines
Quoted 10 lines

In the case (2), both max98090_interrupt and max98090_pll_work read the same clear-on-read register. max98090_pll_work would falsely thought PLL is locked.

There are 2 possible options:
A. turn off ULK interrupt before scheduling max98090_pll_work; and turn on again before exiting max98090_pll_work.
B. remove the second thread of execution.

Adopts option B which is more straightforward.

Quoted 8 lines
Quoted 2 lines

but has the side effect of possibly adding a 10ms delay in the interrupt thread?

(forgot to mention) Option A cannot fix the case (2) race condition:
there would be 2 threads read the same clear-on-read register. In theory, the hardware should faster than CPUs' accesses via I2C. max98090 should returns ULK=1 any time if PLL is unlocked. Shall we ignore the case (2) and adopt option A?

I don't have any specific recommendation, just trying to follow your line of thought on a problem that bugged be in the past. If your tests shows that the extra delay is fine, then it's good progress

Still you may want to clarify your second point and the commit message. The first race condition was clear, the second one not so much.

what did you mean with 'assert ULK == 0' and what does this map to in pll_work

the code looks as this:

static void max98090_pll_work(struct work_struct *work)

{
	if (!snd_soc_component_is_active(component))
		return;

	/* Toggle shutdown OFF then ON */
	snd_soc_component_update_bits(component, M98090_REG_DEVICE_SHUTDOWN,
			    M98090_SHDNN_MASK, 0);

	snd_soc_component_update_bits(component, M98090_REG_DEVICE_SHUTDOWN,
			    M98090_SHDNN_MASK, M98090_SHDNN_MASK);

	/* Give PLL time to lock */
	msleep(10);
}

so in what does the race occur?

or was it race with the other work queue, which starts like this:

static void max98090_pll_det_enable_work(struct work_struct *work)

{
	struct max98090_priv *max98090 =
		container_of(work, struct max98090_priv,
			     pll_det_enable_work.work);
	struct snd_soc_component *component = max98090->component;
	unsigned int status, mask;

	/*
	 * Clear status register in order to clear possibly already occurred
	 * PLL unlock. If PLL hasn't still locked, the status will be set
	 * again and PLL unlock interrupt will occur.
	 * Note this will clear all status bits
	 */
	regmap_read(max98090->regmap, M98090_REG_DEVICE_STATUS, &status);

So here indeed there is the same read, but what is the consequence of the read?

did you mean that in the pll_det_enable_work the value of 'status' may be incorrect as it was cleared already?

But the interrupt does not schedule the pll_det_enable_work(), it happens on a trigger, so how would the race happen?

it'd be good if you provide more details on the flow so that all reviewers get the ideas, it's a good opportunity to fix this for good and move on.
_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#9 lore raw

Re: [alsa-devel] [PATCH 3/3] ASoC: max98090: fix possible race conditions

Quoted 5 lines · Pierre-Louis Bossart

Still you may want to clarify your second point and the commit message. The first race condition was clear, the second one not so much.

what did you mean with 'assert ULK == 0' and what does this map to in pll_work

The case (2) race condition is based on the previous patch:
https://mailman.alsa-project.org/pipermail/alsa-devel/2019-November/158852.html

After applying the patch, the code would be something like: (in the case, two threads read 0x01.)
static void max98090_pll_work(struct work_struct *work) {
[snip]

        snd_soc_component_update_bits(component, M98090_REG_DEVICE_SHUTDOWN,
                            M98090_SHDNN_MASK, 0);
        snd_soc_component_update_bits(component, M98090_REG_DEVICE_SHUTDOWN,
                            M98090_SHDNN_MASK, M98090_SHDNN_MASK);

        for (i = 0; i < 10; ++i) {
                /* Check lock status */
                pll = snd_soc_component_read32(
                                component, M98090_REG_DEVICE_STATUS);
                if (!(pll & M98090_ULK_MASK))
                        break;

                /* Give PLL time to lock */
                usleep_range(1000, 1200);
        }
}

I guess we have 2 choices:
i. stick to the original plan: option B, remove the second thread of execution. In the case, we would be punished by at most 10~12ms delay in the interrupt handler thread. I browsed the max98090_interrupt() and tend to think it should be fine if we delay jack detection for extra 10ms.

ii. adopt option A, play with the masks; and drop the previous patch to avoid multiple threads access 0x01
We would be forced to wait >10ms before re-enabling ULK interrupt. Notably, Documentation/timers/timers-howto.txt states "msleep(1~20) may not do what the caller intends, and will often sleep longer".Documentation/timers/timers-howto.txt".

Either way should be fine. Which one would you suggest?
_______________________________________________
Alsa-devel mailing list [email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#10 lore raw

Re: [alsa-devel] [PATCH 3/3] ASoC: max98090: fix possible race conditions

Quoted 10 lines · Tzung-Bi Shih
Quoted 5 lines · Pierre-Louis Bossart

Still you may want to clarify your second point and the commit message. The first race condition was clear, the second one not so much.

what did you mean with 'assert ULK == 0' and what does this map to in pll_work

The case (2) race condition is based on the previous patch:
https://mailman.alsa-project.org/pipermail/alsa-devel/2019-November/158852.html

ah, ok, so that's a race you introduced :-)

Quoted 6 lines

After applying the patch, the code would be something like: (in the case, two threads read 0x01.)
static void max98090_pll_work(struct work_struct *work) {
[snip]

Quoted 16 lines
         snd_soc_component_update_bits(component, M98090_REG_DEVICE_SHUTDOWN,
                             M98090_SHDNN_MASK, 0);
         snd_soc_component_update_bits(component, M98090_REG_DEVICE_SHUTDOWN,
                             M98090_SHDNN_MASK, M98090_SHDNN_MASK);

         for (i = 0; i < 10; ++i) {
                 /* Check lock status */
                 pll = snd_soc_component_read32(
                                 component, M98090_REG_DEVICE_STATUS);
                 if (!(pll & M98090_ULK_MASK))
                         break;

                 /* Give PLL time to lock */
                 usleep_range(1000, 1200);
         }
}

Sorry, I don't see at what point the race happens.

if your interrupt sees an ULK status, it will schedule the pll_work.
You only test the status again *after* switching the device on/off, so what is the side effect?

I am also wondering if you shouldn't sleep first in the loop, then check the status?

And in case you do have a side effect due to the clear on read, maybe you could save the status in a context and retest in the workqueue, that way you'd have a trace of the ULK event even if the register was cleared.

_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#11 lore raw

Re: [alsa-devel] [PATCH 3/3] ASoC: max98090: fix possible race conditions

Quoted 37 lines · Pierre-Louis Bossart
Quoted 10 lines · Tzung-Bi Shih
Quoted 5 lines · Pierre-Louis Bossart

Still you may want to clarify your second point and the commit message. The first race condition was clear, the second one not so much.

what did you mean with 'assert ULK == 0' and what does this map to in pll_work

The case (2) race condition is based on the previous patch:
https://mailman.alsa-project.org/pipermail/alsa-devel/2019-November/158852.html

ah, ok, so that's a race you introduced :-)

Quoted 6 lines

After applying the patch, the code would be something like: (in the case, two threads read 0x01.)
static void max98090_pll_work(struct work_struct *work) {
[snip]

Quoted 16 lines
         snd_soc_component_update_bits(component, M98090_REG_DEVICE_SHUTDOWN,
                             M98090_SHDNN_MASK, 0);
         snd_soc_component_update_bits(component, M98090_REG_DEVICE_SHUTDOWN,
                             M98090_SHDNN_MASK, M98090_SHDNN_MASK);

         for (i = 0; i < 10; ++i) {
                 /* Check lock status */
                 pll = snd_soc_component_read32(
                                 component, M98090_REG_DEVICE_STATUS);
                 if (!(pll & M98090_ULK_MASK))
                         break;

                 /* Give PLL time to lock */
                 usleep_range(1000, 1200);
         }
}
Quoted 5 lines

Sorry, I don't see at what point the race happens.

if your interrupt sees an ULK status, it will schedule the pll_work. You only test the status again *after* switching the device on/off, so what is the side effect?

Both interrupt thread and pll_work thread access the status register. The side effect is: interrupt thread could read the status register right before pll_work thread's read.

Quoted 2 lines

I am also wondering if you shouldn't sleep first in the loop, then check the status?

ACK, "sleep first and check the status" makes more sense.

Quoted 3 lines

And in case you do have a side effect due to the clear on read, maybe you could save the status in a context and retest in the workqueue, that way you'd have a trace of the ULK event even if the register was cleared.

I think cache the status couldn't be a good idea. We couldn't make sure the freshness of the cache.

Can we suppose CPUs always get ULK=1 if PLL is unlocked so that we can simply ignore the case (2)? Since we know the register is volatile and read the register via I2C should be much slower than hardware raise the bit.
_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#12 lore raw

Re: [alsa-devel] [PATCH 3/3] ASoC: max98090: fix possible race conditions

Quoted 13 lines
Quoted 5 lines

if your interrupt sees an ULK status, it will schedule the pll_work. You only test the status again *after* switching the device on/off, so what is the side effect?

Both interrupt thread and pll_work thread access the status register. The side effect is: interrupt thread could read the status register right before pll_work thread's read.

Quoted 2 lines

I am also wondering if you shouldn't sleep first in the loop, then check the status?

Quoted 8 lines

ACK, "sleep first and check the status" makes more sense.

Quoted 3 lines

And in case you do have a side effect due to the clear on read, maybe you could save the status in a context and retest in the workqueue, that way you'd have a trace of the ULK event even if the register was cleared.

I think cache the status couldn't be a good idea. We couldn't make sure the freshness of the cache.

I was thinking more of treating it as a volatile, but it's ugly indeed.

Quoted 4 lines

Can we suppose CPUs always get ULK=1 if PLL is unlocked so that we can simply ignore the case (2)? Since we know the register is volatile and read the register via I2C should be much slower than hardware raise the bit.

Your option B with the small change to sleep then retest is probably the better solution overall.

BTW did you test this on both Baytrail and BSW chromebooks? In the past I saw baytrail devices exposed this error a lot more than BSW.

_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#13 lore raw

Re: [alsa-devel] [PATCH 3/3] ASoC: max98090: fix possible race conditions

Quoted 7 lines · Pierre-Louis Bossart
Quoted 4 lines

Can we suppose CPUs always get ULK=1 if PLL is unlocked so that we can simply ignore the case (2)? Since we know the register is volatile and read the register via I2C should be much slower than hardware raise the bit.

Your option B with the small change to sleep then retest is probably the better solution overall.

Have sent v2, https://mailman.alsa-project.org/pipermail/alsa-devel/2019-November/159050.html

Quoted 2 lines

BTW did you test this on both Baytrail and BSW chromebooks? In the past I saw baytrail devices exposed this error a lot more than BSW.

I tested on a Baytrail-based chromebook which is easy to generate lots
of "PLL unlocked" on the console. After applying this series and the
next series (https://mailman.alsa-project.org/pipermail/alsa-devel/2019-November/158853.html),
I seldom see "PLL unlocked" on the console. It still happens a few
times, but with very very low probability.
_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel