<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>181175</bug_id>
          
          <creation_ts>2017-12-27 06:29:26 -0800</creation_ts>
          <short_desc>[WTF] Add clock_gettime based monotonicallyIncreasingTime implementation for Linux and BSDs</short_desc>
          <delta_ts>2018-01-05 12:32:36 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>New Bugs</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Yusuke Suzuki">ysuzuki</reporter>
          <assigned_to name="Yusuke Suzuki">ysuzuki</assigned_to>
          <cc>annulen</cc>
    
    <cc>benjamin</cc>
    
    <cc>cdumez</cc>
    
    <cc>cgarcia</cc>
    
    <cc>clopez</cc>
    
    <cc>cmarcelo</cc>
    
    <cc>darin</cc>
    
    <cc>dbates</cc>
    
    <cc>ews-watchlist</cc>
    
    <cc>mark.lam</cc>
    
    <cc>mcatanzaro</cc>
    
    <cc>saam</cc>
    
    <cc>sam</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1384793</commentid>
    <comment_count>0</comment_count>
    <who name="Yusuke Suzuki">ysuzuki</who>
    <bug_when>2017-12-27 06:29:26 -0800</bug_when>
    <thetext>[WTF] Add clock_gettime based monotonicallyIncreasingTime implementation for Linux and BSDs</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1384794</commentid>
    <comment_count>1</comment_count>
      <attachid>330214</attachid>
    <who name="Yusuke Suzuki">ysuzuki</who>
    <bug_when>2017-12-27 06:30:44 -0800</bug_when>
    <thetext>Created attachment 330214
Patch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1384796</commentid>
    <comment_count>2</comment_count>
      <attachid>330214</attachid>
    <who name="Konstantin Tokarev">annulen</who>
    <bug_when>2017-12-27 06:42:08 -0800</bug_when>
    <thetext>Comment on attachment 330214
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=330214&amp;action=review

&gt; Source/WTF/wtf/CurrentTime.cpp:277
&gt; +}

FYI, Qt&apos;s implementation of monotonic clock timer uses more sofisticated check, see https://code.woboq.org/qt5/qtbase/src/corelib/kernel/qelapsedtimer_unix.cpp.html#65 and from line 115. On Linux, it always assumes monotonic clock to be present, on other systems it checks values of macros and, if needed, what sysconf(_SC_MONOTONIC_CLOCK) returns</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1384797</commentid>
    <comment_count>3</comment_count>
    <who name="Konstantin Tokarev">annulen</who>
    <bug_when>2017-12-27 07:10:10 -0800</bug_when>
    <thetext>Here is a version of that file under LGPL 2 (so that portions could be imported if needed): http://code.qt.io/cgit/qt/qtbase.git/tree/src/corelib/tools/qelapsedtimer_unix.cpp?h=5.6</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1384801</commentid>
    <comment_count>4</comment_count>
      <attachid>330214</attachid>
    <who name="Yusuke Suzuki">ysuzuki</who>
    <bug_when>2017-12-27 08:12:02 -0800</bug_when>
    <thetext>Comment on attachment 330214
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=330214&amp;action=review

&gt;&gt; Source/WTF/wtf/CurrentTime.cpp:277
&gt;&gt; +}
&gt; 
&gt; FYI, Qt&apos;s implementation of monotonic clock timer uses more sofisticated check, see https://code.woboq.org/qt5/qtbase/src/corelib/kernel/qelapsedtimer_unix.cpp.html#65 and from line 115. On Linux, it always assumes monotonic clock to be present, on other systems it checks values of macros and, if needed, what sysconf(_SC_MONOTONIC_CLOCK) returns

But actually, are there any Linux/FreeBSD/OpenBSD/NetBSD environments that do not support monotonic clock?
For example, libcxx assumes that supported environments have this monotonic clock[1]. And if it fails, it simply crashes.

[1]: https://github.com/llvm-mirror/libcxx/blob/master/src/chrono.cpp#L220-L227</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1384809</commentid>
    <comment_count>5</comment_count>
      <attachid>330214</attachid>
    <who name="Michael Catanzaro">mcatanzaro</who>
    <bug_when>2017-12-27 09:14:08 -0800</bug_when>
    <thetext>Comment on attachment 330214
Patch

This seems fine to me, since you&apos;ve ensured that it only affects JSCOnly. GTK and WPE will be happy that they continue using g_get_monotonic_time, since WebKit events rely on WebKit&apos;s monotonic time matching GLib&apos;s. (It should be the same under the hood -- CLOCK_MONOTONIC -- either way, but continuing to use g_get_monotonic_time seems preferable.)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1384813</commentid>
    <comment_count>6</comment_count>
    <who name="Konstantin Tokarev">annulen</who>
    <bug_when>2017-12-27 09:18:34 -0800</bug_when>
    <thetext>&gt;libcxx assumes that supported environments have this monotonic clock[1]. And if it fails, it simply crashes.

Cool. But at least it checks that CLOCK_MONOTONIC is defined,</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1384839</commentid>
    <comment_count>7</comment_count>
    <who name="Konstantin Tokarev">annulen</who>
    <bug_when>2017-12-27 16:49:37 -0800</bug_when>
    <thetext>&gt;But actually, are there any Linux/FreeBSD/OpenBSD/NetBSD environments that do not support monotonic clock?

It seems like no, there aren&apos;t</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1384840</commentid>
    <comment_count>8</comment_count>
      <attachid>330214</attachid>
    <who name="Konstantin Tokarev">annulen</who>
    <bug_when>2017-12-27 16:57:18 -0800</bug_when>
    <thetext>Comment on attachment 330214
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=330214&amp;action=review

&gt;&gt;&gt; Source/WTF/wtf/CurrentTime.cpp:277
&gt;&gt;&gt; +}
&gt;&gt; 
&gt;&gt; FYI, Qt&apos;s implementation of monotonic clock timer uses more sofisticated check, see https://code.woboq.org/qt5/qtbase/src/corelib/kernel/qelapsedtimer_unix.cpp.html#65 and from line 115. On Linux, it always assumes monotonic clock to be present, on other systems it checks values of macros and, if needed, what sysconf(_SC_MONOTONIC_CLOCK) returns
&gt; 
&gt; But actually, are there any Linux/FreeBSD/OpenBSD/NetBSD environments that do not support monotonic clock?
&gt; For example, libcxx assumes that supported environments have this monotonic clock[1]. And if it fails, it simply crashes.
&gt; 
&gt; [1]: https://github.com/llvm-mirror/libcxx/blob/master/src/chrono.cpp#L220-L227

