Skip to contentSkip to conversation

Scalable statistics counters on loopback_xmit and tbench

PATCH Ravikiran G Thirumalai 1 participant 1 message Sep 25, 2002

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hi,
I ran tbench on loopback with counters for tx_packets, rx_packets, tx_bytes, rx_bytes replaced by statctrs. Here're the results

2.5.38
-------
236450 total 0.1960
...
2498 loopback_xmit 9.1838

2.5.38+statctrs for lo
--------------------
218334 total 0.1805
...
1129 loopback_xmit 3.5281

Since loopback_xmit is not a significant fraction of the total ticks, throughput improvement is not statistically significant.

This was on a 4xPIII 700, 1G RAM, 64 tbench clients.

Below is a 2.5.38 patch for statctr, and attatched is the looopback driver modifications used. statctr_t is now struct statctr as per Andrew Morton's suggestion. statctr_ninit has been introduced to init n counters at a time.

Is this good enough to go in?

Thanks,
Kiran

fs/proc/root.c +2 -0
diff -X dontdiff -ruN linux-2.5.38/fs/proc/root.c statctr-2.5.38/fs/proc/root.c
@@ -19,6 +19,7 @@
 #include <linux/smp_lock.h>
 
 struct proc_dir_entry *proc_net, *proc_bus, *proc_root_fs, *proc_root_driver;
+struct proc_dir_entry *proc_statistics;
 
 #ifdef CONFIG_SYSCTL
 struct proc_dir_entry *proc_sys_root;
@@ -77,6 +78,7 @@
 	proc_rtas_init();
 #endif
 	proc_bus = proc_mkdir("bus", 0);
+	proc_statistics = proc_mkdir("statistics", 0);
 }
 
 static struct dentry *proc_root_lookup(struct inode * dir, struct dentry * dentry)
include/linux/statctr.h +301 -0

301 lines not on this page · raw message

kernel/Makefile +2 -2
diff -X dontdiff -ruN linux-2.5.38/kernel/Makefile statctr-2.5.38/kernel/Makefile
@@ -3,12 +3,12 @@
 #
 
 export-objs = signal.o sys.o kmod.o context.o ksyms.o pm.o exec_domain.o \
-		printk.o platform.o suspend.o dma.o
+		printk.o platform.o suspend.o dma.o statctr.o
 
 obj-y     = sched.o fork.o exec_domain.o panic.o printk.o \
 	    module.o exit.o itimer.o time.o softirq.o resource.o \
 	    sysctl.o capability.o ptrace.o timer.o user.o \
-	    signal.o sys.o kmod.o context.o futex.o platform.o pid.o
+	    signal.o sys.o kmod.o context.o futex.o platform.o pid.o statctr.o
 
 obj-$(CONFIG_GENERIC_ISA_DMA) += dma.o
 obj-$(CONFIG_SMP) += cpu.o
kernel/statctr.c +265 -0

265 lines not on this page · raw message

drivers/net/loopback.c +28 -5
diff -ruN -X dontdiff linux-2.5.38/drivers/net/loopback.c statctr-2.5.38/drivers/net/loopback.c
@@ -39,6 +39,7 @@
 #include <linux/fcntl.h>
 #include <linux/in.h>
 #include <linux/init.h>
+#include <linux/statctr.h>
 
 #include <asm/system.h>
 #include <asm/uaccess.h>
@@ -115,13 +116,23 @@
 	dev_kfree_skb(skb);
 }
 
+/* Use statctrs for frequently used statistics counters. Using statctr avoids
+ * in smp. 
+ */
+
+struct fast_loopback_stats {
+	struct statctr rx_bytes;
+	struct statctr tx_bytes;
+	struct statctr rx_packets;
+	struct statctr tx_packets;
+} lstats;
+
 /*
  * The higher levels take care of making this non-reentrant (it's
  * called with bh's disabled).
  */
 static int loopback_xmit(struct sk_buff *skb, struct net_device *dev)
 {
-	struct net_device_stats *stats = (struct net_device_stats *)dev->priv;
 
 	/*
 	 *	Optimise so buffers with skb->free=1 are not copied but
@@ -160,10 +171,10 @@
 	}
 
 	dev->last_rx = jiffies;
-	stats->rx_bytes+=skb->len;
-	stats->tx_bytes+=skb->len;
-	stats->rx_packets++;
-	stats->tx_packets++;
+	statctr_add(&lstats.rx_bytes, skb->len);
+	statctr_add(&lstats.tx_bytes, skb->len);
+	statctr_inc(&lstats.rx_packets);
+	statctr_inc(&lstats.tx_packets);
 
 	netif_rx(skb);
 
@@ -172,6 +183,11 @@
 
 static struct net_device_stats *get_stats(struct net_device *dev)
 {
+	struct net_device_stats *stats = (struct net_device_stats *)dev->priv;
+	stats->rx_bytes = statctr_read(&lstats.rx_bytes);
+	stats->tx_bytes = statctr_read(&lstats.tx_bytes);
+	stats->rx_packets = statctr_read(&lstats.rx_packets);
+	stats->tx_packets = statctr_read(&lstats.tx_packets);
 	return (struct net_device_stats *)dev->priv;
 }
 
@@ -200,6 +216,13 @@
 	if (dev->priv == NULL)
 			return -ENOMEM;
 	memset(dev->priv, 0, sizeof(struct net_device_stats));
+	
+	if (statctr_ninit(NULL, GFP_KERNEL, 4, &lstats.tx_bytes, 
+				&lstats.rx_bytes, &lstats.tx_packets, 
+				&lstats.rx_packets)) {
+		kfree(dev->priv);
+		return -ENOMEM;
+	}
 	dev->get_stats = get_stats;
 
 	/*