Re: 64-bit fields in struct net_device_stats

Lincoln Dale
2003-06-16T05:34:58Z

At 11:12 PM 15/06/2003 -0400, Zwane Mwaikambo wrote:
> > suggested to use per cpu stats and overflow into a global counter. (Thanks
> > Zwane) This might be a better idea - the problem is, the counter won't be
> > 100% accurate at all times. The degree of inaccuracy will vary with the
> > threshold value. On the other hand, if the threshold is relatively low, no
> > one will notice the difference these days.
>
>This would be one method of doing updates and for stats it would be fine,
>however feel free to look into other ways...

why not a set of counters which are toggled between.

e.g.
struct netdevice... {
uint64 tx_pkts_counter[2];
uint64 tx_octets_counter[2];
uint64 rx_pkts_counter[2];
uint64 rx_octets_counter[2];
int counter_bounce;
...
}

where readers simply do something like:
tx_bytes +=
netdevice[foo]->tx_octets_counter[(netdevice[foo]->counter_bounce)];

and writer(s) alternate between updating one uint64 and an alternate one?

in this manner, you don't need to do any special synchronization or atomic
updates or have any dependency on any particular architecture being able to
do atomic 64-bit ops.

cheers,

lincoln.