summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Slocum <j.m.slocum@gmail.com>2013-10-03 21:16:39 -0400
committerJames Slocum <j.m.slocum@gmail.com>2013-10-03 21:16:39 -0400
commitbf194646e7a4bd348fd6033b183a1fd78a0aaef1 (patch)
treefe51dfa05dcfc91f56577eb08a85785d9a931466
parent93a74f64ce6e30e940ebbf456bf35679bca8d668 (diff)
Fixed 2 bugs.
Fixed a segfault, and read error. 1) the for(t=0; t<array_size; t+=block_size) loop could write past the end of the buffer and segfault 2) The 'a' buffer was not being advanced, causing the same memory to be read over and over, this caused heavy cache hits and unrealistically high results.
-rw-r--r--README1
-rw-r--r--mbw.c9
2 files changed, 7 insertions, 3 deletions
diff --git a/README b/README
index 0c6f722..218fd8b 100644
--- a/README
+++ b/README
@@ -1,6 +1,7 @@
MBW determines the "copy" memory bandwidth available to userspace programs. Its simplistic approach models that of real applications. It is not tuned to extremes and it is not aware of hardware architecture, just like your average software package.
2006, 2012 Andras.Horvath atnospam gmail.com
+2013 j.m.slocum atnospam gmail.com
http://github.com/raas/mbw
diff --git a/mbw.c b/mbw.c
index 3a02826..1c6fe63 100644
--- a/mbw.c
+++ b/mbw.c
@@ -27,6 +27,8 @@
* MBW memory bandwidth benchmark
*
* 2006, 2012 Andras.Horvath@gmail.com
+ * 2013 j.m.slocum@gmail.com
+ * (Special thanks to Stephen Pasich)
*
* http://github.com/raas/mbw
*
@@ -97,6 +99,7 @@ double worker(unsigned long long asize, long *a, long *b, int type, unsigned lon
unsigned int long_size=sizeof(long);
/* array size in bytes */
unsigned long long array_bytes=asize*long_size;
+ unsigned int advance=block_size/long_size;
if(type==1) { /* memcpy test */
/* timer starts */
@@ -106,11 +109,11 @@ double worker(unsigned long long asize, long *a, long *b, int type, unsigned lon
gettimeofday(&endtime, NULL);
} else if(type==2) { /* memcpy block test */
gettimeofday(&starttime, NULL);
- for(t=0; t<array_bytes; t+=block_size) {
+ for (t=array_bytes; t >= block_size; t-=block_size, a+=advance){
b=mempcpy(b, a, block_size);
}
- if(t>array_bytes) {
- b=mempcpy(b, a, t-array_bytes);
+ if(t) {
+ b=mempcpy(b, a, t);
}
gettimeofday(&endtime, NULL);
} else { /* dumb test */