Thread overview
[phobos] clock_gettime changes
Nov 20, 2010
Brad Roberts
Nov 20, 2010
Jonathan M Davis
Nov 21, 2010
Michel Fortin
Nov 20, 2010
Sean Kelly
Nov 20, 2010
Brad Roberts
Nov 21, 2010
Jonathan M Davis
Nov 21, 2010
Brad Roberts
Nov 21, 2010
Jonathan M Davis
November 20, 2010
... seems to have broken both the druntime and phobos unit tests.

http://d.puremagic.com/test-results/test.ghtml?runid=3025

druntime's error:
unittest.o: In function
`_D4core4sync6config7mktspecFKS4core3sys5posix6signal8timespeclZv':
src/rt/typeinfo/ti_wchar.d:(.text._D4core4sync6config7mktspecFKS4core3sys5posix6signal8timespeclZv+0xa):
undefined reference to `clock_gettime'

phobos' error:
unittest.o: In function
`_D4core4sync6config7mktspecFKS4core3sys5posix6signal8timespeclZv':
src/rt/typeinfo/ti_wchar.d:(.text._D4core4sync6config7mktspecFKS4core3sys5posix6signal8timespeclZv+0xa):
undefined reference to `clock_gettime'

Adding -L-lrt to the DFLAGS variable in dmd.conf fixes the problem.  That'll
need to be reflected in the shipped dmd.conf, assuming it's the right fix.  I
don't have access to the other posix platforms to see if it's needed there or not.

Later,
Brad
November 20, 2010
On Saturday 20 November 2010 01:33:45 Brad Roberts wrote:
> ... seems to have broken both the druntime and phobos unit tests.
> 
> http://d.puremagic.com/test-results/test.ghtml?runid=3025
> 
> druntime's error:
> unittest.o: In function
> `_D4core4sync6config7mktspecFKS4core3sys5posix6signal8timespeclZv':
> src/rt/typeinfo/ti_wchar.d:(.text._D4core4sync6config7mktspecFKS4core3sys5p
> osix6signal8timespeclZv+0xa): undefined reference to `clock_gettime'
> 
> phobos' error:
> unittest.o: In function
> `_D4core4sync6config7mktspecFKS4core3sys5posix6signal8timespeclZv':
> src/rt/typeinfo/ti_wchar.d:(.text._D4core4sync6config7mktspecFKS4core3sys5p
> osix6signal8timespeclZv+0xa): undefined reference to `clock_gettime'
> 
> Adding -L-lrt to the DFLAGS variable in dmd.conf fixes the problem. That'll need to be reflected in the shipped dmd.conf, assuming it's the right fix.  I don't have access to the other posix platforms to see if it's needed there or not.

