From: Santosh Shilimkar <santosh.shilimkar@ti.com>
To: Daniel Lezcano <daniel.lezcano@linaro.org>
Cc: andrew@lunn.ch, khilman@deeprootsystems.com, nsekhar@ti.com,
josephl@nvidia.com, kgene.kim@samsung.com, patches@linaro.org,
magnus.damm@gmail.com, tony@atomide.com, plagnioj@jcrosoft.com,
linaro-kernel@lists.linaro.org, jason@lakedaemon.net,
swarren@wwwdotorg.org, rob.herring@calxeda.com, rjw@sisk.pl,
horms@verge.net.au, linux@maxim.org.za,
linux-arm-kernel@lists.infradead.org, deepthi@linux.vnet.ibm.com,
jkosina@suse.cz, linux-pm@vger.kernel.org, lethal@linux-sh.org,
kernel@pengutronix.de
Subject: Re: [V4 patch 03/15] cpuidle: make a single register function for all
Date: Tue, 23 Apr 2013 18:34:11 +0530 [thread overview]
Message-ID: <517686CB.7080909@ti.com> (raw)
In-Reply-To: <517683DD.6060805@linaro.org>
On Tuesday 23 April 2013 06:21 PM, Daniel Lezcano wrote:
> On 04/23/2013 02:32 PM, Santosh Shilimkar wrote:
>> On Tuesday 23 April 2013 02:24 PM, Daniel Lezcano wrote:
>>> The usual scheme to initialize a cpuidle driver on a SMP is:
>>>
>>> cpuidle_register_driver(drv);
>>> for_each_possible_cpu(cpu) {
>>> device = &per_cpu(cpuidle_dev, cpu);
>>> cpuidle_register_device(device);
>>> }
>>>
>>> This code is duplicated in each cpuidle driver.
>>>
>>> On UP systems, it is done this way:
>>>
>>> cpuidle_register_driver(drv);
>>> device = &per_cpu(cpuidle_dev, cpu);
>>> cpuidle_register_device(device);
>>>
>>> On UP, the macro 'for_each_cpu' does one iteration:
>>>
>>> #define for_each_cpu(cpu, mask) \
>>> for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)mask)
>>>
>>> Hence, the initialization loop is the same for UP than SMP.
>>>
>>> Beside, we saw different bugs / mis-initialization / return code unchecked in
>>> the different drivers, the code is duplicated including bugs. After fixing all
>>> these ones, it appears the initialization pattern is the same for everyone.
>>>
>>> Please note, some drivers are doing dev->state_count = drv->state_count. This is
>>> not necessary because it is done by the cpuidle_enable_device function in the
>>> cpuidle framework. This is true, until you have the same states for all your
>>> devices. Otherwise, the 'low level' API should be used instead with the specific
>>> initialization for the driver.
>>>
>>> Let's add a wrapper function doing this initialization with a cpumask parameter
>>> for the coupled idle states and use it for all the drivers.
>>>
>>> That will save a lot of LOC, consolidate the code, and the modifications in the
>>> future could be done in a single place. Another benefit is the consolidation of
>>> the cpuidle_device variable which is now in the cpuidle framework and no longer
>>> spread accross the different arch specific drivers.
>>>
>>> Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
>>> ---
>>
>> I don't see you have addressed the comment on V3 [1] i gave for the subject patch
>> Any reason ?
>
> Yes, sorry for not answering.
>
> This modification should be handled in the __cpuidle_register_device
> function.
>
> diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c
> index 49e8d30..936d862 100644
> --- a/drivers/cpuidle/cpuidle.c
> +++ b/drivers/cpuidle/cpuidle.c
> @@ -372,7 +372,7 @@ static int __cpuidle_register_device(struct
> cpuidle_device *dev)
> int ret;
> struct cpuidle_driver *drv = cpuidle_get_cpu_driver(dev);
>
> - if (!try_module_get(drv->owner))
> + if (!drv || !try_module_get(drv->owner))
> return -EINVAL;
>
> per_cpu(cpuidle_devices, dev->cpu) = dev;
>
> Thus, the cpuidle_register function is not impacted by this as it will
> always do cpuidle_register_driver, followed by cpuidle_register_device.
>
I still don't follow you. I know the fix will be needed but in the subject
patch sequence as well, the device registration should be done first and
then the driver registration. Below hunk I mean.
----
+int cpuidle_register(struct cpuidle_driver *drv,
+ const struct cpumask *const coupled_cpus)
+{
+ int ret, cpu;
+ struct cpuidle_device *device;
+
+ ret = cpuidle_register_driver(drv);
+ if (ret) {
+ pr_err("failed to register cpuidle driver\n");
+ return ret;
+ }
+
+ for_each_possible_cpu(cpu) {
+ device = &per_cpu(cpuidle_dev, cpu);
+ device->cpu = cpu;
+
+#ifdef CONFIG_ARCH_NEEDS_CPU_IDLE_COUPLED
+ /*
+ * On multiplatform for ARM, the coupled idle states could
+ * enabled in the kernel even if the cpuidle driver does not
+ * use it. Note, coupled_cpus is a struct copy.
+ */
+ if (coupled_cpus)
+ device->coupled_cpus = *coupled_cpus;
+#endif
+ ret = cpuidle_register_device(device);
+ if (!ret)
+ continue;
+
+ pr_err("Failed to register cpuidle device for cpu%d\n", cpu);
+
+ cpuidle_unregister(drv);
+ break;
+ }
------
I also had a comment on kernel doc for both of these new functions.
Out of curiosity I have seen this patch again o.w I would have assumed
that you did address the comments.
Regards,
Santosh
next prev parent reply other threads:[~2013-04-23 13:04 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-23 8:54 [V4 patch 00/15] cpuidle: code consolidation Daniel Lezcano
2013-04-23 8:54 ` [V4 patch 01/15] cpuidle: remove en_core_tk_irqen flag Daniel Lezcano
2013-04-23 8:54 ` [V4 patch 02/15] ARM: ux500: cpuidle: replace for_each_online_cpu by for_each_possible_cpu Daniel Lezcano
2013-04-30 9:16 ` Chander Kashyap
2013-04-23 8:54 ` [V4 patch 03/15] cpuidle: make a single register function for all Daniel Lezcano
2013-04-23 12:19 ` Rob Herring
2013-04-23 12:32 ` Santosh Shilimkar
2013-04-23 12:51 ` Daniel Lezcano
2013-04-23 13:04 ` Santosh Shilimkar [this message]
2013-04-23 8:54 ` [V4 patch 04/15] ARM: ux500: cpuidle: use init/exit common routine Daniel Lezcano
2013-04-23 8:54 ` [V4 patch 05/15] ARM: at91: " Daniel Lezcano
2013-04-23 8:54 ` [V4 patch 06/15] ARM: OMAP3: " Daniel Lezcano
2013-04-23 8:54 ` [V4 patch 07/15] ARM: tegra: " Daniel Lezcano
2013-04-23 8:54 ` [V4 patch 08/15] ARM: shmobile: " Daniel Lezcano
2013-04-23 8:54 ` [V4 patch 09/15] ARM: OMAP4: " Daniel Lezcano
2013-04-23 8:54 ` [V4 patch 10/15] ARM: tegra: cpuidle: use init/exit common routine for tegra2 Daniel Lezcano
2013-04-23 8:54 ` [V4 patch 11/15] ARM: tegra: cpuidle: use init/exit common routine for tegra3 Daniel Lezcano
2013-04-23 8:54 ` [V4 patch 12/15] ARM: calxeda: cpuidle: use init/exit common routine Daniel Lezcano
2013-04-23 8:54 ` [V4 patch 13/15] ARM: kirkwood: " Daniel Lezcano
2013-04-23 8:54 ` [V4 patch 14/15] ARM: davinci: " Daniel Lezcano
2013-04-23 8:54 ` [V4 patch 15/15] ARM: imx: " Daniel Lezcano
2013-04-23 12:00 ` [V4 patch 00/15] cpuidle: code consolidation Rafael J. Wysocki
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=517686CB.7080909@ti.com \
--to=santosh.shilimkar@ti.com \
--cc=andrew@lunn.ch \
--cc=daniel.lezcano@linaro.org \
--cc=deepthi@linux.vnet.ibm.com \
--cc=horms@verge.net.au \
--cc=jason@lakedaemon.net \
--cc=jkosina@suse.cz \
--cc=josephl@nvidia.com \
--cc=kernel@pengutronix.de \
--cc=kgene.kim@samsung.com \
--cc=khilman@deeprootsystems.com \
--cc=lethal@linux-sh.org \
--cc=linaro-kernel@lists.linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-pm@vger.kernel.org \
--cc=linux@maxim.org.za \
--cc=magnus.damm@gmail.com \
--cc=nsekhar@ti.com \
--cc=patches@linaro.org \
--cc=plagnioj@jcrosoft.com \
--cc=rjw@sisk.pl \
--cc=rob.herring@calxeda.com \
--cc=swarren@wwwdotorg.org \
--cc=tony@atomide.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).