From patchwork Thu Sep 22 08:46:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Wagner X-Patchwork-Id: 9344759 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 DC42B601C2 for ; Thu, 22 Sep 2016 08:47:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CD7832A8D9 for ; Thu, 22 Sep 2016 08:47:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C25DA2A8DB; Thu, 22 Sep 2016 08:47:11 +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=unavailable 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 E62022A8DA for ; Thu, 22 Sep 2016 08:47:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933445AbcIVIq7 (ORCPT ); Thu, 22 Sep 2016 04:46:59 -0400 Received: from atlantic540.startdedicated.de ([188.138.9.77]:43331 "EHLO atlantic540.startdedicated.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933243AbcIVIq5 (ORCPT ); Thu, 22 Sep 2016 04:46:57 -0400 Received: from atlantic540.startdedicated.de (localhost [127.0.0.1]) by filter.mynetwork.local (Postfix) with ESMTP id 3987A5001D3; Thu, 22 Sep 2016 10:46:50 +0200 (CEST) Received: from localhost (unknown [212.118.206.70]) by atlantic540.startdedicated.de (Postfix) with ESMTPSA id D36115001D4; Thu, 22 Sep 2016 10:46:49 +0200 (CEST) From: Daniel Wagner To: Jeff Layton Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Daniel Wagner Subject: [PATCH v0 1/3] Synchronize all clients on start up Date: Thu, 22 Sep 2016 10:46:05 +0200 Message-Id: <1474533967-4404-2-git-send-email-wagi@monom.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1474533967-4404-1-git-send-email-wagi@monom.org> References: <1474533967-4404-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;