public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Huang Rui <ray.huang@amd.com>
To: Guenter Roeck <linux@roeck-us.net>
Cc: "Borislav Petkov" <bp@suse.de>, "Jean Delvare" <jdelvare@suse.de>,
	"Andy Lutomirski" <luto@amacapital.net>,
	"Andreas Herrmann" <herrmann.der.user@gmail.com>,
	"Thomas Gleixner" <tglx@linutronix.de>,
	"Peter Zijlstra" <peterz@infradead.org>,
	"Ingo Molnar" <mingo@kernel.org>,
	"Rafael J. Wysocki" <rjw@rjwysocki.net>,
	"Len Brown" <lenb@kernel.org>,
	"John Stultz" <john.stultz@linaro.org>,
	"Frédéric Weisbecker" <fweisbec@gmail.com>,
	lm-sensors@lm-sensors.org, linux-kernel@vger.kernel.org,
	x86@kernel.org,
	"Andreas Herrmann" <herrmann.der.user@googlemail.com>,
	"Aravind Gopalakrishnan" <Aravind.Gopalakrishnan@amd.com>,
	"Borislav Petkov" <bp@alien8.de>,
	"Fengguang Wu" <fengguang.wu@intel.com>,
	"Aaron Lu" <aaron.lu@intel.com>, "Tony Li" <tony.li@amd.com>
Subject: Re: [PATCH 12/15] hwmon, fam15h_power: introduce a cpu accumulated power reporting algorithm
Date: Fri, 28 Aug 2015 18:45:25 +0800	[thread overview]
Message-ID: <20150828104525.GD4191@hr-slim.amd.com> (raw)
In-Reply-To: <20150827173043.GB27452@roeck-us.net>

