From eca731ac63f6bfef57c674c8ce2fba90fbb34cc4 Mon Sep 17 00:00:00 2001 From: peter Date: Sat, 12 Mar 2005 00:10:23 +0000 Subject: [PATCH] Make the tty vmin/vtime timeouts work for hz > 169 on 32 bit machines. --- sys/kern/tty.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/sys/kern/tty.c b/sys/kern/tty.c index f916a1bfe674..bc95f0423c42 100644 --- a/sys/kern/tty.c +++ b/sys/kern/tty.c @@ -97,6 +97,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -1854,14 +1855,13 @@ loop: #undef diff /* * Rounding down may make us wake up just short - * of the target, so we round up. - * The formula is ceiling(slp * hz/1000000). - * 32-bit arithmetic is enough for hz < 169. - * XXX see tvtohz() for how to avoid overflow if hz - * is large (divide by `tick' and/or arrange to - * use tvtohz() if hz is large). + * of the target, so we round up. The 32 bit arithmetic is + * sufficient for the first calculation for hz < 169. */ - slp = (long) (((u_long)slp * hz) + 999999) / 1000000; + if (sizeof(u_long) > 4 || slp <= ULONG_MAX / hz) + slp = (long) (((u_long)slp * hz) + 999999) / 1000000; + else + slp = (slp + (tick - 1)) / tick; goto sleep; } if (qp->c_cc <= 0) {