[Assorted-commits] SF.net SVN: assorted: [352] numa-bench
Brought to you by:
yangzhang
From: <yan...@us...> - 2008-02-10 18:37:28
|
Revision: 352 http://assorted.svn.sourceforge.net/assorted/?rev=352&view=rev Author: yangzhang Date: 2008-02-10 10:37:27 -0800 (Sun, 10 Feb 2008) Log Message: ----------- added numa-bench Added Paths: ----------- numa-bench/ numa-bench/trunk/ numa-bench/trunk/README numa-bench/trunk/src/ numa-bench/trunk/src/Makefile numa-bench/trunk/src/avail.cc numa-bench/trunk/src/cache.cc numa-bench/trunk/src/malloc.cc numa-bench/trunk/src/thrash.cc Added: numa-bench/trunk/README =================================================================== --- numa-bench/trunk/README (rev 0) +++ numa-bench/trunk/README 2008-02-10 18:37:27 UTC (rev 352) @@ -0,0 +1,6 @@ +This is an assortment of microbenchmarks for understanding the performance +behavior of NUMA systems and for exploring the Linux NUMA API. + +Revelant materials include the [libnuma whitepaper]. + +[libnuma whitepaper]: http://www.novell.com/collateral/4621437/4621437.pdf Added: numa-bench/trunk/src/Makefile =================================================================== --- numa-bench/trunk/src/Makefile (rev 0) +++ numa-bench/trunk/src/Makefile 2008-02-10 18:37:27 UTC (rev 352) @@ -0,0 +1,15 @@ +COMMONS := $(wildcard commons/*.h) +CXX = g++ -I. -lnuma -o $@ $^ + +all: avail cache + +avail: avail.cc $(COMMONS) + $(CXX) + +cache: cache.cc $(COMMONS) + $(CXX) + +clean: + rm -f avail cache + +.PHONY: clean Added: numa-bench/trunk/src/avail.cc =================================================================== --- numa-bench/trunk/src/avail.cc (rev 0) +++ numa-bench/trunk/src/avail.cc 2008-02-10 18:37:27 UTC (rev 352) @@ -0,0 +1,7 @@ +#include <numa.h> + +int +main() +{ + return numa_available() < 0; +} Added: numa-bench/trunk/src/cache.cc =================================================================== --- numa-bench/trunk/src/cache.cc (rev 0) +++ numa-bench/trunk/src/cache.cc 2008-02-10 18:37:27 UTC (rev 352) @@ -0,0 +1,15 @@ +#include <iostream> +#include <commons/cpuid.h> + +using namespace std; +using namespace commons; + +int +main() +{ + unsigned char iline, dline; + cache_line_sizes_amd(&iline, &dline); + cout << "AMD: " << (unsigned int) iline << ' ' << (unsigned int) dline << endl; + cout << "Intel: " << cache_line_sizes_intel() << endl; + return 0; +} Added: numa-bench/trunk/src/malloc.cc =================================================================== --- numa-bench/trunk/src/malloc.cc (rev 0) +++ numa-bench/trunk/src/malloc.cc 2008-02-10 18:37:27 UTC (rev 352) @@ -0,0 +1,33 @@ +// Does malloc tend to allocate locally? + +#include <cstdlib> +#include <iostream> +#include <time.h> +#include <pthread.h> + +using namespace std; + +const size_t size = 10000000; + +void +touch(void *pp) +{ + char *p = (char*) pp; + const int reps = 100; + time_t t0 = time(NULL); + for (int c = 0; c < reps; c++) { + for (size_t i = 0; i < size; i++) { + p[i] = i; + } + } + time_t t1 = time(NULL); + cout << t1 - t0 << endl; +} + +int +main() +{ + void *p = malloc(size); + touch(p); + return 0; +} Added: numa-bench/trunk/src/thrash.cc =================================================================== --- numa-bench/trunk/src/thrash.cc (rev 0) +++ numa-bench/trunk/src/thrash.cc 2008-02-10 18:37:27 UTC (rev 352) @@ -0,0 +1,38 @@ +#include <iostream> +#include <pthread.h> +#include <unistd.h> + +using namespace std; + +const int size = 100000000; + +void* +f(void* p) +{ + int *xs = (int*) p; + for (int i = 0; i < size; i++) { + xs[i] = i; + } + cout << "hello, world" << endl; +} + +int +main() +{ + const int n = 16; + int *xs = new int[size]; + + pthread_attr_t a; + pthread_attr_init(&a); + + pthread_t t[n]; + for (int i = 0; i < n; i++) { + pthread_create(&t[i], &a, &f, xs); + } + + void *x; + for (int i = 0; i < n; i++) { + pthread_join(t[i], &x); + } + return 0; +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |