Skip to contentSkip to conversation

Power Capping Framework and RAPL Driver

PATCH In review Srinivas Pandruvada 3 participants 14 messages Sep 19, 2013

Subsystems (7)
lore
Share & tools
lore
#0 lore raw

cover Power Capping Framework and RAPL Driver

Overview
With the evolution of technologies, which enables power monitoring and limiting, more and more devices are able to constrain their power consumption under certain limits. There are several use cases for such technologies:
- Power monitoring: Each device can report its power consumption.
- Power Limiting: Setting power limits on the devices allows users to guard against platform reaching max system power level.
- Maximize performance: While staying below a power limit, it allows devices to automatically adjust performance to meet demands
- Dynamic control and re-budgeting: If each device can be constrained to some power, extra power can redistributed to other devices, which needs additional performance.

One such example of technologies is RAPL (Running Average Power Limit) mechanism available in the latest Intel processors. Intel is slowly adding many devices under RAPL control. Also there are other technologies available, for power capping various devices. Soon it is very likely that other vendors are also adding or considering such implementation.

Power Capping framework is an effort to have a uniform interface available to Linux drivers, which will enable
- A uniform sysfs interface for all devices which can offer power capping
- A common API for drivers, which will avoid code duplication and easy implementation of client drivers.

Also submitting Intel RAPL driver using power capping framework.

History:
v1
Incorporated changes suggested during RFC stage

Jacob Pan (2):
x86/msr: add 64bit _on_cpu access functions
Introduce Intel RAPL power capping driver

Srinivas Pandruvada (4):
PowerCap: Documentation
PowerCap: Add class driver
PowerCap: Added to drivers build
bitops: Introduce BIT_ULL

 Documentation/ABI/testing/sysfs-class-powercap |  152 +++
 Documentation/power/powercap/powercap.txt      |  236 ++++
 arch/x86/include/asm/msr.h                     |   22 +
 arch/x86/lib/msr-smp.c                         |   62 ++
 drivers/Kconfig                                |    2 +
 drivers/Makefile                               |    1 +
 drivers/powercap/Kconfig                       |   31 +
 drivers/powercap/Makefile                      |    2 +
 drivers/powercap/intel_rapl.c                  | 1395 ++++++++++++++++++++++++
 drivers/powercap/powercap_sys.c                |  699 ++++++++++++
 include/linux/bitops.h                         |    1 +
 include/linux/powercap.h                       |  325 ++++++
 12 files changed, 2928 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-class-powercap
 create mode 100644 Documentation/power/powercap/powercap.txt
 create mode 100644 drivers/powercap/Kconfig
 create mode 100644 drivers/powercap/Makefile
 create mode 100644 drivers/powercap/intel_rapl.c
 create mode 100644 drivers/powercap/powercap_sys.c
 create mode 100644 include/linux/powercap.h
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 1/6 PowerCap: Documentation

Added power cap framework documentation. This explains the use of power capping framework, sysfs and programming interface.
There are two documents:
Documentation/power/powercap/powercap.txt : Explains use case and APIs. Documentation/ABI/testing/sysfs-class-powercap: Explains ABIs.

---
 Documentation/ABI/testing/sysfs-class-powercap | 152 ++++++++++++++++
 Documentation/power/powercap/powercap.txt      | 236 +++++++++++++++++++++++++
 2 files changed, 388 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-class-powercap
 create mode 100644 Documentation/power/powercap/powercap.txt
