Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dp: Eearliest deadline first scheduling policy #8262

Merged
merged 2 commits into from
Sep 27, 2023

Conversation

marcinszkudlinski
Copy link
Contributor

This PR introduces a Earlier Deadline First scheduling policy for DP processing

currently there's a limitation - DP module must be surrounded by LL modules.
it simplifies algorithm - there's no need to browse through DP chains calculating
deadlines for each module in function of all modules execution status.
Now is simple - modules deadline is its start + tick time.

example:
Lets assume we do have a pipeline:

LL1 -> DP1 -> LL2 -> DP2 -> LL3 -> DP3 -> LL4

all LLs starts in 1ms tick

for simplification lets assume

  • all LLs are on primary core, all DPs on secondary (100% CPU is for DP)
  • context switching requires 0 cycles

DP1 - starts every 1ms, needs 0.5ms to finish processing
DP2 - starts every 2ms, needs 0.6ms to finish processing
DP3 - starts every 10ms, needs 0.3ms to finish processing

TICK0
only LL1 is ready to run
LL1 processing (producing data chunk for DP1)

TICK1
LL1 is ready to run
DP1 is ready tu run (has data from LL1) set deadline to TICK2
LL1 processing (producing second data chunk for DP1)
DP1 processing for 0.5ms (consuming first data chunk, producing data chunk for LL2)
CPU is idle for 0.5ms

TICK2
LL1 is ready to run
DP1 is ready tu run set deadline to TICK3
LL2 is ready to run
LL1 processing (producing data chunk for DP1)
LL2 processing (producing 50% data chunk for DP2)
DP1 processing for 0.5ms (producing data chunk for LL2)
CPU is idle for 0.5ms

TICK3
LL1 is ready to run
DP1 is ready tu run set deadline to TICK4
LL2 is ready to run
LL1 processing (producing data chunk for DP1)
LL2 processing (producing rest of data chunk for DP2)
DP1 processing for 0.5ms (producing data chunk for LL2)
CPU is idle for 0.5ms

TICK4
LL1 is ready to run
DP1 is ready tu run set deadline to TICK5
LL2 is ready to run
DP2 is ready to run set deadline to TICK6
LL1 processing (producing data chunk for DP1)
LL2 processing (producing 50% of second data chunk for DP2)
DP1 processing for 0.5ms (producing data chunk for LL2)
DP2 processing for 0.5ms (no data produced as DP2 has 0.1ms to go)
100% CPU used

!!!!!! Note here - DP1 must do before DP2 as it MUST finish in this tick. DP2 can wait
	>>>>>>> this is what we call EDF - EARIEST DEADLINE FIRST <<<<<<

TICK5
LL1 is ready to run
DP1 is ready tu run set deadline to TICK6
LL2 is ready to run
DP2 is in progress, deadline is set to TICK6
LL1 processing (producing data chunk for DP1)
LL2 processing (producing rest of second data chunk for DP2)
DP1 processing for 0.5ms (producing data chunk for LL2)
DP2 processing for 0.1ms (producing TWO data chunks for LL3)
CPU is idle for 0.4ms (60% used)

TICK6
LL1 is ready to run
DP1 is ready tu run set deadline to TICK7
LL2 is ready to run
DP2 is ready to run set deadline to TICK8
LL3 is ready to run
LL1 processing (producing data chunk for DP1)
LL2 processing (producing 50% of second data chunk for DP2)
LL3 processing (producing 10% of first data chunk for DP3)
DP1 processing for 0.5ms (producing data chunk for LL2)
DP2 processing for 0.5ms (no data produced as DP2 has 0.1ms to go)
100% CPU used

(........ 9 more cycles - LL3 procuces 100% of data for DP3......)

TICK15
LL1 is ready to run
DP1 is ready tu run set deadline to TICK16
LL2 is ready to run
DP2 is ready to run set deadline to TICK17
LL3 is ready to run
DP3 is ready to run set deadline to TICK25
LL1 processing (producing data chunk for DP1)
LL2 processing (producing 50% of data chunk for DP2)
LL3 processing (producing 10% of second data chunk for DP3)
DP1 processing for 0.5ms (producing data chunk for LL2)
DP2 processing for 0.5ms (no data produced as DP2 has 0.1ms to go)
100% CPU used -
!!! note that DP3 is ready but has no chance to get CPU in this cycle

TICK16
LL1 is ready to run set deadline to TICK17
DP1 is ready tu run
LL2 is ready to run
DP2 is in progress, deadline is set to TICK17
LL3 is ready to run
DP3 is in progress, deadline is set to TICK25
LL1 processing (producing data chunk for DP1)
LL2 processing (producing rest of data chunk for DP2)
LL3 processing (producing 10% of second data chunk for DP3)
DP1 processing for 0.5ms (producing data chunk for LL2)
DP2 processing for 0.1ms (producing data)
DP3 processing for 0.2ms (producing 10 data chunks for LL4)
90% CPU used

TICK17
LL1 is ready to run
DP1 is ready tu run
LL2 is ready to run
DP2 is ready to run
LL3 is ready to run
LL4 is ready to run
!! NOTE that DP3 is not ready - it will be ready again in TICK25
LL1 processing (producing data chunk for DP1)
LL2 processing (producing rest of data chunk for DP2)
LL3 processing (producing next 10% of second data chunk for DP3)
LL4 processing (consuming 10% of data prepared by DP3)
DP1 processing for 0.5ms (producing data chunk for LL2)
DP2 processing for 0.5ms (no data produced as DP2 has 0.1ms to go)
100% CPU used

Now - pipeline is in stable state, CPU used almost in 100% (it would be 100% if DP3
needed 1.2ms for processing - but the example would be too complicated)

src/audio/module_adapter/module_adapter.c Outdated Show resolved Hide resolved
src/schedule/zephyr_dp_schedule.c Outdated Show resolved Hide resolved
src/audio/module_adapter/module_adapter.c Outdated Show resolved Hide resolved
src/schedule/zephyr_dp_schedule.c Outdated Show resolved Hide resolved
For LL modules it is very straightforward - all LL modules
are called one by one in every LL pipeline tick, so module's
period is always equal to LL pipeline period

For DP modules a period has different meaning. As DP
is called "on demand" - whenever it is ready, it may not be
scheduled at every LL tick (and usually is not)

A period meaning for DP is "a time when the module must finish
its job and provide data to next module in pipeline
or the data flow will be corrupted (a glitch)"

In common case the period is calculation is based on module's
OBS - if module provides OBS bytes of data in each cycle, it MUST
finish at least before the next module drains the buffer

In some special cases - modules producing a variable bitrate
(like MPEG) or not producing audio data at all (phrase detector,
speech recognition, etc.) - the module may set the period itself
during prepare operation

This commit adds calculation of DP period. This value will be used
in following commit as a base for deadlines calculation in EDF

Signed-off-by: Marcin Szkudlinski <marcin.szkudlinski@intel.com>
Earliest deadline first scheduling added, based on module
period

Detailed description in zephyr_dp_schedule.c

Signed-off-by: Marcin Szkudlinski <marcin.szkudlinski@intel.com>
@lgirdwood lgirdwood merged commit 59bc4a7 into thesofproject:main Sep 27, 2023
41 checks passed
@marcinszkudlinski marcinszkudlinski deleted the dp-edf-upstream branch June 21, 2024 07:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dp_scheduler MTL Applies to Meteor Lake platform pipeline2.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants