[PATCH v3] staging: android: Replace timeval with timespec64

47 views
Skip to first unread message

Tapasweni Pathak

unread,
Oct 21, 2014, 10:30:06 PM10/21/14
to ar...@arndb.de, opw-k...@googlegroups.com, tapaswe...@gmail.com
'timeval' is used to print timestamps in seconds and millisecond.

32-bit systems using 'struct timeval' will break in the year 2038,
So we have to replace that code with more appropriate types.

This patch changes the android driver to use timespec64.
Since this is a staging driver and the output is only used for a
debugfs file, it is fine to slightly change the output and
use nanoseconds instead. ktime_to_timespec64, is used which will return
seconds and nanoseconds.

Signed-off-by: Tapasweni Pathak <tapaswe...@gmail.com>
---
Changes in v3:
Used timespec64 to replace timeval instead of ktime_t
Changed commit message and subject accordingly.

Changes in v2:
Corrected commit message.
used lld instead of llu.

drivers/staging/android/sync_debug.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/android/sync_debug.c b/drivers/staging/android/sync_debug.c
index 257fc91..9af56fd 100644
--- a/drivers/staging/android/sync_debug.c
+++ b/drivers/staging/android/sync_debug.c
@@ -25,6 +25,7 @@
#include <linux/slab.h>
#include <linux/uaccess.h>
#include <linux/anon_inodes.h>
+#include <linux/time64.h>
#include "sync.h"

#ifdef CONFIG_DEBUG_FS
@@ -95,9 +96,9 @@ static void sync_print_pt(struct seq_file *s, struct sync_pt *pt, bool fence)
sync_status_str(status));

if (status <= 0) {
- struct timeval tv = ktime_to_timeval(pt->base.timestamp);
+ struct timespec64 ts64 = ktime_to_timespec64(pt->base.timestamp);

- seq_printf(s, "@%ld.%06ld", tv.tv_sec, tv.tv_usec);
+ seq_printf(s, "@%lld.%09ld", ts64.tv_sec, ts64.tv_nsec);
}

if (parent->ops->timeline_value_str &&
--
1.7.9.5

Arnd Bergmann

unread,
Oct 22, 2014, 3:00:46 AM10/22/14
to Tapasweni Pathak, opw-k...@googlegroups.com
On Wednesday 22 October 2014 07:59:58 Tapasweni Pathak wrote:
> 'timeval' is used to print timestamps in seconds and millisecond.
>
> 32-bit systems using 'struct timeval' will break in the year 2038,
> So we have to replace that code with more appropriate types.
>
> This patch changes the android driver to use timespec64.
> Since this is a staging driver and the output is only used for a
> debugfs file, it is fine to slightly change the output and
> use nanoseconds instead. ktime_to_timespec64, is used which will return
> seconds and nanoseconds.
>
> Signed-off-by: Tapasweni Pathak <tapaswe...@gmail.com>
>

Reviewed-by: Arnd Bergmann <ar...@arndb.de>

Tapasweni Pathak

unread,
Oct 25, 2014, 10:58:45 PM10/25/14
to opw-k...@googlegroups.com, tapaswe...@gmail.com
'timeval' is used to print timestamps in seconds and millisecond.

32-bit systems using 'struct timeval' will break in the year 2038,
So we have to replace that code with more appropriate types.

This patch changes the android driver to use timespec64.
Since this is a staging driver and the output is only used for a
debugfs file, it is fine to slightly change the output and
use nanoseconds instead. ktime_to_timespec64, is used which will return
seconds and nanoseconds.

Signed-off-by: Tapasweni Pathak <tapaswe...@gmail.com>
---
Changes in v4:
Typecast ts64.tv_sec to s64, to make it long long int type and not
__kernel_time_t.

Changes in v3:
Used timespec64 to replace timeval instead of ktime_t
Changed commit message and subject accordingly.

Changes in v2:
Corrected commit message.
used lld instead of llu.

drivers/staging/android/sync_debug.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/android/sync_debug.c b/drivers/staging/android/sync_debug.c
index 257fc91..1532a86 100644
--- a/drivers/staging/android/sync_debug.c
+++ b/drivers/staging/android/sync_debug.c
@@ -25,6 +25,7 @@
#include <linux/slab.h>
#include <linux/uaccess.h>
#include <linux/anon_inodes.h>
+#include <linux/time64.h>
#include "sync.h"

#ifdef CONFIG_DEBUG_FS
@@ -95,9 +96,9 @@ static void sync_print_pt(struct seq_file *s, struct sync_pt *pt, bool fence)
sync_status_str(status));

if (status <= 0) {
- struct timeval tv = ktime_to_timeval(pt->base.timestamp);
+ struct timespec64 ts64 = ktime_to_timespec64(pt->base.timestamp);

- seq_printf(s, "@%ld.%06ld", tv.tv_sec, tv.tv_usec);
+ seq_printf(s, "@%lld.%09ld", (s64)ts64.tv_sec, ts64.tv_nsec);

Tapasweni Pathak

unread,
Oct 26, 2014, 9:50:28 AM10/26/14
to ar...@arndb.de, opw-k...@googlegroups.com, tapaswe...@gmail.com

Arnd Bergmann

unread,
Oct 26, 2014, 12:49:32 PM10/26/14
to opw-k...@googlegroups.com, Tapasweni Pathak
On Sunday 26 October 2014 19:20:16 Tapasweni Pathak wrote:
> 'timeval' is used to print timestamps in seconds and millisecond.
>
> 32-bit systems using 'struct timeval' will break in the year 2038,
> So we have to replace that code with more appropriate types.
>
> This patch changes the android driver to use timespec64.
> Since this is a staging driver and the output is only used for a
> debugfs file, it is fine to slightly change the output and
> use nanoseconds instead. ktime_to_timespec64, is used which will return
> seconds and nanoseconds.
>
> Signed-off-by: Tapasweni Pathak <tapaswe...@gmail.com>
>

Reviewed-by: Arnd Bergmann <ar...@arndb.de>

I assume this time you managed to build-test it first?

Tapasweni Pathak

unread,
Oct 26, 2014, 12:50:55 PM10/26/14
to Arnd Bergmann, opw-kernel
Yes.

Tapasweni Pathak

unread,
Oct 26, 2014, 12:52:28 PM10/26/14
to Arnd Bergmann, opw-kernel
For this one I did it before too, and did not got the warning. 

Arnd Bergmann

unread,
Oct 26, 2014, 2:52:49 PM10/26/14
to Tapasweni Pathak, opw-kernel
Ah right, the warning only happened on 64-bit builds, not on 32-bit
builds.

Arnd
Reply all
Reply to author
Forward
0 new messages