linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 00/10] hwmon: (fam15h_power) Introduce an accumulated power reporting algorithm
@ 2015-10-30  9:56 Huang Rui
  2015-10-30  9:56 ` [PATCH v3 01/10] hwmon: (fam15h_power) Refactor attributes for dynamically added Huang Rui
                   ` (9 more replies)
  0 siblings, 10 replies; 18+ messages in thread
From: Huang Rui @ 2015-10-30  9:56 UTC (permalink / raw)
  To: Borislav Petkov, Guenter Roeck, Peter Zijlstra, Jean Delvare,
	Andy Lutomirski, Andreas Herrmann, Thomas Gleixner, Ingo Molnar,
	Rafael J. Wysocki, Len Brown, John Stultz,
	Frédéric Weisbecker
  Cc: lm-sensors, linux-kernel, x86, Andreas Herrmann,
	Aravind Gopalakrishnan, Borislav Petkov, Fengguang Wu, Aaron Lu,
	SPG_Linux_Kernel, Huang Rui

Hi all,

This serial of patches introduces an accumulated power reporting
algorithm. It will calculate the average power consumption for the
processor. The cpu feature flag is CPUID.8000_0007H:EDX[12].

This algorithm is used to test the comparison of processor power
consumption with between MWAITX delay and TSC delay on AMD Carrizo
platforms.

Reference:
http://marc.info/?l=linux-kernel&m=143874573111310&w=2

Commit f96756 at tip ("x86/asm: Add MONITORX/MWAITX instruction support")
Commit b466bd at tip ("x86/asm/delay: Introduce an MWAITX-based delay with a configurable timer")

V1: http://marc.info/?l=linux-kernel&m=144066380613299&w=2
V2: http://marc.info/?l=linux-kernel&m=144531018518473&w=2

Changes from v1 -> v2:
- Move fam15h_power_groups and fam15h_power_group into fam15h_power_data to
  avoid overwrite on multi-CPU system.
- Rename FAM15H_MIN_NUM_ATTRS macro and fix return error code.
- Remove unnecessary warning print.
- Adds do_read_registers_on_cu to do all the read to all MSRs and run it on one
  of the online cores on each compute unit with smp_call_function_many().
- Use power1_average and power1_average_interval standard entry
  instread of power1_acc
- Fix the CPU-hotplug case.

Changes from v2 -> v3:
- As Guenter's suggestion, remove typecast, use &data->groups[0].
- Remove all "fam15_power_*" prefix at data.
- Remove unnecessary ( ).
- Fix the issue that is reported by build test robot, and add
  CPU_SUP_AMD as the dependence of fam15h_power
- Remove the WARN_ON at do_read_registers_on_cu, because it must be
  behind CPUID check. The MSR must be available since
  CPUID.8000_0007H:EDX[12] is set 
- Add get_online_cpus()/put_online_cpus() functions.
- Refine commments and the method which generate cpumask for cu.
- Add the interval scope to make the value suitable for user
  experience
- Remove the useless mutex.

A simple example:

ray@hr-ub:~/tip$ sensors
fam15h_power-pci-00c4
Adapter: PCI adapter
power1:       23.73 mW (avg = 634.63 mW, interval =   0.01 s)
                       (crit =  15.00 W)

...

These patches are rebased on groeck/hwmon-next.

Thanks,
Rui

Huang Rui (10):
  hwmon: (fam15h_power) Refactor attributes for dynamically added
  hwmon: (fam15h_power) Enable power1_input on AMD Carrizo
  hwmon: (fam15h_power) Add max compute unit accumulated power
  x86, amd: add accessor for number of cores per compute unit
  hwmon: (fam15h_power) Add CPU_SUP_AMD as the dependence
  hwmon: (fam15h_power) Add compute unit accumulated power
  hwmon: (fam15h_power) Add ptsc counter value for accumulated power
  hwmon: (fam15h_power) Introduce a cpu accumulated power reporting
    algorithm
  hwmon: (fam15h_power) Add documentation for TDP and accumulated power
    algorithm
  MAINTAINERS: change the maintainer of fam15h_power driver

 CREDITS                          |   8 ++
 Documentation/hwmon/fam15h_power |  57 +++++++-
 MAINTAINERS                      |   4 +-
 arch/x86/include/asm/msr-index.h |   1 +
 arch/x86/include/asm/processor.h |   1 +
 arch/x86/kernel/cpu/amd.c        |  19 ++-
 drivers/hwmon/Kconfig            |   2 +-
 drivers/hwmon/fam15h_power.c     | 278 +++++++++++++++++++++++++++++++++++----
 8 files changed, 341 insertions(+), 29 deletions(-)

-- 
1.9.1


^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH v3 01/10] hwmon: (fam15h_power) Refactor attributes for dynamically added
  2015-10-30  9:56 [PATCH v3 00/10] hwmon: (fam15h_power) Introduce an accumulated power reporting algorithm Huang Rui
@ 2015-10-30  9:56 ` Huang Rui
  2015-10-31 22:38   ` Guenter Roeck
  2015-10-30  9:56 ` [PATCH v3 02/10] hwmon: (fam15h_power) Enable power1_input on AMD Carrizo Huang Rui
                   ` (8 subsequent siblings)
  9 siblings, 1 reply; 18+ messages in thread
From: Huang Rui @ 2015-10-30  9:56 UTC (permalink / raw)
  To: Borislav Petkov, Guenter Roeck, Peter Zijlstra, Jean Delvare,
	Andy Lutomirski, Andreas Herrmann, Thomas Gleixner, Ingo Molnar,
	Rafael J. Wysocki, Len Brown, John Stultz,
	Frédéric Weisbecker
  Cc: lm-sensors, linux-kernel, x86, Andreas Herrmann,
	Aravind Gopalakrishnan, Borislav Petkov, Fengguang Wu, Aaron Lu,
	SPG_Linux_Kernel, Huang Rui

Attributes depend on the CPU model the driver gets loaded on.
Therefore, add those attributes dynamically at init time. This is more
flexible to control the different attributes on different platforms.

Suggested-by: Borislav Petkov <bp@alien8.de>
Signed-off-by: Huang Rui <ray.huang@amd.com>
Cc: Guenter Roeck <linux@roeck-us.net>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@kernel.org>
---
 drivers/hwmon/fam15h_power.c | 70 ++++++++++++++++++++++++++++----------------
 1 file changed, 45 insertions(+), 25 deletions(-)

diff --git a/drivers/hwmon/fam15h_power.c b/drivers/hwmon/fam15h_power.c
index e80ee23..2d899fd 100644
--- a/drivers/hwmon/fam15h_power.c
+++ b/drivers/hwmon/fam15h_power.c
@@ -41,12 +41,17 @@ MODULE_LICENSE("GPL");
 #define REG_TDP_RUNNING_AVERAGE		0xe0
 #define REG_TDP_LIMIT3			0xe8
 
+#define FAM15H_MIN_NUM_ATTRS		2
+#define FAM15H_NUM_GROUPS		2
+
 struct fam15h_power_data {
 	struct pci_dev *pdev;
 	unsigned int tdp_to_watts;
 	unsigned int base_tdp;
 	unsigned int processor_pwr_watts;
 	unsigned int cpu_pwr_sample_ratio;
+	const struct attribute_group *groups[FAM15H_NUM_GROUPS];
+	struct attribute_group group;
 };
 
 static ssize_t show_power(struct device *dev,
@@ -105,29 +110,31 @@ static ssize_t show_power_crit(struct device *dev,
 }
 static DEVICE_ATTR(power1_crit, S_IRUGO, show_power_crit, NULL);
 
-static umode_t fam15h_power_is_visible(struct kobject *kobj,
-				       struct attribute *attr,
-				       int index)
+static int fam15h_power_init_attrs(struct pci_dev *pdev,
+				   struct fam15h_power_data *data)
 {
-	/* power1_input is only reported for Fam15h, Models 00h-0fh */
-	if (attr == &dev_attr_power1_input.attr &&
-	   (boot_cpu_data.x86 != 0x15 || boot_cpu_data.x86_model > 0xf))
-		return 0;
+	int n = FAM15H_MIN_NUM_ATTRS;
+	struct attribute **fam15h_power_attrs;
 
-	return attr->mode;
-}
+	if (boot_cpu_data.x86 == 0x15 && boot_cpu_data.x86_model <= 0xf)
+		n += 1;
 
-static struct attribute *fam15h_power_attrs[] = {
-	&dev_attr_power1_input.attr,
-	&dev_attr_power1_crit.attr,
-	NULL
-};
+	fam15h_power_attrs = devm_kcalloc(&pdev->dev, n,
+					  sizeof(*fam15h_power_attrs),
+					  GFP_KERNEL);
 
-static const struct attribute_group fam15h_power_group = {
-	.attrs = fam15h_power_attrs,
-	.is_visible = fam15h_power_is_visible,
-};
-__ATTRIBUTE_GROUPS(fam15h_power);
+	if (!fam15h_power_attrs)
+		return -ENOMEM;
+
+	n = 0;
+	fam15h_power_attrs[n++] = &dev_attr_power1_crit.attr;
+	if (boot_cpu_data.x86 == 0x15 && boot_cpu_data.x86_model <= 0xf)
+		fam15h_power_attrs[n++] = &dev_attr_power1_input.attr;
+
+	data->group.attrs = fam15h_power_attrs;
+
+	return 0;
+}
 
 static bool should_load_on_this_node(struct pci_dev *f4)
 {
@@ -186,11 +193,12 @@ static int fam15h_power_resume(struct pci_dev *pdev)
 #define fam15h_power_resume NULL
 #endif
 
-static void fam15h_power_init_data(struct pci_dev *f4,
-					     struct fam15h_power_data *data)
+static int fam15h_power_init_data(struct pci_dev *f4,
+				  struct fam15h_power_data *data)
 {
 	u32 val, eax, ebx, ecx, edx;
 	u64 tmp;
+	int ret;
 
 	pci_read_config_dword(f4, REG_PROCESSOR_TDP, &val);
 	data->base_tdp = val >> 16;
@@ -211,11 +219,15 @@ static void fam15h_power_init_data(struct pci_dev *f4,
 	/* convert to microWatt */
 	data->processor_pwr_watts = (tmp * 15625) >> 10;
 
+	ret = fam15h_power_init_attrs(f4, data);
+	if (ret)
+		return ret;
+
 	cpuid(0x80000007, &eax, &ebx, &ecx, &edx);
 
 	/* CPUID Fn8000_0007:EDX[12] indicates to support accumulated power */
 	if (!(edx & BIT(12)))
-		return;
+		return 0;
 
 	/*
 	 * determine the ratio of the compute unit power accumulator
@@ -223,14 +235,17 @@ static void fam15h_power_init_data(struct pci_dev *f4,
 	 * Fn8000_0007:ECX
 	 */
 	data->cpu_pwr_sample_ratio = ecx;
+
+	return 0;
 }
 
 static int fam15h_power_probe(struct pci_dev *pdev,
-					const struct pci_device_id *id)
+			      const struct pci_device_id *id)
 {
 	struct fam15h_power_data *data;
 	struct device *dev = &pdev->dev;
 	struct device *hwmon_dev;
+	int ret;
 
 	/*
 	 * though we ignore every other northbridge, we still have to
@@ -246,12 +261,17 @@ static int fam15h_power_probe(struct pci_dev *pdev,
 	if (!data)
 		return -ENOMEM;
 
-	fam15h_power_init_data(pdev, data);
+	ret = fam15h_power_init_data(pdev, data);
+	if (ret)
+		return ret;
+
 	data->pdev = pdev;
 
+	data->groups[0] = &data->group;
+
 	hwmon_dev = devm_hwmon_device_register_with_groups(dev, "fam15h_power",
 							   data,
-							   fam15h_power_groups);
+							   &data->groups[0]);
 	return PTR_ERR_OR_ZERO(hwmon_dev);
 }
 
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v3 02/10] hwmon: (fam15h_power) Enable power1_input on AMD Carrizo
  2015-10-30  9:56 [PATCH v3 00/10] hwmon: (fam15h_power) Introduce an accumulated power reporting algorithm Huang Rui
  2015-10-30  9:56 ` [PATCH v3 01/10] hwmon: (fam15h_power) Refactor attributes for dynamically added Huang Rui
@ 2015-10-30  9:56 ` Huang Rui
  2015-10-31 22:42   ` Guenter Roeck
  2015-10-30  9:56 ` [PATCH v3 03/10] hwmon: (fam15h_power) Add max compute unit accumulated power Huang Rui
                   ` (7 subsequent siblings)
  9 siblings, 1 reply; 18+ messages in thread
From: Huang Rui @ 2015-10-30  9:56 UTC (permalink / raw)
  To: Borislav Petkov, Guenter Roeck, Peter Zijlstra, Jean Delvare,
	Andy Lutomirski, Andreas Herrmann, Thomas Gleixner, Ingo Molnar,
	Rafael J. Wysocki, Len Brown, John Stultz,
	Frédéric Weisbecker
  Cc: lm-sensors, linux-kernel, x86, Andreas Herrmann,
	Aravind Gopalakrishnan, Borislav Petkov, Fengguang Wu, Aaron Lu,
	SPG_Linux_Kernel, Huang Rui

This patch enables power1_input attribute for Carrizo platform.

Signed-off-by: Huang Rui <ray.huang@amd.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Guenter Roeck <linux@roeck-us.net>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@kernel.org>
---
 drivers/hwmon/fam15h_power.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/hwmon/fam15h_power.c b/drivers/hwmon/fam15h_power.c
index 2d899fd..a46e166 100644
--- a/drivers/hwmon/fam15h_power.c
+++ b/drivers/hwmon/fam15h_power.c
@@ -115,8 +115,11 @@ static int fam15h_power_init_attrs(struct pci_dev *pdev,
 {
 	int n = FAM15H_MIN_NUM_ATTRS;
 	struct attribute **fam15h_power_attrs;
+	struct cpuinfo_x86 *c = &boot_cpu_data;
 
-	if (boot_cpu_data.x86 == 0x15 && boot_cpu_data.x86_model <= 0xf)
+	if (c->x86 == 0x15 &&
+	    (c->x86_model <= 0xf ||
+	     (c->x86_model >= 0x60 && c->x86_model <= 0x6f)))
 		n += 1;
 
 	fam15h_power_attrs = devm_kcalloc(&pdev->dev, n,
@@ -128,7 +131,9 @@ static int fam15h_power_init_attrs(struct pci_dev *pdev,
 
 	n = 0;
 	fam15h_power_attrs[n++] = &dev_attr_power1_crit.attr;
-	if (boot_cpu_data.x86 == 0x15 && boot_cpu_data.x86_model <= 0xf)
+	if (c->x86 == 0x15 &&
+	    (c->x86_model <= 0xf ||
+	     (c->x86_model >= 0x60 && c->x86_model <= 0x6f)))
 		fam15h_power_attrs[n++] = &dev_attr_power1_input.attr;
 
 	data->group.attrs = fam15h_power_attrs;
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v3 03/10] hwmon: (fam15h_power) Add max compute unit accumulated power
  2015-10-30  9:56 [PATCH v3 00/10] hwmon: (fam15h_power) Introduce an accumulated power reporting algorithm Huang Rui
  2015-10-30  9:56 ` [PATCH v3 01/10] hwmon: (fam15h_power) Refactor attributes for dynamically added Huang Rui
  2015-10-30  9:56 ` [PATCH v3 02/10] hwmon: (fam15h_power) Enable power1_input on AMD Carrizo Huang Rui
@ 2015-10-30  9:56 ` Huang Rui
  2015-10-31 22:44   ` Guenter Roeck
  2015-10-30  9:56 ` [PATCH v3 04/10] x86, amd: add accessor for number of cores per compute unit Huang Rui
                   ` (6 subsequent siblings)
  9 siblings, 1 reply; 18+ messages in thread
From: Huang Rui @ 2015-10-30  9:56 UTC (permalink / raw)
  To: Borislav Petkov, Guenter Roeck, Peter Zijlstra, Jean Delvare,
	Andy Lutomirski, Andreas Herrmann, Thomas Gleixner, Ingo Molnar,
	Rafael J. Wysocki, Len Brown, John Stultz,
	Frédéric Weisbecker
  Cc: lm-sensors, linux-kernel, x86, Andreas Herrmann,
	Aravind Gopalakrishnan, Borislav Petkov, Fengguang Wu, Aaron Lu,
	SPG_Linux_Kernel, Huang Rui

This patch adds a member in fam15h_power_data which specifies the
maximum accumulated power in a compute unit.

Signed-off-by: Huang Rui <ray.huang@amd.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Guenter Roeck <linux@roeck-us.net>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@kernel.org>
---
 drivers/hwmon/fam15h_power.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/drivers/hwmon/fam15h_power.c b/drivers/hwmon/fam15h_power.c
index a46e166..5f7067d 100644
--- a/drivers/hwmon/fam15h_power.c
+++ b/drivers/hwmon/fam15h_power.c
@@ -26,6 +26,7 @@
 #include <linux/pci.h>
 #include <linux/bitops.h>
 #include <asm/processor.h>
+#include <asm/msr.h>
 
 MODULE_DESCRIPTION("AMD Family 15h CPU processor power monitor");
 MODULE_AUTHOR("Andreas Herrmann <herrmann.der.user@googlemail.com>");
@@ -44,6 +45,8 @@ MODULE_LICENSE("GPL");
 #define FAM15H_MIN_NUM_ATTRS		2
 #define FAM15H_NUM_GROUPS		2
 
+#define MSR_F15H_CU_MAX_PWR_ACCUMULATOR	0xc001007b
+
 struct fam15h_power_data {
 	struct pci_dev *pdev;
 	unsigned int tdp_to_watts;
@@ -52,6 +55,8 @@ struct fam15h_power_data {
 	unsigned int cpu_pwr_sample_ratio;
 	const struct attribute_group *groups[FAM15H_NUM_GROUPS];
 	struct attribute_group group;
+	/* maximum accumulated power of a compute unit */
+	u64 max_cu_acc_power;
 };
 
 static ssize_t show_power(struct device *dev,
@@ -241,6 +246,13 @@ static int fam15h_power_init_data(struct pci_dev *f4,
 	 */
 	data->cpu_pwr_sample_ratio = ecx;
 
+	if (rdmsrl_safe(MSR_F15H_CU_MAX_PWR_ACCUMULATOR, &tmp)) {
+		pr_err("Failed to read max compute unit power accumulator MSR\n");
+		return -ENODEV;
+	}
+
+	data->max_cu_acc_power = tmp;
+
 	return 0;
 }
 
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v3 04/10] x86, amd: add accessor for number of cores per compute unit
  2015-10-30  9:56 [PATCH v3 00/10] hwmon: (fam15h_power) Introduce an accumulated power reporting algorithm Huang Rui
                   ` (2 preceding siblings ...)
  2015-10-30  9:56 ` [PATCH v3 03/10] hwmon: (fam15h_power) Add max compute unit accumulated power Huang Rui
@ 2015-10-30  9:56 ` Huang Rui
  2015-10-31 22:45   ` Guenter Roeck
  2015-10-30  9:56 ` [PATCH v3 05/10] hwmon: (fam15h_power) Add CPU_SUP_AMD as the dependence Huang Rui
                   ` (5 subsequent siblings)
  9 siblings, 1 reply; 18+ messages in thread
From: Huang Rui @ 2015-10-30  9:56 UTC (permalink / raw)
  To: Borislav Petkov, Guenter Roeck, Peter Zijlstra, Jean Delvare,
	Andy Lutomirski, Andreas Herrmann, Thomas Gleixner, Ingo Molnar,
	Rafael J. Wysocki, Len Brown, John Stultz,
	Frédéric Weisbecker
  Cc: lm-sensors, linux-kernel, x86, Andreas Herrmann,
	Aravind Gopalakrishnan, Borislav Petkov, Fengguang Wu, Aaron Lu,
	SPG_Linux_Kernel, Huang Rui

Add an accessor function amd_get_cores_per_cu() which returns the
number of cores per compute unit. In multiple CPUs, they always have
the same number of cores per compute unit.

In a subsequent patch, we will use this function in fam15h_power
driver.

Signed-off-by: Huang Rui <ray.huang@amd.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Guenter Roeck <linux@roeck-us.net>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/include/asm/processor.h |  1 +
 arch/x86/kernel/cpu/amd.c        | 19 +++++++++++++++++--
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
index 19577dd..831ad682 100644
--- a/arch/x86/include/asm/processor.h
+++ b/arch/x86/include/asm/processor.h
@@ -810,6 +810,7 @@ static inline int mpx_disable_management(void)
 
 extern u16 amd_get_nb_id(int cpu);
 extern u32 amd_get_nodes_per_socket(void);
+extern u32 amd_get_cores_per_cu(void);
 
 static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves)
 {
diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
index 4a70fc6..a914b1b 100644
--- a/arch/x86/kernel/cpu/amd.c
+++ b/arch/x86/kernel/cpu/amd.c
@@ -27,6 +27,9 @@
  */
 static u32 nodes_per_socket = 1;
 
+/* cores_per_cu: stores the number of cores per compute unit */
+static u32 cores_per_cu = 1;
+
 static inline int rdmsrl_amd_safe(unsigned msr, unsigned long long *p)
 {
 	u32 gprs[8] = { 0 };
@@ -299,7 +302,6 @@ static int nearby_node(int apicid)
 #ifdef CONFIG_SMP
 static void amd_get_topology(struct cpuinfo_x86 *c)
 {
-	u32 cores_per_cu = 1;
 	u8 node_id;
 	int cpu = smp_processor_id();
 
@@ -314,7 +316,6 @@ static void amd_get_topology(struct cpuinfo_x86 *c)
 		/* get compute unit information */
 		smp_num_siblings = ((ebx >> 8) & 3) + 1;
 		c->compute_unit_id = ebx & 0xff;
-		cores_per_cu += ((ebx >> 8) & 3);
 	} else if (cpu_has(c, X86_FEATURE_NODEID_MSR)) {
 		u64 value;
 
@@ -380,6 +381,13 @@ u32 amd_get_nodes_per_socket(void)
 }
 EXPORT_SYMBOL_GPL(amd_get_nodes_per_socket);
 
+/* this function returns the number of cores per compute unit */
+u32 amd_get_cores_per_cu(void)
+{
+	return cores_per_cu;
+}
+EXPORT_SYMBOL_GPL(amd_get_cores_per_cu);
+
 static void srat_detect_node(struct cpuinfo_x86 *c)
 {
 #ifdef CONFIG_NUMA
@@ -510,6 +518,13 @@ static void bsp_init_amd(struct cpuinfo_x86 *c)
 
 	if (cpu_has(c, X86_FEATURE_MWAITX))
 		use_mwaitx_delay();
+
+	if (cpu_has_topoext) {
+		u32 cpuid;
+
+		cpuid = cpuid_ebx(0x8000001e);
+		cores_per_cu += ((cpuid >> 8) & 3);
+	}
 }
 
 static void early_init_amd(struct cpuinfo_x86 *c)
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v3 05/10] hwmon: (fam15h_power) Add CPU_SUP_AMD as the dependence
  2015-10-30  9:56 [PATCH v3 00/10] hwmon: (fam15h_power) Introduce an accumulated power reporting algorithm Huang Rui
                   ` (3 preceding siblings ...)
  2015-10-30  9:56 ` [PATCH v3 04/10] x86, amd: add accessor for number of cores per compute unit Huang Rui
@ 2015-10-30  9:56 ` Huang Rui
  2015-10-30  9:57 ` [PATCH v3 06/10] hwmon: (fam15h_power) Add compute unit accumulated power Huang Rui
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 18+ messages in thread
From: Huang Rui @ 2015-10-30  9:56 UTC (permalink / raw)
  To: Borislav Petkov, Guenter Roeck, Peter Zijlstra, Jean Delvare,
	Andy Lutomirski, Andreas Herrmann, Thomas Gleixner, Ingo Molnar,
	Rafael J. Wysocki, Len Brown, John Stultz,
	Frédéric Weisbecker
  Cc: lm-sensors, linux-kernel, x86, Andreas Herrmann,
	Aravind Gopalakrishnan, Borislav Petkov, Fengguang Wu, Aaron Lu,
	SPG_Linux_Kernel, Huang Rui

This patch adds CONFIG_CPU_SUP_AMD as the dependence of fam15h_power
driver. Because the following patch will use the interface from
x86/kernel/cpu/amd.c.

Otherwise, the below error might be encountered:

All errors (new ones prefixed by >>):

   drivers/built-in.o: In function `fam15h_power_probe':
>> fam15h_power.c:(.text+0x26e3a3): undefined reference to
>> `amd_get_cores_per_cu'
   fam15h_power.c:(.text+0x26e41e): undefined reference to
`amd_get_cores_per_cu'

Reported-by: build test robot <lkp@intel.com>
Signed-off-by: Huang Rui <ray.huang@amd.com>
---
 drivers/hwmon/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index 796569ee..603eadd 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -288,7 +288,7 @@ config SENSORS_K10TEMP
 
 config SENSORS_FAM15H_POWER
 	tristate "AMD Family 15h processor power"
-	depends on X86 && PCI
+	depends on X86 && PCI && CPU_SUP_AMD
 	help
 	  If you say yes here you get support for processor power
 	  information of your AMD family 15h CPU.
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v3 06/10] hwmon: (fam15h_power) Add compute unit accumulated power
  2015-10-30  9:56 [PATCH v3 00/10] hwmon: (fam15h_power) Introduce an accumulated power reporting algorithm Huang Rui
                   ` (4 preceding siblings ...)
  2015-10-30  9:56 ` [PATCH v3 05/10] hwmon: (fam15h_power) Add CPU_SUP_AMD as the dependence Huang Rui
@ 2015-10-30  9:57 ` Huang Rui
  2015-10-30 10:33   ` kbuild test robot
  2015-10-30  9:57 ` [PATCH v3 07/10] hwmon: (fam15h_power) Add ptsc counter value for " Huang Rui
                   ` (3 subsequent siblings)
  9 siblings, 1 reply; 18+ messages in thread
From: Huang Rui @ 2015-10-30  9:57 UTC (permalink / raw)
  To: Borislav Petkov, Guenter Roeck, Peter Zijlstra, Jean Delvare,
	Andy Lutomirski, Andreas Herrmann, Thomas Gleixner, Ingo Molnar,
	Rafael J. Wysocki, Len Brown, John Stultz,
	Frédéric Weisbecker
  Cc: lm-sensors, linux-kernel, x86, Andreas Herrmann,
	Aravind Gopalakrishnan, Borislav Petkov, Fengguang Wu, Aaron Lu,
	SPG_Linux_Kernel, Huang Rui

This patch adds a member in fam15h_power_data which specifies the
compute unit accumulated power. It adds do_read_registers_on_cu to do
all the read to all MSRs and run it on one of the online cores on each
compute unit with smp_call_function_many(). This behavior can decrease
IPI numbers.

Suggested-by: Borislav Petkov <bp@alien8.de>
Signed-off-by: Huang Rui <ray.huang@amd.com>
Cc: Guenter Roeck <linux@roeck-us.net>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@kernel.org>
---
 drivers/hwmon/fam15h_power.c | 77 +++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 76 insertions(+), 1 deletion(-)

diff --git a/drivers/hwmon/fam15h_power.c b/drivers/hwmon/fam15h_power.c
index 5f7067d..5bbcb55 100644
--- a/drivers/hwmon/fam15h_power.c
+++ b/drivers/hwmon/fam15h_power.c
@@ -25,6 +25,8 @@
 #include <linux/module.h>
 #include <linux/pci.h>
 #include <linux/bitops.h>
+#include <linux/cpu.h>
+#include <linux/cpumask.h>
 #include <asm/processor.h>
 #include <asm/msr.h>
 
@@ -44,7 +46,9 @@ MODULE_LICENSE("GPL");
 
 #define FAM15H_MIN_NUM_ATTRS		2
 #define FAM15H_NUM_GROUPS		2
+#define MAX_CUS				8
 
+#define MSR_F15H_CU_PWR_ACCUMULATOR	0xc001007a
 #define MSR_F15H_CU_MAX_PWR_ACCUMULATOR	0xc001007b
 
 struct fam15h_power_data {
@@ -57,6 +61,8 @@ struct fam15h_power_data {
 	struct attribute_group group;
 	/* maximum accumulated power of a compute unit */
 	u64 max_cu_acc_power;
+	/* accumulated power of the compute units */
+	u64 cu_acc_power[MAX_CUS];
 };
 
 static ssize_t show_power(struct device *dev,
@@ -115,6 +121,75 @@ static ssize_t show_power_crit(struct device *dev,
 }
 static DEVICE_ATTR(power1_crit, S_IRUGO, show_power_crit, NULL);
 
+static void do_read_registers_on_cu(void *_data)
+{
+	struct fam15h_power_data *data = _data;
+	int cpu, cu, cores_per_cu;
+
+	cpu = smp_processor_id();
+
+	cores_per_cu = amd_get_cores_per_cu();
+	cu = cpu / cores_per_cu;
+
+	rdmsrl_safe(MSR_F15H_CU_PWR_ACCUMULATOR, &data->cu_acc_power[cu]);
+}
+
+/*
+ * this function is only able to be called when CPUID
+ * Fn8000_0007:EDX[12] is set
+ */
+static int read_registers(struct fam15h_power_data *data)
+{
+	int this_cpu, ret, i;
+	int cu_num, cores_per_cu;
+	cpumask_var_t mask, tmp_mask, res_mask;
+
+	cores_per_cu = amd_get_cores_per_cu();
+	cu_num = boot_cpu_data.x86_max_cores / cores_per_cu;
+
+	WARN_ON_ONCE(cu_num > MAX_CUS);
+
+	ret = zalloc_cpumask_var(&mask, GFP_KERNEL);
+	if (!ret)
+		return -ENOMEM;
+
+	ret = zalloc_cpumask_var(&tmp_mask, GFP_KERNEL);
+	if (!ret)
+		return -ENOMEM;
+
+	get_online_cpus();
+	this_cpu = get_cpu();
+
+	/* prepare CU temp mask */
+	for (i = 0; i < cores_per_cu; i++)
+		cpumask_set_cpu(i, tmp_mask);
+
+	/*
+	 * Choose the first online core of each compute unit, and then
+	 * read their MSR value of power and ptsc in a single IPI,
+	 * because the MSR value of CPU core represent the compute
+	 * unit's.
+	 */
+	for (i = 0; i < cu_num; i++) {
+		/* WARN_ON for empty CU masks */
+		WARN_ON(!cpumask_and(res_mask, tmp_mask, cpu_online_mask));
+		cpumask_set_cpu(cpumask_any(res_mask), mask);
+		cpumask_shift_left(tmp_mask, tmp_mask, cores_per_cu);
+	}
+
+	if (cpumask_test_cpu(this_cpu, mask))
+		do_read_registers_on_cu(data);
+
+	smp_call_function_many(mask, do_read_registers_on_cu, data, true);
+	put_cpu();
+	put_online_cpus();
+
+	free_cpumask_var(tmp_mask);
+	free_cpumask_var(mask);
+
+	return 0;
+}
+
 static int fam15h_power_init_attrs(struct pci_dev *pdev,
 				   struct fam15h_power_data *data)
 {
@@ -253,7 +328,7 @@ static int fam15h_power_init_data(struct pci_dev *f4,
 
 	data->max_cu_acc_power = tmp;
 
-	return 0;
+	return read_registers(data);
 }
 
 static int fam15h_power_probe(struct pci_dev *pdev,
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v3 07/10] hwmon: (fam15h_power) Add ptsc counter value for accumulated power
  2015-10-30  9:56 [PATCH v3 00/10] hwmon: (fam15h_power) Introduce an accumulated power reporting algorithm Huang Rui
                   ` (5 preceding siblings ...)
  2015-10-30  9:57 ` [PATCH v3 06/10] hwmon: (fam15h_power) Add compute unit accumulated power Huang Rui
@ 2015-10-30  9:57 ` Huang Rui
  2015-10-30  9:57 ` [PATCH v3 08/10] hwmon: (fam15h_power) Introduce a cpu accumulated power reporting algorithm Huang Rui
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 18+ messages in thread
From: Huang Rui @ 2015-10-30  9:57 UTC (permalink / raw)
  To: Borislav Petkov, Guenter Roeck, Peter Zijlstra, Jean Delvare,
	Andy Lutomirski, Andreas Herrmann, Thomas Gleixner, Ingo Molnar,
	Rafael J. Wysocki, Len Brown, John Stultz,
	Frédéric Weisbecker
  Cc: lm-sensors, linux-kernel, x86, Andreas Herrmann,
	Aravind Gopalakrishnan, Borislav Petkov, Fengguang Wu, Aaron Lu,
	SPG_Linux_Kernel, Huang Rui

PTSC is the performance timestamp counter value in a cpu core and the
cores in one compute unit have the fixed frequency. So it picks up the
performance timestamp counter value of the first core per compute unit
to measure the interval for average power per compute unit.

Signed-off-by: Huang Rui <ray.huang@amd.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Guenter Roeck <linux@roeck-us.net>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/include/asm/msr-index.h | 1 +
 drivers/hwmon/fam15h_power.c     | 3 +++
 2 files changed, 4 insertions(+)

diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-index.h
index b8c14bb..47bb7ef 100644
--- a/arch/x86/include/asm/msr-index.h
+++ b/arch/x86/include/asm/msr-index.h
@@ -315,6 +315,7 @@
 #define MSR_F15H_PERF_CTR		0xc0010201
 #define MSR_F15H_NB_PERF_CTL		0xc0010240
 #define MSR_F15H_NB_PERF_CTR		0xc0010241
+#define MSR_F15H_PTSC			0xc0010280
 
 /* Fam 10h MSRs */
 #define MSR_FAM10H_MMIO_CONF_BASE	0xc0010058
diff --git a/drivers/hwmon/fam15h_power.c b/drivers/hwmon/fam15h_power.c
index 5bbcb55..ec09814 100644
--- a/drivers/hwmon/fam15h_power.c
+++ b/drivers/hwmon/fam15h_power.c
@@ -63,6 +63,8 @@ struct fam15h_power_data {
 	u64 max_cu_acc_power;
 	/* accumulated power of the compute units */
 	u64 cu_acc_power[MAX_CUS];
+	/* performance timestamp counter */
+	u64 cpu_sw_pwr_ptsc[MAX_CUS];
 };
 
 static ssize_t show_power(struct device *dev,
@@ -132,6 +134,7 @@ static void do_read_registers_on_cu(void *_data)
 	cu = cpu / cores_per_cu;
 
 	rdmsrl_safe(MSR_F15H_CU_PWR_ACCUMULATOR, &data->cu_acc_power[cu]);
+	rdmsrl_safe(MSR_F15H_PTSC, &data->cpu_sw_pwr_ptsc[cu]);
 }
 
 /*
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v3 08/10] hwmon: (fam15h_power) Introduce a cpu accumulated power reporting algorithm
  2015-10-30  9:56 [PATCH v3 00/10] hwmon: (fam15h_power) Introduce an accumulated power reporting algorithm Huang Rui
                   ` (6 preceding siblings ...)
  2015-10-30  9:57 ` [PATCH v3 07/10] hwmon: (fam15h_power) Add ptsc counter value for " Huang Rui
@ 2015-10-30  9:57 ` Huang Rui
  2015-10-30  9:57 ` [PATCH v3 09/10] hwmon: (fam15h_power) Add documentation for TDP and accumulated power algorithm Huang Rui
  2015-10-30  9:57 ` [PATCH v3 10/10] MAINTAINERS: change the maintainer of fam15h_power driver Huang Rui
  9 siblings, 0 replies; 18+ messages in thread
From: Huang Rui @ 2015-10-30  9:57 UTC (permalink / raw)
  To: Borislav Petkov, Guenter Roeck, Peter Zijlstra, Jean Delvare,
	Andy Lutomirski, Andreas Herrmann, Thomas Gleixner, Ingo Molnar,
	Rafael J. Wysocki, Len Brown, John Stultz,
	Frédéric Weisbecker
  Cc: lm-sensors, linux-kernel, x86, Andreas Herrmann,
	Aravind Gopalakrishnan, Borislav Petkov, Fengguang Wu, Aaron Lu,
	SPG_Linux_Kernel, Huang Rui

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_average entry to measure the processor power
consumption and power1_average_interval entry to set the interval.

A simple example:

ray@hr-ub:~/tip$ sensors
fam15h_power-pci-00c4
Adapter: PCI adapter
power1:       23.73 mW (avg = 634.63 mW, interval =   0.01 s)
                       (crit =  15.00 W)

...

The result is current average processor power consumption in 10
millisecond. The unit of the result is uWatt.

Suggested-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Huang Rui <ray.huang@amd.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@kernel.org>
---
 drivers/hwmon/fam15h_power.c | 117 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 117 insertions(+)

diff --git a/drivers/hwmon/fam15h_power.c b/drivers/hwmon/fam15h_power.c
index ec09814..71c9e6c 100644
--- a/drivers/hwmon/fam15h_power.c
+++ b/drivers/hwmon/fam15h_power.c
@@ -27,6 +27,8 @@
 #include <linux/bitops.h>
 #include <linux/cpu.h>
 #include <linux/cpumask.h>
+#include <linux/time.h>
+#include <linux/sched.h>
 #include <asm/processor.h>
 #include <asm/msr.h>
 
@@ -48,6 +50,9 @@ MODULE_LICENSE("GPL");
 #define FAM15H_NUM_GROUPS		2
 #define MAX_CUS				8
 
+/* set maximum interval as 1 second */
+#define MAX_INTERVAL			1000
+
 #define MSR_F15H_CU_PWR_ACCUMULATOR	0xc001007a
 #define MSR_F15H_CU_MAX_PWR_ACCUMULATOR	0xc001007b
 
@@ -65,6 +70,9 @@ struct fam15h_power_data {
 	u64 cu_acc_power[MAX_CUS];
 	/* performance timestamp counter */
 	u64 cpu_sw_pwr_ptsc[MAX_CUS];
+	/* online/offline status of current compute unit */
+	int cu_on[MAX_CUS];
+	unsigned long power_period;
 };
 
 static ssize_t show_power(struct device *dev,
@@ -135,6 +143,8 @@ static void do_read_registers_on_cu(void *_data)
 
 	rdmsrl_safe(MSR_F15H_CU_PWR_ACCUMULATOR, &data->cu_acc_power[cu]);
 	rdmsrl_safe(MSR_F15H_PTSC, &data->cpu_sw_pwr_ptsc[cu]);
+
+	data->cu_on[cu] = 1;
 }
 
 /*
@@ -150,6 +160,8 @@ static int read_registers(struct fam15h_power_data *data)
 	cores_per_cu = amd_get_cores_per_cu();
 	cu_num = boot_cpu_data.x86_max_cores / cores_per_cu;
 
+	memset(data->cu_on, 0, sizeof(int) * MAX_CUS);
+
 	WARN_ON_ONCE(cu_num > MAX_CUS);
 
 	ret = zalloc_cpumask_var(&mask, GFP_KERNEL);
@@ -193,18 +205,115 @@ static int read_registers(struct fam15h_power_data *data)
 	return 0;
 }
 
+static ssize_t acc_show_power(struct device *dev,
+			      struct device_attribute *attr,
+			      char *buf)
+{
+	struct fam15h_power_data *data = dev_get_drvdata(dev);
+	u64 prev_cu_acc_power[MAX_CUS], prev_ptsc[MAX_CUS],
+	    jdelta[MAX_CUS];
+	u64 tdelta, avg_acc;
+	int cu, cu_num, cores_per_cu, ret;
+	signed long leftover;
+
+	cores_per_cu = amd_get_cores_per_cu();
+	cu_num = boot_cpu_data.x86_max_cores / cores_per_cu;
+
+	ret = read_registers(data);
+	if (ret)
+		return 0;
+
+	cu = 0;
+	while (cu++ < cu_num) {
+		prev_cu_acc_power[cu] = data->cu_acc_power[cu];
+		prev_ptsc[cu] = data->cpu_sw_pwr_ptsc[cu];
+	}
+
+	leftover = schedule_timeout_interruptible(msecs_to_jiffies(data->power_period));
+	if (leftover)
+		return 0;
+
+	ret = read_registers(data);
+	if (ret)
+		return 0;
+
+	for (cu = 0, avg_acc = 0; cu < cu_num; cu++) {
+		/* check if current compute unit is online */
+		if (data->cu_on[cu] == 0)
+			continue;
+
+		if (data->cu_acc_power[cu] < prev_cu_acc_power[cu]) {
+			jdelta[cu] = data->max_cu_acc_power + data->cu_acc_power[cu];
+			jdelta[cu] -= prev_cu_acc_power[cu];
+		} else {
+			jdelta[cu] = data->cu_acc_power[cu] - prev_cu_acc_power[cu];
+		}
+		tdelta = data->cpu_sw_pwr_ptsc[cu] - prev_ptsc[cu];
+		jdelta[cu] *= data->cpu_pwr_sample_ratio * 1000;
+		do_div(jdelta[cu], tdelta);
+
+		/* the unit is microWatt */
+		avg_acc += jdelta[cu];
+	}
+
+	return sprintf(buf, "%llu\n", (unsigned long long)avg_acc);
+}
+static DEVICE_ATTR(power1_average, S_IRUGO, acc_show_power, NULL);
+
+static ssize_t acc_show_power_period(struct device *dev,
+				     struct device_attribute *attr,
+				     char *buf)
+{
+	struct fam15h_power_data *data = dev_get_drvdata(dev);
+
+	return sprintf(buf, "%lu\n", data->power_period);
+}
+
+static ssize_t acc_set_power_period(struct device *dev,
+				    struct device_attribute *attr,
+				    const char *buf, size_t count)
+{
+	struct fam15h_power_data *data = dev_get_drvdata(dev);
+	unsigned long temp;
+	int ret;
+
+	ret = kstrtoul(buf, 10, &temp);
+	if (ret)
+		return ret;
+
+	if (temp > MAX_INTERVAL)
+		return -EINVAL;
+
+	/* the interval value should be greater than 0 */
+	if (temp <= 0)
+		return -EINVAL;
+
+	data->power_period = temp;
+
+	return count;
+}
+static DEVICE_ATTR(power1_average_interval, S_IRUGO | S_IWUSR,
+		   acc_show_power_period, acc_set_power_period);
+
 static int fam15h_power_init_attrs(struct pci_dev *pdev,
 				   struct fam15h_power_data *data)
 {
 	int n = FAM15H_MIN_NUM_ATTRS;
 	struct attribute **fam15h_power_attrs;
 	struct cpuinfo_x86 *c = &boot_cpu_data;
+	u32 cpuid;
 
 	if (c->x86 == 0x15 &&
 	    (c->x86_model <= 0xf ||
 	     (c->x86_model >= 0x60 && c->x86_model <= 0x6f)))
 		n += 1;
 
+	cpuid = cpuid_edx(0x80000007);
+
+	/* check if processor supports accumulated power */
+	if (cpuid & BIT(12))
+		n += 2;
+
 	fam15h_power_attrs = devm_kcalloc(&pdev->dev, n,
 					  sizeof(*fam15h_power_attrs),
 					  GFP_KERNEL);
@@ -219,6 +328,11 @@ static int fam15h_power_init_attrs(struct pci_dev *pdev,
 	     (c->x86_model >= 0x60 && c->x86_model <= 0x6f)))
 		fam15h_power_attrs[n++] = &dev_attr_power1_input.attr;
 
