Tests the performance of some key vm statistics functions.
Signed-off-by: Christoph Lameter <[email protected]>
---
tests/Kconfig | 7 +++
tests/Makefile | 1
tests/vmstat_test.c | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 105 insertions(+)
create mode 100644 tests/vmstat_test.c
Index: linux-2.6/tests/Makefile
===================================================================
--- linux-2.6.orig/tests/Makefile 2009-10-12 15:13:04.000000000 -0500
+++ linux-2.6/tests/Makefile 2009-10-12 15:15:08.000000000 -0500
@@ -1,2 +1,3 @@
obj-$(CONFIG_BENCHMARK_SLAB) += slab_test.o
+obj-#(CONFIG_BENCHMARK_VMSTAT) += vmstat_test.o
Index: linux-2.6/tests/vmstat_test.c
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ linux-2.6/tests/vmstat_test.c 2009-10-12 15:15:08.000000000 -0500
@@ -0,0 +1,97 @@
+/* test-vmstat.c
+ *
+ * Test module for in kernel synthetic vm statistics performance.
+ *
+ * execute
+ *
+ * modprobe test-vmstat
+ *
+ * to run this test
+ *
+ * (C) 2009 Linux Foundation, Christoph Lameter <[email protected]>
+ */
+
+#include <linux/jiffies.h>
+#include <linux/compiler.h>
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/mm.h>
+#include <asm/timex.h>
+#include <asm/system.h>
+
+#define TEST_COUNT 10000
+
+static int vmstat_test_init(void)
+{
+ unsigned int i;
+ cycles_t time1, time2, time;
+ int rem;
+ struct page *page = alloc_page(GFP_KERNEL);
+
+ printk(KERN_ALERT "VMstat testing\n");
+ printk(KERN_ALERT "=====================\n");
+ printk(KERN_ALERT "1. inc_zone_page_state() then dec_zone_page_state()\n");
+ time1 = get_cycles();
+ for (i = 0; i < TEST_COUNT; i++)
+ inc_zone_page_state(page, NR_BOUNCE);
+
+ time2 = get_cycles();
+ time = time2 - time1;
+
+ printk(KERN_ALERT "%i times inc_zone_page_state() ", i);
+ time = div_u64_rem(time, TEST_COUNT, &rem);
+ printk("-> %llu cycles ", time);
+
+ time1 = get_cycles();
+ for (i = 0; i < TEST_COUNT; i++)
+ __dec_zone_page_state(page, NR_BOUNCE);
+
+ time2 = get_cycles();
+ time = time2 - time1;
+
+ printk("__dec_z_p_s() ");
+ time = div_u64_rem(time, TEST_COUNT, &rem);
+ printk("-> %llu cycles\n", time);
+
+ printk(KERN_ALERT "2. inc_zone_page_state()/dec_zone_page_state()\n");
+ time1 = get_cycles();
+ for (i = 0; i < TEST_COUNT; i++) {
+ inc_zone_page_state(page, NR_BOUNCE);
+ dec_zone_page_state(page, NR_BOUNCE);
+ }
+
+ time2 = get_cycles();
+ time = time2 - time1;
+
+ printk(KERN_ALERT "%i times inc/dec ", i);
+ time = div_u64_rem(time, TEST_COUNT, &rem);
+ printk("-> %llu cycles\n", time);
+
+ printk(KERN_ALERT "3. count_vm_event()\n");
+ time1 = get_cycles();
+ for (i = 0; i < TEST_COUNT; i++)
+ count_vm_event(SLABS_SCANNED);
+
+ time2 = get_cycles();
+ time = time2 - time1;
+
+ count_vm_events(SLABS_SCANNED, -TEST_COUNT);
+ printk(KERN_ALERT "%i count_vm_events ", i);
+ time = div_u64_rem(time, TEST_COUNT, &rem);
+ printk("-> %llu cycles\n", time);
+ __free_page(page);
+ return -EAGAIN; /* Fail will directly unload the module */
+}
+
+static void vmstat_test_exit(void)
+{
+ printk(KERN_ALERT "test exit\n");
+}
+
+module_init(vmstat_test_init)
+module_exit(vmstat_test_exit)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Christoph Lameter");
+MODULE_DESCRIPTION("VM statistics test");
+
Index: linux-2.6/tests/Kconfig
===================================================================
--- linux-2.6.orig/tests/Kconfig 2009-10-12 15:14:54.000000000 -0500
+++ linux-2.6/tests/Kconfig 2009-10-12 15:15:55.000000000 -0500
@@ -15,5 +15,12 @@ config BENCHMARK_SLAB
help
A benchmark that measures slab allocator performance.
+config BENCHMARK_VMSTAT
+ tristate "VM statistics Benchmark"
+ default m
+ depends on m
+ help
+ A benchmark measuring the performance of vm statistics.
+
endif # BENCHMARKS
--