Interestingly, it seems like on Linux CLOCK_MONOTONIC isn&apos;t really monotonic, but can be affected by adjtime(3) and NTP. There is additional CLOCK_MONOTONIC_RAW which is available since Linux 2.6.28, which is truly monotonic. Neither Qt nor GLib attempt to use it in their monotonic time wrappers</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1384841</commentid>
    <comment_count>9</comment_count>
    <who name="Carlos Alberto Lopez Perez">clopez</who>
    <bug_when>2017-12-27 17:11:14 -0800</bug_when>
    <thetext>(In reply to Konstantin Tokarev from comment #8)
&gt; 
&gt; Interestingly, it seems like on Linux CLOCK_MONOTONIC isn&apos;t really
&gt; monotonic, but can be affected by adjtime(3) and NTP. There is additional
&gt; CLOCK_MONOTONIC_RAW which is available since Linux 2.6.28, which is truly
&gt; monotonic. Neither Qt nor GLib attempt to use it in their monotonic time
&gt; wrappers

I think both are really monotonic, the difference is that the first is affected by time frequency adjustments via adjtime() (aka: the speed of a second), meanwhile the second doesn&apos;t gets affected by that. https://stackoverflow.com/a/14270415</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1384843</commentid>
    <comment_count>10</comment_count>
      <attachid>330214</attachid>
    <who name="Konstantin Tokarev">annulen</who>
    <bug_when>2017-12-27 17:44:36 -0800</bug_when>
    <thetext>Comment on attachment 330214
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=330214&amp;action=review

&gt; Source/WTF/wtf/CurrentTime.cpp:276
&gt; +    return static_cast&lt;double&gt;(ts.tv_sec) + ts.tv_nsec * 1.0e9;

This code has a bug, it should either be

    static_cast&lt;double&gt;(ts.tv_sec) + ts.tv_nsec / 1.0e9

or

    static_cast&lt;double&gt;(ts.tv_sec) * 1.0e9 + ts.tv_nsec

I would prefer the former as it will result in numbers of smaller order</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1384858</commentid>
    <comment_count>11</comment_count>
      <attachid>330214</attachid>
    <who name="Yusuke Suzuki">ysuzuki</who>
    <bug_when>2017-12-28 06:13:55 -0800</bug_when>
    <thetext>Comment on attachment 330214
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=330214&amp;action=review

&gt;&gt; Source/WTF/wtf/CurrentTime.cpp:276
&gt;&gt; +    return static_cast&lt;double&gt;(ts.tv_sec) + ts.tv_nsec * 1.0e9;
&gt; 
&gt; This code has a bug, it should either be
&gt; 
&gt;     static_cast&lt;double&gt;(ts.tv_sec) + ts.tv_nsec / 1.0e9
&gt; 
&gt; or
&gt; 
&gt;     static_cast&lt;double&gt;(ts.tv_sec) * 1.0e9 + ts.tv_nsec
&gt; 
&gt; I would prefer the former as it will result in numbers of smaller order

Oops, fixed. double should be in seconds. The former is fine.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1384860</commentid>
    <comment_count>12</comment_count>
    <who name="Yusuke Suzuki">ysuzuki</who>
    <bug_when>2017-12-28 06:17:12 -0800</bug_when>
    <thetext>Committed r226304: &lt;https://trac.webkit.org/changeset/226304&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1385235</commentid>
    <comment_count>13</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2018-01-02 13:18:38 -0800</bug_when>
    <thetext>&lt;rdar://problem/36261381&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1385236</commentid>
    <comment_count>14</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2018-01-02 13:18:44 -0800</bug_when>
    <thetext>&lt;rdar://problem/36261385&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1386214</commentid>
    <comment_count>15</comment_count>
      <attachid>330214</attachid>
    <who name="Darin Adler">darin</who>
    <bug_when>2018-01-05 12:32:36 -0800</bug_when>
    <thetext>Comment on attachment 330214
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=330214&amp;action=review

&gt;&gt;&gt; Source/WTF/wtf/CurrentTime.cpp:276
&gt;&gt;&gt; +    return static_cast&lt;double&gt;(ts.tv_sec) + ts.tv_nsec * 1.0e9;
&gt;&gt; 
&gt;&gt; This code has a bug, it should either be
&gt;&gt; 
&gt;&gt;     static_cast&lt;double&gt;(ts.tv_sec) + ts.tv_nsec / 1.0e9
&gt;&gt; 
&gt;&gt; or
&gt;&gt; 
&gt;&gt;     static_cast&lt;double&gt;(ts.tv_sec) * 1.0e9 + ts.tv_nsec
&gt;&gt; 
&gt;&gt; I would prefer the former as it will result in numbers of smaller order
&gt; 
&gt; Oops, fixed. double should be in seconds. The former is fine.

I would have suggested 1.0e-9 instead of switching from multiplication to division.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>330214</attachid>
            <date>2017-12-27 06:30:44 -0800</date>
            <delta_ts>2017-12-27 09:14:08 -0800</delta_ts>
            <desc>Patch</desc>
            <filename>bug-181175-20171227233043.patch</filename>
            <type>text/plain</type>
            <size>1439</size>
            <attacher name="Yusuke Suzuki">ysuzuki</attacher>
            
              <data encoding="base64">U3VidmVyc2lvbiBSZXZpc2lvbjogMjI2Mjk4CmRpZmYgLS1naXQgYS9Tb3VyY2UvV1RGL0NoYW5n
ZU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
NTQwMmJiMzljMWQ0ZDg0YTkuLjFhYzdiMTM0NDI0ZWEwZDcwNGQ2Yjk1MmVhN2YwNGQyY2ZjZTFi
YzUgMTAwNjQ0Ci0tLSBhL1NvdXJjZS9XVEYvd3RmL0N1cnJlbnRUaW1lLmNwcAorKysgYi9Tb3Vy
Y2UvV1RGL3d0Zi9DdXJyZW50VGltZS5jcHAKQEAgLTI2Nyw2ICsyNjcsMTUgQEAgZG91YmxlIG1v
bm90b25pY2FsbHlJbmNyZWFzaW5nVGltZSgpCiAgICAgcmV0dXJuIChtYWNoX2Fic29sdXRlX3Rp
bWUoKSAqIHRpbWViYXNlSW5mby5udW1lcikgLyAoMS4wZTkgKiB0aW1lYmFzZUluZm8uZGVub20p
OwogfQogCisjZWxpZiBPUyhMSU5VWCkgfHwgT1MoRlJFRUJTRCkgfHwgT1MoT1BFTkJTRCkgfHwg
T1MoTkVUQlNEKQorCitkb3VibGUgbW9ub3RvbmljYWxseUluY3JlYXNpbmdUaW1lKCkKK3sKKyAg
ICBzdHJ1Y3QgdGltZXNwZWMgdHMgeyB9OworICAgIGNsb2NrX2dldHRpbWUoQ0xPQ0tfTU9OT1RP
TklDLCAmdHMpOworICAgIHJldHVybiBzdGF0aWNfY2FzdDxkb3VibGU+KHRzLnR2X3NlYykgKyB0
cy50dl9uc2VjICogMS4wZTk7Cit9CisKICNlbHNlCiAKIGRvdWJsZSBtb25vdG9uaWNhbGx5SW5j
cmVhc2luZ1RpbWUoKQo=
</data>
<flag name="review"
          id="349247"
          type_id="1"
          status="+"
          setter="mcatanzaro"
    />
          </attachment>
      

    </bug>

</bugzilla>