Re: [PATCH] ASoC: Intel: Atom: use hardware counter to update hw_ptr

From: Pierre-Louis Bossart
Date: Tue Jul 28 2020 - 13:30:46 EST




On 7/28/20 12:02 PM, Lu, Brent wrote:

So if there are already quirks in atom machine drivers to change the period
size, why is this patch necessary?


The story is: google implemented the constraint but doesn't know why it works
so asked us to explain. After checking the two counters I realized the increase of
ring buffer pointer follows the period size setting in hw_param (256) but the
period of interrupt is always 5ms instead of 5.33 so it's running little bit too fast.
It seems the LPE keeps tracking the difference of two counters. When the
difference exceeds 2160 samples, the next interrupt will be canceled so the
hardware counter could catch up a little.

[ 43.208299] intel_sst_acpi 808622A8:00: mrfld ring_buffer_counter 107520 hardware_counter 98880 pcm delay 8640 (in bytes)
[ 43.208306] intel_sst_acpi 808622A8:00: buffer ptr 26880 pcm_delay rep: 2160
[ 43.208321] sound pcmC1D0p: [Q] pos 26880 hw_ptr 26880 appl_ptr 40000 avail 191680
=> one interrupt is skipped.
[ 43.218299] intel_sst_acpi 808622A8:00: mrfld ring_buffer_counter 108544 hardware_counter 100800 pcm delay 7744 (in bytes)
[ 43.218307] intel_sst_acpi 808622A8:00: buffer ptr 27136 pcm_delay rep: 1936
[ 43.218336] sound pcmC1D0p: [Q] pos 27136 hw_ptr 27136 appl_ptr 40000 avail 191936

So I think why not using the hardware counter? It increases 240 samples every 5ms
perfectly match the 48000 sample rate. The test result is good but I know there must
be a reason for the original designer to use ring buffer counter instead of hardware
counter. I uploaded this patch to see if anyone still remember the reason and share
some insight with me.

I totally agree that we shouldn't touch this part of design. Do you think it make sense
to add a constraint to enforce the period size in machine driver? If yes then I would
upload patches for Chrome atom machines for google.

I think it'd make sense to add this constraint, either in the machine driver or in the platform driver, so that we don't change the position updates and introduce more issues by accident by doing so. As you rightly said, I don't think anyone tested periods multiple of 256 samples so it's not a regression, more aligning with the internal design.