Page MenuHomeFreeBSD

time(1): add an option to use the monotonic clock
ClosedPublic

Authored by asomers on Jan 24 2018, 6:28 PM.
Tags
None
Referenced Files
Unknown Object (File)
Mon, Dec 2, 12:08 PM
Unknown Object (File)
Mon, Dec 2, 4:42 AM
Unknown Object (File)
Nov 22 2024, 4:17 PM
Unknown Object (File)
Nov 22 2024, 1:46 PM
Unknown Object (File)
Oct 14 2024, 10:57 AM
Unknown Object (File)
Oct 8 2024, 2:54 AM
Unknown Object (File)
Oct 2 2024, 3:57 PM
Unknown Object (File)
Oct 1 2024, 6:29 AM
Subscribers

Details

Summary

time(1): add an option to use the monotonic clock

POSIX-compliance requires use of the real-time clock, but we have a non-default
option to use the monotonic clock.

Test Plan

Tested "time sleep 5" with and without -m, while stepping the system
clock forward and backward by one hour.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

usr.bin/time/time.c
303 ↗(On Diff #38403)

This "real" is a little confusing when used with -m. It probably should've said "elapsed" from the very beginning. But I can't change it now without breaking tons of awk scripts. I thought it would be stupid to conditionally change it to "monotonic", because that word doesn't describe what you're measuring (elapsed time), but how you're measuring it. So I left it as is. We should all just think "elapsed" when we see "real" here.

Hmm, it is remarkable to see this after the monotonic clock has existed for so long. Also, GNU time and mksh's keyword appear to use CLOCK_REALTIME without configurability.

I'm not sure preserving the letter of POSIX is important enough to add this option. time is not meant as a high-accuracy benchmarking tool with portable results. Also, relative time services with CLOCK_REALTIME like nanosleep() are not supposed to be affected by clock jumps (but they are affected by speedup/slowdown such as from ntp_adjtime(2)). So changing the clock used by time to CLOCK_MONOTONIC without configurability may be an option as well.

Note that various shells (but not our sh) have a time keyword, which allows timing builtins, pipelines and functions. This keyword tends not to support any options and uses a different implementation. Depending on the shell, some form of quoting or env may or may not be required to call the external time with options.

Remove the -m option and use the monontonic clock unconditionaly

This looks good. I think jilles is right, implementing it with CLOCK_MONOTONIC by default may be better than making it optional. Most people won't look at the man page, and this gives it more of a "do what I mean" behavior.

You might want to run it by bde and see what he thinks about it.

This revision is now accepted and ready to land.Apr 17 2018, 3:41 PM
This revision was automatically updated to reflect the committed changes.