[LinuxPPS] select() on a PPS FD/handle

Rodolfo Giometti giometti at enneenne.com
Thu May 2 11:52:52 CEST 2013


On Wed, May 01, 2013 at 10:23:34AM +1000, Damien Dusha wrote:
> Dear all,
> 
> I have an application that waits on several handles and hence being able to
> select on a pps handle (or, as in this instance, the raw file descriptor)
> is desirable.  However, select() appears to return immediately, reporting
> that the FD has data.  For example, the strace -p output is:

Can you report it adding the -tt option also?

> select(32, [9 23 24 25 26 27 29 30 31], [], NULL, {0, 100000}) = 1 (in
> [23], left {0, 99977})
> ioctl(23, PPS_FETCH, 0xbeeee5c8)        = 0
> gettimeofday({1367365708, 582135}, NULL) = 0
> select(32, [9 23 24 25 26 27 29 30 31], [], NULL, {0, 100000}) = 1 (in
> [23], left {0, 99986})
> ioctl(23, PPS_FETCH, 0xbeeee5c8)        = 0
> gettimeofday({1367365708, 582758}, NULL) = 0
> select(32, [9 23 24 25 2[   90.878840] pps pps0: echo assert
> [   90.882760] pps pps0: echo  clear
> 6 27 29 30 31], [], NULL, {0, 100000}) = 1 (in [23], left {0, 99987})
> ioctl(23, PPS_FETCH, 0xbeeee5c8)        = 0
> gettimeofday({1367365708, 583401}, NULL) = 0
> select(32, [9 23 24 25 26 27 29 30 31], [], NULL, {0, 100000}) = 1 (in
> [23], left {0, 99991})
> ioctl(23, PPS_FETCH, 0xbeeee5c8)        = 0
> gettimeofday({1367365708, 584043}, NULL) = 0
> select(32, [9 23 24 25 26 27 29 30 31], [], NULL, {0, 100000}) = 1 (in
> [23], left {0, 99990})
> ioctl(23, PPS_FETCH, 0xbeeee5c8)        = 0
> gettimeofday({1367365708, 584623}, NULL) = 0
> select(32, [9 23 24 25 26 27 29 30 31], [], NULL, {0, 100000}) = 1 (in
> [23], left {0, 99990})
> ioctl(23, PPS_FETCH, 0xbeeee5c8)        = 0
> gettimeofday({1367365708, 585176}, NULL) = 0
> 
> (The gettimeofday calls can safely be ignored; they are for my application
> to calculate latency)
> 
> As can be seen, the select returns after 100us or so, even through the
> timeout is 100ms, reporting that the [23] (which, in this instance, is the
> PPS FD) is waiting to be read.    The API call that follows returns
> successfully.

Which kernel version are you using?

> The API call is as follows:
> 
>     // According to RFC2783, a timeout of zero will return immediately
>     struct timespec zero;
>     zero.tv_sec = 0;
>     zero.tv_nsec = 0;
> 
>     pps_info_t info;
>     int return_value = time_pps_fetch(m_handle, PPS_TSFMT_TSPEC, &info,
> &zero);
> 
> The PPS handle and the raw FD should be the same value (from <timepps.h>):
> 
>     /* ... then since in LinuxPPS there are no differences between a
>      * "PPS source" and a "PPS handle", we simply return the same value.
>      */
>     *handle = source;
> 
> The PPS client driver is the GPIO client, modified to use the devicetree
> [1], should be declared PPS_CANWAIT.
> 
> Is this the expected behaviour from select()?  If so, what work needs to be
> done in order for the driver to be select()-able?

Select() should work correctly, that is it should return some data to
be read each time you get a new PPS event, and this should occour 1
time per second...

Can you repeat your tests by using a dedicated program where you just
open the PPS source and do the select() on just one FD?

Ciao,

Rodolfo

-- 

GNU/Linux Solutions                  e-mail: giometti at enneenne.com
Linux Device Driver                          giometti at linux.it
Embedded Systems                     phone:  +39 349 2432127
UNIX programming                     skype:  rodolfo.giometti
Freelance ICT Italia - Consulente ICT Italia - www.consulenti-ict.it




More information about the discussions mailing list