Module Name:    src
Committed By:   yamt
Date:           Wed Nov  2 16:49:12 UTC 2011

Modified Files:
        src/regress/sys/kern/select: select.c

Log Message:
- count the number of bits correctly
- more check
- tweak numbers
- use more accurate time


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/regress/sys/kern/select/select.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/regress/sys/kern/select/select.c
diff -u src/regress/sys/kern/select/select.c:1.2 src/regress/sys/kern/select/select.c:1.3
--- src/regress/sys/kern/select/select.c:1.2	Fri Mar 21 16:03:33 2008
+++ src/regress/sys/kern/select/select.c	Wed Nov  2 16:49:12 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: select.c,v 1.2 2008/03/21 16:03:33 ad Exp $	*/
+/*	$NetBSD: select.c,v 1.3 2011/11/02 16:49:12 yamt Exp $	*/
 
 /*-
  * Copyright (c)2008 YAMAMOTO Takashi,
@@ -29,10 +29,13 @@
 #define	FD_SETSIZE	65536
 #include <sys/select.h>
 #include <sys/atomic.h>
+#include <sys/time.h>
 
+#include <assert.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <pthread.h>
+#include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -40,6 +43,7 @@
 
 #define	NPIPE	128
 #define	NTHREAD	64
+#define	NBALLS	5
 #define	VERBOSE	0
 
 #if !defined(RANDOM_MAX)
@@ -48,7 +52,7 @@
 
 int fds[NPIPE][2];
 
-unsigned count;
+volatile unsigned count;
 
 pthread_barrier_t barrier;
 
@@ -97,10 +101,11 @@ f(void *dummy)
 					abort();
 				}
 				if (random() & 1) {
+					assert(!FD_ISSET(fd, &set));
 					FD_SET(fd, &set);
+					nfd++;
 					if (fd > maxfd) {
 						maxfd = fd;
-						nfd++;
 					}
 				}
 			}
@@ -127,6 +132,12 @@ f(void *dummy)
 			    (void *)pthread_self(), ret);
 			abort();
 		}
+		if (ret > NBALLS) {
+			fprintf(stderr, "[%p] unexpected return value %d"
+			    " > NBALLS\n",
+			    (void *)pthread_self(), ret);
+			abort();
+		}
 		nfd = 0;
 		for (fd = 0; fd <= maxfd; fd++) {
 			if (FD_ISSET(fd, &set)) {
@@ -167,6 +178,10 @@ main(int argc, char *argv[])
 	pthread_t pt[NTHREAD];
 	int i;
 	unsigned int secs;
+	struct timeval start_tv;
+	struct timeval end_tv;
+	uint64_t usecs;
+	unsigned int result;
 
 	secs = atoi(argv[1]);
 
@@ -190,12 +205,17 @@ main(int argc, char *argv[])
 		}
 	}
 	pthread_barrier_wait(&barrier);
-	dowrite();
-	dowrite();
-	dowrite();
-	dowrite();
-
+	gettimeofday(&start_tv, NULL);
+	assert(count == 0);
+	for (i = 0; i < NBALLS; i++) {
+		dowrite();
+	}
 	sleep(secs);
-	printf("%u / %u = %lf\n", count, secs, (double)count / secs);
+	gettimeofday(&end_tv, NULL);
+	result = count;
+	usecs = (end_tv.tv_sec - start_tv.tv_sec) * 1000000
+	    + end_tv.tv_usec - start_tv.tv_usec;
+	printf("%u / %f = %f\n", result, (double)usecs / 1000000,
+	    (double)result / usecs * 1000000);
 	exit(EXIT_SUCCESS);
 }

Reply via email to