login
Header Space

 
 

'global' rq->clock (was Re: Horrendous Audio Stutter - current git)

Score:
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Mike Galbraith <efault@...>
Cc: Frans Pop <elendil@...>, Parag Warudkar <parag.warudkar@...>, Ingo Molnar <mingo@...>, LKML <linux-kernel@...>, Guillaume Chazarain <guichaz@...>, Andi Kleen <andi@...>
Date: Friday, May 2, 2008 - 3:56 pm

On Fri, 2008-05-02 at 21:27 +0200, Mike Galbraith wrote:

That's a quite horrible patch for some of us, but I think I know why you
did that, and I think your fancy Q6600 has a stable enough TSC to pull
it off.

Let me try and come up with something slightly less horrible


Ok, the the below would need something that relates tick_timestamp's to
one another.. probably sucks without it..

OTOH, Andi said he was working on a fastish global sched_clock() thingy,
Andi got a link to that code?

Index: linux-2.6-2/kernel/sched.c
===================================================================
--- linux-2.6-2.orig/kernel/sched.c
+++ linux-2.6-2/kernel/sched.c
@@ -560,6 +560,7 @@ struct rq {
 	unsigned long next_balance;
 	struct mm_struct *prev_mm;
 
+	spinlock_t clock_lock;
 	u64 clock, prev_clock_raw;
 	s64 clock_max_delta;
 
@@ -657,20 +658,25 @@ static inline void update_last_tick_seen
 }
 #endif
 
+#define cpu_rq(cpu)		(&per_cpu(runqueues, (cpu)))
+#define this_rq()		(&__get_cpu_var(runqueues))
+#define task_rq(p)		cpu_rq(task_cpu(p))
+#define cpu_curr(cpu)		(cpu_rq(cpu)->curr)
+
 /*
  * Update the per-runqueue clock, as finegrained as the platform can give
  * us, but without assuming monotonicity, etc.:
  */
