All of lore.kernel.org
 help / color / mirror / Atom feed
From: Huang Rui <ray.huang@amd.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: "Borislav Petkov" <bp@alien8.de>, "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>,
	"Fengguang Wu" <fengguang.wu@intel.com>,
	"Aaron Lu" <aaron.lu@intel.com>
Subject: Re: [PATCH v4] perf/x86/amd/power: Add AMD accumulated power reporting mechanism
Date: Fri, 29 Jan 2016 16:18:33 +0800	[thread overview]
Message-ID: <20160129081817.GB28282@hr-amur2> (raw)
In-Reply-To: <20160128152848.GT6356@twins.programming.kicks-ass.net>

On Thu, Jan 28, 2016 at 04:28:48PM +0100, Peter Zijlstra wrote:
> On Thu, Jan 28, 2016 at 10:03:15AM +0100, Borislav Petkov wrote:
> 
> > +
> > +struct power_pmu {
> > +	raw_spinlock_t		lock;
> 
> Now that the list is gone, what does this thing protect?
> 

Protect the event count value before measure it.

> > +	struct pmu		*pmu;
> 
> This member seems superfluous, there's only the one possible value.
> 

Currently, it's only one. But there will be more power pmu types in
future processors. Acc power is one of them.

> > +	local64_t		cpu_sw_pwr_ptsc;
> > +
> > +	/*
> > +	 * These two cpumasks are used for avoiding the allocations on the
> > +	 * CPU_STARTING phase because power_cpu_prepare() will be called with
> > +	 * IRQs disabled.
> > +	 */
> > +	cpumask_var_t		mask;
> > +	cpumask_var_t		tmp_mask;
> > +};
> > +
> > +static struct pmu pmu_class;
> > +
> > +/*
> > + * Accumulated power represents the sum of each compute unit's (CU) power
> > + * consumption. On any core of each CU we read the total accumulated power from
> > + * MSR_F15H_CU_PWR_ACCUMULATOR. cpu_mask represents CPU bit map of all cores
> > + * which are picked to measure the power for the CUs they belong to.
> > + */
> > +static cpumask_t cpu_mask;
> > +
> > +static DEFINE_PER_CPU(struct power_pmu *, amd_power_pmu);
> > +
> > +static u64 event_update(struct perf_event *event, struct power_pmu *pmu)
> > +{
> 
> Is there ever a case where @pmu != __this_cpu_read(power_pmu) ?
> 

It only might be called at pmu:{read, stop}, they ensure
__this_cpu_read(amd_power_pmu). Is there any other case I missed?

> > +	struct hw_perf_event *hwc = &event->hw;
> > +	u64 prev_raw_count, new_raw_count, prev_ptsc, new_ptsc;
> > +	u64 delta, tdelta;
> > +
> > +again:
> > +	prev_raw_count = local64_read(&hwc->prev_count);
> > +	prev_ptsc = local64_read(&pmu->cpu_sw_pwr_ptsc);
> > +	rdmsrl(event->hw.event_base, new_raw_count);
> 
> Is hw.event_base != MSR_F15H_CU_PWR_ACCUMULATOR possible?
> 

Any case that I missed?

Could you explain more?

> > +	rdmsrl(MSR_F15H_PTSC, new_ptsc);
> 
> 
> Also, I suspect this doesn't do what you expect it to do.
> 
> We measure per-event PWR_ACC deltas, but per CPU PTSC values. These do
> not match when there's more than 1 event on the CPU.
> 

OK, I see. My intention of pre-event's count (event->count) should be
PWR_ACC values after divided by PTSC. But here we cannot use
local64_read(&hwc->prev_count) as previous value of PWR_ACC before
divided by PTSC. Thanks to catch it.

> I would suggest adding a new struct to the hw_perf_event union with the
> two u64 deltas like:
> 
> 	struct { /* amd_power */
> 		u64 pwr_acc;
> 		u64 ptsc;
> 	};
> 
> And track these values per-event.
> 

Thanks to reminder.

Thanks,
Rui

      reply	other threads:[~2016-01-29  8:18 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-28  6:38 [PATCH v4] perf/x86/amd/power: Add AMD accumulated power reporting mechanism Huang Rui
2016-01-28  9:03 ` Borislav Petkov
2016-01-28  9:39   ` [PATCH] perf/x86/amd/power: Add AMD accumulated power reporting kbuild test robot
2016-01-28  9:41   ` kbuild test robot
2016-01-28 10:01   ` [PATCH v4] perf/x86/amd/power: Add AMD accumulated power reporting mechanism Huang Rui
2016-01-28 12:42     ` Borislav Petkov
2016-01-28 14:54       ` Borislav Petkov
2016-01-28 10:04   ` [PATCH] perf/x86/amd/power: Add AMD accumulated power reporting kbuild test robot
2016-01-28 15:28   ` [PATCH v4] perf/x86/amd/power: Add AMD accumulated power reporting mechanism Peter Zijlstra
2016-01-29  8:18     ` Huang Rui [this message]

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=20160129081817.GB28282@hr-amur2 \
    --to=ray.huang@amd.com \
    --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=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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.