+	if (cpuid & BIT(12)) {
+		fam15h_power_attrs[n++] = &dev_attr_power1_average.attr;
+		fam15h_power_attrs[n++] = &dev_attr_power1_average_interval.attr;
+	}
+
 	data->group.attrs = fam15h_power_attrs;
 
 	return 0;
@@ -331,6 +445,9 @@ static int fam15h_power_init_data(struct pci_dev *f4,
 
 	data->max_cu_acc_power = tmp;
 
+	/* set default interval as 10 ms */
+	data->power_period = 10;
+
 	return read_registers(data);
 }
 
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v3 09/10] hwmon: (fam15h_power) Add documentation for TDP and accumulated power algorithm
  2015-10-30  9:56 [PATCH v3 00/10] hwmon: (fam15h_power) Introduce an accumulated power reporting algorithm Huang Rui
                   ` (7 preceding siblings ...)
  2015-10-30  9:57 ` [PATCH v3 08/10] hwmon: (fam15h_power) Introduce a cpu accumulated power reporting algorithm Huang Rui
@ 2015-10-30  9:57 ` Huang Rui
  2015-10-30  9:57 ` [PATCH v3 10/10] MAINTAINERS: change the maintainer of fam15h_power driver Huang Rui
  9 siblings, 0 replies; 18+ messages in thread
