Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

After considerable testing/frustration, I have determined that the use of POSIX::times() in my Serial I/O application is causing blocks of serial input characters to be occassionally lost (presumably because interrupts, or perhaps task switching, are being disabled for too long). I am using POSIX::times() simply to measure elapsed time with greater than one second resolution (e.g. for receive timeouts).

I looked on CPAN for the "source" code to POSIX, but did not find "enough" code to determine what "times" is doing. I have not used Timer::HiRes as I was hoping to stay with core components for this application.

Configuration: Redhat 9, Perl 5.8.0, 1 or 2 serial ports at 19,200 using POSIX::termios (works fine w/o POSIX::times).

Questions:
1. Does anyone know what the POSIX::times routine is doing ?
2. If I limit myself to one second resolution with "time" am I likely to eliminate the interrupt overrun problem ?
3. When a module is implemented using XS, is all of the code present in a *.pm module, or is there another file somewhere else ?

Thanks.

Replies are listed 'Best First'.
Re: POSIX::times() cause SIO overrun
by Thelonius (Priest) on Mar 05, 2004 at 17:56 UTC
    The POSIX.xs is in the main perl source code distribution. Here's the code for times():
    void times() PPCODE: struct tms tms; clock_t realtime; realtime = times( &tms ); EXTEND(SP,5); PUSHs( sv_2mortal( newSViv( (IV) realtime ) ) ); PUSHs( sv_2mortal( newSViv( (IV) tms.tms_utime ) ) ); PUSHs( sv_2mortal( newSViv( (IV) tms.tms_stime ) ) ); PUSHs( sv_2mortal( newSViv( (IV) tms.tms_cutime ) ) ); PUSHs( sv_2mortal( newSViv( (IV) tms.tms_cstime ) ) );
    It's hard to see how that could cause problems or take much time to return.