Skip to content

Commit

Permalink
[erts] Fix monotonicity of Erlang monotonic time
Browse files Browse the repository at this point in the history
When 'no time warp mode' was enabled, a smaller Erlang monotonic time
could be read than a previously read time, i.e., breaking the monotonic
property. The runtime system will abort when detecting an issue like
this since OTP 24.3.4.17 and OTP 25.0.

On systems with a fine grained time unit, the window for this happening
was very small, but still existed. On systems with native nanosecond
time unit, which are most if not all non-Windows systems, two readings
needed to be done within 20 nanoseconds.
  • Loading branch information
rickard-green committed Jun 26, 2024
1 parent 0863bd3 commit fee8f70
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion erts/emulator/beam/erl_time_sup.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,8 @@ calc_corrected_erl_mtime(ErtsMonotonicTime os_mtime,
diff += (cip->correction.drift*diff)/ERTS_MONOTONIC_TIME_UNIT;
erl_mtime = cip->erl_mtime;
erl_mtime += diff;
erl_mtime += cip->correction.error*(diff/ERTS_TCORR_ERR_UNIT);
erl_mtime += (cip->correction.error*diff)/ERTS_TCORR_ERR_UNIT;

if (os_mdiff_p)
*os_mdiff_p = diff;
return erl_mtime;
Expand Down

0 comments on commit fee8f70

Please sign in to comment.