From patchwork Thu Feb 19 14:23:14 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Wagner X-Patchwork-Id: 5852231 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id BC262BF440 for ; Thu, 19 Feb 2015 14:29:47 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B447320259 for ; Thu, 19 Feb 2015 14:29:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 80F822026C for ; Thu, 19 Feb 2015 14:29:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753385AbbBSO3m (ORCPT ); Thu, 19 Feb 2015 09:29:42 -0500 Received: from mail.bmw-carit.de ([62.245.222.98]:53407 "EHLO linuxmail.bmw-carit.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752958AbbBSO3k (ORCPT ); Thu, 19 Feb 2015 09:29:40 -0500 X-Greylist: delayed 378 seconds by postgrey-1.27 at vger.kernel.org; Thu, 19 Feb 2015 09:29:39 EST Received: from localhost (unknown [10.242.2.18]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: daniel.wagner) by linuxmail.bmw-carit.de (Postfix) with ESMTPSA id EEE4B40141; Thu, 19 Feb 2015 13:19:47 +0100 (CET) From: Daniel Wagner To: Jeff Layton Cc: linux-fsdevel@vger.kernel.org, Daniel Wagner Subject: [PATCH v0 2/2] lease02: add new "lease02" test Date: Thu, 19 Feb 2015 15:23:14 +0100 Message-Id: <1424355794-30736-3-git-send-email-daniel.wagner@bmw-carit.de> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1424355794-30736-1-git-send-email-daniel.wagner@bmw-carit.de> References: <1424355794-30736-1-git-send-email-daniel.wagner@bmw-carit.de> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add a microbench mark which test the performance of taking and releasing a read lease with many processes in a tight loop. Based on posix02. Signed-off-by: Daniel Wagner --- Makefile.am | 2 +- lease02.c | 178 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 179 insertions(+), 1 deletion(-) create mode 100644 lease02.c diff --git a/Makefile.am b/Makefile.am index b0a2851..4a2ae98 100644 --- a/Makefile.am +++ b/Makefile.am @@ -4,6 +4,6 @@ ACLOCAL_AMFLAGS = -I m4 EXTRA_DIST = m4/gnulib-cache.m4 LDADD = lib/libgnu.a -lrt -bin_PROGRAMS = flock01 flock02 posix01 posix02 posix03 lease01 +bin_PROGRAMS = flock01 flock02 posix01 posix02 posix03 lease01 lease02 SUBDIRS = lib/ diff --git a/lease02.c b/lease02.c new file mode 100644 index 0000000..0fa33e4 --- /dev/null +++ b/lease02.c @@ -0,0 +1,178 @@ +/* + * Lease performance test 2 + * + * Fork off a given number of children who each open their own + * file. Then have each child take a read lease and release the lease + * for the given number of times. + * + * Time this to measure lease performance for lease heavy workloads where the + * locks are generally uncontended. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "timespec.h" + +#define NRPROC (128) +#define NRLOCK (20480) + +static struct timespec *diff; + +static int +leaseunlease(int nrlock, struct timespec *slot) +{ + int fd, i, ret; + pid_t pid = getpid(); + char name[10]; /* big enough for pid_t in hex + NULL */ + struct timespec start, end; + + ret = snprintf(name, sizeof(name), "%x", pid); + if (ret >= (int)sizeof(name)) { + perror("sprintf"); + return 1; + } + + fd = open(name, O_CREAT|O_RDONLY, 0644); + if (fd < 0) { + perror("open"); + return fd; + } + + ret = clock_gettime(CLOCK_MONOTONIC_RAW, &start); + if (ret) { + perror("clock_gettime"); + return ret; + } + + for (i = 0; i < nrlock; ++i) { + ret = fcntl(fd, F_SETLEASE, F_RDLCK); + if (ret < 0) { + perror("fcntl"); + break; + } + ret = fcntl(fd, F_SETLEASE, F_RDLCK); + if (ret < 0) { + perror("fcntl"); + break; + } + } + + ret = clock_gettime(CLOCK_MONOTONIC_RAW, &end); + if (ret) { + perror("clock_gettime"); + return ret; + } + + close(fd); + *slot = timespec_sub(end, start); + return ret; +} + +void +usage(char *prog) +{ + printf("usage: %s [-n nr_procs] [-l nr_locks] directory\n", prog); +} + +int +main(int argc, char **argv) +{ + int i, opt, valid = 0; + int nproc = NRPROC; + int nlock = NRLOCK; + pid_t *pids; + char *dirname; + struct timespec total = { .tv_sec = 0, + .tv_nsec = 0 }; + + while ((opt = getopt(argc, argv, "l:n:")) != -1) { + switch (opt) { + case 'l': + nlock = atoi(optarg); + break; + case 'n': + nproc = atoi(optarg); + break; + default: + usage(argv[0]); + return 1; + } + } + + dirname = argv[optind]; + if (!dirname) { + usage(argv[0]); + return 1; + } + + if (mkdir(dirname, S_IRWXU)) { + perror("mkdir"); + return 1; + } + + if (chdir(dirname)) { + perror("chdir"); + return 1; + } + + pids = calloc(nproc, sizeof(pid_t)); + if (!pids) { + fprintf(stderr, "Unable to allocate pids array!"); + return 1; + } + + diff = mmap(0, nproc * sizeof(*diff), PROT_READ | PROT_WRITE, + MAP_ANONYMOUS | MAP_SHARED, -1, 0); + if (diff == (struct timespec *)-1) { + fprintf(stderr, "Unable to allocate timespec array!"); + return 1; + } + + for (i = 0; i < nproc; ++i) { + pids[i] = fork(); + if (!pids[i]) + return leaseunlease(nlock, &diff[i]); + } + + for (i = 0; i < nproc; ++i) { + int status; + + if (pids[i] < 0) { + fprintf(stderr, "process %d failed to fork\n", i); + continue; + } + if (waitpid(pids[i], &status, 0) < 0) { + fprintf(stderr, "unable to reap pid %d\n", pids[i]); + continue; + } + if (!WIFEXITED(status) || WEXITSTATUS(status)) { + fprintf(stderr, "pid %d exited abnormally(0x%x)\n", pids[i],status); + continue; + } + total = timespec_add(total, diff[i]); + ++valid; + } + + if (valid != nproc) { + fprintf(stderr, "Some children didn't run properly -- " + "requested %d but only got %d\n", nproc, valid); + return 1; + } + + printf("%ld.%ld\n", total.tv_sec, total.tv_nsec); + return 0; +}