From patchwork Sun Apr 7 17:58:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 10888495 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 6D87A922 for ; Sun, 7 Apr 2019 18:01:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5AD332624D for ; Sun, 7 Apr 2019 18:01:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4F5F927F91; Sun, 7 Apr 2019 18:01:27 +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 D9A7528448 for ; Sun, 7 Apr 2019 18:01:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726335AbfDGSB0 (ORCPT ); Sun, 7 Apr 2019 14:01:26 -0400 Received: from mail-it1-f174.google.com ([209.85.166.174]:38426 "EHLO mail-it1-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726388AbfDGSB0 (ORCPT ); Sun, 7 Apr 2019 14:01:26 -0400 Received: by mail-it1-f174.google.com with SMTP id f22so17363723ita.3 for ; Sun, 07 Apr 2019 11:01:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=itCHmiCshLTM2+BHulEM3xFyqyjflEgWdjjcXgdFrpU=; b=n4JMRmBIcd+VKnG5ZJM6BwCQbh9o94et3Uyf6qH2VeddB90cXSXQOKO+uR9u5IvQMl qbfXXIgxndDjckI416yViImUZUdW77IwJpfWQMOP5kPTiFGkNg/RrKNM8uxpRXbva3Ca v6MIz8gDirzJngp4PFrUTMau1/vG5mw6dtJRliTATqys4O8B1OAAOeshhaunVxZTqKvO xPRD8dhYGIg2CILWaWMkIAbt6m7Mw+Eu5OMmIvrrN+lK1A3kHn8sxX4g7hi6uFIuc8Fl BbaDRtcYfB3TSh9FAKdPlVT/7nh6ne5CK35z3QYEdwgW1KFy4sy1MHNvhifFodqYWR4C 4/Rg== 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:mime-version:content-transfer-encoding; bh=itCHmiCshLTM2+BHulEM3xFyqyjflEgWdjjcXgdFrpU=; b=qybb9YmnmZh4rU3R2MCuQQLO6HH12D53QRZ++ucJa1oQtoYdtXUskA5ubkoB+CTxLG aWigrWHDbI7/QE3dPwjK1nTp+gLcQTMqdK+kQNHx7y3eBSQERJLS4Sp1DuHYnG3DPOHr A4mzCLN5H1g3fd8mZdos8MbeK8m9sW9VlQY56ua5XOUf87EHWyrJEvaJKuUoWJoGru3h XYbCsE/lKX1JsyUD7sjdQ4KIKnId6RhH3dq8pDGKpYm5gDfOpLycgHNYiPv1qeBLQudK 88RHxBrRsTMi05qdz4iurwtWeAKvLDfhL/9t5hv0AN18e7Ar1vSTf/hItUOAXY3ZCqSu yJ0g== X-Gm-Message-State: APjAAAVuhc9EaSbIIn2U7nCgd+zt7Sc2wJT1unDQyugx0OgPmnG+RR57 z3E0LEROJriuYhvjKVeVEl4wkeA= X-Google-Smtp-Source: APXvYqy8o1h8kz14N0bl7kYEaOGpKuqJ8gxjzBOd8uHBYvcGeo9dt5kt2dFaJDuuTu8k3hEOnq+83Q== X-Received: by 2002:a05:6638:26e:: with SMTP id x14mr18056261jaq.32.1554660084880; Sun, 07 Apr 2019 11:01:24 -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 m6sm10807362ioj.36.2019.04.07.11.01.24 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 07 Apr 2019 11:01:24 -0700 (PDT) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: Anna Schumaker Cc: linux-nfs@vger.kernel.org Subject: [PATCH v3 04/29] SUNRPC: Refactor rpc_sleep_on() Date: Sun, 7 Apr 2019 13:58:47 -0400 Message-Id: <20190407175912.23528-5-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190407175912.23528-4-trond.myklebust@hammerspace.com> References: <20190407175912.23528-1-trond.myklebust@hammerspace.com> <20190407175912.23528-2-trond.myklebust@hammerspace.com> <20190407175912.23528-3-trond.myklebust@hammerspace.com> <20190407175912.23528-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);