diff options
author | mbligh <mbligh@592f7852-d20e-0410-864c-8624ca9c26a4> | 2008-09-23 03:50:08 +0000 |
---|---|---|
committer | mbligh <mbligh@592f7852-d20e-0410-864c-8624ca9c26a4> | 2008-09-23 03:50:08 +0000 |
commit | a701cb95e78d8bbccf05ba76ea9d4794672e54b6 (patch) | |
tree | e036a6e48799da04e473ac7f9c64d255be88877c | |
parent | 486f957f7c913c7ed81568988aa7ad9c98ed7e75 (diff) |
Fix startup race condition.
Signed-off-by: Peter Kukol <pkukol@google.com>
git-svn-id: svn://test.kernel.org/autotest/trunk@2184 592f7852-d20e-0410-864c-8624ca9c26a4
-rwxr-xr-x | client/tests/dbench/dbench.py | 3 | ||||
-rw-r--r-- | client/tests/dbench/dbench_startup.patch | 98 |
2 files changed, 100 insertions, 1 deletions
diff --git a/client/tests/dbench/dbench.py b/client/tests/dbench/dbench.py index d49d2c4e..58bfed47 100755 --- a/client/tests/dbench/dbench.py +++ b/client/tests/dbench/dbench.py @@ -3,7 +3,7 @@ from autotest_lib.client.bin import autotest_utils, test from autotest_lib.client.common_lib import utils class dbench(test.test): - version = 1 + version = 2 def initialize(self): self.job.require_gcc() @@ -15,6 +15,7 @@ class dbench(test.test): autotest_utils.extract_tarball_to_dir(tarball, self.srcdir) os.chdir(self.srcdir) + utils.system('patch -p1 < ../dbench_startup.patch') utils.system('./configure') utils.system('make') diff --git a/client/tests/dbench/dbench_startup.patch b/client/tests/dbench/dbench_startup.patch new file mode 100644 index 00000000..b23e67ce --- /dev/null +++ b/client/tests/dbench/dbench_startup.patch @@ -0,0 +1,98 @@ +diff -u old/ new/ +--- old/Makefile.in 2008-09-18 14:43:55.000000000 -0700 ++++ new/Makefile.in 2008-09-18 14:42:53.000000000 -0700 +@@ -22,10 +22,10 @@ + all: dbench tbench tbench_srv + + dbench: $(DB_OBJS) +- $(CC) -o $@ $(DB_OBJS) $(LIBS) ++ $(CC) -lpthread -o $@ $(DB_OBJS) $(LIBS) + + tbench: $(TB_OBJS) +- $(CC) -o $@ $(TB_OBJS) $(LIBS) ++ $(CC) -lpthread -o $@ $(TB_OBJS) $(LIBS) + + tbench_srv: $(SRV_OBJS) + $(CC) -o $@ $(SRV_OBJS) $(LIBS) +diff -u old/ new/ +--- old/dbench.c 2008-09-18 14:43:49.000000000 -0700 ++++ new/dbench.c 2008-09-18 14:42:46.000000000 -0700 +@@ -130,6 +130,8 @@ + int synccount; + struct timeval tv; + FILE *load; ++ int shmid; ++ sem_t *sema; + + load = open_loadfile(); + if (load == NULL) { +@@ -162,12 +164,24 @@ + children[i].directory = directory; + } + ++ shmid = shmget(IPC_PRIVATE, sizeof(*sema), IPC_CREAT | 0666); ++ if (shmid < 0) { ++ perror("could not create shared memory segment"); ++ exit(1); ++ } ++ sema = shmat(shmid, NULL, 0); ++ ++ if (sem_init(sema, 1, 0) < 0) { ++ perror("semaphore initilization failed"); ++ exit(1); ++ } ++ + for (i=0;i<nprocs;i++) { + if (fork() == 0) { + setlinebuf(stdout); + nb_setup(&children[i]); + children[i].status = getpid(); +- pause(); ++ sem_wait(sema); + fn(&children[i], loadfile); + _exit(0); + } +@@ -185,12 +199,14 @@ + + if (synccount != nprocs) { + printf("FAILED TO START %d CLIENTS (started %d)\n", nprocs, synccount); ++ shmdt(sema); + return; + } + + printf("%d clients started\n", nprocs); + +- kill(0, SIGCONT); ++ for (i=0;i<nprocs;i++) ++ sem_post(sema); + + tv_start = timeval_current(); + +@@ -202,6 +218,7 @@ + if (WEXITSTATUS(status) != 0) { + printf("Child failed with status %d\n", + WEXITSTATUS(status)); ++ shmdt(sema); + exit(1); + } + i++; +@@ -210,6 +227,8 @@ + alarm(0); + sig_alarm(SIGALRM); + ++ shmdt(sema); ++ + printf("\n"); + } + +diff -u old/ new/ +--- old/dbench.h 2008-09-18 14:43:48.000000000 -0700 ++++ new/dbench.h 2008-09-18 14:42:48.000000000 -0700 +@@ -35,6 +35,7 @@ + #include <sys/ipc.h> + #include <sys/shm.h> + #include <sys/mman.h> ++#include <semaphore.h> + + #ifdef HAVE_SYS_VFS_H + #include <sys/vfs.h> |