Page MenuHomeFreeBSD

Trim duplicate CSR swaps from user exceptions.
ClosedPublic

Authored by jhb on Jan 28 2020, 11:18 AM.
Tags
None
Referenced Files
Unknown Object (File)
Oct 7 2024, 4:58 PM
Unknown Object (File)
Oct 4 2024, 6:29 AM
Unknown Object (File)
Sep 21 2024, 5:50 AM
Unknown Object (File)
Sep 20 2024, 6:38 AM
Unknown Object (File)
Sep 17 2024, 9:50 AM
Unknown Object (File)
Sep 8 2024, 7:57 PM
Unknown Object (File)
Sep 8 2024, 9:20 AM
Unknown Object (File)
Sep 7 2024, 12:34 PM
Subscribers

Details

Summary

The stack pointer is swapped with the sscratch CSR just before the
jump to cpu_exception_handler_user where the first instruction swaps
it again. The two swaps together are a no-op, but the csr swap
instructions can be expensive (e.g. on Bluespec RISC-V cores csr swap
instructions force a full pipeline stall).

Test Plan
  • booted in qemu

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

This revision is now accepted and ready to land.Jan 28 2020, 11:39 AM
sys/riscv/riscv/exception.S
209 ↗(On Diff #67394)

So we check that the sscratch register is empty as a means of determining which mode we came from?

I think this would be better as a check of the SPP bit in sstatus, because it looks like you could eliminate another double sscratch swap in the supervisor case.

sys/riscv/riscv/exception.S
209 ↗(On Diff #67394)

Yes, checking sscratch in this way is pretty typical. You can't check sstatus because you haven't yet saved any GPRs anywhere, so you can't do a 'csrr` to get the value of sstatus and check it. The scheme is that the kernel clears sscratch so that nested kernel exceptions see a 0 value. bbl does the same thing with mscratch FWIW, and I suspect it's probably what Linux does as well. There aren't really any other options when you only have the single scratch register.

This revision was automatically updated to reflect the committed changes.