Documentation/ABI/testing/sysfs-class-powercap new file +152 -0
new file mode 100644
index 0000000..db3b3ff
@@ -0,0 +1,152 @@
+What:		/sys/class/powercap/
+Date:		September 2013
+KernelVersion:	3.13
+Contact:	[email protected]
+Description:
+		The powercap/ class sub directory belongs to the power cap
+		subsystem. Refer to
+		Documentation/power/powercap/powercap.txt for details.
+
+What:		/sys/class/powercap/<control type>
+Date:		September 2013
+KernelVersion:	3.13
+Contact:	[email protected]
+Description:
+		A <control type> is a unique name under /sys/class/powercap.
+		Here <control type> determines how the power is going to be
+		controlled. A <control type> can contain multiple power zones.
+
+What:		/sys/class/powercap/<control type>/enabled
+Date:		September 2013
+KernelVersion:	3.13
+Contact:	[email protected]
+Description:
+		This allows to enable/disable power capping for a "control type".
+		This status affects every power zone using this "control_type.
+
+What:		/sys/class/powercap/<control type>/<power zone>
+Date:		September 2013
+KernelVersion:	3.13
+Contact:	[email protected]
+Description:
+		A power zone is a single or a collection of devices, which can
+		be independently monitored and controlled. A power zone sysfs
+		entry is qualified with the name of the <control type>.
+		E.g. intel-rapl:0:1:1.
+
+What:		/sys/class/powercap/<control type>/<power zone>/<child power zone>
+Date:		September 2013
+KernelVersion:	3.13
+Contact:	[email protected]
+Description:
+		Power zones may be organized in a hierarchy in which child
+		power zones provide monitoring and control for a subset of
+		devices under the parent. For example, if there is a parent
+		power zone for a whole CPU package, each CPU core in it can
+		be a child power zone.
+
+What:		/sys/class/powercap/.../<power zone>/name
+Date:		September 2013
+KernelVersion:	3.13
+Contact:	[email protected]
+Description:
+		Specifies the name of this power zone.
+
+What:		/sys/class/powercap/.../<power zone>/energy_uj
+Date:		September 2013
+KernelVersion:	3.13
+Contact:	[email protected]
+Description:
+		Current energy counter in micro-joules. Write "0" to reset.
+		If the counter can not be reset, then this attribute is
+		read-only.
+
+What:		/sys/class/powercap/.../<power zone>/max_energy_range_uj
+Date:		September 2013
+KernelVersion:	3.13
+Contact:	[email protected]
+Description:
+		Range of the above energy counter in micro-joules.
+
+
+What:		/sys/class/powercap/.../<power zone>/power_uw
+Date:		September 2013
+KernelVersion:	3.13
+Contact:	[email protected]
+Description:
+		Current power in micro-watts.
+
+What:		/sys/class/powercap/.../<power zone>/max_power_range_uw
+Date:		September 2013
+KernelVersion:	3.13
+Contact:	[email protected]
+Description:
+		Range of the above power value in micro-watts.
+
+What:		/sys/class/powercap/.../<power zone>/constraint_X_name
+Date:		September 2013
+KernelVersion:	3.13
+Contact:	[email protected]
+Description:
+		Each power zone can define one or more constraints. Each
+		constraint can have an optional name. Here "X" can have values
+		from 0 to max integer.
+
+What:		/sys/class/powercap/.../<power zone>/constraint_X_power_limit_uw
+Date:		September 2013
+KernelVersion:	3.13
+Contact:	[email protected]
+Description:
+		Power limit in micro-watts should be applicable for
+		the time window specified by "constraint_X_time_window_us".
+		Here "X" can have values from 0 to max integer.
+
+What:		/sys/class/powercap/.../<power zone>/constraint_X_time_window_us
+Date:		September 2013
+KernelVersion:	3.13
+Contact:	[email protected]
+Description:
+		Time window in micro seconds. This is used along with
+		constraint_X_power_limit_uw to define a power constraint.
+		Here "X" can have values from 0 to max integer.
+
+
+What:		/sys/class/powercap/<control type>/.../constraint_X_max_power_uw
+Date:		September 2013
+KernelVersion:	3.13
+Contact:	[email protected]
+Description:
+		Maximum allowed power in micro watts for this constraint.
+		Here "X" can have values from 0 to max integer.
+
+What:		/sys/class/powercap/<control type>/.../constraint_X_min_power_uw
+Date:		September 2013
+KernelVersion:	3.13
+Contact:	[email protected]
+Description:
+		Minimum allowed power in micro watts for this constraint.
+		Here "X" can have values from 0 to max integer.
+
+What:		/sys/class/powercap/.../<power zone>/constraint_X_max_time_window_us
+Date:		September 2013
+KernelVersion:	3.13
+Contact:	[email protected]
+Description:
+		Maximum allowed time window in micro seconds for this
+		constraint. Here "X" can have values from 0 to max integer.
+
+What:		/sys/class/powercap/.../<power zone>/constraint_X_min_time_window_us
+Date:		September 2013
+KernelVersion:	3.13
+Contact:	[email protected]
+Description:
+		Minimum allowed time window in micro seconds for this
+		constraint. Here "X" can have values from 0 to max integer.
+
+What:		/sys/class/powercap/.../<power zone>/enabled
+Date:		September 2013
+KernelVersion:	3.13
+Contact:	[email protected]
+Description
+		This allows to enable/disable power capping at power zone level.
+		This applies to current power zone and its children.
Documentation/power/powercap/powercap.txt new file +236 -0

236 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#2 lore raw

PATCH 2/6 PowerCap: Add class driver

In reply to Srinivas Pandruvada

The power capping framework providing a consistent interface between the kernel and user space that allows power capping drivers to expose their settings to user space in a uniform way.
The overall design of the framework is described in the documentation added by the previous patch in this series.

