Skip to contentSkip to conversation

openvswitch: use ktime_get_ts64() instead of ktime_get_ts()

PATCH Applied Arnd Bergmann 3 participants 4 messages Nov 27, 2017 – Nov 30, 2017

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 openvswitch: use ktime_get_ts64() instead of ktime_get_ts()

timespec is deprecated because of the y2038 overflow, so let's convert this one to ktime_get_ts64(). The code is already safe even on 32-bit architectures, since it uses monotonic times. On 64-bit architectures, nothing changes, while on 32-bit architectures this avoids one type conversion.

---
 net/openvswitch/flow.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
net/openvswitch/flow.c +3 -3
index dbe2379329c5..76d050aba7a4 100644
@@ -56,12 +56,12 @@
 
 u64 ovs_flow_used_time(unsigned long flow_jiffies)
 {
-	struct timespec cur_ts;
+	struct timespec64 cur_ts;
 	u64 cur_ms, idle_ms;
 
-	ktime_get_ts(&cur_ts);
+	ktime_get_ts64(&cur_ts);
 	idle_ms = jiffies_to_msecs(jiffies - flow_jiffies);
-	cur_ms = (u64)cur_ts.tv_sec * MSEC_PER_SEC +
+	cur_ms = (u64)(u32)cur_ts.tv_sec * MSEC_PER_SEC +
 		 cur_ts.tv_nsec / NSEC_PER_MSEC;
 
 	return cur_ms - idle_ms;
Signature · 6 lines
2.9.0

_______________________________________________
Y2038 mailing list
[email protected]
https://lists.linaro.org/mailman/listinfo/y2038
#1 lore raw
Quoted 18 lines · Arnd Bergmann

timespec is deprecated because of the y2038 overflow, so let's convert this one to ktime_get_ts64(). The code is already safe even on 32-bit architectures, since it uses monotonic times. On 64-bit architectures, nothing changes, while on 32-bit architectures this avoids one type conversion.

---
 net/openvswitch/flow.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
net/openvswitch/flow.c +0 -0
index dbe2379329c5..76d050aba7a4 100644
@@ -56,12 +56,12 @@
 
 u64 ovs_flow_used_time(unsigned long flow_jiffies)

net/openvswitch/flow.c line 64

Quoted 10 lines
net/openvswitch/flow.c +3 -3
 {
-       struct timespec cur_ts;
+       struct timespec64 cur_ts;
        u64 cur_ms, idle_ms;
 
-       ktime_get_ts(&cur_ts);
+       ktime_get_ts64(&cur_ts);
        idle_ms = jiffies_to_msecs(jiffies - flow_jiffies);
-       cur_ms = (u64)cur_ts.tv_sec * MSEC_PER_SEC +
+       cur_ms = (u64)(u32)cur_ts.tv_sec * MSEC_PER_SEC +

I am not sure why is tv_sec converted to u32.

Quoted 6 lines
net/openvswitch/flow.c +0 -1
                 cur_ts.tv_nsec / NSEC_PER_MSEC;
 
        return cur_ms - idle_ms;
--

2.9.0

#2 lore raw
Quoted 24 lines · Pravin Shelar
Quoted 23 lines · Arnd Bergmann

timespec is deprecated because of the y2038 overflow, so let's convert this one to ktime_get_ts64(). The code is already safe even on 32-bit architectures, since it uses monotonic times. On 64-bit architectures, nothing changes, while on 32-bit architectures this avoids one type conversion.

---
 net/openvswitch/flow.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
net/openvswitch/flow.c +1 -1
index dbe2379329c5..76d050aba7a4 100644
@@ -56,12 +56,12 @@
 
 u64 ovs_flow_used_time(unsigned long flow_jiffies)
 {
-       struct timespec cur_ts;
+       struct timespec64 cur_ts;
        u64 cur_ms, idle_ms;
 
Quoted 7 lines

net/openvswitch/flow.c line 64

Quoted 5 lines
net/openvswitch/flow.c +2 -2
-       ktime_get_ts(&cur_ts);
+       ktime_get_ts64(&cur_ts);
        idle_ms = jiffies_to_msecs(jiffies - flow_jiffies);
-       cur_ms = (u64)cur_ts.tv_sec * MSEC_PER_SEC +
+       cur_ms = (u64)(u32)cur_ts.tv_sec * MSEC_PER_SEC +

I am not sure why is tv_sec converted to u32.

It was a micro-optimization that I did to turn a 's64 * constant -> s64' operation into a cheaper 's32 * constant -> s64' operation. If you prefer, I can sent it again with a comment, or drop the two casts.

Arnd

maintainer Applied
#3 lore raw
In reply to Arnd Bergmann

From: Arnd Bergmann <[email protected]>
Date: Mon, 27 Nov 2017 12:41:38 +0100

Quoted 7 lines

timespec is deprecated because of the y2038 overflow, so let's convert this one to ktime_get_ts64(). The code is already safe even on 32-bit architectures, since it uses monotonic times. On 64-bit architectures, nothing changes, while on 32-bit architectures this avoids one type conversion.

Applied.