feat(libkernel): answer kern.boottime in sysctl and sysctlbyname #9794
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9794"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by Retr0G28 on 2026-10-22T15:28:02Z.
What
sysctlthrewunsupported MIB 1.21forkern.boottime({CTL_KERN,KERN_BOOTTIME}), andsysctlbynameandsysctlnametomibthrew for the name. In #9683, Java 25 File I/O (PPSA99866) reads it from HotSpot'sos::print_os_infowhile it writes itshs_errreport, and the process aborts at that point instead of writing the report. #9684 fixes the stack-guard error that led to the report in that thread. Any other VM error goes through the same report code, so this is still needed with #9684.FreeBSD 11.4 declares the node in
sys/kern/kern_tc.casSYSCTL_PROC(_kern, KERN_BOOTTIME, boottime, CTLTYPE_STRUCT|CTLFLAG_RD, ...). Its handler,sysctl_kern_boottime, returns a 16-bytestruct timevalfromgetboottimethroughSYSCTL_OUT. Insys/kern/kern_sysctl.c,sysctl_rootreturnsEPERMfor a write to a node withoutCTLFLAG_WR.sysctl_old_usercopies as much as fits and returnsENOMEMwhen the buffer is short, anduserland_sysctlsets the length to what was copied. A size query reports 16.getboottimestays fixed unless the clock is stepped.sysctl{1, 21},sysctlbyname("kern.boottime")andsysctlnametomib("kern.boottime")now answer the node. The value is the guestCLOCK_REALTIMEminus the guestCLOCK_UPTIME, both read throughclock_gettime, so boot time plus uptime matches the current time. It is computed at the first read and then kept. Size queries, short buffers and writes go through the sameCopyOutandEPERMpaths as the other read-only nodes in the file. A MIB with a component after {1, 21} returnsENOTDIRlike the other leaves. A new entry indocs/dev/debt/libkernel.mdcovers what is left open. A later step of the host clock does not move the value, and the value a PS5 title gets has not been measured.Test changes in
guest_system_configuration:CheckBootTimeSysctl. A size query reports 16 by MIB and by name. A read gives0 < tv_sec <= time(nullptr)and0 <= tv_usec < 1000000, and the value plusclock_gettime(CLOCK_UPTIME)is within one second ofclock_gettime(CLOCK_REALTIME). Two reads agree, and the name read agrees with the MIB read.sysctlnametomibgives {1, 21}. An 8-byte buffer gets a length of 8 andENOMEMwith the bytes after it untouched, by MIB and by name, and the MIB read fills it withtv_sec. A write returnsEPERM, by MIB and by name.CheckLeafWithTrailingComponentandkern.boottimetoCheckNameToMib.Tested
Windows 11, WinLibs MinGW-w64 GCC 15.2.0 r7, CMake + Ninja, Release,
-DBUILD_TESTING=ON, rebased onmain11f976b27c.guest_system_configurationwith the new test fails withterminate called after throwing an instance of 'std::runtime_error',what(): sysctl_nid_postfix: unsupported MIB 1.21(exit 0xc0000409). With this PR it passes.LastBootUpTime1792468899 (Win32_OperatingSystem).guest_system_configuration,guest_getrlimit,guest_software_version,guest_thread_sanitizer,guest_hostname,guest_freebsd_clocks,guest_cpu_time_clocks,guest_process_time,guest_process_time_scaled,guest_process_time_counter,guest_process_time_counter_scaledandguest_time_extras. All 12 pass.11f976b27c, with theCLOCK_UPTIMEcheck added after review,guest_system_configurationpasses. With the implementation changed to subtract only half the uptime, it fails at that check (exit 0xc0000409).python tools/check_conventions.py --base origin/mainreports no errors.CLOCK_UPTIMEreads the hostCLOCK_MONOTONIC, so the value is the host's boot time moved later by any time spent suspended. That keepskern.boottime+CLOCK_UPTIME=CLOCK_REALTIME, which is how FreeBSD defines it (tc_setclocksetsboottimebinto the real time minusbinuptime), and the new check tests that relation on every host.Overlap:
tools/pr_overlap.pyreports no shared lines with the PRs it could compare. It could not compare #8553 or #6044, and some PRs that touch only other lines ofdocs/dev/debt/libkernel.md. None of the open PRs that editSystemConfiguration.cpp(#8910 unknown names, #9736kern.proc.env, #8553 MIB mappings) implementskern.boottime. #8910 returnsENOENTfor unknown names but still throws for an unknown MIB such as {1, 21}. Textual conflicts are possible:kern.rng_pseudoin theCheckNameToMibtable, next to the line this PR adds.sysctl_nid_postfixand a call inmain()a few lines from this PR's additions.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T16:21:57Z.
Review: DISMISSED
The source changes and added MIB/name tests look consistent with the existing sysctl paths. I configured the exact PR head and built
guest_system_configuration_testssuccessfully. The focused CTest could not execute: libkernel stops at its documented host CPU gate because this Xeon E5-1620 v2 lacks LZCNT, BMI1, BMI2, MOVBE and AVX2. The PR reports Windows 11 tests passing, while Linux behavior remains untested; the new value uses LinuxCLOCK_MONOTONICfor guest uptime, so please confirm the focused test on a supported Linux host. Hosted checks currently cover eligibility, conventions, intake, labels and report; full product builds were skipped.The branch is eight commits behind current
main(8499ea52e571b0edfc1feecfd3f6b9944012b359). CONTRIBUTING.md requires branches to be based on and kept up to date withmain. Please sync it, resolve any conflicts, and provide the Linux focused-test result before merge.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T16:55:21Z.
Review: COMMENTED
I reviewed the current exact head
b95092a431d60c2688335c3b75bfb1f3c8e43b32. Conventions andgit diff --checkpass, and the merge tree with currentmainis clean. The new tests cover MIB and name lookup, cached value, size query, short buffers, writes and leaf handling. The reported Windows runs are contributor-reported; hosted product jobs are skipped. The branch remains 21 commits behind currentmain(11f976b27c16ed91633f00039dba5dfd97dd7cc1), and the PR still reports no Linux test. That matters for this implementation becauseBootTime()computes realtime minus guestCLOCK_UPTIME, while the existing Linux clock mapping usesCLOCK_MONOTONIC; please rebase and provide the focused Linux test result before merge. I could not rerun the libkernel test locally because this VM’s CPU lacks the required feature set.