mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Huang Rui <ray.huang@amd.com>
Cc: "Borislav Petkov" <bp@suse.de>, "Ingo Molnar" <mingo@kernel.org>,
	"Andy Lutomirski" <luto@amacapital.net>,
	"Thomas Gleixner" <tglx@linutronix.de>,
	"Robert Richter" <rric@kernel.org>,
	"Jacob Shin" <jacob.w.shin@gmail.com>,
	"John Stultz" <john.stultz@linaro.org>,
	"Fr�d�ric Weisbecker" <fweisbec@gmail.com>,
	linux-kernel@vger.kernel.org, spg_linux_kernel@amd.com,
	x86@kernel.org, "Guenter Roeck" <linux@roeck-us.net>,
	"Andreas Herrmann" <herrmann.der.user@googlemail.com>,
	"Suravee Suthikulpanit" <suravee.suthikulpanit@amd.com>,
	"Aravind Gopalakrishnan" <Aravind.Gopalakrishnan@amd.com>,
	"Borislav Petkov" <bp@alien8.de>,
	"Fengguang Wu" <fengguang.wu@intel.com>,
	"Aaron Lu" <aaron.lu@intel.com>
Subject: Re: [PATCH v2 5/5] perf/x86/amd/power: Add AMD accumulated power reporting mechanism
Date: Wed, 20 Jan 2016 10:22:44 +0100	[thread overview]
Message-ID: <20160120092244.GH6357@twins.programming.kicks-ass.net> (raw)
In-Reply-To: <20160120044823.GA13477@hr-amur2>

