[Assorted-commits] SF.net SVN: assorted: [365] numa-bench/trunk/src/malloc.cc
Brought to you by:
yangzhang
From: <yan...@us...> - 2008-02-11 04:57:26
|
Revision: 365 http://assorted.svn.sourceforge.net/assorted/?rev=365&view=rev Author: yangzhang Date: 2008-02-10 20:57:31 -0800 (Sun, 10 Feb 2008) Log Message: ----------- added cpu pinning to malloc Modified Paths: -------------- numa-bench/trunk/src/malloc.cc Modified: numa-bench/trunk/src/malloc.cc =================================================================== --- numa-bench/trunk/src/malloc.cc 2008-02-11 04:57:12 UTC (rev 364) +++ numa-bench/trunk/src/malloc.cc 2008-02-11 04:57:31 UTC (rev 365) @@ -5,17 +5,21 @@ #include <sched.h> +#include <boost/bind.hpp> + #include <commons/check.h> #include <commons/threads.h> #include <commons/time.h> +#include <commons/boost/threads.h> +using namespace boost; using namespace commons; using namespace std; const size_t size = 10000000; void* -chew(void* pp) +chew(void* pp, int core) { char* p = (char*) pp; const int reps = 100; @@ -25,17 +29,16 @@ // Pin this thread to the right processor. cpu_set_t cs; CPU_ZERO(&cs); - CPU_SET(1, &cs); + CPU_SET(core, &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; } } - // Print the elapsed time; + // Print the elapsed time. cout << pid; t.print(); return NULL; @@ -53,21 +56,23 @@ void *p = malloc(size); // warmup - chew(p); + chew(p, 0); 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); + pthread_t t; + check((t = spawn(bind(chew, p, i))) != 0); + check(pthread_join(t, NULL) == 0); } - waitall(ts, n); + // waitall(ts, n); return 0; // THRASH // spawn workers for (int i = 0; i < n; i++) { - check(pthread_create(&ts[i], NULL, chew, p) == 0); + check((ts[i] = spawn(bind(chew, p, i))) == 0); } waitall(ts, n); return 0; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |