From patchwork Sun Oct 16 08:55:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 9378065 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 D323B607FD for ; Sun, 16 Oct 2016 08:55:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C397228FB6 for ; Sun, 16 Oct 2016 08:55:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B353A28FB9; Sun, 16 Oct 2016 08:55:45 +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.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID 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 E240128FB6 for ; Sun, 16 Oct 2016 08:55:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752123AbcJPIzo (ORCPT ); Sun, 16 Oct 2016 04:55:44 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:33952 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752018AbcJPIzn (ORCPT ); Sun, 16 Oct 2016 04:55:43 -0400 Received: by mail-wm0-f65.google.com with SMTP id z189so5247562wmb.1; Sun, 16 Oct 2016 01:55:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=fqK/cAXc3GM2zZMLDJO4Go4OpkWwqz2gpmE4krxefyA=; b=BhWuqbB2I6avunegbTxi9SICI/g6CoPKfDr0hARAIcZ6sKAlmJVE1uG2KYFOfnIJmQ 6jYHDLKzkbtBGCw8yOdjFl8Bp99ukkjvi4zLRlju4sNAloYpObf4gu4dv3WlCe18B0JF s5WOq7oiaYJ7qzI2SfW7Zjwiv/dZuonfz/PBIv6aOz3ymEtqe+QiPgKan8EInVhkTZQp 7dIxG5DIi2XkQU6uhDyY0cuSOQ21TgA7PajBhps0vBYalWQtsJnClhj7Bs9pUthi27Wy SGq1hG/Ww8YBLYpBRo1cVdqWUNkWz7JpKpz93jrbiJoPrXfESm3FZljUZxx2vbuPKUdP bCog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=fqK/cAXc3GM2zZMLDJO4Go4OpkWwqz2gpmE4krxefyA=; b=VAdG0iO2mZVY/dU1Cu68HFhZtAoqux6iGk+O9MqhNE+yxvhzbNI53+Jipx6mCJ+EXi qnaaWIsbO+xfFh0MJ3kM7Qqz47enKNrCWS5kumhNWxy+OLfudqQha9Lfnfc5F+xat9/e NfxLVn6VeBG/+hm+VqVh/OOYNYPqYWBt6tZWDnjYa4K5CG+4l56U3UeirNYfj8YnwsRA JIOwEjnxh3BNhMdMJ3CJSx71Khk7MsDFdeT8EFWLK+f4slBwuiD1LhFGFC2vDEg+QBu1 7A08fj1qm8nixr2pTCF0l8nYsgE5kT8IA1Tej/e0ovh1SNhhUhG/HtdO/2KxTWaIA9pg S6gg== X-Gm-Message-State: AA6/9RkEU7C67eVfJ5E/T9QvoxNJlPsKKd+onsgSfw/TtBy0NWiZLZJL/8RuZe15XdjZjA== X-Received: by 10.28.232.148 with SMTP id f20mr5211323wmi.30.1476608141368; Sun, 16 Oct 2016 01:55:41 -0700 (PDT) Received: from amir-VirtualBox.Home (bzq-79-177-34-153.red.bezeqint.net. [79.177.34.153]) by smtp.gmail.com with ESMTPSA id b77sm8543582wmb.0.2016.10.16.01.55.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 16 Oct 2016 01:55:40 -0700 (PDT) From: Amir Goldstein To: Dave Chinner Cc: Christoph Hellwig , linux-xfs@vger.kernel.org, fstests@vger.kernel.org Subject: [PATCH v2] xfs_io: add command line option -M to run as multi threaded process Date: Sun, 16 Oct 2016 11:55:11 +0300 Message-Id: <1476608111-28948-1-git-send-email-amir73il@gmail.com> X-Mailer: git-send-email 2.7.4 Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP xfs_io -M will start by spawning an idle thread. The purpose of this idle thread is to test io from a multi threaded process. With single threaded process, the file table is not shared and file structs are not reference counted. So in order to detect file struct reference leaks, spawning an idle thread will do the trick. Signed-off-by: Amir Goldstein Reviewed-by: Christoph Hellwig --- io/Makefile | 2 +- io/init.c | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/io/Makefile b/io/Makefile index 1997ca9..032a8c7 100644 --- a/io/Makefile +++ b/io/Makefile @@ -13,7 +13,7 @@ CFILES = init.c \ mmap.c open.c parent.c pread.c prealloc.c pwrite.c seek.c shutdown.c \ sync.c truncate.c reflink.c -LLDLIBS = $(LIBXCMD) $(LIBHANDLE) +LLDLIBS = $(LIBXCMD) $(LIBHANDLE) $(LIBPTHREAD) LTDEPENDENCIES = $(LIBXCMD) $(LIBHANDLE) LLDFLAGS = -static-libtool-libs diff --git a/io/init.c b/io/init.c index 6b88cc6..8a34ceb 100644 --- a/io/init.c +++ b/io/init.c @@ -16,6 +16,7 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#include #include "platform_defs.h" #include "command.h" #include "input.h" @@ -25,6 +26,7 @@ char *progname; int exitcode; int expert; +int multithreaded; size_t pagesize; struct timeval stopwatch; @@ -141,7 +143,7 @@ init( pagesize = getpagesize(); gettimeofday(&stopwatch, NULL); - while ((c = getopt(argc, argv, "ac:dFfmp:nrRstTVx")) != EOF) { + while ((c = getopt(argc, argv, "ac:dFfmMp:nrRstTVx")) != EOF) { switch (c) { case 'a': flags |= IO_APPEND; @@ -166,6 +168,9 @@ init( exit(1); } break; + case 'M': + multithreaded = 1; + break; case 'n': flags |= IO_NONBLOCK; break; @@ -213,12 +218,38 @@ init( add_check_command(init_check_command); } +/* + * The purpose of this idle thread is to test io from a multi threaded process. + * With single threaded process, the file table is not shared and file structs + * are not reference counted. So in order to detect file struct reference + * leaks, spawning an idle thread will do the trick. + */ +void * +idle_loop(void *arg) +{ + for (;;) + pause(); +} + +void +start_idle_thread() +{ + pthread_t t; + + if (pthread_create(&t, NULL, idle_loop, NULL)) { + fprintf(stderr, "Error creating idle thread\n"); + exit(1); + } +} + int main( int argc, char **argv) { init(argc, argv); + if (multithreaded) + start_idle_thread(); command_loop(); return exitcode; }