tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: select() timeout



On 2012-02-03 13.08, Jukka Marin wrote:
I guess it's better to post this here as well:

Hi,

How does timeout of select() work for short timeouts (less than timecounter
tick period)?  I am working on a serial bus protocol where the master first
sends out a data packet and then waits for a reply from a slave.  Timecounter
tick is 10 ms on this box (a net5501) and I would like to use timeouts of
1 ms or even less when data bytes are coming in.

I was using a fixed 20 ms timeout and the protocol was working ok for most
of the time, but sometimes I got a burst of receive timeouts.  I'm not sure
if the data is held in the tty buffers or if my timeout logic is failing yet.

So, are short timeouts reliable with select()?

What do you mean by "realiable"?

I'd say they are probably not in any way ideal for doing time keeping. The time that you will wait is sortof heuristic. The specified time is said to be a "max", but the time might get rounded to the next clock tick. You might also get more delay since scheduling might actually means it takes even more time before you actually execute. And select does not report back how long you actually slept. There is a whole bunch of issues that can become relevant if you actually start having hard constraints on the timing. Unix systems in general are not realtime. And depending on how you want to use the timeouts, you might have to think a little to actually get things right.

        Johnny


Home | Main Index | Thread Index | Old Index