[collectd] int overflow: patch for irq plugin

Florian Forster octo at verplant.org
Mon Apr 20 21:54:07 CEST 2009


Hi Tomasz,

On Sat, Apr 18, 2009 at 05:45:01PM +0200, Tomasz Pala wrote:
> attached patch fixes accounting of most frequent interrupts (like NICs
> on routers). E.g. in my case:
> 
> 213:      76266      76357      76250      76397 2408617852 2411844062 2411642538 2411814531   PCI-MSI-edge      eth1
> 214: 2621368360 2621463385 2621343444 2621386931    2349184         28         35         32   PCI-MSI-edge      eth0
> 
> Here LONG_MAX (2147483647L) overflows in 10 days uptime and strtol()
> returns the same value.
> 
> As all the values (including counter_t) are unsigned long long int,
> the fix is trivial (for now there's no need to check for irq_value
> overflow;>).

thanks for your patch :) I've applied the version that uses `strtoull'
because the value is converted to a 64bit value(s) later anyway. Since
we add all those values up and they may not be 64bit values, we possibly
should force a 32bit wrap around – the code handling counters is
expecting them. If we add 32bit counters in a 64bit value, a wrap-around
of a single counter will probably look similar to a counter-reset, i. e.
not nice ;)

What do you think about this code?:
  uint32_t irq_value = 0;
  uint32_t tmp;
  for (fields)
  {
    tmp = (uint32_t) strtoul (field);
    irq_value += tmp;
  }
  submit ((counter_t) irq_value);

Using (and casting to) a uint32_t here should take care of individual
counter wrap-arounds (as long as the counter uses at least 32 bits).

Regards,
-octo
-- 
Florian octo Forster
Hacker in training
GnuPG: 0x91523C3D
http://verplant.org/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mailman.verplant.org/pipermail/collectd/attachments/20090420/afb681fb/attachment.pgp 


More information about the collectd mailing list