diff mbox

[v0,1/3] Synchronize all clients on start up

Message ID 1464858969-23939-2-git-send-email-wagi@monom.org
State New
Headers show

Commit Message

Daniel Wagner June 2, 2016, 9:16 a.m. UTC
From: Daniel Wagner <daniel.wagner@bmw-carit.de>

The child process start working as soon as they are forked. Sometimes
that leads to a workload pattern that no contention happens at all even
with a high number of processes. Since the main motivation of this
this is to benchmark the contention overhead let the clients wait
till all client processes are created.

Signed-off-by: Daniel Wagner <daniel.wagner@bmw-carit.de>
---
 flock01.c | 24 ++++++++++++++++++++++--
 flock02.c | 24 ++++++++++++++++++++++--
 posix01.c | 24 ++++++++++++++++++++++--
 posix02.c | 24 ++++++++++++++++++++++--
 4 files changed, 88 insertions(+), 8 deletions(-)
diff mbox

Patch

diff --git a/flock01.c b/flock01.c
index f5416f6..5335cd2 100644
--- a/flock01.c
+++ b/flock01.c
@@ -29,6 +29,8 @@ 
 #define NRPROC (128)
 #define NRLOCK (10240)
 
+#define TFR TEMP_FAILURE_RETRY
+
 static struct timespec *diff;
 
 static int
@@ -84,7 +86,8 @@  usage(char *prog)
 int
 main(int argc, char **argv)
 {
-	int i, opt, valid = 0;
+	int i, c, opt, valid = 0;
+	int to_lockers[2];
 	int nproc = NRPROC;
 	int nlock = NRLOCK;
 	pid_t *pids;
@@ -123,11 +126,28 @@  main(int argc, char **argv)
 		return 1;
 	}
 
+	if (pipe(to_lockers)) {
+		fprintf(stderr, "pipe (to_lockers)");
+		return 1;
+	}
+
 	for (i = 0; i < nproc; ++i) {
 		pids[i] = fork();
-		if (!pids[i])
+		if (!pids[i]) {
+			while (TFR(read(to_lockers[0], &c, 1)) != 1)
+				;
 			return lockunlock(argv[optind], nlock, &diff[i]);
+		}
+	}
+
+	close(to_lockers[0]);
+	for (i = 0; i < nproc; ++i) {
+		if (TFR(write(to_lockers[1], &c, 1)) != 1) {
+			perror("write child");
+			return 1;
+		}
 	}
+	close(to_lockers[1]);
 
 	for (i = 0; i < nproc; ++i) {
 		int status;
diff --git a/flock02.c b/flock02.c
index 81c770a..7c1a470 100644
--- a/flock02.c
+++ b/flock02.c
@@ -30,6 +30,8 @@ 
 #define NRPROC (128)
 #define NRLOCK (20480)
 
+#define TFR TEMP_FAILURE_RETRY
+
 static struct timespec *diff;
 
 static int
@@ -91,7 +93,8 @@  usage(char *prog)
 int
 main(int argc, char **argv)
 {
-	int i, opt, valid = 0;
+	int i, c, opt, valid = 0;
+	int to_lockers[2];
 	int nproc = NRPROC;
 	int nlock = NRLOCK;
 	pid_t *pids;
@@ -142,11 +145,28 @@  main(int argc, char **argv)
 		return 1;
 	}
 
+	if (pipe(to_lockers)) {
+		fprintf(stderr, "pipe (to_lockers)");
+		return 1;
+	}
+
 	for (i = 0; i < nproc; ++i) {
 		pids[i] = fork();
-		if (!pids[i])
+		if (!pids[i]) {
+			while (TFR(read(to_lockers[0], &c, 1)) != 1)
+				;
 			return lockunlock(nlock, &diff[i]);
+		}
+	}
+
+	close(to_lockers[0]);
+	for (i = 0; i < nproc; ++i) {
+		if (TFR(write(to_lockers[1], &c, 1)) != 1) {
+			perror("write child");
+			return 1;
+		}
 	}
+	close(to_lockers[1]);
 
 	for (i = 0; i < nproc; ++i) {
 		int status;
diff --git a/posix01.c b/posix01.c
index 09f1de6..432a667 100644
--- a/posix01.c
+++ b/posix01.c
@@ -30,6 +30,8 @@ 
 #define NRPROC (128)
 #define NRLOCK (10240)
 
+#define TFR TEMP_FAILURE_RETRY
+
 static struct timespec *diff;
 
 static int
@@ -97,7 +99,8 @@  int
 main(int argc, char **argv)
 {
 	bool verbose = false, yield = false;
-	int i, opt, valid = 0;
+	int i, c, opt, valid = 0;
+	int to_lockers[2];
 	int nproc = NRPROC;
 	int nlock = NRLOCK;
 	pid_t *pids;
@@ -142,12 +145,29 @@  main(int argc, char **argv)
 		return 1;
 	}
 
+	if (pipe(to_lockers)) {
+		fprintf(stderr, "pipe (to_lockers)");
+		return 1;
+	}
+
 	for (i = 0; i < nproc; ++i) {
 		pids[i] = fork();
-		if (!pids[i])
+		if (!pids[i]) {
+			while (TFR(read(to_lockers[0], &c, 1)) != 1)
+				;
 			return lockunlock(argv[optind], nlock,
 						&diff[i], verbose, yield);
+		}
+	}
+
+	close(to_lockers[0]);
+	for (i = 0; i < nproc; ++i) {
+		if (TFR(write(to_lockers[1], &c, 1)) != 1) {
+			perror("write child");
+			return 1;
+		}
 	}
+	close(to_lockers[1]);
 
 	for (i = 0; i < nproc; ++i) {
 		int status;
diff --git a/posix02.c b/posix02.c
index 9a35c99..5fb2a4d 100644
--- a/posix02.c
+++ b/posix02.c
@@ -29,6 +29,8 @@ 
 #define NRPROC (128)
 #define NRLOCK (20480)
 
+#define TFR TEMP_FAILURE_RETRY
+
 static struct timespec *diff;
 
 static int
@@ -93,7 +95,8 @@  usage(char *prog)
 int
 main(int argc, char **argv)
 {
-	int i, opt, valid = 0;
+	int i, c, opt, valid = 0;
+	int to_lockers[2];
 	int nproc = NRPROC;
 	int nlock = NRLOCK;
 	pid_t *pids;
@@ -144,11 +147,28 @@  main(int argc, char **argv)
 		return 1;
 	}
 
+	if (pipe(to_lockers)) {
+		fprintf(stderr, "pipe (to_lockers)");
+		return 1;
+	}
+
 	for (i = 0; i < nproc; ++i) {
 		pids[i] = fork();
-		if (!pids[i])
+		if (!pids[i]) {
+			while (TFR(read(to_lockers[0], &c, 1)) != 1)
+				;
 			return lockunlock(nlock, &diff[i]);
+		}
+	}
+
+	close(to_lockers[0]);
+	for (i = 0; i < nproc; ++i) {
+		if (TFR(write(to_lockers[1], &c, 1)) != 1) {
+			perror("write child");
+			return 1;
+		}
 	}
+	close(to_lockers[1]);
 
 	for (i = 0; i < nproc; ++i) {
 		int status;