From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752807AbcABDUn (ORCPT ); Fri, 1 Jan 2016 22:20:43 -0500 Received: from mail-io0-f181.google.com ([209.85.223.181]:35767 "EHLO mail-io0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751804AbcABDUl (ORCPT ); Fri, 1 Jan 2016 22:20:41 -0500 MIME-Version: 1.0 In-Reply-To: <1451689635.8255.71.camel@edumazet-glaptop2.roam.corp.google.com> References: <1451635091-109673-1-git-send-email-mikedanese@google.com> <1451689635.8255.71.camel@edumazet-glaptop2.roam.corp.google.com> Date: Fri, 1 Jan 2016 19:20:41 -0800 Message-ID: Subject: Re: [PATCH] net: refactor icmp_global_allow to improve readability and performance. From: Mike Danese To: Eric Dumazet Cc: netdev@vger.kernel.org, "David S. Miller" , Alexey Kuznetsov , James Morris , Hideaki YOSHIFUJI , Patrick McHardy , open list Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Yes, I completely missed the purpose of that. As a new year's resolution, I resolve to read the comments. Thanks for the review! On Fri, Jan 1, 2016 at 3:07 PM, Eric Dumazet wrote: > On Thu, 2015-12-31 at 23:58 -0800, Mike Danese wrote: >> We can reduce the number of operations performed by icmp_global_allow >> and make the routine more readable by refactoring it in two ways: >> >> First, this patch refactors the meaning of the "delta" variable. Before >> this change, it meant min("time since last refill of token bucket", HZ). >> After this change, it means "time since last refill". The original >> definition is required only once but was being calculated twice. The new >> meaning is also more intuitive for a variable named "delta". >> >> Second, by calculating "delta" (time since last refill of token bucket) >> and "cbr" (token bucket can be refilled) at the beginning of the >> routine, we reduce the number of repeated calculations of these two >> variables. >> >> There should be no functional difference. >> >> Signed-off-by: Mike Danese >> --- >> net/ipv4/icmp.c | 17 ++++++++--------- >> 1 file changed, 8 insertions(+), 9 deletions(-) > > Hi Mike > > Sorry, this is a very broken patch. > > There is a comment you apparently missed completely : > > /* Check if token bucket is empty and cannot be refilled > * without taking the spinlock. > */ > > There is a reason we compute 'delta' two times. > > One without the spinlock held, and a second time with the spinlock held. > > This is an opportunistic way to exit early without false sharing in the > stress case where many cpus might enter this code. > > Really I do not think current code needs any 'refactoring', especially > around December 31th at midnight ;) > > >