diff options
author | Stanislaw Gruszka <sgruszka@redhat.com> | 2010-03-11 17:04:39 -0500 |
---|---|---|
committer | Thomas Gleixner <tglx@linutronix.de> | 2010-03-12 16:40:40 -0500 |
commit | ae1a78eecc45fe41215d9dbfd7079999455772d6 (patch) | |
tree | 6aa1fb1b053aa8f9464a6ce83a2b62cac12bab55 /kernel/posix-cpu-timers.c | |
parent | 5eb9aa6414bdab6d075a8763bc3b647181ef3aab (diff) |
cpu-timers: Return correct previous timer reload value
According POSIX we need to correctly set old timer it_interval value when
user request that in timer_settime(). Tested using below program.
#include <sys/time.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include <assert.h>
int main(void)
{
struct sigaction act;
struct sigevent evt = { };
timer_t tid;
struct itimerspec spec, u_spec, k_spec;
evt.sigev_notify = SIGEV_SIGNAL;
evt.sigev_signo = SIGPROF;
assert(timer_create(CLOCK_PROCESS_CPUTIME_ID, &evt, &tid) == 0);
spec.it_value.tv_sec = 1;
spec.it_value.tv_nsec = 2;
spec.it_interval.tv_sec = 3;
spec.it_interval.tv_nsec = 4;
u_spec = spec;
assert(timer_settime(tid, 0, &spec, NULL) == 0);
spec.it_value.tv_sec = 5;
spec.it_value.tv_nsec = 6;
spec.it_interval.tv_sec = 7;
spec.it_interval.tv_nsec = 8;
assert(timer_settime(tid, 0, &spec, &k_spec) == 0);
#define PRT(val) printf(#val ":\t%d/%d\n", (int) u_spec.val, (int) k_spec.val)
PRT(it_value.tv_sec);
PRT(it_value.tv_nsec);
PRT(it_interval.tv_sec);
PRT(it_interval.tv_nsec);
return 0;
}
Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
Cc: Balbir Singh <balbir@in.ibm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'kernel/posix-cpu-timers.c')
-rw-r--r-- | kernel/posix-cpu-timers.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c index 7c7166f766cc..cce2f0b2d406 100644 --- a/kernel/posix-cpu-timers.c +++ b/kernel/posix-cpu-timers.c | |||
@@ -676,7 +676,7 @@ int posix_cpu_timer_set(struct k_itimer *timer, int flags, | |||
676 | struct itimerspec *new, struct itimerspec *old) | 676 | struct itimerspec *new, struct itimerspec *old) |
677 | { | 677 | { |
678 | struct task_struct *p = timer->it.cpu.task; | 678 | struct task_struct *p = timer->it.cpu.task; |
679 | union cpu_time_count old_expires, new_expires, val; | 679 | union cpu_time_count old_expires, new_expires, old_incr, val; |
680 | int ret; | 680 | int ret; |
681 | 681 | ||
682 | if (unlikely(p == NULL)) { | 682 | if (unlikely(p == NULL)) { |
@@ -707,6 +707,7 @@ int posix_cpu_timer_set(struct k_itimer *timer, int flags, | |||
707 | BUG_ON(!irqs_disabled()); | 707 | BUG_ON(!irqs_disabled()); |
708 | 708 | ||
709 | ret = 0; | 709 | ret = 0; |
710 | old_incr = timer->it.cpu.incr; | ||
710 | spin_lock(&p->sighand->siglock); | 711 | spin_lock(&p->sighand->siglock); |
711 | old_expires = timer->it.cpu.expires; | 712 | old_expires = timer->it.cpu.expires; |
712 | if (unlikely(timer->it.cpu.firing)) { | 713 | if (unlikely(timer->it.cpu.firing)) { |
@@ -822,7 +823,7 @@ int posix_cpu_timer_set(struct k_itimer *timer, int flags, | |||
822 | out: | 823 | out: |
823 | if (old) { | 824 | if (old) { |
824 | sample_to_timespec(timer->it_clock, | 825 | sample_to_timespec(timer->it_clock, |
825 | timer->it.cpu.incr, &old->it_interval); | 826 | old_incr, &old->it_interval); |
826 | } | 827 | } |
827 | return ret; | 828 | return ret; |
828 | } | 829 | } |