From f211bc6c8e798e23f6d1f49cf97d5e837de9b982 Mon Sep 17 00:00:00 2001 From: compudj Date: Wed, 22 Aug 2007 00:33:32 +0000 Subject: [PATCH] update git-svn-id: http://ltt.polymtl.ca/svn@2594 04897980-b3bd-0310-b5e0-8ef037075253 --- tests/kernel/Makefile | 10 +- tests/kernel/test-showval.c | 35 +++++++ tests/kernel/test-slub.c | 182 ++++++++++++++++++++++++++++++++++ tests/kernel/test-slub2.c | 191 ++++++++++++++++++++++++++++++++++++ 4 files changed, 417 insertions(+), 1 deletion(-) create mode 100644 tests/kernel/test-showval.c create mode 100644 tests/kernel/test-slub.c create mode 100644 tests/kernel/test-slub2.c diff --git a/tests/kernel/Makefile b/tests/kernel/Makefile index af5ffd81..6c840fee 100644 --- a/tests/kernel/Makefile +++ b/tests/kernel/Makefile @@ -12,9 +12,16 @@ ifneq ($(CONFIG_LTT),) #obj-m += ltt-probe-tests.o #obj-m += test-time-probe3.o endif + obj-m += test-slub.o + obj-m += test-slub2.o + obj-m += test-showval.o #obj-m += cond_call.o #obj-m += cond_call2.o - obj-m += test-irq-latency.o +# obj-m += test-irq-latency.o +# obj-m += test-kprobes2.o +# obj-m += test-imval.o + #obj-m += test-imval-bug.o +# obj-m += test-imvalw.o #obj-m += list-mark.o #obj-m += test-rodata.o #obj-m += test-tlb.o @@ -35,6 +42,7 @@ endif # obj-m += test-cmpxchg.o # obj-m += test-cmpxchg-nolock.o obj-m += test-cmpxchg-nolock2.o + obj-m += test-cmpxchg8b.o # obj-m += test-spinlock.o # obj-m += test-inc.o # obj-m += test-inc-nolock.o diff --git a/tests/kernel/test-showval.c b/tests/kernel/test-showval.c new file mode 100644 index 00000000..18fcaa6d --- /dev/null +++ b/tests/kernel/test-showval.c @@ -0,0 +1,35 @@ +/* test-slub.c + * + * Compare local cmpxchg with irq disable / enable with cmpxchg_local for slub. + */ + + +#include +#include +#include +#include +#include +#include +#include + +extern atomic_t slub_fast_count; +extern atomic_t slub_slow_count; + +static int slub_test_init(void) +{ + printk("Fast slub free: %u\n", atomic_read(&slub_fast_count)); + printk("Slow slub free: %u\n", atomic_read(&slub_slow_count)); + return -EAGAIN; /* Fail will directly unload the module */ +} + +static void slub_test_exit(void) +{ + printk(KERN_ALERT "test exit\n"); +} + +module_init(slub_test_init) +module_exit(slub_test_exit) + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Mathieu Desnoyers"); +MODULE_DESCRIPTION("SLUB test"); diff --git a/tests/kernel/test-slub.c b/tests/kernel/test-slub.c new file mode 100644 index 00000000..88cb59c4 --- /dev/null +++ b/tests/kernel/test-slub.c @@ -0,0 +1,182 @@ +/* test-slub.c + * + * Compare local cmpxchg with irq disable / enable with cmpxchg_local for slub. + */ + + +#include +#include +#include +#include +#include +#include +#include + +#define TEST_COUNT 10000 + +static int slub_test_init(void) +{ + void **v = kmalloc(TEST_COUNT * sizeof(void *), GFP_KERNEL); + unsigned int i; + cycles_t time1, time2, time; + long rem; + int size; + + printk(KERN_ALERT "test init\n"); + + printk(KERN_ALERT "SLUB Performance testing\n"); + printk(KERN_ALERT "========================\n"); + printk(KERN_ALERT "1. Kmalloc: Repeatedly allocate then free test\n"); + for (size = 8; size <= PAGE_SIZE << 2; size <<= 1) { + time1 = get_cycles(); + for (i = 0; i < TEST_COUNT; i++) { + v[i] = kmalloc(size, GFP_KERNEL); + } + time2 = get_cycles(); + time = time2 - time1; + + printk(KERN_ALERT "%i times kmalloc(%d) = \n", i, size); + printk(KERN_ALERT "number of loops: %d\n", TEST_COUNT); + printk(KERN_ALERT "total time: %llu\n", time); + time = div_long_long_rem(time, TEST_COUNT, &rem); + printk(KERN_ALERT "-> %llu cycles\n", time); + + time1 = get_cycles(); + for (i = 0; i < TEST_COUNT; i++) { + kfree(v[i]); + } + time2 = get_cycles(); + time = time2 - time1; + + printk(KERN_ALERT "%i times kfree = \n", i); + printk(KERN_ALERT "number of loops: %d\n", TEST_COUNT); + printk(KERN_ALERT "total time: %llu\n", time); + time = div_long_long_rem(time, TEST_COUNT, &rem); + printk(KERN_ALERT "-> %llu cycles\n", time); + } + + printk(KERN_ALERT "2. Kmalloc: alloc/free test\n"); + for (size = 8; size <= PAGE_SIZE << 2; size <<= 1) { + time1 = get_cycles(); + for (i = 0; i < TEST_COUNT; i++) { + kfree(kmalloc(size, GFP_KERNEL)); + } + time2 = get_cycles(); + time = time2 - time1; + + printk(KERN_ALERT "%i times kmalloc(%d)/kfree = \n", i, size); + printk(KERN_ALERT "number of loops: %d\n", TEST_COUNT); + printk(KERN_ALERT "total time: %llu\n", time); + time = div_long_long_rem(time, TEST_COUNT, &rem); + printk(KERN_ALERT "-> %llu cycles\n", time); + } +#if 0 + printk(KERN_ALERT "3. kmem_cache_alloc: Repeatedly allocate then free test\n"); + for (size = 3; size <= PAGE_SHIFT; size ++) { + time1 = get_cycles(); + for (i = 0; i < TEST_COUNT; i++) { + v[i] = kmem_cache_alloc(kmalloc_caches + size, GFP_KERNEL); + } + time2 = get_cycles(); + time = time2 - time1; + + printk(KERN_ALERT "%d times kmem_cache_alloc(%d) = \n", i, 1 << size); + printk(KERN_ALERT "number of loops: %d\n", TEST_COUNT); + printk(KERN_ALERT "total time: %llu\n", time); + time = div_long_long_rem(time, TEST_COUNT, &rem); + printk(KERN_ALERT "-> %llu cycles\n", time); + + time1 = get_cycles(); + for (i = 0; i < TEST_COUNT; i++) { + kmem_cache_free(kmalloc_caches + size, v[i]); + } + time2 = get_cycles(); + time = time2 - time1; + + printk(KERN_ALERT "%i times kmem_cache_free = \n", i); + printk(KERN_ALERT "number of loops: %d\n", TEST_COUNT); + printk(KERN_ALERT "total time: %llu\n", time); + time = div_long_long_rem(time, TEST_COUNT, &rem); + printk(KERN_ALERT "-> %llu cycles\n", time); + } + + printk(KERN_ALERT "4. kmem_cache_alloc: alloc/free test\n"); + for (size = 3; size <= PAGE_SHIFT; size++) { + time1 = get_cycles(); + for (i = 0; i < TEST_COUNT; i++) { + kmem_cache_free(kmalloc_caches + size, + kmem_cache_alloc(kmalloc_caches + size, + GFP_KERNEL)); + } + time2 = get_cycles(); + time = time2 - time1; + + printk(KERN_ALERT "%d times kmem_cache_alloc(%d)/kmem_cache_free = \n", i, 1 << size); + printk(KERN_ALERT "number of loops: %d\n", TEST_COUNT); + printk(KERN_ALERT "total time: %llu\n", time); + time = div_long_long_rem(time, TEST_COUNT, &rem); + printk(KERN_ALERT "-> %llu cycles\n", time); + } + printk(KERN_ALERT "5. kmem_cache_zalloc: Repeatedly allocate then free test\n"); + for (size = 3; size <= PAGE_SHIFT; size ++) { + time1 = get_cycles(); + for (i = 0; i < TEST_COUNT; i++) { + v[i] = kmem_cache_zalloc(kmalloc_caches + size, GFP_KERNEL); + } + time2 = get_cycles(); + time = time2 - time1; + + printk(KERN_ALERT "%d times kmem_cache_zalloc(%d) = \n", i, 1 << size); + printk(KERN_ALERT "number of loops: %d\n", TEST_COUNT); + printk(KERN_ALERT "total time: %llu\n", time); + time = div_long_long_rem(time, TEST_COUNT, &rem); + printk(KERN_ALERT "-> %llu cycles\n", time); + + time1 = get_cycles(); + for (i = 0; i < TEST_COUNT; i++) { + kmem_cache_free(kmalloc_caches + size, v[i]); + } + time2 = get_cycles(); + time = time2 - time1; + + printk(KERN_ALERT "%i times kmem_cache_free = \n", i); + printk(KERN_ALERT "number of loops: %d\n", TEST_COUNT); + printk(KERN_ALERT "total time: %llu\n", time); + time = div_long_long_rem(time, TEST_COUNT, &rem); + printk(KERN_ALERT "-> %llu cycles\n", time); + } + + printk(KERN_ALERT "6. kmem_cache_zalloc: alloc/free test\n"); + for (size = 3; size <= PAGE_SHIFT; size++) { + time1 = get_cycles(); + for (i = 0; i < TEST_COUNT; i++) { + kmem_cache_free(kmalloc_caches + size, + kmem_cache_zalloc(kmalloc_caches + size, + GFP_KERNEL)); + } + time2 = get_cycles(); + time = time2 - time1; + + printk(KERN_ALERT "%d times kmem_cache_zalloc(%d)/kmem_cache_free = \n", i, 1 << size); + printk(KERN_ALERT "number of loops: %d\n", TEST_COUNT); + printk(KERN_ALERT "total time: %llu\n", time); + time = div_long_long_rem(time, TEST_COUNT, &rem); + printk(KERN_ALERT "-> %llu cycles\n", time); + + } +#endif //0 + kfree(v); + return -EAGAIN; /* Fail will directly unload the module */ +} + +static void slub_test_exit(void) +{ + printk(KERN_ALERT "test exit\n"); +} + +module_init(slub_test_init) +module_exit(slub_test_exit) + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Mathieu Desnoyers"); +MODULE_DESCRIPTION("SLUB test"); diff --git a/tests/kernel/test-slub2.c b/tests/kernel/test-slub2.c new file mode 100644 index 00000000..5d302a35 --- /dev/null +++ b/tests/kernel/test-slub2.c @@ -0,0 +1,191 @@ +/* test-slub.c + * + * Compare local cmpxchg with irq disable / enable with cmpxchg_local for slub. + */ + + +#include +#include +#include +#include +#include +#include +#include + +#define TEST_COUNT 10000 + +extern atomic_t slub_fast_count; +extern atomic_t slub_slow_count; + +static int slub_test_init(void) +{ + void **v = kmalloc(TEST_COUNT * sizeof(void *), GFP_KERNEL); + unsigned int i; + cycles_t time1, time2, time; + long rem; + int size; + + printk(KERN_ALERT "test init\n"); + + printk("Fast slub free: %u\n", atomic_read(&slub_fast_count)); + printk("Slow slub free: %u\n", atomic_read(&slub_slow_count)); + printk(KERN_ALERT "SLUB Performance testing\n"); + printk(KERN_ALERT "========================\n"); + printk(KERN_ALERT "1. Kmalloc: Repeatedly allocate then free test\n"); + for (size = 8; size <= PAGE_SIZE << 2; size <<= 1) { + time1 = get_cycles(); + for (i = 0; i < TEST_COUNT; i++) { + v[i] = kmalloc(size, GFP_KERNEL); + } + time2 = get_cycles(); + time = time2 - time1; + + printk(KERN_ALERT "%i times kmalloc(%d) = \n", i, size); + printk(KERN_ALERT "number of loops: %d\n", TEST_COUNT); + printk(KERN_ALERT "total time: %llu\n", time); + time = div_long_long_rem(time, TEST_COUNT, &rem); + printk(KERN_ALERT "-> %llu cycles\n", time); + + time1 = get_cycles(); + for (i = 0; i < TEST_COUNT; i++) { + kfree(v[i]); + } + time2 = get_cycles(); + time = time2 - time1; + + printk(KERN_ALERT "%i times kfree = \n", i); + printk(KERN_ALERT "number of loops: %d\n", TEST_COUNT); + printk(KERN_ALERT "total time: %llu\n", time); + time = div_long_long_rem(time, TEST_COUNT, &rem); + printk(KERN_ALERT "-> %llu cycles\n", time); + } + printk("Fast slub free: %u\n", atomic_read(&slub_fast_count)); + printk("Slow slub free: %u\n", atomic_read(&slub_slow_count)); + + printk(KERN_ALERT "2. Kmalloc: alloc/free test\n"); + for (size = 8; size <= PAGE_SIZE << 2; size <<= 1) { + time1 = get_cycles(); + for (i = 0; i < TEST_COUNT; i++) { + kfree(kmalloc(size, GFP_KERNEL)); + } + time2 = get_cycles(); + time = time2 - time1; + + printk(KERN_ALERT "%i times kmalloc(%d)/kfree = \n", i, size); + printk(KERN_ALERT "number of loops: %d\n", TEST_COUNT); + printk(KERN_ALERT "total time: %llu\n", time); + time = div_long_long_rem(time, TEST_COUNT, &rem); + printk(KERN_ALERT "-> %llu cycles\n", time); + } + printk("Fast slub free: %u\n", atomic_read(&slub_fast_count)); + printk("Slow slub free: %u\n", atomic_read(&slub_slow_count)); +#if 0 + printk(KERN_ALERT "3. kmem_cache_alloc: Repeatedly allocate then free test\n"); + for (size = 3; size <= PAGE_SHIFT; size ++) { + time1 = get_cycles(); + for (i = 0; i < TEST_COUNT; i++) { + v[i] = kmem_cache_alloc(kmalloc_caches + size, GFP_KERNEL); + } + time2 = get_cycles(); + time = time2 - time1; + + printk(KERN_ALERT "%d times kmem_cache_alloc(%d) = \n", i, 1 << size); + printk(KERN_ALERT "number of loops: %d\n", TEST_COUNT); + printk(KERN_ALERT "total time: %llu\n", time); + time = div_long_long_rem(time, TEST_COUNT, &rem); + printk(KERN_ALERT "-> %llu cycles\n", time); + + time1 = get_cycles(); + for (i = 0; i < TEST_COUNT; i++) { + kmem_cache_free(kmalloc_caches + size, v[i]); + } + time2 = get_cycles(); + time = time2 - time1; + + printk(KERN_ALERT "%i times kmem_cache_free = \n", i); + printk(KERN_ALERT "number of loops: %d\n", TEST_COUNT); + printk(KERN_ALERT "total time: %llu\n", time); + time = div_long_long_rem(time, TEST_COUNT, &rem); + printk(KERN_ALERT "-> %llu cycles\n", time); + } + + printk(KERN_ALERT "4. kmem_cache_alloc: alloc/free test\n"); + for (size = 3; size <= PAGE_SHIFT; size++) { + time1 = get_cycles(); + for (i = 0; i < TEST_COUNT; i++) { + kmem_cache_free(kmalloc_caches + size, + kmem_cache_alloc(kmalloc_caches + size, + GFP_KERNEL)); + } + time2 = get_cycles(); + time = time2 - time1; + + printk(KERN_ALERT "%d times kmem_cache_alloc(%d)/kmem_cache_free = \n", i, 1 << size); + printk(KERN_ALERT "number of loops: %d\n", TEST_COUNT); + printk(KERN_ALERT "total time: %llu\n", time); + time = div_long_long_rem(time, TEST_COUNT, &rem); + printk(KERN_ALERT "-> %llu cycles\n", time); + } + printk(KERN_ALERT "5. kmem_cache_zalloc: Repeatedly allocate then free test\n"); + for (size = 3; size <= PAGE_SHIFT; size ++) { + time1 = get_cycles(); + for (i = 0; i < TEST_COUNT; i++) { + v[i] = kmem_cache_zalloc(kmalloc_caches + size, GFP_KERNEL); + } + time2 = get_cycles(); + time = time2 - time1; + + printk(KERN_ALERT "%d times kmem_cache_zalloc(%d) = \n", i, 1 << size); + printk(KERN_ALERT "number of loops: %d\n", TEST_COUNT); + printk(KERN_ALERT "total time: %llu\n", time); + time = div_long_long_rem(time, TEST_COUNT, &rem); + printk(KERN_ALERT "-> %llu cycles\n", time); + + time1 = get_cycles(); + for (i = 0; i < TEST_COUNT; i++) { + kmem_cache_free(kmalloc_caches + size, v[i]); + } + time2 = get_cycles(); + time = time2 - time1; + + printk(KERN_ALERT "%i times kmem_cache_free = \n", i); + printk(KERN_ALERT "number of loops: %d\n", TEST_COUNT); + printk(KERN_ALERT "total time: %llu\n", time); + time = div_long_long_rem(time, TEST_COUNT, &rem); + printk(KERN_ALERT "-> %llu cycles\n", time); + } + + printk(KERN_ALERT "6. kmem_cache_zalloc: alloc/free test\n"); + for (size = 3; size <= PAGE_SHIFT; size++) { + time1 = get_cycles(); + for (i = 0; i < TEST_COUNT; i++) { + kmem_cache_free(kmalloc_caches + size, + kmem_cache_zalloc(kmalloc_caches + size, + GFP_KERNEL)); + } + time2 = get_cycles(); + time = time2 - time1; + + printk(KERN_ALERT "%d times kmem_cache_zalloc(%d)/kmem_cache_free = \n", i, 1 << size); + printk(KERN_ALERT "number of loops: %d\n", TEST_COUNT); + printk(KERN_ALERT "total time: %llu\n", time); + time = div_long_long_rem(time, TEST_COUNT, &rem); + printk(KERN_ALERT "-> %llu cycles\n", time); + + } +#endif //0 + kfree(v); + return -EAGAIN; /* Fail will directly unload the module */ +} + +static void slub_test_exit(void) +{ + printk(KERN_ALERT "test exit\n"); +} + +module_init(slub_test_init) +module_exit(slub_test_exit) + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Mathieu Desnoyers"); +MODULE_DESCRIPTION("SLUB test"); -- 2.34.1