2005-03-17 02:27:20

by Hong Liu

[permalink] [raw]
Subject: [PATCH 2.6] fix POSIX timers expire before their scheduled time

POSIX says: POSIX timers should not expire before their scheduled time.

Due to the timer started between jiffies, there are cases that the timer
will expire before its scheduled time.
This patch ensures timers will not expire early.

--- a/kernel/posix-timers.c 2005-03-10 15:46:27.329333664 +0800
+++ b/kernel/posix-timers.c 2005-03-10 15:50:11.884196136 +0800
@@ -957,7 +957,8 @@
&expire_64, &(timr->wall_to_prev))) {
return -EINVAL;
}
- timr->it_timer.expires = (unsigned long)expire_64;
+ timr->it_timer.expires = (unsigned long)expire_64 + 1;
tstojiffie(&new_setting->it_interval, clock->res, &expire_64);
timr->it_incr = (unsigned long)expire_64;



2005-03-17 06:29:51

by George Anzinger

[permalink] [raw]
Subject: Re: [PATCH 2.6] fix POSIX timers expire before their scheduled time

Liu, Hong wrote:
> POSIX says: POSIX timers should not expire before their scheduled time.
>
> Due to the timer started between jiffies, there are cases that the timer
> will expire before its scheduled time.
> This patch ensures timers will not expire early.
>
> --- a/kernel/posix-timers.c 2005-03-10 15:46:27.329333664 +0800
> +++ b/kernel/posix-timers.c 2005-03-10 15:50:11.884196136 +0800
> @@ -957,7 +957,8 @@
> &expire_64, &(timr->wall_to_prev))) {
> return -EINVAL;
> }
> - timr->it_timer.expires = (unsigned long)expire_64;
> + timr->it_timer.expires = (unsigned long)expire_64 + 1;
> tstojiffie(&new_setting->it_interval, clock->res, &expire_64);
> timr->it_incr = (unsigned long)expire_64;
>
Has this happened?? The following code (in adjust_abs_time()) is supposed to
prevent this sort of thing:

if (oc.tv_sec | oc.tv_nsec) {
oc.tv_nsec += clock->res;
timespec_norm(&oc);
}

Also, we run rather extensive tests for this sort of thing.


--
George Anzinger [email protected]
High-res-timers: http://sourceforge.net/projects/high-res-timers/

2005-03-17 06:55:01

by Hong Liu

[permalink] [raw]
Subject: Re: [PATCH 2.6] fix POSIX timers expire before their scheduled time

On Thu, 2005-03-17 at 14:29, George Anzinger wrote:
> Liu, Hong wrote:
> > POSIX says: POSIX timers should not expire before their scheduled time.
> >
> > Due to the timer started between jiffies, there are cases that the timer
> > will expire before its scheduled time.
> > This patch ensures timers will not expire early.
> >
> > --- a/kernel/posix-timers.c 2005-03-10 15:46:27.329333664 +0800
> > +++ b/kernel/posix-timers.c 2005-03-10 15:50:11.884196136 +0800
> > @@ -957,7 +957,8 @@
> > &expire_64, &(timr->wall_to_prev))) {
> > return -EINVAL;
> > }
> > - timr->it_timer.expires = (unsigned long)expire_64;
> > + timr->it_timer.expires = (unsigned long)expire_64 + 1;
> > tstojiffie(&new_setting->it_interval, clock->res, &expire_64);
> > timr->it_incr = (unsigned long)expire_64;
> >
> Has this happened?? The following code (in adjust_abs_time()) is supposed to
> prevent this sort of thing:
>
> if (oc.tv_sec | oc.tv_nsec) {
> oc.tv_nsec += clock->res;
> timespec_norm(&oc);
> }
>
> Also, we run rather extensive tests for this sort of thing.
>
The attached case from PosixTestSuite(http://posixtest.sourceforge.net)
failed on IA64 platform.
And if I changed the time interval to N*clock_res in this case, it will
also fail on IA32 platform.


BTW, I can't find the code piece you mentioned in 2.6.11 kernel.


Attachments:
9-1.c (3.61 kB)