From: Ingo Molnar <mingo@kernel.org>
To: Huang Rui <ray.huang@amd.com>
Cc: "Borislav Petkov" <bp@suse.de>,
"Peter Zijlstra" <peterz@infradead.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 v3] perf/x86/amd/power: Add AMD accumulated power reporting mechanism
Date: Tue, 26 Jan 2016 09:28:23 +0100 [thread overview]
Message-ID: <20160126082823.GA8729@gmail.com> (raw)
In-Reply-To: <1453710723-1616-1-git-send-email-ray.huang@amd.com>
* Huang Rui <ray.huang@amd.com> 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.
> +static void __pmu_event_start(struct power_pmu *pmu,
> + struct perf_event *event)
So this looks better either on a single line, or as:
static void
__pmu_event_start(struct power_pmu *pmu, struct perf_event *event)
Breaking the argument list combines the worst of the two worlds.
> + if ((mode & PERF_EF_UPDATE) && !(hwc->state & PERF_HES_UPTODATE)) {
> + /*
> + * Drain the remaining delta count out of a event
> + * that we are disabling:
s/an event
(Please re-read all the comments - I saw a few other typos and spelling mistakes
as well.)
> + 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;
?
> +static struct attribute_group pmu_attr_group = {
> + .attrs = pmu_attrs,
> +};
> +
> +
> +/*
> + * at current, it only supports to report the power of each
s/currently it only supports power reporting of each
> + * processor/package
> + */
> +EVENT_ATTR_STR(power-pkg, power_pkg, "event=0x01");
> +
> +EVENT_ATTR_STR(power-pkg.unit, power_pkg_unit, "mWatts");
> +
> +/* convert the count from micro-Watts to milli-Watts */
> +EVENT_ATTR_STR(power-pkg.scale, power_pkg_scale, "1.000000e-3");
> +
> +
> +static struct attribute *events_attr[] = {
> + EVENT_PTR(power_pkg),
> + EVENT_PTR(power_pkg_unit),
> + EVENT_PTR(power_pkg_scale),
> + NULL,
> +};
> +
> +static struct attribute_group pmu_events_group = {
> + .name = "events",
> + .attrs = events_attr,
> +static struct attribute_group pmu_format_group = {
> + .name = "format",
> + .attrs = formats_attr,
> +};
Please initialize structures in a vertically aligned manner, like you did it later
on:
> +static struct pmu pmu_class = {
> + .attr_groups = attr_groups,
> + .task_ctx_nr = perf_invalid_context, /* system-wide only */
> + .event_init = pmu_event_init,
> + .add = pmu_event_add, /* must have */
> + .del = pmu_event_del, /* must have */
> + .start = pmu_event_start,
> + .stop = pmu_event_stop,
> + .read = pmu_event_read,
> +};
Btw., I don't think the 'must have' comment adds any important information needed
to understand this new PMU driver.
> +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. )
Thanks,
Ingo
next prev parent reply other threads:[~2016-01-26 8:28 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-25 8:32 [PATCH v3] perf/x86/amd/power: Add AMD accumulated power reporting mechanism Huang Rui
2016-01-25 11:13 ` Peter Zijlstra
2016-01-25 15:43 ` Huang Rui
2016-01-26 8:28 ` Ingo Molnar [this message]
2016-01-26 13:47 ` 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=20160126082823.GA8729@gmail.com \
--to=mingo@kernel.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=peterz@infradead.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;
as well as URLs for NNTP newsgroup(s).