[openib-general] [PATCH] IB/perftest: Fix get_median, size of delta, usage(), worst latency

CH Ganapathi cganapathi at novell.com
Wed Aug 30 23:09:14 PDT 2006


Hi,

1) When iters (exchanges) is even, delta has odd no.of elements and when iters 
    is odd, delta has even no.of elements. Hence when (iters - 1) is passed 
    get_median() uses incorrect indexes to find the median.
For example: 
  When iters = 2 , get_median returns median = (delta[0] + delta[-1])/2 when it 
                     should have been median = delta[0].
  When iters = 3 get_median returns median = delta[1] when actually it should
                     have been median = (delta[0] + delta[1])/2.

2) The array delta requires only (iters - 1) size to be allocated.
3) Worst latency is delta[iters - 2] in read_lat.c, not delta[iters - 3].
4) usage() in write_bw.c incorrectly states default exchanges as 1000.

Thanks,
Ganapathi
Novell Inc.

The following patch includes:

o Fix get_median.
o Change usage() in write_bw.c to match the actual default of exchanges.
o Fix worst latency in read_lat.c.
o Allocate only the necessary (iters - 1) elements for delta.

Signed-off-by: Ganapathi CH <cganapathi at novell.com>

Index: userspace/perftest/read_lat.c
===================================================================
--- userspace/perftest/read_lat.c	(revision 9196)
+++ userspace/perftest/read_lat.c	(working copy)
@@ -568,7 +568,7 @@
  */
 static inline cycles_t get_median(int n, cycles_t delta[])
 {
-	if (n % 2)
+	if ((n - 1) % 2)
 		return(delta[n / 2] + delta[n / 2 - 1]) / 2;
 	else
 		return delta[n / 2];
@@ -591,7 +591,7 @@
 	cycles_t median;
 	unsigned int i;
 	const char* units;
-	cycles_t *delta = malloc(iters * sizeof *delta);
+	cycles_t *delta = malloc((iters - 1) * sizeof *delta);
 
 	if (!delta) {
 		perror("malloc");
@@ -627,7 +627,7 @@
 	median = get_median(iters - 1, delta);
 	printf("%7d        %d        %7.2f        %7.2f          %7.2f\n",
 	       size,iters,delta[0] / cycles_to_units ,
-	       delta[iters - 3] / cycles_to_units ,median / cycles_to_units );
+	       delta[iters - 2] / cycles_to_units ,median / cycles_to_units );
 
 	free(delta);
 }
Index: userspace/perftest/write_bw.c
===================================================================
--- userspace/perftest/write_bw.c	(revision 9196)
+++ userspace/perftest/write_bw.c	(working copy)
@@ -509,7 +509,7 @@
 	printf("  -s, --size=<size>         size of message to exchange (default 65536)\n");
 	printf("  -a, --all                 Run sizes from 2 till 2^23\n");
 	printf("  -t, --tx-depth=<dep>      size of tx queue (default 100)\n");
-	printf("  -n, --iters=<iters>       number of exchanges (at least 2, default 1000)\n");
+	printf("  -n, --iters=<iters>       number of exchanges (at least 2, default 5000)\n");
 	printf("  -b, --bidirectional       measure bidirectional bandwidth (default unidirectional)\n");
 	printf("  -V, --version             display version number\n");
 }
Index: userspace/perftest/rdma_lat.c
===================================================================
--- userspace/perftest/rdma_lat.c	(revision 9196)
+++ userspace/perftest/rdma_lat.c	(working copy)
@@ -516,7 +516,7 @@
  */
 static inline cycles_t get_median(int n, cycles_t delta[])
 {
-	if (n % 2)
+	if ((n - 1) % 2)
 		return (delta[n / 2] + delta[n / 2 - 1]) / 2;
 	else
 		return delta[n / 2];
@@ -538,7 +538,7 @@
 	cycles_t median;
 	unsigned int i;
 	const char* units;
-	cycles_t *delta = malloc(iters * sizeof *delta);
+	cycles_t *delta = malloc((iters - 1) * sizeof *delta);
 
  	if (!delta) {
 		perror("malloc");
Index: userspace/perftest/send_lat.c
===================================================================
--- userspace/perftest/send_lat.c	(revision 9196)
+++ userspace/perftest/send_lat.c	(working copy)
@@ -678,7 +678,7 @@
  */
 static inline cycles_t get_median(int n, cycles_t delta[])
 {
-	if (n % 2)
+	if ((n - 1) % 2)
 		return(delta[n / 2] + delta[n / 2 - 1]) / 2;
 	else
 		return delta[n / 2];
@@ -701,7 +701,7 @@
 	cycles_t median;
 	unsigned int i;
 	const char* units;
-	cycles_t *delta = malloc(iters * sizeof *delta);
+	cycles_t *delta = malloc((iters - 1) * sizeof *delta);
 
 	if (!delta) {
 		perror("malloc");
Index: userspace/perftest/write_lat.c
===================================================================
--- userspace/perftest/write_lat.c	(revision 9196)
+++ userspace/perftest/write_lat.c	(working copy)
@@ -579,7 +579,7 @@
  */
 static inline cycles_t get_median(int n, cycles_t delta[])
 {
-	if (n % 2)
+	if ((n - 1) % 2)
 		return(delta[n / 2] + delta[n / 2 - 1]) / 2;
 	else
 		return delta[n / 2];
@@ -602,7 +602,7 @@
 	cycles_t median;
 	unsigned int i;
 	const char* units;
-	cycles_t *delta = malloc(iters * sizeof *delta);
+	cycles_t *delta = malloc((iters - 1) * sizeof *delta);
 
 	if (!delta) {
 		perror("malloc");





More information about the general mailing list