Skip to content

dmic: fix pause/release error leading to invalid dmic_active_fifos - #4283

Merged
lgirdwood merged 1 commit into
thesofproject:mainfrom
kv2019i:topic/fix-dmic-pause
Jun 4, 2021
Merged

lgirdwood merged 1 commit into
thesofproject:mainfrom
kv2019i:topic/fix-dmic-pause

Conversation

@kv2019i

@kv2019i kv2019i commented Jun 2, 2021

Copy link
Copy Markdown
Collaborator

The 'in_active' parameter of dmic_stop() is used to control whether
the fifo should be released or not. In case of COMP_TRIGGER_PAUSE,
this should be false and the 'dmic_active_fifos' count should not
be modified.

Without this fix:

PAUSED -> RELEASE -> dmic_start() -> no change on dmic_active_fifos

ACTIVE -> PAUSE -> dmic_stop() -> dmic_active_fifos--

If a test case repeatedly pauses and releases, 'dmic_active_fifos'
will go out-of-sync.

Fix the issue that dmic_stop for PAUSE does not release the fifo
reference.

Fixes: 2273174 ("dmic: don't decrement active FIFO count below 0")
Signed-off-by: Kai Vehmanen kai.vehmanen@linux.intel.com

The 'in_active' parameter of dmic_stop() is used to control whether
the fifo should be released or not. In case of COMP_TRIGGER_PAUSE,
this should be false and the 'dmic_active_fifos' count should not
be modified.

Without this fix:

  PAUSED -> RELEASE -> dmic_start() -> no change on dmic_active_fifos

  ACTIVE -> PAUSE   -> dmic_stop()  -> dmic_active_fifos--

If a test case repeatedly pauses and releases, 'dmic_active_fifos'
will go out-of-sync.

Fix the issue that dmic_stop for PAUSE does not release the fifo
reference.

Fixes: 2273174 ("dmic: don't decrement active FIFO count below 0")
Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
@kv2019i

kv2019i commented Jun 2, 2021

Copy link
Copy Markdown
Collaborator Author

FYI @keyonjie and @ranj063 This could cause subtle errors in dmic_stop() and dmic_remove() that might show up e.g. with dynamic pipeline topologies. With our mainline SOF (not Zephyr), the "multiple-pause-resume.sh" test passes without error, but if you look at sof-logger, one can see:

[          31.770832] (          17.083332) c0 dmic-dai     2.1   src/drivers/intel/dmic.c:1421 dmic_start(), done active_fifos = -39
[      502692.740441] (          18.333332) c0 dmic-dai     2.1   src/drivers/intel/dmic.c:1451 dmic_stop(), dmic_active_fifos = -39
[      505509.563246] (          16.927082) c0 dmic-dai     2.1   src/drivers/intel/dmic.c:1421 dmic_start(), done active_fifos = -40
[     1006391.835010] (          18.229166) c0 dmic-dai     2.1   src/drivers/intel/dmic.c:1451 dmic_stop(), dmic_active_fifos = -40
[     1157646.568583] (          16.979166) c0 dmic-dai     2.1   src/drivers/intel/dmic.c:1421 dmic_start(), done active_fifos = -41
[     1407690.360730] (          18.229166) c0 dmic-dai     2.1   src/drivers/intel/dmic.c:1451 dmic_stop(), dmic_active_fifos = -41
[     1655148.215480] (         144.270828) c0 dmic-dai     2.1   src/drivers/intel/dmic.c:1421 dmic_start(), done active_fifos = -42
[     1906511.174242] (          18.385416) c0 dmic-dai     2.1   src/drivers/intel/dmic.c:1451 dmic_stop(), dmic_active_fifos = -42

... as active_fifos count goes to zero, this means dmic driver does not work as expected and more subtle errors can occur, even if not caught by this test case.

Comment thread src/drivers/intel/dmic.c
case COMP_TRIGGER_PAUSE:
dmic->state = COMP_STATE_PAUSED;
dmic_stop(dai, true);
dmic_stop(dai, false);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kv2019i is this a better fix?

if (dmic->state == COMP_STATE_PREPARE || dmic->state == COMP_STATE_PAUSED)		 
   (*uncached_dmic_active_fifos)++;

@singalsu singalsu Jun 3, 2021 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kv2019i I'm worried about active_fifos_count not tracking stopped FIFOs HW even if it fixes the reference loss. Non-matching count will alter the stop sequence and could leave bus clock on. I'm not sure about and need to test this.

@ranj063 Wouldn't that remove @lyakh 's add? Instead of in_active flag I wonder if the active fifos count should be replaced with a bit-field. In dmic_stop() the corresponding bit to DAI # is cleared, and set it dmic_start().

Maybe such bitmask "active_fifos_mask" would help to simplify to remove all recently added pause/stop bug fix logic?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ranj063 We shouldn't increase fifo-count when state is paused, so that's not right. I'd vote for using a bitfield instead. This would be both easier to understand and also easier to debug than having a counter.

@keyonjie

keyonjie commented Jun 3, 2021

Copy link
Copy Markdown
Contributor

nice catch, @kv2019i ,
FYI @singalsu we did see minus dmic_active_fifos value.

As @ranj063 mentioned, we might need to think it more to make the state and the dmic_active_fifos count more consistent.

@keyonjie

keyonjie commented Jun 3, 2021 •

Copy link
Copy Markdown
Contributor

@kv2019i @ranj063 @singalsu let me submit a cleanup PR for this.

[update]
here is the PR: #4285

@kv2019i

kv2019i commented Jun 3, 2021

Copy link
Copy Markdown
Collaborator Author

@keyonjie 's rework #4285 hit some issue (removing pause will have side-effects), so this is still valid to consider.

Some refactoring is probably in order, but I think this PR can be merged first.

@ranj063

ranj063 commented Jun 3, 2021

Copy link
Copy Markdown
Collaborator

@keyonjie 's rework #4285 hit some issue (removing pause will have side-effects), so this is still valid to consider.

Some refactoring is probably in order, but I think this PR can be merged first.

im good to merge this now and move to use bitfield for active fifos!

@singalsu singalsu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It fixes the issue so please merge. More fixes later.

@lgirdwood

Copy link
Copy Markdown
Member

CI showing APL DUT not booting.

@lgirdwood

Copy link
Copy Markdown
Member

@kv2019i for rc3/final ? @keyonjie fyi.

@lgirdwood
lgirdwood merged commit 282fe22 into thesofproject:main Jun 4, 2021
@kv2019i

kv2019i commented Jun 4, 2021

Copy link
Copy Markdown
Collaborator Author

@lgirdwood Yes for rc3/final (the patch this is fixing is in rc2 so this should go as well)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants