All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <a.p.zijlstra@chello.nl>
To: Mike Galbraith <efault@gmx.de>
Cc: Frans Pop <elendil@planet.nl>,
	Parag Warudkar <parag.warudkar@gmail.com>,
	Ingo Molnar <mingo@elte.hu>, LKML <linux-kernel@vger.kernel.org>,
	Guillaume Chazarain <guichaz@yahoo.fr>,
	Andi Kleen <andi@firstfloor.org>
Subject: 'global' rq->clock (was Re: Horrendous Audio Stutter - current git)
Date: Fri, 02 May 2008 21:56:26 +0200	[thread overview]
Message-ID: <1209758186.6929.18.camel@lappy> (raw)
In-Reply-To: <1209756423.4693.8.camel@marge.simson.net>

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

> Fix undesirable rq.clock update noops.
> 
> Signed-off-by: Mike Galbraith <efault@gmx.de>
> 
> Index: linux-2.6.26.git/kernel/sched.c
> ===================================================================
> --- linux-2.6.26.git.orig/kernel/sched.c
> +++ linux-2.6.26.git/kernel/sched.c
> @@ -668,9 +668,6 @@ static void __update_rq_clock(struct rq 
>  	s64 delta = now - prev_raw;
>  	u64 clock = rq->clock;
>  
> -#ifdef CONFIG_SCHED_DEBUG
> -	WARN_ON_ONCE(cpu_of(rq) != smp_processor_id());
> -#endif
>  	/*
>  	 * Protect against sched_clock() occasionally going backwards:
>  	 */
> @@ -3009,8 +3006,8 @@ static void double_rq_lock(struct rq *rq
>  			spin_lock(&rq1->lock);
>  		}
>  	}
> -	update_rq_clock(rq1);
> -	update_rq_clock(rq2);
> +	__update_rq_clock(rq1);
> +	__update_rq_clock(rq2);
>  }
>  
>  /*
> @@ -3860,7 +3857,7 @@ redo:
>  		/* Attempt to move tasks */
>  		double_lock_balance(this_rq, busiest);
>  		/* this_rq->clock is already updated */
> -		update_rq_clock(busiest);
> +		__update_rq_clock(busiest);
>  		ld_moved = move_tasks(this_rq, this_cpu, busiest,
>  					imbalance, sd, CPU_NEWLY_IDLE,
>  					&all_pinned);
> @@ -3959,8 +3956,8 @@ static void active_load_balance(struct r
>  
>  	/* move a task from busiest_rq to target_rq */
>  	double_lock_balance(busiest_rq, target_rq);
> -	update_rq_clock(busiest_rq);
> -	update_rq_clock(target_rq);
> +	__update_rq_clock(busiest_rq);
> +	__update_rq_clock(target_rq);
>  
>  	/* Search for an sd spanning us and the target CPU. */
>  	for_each_domain(target_cpu, sd) {
> Index: linux-2.6.26.git/kernel/sched_fair.c
> ===================================================================
> --- linux-2.6.26.git.orig/kernel/sched_fair.c
> +++ linux-2.6.26.git/kernel/sched_fair.c
> @@ -1221,7 +1221,7 @@ static void check_preempt_wakeup(struct 
>  	int se_depth, pse_depth;
>  
>  	if (unlikely(rt_prio(p->prio))) {
> -		update_rq_clock(rq);
> +		__update_rq_clock(rq);
>  		update_curr(cfs_rq);
>  		resched_task(curr);
>  		return;
> 

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;




  reply	other threads:[~2008-05-02 19:56 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-02  0:14 Horrendous Audio Stutter - current git Parag Warudkar
2008-05-02  8:34 ` Peter Zijlstra
2008-05-02 10:32   ` Frans Pop
2008-05-02 10:35     ` Peter Zijlstra
2008-05-02 11:08       ` Peter Zijlstra
2008-05-02 11:37         ` Frans Pop
2008-05-02 11:39           ` Peter Zijlstra
2008-05-02 11:45             ` Frans Pop
2008-05-02 11:51               ` Peter Zijlstra
2008-05-02 12:06             ` Frans Pop
2008-05-02 12:22               ` Parag Warudkar
2008-05-02 13:21                 ` Dhaval Giani
2008-05-02 11:10   ` Parag Warudkar
2008-05-02 12:09     ` Mike Galbraith
2008-05-02 12:21       ` Parag Warudkar
2008-05-02 12:37         ` Mike Galbraith
2008-05-02 15:02           ` Mike Galbraith
2008-05-02 15:49             ` Frans Pop
2008-05-02 18:53               ` Frans Pop
2008-05-02 19:27                 ` Mike Galbraith
2008-05-02 19:56                   ` Peter Zijlstra [this message]
2008-05-02 20:38                     ` 'global' rq->clock (was Re: Horrendous Audio Stutter - current git) Guillaume Chazarain
2008-05-02 20:46                       ` Peter Zijlstra
2008-05-02 22:00                         ` 'global' rq->clock David Miller
2008-05-02 21:48                     ` David Miller
2008-05-02 10:09                       ` Arjan van de Ven
2008-05-04 12:12                         ` Peter Zijlstra
2008-05-02 22:07                       ` Peter Zijlstra
2008-05-03  8:28                         ` Ingo Molnar
2008-05-03  9:05                           ` David Miller
2008-05-03 10:10                             ` Ingo Molnar
2008-05-03 19:27                               ` David Miller
2008-05-03 19:37                                 ` Ingo Molnar
2008-05-03 22:30                                 ` Benjamin Herrenschmidt
2008-05-03 22:38                                   ` Ingo Molnar
2008-05-03 23:04                                     ` David Miller
2008-05-03 23:36                                       ` David Miller
2008-05-03 23:38                                         ` Ingo Molnar
2008-05-03 23:40                                           ` David Miller
2008-05-03 23:47                                             ` Ingo Molnar
2008-05-04  2:22                                     ` Benjamin Herrenschmidt
2008-05-03 19:28                               ` David Miller
2008-05-03 19:39                                 ` Ingo Molnar
2008-05-03  6:20                     ` 'global' rq->clock (was Re: Horrendous Audio Stutter - current git) Mike Galbraith
2008-05-02 19:38               ` Horrendous Audio Stutter - current git Mike Galbraith
2008-05-03  7:13           ` Frans Pop
2008-05-03  7:39             ` Mike Galbraith
2008-05-07  8:26   ` Frans Pop
2008-05-07  8:32     ` Ingo Molnar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1209758186.6929.18.camel@lappy \
    --to=a.p.zijlstra@chello.nl \
    --cc=andi@firstfloor.org \
    --cc=efault@gmx.de \
    --cc=elendil@planet.nl \
    --cc=guichaz@yahoo.fr \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=parag.warudkar@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.