[PATCH v5 23/24] posix-cpu-timers: Convert to y2038 safe callbacks

2015-06-12 Thread Baolin Wang
The clock_getres()/clock_get()/clock_set()/timer_set()/timer_get()
callbacks in struct k_clock are not year 2038 safe on 32bit systems,
and it need convert to safe callbacks which use struct timespec64
or struct itimerspec64.

Signed-off-by: Baolin Wang 
---
 kernel/time/posix-cpu-timers.c |   84 +---
 1 file changed, 45 insertions(+), 39 deletions(-)

diff --git a/kernel/time/posix-cpu-timers.c b/kernel/time/posix-cpu-timers.c
index 892e3da..1d4605c 100644
--- a/kernel/time/posix-cpu-timers.c
+++ b/kernel/time/posix-cpu-timers.c
@@ -52,7 +52,7 @@ static int check_clock(const clockid_t which_clock)
 }
 
 static inline unsigned long long
-timespec_to_sample(const clockid_t which_clock, const struct timespec *tp)
+timespec64_to_sample(const clockid_t which_clock, const struct timespec64 *tp)
 {
unsigned long long ret;
 
@@ -60,19 +60,19 @@ timespec_to_sample(const clockid_t which_clock, const 
struct timespec *tp)
if (CPUCLOCK_WHICH(which_clock) == CPUCLOCK_SCHED) {
ret = (unsigned long long)tp->tv_sec * NSEC_PER_SEC + 
tp->tv_nsec;
} else {
-   ret = cputime_to_expires(timespec_to_cputime(tp));
+   ret = cputime_to_expires(timespec64_to_cputime(tp));
}
return ret;
 }
 
