Re: [Y2038] [PATCH v2] aoe: Use 64-bit timestamp in frame

2016-06-16 Thread Tina Ruchandani
> What's the target for this patch, Tina?  Is there a FAQ or something I
> can read to see how the y2038 project generally operates?
>
> --
>   Ed

Hi Ed,

A dedicated page on this project is available on Linux Kernel Newbies where
you can find updated
info on drivers,filesystems,systemcalls and other portions of kernel
affected by y2038.
(http://kernelnewbies.org/y2038)
___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


Re: [Y2038] [PATCH v2] aoe: Use 64-bit timestamp in frame

2016-05-30 Thread Tina Ruchandani
>
> ... But after reviewing the previous discussion I think I should
> try to find people with 32-bit systems who can tell me whether they
> see a performance regression.
>
> I'll do that and try to get an answer soon.
>

Please consider this patch as a first-cut draft attempt to get the
ball rolling on this again. It would be nice to take this to
completion, given all the effort you and Arnd put into the discussion
last here. I didn't get the chance to discuss this with Arnd before
sending it out, and its likely that what I implemented is different
from and sub-par compared to what he had mind. The discussion last
year didn't seem to mention the need for a 32-bit divide, I ended up
needing it here.
Also, Arnd has some efficient interfaces in mind - introducing
light-weight ktime_get_us() perhaps. I don't know how that would be
done, and hence I tried the other approach he had suggested.
___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [PATCH v2] aoe: Use 64-bit timestamp in frame

2016-05-30 Thread Tina Ruchandani
'struct frame' uses two variables to store the sent timestamp - 'struct
timeval' and jiffies. jiffies is used to avoid discrepancies caused by
updates to system time. 'struct timeval' uses 32-bit representation for
seconds which will overflow in year 2038.

This patch does the following:
- Replace the use of 'struct timeval' and jiffies with struct timespec64,
which provides a 64-bit seconds timestamp and is year 2038 safe.
- timespec64 provides both long range (like jiffies) and high resolution
(like timeval). Using monotonic time (ktime_get_ts64) instead of wall-clock
time prevents any discrepancies caused by updates to system time.

The previous attempt at this patch and related discussion is here:
https://lists.linaro.org/pipermail/y2038/2015-May/000245.html
As noted previously, the existing code is 2038-safe, as it only uses a
delta instead of absolute timestamps. However, this patch is part of a
larger attempt to remove _all_ instances of 32-bit timekeeping from the
kernel (time_t, struct timeval and struct timespec) since we do not know
which of the many instances of their usage are buggy.

It is worth noting that there may be a slight performance penalty, due
to timespec64 using nanoseconds instead of microseconds. The tsince_hr
function contains a 32-bit multiply just like the existing code, but now
it also has a 32-bit divide.

Suggested-by: Arnd Bergmann 
Signed-off-by: Tina Ruchandani 

--
Changes in v2:
- Change use of ktime_t to timespec64 to avoid expensive 64-bit
  divide in ktime_us_delta
---
 drivers/block/aoe/aoe.h|  3 +--
 drivers/block/aoe/aoecmd.c | 38 +-
 2 files changed, 10 insertions(+), 31 deletions(-)

diff --git a/drivers/block/aoe/aoe.h b/drivers/block/aoe/aoe.h
index 9220f8e..d587806 100644
--- a/drivers/block/aoe/aoe.h
+++ b/drivers/block/aoe/aoe.h
@@ -112,8 +112,7 @@ enum frame_flags {
 struct frame {
struct list_head head;
u32 tag;
-   struct timeval sent;/* high-res time packet was sent */
-   u32 sent_jiffs; /* low-res jiffies-based sent time */
+   struct timespec64 sent;
ulong waited;
ulong waited_total;
struct aoetgt *t;   /* parent target I belong to */
diff --git a/drivers/block/aoe/aoecmd.c b/drivers/block/aoe/aoecmd.c
index d597e43..4df542f 100644
--- a/drivers/block/aoe/aoecmd.c
+++ b/drivers/block/aoe/aoecmd.c
@@ -398,8 +398,7 @@ aoecmd_ata_rw(struct aoedev *d)

skb = skb_clone(f->skb, GFP_ATOMIC);
if (skb) {
-   do_gettimeofday(&f->sent);
-   f->sent_jiffs = (u32) jiffies;
+   ktime_get_ts64(&f->sent);
__skb_queue_head_init(&queue);
__skb_queue_tail(&queue, skb);
aoenet_xmit(&queue);
@@ -489,8 +488,7 @@ resend(struct aoedev *d, struct frame *f)
skb = skb_clone(skb, GFP_ATOMIC);
if (skb == NULL)
return;
-   do_gettimeofday(&f->sent);
-   f->sent_jiffs = (u32) jiffies;
+   ktime_get_ts64(&f->sent);
__skb_queue_head_init(&queue);
__skb_queue_tail(&queue, skb);
aoenet_xmit(&queue);
@@ -499,32 +497,17 @@ resend(struct aoedev *d, struct frame *f)
 static int
 tsince_hr(struct frame *f)
 {
-   struct timeval now;
+   struct timespec64 now, delta;
int n;

-   do_gettimeofday(&now);
-   n = now.tv_usec - f->sent.tv_usec;
-   n += (now.tv_sec - f->sent.tv_sec) * USEC_PER_SEC;
+   ktime_get_ts64(&now);
+   delta = timespec64_sub(now, f->sent);
+   n =  ((int32_t) (delta.tv_sec)) * USEC_PER_SEC +
+   delta.tv_nsec / NSEC_PER_USEC;

if (n < 0)
n = -n;

-   /* For relatively long periods, use jiffies to avoid
-* discrepancies caused by updates to the system time.
-*
-* On system with HZ of 1000, 32-bits is over 49 days
-* worth of jiffies, or over 71 minutes worth of usecs.
-*
-* Jiffies overflow is handled by subtraction of unsigned ints:
-* (gdb) print (unsigned) 2 - (unsigned) 0xfffe
-* $3 = 4
-* (gdb)
-*/
-   if (n > USEC_PER_SEC / 4) {
-   n = ((u32) jiffies) - f->sent_jiffs;
-   n *= USEC_PER_SEC / HZ;
-   }
-
return n;
 }

@@ -589,7 +572,6 @@ reassign_frame(struct frame *f)
nf->waited = 0;
nf->waited_total = f->waited_total;
nf->sent = f->sent;
-   nf->sent_jiffs = f->sent_jiffs;
f->skb = skb;

return nf;
@@ -633,8 +615,7 @@ probe(struct aoetgt *t)

skb = skb_clone(f->skb, GFP_ATOMIC);
if (skb) {
-   do_gettimeofday(&f->sent);
-   f->sent_jiffs = (u32) jiffies;
+   ktime_get_ts64(&f->sent);
__skb_queu

Re: [Y2038] [PATCH v2] drm/msm: Use 64-bit timekeeping

2016-04-21 Thread Tina Ruchandani
>> which only does one 64-bit division, and it's one that we can probably
>> optimize out in the future (we can check in ktime_ms_delta whether the
>> difference is more than 2^32 nanoseconds as the fast path).

It looks like ktime_divns already has that optimization for 32-bit divisor,
so your solution should avoid the 64-bit division.
___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


Re: [Y2038] [PATCH v2] drm/msm: Use 64-bit timekeeping

2016-04-21 Thread Tina Ruchandani
>
> How about
>
> remaining_jiffies = msecs_to_jiffies(ktime_ms_delta(*timeout, now));
>
> which only does one 64-bit division, and it's one that we can probably
> optimize out in the future (we can check in ktime_ms_delta whether the
> difference is more than 2^32 nanoseconds as the fast path).

Hi Arnd,
I had thought about that, but discard that approach being confused
about the truncation.
ktime_ms_delta returns s64 and msecs_to_jiffies will truncate that
input to int. However,
I now realize that for the msecs value to be greater than 32 bits, the
time delta has to be
>= ((2^29)/(60*60*24*365)) or >= 17 years. So your solution is safe.
If that sounds ok, I will send out a v3.
___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [PATCH v2] drm/msm: Use 64-bit timekeeping

2016-04-13 Thread Tina Ruchandani
'struct timespec' uses a 32-bit seconds which will overflow in year
2038 and beyond. This patch replaces timespec with timespec64. The
code is correct as is - the patch is merely part of a larger attempt
to remove all 32-bit timekeeping variables (timespec, timeval, time_t)
from the kernel.

Signed-off-by: Tina Ruchandani 
-- 
Changes in v2:
 Fix checkpatch warning
---
 drivers/gpu/drm/msm/msm_drv.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/msm/msm_drv.c b/drivers/gpu/drm/msm/msm_drv.c
index c03b967..59c1948 100644
--- a/drivers/gpu/drm/msm/msm_drv.c
+++ b/drivers/gpu/drm/msm/msm_drv.c
@@ -717,8 +717,9 @@ int msm_wait_fence(struct drm_device *dev, uint32_t fence,
remaining_jiffies = 0;
} else {
ktime_t rem = ktime_sub(*timeout, now);
-   struct timespec ts = ktime_to_timespec(rem);
-   remaining_jiffies = timespec_to_jiffies(&ts);
+   struct timespec64 ts = ktime_to_timespec64(rem);
+
+   remaining_jiffies = timespec64_to_jiffies(&ts);
}

if (interruptible)
--
2.8.0.rc3.226.g39d4020

___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [PATCH] drm/msm: Use 64-bit timekeeping

2016-04-13 Thread Tina Ruchandani
'struct timespec' uses a 32-bit seconds which will overflow in year
2038 and beyond. This patch replaces timespec with timespec64. The
code is correct as is - the patch is merely part of a larger attempt
to remove all 32-bit timekeeping variables (timespec, timeval, time_t)
from the kernel.

Signed-off-by: Tina Ruchandani 
---
 drivers/gpu/drm/msm/msm_drv.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/msm/msm_drv.c b/drivers/gpu/drm/msm/msm_drv.c
index c03b967..b095085 100644
--- a/drivers/gpu/drm/msm/msm_drv.c
+++ b/drivers/gpu/drm/msm/msm_drv.c
@@ -717,8 +717,8 @@ int msm_wait_fence(struct drm_device *dev, uint32_t fence,
remaining_jiffies = 0;
} else {
ktime_t rem = ktime_sub(*timeout, now);
-   struct timespec ts = ktime_to_timespec(rem);
-   remaining_jiffies = timespec_to_jiffies(&ts);
+   struct timespec64 ts = ktime_to_timespec64(rem);
+   remaining_jiffies = timespec64_to_jiffies(&ts);
}
 
if (interruptible)
-- 
2.8.0.rc3.226.g39d4020

___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [PATCH] drm/sti: Use 64-bit timestamps

2016-04-13 Thread Tina Ruchandani
'struct timespec' uses a 32-bit field for seconds, which
will overflow in year 2038 and beyond. This patch is part
of a larger attempt to remove instances of timeval, timespec
and time_t, all of which suffer from the y2038 issue, from the
kernel.

Signed-off-by: Tina Ruchandani 
---
 drivers/gpu/drm/sti/sti_plane.c | 16 +++-
 drivers/gpu/drm/sti/sti_plane.h |  2 +-
 2 files changed, 4 insertions(+), 14 deletions(-)

diff --git a/drivers/gpu/drm/sti/sti_plane.c b/drivers/gpu/drm/sti/sti_plane.c
index f10c98d..3b46899 100644
--- a/drivers/gpu/drm/sti/sti_plane.c
+++ b/drivers/gpu/drm/sti/sti_plane.c
@@ -45,25 +45,15 @@ const char *sti_plane_to_str(struct sti_plane *plane)

 #define STI_FPS_INTERVAL_MS 3000

-static int sti_plane_timespec_ms_diff(struct timespec lhs, struct timespec rhs)
-{
-   struct timespec tmp_ts = timespec_sub(lhs, rhs);
-   u64 tmp_ns = (u64)timespec_to_ns(&tmp_ts);
-
-   do_div(tmp_ns, NSEC_PER_MSEC);
-
-   return (u32)tmp_ns;
-}
-
 void sti_plane_update_fps(struct sti_plane *plane,
  bool new_frame,
  bool new_field)
 {
-   struct timespec now;
+   ktime_t now;
struct sti_fps_info *fps;
int fpks, fipks, ms_since_last, num_frames, num_fields;

-   getrawmonotonic(&now);
+   now = ktime_get();

/* Compute number of frame updates */
fps = &plane->fps_info;
@@ -76,7 +66,7 @@ void sti_plane_update_fps(struct sti_plane *plane,
return;

fps->curr_frame_counter++;
-   ms_since_last = sti_plane_timespec_ms_diff(now, fps->last_timestamp);
+   ms_since_last = ktime_to_ms(ktime_sub(now, fps->last_timestamp));
num_frames = fps->curr_frame_counter - fps->last_frame_counter;

if (num_frames <= 0  || ms_since_last < STI_FPS_INTERVAL_MS)
diff --git a/drivers/gpu/drm/sti/sti_plane.h b/drivers/gpu/drm/sti/sti_plane.h
index c50a3b9..0a64eb0 100644
--- a/drivers/gpu/drm/sti/sti_plane.h
+++ b/drivers/gpu/drm/sti/sti_plane.h
@@ -57,7 +57,7 @@ struct sti_fps_info {
unsigned int last_frame_counter;
unsigned int curr_field_counter;
unsigned int last_field_counter;
-   struct timespec last_timestamp;
+   ktime_t  last_timestamp;
char fps_str[FPS_LENGTH];
char fips_str[FPS_LENGTH];
 };
--
2.8.0.rc3.226.g39d4020

___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


Re: [Y2038] [PATCH, RESEND 3] qla2xxx: Remove use of 'struct timeval'

2016-04-13 Thread Tina Ruchandani
>
> Applied to 4.6/scsi-queue.

Hi Martin,
I am not seeing this patch in v4.6-rc3 in Linus's tree. Should I resend this?
Thanks,
Tina
___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [PATCH] mpt3sas: Remove usage of 'struct timeval'

2016-04-13 Thread Tina Ruchandani
'struct timeval' will have its tv_sec value overflow on 32-bit systems
in year 2038 and beyond. This patch replaces the use of struct timeval
for computing mpi_request.TimeStamp, and instead uses ktime_t which provides
64-bit seconds value. The timestamp computed remains unaffected (milliseconds
since Unix epoch).

Signed-off-by: Tina Ruchandani 
Reviewed-by: Arnd Bergmann 
---
 drivers/scsi/mpt3sas/mpt3sas_base.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c 
b/drivers/scsi/mpt3sas/mpt3sas_base.c
index 8c44b9c..326c152 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_base.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_base.c
@@ -57,6 +57,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 

@@ -4387,7 +4388,7 @@ _base_send_ioc_init(struct MPT3SAS_ADAPTER *ioc, int 
sleep_flag)
Mpi2IOCInitRequest_t mpi_request;
Mpi2IOCInitReply_t mpi_reply;
int i, r = 0;
-   struct timeval current_time;
+   ktime_t current_time;
u16 ioc_status;
u32 reply_post_free_array_sz = 0;
Mpi2IOCInitRDPQArrayEntry *reply_post_free_array = NULL;
@@ -4449,9 +4450,8 @@ _base_send_ioc_init(struct MPT3SAS_ADAPTER *ioc, int 
sleep_flag)
/* This time stamp specifies number of milliseconds
 * since epoch ~ midnight January 1, 1970.
 */
-   do_gettimeofday(¤t_time);
-   mpi_request.TimeStamp = cpu_to_le64((u64)current_time.tv_sec * 1000 +
-   (current_time.tv_usec / 1000));
+   current_time = ktime_get_real();
+   mpi_request.TimeStamp = cpu_to_le64(ktime_to_ms(current_time));

if (ioc->logging_level & MPT_DEBUG_INIT) {
__le32 *mfp;
--
2.8.0.rc3.226.g39d4020

___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [PATCH v3] prism54: isl_38xx: Replace 'struct timeval'

2016-04-13 Thread Tina Ruchandani
'struct timeval' uses a 32-bit seconds field which will overflow in
year 2038 and beyond. This patch is part of a larger effort to remove
all instances of 'struct timeval' from the kernel and replace them
with 64-bit timekeeping variables.
The patch also fixes the debug printf specifier to avoid the
seconds value being truncated.
The patch was build-tested / debugged by removing the
"if VERBOSE > SHOW_ERROR_MESSAGES" guards.

Signed-off-by: Tina Ruchandani 
Suggested-by: Arnd Bergmann 
--
Changes in v3:
 Fix commit message
Changes in v2:
 Changed printf specifier as suggested by Arnd Bergmann to
avoid truncation.
---
 drivers/net/wireless/intersil/prism54/isl_38xx.c | 35 
 1 file changed, 18 insertions(+), 17 deletions(-)

diff --git a/drivers/net/wireless/intersil/prism54/isl_38xx.c 
b/drivers/net/wireless/intersil/prism54/isl_38xx.c
index 333c1a2..6700387 100644
--- a/drivers/net/wireless/intersil/prism54/isl_38xx.c
+++ b/drivers/net/wireless/intersil/prism54/isl_38xx.c
@@ -19,6 +19,7 @@
 #include 
 #include 
 #include 
+#include 

 #include 
 #include 
@@ -113,7 +114,7 @@ isl38xx_trigger_device(int asleep, void __iomem 
*device_base)

 #if VERBOSE > SHOW_ERROR_MESSAGES
u32 counter = 0;
-   struct timeval current_time;
+   struct timespec64 current_ts64;
DEBUG(SHOW_FUNCTION_CALLS, "isl38xx trigger device\n");
 #endif

@@ -121,22 +122,22 @@ isl38xx_trigger_device(int asleep, void __iomem 
*device_base)
if (asleep) {
/* device is in powersave, trigger the device for wakeup */
 #if VERBOSE > SHOW_ERROR_MESSAGES
-   do_gettimeofday(¤t_time);
-   DEBUG(SHOW_TRACING, "%08li.%08li Device wakeup triggered\n",
- current_time.tv_sec, (long)current_time.tv_usec);
+   ktime_get_real_ts64(¤t_ts64);
+   DEBUG(SHOW_TRACING, "%lld.%09ld Device wakeup triggered\n",
+ (s64)current_ts64.tv_sec, current_ts64.tv_nsec);

-   DEBUG(SHOW_TRACING, "%08li.%08li Device register read %08x\n",
- current_time.tv_sec, (long)current_time.tv_usec,
+   DEBUG(SHOW_TRACING, "%lld.%09ld Device register read %08x\n",
+ (s64)current_ts64.tv_sec, current_ts64.tv_nsec,
  readl(device_base + ISL38XX_CTRL_STAT_REG));
 #endif

reg = readl(device_base + ISL38XX_INT_IDENT_REG);
if (reg == 0xabadface) {
 #if VERBOSE > SHOW_ERROR_MESSAGES
-   do_gettimeofday(¤t_time);
+   ktime_get_real_ts64(¤t_ts64);
DEBUG(SHOW_TRACING,
- "%08li.%08li Device register abadface\n",
- current_time.tv_sec, (long)current_time.tv_usec);
+ "%lld.%09ld Device register abadface\n",
+ (s64)current_ts64.tv_sec, current_ts64.tv_nsec);
 #endif
/* read the Device Status Register until Sleepmode bit 
is set */
while (reg = readl(device_base + ISL38XX_CTRL_STAT_REG),
@@ -149,13 +150,13 @@ isl38xx_trigger_device(int asleep, void __iomem 
*device_base)

 #if VERBOSE > SHOW_ERROR_MESSAGES
DEBUG(SHOW_TRACING,
- "%08li.%08li Device register read %08x\n",
- current_time.tv_sec, (long)current_time.tv_usec,
+ "%lld.%09ld Device register read %08x\n",
+ (s64)current_ts64.tv_sec, current_ts64.tv_nsec,
  readl(device_base + ISL38XX_CTRL_STAT_REG));
-   do_gettimeofday(¤t_time);
+   ktime_get_real_ts64(¤t_ts64);
DEBUG(SHOW_TRACING,
- "%08li.%08li Device asleep counter %i\n",
- current_time.tv_sec, (long)current_time.tv_usec,
+ "%lld.%09ld Device asleep counter %i\n",
+ (s64)current_ts64.tv_sec, current_ts64.tv_nsec,
  counter);
 #endif
}
@@ -168,9 +169,9 @@ isl38xx_trigger_device(int asleep, void __iomem 
*device_base)

/* perform another read on the Device Status Register */
reg = readl(device_base + ISL38XX_CTRL_STAT_REG);
-   do_gettimeofday(¤t_time);
-   DEBUG(SHOW_TRACING, "%08li.%08li Device register read %08x\n",
- current_time.tv_sec, (long)current_time.tv_usec, reg);
+   ktime_get_real_ts64(¤t_ts64);
+   DEBUG(SHOW_TRACING, "%lld.%00ld Device register read %08x\n",
+ (s64)current_ts64.tv_sec, current_ts64.tv_nsec, re

[Y2038] [PATCH v2] prism54: isl_38xx: Replace 'struct timeval'

2016-03-22 Thread Tina Ruchandani
'struct timeval' uses a 32-bit seconds field which will overflow in
year 2038 and beyond. This patch is part of a larger effort to remove
all instances of 'struct timeval' from the kernel and replace them
with 64-bit timekeeping variables.
The correctness of the code isn't affected by this patch - the seconds
value being printed would earlier be wrong due to overflow in timeval,
and now it gets truncated to 32-bit due to the 'long' cast used on
tv.sec field to prevent compiler warnings. Truly fixing this would
require changing the debug print to print more than 8 digits and
use a different specifier from %li.
The patch was build-tested / debugged by removing the
"if VERBOSE > SHOW_ERROR_MESSAGES" guards.

Signed-off-by: Tina Ruchandani 
Suggested-by: Arnd Bergmann 
--
Changes in v2:
- Changed printf specifier as suggested by Arnd Bergmann to
avoid truncation.
---
 drivers/net/wireless/intersil/prism54/isl_38xx.c | 35 
 1 file changed, 18 insertions(+), 17 deletions(-)

diff --git a/drivers/net/wireless/intersil/prism54/isl_38xx.c 
b/drivers/net/wireless/intersil/prism54/isl_38xx.c
index 333c1a2..6700387 100644
--- a/drivers/net/wireless/intersil/prism54/isl_38xx.c
+++ b/drivers/net/wireless/intersil/prism54/isl_38xx.c
@@ -19,6 +19,7 @@
 #include 
 #include 
 #include 
+#include 

 #include 
 #include 
@@ -113,7 +114,7 @@ isl38xx_trigger_device(int asleep, void __iomem 
*device_base)

 #if VERBOSE > SHOW_ERROR_MESSAGES
u32 counter = 0;
-   struct timeval current_time;
+   struct timespec64 current_ts64;
DEBUG(SHOW_FUNCTION_CALLS, "isl38xx trigger device\n");
 #endif

@@ -121,22 +122,22 @@ isl38xx_trigger_device(int asleep, void __iomem 
*device_base)
if (asleep) {
/* device is in powersave, trigger the device for wakeup */
 #if VERBOSE > SHOW_ERROR_MESSAGES
-   do_gettimeofday(¤t_time);
-   DEBUG(SHOW_TRACING, "%08li.%08li Device wakeup triggered\n",
- current_time.tv_sec, (long)current_time.tv_usec);
+   ktime_get_real_ts64(¤t_ts64);
+   DEBUG(SHOW_TRACING, "%lld.%09ld Device wakeup triggered\n",
+ (s64)current_ts64.tv_sec, current_ts64.tv_nsec);

-   DEBUG(SHOW_TRACING, "%08li.%08li Device register read %08x\n",
- current_time.tv_sec, (long)current_time.tv_usec,
+   DEBUG(SHOW_TRACING, "%lld.%09ld Device register read %08x\n",
+ (s64)current_ts64.tv_sec, current_ts64.tv_nsec,
  readl(device_base + ISL38XX_CTRL_STAT_REG));
 #endif

reg = readl(device_base + ISL38XX_INT_IDENT_REG);
if (reg == 0xabadface) {
 #if VERBOSE > SHOW_ERROR_MESSAGES
-   do_gettimeofday(¤t_time);
+   ktime_get_real_ts64(¤t_ts64);
DEBUG(SHOW_TRACING,
- "%08li.%08li Device register abadface\n",
- current_time.tv_sec, (long)current_time.tv_usec);
+ "%lld.%09ld Device register abadface\n",
+ (s64)current_ts64.tv_sec, current_ts64.tv_nsec);
 #endif
/* read the Device Status Register until Sleepmode bit 
is set */
while (reg = readl(device_base + ISL38XX_CTRL_STAT_REG),
@@ -149,13 +150,13 @@ isl38xx_trigger_device(int asleep, void __iomem 
*device_base)

 #if VERBOSE > SHOW_ERROR_MESSAGES
DEBUG(SHOW_TRACING,
- "%08li.%08li Device register read %08x\n",
- current_time.tv_sec, (long)current_time.tv_usec,
+ "%lld.%09ld Device register read %08x\n",
+ (s64)current_ts64.tv_sec, current_ts64.tv_nsec,
  readl(device_base + ISL38XX_CTRL_STAT_REG));
-   do_gettimeofday(¤t_time);
+   ktime_get_real_ts64(¤t_ts64);
DEBUG(SHOW_TRACING,
- "%08li.%08li Device asleep counter %i\n",
- current_time.tv_sec, (long)current_time.tv_usec,
+ "%lld.%09ld Device asleep counter %i\n",
+ (s64)current_ts64.tv_sec, current_ts64.tv_nsec,
  counter);
 #endif
}
@@ -168,9 +169,9 @@ isl38xx_trigger_device(int asleep, void __iomem 
*device_base)

/* perform another read on the Device Status Register */
reg = readl(device_base + ISL38XX_CTRL_STAT_REG);
-   do_gettimeofday(¤t_time);
-   DEBUG(SHOW_TRACING, "%08li.%08li Device register read %08x\n",
- 

[Y2038] [PATCH] prism54: isl_38xx: Replace 'struct timeval'

2016-03-22 Thread Tina Ruchandani
'struct timeval' uses a 32-bit seconds field which will overflow in
year 2038 and beyond. This patch is part of a larger effort to remove
all instances of 'struct timeval' from the kernel and replace them
with 64-bit timekeeping variables.
The correctness of the code isn't affected by this patch - the seconds
value being printed would earlier be wrong due to overflow in timeval,
and now it gets truncated to 32-bit due to the 'long' cast used on
tv.sec field to prevent compiler warnings. Truly fixing this would 
require changing the debug print to print more than 8 digits and using 
a different specifier from %li.
The patch was build-tested / debugged by removing the
"if VERBOSE > SHOW_ERROR_MESSAGES" guards.

Signed-off-by: Tina Ruchandani 
---
 drivers/net/wireless/intersil/prism54/isl_38xx.c | 29 +++-
 1 file changed, 18 insertions(+), 11 deletions(-)

diff --git a/drivers/net/wireless/intersil/prism54/isl_38xx.c 
b/drivers/net/wireless/intersil/prism54/isl_38xx.c
index 333c1a2..e510375 100644
--- a/drivers/net/wireless/intersil/prism54/isl_38xx.c
+++ b/drivers/net/wireless/intersil/prism54/isl_38xx.c
@@ -19,6 +19,7 @@
 #include 
 #include 
 #include 
+#include 

 #include 
 #include 
@@ -113,7 +114,7 @@ isl38xx_trigger_device(int asleep, void __iomem 
*device_base)

 #if VERBOSE > SHOW_ERROR_MESSAGES
u32 counter = 0;
-   struct timeval current_time;
+   struct timespec64 current_ts64;
DEBUG(SHOW_FUNCTION_CALLS, "isl38xx trigger device\n");
 #endif

@@ -121,22 +122,25 @@ isl38xx_trigger_device(int asleep, void __iomem 
*device_base)
if (asleep) {
/* device is in powersave, trigger the device for wakeup */
 #if VERBOSE > SHOW_ERROR_MESSAGES
-   do_gettimeofday(¤t_time);
+   ktime_get_real_ts64(¤t_ts64);
DEBUG(SHOW_TRACING, "%08li.%08li Device wakeup triggered\n",
- current_time.tv_sec, (long)current_time.tv_usec);
+ (long)current_ts64.tv_sec,
+ (long)(current_ts64.tv_nsec / NSEC_PER_USEC));

DEBUG(SHOW_TRACING, "%08li.%08li Device register read %08x\n",
- current_time.tv_sec, (long)current_time.tv_usec,
+ (long)current_ts64.tv_sec,
+ (long)(current_ts64.tv_nsec / NSEC_PER_USEC),
  readl(device_base + ISL38XX_CTRL_STAT_REG));
 #endif

reg = readl(device_base + ISL38XX_INT_IDENT_REG);
if (reg == 0xabadface) {
 #if VERBOSE > SHOW_ERROR_MESSAGES
-   do_gettimeofday(¤t_time);
+   ktime_get_real_ts64(¤t_ts64);
DEBUG(SHOW_TRACING,
  "%08li.%08li Device register abadface\n",
- current_time.tv_sec, (long)current_time.tv_usec);
+ (long)current_ts64.tv_sec,
+ (long)(current_ts64.tv_nsec / NSEC_PER_USEC));
 #endif
/* read the Device Status Register until Sleepmode bit 
is set */
while (reg = readl(device_base + ISL38XX_CTRL_STAT_REG),
@@ -150,12 +154,14 @@ isl38xx_trigger_device(int asleep, void __iomem 
*device_base)
 #if VERBOSE > SHOW_ERROR_MESSAGES
DEBUG(SHOW_TRACING,
  "%08li.%08li Device register read %08x\n",
- current_time.tv_sec, (long)current_time.tv_usec,
+ (long)current_ts64.tv_sec,
+ (long)(current_ts64.tv_nsec / NSEC_PER_USEC),
  readl(device_base + ISL38XX_CTRL_STAT_REG));
-   do_gettimeofday(¤t_time);
+   ktime_get_real_ts64(¤t_ts64);
DEBUG(SHOW_TRACING,
  "%08li.%08li Device asleep counter %i\n",
- current_time.tv_sec, (long)current_time.tv_usec,
+ (long)current_ts64.tv_sec,
+ (long)(current_ts64.tv_nsec / NSEC_PER_USEC),
  counter);
 #endif
}
@@ -168,9 +174,10 @@ isl38xx_trigger_device(int asleep, void __iomem 
*device_base)

/* perform another read on the Device Status Register */
reg = readl(device_base + ISL38XX_CTRL_STAT_REG);
-   do_gettimeofday(¤t_time);
+   ktime_get_real_ts64(¤t_ts64);
DEBUG(SHOW_TRACING, "%08li.%08li Device register read %08x\n",
- current_time.tv_sec, (long)current_time.tv_usec, reg);
+ (long)current_ts64.tv_sec,
+ (long)(current_ts64.tv_nsec / NSEC_PER_USEC), reg);
 #endif
} else {
/* device is (sti

[Y2038] [PATCH] firewire: nosy: Replace timeval with timespec64

2016-03-20 Thread Tina Ruchandani
'struct timeval' uses a 32 bit field for its 'seconds' value which
will overflow in year 2038 and beyond. This patch replaces the use
of timeval in nosy.c with timespec64 which doesn't suffer from y2038
issue. The code is correct as is - since it is only using the
microseconds portion of timeval. However, this patch does the
replacement as part of a larger effort to remove all instances of
'struct timeval' from the kernel (that would help identify cases
where the code is actually broken).

Signed-off-by: Tina Ruchandani 
---
 drivers/firewire/nosy.c | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/firewire/nosy.c b/drivers/firewire/nosy.c
index 8a46077..631c977 100644
--- a/drivers/firewire/nosy.c
+++ b/drivers/firewire/nosy.c
@@ -446,14 +446,16 @@ static void
 bus_reset_irq_handler(struct pcilynx *lynx)
 {
struct client *client;
-   struct timeval tv;
+   struct timespec64 ts64;
+   u32timestamp;

-   do_gettimeofday(&tv);
+   ktime_get_real_ts64(&ts64);
+   timestamp = ts64.tv_nsec / NSEC_PER_USEC;

spin_lock(&lynx->client_list_lock);

list_for_each_entry(client, &lynx->client_list, link)
-   packet_buffer_put(&client->buffer, &tv.tv_usec, 4);
+   packet_buffer_put(&client->buffer, ×tamp, 4);

spin_unlock(&lynx->client_list_lock);
 }
--
2.8.0.rc3.226.g39d4020

___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [PATCH v7] isdn: Use ktime_t instead of 'struct timeval'

2016-03-19 Thread Tina Ruchandani
'struct timeval' uses 32-bit representation for seconds which will
overflow in year 2038 and beyond. mISDN/clock.c needs to compute and
store elapsed time in intervals of 125 microseconds. This patch replaces
the usage of 'struct timeval' with 64-bit ktime_t which is y2038 safe.
The patch also replaces do_gettimeofday() (wall-clock time) with
ktime_get() (monotonic time) since we only care about elapsed time here.

Signed-off-by: Tina Ruchandani 
Suggested-by: Arnd Bergmnann 
Suggested-by: David Miller 
---
Changes in v7:
- Upodate variable names to remove mentions of 'tv' for timeval
Changes in v6:
- Fix compilation errors caused by bad code editing
Changes in v5:
- Apply cleanly to net-next
Changes in v4:
- Fix compile error (NS_PER_SEC -> NSEC_PER_SEC)
Changes in v3:
- Use division scheme suggested by Arnd Bergmann to avoid
  a (64-bit variable) / (32-bit variable) expression.
Changes in v2:
- Avoid possible truncation bug caused by assigning ktime_us_delta
output to a 16-bit number.
- Use ktime_us_delta, more concise than a combination of ktime_sub
and ktime_to_us.
---
 drivers/isdn/mISDN/clock.c | 69 +++---
 include/linux/mISDNif.h|  2 +-
 2 files changed, 30 insertions(+), 41 deletions(-)

diff --git a/drivers/isdn/mISDN/clock.c b/drivers/isdn/mISDN/clock.c
index 693fb7c..f8f659f 100644
--- a/drivers/isdn/mISDN/clock.c
+++ b/drivers/isdn/mISDN/clock.c
@@ -37,6 +37,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include "core.h"
@@ -45,15 +46,15 @@ static u_int *debug;
 static LIST_HEAD(iclock_list);
 static DEFINE_RWLOCK(iclock_lock);
 static u16 iclock_count;   /* counter of last clock */
-static struct timeval iclock_tv;   /* time stamp of last clock */
-static int iclock_tv_valid;/* already received one timestamp */
+static ktime_t iclock_timestamp;   /* time stamp of last clock */
+static int iclock_timestamp_valid; /* already received one timestamp */
 static struct mISDNclock *iclock_current;
 
 void
 mISDN_init_clock(u_int *dp)
 {
debug = dp;
-   do_gettimeofday(&iclock_tv);
+   iclock_timestamp = ktime_get();
 }
 
 static void
@@ -86,7 +87,7 @@ select_iclock(void)
}
if (bestclock != iclock_current) {
/* no clock received yet */
-   iclock_tv_valid = 0;
+   iclock_timestamp_valid = 0;
}
iclock_current = bestclock;
 }
@@ -139,12 +140,11 @@ mISDN_unregister_clock(struct mISDNclock *iclock)
 EXPORT_SYMBOL(mISDN_unregister_clock);
 
 void
-mISDN_clock_update(struct mISDNclock *iclock, int samples, struct timeval *tv)
+mISDN_clock_update(struct mISDNclock *iclock, int samples, ktime_t *timestamp)
 {
u_long  flags;
-   struct timeval  tv_now;
-   time_t  elapsed_sec;
-   int elapsed_8000th;
+   ktime_t timestamp_now;
+   u16 delta;
 
write_lock_irqsave(&iclock_lock, flags);
if (iclock_current != iclock) {
@@ -156,33 +156,27 @@ mISDN_clock_update(struct mISDNclock *iclock, int 
samples, struct timeval *tv)
write_unlock_irqrestore(&iclock_lock, flags);
return;
}
-   if (iclock_tv_valid) {
+   if (iclock_timestamp_valid) {
/* increment sample counter by given samples */
iclock_count += samples;
-   if (tv) { /* tv must be set, if function call is delayed */
-   iclock_tv.tv_sec = tv->tv_sec;
-   iclock_tv.tv_usec = tv->tv_usec;
-   } else
-   do_gettimeofday(&iclock_tv);
+   if (timestamp) { /* timestamp must be set, if function call is 
delayed */
+   iclock_timestamp = *timestamp;
+   } else  {
+   iclock_timestamp = ktime_get();
+   }
} else {
/* calc elapsed time by system clock */
-   if (tv) { /* tv must be set, if function call is delayed */
-   tv_now.tv_sec = tv->tv_sec;
-   tv_now.tv_usec = tv->tv_usec;
-   } else
-   do_gettimeofday(&tv_now);
-   elapsed_sec = tv_now.tv_sec - iclock_tv.tv_sec;
-   elapsed_8000th = (tv_now.tv_usec / 125)
-   - (iclock_tv.tv_usec / 125);
-   if (elapsed_8000th < 0) {
-   elapsed_sec -= 1;
-   elapsed_8000th += 8000;
+   if (timestamp) { /* timestamp must be set, if function call is 
delayed */
+   timestamp_now = *timestamp;
+   } else {
+   timestamp_now = ktime_get();
}
+   delta = ktime_divns(ktime_sub(timestamp_now, iclock_timestamp),
+   (NSE

[Y2038] Timestamp bugs in the news

2016-02-13 Thread Tina Ruchandani
Thought this might be of interest to this group - changing the date to
1st January 1970 disables 64-bit iOS devices.

Original link: 
https://www.reddit.com/r/jailbreak/comments/458ao3/discussion_changing_time_date_settings_to_jan_1/

Hacker News discussion: https://news.ycombinator.com/item?id=11079781
___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


Re: [Y2038] [RESEND PATCH] mpt2sas: Remove usage of 'struct timeval'

2015-10-30 Thread Tina Ruchandani
> Can you wait a cycle on this? Martin Petersen is on a mission to wrangle the 
> mpt2/3sas merger in this window, which will conflict with this.
>

James,
No issues. Making a note here though that the patches for
mpt2sas_base.c and mpt3sas_base.c are identical, I submitted the
latter before I saw your email.
Tina
___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [RESEND PATCH] qla2xxx: Remove use of 'struct timeval'

2015-10-30 Thread Tina Ruchandani
struct register_host_info stores a 64-bit UTC system time timestamp.
This patch removes the use of 'struct timeval' to obtain that timestamp
as its tv_sec value will overflow on 32-bit systems in year 2038 beyond.
The patch uses ktime_get_real_seconds() which returns a 64-bit seconds value.

Signed-off-by: Tina Ruchandani 
---
 drivers/scsi/qla2xxx/qla_mr.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_mr.c b/drivers/scsi/qla2xxx/qla_mr.c
index 6d190b4..d64a64a 100644
--- a/drivers/scsi/qla2xxx/qla_mr.c
+++ b/drivers/scsi/qla2xxx/qla_mr.c
@@ -6,6 +6,7 @@
  */
 #include "qla_def.h"
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -1812,7 +1813,6 @@ qlafx00_fx_disc(scsi_qla_host_t *vha, fc_port_t *fcport, 
uint16_t fx_type)
struct host_system_info *phost_info;
struct register_host_info *preg_hsi;
struct new_utsname *p_sysid = NULL;
-   struct timeval tv;
 
sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
if (!sp)
@@ -1886,8 +1886,7 @@ qlafx00_fx_disc(scsi_qla_host_t *vha, fc_port_t *fcport, 
uint16_t fx_type)
p_sysid->domainname, DOMNAME_LENGTH);
strncpy(phost_info->hostdriver,
QLA2XXX_VERSION, VERSION_LENGTH);
-   do_gettimeofday(&tv);
-   preg_hsi->utc = (uint64_t)tv.tv_sec;
+   preg_hsi->utc = (uint64_t)ktime_get_real_seconds();
ql_dbg(ql_dbg_init, vha, 0x0149,
"ISP%04X: Host registration with firmware\n",
ha->pdev->device);
-- 
2.2.0.rc0.207.ga3a616c

___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [RESEND PATCH] [SCSI] mvumi: 64bit value for seconds_since1970

2015-10-30 Thread Tina Ruchandani
struct mvumi_hs_page2 stores a "seconds_since1970" field which is of
type u64. It is however, written to, using 'struct timeval' which has
a 32-bit seconds field and whose value will overflow in year 2038.
This patch uses ktime_get_real_seconds() instead since it provides a
64-bit seconds value, which is 2038 safe.

Signed-off-by: Tina Ruchandani 
---
 drivers/scsi/mvumi.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/scsi/mvumi.c b/drivers/scsi/mvumi.c
index 3e6b866..02360de 100644
--- a/drivers/scsi/mvumi.c
+++ b/drivers/scsi/mvumi.c
@@ -31,6 +31,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -858,8 +859,8 @@ static void mvumi_hs_build_page(struct mvumi_hba *mhba,
struct mvumi_hs_page2 *hs_page2;
struct mvumi_hs_page4 *hs_page4;
struct mvumi_hs_page3 *hs_page3;
-   struct timeval time;
-   unsigned int local_time;
+   u64 time;
+   u64 local_time;
 
switch (hs_header->page_code) {
case HS_PAGE_HOST_INFO:
@@ -877,9 +878,8 @@ static void mvumi_hs_build_page(struct mvumi_hba *mhba,
hs_page2->slot_number = 0;
hs_page2->intr_level = 0;
hs_page2->intr_vector = 0;
-   do_gettimeofday(&time);
-   local_time = (unsigned int) (time.tv_sec -
-   (sys_tz.tz_minuteswest * 60));
+   time = ktime_get_real_seconds();
+   local_time = (time - (sys_tz.tz_minuteswest * 60));
hs_page2->seconds_since1970 = local_time;
hs_header->checksum = mvumi_calculate_checksum(hs_header,
hs_header->frame_length);
-- 
2.2.0.rc0.207.ga3a616c

___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [RESEND PATCH] mpt3sas: Remove usage of 'struct timeval'

2015-10-30 Thread Tina Ruchandani
'struct timeval' will have its tv_sec value overflow on 32-bit systems
in year 2038 and beyond. This patch replaces the use of struct timeval
for computing mpi_request.TimeStamp, and instead uses ktime_t which provides
64-bit seconds value. The timestamp computed remains unaffected (milliseconds
since Unix epoch).

Signed-off-by: Tina Ruchandani 
---
 drivers/scsi/mpt3sas/mpt3sas_base.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c 
b/drivers/scsi/mpt3sas/mpt3sas_base.c
index 1560115..ee9c3c6 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_base.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_base.c
@@ -56,6 +56,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -3735,7 +3736,7 @@ _base_send_ioc_init(struct MPT3SAS_ADAPTER *ioc, int 
sleep_flag)
Mpi2IOCInitRequest_t mpi_request;
Mpi2IOCInitReply_t mpi_reply;
int i, r = 0;
-   struct timeval current_time;
+   ktime_t current_time;
u16 ioc_status;
u32 reply_post_free_array_sz = 0;
Mpi2IOCInitRDPQArrayEntry *reply_post_free_array = NULL;
@@ -3797,9 +3798,8 @@ _base_send_ioc_init(struct MPT3SAS_ADAPTER *ioc, int 
sleep_flag)
/* This time stamp specifies number of milliseconds
 * since epoch ~ midnight January 1, 1970.
 */
-   do_gettimeofday(¤t_time);
-   mpi_request.TimeStamp = cpu_to_le64((u64)current_time.tv_sec * 1000 +
-   (current_time.tv_usec / 1000));
+   current_time = ktime_get_real();
+   mpi_request.TimeStamp = cpu_to_le64(ktime_to_ms(current_time));
 
if (ioc->logging_level & MPT_DEBUG_INIT) {
__le32 *mfp;
-- 
2.2.0.rc0.207.ga3a616c

___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [RESEND PATCH] mpt2sas: Remove usage of 'struct timeval'

2015-10-30 Thread Tina Ruchandani
'struct timeval' will have its tv_sec value overflow on 32-bit systems
in year 2038 and beyond. This patch replaces the use of struct timeval
for computing mpi_request.TimeStamp, and instead uses ktime_t which provides
64-bit seconds value. The timestamp computed remains unaffected (milliseconds
since Unix epoch).

Signed-off-by: Tina Ruchandani 
---
 drivers/scsi/mpt2sas/mpt2sas_base.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/mpt2sas/mpt2sas_base.c 
b/drivers/scsi/mpt2sas/mpt2sas_base.c
index 58e4521..6d80477 100644
--- a/drivers/scsi/mpt2sas/mpt2sas_base.c
+++ b/drivers/scsi/mpt2sas/mpt2sas_base.c
@@ -57,6 +57,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -3616,7 +3617,7 @@ _base_send_ioc_init(struct MPT2SAS_ADAPTER *ioc, int 
sleep_flag)
Mpi2IOCInitRequest_t mpi_request;
Mpi2IOCInitReply_t mpi_reply;
int i, r = 0;
-   struct timeval current_time;
+   ktime_t current_time;
u16 ioc_status;
u32 reply_post_free_array_sz = 0;
Mpi2IOCInitRDPQArrayEntry *reply_post_free_array = NULL;
@@ -3678,9 +3679,8 @@ _base_send_ioc_init(struct MPT2SAS_ADAPTER *ioc, int 
sleep_flag)
/* This time stamp specifies number of milliseconds
 * since epoch ~ midnight January 1, 1970.
 */
-   do_gettimeofday(¤t_time);
-   mpi_request.TimeStamp = cpu_to_le64((u64)current_time.tv_sec * 1000 +
-   (current_time.tv_usec / 1000));
+   current_time = ktime_get_real();
+   mpi_request.TimeStamp = cpu_to_le64(ktime_to_ms(current_time));
 
if (ioc->logging_level & MPT_DEBUG_INIT) {
__le32 *mfp;
-- 
2.2.0.rc0.207.ga3a616c

___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


Re: [Y2038] [RESEND PATCH v3] scsi: stex: Remove use of struct timeval

2015-10-30 Thread Tina Ruchandani
>
> Thanks for the conversion. Can you please check if other (scsi) drivers
> have the same y2038 issues? A quick "git grep do_gettimeofday
> drivers/scsi/  | wc -l" reveals 30 occurrences (of cause not all are
> problematic).
>

Hi Johannes,
Yes, there are quite a few occurrences of timeval within scsi. I had
sent some of the trivial back in the Feb-May 2015 period, and they
were ack-ed by my then mentor and a couple of other people, but not
merged or ack-ed by someone from linux-scsi. Until today, I thought
using "RESEND" would be impolite, but now I will resend the other ones
as well. Arnd Bergmann is leading this effort and may have more
insightful comments.
Thanks,
Tina
___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [PATCH] AFS: Correctly use 64-bit time for UUID

2015-10-30 Thread Tina Ruchandani
UUID calculation uses 'struct timespec' whose seconds will overflow
in year 2038 and beyond for 32-bit systems. This patch removes the
dependency on 'struct timespec' by using ktime_get_real().
While the patch does not fix a 'bug' as such, it is part of a larger
effort to remove instances of 'struct timespec' and other data-structures
suffering from y2038 problem from the kernel.

Suggested-by: Arnd Bergmann 
Signed-off-by: Tina Ruchandani 
---
Changes in v2:
- Use 64-bit division API, fix 32-bit build
---
 fs/afs/main.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/fs/afs/main.c b/fs/afs/main.c
index 35de0c0..129ff43 100644
--- a/fs/afs/main.c
+++ b/fs/afs/main.c
@@ -14,6 +14,7 @@
 #include 
 #include 
 #include 
+#include 
 #include "internal.h"
 
 MODULE_DESCRIPTION("AFS Client File System");
@@ -37,7 +38,6 @@ struct workqueue_struct *afs_wq;
  */
 static int __init afs_get_client_UUID(void)
 {
-   struct timespec ts;
u64 uuidtime;
u16 clockseq;
int ret;
@@ -48,9 +48,7 @@ static int __init afs_get_client_UUID(void)
if (ret < 0)
return ret;
 
-   getnstimeofday(&ts);
-   uuidtime = (u64) ts.tv_sec * 1000 * 1000 * 10;
-   uuidtime += ts.tv_nsec / 100;
+   uuidtime = ktime_divns(ktime_get_real(), 100);
uuidtime += AFS_UUID_TO_UNIX_TIME;
afs_uuid.time_low = uuidtime;
afs_uuid.time_mid = uuidtime >> 32;
-- 
1.9.1

___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [RESEND PATCH v3] scsi: stex: Remove use of struct timeval

2015-10-30 Thread Tina Ruchandani
Function stex_gettime uses 'struct timeval' whose tv_sec value
will overflow on 32-bit systems in year 2038 and beyond. This patch
replaces the use of struct timeval and do_gettimeofday with
ktime_get_real_seconds, which returns a 64-bit seconds value.

Suggested-by: Arnd Bergmann 
Signed-off-by: Tina Ruchandani 
--
Changes in v3:
- Remove stex_gettime altogether, directly assign the timestamp.
Changes in v2:
- Change subject line to indicate that the patch is restricted to stex driver.
---
---
 drivers/scsi/stex.c | 13 +++--
 1 file changed, 3 insertions(+), 10 deletions(-)

diff --git a/drivers/scsi/stex.c b/drivers/scsi/stex.c
index 98a62bc..84e196e 100644
--- a/drivers/scsi/stex.c
+++ b/drivers/scsi/stex.c
@@ -25,6 +25,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -362,14 +363,6 @@ MODULE_DESCRIPTION("Promise Technology SuperTrak EX 
Controllers");
 MODULE_LICENSE("GPL");
 MODULE_VERSION(ST_DRIVER_VERSION);
 
-static void stex_gettime(__le64 *time)
-{
-   struct timeval tv;
-
-   do_gettimeofday(&tv);
-   *time = cpu_to_le64(tv.tv_sec);
-}
-
 static struct status_msg *stex_get_status(struct st_hba *hba)
 {
struct status_msg *status = hba->status_buffer + hba->status_tail;
@@ -1002,7 +995,7 @@ static int stex_common_handshake(struct st_hba *hba)
h->req_cnt = cpu_to_le16(hba->rq_count+1);
h->status_sz = cpu_to_le16(sizeof(struct status_msg));
h->status_cnt = cpu_to_le16(hba->sts_count+1);
-   stex_gettime(&h->hosttime);
+   h->hosttime = cpu_to_le64(ktime_get_real_seconds());
h->partner_type = HMU_PARTNER_TYPE;
if (hba->extra_offset) {
h->extra_offset = cpu_to_le32(hba->extra_offset);
@@ -1076,7 +1069,7 @@ static int stex_ss_handshake(struct st_hba *hba)
h->req_cnt = cpu_to_le16(hba->rq_count+1);
h->status_sz = cpu_to_le16(sizeof(struct status_msg));
h->status_cnt = cpu_to_le16(hba->sts_count+1);
-   stex_gettime(&h->hosttime);
+   h->hosttime = cpu_to_le64(ktime_get_real_seconds());
h->partner_type = HMU_PARTNER_TYPE;
h->extra_offset = h->extra_size = 0;
scratch_size = (hba->sts_count+1)*sizeof(u32);
-- 
2.2.0.rc0.207.ga3a616c
___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [PATCH] [DCCP]: Use 64-bit timekeeping

2015-10-30 Thread Tina Ruchandani
This patch changes the use of struct timespec in
dccp_probe to use struct timespec64 instead. timespec uses a 32-bit
seconds field which will overflow in the year 2038 and beyond. timespec64
uses a 64-bit seconds field. Note that the correctness of the code isn't
changed, since the original code only uses the timestamps to compute a
small elapsed interval. This patch is part of a larger attempt to remove
instances of 32-bit timekeeping structures (timespec, timeval, time_t)
from the kernel so it is easier to identify where the real 2038 issues
are.

Signed-off-by: Tina Ruchandani 
---
 net/dccp/probe.c | 11 ++-
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/net/dccp/probe.c b/net/dccp/probe.c
index d8346d0..3d3fda0 100644
--- a/net/dccp/probe.c
+++ b/net/dccp/probe.c
@@ -30,6 +30,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -47,20 +48,20 @@ static struct {
struct kfifo  fifo;
spinlock_tlock;
wait_queue_head_t wait;
-   struct timespec   tstart;
+   struct timespec64 tstart;
 } dccpw;
 
 static void printl(const char *fmt, ...)
 {
va_list args;
int len;
-   struct timespec now;
+   struct timespec64 now;
char tbuf[256];
 
va_start(args, fmt);
-   getnstimeofday(&now);
+   getnstimeofday64(&now);
 
-   now = timespec_sub(now, dccpw.tstart);
+   now = timespec64_sub(now, dccpw.tstart);
 
len = sprintf(tbuf, "%lu.%06lu ",
  (unsigned long) now.tv_sec,
@@ -110,7 +111,7 @@ static struct jprobe dccp_send_probe = {
 static int dccpprobe_open(struct inode *inode, struct file *file)
 {
kfifo_reset(&dccpw.fifo);
-   getnstimeofday(&dccpw.tstart);
+   getnstimeofday64(&dccpw.tstart);
return 0;
 }
 
-- 
1.9.1

___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [PATCH v2] USB: usbmon: Remove timeval usage for timestamp

2015-10-29 Thread Tina Ruchandani
struct timeval' uses 32-bits for its seconds field and will overflow in
the year 2038 and beyond. This patch replaces the usage of 'struct timeval'
in mon_get_timestamp() with timespec64 which uses a 64-bit seconds field
and is y2038-safe. mon_get_timestamp() truncates the timestamp at 4096 seconds,
so the correctness of the code is not affected. This patch is part of a larger
attempt to remove instances of struct timeval and other 32-bit timekeeping
(time_t, struct timespec) from the kernel.

Signed-off-by: Tina Ruchandani 
Suggested-by: Arnd Bergmann 
---
Changes in v2:
- Switch to monotonic time since we only care about time elapsed.
---
 drivers/usb/mon/mon_text.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/mon/mon_text.c b/drivers/usb/mon/mon_text.c
index ad40825..98e4f63 100644
--- a/drivers/usb/mon/mon_text.c
+++ b/drivers/usb/mon/mon_text.c
@@ -9,6 +9,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -176,12 +177,12 @@ static inline char mon_text_get_data(struct 
mon_event_text *ep, struct urb *urb,
 
 static inline unsigned int mon_get_timestamp(void)
 {
-   struct timeval tval;
+   struct timespec64 now;
unsigned int stamp;
 
-   do_gettimeofday(&tval);
-   stamp = tval.tv_sec & 0xFFF;/* 2^32 = 4294967296. Limit to 4096s. */
-   stamp = stamp * 100 + tval.tv_usec;
+   ktime_get_ts64(&now);
+   stamp = now.tv_sec & 0xFFF;  /* 2^32 = 4294967296. Limit to 4096s. */
+   stamp = stamp * USEC_PER_SEC + now.tv_nsec / NSEC_PER_USEC;
return stamp;
 }
 
-- 
2.6.0.rc2.230.g3dd15c0

___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [RESEND PATCH] USB: usbmon: Use 64bit timestamp for mon_bin_hdr

2015-10-29 Thread Tina Ruchandani
struct mon_bin_hdr allows for a 64-bit seconds timestamp. The code
currently uses 'struct timeval' to populate the timestamp in mon_bin_hdr,
which has a 32-bit seconds field and will overflow in year 2038 and beyond.
This patch replaces 'struct timeval' with 'struct timespec64' which is
y2038 safe. This patch is part of a larger attempt to remove instances
of struct timeval and other 32-bit timekeeping (time_t, struct timespec)
from the kernel.

Signed-off-by: Tina Ruchandani 
---
 drivers/usb/mon/mon_bin.c | 17 +
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/drivers/usb/mon/mon_bin.c b/drivers/usb/mon/mon_bin.c
index 3598f1a..1a874a1 100644
--- a/drivers/usb/mon/mon_bin.c
+++ b/drivers/usb/mon/mon_bin.c
@@ -18,6 +18,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 
@@ -92,8 +93,8 @@ struct mon_bin_hdr {
unsigned short busnum;  /* Bus number */
char flag_setup;
char flag_data;
-   s64 ts_sec; /* gettimeofday */
-   s32 ts_usec;/* gettimeofday */
+   s64 ts_sec; /* getnstimeofday64 */
+   s32 ts_usec;/* getnstimeofday64 */
int status;
unsigned int len_urb;   /* Length of data (submitted or actual) */
unsigned int len_cap;   /* Delivered length */
@@ -483,7 +484,7 @@ static void mon_bin_event(struct mon_reader_bin *rp, struct 
urb *urb,
 char ev_type, int status)
 {
const struct usb_endpoint_descriptor *epd = &urb->ep->desc;
-   struct timeval ts;
+   struct timespec64 ts;
unsigned long flags;
unsigned int urb_length;
unsigned int offset;
@@ -494,7 +495,7 @@ static void mon_bin_event(struct mon_reader_bin *rp, struct 
urb *urb,
struct mon_bin_hdr *ep;
char data_tag = 0;
 
-   do_gettimeofday(&ts);
+   getnstimeofday64(&ts);
 
spin_lock_irqsave(&rp->b_lock, flags);
 
@@ -568,7 +569,7 @@ static void mon_bin_event(struct mon_reader_bin *rp, struct 
urb *urb,
ep->busnum = urb->dev->bus->busnum;
ep->id = (unsigned long) urb;
ep->ts_sec = ts.tv_sec;
-   ep->ts_usec = ts.tv_usec;
+   ep->ts_usec = ts.tv_nsec / NSEC_PER_USEC;
ep->status = status;
ep->len_urb = urb_length;
ep->len_cap = length + lendesc;
@@ -629,12 +630,12 @@ static void mon_bin_complete(void *data, struct urb *urb, 
int status)
 static void mon_bin_error(void *data, struct urb *urb, int error)
 {
struct mon_reader_bin *rp = data;
-   struct timeval ts;
+   struct timespec64 ts;
unsigned long flags;
unsigned int offset;
struct mon_bin_hdr *ep;
 
-   do_gettimeofday(&ts);
+   getnstimeofday64(&ts);
 
spin_lock_irqsave(&rp->b_lock, flags);
 
@@ -656,7 +657,7 @@ static void mon_bin_error(void *data, struct urb *urb, int 
error)
ep->busnum = urb->dev->bus->busnum;
ep->id = (unsigned long) urb;
ep->ts_sec = ts.tv_sec;
-   ep->ts_usec = ts.tv_usec;
+   ep->ts_usec = ts.tv_nsec / NSEC_PER_USEC;
ep->status = error;
 
ep->flag_setup = '-';
-- 
2.6.0.rc2.230.g3dd15c0

___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [PATCH] NET: ATM: MPOA: Remove 32-bit timekeeping

2015-10-29 Thread Tina Ruchandani
net/atm/mpoa_* files use 'struct timeval' to store event
timestamps. struct timeval uses a 32-bit seconds field which will
overflow in the year 2038 and beyond. Morever, the timestamps are being
compared only to get seconds elapsed, so struct timeval which stores
a seconds and microseconds field is an overkill. This patch replaces
the use of struct timeval with time64_t to store a 64-bit seconds field.

Signed-off-by: Tina Ruchandani 
---
 net/atm/common.c  |  2 +-
 net/atm/mpc.c |  9 +
 net/atm/mpoa_caches.c | 49 -
 net/atm/mpoa_caches.h |  9 +
 net/atm/mpoa_proc.c   | 15 +--
 5 files changed, 44 insertions(+), 40 deletions(-)

diff --git a/net/atm/common.c b/net/atm/common.c
index 49a872d..a48a1ac 100644
--- a/net/atm/common.c
+++ b/net/atm/common.c
@@ -14,7 +14,7 @@
 #include 
 #include 
 #include 
-#include /* struct timeval */
+#include   /* 64-bit time for seconds */
 #include 
 #include 
 #include 
diff --git a/net/atm/mpc.c b/net/atm/mpc.c
index 0e98222..211468e 100644
--- a/net/atm/mpc.c
+++ b/net/atm/mpc.c
@@ -1090,7 +1090,7 @@ static void MPOA_trigger_rcvd(struct k_message *msg, 
struct mpoa_client *mpc)
msg->type = SND_MPOA_RES_RQST;
msg->content.in_info = entry->ctrl_info;
msg_to_mpoad(msg, mpc);
-   do_gettimeofday(&(entry->reply_wait));
+   entry->reply_wait = ktime_get_real_seconds();
mpc->in_ops->put(entry);
return;
}
@@ -1100,7 +1100,7 @@ static void MPOA_trigger_rcvd(struct k_message *msg, 
struct mpoa_client *mpc)
msg->type = SND_MPOA_RES_RQST;
msg->content.in_info = entry->ctrl_info;
msg_to_mpoad(msg, mpc);
-   do_gettimeofday(&(entry->reply_wait));
+   entry->reply_wait = ktime_get_real_seconds();
mpc->in_ops->put(entry);
return;
}
@@ -1176,8 +1176,9 @@ static void MPOA_res_reply_rcvd(struct k_message *msg, 
struct mpoa_client *mpc)
}
 
entry->ctrl_info = msg->content.in_info;
-   do_gettimeofday(&(entry->tv));
-   do_gettimeofday(&(entry->reply_wait)); /* Used in refreshing func from 
now on */
+   entry->tv = ktime_get_real_seconds();
+   /* Used in refreshing func from now on */
+   entry->reply_wait = ktime_get_real_seconds();
entry->refresh_time = 0;
ddprintk_cont("entry->shortcut = %p\n", entry->shortcut);
 
diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c
index d1b2d9a..2a59830 100644
--- a/net/atm/mpoa_caches.c
+++ b/net/atm/mpoa_caches.c
@@ -116,7 +116,7 @@ static in_cache_entry *in_cache_add_entry(__be32 dst_ip,
 
memcpy(entry->MPS_ctrl_ATM_addr, client->mps_ctrl_addr, ATM_ESA_LEN);
entry->ctrl_info.in_dst_ip = dst_ip;
-   do_gettimeofday(&(entry->tv));
+   entry->tv = ktime_get_real_seconds();
entry->retry_time = client->parameters.mpc_p4;
entry->count = 1;
entry->entry_state = INGRESS_INVALID;
@@ -147,7 +147,7 @@ static int cache_hit(in_cache_entry *entry, struct 
mpoa_client *mpc)
if (qos != NULL)
msg.qos = qos->qos;
msg_to_mpoad(&msg, mpc);
-   do_gettimeofday(&(entry->reply_wait));
+   entry->reply_wait = ktime_get_real_seconds();
entry->entry_state = INGRESS_RESOLVING;
}
if (entry->shortcut != NULL)
@@ -170,7 +170,7 @@ static int cache_hit(in_cache_entry *entry, struct 
mpoa_client *mpc)
if (qos != NULL)
msg.qos = qos->qos;
msg_to_mpoad(&msg, mpc);
-   do_gettimeofday(&(entry->reply_wait));
+   entry->reply_wait = ktime_get_real_seconds();
}
 
return CLOSED;
@@ -226,17 +226,16 @@ static void in_cache_remove_entry(in_cache_entry *entry,
 static void clear_count_and_expired(struct mpoa_client *client)
 {
in_cache_entry *entry, *next_entry;
-   struct timeval now;
+   time64_t now;
 
-   do_gettimeofday(&now);
+   now = ktime_get_real_seconds();
 
write_lock_bh(&client->ingress_lock);
entry = client->in_cache;
while (entry != NULL) {
entry->count = 0;
next_entry = entry->next;
-   if ((now.tv_sec - entry->tv.tv_sec)
-  > entry->ctrl_info.holding_time) {
+   if ((now - entry->tv) > entry->ctrl_info.holding_time) {
dprintk("holding time expired, ip = %pI4\n",
&entry->ctrl_

Re: [Y2038] [PATCH] fbdev: radeon: Remove 'struct timeval' usage

2015-06-05 Thread Tina Ruchandani
>>> + hz = 100/delta;
>
> This needs to be on of the do_div family.
>
> Dave.

Hi Dave,
I build-tested the patch for both 32-bit and 64-bit x86. If my
understanding is correct, since the divisor is 64-bit here, the
compiler will do "if (delta > 100) hz = 0; else hz =
100/(s32)delta" automatically?
In general, is this a good thumb-rule to follow - use do_div if the
dividend is 64-bit, and normal divide operator if only the divisor is
64-bit?

Tina
___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [PATCH] drm/exynos/ipp: Replace struct timeval usage

2015-05-31 Thread Tina Ruchandani
'struct timeval' uses a 32-bit seconds representation which
will overflow in the year 2038 and beyond. This patch
replaces the use of struct timeval with struct timespec64
which uses a 64-bit seconds representation and is y2038 safe.

The patch is part of a larger effort to remove all 32-bit
timekeeping variables (timeval, time_t and timespec) from the
kernel.

Signed-off-by: Tina Ruchandani 
---
 drivers/gpu/drm/exynos/exynos_drm_ipp.c | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/exynos/exynos_drm_ipp.c 
b/drivers/gpu/drm/exynos/exynos_drm_ipp.c
index b7f1cbc..7cd4a97 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_ipp.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_ipp.c
@@ -16,6 +16,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -1414,7 +1415,7 @@ static int ipp_send_event(struct exynos_drm_ippdrv 
*ippdrv,
struct drm_exynos_ipp_queue_buf qbuf;
struct drm_exynos_ipp_send_event *e;
struct list_head *head;
-   struct timeval now;
+   struct timespec64 now;
unsigned long flags;
u32 tbuf_id[EXYNOS_DRM_OPS_MAX] = {0, };
int ret, i;
@@ -1518,10 +1519,11 @@ static int ipp_send_event(struct exynos_drm_ippdrv 
*ippdrv,
e = list_first_entry(&c_node->event_list,
struct drm_exynos_ipp_send_event, base.link);
 
-   do_gettimeofday(&now);
-   DRM_DEBUG_KMS("tv_sec[%ld]tv_usec[%ld]\n", now.tv_sec, now.tv_usec);
+   getnstimeofday64(&now);
+   DRM_DEBUG_KMS("tv_sec[%lld]tv_usec[%lld]\n", now.tv_sec, (now.tv_nsec /
+   NSEC_PER_SEC));
e->event.tv_sec = now.tv_sec;
-   e->event.tv_usec = now.tv_usec;
+   e->event.tv_usec = now.tv_nsec / NSEC_PER_SEC;
e->event.prop_id = property->prop_id;
 
/* set buffer id about source destination */
-- 
2.2.0.rc0.207.ga3a616c

___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [PATCH] drm/exynos/ipp: Replace struct timeval usage

2015-05-31 Thread Tina Ruchandani
'struct timeval' uses a 32-bit seconds representation which
will overflow in the year 2038 and beyond. This patch
replaces the use of struct timeval with struct timespec64
which uses a 64-bit seconds representation and is y2038 safe.

The patch is part of a larger effort to remove all 32-bit
timekeeping variables (timeval, time_t and timespec) from the
kernel.
---
 drivers/gpu/drm/exynos/exynos_drm_ipp.c | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/exynos/exynos_drm_ipp.c 
b/drivers/gpu/drm/exynos/exynos_drm_ipp.c
index b7f1cbc..7cd4a97 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_ipp.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_ipp.c
@@ -16,6 +16,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -1414,7 +1415,7 @@ static int ipp_send_event(struct exynos_drm_ippdrv 
*ippdrv,
struct drm_exynos_ipp_queue_buf qbuf;
struct drm_exynos_ipp_send_event *e;
struct list_head *head;
-   struct timeval now;
+   struct timespec64 now;
unsigned long flags;
u32 tbuf_id[EXYNOS_DRM_OPS_MAX] = {0, };
int ret, i;
@@ -1518,10 +1519,11 @@ static int ipp_send_event(struct exynos_drm_ippdrv 
*ippdrv,
e = list_first_entry(&c_node->event_list,
struct drm_exynos_ipp_send_event, base.link);
 
-   do_gettimeofday(&now);
-   DRM_DEBUG_KMS("tv_sec[%ld]tv_usec[%ld]\n", now.tv_sec, now.tv_usec);
+   getnstimeofday64(&now);
+   DRM_DEBUG_KMS("tv_sec[%lld]tv_usec[%lld]\n", now.tv_sec, (now.tv_nsec /
+   NSEC_PER_SEC));
e->event.tv_sec = now.tv_sec;
-   e->event.tv_usec = now.tv_usec;
+   e->event.tv_usec = now.tv_nsec / NSEC_PER_SEC;
e->event.prop_id = property->prop_id;
 
/* set buffer id about source destination */
-- 
2.2.0.rc0.207.ga3a616c

___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [PATCH] drm/exynos: g2d: Replace struct timeval usage

2015-05-31 Thread Tina Ruchandani
'struct timeval' uses a 32-bit seconds representation which
will overflow in the year 2038 and beyond. This patch
replaces the use of struct timeval with struct timespec64
which uses a 64-bit seconds representation and is y2038 safe.

The patch is part of a larger effort to remove all 32-bit
timekeeping variables (timeval, time_t and timespec) from the
kernel.

Signed-off-by: Tina Ruchandani 
---
 drivers/gpu/drm/exynos/exynos_drm_g2d.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/exynos/exynos_drm_g2d.c 
b/drivers/gpu/drm/exynos/exynos_drm_g2d.c
index 81a2508..69e236f 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_g2d.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_g2d.c
@@ -15,6 +15,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -889,7 +890,7 @@ static void g2d_finish_event(struct g2d_data *g2d, u32 
cmdlist_no)
struct drm_device *drm_dev = g2d->subdrv.drm_dev;
struct g2d_runqueue_node *runqueue_node = g2d->runqueue_node;
struct drm_exynos_pending_g2d_event *e;
-   struct timeval now;
+   struct timespec64 now;
unsigned long flags;
 
if (list_empty(&runqueue_node->event_list))
@@ -898,9 +899,9 @@ static void g2d_finish_event(struct g2d_data *g2d, u32 
cmdlist_no)
e = list_first_entry(&runqueue_node->event_list,
 struct drm_exynos_pending_g2d_event, base.link);
 
-   do_gettimeofday(&now);
+   getnstimeofday64(&now);
e->event.tv_sec = now.tv_sec;
-   e->event.tv_usec = now.tv_usec;
+   e->event.tv_usec = (now.tv_nsec / NSEC_PER_USEC);
e->event.cmdlist_no = cmdlist_no;
 
spin_lock_irqsave(&drm_dev->event_lock, flags);
-- 
2.2.0.rc0.207.ga3a616c

___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [PATCH v4] isdn: Use ktime_t instead of 'struct timeval'

2015-05-31 Thread Tina Ruchandani
'struct timeval' uses 32-bit representation for seconds which will
overflow in year 2038 and beyond. mISDN/clock.c needs to compute and
store elapsed time in intervals of 125 microseconds. This patch replaces
the usage of 'struct timeval' with 64-bit ktime_t which is y2038 safe.
The patch also replaces do_gettimeofday (wall-clock time) with ktime_get
(monotonic time) since we only care about elapsed time here.

Signed-off-by: Tina Ruchandani 
Suggested-by: Arnd Bergmnann 
--
Changes in v4: 
- Fix compile error (NS_PER_SEC -> NSEC_PER_SEC)
Changes in v3:
- Use division scheme suggested by Arnd Bergmann to avoid
  a (64-bit variable) / (32-bit variable) expression.
Changes in v2:
- Avoid possible truncation bug caused by assigning ktime_us_delta
output to a 16-bit number.
- Use ktime_us_delta, more concise than a combination of ktime_sub
and ktime_to_us.
---
 drivers/isdn/mISDN/clock.c | 56 ++
 include/linux/mISDNif.h|  2 +-
 2 files changed, 23 insertions(+), 35 deletions(-)

diff --git a/drivers/isdn/mISDN/clock.c b/drivers/isdn/mISDN/clock.c
index 693fb7c..409c508 100644
--- a/drivers/isdn/mISDN/clock.c
+++ b/drivers/isdn/mISDN/clock.c
@@ -37,6 +37,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include "core.h"
@@ -45,7 +46,7 @@ static u_int *debug;
 static LIST_HEAD(iclock_list);
 static DEFINE_RWLOCK(iclock_lock);
 static u16 iclock_count;   /* counter of last clock */
-static struct timeval iclock_tv;   /* time stamp of last clock */
+static ktime_t iclock_tv;  /* time stamp of last clock */
 static int iclock_tv_valid;/* already received one timestamp */
 static struct mISDNclock *iclock_current;
 
@@ -53,7 +54,7 @@ void
 mISDN_init_clock(u_int *dp)
 {
debug = dp;
-   do_gettimeofday(&iclock_tv);
+   iclock_tv = ktime_get();
 }
 
 static void
@@ -139,12 +140,11 @@ mISDN_unregister_clock(struct mISDNclock *iclock)
 EXPORT_SYMBOL(mISDN_unregister_clock);
 
 void
-mISDN_clock_update(struct mISDNclock *iclock, int samples, struct timeval *tv)
+mISDN_clock_update(struct mISDNclock *iclock, int samples, ktime_t *tv)
 {
u_long  flags;
-   struct timeval  tv_now;
-   time_t  elapsed_sec;
-   int elapsed_8000th;
+   ktime_t tv_now;
+   u16 delta;
 
write_lock_irqsave(&iclock_lock, flags);
if (iclock_current != iclock) {
@@ -160,28 +160,22 @@ mISDN_clock_update(struct mISDNclock *iclock, int 
samples, struct timeval *tv)
/* increment sample counter by given samples */
iclock_count += samples;
if (tv) { /* tv must be set, if function call is delayed */
-   iclock_tv.tv_sec = tv->tv_sec;
-   iclock_tv.tv_usec = tv->tv_usec;
-   } else
-   do_gettimeofday(&iclock_tv);
+   iclock_tv = *tv;
+   } else {
+   iclock_tv = ktime_get();
+   }
} else {
/* calc elapsed time by system clock */
if (tv) { /* tv must be set, if function call is delayed */
-   tv_now.tv_sec = tv->tv_sec;
-   tv_now.tv_usec = tv->tv_usec;
-   } else
-   do_gettimeofday(&tv_now);
-   elapsed_sec = tv_now.tv_sec - iclock_tv.tv_sec;
-   elapsed_8000th = (tv_now.tv_usec / 125)
-   - (iclock_tv.tv_usec / 125);
-   if (elapsed_8000th < 0) {
-   elapsed_sec -= 1;
-   elapsed_8000th += 8000;
+   tv_now = *tv;
+   } else {
+   tv_now = ktime_get();
}
+   delta = ktime_divns(ktime_sub(tv_now, iclock_tv),
+   (NSEC_PER_SEC / 8000));
/* add elapsed time to counter and set new timestamp */
-   iclock_count += elapsed_sec * 8000 + elapsed_8000th;
-   iclock_tv.tv_sec = tv_now.tv_sec;
-   iclock_tv.tv_usec = tv_now.tv_usec;
+   iclock_count += delta;
+   iclock_tv = tv_now;
iclock_tv_valid = 1;
if (*debug & DEBUG_CLOCK)
printk("Received first clock from source '%s'.\n",
@@ -195,22 +189,16 @@ unsigned short
 mISDN_clock_get(void)
 {
u_long  flags;
-   struct timeval  tv_now;
-   time_t  elapsed_sec;
-   int elapsed_8000th;
+   ktime_t tv_now;
+   u16 delta;
u16 count;
 
read_lock_irqsave(&iclock_lock, flags);
/* calc elapsed time by system clock */
-   do_gettimeofday(&tv_now);
-   elapsed_sec = tv_now

[Y2038] [PATCH v3] [media] dvb-frontend: Replace timeval with ktime_t

2015-05-31 Thread Tina Ruchandani
struct timeval uses a 32-bit seconds representation which will
overflow in the year 2038 and beyond. This patch replaces
the usage of struct timeval with ktime_t which is a 64-bit
timestamp and is year 2038 safe.
This patch is part of a larger attempt to remove all instances
of 32-bit timekeeping variables (timeval, timespec, time_t)
which are not year 2038 safe, from the kernel.

Signed-off-by: Tina Ruchandani 
Suggested-by: Arnd Bergmann 

--
Changes in v3:
- Clean up commit message.
- Use ktime_us_delta which is more concise than the combination
of ktime_sub and ktime_to_us
Changes in v2:
- Use the more concise ktime_us_delta
- Preserve the waketime argument in dvb_frontend_sleep_until as
a pointer, fixes bug introduced in v1 of the patch where the caller
doesn't get its timestamp modified.

Signed-off-by: Tina Ruchandani 
---
 drivers/media/dvb-core/dvb_frontend.c | 41 ++-
 drivers/media/dvb-core/dvb_frontend.h |  3 +--
 drivers/media/dvb-frontends/stv0299.c | 12 +-
 3 files changed, 19 insertions(+), 37 deletions(-)

diff --git a/drivers/media/dvb-core/dvb_frontend.c 
b/drivers/media/dvb-core/dvb_frontend.c
index 882ca41..69be73c 100644
--- a/drivers/media/dvb-core/dvb_frontend.c
+++ b/drivers/media/dvb-core/dvb_frontend.c
@@ -40,6 +40,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include "dvb_frontend.h"
@@ -889,42 +890,21 @@ static void dvb_frontend_stop(struct dvb_frontend *fe)
fepriv->thread);
 }
 
-s32 timeval_usec_diff(struct timeval lasttime, struct timeval curtime)
-{
-   return ((curtime.tv_usec < lasttime.tv_usec) ?
-   100 - lasttime.tv_usec + curtime.tv_usec :
-   curtime.tv_usec - lasttime.tv_usec);
-}
-EXPORT_SYMBOL(timeval_usec_diff);
-
-static inline void timeval_usec_add(struct timeval *curtime, u32 add_usec)
-{
-   curtime->tv_usec += add_usec;
-   if (curtime->tv_usec >= 100) {
-   curtime->tv_usec -= 100;
-   curtime->tv_sec++;
-   }
-}
-
 /*
  * Sleep until gettimeofday() > waketime + add_usec
  * This needs to be as precise as possible, but as the delay is
  * usually between 2ms and 32ms, it is done using a scheduled msleep
  * followed by usleep (normally a busy-wait loop) for the remainder
  */
-void dvb_frontend_sleep_until(struct timeval *waketime, u32 add_usec)
+void dvb_frontend_sleep_until(ktime_t *waketime, u32 add_usec)
 {
-   struct timeval lasttime;
s32 delta, newdelta;
 
-   timeval_usec_add(waketime, add_usec);
-
-   do_gettimeofday(&lasttime);
-   delta = timeval_usec_diff(lasttime, *waketime);
+   ktime_add_us(*waketime, add_usec);
+   delta = ktime_us_delta(ktime_get_real(), *waketime);
if (delta > 2500) {
msleep((delta - 1500) / 1000);
-   do_gettimeofday(&lasttime);
-   newdelta = timeval_usec_diff(lasttime, *waketime);
+   newdelta = ktime_us_delta(ktime_get_real(), *waketime);
delta = (newdelta > delta) ? 0 : newdelta;
}
if (delta > 0)
@@ -2458,13 +2438,13 @@ static int dvb_frontend_ioctl_legacy(struct file *file,
 * include the initialization or start bit
 */
unsigned long swcmd = ((unsigned long) parg) << 1;
-   struct timeval nexttime;
-   struct timeval tv[10];
+   ktime_t nexttime;
+   ktime_t tv[10];
int i;
u8 last = 1;
if (dvb_frontend_debug)
printk("%s switch command: 0x%04lx\n", 
__func__, swcmd);
-   do_gettimeofday(&nexttime);
+   nexttime = ktime_get_real();
if (dvb_frontend_debug)
tv[0] = nexttime;
/* before sending a command, initialize by sending
@@ -2475,7 +2455,7 @@ static int dvb_frontend_ioctl_legacy(struct file *file,
 
for (i = 0; i < 9; i++) {
if (dvb_frontend_debug)
-   do_gettimeofday(&tv[i + 1]);
+   tv[i+1] = ktime_get_real();
if ((swcmd & 0x01) != last) {
/* set voltage to (last ? 13V : 18V) */
fe->ops.set_voltage(fe, (last) ? 
SEC_VOLTAGE_13 : SEC_VOLTAGE_18);
@@ -2489,7 +2469,8 @@ static int dvb_frontend_ioctl_legacy(struct file *file,
printk("%s(%d): switch delay (should be 32k 
followed by all 8k\n",
__func__, fe->dvb->num);
for (i

Re: [Y2038] [PATCH v2] [media] dvb-frontend: Replace timeval with ktime_t

2015-05-30 Thread Tina Ruchandani
> --
> Changes in v2:
> - Use the more concise ktime_us_delta

Oops, please ignore this patch and please consider the v3 sent out
immediately after instead.

Tina
___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


Re: [Y2038] [PATCH v3] isdn: Use ktime_t instead of 'struct timeval'

2015-05-30 Thread Tina Ruchandani
>
> This doesn't compile:
>

Oops, I sent an older version of the patch with a typo. I've correct
this in a v4. (NS_PER_SEC -> NSEC_PER_SEC). Thanks for taking a look
at this.

Tina
___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [PATCH v2] [media] dvb-frontend: Replace timeval with ktime_t

2015-05-30 Thread Tina Ruchandani
struct timeval uses a 32-bit seconds representation which will
overflow in the year 2038 and beyond. This patch replaces
the usage of struct timeval with ktime_t which is a 64-bit
timestamp and is year 2038 safe.
This patch is part of a larger attempt to remove all instances
of 32-bit timekeeping variables (timeval, timespec, time_t)
which are not year 2038 safe, from the kernel.
The patch is a work-in-progress - correctness of the following
changes is unclear:
(a) Usage of timeval_usec_diff - The function seems to subtract
usec values without caring about the difference of the seconds field.
There may be an implicit assumption in the original code that the
time delta is always of the order of microseconds.
The patch replaces the usage of timeval_usec_diff with
ktime_to_us(ktime_sub()) which computes the real timestamp difference,
not just the difference in the usec field.
(b) printk diffing the tv[i] and tv[i-1] values. The original
printk statement seems to get the order wrong. This patch preserves
that order.

Signed-off-by: Tina Ruchandani 
Suggested-by: Arnd Bergmann 

--
Changes in v2:
- Use the more concise ktime_us_delta
- Preserve the waketime argument in dvb_frontend_sleep_until as
a pointer, fixes bug introduced in v1 of the patch where the caller
doesn't get its timestamp modified.
---
 drivers/media/dvb-core/dvb_frontend.c | 40 +--
 drivers/media/dvb-core/dvb_frontend.h |  3 +--
 drivers/media/dvb-frontends/stv0299.c | 11 +-
 3 files changed, 17 insertions(+), 37 deletions(-)

diff --git a/drivers/media/dvb-core/dvb_frontend.c 
b/drivers/media/dvb-core/dvb_frontend.c
index 882ca41..c110e37 100644
--- a/drivers/media/dvb-core/dvb_frontend.c
+++ b/drivers/media/dvb-core/dvb_frontend.c
@@ -40,6 +40,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include "dvb_frontend.h"
@@ -889,42 +890,21 @@ static void dvb_frontend_stop(struct dvb_frontend *fe)
fepriv->thread);
 }
 
-s32 timeval_usec_diff(struct timeval lasttime, struct timeval curtime)
-{
-   return ((curtime.tv_usec < lasttime.tv_usec) ?
-   100 - lasttime.tv_usec + curtime.tv_usec :
-   curtime.tv_usec - lasttime.tv_usec);
-}
-EXPORT_SYMBOL(timeval_usec_diff);
-
-static inline void timeval_usec_add(struct timeval *curtime, u32 add_usec)
-{
-   curtime->tv_usec += add_usec;
-   if (curtime->tv_usec >= 100) {
-   curtime->tv_usec -= 100;
-   curtime->tv_sec++;
-   }
-}
-
 /*
  * Sleep until gettimeofday() > waketime + add_usec
  * This needs to be as precise as possible, but as the delay is
  * usually between 2ms and 32ms, it is done using a scheduled msleep
  * followed by usleep (normally a busy-wait loop) for the remainder
  */
-void dvb_frontend_sleep_until(struct timeval *waketime, u32 add_usec)
+void dvb_frontend_sleep_until(ktime_t *waketime, u32 add_usec)
 {
-   struct timeval lasttime;
s32 delta, newdelta;
 
-   timeval_usec_add(waketime, add_usec);
-
-   do_gettimeofday(&lasttime);
-   delta = timeval_usec_diff(lasttime, *waketime);
+   ktime_add_us(*waketime, add_usec);
+   delta = ktime_us_delta(ktime_get_real(), *waketime);
if (delta > 2500) {
msleep((delta - 1500) / 1000);
-   do_gettimeofday(&lasttime);
-   newdelta = timeval_usec_diff(lasttime, *waketime);
+   newdelta = ktime_us_delta(ktime_get_real(), *waketime);
delta = (newdelta > delta) ? 0 : newdelta;
}
if (delta > 0)
@@ -2458,13 +2438,13 @@ static int dvb_frontend_ioctl_legacy(struct file *file,
 * include the initialization or start bit
 */
unsigned long swcmd = ((unsigned long) parg) << 1;
-   struct timeval nexttime;
-   struct timeval tv[10];
+   ktime_t nexttime;
+   ktime_t tv[10];
int i;
u8 last = 1;
if (dvb_frontend_debug)
printk("%s switch command: 0x%04lx\n", 
__func__, swcmd);
-   do_gettimeofday(&nexttime);
+   nexttime = ktime_get_real();
if (dvb_frontend_debug)
tv[0] = nexttime;
/* before sending a command, initialize by sending
@@ -2475,7 +2455,7 @@ static int dvb_frontend_ioctl_legacy(struct file *file,
 
for (i = 0; i < 9; i++) {
if (dvb_frontend_debug)
-   do_gettimeofday(&tv[i + 1]);
+   tv[i+1] = ktime_get_real();
if ((swcmd & 0x01)

[Y2038] [PATCH v3] isdn: Use ktime_t instead of 'struct timeval'

2015-05-26 Thread Tina Ruchandani
'struct timeval' uses 32-bit representation for seconds which will
overflow in year 2038 and beyond. mISDN/clock.c needs to compute and
store elapsed time in intervals of 125 microseconds. This patch replaces
the usage of 'struct timeval' with 64-bit ktime_t which is y2038 safe.
The patch also replaces do_gettimeofday() (wall-clock time) with 
ktime_get() (monotonic time) since we only care about elapsed time here.

Signed-off-by: Tina Ruchandani 
Suggested-by: Arnd Bergmnann 
--
Changes in v3:
- Use division scheme suggested by Arnd Bergmann to avoid
  a (64-bit variable) / (32-bit variable) expression.
Changes in v2:
- Avoid possible truncation bug caused by assigning ktime_us_delta
output to a 16-bit number.
- Use ktime_us_delta, more concise than a combination of ktime_sub
and ktime_to_us.
---
 drivers/isdn/mISDN/clock.c | 56 ++
 include/linux/mISDNif.h|  2 +-
 2 files changed, 23 insertions(+), 35 deletions(-)

diff --git a/drivers/isdn/mISDN/clock.c b/drivers/isdn/mISDN/clock.c
index 693fb7c..0ea7e2f 100644
--- a/drivers/isdn/mISDN/clock.c
+++ b/drivers/isdn/mISDN/clock.c
@@ -37,6 +37,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include "core.h"
@@ -45,7 +46,7 @@ static u_int *debug;
 static LIST_HEAD(iclock_list);
 static DEFINE_RWLOCK(iclock_lock);
 static u16 iclock_count;   /* counter of last clock */
-static struct timeval iclock_tv;   /* time stamp of last clock */
+static ktime_t iclock_tv;  /* time stamp of last clock */
 static int iclock_tv_valid;/* already received one timestamp */
 static struct mISDNclock *iclock_current;
 
@@ -53,7 +54,7 @@ void
 mISDN_init_clock(u_int *dp)
 {
debug = dp;
-   do_gettimeofday(&iclock_tv);
+   iclock_tv = ktime_get();
 }
 
 static void
@@ -139,12 +140,11 @@ mISDN_unregister_clock(struct mISDNclock *iclock)
 EXPORT_SYMBOL(mISDN_unregister_clock);
 
 void
-mISDN_clock_update(struct mISDNclock *iclock, int samples, struct timeval *tv)
+mISDN_clock_update(struct mISDNclock *iclock, int samples, ktime_t *tv)
 {
u_long  flags;
-   struct timeval  tv_now;
-   time_t  elapsed_sec;
-   int elapsed_8000th;
+   ktime_t tv_now;
+   u16 delta;
 
write_lock_irqsave(&iclock_lock, flags);
if (iclock_current != iclock) {
@@ -160,28 +160,22 @@ mISDN_clock_update(struct mISDNclock *iclock, int 
samples, struct timeval *tv)
/* increment sample counter by given samples */
iclock_count += samples;
if (tv) { /* tv must be set, if function call is delayed */
-   iclock_tv.tv_sec = tv->tv_sec;
-   iclock_tv.tv_usec = tv->tv_usec;
-   } else
-   do_gettimeofday(&iclock_tv);
+   iclock_tv = *tv;
+   } else {
+   iclock_tv = ktime_get();
+   }
} else {
/* calc elapsed time by system clock */
if (tv) { /* tv must be set, if function call is delayed */
-   tv_now.tv_sec = tv->tv_sec;
-   tv_now.tv_usec = tv->tv_usec;
-   } else
-   do_gettimeofday(&tv_now);
-   elapsed_sec = tv_now.tv_sec - iclock_tv.tv_sec;
-   elapsed_8000th = (tv_now.tv_usec / 125)
-   - (iclock_tv.tv_usec / 125);
-   if (elapsed_8000th < 0) {
-   elapsed_sec -= 1;
-   elapsed_8000th += 8000;
+   tv_now = *tv;
+   } else {
+   tv_now = ktime_get();
}
+   delta = ktime_divns(ktime_sub(tv_now, iclock_tv),
+   (NS_PER_SEC / 8000));
/* add elapsed time to counter and set new timestamp */
-   iclock_count += elapsed_sec * 8000 + elapsed_8000th;
-   iclock_tv.tv_sec = tv_now.tv_sec;
-   iclock_tv.tv_usec = tv_now.tv_usec;
+   iclock_count += delta;
+   iclock_tv = tv_now;
iclock_tv_valid = 1;
if (*debug & DEBUG_CLOCK)
printk("Received first clock from source '%s'.\n",
@@ -195,22 +189,16 @@ unsigned short
 mISDN_clock_get(void)
 {
u_long  flags;
-   struct timeval  tv_now;
-   time_t  elapsed_sec;
-   int elapsed_8000th;
+   ktime_t tv_now;
+   u16 delta;
u16 count;
 
read_lock_irqsave(&iclock_lock, flags);
/* calc elapsed time by system clock */
-   do_gettimeofday(&tv_now);
-   elapsed_sec = tv_now.tv_sec - iclock_tv.tv_sec;
-   elapse

[Y2038] [PATCH] fbdev: radeon: Remove 'struct timeval' usage

2015-05-24 Thread Tina Ruchandani
'struct timeval' uses a 32-bit representation for the
seconds field which will overflow in the year 2038 and beyond.
This patch replaces the usage of 'struct timeval' with
ktime_t which uses a 64-bit time representation and does not
suffer from the y2038 problem. This patch is part of a larger
effort to remove all instances of 'struct timeval', 'struct
timespec', time_t and other 32-bit timekeeping variables
from the kernel.
The patch also replaces the use of real time (do_gettimeofday)
with monotonic time (ktime_get).

Signed-off-by: Tina Ruchandani 
---
 drivers/video/fbdev/aty/radeon_base.c | 29 ++---
 1 file changed, 14 insertions(+), 15 deletions(-)

diff --git a/drivers/video/fbdev/aty/radeon_base.c 
b/drivers/video/fbdev/aty/radeon_base.c
index 01237c8..9747e9e 100644
--- a/drivers/video/fbdev/aty/radeon_base.c
+++ b/drivers/video/fbdev/aty/radeon_base.c
@@ -64,6 +64,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -461,8 +462,8 @@ static int radeon_probe_pll_params(struct radeonfb_info 
*rinfo)
int hTotal, vTotal, num, denom, m, n;
unsigned long long hz, vclk;
long xtal;
-   struct timeval start_tv, stop_tv;
-   long total_secs, total_usecs;
+   ktime_t start, stop;
+   s64 delta;
int i;
 
/* Ugh, we cut interrupts, bad bad bad, but we want some precision
@@ -478,7 +479,7 @@ static int radeon_probe_pll_params(struct radeonfb_info 
*rinfo)
if (((INREG(CRTC_VLINE_CRNT_VLINE) >> 16) & 0x3ff) == 0)
break;
 
-   do_gettimeofday(&start_tv);
+   start = ktime_get();
 
for(i=0; i<100; i++)
if (((INREG(CRTC_VLINE_CRNT_VLINE) >> 16) & 0x3ff) != 0)
@@ -487,20 +488,18 @@ static int radeon_probe_pll_params(struct radeonfb_info 
*rinfo)
for(i=0; i<100; i++)
if (((INREG(CRTC_VLINE_CRNT_VLINE) >> 16) & 0x3ff) == 0)
break;
-   
-   do_gettimeofday(&stop_tv);
-   
+
+   stop = ktime_get();
+
local_irq_enable();
 
-   total_secs = stop_tv.tv_sec - start_tv.tv_sec;
-   if (total_secs > 10)
+   delta = ktime_us_delta(stop, start);
+
+   /* Return -1 if more than 10 seconds have elapsed */
+   if (delta > (10*100))
return -1;
-   total_usecs = stop_tv.tv_usec - start_tv.tv_usec;
-   total_usecs += total_secs * 100;
-   if (total_usecs < 0)
-   total_usecs = -total_usecs;
-   hz = 100/total_usecs;
- 
+   hz = 100/delta;
+
hTotal = ((INREG(CRTC_H_TOTAL_DISP) & 0x1ff) + 1) * 8;
vTotal = ((INREG(CRTC_V_TOTAL_DISP) & 0x3ff) + 1);
vclk = (long long)hTotal * (long long)vTotal * hz;
@@ -548,7 +547,7 @@ static int radeon_probe_pll_params(struct radeonfb_info 
*rinfo)
denom *= 3;
break;
case 6:
-   denom *= 6;   
+   denom *= 6;
break;
case 7:
denom *= 12;
-- 
2.2.0.rc0.207.ga3a616c

___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [PATCH v2] [media] dvb-frontend: Replace timeval with ktime_t

2015-05-19 Thread Tina Ruchandani
struct timeval uses a 32-bit seconds representation which will
overflow in the year 2038 and beyond. This patch replaces
the usage of struct timeval with ktime_t which is a 64-bit
timestamp and is year 2038 safe.
This patch is part of a larger attempt to remove all instances
of 32-bit timekeeping variables (timeval, timespec, time_t)
which are not year 2038 safe, from the kernel.
The patch is a work-in-progress - correctness of the following
changes is unclear:
(a) Usage of timeval_usec_diff - The function seems to subtract
usec values without caring about the difference of the seconds field.
There may be an implicit assumption in the original code that the
time delta is always of the order of microseconds.
The patch replaces the usage of timeval_usec_diff with
ktime_to_us(ktime_sub()) which computes the real timestamp difference,
not just the difference in the usec field.
(b) printk diffing the tv[i] and tv[i-1] values. The original
printk statement seems to get the order wrong. This patch preserves
that order.

Signed-off-by: Tina Ruchandani 
Suggested-by: Arnd Bergmann 

--
Changes in v2:
- Use the more concise ktime_us_delta
- Preserve the waketime argument in dvb_frontend_sleep_until as
a pointer, fixes bug introduced in v1 of the patch where the caller
doesn't get its timestamp modified.
---
 drivers/media/dvb-core/dvb_frontend.c | 40 +--
 drivers/media/dvb-core/dvb_frontend.h |  3 +--
 drivers/media/dvb-frontends/stv0299.c | 11 +-
 3 files changed, 17 insertions(+), 37 deletions(-)

diff --git a/drivers/media/dvb-core/dvb_frontend.c 
b/drivers/media/dvb-core/dvb_frontend.c
index 882ca41..c110e37 100644
--- a/drivers/media/dvb-core/dvb_frontend.c
+++ b/drivers/media/dvb-core/dvb_frontend.c
@@ -40,6 +40,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include "dvb_frontend.h"
@@ -889,42 +890,21 @@ static void dvb_frontend_stop(struct dvb_frontend *fe)
fepriv->thread);
 }
 
-s32 timeval_usec_diff(struct timeval lasttime, struct timeval curtime)
-{
-   return ((curtime.tv_usec < lasttime.tv_usec) ?
-   100 - lasttime.tv_usec + curtime.tv_usec :
-   curtime.tv_usec - lasttime.tv_usec);
-}
-EXPORT_SYMBOL(timeval_usec_diff);
-
-static inline void timeval_usec_add(struct timeval *curtime, u32 add_usec)
-{
-   curtime->tv_usec += add_usec;
-   if (curtime->tv_usec >= 100) {
-   curtime->tv_usec -= 100;
-   curtime->tv_sec++;
-   }
-}
-
 /*
  * Sleep until gettimeofday() > waketime + add_usec
  * This needs to be as precise as possible, but as the delay is
  * usually between 2ms and 32ms, it is done using a scheduled msleep
  * followed by usleep (normally a busy-wait loop) for the remainder
  */
-void dvb_frontend_sleep_until(struct timeval *waketime, u32 add_usec)
+void dvb_frontend_sleep_until(ktime_t *waketime, u32 add_usec)
 {
-   struct timeval lasttime;
s32 delta, newdelta;
 
-   timeval_usec_add(waketime, add_usec);
-
-   do_gettimeofday(&lasttime);
-   delta = timeval_usec_diff(lasttime, *waketime);
+   ktime_add_us(*waketime, add_usec);
+   delta = ktime_us_delta(ktime_get_real(), *waketime);
if (delta > 2500) {
msleep((delta - 1500) / 1000);
-   do_gettimeofday(&lasttime);
-   newdelta = timeval_usec_diff(lasttime, *waketime);
+   newdelta = ktime_us_delta(ktime_get_real(), *waketime);
delta = (newdelta > delta) ? 0 : newdelta;
}
if (delta > 0)
@@ -2458,13 +2438,13 @@ static int dvb_frontend_ioctl_legacy(struct file *file,
 * include the initialization or start bit
 */
unsigned long swcmd = ((unsigned long) parg) << 1;
-   struct timeval nexttime;
-   struct timeval tv[10];
+   ktime_t nexttime;
+   ktime_t tv[10];
int i;
u8 last = 1;
if (dvb_frontend_debug)
printk("%s switch command: 0x%04lx\n", 
__func__, swcmd);
-   do_gettimeofday(&nexttime);
+   nexttime = ktime_get_real();
if (dvb_frontend_debug)
tv[0] = nexttime;
/* before sending a command, initialize by sending
@@ -2475,7 +2455,7 @@ static int dvb_frontend_ioctl_legacy(struct file *file,
 
for (i = 0; i < 9; i++) {
if (dvb_frontend_debug)
-   do_gettimeofday(&tv[i + 1]);
+   tv[i+1] = ktime_get_real();
if ((swcmd & 0x01)

[Y2038] [PATCH v2] xen/pcifront: Remove usage of struct timeval

2015-05-18 Thread Tina Ruchandani
struct timeval uses a 32-bit field for representing seconds,
which will overflow in the year 2038 and beyond. This patch replaces
struct timeval with 64-bit ktime_t which is 2038 safe.
The patch is part of a larger effort to remove instances of
32-bit timekeeping variables (timeval, time_t and timespec)
from the kernel.

Signed-off-by: Tina Ruchandani 
Suggested-by: Arnd Bergmann 
--
Changes in v2:
- Use monotonic time (ktime_get_ns()) instead of real time
since we only care about elapsed delta here.
- Use macro ktime_get_ns() instead of getting ktime_t and
converting it to ns.
---
 drivers/pci/xen-pcifront.c | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/pci/xen-pcifront.c b/drivers/pci/xen-pcifront.c
index 7cfd2db..c4796c8 100644
--- a/drivers/pci/xen-pcifront.c
+++ b/drivers/pci/xen-pcifront.c
@@ -20,6 +20,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include 
@@ -115,7 +116,6 @@ static int do_pci_op(struct pcifront_device *pdev, struct 
xen_pci_op *op)
evtchn_port_t port = pdev->evtchn;
unsigned irq = pdev->irq;
s64 ns, ns_timeout;
-   struct timeval tv;
 
spin_lock_irqsave(&pdev->sh_info_lock, irq_flags);
 
@@ -132,8 +132,7 @@ static int do_pci_op(struct pcifront_device *pdev, struct 
xen_pci_op *op)
 * (in the latter case we end up continually re-executing poll() with a
 * timeout in the past). 1s difference gives plenty of slack for error.
 */
-   do_gettimeofday(&tv);
-   ns_timeout = timeval_to_ns(&tv) + 2 * (s64)NSEC_PER_SEC;
+   ns_timeout = ktime_get_ns() + 2 * (s64)NSEC_PER_SEC;
 
xen_clear_irq_pending(irq);
 
@@ -141,8 +140,7 @@ static int do_pci_op(struct pcifront_device *pdev, struct 
xen_pci_op *op)
(unsigned long *)&pdev->sh_info->flags)) {
xen_poll_irq_timeout(irq, jiffies + 3*HZ);
xen_clear_irq_pending(irq);
-   do_gettimeofday(&tv);
-   ns = timeval_to_ns(&tv);
+   ns = ktime_get_ns();
if (ns > ns_timeout) {
dev_err(&pdev->xdev->dev,
"pciback not responding!!!\n");
-- 
2.2.0.rc0.207.ga3a616c

___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [PATCH] xen/pcifront: Remove usage of struct timeval

2015-05-10 Thread Tina Ruchandani
struct timeval uses a 32-bit field for representing seconds,
which will overflow in the year 2038 and beyond. This patch replaces
struct timeval with 64-bit ktime_t which is 2038 safe.
The patch is part of a larger effort to remove instances of
32-bit timekeeping variables (timeval, time_t and timespec)
from the kernel.

Signed-off-by: Tina Ruchandani 
---
 drivers/pci/xen-pcifront.c | 11 ++-
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/pci/xen-pcifront.c b/drivers/pci/xen-pcifront.c
index 7cfd2db..43d1d6c 100644
--- a/drivers/pci/xen-pcifront.c
+++ b/drivers/pci/xen-pcifront.c
@@ -20,6 +20,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include 
@@ -115,7 +116,7 @@ static int do_pci_op(struct pcifront_device *pdev, struct 
xen_pci_op *op)
evtchn_port_t port = pdev->evtchn;
unsigned irq = pdev->irq;
s64 ns, ns_timeout;
-   struct timeval tv;
+   ktime_t tv;
 
spin_lock_irqsave(&pdev->sh_info_lock, irq_flags);
 
@@ -132,8 +133,8 @@ static int do_pci_op(struct pcifront_device *pdev, struct 
xen_pci_op *op)
 * (in the latter case we end up continually re-executing poll() with a
 * timeout in the past). 1s difference gives plenty of slack for error.
 */
-   do_gettimeofday(&tv);
-   ns_timeout = timeval_to_ns(&tv) + 2 * (s64)NSEC_PER_SEC;
+   tv = ktime_get_real();
+   ns_timeout = ktime_to_ns(tv) + 2 * (s64)NSEC_PER_SEC;
 
xen_clear_irq_pending(irq);
 
@@ -141,8 +142,8 @@ static int do_pci_op(struct pcifront_device *pdev, struct 
xen_pci_op *op)
(unsigned long *)&pdev->sh_info->flags)) {
xen_poll_irq_timeout(irq, jiffies + 3*HZ);
xen_clear_irq_pending(irq);
-   do_gettimeofday(&tv);
-   ns = timeval_to_ns(&tv);
+   tv = ktime_get_real();
+   ns = ktime_to_ns(tv);
if (ns > ns_timeout) {
dev_err(&pdev->xdev->dev,
"pciback not responding!!!\n");
-- 
2.2.0.rc0.207.ga3a616c

___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [PATCH] [media] dvb-frontend: Replace timeval with ktime_t

2015-05-10 Thread Tina Ruchandani
struct timeval uses a 32-bit seconds representation which will
overflow in the year 2038 and beyond. This patch replaces
the usage of struct timeval with ktime_t which is a 64-bit
timestamp and is year 2038 safe.
This patch is part of a larger attempt to remove all instances
of 32-bit timekeeping variables (timeval, timespec, time_t)
which are not year 2038 safe, from the kernel.
The patch is a work-in-progress - correctness of the following
changes is unclear:
(a) Usage of timeval_usec_diff - The function seems to subtract
usec values without caring about the difference of the seconds field.
There may be an implicit assumption in the original code that the
time delta is always of the order of microseconds.
The patch replaces the usage of timeval_usec_diff with
ktime_to_us(ktime_sub()) which computes the real timestamp difference,
not just the difference in the usec field.
(b) printk diffing the tv[i] and tv[i-1] values. The original
printk statement seems to get the order wrong. This patch preserves
that order.

Signed-off-by: Tina Ruchandani 
---
 drivers/media/dvb-core/dvb_frontend.c | 46 ---
 drivers/media/dvb-core/dvb_frontend.h |  3 +--
 drivers/media/dvb-frontends/stv0299.c | 15 ++--
 3 files changed, 24 insertions(+), 40 deletions(-)

diff --git a/drivers/media/dvb-core/dvb_frontend.c 
b/drivers/media/dvb-core/dvb_frontend.c
index 882ca41..48c3daf 100644
--- a/drivers/media/dvb-core/dvb_frontend.c
+++ b/drivers/media/dvb-core/dvb_frontend.c
@@ -40,6 +40,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include "dvb_frontend.h"
@@ -889,42 +890,25 @@ static void dvb_frontend_stop(struct dvb_frontend *fe)
fepriv->thread);
 }
 
-s32 timeval_usec_diff(struct timeval lasttime, struct timeval curtime)
-{
-   return ((curtime.tv_usec < lasttime.tv_usec) ?
-   100 - lasttime.tv_usec + curtime.tv_usec :
-   curtime.tv_usec - lasttime.tv_usec);
-}
-EXPORT_SYMBOL(timeval_usec_diff);
-
-static inline void timeval_usec_add(struct timeval *curtime, u32 add_usec)
-{
-   curtime->tv_usec += add_usec;
-   if (curtime->tv_usec >= 100) {
-   curtime->tv_usec -= 100;
-   curtime->tv_sec++;
-   }
-}
-
 /*
  * Sleep until gettimeofday() > waketime + add_usec
  * This needs to be as precise as possible, but as the delay is
  * usually between 2ms and 32ms, it is done using a scheduled msleep
  * followed by usleep (normally a busy-wait loop) for the remainder
  */
-void dvb_frontend_sleep_until(struct timeval *waketime, u32 add_usec)
+void dvb_frontend_sleep_until(ktime_t waketime, u32 add_usec)
 {
-   struct timeval lasttime;
+   ktime_t lasttime;
s32 delta, newdelta;
 
-   timeval_usec_add(waketime, add_usec);
+   ktime_add_us(waketime, add_usec);
 
-   do_gettimeofday(&lasttime);
-   delta = timeval_usec_diff(lasttime, *waketime);
+   lasttime = ktime_get_real();
+   delta = ktime_to_us(ktime_sub(lasttime, waketime));
if (delta > 2500) {
msleep((delta - 1500) / 1000);
-   do_gettimeofday(&lasttime);
-   newdelta = timeval_usec_diff(lasttime, *waketime);
+   lasttime = ktime_get_real();
+   newdelta = ktime_to_us(ktime_sub(lasttime, waketime));
delta = (newdelta > delta) ? 0 : newdelta;
}
if (delta > 0)
@@ -2458,24 +2442,24 @@ static int dvb_frontend_ioctl_legacy(struct file *file,
 * include the initialization or start bit
 */
unsigned long swcmd = ((unsigned long) parg) << 1;
-   struct timeval nexttime;
-   struct timeval tv[10];
+   ktime_t nexttime;
+   ktime_t tv[10];
int i;
u8 last = 1;
if (dvb_frontend_debug)
printk("%s switch command: 0x%04lx\n", 
__func__, swcmd);
-   do_gettimeofday(&nexttime);
+   nexttime = ktime_get_real();
if (dvb_frontend_debug)
tv[0] = nexttime;
/* before sending a command, initialize by sending
 * a 32ms 18V to the switch
 */
fe->ops.set_voltage(fe, SEC_VOLTAGE_18);
-   dvb_frontend_sleep_until(&nexttime, 32000);
+   dvb_frontend_sleep_until(nexttime, 32000);
 
for (i = 0; i < 9; i++) {
if (dvb_frontend_debug)
-   do_gettimeofday(&tv[i + 1]);
+   tv[i+1] = ktime_get_real();
   

[Y2038] [PATCH] aoe: Use 64-bit timestamp in frame

2015-05-10 Thread Tina Ruchandani
'struct frame' uses two variables to store the sent timestamp - 'struct
timeval' and jiffies. jiffies is used to avoid discrepancies caused by
updates to system time. 'struct timeval' uses 32-bit representation for
seconds which will overflow in year 2038.
This patch does the following:
- Replace the use of 'struct timeval' and jiffies with ktime_t, which
is a 64-bit timestamp and is year 2038 safe.
- ktime_t provides both long range (like jiffies) and high resolution
(like timeval). Using ktime_get (monotonic time) instead of wall-clock
time prevents any discprepancies caused by updates to system time.

Signed-off-by: Tina Ruchandani 
---
 drivers/block/aoe/aoe.h|  3 +--
 drivers/block/aoe/aoecmd.c | 36 +++-
 2 files changed, 8 insertions(+), 31 deletions(-)

diff --git a/drivers/block/aoe/aoe.h b/drivers/block/aoe/aoe.h
index 9220f8e..4582b3c 100644
--- a/drivers/block/aoe/aoe.h
+++ b/drivers/block/aoe/aoe.h
@@ -112,8 +112,7 @@ enum frame_flags {
 struct frame {
struct list_head head;
u32 tag;
-   struct timeval sent;/* high-res time packet was sent */
-   u32 sent_jiffs; /* low-res jiffies-based sent time */
+   ktime_t sent;
ulong waited;
ulong waited_total;
struct aoetgt *t;   /* parent target I belong to */
diff --git a/drivers/block/aoe/aoecmd.c b/drivers/block/aoe/aoecmd.c
index 422b7d8..7f78780 100644
--- a/drivers/block/aoe/aoecmd.c
+++ b/drivers/block/aoe/aoecmd.c
@@ -398,8 +398,7 @@ aoecmd_ata_rw(struct aoedev *d)
 
skb = skb_clone(f->skb, GFP_ATOMIC);
if (skb) {
-   do_gettimeofday(&f->sent);
-   f->sent_jiffs = (u32) jiffies;
+   f->sent = ktime_get();
__skb_queue_head_init(&queue);
__skb_queue_tail(&queue, skb);
aoenet_xmit(&queue);
@@ -489,8 +488,7 @@ resend(struct aoedev *d, struct frame *f)
skb = skb_clone(skb, GFP_ATOMIC);
if (skb == NULL)
return;
-   do_gettimeofday(&f->sent);
-   f->sent_jiffs = (u32) jiffies;
+   f->sent = ktime_get();
__skb_queue_head_init(&queue);
__skb_queue_tail(&queue, skb);
aoenet_xmit(&queue);
@@ -499,32 +497,15 @@ resend(struct aoedev *d, struct frame *f)
 static int
 tsince_hr(struct frame *f)
 {
-   struct timeval now;
+   ktime_t now;
int n;
 
-   do_gettimeofday(&now);
-   n = now.tv_usec - f->sent.tv_usec;
-   n += (now.tv_sec - f->sent.tv_sec) * USEC_PER_SEC;
+   now = ktime_get();
+   n = ktime_to_us(ktime_sub(now, f->sent));
 
if (n < 0)
n = -n;
 
-   /* For relatively long periods, use jiffies to avoid
-* discrepancies caused by updates to the system time.
-*
-* On system with HZ of 1000, 32-bits is over 49 days
-* worth of jiffies, or over 71 minutes worth of usecs.
-*
-* Jiffies overflow is handled by subtraction of unsigned ints:
-* (gdb) print (unsigned) 2 - (unsigned) 0xfffe
-* $3 = 4
-* (gdb)
-*/
-   if (n > USEC_PER_SEC / 4) {
-   n = ((u32) jiffies) - f->sent_jiffs;
-   n *= USEC_PER_SEC / HZ;
-   }
-
return n;
 }
 
@@ -589,7 +570,6 @@ reassign_frame(struct frame *f)
nf->waited = 0;
nf->waited_total = f->waited_total;
nf->sent = f->sent;
-   nf->sent_jiffs = f->sent_jiffs;
f->skb = skb;
 
return nf;
@@ -633,8 +613,7 @@ probe(struct aoetgt *t)
 
skb = skb_clone(f->skb, GFP_ATOMIC);
if (skb) {
-   do_gettimeofday(&f->sent);
-   f->sent_jiffs = (u32) jiffies;
+   f->sent = ktime_get();
__skb_queue_head_init(&queue);
__skb_queue_tail(&queue, skb);
aoenet_xmit(&queue);
@@ -1474,8 +1453,7 @@ aoecmd_ata_id(struct aoedev *d)
 
skb = skb_clone(skb, GFP_ATOMIC);
if (skb) {
-   do_gettimeofday(&f->sent);
-   f->sent_jiffs = (u32) jiffies;
+   f->sent = ktime_get();
}
 
return skb;
-- 
2.2.0.rc0.207.ga3a616c

___
Y2038 mailing list
Y2038@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/y2038


[Y2038] [PATCH] isdn: Use ktime_t instead of 'struct timeval'

2015-05-10 Thread Tina Ruchandani
'struct timeval' uses 32-bit representation for seconds which will
overflow in year 2038 and beyond. mISDN/clock.c needs to compute and
store elapsed time in intervals of 125 microseconds. This patch replaces
the usage of 'struct timeval' with 64-bit ktime_t which is y2038 safe.
The patch also replaces use of wall-clock time (do_gettimeofday) with 
monotonic time (ktime_get) since we only care about elapsed time here.

Signed-off-by: Tina Ruchandani 
---
 drivers/isdn/mISDN/clock.c | 53 +-
 include/linux/mISDNif.h|  2 +-
 2 files changed, 21 insertions(+), 34 deletions(-)

diff --git a/drivers/isdn/mISDN/clock.c b/drivers/isdn/mISDN/clock.c
index 693fb7c..7550f2e 100644
--- a/drivers/isdn/mISDN/clock.c
+++ b/drivers/isdn/mISDN/clock.c
@@ -37,6 +37,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include "core.h"
@@ -45,7 +46,7 @@ static u_int *debug;
 static LIST_HEAD(iclock_list);
 static DEFINE_RWLOCK(iclock_lock);
 static u16 iclock_count;   /* counter of last clock */
-static struct timeval iclock_tv;   /* time stamp of last clock */
+static ktime_t iclock_tv;  /* time stamp of last clock */
 static int iclock_tv_valid;/* already received one timestamp */
 static struct mISDNclock *iclock_current;
 
@@ -53,7 +54,7 @@ void
 mISDN_init_clock(u_int *dp)
 {
debug = dp;
-   do_gettimeofday(&iclock_tv);
+   iclock_tv = ktime_get();
 }
 
 static void
@@ -139,12 +140,11 @@ mISDN_unregister_clock(struct mISDNclock *iclock)
 EXPORT_SYMBOL(mISDN_unregister_clock);
 
 void
-mISDN_clock_update(struct mISDNclock *iclock, int samples, struct timeval *tv)
+mISDN_clock_update(struct mISDNclock *iclock, int samples, ktime_t *tv)
 {
u_long  flags;
-   struct timeval  tv_now;
-   time_t  elapsed_sec;
-   int elapsed_8000th;
+   ktime_t tv_now;
+   u16 delta;
 
write_lock_irqsave(&iclock_lock, flags);
if (iclock_current != iclock) {
@@ -160,28 +160,20 @@ mISDN_clock_update(struct mISDNclock *iclock, int 
samples, struct timeval *tv)
/* increment sample counter by given samples */
iclock_count += samples;
if (tv) { /* tv must be set, if function call is delayed */
-   iclock_tv.tv_sec = tv->tv_sec;
-   iclock_tv.tv_usec = tv->tv_usec;
+   iclock_tv = *tv;
} else
-   do_gettimeofday(&iclock_tv);
+   iclock_tv = ktime_get();
} else {
/* calc elapsed time by system clock */
if (tv) { /* tv must be set, if function call is delayed */
-   tv_now.tv_sec = tv->tv_sec;
-   tv_now.tv_usec = tv->tv_usec;
+   tv_now = *tv;
} else
-   do_gettimeofday(&tv_now);
-   elapsed_sec = tv_now.tv_sec - iclock_tv.tv_sec;
-   elapsed_8000th = (tv_now.tv_usec / 125)
-   - (iclock_tv.tv_usec / 125);
-   if (elapsed_8000th < 0) {
-   elapsed_sec -= 1;
-   elapsed_8000th += 8000;
-   }
+   tv_now = ktime_get();
+   delta = ktime_to_us(ktime_sub(tv_now, iclock_tv));
+   delta = delta / 125;
/* add elapsed time to counter and set new timestamp */
-   iclock_count += elapsed_sec * 8000 + elapsed_8000th;
-   iclock_tv.tv_sec = tv_now.tv_sec;
-   iclock_tv.tv_usec = tv_now.tv_usec;
+   iclock_count += delta;
+   iclock_tv = tv_now;
iclock_tv_valid = 1;
if (*debug & DEBUG_CLOCK)
printk("Received first clock from source '%s'.\n",
@@ -195,22 +187,17 @@ unsigned short
 mISDN_clock_get(void)
 {
u_long  flags;
-   struct timeval  tv_now;
-   time_t  elapsed_sec;
-   int elapsed_8000th;
+   ktime_t tv_now;
+   u16 delta;
u16 count;
 
read_lock_irqsave(&iclock_lock, flags);
/* calc elapsed time by system clock */
-   do_gettimeofday(&tv_now);
-   elapsed_sec = tv_now.tv_sec - iclock_tv.tv_sec;
-   elapsed_8000th = (tv_now.tv_usec / 125) - (iclock_tv.tv_usec / 125);
-   if (elapsed_8000th < 0) {
-   elapsed_sec -= 1;
-   elapsed_8000th += 8000;
-   }
+   tv_now = ktime_get();
+   delta = ktime_to_us(ktime_sub(tv_now, iclock_tv));
+   delta = delta / 125;
/* add elapsed time to counter */
-   count = iclock_count + elapsed_sec * 8000 + elapsed_8000th;
+   count = iclock_count + delta;