Skip to contentSkip to conversation

Add pselect, ppoll system calls.

DISCUSSION Mattias Engdegård 4 participants 9 messages Jun 13, 2005 – Jun 14, 2005

lore
Share & tools
lore
#0 lore raw
Quoted 3 lines

I think passing const struct timeval * or const struct timespec * (depending if you want micro or nanoseconds) is better and what other functions use for timeouts, then passing int64_t.

If we can design ppoll() any way we like, which seems likely, I would prefer having the timeout given as an absolute timestamp. It would save some gettimeofday() (or clock_gettime()) syscalls and simplify user code in common cases.

If I'm not mistaken, sem_timedwait() and pthread_cond_timedwait() were designed to take an absolute timeout for this reason.

#1 lore raw
Quoted 2 lines · Mattias Engdegård

If we can design ppoll() any way we like, which seems likely, I would prefer having the timeout given as an absolute timestamp.

Absolute timestamps are messy though. How do you deal with system time changes?

Chris

#2 lore raw
Quoted 7 lines
Quoted 2 lines · Mattias Engdegård

If we can design ppoll() any way we like, which seems likely, I would prefer having the timeout given as an absolute timestamp.

Absolute timestamps are messy though. How do you deal with system time changes?

Monotonic clocks are there for exactly that, no?

#3 lore raw
Quoted 6 lines · On Mon, 13 Jun 2005 22:08:55 +0200, =?ISO-8859-1?Q?Mattias Engdeg=E5rd?= said:
Quoted 4 lines

Mattias Engdegård wrote:

Absolute timestamps are messy though. How do you deal with system time changes?

Monotonic clocks are there for exactly that, no?

Monotonic clocks are guaranteed to not go backward. A sudden warp 35 seconds into the future when you have timers set for 15 and 20 seconds into the future is still ugly....

#4 lore raw
Quoted 3 lines

Monotonic clocks are guaranteed to not go backward. A sudden warp 35 seconds into the future when you have timers set for 15 and 20 seconds into the future is still ugly....

I don't have the POSIX specs handy, but I see no reason we could not let it use a warpless monotonic clock.

The problem of timeouts going wild when time is being warped applies to syscalls using relative timeouts as well. Even when a relative timeout is wanted, it is usually transformed (via gettimeofday or similar) to an absolute timeout:

T = some_clock() + dT
timeout = dT
loop:
poll(..., timeout)
if (poll did not time out):
now = some_clock()
timeout = MAX(0, T - now)
goto loop

This kind of code is very common, because the timeout is usually the time to some event in the future. If some_clock() is subject to warping (which is the case when gettimeofday() is used), then you have the problem again.

#5 lore raw
Quoted 6 lines · On Tue, 2005-06-14 at 16:07 +0200, =?ISO-8859-1?Q?Mattias Engdeg=E5rd?= wrote:
Quoted 3 lines

Monotonic clocks are guaranteed to not go backward. A sudden warp 35 seconds into the future when you have timers set for 15 and 20 seconds into the future is still ugly....

I don't have the POSIX specs handy, but I see no reason we could not let it use a warpless monotonic clock.

You have already one - the uptime of the system.

Quoted 3 lines

The problem of timeouts going wild when time is being warped applies to syscalls using relative timeouts as well. Even when a relative timeout is wanted, it is usually transformed (via gettimeofday or

Doing "Relative timeouts" with "gettimeofday()" is a strategic error. Specify the timeout und use (the return value of) times(2) for this.

Use "gettimeofday()" and similar just if (and only if) you communicate with the user (read: that is a pure user interface issue).

Bernd

Signature · 3 lines
Firmix Software GmbH                   http://www.firmix.at/
mobil: +43 664 4416156                 fax: +43 1 7890849-55
          Embedded Linux Development and Services
#6 lore raw
Quoted 4 lines
Quoted 2 lines

I don't have the POSIX specs handy, but I see no reason we could not let it use a warpless monotonic clock.

You have already one - the uptime of the system.

For example, yes.

Quoted 2 lines

Doing "Relative timeouts" with "gettimeofday()" is a strategic error. Specify the timeout und use (the return value of) times(2) for this.

Having an interface use absolute timeouts will avoid this strategic error, simplify common code, and reduce the number of needed syscalls.

Quoted 2 lines

Use "gettimeofday()" and similar just if (and only if) you communicate with the user (read: that is a pure user interface issue).

Of course, but it is not uncommon, perhaps because it's tedious to convert between clock ticks and a struct timeval.
There is also the problem that the clock tick resolution has historically been low (commonly 10 ms), which may cause bigger jitter in the longer term. Also, a clock_t is frequently only 32 bits wide.

#7 lore raw

Trimmed Cc: so reduce mail on already mail-overloaded folks.

Quoted 11 lines · On Tue, 2005-06-14 at 16:42 +0200, =?ISO-8859-1?Q?Mattias Engdeg=E5rd?= wrote:
Quoted 4 lines
Quoted 2 lines

I don't have the POSIX specs handy, but I see no reason we could not let it use a warpless monotonic clock.

You have already one - the uptime of the system.

For example, yes.

Quoted 2 lines

Doing "Relative timeouts" with "gettimeofday()" is a strategic error. Specify the timeout und use (the return value of) times(2) for this.

Having an interface use absolute timeouts will avoid this strategic error,

If the absolute timeouts means "the uptime in some point in the future", yes.
If the absolute timeouts means "the time in the real world", then it *is* the strategic error. This "time in the real world" (if it is usable on the user interface), is neither monotonic nor warpless.

Quoted 1 line

simplify common code, and reduce the number of needed syscalls.

Bernd

Signature · 3 lines
Firmix Software GmbH                   http://www.firmix.at/
mobil: +43 664 4416156                 fax: +43 1 7890849-55
          Embedded Linux Development and Services
#8 lore raw
In reply to Mattias Engdegård
Quoted 6 lines · On Tue, 14 Jun 2005 16:07:54 +0200, =?ISO-8859-1?Q?Mattias Engdeg=E5rd?= said:
Quoted 3 lines

Monotonic clocks are guaranteed to not go backward. A sudden warp 35 seconds into the future when you have timers set for 15 and 20 seconds into the future is still ugly....

I don't have the POSIX specs handy, but I see no reason we could not let it use a warpless monotonic clock.

Right - I just mentioned it because "warpless" is an additional constraint on the clock implementation.

The last time I looked at the NTP code, there was a definite upper limit to how much warpless slewing of the clock was easily achievable - if you had a large initial adjustment to make, you still have to either take one large step, or be prepared to spend literally hours/days slewing the clock.

And then there's always the sysadmin issuing a 'date' command to manually set the clock. The kernel *still* needs to be able to handle warps correctly, because I believe 'date' *is* in Posix? ;)

(The other possible way to handle this is the old IBM S/370 way - where setting the system clock by warping it was only practical during system boot (as it was done before any timers got launched), and required an operator intervention to hit the 'TOD Clock Set Enable' button. So the operator would look at their watch, enter a time 15-20 seconds into the future, and whack the button at the specified time).