From patchwork Tue Nov 15 09:10:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13043330 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9ED1EC433FE for ; Tue, 15 Nov 2022 09:11:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237844AbiKOJLV (ORCPT ); Tue, 15 Nov 2022 04:11:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237875AbiKOJLH (ORCPT ); Tue, 15 Nov 2022 04:11:07 -0500 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 89FA921E1D for ; Tue, 15 Nov 2022 01:11:06 -0800 (PST) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-349423f04dbso130655457b3.13 for ; Tue, 15 Nov 2022 01:11:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=b0YyahNj2Zvm6NvOfL2D9vMZ8vKhHxd5MfdejYaMVGo=; b=Mbmu2SDQ5a7AmXFkD6VG1SuaLF12GPCeLperCgZe7O1uL1/61NoGMff+Sq5x9TCRjz ebSva1VJsxQiwevZK2BvsrQ3RkatHYUW1TT1/cEjSn3zlN3jjELPyJNu2lCLnn9VOWeq Y+AHglsgUXiy0nVm4PTzY2d59Zjv1o5xFqmPkAQIeTdHte4LxziAjHSHBuNByedM6lR/ z/5bAwqhKOTDEC+f3a8dxAKJX/YRlF1ziZW45yX8ZJRlLhCBtbIW+90Bh+dXUYx/VOlM fqyMSJoRVQz6ruPr7nl0pDSZ2viaKza0exmvmTgQse384dCeZPyPFHZDgwtGe6wfE3gb ajGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=b0YyahNj2Zvm6NvOfL2D9vMZ8vKhHxd5MfdejYaMVGo=; b=pn/R+YfnZKuBBn0RqI4C4pGaNmJQwmBsrIrrOfT8iaRPSqi9ySNpOb0Tw46Np+RDqb Cx677rQW9jz355YWP4TxXVmySGFyEFJN2xPPJPcrU0FwttXpU+3nc49tOAGx3YXTBb4w oAVfdQHtqVZdiH3SVxjrRpOA+mkqs0QdhZGrpoIPkyBRjfrzojTMRgHQlKkbW1MUEzBN qJnP1Be8SxYqFcMqiC+AAX4hNSLNuYpKn/r2TunrFSRusO8zFOVa/NVWBuUMynBQpMuV rFS7GRMLX3VCIsXIZC6MHRfG0lzTHQpD+hq0qIuvVbRTH/InAemFHjTx8Nj2z9Ij3pyh r51A== X-Gm-Message-State: ANoB5pnEbIlszQ3s9Nu+pOGGq7kWJENWRfLIqu0zNGXHHpFG/l5zduub oEHjxOhMtAaS/xlGVddBkG+gqHksZI6Kyw== X-Google-Smtp-Source: AA0mqf5wPJVO3WaTvMZ76Y61u2ldYDX8jG9N3ixSJKw8V4XiNTP7BwTvMDvjmIo1kXRSC74RrIe+1XJf98BEmA== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a25:24cd:0:b0:6dd:e49a:6039 with SMTP id k196-20020a2524cd000000b006dde49a6039mr2080339ybk.274.1668503465205; Tue, 15 Nov 2022 01:11:05 -0800 (PST) Date: Tue, 15 Nov 2022 09:10:56 +0000 In-Reply-To: <20221115091101.2234482-1-edumazet@google.com> Mime-Version: 1.0 References: <20221115091101.2234482-1-edumazet@google.com> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog Message-ID: <20221115091101.2234482-2-edumazet@google.com> Subject: [PATCH net-next 1/6] net: mm_account_pinned_pages() optimization From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet , Willem de Bruijn Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Adopt atomic_long_try_cmpxchg() in mm_account_pinned_pages() as it is slightly more efficient. Signed-off-by: Eric Dumazet Cc: Willem de Bruijn --- net/core/skbuff.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 90d085290d49d864b8431f99a19dbda867d9c03b..4bf95e36ed162611e8245c64c6caeecf9f60ef5d 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -1267,13 +1267,12 @@ int mm_account_pinned_pages(struct mmpin *mmp, size_t size) max_pg = rlimit(RLIMIT_MEMLOCK) >> PAGE_SHIFT; user = mmp->user ? : current_user(); + old_pg = atomic_long_read(&user->locked_vm); do { - old_pg = atomic_long_read(&user->locked_vm); new_pg = old_pg + num_pg; if (new_pg > max_pg) return -ENOBUFS; - } while (atomic_long_cmpxchg(&user->locked_vm, old_pg, new_pg) != - old_pg); + } while (!atomic_long_try_cmpxchg(&user->locked_vm, &old_pg, new_pg)); if (!mmp->user) { mmp->user = get_uid(user); From patchwork Tue Nov 15 09:10:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13043331 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8A674C4332F for ; Tue, 15 Nov 2022 09:11:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237861AbiKOJLX (ORCPT ); Tue, 15 Nov 2022 04:11:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237850AbiKOJLJ (ORCPT ); Tue, 15 Nov 2022 04:11:09 -0500 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 480AA21E2A for ; Tue, 15 Nov 2022 01:11:08 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id 4-20020a250104000000b006de5a38d75bso9787418ybb.20 for ; Tue, 15 Nov 2022 01:11:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=AQtykxHiwgykFBU1KSjj+ViZJkVO1odUlq/LYoyPTB0=; b=VfdPo2+5MUm9/3E4ypg6A/BaODeh//dGMRS3Xfilt8nKLb4tUmeVd7dsAPYupp4qtZ 4ZSZzwK+ThYnT/YYc2LOmXZNt/2EdYdg09A6Ujp8FuW48Pi1IZZBgtyPRdlGgn5AmahW 9UAG83Aocw/Xfqryl/Z+BToXgEdMuxml+WuGouZvU+m0bfQQiyxzgnm0IFzGT9yPeKwX mTL9UusVcYpDgp0uXvCLyyndgIGo2sbHt97A31ymqm/WYNRTkH0Um+zp438aEd3Lbwg5 BZI6Br8HokCPHTiSUnRcVNi+WK2qj/0wBke/xc+6pauFxCCSG+43LMjbto+C6YALhqzt I+3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=AQtykxHiwgykFBU1KSjj+ViZJkVO1odUlq/LYoyPTB0=; b=1Rmf6rYbfAevyFJI2PdDmIipo92gS19P54oIYubniyVt52IDVTSSbiksGYaKuBfzMP Qrw4vLYKeV3e2sgpxsK0SRTJ9txumrMkaf6dq8rUkc1O3ep10AkP0gyHSiNQB5fUiVVs YBf26jkcfrBDaU4FVnQW4Gw2WfSecEHpXY6K/1Cd9WRvY2wgGIVod0qS/wiTkXtlVeLx aEwo+eK2HV6B7BSNTmsFMAsbczlKmQWyZjLwCBCeGHrYmyATC+TMy3rh/QZpr9hu36vu 8DkAhixi44IMDsf0cNjej+G71CZyrlfP8SiVT9mjnGvmtX0Q/eC3vRXG42FlSEgl9SZm d4yQ== X-Gm-Message-State: ANoB5plTlspqmYIfTCMRbeeNqaCq9zDEuw8KoSPKsFBfu6KLY90O+0vi 6t554WLwW0IDe91e7DMvoRS6KhJb40j63Q== X-Google-Smtp-Source: AA0mqf7yC4mF5EHv3j1Lqd4kK0XbFSiUKqrHOA/e3MKf+ApeqWRA9iD4tiV0KGgZau1qKHGSPnlC8e4JBMIh9g== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a81:ae5f:0:b0:377:40d0:a20c with SMTP id g31-20020a81ae5f000000b0037740d0a20cmr6564513ywk.132.1668503467195; Tue, 15 Nov 2022 01:11:07 -0800 (PST) Date: Tue, 15 Nov 2022 09:10:57 +0000 In-Reply-To: <20221115091101.2234482-1-edumazet@google.com> Mime-Version: 1.0 References: <20221115091101.2234482-1-edumazet@google.com> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog Message-ID: <20221115091101.2234482-3-edumazet@google.com> Subject: [PATCH net-next 2/6] ipv6: fib6_new_sernum() optimization From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet , David Ahern Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Adopt atomic_try_cmpxchg() which is slightly more efficient. Signed-off-by: Eric Dumazet Cc: David Ahern Reviewed-by: David Ahern --- net/ipv6/ip6_fib.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c index 413f66781e50de62d6b20042d84798e7da59165a..2438da5ff6da810d9f612fc66df4d28510f50f10 100644 --- a/net/ipv6/ip6_fib.c +++ b/net/ipv6/ip6_fib.c @@ -91,13 +91,12 @@ static void fib6_walker_unlink(struct net *net, struct fib6_walker *w) static int fib6_new_sernum(struct net *net) { - int new, old; + int new, old = atomic_read(&net->ipv6.fib6_sernum); do { - old = atomic_read(&net->ipv6.fib6_sernum); new = old < INT_MAX ? old + 1 : 1; - } while (atomic_cmpxchg(&net->ipv6.fib6_sernum, - old, new) != old); + } while (!atomic_try_cmpxchg(&net->ipv6.fib6_sernum, &old, new)); + return new; } From patchwork Tue Nov 15 09:10:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13043333 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 22C30C4332F for ; Tue, 15 Nov 2022 09:11:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237891AbiKOJL1 (ORCPT ); Tue, 15 Nov 2022 04:11:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233081AbiKOJLL (ORCPT ); Tue, 15 Nov 2022 04:11:11 -0500 Received: from mail-qk1-x749.google.com (mail-qk1-x749.google.com [IPv6:2607:f8b0:4864:20::749]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D1C8121E30 for ; Tue, 15 Nov 2022 01:11:09 -0800 (PST) Received: by mail-qk1-x749.google.com with SMTP id de43-20020a05620a372b00b006fae7e5117fso13052571qkb.6 for ; Tue, 15 Nov 2022 01:11:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=n0VLENMcyvxwA2BZU5YBTMVw3WKcpvSd2Zjv1qxjp44=; b=FtgMXTd0TUIY3ZD3cb6R+fm9VjWxuEThcuyIZHyMLZ9EFVWbeSXXXKM5iEFzhEdq7F qQ10umbnCxRMJQQMm7x7VEGNrLNnQeQwaw97hdiy/VqS2mgvPp8MsT/8QmwQFBTNmlr6 b13mh44hDaq4D7F4UOmE4cq6etft5KSRmWsREhIPg5fqfLamowvZfZywmCBrmOsr0F07 1HkjGnzfr9go3lyTzWAFLl9W4bRj/zZbmOuGcdrn0c/BL5J9x+QM+HEu5zb1aUfTSiUh 469gzpdZWWjzo/xFx3XN8aHKSJWXy0umuItni1qKabgQ8r3ZpHePuPXD7zKVhTfEc5QL GhdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=n0VLENMcyvxwA2BZU5YBTMVw3WKcpvSd2Zjv1qxjp44=; b=QZPdS019L2ZtlH08Q5CBr37E9ClHR/jlG8dzs64ySUckPln35UgDLlV5P/OZTnkwwD RodRO2Dn9Z9QBjUfA7kA248ZO5uysg3xlJH1Bc42UQlpHvheVw35sVndmmgB4EGJypBK fjTss4IxnDsOei7A0qYqZIWnxK4gGPdSphHc9bPzYR7lL5CeRimz6Qfx2kBzpI4O07io 22qKRCsy4J6lngwBnci/fSwQxsN0nTfKX1YG/bIo+K0++XcjXTrZSP+hrvCMAYdKBB6a gjyAd7Z4VxXrEMThPvnAYITsK6dE1pkvgRzIKnDF+1jj1i6BR4ZCMAM0p4E/gVlIgVwV 8M7A== X-Gm-Message-State: ANoB5pnE4n+sUdKR17hsJRgkZfAQzQ55dwSbIfksCVsqN9RSR34ek/fs PBJ8TgGFFVKLhnBGnKIr+vnE7FI+zpzQCw== X-Google-Smtp-Source: AA0mqf4T6gvrIqro5KqII+Xa+IRxQXhYyaBp/uBardQUDLJHY6pfO7ur43XRaybvIUP9xiw5hKCJ4zrOQI7ybQ== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a05:6214:598d:b0:4b1:97a2:405b with SMTP id ll13-20020a056214598d00b004b197a2405bmr16097598qvb.27.1668503469072; Tue, 15 Nov 2022 01:11:09 -0800 (PST) Date: Tue, 15 Nov 2022 09:10:58 +0000 In-Reply-To: <20221115091101.2234482-1-edumazet@google.com> Mime-Version: 1.0 References: <20221115091101.2234482-1-edumazet@google.com> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog Message-ID: <20221115091101.2234482-4-edumazet@google.com> Subject: [PATCH net-next 3/6] net: net_{enable|disable}_timestamp() optimizations From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Adopting atomic_try_cmpxchg() makes the code cleaner. Signed-off-by: Eric Dumazet --- net/core/dev.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/net/core/dev.c b/net/core/dev.c index 117e830cabb0787ecd3da13bd88f8818fddaddc1..10b56648a9d4a0a709f8e23bb3e114854a4a1b69 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -2073,13 +2073,10 @@ static DECLARE_WORK(netstamp_work, netstamp_clear); void net_enable_timestamp(void) { #ifdef CONFIG_JUMP_LABEL - int wanted; + int wanted = atomic_read(&netstamp_wanted); - while (1) { - wanted = atomic_read(&netstamp_wanted); - if (wanted <= 0) - break; - if (atomic_cmpxchg(&netstamp_wanted, wanted, wanted + 1) == wanted) + while (wanted > 0) { + if (atomic_try_cmpxchg(&netstamp_wanted, &wanted, wanted + 1)) return; } atomic_inc(&netstamp_needed_deferred); @@ -2093,13 +2090,10 @@ EXPORT_SYMBOL(net_enable_timestamp); void net_disable_timestamp(void) { #ifdef CONFIG_JUMP_LABEL - int wanted; + int wanted = atomic_read(&netstamp_wanted); - while (1) { - wanted = atomic_read(&netstamp_wanted); - if (wanted <= 1) - break; - if (atomic_cmpxchg(&netstamp_wanted, wanted, wanted - 1) == wanted) + while (wanted > 1) { + if (atomic_try_cmpxchg(&netstamp_wanted, &wanted, wanted - 1)) return; } atomic_dec(&netstamp_needed_deferred); From patchwork Tue Nov 15 09:10:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13043332 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F300CC43217 for ; Tue, 15 Nov 2022 09:11:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237881AbiKOJLY (ORCPT ); Tue, 15 Nov 2022 04:11:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237882AbiKOJLM (ORCPT ); Tue, 15 Nov 2022 04:11:12 -0500 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB164220C7 for ; Tue, 15 Nov 2022 01:11:11 -0800 (PST) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-368e6c449f2so129312467b3.5 for ; Tue, 15 Nov 2022 01:11:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=IzTEGInsc651trn1H4eivMKji6foEGR4+N7CqOcQ3T8=; b=lGwe+6lwEiQlGp/jWFijhh3QcJd08W/LJl/piDQ+ZuLryzNE2eqwUQ4obk1dzN8O0C lSyuOhsaneuIzPOMDNRFmtKVhl7af/B0Yd8cbDm3hhHpWUqoBfnBpaOHCpzlJISYw4Pv QLadFkk7gG/oynzOiWLIm0InaJZuiczzsM4tlLEPkRvfoMVJxn7RoTopInfCo84W6w8m aKYxROC4hrRx8EC+78yucZF+VRhYY4QqaFAxqXqF0djT9CKIb/vwq53tWXV5gLAax8sP uFFTKtMyqIcr6VbBOxouNVssEs7El9dgPGfxU4Zv+RbTZt+sDv1ZzTjhmr91oI+usLf3 ES0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=IzTEGInsc651trn1H4eivMKji6foEGR4+N7CqOcQ3T8=; b=gJbavJpzEa79pkqI9Knb2TS5gkOqIYWPMr0tKe/L9gWYROyOfLiMwZCFttyUqnL3UH 0QJ4z0l87GHZmmiBCGJ3j3Mrf8l8udo2Z4Cnp+MXxnp3BmxWAvveYqhQ1iVp6lqpm5I2 eugu7ZJcQq/mbIrWJKqmpzbYuNRPV5qY1PU9U0hGwcSTksL2G2tmUTKVVKEzPGQmKoy/ Eb9HmsJZTs4i47Eks9VpemIDLJfBMllYCZs+NZJipSwT+o6BVFbX9peqxXndamUcn93Z vmQp6RCjI40mqKnemBICGcHCXEzz674ncWopngYIXJtg9zMcJW2IE6io1CLhP4MYNPXH dksA== X-Gm-Message-State: ACrzQf06m+mg3B8IPTCNtEZyDSLTsZjpqB1bezaxXWbVMRtyfYA+q+xE j3onY7fbkEyYjeSH2H65sr18vcj4RsDJAg== X-Google-Smtp-Source: AMsMyM4MBxsH1nQbav9mkjyf92C0Am6VF/DT/16xjtPhluXoX5eEcWD3zyHowGC87u8erRVEOS4rr3DdWnfmVQ== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a0d:f182:0:b0:370:7d9b:a54e with SMTP id a124-20020a0df182000000b003707d9ba54emr54734296ywf.133.1668503470497; Tue, 15 Nov 2022 01:11:10 -0800 (PST) Date: Tue, 15 Nov 2022 09:10:59 +0000 In-Reply-To: <20221115091101.2234482-1-edumazet@google.com> Mime-Version: 1.0 References: <20221115091101.2234482-1-edumazet@google.com> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog Message-ID: <20221115091101.2234482-5-edumazet@google.com> Subject: [PATCH net-next 4/6] net: adopt try_cmpxchg() in napi_schedule_prep() and napi_complete_done() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org This makes the code slightly more efficient. Signed-off-by: Eric Dumazet --- net/core/dev.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/net/core/dev.c b/net/core/dev.c index 10b56648a9d4a0a709f8e23bb3e114854a4a1b69..0c12c7ad04f21da05fef4c60ca5570bff48ec491 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -5979,10 +5979,9 @@ EXPORT_SYMBOL(__napi_schedule); */ bool napi_schedule_prep(struct napi_struct *n) { - unsigned long val, new; + unsigned long new, val = READ_ONCE(n->state); do { - val = READ_ONCE(n->state); if (unlikely(val & NAPIF_STATE_DISABLE)) return false; new = val | NAPIF_STATE_SCHED; @@ -5995,7 +5994,7 @@ bool napi_schedule_prep(struct napi_struct *n) */ new |= (val & NAPIF_STATE_SCHED) / NAPIF_STATE_SCHED * NAPIF_STATE_MISSED; - } while (cmpxchg(&n->state, val, new) != val); + } while (!try_cmpxchg(&n->state, &val, new)); return !(val & NAPIF_STATE_SCHED); } @@ -6063,9 +6062,8 @@ bool napi_complete_done(struct napi_struct *n, int work_done) local_irq_restore(flags); } + val = READ_ONCE(n->state); do { - val = READ_ONCE(n->state); - WARN_ON_ONCE(!(val & NAPIF_STATE_SCHED)); new = val & ~(NAPIF_STATE_MISSED | NAPIF_STATE_SCHED | @@ -6078,7 +6076,7 @@ bool napi_complete_done(struct napi_struct *n, int work_done) */ new |= (val & NAPIF_STATE_MISSED) / NAPIF_STATE_MISSED * NAPIF_STATE_SCHED; - } while (cmpxchg(&n->state, val, new) != val); + } while (!try_cmpxchg(&n->state, &val, new)); if (unlikely(val & NAPIF_STATE_MISSED)) { __napi_schedule(n); From patchwork Tue Nov 15 09:11:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13043335 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 57BBFC433FE for ; Tue, 15 Nov 2022 09:11:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237899AbiKOJLa (ORCPT ); Tue, 15 Nov 2022 04:11:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237885AbiKOJLO (ORCPT ); Tue, 15 Nov 2022 04:11:14 -0500 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32804B52 for ; Tue, 15 Nov 2022 01:11:13 -0800 (PST) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-373582569edso129029167b3.2 for ; Tue, 15 Nov 2022 01:11:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=/KnDPmLiLROE2x+/oI+9SLuVYCuUAikRvTz6TZve5eg=; b=SiFwt1Maic3Hskls/JE6DELx9xMsqexIwazw57Hiw5sEj8Eb//Lt+4QVwYDnQUjFwC WsqWT/bl4fBuIPIDn4ekxKPT5zbH5TDtCvld+q2SXMTYoUfqgDxm+KXv3wQkEAhUxqZk lO+UdM/FEPPPBFXftOA7+8XvQydzThPAjja1FZLO1b7UsyeLMvanBNUkvhVz0r2uKhVB wILs0LTb8S9ru/IfXD6zHfY7zQg6O3y6g05g1P8QyGQqg3YjHlBdgzibCmusa9XlQZO4 kMYsQaOnBWoSpclO72rirul3LjZTLsiy9hC/tCbXImwDR6J7VXCS6rKP0pXG+laOEkAF yxMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=/KnDPmLiLROE2x+/oI+9SLuVYCuUAikRvTz6TZve5eg=; b=c7r1Lwq87PHkZtb6vj9GIABzybfUCV45qTtYBZ++dF2zbiWewNcG1CuaOP5gfItXmA P2bmBItGgUJnFCKropix6U5dyjUnUeIgZcKb+xE4OC5pVYCzAf+LDOljhy81MGAlPkP9 qnKRu2SnFwuA56uKqFpBigpA+EZb8jNziBJgxyaCPOP3IrD5Bk8mFXsYkGMOLmXjv3Md Fq6BwTWKu1J9IWDJwpliZpjMqKqy2Pijlr9oUv5w+Wq4RvyETmaTKLEdMDXvVXnIX4kH VP02LnIphbRfo1Tv+IKcVegVuFA8BROpLIvq8+QYw4PxsK5aJNXjW3Wzafu1omZwIfCj 7Aww== X-Gm-Message-State: ANoB5pmBvshV7utqwIDeez9UVefslPppQtwLTMUJXt3h/K3FZJNXrFBV iViYiYj24JHlWuFAHHKnq9AMp/YVGX7FlQ== X-Google-Smtp-Source: AA0mqf4d7gvPBejyqmSOpYyr3Pf/YswwIitZGipRZbXHtyt0FEYHiC0efPqJatJsozEgjLoPy0u5nyPdL8iOWw== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a25:ca4f:0:b0:6cc:6a92:7a17 with SMTP id a76-20020a25ca4f000000b006cc6a927a17mr16011719ybg.282.1668503472536; Tue, 15 Nov 2022 01:11:12 -0800 (PST) Date: Tue, 15 Nov 2022 09:11:00 +0000 In-Reply-To: <20221115091101.2234482-1-edumazet@google.com> Mime-Version: 1.0 References: <20221115091101.2234482-1-edumazet@google.com> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog Message-ID: <20221115091101.2234482-6-edumazet@google.com> Subject: [PATCH net-next 5/6] net: adopt try_cmpxchg() in napi_{enable|disable}() From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org This makes code a bit cleaner. Signed-off-by: Eric Dumazet --- net/core/dev.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/net/core/dev.c b/net/core/dev.c index 0c12c7ad04f21da05fef4c60ca5570bff48ec491..fb943dad96513e0f9eb1c3ce30c5bb7170edea5e 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -6397,8 +6397,8 @@ void napi_disable(struct napi_struct *n) might_sleep(); set_bit(NAPI_STATE_DISABLE, &n->state); - for ( ; ; ) { - val = READ_ONCE(n->state); + val = READ_ONCE(n->state); + do { if (val & (NAPIF_STATE_SCHED | NAPIF_STATE_NPSVC)) { usleep_range(20, 200); continue; @@ -6406,10 +6406,7 @@ void napi_disable(struct napi_struct *n) new = val | NAPIF_STATE_SCHED | NAPIF_STATE_NPSVC; new &= ~(NAPIF_STATE_THREADED | NAPIF_STATE_PREFER_BUSY_POLL); - - if (cmpxchg(&n->state, val, new) == val) - break; - } + } while (!try_cmpxchg(&n->state, &val, new)); hrtimer_cancel(&n->timer); @@ -6426,16 +6423,15 @@ EXPORT_SYMBOL(napi_disable); */ void napi_enable(struct napi_struct *n) { - unsigned long val, new; + unsigned long new, val = READ_ONCE(n->state); do { - val = READ_ONCE(n->state); BUG_ON(!test_bit(NAPI_STATE_SCHED, &val)); new = val & ~(NAPIF_STATE_SCHED | NAPIF_STATE_NPSVC); if (n->dev->threaded && n->thread) new |= NAPIF_STATE_THREADED; - } while (cmpxchg(&n->state, val, new) != val); + } while (!try_cmpxchg(&n->state, &val, new)); } EXPORT_SYMBOL(napi_enable); From patchwork Tue Nov 15 09:11:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 13043334 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6F614C4332F for ; Tue, 15 Nov 2022 09:11:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237898AbiKOJLa (ORCPT ); Tue, 15 Nov 2022 04:11:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237801AbiKOJLP (ORCPT ); Tue, 15 Nov 2022 04:11:15 -0500 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E393225D5 for ; Tue, 15 Nov 2022 01:11:14 -0800 (PST) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-3697bd55974so129510717b3.15 for ; Tue, 15 Nov 2022 01:11:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=5Q+NBgnsxBhbS8CdFydsv9HAeIB1Hf47gnOOENdaeoQ=; b=n/68GvE/xJTi1O94gN97zg2kEVBihz3YWx8HhowtfmcpH+n722ApCBaD3BvaP05wth IX8FBJ5a58oDDqhGFlC+yuGpnHW/+wP3oRJADDbl+Kosc1rhtogQoQuNfyYMvVKH+Aq9 MFMpMzQvzVRFRLI48fw0TiBnfDYsQ8Jjh8QGr8ktBL9wy6jEOiV5Xbha5iWpmMgESa44 Q4u14/1xOVc2TFP5sbNS2MlhSKqzuODjXYeHg9+FNKpVcap1WmrIhmkzRz8w3DeXW4xt 3CG65c3OsRcH7JjoIJG7bxXN1kD3p87Jyciqm3S/R6gfeR+taz/yuqpSxwZiGx3Mhs0z wprw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=5Q+NBgnsxBhbS8CdFydsv9HAeIB1Hf47gnOOENdaeoQ=; b=tmJc8MiBFvUS27pKveIvXk6Jj0KX+SBbGJjcEpOw/TGEstufa+Ihjwvd9KBd1cmIZc 61oOku78gsyxyuLQzrBcdi5Q+UDFcsHpOJQFJgJ67RH1GsujhX6YCb/uGxjbhH0q3bsK S352vF3ih0VCH5qZfhkU1Q3FjHu1ZeJ1SigEGOlZESgYuADxQ+arrgVQfLJJkxwjGNy/ RdFOiBbDV/FTiJRL/dIebSfCWHtIY7fjmRXFP6u5whmc5wN7ghhFxmZa1bAaZWZwBkNe HwwJCsz7WeVsLxUuTFaQCLfWhR35URaf6K+KGfvJfAYnbZcuRhOYC/23OfZpBxsI2hxM UDAQ== X-Gm-Message-State: ANoB5pkQZsyfs3on/W9KEu0xqom3/sR5dSd9OJRftZg9W2ibX7IdWfMS 2n+f3S5wGQVt902rhJkrGm90uNA0tfeOdA== X-Google-Smtp-Source: AA0mqf6hfIbyWf4NvjQSVZGDwH85zXS/sFcauG4+1nxuHmvcDRGtIS1VeSWrpscs9CVsS9AadQ1tVFcBQLmakA== X-Received: from edumazet1.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:395a]) (user=edumazet job=sendgmr) by 2002:a5b:604:0:b0:6dd:cf4b:9040 with SMTP id d4-20020a5b0604000000b006ddcf4b9040mr14934620ybq.223.1668503474245; Tue, 15 Nov 2022 01:11:14 -0800 (PST) Date: Tue, 15 Nov 2022 09:11:01 +0000 In-Reply-To: <20221115091101.2234482-1-edumazet@google.com> Mime-Version: 1.0 References: <20221115091101.2234482-1-edumazet@google.com> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog Message-ID: <20221115091101.2234482-7-edumazet@google.com> Subject: [PATCH net-next 6/6] net: __sock_gen_cookie() cleanup From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, eric.dumazet@gmail.com, Eric Dumazet Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Adopt atomic64_try_cmpxchg() and remove the loop, to make the intent more obvious. Signed-off-by: Eric Dumazet --- net/core/sock_diag.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c index f7cf74cdd3db1f7f0783db88fc28fd876fbac4b6..b11593cae5a09b15a10d6ba35bccc22263cb8fc8 100644 --- a/net/core/sock_diag.c +++ b/net/core/sock_diag.c @@ -25,14 +25,14 @@ DEFINE_COOKIE(sock_cookie); u64 __sock_gen_cookie(struct sock *sk) { - while (1) { - u64 res = atomic64_read(&sk->sk_cookie); + u64 res = atomic64_read(&sk->sk_cookie); - if (res) - return res; - res = gen_cookie_next(&sock_cookie); - atomic64_cmpxchg(&sk->sk_cookie, 0, res); + if (!res) { + u64 new = gen_cookie_next(&sock_cookie); + + atomic64_try_cmpxchg(&sk->sk_cookie, &res, new); } + return res; } int sock_diag_check_cookie(struct sock *sk, const __u32 *cookie)