Skip to content

copier: pipeline period recalculation#7626

Closed
tmleman wants to merge 1 commit intothesofproject:mainfrom
tmleman:topic/upstream/pr/copier/gtw/deep_buffer
Closed

copier: pipeline period recalculation#7626
tmleman wants to merge 1 commit intothesofproject:mainfrom
tmleman:topic/upstream/pr/copier/gtw/deep_buffer

Conversation

@tmleman
Copy link
Contributor

@tmleman tmleman commented May 16, 2023

In case of a deep buffering pipelines don't require scheduling on every millisecond. We can calculate period based on the gateway buffer size.

At pipeline creation we assume that it can work on longer periods, period value is set to zero to be later adjust base on the pipeline components.

@marcinszkudlinski marcinszkudlinski self-requested a review May 17, 2023 09:57
@tmleman tmleman force-pushed the topic/upstream/pr/copier/gtw/deep_buffer branch 2 times, most recently from a6f4587 to 6a828ca Compare June 1, 2023 12:14
@tmleman tmleman force-pushed the topic/upstream/pr/copier/gtw/deep_buffer branch from 6a828ca to bff7c8d Compare June 15, 2023 10:51
@tmleman tmleman force-pushed the topic/upstream/pr/copier/gtw/deep_buffer branch 3 times, most recently from 4b85350 to 19226b9 Compare June 20, 2023 11:09
@tmleman tmleman marked this pull request as ready for review June 20, 2023 11:12
@tmleman tmleman requested review from btian1, lyakh, mmaka1 and ranj063 June 20, 2023 11:35
Copy link
Collaborator

Choose a reason for hiding this comment

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

just as an example to clarify why this won't quite calculate correct results and why you need to round up line 114:

one_s = 8090
ten_ms = 80
dma_buffer_size = 8000
chunk_count = 100

that will tell you, that you can fit 100 10ms long chunks in the buffer, so you could conclude that a full second of audio fits into the buffer, whereas it doesn't - 90 bytes don't fit. Whereas if you round up the first division in line 114, you get

one_s = 8090
ten_ms = 81
dma_buffer_size = 8000
chunk_count = 98

so you conclude, that 980ms of audio will fit into the buffer, which is correct - they will fit there and will occupy 0.98*8090 < 7983 < 8000 bytes.

Copy link
Contributor

Choose a reason for hiding this comment

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

may need enumerate all the possible freqs and then divide can be avoided by look up table.
like is only support 44100 and 48000 input, then two divide can be avoided.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I assumed that rounding is not needed because none of the formats we use will result in a value that is not divisible by 100. I added rounding anyway.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I dont think there are any rates that are not multiples of 100.

Copy link
Collaborator

Choose a reason for hiding this comment

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

so we will not support 11.025 khz and 22.05 khz ?

enum ipc4_sampling_frequency {
	IPC4_FS_8000HZ = 8000,
	IPC4_FS_11025HZ = 11025,
	IPC4_FS_12000HZ = 12000, /**< Mp3, AAC, SRC only */
	IPC4_FS_16000HZ = 16000,
	IPC4_FS_18900HZ = 18900, /**< SRC only for 44100 */
	IPC4_FS_22050HZ = 22050,
	IPC4_FS_24000HZ = 24000, /**< Mp3, AAC, SRC only */
	IPC4_FS_32000HZ = 32000,
	IPC4_FS_37800HZ = 37800, /**< SRC only for 44100 */
	IPC4_FS_44100HZ = 44100,
	IPC4_FS_48000HZ = 48000, /**< Default */
	IPC4_FS_64000HZ = 64000, /**< AAC, SRC only */
	IPC4_FS_88200HZ = 88200, /**< AAC, SRC only */
	IPC4_FS_96000HZ = 96000, /**< AAC, SRC only */
	IPC4_FS_176400HZ = 176400, /**< SRC only */
	IPC4_FS_192000HZ = 192000, /**< SRC only */
	IPC4_FS_INVALID
};

Copy link
Member

Choose a reason for hiding this comment

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

oh, good point @RanderWang - these are rare but in IPC4 and ALSA.
@tmleman looks like we need a switch here to deal with the non divisible corner cases.

Copy link
Collaborator

Choose a reason for hiding this comment

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

so in my above example if buffer size is 80 bytes, you'll calculate chunk_count == 1 but in fact it won't fit full 10ms of audio

Copy link
Member

Choose a reason for hiding this comment

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

Isn't buffer size validated prior to this logic ? @tmleman do we validate copier->base.audio_fmt.sampling_frequency, copier->base.audio_fmt.depth or copier->base.audio_fmt.channels_count to be non zero here otherwise we can divide by 0.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I was thinking it would be ncie to have a log entry to catch if topology has an incorrect configuration. But as this is called also in normal case, addign a INF level log is probably not a good idea here. It would be good to have a note/warning if host is asking for a combiation with copier configured with deep buffers for DMA, but the pipeline is not compatible.

Copy link
Collaborator

Choose a reason for hiding this comment

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

With so many inputs (both from runtime PCM config as well as topology), I think this warrants printing out the modified period size to FW log.

Copy link
Member

Choose a reason for hiding this comment

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

ack, would be handy for debug.

Copy link
Contributor

Choose a reason for hiding this comment

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