---
 drivers/powercap/Kconfig        |  19 ++
 drivers/powercap/Makefile       |   1 +
 drivers/powercap/powercap_sys.c | 699 ++++++++++++++++++++++++++++++++++++++++
 include/linux/powercap.h        | 325 +++++++++++++++++++
 4 files changed, 1044 insertions(+)
 create mode 100644 drivers/powercap/Kconfig
 create mode 100644 drivers/powercap/Makefile
 create mode 100644 drivers/powercap/powercap_sys.c
 create mode 100644 include/linux/powercap.h
drivers/powercap/Kconfig new file +19 -0
new file mode 100644
index 0000000..a37055e
@@ -0,0 +1,19 @@
+#
+# Generic power capping sysfs interface configuration
+#
+
+menuconfig POWERCAP
+	bool "Generic powercap sysfs driver"
+	help
+	  The power capping sysfs interface allows kernel subsystems to expose power
+	  capping settings to user space in a consistent way.  Usually, it consists
+	  of multiple control types that determine which settings may be exposed and
+	  power zones representing parts of the system that can be subject to power
+	  capping.
+
+	  If you want this code to be compiled in, say Y here.
+
+if POWERCAP
+# Client driver configurations go here.
+
+endif
drivers/powercap/Makefile new file +1 -0
new file mode 100644
index 0000000..6defbc8
@@ -0,0 +1 @@
+obj-$(CONFIG_POWERCAP)	+= powercap_sys.o
include/linux/powercap.h new file +325 -0

325 lines not on this page · raw message

drivers/powercap/powercap_sys.c new file +699 -0

699 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#3 lore raw

PATCH 3/6 PowerCap: Added to drivers build

In reply to Srinivas Pandruvada

Added changes to Makefile and Kconfig to include in driver build.

---
 drivers/Kconfig  | 2 ++
 drivers/Makefile | 1 +
 2 files changed, 3 insertions(+)
drivers/Kconfig +2 -0
index aa43b91..969e987 100644
@@ -166,4 +166,6 @@ source "drivers/reset/Kconfig"
 
 source "drivers/fmc/Kconfig"
 
+source "drivers/powercap/Kconfig"
+
 endmenu
drivers/Makefile +1 -0
index ab93de8..34c1d55 100644
@@ -152,3 +152,4 @@ obj-$(CONFIG_VME_BUS)		+= vme/
 obj-$(CONFIG_IPACK_BUS)		+= ipack/
 obj-$(CONFIG_NTB)		+= ntb/
 obj-$(CONFIG_FMC)		+= fmc/
+obj-$(CONFIG_POWERCAP)		+= powercap/
Signature · 1 line
1.8.3.1
#4 lore raw

PATCH 4/6 x86/msr: add 64bit _on_cpu access functions

In reply to Srinivas Pandruvada

From: Jacob Pan <[email protected]>

Having 64-bit MSR access methods on given CPU can avoid shifting and simplify MSR content manipulation. We already have other combinations of rdmsrl_xxx and wrmsrl_xxx but missing the _on_cpu version.

---
 arch/x86/include/asm/msr.h | 22 ++++++++++++++++
 arch/x86/lib/msr-smp.c     | 62 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 84 insertions(+)
arch/x86/include/asm/msr.h +22 -0
index cb75028..e139b13 100644
@@ -218,10 +218,14 @@ void msrs_free(struct msr *msrs);
 #ifdef CONFIG_SMP
 int rdmsr_on_cpu(unsigned int cpu, u32 msr_no, u32 *l, u32 *h);
 int wrmsr_on_cpu(unsigned int cpu, u32 msr_no, u32 l, u32 h);
+int rdmsrl_on_cpu(unsigned int cpu, u32 msr_no, u64 *q);
+int wrmsrl_on_cpu(unsigned int cpu, u32 msr_no, u64 q);
 void rdmsr_on_cpus(const struct cpumask *mask, u32 msr_no, struct msr *msrs);
 void wrmsr_on_cpus(const struct cpumask *mask, u32 msr_no, struct msr *msrs);
 int rdmsr_safe_on_cpu(unsigned int cpu, u32 msr_no, u32 *l, u32 *h);
 int wrmsr_safe_on_cpu(unsigned int cpu, u32 msr_no, u32 l, u32 h);
+int rdmsrl_safe_on_cpu(unsigned int cpu, u32 msr_no, u64 *q);
+int wrmsrl_safe_on_cpu(unsigned int cpu, u32 msr_no, u64 q);
 int rdmsr_safe_regs_on_cpu(unsigned int cpu, u32 regs[8]);
 int wrmsr_safe_regs_on_cpu(unsigned int cpu, u32 regs[8]);
 #else  /*  CONFIG_SMP  */
