Files
geramyloveless 41aceb6fe0 linuxu: per-task per-CPU variables and kernel FPU sections
Linux gives a task exclusive use of its CPU's per-CPU copy between
preempt_disable() and preempt_enable(). linuxu threads all run as CPU 0
concurrently and preemption control excludes nobody, so one shared copy
would be raced. linux/percpu.h therefore keeps per-CPU variables per
task: the first this_cpu_*() access copies the definition's initial
value into storage owned by the task (released by put_task_struct()),
which is exactly what a pinned task observes on Linux. per_cpu() names
the boot copy; no built source inspects other CPUs' copies.

linux/fpu.h provides kernel_fpu_available()/kernel_fpu_begin()/end().
In a process the FP/SIMD registers belong to the running thread and the
OS preserves them across switches, so nothing is saved; the section is
tracked per task and nesting or an unbalanced end warns as on Linux.
This is what Display Core's dc_fpu.c (DC_FP_START/END and its per-CPU
recursion depth) runs on.

scripts/test-percpu-fpu.sh checks per-thread isolation of the copies,
initial values, the boot copy and the dc_fpu depth pattern under
ASan/UBSan.
2026-10-02 20:56:19 -07:00

28 lines
958 B
C

/* linuxu: SHIM (third_party/linux/include/linux/fpu.h -> asm/fpu.h)
*
* Kernel FPU sections. Linux brackets FP/SIMD use in kernel code with
* kernel_fpu_begin()/kernel_fpu_end() because the kernel does not own the
* FP register file; the section saves the user state, disables preemption
* and must not nest. linuxu code runs in an ordinary process, where the
* FP/SIMD registers always belong to the running thread and the OS
* preserves them across context switches, so no state is saved. The
* section is still tracked per task (linux/percpu.h) so a nested begin or
* an unbalanced end is reported as Linux would.
*/
#ifndef _LINUX_FPU_H
#define _LINUX_FPU_H
#include <linux/types.h>
static inline bool kernel_fpu_available(void)
{
return true;
}
void kernel_fpu_begin(void);
void kernel_fpu_end(void);
/* True between kernel_fpu_begin() and kernel_fpu_end() on this task. */
bool linuxu_kernel_fpu_active(void);
#endif /* _LINUX_FPU_H */