From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
To: Daniel Wagner <daniel.wagner@oss.bmw-carit.de>
Cc: linux-rt-users@vger.kernel.org,
Daniel Wagner <daniel.wagner@bmw-carit.de>
Subject: Re: [RFC v0] thermal: Protect schedule flag by raw spin
Date: Fri, 9 May 2014 14:09:02 +0200 [thread overview]
Message-ID: <20140509120902.GB29014@linutronix.de> (raw)
In-Reply-To: <1397485347-2235-1-git-send-email-daniel.wagner@oss.bmw-carit.de>
* Daniel Wagner | 2014-04-14 16:22:27 [+0200]:
>diff --git a/drivers/thermal/x86_pkg_temp_thermal.c b/drivers/thermal/x86_pkg_temp_thermal.c
>index 7257366..7d0b0ac 100644
>--- a/drivers/thermal/x86_pkg_temp_thermal.c
>+++ b/drivers/thermal/x86_pkg_temp_thermal.c
>@@ -363,16 +363,16 @@ static int pkg_temp_thermal_platform_thermal_notify(__u64 msr_val)
> * are in the same interrupt state. So scheduling on any one CPU in
> * the package is enough and simply return for others.
> */
>- spin_lock_irqsave(&pkg_work_lock, flags);
>+ raw_spin_lock_irqsave(&pkg_work_lock, flags);
> ++pkg_interrupt_cnt;
> if (unlikely(phy_id > max_phy_id) || unlikely(!pkg_work_scheduled) ||
> pkg_work_scheduled[phy_id]) {
> disable_pkg_thres_interrupt();
>- spin_unlock_irqrestore(&pkg_work_lock, flags);
>+ raw_spin_unlock_irqrestore(&pkg_work_lock, flags);
> return -EINVAL;
> }
> pkg_work_scheduled[phy_id] = 1;
>- spin_unlock_irqrestore(&pkg_work_lock, flags);
>+ raw_spin_unlock_irqrestore(&pkg_work_lock, flags);
>
> disable_pkg_thres_interrupt();
> schedule_delayed_work_on(cpu,
This doens't work. Since you come out of the hard-irq context you can
not call schedule_work() here. Currently I don't have any better idea
than to do something like in "x86/mce: Defer mce wakeups to threads for
PREEMPT_RT"
>@@ -426,19 +426,28 @@ static int pkg_temp_thermal_device_add(unsigned int cpu)
> goto err_ret_unlock;
> }
>
>- spin_lock_irqsave(&pkg_work_lock, flags);
>- if (topology_physical_package_id(cpu) > max_phy_id)
>+ if (topology_physical_package_id(cpu) > max_phy_id) {
> max_phy_id = topology_physical_package_id(cpu);
I like this. You shouldn't however modify max_phy_id outside of the
lock. Besides that it looks good.
>- temp = krealloc(pkg_work_scheduled,
>- (max_phy_id+1) * sizeof(u8), GFP_ATOMIC);
>- if (!temp) {
>- spin_unlock_irqrestore(&pkg_work_lock, flags);
>- err = -ENOMEM;
>- goto err_ret_free;
>+
>+ temp = kmalloc((max_phy_id+1) * sizeof(u8), GFP_KERNEL);
>+ if (!temp) {
>+ err = -ENOMEM;
>+ goto err_ret_free;
>+ }
>+
>+ raw_spin_lock_irqsave(&pkg_work_lock, flags);
>+
>+ p = pkg_work_scheduled;
>+
>+ memcpy(temp, pkg_work_scheduled, ksize(pkg_work_scheduled));
>+ pkg_work_scheduled = temp;
>+
>+ pkg_work_scheduled[topology_physical_package_id(cpu)] = 0;
This seems to be the "init" which needs to be done. Now you skip it if
you are first called with 4 and later with 3,2,1,0 for instance. Using
kzalloc() instead of kmalloc() should make it right and avoid the need
of = 0 here.
>+
>+ raw_spin_unlock_irqrestore(&pkg_work_lock, flags);
>+
>+ kfree(p);
> }
>- pkg_work_scheduled = temp;
>- pkg_work_scheduled[topology_physical_package_id(cpu)] = 0;
>- spin_unlock_irqrestore(&pkg_work_lock, flags);
>
> phy_dev_entry->phys_proc_id = topology_physical_package_id(cpu);
> phy_dev_entry->first_cpu = cpu;
Sebastian
next prev parent reply other threads:[~2014-05-09 12:09 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-14 14:22 [RFC v0] thermal: Protect schedule flag by raw spin Daniel Wagner
2014-05-09 12:09 ` Sebastian Andrzej Siewior [this message]
2014-05-12 7:43 ` Daniel Wagner
2014-05-14 10:23 ` Sebastian Andrzej Siewior
2014-05-14 13:36 ` Daniel Wagner
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=20140509120902.GB29014@linutronix.de \
--to=bigeasy@linutronix.de \
--cc=daniel.wagner@bmw-carit.de \
--cc=daniel.wagner@oss.bmw-carit.de \
--cc=linux-rt-users@vger.kernel.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 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).