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)
Sun, Apr 14, 5:43 PM
Unknown Object (File)
Sun, Apr 7, 11:09 AM
Unknown Object (File)
Mon, Apr 1, 4:05 AM
Unknown Object (File)
Jan 25 2024, 5:19 AM
Unknown Object (File)
Jan 13 2024, 12:46 AM
Unknown Object (File)
Dec 12 2023, 10:33 AM
Unknown Object (File)
Nov 15 2023, 5:58 PM
Unknown Object (File)
Nov 6 2023, 1:24 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.