From: Huang Rui @ 2015-10-30  9:57 UTC (permalink / raw)
  To: Borislav Petkov, Guenter Roeck, Peter Zijlstra, Jean Delvare,
	Andy Lutomirski, Andreas Herrmann, Thomas Gleixner, Ingo Molnar,
	Rafael J. Wysocki, Len Brown, John Stultz,
	Frédéric Weisbecker
  Cc: lm-sensors, linux-kernel, x86, Andreas Herrmann,
	Aravind Gopalakrishnan, Borislav Petkov, Fengguang Wu, Aaron Lu,
	SPG_Linux_Kernel, Huang Rui

This patch adds the description to explain the TDP reporting mechanism
and accumulated power algorithm.

Signed-off-by: Huang Rui <ray.huang@amd.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Guenter Roeck <linux@roeck-us.net>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@kernel.org>
---
 Documentation/hwmon/fam15h_power | 57 +++++++++++++++++++++++++++++++++++++++-
 1 file changed, 56 insertions(+), 1 deletion(-)

diff --git a/Documentation/hwmon/fam15h_power b/Documentation/hwmon/fam15h_power
index e2b1b69..2c4fbee 100644
--- a/Documentation/hwmon/fam15h_power
+++ b/Documentation/hwmon/fam15h_power
@@ -10,14 +10,22 @@ Supported chips:
   Datasheets:
   BIOS and Kernel Developer's Guide (BKDG) For AMD Family 15h Processors
   BIOS and Kernel Developer's Guide (BKDG) For AMD Family 16h Processors
