On Saturday 11 April 2015 18:46:55 Baolin Wang wrote:
This patch introduces the new methods of k_clock structure with timespec64 type, converts the timespec type to timespec64 type for the callback function in posix-cpu-timers.c file.
Signed-off-by: Baolin Wang baolin.wang@linaro.org
The patch looks correct, but it wasn't obvious at first why you are modifying some of the functions in here such as posix_cpu_timer_get. It would be helpful to explain that first.
Arnd
kernel/time/posix-cpu-timers.c | 58 +++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 24 deletions(-)
diff --git a/kernel/time/posix-cpu-timers.c b/kernel/time/posix-cpu-timers.c index 0075da7..7bd88f6 100644 --- a/kernel/time/posix-cpu-timers.c +++ b/kernel/time/posix-cpu-timers.c @@ -67,12 +67,12 @@ timespec_to_sample(const clockid_t which_clock, const struct timespec *tp) static void sample_to_timespec(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);
else*tp = ns_to_timespec64(expires);
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 @@ -263,7 +263,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; @@ -283,7 +283,8 @@ static int posix_cpu_clock_get_task(struct task_struct *tsk, } -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; @@ -604,6 +605,7 @@ static int posix_cpu_timer_set(struct k_itimer *timer, int timer_flags, struct sighand_struct *sighand; struct task_struct *p = timer->it.cpu.task; unsigned long long old_expires, new_expires, old_incr, val;
- struct timespec64 ts64; int ret;
WARN_ON_ONCE(p == NULL); @@ -671,7 +673,8 @@ static int posix_cpu_timer_set(struct k_itimer *timer, int timer_flags, old_expires = timer->it.cpu.expires - val; sample_to_timespec(timer->it_clock, old_expires,
&old->it_value);
&ts64);
old->it_value = timespec64_to_timespec(ts64); } else { old->it_value.tv_nsec = 1; old->it_value.tv_sec = 0;
@@ -735,7 +738,8 @@ static int posix_cpu_timer_set(struct k_itimer *timer, int timer_flags, out: if (old) { sample_to_timespec(timer->it_clock,
old_incr, &old->it_interval);
old_incr, &ts64);
} if (!ret) posix_cpu_timer_kick_nohz();old->it_interval = timespec64_to_timespec(ts64);
@@ -746,6 +750,7 @@ static void posix_cpu_timer_get(struct k_itimer *timer, struct itimerspec *itp) { unsigned long long now; struct task_struct *p = timer->it.cpu.task;
- struct timespec64 ts64;
WARN_ON_ONCE(p == NULL); @@ -753,7 +758,8 @@ static void posix_cpu_timer_get(struct k_itimer *timer, struct itimerspec *itp) * Easy part: convert the reload time. */ sample_to_timespec(timer->it_clock,
timer->it.cpu.incr, &itp->it_interval);
timer->it.cpu.incr, &ts64);
- itp->it_interval = timespec64_to_timespec(ts64);
if (timer->it.cpu.expires == 0) { /* Timer not armed at all. */ itp->it_value.tv_sec = itp->it_value.tv_nsec = 0; @@ -783,7 +789,8 @@ static void posix_cpu_timer_get(struct k_itimer *timer, struct itimerspec *itp) */ timer->it.cpu.expires = 0; sample_to_timespec(timer->it_clock, timer->it.cpu.expires,
&itp->it_value);
&ts64);
} else { cpu_timer_sample_group(timer->it_clock, p, &now); unlock_task_sighand(p, &flags);itp->it_value = timespec64_to_timespec(ts64);
@@ -793,7 +800,8 @@ static void posix_cpu_timer_get(struct k_itimer *timer, struct itimerspec *itp) if (now < timer->it.cpu.expires) { sample_to_timespec(timer->it_clock, timer->it.cpu.expires - now,
&itp->it_value);
&ts64);
} else { /*itp->it_value = timespec64_to_timespec(ts64);
- The timer should have expired already, but the firing
@@ -1248,6 +1256,7 @@ static int do_cpu_nanosleep(const clockid_t which_clock, int flags, struct timespec *rqtp, struct itimerspec *it) { struct k_itimer timer;
- struct timespec64 ts64; int error;
/* @@ -1295,7 +1304,8 @@ static int do_cpu_nanosleep(const clockid_t which_clock, int flags, /* * We were interrupted by a signal. */
sample_to_timespec(which_clock, timer.it.cpu.expires, rqtp);
sample_to_timespec(which_clock, timer.it.cpu.expires, &ts64);
error = posix_cpu_timer_set(&timer, 0, &zero_it, it); if (!error) { /**rqtp = timespec64_to_timespec(ts64);
@@ -1395,12 +1405,12 @@ static long posix_cpu_nsleep_restart(struct restart_block *restart_block) #define THREAD_CLOCK MAKE_THREAD_CPUCLOCK(0, CPUCLOCK_SCHED) static int process_cpu_clock_getres(const clockid_t which_clock,
struct timespec *tp)
struct timespec64 *tp)
{ return posix_cpu_clock_getres(PROCESS_CLOCK, tp); } static int process_cpu_clock_get(const clockid_t which_clock,
struct timespec *tp)
struct timespec64 *tp)
{ return posix_cpu_clock_get(PROCESS_CLOCK, tp); } @@ -1420,12 +1430,12 @@ static long process_cpu_nsleep_restart(struct restart_block *restart_block) return -EINVAL; } static int thread_cpu_clock_getres(const clockid_t which_clock,
struct timespec *tp)
struct timespec64 *tp)
{ return posix_cpu_clock_getres(THREAD_CLOCK, tp); } static int thread_cpu_clock_get(const clockid_t which_clock,
struct timespec *tp)
struct timespec64 *tp)
{ return posix_cpu_clock_get(THREAD_CLOCK, tp); } @@ -1436,9 +1446,9 @@ static int thread_cpu_timer_create(struct k_itimer *timer) } struct k_clock clock_posix_cpu = {
- .clock_getres = posix_cpu_clock_getres,
- .clock_set = posix_cpu_clock_set,
- .clock_get = posix_cpu_clock_get,
- .clock_getres64 = posix_cpu_clock_getres,
- .clock_set64 = posix_cpu_clock_set,
- .clock_get64 = posix_cpu_clock_get, .timer_create = posix_cpu_timer_create, .nsleep = posix_cpu_nsleep, .nsleep_restart = posix_cpu_nsleep_restart,
@@ -1450,15 +1460,15 @@ struct k_clock clock_posix_cpu = { static __init int init_posix_cpu_timers(void) { struct k_clock process = {
.clock_getres = process_cpu_clock_getres,
.clock_get = process_cpu_clock_get,
.clock_getres64 = process_cpu_clock_getres,
.timer_create = process_cpu_timer_create, .nsleep = process_cpu_nsleep, .nsleep_restart = process_cpu_nsleep_restart, }; struct k_clock thread = {.clock_get64 = process_cpu_clock_get,
.clock_getres = thread_cpu_clock_getres,
.clock_get = thread_cpu_clock_get,
.clock_getres64 = thread_cpu_clock_getres,
.timer_create = thread_cpu_timer_create, }; struct timespec ts;.clock_get64 = thread_cpu_clock_get,