Source-Changes-D archive

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

Re: CVS commit: src/sys/external/bsd/drm2/include/linux



On Sat, 26 Jul 2014, Taylor R Campbell wrote:
Make Linux usecs_to_jiffies work with hz up to 2000.

usecs_to_jiffies(unsigned int usec)
{
-       return mstohz((usec + (1000 / hz) - 1) / (1000 / hz));
+       if (hz <= 100)
+               return mstohz(roundup(usec, (1000 / hz)));
+
+       /*
+        * Avoid integer overflow on 32-bit platforms.  The cutoff is
+        * kinda arbitrary; for hz <= 2000, 0x200000 is safe, but both
+        * values could wiggle around a little.
+        */
+       KASSERT(hz <= 2000);
+       if (usec <= 0x200000)
+               return ((usec * hz) / 1000000);
+       else
+               return ((usec / 1000000) * hz);
}

You could just populate a struct timeval, and call tvtohz(9).

What is the desired behaviour for small inputs? The code quoted above appears to round up when hz <= 100 (and to return 1 for very small but non-zero inputs) but to round down (and to return 0 for very small inputs) when hz > 100. Once the desired behaviour is clarified, you could implement it by making adjustments to the value before or after calling tvtohz.

--apb (Alan Barrett)


Home | Main Index | Thread Index | Old Index