+  AMD64 Architecture Programmer's Manual Volume 2: System Programming
 
 Author: Andreas Herrmann <herrmann.der.user@googlemail.com>
 
 Description
 -----------
 
+1) Processor TDP (Thermal design power)
+
+Given a fixed frequency and voltage, the power consumption of a
+processor varies based on the workload being executed. Derated power
+is the power consumed when running a specific application. Thermal
+design power (TDP) is an example of derated power.
+
 This driver permits reading of registers providing power information
-of AMD Family 15h and 16h processors.
+of AMD Family 15h and 16h processors via TDP algorithm.
 
 For AMD Family 15h and 16h processors the following power values can
 be calculated using different processor northbridge function
@@ -37,3 +45,50 @@ This driver provides ProcessorPwrWatts and CurrPwrWatts:
 On multi-node processors the calculated value is for the entire
 package and not for a single node. Thus the driver creates sysfs
 attributes only for internal node0 of a multi-node processor.
+
+2) Accumulated Power Mechanism
+
+This driver also introduces an algorithm that should be used to
+calculate the average power consumed by a processor during a
+measurement interval Tm. The feature of accumulated power mechanism is
+indicated by CPUID Fn8000_0007_EDX[12].
+
+* Tsample: compute unit power accumulator sample period
+* Tref: the PTSC counter period
+* PTSC: performance timestamp counter
+* N: the ratio of compute unit power accumulator sample period to the
+  PTSC period
+* Jmax: max compute unit accumulated power which is indicated by
+  MaxCpuSwPwrAcc MSR C001007b
+* Jx/Jy: compute unit accumulated power which is indicated by
+  CpuSwPwrAcc MSR C001007a
+* Tx/Ty: the value of performance timestamp counter which is indicated
+  by CU_PTSC MSR C0010280
+* PwrCPUave: CPU average power
+
+i. Determine the ratio of Tsample to Tref by executing CPUID Fn8000_0007.
+	N = value of CPUID Fn8000_0007_ECX[CpuPwrSampleTimeRatio[15:0]].
+
+ii. Read the full range of the cumulative energy value from the new
+MSR MaxCpuSwPwrAcc.
+	Jmax = value returned.
+iii. At time x, SW reads CpuSwPwrAcc MSR and samples the PTSC.
+	Jx = value read from CpuSwPwrAcc and Tx = value read from
+PTSC.
+
+iv. At time y, SW reads CpuSwPwrAcc MSR and samples the PTSC.
+	Jy = value read from CpuSwPwrAcc and Ty = value read from
+PTSC.
+
+v. Calculate the average power consumption for a compute unit over
+time period (y-x). Unit of result is uWatt.
+	if (Jy < Jx) // Rollover has occurred
+		Jdelta = (Jy + Jmax) - Jx
+	else
+		Jdelta = Jy - Jx
+	PwrCPUave = N * Jdelta * 1000 / (Ty - Tx)
+
+This driver provides PwrCPUave and interval(default is 10 millisecond
+and maximum is 1 second):
+* power1_average (PwrCPUave)
+* power1_average_interval (Interval)
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH v3 10/10] MAINTAINERS: change the maintainer of fam15h_power driver
  2015-10-30  9:56 [PATCH v3 00/10] hwmon: (fam15h_power) Introduce an accumulated power reporting algorithm Huang Rui
                   ` (8 preceding siblings ...)
  2015-10-30  9:57 ` [PATCH v3 09/10] hwmon: (fam15h_power) Add documentation for TDP and accumulated power algorithm Huang Rui
