[OPW,kernel] Staging: lustre: lnet: lnet: Better cookie gen
diff mbox

Message ID 20141030212220.GA5698@localhost
State New, archived
Headers show

Commit Message

Tina Ruchandani Oct. 30, 2014, 9:22 p.m. UTC
api-ni.c uses do_gettimeofday to get a 'cookie' or timestamp.
This patch replaces it with ktime_get_ns for the following reasons:
1. ktime_get_ns returns a __u64 which is safer than 'struct timeval'
which will overflow on 32-bit systems in year 2038 and beyond.
2. Improved resolution: nsecs instead of usecs.
3. Reduced compute: ktime_get_ns is faster than the multiply/add
   combination used in this function

Signed-off-by: Tina Ruchandani <ruchandani.tina@gmail.com>
Suggested-by: Arnd Bergmann <arnd@arndb.de>
---
 drivers/staging/lustre/lnet/lnet/api-ni.c | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

Comments

Arnd Bergmann Oct. 30, 2014, 9:29 p.m. UTC | #1
On Thursday 30 October 2014 14:22:20 Tina Ruchandani wrote:
> +       __u64 cookie;
> +
> +       cookie = ktime_get_ns();
>         return cookie;

You can fold these four lines into one, other wise this looks like a
great cleanup. Note that in general, we use u64 rather than __u64 for
kernel-internal declarations. The __u64 syntax is meant for stuff that
gets passed to user space.

	Arnd

Patch
diff mbox

diff --git a/drivers/staging/lustre/lnet/lnet/api-ni.c b/drivers/staging/lustre/lnet/lnet/api-ni.c
index 60bc2ae..c6e6748 100644
--- a/drivers/staging/lustre/lnet/lnet/api-ni.c
+++ b/drivers/staging/lustre/lnet/lnet/api-ni.c
@@ -37,6 +37,7 @@ 
 #define DEBUG_SUBSYSTEM S_LNET
 #include "../../include/linux/lnet/lib-lnet.h"
 #include <linux/log2.h>
+#include <linux/ktime.h>
 
 #define D_LNI D_CONSOLE
 
@@ -417,16 +418,11 @@  static __u64
 lnet_create_interface_cookie(void)
 {
 	/* NB the interface cookie in wire handles guards against delayed
-	 * replies and ACKs appearing valid after reboot. Initialisation time,
-	 * even if it's only implemented to millisecond resolution is probably
-	 * easily good enough. */
-	struct timeval tv;
-	__u64	  cookie;
-
-	do_gettimeofday(&tv);
-	cookie = tv.tv_sec;
-	cookie *= 1000000;
-	cookie += tv.tv_usec;
+	 * replies and ACKs appearing valid after reboot.
+	 */
+	__u64 cookie;
+
+	cookie = ktime_get_ns();
 	return cookie;
 }