From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7984DC33CB2 for ; Wed, 15 Jan 2020 03:23:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5AFB6222C3 for ; Wed, 15 Jan 2020 03:23:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728949AbgAODXx (ORCPT ); Tue, 14 Jan 2020 22:23:53 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:9175 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728879AbgAODXw (ORCPT ); Tue, 14 Jan 2020 22:23:52 -0500 Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 60212E03A4F264E77DEC; Wed, 15 Jan 2020 11:23:49 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.439.0; Wed, 15 Jan 2020 11:23:40 +0800 From: Shaokun Zhang To: , CC: Yuqi Jin , "David S. Miller" , Alexey Kuznetsov , Hideaki YOSHIFUJI , Eric Dumazet , Yang Guo , Shaokun Zhang Subject: [PATCH] net: optimize cmpxchg in ip_idents_reserve Date: Wed, 15 Jan 2020 11:23:40 +0800 Message-ID: <1579058620-26684-1-git-send-email-zhangshaokun@hisilicon.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.69.192.56] X-CFilter-Loop: Reflected Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Yuqi Jin atomic_try_cmpxchg is called instead of atomic_cmpxchg that can reduce the access number of the global variable @p_id in the loop. Let's optimize it for performance. Cc: "David S. Miller" Cc: Alexey Kuznetsov Cc: Hideaki YOSHIFUJI Cc: Eric Dumazet Cc: Yang Guo Signed-off-by: Yuqi Jin Signed-off-by: Shaokun Zhang --- net/ipv4/route.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/ipv4/route.c b/net/ipv4/route.c index 87e979f2b74a..7e28c7121c20 100644 --- a/net/ipv4/route.c +++ b/net/ipv4/route.c @@ -496,10 +496,10 @@ u32 ip_idents_reserve(u32 hash, int segs) delta = prandom_u32_max(now - old); /* Do not use atomic_add_return() as it makes UBSAN unhappy */ + old = (u32)atomic_read(p_id); do { - old = (u32)atomic_read(p_id); new = old + delta + segs; - } while (atomic_cmpxchg(p_id, old, new) != old); + } while (!atomic_try_cmpxchg(p_id, &old, new)); return new - segs; } -- 2.7.4