[PATCH 1/13] timestamp fixes

From: Nick Piggin
Date: Thu Feb 24 2005 - 02:19:21 EST


1/13

Some fixes for unsynchronised TSCs. A task's timestamp may have been set
by another CPU. Although we try to adjust this correctly with the
timestamp_last_tick field, there is no guarantee this will be exactly right.

Signed-off-by: Nick Piggin <nickpiggin@xxxxxxxxxxxx>

Index: linux-2.6/kernel/sched.c
===================================================================
--- linux-2.6.orig/kernel/sched.c 2005-02-24 17:31:25.384986289 +1100
+++ linux-2.6/kernel/sched.c 2005-02-24 17:43:39.356379395 +1100
@@ -648,6 +648,7 @@

static void recalc_task_prio(task_t *p, unsigned long long now)
{
+ /* Caller must always ensure 'now >= p->timestamp' */
unsigned long long __sleep_time = now - p->timestamp;
unsigned long sleep_time;

@@ -2703,8 +2704,10 @@

schedstat_inc(rq, sched_cnt);
now = sched_clock();
- if (likely(now - prev->timestamp < NS_MAX_SLEEP_AVG))
+ if (likely((long long)now - prev->timestamp < NS_MAX_SLEEP_AVG))
run_time = now - prev->timestamp;
+ if (unlikely((long long)now - prev->timestamp < 0))
+ run_time = 0;
else
run_time = NS_MAX_SLEEP_AVG;

@@ -2782,6 +2785,8 @@

if (!rt_task(next) && next->activated > 0) {
unsigned long long delta = now - next->timestamp;
+ if (unlikely((long long)now - next->timestamp < 0))
+ delta = 0;

if (next->activated == 1)
delta = delta * (ON_RUNQUEUE_WEIGHT * 128 / 100) / 128;