Received: by 2002:a05:7412:3290:b0:fa:6e18:a558 with SMTP id ev16csp306271rdb; Thu, 25 Jan 2024 16:34:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IHrJhGGHoiWI3Znk3kNJCY2Nx6MhjsyvrKWLa2ZBJDfkRTOtIAJuB9qsga4z0SnZkYeNdZJ X-Received: by 2002:a05:6a00:4f95:b0:6dd:7b4f:ed8b with SMTP id ld21-20020a056a004f9500b006dd7b4fed8bmr548318pfb.27.1706229275984; Thu, 25 Jan 2024 16:34:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706229275; cv=pass; d=google.com; s=arc-20160816; b=ctWllTM3/mmX2rh7wNEZnQwFXYOkEh/Aa6uZagJ6G7XBp7JMU7ahQ0EwBimmcZP3Su m/66OwL9rChH+NBhQ2MBshNqyWIB+CYlbKZPyeZvTU5iW0lLV/RSPN6cwVZo/HyHKNDE 4jhza/ClW+a0/N90Jva1qZz/c6Bey5bO3M4dZ/075f40S9vKTmhvly16ncgCzQHcLq18 xO6a8VJ+x2OXAv3o+oH28lN6Io9V9TzoMyBLOVkQKX0NjMV5I02MOnD4DPeG+eVMiOw/ zoZoj5vG+q7CPnV1uu3mpUs/Vo/4YcMhzpg6SjZ5Ds1bm2T/C21xqkHH/PpMqwJqR9di sBNQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=C3n8jP9y3uPiUHRGFsi0dJRm8wXS2AMvfgDp5gCgG2I=; fh=WuzUXX5EP/9U+m6IgkGT74/kj14EftA7Qs0IwOkDPzg=; b=ub8GI/V89tiLF38qfNEWx2OhvNuYrPEnUTwO/Dp+DtoFjHonkEGp7gorDtmGpYcjtz 3Y5NQfWJ6iy/2R21yzYFzHvDuJnmWke8yGnpL+SV80qD+KLtEyf46cyjEgk9z0/F9O0I Vgi1FfZgnZJJy9jeE0xgwXwHoP3PCL5+E2/JZKy1Y05KNt9yJZNxbVgjUQUBmFu4js7S Qag/tyannotc3lQ53/i/fy1Xz23w0kxVs4VOd5/XyfixG/TLlsI1raYgoHKpb6VHm7pq BQj82RF1ogPI871qkNXKbv7Uo0DVdJMoHR9fMkC93pGgBSTX4pr4ScziHX6BbtuWJjPT +x4A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@networkplumber-org.20230601.gappssmtp.com header.s=20230601 header.b=03J8gHrI; arc=pass (i=1 spf=pass spfdomain=networkplumber.org dkim=pass dkdomain=networkplumber-org.20230601.gappssmtp.com dmarc=pass fromdomain=networkplumber.org); spf=pass (google.com: domain of linux-kernel+bounces-39459-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-39459-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=networkplumber.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id j71-20020a63804a000000b005cdfd6f30a0si132627pgd.748.2024.01.25.16.34.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 16:34:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-39459-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@networkplumber-org.20230601.gappssmtp.com header.s=20230601 header.b=03J8gHrI; arc=pass (i=1 spf=pass spfdomain=networkplumber.org dkim=pass dkdomain=networkplumber-org.20230601.gappssmtp.com dmarc=pass fromdomain=networkplumber.org); spf=pass (google.com: domain of linux-kernel+bounces-39459-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-39459-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=networkplumber.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id EC510B257AD for ; Fri, 26 Jan 2024 00:26:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AA0D3801; Fri, 26 Jan 2024 00:26:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=networkplumber-org.20230601.gappssmtp.com header.i=@networkplumber-org.20230601.gappssmtp.com header.b="03J8gHrI" Received: from mail-oi1-f169.google.com (mail-oi1-f169.google.com [209.85.167.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EFB6B4416 for ; Fri, 26 Jan 2024 00:26:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706228762; cv=none; b=Z6u4MNOSS5cbr0E3Ac/73ct+Q0/Pk/TGGKQ8aKXvGNsLwu+HonYC2SHOsnpLQXLGxAy5R11lxEo0aq3/nvpt+X/VuPc92CmnLTHwcS0FhHSq/so1zZwGpJPr/jlHLivXSPSccac+fSba3/ljUNfBYw9rG1r7xH89v8fBh9YPQKw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706228762; c=relaxed/simple; bh=6uc9Il8X4Kn9u6X/lHrXvQxTWpXcD8ov8vlLdijWmI8=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=U0WfWWNyX08L7At/u0fcG4zDTOsrqYehNSTfARi0SLXKjwSOtF27wN51d7oI4YbFMaswUo9jy5i5QNYpnmiuN5ZSz9ve+ReC2qFvmWKjBgRlbBMuO/7S0x9BDJ1s1V/3RW0ROU1oL+bSDKle/tPQSxiTllGtghLQun8SS+2Y+Qo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=networkplumber.org; spf=pass smtp.mailfrom=networkplumber.org; dkim=pass (2048-bit key) header.d=networkplumber-org.20230601.gappssmtp.com header.i=@networkplumber-org.20230601.gappssmtp.com header.b=03J8gHrI; arc=none smtp.client-ip=209.85.167.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=networkplumber.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=networkplumber.org Received: by mail-oi1-f169.google.com with SMTP id 5614622812f47-3bdbf401bd3so80748b6e.0 for ; Thu, 25 Jan 2024 16:26:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1706228760; x=1706833560; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=C3n8jP9y3uPiUHRGFsi0dJRm8wXS2AMvfgDp5gCgG2I=; b=03J8gHrIpmQpsE9x+BgZlC3yjvO4HdHQH+lw9Ewx6XxsPITXcBcm9et+zrLLldQrkP xoyTE0bOZBTtks+clEwklz5Q/ZLEO18mgmn0aLxedIqRww2nFBr/jjwgkPgu+AVyxX7h R9KPHx/SP53VHTJ6ksh4xOe7q02uP9cWf9RTT/VVsyTtFOXedO9dd/HWQVCDrT7wN//p wGYKOLi0rgq8o498bGpoEnw4mHRgDOHAP8L3Dwx05yyAt6umDWdObpzJUeYYfMPlTN/E jd4gTTfVXiCYOZmYFzpETHTgM6FLf23qkI0DyG0xKrhxCH6anzrUMlxLHKFm/RiI0zg6 AkkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706228760; x=1706833560; 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=C3n8jP9y3uPiUHRGFsi0dJRm8wXS2AMvfgDp5gCgG2I=; b=fPVh7+ZfuA1DCMTmXtjVuPKMoUzsRTGxr6+twtBgXtF0DJ5WxCakVvRiDKm5TLuTPl BFdozkQoXPJX6fFI2McwLHQljNT2PYVhmdTDegRJfkyNs7svtZhGLzbFL4z/XnQpkeNk ntFnVacypD0cHbK4lvjj4bYu5i6nYcthkNzipOL/xNz1iEqlfUv89BI96UqH5XghnmYa jlnOQlXMnHwfoUa7H0wlZC1+2oZ95nXxXnAg+VsWeTChzy6ipGkGkt++lCr3AgOGVSMw qp1DEbSxV7j92bH7NPlKMKdbbvSgG/vrAbtQXo81dd6CMoFz35zXVBtE94q957FyCT0F OU5w== X-Gm-Message-State: AOJu0YwLvPEfYGz4noYVl14tcUsCrZslEhDU6fQXg+iNdLxqqX17kbR0 mLI4b1ZeNuPULAi7rOmhLQb6UEFwP4kDLj5mmpJyCOuU+sFA6EDhI3wHDsHgud4= X-Received: by 2002:aca:2103:0:b0:3bd:9d4c:de with SMTP id 3-20020aca2103000000b003bd9d4c00demr563865oiz.30.1706228760099; Thu, 25 Jan 2024 16:26:00 -0800 (PST) Received: from hermes.local (204-195-123-141.wavecable.com. [204.195.123.141]) by smtp.gmail.com with ESMTPSA id n13-20020a056a000d4d00b006dddd5cc47csm105379pfv.157.2024.01.25.16.25.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 16:25:59 -0800 (PST) From: Stephen Hemminger To: netdev@vger.kernel.org Cc: Stephen Hemminger , Willem de Bruijn , Jason Wang , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux-kernel@vger.kernel.org (open list) Subject: [PATCH] net/tun: use reciprocal_scale Date: Thu, 25 Jan 2024 16:25:11 -0800 Message-ID: <20240126002550.169608-1-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Use the inline function reciprocal_scale rather than open coding the scale optimization. Also, remove unnecessary initializations. Resulting compiled code is unchanged (according to godbolt). Signed-off-by: Stephen Hemminger --- drivers/net/tun.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/net/tun.c b/drivers/net/tun.c index 4a4f8c8e79fa..e335ece47dec 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -54,6 +54,7 @@ #include #include #include +#include #include #include #include @@ -523,8 +524,7 @@ static inline void tun_flow_save_rps_rxhash(struct tun_flow_entry *e, u32 hash) static u16 tun_automq_select_queue(struct tun_struct *tun, struct sk_buff *skb) { struct tun_flow_entry *e; - u32 txq = 0; - u32 numqueues = 0; + u32 txq, numqueues; numqueues = READ_ONCE(tun->numqueues); @@ -534,8 +534,7 @@ static u16 tun_automq_select_queue(struct tun_struct *tun, struct sk_buff *skb) tun_flow_save_rps_rxhash(e, txq); txq = e->queue_index; } else { - /* use multiply and shift instead of expensive divide */ - txq = ((u64)txq * numqueues) >> 32; + txq = reciprocal_scale(txq, numqueues); } return txq; -- 2.43.0