The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Huang Rui <ray.huang@amd.com>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: Borislav Petkov <bp@suse.de>,
	Peter Zijlstra <peterz@infradead.org>,
	"Ingo Molnar" <mingo@kernel.org>,
	Andy Lutomirski <luto@amacapital.net>,
	"Robert Richter" <rric@kernel.org>,
	Jacob Shin <jacob.w.shin@gmail.com>,
	"Arnaldo Carvalho de Melo" <acme@kernel.org>,
	Kan Liang <kan.liang@intel.com>, <linux-kernel@vger.kernel.org>,
	<spg_linux_kernel@amd.com>, <x86@kernel.org>,
	Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>,
	Aravind Gopalakrishnan <Aravind.Gopalakrishnan@amd.com>,
	Borislav Petkov <bp@alien8.de>,
	"Fengguang Wu" <fengguang.wu@intel.com>,
	Guenter Roeck <linux@roeck-us.net>
Subject: Re: [PATCH v6 2/2] perf/x86/amd/power: Add AMD accumulated power reporting mechanism
Date: Fri, 4 Mar 2016 00:18:11 +0800	[thread overview]
Message-ID: <20160303161809.GA2791@hr-amur2> (raw)
In-Reply-To: <alpine.DEB.2.11.1603031619390.3597@nanos>

On Thu, Mar 03, 2016 at 04:26:46PM +0100, Thomas Gleixner wrote:
> On Thu, 3 Mar 2016, Huang Rui wrote:
> > On Thu, Mar 03, 2016 at 09:50:11AM +0100, Thomas Gleixner wrote:
> > > On Thu, 3 Mar 2016, Huang Rui wrote:
> > > And of course if CPU_DOWN_PREPARE fails and this is the last cpu in the
> > > compute unit, nothing takes over the duty for this compute unit. So you need
> > > to handle CPU_DOWN_FAILED ....
> > > 
> > 
> > OK, so I need to do power_cpu_init when notified CPU_DOWN_FAILED, am I
> > right?
> 
> Yes.
>  
> > > > +	cpu_notifier_register_begin();
> > > > +
> > > > +	/* Choose one online core of each compute unit. */
> > > > +	for (i = 0; i < boot_cpu_data.x86_max_cores; i += smp_num_siblings) {
> > > > +		WARN_ON(cpumask_empty(topology_sibling_cpumask(i)));
> > > 
> > > Err. What guarantees that in each compute unit is one sibling online? And what
> > > value has that WARN_ON? We don't care about the stack trace here, because it's
> > > known already.
> > > 
> > 
> > When this driver is not as module before, I think there should be one
> > sibling online at least at initialization phase. But now, you're
> > right, we cannot guarantee it.
> > 
> > > > +		cpumask_set_cpu(cpumask_any(topology_sibling_cpumask(i)), &cpu_mask);
> > > 
> > > Of course you just continue in that case and end up with:
> > > 
> > >        	      cpumask_set_cpu(nr_cpu_ids, &cpu_mask);
> > > 
> > > i.e. you try to do that on an invalid bit, which will trigger a justified
> > > warning in cpumask_set_cpu() if CONFIG_DEBUG_PER_CPU_MAPS is enabled.
> > > 
> > > Aside of that this only handles a single socket. And why do you do the above
> > > if you handle the same thing in the loop below?
> > > 
> > 
> > Because the sibling online shouldn't be empty at initialization phase
> > if the driver is not module before. So...
> > 
> > Thanks to catch it.
> > 
> > How about below update:
> > 
> > for (i = 0; i < boot_cpu_data.x86_max_cores; i += smp_num_siblings) {
> >         if (!cpumask_empty(topology_sibling_cpumask(i)))
> >                 cpumask_set_cpu(cpumask_any(topology_sibling_cpumask(i)), &cpu_mask);
> > }
> 
> Why? You do a full for_each_online_cpu(i) loop after that, which does
> exactly the same thing, right?
>  

But looks like power_cpu_init cannot handle it if we don't take any
action here.

e. g. 
cpu_mask: 0000 and online mask: 1111 -> power_cpu_init(0) -> cpu_mask is still: 0000

topology_sibling_cpumask(0): 0011
target: 1 (i. e. we cannot do cpumask_set_cpu(0, &cpu_mask))

Maybe, we need to think out a stronger power_cpu_init if you want to
only do init thing at for_each_online_cpu.

> > > > +	}
> > > > +
> > > > +	for_each_online_cpu(i)
> > > > +		power_cpu_init(i);
> > > > +
> > > > +	__register_cpu_notifier(&power_cpu_notifier_nb);
> > > > +
> > > > +	ret = perf_pmu_register(&pmu_class, "power", -1);
> > > > +	if (WARN_ON(ret)) {
> > > > +		pr_warn("AMD Power PMU registration failed\n");
> > > 
> > > This still leaks the cpu notifier. .....
> > > 
> > 
> > OK, so I should do __unregister_cpu_notifier(&power_cpu_notifier_nb)
> > here.
> 
> You can register the notifier after perf_pmu_register succeeded, right?
>  

Yep.

> > > > +	pr_info("AMD Power PMU detected, %d compute units\n", cu_num);
> > > 
> > > Why is the number of compute units interesting at all?
> > > 
> > 
> > Because the accumulated power bases on compute units.
> > We can see the mask from /sys/devices/power/cpumask and number of
> > compute units to know if all compute units are set at cpumask.
> > So I add a printk here, does it make sense?
> 
> No, because it's completely non intuitive. How on earth am I supposed to get
> the connection between /sys/devices/power/cpumask and number of compute units
> without staring at the code? So this is only interesting for a developer who
> can deduce that number from /proc/cpuinfo or dmesg as well.
> 

OK, I will remove unnecessary cu_num next version. 

Thanks,
Rui

  reply	other threads:[~2016-03-03 16:19 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-03  8:04 [PATCH v6 0/2] perf/x86/power: Introduce AMD accumlated power reporting mechanism Huang Rui
2016-03-03  8:04 ` [PATCH v6 1/2] perf/x86: Export events_sysfs_show() Huang Rui
2016-03-03  8:04 ` [PATCH v6 2/2] perf/x86/amd/power: Add AMD accumulated power reporting mechanism Huang Rui
2016-03-03  8:50   ` Thomas Gleixner
2016-03-03 15:13     ` Huang Rui
2016-03-03 15:26       ` Thomas Gleixner
2016-03-03 16:18         ` Huang Rui [this message]
2016-03-03 17:57           ` Thomas Gleixner
2016-03-04  3:11             ` Huang Rui

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=20160303161809.GA2791@hr-amur2 \
    --to=ray.huang@amd.com \
    --cc=Aravind.Gopalakrishnan@amd.com \
    --cc=acme@kernel.org \
    --cc=bp@alien8.de \
    --cc=bp@suse.de \
    --cc=fengguang.wu@intel.com \
    --cc=jacob.w.shin@gmail.com \
    --cc=kan.liang@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=luto@amacapital.net \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --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