Skip to content
Tcl Source Code History Of Ticket 2904418fffffffffffffffffffffffffffffffff
Login

History Of Ticket 2904418fffffffffffffffffffffffffffffffff

Artifacts Associated With Ticket 2904418fffffffffffffffffffffffffffffffff

  1. Ticket change [dd451a40ad] (rid 114641) by ferrieux on 2009-11-26 10:01:46:

    1. assignee initialized to: "kennykb"
    2. cmimetype initialized to: "text/plain"
    3. comment initialized to:
      A synchronous [after] may waste up to a full millisecond of CPU busylooping on gettimeofday().
      Strace -tt -T output from an interactive tclsh where I typed "after 10":
      
      10:43:11.589638 read(0, "after 10\n", 4096) = 9 <3.160754>
      10:43:14.750481 gettimeofday({1259228594, 750498}, NULL) = 0 <0.000006>
      10:43:14.750519 gettimeofday({1259228594, 750535}, NULL) = 0 <0.000006>
      10:43:14.750555 gettimeofday({1259228594, 750571}, NULL) = 0 <0.000005>
      10:43:14.750593 select(0, NULL, NULL, NULL, {0, 9000}) = 0 (Timeout) <0.009340>
      10:43:14.759973 gettimeofday({1259228594, 759991}, NULL) = 0 <0.000007>
      10:43:14.760021 gettimeofday({1259228594, 760035}, NULL) = 0 <0.000005>
      10:43:14.760055 gettimeofday({1259228594, 760069}, NULL) = 0 <0.000006>
      10:43:14.760094 gettimeofday({1259228594, 760106}, NULL) = 0 <0.000004>
      10:43:14.760132 gettimeofday({1259228594, 760144}, NULL) = 0 <0.000006>
      10:43:14.760162 gettimeofday({1259228594, 760177}, NULL) = 0 <0.000007>
      10:43:14.760197 gettimeofday({1259228594, 760209}, NULL) = 0 <0.000006>
      10:43:14.760234 gettimeofday({1259228594, 760248}, NULL) = 0 <0.000005>
      10:43:14.760268 gettimeofday({1259228594, 760281}, NULL) = 0 <0.000005>
      10:43:14.760299 gettimeofday({1259228594, 760311}, NULL) = 0 <0.000005>
      10:43:14.760331 gettimeofday({1259228594, 760344}, NULL) = 0 <0.000006>
      10:43:14.760362 gettimeofday({1259228594, 760375}, NULL) = 0 <0.000005>
      10:43:14.760397 gettimeofday({1259228594, 760413}, NULL) = 0 <0.000007>
      10:43:14.760432 gettimeofday({1259228594, 760444}, NULL) = 0 <0.000006>
      10:43:14.760462 gettimeofday({1259228594, 760474}, NULL) = 0 <0.000005>
      10:43:14.760492 gettimeofday({1259228594, 760505}, NULL) = 0 <0.000005>
      10:43:14.760534 write(1, "% ", 2)       = 2 <0.000009>
      10:43:14.760575 read(0, 
      
      Clearly what happens is a rounding problem: the select() does an efficient wait on the integer part, in milliseconds, of the computed ETA, then the loop in AfterDelay checks again, and finds a submillisecond remaining time, so no more select()s, and busily calls gettimeofday until the target is reached.
      
      (As a side note, the fact that the select() rounds to milliseconds while its argument is in microseconds seems strange. But this is a red herring, since the OS's resolution isn't that fine anyway).
      
      I think that [after] should have a declared policy of either "undershooting" (floor of value) or "overshooting" (ceiling of value) to compute the select() millisecond timeout, and just call it once and return, without busylooping to fine-tune the result. The rationale is that anybody wanting a non-drifting clock can simply use [clock clicks] or [clock milliseconds] and recompute his [after] argument. Atomic accuracy of [after] is a pipe dream in soft-realtime OSes in any case.
      
      FWIW, I put this a high prio even though it is an old bug, because, it completely cripples the performance of a script of mine which otherwise happily swallows megabits per seconds of MPEG TS stream and achieves absolutely no drift. Yes, in Tcl :)
      
      
    4. foundin initialized to: "None"
    5. is_private initialized to: "0"
    6. priority initialized to: "8"
    7. resolution initialized to: "None"
    8. status initialized to: "Open"
    9. submitter initialized to: "ferrieux"
    10. subsystem initialized to: "03. Timer Events"
    11. title initialized to: "One millisecond of busyloop in [after]"
    12. type initialized to: "Bug"
  2. Ticket change [af3e56fd2d] (rid 97778) by dkf on 2009-11-26 17:14:11:

    1. icomment:
      At least that will stop me from worrying about the granularity of poll() when I get back to working on the poll-based notifier (it's also millisecond-level).
      
      
    2. login: "dkf"
    3. mimetype: "text/plain"
    4. username: "dkf"
  3. Add attachment "after.patch" [62804d154e] (rid 92411) by ferrieux on 2009-11-27 20:23:18.

  4. Ticket change [2c6a44326e] (rid 118900) by ferrieux on 2009-11-27 20:23:21:

    1. icomment:
      
      
      File Added - 352776: after.patch
      
      
      
    2. login: "ferrieux"
    3. mimetype: "text/plain"
    4. username: "ferrieux"
  5. Ticket change [f707468a5f] (rid 130418) by ferrieux on 2009-11-27 20:25:47:

    1. icomment:
      Attached trivial patch breaking out of the loop when <1ms is left.
      Please review.
      
      
      
    2. login: "ferrieux"
    3. mimetype: "text/plain"
    4. username: "ferrieux"
  6. Ticket change [b4e9e72f8a] (rid 125133) by ferrieux on 2009-11-27 20:25:53:

    1. resolution changed to: "Fixed"
  7. Ticket change [4aa33071eb] (rid 126569) by ferrieux on 2009-11-30 07:22:40:

    1. icomment:
      Also see 2905784 for further squeezing out of unneeded gettimeofday()s.
      
      
    2. login: "ferrieux"
    3. mimetype: "text/plain"
    4. username: "ferrieux"
  8. Ticket change [ec995a5f5a] (rid 103733) by ferrieux on 2010-10-29 23:37:40:

    1. closedate changed to: "2010-10-29T16:37:40"
    2. closer changed to: "ferrieux"
    3. icomment:
      
      
      allow_comments - 1
      
      Marking this one as dupe, since 2905784 has the final patch grouping [after] optimizations.
      
      
    4. login: "ferrieux"
    5. mimetype: "text/plain"
    6. resolution changed to: "Duplicate"
    7. status changed to: "Closed"
    8. username: "ferrieux"