Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp7893987ybl; Thu, 16 Jan 2020 07:20:24 -0800 (PST) X-Google-Smtp-Source: APXvYqz6+ZhqWVWEgP/JdwSexqGEdPchiuAlB8mFzEvXCyWxkootOOjLmFUL5J+JN51v6GiZ5llg X-Received: by 2002:a9d:7984:: with SMTP id h4mr2430962otm.297.1579188023959; Thu, 16 Jan 2020 07:20:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579188023; cv=none; d=google.com; s=arc-20160816; b=tHfj+r01jVCXyAfceRd7wONMUdtDFQ8w5e/KoQ6GqMobWy/rB54qITBZg3ZkGBh3fw +0lrgFP5ohJsyhNjUKT8nkvl+XMIUmUUlBINxnfc47wRKbePx/quzTYAyU+3Hqg0SPzk ZyeF6zzM6/UzjUlf8TXAuiLW3BiFyIZwJzmmJSivqyOVrqDvZBqvT7t6nBeyBjpcaZIh zOka9j7TJz3XqTZmpYZub/pAghbYu3/O6E1jDPFzAtvSqXuWIMx2NCE0o3XtfXz13Hjq 4ahhQsJT/pT6ouXBN5O9u5RM7rk+ArVJE0k0a39SeusSL1dIZ854hDgQg6VTqkN96DNT uU9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:references:cc:to:from:subject:dkim-signature; bh=Gv/c4WmqGfA4FwM+VUnPA6bgCeuDGypbQgWIA5eSdW4=; b=Gbe68TUUvWc2DQ0ysXKv0qax1+PGTNkfLLQisgp5vFExfpxe0HScfsHpQUVjiw1SlM FEd6HvA3nhHkBb2bQEsZv/0Y7UVGNS504au8Y9PH+/pkOuzEb+0lxVaZan/CVaLrvrfq ktnKdTifOW8eTCd26IUxNxBER++atY7QD5/J/IAnqCErrfa7j5uRdKjzPi172GLT9U/t DHmWVerlWc2ycaTvgFzT+fCWRl8A6OvL3atUFZOeU8gInsLk1obBErOHO2h2e+08YJvU TyRTIrdxSrqRzo6bFWJHZYgcNrbXwaRjSw9LG214Vlx8Rs6F4FZA9pmqL1u53Davq7Da XQQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=BdnC5X2e; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w1si12128485oia.169.2020.01.16.07.20.11; Thu, 16 Jan 2020 07:20:23 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=BdnC5X2e; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726688AbgAPPTI (ORCPT + 99 others); Thu, 16 Jan 2020 10:19:08 -0500 Received: from mail-pj1-f67.google.com ([209.85.216.67]:52032 "EHLO mail-pj1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726189AbgAPPTH (ORCPT ); Thu, 16 Jan 2020 10:19:07 -0500 Received: by mail-pj1-f67.google.com with SMTP id d15so1665680pjw.1; Thu, 16 Jan 2020 07:19:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=Gv/c4WmqGfA4FwM+VUnPA6bgCeuDGypbQgWIA5eSdW4=; b=BdnC5X2ejkNu6VgzVywx16V1MICoF+R7x5yXvrxhs7+K4demvgdXAocEzXP9dNN6tf ALngM0W3ucKlEPjA7RGYNqdUiwrkXVa8/9WO7kukDQicGPWFqPI4lc4hhwQ8kxPWkeTA uii4HQEyjtbDY0ca0MsBV6F/H3eQUS8xY0jLnQxn4U6MKtOlbY+mE+P67VziGut5c2bW oDzRiZtHaYAPl8KfLtuTHnD5LGAm6bDc9wP1G6Innf7Q0kgyz7SIKOS/mB/xX6glorIE zuPxvXwvYL7okIrTR2KM8zVHY+bOlVyU7FMYJGdqS/BAdbdJXAv2yORk2D3QZkTtFC5t D9mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=Gv/c4WmqGfA4FwM+VUnPA6bgCeuDGypbQgWIA5eSdW4=; b=Sxx8EgpQvmtNOnBdh9QmtwyFGhs7pmR9v+EbI+sZ8mBovwZkoSjyf/hLVT+UMvxZT3 AGtgNYdu15X1trB0Ega3uSs5ZgMp00XYZ83G+iiO0bT/5cQ4axCDseK4esajY93Xybpy WyZY+R+UGyUwt6ScX+Bb2SHnKtiKEWhosQcesvWL9wonFgP24zEDRwcMv2QbRrN4oHtx jDxTQQUoGIxr7sul2DnPLsbfQQJlgBOy+BGossV2c7G9CsD9vxngEmmTpYopUzGiU4Br 0FH5Aozw8Re4iRIOEJR/YvhRMoz3a/g8YuyD+6847Li4YpniV5LZO8TWRW5Wk6xUm0Km zv8Q== X-Gm-Message-State: APjAAAUJE8lZOfFS6f8crA6eTM4ibqRjjGpd/VO+lZtzCcEgh4kfceGf RcrJXf1dy52dfACnW24mCBM= X-Received: by 2002:a17:90a:9416:: with SMTP id r22mr7531065pjo.2.1579187947145; Thu, 16 Jan 2020 07:19:07 -0800 (PST) Received: from [192.168.86.235] (c-73-241-150-58.hsd1.ca.comcast.net. [73.241.150.58]) by smtp.gmail.com with ESMTPSA id k9sm4007510pjo.19.2020.01.16.07.19.05 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 16 Jan 2020 07:19:06 -0800 (PST) Subject: Re: [PATCH] net: optimize cmpxchg in ip_idents_reserve From: Eric Dumazet To: David Miller , zhangshaokun@hisilicon.com Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, jinyuqi@huawei.com, kuznet@ms2.inr.ac.ru, yoshfuji@linux-ipv6.org, edumazet@google.com, guoyang2@huawei.com References: <1579058620-26684-1-git-send-email-zhangshaokun@hisilicon.com> <20200116.042722.153124126288244814.davem@davemloft.net> <930faaff-4d18-452d-2e44-ef05b65dc858@gmail.com> Message-ID: <1b3aaddf-22f5-1846-90f1-42e68583c1e4@gmail.com> Date: Thu, 16 Jan 2020 07:19:05 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: <930faaff-4d18-452d-2e44-ef05b65dc858@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 1/16/20 7:12 AM, Eric Dumazet wrote: > > > On 1/16/20 4:27 AM, David Miller wrote: >> From: Shaokun Zhang >> Date: Wed, 15 Jan 2020 11:23:40 +0800 >> >>> 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 >> >> I doubt this makes any measurable improvement in performance. >> >> If you can document a specific measurable improvement under >> a useful set of circumstances for real usage, then put those >> details into the commit message and resubmit. >> >> Otherwise, I'm not applying this, sorry. >> > > > Real difference that could be made here is to > only use this cmpxchg() dance for CONFIG_UBSAN > > When CONFIG_UBSAN is not set, atomic_add_return() is just fine. > > (Supposedly UBSAN should not warn about that either, but this depends on compiler version) I will test something like : diff --git a/net/ipv4/route.c b/net/ipv4/route.c index 2010888e68ca96ae880481973a6d808d6c5612c5..e2fa972f5c78f2aefc801db6a45b2a81141c3028 100644 --- a/net/ipv4/route.c +++ b/net/ipv4/route.c @@ -495,11 +495,15 @@ u32 ip_idents_reserve(u32 hash, int segs) if (old != now && cmpxchg(p_tstamp, old, now) == old) delta = prandom_u32_max(now - old); - /* Do not use atomic_add_return() as it makes UBSAN unhappy */ +#ifdef CONFIG_UBSAN + /* Do not use atomic_add_return() as it makes old UBSAN versions unhappy */ do { old = (u32)atomic_read(p_id); new = old + delta + segs; } while (atomic_cmpxchg(p_id, old, new) != old); +#else + new = atomic_add_return(segs + delta, p_id); +#endif return new - segs; }