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

Re: patch for wanna-build (sysinfo/getloadavg)



> On Sat, Jul 26, 2003 at 06:38:19PM +0000, Robert Millan wrote:
> > On Thu, Jul 24, 2003 at 12:14:57AM +0100, Roger Leigh wrote:
> > > [...]
> > > 
> > > This seems rather complex!  Why not just do something like:
> > >                 waittime = (long) (loadavg[0] / 16384) * 6 + 20;
> > > 
> > > If you don't need SI_LOAD_SHIFT (Linux-specific??), it can probably be
> > > even simpler.
> > 
> > Can I cast a double to long like that? What kind of truncating happens if
> > loadavg[0] is bigger than LONG_MAX? Does a division with 2^14 garantee it
> > will fit nicely?

My guess is that if the load average is so high that you get overflow
when converting it to a long, you're in big trouble anyway... But you
could do some simple checking like

  if (loadavg[0] > 10000.0)
    /* Insane load average */
    waittime = WAIT_MAX; /* I don't know what's reasonable here.
                            Five minutes? Five hours? */
  else
    /* Sane load average, no overflow possible */
    waittime = (long) (loadavg[0] / 16384) * 6 + 20;

BTW, I don't quite understand the conversion formula. What unit is the
wait time? To me it seems that waittime will always be set to 20,
unless the load average is above 2730, and that doesn't seem like a
reasonable threshold at all.

/Niels



Reply to: