utimensat UTIME_NOW granularity bug

Eric Blake ebb9@byu.net
Fri Oct 9 12:46:00 GMT 2009


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Christopher Faylor on 10/8/2009 10:58 PM:
> 
> I don't like "MILLION" or "BILLION".  I think a real number is clearer
> for that.  Maybe it's jsut me but when I see million I can't help myself
> from checking to see if it's 1000000 or 1024*1024.  And, if you're going
> to assign constants to 1 with a bunch of zeros where do you draw the
> line?

OK, here's the respin without the churn.

> 
> It looks like you either don't need the systime() call or it should
> call systime_ns.

Done.  hires_us still uses systime().

> 
>>       long long x = time_in->tv_sec * NSPERSEC +
>> -			    time_in->tv_nsec / (NSPERSEC/100000) + FACTOR;
>> +			    time_in->tv_nsec / (BILLION / NSPERSEC) + FACTOR;
> 
> I'm too tired now to figure out why you switched these but it seems
> odd that you switched the numerator and denominator  here but
> 
>>   long long x = time_in->tv_sec * NSPERSEC +
>> -			time_in->tv_usec * (NSPERSEC/1000000) + FACTOR;
>> +			time_in->tv_usec * (NSPERSEC / MILLION) + FACTOR;

Because the number 100000 is unrelated to anything else in this file; just
because NSPERSEC/1000000 gives the right answer doesn't mean it expresses
the right equation.  We are really calculating these two values:

tv_nsec / 100 (nsecs) - scaling down
tv_nsec * 10 (usecs) - scaling up

so that x will be in terms of 100ns ticks.  The relations should be:

/ 100 = 1000000000/NSPERSEC = 1000000000/10000000
*  10 =   NSPERSEC/1000000  =   10000000/1000000

since NSPERSEC falls in between nanoseconds and microseconds.

(By the way, I love git - it makes it very easy to rebase a patch against
CVS).

2009-10-09  Eric Blake  <ebb9@byu.net>

	* hires.h (hires_ms): Change initime_us to initime_ns, with 10x
	more resolution.
	(hires_ms::nsecs): New prototype.
	(hires_ms::usecs, hires_ms::msecs, hires_ms::uptime): Adjust.
	* times.cc (systime_ns): New helper function.
	(hires_ms::prime): Use it for more resolution.
	(hires_ms::usecs): Change to...
	(hires_ms::nsecs): ...with more resolution.
	(clock_gettime): Use more resolution.
	(systime): Rewrite in terms of systime_ns.
	(timespec_to_filetime): Rewrite math to reflect true operation.
	* fhandler_disk_file.cc (utimens_fs): Get current time before
	opening handle, using higher resolution.

- --
Don't work too hard, make some time for fun as well!

Eric Blake             ebb9@byu.net
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkrPMH8ACgkQ84KuGfSFAYA9jgCfa+431ch8i/qqCgFFNMgqCUy2
6qYAoJhUWLC0DNaRawytPNM+LYpzixCm
=3A7g
-----END PGP SIGNATURE-----
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: cygwin.patch30
URL: <http://cygwin.com/pipermail/cygwin-patches/attachments/20091009/a652d1d5/attachment.ksh>


More information about the Cygwin-patches mailing list