From patchwork Thu Jun 2 09:16:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Wagner X-Patchwork-Id: 9149603 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3E30E60221 for ; Thu, 2 Jun 2016 09:16:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2D93B254F7 for ; Thu, 2 Jun 2016 09:16:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 22ABC26907; Thu, 2 Jun 2016 09:16:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F3BB6254F7 for ; Thu, 2 Jun 2016 09:16:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932230AbcFBJQV (ORCPT ); Thu, 2 Jun 2016 05:16:21 -0400 Received: from hotel311.server4you.de ([85.25.146.15]:44126 "EHLO hotel311.server4you.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752849AbcFBJQS (ORCPT ); Thu, 2 Jun 2016 05:16:18 -0400 Received: from hotel311.server4you.de (localhost [127.0.0.1]) by filter.mynetwork.local (Postfix) with ESMTP id 9A68E194192D; Thu, 2 Jun 2016 11:16:14 +0200 (CEST) Received: from localhost (unknown [212.118.206.70]) by hotel311.server4you.de (Postfix) with ESMTPSA id 5B70719414E6; Thu, 2 Jun 2016 11:16:14 +0200 (CEST) From: Daniel Wagner To: Jeff Layton Cc: linux-fsdevel@vger.kernel.org, Dave Chinner , Daniel Wagner Subject: [PATCH v0 1/3] Synchronize all clients on start up Date: Thu, 2 Jun 2016 11:16:07 +0200 Message-Id: <1464858969-23939-2-git-send-email-wagi@monom.org> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1464858969-23939-1-git-send-email-wagi@monom.org> References: <1464858969-23939-1-git-send-email-wagi@monom.org> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Daniel Wagner 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 --- flock01.c | 24 ++++++++++++++++++++++-- flock02.c | 24 ++++++++++++++++++++++-- posix01.c | 24 ++++++++++++++++++++++-- posix02.c | 24 ++++++++++++++++++++++-- 4 files changed, 88 insertions(+), 8 deletions(-) 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;