Received: by 2002:a05:6358:f14:b0:e5:3b68:ec04 with SMTP id b20csp5118109rwj; Tue, 20 Dec 2022 21:02:27 -0800 (PST) X-Google-Smtp-Source: AMrXdXumlg3EBjZOoIsYsczwV8l+mavKfyYbJceu9V0LHOyM9m/p/G5c2GQjgZ4Em/l+YjK42pLk X-Received: by 2002:a17:90b:3e82:b0:223:b557:d74f with SMTP id rj2-20020a17090b3e8200b00223b557d74fmr721535pjb.39.1671598947478; Tue, 20 Dec 2022 21:02:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671598947; cv=none; d=google.com; s=arc-20160816; b=vXTBs+gU0NKbt4Fz2BmKqxDJVLCZ3PZORZYT59Xniy+KWrkPoHHjlxlLvT7/i/q4jB QfZCSExg8dIuP6/LiNAap1PMUcZU4hQwxtEOeWnHuahbbS/GatT+H10AVRpxcaiS7Rqs 7Tgd55VOf+BXMttK06DqhFd5bksY28mrnAclF0ZTuMC5sT+XZh9FxATsWXSyvghPm7Rx EgYUpz5FRkr7yhN6IKZ2gc9biq8NQccDSPNqAzRDbvMozzCYJQeeTGN3Kr/gV5OiRvoN NsFH0G2SMlPK/3mCJCuOp56XJZUXnsDNYc/OH0+zsm6az69H/ZX9DUyi7sbG0uqkq+JI 70ZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=GWX6ezao04Awur4XebBcbzgdL1TSR5w6fZheybAPgFI=; b=dtenC4Z0xOrzkGd0K4tvzed0F9eZPHPPSXgsMT/21yY9Cr+XQNCLxubD5iUYULGksc 4R2kUzuqRatRO8ajMdWJhVZ3GFgkJKJTudw++aQzsuaBRnuQ9fdFk1SvINF92fysostD rLMPwR8BCS1NvDiNLkJf6Ybg+CzsmuUdCw8dYUuRnt0f7fWp4zX9taeqkFEROiRkm6if WJlThRE5n/10IeiCGXwk3nKeIR3z26TETUkw6d/eE/+v4sEzQs0xrcPqCpsSBnbQBboF bHShQSC6Dy+ec/uqAMOOssxd4EZOPdXJbYxs8z99wf149s9BzFT9Ber2Tw+fPgLrOZS5 b4Gg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l184-20020a6391c1000000b0047731d8c0ddsi15250911pge.511.2022.12.20.21.02.18; Tue, 20 Dec 2022 21:02:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234422AbiLUEnE (ORCPT + 69 others); Tue, 20 Dec 2022 23:43:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229679AbiLUEnC (ORCPT ); Tue, 20 Dec 2022 23:43:02 -0500 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E049818377; Tue, 20 Dec 2022 20:43:00 -0800 (PST) Received: by mail-pl1-f170.google.com with SMTP id d15so14403107pls.6; Tue, 20 Dec 2022 20:43:00 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=GWX6ezao04Awur4XebBcbzgdL1TSR5w6fZheybAPgFI=; b=upz2i6Tr9zB+x+wrCGeS9Pm1KlTAuY9CeS3RvYfYJ+tAxHLYZBTt/ZbQKTsWPtUmP+ 0S8dcPg79PT/LMtNU8Tdl8ytgmowme7SHPYKynzM46QYHjheUj/ziBdqtT+QIWtyNOKI 6jCaQ+5GSvAgZTyuVMTpXGLxQr3Sf0cGhmS/YRyTdG8IurfGO1wyEJ/2+r9JJZB9cR+n ynrbddADyayYucyUOBX8u/1xPvWIPr5ELJHHMfmZQUnfrDixip+JzoFerYu4h/GA/QfU Mk/VZ4YSaw8TU8i8sb1FWhZrYoz1+72jplZkJn83bevmjE6rKWwSR50do01dZ5h1rPJe GOZQ== X-Gm-Message-State: AFqh2kpB/CWHXL+4NFbYvkVDg95i9r4pMODI/x5H4LpXVdn5xxShkKh8 xeR5Qds3uFmHPFPDktpHp7M= X-Received: by 2002:a05:6a21:6da5:b0:a4:414c:84c5 with SMTP id wl37-20020a056a216da500b000a4414c84c5mr1350832pzb.12.1671597780216; Tue, 20 Dec 2022 20:43:00 -0800 (PST) Received: from localhost.localdomain ([14.4.134.166]) by smtp.gmail.com with ESMTPSA id e13-20020a6558cd000000b004768ce9e4fasm9072136pgu.59.2022.12.20.20.42.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Dec 2022 20:42:59 -0800 (PST) From: Leesoo Ahn To: lsahn@ooseel.net Cc: Oliver Neukum , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Greg KH , netdev@vger.kernel.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] usbnet: optimize usbnet_bh() to reduce CPU load Date: Wed, 21 Dec 2022 13:42:30 +0900 Message-Id: <20221221044230.1012787-1-lsahn@ooseel.net> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.6 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The current source pushes skb into dev->done queue by calling skb_queue_tail() and then pop it by calling skb_dequeue() to branch to rx_cleanup state for freeing urb/skb in usbnet_bh(). It takes extra CPU load, 2.21% (skb_queue_tail) as follows. - 11.58% 0.26% swapper [k] usbnet_bh - 11.32% usbnet_bh - 6.43% skb_dequeue 6.34% _raw_spin_unlock_irqrestore - 2.21% skb_queue_tail 2.19% _raw_spin_unlock_irqrestore - 1.68% consume_skb - 0.97% kfree_skbmem 0.80% kmem_cache_free 0.53% skb_release_data To reduce the extra CPU load use return values jumping to rx_cleanup state directly to free them instead of calling skb_queue_tail() and skb_dequeue() for push/pop respectively. - 7.87% 0.25% swapper [k] usbnet_bh - 7.62% usbnet_bh - 4.81% skb_dequeue 4.74% _raw_spin_unlock_irqrestore - 1.75% consume_skb - 0.98% kfree_skbmem 0.78% kmem_cache_free 0.58% skb_release_data 0.53% smsc95xx_rx_fixup Signed-off-by: Leesoo Ahn --- v2: - Replace goto label with return statement to reduce goto entropy - Add CPU load information by perf in commit message v1 at: https://patchwork.kernel.org/project/netdevbpf/patch/20221217161851.829497-1-lsahn@ooseel.net/ --- drivers/net/usb/usbnet.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/drivers/net/usb/usbnet.c b/drivers/net/usb/usbnet.c index 64a9a80b2309..6e82fef90dd9 100644 --- a/drivers/net/usb/usbnet.c +++ b/drivers/net/usb/usbnet.c @@ -555,32 +555,30 @@ static int rx_submit (struct usbnet *dev, struct urb *urb, gfp_t flags) /*-------------------------------------------------------------------------*/ -static inline void rx_process (struct usbnet *dev, struct sk_buff *skb) +static inline int rx_process(struct usbnet *dev, struct sk_buff *skb) { if (dev->driver_info->rx_fixup && !dev->driver_info->rx_fixup (dev, skb)) { /* With RX_ASSEMBLE, rx_fixup() must update counters */ if (!(dev->driver_info->flags & FLAG_RX_ASSEMBLE)) dev->net->stats.rx_errors++; - goto done; + return 1; } // else network stack removes extra byte if we forced a short packet /* all data was already cloned from skb inside the driver */ if (dev->driver_info->flags & FLAG_MULTI_PACKET) - goto done; + return 1; if (skb->len < ETH_HLEN) { dev->net->stats.rx_errors++; dev->net->stats.rx_length_errors++; netif_dbg(dev, rx_err, dev->net, "rx length %d\n", skb->len); - } else { - usbnet_skb_return(dev, skb); - return; + return 1; } -done: - skb_queue_tail(&dev->done, skb); + usbnet_skb_return(dev, skb); + return 0; } /*-------------------------------------------------------------------------*/ @@ -1528,13 +1526,14 @@ static void usbnet_bh (struct timer_list *t) entry = (struct skb_data *) skb->cb; switch (entry->state) { case rx_done: - entry->state = rx_cleanup; - rx_process (dev, skb); + if (rx_process(dev, skb)) + goto cleanup; continue; case tx_done: kfree(entry->urb->sg); fallthrough; case rx_cleanup: +cleanup: usb_free_urb (entry->urb); dev_kfree_skb (skb); continue; -- 2.34.1