From bfe77af11017ea97c11e4b591882765e2e421721 Mon Sep 17 00:00:00 2001 From: Steve Peters Date: Wed, 3 Jan 2007 01:46:41 +0000 Subject: [PATCH] Upgrade to Time-HiRes-1.9704 p4raw-id: //depot/perl@29671 --- ext/Time/HiRes/Changes | 6 +++++ ext/Time/HiRes/HiRes.pm | 60 +++++++++++++++++++++++++++++++++++------------- ext/Time/HiRes/HiRes.xs | 2 +- ext/Time/HiRes/t/HiRes.t | 9 ++++---- 4 files changed, 56 insertions(+), 21 deletions(-) diff --git a/ext/Time/HiRes/Changes b/ext/Time/HiRes/Changes index 43e5300..dc4fe51 100644 --- a/ext/Time/HiRes/Changes +++ b/ext/Time/HiRes/Changes @@ -1,5 +1,11 @@ Revision history for the Perl extension Time::HiRes. +1.9704 [2007-01-01] + - allow 10% of slop in test #14 (testing difference between + CORE::time() and Time::HiRes::time()), there seem to be often + transient failures from Perl smoke builds on this test + - small pod tweaks + 1.9703 [2006-12-08] - use int main(int argc, char **argv) consistently in Makefile.PL, should help with diff --git a/ext/Time/HiRes/HiRes.pm b/ext/Time/HiRes/HiRes.pm index d1e4333..b666341 100644 --- a/ext/Time/HiRes/HiRes.pm +++ b/ext/Time/HiRes/HiRes.pm @@ -23,7 +23,7 @@ require DynaLoader; stat ); -$VERSION = '1.9703'; +$VERSION = '1.9704'; $XS_VERSION = $VERSION; $VERSION = eval $VERSION; @@ -108,12 +108,14 @@ Time::HiRes - High resolution alarm, sleep, gettimeofday, interval timers alarm ($floating_seconds); alarm ($floating_seconds, $floating_interval); - use Time::HiRes qw( setitimer getitimer - ITIMER_REAL ITIMER_VIRTUAL ITIMER_PROF ITIMER_REALPROF ); + use Time::HiRes qw( setitimer getitimer ); setitimer ($which, $floating_seconds, $floating_interval ); getitimer ($which); + use Time::HiRes qw( clock_gettime clock_getres clock_nanosleep + ITIMER_REAL ITIMER_VIRTUAL ITIMER_PROF ITIMER_REALPROF ); + $realtime = clock_gettime(CLOCK_REALTIME); $resolution = clock_getres(CLOCK_REALTIME); @@ -122,6 +124,8 @@ Time::HiRes - High resolution alarm, sleep, gettimeofday, interval timers my $ticktock = clock(); + use Time::HiRes qw( stat ); + my @stat = stat("file"); my @stat = stat(FH); @@ -158,6 +162,14 @@ If you are using C for something else than mixing sleeping with signals, give some thought to whether Perl is the tool you should be using for work requiring nanosecond accuracies. +Remember that unless you are working on a I system, +any clocks and timers will be imprecise, especially so if you are working +in a pre-emptive multiuser system. Understand the difference between +I and process time (in UNIX-like systems the sum of +I and I times). Any attempt to sleep for X seconds will +most probably end up sleeping B than that, but don't be surpised +if you end up sleeping slightly B. + The following functions can be imported from this module. No functions are exported by default. @@ -172,9 +184,9 @@ seconds like C (see below). =item usleep ( $useconds ) Sleeps for the number of microseconds (millionths of a second) -specified. Returns the number of microseconds actually slept. Can -sleep for more than one second, unlike the C system call. Can -also sleep for zero seconds, which often works like a I. +specified. Returns the number of microseconds actually slept. +Can sleep for more than one second, unlike the C system call. +Can also sleep for zero seconds, which often works like a I. See also C, C, and C. @@ -185,8 +197,8 @@ Do not expect usleep() to be exact down to one microsecond. Sleeps for the number of nanoseconds (1e9ths of a second) specified. Returns the number of nanoseconds actually slept (accurate only to microseconds, the nearest thousand of them). Can sleep for more than -one second. Can also sleep for zero seconds, which often works like a -I. See also C, +one second. Can also sleep for zero seconds, which often works like +a I. See also C, C, and C. Do not expect nanosleep() to be exact down to one nanosecond. @@ -197,6 +209,8 @@ Getting even accuracy of one thousand nanoseconds is good. Issues a C call; the C<$interval_useconds> is optional and will be zero if unspecified, resulting in C-like behaviour. +ualarm(0) will cancel an outstanding ualarm(). + Note that the interaction between alarms and sleeps is unspecified. =item tv_interval @@ -261,7 +275,7 @@ Note that the interaction between alarms and sleeps is unspecified. =item setitimer ( $which, $floating_seconds [, $interval_floating_seconds ] ) -Start up an interval timer: after a certain time, a signal arrives, +Start up an interval timer: after a certain time, a signal ($which) arrives, and more signals may keep arriving at certain intervals. To disable an "itimer", use C<$floating_seconds> of zero. If the C<$interval_floating_seconds> is set to zero (or unspecified), the @@ -275,7 +289,7 @@ In scalar context, the remaining time in the timer is returned. In list context, both the remaining time and the interval are returned. -There are usually three or four interval timers available: the +There are usually three or four interval timers (signals) available: the C<$which> can be C, C, C, or C. Note that which ones are available depends: true UNIX platforms usually have the first three, but (for example) Win32 @@ -300,7 +314,8 @@ delivered when the timer expires. C can interrupt system calls. The semantics of interval timers for multithreaded programs are system-specific, and some systems may support additional interval -timers. See your C documentation. +timers. For example, it is unspecified which thread gets the signals. +See your C documentation. =item getitimer ( $which ) @@ -385,11 +400,21 @@ granularity is B seconds). A zero return value of &Time::HiRes::d_hires_stat means that Time::HiRes::stat is a no-op passthrough for CORE::stat(), and therefore the timestamps will stay integers. The same -will happen if the filesystem does not do subsecond timestamps, +thing will happen if the filesystem does not do subsecond timestamps, even if the &Time::HiRes::d_hires_stat is non-zero. In any case do not expect nanosecond resolution, or even a microsecond -resolution. +resolution. Also note that the modify/access timestamps might have +different resolutions, and that they need not be synchronized, e.g. +if the operations are + + write + stat # t1 + read + stat # t2 + +the access time stamp from t2 need not be greater-than the modify +time stamp from t1: it may be equal or I. =back @@ -402,6 +427,8 @@ resolution. # signal alarm in 2.5s & every .1s thereafter ualarm(2_500_000, 100_000); + # cancel that ualarm + ualarm(0); # get seconds and microseconds since the epoch ($s, $usec) = gettimeofday(); @@ -521,8 +548,9 @@ might help in this (in case your system supports CLOCK_MONOTONIC). Perl modules L, L. -Your system documentation for C, C, -C, C, C, C. +Your system documentation for C, C, +C, C, C, C, +C, C, C, C, C. =head1 AUTHORS @@ -535,7 +563,7 @@ G. Aas Copyright (c) 1996-2002 Douglas E. Wegscheid. All rights reserved. -Copyright (c) 2002, 2003, 2004, 2005, 2006 Jarkko Hietaniemi. All rights reserved. +Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007 Jarkko Hietaniemi. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. diff --git a/ext/Time/HiRes/HiRes.xs b/ext/Time/HiRes/HiRes.xs index 97dbb59..fcf93bb 100644 --- a/ext/Time/HiRes/HiRes.xs +++ b/ext/Time/HiRes/HiRes.xs @@ -2,7 +2,7 @@ * * Copyright (c) 1996-2002 Douglas E. Wegscheid. All rights reserved. * - * Copyright (c) 2002,2003,2004,2005,2006 Jarkko Hietaniemi. All rights reserved. + * Copyright (c) 2002,2003,2004,2005,2006,2007 Jarkko Hietaniemi. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the same terms as Perl itself. diff --git a/ext/Time/HiRes/t/HiRes.t b/ext/Time/HiRes/t/HiRes.t index c4c2d6b..3be8d3c 100644 --- a/ext/Time/HiRes/t/HiRes.t +++ b/ext/Time/HiRes/t/HiRes.t @@ -16,7 +16,7 @@ BEGIN { $| = 1; print "1..38\n"; } END { print "not ok 1\n" unless $loaded } -use Time::HiRes 1.9701; # Remember to bump this once in a while. +use Time::HiRes 1.9704; # Remember to bump this once in a while. use Time::HiRes qw(tv_interval); $loaded = 1; @@ -228,9 +228,10 @@ unless ($have_gettimeofday) { $n++; } # $s should be, at worst, equal to $n - # (time() may be rounding down, up, or closest) - ok 14, abs($s) / $n <= 1.0, "Time::HiRes::time() not close to time()"; - print "# s = $s, n = $n, s/n = ", $s/$n, "\n"; + # (time() may be rounding down, up, or closest), + # but allow 10% of slop. + ok 14, abs($s) / $n <= 1.10, "Time::HiRes::time() not close to time()"; + print "# s = $s, n = $n, s/n = ", abs($s)/$n, "\n"; } my $has_ualarm = $Config{d_ualarm}; -- 2.7.4