![]() |
|
|||
0001 /* SPDX-License-Identifier: GPL-2.0 */ 0002 #ifndef _ASM_X86_FPU_SCHED_H 0003 #define _ASM_X86_FPU_SCHED_H 0004 0005 #include <linux/sched.h> 0006 0007 #include <asm/cpufeature.h> 0008 #include <asm/fpu/types.h> 0009 0010 #include <asm/trace/fpu.h> 0011 0012 extern void save_fpregs_to_fpstate(struct fpu *fpu); 0013 extern void fpu__drop(struct fpu *fpu); 0014 extern int fpu_clone(struct task_struct *dst, unsigned long clone_flags, bool minimal); 0015 extern void fpu_flush_thread(void); 0016 0017 /* 0018 * FPU state switching for scheduling. 0019 * 0020 * This is a two-stage process: 0021 * 0022 * - switch_fpu_prepare() saves the old state. 0023 * This is done within the context of the old process. 0024 * 0025 * - switch_fpu_finish() sets TIF_NEED_FPU_LOAD; the floating point state 0026 * will get loaded on return to userspace, or when the kernel needs it. 0027 * 0028 * If TIF_NEED_FPU_LOAD is cleared then the CPU's FPU registers 0029 * are saved in the current thread's FPU register state. 0030 * 0031 * If TIF_NEED_FPU_LOAD is set then CPU's FPU registers may not 0032 * hold current()'s FPU registers. It is required to load the 0033 * registers before returning to userland or using the content 0034 * otherwise. 0035 * 0036 * The FPU context is only stored/restored for a user task and 0037 * PF_KTHREAD is used to distinguish between kernel and user threads. 0038 */ 0039 static inline void switch_fpu_prepare(struct fpu *old_fpu, int cpu) 0040 { 0041 if (cpu_feature_enabled(X86_FEATURE_FPU) && 0042 !(current->flags & PF_KTHREAD)) { 0043 save_fpregs_to_fpstate(old_fpu); 0044 /* 0045 * The save operation preserved register state, so the 0046 * fpu_fpregs_owner_ctx is still @old_fpu. Store the 0047 * current CPU number in @old_fpu, so the next return 0048 * to user space can avoid the FPU register restore 0049 * when is returns on the same CPU and still owns the 0050 * context. 0051 */ 0052 old_fpu->last_cpu = cpu; 0053 0054 trace_x86_fpu_regs_deactivated(old_fpu); 0055 } 0056 } 0057 0058 /* 0059 * Delay loading of the complete FPU state until the return to userland. 0060 * PKRU is handled separately. 0061 */ 0062 static inline void switch_fpu_finish(void) 0063 { 0064 if (cpu_feature_enabled(X86_FEATURE_FPU)) 0065 set_thread_flag(TIF_NEED_FPU_LOAD); 0066 } 0067 0068 #endif /* _ASM_X86_FPU_SCHED_H */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |