Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/regress/sys/kern/select - count the number of bits correctly



details:   https://anonhg.NetBSD.org/src/rev/7cb4f86bf279
branches:  trunk
changeset: 770812:7cb4f86bf279
user:      yamt <yamt%NetBSD.org@localhost>
date:      Wed Nov 02 16:49:12 2011 +0000

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

diffstat:

 regress/sys/kern/select/select.c |  38 +++++++++++++++++++++++++++++---------
 1 files changed, 29 insertions(+), 9 deletions(-)

diffs (101 lines):

diff -r 2cd2fd378b75 -r 7cb4f86bf279 regress/sys/kern/select/select.c
--- a/regress/sys/kern/select/select.c  Wed Nov 02 16:45:00 2011 +0000
+++ b/regress/sys/kern/select/select.c  Wed Nov 02 16:49:12 2011 +0000
@@ -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 @@
                                        abort();
                                }
                                if (random() & 1) {
+                                       assert(!FD_ISSET(fd, &set));
                                        FD_SET(fd, &set);
+                                       nfd++;
                                        if (fd > maxfd) {
                                                maxfd = fd;
-                                               nfd++;
                                        }
                                }
                        }
@@ -127,6 +132,12 @@
                            (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 @@
        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 @@
                }
        }
        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);
 }



Home | Main Index | Thread Index | Old Index