Re: Locking with per-cpu variables

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

 



On Sun, 16 Oct 2005, Aritz Bastida wrote:

1.- Suppose that I want to read the statistics (per-cpu and the total
numbers) via proc files. The proc read function would have to access
other cpu's variables, which in turn, could be updated by its cpu at
the same time.

Which is generally fine. Only "problem" is that you won't know if you read the counter before or after the update last update.

If you need to read multiple values and there needs to be a consistent reading of them all then some kind of locking will be required, but if you only need an approximate of each counter individually then no locking is required.

2.- Suppose that I also want to be able to reset the counters from
user space (via proc files too). Now I would be changing the counters
in the proc write function.

This can be done lockless by not writing to the actual counters but just write a separate flag that the counter needs to be reset, and then read (and clear) that flag from the per-cpu thread resetting the counter.

counters, not anything strange or difficult (I guess that even if some
other cpu would be incrementing one counter, instead of resetting to
cero, its value would be one, or something similar).

No, without locking or serialization by doing the reset from the per-cpu thread the reset can be lost.

Regards
Henrik
-
: send the line "unsubscribe linux-net" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux 802.1Q VLAN]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Git]     [Bugtraq]     [Yosemite News and Information]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux PCI]     [Linux Admin]     [Samba]

  Powered by Linux