Repository navigation
feat(libkernel): answer kern.boottime in sysctl and sysctlbyname - #9794
Conversation
|
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
MarcZX10
left a comment
There was a problem hiding this comment.
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_tests successfully. 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 Linux CLOCK_MONOTONIC for 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 with main. Please sync it, resolve any conflicts, and provide the Linux focused-test result before merge.
MarcZX10
left a comment
There was a problem hiding this comment.
I reviewed the current exact head b95092a431d60c2688335c3b75bfb1f3c8e43b32. Conventions and git diff --check pass, and the merge tree with current main is 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 current main (11f976b27c16ed91633f00039dba5dfd97dd7cc1), and the PR still reports no Linux test. That matters for this implementation because BootTime() computes realtime minus guest CLOCK_UPTIME, while the existing Linux clock mapping uses CLOCK_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.
FreeBSD 11.4 serves kern.boottime ({CTL_KERN, KERN_BOOTTIME}) from
sysctl_kern_boottime in sys/kern/kern_tc.c as a read-only 16-byte struct
timeval, so a size query reports 16, a short buffer gets a partial copy
and ENOMEM, and a write gets EPERM from sysctl_root. sysctl, sysctlbyname
and sysctlnametomib now answer it with the guest CLOCK_REALTIME minus
CLOCK_UPTIME, taken at the first read and kept. HotSpot reads it while
writing its error report, which aborted with "unsupported MIB 1.21".
b95092a to
124dc3b
Compare
|
@MarcZX10 Thanks. Rebased onto On To make that checkable on every host, |
|
Linux run of head Setup: CachyOS, kernel 7.3.0-4, GCC 16.2.1, glibc 2.44, CMake 4.4.3, Ninja,
No title or console run. AI-assisted: yes (Claude Code). |
Dismissing a stale review: the requested changes were addressed after it (new head and/or updated description with the asked-for runs) and the merge queue blocks on it. Please request changes again if anything is still open.
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 onmain11f976b.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.CLOCK_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)