1 Commits
Author SHA1 Message Date
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