diff mbox

[v1] arm64: fix bug for reloading FPSIMD state after cpu power off

Message ID 1409463591-661-1-git-send-email-leoy@marvell.com (mailing list archive)
State New, archived
Headers show

Commit Message

Leo Yan Aug. 31, 2014, 5:39 a.m. UTC
Now arm64 defers reloading FPSIMD state, but this optimization also
introduces the bug after cpu resume back from low power mode.

The reason is after the cpu has been powered off, s/w need set the
cpu's fpsimd_last_state to NULL so that it will force to reload
FPSIMD state for the thread, otherwise there has the chance to meet
the condition for both the task's fpsimd_state.cpu field contains the
id of the current cpu, and the cpu's fpsimd_last_state per-cpu variable
points to the task's fpsimd_state, so finally kernel will skip to reload
the context during it return back to userland.

Furthermore, this patch also removes the redundant operation for saving
the state for idle thread; this operation is needless due kernel's idle
thread will not use any VFP/NEON instruction. so that this also can
benefit a bit for the latency during cpu's power off.

Signed-off-by: Leo Yan <leoy@marvell.com>
---
 arch/arm64/kernel/fpsimd.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

Comments

Catalin Marinas Aug. 31, 2014, 10:11 p.m. UTC | #1
On 31 Aug 2014, at 06:39, Leo Yan <leoy@marvell.com> wrote:
> Now arm64 defers reloading FPSIMD state, but this optimization also
> introduces the bug after cpu resume back from low power mode.

You are right, I can see a bug here.

> diff --git a/arch/arm64/kernel/fpsimd.c b/arch/arm64/kernel/fpsimd.c
> index ad8aebb..4caef93 100644
> --- a/arch/arm64/kernel/fpsimd.c
> +++ b/arch/arm64/kernel/fpsimd.c
> @@ -268,13 +268,9 @@ static int fpsimd_cpu_pm_notifier(struct notifier_block *self,
> {
> 	switch (cmd) {
> 	case CPU_PM_ENTER:
> -		if (current->mm && !test_thread_flag(TIF_FOREIGN_FPSTATE))
> -			fpsimd_save_state(&current->thread.fpsimd_state);

That’s needed if we enter a low power state directly from a task with
a valid mm (user). I’m not sure that’s possible, but just in case.

> +		this_cpu_write(fpsimd_last_state, NULL);

That’s correct. In most cases, we enter low power state from the idle
thread which does not have an mm, so the CPU_PM_EXIT case wouldn’t set
a TIF_FOREIGN_FPSTATE, so thread switching would not detect the change.

> 		break;
> 	case CPU_PM_EXIT:
> -		if (current->mm)
> -			set_thread_flag(TIF_FOREIGN_FPSTATE);

See above for why this may still be needed (it case it returns to user
directly without fpsimd_thread_switch() to detect fpsimd_last_state).

Catalin
Leo Yan Sept. 1, 2014, 1:47 a.m. UTC | #2
On 09/01/2014 06:11 AM, Catalin Marinas wrote:
> On 31 Aug 2014, at 06:39, Leo Yan <leoy@marvell.com> wrote:
>> Now arm64 defers reloading FPSIMD state, but this optimization also
>> introduces the bug after cpu resume back from low power mode.
>
> You are right, I can see a bug here.
>
>> diff --git a/arch/arm64/kernel/fpsimd.c b/arch/arm64/kernel/fpsimd.c
>> index ad8aebb..4caef93 100644
>> --- a/arch/arm64/kernel/fpsimd.c
>> +++ b/arch/arm64/kernel/fpsimd.c
>> @@ -268,13 +268,9 @@ static int fpsimd_cpu_pm_notifier(struct notifier_block *self,
>> {
>> 	switch (cmd) {
>> 	case CPU_PM_ENTER:
>> -		if (current->mm && !test_thread_flag(TIF_FOREIGN_FPSTATE))
>> -			fpsimd_save_state(&current->thread.fpsimd_state);
>
> That’s needed if we enter a low power state directly from a task with
> a valid mm (user). I’m not sure that’s possible, but just in case.

u are right, in some special cases (such like IKS, etc) a normal thread 
also may call cpu_suspend() function so that it will run here; i will 
commit another patch to reserve this part.

>> +		this_cpu_write(fpsimd_last_state, NULL);
>
> That’s correct. In most cases, we enter low power state from the idle
> thread which does not have an mm, so the CPU_PM_EXIT case wouldn’t set
> a TIF_FOREIGN_FPSTATE, so thread switching would not detect the change.
>
>> 		break;
>> 	case CPU_PM_EXIT:
>> -		if (current->mm)
>> -			set_thread_flag(TIF_FOREIGN_FPSTATE);
>
> See above for why this may still be needed (it case it returns to user
> directly without fpsimd_thread_switch() to detect fpsimd_last_state).

Will reserve this part as well.

Thanks,
Leo Yan
diff mbox

Patch

diff --git a/arch/arm64/kernel/fpsimd.c b/arch/arm64/kernel/fpsimd.c
index ad8aebb..4caef93 100644
--- a/arch/arm64/kernel/fpsimd.c
+++ b/arch/arm64/kernel/fpsimd.c
@@ -268,13 +268,9 @@  static int fpsimd_cpu_pm_notifier(struct notifier_block *self,
 {
 	switch (cmd) {
 	case CPU_PM_ENTER:
-		if (current->mm && !test_thread_flag(TIF_FOREIGN_FPSTATE))
-			fpsimd_save_state(&current->thread.fpsimd_state);
+		this_cpu_write(fpsimd_last_state, NULL);
 		break;
 	case CPU_PM_EXIT:
-		if (current->mm)
-			set_thread_flag(TIF_FOREIGN_FPSTATE);
-		break;
 	case CPU_PM_ENTER_FAILED:
 	default:
 		return NOTIFY_DONE;