On Thu, Aug 27, 2015 at 10:30:43AM -0700, Guenter Roeck wrote:
> On Thu, Aug 27, 2015 at 04:07:43PM +0800, Huang Rui wrote:
> > This patch introduces an algorithm that computes the average power by
> > reading a delta value of “core power accumulator” register during
> > measurement interval, and then dividing delta value by the length of
> > the time interval.
> > 
> > User is able to use power1_acc entry to measure the processor power
> > consumption and power1_acc just needs to be read twice with an needed
> > interval in-between.
> > 
> > A simple example:
> > 
> > $ cat /sys/bus/pci/devices/0000\:00\:18.4/hwmon/hwmon0/power1_acc
> > $ sleep 10000s
> > $ cat /sys/bus/pci/devices/0000\:00\:18.4/hwmon/hwmon0/power1_acc
> > 
> > The result is current average processor power consumption in 10000
> > seconds. The unit of the result is uWatt.
> > 
> > Signed-off-by: Huang Rui <ray.huang@amd.com>
> > ---
> >  drivers/hwmon/fam15h_power.c | 62 ++++++++++++++++++++++++++++++++++++++++++++
> >  1 file changed, 62 insertions(+)
> > 
> > diff --git a/drivers/hwmon/fam15h_power.c b/drivers/hwmon/fam15h_power.c
> > index d529e4b..3bab797 100644
> > --- a/drivers/hwmon/fam15h_power.c
> > +++ b/drivers/hwmon/fam15h_power.c
> > @@ -60,6 +60,7 @@ struct fam15h_power_data {
> >  	u64 cu_acc_power[MAX_CUS];
> >  	/* performance timestamp counter */
> >  	u64 cpu_sw_pwr_ptsc[MAX_CUS];
> > +	struct mutex acc_pwr_mutex;
> >  };
> >  
> >  static ssize_t show_power(struct device *dev,
> > @@ -121,17 +122,74 @@ static DEVICE_ATTR(power1_crit, S_IRUGO, show_power_crit, NULL);
> >  static struct attribute_group fam15h_power_group;
> >  __ATTRIBUTE_GROUPS(fam15h_power);
> >  
> > +static ssize_t show_power_acc(struct device *dev,
> > +			      struct device_attribute *attr, char *buf)
> > +{
> > +	int cpu, cu, cu_num, cores_per_cu;
> > +	u64 curr_cu_acc_power[MAX_CUS],
> > +	    curr_ptsc[MAX_CUS], jdelta[MAX_CUS];
> > +	u64 tdelta, avg_acc;
> > +	struct fam15h_power_data *data = dev_get_drvdata(dev);
> > +
> > +	cores_per_cu = amd_get_cores_per_cu();
> > +	cu_num = boot_cpu_data.x86_max_cores / cores_per_cu;
> > +
> > +	for (cpu = 0, avg_acc = 0; cpu < cu_num * cores_per_cu; cpu += cores_per_cu) {
> > +		cu = cpu / cores_per_cu;
> > +		if (rdmsrl_safe_on_cpu(cpu, MSR_F15H_PTSC, &curr_ptsc[cu])) {
> > +			pr_err("Failed to read PTSC counter MSR on core%d\n",
> > +			       cpu);
> > +			return 0;
> > +		}
> > +
> > +		if (rdmsrl_safe_on_cpu(cpu, MSR_F15H_CU_PWR_ACCUMULATOR,
> > +				       &curr_cu_acc_power[cu])) {
> > +			pr_err("Failed to read compute unit power accumulator MSR on core%d\n",
> > +			       cpu);
> > +			return 0;
> > +		}
> > +
> > +		if (curr_cu_acc_power[cu] < data->cu_acc_power[cu]) {
> > +			jdelta[cu] = data->max_cu_acc_power + curr_cu_acc_power[cu];
> > +			jdelta[cu] -= data->cu_acc_power[cu];
> > +		} else {
> > +			jdelta[cu] = curr_cu_acc_power[cu] - data->cu_acc_power[cu];
> > +		}
> > +		tdelta = curr_ptsc[cu] - data->cpu_sw_pwr_ptsc[cu];
> > +		jdelta[cu] *= data->cpu_pwr_sample_ratio * 1000;
> > +		do_div(jdelta[cu], tdelta);
> > +
> > +		mutex_lock(&data->acc_pwr_mutex);
> > +		data->cu_acc_power[cu] = curr_cu_acc_power[cu];
> > +		data->cpu_sw_pwr_ptsc[cu] = curr_ptsc[cu];
> > +		mutex_unlock(&data->acc_pwr_mutex);
> > +
> > +		/* the unit is microWatt */
> > +		avg_acc += jdelta[cu];
> > +	}
> > +
> > +	return sprintf(buf, "%u\n", (unsigned int) avg_acc);
> > +}
> > +static DEVICE_ATTR(power1_acc, S_IRUGO, show_power_acc, NULL);
> 
> I am not really a friend of introducing a non-standard attribute.
> Does the energy attribute not work here ?
> 

You're right. Non-standard attribute might not be good. Could you
please give me some hints if I use "energy" instead?

Thanks,
Rui

  reply	other threads:[~2015-08-28 10:47 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-27  8:07 [PATCH 00/15] hwmon, fam15h_power: introduce an accumulated power reporting algorithm Huang Rui
2015-08-27  8:07 ` [PATCH 01/15] hwmon, fam15h_power: add support for AMD Carrizo Huang Rui
2015-08-27 14:35   ` Guenter Roeck
2015-08-27  8:07 ` [PATCH 02/15] hwmon, fam15h_power: rename fam15h_power_is_internal_node0 function Huang Rui
2015-08-27 14:35   ` Guenter Roeck
2015-08-27  8:07 ` [PATCH 03/15] hwmon, fam15h_power: refactor attributes for dynamically added Huang Rui
2015-08-27 14:46   ` Guenter Roeck
2015-08-28 10:05     ` Huang Rui
2015-08-27  8:07 ` [PATCH 04/15] hwmon, fam15h_power: update running_avg_capture bit field to 28 Huang Rui
2015-08-27 14:48   ` Guenter Roeck
2015-08-27  8:07 ` [PATCH 05/15] hwmon, fam15h_power: enable power1_input on AMD Carrizo Huang Rui
2015-08-27 14:50   ` Guenter Roeck
2015-08-27  8:07 ` [PATCH 06/15] hwmon, fam15h_power: add documentation for new processors support Huang Rui
2015-08-27 14:51   ` Guenter Roeck
2015-08-27  8:07 ` [PATCH 07/15] hwmon, fam15h_power: add ratio of Tsample to the PTSC period Huang Rui
2015-08-27 14:54   ` Guenter Roeck
2015-08-27  8:07 ` [PATCH 08/15] hwmon, fam15h_power: add max compute unit accumulated power Huang Rui
2015-08-27 14:56   ` Guenter Roeck
2015-08-27  8:07 ` [PATCH 09/15] x86, amd: add accessor for number of cores per compute unit Huang Rui
2015-08-27 17:27   ` Guenter Roeck
2015-08-28 10:28     ` Huang Rui
2015-08-28  6:48   ` Borislav Petkov
2015-08-28  8:00     ` Guenter Roeck
2015-08-28  8:04     ` Ingo Molnar
2015-08-28  8:56       ` Borislav Petkov
2015-08-28 10:18       ` Huang Rui
2015-08-29  9:19       ` Ingo Molnar
2015-08-30 15:53         ` Borislav Petkov
2015-08-31  8:38           ` Peter Zijlstra
2015-08-31 13:26             ` Guenter Roeck
2015-08-31 13:38               ` Peter Zijlstra
2015-08-31 13:53                 ` Guenter Roeck
2015-08-31 14:57                   ` Peter Zijlstra
2015-08-31 15:11                     ` Guenter Roeck
2015-08-31 16:06             ` Borislav Petkov
2015-08-31 16:19               ` Guenter Roeck
2015-08-31 20:44                 ` Peter Zijlstra
2015-08-31 21:24                   ` Guenter Roeck
2015-09-01 15:56                     ` Borislav Petkov
2015-09-01 16:06                       ` Guenter Roeck
2015-08-27  8:07 ` [PATCH 10/15] hwmon, fam15h_power: add compute unit accumulated power Huang Rui
2015-08-28  8:03   ` Ingo Molnar
2015-08-28 10:42     ` Huang Rui
2015-08-27  8:07 ` [PATCH 11/15] hwmon, fam15h_power: add ptsc counter value for " Huang Rui
2015-08-27  8:07 ` [PATCH 12/15] hwmon, fam15h_power: introduce a cpu accumulated power reporting algorithm Huang Rui
2015-08-27 17:30   ` Guenter Roeck
2015-08-28 10:45     ` Huang Rui [this message]
2015-08-28 14:05       ` Guenter Roeck
2015-08-31  4:16         ` Huang Rui
2015-08-31  4:30           ` Guenter Roeck
2015-08-31 13:11             ` Huang Rui
2015-08-31 13:25   ` Peter Zijlstra
2015-08-31 14:59     ` Peter Zijlstra
2015-08-27  8:07 ` [PATCH 13/15] hwmon, fam15h_power: add documentation for previous TDP reporting Huang Rui
2015-08-27  8:07 ` [PATCH 14/15] hwmon, fam15h_power: add documentation for accumulated power algorithm Huang Rui
2015-08-27  8:07 ` [PATCH 15/15] MAINTAINERS: change the maintainer of fam15h_power driver Huang Rui
2015-08-29 16:33   ` [15/15] " Guenter Roeck
2015-08-31  1:11     ` Huang Rui
2015-08-31 15:19     ` Andreas Herrmann

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=20150828104525.GD4191@hr-slim.amd.com \
    --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@gmail.com \
    --cc=herrmann.der.user@googlemail.com \
    --cc=jdelvare@suse.de \
    --cc=john.stultz@linaro.org \
    --cc=lenb@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=lm-sensors@lm-sensors.org \
    --cc=luto@amacapital.net \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rjw@rjwysocki.net \
    --cc=tglx@linutronix.de \
    --cc=tony.li@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