From patchwork Thu Mar 28 20:52:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 10875967 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 5EB2F1575 for ; Thu, 28 Mar 2019 20:56:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 49B5428F2B for ; Thu, 28 Mar 2019 20:56:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3E58628F6C; Thu, 28 Mar 2019 20:56:14 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,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 D1A3C28F2B for ; Thu, 28 Mar 2019 20:56:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726289AbfC1U4N (ORCPT ); Thu, 28 Mar 2019 16:56:13 -0400 Received: from mail-it1-f173.google.com ([209.85.166.173]:55644 "EHLO mail-it1-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726307AbfC1U4M (ORCPT ); Thu, 28 Mar 2019 16:56:12 -0400 Received: by mail-it1-f173.google.com with SMTP id z126so436179itd.5 for ; Thu, 28 Mar 2019 13:56:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=itCHmiCshLTM2+BHulEM3xFyqyjflEgWdjjcXgdFrpU=; b=kJLSpMZkGFzFptzBS9AqvPLVAPxcxL8pCoX0PwSdPQCyef6Cq+na5EDPgBFJoX9paP Gv/CQwFLLFF8R99p5EL7k2i5yOHXgDJJ2hCpPzkOWCI6Qy1/V2Bwo2Y6Q1zlKN/PaoQC Jp+plN9t/GWicL01dQ2F2SemBpSfvkpwBYx9e6A0dg2rtfO/O6Js8lQ9Xa3chbBpaAML ybU8E5tCTxTRqC0wbJA8tXHdSTA8lYP+e1R0iU1lKRIIs2mTeKGVbhEyzNFSI3s+P9vz SaqX1vvMqab2xpZ+TwunRhJ4rN4ba729r8K0KHO7yjRtsgSBS7m/L7Y0Tj1TeHRnoT56 XlIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=itCHmiCshLTM2+BHulEM3xFyqyjflEgWdjjcXgdFrpU=; b=cVSh1LAs8mWSKfc8phDb4CaL0uSFzChUvULMjsefZD+oqFg/Pj7vgxqpIhAAv7R/I5 JxIfdlYQ3BjWCoB7wFE6mnHEPLibz1u9wpA9sVXM/5DVgG54IU6XTL98Eypk0y08vdH6 UU1heBEjCva0WmD0QL31o5kwXVbGc/dF1FRExTUgtA14bW52u55tn9wA4ao7YKIVfHaO VrxYCLrput5h1uqo6jYRUwvINp4tVMeAbPpPK+B+I53ltVV92PvXyWdaL7UHrWY3up23 eMCaq620RAWCrDsW0fUV+xmgxYRw7AT0UCDiIU4rzw5es76gsSIl+Y38GngD/GUBmKj1 nTCw== X-Gm-Message-State: APjAAAWiUjqjQ0styr2EDuUDEMJ5P9und6IzYuKSJPbaAFpSZPxhy4Yx kRU66vIkBJN+c+nKSYSF9TEtmnM= X-Google-Smtp-Source: APXvYqyYSnAabCVJG8NBDQPLukrb58csuLalvhyScMewzNzMLhlI6nbKiT1XCl+oRUdVoHJfjlKY5A== X-Received: by 2002:a02:b097:: with SMTP id v23mr33623578jah.42.1553806571151; Thu, 28 Mar 2019 13:56:11 -0700 (PDT) Received: from localhost.localdomain (c-68-40-189-247.hsd1.mi.comcast.net. [68.40.189.247]) by smtp.gmail.com with ESMTPSA id t67sm1084750ita.35.2019.03.28.13.56.10 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 28 Mar 2019 13:56:10 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: linux-nfs@vger.kernel.org Subject: [PATCH 04/25] SUNRPC: Refactor rpc_sleep_on() Date: Thu, 28 Mar 2019 16:52:18 -0400 Message-Id: <20190328205239.29674-5-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190328205239.29674-4-trond.myklebust@hammerspace.com> References: <20190328205239.29674-1-trond.myklebust@hammerspace.com> <20190328205239.29674-2-trond.myklebust@hammerspace.com> <20190328205239.29674-3-trond.myklebust@hammerspace.com> <20190328205239.29674-4-trond.myklebust@hammerspace.com> MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP rpc_sleep_on() does not need to set the task->tk_callback under the queue lock, so move that out. Also refactor the check for whether the task is active. Signed-off-by: Trond Myklebust --- net/sunrpc/sched.c | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c index 3d6cb91ba598..8e96a841dd11 100644 --- a/net/sunrpc/sched.c +++ b/net/sunrpc/sched.c @@ -362,7 +362,6 @@ static void rpc_make_runnable(struct workqueue_struct *wq, */ static void __rpc_sleep_on_priority(struct rpc_wait_queue *q, struct rpc_task *task, - rpc_action action, unsigned char queue_priority) { dprintk("RPC: %5u sleep_on(queue \"%s\" time %lu)\n", @@ -372,27 +371,39 @@ static void __rpc_sleep_on_priority(struct rpc_wait_queue *q, __rpc_add_wait_queue(q, task, queue_priority); - WARN_ON_ONCE(task->tk_callback != NULL); - task->tk_callback = action; __rpc_add_timer(q, task); } -void rpc_sleep_on(struct rpc_wait_queue *q, struct rpc_task *task, - rpc_action action) +static void rpc_set_tk_callback(struct rpc_task *task, rpc_action action) +{ + if (action && !WARN_ON_ONCE(task->tk_callback != NULL)) + task->tk_callback = action; +} + +static bool rpc_sleep_check_activated(struct rpc_task *task) { /* We shouldn't ever put an inactive task to sleep */ - WARN_ON_ONCE(!RPC_IS_ACTIVATED(task)); - if (!RPC_IS_ACTIVATED(task)) { + if (WARN_ON_ONCE(!RPC_IS_ACTIVATED(task))) { task->tk_status = -EIO; rpc_put_task_async(task); - return; + return false; } + return true; +} + +void rpc_sleep_on(struct rpc_wait_queue *q, struct rpc_task *task, + rpc_action action) +{ + if (!rpc_sleep_check_activated(task)) + return; + + rpc_set_tk_callback(task, action); /* * Protect the queue operations. */ spin_lock_bh(&q->lock); - __rpc_sleep_on_priority(q, task, action, task->tk_priority); + __rpc_sleep_on_priority(q, task, task->tk_priority); spin_unlock_bh(&q->lock); } EXPORT_SYMBOL_GPL(rpc_sleep_on); @@ -400,19 +411,16 @@ EXPORT_SYMBOL_GPL(rpc_sleep_on); void rpc_sleep_on_priority(struct rpc_wait_queue *q, struct rpc_task *task, rpc_action action, int priority) { - /* We shouldn't ever put an inactive task to sleep */ - WARN_ON_ONCE(!RPC_IS_ACTIVATED(task)); - if (!RPC_IS_ACTIVATED(task)) { - task->tk_status = -EIO; - rpc_put_task_async(task); + if (!rpc_sleep_check_activated(task)) return; - } + + rpc_set_tk_callback(task, action); /* * Protect the queue operations. */ spin_lock_bh(&q->lock); - __rpc_sleep_on_priority(q, task, action, priority - RPC_PRIORITY_LOW); + __rpc_sleep_on_priority(q, task, priority - RPC_PRIORITY_LOW); spin_unlock_bh(&q->lock); } EXPORT_SYMBOL_GPL(rpc_sleep_on_priority);