firewire: Replace timeval with timespec64
PATCH v2 1/1 firewire: Replace timeval with timespec64
32 bit systems using 'struct timeval' will break in the year 2038, so we replace the code appropriately. However, this driver is not broken in 2038 since we are using only the microseconds portion of the current time.
This patch replaces timeval with timespec64.
---
Changes in v2:
-Replaced timespec with timspec64
-Modified commit message
-Used ktime_get_real_ts64() instead of getnstimeofday64()
drivers/firewire/nosy.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/firewire/nosy.c +6 -4
@@ -33,6 +33,7 @@#include <linux/sched.h> /* required for linux/wait.h */ #include <linux/slab.h> #include <linux/spinlock.h> +#include <linux/time64.h> #include <linux/timex.h> #include <linux/uaccess.h> #include <linux/wait.h>
@@ -413,17 +414,18 @@ static void packet_irq_handler(struct pcilynx *lynx) {struct client *client; -u32 tcode_mask, tcode; +u32 tcode_mask, tcode, timestamp;size_t length; -struct timeval tv; +struct timespec64 ts64;/* FIXME: Also report rcv_speed. */ length =__le32_to_cpu (lynx->rcv_pcl->pcl_status) &0x00001fff ; tcode =__le32_to_cpu (lynx->rcv_buffer[1 ]) >>4 &0xf ; -do_gettimeofday (&tv); - lynx->rcv_buffer[0 ] = (__force __le32 )tv.tv_usec; +ktime_get_real_ts64 (&ts64); + timestamp = ts64.tv_nsec /NSEC_PER_USEC ; + lynx->rcv_buffer[0 ] = (__force __le32 )timestamp;if (length ==PHY_PACKET_SIZE ) tcode_mask =1 <<TCODE_PHY_PACKET ;
Signature · 1 line
1.9.1
Quoted 8 lines · On Thursday 22 October 2015 04:05:00 Amitoj Kaur Chawla wrote:
32 bit systems using 'struct timeval' will break in the year 2038, so we replace the code appropriately. However, this driver is not broken in 2038 since we are using only the microseconds portion of the current time.
This patch replaces timeval with timespec64.
Signed-off-by Amitoj Kaur Chawla <[email protected]>
(adding the y2038 mailing list as well)
Quoted 44 lines
Changes in v2:
-Replaced timespec with timspec64
-Modified commit message
-Usedktime_get_real_ts64()instead ofgetnstimeofday64()drivers/firewire/nosy.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)drivers/firewire/nosy.c +6
-4@@ -33,6 +33,7 @@#include <linux/sched.h> /* required for linux/wait.h */ #include <linux/slab.h> #include <linux/spinlock.h> +#include <linux/time64.h> #include <linux/timex.h> #include <linux/uaccess.h> #include <linux/wait.h> @@ -413,17 +414,18 @@ static void packet_irq_handler(struct pcilynx *lynx) {struct client *client; -u32 tcode_mask, tcode; +u32 tcode_mask, tcode, timestamp;size_t length; -struct timeval tv; +struct timespec64 ts64;/* FIXME: Also report rcv_speed. */ length =__le32_to_cpu (lynx->rcv_pcl->pcl_status) &0x00001fff ; tcode =__le32_to_cpu (lynx->rcv_buffer[1 ]) >>4 &0xf ; -do_gettimeofday (&tv); - lynx->rcv_buffer[0 ] = (__force __le32 )tv.tv_usec; +ktime_get_real_ts64 (&ts64); + timestamp = ts64.tv_nsec /NSEC_PER_USEC ; + lynx->rcv_buffer[0 ] = (__force __le32 )timestamp;if (length ==PHY_PACKET_SIZE ) tcode_mask =1 <<TCODE_PHY_PACKET ;
Quoted 1 line · On Oct 22 Arnd Bergmann wrote:
On Thursday 22 October 2015 04:05:00 Amitoj Kaur Chawla wrote:
[...]
Quoted 8 lines
Reviewed-by Arnd Bergmann <[email protected]>(adding the y2038 mailing list as well)
Quoted 4 lines
Changes in v2:
-Replaced timespec with timspec64
-Modified commit message
-Usedktime_get_real_ts64()instead ofgetnstimeofday64()
[...]
Quoted 2 lines
Quoted 2 lines
drivers/firewire/nosy.c +0
-0
[...]
Quoted 2 lines
Quoted 2 lines
drivers/firewire/nosy.c +0
-0@@ -413,17 +414,18 @@ static void packet_irq_handler(struct pcilynx *lynx)
[...]
Quoted 5 lines
drivers/firewire/nosy.c static void · line 428
Quoted 5 lines
drivers/firewire/nosy.c +3
-2-do_gettimeofday (&tv); - lynx->rcv_buffer[0 ] = (__force __le32 )tv.tv_usec; +ktime_get_real_ts64 (&ts64); + timestamp = ts64.tv_nsec /NSEC_PER_USEC ; + lynx->rcv_buffer[0 ] = (__force __le32 )timestamp;
Looks fine to me, but I have a question. It was possibly already discussed at patch v1, though that was apparently not posted to an open list.
include/linux/timekeeping.h says:
#define ktime_get_real_ts64(ts) getnstimeofday64(ts)
kernel/time/timekeeping.c says:
/**
* do_gettimeofday - Returns the time of day in a timeval
* @tv: pointer to the timeval to be set
*
* NOTE: Users should be converted to using getnstimeofday() */
So what is the reason for calling ktime_get_real_ts64() instead of getnstimeofday[64]()?
PS, note to self:
Independently of this patch, I need to check whether CLOCK_REALTIME was really the right clock here, in contrast to CLOCK_MONOTONIC.
Signature · 3 lines
Stefan Richter -=====-===== =-=- =-==- http://arcgraph.de/sr/
Quoted 15 lines · On Thursday 22 October 2015 15:07:50 Stefan Richter wrote:
Looks fine to me, but I have a question. It was possibly already discussed at patch v1, though that was apparently not posted to an open list.
include/linux/timekeeping.hsays:
#definektime_get_real_ts64(ts)getnstimeofday64(ts)
kernel/time/timekeeping.csays:
/**
*do_gettimeofday- Returns the time of day in a timeval
* @tv: pointer to the timeval to be set
*
* NOTE: Users should be converted to usinggetnstimeofday()*/
Quoted 2 lines
So what is the reason for calling
ktime_get_real_ts64()instead of getnstimeofday[64]()?
They are identical in behavior, I don't know exactly why we have two but I'm advocating the move to ktime_* functions for consistency with ktime_get_seconds(), ktime_get_ns() and ktime_get() that don't have another alias. Once all users of the old getnstimeofday() and do_gettimeofday() have been converted, I might change over all users of getnstimeofday64() to ktime_get_real_ts64() and remove all of the get*timeofday*() family.
Quoted 3 lines
PS, note to self:
Independently of this patch, I need to check whetherCLOCK_REALTIMEwas really the right clock here, in contrast toCLOCK_MONOTONIC.
Yes, good idea. I usually recommend changing to montonic time (ktime_get_ts64()) in the same patch, but in this particular case that would have been a user-visible change that we should not mix in to a single commit.
Arnd
Quoted 6 lines · On Oct 22 Arnd Bergmann wrote:
Quoted 5 lines · On Thursday 22 October 2015 04:05:00 Amitoj Kaur Chawla wrote:
32 bit systems using 'struct timeval' will break in the year 2038, so we replace the code appropriately. However, this driver is not broken in 2038 since we are using only the microseconds portion of the current time.
Quoted 7 lines
Quoted 3 lines
This patch replaces timeval with timespec64.
Signed-off-by Amitoj Kaur Chawla <[email protected]>Reviewed-by Arnd Bergmann <[email protected]>(adding the y2038 mailing list as well)
Committed to linux1394.git.
Arnd, do you have special y2038 plans that make it desirable to have this merged before v4.4? Otherwise I would submit it for v4.5-rc1.
Quoted 45 lines
Quoted 44 lines
Changes in v2:
-Replaced timespec with timspec64
-Modified commit message
-Usedktime_get_real_ts64()instead ofgetnstimeofday64()drivers/firewire/nosy.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)drivers/firewire/nosy.c +6
-4@@ -33,6 +33,7 @@#include <linux/sched.h> /* required for linux/wait.h */ #include <linux/slab.h> #include <linux/spinlock.h> +#include <linux/time64.h> #include <linux/timex.h> #include <linux/uaccess.h> #include <linux/wait.h> @@ -413,17 +414,18 @@ static void packet_irq_handler(struct pcilynx *lynx) {struct client *client; -u32 tcode_mask, tcode; +u32 tcode_mask, tcode, timestamp;size_t length; -struct timeval tv; +struct timespec64 ts64;/* FIXME: Also report rcv_speed. */ length =__le32_to_cpu (lynx->rcv_pcl->pcl_status) &0x00001fff ; tcode =__le32_to_cpu (lynx->rcv_buffer[1 ]) >>4 &0xf ; -do_gettimeofday (&tv); - lynx->rcv_buffer[0 ] = (__force __le32 )tv.tv_usec; +ktime_get_real_ts64 (&ts64); + timestamp = ts64.tv_nsec /NSEC_PER_USEC ; + lynx->rcv_buffer[0 ] = (__force __le32 )timestamp;if (length ==PHY_PACKET_SIZE ) tcode_mask =1 <<TCODE_PHY_PACKET ;
Signature · 3 lines
Stefan Richter -=====-===== =-== --=-= http://arcgraph.de/sr/
Quoted 11 lines · On Thursday 05 November 2015 14:34:48 Stefan Richter wrote:
Quoted 10 lines · On Oct 22 Arnd Bergmann wrote:
Quoted 8 lines · On Thursday 22 October 2015 04:05:00 Amitoj Kaur Chawla wrote:
32 bit systems using 'struct timeval' will break in the year 2038, so we replace the code appropriately. However, this driver is not broken in 2038 since we are using only the microseconds portion of the current time.
This patch replaces timeval with timespec64.
Signed-off-by Amitoj Kaur Chawla <[email protected]>
Quoted 7 lines
Quoted 3 lines
Reviewed-by Arnd Bergmann <[email protected]>(adding the y2038 mailing list as well)
Committed to linux1394.git.
Arnd, do you have special y2038 plans that make it desirable to have this merged before v4.4? Otherwise I would submit it for v4.5-rc1.
4.5-rc1 is fine.
Arnd