@@ -235,6 +239,16 @@ static inline int wrmsr_on_cpu(unsigned int cpu, u32 msr_no, u32 l, u32 h)
 	wrmsr(msr_no, l, h);
 	return 0;
 }
+static inline int rdmsrl_on_cpu(unsigned int cpu, u32 msr_no, u64 *q)
+{
+	rdmsrl(msr_no, *q);
+	return 0;
+}
+static inline int wrmsrl_on_cpu(unsigned int cpu, u32 msr_no, u64 q)
+{
+	wrmsrl(msr_no, q);
+	return 0;
+}
 static inline void rdmsr_on_cpus(const struct cpumask *m, u32 msr_no,
 				struct msr *msrs)
 {
@@ -254,6 +268,14 @@ static inline int wrmsr_safe_on_cpu(unsigned int cpu, u32 msr_no, u32 l, u32 h)
 {
 	return wrmsr_safe(msr_no, l, h);
 }
+static inline int rdmsrl_safe_on_cpu(unsigned int cpu, u32 msr_no, u64 *q)
+{
+	return rdmsrl_safe(msr_no, q);
+}
+static inline int wrmsrl_safe_on_cpu(unsigned int cpu, u32 msr_no, u64 q)
+{
+	return wrmsrl_safe(msr_no, q);
+}
 static inline int rdmsr_safe_regs_on_cpu(unsigned int cpu, u32 regs[8])
 {
 	return rdmsr_safe_regs(regs);
arch/x86/lib/msr-smp.c +62 -0

80 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#5 lore raw

PATCH 5/6 bitops: Introduce BIT_ULL

In reply to Srinivas Pandruvada

Adding BIT(x) equivalent for unsigned long long type, BIT_ULL(x).

---
 include/linux/bitops.h | 1 +
 1 file changed, 1 insertion(+)
include/linux/bitops.h +1 -0
index a3b6b82..34e9e94 100644
@@ -4,6 +4,7 @@
 
 #ifdef	__KERNEL__
 #define BIT(nr)			(1UL << (nr))
+#define BIT_ULL(nr)		(1ULL << (nr))
 #define BIT_MASK(nr)		(1UL << ((nr) % BITS_PER_LONG))
 #define BIT_WORD(nr)		((nr) / BITS_PER_LONG)
 #define BITS_PER_BYTE		8
Signature · 1 line
1.8.3.1
maintainer
#6 lore raw

Re: [PATCH v1 5/6] bitops: Introduce BIT_ULL

Quoted 15 lines · Srinivas Pandruvada

Adding BIT(x) equivalent for unsigned long long type, BIT_ULL(x).

---
 include/linux/bitops.h | 1 +
 1 file changed, 1 insertion(+)
include/linux/bitops.h +0 -0
index a3b6b82..34e9e94 100644

include/linux/bitops.h line 7

Quoted 4 lines
include/linux/bitops.h +1 -0
@@ -4,6 +4,7 @@
 
 #ifdef	__KERNEL__
 #define BIT(nr)			(1UL << (nr))
+#define BIT_ULL(nr)		(1ULL << (nr))

We already have BIT_64 for that.

Signature · 5 lines
Regards/Gruss,
    Boris.

Sent from a fat crate under my desk. Formatting is fine.
--
#7 lore raw

Re: [PATCH v1 5/6] bitops: Introduce BIT_ULL

Quoted 17 lines · Borislav Petkov
Quoted 16 lines · Srinivas Pandruvada

Adding BIT(x) equivalent for unsigned long long type, BIT_ULL(x).

---
  include/linux/bitops.h | 1 +
  1 file changed, 1 insertion(+)
include/linux/bitops.h +0 -0
index a3b6b82..34e9e94 100644
@@ -4,6 +4,7 @@
 
Quoted 5 lines

include/linux/bitops.h line 7

Quoted 3 lines
include/linux/bitops.h +1 -0
  #ifdef	__KERNEL__
  #define BIT(nr)			(1UL << (nr))
+#define BIT_ULL(nr)		(1ULL << (nr))

We already have BIT_64 for that.

The current definition for BIT_64 is in arch/x86/include/asm/bitops.h. I feel it should be applicable for all architectures and move to some common file.

Thanks,
Srinivas

maintainer
#8 lore raw

Re: [PATCH v1 5/6] bitops: Introduce BIT_ULL

Quoted 3 lines · Srinivas Pandruvada

The current definition for BIT_64 is in arch/x86/include/asm/bitops.h. I feel it should be applicable for all architectures and move to some common file.

Feel free to move it there or change BIT_64 to BIT_ULL or whatever ... just don't add yet another redundant macro.

Thanks.

Signature · 5 lines
Regards/Gruss,
    Boris.

Sent from a fat crate under my desk. Formatting is fine.
--
#9 lore raw

Re: [PATCH v1 5/6] bitops: Introduce BIT_ULL

Quoted 7 lines · Borislav Petkov
Quoted 3 lines · Srinivas Pandruvada

The current definition for BIT_64 is in arch/x86/include/asm/bitops.h. I feel it should be applicable for all architectures and move to some common file.

Feel free to move it there or change BIT_64 to BIT_ULL or whatever ... just don't add yet another redundant macro.

Seems sensible.

Maybe using U32_C/U64_C is better than 1ul and 1ull as it'd work in assembly.

Maybe something like:

Add BIT_ULL/BIT_ULL_MASK/BIT_ULL_WORD
Rename BIT_64 uses to BIT_ULL
Remove BIT_64 from x86 specific location

---

It looks like bitops.h needs
#include <linux/kernel.h>
as it uses DIV_ROUND_UP

 arch/x86/include/asm/bitops.h    |  2 --
 arch/x86/kernel/cpu/mcheck/mce.c |  4 ++--
 drivers/edac/amd64_edac.c        | 10 +++++-----
 drivers/edac/mce_amd.c           |  2 +-
 drivers/edac/mce_amd.h           |  4 ++--
 include/linux/bitops.h           | 13 ++++++++++---
 6 files changed, 20 insertions(+), 15 deletions(-)
arch/x86/include/asm/bitops.h +0 -2
index 41639ce..f0bb112 100644
@@ -23,8 +23,6 @@
 # error "Unexpected BITS_PER_LONG"
 #endif
 
-#define BIT_64(n)			(U64_C(1) << (n))
-
 /*
  * These have to be done with inline assembly: that way the bit-setting
  * is guaranteed to be atomic. All bit operations return 0 if the bit
arch/x86/kernel/cpu/mcheck/mce.c +2 -2
index b3218cd..8074b58 100644
@@ -1551,8 +1551,8 @@ static int __mcheck_cpu_apply_quirks(struct cpuinfo_x86 *c)
 				 rdmsrl(msrs[i], val);
 
 				 /* CntP bit set? */
-				 if (val & BIT_64(62)) {
-					val &= ~BIT_64(62);
+				 if (val & BIT_ULL(62)) {
+					val &= ~BIT_ULL(62);
 					wrmsrl(msrs[i], val);
 				 }
 			 }
drivers/edac/amd64_edac.c +5 -5
index 3c9e4e9..f277053 100644
@@ -1310,7 +1310,7 @@ static u64 f1x_get_norm_dct_addr(struct amd64_pvt *pvt, u8 range,
 		if ((!(dct_sel_base_addr >> 16) ||
 		     dct_sel_base_addr < dhar_base(pvt)) &&
 		    dhar_valid(pvt) &&
-		    (sys_addr >= BIT_64(32)))
+		    (sys_addr >= BIT_ULL(32)))
 			chan_off = hole_off;
 		else
 			chan_off = dct_sel_base_off;
@@ -1324,7 +1324,7 @@ static u64 f1x_get_norm_dct_addr(struct amd64_pvt *pvt, u8 range,
 		 * else
 		 *	remove dram base to normalize to DCT address
 		 */
-		if (dhar_valid(pvt) && (sys_addr >= BIT_64(32)))
+		if (dhar_valid(pvt) && (sys_addr >= BIT_ULL(32)))
 			chan_off = hole_off;
 		else
 			chan_off = dram_base;
@@ -1459,7 +1459,7 @@ static int f1x_match_to_this_node(struct amd64_pvt *pvt, unsigned range,
 
 	if (dhar_valid(pvt) &&
 	    dhar_base(pvt) <= sys_addr &&
-	    sys_addr < BIT_64(32)) {
+	    sys_addr < BIT_ULL(32)) {
 		amd64_warn("Huh? Address is in the MMIO hole: 0x%016llx\n",
 			    sys_addr);
 		return -EINVAL;
@@ -1551,7 +1551,7 @@ static int f15_m30h_match_to_this_node(struct amd64_pvt *pvt, unsigned range,
 
 	if (dhar_valid(pvt) &&
 	    dhar_base(pvt) <= sys_addr &&
-	    sys_addr < BIT_64(32)) {
+	    sys_addr < BIT_ULL(32)) {
 		amd64_warn("Huh? Address is in the MMIO hole: 0x%016llx\n",
 			    sys_addr);
 		return -EINVAL;
@@ -1582,7 +1582,7 @@ static int f15_m30h_match_to_this_node(struct amd64_pvt *pvt, unsigned range,
 	leg_mmio_hole = (u8) (dct_cont_base_reg >> 1 & BIT(0));
 
 	/* Get normalized DCT addr */
-	if (leg_mmio_hole && (sys_addr >= BIT_64(32)))
+	if (leg_mmio_hole && (sys_addr >= BIT_ULL(32)))
 		chan_offset = dhar_offset;
 	else
 		chan_offset = dct_base << 27;
drivers/edac/mce_amd.c +1 -1
index 30f7309..6486270 100644
@@ -395,7 +395,7 @@ static void decode_mc1_mce(struct mce *m)
 		pr_cont("%s TLB %s.\n", LL_MSG(ec),
 			(xec ? "multimatch" : "parity error"));
 	else if (BUS_ERROR(ec)) {
-		bool k8 = (boot_cpu_data.x86 == 0xf && (m->status & BIT_64(58)));
+		bool k8 = (boot_cpu_data.x86 == 0xf && (m->status & BIT_ULL(58)));
 
 		pr_cont("during %s.\n", (k8 ? "system linefill" : "NB data read"));
 	} else if (fam_ops->mc1_mce(ec, xec))
drivers/edac/mce_amd.h +2 -2
index 51b7e3a..f4aa69d 100644
@@ -32,8 +32,8 @@
 #define R4(x)				(((x) >> 4) & 0xf)
 #define R4_MSG(x)			((R4(x) < 9) ?  rrrr_msgs[R4(x)] : "Wrong R4!")
 
-#define MCI_STATUS_DEFERRED		BIT_64(44)
-#define MCI_STATUS_POISON		BIT_64(43)
+#define MCI_STATUS_DEFERRED		BIT_ULL(44)
+#define MCI_STATUS_POISON		BIT_ULL(43)
 
 extern const char * const pp_msgs[];
 
include/linux/bitops.h +10 -3
index a3b6b82..33e6f13 100644
@@ -3,11 +3,18 @@
 #include <asm/types.h>
 
 #ifdef	__KERNEL__
-#define BIT(nr)			(1UL << (nr))
-#define BIT_MASK(nr)		(1UL << ((nr) % BITS_PER_LONG))
-#define BIT_WORD(nr)		((nr) / BITS_PER_LONG)
+
 #define BITS_PER_BYTE		8
 #define BITS_TO_LONGS(nr)	DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
+
+#define BIT(nr)			(U32_C(1) << (nr))
+#define BIT_MASK(nr)		(U32_C(1) << ((nr) % BITS_PER_LONG))
+#define BIT_WORD(nr)		((nr) / BITS_PER_LONG)
+
+#define BIT_ULL(nr)		(U64_C(1) << (nr))
+#define BIT_ULL_MASK(nr)	(U64_C(1) << ((nr) % BITS_PER_LONG))
+#define BIT_ULL_WORD(nr)	((nr) / BITS_PER_LONG)
+
 #endif
 
 extern unsigned int __sw_hweight8(unsigned int w);
#10 lore raw

Re: [PATCH v1 5/6] bitops: Introduce BIT_ULL

Quoted 9 lines · Joe Perches
Quoted 6 lines · Borislav Petkov
Quoted 3 lines · Srinivas Pandruvada

The current definition for BIT_64 is in arch/x86/include/asm/bitops.h. I feel it should be applicable for all architectures and move to some common file.

Feel free to move it there or change BIT_64 to BIT_ULL or whatever ... just don't add yet another redundant macro.

Seems sensible.

Quoted 8 lines

Maybe using U32_C/U64_C is better than 1ul and 1ull as it'd work in assembly.

Maybe something like:

Add BIT_ULL/BIT_ULL_MASK/BIT_ULL_WORD
Rename BIT_64 uses to BIT_ULL
Remove BIT_64 from x86 specific location

Let's do in two steps:
- In the next patcheset I will add BIT_ULL_MASK and BIT_ULL_WORD in addition to BIT_ULL
- Once this series is approved, submit a separate patch to change BIT_64 to BIT_ULL

Quoted 152 lines

---

It looks like bitops.h needs
#include <linux/kernel.h>
as it uses DIV_ROUND_UP

  arch/x86/include/asm/bitops.h    |  2 --
  arch/x86/kernel/cpu/mcheck/mce.c |  4 ++--
  drivers/edac/amd64_edac.c        | 10 +++++-----
  drivers/edac/mce_amd.c           |  2 +-
  drivers/edac/mce_amd.h           |  4 ++--
  include/linux/bitops.h           | 13 ++++++++++---
  6 files changed, 20 insertions(+), 15 deletions(-)
arch/x86/include/asm/bitops.h +0 -2
index 41639ce..f0bb112 100644
@@ -23,8 +23,6 @@
  # error "Unexpected BITS_PER_LONG"
  #endif
 
-#define BIT_64(n)			(U64_C(1) << (n))
-
  /*
   * These have to be done with inline assembly: that way the bit-setting
   * is guaranteed to be atomic. All bit operations return 0 if the bit
arch/x86/kernel/cpu/mcheck/mce.c +2 -2
index b3218cd..8074b58 100644
@@ -1551,8 +1551,8 @@ static int __mcheck_cpu_apply_quirks(struct cpuinfo_x86 *c)
  				 rdmsrl(msrs[i], val);
 
  				 /* CntP bit set? */
-				 if (val & BIT_64(62)) {
-					val &= ~BIT_64(62);
+				 if (val & BIT_ULL(62)) {
+					val &= ~BIT_ULL(62);
  					wrmsrl(msrs[i], val);
  				 }
  			 }
drivers/edac/amd64_edac.c +5 -5
index 3c9e4e9..f277053 100644
@@ -1310,7 +1310,7 @@ static u64 f1x_get_norm_dct_addr(struct amd64_pvt *pvt, u8 range,
  		if ((!(dct_sel_base_addr >> 16) ||
  		     dct_sel_base_addr < dhar_base(pvt)) &&
  		    dhar_valid(pvt) &&
-		    (sys_addr >= BIT_64(32)))
+		    (sys_addr >= BIT_ULL(32)))
  			chan_off = hole_off;
  		else
  			chan_off = dct_sel_base_off;
@@ -1324,7 +1324,7 @@ static u64 f1x_get_norm_dct_addr(struct amd64_pvt *pvt, u8 range,
  		 * else
  		 *	remove dram base to normalize to DCT address
  		 */
-		if (dhar_valid(pvt) && (sys_addr >= BIT_64(32)))
+		if (dhar_valid(pvt) && (sys_addr >= BIT_ULL(32)))
  			chan_off = hole_off;
  		else
  			chan_off = dram_base;
@@ -1459,7 +1459,7 @@ static int f1x_match_to_this_node(struct amd64_pvt *pvt, unsigned range,
 
  	if (dhar_valid(pvt) &&
  	    dhar_base(pvt) <= sys_addr &&
-	    sys_addr < BIT_64(32)) {
+	    sys_addr < BIT_ULL(32)) {
  		amd64_warn("Huh? Address is in the MMIO hole: 0x%016llx\n",
  			    sys_addr);
  		return -EINVAL;
@@ -1551,7 +1551,7 @@ static int f15_m30h_match_to_this_node(struct amd64_pvt *pvt, unsigned range,
 
  	if (dhar_valid(pvt) &&
  	    dhar_base(pvt) <= sys_addr &&
-	    sys_addr < BIT_64(32)) {
+	    sys_addr < BIT_ULL(32)) {
  		amd64_warn("Huh? Address is in the MMIO hole: 0x%016llx\n",
  			    sys_addr);
  		return -EINVAL;
@@ -1582,7 +1582,7 @@ static int f15_m30h_match_to_this_node(struct amd64_pvt *pvt, unsigned range,
  	leg_mmio_hole = (u8) (dct_cont_base_reg >> 1 & BIT(0));
 
  	/* Get normalized DCT addr */
-	if (leg_mmio_hole && (sys_addr >= BIT_64(32)))
+	if (leg_mmio_hole && (sys_addr >= BIT_ULL(32)))
  		chan_offset = dhar_offset;
  	else
  		chan_offset = dct_base << 27;
drivers/edac/mce_amd.c +1 -1
index 30f7309..6486270 100644
@@ -395,7 +395,7 @@ static void decode_mc1_mce(struct mce *m)
  		pr_cont("%s TLB %s.\n", LL_MSG(ec),
  			(xec ? "multimatch" : "parity error"));
  	else if (BUS_ERROR(ec)) {
-		bool k8 = (boot_cpu_data.x86 == 0xf && (m->status & BIT_64(58)));
+		bool k8 = (boot_cpu_data.x86 == 0xf && (m->status & BIT_ULL(58)));
 
  		pr_cont("during %s.\n", (k8 ? "system linefill" : "NB data read"));
  	} else if (fam_ops->mc1_mce(ec, xec))
drivers/edac/mce_amd.h +2 -2
index 51b7e3a..f4aa69d 100644
@@ -32,8 +32,8 @@
  #define R4(x)				(((x) >> 4) & 0xf)
  #define R4_MSG(x)			((R4(x) < 9) ?  rrrr_msgs[R4(x)] : "Wrong R4!")
 
-#define MCI_STATUS_DEFERRED		BIT_64(44)
-#define MCI_STATUS_POISON		BIT_64(43)
+#define MCI_STATUS_DEFERRED		BIT_ULL(44)
+#define MCI_STATUS_POISON		BIT_ULL(43)
 
  extern const char * const pp_msgs[];
 
include/linux/bitops.h +10 -4
index a3b6b82..33e6f13 100644
@@ -3,11 +3,18 @@
  #include <asm/types.h>
 
  #ifdef	__KERNEL__
-#define BIT(nr)			(1UL << (nr))
-#define BIT_MASK(nr)		(1UL << ((nr) % BITS_PER_LONG))
-#define BIT_WORD(nr)		((nr) / BITS_PER_LONG)
+
  #define BITS_PER_BYTE		8
  #define BITS_TO_LONGS(nr)	DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
+
+#define BIT(nr)			(U32_C(1) << (nr))
+#define BIT_MASK(nr)		(U32_C(1) << ((nr) % BITS_PER_LONG))
+#define BIT_WORD(nr)		((nr) / BITS_PER_LONG)
+
+#define BIT_ULL(nr)		(U64_C(1) << (nr))
+#define BIT_ULL_MASK(nr)	(U64_C(1) << ((nr) % BITS_PER_LONG))
+#define BIT_ULL_WORD(nr)	((nr) / BITS_PER_LONG)
+
  #endif
 
  extern unsigned int __sw_hweight8(unsigned int w);
 
 
--

To unsubscribe from this list: send the line "unsubscribe linux-pm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#11 lore raw

Re: [PATCH v1 5/6] bitops: Introduce BIT_ULL

Quoted 5 lines · Srinivas Pandruvada

Let's do in two steps:
- In the next patcheset I will add BIT_ULL_MASK and BIT_ULL_WORD in addition to BIT_ULL
- Once this series is approved, submit a separate patch to change BIT_64 to BIT_ULL

Fine by me.

maintainer
#12 lore raw

Re: [PATCH v1 5/6] bitops: Introduce BIT_ULL

Quoted 9 lines · Joe Perches
Quoted 5 lines · Srinivas Pandruvada

Let's do in two steps:
- In the next patcheset I will add BIT_ULL_MASK and BIT_ULL_WORD in addition to BIT_ULL
- Once this series is approved, submit a separate patch to change BIT_64 to BIT_ULL

Fine by me.

+1.

Signature · 5 lines
Regards/Gruss,
    Boris.

Sent from a fat crate under my desk. Formatting is fine.
--
#13 lore raw

PATCH 6/6 Introduce Intel RAPL power capping driver

In reply to Srinivas Pandruvada

From: Jacob Pan <[email protected]>

The Intel Running Average Power Limit(RAPL) technology provides platform software with the ability to monitor, control, and get notifications on power usage.
This feature is present in all Sandy Bridge and later Intel processors. Newer models allow more fine grained controls to be applied. In RAPL, power control is divided into domains, which include package, DRAM controller, CPU core (Power Plane 0), graphics uncore (power plane 1), etc.

The purpose of this driver is to expose the RAPL settings to userspace. Overall, RAPL fits in the new powercap class driver in
that platform level power capping controls are exposed via this generic interface.

This driver is based on an earlier patch from Zhang Rui.
https://lkml.org/lkml/2011/5/26/93

However, while the previous work was mainly focused on thermal monitoring the focus here is on the usability from user space perspective.

---
 drivers/powercap/Kconfig      |   12 +
 drivers/powercap/Makefile     |    1 +
 drivers/powercap/intel_rapl.c | 1395 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 1408 insertions(+)
 create mode 100644 drivers/powercap/intel_rapl.c
drivers/powercap/Kconfig +12 -0
index a37055e..dd6a4bf 100644
@@ -15,5 +15,17 @@ menuconfig POWERCAP
 
 if POWERCAP
 # Client driver configurations go here.
+config INTEL_RAPL
+	tristate "Intel RAPL Support"
+	default n
+	---help---
+	  This enables support for the Intel Running Average Power Limit (RAPL)
+	  technology which allows power limits to be enforced and monitored on
+	  modern Intel processors (Sandy Bridge and later).
+
+	  In RAPL, the platform level settings are divided into domains for
+	  fine grained control. These domains include processor package, DRAM
+	  controller, CPU core (Power Plance 0), graphics uncore (Power Plane
+	  1), etc.
 
 endif
drivers/powercap/Makefile +1 -0
index 6defbc8..0a21ef3 100644
@@ -1 +1,2 @@
 obj-$(CONFIG_POWERCAP)	+= powercap_sys.o
+obj-$(CONFIG_INTEL_RAPL) += intel_rapl.o
drivers/powercap/intel_rapl.c new file +1395 -0

1,395 lines not on this page · raw message

Signature · 1 line
1.8.3.1