-static void sample_to_timespec(const clockid_t which_clock,
+static void sample_to_timespec64(const clockid_t which_clock,
   unsigned long long expires,
-  struct timespec *tp)
+  struct timespec64 *tp)
 {
if (CPUCLOCK_WHICH(which_clock) == CPUCLOCK_SCHED)
-   *tp = ns_to_timespec(expires);
+   *tp = ns_to_timespec64(expires);
else
-   cputime_to_timespec((__force cputime_t)expires, tp);
+   cputime_to_timespec64((__force cputime_t)expires, tp);
 }
 
 /*
@@ -141,7 +141,7 @@ static inline unsigned long long virt_ticks(struct 
task_struct *p)
 }
 
 static int
-posix_cpu_clock_getres(const clockid_t which_clock, struct timespec *tp)
+posix_cpu_clock_getres(const clockid_t which_clock, struct timespec64 *tp)
 {
int error = check_clock(which_clock);
if (!error) {
@@ -160,7 +160,7 @@ posix_cpu_clock_getres(const clockid_t which_clock, struct 
timespec *tp)
 }
 
 static int
-posix_cpu_clock_set(const clockid_t which_clock, const struct timespec *tp)
+posix_cpu_clock_set(const clockid_t which_clock, const struct timespec64 *tp)
 {
/*
 * You can never reset a CPU clock, but we check for other errors
@@ -286,7 +286,7 @@ static int cpu_clock_sample_group(const clockid_t 
which_clock,
 
 static int posix_cpu_clock_get_task(struct task_struct *tsk,
const clockid_t which_clock,
-   struct timespec *tp)
+   struct timespec64 *tp)
 {
int err = -EINVAL;
unsigned long long rtn;
@@ -300,13 +300,14 @@ static int posix_cpu_clock_get_task(struct task_struct 
*tsk,
}
 
if (!err)
-   sample_to_timespec(which_clock, rtn, tp);
+   sample_to_timespec64(which_clock, rtn, tp);
 
return err;
 }
 
 
-static int posix_cpu_clock_get(const clockid_t which_clock, struct timespec 
*tp)
+static int posix_cpu_clock_get(const clockid_t which_clock,
+   struct timespec64 *tp)
 {
const pid_t pid = CPUCLOCK_PID(which_clock);
int err = -EINVAL;
@@ -622,7 +623,7 @@ static inline void posix_cpu_timer_kick_nohz(void) { }
  * and try again.  (This happens when the timer is in the middle of firing.)
  */
 static int posix_cpu_timer_set(struct k_itimer *timer, int timer_flags,
-  struct itimerspec *new, struct itimerspec *old)
+  struct itimerspec64 *new, struct itimerspec64 
*old)
 {
unsigned long flags;
struct sighand_struct *sighand;
@@ -632,7 +633,7 @@ static int posix_cpu_timer_set(struct k_itimer *timer, int 
timer_flags,
 
WARN_ON_ONCE(p == NULL);
 
-   new_expires = timespec_to_sample(timer->it_clock, >it_value);
+   new_expires = timespec64_to_sample(timer->it_clock, >it_value);
 
/*
 * Protect against sighand release/switch in exit/exec and p->cpu_timers
@@ -693,7 +694,7 @@ static int posix_cpu_timer_set(struct k_itimer *timer, int 
timer_flags,
bump_cpu_timer(timer, val);
if (val < timer->it.cpu.expires) {
old_expires = timer->it.cpu.expires - val;
-   sample_to_timespec(timer->it_clock,
+   sample_to_timespec64(timer->it_clock,
   old_expires,
   >it_value);
} else {
@@ -733,7 +734,7 @@ static int posix_cpu_timer_set(struct 

[PATCH v5 23/24] posix-cpu-timers: Convert to y2038 safe callbacks

2015-06-12 Thread Baolin Wang
The clock_getres()/clock_get()/clock_set()/timer_set()/timer_get()
callbacks in struct k_clock are not year 2038 safe on 32bit systems,
and it need convert to safe callbacks which use struct timespec64
or struct itimerspec64.

Signed-off-by: Baolin Wang baolin.w...@linaro.org
---
 kernel/time/posix-cpu-timers.c |   84 +---
 1 file changed, 45 insertions(+), 39 deletions(-)

diff --git a/kernel/time/posix-cpu-timers.c b/kernel/time/posix-cpu-timers.c
index 892e3da..1d4605c 100644
--- a/kernel/time/posix-cpu-timers.c
+++ b/kernel/time/posix-cpu-timers.c
@@ -52,7 +52,7 @@ static int check_clock(const clockid_t which_clock)
 }
 
 static inline unsigned long long
-timespec_to_sample(const clockid_t which_clock, const struct timespec *tp)
+timespec64_to_sample(const clockid_t which_clock, const struct timespec64 *tp)
 {
unsigned long long ret;
 
@@ -60,19 +60,19 @@ timespec_to_sample(const clockid_t which_clock, const 
struct timespec *tp)
if (CPUCLOCK_WHICH(which_clock) == CPUCLOCK_SCHED) {
ret = (unsigned long long)tp-tv_sec * NSEC_PER_SEC + 
tp-tv_nsec;
} else {
-   ret = cputime_to_expires(timespec_to_cputime(tp));
+   ret = cputime_to_expires(timespec64_to_cputime(tp));
}
return ret;
 }
 
-static void sample_to_timespec(const clockid_t which_clock,
+static void sample_to_timespec64(const clockid_t which_clock,
   unsigned long long expires,
-  struct timespec *tp)
+  struct timespec64 *tp)
 {
if (CPUCLOCK_WHICH(which_clock) == CPUCLOCK_SCHED)
-   *tp = ns_to_timespec(expires);
+   *tp = ns_to_timespec64(expires);
else
-   cputime_to_timespec((__force cputime_t)expires, tp);
+   cputime_to_timespec64((__force cputime_t)expires, tp);
 }
 
 /*
@@ -141,7 +141,7 @@ static inline unsigned long long virt_ticks(struct 
task_struct *p)
 }
 
 static int
-posix_cpu_clock_getres(const clockid_t which_clock, struct timespec *tp)
+posix_cpu_clock_getres(const clockid_t which_clock, struct timespec64 *tp)
 {
int error = check_clock(which_clock);
if (!error) {
@@ -160,7 +160,7 @@ posix_cpu_clock_getres(const clockid_t which_clock, struct 
timespec *tp)
 }
 
 static int
-posix_cpu_clock_set(const clockid_t which_clock, const struct timespec *tp)
+posix_cpu_clock_set(const clockid_t which_clock, const struct timespec64 *tp)
 {
/*
 * You can never reset a CPU clock, but we check for other errors
@@ -286,7 +286,7 @@ static int cpu_clock_sample_group(const clockid_t 
which_clock,
 
 static int posix_cpu_clock_get_task(struct task_struct *tsk,
const clockid_t which_clock,
-   struct timespec *tp)
+   struct timespec64 *tp)
 {
int err = -EINVAL;
unsigned long long rtn;
@@ -300,13 +300,14 @@ static int posix_cpu_clock_get_task(struct task_struct 
*tsk,
}
 
if (!err)
-   sample_to_timespec(which_clock, rtn, tp);
+   sample_to_timespec64(which_clock, rtn, tp);
 
return err;
 }
 
 
-static int posix_cpu_clock_get(const clockid_t which_clock, struct timespec 
*tp)
+static int posix_cpu_clock_get(const clockid_t which_clock,
+   struct timespec64 *tp)
 {
const pid_t pid = CPUCLOCK_PID(which_clock);
int err = -EINVAL;
@@ -622,7 +623,7 @@ static inline void posix_cpu_timer_kick_nohz(void) { }
  * and try again.  (This happens when the timer is in the middle of firing.)
  */
 static int posix_cpu_timer_set(struct k_itimer *timer, int timer_flags,
-  struct itimerspec *new, struct itimerspec *old)
+  struct itimerspec64 *new, struct itimerspec64 
*old)
 {
unsigned long flags;
struct sighand_struct *sighand;
@@ -632,7 +633,7 @@ static int posix_cpu_timer_set(struct k_itimer *timer, int 
timer_flags,
 
WARN_ON_ONCE(p == NULL);
 
-   new_expires = timespec_to_sample(timer-it_clock, new-it_value);
+   new_expires = timespec64_to_sample(timer-it_clock, new-it_value);
 
/*
 * Protect against sighand release/switch in exit/exec and p-cpu_timers
@@ -693,7 +694,7 @@ static int posix_cpu_timer_set(struct k_itimer *timer, int 
timer_flags,
bump_cpu_timer(timer, val);
if (val  timer-it.cpu.expires) {
old_expires = timer-it.cpu.expires - val;
-   sample_to_timespec(timer-it_clock,
+   sample_to_timespec64(timer-it_clock,
   old_expires,
   old-it_value);
} else {
@@ -733,7 +734,7 @@ static int