All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nathan Zimmer <nzimmer@sgi.com>
To: Viresh Kumar <viresh.kumar@linaro.org>
Cc: rjw@sisk.pl, cpufreq@vger.kernel.org, linux-pm@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] cpufreq: convert the cpufreq_driver to use the rcu
Date: Wed, 3 Apr 2013 11:37:10 -0500	[thread overview]
Message-ID: <515C5AB6.5090109@sgi.com> (raw)
In-Reply-To: <CAKohpon1QiCfJhWBi_f7U1EU410JMGHq+QnpEPJ+rdiUjsKsQA@mail.gmail.com>

On 04/03/2013 10:32 AM, Viresh Kumar wrote:
> Please always mention Version number and history. Not everybody
> remembers what changed after last version.
Your right.  I was rushing and forgot.
I need to develop the habit of adding some history to my git commits 
when I amend them.

>
> On 3 April 2013 20:33, Nathan Zimmer <nzimmer@sgi.com> wrote:
>> We eventually would like to remove the rwlock cpufreq_driver_lock or convert
>> it back to a spinlock and protect the read sections with RCU.  The first step in
> Why do we want to convert it back to spinlock?
Documentation/spinlocks.txt:84
I am not sure why but there is the directive I am following.
>> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
>>   bool have_governor_per_policy(void)
>>   {
>> -       return cpufreq_driver->have_governor_per_policy;
>> +       bool have_governor;
> Name it have_governor_per_policy, it looks wrong otherwise.
>
>> +       rcu_read_lock();
>> +       have_governor = rcu_dereference(cpufreq_driver)->have_governor_per_policy;
>> +       rcu_read_unlock();
>> +       return have_governor;
>>   }
Will do.
>>   static ssize_t show_scaling_driver(struct cpufreq_policy *policy, char *buf)
>>   {
>> -       return scnprintf(buf, CPUFREQ_NAME_PLEN, "%s\n", cpufreq_driver->name);
>> +       char *name;
>> +       rcu_read_lock();
>> +       name = rcu_dereference(cpufreq_driver)->name;
>> +       rcu_read_unlock();
>> +       return scnprintf(buf, CPUFREQ_NAME_PLEN, "%s\n", name);
>>   }
> This is the definition of struct cpufreq_driver:
>
> struct cpufreq_driver {
> 	struct module           *owner;
> 	char			name[CPUFREQ_NAME_LEN];
>
>         ...
> };
>
> Purpose of rcu read_lock/unlock are to define the rcu critical section
> after which rcu layer is free to free the memory allocated to earlier
> instance of cpufreq_driver.
>
> So, after the unlock() call you _should_not_ use the memory allocated to
> cpufreq_driver instance. And here, you are using memory allocated to name[]
> after the unlock() call.
Ok I'll fix this spot.

> Which looks to be wrong... I left other parts of driver upto you to fix for this
> "rule of thumb".
In places like show_bios_limit and cpufreq_add_dev_interface we know 
that the memory will still
be there since the cpufreq_driver->owner is held.

> Sorry for not pointing this earlier but rcu is as new to me as it is
> to you. I know
> you must be frustrated with so many versions of this patch, and everytime we
> get a new problem to you... Don't get disheartened with it.. Keep the good work
> going :)
Making a learners mistake isn't really discouraging to me, even when I 
do it twice.

> --
> viresh

WARNING: multiple messages have this Message-ID (diff)
From: Nathan Zimmer <nzimmer@sgi.com>
To: Viresh Kumar <viresh.kumar@linaro.org>
Cc: <rjw@sisk.pl>, <cpufreq@vger.kernel.org>,
	<linux-pm@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] cpufreq: convert the cpufreq_driver to use the rcu
Date: Wed, 3 Apr 2013 11:37:10 -0500	[thread overview]
Message-ID: <515C5AB6.5090109@sgi.com> (raw)
In-Reply-To: <CAKohpon1QiCfJhWBi_f7U1EU410JMGHq+QnpEPJ+rdiUjsKsQA@mail.gmail.com>

On 04/03/2013 10:32 AM, Viresh Kumar wrote:
> Please always mention Version number and history. Not everybody
> remembers what changed after last version.
Your right.  I was rushing and forgot.
I need to develop the habit of adding some history to my git commits 
when I amend them.

>
> On 3 April 2013 20:33, Nathan Zimmer <nzimmer@sgi.com> wrote:
>> We eventually would like to remove the rwlock cpufreq_driver_lock or convert
>> it back to a spinlock and protect the read sections with RCU.  The first step in
> Why do we want to convert it back to spinlock?
Documentation/spinlocks.txt:84
I am not sure why but there is the directive I am following.
>> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
>>   bool have_governor_per_policy(void)
>>   {
>> -       return cpufreq_driver->have_governor_per_policy;
>> +       bool have_governor;
> Name it have_governor_per_policy, it looks wrong otherwise.
>
>> +       rcu_read_lock();
>> +       have_governor = rcu_dereference(cpufreq_driver)->have_governor_per_policy;
>> +       rcu_read_unlock();
>> +       return have_governor;
>>   }
Will do.
>>   static ssize_t show_scaling_driver(struct cpufreq_policy *policy, char *buf)
>>   {
>> -       return scnprintf(buf, CPUFREQ_NAME_PLEN, "%s\n", cpufreq_driver->name);
>> +       char *name;
>> +       rcu_read_lock();
>> +       name = rcu_dereference(cpufreq_driver)->name;
>> +       rcu_read_unlock();
>> +       return scnprintf(buf, CPUFREQ_NAME_PLEN, "%s\n", name);
>>   }
> This is the definition of struct cpufreq_driver:
>
> struct cpufreq_driver {
> 	struct module           *owner;
> 	char			name[CPUFREQ_NAME_LEN];
>
>         ...
> };
>
> Purpose of rcu read_lock/unlock are to define the rcu critical section
> after which rcu layer is free to free the memory allocated to earlier
> instance of cpufreq_driver.
>
> So, after the unlock() call you _should_not_ use the memory allocated to
> cpufreq_driver instance. And here, you are using memory allocated to name[]
> after the unlock() call.
Ok I'll fix this spot.

> Which looks to be wrong... I left other parts of driver upto you to fix for this
> "rule of thumb".
In places like show_bios_limit and cpufreq_add_dev_interface we know 
that the memory will still
be there since the cpufreq_driver->owner is held.

> Sorry for not pointing this earlier but rcu is as new to me as it is
> to you. I know
> you must be frustrated with so many versions of this patch, and everytime we
> get a new problem to you... Don't get disheartened with it.. Keep the good work
> going :)
Making a learners mistake isn't really discouraging to me, even when I 
do it twice.

> --
> viresh


  reply	other threads:[~2013-04-03 16:37 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <AKohpo=Um9LGhGtMB0z9C2jxmS3oHwV7i_Gmsq5rR80ZcGYyLw@mail.gmail.com>
2013-04-03 15:03 ` [PATCH] cpufreq: convert the cpufreq_driver to use the rcu Nathan Zimmer
2013-04-03 15:32   ` Viresh Kumar
2013-04-03 16:37     ` Nathan Zimmer [this message]
2013-04-03 16:37       ` Nathan Zimmer
2013-04-04 14:53       ` [PATCH linux-next v8] " Nathan Zimmer
2013-04-04 16:27         ` Viresh Kumar
2013-04-28 22:22           ` Rafael J. Wysocki
2013-04-29 21:37             ` Paul E. McKenney
2013-04-29 21:47               ` Rafael J. Wysocki
2013-04-29 21:43                 ` Nathan Zimmer
2013-04-29 21:43                   ` Nathan Zimmer

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=515C5AB6.5090109@sgi.com \
    --to=nzimmer@sgi.com \
    --cc=cpufreq@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=rjw@sisk.pl \
    --cc=viresh.kumar@linaro.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.