From patchwork Wed Jan 17 13:51:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yishai Hadas X-Patchwork-Id: 10169301 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 572E0603B5 for ; Wed, 17 Jan 2018 13:52:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 46B30251F4 for ; Wed, 17 Jan 2018 13:52:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3B1CA28450; Wed, 17 Jan 2018 13:52:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A3A4B251F4 for ; Wed, 17 Jan 2018 13:52:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753334AbeAQNwB (ORCPT ); Wed, 17 Jan 2018 08:52:01 -0500 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:41454 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753343AbeAQNv6 (ORCPT ); Wed, 17 Jan 2018 08:51:58 -0500 Received: from Internal Mail-Server by MTLPINE1 (envelope-from yishaih@mellanox.com) with ESMTPS (AES256-SHA encrypted); 17 Jan 2018 15:51:54 +0200 Received: from vnc17.mtl.labs.mlnx (vnc17.mtl.labs.mlnx [10.7.2.17]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id w0HDps3g015490; Wed, 17 Jan 2018 15:51:54 +0200 Received: from vnc17.mtl.labs.mlnx (vnc17.mtl.labs.mlnx [127.0.0.1]) by vnc17.mtl.labs.mlnx (8.13.8/8.13.8) with ESMTP id w0HDpsf3020826; Wed, 17 Jan 2018 15:51:54 +0200 Received: (from yishaih@localhost) by vnc17.mtl.labs.mlnx (8.13.8/8.13.8/Submit) id w0HDpnJQ020816; Wed, 17 Jan 2018 15:51:49 +0200 From: Yishai Hadas To: linux-rdma@vger.kernel.org Cc: yishaih@mellanox.com, ferasda@mellanox.com, jgg@mellanox.com, majd@mellanox.com, valex@mellanox.com, Eitan Rabin Subject: [PATCH rdma-core 3/5] mlx5: Add direct verb to translate device timestamp to nanoseconds Date: Wed, 17 Jan 2018 15:51:31 +0200 Message-Id: <1516197093-20699-4-git-send-email-yishaih@mellanox.com> X-Mailer: git-send-email 1.8.2.3 In-Reply-To: <1516197093-20699-1-git-send-email-yishaih@mellanox.com> References: <1516197093-20699-1-git-send-email-yishaih@mellanox.com> Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Feras Daoud Add a direct verb that translates device timestamps from HCA core clock units to nanoseconds using the device clock info. Signed-off-by: Feras Daoud Signed-off-by: Eitan Rabin Reviewed-by: Yishai Hadas --- providers/mlx5/man/CMakeLists.txt | 1 + providers/mlx5/man/mlx5dv_ts_to_ns.3 | 35 +++++++++++++++++++++++++++++++ providers/mlx5/mlx5dv.h | 40 ++++++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 providers/mlx5/man/mlx5dv_ts_to_ns.3 diff --git a/providers/mlx5/man/CMakeLists.txt b/providers/mlx5/man/CMakeLists.txt index 6ce94a9..876b6fc 100644 --- a/providers/mlx5/man/CMakeLists.txt +++ b/providers/mlx5/man/CMakeLists.txt @@ -2,5 +2,6 @@ rdma_man_pages( mlx5dv_get_clock_info.3 mlx5dv_init_obj.3 mlx5dv_query_device.3 + mlx5dv_ts_to_ns.3 mlx5dv.7 ) diff --git a/providers/mlx5/man/mlx5dv_ts_to_ns.3 b/providers/mlx5/man/mlx5dv_ts_to_ns.3 new file mode 100644 index 0000000..197b195 --- /dev/null +++ b/providers/mlx5/man/mlx5dv_ts_to_ns.3 @@ -0,0 +1,35 @@ +.\" -*- nroff -*- +.\" Licensed under the OpenIB.org (MIT) - See COPYING.md +.\" +.TH MLX5DV_TS_TO_NS 3 2017-11-08 1.0.0 +.SH "NAME" +mlx5dv_ts_to_ns \- Convert device timestamp from HCA core clock units to +the corresponding nanosecond counts +.SH "SYNOPSIS" +.nf +.B #include +.sp +.BI "uint64_t mlx5dv_ts_to_ns(struct mlx5dv_clock_info *clock_info, +.BI " uint64_t device_timestamp); +.fi +.SH "DESCRIPTION" +.B mlx5dv_ts_to_ns(3) +Converts a host byte order +.I device_timestamp +from HCA core clock units into the corresponding nanosecond wallclock time. +.PP +\fBstruct mlx5dv_clock_info\fR can be retrieved using \fBmlx5dv_get_clock_info(3)\fR. +.PP +The greater the difference between the device reporting a timestamp and the last +mlx5dv_clock_info update, the greater the inaccuracy of the clock time conversion. + +.fi +.SH "RETURN VALUE" +Timestamp in nanoseconds +.SH "SEE ALSO" +.BR mlx5dv (7), +.BR mlx5dv_get_clock_info (3), +.BR mlx5dv_query_device (3) +.SH "AUTHORS" +.TP +Feras Daoud diff --git a/providers/mlx5/mlx5dv.h b/providers/mlx5/mlx5dv.h index 2447517..2a4a823 100644 --- a/providers/mlx5/mlx5dv.h +++ b/providers/mlx5/mlx5dv.h @@ -811,4 +811,44 @@ struct mlx5dv_clock_info { int mlx5dv_get_clock_info(struct ibv_context *context, struct mlx5dv_clock_info *clock_info); +/* + * Translate device timestamp to nano-sec + * + * Input: + * clock_info - clock info to be filled + * device_timestamp - timestamp to translate + * + * Return: nano-sec + */ +static inline uint64_t mlx5dv_ts_to_ns(struct mlx5dv_clock_info *clock_info, + uint64_t device_timestamp) +{ + uint64_t delta, nsec; + + /* + * device_timestamp & cycles are the free running 'mask' bit counters + * from the hardware hca_core_clock clock. + */ + delta = (device_timestamp - clock_info->last_cycles) & clock_info->mask; + nsec = clock_info->nsec; + + /* + * Guess if the device_timestamp is more recent than + * clock_info->last_cycles, if not (too far in the future) treat + * it as old time stamp. This will break every max_clock_info_update_nsec. + */ + + if (delta > clock_info->mask / 2) { + delta = (clock_info->last_cycles - device_timestamp) & + clock_info->mask; + nsec -= ((delta * clock_info->mult) - clock_info->frac) >> + clock_info->shift; + } else { + nsec += ((delta * clock_info->mult) + clock_info->frac) >> + clock_info->shift; + } + + return nsec; +} + #endif /* _MLX5DV_H_ */