Re: [patch] jiffies wraparound [Re: 2.1.125 Show stopper list: Draft]

Andrea Arcangeli (andrea@e-mind.com)
Sun, 18 Oct 1998 20:27:30 +0200 (CEST)


On Sun, 18 Oct 1998, MOLNAR Ingo wrote:

>not sure, maybe instead of pointer games, it might be better to use the
>return value:
>
> timeout -= schedule_timeout(timeout);

I don' t agree to return the time we passes there because we end up doing
two subtraction every time (one inside schedule_timeout() and one in the
caller).

I think we can instead do this:

signed long timeout = HZ;
^^^^^^
do {
timeout = schedule_timeout(timeout);
} while (timeout>0)
^^

Tell me what you like more (this is an incremental patch):

Index: kernel/sched.c
===================================================================
RCS file: /var/cvs/linux/kernel/sched.c,v
retrieving revision 1.1.1.1.14.4
diff -u -r1.1.1.1.14.4 sched.c
--- sched.c 1998/10/18 16:24:09 1.1.1.1.14.4
+++ sched.c 1998/10/18 18:24:46
@@ -444,12 +444,18 @@

#endif

-#define MAX_TIMEOUT (jiffies + (~0UL >> 1))
+#define MAX_TIMEOUT (~0UL >> 1)

-void schedule_timeout(unsigned long * timeout)
+signed long schedule_timeout(signed long timeout)
{
- unsigned long __timeout = *timeout;
struct timer_list timer;
+ unsigned long expire;
+
+ /*
+ * Handle special cases.
+ */
+ if (timeout == -1)
+ timeout = MAX_TIMEOUT;

/*
* PARANOID.
@@ -460,24 +466,20 @@
" from %p\n", __builtin_return_address(0));
goto normal_schedule;
}
- if (!__timeout || __timeout > (~0UL >> 1))
+ if (!timeout || timeout < 0)
{
printk(KERN_ERR "schedule_timeout: wrong timeout value %lx"
- "from %p\n", __timeout, __builtin_return_address(0));
+ "from %p\n", timeout, __builtin_return_address(0));
goto normal_schedule;
}

-
/*
* Here we start for real.
*/
- if (__timeout == ~0UL)
- __timeout = MAX_TIMEOUT;
- else
- __timeout += jiffies;
+ expire = (unsigned long) timeout + jiffies;

init_timer(&timer);
- timer.expires = __timeout;
+ timer.expires = expire;
timer.data = (unsigned long) current;
timer.function = process_timeout;

@@ -485,20 +487,13 @@
schedule();
del_timer(&timer);

- __timeout -= jiffies;
+ timeout = (signed long) (expire - jiffies);

- /*
- * This will allow us to be lazy in the caller.
- */
- if ((signed long) __timeout < 0)
- __timeout = 0;
-
- *timeout = __timeout;
+ return timeout < 0 ? 0 : timeout;

- return;
-
normal_schedule:
schedule();
+ return 0;
}

#undef MAX_TIMEOUT
@@ -1606,7 +1601,7 @@
expire = timespec_to_jiffies(&t) + (t.tv_sec || t.tv_nsec);

current->state = TASK_INTERRUPTIBLE;
- schedule_timeout(&expire);
+ expire = schedule_timeout(expire);

if (expire) {
if (rmtp) {

Andrea Arcangeli

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/