MLK-14308 ARM: imx: fix race condition of multi-cores low power idle on i.mx7d
authorAnson Huang <Anson.Huang@nxp.com>
Thu, 2 Mar 2017 09:39:12 +0000 (17:39 +0800)
committerNitin Garg <nitin.garg@nxp.com>
Mon, 19 Mar 2018 20:21:57 +0000 (15:21 -0500)
commit51e260ead3dc2d7d51126ff3740043b15a5fd98a
tree60cb948cae83eb739690f105b5437ed95f1d691f
parent5315db4dc4f6dcedf421624f76f34fc7f2242bff
MLK-14308 ARM: imx: fix race condition of multi-cores low power idle on i.mx7d

On i.MX7D low power idle, consider below scenario which has
race condition that low power idle is entered unexpectedly
for first CPU:

CPU#1 enters low power idle:
1. set last_cpu to invalid -1;
2. set cpu1_wfi in low level ASM code;
3. enter WFI;
CPU#0 enters low power idle:
4. set last_cpu to CPU#0;
5. Set hardware(DDR, CCM, ANATOP) to low power idle mode;
6. enter WFI;

If during 4~6 window, CPU#1 go out of WFI and then go into low
power idle again, the condition check of master_lpi will be true
and CPU#1 will go through 4~6 steps in low level ASM code,
which is unexpected. As cpu_cluster_pm_enter/exit can only be called
once for last cpu in same cluster.

To avoid this race condition, add last_cpu check as well as master_lpi
check, that means if last_cpu is a valid value, the other CPU entering
low power idle will be treated as first CPU. And also move the setting
of last_cpu to invalid value to last CPU low power idle exit path.

Signed-off-by: Anson Huang <Anson.Huang@nxp.com>
arch/arm/mach-imx/cpuidle-imx7d.c