Artifacts Associated With Ticket b7b707a310ea42e9
Ticket change [cb8fe8d657] (rid 152775) by sebres on 2017-03-31 19:00:03:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/plain"
- comment initialized to:
This can be seen as the amendment for [b87ad7e9146832d505f9a430d779c5313c440256] The short description: By NRT (near real-time) development under windows, I get several issues with drifting of the [clock microseconds] etc. back, that looks like: clock microseconds -> 1490985783769193 clock microseconds -> 1490985783769191 Additionally I've own clock extension with "nanoseconds", where this is more critical and very annoying: clock nanoseconds -> 1490985425627129800 clock nanoseconds -> 1490985425627128400 This goes to the calibration cycle, where the new combination of fileTimeLastCall, curCounterFreq and perfCounterLastCall breaks the forward running of the native virtual clock. I've fixed it for tcl8.5 branch (merge-able to 8.6 and trunk), solution coming soon... Just as reminder for me (excerpt of log-message of the fix): ``` SHA-1: a746f0501229a4a76e3c9a3825c55dbe9c8c3cdf * optimized calibration cycle (makes Tcl for windows "RTS" resp. NRT-capable): - the clock ticks never backwards (avoid it by negative drifts using comparison of times before and after calibration); - more precise, smooth/soft drifting (avoids too large drifts, already after 10 iterations the drift gets fewer as 0.1 microseconds); - because of more accurate drifting (aspire to the smallest difference), we can prolong calibration interval (up to 10 seconds by small tdiff-value); ```
- is_private initialized to: "0"
- login: "sebres"
- priority initialized to: "5 Medium"
- resolution initialized to: "None"
- severity initialized to: "Severe"
- status initialized to: "Open"
- submitter initialized to: "sebres"
- subsystem initialized to: "03. Timer Events"
- title initialized to:
[win32] NRT-only - NativeGetTime backwards time-drifts bug (fixed)
- type initialized to: "Bug"
Ticket change [ed0fff70e5] (rid 152776) by sebres on 2017-03-31 19:01:29:
- foundin changed to: "all (fixed in my tcl-8.5-branch)"
- login: "sebres"
- mimetype: "text/plain"
- priority changed to: "7 High"
- resolution changed to: "Fixed"
Ticket change [5d701a74e5] (rid 152777) by sebres on 2017-03-31 20:53:49:
- icomment:
As example below small excerpt with DEBUG-output of the calibration thread: ``` *****[30F4]***** 1490992535186529 ** tdiff **-1965, 14909925351865281, 14909925351867246 *****[30F4]***** before 14909925351870010, 14909925351870010 *****[30F4]***** after 14909925351870009, 14909925351870010, diff: -1 / 0 *****[30F4]***** 1490992535187944, [10] ** cfreq == 3117204, nfreq == 3117441, perfc == 2031595984296 *****[30F4]***** 1490992545326460 ** tdiff **-2006, 14909925453264590, 14909925453266596 *****[30F4]***** before 14909925469160412, 14909925469160412 *****[30F4]***** after 14909925469160386, 14909925469160412, diff: -26 / 0 *****[30F4]***** 1490992546917626, [10] ** cfreq == 3117209, nfreq == 3117441, perfc == 2031627592529 *****[30F4]***** 1490992556043572 ** tdiff **-2206, 14909925560435703, 14909925560437909 *****[30F4]***** before 14909925560441189, 14909925560441189 *****[30F4]***** after 14909925560441188, 14909925560441189, diff: -1 / 0 *****[30F4]***** 1490992556045267, [10] ** cfreq == 3117203, nfreq == 3117441, perfc == 2031660999997 *****[30F4]***** 1490992566183518 ** tdiff **-2089, 14909925661835170, 14909925661837259 *****[30F4]***** 1490992566184086, [10] ** cfreq == 3117205, nfreq == 3117441, perfc == 2031692608269 *****[30F4]***** 1490992576323403 ** tdiff **-2587, 14909925763234022, 14909925763236609 *****[30F4]***** before 14909925763238690, 14909925763238690 *****[30F4]***** after 14909925763238689, 14909925763238690, diff: -1 / 0 *****[30F4]***** 1490992576324574, [10] ** cfreq == 3117182, nfreq == 3117441, perfc == 2031724216370 *****[30F4]***** 1490992586463519 ** tdiff **-786, 14909925864635173, 14909925864635959 *****[30F4]***** 1490992586464045, [10] ** cfreq == 3117256, nfreq == 3117441, perfc == 2031755824954 ``` Legend: tdiff : current deviation from virtual time (vt0) to the file-time (in 100-ns); before : nt0, nt0 - virtual time before calibration; after : nt1, nt1c - virtual time after calibration and correction (nt1c = vt0 + (nt0-nt1)); diff : -26 / 0 - difference without and with correction; [10] : current calibration interval (10 seconds) cfreq : calculated frequency; nfreq : nominal frequency; perfc : last performance counter; - login: "sebres"
- mimetype: "text/plain"
- icomment:
Ticket change [eabd04466f] (rid 153927) by sebres on 2017-05-23 22:01:26:
- icomment:
[f6637d3dd85af2a35101e2461c5769ebd1b27cbe] closes this
- login: "sebres"
- mimetype: "text/x-fossil-wiki"
- status changed to: "Pending"
- icomment:
Ticket change [a3ec7b716e] (rid 169693) by sebres on 2019-03-05 20:23:02:
- closedate changed to: "2458548.34933226"
- closer changed to: "sebres"
- icomment:
fixed in a minimalist way in [f6637d3dd8] (merged now), the extensions are provided in event-perf-branches (thus close now).
- login: "sebres"
- mimetype: "text/x-fossil-wiki"
- status changed to: "Closed"
Ticket change [ee917a6ff1] (rid 169694) by sebres on 2019-03-05 22:01:39:
- closedate changed to: "2458548.41781588"
- icomment:
Just as PoC (or for the case someone needs it for tests resp. to check for some other platforms)... Here is an example with 30 seconds run-time: <code><pre style="padding-left:10pt"> proc test {tm} { set l [clock microseconds]; timerate { set i [clock microseconds]; if {$i < $l} {error "$i < $l"}; set l $i } $tm }; test 30000 </pre></code> Similar tests have been succeeded (no backward-drifts after run-time of ca. half an hour) on physical host and virtual machines of me (single- and multi-threaded). - login: "sebres"
- mimetype: "text/x-fossil-wiki"
Ticket change [41b34f6960] (rid 177917) by sebres on 2019-12-16 14:08:56:
- closer changed to: "nobody"
- icomment:
Newest findings here - test cmdMZ-6.6 could sporadically fail with: <pre> ---- Result was: {1 0 1 0 1 0 1 1 1} {998.039 µs/# 51 # 1002.0 #/sec 50.900 net-ms} {999.255 µs/# 51 # 1000.7 #/sec 50.962 net-ms} ---- Result should have been (glob matching): {1 1 1 1 1 1 1 1 1} * </pre> In normal case the first measurement value (m1) is in about <code>{11.8732 µs/# 4212 # 84223.2 #/sec 50.010 net-ms}</code>.<br/>So a busy wait 0.01ms (<code>_nrt_sleep 0.01</code>) is abrupt 100 times slower (or even more due to repetition). Probably I should rebase parts of my event-perf-branch fixing that. - login: "sebres"
- mimetype: "text/x-fossil-wiki"
- status changed to: "Open"
Ticket change [186f1d605b] (rid 256287) by sebres on 2026-09-14 00:12:57:
- icomment:
I wanted to add another new monotonic test case to clock.test (to cover in-sync-ticking with microseconds): <code><pre style="margin-left:15pt"> test clock-33.13 {clock test, monotonic ticks in sync with microseconds (compiled only)} { lassign [::testClock::aligned-times microseconds monotonic] t1 t2 set time [expr {$t1 - $t2}]; # microseconds alignment timerate {} 1; # short but precise busy wait lassign [::testClock::aligned-times microseconds monotonic] t1 t2 if { $t2 + $time != $t1 } { ::tcltest::Skip "timing issue"; # did we experience time drift? } } {} </pre></code> But an attempt to test its stability failed on windows (I guess because of drifting through calibration): <code><pre style="margin-left:15pt"> timerate { lassign [::testClock::aligned-times microseconds monotonic] t1 t2 set time [expr {$t1 - $t2}]; # microseconds alignment timerate {} 1; # short but precise busy wait lassign [::testClock::aligned-times microseconds monotonic] t1 t2 if { $t2 + $time - $t1 != 0 } { ::tcltest::Skip "timing issue ([expr {abs($t2 + $time - $t1)}] > 0)"; # did we experience time drift? } } 3000 </pre></code> The microseconds sporadically drifting 1ms or 2ms compared to monotonic time. I cannot reproduce it in my fork with [fdfbd5e10] integrated (I also never saw microseconds drifts there).<br/> So I'll try to partially backport tclWinTime.c enhancement (inlined calibration for wall clock without calibration thread). - login: "sebres"
- mimetype: "text/x-fossil-wiki"
- icomment:
Ticket change [c455d4d153] (rid 256293) by oehhar on 2026-09-14 08:24:48:
- icomment:
Hi Sergey, thanks for this. I never saw MS-Windows clock reliable at all. Just a "timerate {after 1}" gives from 16 to 60 milliseconds. Thanks for any enhancement. In the monotonic clock changes, I tried to conserve anything what was there. But the resolution and relyability is still bad. All test files are on 100ms time frame and are still not relyable. But the syntax is prepared for microseconds resolution ;-). This is not critism, just to remark that I see open work possible, Harald - login: "oehhar"
- mimetype: "text/x-fossil-wiki"
- username: "oehhar"
- icomment:
Ticket change [124cb22a90] (rid 256294) by sebres on 2026-09-14 11:03:29:
- icomment:
<blockquote> > I never saw MS-Windows clock reliable at all.<br/> > Just a "timerate {after 1}" gives from 16 to 60 milliseconds. </blockquote> Did you ever try [fdfbd5e10]? It is dozen nanoseconds accurate. <code><pre style="margin-left:15px"> % timerate {after 1} 1000.53 µs/# 999 # 999.47 #/sec 999.529 net-ms % timerate {after 0.1} 100.291 µs/# 9968 # 9971.0 #/sec 999.696 net-ms % timerate {after 0.01} 10.1089 µs/# 98683 # 98922.6 #/sec 997.578 net-ms % timerate {after 0.001} 1.016859 µs/# 960272 # 983420 #/sec 976.461 net-ms % timerate {after 0.0001} 0.117602 µs/# 7036594 # 8503231 #/sec 827.520 net-ms </code></pre> - login: "sebres"
- mimetype: "text/x-fossil-wiki"
- icomment:
Ticket change [e96c8b3045] (rid 256296) by oehhar on 2026-09-14 11:25:34:
- icomment:
Thanks great. No, never tried it. I looked into it while doing the 3 years monotonic clock TIP nightmare work but did not understand one line, sorry. To have only 1% of your usual performance is still a dream, sorry... Thanks for all the great Wizard work, Harald
- login: "oehhar"
- mimetype: "text/x-fossil-wiki"
- username: "oehhar"
- icomment: