Page MenuHomeFreeBSD

thread0: Clear td_rux stats in proc0_post
ClosedPublic

Authored by jhb on Dec 2 2025, 10:44 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Jan 3, 1:31 PM
Unknown Object (File)
Wed, Dec 31, 1:14 PM
Unknown Object (File)
Sat, Dec 27, 10:01 PM
Unknown Object (File)
Sat, Dec 27, 7:43 AM
Unknown Object (File)
Sat, Dec 27, 7:43 AM
Unknown Object (File)
Sat, Dec 27, 7:43 AM
Unknown Object (File)
Sat, Dec 27, 7:43 AM
Unknown Object (File)
Sat, Dec 27, 7:43 AM
Subscribers

Details

Summary

proc0_post aims to reset the CPU usage accounting for all threads and
processes in the system to zero once the time of day is verified.
However, the per-thread stats were not being cleared, resulting in
over-reported time for thread0 post-boot.

Fixes: bed4c5241663 ("Implement RUSAGE_THREAD. Add td_rux...")

Diff Detail

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

Event Timeline

jhb requested review of this revision.Dec 2 2025, 10:44 PM
markj added inline comments.
sys/kern/init_main.c
663

This comment is somewhat misleading.

This revision is now accepted and ready to land.Dec 2 2025, 11:14 PM
kib added inline comments.
sys/kern/init_main.c
667

Don't we need both process stat spinlock (already taken) and thread lock to safely modify td_rux?

sys/kern/init_main.c
666–671

The reset to 0 could be factored out in a new ruxreset_locked() function taking a pointer to a struct rusage_ext, allowing to replace both these assignments and those before the loop by function calls.

667

Don't we need both process stat spinlock (already taken) and thread lock to safely modify td_rux?

Yes.

sys/kern/init_main.c
663

I almost removed it, but rufetch() does clear some other thread stats (td_[usi]ticks for example).

666–671

Except it's not a full reset. Maybe we should also be clearing rux_[ust]u as well? They are probably zero since nothing can query them this early in practice.

667

Mmm, yes.

sys/kern/init_main.c
666–671

That seems to make more sense yes, these fields are somewhat related, in particular having rux_runtime reset to 0 and non-zero values for rux_[ust]u is inconsistent.

This revision now requires review to proceed.Dec 3 2025, 4:31 PM
This revision is now accepted and ready to land.Dec 3 2025, 4:47 PM
This revision was automatically updated to reflect the committed changes.