-static void __update_rq_clock(struct rq *rq)
+static void ___update_rq_clock(struct rq *rq, u64 now)
 {
 	u64 prev_raw = rq->prev_clock_raw;
-	u64 now = sched_clock();
 	s64 delta = now - prev_raw;
 	u64 clock = rq->clock;
 
 #ifdef CONFIG_SCHED_DEBUG
 	WARN_ON_ONCE(cpu_of(rq) != smp_processor_id());
 #endif
+	spin_lock(&rq->clock_lock);
 	/*
 	 * Protect against sched_clock() occasionally going backwards:
 	 */
@@ -699,12 +705,31 @@ static void __update_rq_clock(struct rq 
 
 	rq->prev_clock_raw = now;
 	rq->clock = clock;
+	spin_unlock(&rq->clock_lock);
+}
+
+static void __update_rq_clock(struct rq *rq)
+{
+	___update_rq_clock(rq, sched_clock());
+}
+
+static void __update_remote_rq_clock(struct rq *rq)
+{
+	u64 now = sched_clock();
+	struct rq *this_rq = this_rq();
+
+	now -= this_rq->tick_timestamp;
+	now += rq->tick_timestamp;
+
+	___update_rq_clock(rq, now);
 }
 
 static void update_rq_clock(struct rq *rq)
 {
 	if (likely(smp_processor_id() == cpu_of(rq)))
 		__update_rq_clock(rq);
+	else
+		__update_remote_rq_clock(rq);
 }
 
 /*
@@ -717,11 +742,6 @@ static void update_rq_clock(struct rq *r
 #define for_each_domain(cpu, __sd) \
 	for (__sd = rcu_dereference(cpu_rq(cpu)->sd); __sd; __sd = __sd->parent)
 
-#define cpu_rq(cpu)		(&per_cpu(runqueues, (cpu)))
-#define this_rq()		(&__get_cpu_var(runqueues))
-#define task_rq(p)		cpu_rq(task_cpu(p))
-#define cpu_curr(cpu)		(cpu_rq(cpu)->curr)
-
 /*
  * Tunables that become constants when CONFIG_SCHED_DEBUG is off:
  */
@@ -8147,6 +8167,7 @@ void __init sched_init(void)
 
 		rq = cpu_rq(i);
 		spin_lock_init(&rq->lock);
+		spin_lock_init(&rq->clock_lock);
 		lockdep_set_class(&rq->lock, &rq->rq_lock_key);
 		rq->nr_running = 0;
 		rq->clock = 1;



--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Horrendous Audio Stutter - current git, Parag Warudkar, (Thu May 1, 8:14 pm)
Re: Horrendous Audio Stutter - current git, Peter Zijlstra, (Fri May 2, 4:34 am)
Re: Horrendous Audio Stutter - current git, Frans Pop, (Wed May 7, 4:26 am)
Re: Horrendous Audio Stutter - current git, Ingo Molnar, (Wed May 7, 4:32 am)
Re: Horrendous Audio Stutter - current git, Parag Warudkar, (Fri May 2, 7:10 am)
Re: Horrendous Audio Stutter - current git, Mike Galbraith, (Fri May 2, 8:09 am)
Re: Horrendous Audio Stutter - current git, Parag Warudkar, (Fri May 2, 8:21 am)
Re: Horrendous Audio Stutter - current git, Mike Galbraith, (Fri May 2, 8:37 am)
Re: Horrendous Audio Stutter - current git, Frans Pop, (Sat May 3, 3:13 am)
Re: Horrendous Audio Stutter - current git, Mike Galbraith, (Sat May 3, 3:39 am)
Re: Horrendous Audio Stutter - current git, Mike Galbraith, (Fri May 2, 11:02 am)
Re: Horrendous Audio Stutter - current git, Frans Pop, (Fri May 2, 11:49 am)
Re: Horrendous Audio Stutter - current git, Mike Galbraith, (Fri May 2, 3:38 pm)
Re: Horrendous Audio Stutter - current git, Frans Pop, (Fri May 2, 2:53 pm)
Re: Horrendous Audio Stutter - current git, Mike Galbraith, (Fri May 2, 3:27 pm)
'global' rq->clock (was Re: Horrendous Audio Stutter - cu..., Peter Zijlstra, (Fri May 2, 3:56 pm)
Re: 'global' rq-&gt;clock, David Miller, (Fri May 2, 5:48 pm)
Re: 'global' rq-&gt;clock, Arjan van de Ven, (Fri May 2, 6:09 am)
Re: 'global' rq-&gt;clock, Peter Zijlstra, (Sun May 4, 8:12 am)
Re: 'global' rq-&gt;clock, Peter Zijlstra, (Fri May 2, 6:07 pm)
Re: 'global' rq-&gt;clock, Ingo Molnar, (Sat May 3, 4:28 am)
Re: 'global' rq-&gt;clock, David Miller, (Sat May 3, 5:05 am)
Re: 'global' rq-&gt;clock, Ingo Molnar, (Sat May 3, 6:10 am)
Re: 'global' rq-&gt;clock, David Miller, (Sat May 3, 3:28 pm)
Re: 'global' rq-&gt;clock, Ingo Molnar, (Sat May 3, 3:39 pm)
Re: 'global' rq-&gt;clock, David Miller, (Sat May 3, 3:27 pm)
Re: 'global' rq-&gt;clock, Benjamin Herrenschmidt, (Sat May 3, 6:30 pm)
Re: 'global' rq-&gt;clock, Ingo Molnar, (Sat May 3, 6:38 pm)
Re: 'global' rq-&gt;clock, Benjamin Herrenschmidt, (Sat May 3, 10:22 pm)
Re: 'global' rq-&gt;clock, David Miller, (Sat May 3, 7:04 pm)
Re: 'global' rq-&gt;clock, David Miller, (Sat May 3, 7:36 pm)
Re: 'global' rq-&gt;clock, Ingo Molnar, (Sat May 3, 7:38 pm)
Re: 'global' rq-&gt;clock, David Miller, (Sat May 3, 7:40 pm)
Re: 'global' rq-&gt;clock, Ingo Molnar, (Sat May 3, 7:47 pm)
Re: 'global' rq-&gt;clock, Ingo Molnar, (Sat May 3, 3:37 pm)
Re: 'global' rq-&gt;clock (was Re: Horrendous Audio Stutter ..., Guillaume Chazarain, (Fri May 2, 4:38 pm)
Re: 'global' rq-&gt;clock, David Miller, (Fri May 2, 6:00 pm)
Re: Horrendous Audio Stutter - current git, Frans Pop, (Fri May 2, 6:32 am)
Re: Horrendous Audio Stutter - current git, Peter Zijlstra, (Fri May 2, 6:35 am)
Re: Horrendous Audio Stutter - current git, Peter Zijlstra, (Fri May 2, 7:08 am)
Re: Horrendous Audio Stutter - current git, Frans Pop, (Fri May 2, 7:37 am)
Re: Horrendous Audio Stutter - current git, Peter Zijlstra, (Fri May 2, 7:39 am)
Re: Horrendous Audio Stutter - current git, Frans Pop, (Fri May 2, 8:06 am)
Re: Horrendous Audio Stutter - current git, Parag Warudkar, (Fri May 2, 8:22 am)
Re: Horrendous Audio Stutter - current git, Dhaval Giani, (Fri May 2, 9:21 am)
Re: Horrendous Audio Stutter - current git, Frans Pop, (Fri May 2, 7:45 am)
Re: Horrendous Audio Stutter - current git, Peter Zijlstra, (Fri May 2, 7:51 am)
speck-geostationary