@ 2015-10-30  9:57 ` Huang Rui
  9 siblings, 0 replies; 18+ messages in thread
From: Huang Rui @ 2015-10-30  9:57 UTC (permalink / raw)
  To: Borislav Petkov, Guenter Roeck, Peter Zijlstra, Jean Delvare,
	Andy Lutomirski, Andreas Herrmann, Thomas Gleixner, Ingo Molnar,
	Rafael J. Wysocki, Len Brown, John Stultz,
	Frédéric Weisbecker
  Cc: lm-sensors, linux-kernel, x86, Andreas Herrmann,
	Aravind Gopalakrishnan, Borislav Petkov, Fengguang Wu, Aaron Lu,
	SPG_Linux_Kernel, Huang Rui

Andreas Herrmann won't take the maintainer of fam15h_power driver. I
will take it and appreciate him for the great contributions on this
driver.

Signed-off-by: Huang Rui <ray.huang@amd.com>
Acked-by: Andreas Herrmann <herrmann.der.user@googlemail.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Aravind Gopalakrishnan <Aravind.Gopalakrishnan@amd.com>
---
 CREDITS     | 8 ++++++++
 MAINTAINERS | 4 ++--
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/CREDITS b/CREDITS
index 8207cc6..30bdce8 100644
--- a/CREDITS
+++ b/CREDITS
@@ -1507,6 +1507,14 @@ S: 312/107 Canberra Avenue
 S: Griffith, ACT 2603 
 S: Australia
 
+N: Andreas Herrmann
+E: herrmann.der.user@gmail.com
+E: herrmann.der.user@googlemail.com
+D: Key developer of x86/AMD64
+D: Author of AMD family 15h processor power monintoring driver
+D: Maintainer of AMD Athlon 64 and Opteron processor frequency driver
+S: Germany
+
 N: Sebastian Hetze
 E: she@lunetix.de
 D: German Linux Documentation,
diff --git a/MAINTAINERS b/MAINTAINERS
index 5f46784..a2d954f 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -608,9 +608,9 @@ F:	drivers/crypto/ccp/
 F:	include/linux/ccp.h
 
 AMD FAM15H PROCESSOR POWER MONITORING DRIVER
-M:	Andreas Herrmann <herrmann.der.user@googlemail.com>
+M:	Huang Rui <ray.huang@amd.com>
 L:	lm-sensors@lm-sensors.org
-S:	Maintained
+S:	Supported
 F:	Documentation/hwmon/fam15h_power
 F:	drivers/hwmon/fam15h_power.c
 
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [PATCH v3 06/10] hwmon: (fam15h_power) Add compute unit accumulated power
  2015-10-30  9:57 ` [PATCH v3 06/10] hwmon: (fam15h_power) Add compute unit accumulated power Huang Rui
@ 2015-10-30 10:33   ` kbuild test robot
  2015-11-02  4:45     ` Huang Rui
  0 siblings, 1 reply; 18+ messages in thread
From: kbuild test robot @ 2015-10-30 10:33 UTC (permalink / raw)
  To: Huang Rui
  Cc: kbuild-all, Borislav Petkov, Guenter Roeck, Peter Zijlstra,
	Jean Delvare, Andy Lutomirski, Andreas Herrmann, Thomas Gleixner,
	Ingo Molnar, Rafael J. Wysocki, Len Brown, John Stultz,
	Frédéric Weisbecker, lm-sensors, linux-kernel, x86,
	Andreas Herrmann, Aravind Gopalakrishnan, Borislav Petkov,
	Fengguang Wu, Aaron Lu, SPG_Linux_Kernel, Huang Rui

[-- Attachment #1: Type: text/plain, Size: 4055 bytes --]

Hi Huang,

[auto build test WARNING on hwmon/hwmon-next -- if it's inappropriate base, please suggest rules for selecting the more suitable base]

url:    https://github.com/0day-ci/linux/commits/Huang-Rui/hwmon-fam15h_power-Introduce-an-accumulated-power-reporting-algorithm/20151030-181426
config: x86_64-randconfig-x012-10300134 (attached as .config)
reproduce:
        # save the attached .config to linux build tree
        make ARCH=x86_64 

Note: it may well be a FALSE warning. FWIW you are at least aware of it now.
http://gcc.gnu.org/wiki/Better_Uninitialized_Warnings

All warnings (new ones prefixed by >>):

   In file included from arch/x86/include/asm/cpumask.h:4:0,
                    from arch/x86/include/asm/msr.h:10,
                    from arch/x86/include/asm/processor.h:20,
                    from arch/x86/include/asm/atomic.h:6,
                    from include/linux/atomic.h:4,
                    from include/linux/debug_locks.h:5,
                    from include/linux/lockdep.h:23,
                    from include/linux/spinlock_types.h:18,
                    from include/linux/mutex.h:15,
                    from include/linux/kernfs.h:13,
                    from include/linux/sysfs.h:15,
                    from include/linux/kobject.h:21,
                    from include/linux/device.h:17,
                    from include/linux/hwmon-sysfs.h:23,
                    from drivers/hwmon/fam15h_power.c:23:
   drivers/hwmon/fam15h_power.c: In function 'fam15h_power_probe':
>> include/linux/cpumask.h:24:29: warning: 'res_mask' may be used uninitialized in this function [-Wmaybe-uninitialized]
    #define cpumask_bits(maskp) ((maskp)->bits)
                                ^
   drivers/hwmon/fam15h_power.c:145:32: note: 'res_mask' was declared here
     cpumask_var_t mask, tmp_mask, res_mask;
                                   ^

vim +/res_mask +24 include/linux/cpumask.h

^1da177e Linus Torvalds 2005-04-16   8   */
^1da177e Linus Torvalds 2005-04-16   9  #include <linux/kernel.h>
^1da177e Linus Torvalds 2005-04-16  10  #include <linux/threads.h>
^1da177e Linus Torvalds 2005-04-16  11  #include <linux/bitmap.h>
187f1882 Paul Gortmaker 2011-11-23  12  #include <linux/bug.h>
^1da177e Linus Torvalds 2005-04-16  13  
cdfdef75 Rusty Russell  2015-03-05  14  /* Don't assign or return these: may not be this big! */
2d3854a3 Rusty Russell  2008-11-05  15  typedef struct cpumask { DECLARE_BITMAP(bits, NR_CPUS); } cpumask_t;
^1da177e Linus Torvalds 2005-04-16  16  
ae7a47e7 Rusty Russell  2008-12-30  17  /**
6ba2ef7b Rusty Russell  2009-09-24  18   * cpumask_bits - get the bits in a cpumask
6ba2ef7b Rusty Russell  2009-09-24  19   * @maskp: the struct cpumask *
ae7a47e7 Rusty Russell  2008-12-30  20   *
6ba2ef7b Rusty Russell  2009-09-24  21   * You should only assume nr_cpu_ids bits of this mask are valid.  This is
6ba2ef7b Rusty Russell  2009-09-24  22   * a macro so it's const-correct.
ae7a47e7 Rusty Russell  2008-12-30  23   */
6ba2ef7b Rusty Russell  2009-09-24 @24  #define cpumask_bits(maskp) ((maskp)->bits)
7ea931c9 Paul Jackson   2008-04-28  25  
f1bbc032 Tejun Heo      2015-02-13  26  /**
f1bbc032 Tejun Heo      2015-02-13  27   * cpumask_pr_args - printf args to output a cpumask
f1bbc032 Tejun Heo      2015-02-13  28   * @maskp: cpumask to be printed
f1bbc032 Tejun Heo      2015-02-13  29   *
f1bbc032 Tejun Heo      2015-02-13  30   * Can be used to provide arguments for '%*pb[l]' when printing a cpumask.
f1bbc032 Tejun Heo      2015-02-13  31   */
f1bbc032 Tejun Heo      2015-02-13  32  #define cpumask_pr_args(maskp)		nr_cpu_ids, cpumask_bits(maskp)

:::::: The code at line 24 was first introduced by commit
:::::: 6ba2ef7baac23a5d9bb85e28b882d16b439a2293 cpumask: Move deprecated functions to end of header.

:::::: TO: Rusty Russell <rusty@rustcorp.com.au>
:::::: CC: Rusty Russell <rusty@rustcorp.com.au>

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/octet-stream, Size: 20791 bytes --]

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v3 01/10] hwmon: (fam15h_power) Refactor attributes for dynamically added
  2015-10-30  9:56 ` [PATCH v3 01/10] hwmon: (fam15h_power) Refactor attributes for dynamically added Huang Rui
@ 2015-10-31 22:38   ` Guenter Roeck
  0 siblings, 0 replies; 18+ messages in thread
From: Guenter Roeck @ 2015-10-31 22:38 UTC (permalink / raw)
  To: Huang Rui, Borislav Petkov, Peter Zijlstra, Jean Delvare,
	Andy Lutomirski, Andreas Herrmann, Thomas Gleixner, Ingo Molnar,
	Rafael J. Wysocki, Len Brown, John Stultz,
	Frédéric Weisbecker
  Cc: lm-sensors, linux-kernel, x86, Andreas Herrmann,
	Aravind Gopalakrishnan, Borislav Petkov, Fengguang Wu, Aaron Lu,
	SPG_Linux_Kernel

On 10/30/2015 02:56 AM, Huang Rui wrote:
> Attributes depend on the CPU model the driver gets loaded on.
> Therefore, add those attributes dynamically at init time. This is more
> flexible to control the different attributes on different platforms.
>
> Suggested-by: Borislav Petkov <bp@alien8.de>
> Signed-off-by: Huang Rui <ray.huang@amd.com>

Applied.

Thanks,
Guenter


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v3 02/10] hwmon: (fam15h_power) Enable power1_input on AMD Carrizo
  2015-10-30  9:56 ` [PATCH v3 02/10] hwmon: (fam15h_power) Enable power1_input on AMD Carrizo Huang Rui
@ 2015-10-31 22:42   ` Guenter Roeck
  2015-11-02  4:58     ` Huang Rui
  0 siblings, 1 reply; 18+ messages in thread
From: Guenter Roeck @ 2015-10-31 22:42 UTC (permalink / raw)
  To: Huang Rui, Jean Delvare, Andreas Herrmann; +Cc: lm-sensors, linux-kernel

On 10/30/2015 02:56 AM, Huang Rui wrote:
> This patch enables power1_input attribute for Carrizo platform.
>
> Signed-off-by: Huang Rui <ray.huang@amd.com>
> Cc: Borislav Petkov <bp@alien8.de>
> Cc: Guenter Roeck <linux@roeck-us.net>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Ingo Molnar <mingo@kernel.org>

Applied to -next.

On a side note, your Cc: list is a bit large. You might want to cut it down a bit.

Thanks,
Guenter


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v3 03/10] hwmon: (fam15h_power) Add max compute unit accumulated power
  2015-10-30  9:56 ` [PATCH v3 03/10] hwmon: (fam15h_power) Add max compute unit accumulated power Huang Rui
@ 2015-10-31 22:44   ` Guenter Roeck
  0 siblings, 0 replies; 18+ messages in thread
From: Guenter Roeck @ 2015-10-31 22:44 UTC (permalink / raw)
  To: Huang Rui, Borislav Petkov, Peter Zijlstra, Jean Delvare,
	Andy Lutomirski, Andreas Herrmann, Thomas Gleixner, Ingo Molnar,
	Rafael J. Wysocki, Len Brown, John Stultz,
	Frédéric Weisbecker
  Cc: lm-sensors, linux-kernel, x86, Andreas Herrmann,
	Aravind Gopalakrishnan, Borislav Petkov, Fengguang Wu, Aaron Lu,
	SPG_Linux_Kernel

On 10/30/2015 02:56 AM, Huang Rui wrote:
> This patch adds a member in fam15h_power_data which specifies the
> maximum accumulated power in a compute unit.
>
> Signed-off-by: Huang Rui <ray.huang@amd.com>
> Cc: Borislav Petkov <bp@alien8.de>
> Cc: Guenter Roeck <linux@roeck-us.net>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Ingo Molnar <mingo@kernel.org>

Applied to -next.

Thanks,
Guenter



^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v3 04/10] x86, amd: add accessor for number of cores per compute unit
  2015-10-30  9:56 ` [PATCH v3 04/10] x86, amd: add accessor for number of cores per compute unit Huang Rui
@ 2015-10-31 22:45   ` Guenter Roeck
  0 siblings, 0 replies; 18+ messages in thread
From: Guenter Roeck @ 2015-10-31 22:45 UTC (permalink / raw)
  To: Huang Rui, Borislav Petkov, Peter Zijlstra, Jean Delvare,
	Andy Lutomirski, Andreas Herrmann, Thomas Gleixner, Ingo Molnar,
	Rafael J. Wysocki, Len Brown, John Stultz,
	Frédéric Weisbecker
  Cc: lm-sensors, linux-kernel, x86, Andreas Herrmann,
	Aravind Gopalakrishnan, Borislav Petkov, Fengguang Wu, Aaron Lu,
	SPG_Linux_Kernel

On 10/30/2015 02:56 AM, Huang Rui wrote:
> Add an accessor function amd_get_cores_per_cu() which returns the
> number of cores per compute unit. In multiple CPUs, they always have
> the same number of cores per compute unit.
>
> In a subsequent patch, we will use this function in fam15h_power
> driver.
>
> Signed-off-by: Huang Rui <ray.huang@amd.com>
> Cc: Borislav Petkov <bp@alien8.de>
> Cc: Guenter Roeck <linux@roeck-us.net>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Ingo Molnar <mingo@kernel.org>

This patch will require an Acked-by: from an x86 maintainer.

Thanks,
Guenter

> ---
>   arch/x86/include/asm/processor.h |  1 +
>   arch/x86/kernel/cpu/amd.c        | 19 +++++++++++++++++--
>   2 files changed, 18 insertions(+), 2 deletions(-)
>
> diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
> index 19577dd..831ad682 100644
> --- a/arch/x86/include/asm/processor.h
> +++ b/arch/x86/include/asm/processor.h
> @@ -810,6 +810,7 @@ static inline int mpx_disable_management(void)
>
>   extern u16 amd_get_nb_id(int cpu);
>   extern u32 amd_get_nodes_per_socket(void);
> +extern u32 amd_get_cores_per_cu(void);
>
>   static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves)
>   {
> diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
> index 4a70fc6..a914b1b 100644
> --- a/arch/x86/kernel/cpu/amd.c
> +++ b/arch/x86/kernel/cpu/amd.c
> @@ -27,6 +27,9 @@
>    */
>   static u32 nodes_per_socket = 1;
>
> +/* cores_per_cu: stores the number of cores per compute unit */
> +static u32 cores_per_cu = 1;
> +
>   static inline int rdmsrl_amd_safe(unsigned msr, unsigned long long *p)
>   {
>   	u32 gprs[8] = { 0 };
> @@ -299,7 +302,6 @@ static int nearby_node(int apicid)
>   #ifdef CONFIG_SMP
>   static void amd_get_topology(struct cpuinfo_x86 *c)
>   {
> -	u32 cores_per_cu = 1;
>   	u8 node_id;
>   	int cpu = smp_processor_id();
>
> @@ -314,7 +316,6 @@ static void amd_get_topology(struct cpuinfo_x86 *c)
>   		/* get compute unit information */
>   		smp_num_siblings = ((ebx >> 8) & 3) + 1;
>   		c->compute_unit_id = ebx & 0xff;
> -		cores_per_cu += ((ebx >> 8) & 3);
>   	} else if (cpu_has(c, X86_FEATURE_NODEID_MSR)) {
>   		u64 value;
>
> @@ -380,6 +381,13 @@ u32 amd_get_nodes_per_socket(void)
>   }
>   EXPORT_SYMBOL_GPL(amd_get_nodes_per_socket);
>
> +/* this function returns the number of cores per compute unit */
> +u32 amd_get_cores_per_cu(void)
> +{
> +	return cores_per_cu;
> +}
> +EXPORT_SYMBOL_GPL(amd_get_cores_per_cu);
> +
>   static void srat_detect_node(struct cpuinfo_x86 *c)
>   {
>   #ifdef CONFIG_NUMA
> @@ -510,6 +518,13 @@ static void bsp_init_amd(struct cpuinfo_x86 *c)
>
>   	if (cpu_has(c, X86_FEATURE_MWAITX))
>   		use_mwaitx_delay();
> +
> +	if (cpu_has_topoext) {
> +		u32 cpuid;
> +
> +		cpuid = cpuid_ebx(0x8000001e);
> +		cores_per_cu += ((cpuid >> 8) & 3);
> +	}
>   }
>
>   static void early_init_amd(struct cpuinfo_x86 *c)
>


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH v3 06/10] hwmon: (fam15h_power) Add compute unit accumulated power
  2015-10-30 10:33   ` kbuild test robot
