From: "John Kacur" <jkacur@gmail.com>
To: "Andrew Morton" <akpm@linux-foundation.org>
Cc: mgross@linux.intel.com, linux-kernel@vger.kernel.org,
linux-rt-users@vger.kernel.org, peterz@infradead.org,
rostedt@goodmis.org, mingo@elte.hu, tglx@linutronix.de,
arjan@infradead.org
Subject: Re: [PATCH RFC] pm_qos_requirement might sleep
Date: Fri, 29 Aug 2008 08:31:12 +0200 [thread overview]
Message-ID: <520f0cf10808282331r3425f4f4jfac2d3a7d53c8821@mail.gmail.com> (raw)
In-Reply-To: <20080828173201.8912a1f3.akpm@linux-foundation.org>
On Fri, Aug 29, 2008 at 2:32 AM, Andrew Morton
<akpm@linux-foundation.org> wrote:
> On Thu, 28 Aug 2008 12:44:20 -0700
> mark gross <mgross@linux.intel.com> wrote:
>
>> From: John Kacur <jkacur at gmail dot com>
>
> I tend to deobfuscate email addresses when preparing the changelogs.
>
> Not sure why, really, and I feel a bit guilty about doing it (hey, you
> can forward the resulting spam to me if you like). One reason I guess
> is to avoid breaking all the emails which my scripts will automatically
> send out as the patch goes through its little lifecycle. Some of which
> can sometimes be quite important.
>
>> Patch to make PM_QOS and CPU_IDLE play nicer when ran with the
>> RT-Preempt kernel. CPU_IDLE polls the target_value's of some of the
>> pm_qos parameters from the idle loop causing sleeping locking
>> warnings. Changing the target_value to an atomic avoids this issue.
>>
>> Signed-off-by: mark gross <mgross@linux.intel.com>
>>
>> Thanks,
>>
>> --mgross
>>
>>
>> Remove the spinlock in pm_qos_requirement by making target_value an atomic type.
>> This is necessary for real-time since pm_qos_requirement is called by idle and
>> cannot be allowed to sleep.
>> Signed-off-by: John Kacur <jkacur at gmail dot com>
>
> As usual when I get two different changelogs, I create a masterpiece
> which is better than either of the originals!
>
>> Index: linux-2.6/kernel/pm_qos_params.c
>> ===================================================================
>> --- linux-2.6.orig/kernel/pm_qos_params.c 2008-08-08 07:52:01.000000000 -0700
>> +++ linux-2.6/kernel/pm_qos_params.c 2008-08-28 12:14:55.000000000 -0700
>> @@ -43,7 +43,7 @@
>> #include <linux/uaccess.h>
>>
>> /*
>> - * locking rule: all changes to target_value or requirements or notifiers lists
>> + * locking rule: all changes to requirements or notifiers lists
>> * or pm_qos_object list and pm_qos_objects need to happen with pm_qos_lock
>> * held, taken with _irqsave. One lock to rule them all
>> */
>> @@ -66,7 +66,7 @@
>> struct miscdevice pm_qos_power_miscdev;
>> char *name;
>> s32 default_value;
>> - s32 target_value;
>> + atomic_t target_value;
>> s32 (*comparitor)(s32, s32);
>> };
>>
>> @@ -77,7 +77,7 @@
>> .notifiers = &cpu_dma_lat_notifier,
>> .name = "cpu_dma_latency",
>> .default_value = 2000 * USEC_PER_SEC,
>> - .target_value = 2000 * USEC_PER_SEC,
>> + .target_value = ATOMIC_INIT(2000 * USEC_PER_SEC),
>> .comparitor = min_compare
>> };
>>
>> @@ -87,7 +87,7 @@
>> .notifiers = &network_lat_notifier,
>> .name = "network_latency",
>> .default_value = 2000 * USEC_PER_SEC,
>> - .target_value = 2000 * USEC_PER_SEC,
>> + .target_value = ATOMIC_INIT(2000 * USEC_PER_SEC),
>> .comparitor = min_compare
>> };
>>
>> @@ -99,7 +99,7 @@
>> .notifiers = &network_throughput_notifier,
>> .name = "network_throughput",
>> .default_value = 0,
>> - .target_value = 0,
>> + .target_value = ATOMIC_INIT(0),
>> .comparitor = max_compare
>> };
>>
>> @@ -150,11 +150,11 @@
>> extreme_value = pm_qos_array[target]->comparitor(
>> extreme_value, node->value);
>> }
>> - if (pm_qos_array[target]->target_value != extreme_value) {
>> + if (atomic_read(&pm_qos_array[target]->target_value) != extreme_value) {
>> call_notifier = 1;
>> - pm_qos_array[target]->target_value = extreme_value;
>> + atomic_set(&pm_qos_array[target]->target_value, extreme_value);
>> pr_debug(KERN_ERR "new target for qos %d is %d\n", target,
>> - pm_qos_array[target]->target_value);
>> + atomic_read(&pm_qos_array[target]->target_value));
>> }
>> spin_unlock_irqrestore(&pm_qos_lock, flags);
>>
>> @@ -193,14 +193,7 @@
>> */
>> int pm_qos_requirement(int pm_qos_class)
>> {
>> - int ret_val;
>> - unsigned long flags;
>> -
>> - spin_lock_irqsave(&pm_qos_lock, flags);
>> - ret_val = pm_qos_array[pm_qos_class]->target_value;
>> - spin_unlock_irqrestore(&pm_qos_lock, flags);
>> -
>> - return ret_val;
>> + return atomic_read(&pm_qos_array[pm_qos_class]->target_value);
>> }
>> EXPORT_SYMBOL_GPL(pm_qos_requirement);
>
> OK, so I've stared and stared. This patch doesn't do anything.
>
> I'm suspecting that the rt patch might be doing something silly, like
> thinking that it needs to take pm_qos_lock to read a single word from
> memory, or something like that.
>
> But this patch is simply not understandable given the amount of
> information which you guys have provided.
>
Hi Andrew
The purpose of the patch is to remove the spin_lock around the read in
the function pm_qos_requirement - since spinlocks can sleep in -rt and
this function is called from idle. I did propose a patch, that simply
removed the spinlock, since Peter Zilstra and others (yourself) point
out, the lock isn't needed to read a single word from memory. Although
the patch worked fine, Arjan objected to it, because it was not
symmetric. A reader of the code might wonder why it was locked in
other functions but not here. He suggested changing it to an atomic
type might be less confusing. The alternative which I like better
actually is to simply remove the lock in pm_qos_requirement and add a
comment for readers of the code.
John
next prev parent reply other threads:[~2008-08-29 6:31 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-08-04 20:52 [PATCH RFC] pm_qos_requirement might sleep John Kacur
2008-08-05 7:25 ` Peter Zijlstra
2008-08-05 20:49 ` mark gross
2008-08-05 21:09 ` Peter Zijlstra
2008-08-05 22:18 ` John Kacur
2008-08-11 13:25 ` John Kacur
2008-08-12 22:49 ` mark gross
2008-08-13 8:24 ` John Kacur
2008-08-14 15:52 ` mark gross
2008-08-14 17:48 ` Peter Zijlstra
2008-08-14 22:51 ` John Kacur
2008-08-20 19:14 ` mark gross
2008-08-25 16:34 ` mark gross
2008-08-25 16:35 ` Peter Zijlstra
2008-08-26 8:48 ` John Kacur
2008-08-26 16:18 ` mark gross
2008-08-26 17:45 ` John Kacur
2008-08-28 19:38 ` mark gross
2008-08-28 19:44 ` mark gross
2008-08-29 0:32 ` Andrew Morton
2008-08-29 6:31 ` John Kacur [this message]
2008-08-29 14:29 ` Steven Rostedt
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=520f0cf10808282331r3425f4f4jfac2d3a7d53c8821@mail.gmail.com \
--to=jkacur@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=arjan@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rt-users@vger.kernel.org \
--cc=mgross@linux.intel.com \
--cc=mingo@elte.hu \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
/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).