From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755649AbcFQPXF (ORCPT ); Fri, 17 Jun 2016 11:23:05 -0400 Received: from mout.kundenserver.de ([212.227.126.131]:57755 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754470AbcFQPXB (ORCPT ); Fri, 17 Jun 2016 11:23:01 -0400 From: Arnd Bergmann To: Saeed Mahameed Cc: Matan Barak , Leon Romanovsky , Saeed Mahameed , "David S. Miller" , Achiad Shochat , Tariq Toukan , Gal Pressman , Maor Gottlieb , Huy Nguyen , Linux Netdev List , linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/2] mlx5: fix 64-bit division on times Date: Fri, 17 Jun 2016 17:24:40 +0200 Message-ID: <7479054.ALBOnYT4q2@wuerfel> User-Agent: KMail/5.1.3 (Linux/4.4.0-22-generic; KDE/5.18.0; x86_64; ; ) In-Reply-To: References: <20160615152816.2800830-1-arnd@arndb.de> <20160615152816.2800830-2-arnd@arndb.de> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Provags-ID: V03:K0:2EN9MWmt4S/0q8QJ4wmY3fLfvPPMdhT3Keq/1RkwwXsX8Kb9WS3 IO5s6vJrF69RG/arMmFkKBsMpxaAx2Foepj8WyciJEetAaX8T+66dROBHjaqu7xKRsz4+0Q iynUbTpUAhWjPVyNj/M9jbBmBd7d+37UyVjEbV3AOKD7FhlnOnCa3oTkJsgH5RX7vGSP/0y VCMLQOaiYabNySSLrDVuA== X-UI-Out-Filterresults: notjunk:1;V01:K0:/bSF7tqbXcM=:Wd+mu6aTGeF9tw17SuRUwW dl72gNKvRWffgyT0HlLrIEdCUlXzjfnrEpl4XcyMMJAI9FdaPkHXmP1pGmz21u3lMmHrRNoFH zj13IvbvH4m3XaJL1mmHXiECDYBluiG66pXGd1YNK+2Dh56eoEccBPLQDuyM2CkjgECB+v0Qk 7XcPX+TsH/O8IpNiCS/xET8S5fwm9OnzbKnpYLokOvFWpYFrGpA+jR0z6cAKfZ10WS968BAHK e09vhwit57xFZ8N2c9M6/jDIDXCWaDV70+BbSLOasqSIUeQTi6CvC6XVP84o4QuodrC0S5n3I 3dDiNhcVOLUNuSzhkL2kdFF7gJEyuVaXuXC3WWIIJZVByJt780xGIQEa6eT0yNOxCFA1K0H06 Y8da2G2J/Runqv7t4CZi9MHXqqdOhS0JHIgBjWMv7gcYgtGtT6Z2gGiYKClrCNKpmTpuUSItW gqTB3QU+WMGfvNh4Phsfj1GE+HqsSLNz22EQ2YQKr6sy6/2TPAjXsOH0AvhCiQQUPrw5t6bdB rIlWIHkur5PTFNMf/GFzvlRopuVyi06ZNW6Qhmisk6aEtSOHa0GFWfd3iau8/fSOVRKjZSw9i tga1ohsPUl1X7ZpNzt5AjYC1vl1/qEMlmfGd/Mp5O1WrC3JGGhkGHWpaV0Ca9nMI2fPqdI5rz IAyxOyn943xPIesUoOxmxquD9FkeV7Nw3NgzYgx2XZKbLmBUIwBbbkkGFRyfmJvcW+xyHRIZp 0gvadGJhEuRG1wfR Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Friday, June 17, 2016 6:09:00 PM CEST Saeed Mahameed wrote: > On Wed, Jun 15, 2016 at 6:27 PM, Arnd Bergmann wrote: > > The mlx5 driver fails to build on 32-bit architectures after some > > references to 64-bit divisions got added: > > > > drivers/net/built-in.o: In function `mlx5e_rx_am': > > :(.text+0xf88ac): undefined reference to `__aeabi_ldivmod' > > > > The driver even performs three division here, and it uses the > > obsolete 'struct timespec' that we want to get rid of. > > > > Using ktime_t and ktime_us_delta() replaces one of the divisions > > and is mildly more efficient, aside from working across 'settimeofday' > > calls and being the right type for the y2038 conversion. > > > > Using a u32 instead of s64 to store the number of microseconds > > limits the maximum time to about 71 minutes, but if we exceed that > > time, we probably don't care about the result any more for the > > purpose of rx coalescing. > > > > For the number of packets, we are taking the difference between > > two 'unsigned int', so the result won't ever be greater than that > > either. > > > > After those changes, the other two divisions are done as 32-bit > > arithmetic operations, which are much faster. > > Nice catch Arnd, we originally fixed this with div_u64, but your > solution looks wiser. > does ktime_t gives time in a resolution same as timespec ? ktime_t is a 64-bit nanosecond counter, so the resolution is the same as ktime_get_ts64(), which is the "monotonic" equivalent of getnstimeofday(). There are also variants that have the same resolution but are less accurate and don't set the exact lower bits in order to get a faster reading, but the above are all as accurate as the machine allows. Arnd