NET: 64-bit network statistics
Subsystems (3)
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
I've created a patch that monitors changes to the network statistics variables and keeps internal 64-bit counter. I decided to split it into two parts (patches are to follow in next emails):
1) generic variable monitoring system (watch64)
The watch64 system allows the programmer to specify the approximate interval at which he wants his variables checked. If he tries to specify shorter interval than the minimum a default value of HZ/10 is used. To minimize locking, RCU and seqlock are used. On 64-bit systems, all is optimized away.
2) network statistics specific patch (64network)
Upon registration of a network device, all the statistics variables are registered with watch64. Additionally, a new proc file is
created /proc/net/dev64 displays the 64-bit values as supposed
to /proc/net/dev which is left to display the original 32-bit variables for backward compatibility. The sysfs interface (/sys/class/net/<interface>/statistics/*) displays the 64-bit values only. On 64-bit systems, all is optimized away through watch64.
Josef "Jeff" Sipek.
- --
*NOTE: This message is ROT-13 encrypted twice for extra protection* -----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)
iD8DBQFBOKSzwFP0+seVj/4RAkz7AJ0Ut21nPMkHGKv1dXK17yoA5hQ1+ACglpMq IHh+tYW3innmwjlA7EU2x78=
=LnHg
-----END PGP SIGNATURE-----
PATCH 1/1 watch64: generic variable monitoring system
The watch64 system allows the programmer to specify the approximate interval at which he wants his variables checked. If he tries to specify shorter interval than the minimum a default value of HZ/10 is used. To minimize locking, RCU and seqlock are used. On 64-bit systems, all is optimized away.
The following patch can be also pulled from http://jeffpc.bkbits.net/watch64-2.6
Josef "Jeff" Sipek.
Documentation/00-INDEX 2004-09-03 12:21:17 -04:00 +2 -0
@@ -250,6 +250,8 @@ - directory with info regarding video/TV/radio cards and linux. vm/ - directory with info on the Linux vm code. +watch64.txt + - watch64 API description watchdog/ - how to auto-reboot Linux if it has "fallen and can't get up". ;-) x86_64/
Documentation/watch64.txt 2004-09-03 12:21:17 -04:00 renamed from dev/null Wed Dec 31 16:00:00 196900 +35 -0
@@ -0,0 +1,35 @@ +int watch64_register(unsigned long* ptr, unsigned int interval); + + - Registers *ptr to be monitored every interval jiffies. + - If interval==0, WATCH64_INTERVAL will be used (HZ/10 by default) + +int watch64_unregister(unsigned long* ptr, struct watch64* st); + + - Unregister *ptr + - st is optional pointer to the struct containing the registration + information + - if st==NULL, it will be looked up automatically + +struct watch64* watch64_find(unsigned long* ptr); + + - Return struct with registration information of *ptr + +int watch64_disable(unsigned long* ptr, struct watch64* st); + + - Disable *ptr from being monitored, without removing it from the list + - st is optional (see watch64_unregister for more information) + +int watch64_enable(unsigned long* ptr, struct watch64* st); + + - Enable *ptr from being monitored (opposite of watch64_disable) + - st is optional (see watch64_unregister for more information) + +int watch64_toggle(unsigned long* ptr, struct watch64* st); + + - Toggle the enable/disable status + - st is optional (see watch64_unregister for more information) + +inline u_int64_t watch64_getval(unsigned long* ptr, struct watch64* st); + + - Return the whole 64-bit counter + - st is optional (see watch64_unregister for more information)
include/linux/watch64.h 2004-09-03 12:21:17 -04:00 renamed from dev/null Wed Dec 31 16:00:00 196900 +63 -0
63 lines not on this page · raw message
kernel/Makefile 2004-09-03 12:21:17 -04:00 +1 -1
@@ -7,7 +7,7 @@ sysctl.o capability.o ptrace.o timer.o user.o \ signal.o sys.o kmod.o workqueue.o pid.o \ rcupdate.o intermodule.o extable.o params.o posix-timers.o \ - kthread.o + kthread.o watch64.o obj-$(CONFIG_FUTEX) += futex.o obj-$(CONFIG_GENERIC_ISA_DMA) += dma.o
kernel/watch64.c 2004-09-03 12:21:17 -04:00 renamed from dev/null Wed Dec 31 16:00:00 196900 +392 -0
392 lines not on this page · raw message
Re: [PATCH 2.6] watch64: generic variable monitoring system
In article <[email protected]> (at Fri, 03 Sep 2004 13:19:24 -0400), "Josef 'Jeff' Sipek" <[email protected]> says:
Quoted 4 lines
The watch64 system allows the programmer to specify the approximate interval at which he wants his variables checked. If he tries to specify shorter interval than the minimum a default value of HZ/10 is used. To minimize locking, RCU and seqlock are used. On 64-bit systems, all is optimized away.
I agree with the basic principle; it is very similar to mine. However, it is too complicated isn't it?
I would do per-"table" registration (instead of per-variable one); watch64_getval() seems very ugly to me...
Signature · 2 lines
Hideaki YOSHIFUJI @ USAGI Project <[email protected]> GPG FP: 9022 65EB 1ECF 3AD1 0BDF 80D8 4807 F894 E062 0EEA
Re: [PATCH 2.6] watch64: generic variable monitoring system
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Quoted 1 line · YOSHIFUJI Hideaki / 吉藤英明
I agree with the basic principle; it is very similar to mine.
Yes, I saw a patch on lkml a while a go (possibly yours?) that used a workqueue (IIRC.)
Quoted 1 line
However, it is too complicated isn't it?
I considered the option of removing the capability of the programmer asking for a certain interval, and instead having all the variables checked every WATCH64_INTERVAL.
Quoted 1 line
I would do per-"table" registration (instead of per-variable one);
I considered that option, but then decided to make the watch64 system generic enough so that it could be used from anywhere in the kernel. Is my idea of having a kernel-wide subsystem like this too heavy-weight?
Quoted 1 line
watch64_getval()seems very ugly to me...
How so? Is it the multiplicity of "if (!st)"?
Jeff.
- --
bad pun of the week: the formula 1 control computer suffered from a race condition
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)
iD8DBQFBONLzwFP0+seVj/4RAvYsAKCdVy9EzivcGtwa9CDiuvy/nwWuJwCglQ4L iIf4QXC7PA+YwQs3905sRv0=
=NkA4
-----END PGP SIGNATURE-----
Re: [PATCH 2.6] watch64: generic variable monitoring system
In reply to Josef 'Jeff' SipekQuoted 10 lines · On Fri, 03 Sep 2004 13:19:24 -0400 "Josef 'Jeff' Sipek" <[email protected]>…
The watch64 system allows the programmer to specify the approximate interval at which he wants his variables checked. If he tries to specify shorter interval than the minimum a default value of HZ/10 is used. To minimize locking, RCU and seqlock are used. On 64-bit systems, all is optimized away.
The following patch can be also pulled from http://jeffpc.bkbits.net/watch64-2.6
Josef "Jeff" Sipek.
Signed-off-by Josef "Jeff" Sipek <[email protected]>
- Seems like a big interface for a simple problem.
- Code doesn't match the kernel style (read Documentation/CodingStyle)
- Does it really need RCU and seqlock, wouldn't one suffice
Re: [PATCH 2.6] watch64: generic variable monitoring system
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Quoted 1 line · you
- Seems like a big interface for a simple problem.
I agree that the interface could be simplified a lot, however I decided to make it as generic as possible so that any part of the kernel can use it. I also am contemplating whether it would make sense to remove the capability of setting the interval to any value, and just have all variables checked every WATCH64_INTERVAL.
Quoted 1 line
- Code doesn't match the kernel style (read
Documentation/CodingStyle)
Agreed. I'm going submit a correction patch.
Quoted 1 line
- Does it really need RCU and seqlock, wouldn't one suffice
As far as I can tell, it does. RCU to protect the linked list, and seqlock to protect the internal 64-bit counter.
Jeff.
- --
Research, n.:
Consider Columbus:
He didn't know where he was going.
When he got there he didn't know where he was. When he got back he didn't know where he had been. And he did it all on someone else's money.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)
iD8DBQFBONGlwFP0+seVj/4RAlAFAJ9OiipyTpCGljodcwYgDSlXaWB3LACgnWLk ZZLfkwnTFdsihHvTmfR+AuA=
=g5hE
-----END PGP SIGNATURE-----
Re: [PATCH 2.6] watch64: generic variable monitoring system
The following fixes watch64 patch previously submitted to follow CodingStyle guidelines. BK repo is up to date as well
Jeff.
watch64.c 2004-09-03 16:12:39 -04:00 renamed from kernel/watch64.c 2004-07-14 16:41:26 -04:00 +18 -14
@@ -110,7 +110,8 @@ return; } - printk(KERN_WARNING "watch64: 2003/08/22 Josef 'Jeff' Sipek <[email protected]>\n"); + printk(KERN_WARNING "watch64: 2003/08/22 Josef 'Jeff' Sipek " + "<[email protected]>\n"); printk(KERN_WARNING "watch64: Enabling Watch64 extensions..."); init_timer(&watch64_timer);
@@ -139,19 +140,21 @@ rcu_read_lock(); list_for_each_rcu(entry, &watch64_head) { watch_struct = list_entry(entry, struct watch64, list); - if (*watch_struct->ptr != watch_struct->oldval) { - tmp = *watch_struct->ptr; - if (tmp > watch_struct->oldval) { - write_seqlock(&watch_struct->lock); - watch_struct->total += tmp - watch_struct->oldval; - write_sequnlock(&watch_struct->lock); - } else if (tmp < watch_struct->oldval) { - write_seqlock(&watch_struct->lock); - watch_struct->total += ((u_int64_t) 1<<BITS_PER_LONG) - watch_struct->oldval + tmp; - write_sequnlock(&watch_struct->lock); - } - watch_struct->oldval = tmp; + if (*watch_struct->ptr == watch_struct->oldval) + continue; + + tmp = *watch_struct->ptr; + if (tmp > watch_struct->oldval) { + write_seqlock(&watch_struct->lock); + watch_struct->total += tmp - watch_struct->oldval; + write_sequnlock(&watch_struct->lock); + } else if (tmp < watch_struct->oldval) { + write_seqlock(&watch_struct->lock); + watch_struct->total += ((u_int64_t) 1<<BITS_PER_LONG) + - watch_struct->oldval + tmp; + write_sequnlock(&watch_struct->lock); } + watch_struct->oldval = tmp; } rcu_read_unlock();
@@ -181,7 +184,8 @@ temp->interval = WATCH64_INTERVAL; else if (interval<WATCH64_MINIMUM) { temp->interval = WATCH64_MINIMUM; - printk("watch64: attempted to add new watch with interval below %d jiffies",WATCH64_MINIMUM); + printk("watch64: attempted to add new watch with " + "interval below %d jiffies",WATCH64_MINIMUM); } else temp->interval = interval;
Re: [PATCH 2.6] watch64: generic variable monitoring system
In reply to Stephen Hemminger-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Quoted 1 line · Stephen Hemminger
- Code doesn't match the kernel style (read
Documentation/CodingStyle)
Sorry about the white space, KMail apparently likes to butcher the text. These are the same patches with the little cleanup update.
Jeff.
- --
Reality is merely an illusion, albeit a very persistent one.
- Albert Einstein
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)
iD4DBQFBOOW+wFP0+seVj/4RAgSiAJj54qcqdEx66lbMW9ik0XviupTNAKC82an1 R0pGX0pTBZ78NWrZpxJm+w==
=EesC
-----END PGP SIGNATURE-----
Documentation/00-INDEX +2 -0
@@ -250,6 +250,8 @@ - directory with info regarding video/TV/radio cards and linux. vm/ - directory with info on the Linux vm code. +watch64.txt + - watch64 API description watchdog/ - how to auto-reboot Linux if it has "fallen and can't get up". ;-) x86_64/
Documentation/watch64.txt new file +35 -0
@@ -0,0 +1,35 @@ +int watch64_register(unsigned long* ptr, unsigned int interval); + + - Registers *ptr to be monitored every interval jiffies. + - If interval==0, WATCH64_INTERVAL will be used (HZ/10 by default) + +int watch64_unregister(unsigned long* ptr, struct watch64* st); + + - Unregister *ptr + - st is optional pointer to the struct containing the registration + information + - if st==NULL, it will be looked up automatically + +struct watch64* watch64_find(unsigned long* ptr); + + - Return struct with registration information of *ptr + +int watch64_disable(unsigned long* ptr, struct watch64* st); + + - Disable *ptr from being monitored, without removing it from the list + - st is optional (see watch64_unregister for more information) + +int watch64_enable(unsigned long* ptr, struct watch64* st); + + - Enable *ptr from being monitored (opposite of watch64_disable) + - st is optional (see watch64_unregister for more information) + +int watch64_toggle(unsigned long* ptr, struct watch64* st); + + - Toggle the enable/disable status + - st is optional (see watch64_unregister for more information) + +inline u_int64_t watch64_getval(unsigned long* ptr, struct watch64* st); + + - Return the whole 64-bit counter + - st is optional (see watch64_unregister for more information)
include/linux/watch64.h new file +63 -0
63 lines not on this page · raw message
kernel/Makefile +1 -1
@@ -7,7 +7,7 @@ sysctl.o capability.o ptrace.o timer.o user.o \ signal.o sys.o kmod.o workqueue.o pid.o \ rcupdate.o intermodule.o extable.o params.o posix-timers.o \ - kthread.o + kthread.o watch64.o obj-$(CONFIG_FUTEX) += futex.o obj-$(CONFIG_GENERIC_ISA_DMA) += dma.o
kernel/watch64.c new file +396 -0
396 lines not on this page · raw message
include/linux/netdevice.h +5 -0
@@ -14,6 +14,7 @@* Alan Cox, <[email protected]> * Bjorn Ekwall. <[email protected]> * Pekka Riikonen <[email protected]> +* Josef "Jeff" Sipek <[email protected]> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License
@@ -945,6 +946,10 @@#ifdef CONFIG_SYSCTL extern char *net_sysctl_strdup (const char *s);#endif + +/* * Register/unregister all the members of struct net_device_stats with watch64 */ +inline void net_register_stats64 (struct net_device_stats * stats); +inline void net_unregister_stats64 (struct net_device_stats * stats);
#endif /* __KERNEL__ */
net/core/dev.c +180 -7
276 lines not on this page · raw message
net/core/net-sysfs.c +4 -2
@@ -16,6 +16,7 @@#include <net/sock.h> #include <linux/rtnetlink.h> #include <linux/wireless.h> +#include <linux/watch64.h> #define to_class_dev (obj) container_of(obj,struct class_device,kobj)#define to_net_dev (class) container_of(class, struct net_device, class_dev)
@@ -23,6 +24,7 @@static const char fmt_hex[] ="%#x\n" ;static const char fmt_dec[] ="%d\n" ;static const char fmt_ulong[] ="%lu\n" ; +static const char fmt_ullong[] ="%llu\n" ;static inline int dev_isalive (const struct net_device *dev) {
@@ -204,8 +206,8 @@read_lock (&dev_base_lock);if (dev_isalive (dev) && dev->get_stats && (stats = (*dev->get_stats)(dev))) - ret =sprintf (buf, fmt_ulong, - *(unsigned long *)(((u8 *) stats) + offset)); + ret =sprintf (buf, fmt_ullong, +watch64_getval ((unsigned long *)(((u8 *) stats) + offset),NULL ));read_unlock (&dev_base_lock);return ret;
Re: [PATCH 2.6] watch64: generic variable monitoring system
I have a feeling this was discussed somewhere(other than netdev) and i missed it. Why isnt this watch64 being done in user space?
cheers,
jamal
Quoted 21 lines · Josef 'Jeff' Sipek
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1Quoted 1 line · Stephen Hemminger
- Code doesn't match the kernel style (read
Documentation/CodingStyle)Sorry about the white space, KMail apparently likes to butcher the text. These are the same patches with the little cleanup update.
Jeff.
- --
Reality is merely an illusion, albeit a very persistent one.
- Albert Einstein
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)iD4DBQFBOOW+wFP0+seVj/4RAgSiAJj54qcqdEx66lbMW9ik0XviupTNAKC82an1 R0pGX0pTBZ78NWrZpxJm+w==
=EesC
-----END PGP SIGNATURE-----
Re: [PATCH 2.6] watch64: generic variable monitoring system
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Quoted 2 lines · jamal
I have a feeling this was discussed somewhere(other than netdev) and i missed it. Why isnt this watch64 being done in user space?
There was a discussion about 64-bit network statistics about a year ago on lkml.
watch64 is a generic so that anyone in the kernel can use it.
Jeff.
- --
Mankind invented the atomic bomb, but no mouse would ever construct a mousetrap.
- Albert Einstein
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)
iD8DBQFBOzybwFP0+seVj/4RArmhAKC3ddX4ZGoAMQKxGplXqqbER9BBMQCfencW wDt06dC8MifG9NU3xWx0ULo=
=z9kC
-----END PGP SIGNATURE-----
Re: [PATCH 2.6] watch64: generic variable monitoring system
Quoted 6 lines · Jeff Sipek
Quoted 2 lines · jamal
I have a feeling this was discussed somewhere(other than netdev) and i missed it. Why isnt this watch64 being done in user space?
There was a discussion about 64-bit network statistics about a year ago on lkml.
Sorry unsubscribed from lkml since summer of '94. [net related discussions should really happen on netdev].
Quoted 1 line
watch64 is a generic so that anyone in the kernel can use it.
Ok - so why does this have to be in the kernel?
cheers,
jamal
Re: [PATCH 2.6] watch64: generic variable monitoring system
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Sorry, I missed your email.
Quoted 6 lines · jamal
Quoted 2 lines · Jeff Sipek
There was a discussion about 64-bit network statistics about a year ago on lkml.
Sorry unsubscribed from lkml since summer of '94. [net related discussions should really happen on netdev].
netdev was CC'd during this whole discussion.
Quoted 3 lines
Quoted 1 line
watch64 is a generic so that anyone in the kernel can use it.
Ok - so why does this have to be in the kernel?
I think it is convenient to have the 64 bit net stats reported by the kernel.
Jeff.
- --
My public GPG key can be found at
http://shells.gnugeneration.com/~jeffpc/gpg/public-0xC7958FFE.txt
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)
iD8DBQFBRHENwFP0+seVj/4RAuzcAKCdBAooPae8pTaMEHbWmVDKAO7C5ACeLi21 cen/Ag4bH5Dm9xkQiXj+d0Q=
=BrV+
-----END PGP SIGNATURE-----
PATCH 1/1 64network: 64-bit network statistics
In reply to josef Jeff SipekUpon registration of a network device, all the statistics variables are registered with watch64. Additionally, a new proc file is
created /proc/net/dev64 displays the 64-bit values as supposed
to /proc/net/dev which is left to display the original 32-bit variables for backward compatibility. The sysfs interface (/sys/class/net/<interface>/statistics/*) displays the 64-bit values only. On 64-bit systems, all is optimized away through watch64.
Requires: watch64
The following patch can be also pulled from http://jeffpc.bkbits.net/64network-2.6 (includes watch64)
Josef "Jeff" Sipek
include/linux/netdevice.h 2004-09-03 12:22:08 -04:00 +5 -0
@@ -14,6 +14,7 @@ * Alan Cox, <[email protected]> * Bjorn Ekwall. <[email protected]> * Pekka Riikonen <[email protected]> + * Josef "Jeff" Sipek <[email protected]> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License
@@ -945,6 +946,10 @@ #ifdef CONFIG_SYSCTL extern char *net_sysctl_strdup(const char *s); #endif + +/* Register/unregister all the members of struct net_device_stats with watch64 */ +inline void net_register_stats64(struct net_device_stats* stats); +inline void net_unregister_stats64(struct net_device_stats* stats); #endif /* __KERNEL__ */
net/core/dev.c 2004-09-03 12:22:08 -04:00 +180 -7
276 lines not on this page · raw message
net/core/net-sysfs.c 2004-09-03 12:22:08 -04:00 +4 -2
@@ -16,6 +16,7 @@ #include <net/sock.h> #include <linux/rtnetlink.h> #include <linux/wireless.h> +#include <linux/watch64.h> #define to_class_dev(obj) container_of(obj,struct class_device,kobj) #define to_net_dev(class) container_of(class, struct net_device, class_dev)
@@ -23,6 +24,7 @@ static const char fmt_hex[] = "%#x\n"; static const char fmt_dec[] = "%d\n"; static const char fmt_ulong[] = "%lu\n"; +static const char fmt_ullong[] = "%llu\n"; static inline int dev_isalive(const struct net_device *dev) {
@@ -204,8 +206,8 @@ read_lock(&dev_base_lock); if (dev_isalive(dev) && dev->get_stats && (stats = (*dev->get_stats)(dev))) - ret = sprintf(buf, fmt_ulong, - *(unsigned long *)(((u8 *) stats) + offset)); + ret = sprintf(buf, fmt_ullong, + watch64_getval((unsigned long *)(((u8 *) stats) + offset),NULL)); read_unlock(&dev_base_lock); return ret;
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Quoted 5 lines · josef Jeff Sipek
I've created a patch that monitors changes to the network statistics variables and keeps internal 64-bit counter. I decided to split it into two parts (patches are to follow in next emails):
1) generic variable monitoring system (watch64)
2) network statistics specific patch (64network)
Btw, both of these patches apply cleanly against 2.6.9-rc1-bk10.
Jeff.
- --
bad pun of the week: the formula 1 control computer suffered from a race condition
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)
iD8DBQFBOKjQwFP0+seVj/4RApg/AKDEFSTVOMSvVh9zVU65o/P6ZcfBxgCffeId QddOVsR+uHdkV2D4/U8QVO4=
=jQIT
-----END PGP SIGNATURE-----