All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
To: Linus Torvalds <torvalds@osdl.org>
Cc: Thomas Gleixner <tglx@timesys.com>, Ingo Molnar <mingo@elte.hu>,
	Alan Stern <stern@rowland.harvard.edu>,
	LKML <linux-kernel@vger.kernel.org>,
	john stultz <johnstul@us.ibm.com>,
	David Miller <davem@davemloft.net>,
	Arjan van de Ven <arjan@infradead.org>,
	Andrew Morton <akpm@osdl.org>, Andi Kleen <ak@suse.de>
Subject: Re: [patch] cpufreq: mark cpufreq_tsc() as core_initcall_sync
Date: Thu, 16 Nov 2006 18:33:16 -0800	[thread overview]
Message-ID: <20061117023316.GA3707@us.ibm.com> (raw)
In-Reply-To: <Pine.LNX.4.64.0611161342320.3349@woody.osdl.org>

On Thu, Nov 16, 2006 at 01:47:48PM -0800, Linus Torvalds wrote:
> 
> 
> On Thu, 16 Nov 2006, Thomas Gleixner wrote:
> > 
> > Here is the i386/sparc fixup
> 
> Gag me with a volvo.

No can do -- my wife drives a Ford and my car is a bicycle.

> This is disgusting, but I would actually prefer the following version over 
> the patches I've seen, because
> 
>  - it doesn't end up having any architecture-specific parts
> 
>  - it doesn't use the new "xxx_sync()" thing that I'm not even sure we 
>    should be using.
> 
>  - it makes it clear that this should be fixed, preferably by just having 
>    some way to initialize SRCU structs staticalyl. If we get that, the fix 
>    is to just replace the horrible "initialize by hand" with a static 
>    initializer once and for all.
> 
> Hmm?
> 
> Totally untested, but it compiles and it _looks_ sane. The overhead of the 
> function call should be minimal, once things are initialized.
> 
> Paul, it would be _really_ nice to have some way to just initialize that 
> SRCU thing statically. This kind of crud is just crazy.

Static initialization is a bit of a tarpit for SRCU.  Before this week,
I would have protested bitterly over the overhead of a dynamic runtime
check, but Jens is running into another issue that looks to require a
bit more read-side overhead as well (synchronize_srcu() is too expensive
for his situation).  Now if I can get one of the local weak-memory model
torture-chamber boxes to deal with a recent kernel...

Hardware whines aside, shouldn't be too hard.  Will put something
together...

							Thanx, Paul

> Comments?
> 
> 		Linus
> 
> ----
> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
> index 86e69b7..02326b2 100644
> --- a/drivers/cpufreq/cpufreq.c
> +++ b/drivers/cpufreq/cpufreq.c
> @@ -52,14 +52,39 @@ static void handle_update(void *data);
>   * The mutex locks both lists.
>   */
>  static BLOCKING_NOTIFIER_HEAD(cpufreq_policy_notifier_list);
> -static struct srcu_notifier_head cpufreq_transition_notifier_list;
> 
> -static int __init init_cpufreq_transition_notifier_list(void)
> +/*
> + * This is horribly horribly ugly.
> + *
> + * We really want to initialize the transition notifier list
> + * statically and just once, but there is no static way to
> + * initialize a srcu lock, so we instead make up all this nasty
> + * infrastructure to make sure it's initialized when we use it.
> + *
> + * Bleaargh.
> + */
> +static struct srcu_notifier_head *cpufreq_transition_notifier_list(void)
>  {
> -	srcu_init_notifier_head(&cpufreq_transition_notifier_list);
> -	return 0;
> +	static struct srcu_notifier_head *initialized;
> +	struct srcu_notifier_head *ret;
> +
> +	ret = initialized;
> +	if (!ret) {
> +		static DEFINE_MUTEX(init_lock);
> +
> +		mutex_lock(&init_lock);
> +		ret = initialized;
> +		if (!ret) {
> +			static struct srcu_notifier_head list_head;
> +			ret = &list_head;
> +			srcu_init_notifier_head(ret);
> +			smp_wmb();
> +			initialized = ret;
> +		}
> +		mutex_unlock(&init_lock);
> +	}
> +	return ret;
>  }
> -core_initcall(init_cpufreq_transition_notifier_list);
> 
>  static LIST_HEAD(cpufreq_governor_list);
>  static DEFINE_MUTEX (cpufreq_governor_mutex);
> @@ -268,14 +293,14 @@ void cpufreq_notify_transition(struct cp
>  				freqs->old = policy->cur;
>  			}
>  		}
> -		srcu_notifier_call_chain(&cpufreq_transition_notifier_list,
> +		srcu_notifier_call_chain(cpufreq_transition_notifier_list(),
>  				CPUFREQ_PRECHANGE, freqs);
>  		adjust_jiffies(CPUFREQ_PRECHANGE, freqs);
>  		break;
> 
>  	case CPUFREQ_POSTCHANGE:
>  		adjust_jiffies(CPUFREQ_POSTCHANGE, freqs);
> -		srcu_notifier_call_chain(&cpufreq_transition_notifier_list,
> +		srcu_notifier_call_chain(cpufreq_transition_notifier_list(),
>  				CPUFREQ_POSTCHANGE, freqs);
>  		if (likely(policy) && likely(policy->cpu == freqs->cpu))
>  			policy->cur = freqs->new;
> @@ -1055,7 +1080,7 @@ static int cpufreq_suspend(struct sys_de
>  		freqs.old = cpu_policy->cur;
>  		freqs.new = cur_freq;
> 
> -		srcu_notifier_call_chain(&cpufreq_transition_notifier_list,
> +		srcu_notifier_call_chain(cpufreq_transition_notifier_list(),
>  				    CPUFREQ_SUSPENDCHANGE, &freqs);
>  		adjust_jiffies(CPUFREQ_SUSPENDCHANGE, &freqs);
> 
> @@ -1137,7 +1162,7 @@ static int cpufreq_resume(struct sys_dev
>  			freqs.new = cur_freq;
> 
>  			srcu_notifier_call_chain(
> -					&cpufreq_transition_notifier_list,
> +					cpufreq_transition_notifier_list(),
>  					CPUFREQ_RESUMECHANGE, &freqs);
>  			adjust_jiffies(CPUFREQ_RESUMECHANGE, &freqs);
> 
> @@ -1183,7 +1208,7 @@ int cpufreq_register_notifier(struct not
>  	switch (list) {
>  	case CPUFREQ_TRANSITION_NOTIFIER:
>  		ret = srcu_notifier_chain_register(
> -				&cpufreq_transition_notifier_list, nb);
> +				cpufreq_transition_notifier_list(), nb);
>  		break;
>  	case CPUFREQ_POLICY_NOTIFIER:
>  		ret = blocking_notifier_chain_register(
> @@ -1215,7 +1240,7 @@ int cpufreq_unregister_notifier(struct n
>  	switch (list) {
>  	case CPUFREQ_TRANSITION_NOTIFIER:
>  		ret = srcu_notifier_chain_unregister(
> -				&cpufreq_transition_notifier_list, nb);
> +				cpufreq_transition_notifier_list(), nb);
>  		break;
>  	case CPUFREQ_POLICY_NOTIFIER:
>  		ret = blocking_notifier_chain_unregister(

  parent reply	other threads:[~2006-11-17  2:32 UTC|newest]

Thread overview: 108+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-11-16 20:00 BUG: cpufreq notification broken Thomas Gleixner
2006-11-16 20:15 ` [patch] cpufreq: mark cpufreq_tsc() as core_initcall_sync Ingo Molnar
2006-11-16 20:45   ` Thomas Gleixner
2006-11-16 21:47     ` Linus Torvalds
2006-11-16 22:03       ` Alan Stern
2006-11-16 22:21         ` Linus Torvalds
2006-11-17  3:06           ` Alan Stern
2006-11-17  6:51             ` Paul E. McKenney
2006-11-17  9:29               ` Jens Axboe
2006-11-17 18:39                 ` Oleg Nesterov
2006-11-18  0:28                   ` Paul E. McKenney
2006-11-18 16:15                     ` Alan Stern
2006-11-18 17:14                       ` Paul E. McKenney
2006-11-18 19:34                         ` Oleg Nesterov
2006-11-19 21:26                           ` Paul E. McKenney
2006-11-18 21:00                         ` Alan Stern
2006-11-18 21:25                           ` Oleg Nesterov
2006-11-18 22:13                             ` Alan Stern
2006-11-18 22:46                               ` Oleg Nesterov
2006-11-19 20:12                                 ` Alan Stern
2006-11-19 21:43                           ` Paul E. McKenney
2006-11-20 17:19                             ` Alan Stern
2006-11-20 17:58                               ` Jens Axboe
2006-11-20 19:39                                 ` Alan Stern
2006-11-20 20:13                                   ` Jens Axboe
2006-11-20 21:39                                     ` Alan Stern
2006-11-21  7:39                                       ` Jens Axboe
2006-11-20 18:57                               ` Oleg Nesterov
2006-11-20 20:01                                 ` Alan Stern
2006-11-20 20:51                                   ` Paul E. McKenney
2006-11-21 20:04                                   ` Oleg Nesterov
2006-11-21 20:54                                     ` Alan Stern
2006-11-21 22:07                                     ` Paul E. McKenney
2006-11-20 20:38                                 ` Paul E. McKenney
2006-11-21 16:44                                   ` Oleg Nesterov
2006-11-21 19:56                                     ` Paul E. McKenney
2006-11-21 20:26                                       ` Alan Stern
2006-11-21 23:03                                         ` Paul E. McKenney
2006-11-22  2:17                                           ` Alan Stern
2006-11-22 17:01                                             ` Paul E. McKenney
2006-11-26 22:25                                 ` Oleg Nesterov
2006-11-27 21:10                                   ` Alan Stern
2006-11-28  1:47                                     ` Paul E. McKenney
2006-11-20 19:17                               ` Paul E. McKenney
2006-11-20 20:22                                 ` Alan Stern
2006-11-21 17:55                                   ` Paul E. McKenney
2006-11-21 17:56                             ` Alan Stern
2006-11-21 19:13                               ` Paul E. McKenney
2006-11-21 20:40                                 ` Alan Stern
2006-11-22 18:08                                   ` Paul E. McKenney
2006-11-21 21:01                                 ` Oleg Nesterov
2006-11-22  0:51                                   ` Paul E. McKenney
2006-11-18 18:46                     ` Oleg Nesterov
2006-11-19 21:07                       ` Paul E. McKenney
2006-11-20  7:15                         ` Jens Axboe
2006-11-20 16:59                           ` Paul E. McKenney
2006-11-20 17:55                             ` Jens Axboe
2006-11-20 20:09                               ` Paul E. McKenney
2006-11-20 20:21                                 ` Jens Axboe
2006-11-18 19:02                     ` Oleg Nesterov
2006-11-19 21:23                       ` Paul E. McKenney
2006-11-17 19:15                 ` Paul E. McKenney
2006-11-17 19:27                   ` Alan Stern
2006-11-18  0:38                     ` Paul E. McKenney
2006-11-18  4:33                       ` Alan Stern
2006-11-18  4:51                         ` Andrew Morton
2006-11-18  5:57                           ` Paul E. McKenney
2006-11-19 19:00                 ` Oleg Nesterov
2006-11-19 20:21                   ` Alan Stern
2006-11-19 20:55                     ` Oleg Nesterov
2006-11-19 21:09                       ` Alan Stern
2006-11-19 21:17                         ` Oleg Nesterov
2006-11-19 21:54                           ` Paul E. McKenney
2006-11-19 22:28                             ` Oleg Nesterov
2006-11-20  5:47                               ` Paul E. McKenney
2006-11-19 21:20                       ` Paul E. McKenney
2006-11-19 21:50                         ` Oleg Nesterov
2006-11-19 22:04                           ` Paul E. McKenney
2006-11-23 14:59                   ` Oleg Nesterov
2006-11-23 20:40                     ` Paul E. McKenney
2006-11-23 21:34                       ` Oleg Nesterov
2006-11-23 21:49                       ` Oleg Nesterov
2006-11-27  4:33                         ` Paul E. McKenney
2006-11-24 18:21                     ` Oleg Nesterov
2006-11-24 20:04                       ` Jens Axboe
2006-11-24 20:47                       ` Alan Stern
2006-11-24 21:13                         ` Oleg Nesterov
2006-11-25  3:24                           ` Alan Stern
2006-11-25 17:14                             ` Oleg Nesterov
2006-11-25 22:06                               ` Alan Stern
2006-11-26 21:34                                 ` Oleg Nesterov
2006-11-27  5:02                       ` Paul E. McKenney
2006-11-27 16:11                         ` Oleg Nesterov
2006-11-27 16:56                           ` Oleg Nesterov
2006-11-29 19:29                           ` Paul E. McKenney
2006-11-29 20:16                             ` Oleg Nesterov
2006-11-29 23:08                               ` Paul E. McKenney
2006-11-30  0:01                                 ` Oleg Nesterov
2006-11-17  2:33       ` Paul E. McKenney [this message]
2006-11-16 20:52   ` Peter Zijlstra
2006-11-16 21:20   ` Andrew Morton
2006-11-16 21:27     ` Thomas Gleixner
2006-11-20 19:57   ` Linus Torvalds
2006-11-16 20:27 ` BUG: cpufreq notification broken Alan Stern
2006-11-16 21:09   ` Thomas Gleixner
2006-11-16 21:26     ` Alan Stern
2006-11-16 21:36       ` Thomas Gleixner
2006-11-16 21:56         ` Alan Stern

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=20061117023316.GA3707@us.ibm.com \
    --to=paulmck@linux.vnet.ibm.com \
    --cc=ak@suse.de \
    --cc=akpm@osdl.org \
    --cc=arjan@infradead.org \
    --cc=davem@davemloft.net \
    --cc=johnstul@us.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=stern@rowland.harvard.edu \
    --cc=tglx@timesys.com \
    --cc=torvalds@osdl.org \
    /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.