librt is required for clock_gettime(), so that is the correct fix. Apparently, MacOS doesn't have clock_gettime(), so it will continue to use gettimeofday() and won't need librt (it probably isn't on the system anyway, or it would have clock_gettime()). I have no idea about FreeBSD.

- Jonathan M Davis
November 20, 2010
Oops.  I'll disable the check for clock_gettime in core.sync.config.

On Nov 20, 2010, at 1:33 AM, Brad Roberts wrote:

> ... seems to have broken both the druntime and phobos unit tests.
> 
> http://d.puremagic.com/test-results/test.ghtml?runid=3025
> 
> druntime's error:
> unittest.o: In function
> `_D4core4sync6config7mktspecFKS4core3sys5posix6signal8timespeclZv':
> src/rt/typeinfo/ti_wchar.d:(.text._D4core4sync6config7mktspecFKS4core3sys5posix6signal8timespeclZv+0xa):
> undefined reference to `clock_gettime'
> 
> phobos' error:
> unittest.o: In function
> `_D4core4sync6config7mktspecFKS4core3sys5posix6signal8timespeclZv':
> src/rt/typeinfo/ti_wchar.d:(.text._D4core4sync6config7mktspecFKS4core3sys5posix6signal8timespeclZv+0xa):
> undefined reference to `clock_gettime'
> 
> Adding -L-lrt to the DFLAGS variable in dmd.conf fixes the problem.  That'll
> need to be reflected in the shipped dmd.conf, assuming it's the right fix.  I
> don't have access to the other posix platforms to see if it's needed there or not.
> 
> Later,
> Brad

November 20, 2010
I have no problems with the original change, as long as the shipped dmd.conf file is updated so that it 'just works' for everyone.  The release notes would need to call this out carefully so that those that maintain their own dmd.conf file, for whatever reasons, also know about the change.

On 11/20/2010 10:08 AM, Sean Kelly wrote:
> Oops.  I'll disable the check for clock_gettime in core.sync.config.
> 
> On Nov 20, 2010, at 1:33 AM, Brad Roberts wrote:
> 
>> ... seems to have broken both the druntime and phobos unit tests.
>>
>> http://d.puremagic.com/test-results/test.ghtml?runid=3025
>>
>> druntime's error:
>> unittest.o: In function
>> `_D4core4sync6config7mktspecFKS4core3sys5posix6signal8timespeclZv':
>> src/rt/typeinfo/ti_wchar.d:(.text._D4core4sync6config7mktspecFKS4core3sys5posix6signal8timespeclZv+0xa):
>> undefined reference to `clock_gettime'
>>
>> phobos' error:
>> unittest.o: In function
>> `_D4core4sync6config7mktspecFKS4core3sys5posix6signal8timespeclZv':
>> src/rt/typeinfo/ti_wchar.d:(.text._D4core4sync6config7mktspecFKS4core3sys5posix6signal8timespeclZv+0xa):
>> undefined reference to `clock_gettime'
>>
>> Adding -L-lrt to the DFLAGS variable in dmd.conf fixes the problem.  That'll
>> need to be reflected in the shipped dmd.conf, assuming it's the right fix.  I
>> don't have access to the other posix platforms to see if it's needed there or not.
>>
>> Later,
>> Brad

November 20, 2010
On Saturday 20 November 2010 10:08:58 Sean Kelly wrote:
> Oops.  I'll disable the check for clock_gettime in core.sync.config.

Either keep it as is or version it so that MacOSX uses gettimeofday(), since MacOSX doesn't have gettimeofday(). In either case, it should use clock_gettime() on Linux on gettimeofday of MacOSX, and so dmd.conf should link in librt or Linux but not on MacOSX.

- Jonathan M Davis
November 20, 2010
I removed the -L-lrt from the auto-tester's dmd.conf file and it's still failing the phobos tests:

generated/linux/debug/unittest/std/datetime.o: In function `_D3std8datetime5Ticks12_staticCtor1OFNeZv': /home/braddr/sandbox/d/d-tester/client/3070/phobos-trunk/phobos/std/datetime.d:80: undefined reference to `clock_getres' generated/linux/debug/unittest/std/datetime.o: In function `_D3std8datetime7systimeFNeZS3std8datetime5Ticks': /home/braddr/sandbox/d/d-tester/client/3070/phobos-trunk/phobos/std/datetime.d:666: undefined reference to `clock_gettime'

The druntime tests do pass without linking against librt.

For now, adding librt back again so that the tests pass.

On 11/20/2010 10:08 AM, Sean Kelly wrote:
> Oops.  I'll disable the check for clock_gettime in core.sync.config.
> 
> On Nov 20, 2010, at 1:33 AM, Brad Roberts wrote:
> 
>> ... seems to have broken both the druntime and phobos unit tests.
>>
>> http://d.puremagic.com/test-results/test.ghtml?runid=3025
>>
>> druntime's error:
>> unittest.o: In function
>> `_D4core4sync6config7mktspecFKS4core3sys5posix6signal8timespeclZv':
>> src/rt/typeinfo/ti_wchar.d:(.text._D4core4sync6config7mktspecFKS4core3sys5posix6signal8timespeclZv+0xa):
>> undefined reference to `clock_gettime'
>>
>> phobos' error:
>> unittest.o: In function
>> `_D4core4sync6config7mktspecFKS4core3sys5posix6signal8timespeclZv':
>> src/rt/typeinfo/ti_wchar.d:(.text._D4core4sync6config7mktspecFKS4core3sys5posix6signal8timespeclZv+0xa):
>> undefined reference to `clock_gettime'
>>
>> Adding -L-lrt to the DFLAGS variable in dmd.conf fixes the problem.  That'll
>> need to be reflected in the shipped dmd.conf, assuming it's the right fix.  I
>> don't have access to the other posix platforms to see if it's needed there or not.
>>
>> Later,
>> Brad

November 20, 2010
On Saturday 20 November 2010 18:33:35 Brad Roberts wrote:
> I removed the -L-lrt from the auto-tester's dmd.conf file and it's still failing the phobos tests:
> 
> generated/linux/debug/unittest/std/datetime.o: In function `_D3std8datetime5Ticks12_staticCtor1OFNeZv': /home/braddr/sandbox/d/d-tester/client/3070/phobos-trunk/phobos/std/datetim e.d:80: undefined reference to `clock_getres' generated/linux/debug/unittest/std/datetime.o: In function `_D3std8datetime7systimeFNeZS3std8datetime5Ticks': /home/braddr/sandbox/d/d-tester/client/3070/phobos-trunk/phobos/std/datetim e.d:666: undefined reference to `clock_gettime'
> 
> The druntime tests do pass without linking against librt.
> 
> For now, adding librt back again so that the tests pass.

Well, the current version of std.datetime in Phobos checks whether clock_gettime() is available both for using clock_gettime() and for using clock_getres(). Both are in librt. Why std.datetime would try to use clock_getres() when clock_gettime() is unavailable, I don't know.

Really, the ideal situation is that clock_gettime(), clock_gettres(), etc. are available and used by the time code. That requires linking in librt. Without that, you cannot have a monotonic clock or a real time clock on Linux. This is particularly bad for StopWatch and benchmarking code, but it harms the accuracy of the time code in general. So, I really think that we should have clock_gettime() and clock_getres() in druntime with -L-lrt in the dmd.conf for Linux. Unfortunately, they aren't on the Mac, so the time code is going to have to use whatever the proper function calls are on the Mac, and clock_getttime() and company will have to be properly versioned so that MacOSX doesn't use them. But the Linux stuff needs them.

- Jonathan M Davis
November 20, 2010
Le 2010-11-20 ? 4:43, Jonathan M Davis a ?crit :

> librt is required for clock_gettime(), so that is the correct fix. Apparently, MacOS doesn't have clock_gettime(), so it will continue to use gettimeofday() and won't need librt (it probably isn't on the system anyway, or it would have clock_gettime()). I have no idea about FreeBSD.

I think you can use mach_absolute_time() for monotonic time on OS X. See this technote: <http://developer.apple.com/library/mac/qa/qa2004/qa1398.html>


-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/