Page MenuHomeFreeBSD

riscv cpu_fork(), saving fpe state
Needs ReviewPublic

Authored by jsihv_gmx.com on Tue, Nov 18, 3:18 PM.
Tags
Referenced Files
F137280996: D53804.id166678.diff
Sat, Nov 22, 12:47 AM
F137279174: D53804.id.diff
Sat, Nov 22, 12:33 AM
F137279109: D53804.diff
Sat, Nov 22, 12:32 AM
Unknown Object (File)
Thu, Nov 20, 1:26 PM
Unknown Object (File)
Thu, Nov 20, 1:25 PM
Unknown Object (File)
Thu, Nov 20, 1:17 PM
Unknown Object (File)
Thu, Nov 20, 3:12 AM
Unknown Object (File)
Thu, Nov 20, 1:26 AM
Subscribers

Details

Reviewers
br
Summary

This is an attempt to replace TODO in riscv's cpu_fork(). The code updates the floating point state before it proceeds copying the pcb struct.

pcb_fp_started flag is used as a condition as in a corresponding arm64 code and eg. in riscv's exec_machdep.c:fill_fpregs(). It indicates that fp is in use. I have verified with a debug code that when PCB_FP_STARTED is off, pcb_x registers are always zero.

A corresponding function in arm64 has a condition (td1 == curthread) for saving the fp state (and amd64 has it in MPASS).
arm64 added this condition here: https://github.com/freebsd/freebsd-src/commit/2db317ca8577a0b208ecae38ecfa4a8a690a0fa8
However, so far I have not found out in which kind of situation td1 might not be curthread. I've put a such condition (td1 != curthread) to my debug code in order to see if this condition is ever true but after booting and making some forking as a user, the condition has not ever been true. I also asked about it on our IRC channel and nobody seemed to know what's the meaning of this condition. So I have not included this condition here.

critical_enter() and critical_exit() are used here similarly as arm64 and amd64 use it in corresponding places to prevent a thread being preempted when thread's state is being saved.

fpe_state_save() leads to an assembly code in swtch.S which contains instructions which are equivalent to fpe_enable() and fpe_disable() and these calls are therefore not used here.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped