Re: [PATCH v3] perf/x86/amd/power: Add AMD accumulated power reporting mechanism

From: Huang Rui
Date: Tue Jan 26 2016 - 08:47:08 EST


On Tue, Jan 26, 2016 at 09:28:23AM +0100, Ingo Molnar wrote:
>
> * Huang Rui <ray.huang@xxxxxxx> wrote:
>
> > +/*
> > + * Acc power status counters
> > + */
> > +#define AMD_POWER_PKG_ID 0
> > +#define AMD_POWER_EVENTSEL_PKG 1
>
> > +/*
> > + * the ratio of compute unit power accumulator sample period to the
> > + * PTSC period
> > + */
>
> > +/*
> > + * Accumulated power is to measure the sum of each compute unit's
> > + * power consumption. So it picks only one core from each compute unit
> > + * to get the power with MSR_F15H_CU_PWR_ACCUMULATOR. The cpu_mask
> > + * represents CPU bit map of all cores which are picked to measure the
> > + * power for the compute units that they belong to.
> > + */
> > +static cpumask_t cpu_mask;
>
> > + /*
> > + * calculate the power comsumption for each compute unit over
> > + * a time period, the unit of final value (delta) is
> > + * micro-Watts. Then add it into event count.
> > + */
>
> Please capitalize sentences consistently - half of the comments you added start
> lower-case.
>

Some of lower-case starting cases are not complete sentences such as:

/*
* the ratio of compute unit power accumulator sample period to the
* PTSC period
*/

/* maximum accumulated power of a compute unit */

So can I check again and capitalize comment if it is complete
sentence?

>
> > + if (cfg == AMD_POWER_EVENTSEL_PKG)
> > + bit = AMD_POWER_PKG_ID;
> > + else
> > + return -EINVAL;
> > +
> > + event->hw.event_base = MSR_F15H_CU_PWR_ACCUMULATOR;
> > + event->hw.config = cfg;
> > + event->hw.idx = bit;
> > +
> > + return ret;
>
> so this control flow looks pretty weird. Why not:
>
> > + if (cfg != AMD_POWER_EVENTSEL_PKG)
> > + return -EINVAL;
> > +
> > + event->hw.event_base = MSR_F15H_CU_PWR_ACCUMULATOR;
> > + event->hw.config = cfg;
> > + event->hw.idx = AMD_POWER_PKG_ID;
> > +
> > + return ret;
>
> ?
>

Looks better.

> > +static int power_cpu_init(int cpu)
> > +{
> > + struct power_pmu *pmu = per_cpu(amd_power_pmu, cpu);
> > +
> > + if (pmu)
> > + return 0;
> > +
> > + if (!cpumask_and(pmu->mask, topology_sibling_cpumask(cpu),
> > + &cpu_mask))
> > + cpumask_set_cpu(cpu, &cpu_mask);
> > +
> > + return 0;
> > +}
>
> Hm, has this function ever been runtime tested? This function either does nothing
> (contrary to the clear intention of twiddling the cpu_mask), or crashes on a NULL
> pointer.
>
> ( Also, the code has an annoying line-break. Don't pacify checkpatch by making the
> code harder to read. )
>

OK, that should be "if (!pmu)", thanks to check so carefully. I tested
to make the core offline and check the event context migration with
power_cpu_exit, but might miss this scenario. I will do more testing
on runtime case. Will fix it on next version.

Thanks,
Rui