Page MenuHomeFreeBSD

Implement GET_STACK_USAGE on remaining archs
ClosedPublic

Authored by mhorne on Oct 20 2021, 3:14 PM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, Dec 4, 1:16 AM
Unknown Object (File)
Mon, Nov 25, 12:16 PM
Unknown Object (File)
Nov 14 2024, 1:23 PM
Unknown Object (File)
Nov 8 2024, 12:25 PM
Unknown Object (File)
Nov 8 2024, 7:02 AM
Unknown Object (File)
Nov 8 2024, 6:40 AM
Unknown Object (File)
Oct 22 2024, 7:03 PM
Unknown Object (File)
Oct 20 2024, 9:08 AM

Details

Summary

This definition enables callers to estimate remaining space on the
kstack, and take action on it. Notably, it enables optimizations in the
GEOM and netgraph subsystems to directly dispatch work items when there
is sufficient stack space, rather than queuing them for a worker thread.

Implement it for riscv, arm, and mips. Remove the #ifdefs, so it will
not go unimplemented elsewhere. As with 6514b4f06180, we exclude
sizeof(pcb) from the usable total, as it is allocated from the bottom of
the kstack on these architectures.

Test Plan

Tested on riscv to verify that direct dispatch of BIOs works as intended. Tested as it relates to PR 259157, where GET_STACK_USAGE mitigates a panic in a netgraph test.

Compiled on arm and mips.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

mhorne added a subscriber: trasz.

I am not sure what can I add to this review.

But note that i386 GET_STACK_USAGE() is completely wrong. It does not account neither for pcb nor for the FPU save area, both allocated on the top of the stack.
Since I moved first pcb, then FPU save area from the amd64 stack, suddenly amd64 version appeared to be sane.

In D32580#735395, @kib wrote:

It does not account neither for pcb nor for the FPU save area, both allocated on the top of the stack.

Sure that should be improved, but since free space thresholds in GEOM and Netgraph are set quite safe (50% and 25%), previous code also worked acceptably.

This revision is now accepted and ready to land.Oct 20 2021, 8:45 PM

Oh, I'm impressed that this fixes the "intended break" triggered by the netgraph test.
Please go ahead!

Have used take the pcb into account as well, as otherwise it could exceed the total as the stack approaches its limit. Simplify the calculation of used by using total.

This revision now requires review to proceed.Nov 24 2021, 8:15 PM
This revision is now accepted and ready to land.Nov 24 2021, 9:15 PM
This revision was automatically updated to reflect the committed changes.