> --
> 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
>
> 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
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 <ruchandani.tina(a)gmail.com>
Suggested-by: Arnd Bergmann <arnd(a)arndb.de>
--
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 <linux/freezer.h>
#include <linux/jiffies.h>
#include <linux/kthread.h>
+#include <linux/ktime.h>
#include <asm/processor.h>
#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) ?
- 1000000 - 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 >= 1000000) {
- curtime->tv_usec -= 1000000;
- 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,7 @@ 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 = 1; i < 10; i++)
- printk("%d: %d\n", i, timeval_usec_diff(tv[i-1] , tv[i]));
+ printk("%d: %d\n", i, (int) ktime_to_us(ktime_sub(tv[i-1], tv[i])));
}
err = 0;
fepriv->state = FESTATE_DISEQC;
diff --git a/drivers/media/dvb-core/dvb_frontend.h b/drivers/media/dvb-core/dvb_frontend.h
index 816269e..5b64686 100644
--- a/drivers/media/dvb-core/dvb_frontend.h
+++ b/drivers/media/dvb-core/dvb_frontend.h
@@ -439,7 +439,6 @@ extern void dvb_frontend_reinitialise(struct dvb_frontend *fe);
extern int dvb_frontend_suspend(struct dvb_frontend *fe);
extern int dvb_frontend_resume(struct dvb_frontend *fe);
-extern void dvb_frontend_sleep_until(struct timeval *waketime, u32 add_usec);
-extern s32 timeval_usec_diff(struct timeval lasttime, struct timeval curtime);
+extern void dvb_frontend_sleep_until(ktime_t *waketime, u32 add_usec);
#endif
diff --git a/drivers/media/dvb-frontends/stv0299.c b/drivers/media/dvb-frontends/stv0299.c
index b57ecf4..70c8065 100644
--- a/drivers/media/dvb-frontends/stv0299.c
+++ b/drivers/media/dvb-frontends/stv0299.c
@@ -44,6 +44,7 @@
#include <linux/init.h>
#include <linux/kernel.h>
+#include <linux/ktime.h>
#include <linux/module.h>
#include <linux/string.h>
#include <linux/slab.h>
@@ -404,8 +405,8 @@ static int stv0299_send_legacy_dish_cmd (struct dvb_frontend* fe, unsigned long
u8 lv_mask = 0x40;
u8 last = 1;
int i;
- struct timeval nexttime;
- struct timeval tv[10];
+ ktime_t nexttime;
+ ktime_t tv[10];
reg0x08 = stv0299_readreg (state, 0x08);
reg0x0c = stv0299_readreg (state, 0x0c);
@@ -418,7 +419,7 @@ static int stv0299_send_legacy_dish_cmd (struct dvb_frontend* fe, unsigned long
if (debug_legacy_dish_switch)
printk ("%s switch command: 0x%04lx\n",__func__, cmd);
- do_gettimeofday (&nexttime);
+ nexttime = ktime_get_real();
if (debug_legacy_dish_switch)
tv[0] = nexttime;
stv0299_writeregI (state, 0x0c, reg0x0c | 0x50); /* set LNB to 18V */
@@ -427,7 +428,7 @@ static int stv0299_send_legacy_dish_cmd (struct dvb_frontend* fe, unsigned long
for (i=0; i<9; i++) {
if (debug_legacy_dish_switch)
- do_gettimeofday (&tv[i+1]);
+ tv[i+1] = ktime_get_real();
if((cmd & 0x01) != last) {
/* set voltage to (last ? 13V : 18V) */
stv0299_writeregI (state, 0x0c, reg0x0c | (last ? lv_mask : 0x50));
@@ -443,7 +444,7 @@ static int stv0299_send_legacy_dish_cmd (struct dvb_frontend* fe, unsigned long
printk ("%s(%d): switch delay (should be 32k followed by all 8k\n",
__func__, fe->dvb->num);
for (i = 1; i < 10; i++)
- printk ("%d: %d\n", i, timeval_usec_diff(tv[i-1] , tv[i]));
+ printk("%d: %d\n", i, (int) ktime_to_us(ktime_sub(tv[i-1], tv[i])));
}
return 0;
--
2.2.0.rc0.207.ga3a616c
This patch series changes the 32-bit time types (timespec/itimerspec) to
the 64-bit types (timespec64/itimerspec64), since 32-bit time types will
break in the year 2038.
This patch series introduces new methods with timespec64/itimerspec64 type,
and removes the old ones with timespec/itimerspec type for posix_clock_operations
and k_clock structure.
timekeeping: Introduce struct itimerspec64.
timekeeping: Introduce current_kernel_time64().
timekeeping: Change timekeeping_clocktai() with timespec64 type.
hrtimer: Introduce hrtimer_get_res64().
security: Introduce security_settime64().
time: Introduce do_sys_settimeofday64().
time: Introduce jiffies_to_timespec64()/timespec64_to_jiffies().
cputime: Introduce cputime_to_timespec64()/timespec64_to_cputime().
posix-timers: Introduce {get,put}_timespec()/{get,put}_itimerspec().
posix-timers: Split up timer_gettime()/timer_settime()/clock_settime()/
clock_gettime()/clock_getres().
posix-timers: Convert timer_gettime()/timer_settime()/clock_settime()/
clock_gettime()/clock_getres() to timespec64/itimerspec64.
mmtimer: Convert to timespec64/itimerspec64.
alarmtimer: Convert to timespec64/itimerspec64.
posix-clock: Convert to timespec64/itimerspec64.
posix-cpu-timers: Convert to timespec64/itimerspec64.
Baolin Wang (25):
linux/time64.h:Introduce the 'struct itimerspec64' for 64bit
timekeeping:Introduce the current_kernel_time64() function with
timespec64 type
time/hrtimer:Introduce hrtimer_get_res64() with timespec64 type
security/security: Introduce security_settime64() function with
timespec64 type
time:Introduce the do_sys_settimeofday64() function with timespec64
type
time/posix-timers:Introduce {get,put}_timespec and
{get,put}_itimerspec
posix-timers:Change the implementation for timer_gettime syscall
function
posix-timers:Convert to the 64bit methods for the timer_gettime
syscall function
posix-timers:Change the implementation for timer_settime syscall
posix-timers:Convert to the 64bit methods for the timer_settime
syscall function
posix-timers:Change the implementation for clock_settime syscall
function
posix-timers:Convert to the 64bit methods for the clock_settime
syscall function
posix-timers:Change the implementation for clock_gettime syscall
function
posix-timers:Convert to the 64bit methods for the clock_gettime
syscall function
posix-timers:Change the implementation for clock_getres syscall
function
posix-timers:Convert to the 64bit methods for the clock_getres
syscall function
timekeeping:Introduce the timekeeping_clocktai() function with
timespec64 type
time/posix-timers:Convert to the 64bit methods for k_clock callback
functions
char/mmtimer:Convert to the 64bit methods for k_clock callback
functions
time/alarmtimer:Convert to the new 64bit methods for k_clock
structure
time/posix-clock:Convert to the 64bit methods for k_clock and
posix_clock_operations structure
time/time:Introduce the
timespec64_to_jiffies()/jiffies_to_timespec64() function
cputime:Introduce the cputime_to_timespec64/timespec64_to_cputime
function
time/posix-cpu-timers:Convert to the 64bit methods for k_clock
structure
k_clock:Remove the 32bit methods with timespec/itimerspec type
arch/powerpc/include/asm/cputime.h | 6 +-
arch/s390/include/asm/cputime.h | 8 +-
drivers/char/mmtimer.c | 36 +++--
drivers/ptp/ptp_clock.c | 26 +---
include/asm-generic/cputime_jiffies.h | 10 +-
include/asm-generic/cputime_nsecs.h | 4 +-
include/linux/cputime.h | 16 ++
include/linux/hrtimer.h | 16 +-
include/linux/jiffies.h | 21 ++-
include/linux/posix-clock.h | 10 +-
include/linux/posix-timers.h | 18 +--
include/linux/security.h | 25 +++-
include/linux/time64.h | 35 +++++
include/linux/timekeeping.h | 26 +++-
kernel/time/alarmtimer.c | 43 +++---
kernel/time/hrtimer.c | 10 +-
kernel/time/posix-clock.c | 20 +--
kernel/time/posix-cpu-timers.c | 84 ++++++-----
kernel/time/posix-timers.c | 259 +++++++++++++++++++++------------
kernel/time/time.c | 20 +--
kernel/time/timekeeping.c | 6 +-
kernel/time/timekeeping.h | 1 -
security/commoncap.c | 2 +-
security/security.c | 2 +-
24 files changed, 437 insertions(+), 267 deletions(-)
--
1.7.9.5