may need enumerate all the possible freqs and then divide can be avoided by look up table.
like is only support 44100 and 48000 input, then two divide can be avoided.

Copy link
Contributor

Choose a reason for hiding this comment

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

dev->pipeline->long_period same meaning with dev->deep_buffering

Copy link
Member

@lgirdwood lgirdwood left a comment

Choose a reason for hiding this comment

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

@tmleman This should be a pipeline 2.0 API i.e.

int pipeline_sleep(pipeline, ms);

And this could be called by copiers during process() when conditions allow the pipe to skip schedling ticks. It should also be a feature that can be enabled/disabled by topology flag (i. assume there is an IPC4 flag to enable it ?)

@tmleman tmleman force-pushed the topic/upstream/pr/copier/gtw/deep_buffer branch from 19226b9 to 24bafe6 Compare August 1, 2023 13:32
@tmleman
Copy link
Contributor Author

tmleman commented Aug 1, 2023

23ww31.3 Update(1/2): resolving some issues from review comments.

@tmleman tmleman force-pushed the topic/upstream/pr/copier/gtw/deep_buffer branch from 24bafe6 to 15863d3 Compare August 1, 2023 13:38
@tmleman
Copy link
Contributor Author

tmleman commented Aug 1, 2023

23ww31.3 Update(2/2): rebase

Copy link
Member

@lgirdwood lgirdwood left a comment

Choose a reason for hiding this comment

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

@tmleman @ranj063 I assume we have a CI test or topology that can test 10ms pipelines ? If so, we should make sure its run since we are optimizing non 1ms pipelines now.

@lgirdwood
Copy link
Member

@tmleman sorry to ask, are you able to rebase again on HEAD as a build failure was introduced with VMH and was fixed late yesterday. Thanks !

@tmleman tmleman force-pushed the topic/upstream/pr/copier/gtw/deep_buffer branch from 15863d3 to 53d130e Compare August 2, 2023 11:51
@tmleman
Copy link
Contributor Author

tmleman commented Aug 2, 2023

23ww31.4 Update(1/2):

  • renaming variable long_period to deep_buffering,
  • replacing division by 8 with bit shift for medieval compilers.

@tmleman tmleman force-pushed the topic/upstream/pr/copier/gtw/deep_buffer branch from 53d130e to 50e962e Compare August 2, 2023 11:52
@tmleman
Copy link
Contributor Author

tmleman commented Aug 2, 2023

23ww31.4 Update(2/2): rebase

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I dont think there are any rates that are not multiples of 100.

Copy link
Member

Choose a reason for hiding this comment

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

Isn't buffer size validated prior to this logic ? @tmleman do we validate copier->base.audio_fmt.sampling_frequency, copier->base.audio_fmt.depth or copier->base.audio_fmt.channels_count to be non zero here otherwise we can divide by 0.

Copy link
Member

Choose a reason for hiding this comment

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

ack, would be handy for debug.

Copy link
Member

Choose a reason for hiding this comment

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

I would pipe_info("setting pipe period to %d us", LL_TIMER_PERIOD_US) as this will catch any changes to LL period macro.

Copy link
Contributor

@btian1 btian1 left a comment

Choose a reason for hiding this comment

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

@tmleman , I would suggest split this PR to two patches if you need use two deep_buffering, one is for dev->deep_buffering adding, another is for pipeline->deep_buffering adding, this will make the PR more easy to read and understand.

@tmleman tmleman force-pushed the topic/upstream/pr/copier/gtw/deep_buffer branch 2 times, most recently from 6baa99c to 6297bd9 Compare August 7, 2023 12:01
@lgirdwood
Copy link
Member

@tmleman does the latest update resolve the review comments ?

@tmleman
Copy link
Contributor Author

tmleman commented Aug 11, 2023

@abonislawski @marcinszkudlinski request for a review.

struct ipc_comp_dev *ipc_comp =
ipc_get_comp_by_ppl_id(ipc,
COMP_TYPE_PIPELINE,
pipe_id);
Copy link
Collaborator

Choose a reason for hiding this comment

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

are we sure, that ipc_comp cannot be NULL here? pipe_id comes from an IPC... BTW, looks like ipc4_add_comp_dev() can be static

In case of a deep buffering pipelines don't require scheduling on every
millisecond. We can calculate period based on the gateway buffer size.

At pipeline creation we assume that it can work on longer periods,
period value is set to zero to be later adjust base on the pipeline
components.

Signed-off-by: Tomasz Leman <tomasz.m.leman@intel.com>
@tmleman tmleman force-pushed the topic/upstream/pr/copier/gtw/deep_buffer branch from 6297bd9 to db78be6 Compare October 3, 2023 14:27
@tmleman
Copy link
Contributor Author

tmleman commented Oct 3, 2023

23ww40.3 Update: rebase

@lgirdwood
Copy link
Member

23ww40.3 Update: rebase

@tmleman CI showing some issues. We probably want to rebase and retest to give confidence the calculations are correct.

@lgirdwood lgirdwood added this to the v2.8 milestone Oct 20, 2023
@tmleman
Copy link
Contributor Author

tmleman commented Nov 8, 2023

I'm closing this PR. I don't have time to work on it at the moment.

@tmleman tmleman closed this Nov 8, 2023
@tmleman tmleman deleted the topic/upstream/pr/copier/gtw/deep_buffer branch December 17, 2025 12:14
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.

8 participants