fix: read mclock64() in os.clock(), not clock64() - #9
Merged
Conversation
libc370 #49 (mvslovers/libc370@f6d1888) changed clock64() to seconds resolution, matching what time64.h had documented all along. os_clock() divides its source by CLOCKS_PER_SEC (1000) to split it into whole seconds plus a millisecond remainder, so it needs a millisecond source. Reading clock64() there now yields a value 1000x too small, and so is every elapsed time derived from it. mclock64() stayed at milliseconds through #49, so switching the single call site restores the previous values. The rest of os_clock() is unchanged; clock64() had exactly one production use in this repo. Nothing catches this at build time: clock64_t and mclock64_t are both plain uint64_t, so the resolution mismatch is silent and the module still compiles, links and runs. os.date, os.time and os.difftime are unaffected. #49 moved time64() in the same commit but deliberately kept its value unchanged -- it used to divide clock64()'s milliseconds by CLOCKS_PER_SEC and now returns clock64()'s seconds directly. Refs #8
mgrossmann
force-pushed
the
fix/os-clock-mclock64
branch
from
August 7, 2026 17:16
e24bffc to
2758cce
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #8.
Why
libc370 #49 landed as mvslovers/libc370@f6d1888, changing
clock64()to secondsresolution — the behaviour
time64.h:45had documented all along.os_clock()divides its source byCLOCKS_PER_SEC(1000) to split it into whole secondsplus a millisecond remainder, so it needs a millisecond source. Reading
clock64()there now produces a value 1000x too small. Modelling the exact arithmetic against a real
STCK-derived timestamp:
The build does not catch it.
clock64_tandmclock64_tare both plainuint64_t, sothe resolution mismatch is silent —
os.clock()keeps compiling, linking and returning aplausible-looking number.
lua370 is exposed automatically: mbt's reusable workflows pin cc370 via
inputs.cc370_refbut clone libc370 atmainHEAD with no ref, and the toolchain cachekey embeds that SHA.
What changed
One line, plus the comment above it:
mclock64()stayed at milliseconds through #49.clock64()had exactly one productionuse in this repo, so the rest of
os_clock()is untouched.The comment was rewritten to record why this is deliberately
mclock64(), and its stalecrent370/crent470paths dropped in favour of naming the functions — the originalnote about libc370's
clock()stub being the underlying reason is kept.Verification
loslib.o's external reference goesTM64CLCK→TM64MCLK(decodedfrom the EBCDIC object); confirmed against a rebuild of the unmodified file.
make,make lib,make testall rc=0under
-Wall -Werror.tm64clck.ois byte-identicalto the copy inside the installed
libc.a).Not affected
os.date,os.time,os.difftimeusetime64()/gmtime64_r()/localtime64_r()/mktime64()/difftime64(). #49 movedtime64()in the same commit but deliberatelykept its value unchanged — it used to divide
clock64()'s milliseconds byCLOCKS_PER_SECand now returnsclock64()'s seconds directly. Two cancelling constantswere removed together, so no change is needed here.
Left open (see #8 for detail)
Neither is closed by this PR, and neither is in this diff:
os_clock()still divides a millisecond source byCLOCKS_PER_SEC, correct only whilethat macro is 1000. #49 removed libc370's last reader of it, so this is now effectively
the only place using it as a wall-clock scaler.
os.clock()returns elapsed wall-clock time rather than CPU time as Lua specifies. Theroot cause is libc370's
clock()stub returning-1; once that is implemented for real(TCB /
TIMEUSED),os_clock()should move to the existing#elsebranch.Ref: mvslovers/libc370#49