@ 2015-11-02  4:45     ` Huang Rui
  0 siblings, 0 replies; 18+ messages in thread
From: Huang Rui @ 2015-11-02  4:45 UTC (permalink / raw)
  To: kbuild test robot
  Cc: kbuild-all, Borislav Petkov, Guenter Roeck, Peter Zijlstra,
	Jean Delvare, Andy Lutomirski, Andreas Herrmann, Thomas Gleixner,
	Ingo Molnar, Rafael J. Wysocki, Len Brown, John Stultz,
	Fr�d�ric Weisbecker, lm-sensors, linux-kernel, x86,
	Andreas Herrmann, Aravind Gopalakrishnan, Borislav Petkov,
	Fengguang Wu, Aaron Lu, SPG_Linux_Kernel

On Fri, Oct 30, 2015 at 06:33:42PM +0800, kbuild test robot wrote:
> Hi Huang,
> 
> [auto build test WARNING on hwmon/hwmon-next -- if it's inappropriate base, please suggest rules for selecting the more suitable base]
> 
> url:    https://github.com/0day-ci/linux/commits/Huang-Rui/hwmon-fam15h_power-Introduce-an-accumulated-power-reporting-algorithm/20151030-181426
> config: x86_64-randconfig-x012-10300134 (attached as .config)
> reproduce:
>         # save the attached .config to linux build tree
>         make ARCH=x86_64 
> 
> Note: it may well be a FALSE warning. FWIW you are at least aware of it now.
> http://gcc.gnu.org/wiki/Better_Uninitialized_Warnings
> 
> All warnings (new ones prefixed by >>):
> 
>    In file included from arch/x86/include/asm/cpumask.h:4:0,
>                     from arch/x86/include/asm/msr.h:10,
>                     from arch/x86/include/asm/processor.h:20,
>                     from arch/x86/include/asm/atomic.h:6,
>                     from include/linux/atomic.h:4,
>                     from include/linux/debug_locks.h:5,
>                     from include/linux/lockdep.h:23,
>                     from include/linux/spinlock_types.h:18,
>                     from include/linux/mutex.h:15,
>                     from include/linux/kernfs.h:13,
>                     from include/linux/sysfs.h:15,
>                     from include/linux/kobject.h:21,
>                     from include/linux/device.h:17,
>                     from include/linux/hwmon-sysfs.h:23,
>                     from drivers/hwmon/fam15h_power.c:23:
>    drivers/hwmon/fam15h_power.c: In function 'fam15h_power_probe':
> >> include/linux/cpumask.h:24:29: warning: 'res_mask' may be used uninitialized in this function [-Wmaybe-uninitialized]
>     #define cpumask_bits(maskp) ((maskp)->bits)
>                                 ^
>    drivers/hwmon/fam15h_power.c:145:32: note: 'res_mask' was declared here
>      cpumask_var_t mask, tmp_mask, res_mask;
>                                    ^

Thank you to capture it! That's because my machine doesn't enable
CONFIG_CPUMASK_OFFSTACK. So I didn't find this issue before.  :)

It needs to allocate res_mask like below:

---
diff --git a/drivers/hwmon/fam15h_power.c b/drivers/hwmon/fam15h_power.c
index 71c9e6c..499776b 100644
--- a/drivers/hwmon/fam15h_power.c
+++ b/drivers/hwmon/fam15h_power.c
@@ -172,6 +172,10 @@ static int read_registers(struct fam15h_power_data *data)
 	if (!ret)
 		return -ENOMEM;
 
+	ret = zalloc_cpumask_var(&res_mask, GFP_KERNEL);
+	if (!ret)
+		return -ENOMEM;
+
 	get_online_cpus();
 	this_cpu = get_cpu();
 
@@ -199,6 +203,7 @@ static int read_registers(struct fam15h_power_data *data)
 	put_cpu();
 	put_online_cpus();
 
+	free_cpumask_var(res_mask);
 	free_cpumask_var(tmp_mask);
 	free_cpumask_var(mask);
 
---

Thanks,
Rui

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [PATCH v3 02/10] hwmon: (fam15h_power) Enable power1_input on AMD Carrizo
  2015-10-31 22:42   ` Guenter Roeck
@ 2015-11-02  4:58     ` Huang Rui
  0 siblings, 0 replies; 18+ messages in thread
From: Huang Rui @ 2015-11-02  4:58 UTC (permalink / raw)
  To: Guenter Roeck; +Cc: Jean Delvare, Andreas Herrmann, lm-sensors, linux-kernel

On Sat, Oct 31, 2015 at 03:42:46PM -0700, Guenter Roeck wrote:
> On 10/30/2015 02:56 AM, Huang Rui wrote:
> >This patch enables power1_input attribute for Carrizo platform.
> >
> >Signed-off-by: Huang Rui <ray.huang@amd.com>
> >Cc: Borislav Petkov <bp@alien8.de>
> >Cc: Guenter Roeck <linux@roeck-us.net>
> >Cc: Peter Zijlstra <peterz@infradead.org>
> >Cc: Ingo Molnar <mingo@kernel.org>
> 
> Applied to -next.
> 
> On a side note, your Cc: list is a bit large. You might want to cut it down a bit.
> 

OK, do you point the Cc list in the patch?

Cc: Borislav Petkov <bp@alien8.de>
Cc: Guenter Roeck <linux@roeck-us.net>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@kernel.org>

Or in the mail?
Cc: lm-sensors@lm-sensors.org, linux-kernel@vger.kernel.org, ...

Thanks,
Rui

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2015-11-02  4:59 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-30  9:56 [PATCH v3 00/10] hwmon: (fam15h_power) Introduce an accumulated power reporting algorithm Huang Rui
2015-10-30  9:56 ` [PATCH v3 01/10] hwmon: (fam15h_power) Refactor attributes for dynamically added Huang Rui
2015-10-31 22:38   ` Guenter Roeck
2015-10-30  9:56 ` [PATCH v3 02/10] hwmon: (fam15h_power) Enable power1_input on AMD Carrizo Huang Rui
2015-10-31 22:42   ` Guenter Roeck
2015-11-02  4:58     ` Huang Rui
2015-10-30  9:56 ` [PATCH v3 03/10] hwmon: (fam15h_power) Add max compute unit accumulated power Huang Rui
2015-10-31 22:44   ` Guenter Roeck
2015-10-30  9:56 ` [PATCH v3 04/10] x86, amd: add accessor for number of cores per compute unit Huang Rui
2015-10-31 22:45   ` Guenter Roeck
2015-10-30  9:56 ` [PATCH v3 05/10] hwmon: (fam15h_power) Add CPU_SUP_AMD as the dependence Huang Rui
2015-10-30  9:57 ` [PATCH v3 06/10] hwmon: (fam15h_power) Add compute unit accumulated power Huang Rui
2015-10-30 10:33   ` kbuild test robot
2015-11-02  4:45     ` Huang Rui
2015-10-30  9:57 ` [PATCH v3 07/10] hwmon: (fam15h_power) Add ptsc counter value for " Huang Rui
2015-10-30  9:57 ` [PATCH v3 08/10] hwmon: (fam15h_power) Introduce a cpu accumulated power reporting algorithm Huang Rui
2015-10-30  9:57 ` [PATCH v3 09/10] hwmon: (fam15h_power) Add documentation for TDP and accumulated power algorithm Huang Rui
2015-10-30  9:57 ` [PATCH v3 10/10] MAINTAINERS: change the maintainer of fam15h_power driver Huang Rui

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