[Assorted-commits] SF.net SVN: assorted: [356] numa-bench/trunk/src
Brought to you by:
yangzhang
From: <yan...@us...> - 2008-02-10 21:48:13
|
Revision: 356 http://assorted.svn.sourceforge.net/assorted/?rev=356&view=rev Author: yangzhang Date: 2008-02-10 13:48:17 -0800 (Sun, 10 Feb 2008) Log Message: ----------- updates Modified Paths: -------------- numa-bench/trunk/src/Makefile numa-bench/trunk/src/malloc.cc Added Paths: ----------- numa-bench/trunk/src/openmp.cc numa-bench/trunk/src/threads.cc Modified: numa-bench/trunk/src/Makefile =================================================================== --- numa-bench/trunk/src/Makefile 2008-02-10 18:52:12 UTC (rev 355) +++ numa-bench/trunk/src/Makefile 2008-02-10 21:48:17 UTC (rev 356) @@ -1,7 +1,8 @@ COMMONS := $(wildcard commons/*.h) -CXX = g++ -I. -lnuma -o $@ $^ +CXX = g++-4.2 -I. -lnuma -lpthread -o $@ $^ -all: avail cache +# all: avail cache malloc threads +all: malloc avail: avail.cc $(COMMONS) $(CXX) @@ -9,6 +10,15 @@ cache: cache.cc $(COMMONS) $(CXX) +malloc: malloc.cc $(COMMONS) + $(CXX) + +threads: threads.cc $(COMMONS) + $(CXX) + +openmp: openmp.cc + $(CXX) -fopenmp + clean: rm -f avail cache Modified: numa-bench/trunk/src/malloc.cc =================================================================== --- numa-bench/trunk/src/malloc.cc 2008-02-10 18:52:12 UTC (rev 355) +++ numa-bench/trunk/src/malloc.cc 2008-02-10 21:48:17 UTC (rev 356) @@ -2,32 +2,73 @@ #include <cstdlib> #include <iostream> -#include <time.h> -#include <pthread.h> +#include <sched.h> + +#include <commons/check.h> +#include <commons/threads.h> +#include <commons/time.h> + +using namespace commons; using namespace std; const size_t size = 10000000; -void -touch(void *pp) +void* +chew(void* pp) { - char *p = (char*) pp; + char* p = (char*) pp; const int reps = 100; - time_t t0 = time(NULL); + pid_t pid = gettid(); + timer t(": "); + + // Pin this thread to the right processor. + cpu_set_t cs; + CPU_ZERO(&cs); + CPU_SET(1, &cs); + sched_setaffinity(pid, sizeof(cs), &cs); + + // TODO: try shuffling indexes 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; + + // Print the elapsed time; + cout << pid; + t.print(); + return NULL; } int -main() +main(int argc, char** argv) { + if (argc < 2) { + cerr << "malloc <nthreads>" << endl; + return 1; + } + + const int n = atoi(argv[1]); void *p = malloc(size); - touch(p); + + // warmup + chew(p); + pthread_t ts[n]; + + // start thread on each core + for (int i = 0; i < n; i++) { + check(pthread_create(&ts[i], NULL, chew, p) == 0); + } + waitall(ts, n); return 0; + + // THRASH + + // spawn workers + for (int i = 0; i < n; i++) { + check(pthread_create(&ts[i], NULL, chew, p) == 0); + } + waitall(ts, n); + return 0; } Added: numa-bench/trunk/src/openmp.cc =================================================================== --- numa-bench/trunk/src/openmp.cc (rev 0) +++ numa-bench/trunk/src/openmp.cc 2008-02-10 21:48:17 UTC (rev 356) @@ -0,0 +1,7 @@ +#pragma omp + +int +main() +{ + return 0; +} Added: numa-bench/trunk/src/threads.cc =================================================================== --- numa-bench/trunk/src/threads.cc (rev 0) +++ numa-bench/trunk/src/threads.cc 2008-02-10 21:48:17 UTC (rev 356) @@ -0,0 +1,30 @@ +/** + * Demonstrates that each thread has its own unique TID. + */ + +#include <iostream> + +#include <pthread.h> +#include <sys/types.h> +#include <commons/threads.h> + +using namespace std; +using namespace commons; + +void* +print_tid(void*) +{ + pid_t pid = gettid(); + (pid_t)syscall(__NR_gettid); + cout << pid << endl; +} + +int +main() +{ + pthread_t t; + pthread_create(&t, NULL, &print_tid, NULL); + print_tid(NULL); + pthread_join(t, NULL); + return 0; +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |