The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@linutronix.de>
To: Huang Rui <ray.huang@amd.com>
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: Thu, 3 Mar 2016 09:50:11 +0100 (CET)	[thread overview]
Message-ID: <alpine.DEB.2.11.1603030912560.3597@nanos> (raw)
In-Reply-To: <1456992284-4808-3-git-send-email-ray.huang@amd.com>

On Thu, 3 Mar 2016, Huang Rui wrote:
> +/*
> + * The ratio of compute unit power accumulator sample period to the
> + * PTSC period.
> + */
> +static unsigned int cpu_pwr_sample_ratio;
> +static unsigned int cu_num;

Why do you need static storage for that information when the only purpose is
to printk it in init?

> +static void power_cpu_exit(int cpu)
> +{
> +	int target = nr_cpumask_bits;

What's that initialization for?

> +
> +	if (!cpumask_test_and_clear_cpu(cpu, &cpu_mask))
> +		return;
> +
> +	/*
> +	 * Find a new CPU on the same compute unit, if was set in cpumask
> +	 * and still some CPUs on compute unit. Then migrate event and
> +	 * context to new CPU.
> +	 */
> +	target = cpumask_any_but(topology_sibling_cpumask(cpu), cpu);
> +	if (target < nr_cpumask_bits) {
> +		cpumask_set_cpu(target, &cpu_mask);
> +		perf_pmu_migrate_context(&pmu_class, cpu, target);
> +	}
> +}
> +
> +static void power_cpu_init(int cpu)
> +{
> +	/*
> +	 * 1) If any CPU is set at cpu_mask in the same compute unit, do
> +	 * nothing.
> +	 * 2) If no CPU is set at cpu_mask in the same compute unit,
> +	 * set current STARTING CPU.
> +	 *
> +	 * If cpu_mask and topology_sibling_cpumask has intersected
> +	 * bits, that means any CPU is set in the same compute unit.
> +	 * But cpumask_weight(topology_sibling_cpumask(cpu)) == 1
> +	 * means no CPU is set on cpu_mask in the same compute unit
> +	 * before init current STARTING CPU.
> +	 */
> +	if (!cpumask_intersects(&cpu_mask, topology_sibling_cpumask(cpu)) &&
> +	    cpumask_weight(topology_sibling_cpumask(cpu)) == 1)
> +			cpumask_set_cpu(cpu, &cpu_mask);

I don't think you need that complexity.

	target = cpumask_any_but(topology_sibling_cpumask(cpu), cpu);
	if (target >= nr_cpumask_bits)
		cpumask_set_cpu(cpu, &cpu_mask);
	   
Simply because if there is a cpu aside of the new one already in the sibling
mask, then it is also in cpu_mask. Hmm?

> +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_STARTING:
> +		power_cpu_init(cpu);
> +		break;
> +	case CPU_DOWN_PREPARE:
> +		power_cpu_exit(cpu);
> +		break;

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 ....

> +static int __init amd_power_pmu_init(void)
> +{
> +	int i, ret;
> +	u64 tmp;
> +
> +	if (!x86_match_cpu(cpu_match))
> +		return 0;
> +
> +	if (!boot_cpu_has(X86_FEATURE_ACC_POWER))
> +		return -ENODEV;
> +
> +	cu_num = boot_cpu_data.x86_max_cores / smp_num_siblings;
> +
> +	cpu_pwr_sample_ratio = cpuid_ecx(0x80000007);
> +
> +	if (rdmsrl_safe(MSR_F15H_CU_MAX_PWR_ACCUMULATOR, &tmp)) {
> +		pr_err("Failed to read max compute unit power accumulator MSR\n");
> +		return -ENODEV;
> +	}
> +	max_cu_acc_power = tmp;

Why do you need an intermediate 'tmp' for this?

> +	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.

> +		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?

> +	}
> +
> +	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. .....

> +		goto out;
> +	}
> +
> +	pr_info("AMD Power PMU detected, %d compute units\n", cu_num);

Why is the number of compute units interesting at all?

Thanks,

	tglx

  reply	other threads:[~2016-03-03  8:51 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 [this message]
2016-03-03 15:13     ` Huang Rui
2016-03-03 15:26       ` Thomas Gleixner
2016-03-03 16:18         ` Huang Rui
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=alpine.DEB.2.11.1603030912560.3597@nanos \
    --to=tglx@linutronix.de \
    --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=ray.huang@amd.com \
    --cc=rric@kernel.org \
    --cc=spg_linux_kernel@amd.com \
    --cc=suravee.suthikulpanit@amd.com \
    --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