Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: c8afdd8d8b455b9d1cb8dce56f68a6b242bf09df
Ticket: b87ad7e9146832d505f9a430d779c5313c440256
NativeGetTime time-drifts bug (fixed)
User & Date: sebres on 2016-12-29 01:03:16
Changes

  1. assignee changed to: "nobody"
  2. closer changed to: "nobody"
  3. cmimetype changed to: "text/plain"
  4. comment changed to:
    By testing of performance of my newer tcl-clock module I've realized that we have a bug in time routines (at least grave on Windows platform).
    
    If some thread too often calls Tcl_GetTime, that blurs current performance counters normally actualized in calibration thread in UpdateTimeEachSecond.
    
    This entails that sometimes sporadically time-drifts resp. jump-esque time-shifts occurred, what for example produces very confusing results during time measurement.
    
    An explanation example with "time" command:
    
    % time {puts [time {clock scan "2451545 102030" -format "%J%H%M%S"} 566000]} 100
    
    0.8814169611307421 microseconds per iteration
    0.8766148409893993 microseconds per iteration
    0.8825282685512368 microseconds per iteration
    0.8852031802120142 microseconds per iteration
    0.8810035335689046 microseconds per iteration
    ---------------------------------------------
    2.7021978798586574 microseconds per iteration
    ---------------------------------------------
    0.8808533568904594 microseconds per iteration
    0.8875512367491166 microseconds per iteration
    0.8777968197879858 microseconds per iteration
    0.8813586572438162 microseconds per iteration
    0.8832685512367491 microseconds per iteration
    0.8851378091872791 microseconds per iteration
    
    Or another example with my "timerate" command (with debug output of now.sec/now.usec from Tcl_GetTime, and start, planed stop in microseconds):
    
    % time {puts [timerate {clock scan "2451545 102030" -format "%J%H%M%S"} 500]} 100
    
    *********1482963877, 264920 = 1482963877264920 - 1482963877764920
    *********1482963877, 764920 = 1482963877764920
    0.882205 µs/#, 566762 #, 1133524 #/sec
    *********1482963877, 765445 = 1482963877765445 - 1482963878265445
    *********1482963878, 265445 = 1482963878265445
    0.879648 µs/#, 568409 #, 1136818 #/sec
    *********1482963878, 265821 = 1482963878265821 - 1482963878765821
    *********1482963878, 765821 = 1482963878765821
    0.880355 µs/#, 567953 #, 1135906 #/sec
    *********1482963878, 766199 = 1482963878766199 - 1482963879266199
    *********1482963879, 266199 = 1482963879266199
    0.881784 µs/#, 567032 #, 1134064 #/sec
    *********1482963879, 266795 = 1482963879266795 - 1482963879766795
    *********1482963879, 766795 = 1482963879766795
    0.877449 µs/#, 569834 #, 1139668 #/sec
    *********1482963879, 767440 = 1482963879767440 - 1482963880267440
    *********1482963880, 267440 = 1482963880267440
    0.883411 µs/#, 565988 #, 1131976 #/sec
    *********1482963880, 267811 = 1482963880267811 - 1482963880767811
    *********1482963880, 767811 = 1482963880767811
    0.881778 µs/#, 567036 #, 1134072 #/sec
    -----------------------------------------------------------------
    *********1482963880, 768160 = 1482963880768160 - 1482963881268160
    *********1482963881, 913628 = 1482963881913628
    8.606911 µs/#, 133087 #, 116185 #/sec
    -----------------------------------------------------------------
    *********1482963881, 914035 = 1482963881914035 - 1482963882414035
    *********1482963882, 414035 = 1482963882414035
    0.882879 µs/#, 566329 #, 1132658 #/sec
    *********1482963882, 414404 = 1482963882414404 - 1482963882914404
    *********1482963882, 914404 = 1482963882914404
    0.877547 µs/#, 569770 #, 1139540 #/sec
    *********1482963882, 914911 = 1482963882914911 - 1482963883414911
    *********1482963883, 414911 = 1482963883414911
    0.878137 µs/#, 569387 #, 1138774 #/sec
    *********1482963883, 415353 = 1482963883415353 - 1482963883915353
    *********1482963883, 915353 = 1482963883915353
    0.880037 µs/#, 568158 #, 1136316 #/sec
    
    
    More detailed example with "time" command and microseconds with difference between start/stop.
    Here you see that instead 500ms in makes a time jump to the next second (1500ms) despite the real execution of 500ms.
    
    % set p [clock microseconds]; time { puts "[time {clock scan "2451545 102030" -format "%J%H%M%S"} 566000]\t**** [set n [clock microseconds]] -- [expr {$n - $p}]"; set p $n } 100
    
    0.8926342756183746 microseconds per iteration   **** 1482965362339022 -- 505488
    0.8897190812720848 microseconds per iteration   **** 1482965362842886 -- 503864
    0.8906837455830389 microseconds per iteration   **** 1482965363347259 -- 504373
    0.8877826855123675 microseconds per iteration   **** 1482965363849937 -- 502678
    0.8867455830388693 microseconds per iteration   **** 1482965364352100 -- 502163
    0.8848586572438163 microseconds per iteration   **** 1482965364853183 -- 501083
    0.8814593639575972 microseconds per iteration   **** 1482965365352326 -- 499143
    0.8891395759717314 microseconds per iteration   **** 1482965365855784 -- 503458
    0.8802950530035336 microseconds per iteration   **** 1482965366354316 -- 498532
    --------------------------------------------------------------------------------
    2.708512367491166 microseconds per iteration    **** 1482965367887622 -- 1533306
    --------------------------------------------------------------------------------
    0.8872332155477032 microseconds per iteration   **** 1482965368390069 -- 502447
    0.8919593639575971 microseconds per iteration   **** 1482965368895198 -- 505129
    0.8893409893992933 microseconds per iteration   **** 1482965369398836 -- 503638
    
    After fixing of this issue, the result looks like this.
    All the times are become longer, but no jumps resp. time-shifts any more:
    
    % set p [clock microseconds]; time { puts "[time {clock scan "2451545 102030" -format "%J%H%M%S"} 566000]\t**** [set n [clock microseconds]] -- [expr {$n - $p}]"; set p $n } 100
    
    0.9901731448763251 microseconds per iteration   **** 1482967567052169 -- 560698
    0.9650424028268552 microseconds per iteration   **** 1482967567598682 -- 546513
    0.9574081272084806 microseconds per iteration   **** 1482967568140856 -- 542174
    0.9472137809187279 microseconds per iteration   **** 1482967568677202 -- 536346
    0.9592455830388693 microseconds per iteration   **** 1482967569220385 -- 543183
    0.9634293286219081 microseconds per iteration   **** 1482967569765893 -- 545508
    0.9630742049469965 microseconds per iteration   **** 1482967570311220 -- 545327
    0.9530530035335689 microseconds per iteration   **** 1482967570850904 -- 539684
    0.9532349823321554 microseconds per iteration   **** 1482967571390720 -- 539816
    0.9471431095406361 microseconds per iteration   **** 1482967571927080 -- 536360
    0.9596484098939929 microseconds per iteration   **** 1482967572470496 -- 543416
    0.9597349823321555 microseconds per iteration   **** 1482967573013965 -- 543469
    0.9652067137809187 microseconds per iteration   **** 1482967573560460 -- 546495
    0.9649399293286219 microseconds per iteration   **** 1482967574106875 -- 546415
    0.956809187279152 microseconds per iteration    **** 1482967574648661 -- 541786
    0.9588038869257951 microseconds per iteration   **** 1482967575191604 -- 542943
    0.9484293286219081 microseconds per iteration   **** 1482967575728694 -- 537090
    0.96363074204947 microseconds per iteration     **** 1482967576274333 -- 545639
    0.9441678445229682 microseconds per iteration   **** 1482967576808984 -- 534651
    
    --
    
    Currently no fossil handy (new computer and fossil-repo (or my network?) is too slow by cloning, so permanent timeouts). I've committed it in my github-repo. See https://github.com/sebres/tcl/commit/975126bb18342949a317fe55fb68e89b0665f563
    
    [win] bug fix in NativeGetTime: each call of it blurs current performance counters actualized in calibration thread in UpdateTimeEachSecond;
    [unix] wrong cast fixed in TclpGetWideClicks: multiplication with 1000000 in long int may cause overflow
    
  5. foundin changed to: "all"
  6. is_private changed to: "0"
  7. login: "sebres"
  8. priority changed to: "5 Medium"
  9. resolution changed to: "None"
  10. severity changed to: "Critical"
  11. status changed to: "Open"
  12. submitter changed to: "sebres"
  13. subsystem changed to: "06. Time Measurement"
  14. title changed to: "NativeGetTime time-drifts bug (fixed)"
  15. type changed to: "Bug"