Skip to contentSkip to conversation

poll()/select() timeout behavior

PATCH In review Bill Rugolsky Jr. 2 participants 2 messages Feb 20, 2004 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 3/4 poll()/select() timeout behavior

This patch changes select() and poll() to not wait forever when a valid, but large timeout value is supplied. The SUSv3 manual page for select(2) states:

"If the timeout argument specifies a timeout interval greater than the implementation-defined maximum value, the maximum value shall be used as the actual timeout value."

Both select() and poll() have a well-defined mechanism to wait forever, so there is no need for the existing behavior.

Please apply.

Bill Rugolsky

fs/select.c +3 -1
@@ -316,6 +316,8 @@
 		if ((unsigned long) sec < (MAX_SCHEDULE_TIMEOUT-1) / HZ - 1) {
 			timeout = ROUND_UP(usec, 1000000/HZ);
 			timeout += sec * (unsigned long) HZ;
+		} else {
+			timeout = MAX_SCHEDULE_TIMEOUT-1;
 		}
 	}
 
@@ -476,7 +478,7 @@
 			if (seconds <= (MAX_SCHEDULE_TIMEOUT-2) / HZ - 1)
 				timeout += seconds*HZ;
 			else
-				timeout = MAX_SCHEDULE_TIMEOUT;
+				timeout = MAX_SCHEDULE_TIMEOUT-1;
 		}
 	}
 
#1 lore raw
Quoted 8 lines · Bill Rugolsky Jr.

This patch changes select() and poll() to not wait forever when a valid, but large timeout value is supplied. The SUSv3 manual page for select(2) states:

"If the timeout argument specifies a timeout interval greater than the implementation-defined maximum value, the maximum value shall be used as the actual timeout value."

Quoted 6 lines

Both select() and poll() have a well-defined mechanism to wait forever, so there is no need for the existing behavior.

Please apply.

Bill Rugolsky

The "well-defined mechanism" to wait forever for poll() is to use ANY negative value as the timeout value. If you chose -1, that, currently is MAX_SCHEDULE_TIMEOUT on Linux 2.4.24. Don't your changes muck this up or is "<0" checked somewhere else?

Quoted 13 lines
fs/select.c +2 -0
@@ -316,6 +316,8 @@
 		if ((unsigned long) sec < (MAX_SCHEDULE_TIMEOUT-1) / HZ - 1) {
 			timeout = ROUND_UP(usec, 1000000/HZ);
 			timeout += sec * (unsigned long) HZ;
+		} else {
+			timeout = MAX_SCHEDULE_TIMEOUT-1;
 		}
 	}
 

fs/select.c line 484

Quoted 8 lines
fs/select.c +1 -1
@@ -476,7 +478,7 @@
 			if (seconds <= (MAX_SCHEDULE_TIMEOUT-2) / HZ - 1)
 				timeout += seconds*HZ;
 			else
-				timeout = MAX_SCHEDULE_TIMEOUT;
+				timeout = MAX_SCHEDULE_TIMEOUT-1;
 		}
 	}
 

Cheers,
Dick Johnson
Penguin : Linux version 2.4.24 on an i686 machine (797.90 BogoMips).
Note 96.31% of all statistics are fiction.