s390/fpu: limit save and restore to used registers
authorHeiko Carstens <hca@linux.ibm.com>
Sat, 3 Feb 2024 10:45:18 +0000 (11:45 +0100)
committerHeiko Carstens <hca@linux.ibm.com>
Fri, 16 Feb 2024 13:30:16 +0000 (14:30 +0100)
commit8c09871a950a3fe686e0e27fd4193179c5f74f37
tree55b39ecbbdcb9e43dc3c24b733795f606068637a
parent066c40918bb495de8f2e45bd7eec06737a142712
s390/fpu: limit save and restore to used registers

The first invocation of kernel_fpu_begin() after switching from user to
kernel context will save all vector registers, even if only parts of the
vector registers are used within the kernel fpu context. Given that save
and restore of all vector registers is quite expensive change the current
approach in several ways:

- Instead of saving and restoring all user registers limit this to those
  registers which are actually used within an kernel fpu context.

- On context switch save all remaining user fpu registers, so they can be
  restored when the task is rescheduled.

- Saving user registers within kernel_fpu_begin() is done without disabling
  and enabling interrupts - which also slightly reduces runtime. In worst
  case (e.g. interrupt context uses the same registers) this may lead to
  the situation that registers are saved several times, however the
  assumption is that this will not happen frequently, so that the new
  method is faster in nearly all cases.

- save_user_fpu_regs() can still be called from all contexts and saves all
  (or all remaining) user registers to a tasks ufpu user fpu save area.

Overall this reduces the time required to save and restore the user fpu
context for nearly all cases.

Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
arch/s390/include/asm/entry-common.h
arch/s390/include/asm/fpu.h
arch/s390/include/asm/processor.h
arch/s390/kernel/fpu.c