From patchwork Sat Nov 10 15:13:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 10677249 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CB3631709 for ; Sat, 10 Nov 2018 15:13:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BB848287D2 for ; Sat, 10 Nov 2018 15:13:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AFFF52900D; Sat, 10 Nov 2018 15:13:34 +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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,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 56E65287D2 for ; Sat, 10 Nov 2018 15:13:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726337AbeKKA6x (ORCPT ); Sat, 10 Nov 2018 19:58:53 -0500 Received: from mail-pf1-f196.google.com ([209.85.210.196]:33719 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726188AbeKKA6w (ORCPT ); Sat, 10 Nov 2018 19:58:52 -0500 Received: by mail-pf1-f196.google.com with SMTP id v68-v6so2272470pfk.0 for ; Sat, 10 Nov 2018 07:13:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=zXCotydMRMCbhLI8GX8sTdMcPzD179BDZkLEEcbwTOI=; b=fCz6jBilo74Z7sgsyOX6NoJe7bAx/aTnp/fbliEBKH+JzwsIFRl99+ddnB8AtgTwpK ciNnmcsJrqM5wR3VVXCQ3AOyip7stAETgsUlqUR3Wv+lsNlOwKLSZLUkRyqY/gB7KU2k re6suFgx+/p7XcuuqKNY6++NVfzl1D0wWHQCU4x3NlBXEKXc9Egj11jTbew3X+BV+H70 Ev9npuZn+HwNtmYx2qmchTT+aDDUqexZwk3wP24mlKxTtd+WoHs6sJb28Dd9EWHAEQUu L6xBB23l/Al8XWhWij01xzrPv5jcEV0jnhWaisW39xK999Cc/IHh/3cfwe3nAKgwINoB inUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=zXCotydMRMCbhLI8GX8sTdMcPzD179BDZkLEEcbwTOI=; b=e8osrfx30L1Cpte4jeEbjkHT1e1LyvcoQEh5i5s1OuewQSD3dGsX+E8XzqyHC/paff sV3W7YjQI6McG4tjKYDta4x2hQOMz0PojBQb4Rj2ugUmPsRRPVEVWYjZwbq/l0kRnHjZ tAN7r26rpLg/nU7m7594lGmXLEpOmxF+7gpU3Ix3F6RXZy/5QLrSCsiZdC7ivS7Arui+ 9yLRMvdtVVSUrqCLgE9CnOw+MYR95g7v24dWvptDuELIOdGWE3+/8Fl2lsgh/HqfFWWk bhhQjeq+di9BQgdobCK52EyMhsGjf9yljNPGx60UwssRn24Cf+7ReL7bLV9fJbKcEJIN xIFA== X-Gm-Message-State: AGRZ1gL/g08mdZgky5tuIl/rp1qTgaJSMcmfpaEk/Q0ZdL2X7b5S5D+e 6SsFQKvYfbCuw3lUcBNWiZb+UXgiQP0= X-Google-Smtp-Source: AJdET5fNcwYuefwa5tDUnZbrp6K2h1j+Zb6V1ulu/a5gOMsdY4ukTt/HL2a+on+EUvOtJy7YtqVBbw== X-Received: by 2002:a63:4c59:: with SMTP id m25mr11445068pgl.173.1541862812358; Sat, 10 Nov 2018 07:13:32 -0800 (PST) Received: from x1.localdomain (66.29.188.166.static.utbb.net. [66.29.188.166]) by smtp.gmail.com with ESMTPSA id d68-v6sm11178615pfa.80.2018.11.10.07.13.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 10 Nov 2018 07:13:31 -0800 (PST) From: Jens Axboe To: linux-block@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 6/6] block: add polled wakeup task helper Date: Sat, 10 Nov 2018 08:13:17 -0700 Message-Id: <20181110151317.3813-7-axboe@kernel.dk> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181110151317.3813-1-axboe@kernel.dk> References: <20181110151317.3813-1-axboe@kernel.dk> Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If we're polling for IO on a device that doesn't use interrupts, then IO completion loop (and wake of task) is done by submitting task itself. If that is the case, then we don't need to enter the wake_up_process() function, we can simply mark ourselves as TASK_RUNNING. Signed-off-by: Jens Axboe --- fs/block_dev.c | 4 ++-- fs/iomap.c | 2 +- include/linux/blkdev.h | 13 +++++++++++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/fs/block_dev.c b/fs/block_dev.c index e7550b1f9670..eea37d801f1c 100644 --- a/fs/block_dev.c +++ b/fs/block_dev.c @@ -181,7 +181,7 @@ static void blkdev_bio_end_io_simple(struct bio *bio) struct task_struct *waiter = bio->bi_private; WRITE_ONCE(bio->bi_private, NULL); - wake_up_process(waiter); + blk_wake_io_task(waiter); } static ssize_t @@ -316,7 +316,7 @@ static void blkdev_bio_end_io(struct bio *bio) struct task_struct *waiter = dio->waiter; WRITE_ONCE(dio->waiter, NULL); - wake_up_process(waiter); + blk_wake_io_task(waiter); } } diff --git a/fs/iomap.c b/fs/iomap.c index f61d13dfdf09..b0462b363bad 100644 --- a/fs/iomap.c +++ b/fs/iomap.c @@ -1525,7 +1525,7 @@ static void iomap_dio_bio_end_io(struct bio *bio) if (dio->wait_for_completion) { struct task_struct *waiter = dio->submit.waiter; WRITE_ONCE(dio->submit.waiter, NULL); - wake_up_process(waiter); + blk_wake_io_task(waiter); } else if (dio->flags & IOMAP_DIO_WRITE) { struct inode *inode = file_inode(dio->iocb->ki_filp); diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index ad8474ec8c58..b0ce931cc734 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1798,4 +1798,17 @@ static inline int blkdev_issue_flush(struct block_device *bdev, gfp_t gfp_mask, #endif /* CONFIG_BLOCK */ +static inline void blk_wake_io_task(struct task_struct *waiter) +{ + /* + * If we're polling, the task itself is doing the completions. For + * that case, we don't need to signal a wakeup, it's enough to just + * mark us as RUNNING. + */ + if (waiter == current) + __set_current_state(TASK_RUNNING); + else + wake_up_process(waiter); +} + #endif