From patchwork Fri Oct 2 22:25:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Wang X-Patchwork-Id: 1376124 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20161025 header.b=dd93fBN2; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4C34MJ4LpFz9sRR for ; Sat, 3 Oct 2020 08:25:48 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725847AbgJBWZs (ORCPT ); Fri, 2 Oct 2020 18:25:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725379AbgJBWZm (ORCPT ); Fri, 2 Oct 2020 18:25:42 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 287C3C0613D0 for ; Fri, 2 Oct 2020 15:25:42 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id n13so3146599ybk.9 for ; Fri, 02 Oct 2020 15:25:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=0e+7IEbYcjux0MzEdsGB+Kd6sxVaCkN3KuJ4/wrBOPU=; b=dd93fBN2s95RJPg5HzDE/4OQUnFwEEe1/tA9O66EEr5oXOBlEtkwHoJsW73U/lFBdU 6RPFdXwnb4ZlnAx+yr6Z1Tj/BrIkWxvuQpovX/LREM71rA6a3HMWw4yoWQYr5L82LaSl U8mPRz0LqPibBLbCRsJqCfcAVcSc0Yy+HRLVZXEe0Ax6kJP8KyJKg8MwxRw1kOZ86gU3 7VyBQG3rKT24YSglsWOFoQkHo1+NV+E64kzmjlDAACjK7HBJzaLzi1WPs8bE4w9nSjOO 92biOyWmYUP1DV8/BJsT36qljOQGGHXjf17l8/ZQklSfa5u6dfnpb6iIfMLLiy9fDcHT hfTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=0e+7IEbYcjux0MzEdsGB+Kd6sxVaCkN3KuJ4/wrBOPU=; b=ndbxJ0oqEto2nV2Estfsk8ftGxNPW3puVHadcP4WDfFPOu9iOU/KxVFfEMZFgrMkJy iBn+xVi68PbxgT1L6vN+2PnDxBUs4zRbsHC/jyAOUYkKEp1JcaXswWTRNg9caBmR+l8x U2dEDWWmjLMj2Qs7Be99uk5UaM0qC8JksHCGYMIalAwEZTN1r6JPdITTMrfCX2dCbB43 ukAQBL0adUG5Sd8axHsIwGaVSp+RQPBmtZ64E7PAkX1Mat7ZaF9bw+qhKe9/ZVlE0bj3 uuohuFyD2S+UhB8K3SPPrsr4kkqxsVRx/ljDm1T37XsZThT6lMs9uLyrVoHD3ibamWC6 q5Fw== X-Gm-Message-State: AOAM530Hd/YIUbvrueROMr8nW4Biun+P/PbIWoXlscRblTKXTc2Q36kP pVHjckYFfmYEONBbKSIambePAgU0T0U= X-Google-Smtp-Source: ABdhPJyI+rd6pxsGPq+vCAusSogCB7tZcybC6IR47SY2Ec7vOYgnj1Yo7qrB4VMmJVR6xu3hAcuEq7tzxJI= Sender: "weiwan via sendgmr" X-Received: from weiwan.svl.corp.google.com ([2620:15c:2c4:201:1ea0:b8ff:fe75:cf08]) (user=weiwan job=sendgmr) by 2002:a25:ab8e:: with SMTP id v14mr5754235ybi.465.1601677541283; Fri, 02 Oct 2020 15:25:41 -0700 (PDT) Date: Fri, 2 Oct 2020 15:25:13 -0700 In-Reply-To: <20201002222514.1159492-1-weiwan@google.com> Message-Id: <20201002222514.1159492-5-weiwan@google.com> Mime-Version: 1.0 References: <20201002222514.1159492-1-weiwan@google.com> X-Mailer: git-send-email 2.28.0.806.g8561365e88-goog Subject: [PATCH net-next v2 4/5] net: modify kthread handler to use __napi_poll() From: Wei Wang To: "David S . Miller" , netdev@vger.kernel.org Cc: Eric Dumazet , Jakub Kicinski , Paolo Abeni , Hannes Frederic Sowa , Felix Fietkau , Wei Wang Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Jakub Kicinski The current kthread handler calls napi_poll() and has to pass a dummy repoll list to the function, which seems redundent. The new proposed kthread handler calls the newly proposed __napi_poll(), and respects napi->weight as before. If repoll is needed, cond_resched() is called first to give other tasks a chance to run before repolling. This change is proposed by Jakub Kicinski on top of the previous patch. Signed-off-by: Jakub Kicinski Signed-off-by: Wei Wang --- net/core/dev.c | 62 +++++++++++++++++++------------------------------- 1 file changed, 24 insertions(+), 38 deletions(-) diff --git a/net/core/dev.c b/net/core/dev.c index c82522262ca8..b4f33e442b5e 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -6827,6 +6827,15 @@ static int __napi_poll(struct napi_struct *n, bool *repoll) gro_normal_list(n); + /* Some drivers may have called napi_schedule + * prior to exhausting their budget. + */ + if (unlikely(!list_empty(&n->poll_list))) { + pr_warn_once("%s: Budget exhausted after napi rescheduled\n", + n->dev ? n->dev->name : "backlog"); + return work; + } + *repoll = true; return work; @@ -6847,15 +6856,6 @@ static int napi_poll(struct napi_struct *n, struct list_head *repoll) if (!do_repoll) goto out_unlock; - /* Some drivers may have called napi_schedule - * prior to exhausting their budget. - */ - if (unlikely(!list_empty(&n->poll_list))) { - pr_warn_once("%s: Budget exhausted after napi rescheduled\n", - n->dev ? n->dev->name : "backlog"); - goto out_unlock; - } - list_add_tail(&n->poll_list, repoll); out_unlock: @@ -6884,40 +6884,26 @@ static int napi_thread_wait(struct napi_struct *napi) static int napi_threaded_poll(void *data) { struct napi_struct *napi = data; + void *have; while (!napi_thread_wait(napi)) { - struct list_head dummy_repoll; - int budget = netdev_budget; - unsigned long time_limit; - bool again = true; + for (;;) { + bool repoll = false; - INIT_LIST_HEAD(&dummy_repoll); - local_bh_disable(); - time_limit = jiffies + 2; - do { - /* ensure that the poll list is not empty */ - if (list_empty(&dummy_repoll)) - list_add(&napi->poll_list, &dummy_repoll); - - budget -= napi_poll(napi, &dummy_repoll); - if (unlikely(budget <= 0 || - time_after_eq(jiffies, time_limit))) { - cond_resched(); - - /* refresh the budget */ - budget = netdev_budget; - __kfree_skb_flush(); - time_limit = jiffies + 2; - } + local_bh_disable(); - if (napi_disable_pending(napi)) - again = false; - else if (!test_bit(NAPI_STATE_SCHED, &napi->state)) - again = false; - } while (again); + have = netpoll_poll_lock(napi); + __napi_poll(napi, &repoll); + netpoll_poll_unlock(have); - __kfree_skb_flush(); - local_bh_enable(); + __kfree_skb_flush(); + local_bh_enable(); + + if (!repoll) + break; + + cond_resched(); + } } return 0; }