1package Time::HiRes;
2
3{ use 5.006; }
4use strict;
5
6require Exporter;
7use XSLoader ();
8
9our @ISA = qw(Exporter);
10
11our @EXPORT = qw( );
12# More or less this same list is in Makefile.PL.  Should unify.
13our @EXPORT_OK = qw (usleep sleep ualarm alarm gettimeofday time tv_interval
14                 getitimer setitimer nanosleep clock_gettime clock_getres
15                 clock clock_nanosleep
16                 CLOCKS_PER_SEC
17                 CLOCK_BOOTTIME
18                 CLOCK_HIGHRES
19                 CLOCK_MONOTONIC
20                 CLOCK_MONOTONIC_COARSE
21                 CLOCK_MONOTONIC_FAST
22                 CLOCK_MONOTONIC_PRECISE
23                 CLOCK_MONOTONIC_RAW
24                 CLOCK_PROCESS_CPUTIME_ID
25                 CLOCK_PROF
26                 CLOCK_REALTIME
27                 CLOCK_REALTIME_COARSE
28                 CLOCK_REALTIME_FAST
29                 CLOCK_REALTIME_PRECISE
30                 CLOCK_REALTIME_RAW
31                 CLOCK_SECOND
32                 CLOCK_SOFTTIME
33                 CLOCK_THREAD_CPUTIME_ID
34                 CLOCK_TIMEOFDAY
35                 CLOCK_UPTIME
36                 CLOCK_UPTIME_COARSE
37                 CLOCK_UPTIME_FAST
38                 CLOCK_UPTIME_PRECISE
39                 CLOCK_UPTIME_RAW
40                 CLOCK_VIRTUAL
41                 ITIMER_PROF
42                 ITIMER_REAL
43                 ITIMER_REALPROF
44                 ITIMER_VIRTUAL
45                 TIMER_ABSTIME
46                 d_usleep d_ualarm d_gettimeofday d_getitimer d_setitimer
47                 d_nanosleep d_clock_gettime d_clock_getres
48                 d_clock d_clock_nanosleep d_hires_stat
49                 d_futimens d_utimensat d_hires_utime
50                 stat lstat utime
51                );
52
53our $VERSION = '1.9775';
54our $XS_VERSION = $VERSION;
55$VERSION = eval $VERSION;
56
57our $AUTOLOAD;
58sub AUTOLOAD {
59    my $constname;
60    ($constname = $AUTOLOAD) =~ s/.*:://;
61    # print "AUTOLOAD: constname = $constname ($AUTOLOAD)\n";
62    die "&Time::HiRes::constant not defined" if $constname eq 'constant';
63    my ($error, $val) = constant($constname);
64    # print "AUTOLOAD: error = $error, val = $val\n";
65    if ($error) {
66        my (undef,$file,$line) = caller;
67        die "$error at $file line $line.\n";
68    }
69    {
70        no strict 'refs';
71        *$AUTOLOAD = sub { $val };
72    }
73    goto &$AUTOLOAD;
74}
75
76sub import {
77    my $this = shift;
78    for my $i (@_) {
79        if (($i eq 'clock_getres'    && !&d_clock_getres)    ||
80            ($i eq 'clock_gettime'   && !&d_clock_gettime)   ||
81            ($i eq 'clock_nanosleep' && !&d_clock_nanosleep) ||
82            ($i eq 'clock'           && !&d_clock)           ||
83            ($i eq 'nanosleep'       && !&d_nanosleep)       ||
84            ($i eq 'usleep'          && !&d_usleep)          ||
85            ($i eq 'utime'           && !&d_hires_utime)     ||
86            ($i eq 'ualarm'          && !&d_ualarm)) {
87            require Carp;
88            Carp::croak("Time::HiRes::$i(): unimplemented in this platform");
89        }
90    }
91    Time::HiRes->export_to_level(1, $this, @_);
92}
93
94XSLoader::load( 'Time::HiRes', $XS_VERSION );
95
96# Preloaded methods go here.
97
98sub tv_interval {
99    # probably could have been done in C
100    my ($a, $b) = @_;
101    $b = [gettimeofday()] unless defined($b);
102    (${$b}[0] - ${$a}[0]) + ((${$b}[1] - ${$a}[1]) / 1_000_000);
103}
104
105# Autoload methods go after =cut, and are processed by the autosplit program.
106
1071;
108__END__
109
110=head1 NAME
111
112Time::HiRes - High resolution alarm, sleep, gettimeofday, interval timers
113
114=head1 SYNOPSIS
115
116  use Time::HiRes qw( usleep ualarm gettimeofday tv_interval nanosleep
117                      clock_gettime clock_getres clock_nanosleep clock
118                      stat lstat utime);
119
120  usleep ($microseconds);
121  nanosleep ($nanoseconds);
122
123  ualarm ($microseconds);
124  ualarm ($microseconds, $interval_microseconds);
125
126  $t0 = [gettimeofday];
127  ($seconds, $microseconds) = gettimeofday;
128
129  $elapsed = tv_interval ( $t0, [$seconds, $microseconds]);
130  $elapsed = tv_interval ( $t0, [gettimeofday]);
131  $elapsed = tv_interval ( $t0 );
132
133  use Time::HiRes qw ( time alarm sleep );
134
135  $now_fractions = time;
136  sleep ($floating_seconds);
137  alarm ($floating_seconds);
138  alarm ($floating_seconds, $floating_interval);
139
140  use Time::HiRes qw( setitimer getitimer );
141
142  setitimer ($which, $floating_seconds, $floating_interval );
143  getitimer ($which);
144
145  use Time::HiRes qw( clock_gettime clock_getres clock_nanosleep
146                      ITIMER_REAL ITIMER_VIRTUAL ITIMER_PROF
147                      ITIMER_REALPROF );
148
149  $realtime   = clock_gettime(CLOCK_REALTIME);
150  $resolution = clock_getres(CLOCK_REALTIME);
151
152  clock_nanosleep(CLOCK_REALTIME, 1.5e9);
153  clock_nanosleep(CLOCK_REALTIME, time()*1e9 + 10e9, TIMER_ABSTIME);
154
155  my $ticktock = clock();
156
157  use Time::HiRes qw( stat lstat );
158
159  my @stat = stat("file");
160  my @stat = stat(FH);
161  my @stat = lstat("file");
162
163  use Time::HiRes qw( utime );
164  utime $floating_seconds, $floating_seconds, file...;
165
166=head1 DESCRIPTION
167
168The C<Time::HiRes> module implements a Perl interface to the
169C<usleep>, C<nanosleep>, C<ualarm>, C<gettimeofday>, and
170C<setitimer>/C<getitimer> system calls, in other words, high
171resolution time and timers. See the L</EXAMPLES> section below and the
172test scripts for usage; see your system documentation for the
173description of the underlying C<nanosleep> or C<usleep>, C<ualarm>,
174C<gettimeofday>, and C<setitimer>/C<getitimer> calls.
175
176If your system lacks C<gettimeofday()> or an emulation of it you don't
177get C<gettimeofday()> or the one-argument form of C<tv_interval()>.
178If your system lacks all of C<nanosleep()>, C<usleep()>,
179C<select()>, and C<poll>, you don't get C<Time::HiRes::usleep()>,
180C<Time::HiRes::nanosleep()>, or C<Time::HiRes::sleep()>.
181If your system lacks both C<ualarm()> and C<setitimer()> you don't get
182C<Time::HiRes::ualarm()> or C<Time::HiRes::alarm()>.
183
184If you try to import an unimplemented function in the C<use> statement
185it will fail at compile time.
186
187If your subsecond sleeping is implemented with C<nanosleep()> instead
188of C<usleep()>, you can mix subsecond sleeping with signals since
189C<nanosleep()> does not use signals.  This, however, is not portable,
190and you should first check for the truth value of
191C<&Time::HiRes::d_nanosleep> to see whether you have nanosleep, and
192then carefully read your C<nanosleep()> C API documentation for any
193peculiarities.
194
195If you are using C<nanosleep> for something else than mixing sleeping
196with signals, give some thought to whether Perl is the tool you should
197be using for work requiring nanosecond accuracies.
198
199Remember that unless you are working on a I<hard realtime> system,
200any clocks and timers will be imprecise, especially so if you are working
201in a pre-emptive multiuser system.  Understand the difference between
202I<wallclock time> and process time (in UNIX-like systems the sum of
203I<user> and I<system> times).  Any attempt to sleep for X seconds will
204most probably end up sleeping B<more> than that, but don't be surprised
205if you end up sleeping slightly B<less>.
206
207The following functions can be imported from this module.
208No functions are exported by default.
209
210=over 4
211
212=item gettimeofday ()
213
214In array context returns a two-element array with the seconds and
215microseconds since the epoch.  In scalar context returns floating
216seconds like C<Time::HiRes::time()> (see below).
217
218=item usleep ( $useconds )
219
220Sleeps for the number of microseconds (millionths of a second)
221specified.  Returns the number of microseconds actually slept.
222Can sleep for more than one second, unlike the C<usleep> system call.
223Can also sleep for zero seconds, which often works like a I<thread yield>.
224See also L<C<Time::HiRes::sleep()>|/sleep ( $floating_seconds )>, and
225L<C<clock_nanosleep()>|/clock_nanosleep ( $which, $nanoseconds, $flags = 0)>.
226
227Do not expect usleep() to be exact down to one microsecond.
228
229=item nanosleep ( $nanoseconds )
230
231Sleeps for the number of nanoseconds (1e9ths of a second) specified.
232Returns the number of nanoseconds actually slept (accurate only to
233microseconds, the nearest thousand of them).  Can sleep for more than
234one second.  Can also sleep for zero seconds, which often works like
235a I<thread yield>.  See also
236L<C<Time::HiRes::sleep()>|/sleep ( $floating_seconds )>,
237L<C<Time::HiRes::usleep()>|/usleep ( $useconds )>, and
238L<C<clock_nanosleep()>|/clock_nanosleep ( $which, $nanoseconds, $flags = 0)>.
239
240Do not expect nanosleep() to be exact down to one nanosecond.
241Getting even accuracy of one thousand nanoseconds is good.
242
243=item ualarm ( $useconds [, $interval_useconds ] )
244
245Issues a C<ualarm> call; the C<$interval_useconds> is optional and
246will be zero if unspecified, resulting in C<alarm>-like behaviour.
247
248Returns the remaining time in the alarm in microseconds, or C<undef>
249if an error occurred.
250
251ualarm(0) will cancel an outstanding ualarm().
252
253Note that the interaction between alarms and sleeps is unspecified.
254
255=item tv_interval
256
257tv_interval ( $ref_to_gettimeofday [, $ref_to_later_gettimeofday] )
258
259Returns the floating seconds between the two times, which should have
260been returned by C<gettimeofday()>. If the second argument is omitted,
261then the current time is used.
262
263=item time ()
264
265Returns a floating seconds since the epoch. This function can be
266imported, resulting in a nice drop-in replacement for the C<time>
267provided with core Perl; see the L</EXAMPLES> below.
268
269B<NOTE 1>: This higher resolution timer can return values either less
270or more than the core C<time()>, depending on whether your platform
271rounds the higher resolution timer values up, down, or to the nearest second
272to get the core C<time()>, but naturally the difference should be never
273more than half a second.  See also L</clock_getres>, if available
274in your system.
275
276B<NOTE 2>: Since Sunday, September 9th, 2001 at 01:46:40 AM GMT, when
277the C<time()> seconds since epoch rolled over to 1_000_000_000, the
278default floating point format of Perl and the seconds since epoch have
279conspired to produce an apparent bug: if you print the value of
280C<Time::HiRes::time()> you seem to be getting only five decimals, not
281six as promised (microseconds).  Not to worry, the microseconds are
282there (assuming your platform supports such granularity in the first
283place).  What is going on is that the default floating point format of
284Perl only outputs 15 digits.  In this case that means ten digits
285before the decimal separator and five after.  To see the microseconds
286you can use either C<printf>/C<sprintf> with C<"%.6f">, or the
287C<gettimeofday()> function in list context, which will give you the
288seconds and microseconds as two separate values.
289
290=item sleep ( $floating_seconds )
291
292Sleeps for the specified amount of seconds.  Returns the number of
293seconds actually slept (a floating point value).  This function can
294be imported, resulting in a nice drop-in replacement for the C<sleep>
295provided with perl, see the L</EXAMPLES> below.
296
297Note that the interaction between alarms and sleeps is unspecified.
298
299=item alarm ( $floating_seconds [, $interval_floating_seconds ] )
300
301The C<SIGALRM> signal is sent after the specified number of seconds.
302Implemented using C<setitimer()> if available, C<ualarm()> if not.
303The C<$interval_floating_seconds> argument is optional and will be
304zero if unspecified, resulting in C<alarm()>-like behaviour.  This
305function can be imported, resulting in a nice drop-in replacement for
306the C<alarm> provided with perl, see the L</EXAMPLES> below.
307
308Returns the remaining time in the alarm in seconds, or C<undef>
309if an error occurred.
310
311B<NOTE 1>: With some combinations of operating systems and Perl
312releases C<SIGALRM> restarts C<select()>, instead of interrupting it.
313This means that an C<alarm()> followed by a C<select()> may together
314take the sum of the times specified for the C<alarm()> and the
315C<select()>, not just the time of the C<alarm()>.
316
317Note that the interaction between alarms and sleeps is unspecified.
318
319=item setitimer ( $which, $floating_seconds [, $interval_floating_seconds ] )
320
321Start up an interval timer: after a certain time, a signal ($which) arrives,
322and more signals may keep arriving at certain intervals.  To disable
323an "itimer", use C<$floating_seconds> of zero.  If the
324C<$interval_floating_seconds> is set to zero (or unspecified), the
325timer is disabled B<after> the next delivered signal.
326
327Use of interval timers may interfere with C<alarm()>, C<sleep()>,
328and C<usleep()>.  In standard-speak the "interaction is unspecified",
329which means that I<anything> may happen: it may work, it may not.
330
331In scalar context, the remaining time in the timer is returned.
332
333In list context, both the remaining time and the interval are returned.
334
335There are usually three or four interval timers (signals) available: the
336C<$which> can be C<ITIMER_REAL>, C<ITIMER_VIRTUAL>, C<ITIMER_PROF>, or
337C<ITIMER_REALPROF>.  Note that which ones are available depends: true
338UNIX platforms usually have the first three, but only Solaris seems to
339have C<ITIMER_REALPROF> (which is used to profile multithreaded programs).
340Win32 unfortunately does not have interval timers.
341
342C<ITIMER_REAL> results in C<alarm()>-like behaviour.  Time is counted in
343I<real time>; that is, wallclock time.  C<SIGALRM> is delivered when
344the timer expires.
345
346C<ITIMER_VIRTUAL> counts time in (process) I<virtual time>; that is,
347only when the process is running.  In multiprocessor/user/CPU systems
348this may be more or less than real or wallclock time.  (This time is
349also known as the I<user time>.)  C<SIGVTALRM> is delivered when the
350timer expires.
351
352C<ITIMER_PROF> counts time when either the process virtual time or when
353the operating system is running on behalf of the process (such as I/O).
354(This time is also known as the I<system time>.)  (The sum of user
355time and system time is known as the I<CPU time>.)  C<SIGPROF> is
356delivered when the timer expires.  C<SIGPROF> can interrupt system calls.
357
358The semantics of interval timers for multithreaded programs are
359system-specific, and some systems may support additional interval
360timers.  For example, it is unspecified which thread gets the signals.
361See your L<C<setitimer(2)>> documentation.
362
363=item getitimer ( $which )
364
365Return the remaining time in the interval timer specified by C<$which>.
366
367In scalar context, the remaining time is returned.
368
369In list context, both the remaining time and the interval are returned.
370The interval is always what you put in using C<setitimer()>.
371
372=item clock_gettime ( $which )
373
374Return as seconds the current value of the POSIX high resolution timer
375specified by C<$which>.  All implementations that support POSIX high
376resolution timers are supposed to support at least the C<$which> value
377of C<CLOCK_REALTIME>, which is supposed to return results close to the
378results of C<gettimeofday>, or the number of seconds since 00:00:00:00
379January 1, 1970 Greenwich Mean Time (GMT).  Do not assume that
380CLOCK_REALTIME is zero, it might be one, or something else.
381Another potentially useful (but not available everywhere) value is
382C<CLOCK_MONOTONIC>, which guarantees a monotonically increasing time
383value (unlike time() or gettimeofday(), which can be adjusted).
384See your system documentation for other possibly supported values.
385
386=item clock_getres ( $which )
387
388Return as seconds the resolution of the POSIX high resolution timer
389specified by C<$which>.  All implementations that support POSIX high
390resolution timers are supposed to support at least the C<$which> value
391of C<CLOCK_REALTIME>, see L</clock_gettime>.
392
393B<NOTE>: the resolution returned may be highly optimistic.  Even if
394the resolution is high (a small number), all it means is that you'll
395be able to specify the arguments to clock_gettime() and clock_nanosleep()
396with that resolution.  The system might not actually be able to measure
397events at that resolution, and the various overheads and the overall system
398load are certain to affect any timings.
399
400=item clock_nanosleep ( $which, $nanoseconds, $flags = 0)
401
402Sleeps for the number of nanoseconds (1e9ths of a second) specified.
403Returns the number of nanoseconds actually slept.  The $which is the
404"clock id", as with clock_gettime() and clock_getres().  The flags
405default to zero but C<TIMER_ABSTIME> can specified (must be exported
406explicitly) which means that C<$nanoseconds> is not a time interval
407(as is the default) but instead an absolute time.  Can sleep for more
408than one second.  Can also sleep for zero seconds, which often works
409like a I<thread yield>.  See also
410L<C<Time::HiRes::sleep()>|/sleep ( $floating_seconds )>,
411L<C<Time::HiRes::usleep()>|/usleep ( $useconds )>, and
412L<C<Time::HiRes::nanosleep()>|/nanosleep ( $nanoseconds )>.
413
414Do not expect clock_nanosleep() to be exact down to one nanosecond.
415Getting even accuracy of one thousand nanoseconds is good.
416
417=item clock()
418
419Return as seconds the I<process time> (user + system time) spent by
420the process since the first call to clock() (the definition is B<not>
421"since the start of the process", though if you are lucky these times
422may be quite close to each other, depending on the system).  What this
423means is that you probably need to store the result of your first call
424to clock(), and subtract that value from the following results of clock().
425
426The time returned also includes the process times of the terminated
427child processes for which wait() has been executed.  This value is
428somewhat like the second value returned by the times() of core Perl,
429but not necessarily identical.  Note that due to backward
430compatibility limitations the returned value may wrap around at about
4312147 seconds or at about 36 minutes.
432
433=item stat
434
435=item stat FH
436
437=item stat EXPR
438
439=item lstat
440
441=item lstat FH
442
443=item lstat EXPR
444
445As L<perlfunc/stat> or L<perlfunc/lstat>
446but with the access/modify/change file timestamps
447in subsecond resolution, if the operating system and the filesystem
448both support such timestamps.  To override the standard stat():
449
450    use Time::HiRes qw(stat);
451
452Test for the value of &Time::HiRes::d_hires_stat to find out whether
453the operating system supports subsecond file timestamps: a value
454larger than zero means yes. There are unfortunately no easy
455ways to find out whether the filesystem supports such timestamps.
456UNIX filesystems often do; NTFS does; FAT doesn't (FAT timestamp
457granularity is B<two> seconds).
458
459A zero return value of &Time::HiRes::d_hires_stat means that
460Time::HiRes::stat is a no-op passthrough for CORE::stat()
461(and likewise for lstat),
462and therefore the timestamps will stay integers.  The same
463thing will happen if the filesystem does not do subsecond timestamps,
464even if the &Time::HiRes::d_hires_stat is non-zero.
465
466In any case do not expect nanosecond resolution, or even a microsecond
467resolution.  Also note that the modify/access timestamps might have
468different resolutions, and that they need not be synchronized, e.g.
469if the operations are
470
471    write
472    stat # t1
473    read
474    stat # t2
475
476the access time stamp from t2 need not be greater-than the modify
477time stamp from t1: it may be equal or I<less>.
478
479=item utime LIST
480
481As L<perlfunc/utime>
482but with the ability to set the access/modify file timestamps
483in subsecond resolution, if the operating system and the filesystem,
484and the mount options of the filesystem, all support such timestamps.
485
486To override the standard utime():
487
488    use Time::HiRes qw(utime);
489
490Test for the value of &Time::HiRes::d_hires_utime to find out whether
491the operating system supports setting subsecond file timestamps.
492
493As with CORE::utime(), passing undef as both the atime and mtime will
494call the syscall with a NULL argument.
495
496The actual achievable subsecond resolution depends on the combination
497of the operating system and the filesystem.
498
499Modifying the timestamps may not be possible at all: for example, the
500C<noatime> filesystem mount option may prohibit you from changing the
501access time timestamp.
502
503Returns the number of files successfully changed.
504
505=back
506
507=head1 EXAMPLES
508
509  use Time::HiRes qw(usleep ualarm gettimeofday tv_interval);
510
511  $microseconds = 750_000;
512  usleep($microseconds);
513
514  # signal alarm in 2.5s & every .1s thereafter
515  ualarm(2_500_000, 100_000);
516  # cancel that ualarm
517  ualarm(0);
518
519  # get seconds and microseconds since the epoch
520  ($s, $usec) = gettimeofday();
521
522  # measure elapsed time
523  # (could also do by subtracting 2 gettimeofday return values)
524  $t0 = [gettimeofday];
525  # do bunch of stuff here
526  $t1 = [gettimeofday];
527  # do more stuff here
528  $t0_t1 = tv_interval $t0, $t1;
529
530  $elapsed = tv_interval ($t0, [gettimeofday]);
531  $elapsed = tv_interval ($t0); # equivalent code
532
533  #
534  # replacements for time, alarm and sleep that know about
535  # floating seconds
536  #
537  use Time::HiRes;
538  $now_fractions = Time::HiRes::time;
539  Time::HiRes::sleep (2.5);
540  Time::HiRes::alarm (10.6666666);
541
542  use Time::HiRes qw ( time alarm sleep );
543  $now_fractions = time;
544  sleep (2.5);
545  alarm (10.6666666);
546
547  # Arm an interval timer to go off first at 10 seconds and
548  # after that every 2.5 seconds, in process virtual time
549
550  use Time::HiRes qw ( setitimer ITIMER_VIRTUAL time );
551
552  $SIG{VTALRM} = sub { print time, "\n" };
553  setitimer(ITIMER_VIRTUAL, 10, 2.5);
554
555  use Time::HiRes qw( clock_gettime clock_getres CLOCK_REALTIME );
556  # Read the POSIX high resolution timer.
557  my $high = clock_gettime(CLOCK_REALTIME);
558  # But how accurate we can be, really?
559  my $reso = clock_getres(CLOCK_REALTIME);
560
561  use Time::HiRes qw( clock_nanosleep TIMER_ABSTIME );
562  clock_nanosleep(CLOCK_REALTIME, 1e6);
563  clock_nanosleep(CLOCK_REALTIME, 2e9, TIMER_ABSTIME);
564
565  use Time::HiRes qw( clock );
566  my $clock0 = clock();
567  ... # Do something.
568  my $clock1 = clock();
569  my $clockd = $clock1 - $clock0;
570
571  use Time::HiRes qw( stat );
572  my ($atime, $mtime, $ctime) = (stat("istics"))[8, 9, 10];
573
574=head1 C API
575
576In addition to the perl API described above, a C API is available for
577extension writers.  The following C functions are available in the
578modglobal hash:
579
580  name             C prototype
581  ---------------  ----------------------
582  Time::NVtime     NV (*)()
583  Time::U2time     void (*)(pTHX_ UV ret[2])
584
585Both functions return equivalent information (like C<gettimeofday>)
586but with different representations.  The names C<NVtime> and C<U2time>
587were selected mainly because they are operating system independent.
588(C<gettimeofday> is Unix-centric, though some platforms like Win32 and
589VMS have emulations for it.)
590
591Here is an example of using C<NVtime> from C:
592
593  NV (*myNVtime)(); /* Returns -1 on failure. */
594  SV **svp = hv_fetchs(PL_modglobal, "Time::NVtime", 0);
595  if (!svp)         croak("Time::HiRes is required");
596  if (!SvIOK(*svp)) croak("Time::NVtime isn't a function pointer");
597  myNVtime = INT2PTR(NV(*)(), SvIV(*svp));
598  printf("The current time is: %" NVff "\n", (*myNVtime)());
599
600=head1 DIAGNOSTICS
601
602=head2 useconds or interval more than ...
603
604In ualarm() you tried to use number of microseconds or interval (also
605in microseconds) more than 1_000_000 and setitimer() is not available
606in your system to emulate that case.
607
608=head2 negative time not invented yet
609
610You tried to use a negative time argument.
611
612=head2 internal error: useconds < 0 (unsigned ... signed ...)
613
614Something went horribly wrong-- the number of microseconds that cannot
615become negative just became negative.  Maybe your compiler is broken?
616
617=head2 useconds or uinterval equal to or more than 1000000
618
619In some platforms it is not possible to get an alarm with subsecond
620resolution and later than one second.
621
622=head2 unimplemented in this platform
623
624Some calls simply aren't available, real or emulated, on every platform.
625
626=head1 CAVEATS
627
628Notice that the core C<time()> maybe rounding rather than truncating.
629What this means is that the core C<time()> may be reporting the time
630as one second later than C<gettimeofday()> and C<Time::HiRes::time()>.
631
632Adjusting the system clock (either manually or by services like ntp)
633may cause problems, especially for long running programs that assume
634a monotonously increasing time (note that all platforms do not adjust
635time as gracefully as UNIX ntp does).  For example in Win32 (and derived
636platforms like Cygwin and MinGW) the Time::HiRes::time() may temporarily
637drift off from the system clock (and the original time())  by up to 0.5
638seconds. Time::HiRes will notice this eventually and recalibrate.
639Note that since Time::HiRes 1.77 the clock_gettime(CLOCK_MONOTONIC)
640might help in this (in case your system supports CLOCK_MONOTONIC).
641
642Some systems have APIs but not implementations: for example QNX and Haiku
643have the interval timer APIs but not the functionality.
644
645In pre-Sierra macOS (pre-10.12, OS X) clock_getres(), clock_gettime()
646and clock_nanosleep() are emulated using the Mach timers; as a side
647effect of being emulated the CLOCK_REALTIME and CLOCK_MONOTONIC are
648the same timer.
649
650gnukfreebsd seems to have non-functional futimens() and utimensat()
651(at least as of 10.1): therefore the hires utime() does not work.
652
653=head1 SEE ALSO
654
655Perl modules L<BSD::Resource>, L<Time::TAI64>.
656
657Your system documentation for L<C<clock(3)>>, L<C<clock_gettime(2)>>,
658L<C<clock_getres(3)>>, L<C<clock_nanosleep(3)>>, L<C<clock_settime(2)>>,
659L<C<getitimer(2)>>, L<C<gettimeofday(2)>>, L<C<setitimer(2)>>, L<C<sleep(3)>>,
660L<C<stat(2)>>, L<C<ualarm(3)>>.
661
662=head1 AUTHORS
663
664D. Wegscheid <wegscd@whirlpool.com>
665R. Schertler <roderick@argon.org>
666J. Hietaniemi <jhi@iki.fi>
667G. Aas <gisle@aas.no>
668
669=head1 COPYRIGHT AND LICENSE
670
671Copyright (c) 1996-2002 Douglas E. Wegscheid.  All rights reserved.
672
673Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008 Jarkko Hietaniemi.
674All rights reserved.
675
676Copyright (C) 2011, 2012, 2013 Andrew Main (Zefram) <zefram@fysh.org>
677
678This program is free software; you can redistribute it and/or modify
679it under the same terms as Perl itself.
680
681=cut
682