From patchwork Fri Oct 14 20:44:38 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 9377485 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 A18C36075E for ; Fri, 14 Oct 2016 20:45:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 91F03283F5 for ; Fri, 14 Oct 2016 20:45:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 825E929758; Fri, 14 Oct 2016 20:45:42 +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.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, 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 1C41A283F5 for ; Fri, 14 Oct 2016 20:45:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754140AbcJNUpl (ORCPT ); Fri, 14 Oct 2016 16:45:41 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:34046 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754265AbcJNUpk (ORCPT ); Fri, 14 Oct 2016 16:45:40 -0400 Received: by mail-wm0-f68.google.com with SMTP id z189so174315wmb.1; Fri, 14 Oct 2016 13:45:10 -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=SEzc9F/7fiZxef7zxqe2p85dJ2xMg6qrf99aIfluWRs=; b=C5s1mUkZm7EFt4AAHbC0eOL17CNvhonHsbZG0I/oOeJpPobJUj3LpYhYQaEss3kDt/ p3Zt2YnrVrKhCHZGDhvzb3gfj51WwGT/APwJmGxG8PmS48IOQ704UFmluv90ekK9Bmr7 l4bZzozL264GezJi+i2d5zaMb8io0clTALZaXE39OwGZLRIVxTGH5QR4+LoQr/86eZyM BVrvwUV+wbkJl2UeAtFclw+jP7HJ3jhtoBNQiyPDoA+FIVC/7ITZ2al4CTGhfRPCN/k6 XWd98m5dx0oKebICS9j8gyc3TQv6m5cxn39r6khb26cCnx4NbslZM8yPAoECtsUZSMNg 6vkw== 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=SEzc9F/7fiZxef7zxqe2p85dJ2xMg6qrf99aIfluWRs=; b=UjZM0EysJiLxqJUmExEITEtuBYJfYAzJecEg/K6LEs6Mfs3HQisYO3QvJBCkn8NWhN F3DOkjispQ0RmjhIv8gks/HYrG4d2ON83y5VUOw1Vk9FkMcEFqSxGeZ/ZAPG5EmwBQWT o0CjdM/PK+2R1zNNBDGSXOicrCDclVq567aTiJD6GxC1NKlI9ylFQBcmP3oHdbt1BDr8 17FDPtqugPXtqwiFOgo1xtQxhQRpanpKy+DSCNZ+yYtnQurV1H9Bl9Tk3lVTj9eNJBtd 82Z2MX5AugxncNf0XPFsoho5aNdO5vFBOP6IbLHbUrB+3jo2SYatXPkcQTM02SPkgL1r ePtg== X-Gm-Message-State: AA6/9Rn4WP7UujRzY7x7rAV6f8xsDhWlVIxRUCZwRY5Bk1tDwdQpX1ay4icRwLNUaTmDtg== X-Received: by 10.28.30.143 with SMTP id e137mr12074wme.117.1476477909430; Fri, 14 Oct 2016 13:45:09 -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 za1sm29692253wjb.8.2016.10.14.13.45.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 14 Oct 2016 13:45:08 -0700 (PDT) From: Amir Goldstein To: Dave Chinner Cc: linux-xfs@vger.kernel.org, fstests@vger.kernel.org Subject: [PATCH] xfs_io: add command line option -M to run as multi threaded process Date: Fri, 14 Oct 2016 23:44:38 +0300 Message-Id: <1476477878-17588-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 | 32 +++++++++++++++++++++++++++++++- 2 files changed, 32 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..1d1b97f 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,37 @@ 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; }