On Wed, Jan 20, 2016 at 12:48:24PM +0800, Huang Rui wrote:
> Hi Peter,
> 
> Thanks so much to your comments.
> 
> On Tue, Jan 19, 2016 at 01:12:50PM +0100, Peter Zijlstra wrote:
> > On Thu, Jan 14, 2016 at 10:50:08AM +0800, Huang Rui wrote:
> > > +struct power_pmu {
> > > +	spinlock_t		lock;
> > 
> > This should be a raw_spinlock_t, as it'll be nested under other
> > raw_spinlock_t's.
> > 
> 
> Do you mean the following spinlock operations are in hardware
> interrupts disabled case, so I need use raw_spinlock_t instead, right?


			mainline		-rt

raw_spinlock_t		spin-waits		spin-waits
spinlock_t		spin-waits		blocks (rt-mutex)
struct mutex		blocks			blocks (rt-mutex)


since these functions are themselves called with raw_spinlock_t held
(perf_event_context::lock for example, but also rq::lock), any lock
nested inside them must also be raw_spinlock_t.

I have a lockdep patch somewhere that checks these ordering things; I
should rebase and post that again.

> Use raw_spin_lock_irqsave/raw_spin_unlock_irqrestore?

pmu::{start,stop,add,del} will be called with IRQs already disabled.

> > > +static int power_cpu_init(int cpu)
> > > +{
> > > +	int i, cu, ret = 0;
> > > +	cpumask_var_t mask, dummy_mask;
> > > +
> > > +	cu = cpu / cores_per_cu;
> > > +
> > > +	if (!zalloc_cpumask_var(&mask, GFP_KERNEL))
> > > +		return -ENOMEM;
> > > +
> > > +	if (!zalloc_cpumask_var(&dummy_mask, GFP_KERNEL)) {
> > > +		ret = -ENOMEM;
> > > +		goto out;
> > > +	}
> > > +
> > > +	for (i = 0; i < cores_per_cu; i++)
> > > +		cpumask_set_cpu(i, mask);
> > > +
> > > +	cpumask_shift_left(mask, mask, cu * cores_per_cu);
> > > +
> > > +	if (!cpumask_and(dummy_mask, mask, &cpu_mask))
> > > +		cpumask_set_cpu(cpu, &cpu_mask);
> > > +
> > > +	free_cpumask_var(dummy_mask);
> > > +out:
> > > +	free_cpumask_var(mask);
> > > +
> > > +	return ret;
> > > +}
> > 
> > > +static int power_cpu_notifier(struct notifier_block *self,
> > > +			      unsigned long action, void *hcpu)
> > > +{
> > > +	unsigned int cpu = (long)hcpu;
> > > +
> > > +	switch (action & ~CPU_TASKS_FROZEN) {
> > > +	case CPU_UP_PREPARE:
> > > +		if (power_cpu_prepare(cpu))
> > > +			return NOTIFY_BAD;
> > > +		break;
> > > +	case CPU_STARTING:
> > > +		if (power_cpu_init(cpu))
> > > +			return NOTIFY_BAD;
> > 
> > this is called with IRQs disabled, which makes those GFP_KERNEL allocs
> > above a pretty bad idea.
> > 
> 
> Right, so should I use GFP_ATOMIC to allocate cpumask here?

One should not use GFP_ATOMIC if at all possible, also no, -rt cannot do
_any_ allocations from this site.

> > Also, note that -rt cannot actually do _any_ allocations/frees from
> > STARTING.
> > 
> > Please move the allocs/frees to PREPARE/ONLINE.
> > 
> 
> How about add two cpumask_var_t at power_pmu structure? Then allocate
> the two cpumask_var_t (pmu->mask, pmu->dummy_mask), and they can be
> also used on power_cpu_init.

That would work.

  reply	other threads:[~2016-01-20  9:23 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-14  2:50 [PATCH v2 0/5] perf/x86/power: Introduce AMD accumlated " Huang Rui
2016-01-14  2:50 ` [PATCH v2 1/5] x86/amd: move nodes_per_socket into bsp_init_amd Huang Rui
2016-03-21  9:54   ` [tip:perf/urgent] perf/x86/amd: Move nodes_per_socket into bsp_init_amd() tip-bot for Huang Rui
2016-01-14  2:50 ` [PATCH v2 2/5] x86/amd: add accessor for number of cores per compute unit Huang Rui
2016-01-14  2:50 ` [PATCH v2 3/5] x86/cpufeature: add AMD Accumulated Power Mechanism feature flag Huang Rui
2016-03-21  9:55   ` [tip:perf/urgent] x86/cpufeature, perf/x86: Add " tip-bot for Huang Rui
2016-01-14  2:50 ` [PATCH v2 4/5] perf/x86: Move events_sysfs_show outside CPU_SUP_INTEL Huang Rui
2016-01-14  2:50 ` [PATCH v2 5/5] perf/x86/amd/power: Add AMD accumulated power reporting mechanism Huang Rui
2016-01-19 12:12   ` Peter Zijlstra
2016-01-20  4:48     ` Huang Rui
2016-01-20  9:22       ` Peter Zijlstra [this message]
2016-01-21  7:04         ` Huang Rui
2016-01-21  9:02           ` Peter Zijlstra
2016-01-21 14:42             ` Huang Rui
2016-01-21 15:10               ` Peter Zijlstra
2016-01-21 15:24                 ` Huang Rui
2016-01-21 15:51                   ` Peter Zijlstra
2016-01-21 16:59                 ` Borislav Petkov
2016-01-22  8:04                   ` Huang Rui
2016-01-22 17:51                     ` Borislav Petkov
2016-01-14  6:01 ` [PATCH v2 0/5] perf/x86/power: Introduce AMD accumlated " Borislav Petkov

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=20160120092244.GH6357@twins.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=Aravind.Gopalakrishnan@amd.com \
    --cc=aaron.lu@intel.com \
    --cc=bp@alien8.de \
    --cc=bp@suse.de \
    --cc=fengguang.wu@intel.com \
    --cc=fweisbec@gmail.com \
    --cc=herrmann.der.user@googlemail.com \
    --cc=jacob.w.shin@gmail.com \
    --cc=john.stultz@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=luto@amacapital.net \
    --cc=mingo@kernel.org \
    --cc=ray.huang@amd.com \
    --cc=rric@kernel.org \
    --cc=spg_linux_kernel@amd.com \
    --cc=suravee.suthikulpanit@amd.com \
    --cc=tglx@linutronix.de \
    --cc=x86@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

Powered by JetHome