From patchwork Wed Jun 15 15:27:52 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 102214 Delivered-To: patch@linaro.org Received: by 10.140.106.246 with SMTP id e109csp2631792qgf; Wed, 15 Jun 2016 08:27:38 -0700 (PDT) X-Received: by 10.66.161.201 with SMTP id xu9mr4370504pab.140.1466004458155; Wed, 15 Jun 2016 08:27:38 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f71si45659055pfa.157.2016.06.15.08.27.37; Wed, 15 Jun 2016 08:27:38 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933222AbcFOP1a (ORCPT + 30 others); Wed, 15 Jun 2016 11:27:30 -0400 Received: from mout.kundenserver.de ([212.227.126.135]:56173 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932121AbcFOP11 (ORCPT ); Wed, 15 Jun 2016 11:27:27 -0400 Received: from wuerfel.lan. ([78.42.132.4]) by mrelayeu.kundenserver.de (mreue001) with ESMTPA (Nemesis) id 0MTsps-1amhct0WSO-00QVN0; Wed, 15 Jun 2016 17:27:19 +0200 From: Arnd Bergmann To: Matan Barak , Leon Romanovsky Cc: Arnd Bergmann , Saeed Mahameed , "David S. Miller" , Achiad Shochat , Tariq Toukan , Gal Pressman , Maor Gottlieb , Huy Nguyen , netdev@vger.kernel.org, linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] mlx5: fix 64-bit division on times Date: Wed, 15 Jun 2016 17:27:52 +0200 Message-Id: <20160615152816.2800830-2-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20160615152816.2800830-1-arnd@arndb.de> References: <20160615152816.2800830-1-arnd@arndb.de> X-Provags-ID: V03:K0:lDbL6gMP5xcPLGbFiEcOTi3U8zj/NrlPpAXNOF8J6VlpfI2An71 w7XhT0ZMBoBOuHopB6Wkt7T/c6WyqYXYTQ9eNYVSBSDlOTMVP/Ti9/tlmKegBah5B15mcPB tbtohajDub7yCohguKVhpybPG1huBbZWXqvhQixExI9Xi9hyd3+t3gnKtHeI0EpcBlS1LO2 k1kgfYSSGUZWL47qYGrIw== X-UI-Out-Filterresults: notjunk:1; V01:K0:G+VbYbFvuSU=:CUF9gw21BP3q1mvhyktnyU V/Lfim4blBUxAVfVVZRH93g9SyaErKDC04LxRXNxUF5zZXHDmEXIo9xZUwwlkweKqewCHeGiF fRk76VSvQnznCi3CaXe9j+whRUmBrwehPiOkKad0DfVV4G9EfgSjuyCaFgxJXDnL2ed+cHVg6 pxAaIfTYYQ009F6aymT2AxqbvNYejYiJQ1MOiJPLpm7W7I0QXZbR6eyst3shSnrQiLgWLmUhe naJUehokMmjuDx4DyZnqQDgy9evILBuKCmtcaY07td7ZN56hFvfX/f+Um4/Bte6JgYt4Unrl/ yup4SuHjxQUElaLf0EHib2c/KlhdgAzrq67jteQyeZCl8o0QHEct9ElCPTH2Fc83Lnzbvq9jQ rvMBYnXUGMDcXVNpJbYXz4PJOhqXXQoEsQH+5DU/jjO7nuwppaiRywhL2UUifCBrRCmYI2wI9 UIvXSNOYfwPxAWrMg51vLSHZtQJ3B68kM3QAG+IHXyDajn5obAf98MZogjFanrZkOnVRAhgdk DkOCW/uxc+ktSSZBXSbYodosbwpNQIEw/NMRCdjuNAVyTwVtpo9uTLEgqQd7D9ViN7ZWzOQJr eqULVpQc3flSSiiM+TRsIbFCsg4Uj0Xof94mQGvOL8ii3Uwuc7VQGg8PW70Pr5ABQZQn+J+yP Vqij3i39Yq7ac9nWMkdBM3Yf/y9dLyGpotT0vSpXyVybDQ71V4EOOb2XhfnqRuoZgZGo= Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Signed-off-by: Arnd Bergmann Fixes: 3841f0b3493b ("net/mlx5e: Support adaptive RX coalescing") --- drivers/net/ethernet/mellanox/mlx5/core/en.h | 2 +- drivers/net/ethernet/mellanox/mlx5/core/en_rx_am.c | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) -- 2.9.0 diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en.h b/drivers/net/ethernet/mellanox/mlx5/core/en.h index 775b8d02a3dc..37df5728323b 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/en.h @@ -272,7 +272,7 @@ struct mlx5e_rx_am_stats { }; struct mlx5e_rx_am_sample { - struct timespec time; + ktime_t time; unsigned int pkt_ctr; u16 event_ctr; }; diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rx_am.c b/drivers/net/ethernet/mellanox/mlx5/core/en_rx_am.c index cdff5cace4c2..bd0c70220a80 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_rx_am.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rx_am.c @@ -267,7 +267,7 @@ static bool mlx5e_am_decision(struct mlx5e_rx_am_stats *curr_stats, static void mlx5e_am_sample(struct mlx5e_rq *rq, struct mlx5e_rx_am_sample *s) { - getnstimeofday(&s->time); + s->time = ktime_get(); s->pkt_ctr = rq->stats.packets; s->event_ctr = rq->cq.event_ctr; } @@ -278,17 +278,17 @@ static void mlx5e_am_calc_stats(struct mlx5e_rx_am_sample *start, struct mlx5e_rx_am_sample *end, struct mlx5e_rx_am_stats *curr_stats) { - struct timespec time = timespec_sub(end->time, start->time); - s64 delta_us = timespec_to_ns(&time) / 1000; - s64 npkts = end->pkt_ctr - start->pkt_ctr; + /* u32 holds up to 71 minutes, should be enough */ + u32 delta_us = ktime_us_delta(end->time, start->time); + unsigned int npkts = end->pkt_ctr - start->pkt_ctr; if (!delta_us) { WARN_ONCE(true, "mlx5e_am_calc_stats: delta_us=0\n"); return; } - curr_stats->ppms = (npkts * 1000) / delta_us; - curr_stats->epms = (MLX5E_AM_NEVENTS * 1000) / delta_us; + curr_stats->ppms = (npkts * USEC_PER_MSEC) / delta_us; + curr_stats->epms = (MLX5E_AM_NEVENTS * USEC_PER_MSEC) / delta_us; } void mlx5e_rx_am_work(struct work_struct *work)