Skip to content

Fix clock change in waiti for multicore access - #3113

Merged
lgirdwood merged 6 commits into
thesofproject:masterfrom
ktrzcinx:fix-clock-change-in-waiti
Jul 9, 2020
Merged

lgirdwood merged 6 commits into
thesofproject:masterfrom
ktrzcinx:fix-clock-change-in-waiti

Conversation

@ktrzcinx

@ktrzcinx ktrzcinx commented Jun 30, 2020 •

Copy link
Copy Markdown
Member

There was race condition in situation with multicore environment:

  1. One core saves active current_freq_idx to active_freq_idx (HPRO) and then change current_freq_idx to LPRO
  2. Another core saves active current_freq_idx to active_freq_idx (LPRO) and then change current_freq_idx to LPRO
  3. After wake-up system restore active_freq_idx - LPRO instead HPRO

Moreover sleep_core_mask must be introduced because in a case with multiple cores connected to single clock source, then clock rate may be reduced only when each of them is in wait state.

@ktrzcinx
ktrzcinx force-pushed the fix-clock-change-in-waiti branch 4 times, most recently from ea2f1fc to 8f93ad4 Compare June 30, 2020 08:13
@ktrzcinx ktrzcinx changed the title Fix clock change in waiti [WIP] Fix clock change in waiti Jun 30, 2020
Comment thread src/platform/intel/cavs/lib/clk.c Resolved
Comment thread src/platform/intel/cavs/lib/clk.c Resolved
Comment thread src/platform/intel/cavs/lib/clk.c Resolved
@ktrzcinx
ktrzcinx force-pushed the fix-clock-change-in-waiti branch 2 times, most recently from 1e15c0b to 0f792e2 Compare June 30, 2020 13:53
@ktrzcinx ktrzcinx changed the title [WIP] Fix clock change in waiti Fix clock change in waiti Jun 30, 2020
Comment thread src/platform/intel/cavs/lib/clk.c Resolved
@ktrzcinx
ktrzcinx force-pushed the fix-clock-change-in-waiti branch 2 times, most recently from b7e55b3 to 3af0bd4 Compare July 1, 2020 09:54
@mmaka1

mmaka1 commented Jul 1, 2020

Copy link
Copy Markdown

@ktrzcinx Some checkpatch issues regarding typos and comment misalignment are valid.

@mmaka1 mmaka1 changed the title Fix clock change in waiti Fix clock change in waiti for multicore access Jul 1, 2020
@ktrzcinx
ktrzcinx force-pushed the fix-clock-change-in-waiti branch from 3af0bd4 to 9767f55 Compare July 1, 2020 11:26
Comment thread src/platform/intel/cavs/lib/clk.c Resolved
Comment thread src/arch/xtensa/include/arch/atomic.h Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should return the old value not the new value. See https://gcc.gnu.org/onlinedocs/gcc-4.1.1/gcc/Atomic-Builtins.html. This also needs fixed in atomic_add and atomic_dec.

@ktrzcinx ktrzcinx Jul 8, 2020 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@lgirdwood updated in #3151

Comment thread src/platform/intel/cavs/lib/clk.c Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is really runtime PM.

pm_runtime_get(PM_HP_CLOCK, cpu_get_id());

Which nicely abstracts the clocking PM. Likewise

pm_runtime_put(PM_HP_CLOCK, cpu_get_id());

will cjheck if mask is 0 and switch off HP clock.

@ktrzcinx ktrzcinx Jul 7, 2020 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

But to maintain this from pm_runtime, I will need to change clock API (set_freq() will need new parameter defining if clock change is temporary or persistent implementation dedicated function for temporary clock frequency reduction - clock_low_power_mode())

@mmaka1 mmaka1 mentioned this pull request Jul 7, 2020
@ktrzcinx
ktrzcinx force-pushed the fix-clock-change-in-waiti branch from 9767f55 to db2a7a9 Compare July 8, 2020 09:23
@ktrzcinx
ktrzcinx requested review from libinyang and mrajwa as code owners July 8, 2020 09:23
@ktrzcinx
ktrzcinx force-pushed the fix-clock-change-in-waiti branch from db2a7a9 to 8aae9f5 Compare July 8, 2020 10:10
@ktrzcinx
ktrzcinx force-pushed the fix-clock-change-in-waiti branch 3 times, most recently from b1edc00 to d568160 Compare July 8, 2020 10:38
In situation with two or more active cores, saving active frequency
index in platform_clock_on_waiti suffer from race condition.
Changing state in *set_cpu_freq() method is much more safe.

Signed-off-by: Karol Trzcinski <karolx.trzcinski@linux.intel.com>
@mmaka1 mmaka1 mentioned this pull request Jul 8, 2020
@lgirdwood

Copy link
Copy Markdown
Member

Blocking on #3151.

@ktrzcinx

ktrzcinx commented Jul 8, 2020

Copy link
Copy Markdown
Member Author

Blocking on #3151.

Actually already there are spin_lock used instead of atomic_or/and so #3151 is not related with this one

@lgirdwood lgirdwood left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Are we missing the atomic OR / AND ? or are these no longer needed ?

Comment thread src/platform/intel/cavs/lib/clk.c Resolved
Comment thread src/include/sof/lib/clk.h Resolved
Comment thread src/platform/baytrail/lib/clk.c Resolved
Comment thread src/lib/clk.c Resolved
Comment thread src/include/sof/lib/pm_runtime.h Resolved
@ktrzcinx

ktrzcinx commented Jul 8, 2020

Copy link
Copy Markdown
Member Author

Are we missing the atomic OR / AND ? or are these no longer needed ?

OR / AND operations are already inside spin_lock / unlock block, so I guess that there atomic operations are not needed (but it wouldn't be also not an error to use it)

ktrzcinx added 5 commits July 8, 2020 16:12
It was needed to call two functions and update one global variable
to change clock frequency, what is quite error prone solution.
After merging it to one function, it is easier to keep clock description
synchronized.

Signed-off-by: Karol Trzcinski <karolx.trzcinski@linux.intel.com>
Set bit for PLATFORM_MASTER_CORE_ID and remove exception
handlind from arch_cpu_is_core_enabled.

Signed-off-by: Karol Trzcinski <karolx.trzcinski@linux.intel.com>
Core enable/disable is related with power management and maintenance
of clock trees, so such an mask should be possible to read.

Signed-off-by: Karol Trzcinski <karolx.trzcinski@linux.intel.com>
This function will be called from power manager to change current
clock value for sleep time.
Detailed implemnentation may be clock instance dependednt.

Signed-off-by: Karol Trzcinski <karolx.trzcinski@linux.intel.com>
Clock manegement is important part for power consumption optimization,
what is a task of this module.

Signed-off-by: Karol Trzcinski <karolx.trzcinski@linux.intel.com>
@ktrzcinx
ktrzcinx force-pushed the fix-clock-change-in-waiti branch from d568160 to 50b9cc4 Compare July 8, 2020 14:13
@lgirdwood

Copy link
Copy Markdown
Member

CI jenkins known issues.

@lgirdwood
lgirdwood merged commit 447359f into thesofproject:master Jul 9, 2020
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.

3 participants