Skip to contentSkip to conversation

platform/x86/intel/uncore-freq: Enhance HW interface

PATCH In review Srinivas Pandruvada 2 participants 6 messages Feb 4, 2022 – Feb 17, 2022

Subsystems (2)
lore
Share & tools
lore

Srinivas Pandruvada

author maintainer
#0 lore raw

cover platform/x86/intel/uncore-freq: Enhance HW interface

The uncore frequency scaling is getting used by more customers to either have a deterministic performance or control power consumption. The uncore frequency scaling depends on non architecture MSRs, format of those MSR can be different on different generations of CPUs. This series prepares for easy addition of new HW interface.

There are no functional changes done except adding a new addition to read uncore frequency.

- The first patch creates a separate folder for uncore-freq.
- The second patch uses sysfs groups to create attributes.
- The third patch adds capability to read current uncore frequency.
- The fourth patch splits common and enumeration part. The enumeration part will be specific to each HW interface.

Srinivas Pandruvada (4):
platform/x86/intel/uncore-freq: Move to uncore-frequency folder platform/x86/intel/uncore-freq: Use sysfs API to create attributes platform/x86/intel/uncore-freq: Display uncore current frequency platform/x86/intel-uncore-freq: Split common and enumeration part

 drivers/platform/x86/intel/Kconfig            |  14 +-
 drivers/platform/x86/intel/Makefile           |   4 +-
 drivers/platform/x86/intel/uncore-frequency.c | 452 ------------------
 .../x86/intel/uncore-frequency/Kconfig        |  21 +
 .../x86/intel/uncore-frequency/Makefile       |   9 +
 .../uncore-frequency-common.c                 | 252 ++++++++++
 .../uncore-frequency-common.h                 |  62 +++
 .../intel/uncore-frequency/uncore-frequency.c | 272 +++++++++++
 8 files changed, 620 insertions(+), 466 deletions(-)
 delete mode 100644 drivers/platform/x86/intel/uncore-frequency.c
 create mode 100644 drivers/platform/x86/intel/uncore-frequency/Kconfig
 create mode 100644 drivers/platform/x86/intel/uncore-frequency/Makefile
 create mode 100644 drivers/platform/x86/intel/uncore-frequency/uncore-frequency-common.c
 create mode 100644 drivers/platform/x86/intel/uncore-frequency/uncore-frequency-common.h
 create mode 100644 drivers/platform/x86/intel/uncore-frequency/uncore-frequency.c
Signature · 1 line
2.31.1
author maintainer
#1 lore raw

PATCH 1/4 platform/x86/intel/uncore-freq: Move to uncore-frequency folder

From: Srinivas Pandruvada <[email protected]>

Move the current driver from platform/x86/intel/uncore-frequency.c to platform/x86/intel/uncore-frequency/uncore-frequency.c.

No functional changes are expected.

---
 drivers/platform/x86/intel/Kconfig            | 14 ++-----------
 drivers/platform/x86/intel/Makefile           |  4 ++--
 .../x86/intel/uncore-frequency/Kconfig        | 21 +++++++++++++++++++
 .../x86/intel/uncore-frequency/Makefile       |  7 +++++++
 .../{ => uncore-frequency}/uncore-frequency.c |  0
 5 files changed, 32 insertions(+), 14 deletions(-)
 create mode 100644 drivers/platform/x86/intel/uncore-frequency/Kconfig
 create mode 100644 drivers/platform/x86/intel/uncore-frequency/Makefile
 rename drivers/platform/x86/intel/{ => uncore-frequency}/uncore-frequency.c (100%)
drivers/platform/x86/intel/Kconfig +2 -12
index 8e65086bb6c8..ff754b60076e 100644
@@ -12,6 +12,8 @@ source "drivers/platform/x86/intel/pmt/Kconfig"
 source "drivers/platform/x86/intel/speed_select_if/Kconfig"
 source "drivers/platform/x86/intel/telemetry/Kconfig"
 source "drivers/platform/x86/intel/wmi/Kconfig"
+source "drivers/platform/x86/intel/uncore-frequency/Kconfig"
+
 
 config INTEL_HID_EVENT
 	tristate "Intel HID Event"
@@ -159,18 +161,6 @@ config INTEL_TURBO_MAX_3
 	  This driver is only required when the system is not using Hardware
 	  P-States (HWP). In HWP mode, priority can be read from ACPI tables.
 
-config INTEL_UNCORE_FREQ_CONTROL
-	tristate "Intel Uncore frequency control driver"
-	depends on X86_64
-	help
-	  This driver allows control of Uncore frequency limits on
-	  supported server platforms.
-
-	  Uncore frequency controls RING/LLC (last-level cache) clocks.
-
-	  To compile this driver as a module, choose M here: the module
-	  will be called intel-uncore-frequency.
-
 config INTEL_VSEC
 	tristate "Intel Vendor Specific Extended Capabilities Driver"
 	depends on PCI
drivers/platform/x86/intel/Makefile +2 -2
index 35f2066578b2..1d5ada7b4d32 100644
@@ -13,6 +13,8 @@ obj-$(CONFIG_INTEL_PMT_CLASS)		+= pmt/
 obj-$(CONFIG_INTEL_SPEED_SELECT_INTERFACE) += speed_select_if/
 obj-$(CONFIG_INTEL_TELEMETRY)		+= telemetry/
 obj-$(CONFIG_INTEL_WMI)			+= wmi/
+obj-$(CONFIG_INTEL_UNCORE_FREQ_CONTROL)	+= uncore-frequency/
+
 
 # Intel input drivers
 intel-hid-y				:= hid.o
@@ -48,5 +50,3 @@ intel-smartconnect-y			:= smartconnect.o
 obj-$(CONFIG_INTEL_SMARTCONNECT)	+= intel-smartconnect.o
 intel_turbo_max_3-y			:= turbo_max_3.o
 obj-$(CONFIG_INTEL_TURBO_MAX_3)		+= intel_turbo_max_3.o
-intel-uncore-frequency-y		:= uncore-frequency.o
-obj-$(CONFIG_INTEL_UNCORE_FREQ_CONTROL)	+= intel-uncore-frequency.o
drivers/platform/x86/intel/uncore-frequency/Kconfig new file +21 -0
new file mode 100644
index 000000000000..21b209124916
@@ -0,0 +1,21 @@
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# Uncore Frquency control drivers
+#
+
+menu "Intel Uncore Frequency Control"
+	depends on X86_64 || COMPILE_TEST
+
+config INTEL_UNCORE_FREQ_CONTROL
+	tristate "Intel Uncore frequency control driver"
+	depends on X86_64
+	help
+	  This driver allows control of Uncore frequency limits on
+	  supported server platforms.
+
+	  Uncore frequency controls RING/LLC (last-level cache) clocks.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called intel-uncore-frequency.
+
+endmenu
drivers/platform/x86/intel/uncore-frequency/Makefile new file +7 -0
new file mode 100644
index 000000000000..e22186a480e2
@@ -0,0 +1,7 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Makefile for linux/drivers/platform/x86/intel/uncore-frequency
+#
+
+obj-$(CONFIG_INTEL_UNCORE_FREQ_CONTROL)	+= intel-uncore-frequency.o
+intel-uncore-frequency-y		:= uncore-frequency.o
drivers/platform/x86/intel/uncore-frequency/uncore-frequency.c renamed from drivers/platform/x86/intel/uncore-frequency.c +0 -0
similarity index 100%
rename from drivers/platform/x86/intel/uncore-frequency.c
rename to drivers/platform/x86/intel/uncore-frequency/uncore-frequency.c
Signature · 1 line
2.31.1
author maintainer
#2 lore raw

PATCH 2/4 platform/x86/intel/uncore-freq: Use sysfs API to create attributes

In reply to Srinivas Pandruvada

From: Srinivas Pandruvada <[email protected]>

Use of sysfs API is always preferable over using kobject calls to create attributes. Remove usage of kobject_init_and_add() and use sysfs_create_group(). To create relationship between sysfs attribute and uncore instance use device_attribute*, which is defined per uncore instance.

To create uniform locking for both read and write attributes take lock in the sysfs callbacks, not in the actual functions where the MSRs are read or updated.

No functional changes are expected.

---
 .../intel/uncore-frequency/uncore-frequency.c | 225 +++++++++---------
 1 file changed, 113 insertions(+), 112 deletions(-)
drivers/platform/x86/intel/uncore-frequency/uncore-frequency.c +113 -112
index 4cd8254f2e40..35b00608a81d 100644
@@ -1,7 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0
 /*
  * Intel Uncore Frequency Setting
- * Copyright (c) 2019, Intel Corporation.
+ * Copyright (c) 2022, Intel Corporation.
  * All rights reserved.
  *
  * Provide interface to set MSR 620 at a granularity of per die. On CPU online,
@@ -32,22 +32,37 @@
  * @initial_max_freq_khz: Sampled maximum uncore frequency at driver init
  * @control_cpu:	Designated CPU for a die to read/write
  * @valid:		Mark the data valid/invalid
+ * @package_id:	Package id for this instance
+ * @die_id:		Die id for this instance
+ * @name:		Sysfs entry name for this instance
+ * @uncore_attr_group:	Attribute group storage
+ * @max_freq_khz_dev_attr: Storage for device attribute max_freq_khz
+ * @mix_freq_khz_dev_attr: Storage for device attribute min_freq_khz
+ * @initial_max_freq_khz_dev_attr: Storage for device attribute initial_max_freq_khz
+ * @initial_min_freq_khz_dev_attr: Storage for device attribute initial_min_freq_khz
+ * @uncore_attrs:	Attribute storage for group creation
  *
  * This structure is used to encapsulate all data related to uncore sysfs
  * settings for a die/package.
  */
 struct uncore_data {
-	struct kobject kobj;
-	struct completion kobj_unregister;
 	u64 stored_uncore_data;
 	u32 initial_min_freq_khz;
 	u32 initial_max_freq_khz;
 	int control_cpu;
 	bool valid;
+	int package_id;
+	int die_id;
+	char name[32];
+
+	struct attribute_group uncore_attr_group;
+	struct device_attribute max_freq_khz_dev_attr;
+	struct device_attribute min_freq_khz_dev_attr;
+	struct device_attribute initial_max_freq_khz_dev_attr;
+	struct device_attribute initial_min_freq_khz_dev_attr;
+	struct attribute *uncore_attrs[5];
 };
 
-#define to_uncore_data(a) container_of(a, struct uncore_data, kobj)
-
 /* Max instances for uncore data, one for each die */
 static int uncore_max_entries __read_mostly;
 /* Storage for uncore data for all instances */
@@ -61,36 +76,6 @@ static enum cpuhp_state uncore_hp_state __read_mostly;
 /* Mutex to control all mutual exclusions */
 static DEFINE_MUTEX(uncore_lock);
 
-struct uncore_attr {
-	struct attribute attr;
-	ssize_t (*show)(struct kobject *kobj,
-			struct attribute *attr, char *buf);
-	ssize_t (*store)(struct kobject *kobj,
-			 struct attribute *attr, const char *c, ssize_t count);
-};
-
-#define define_one_uncore_ro(_name) \
-static struct uncore_attr _name = \
-__ATTR(_name, 0444, show_##_name, NULL)
-
-#define define_one_uncore_rw(_name) \
-static struct uncore_attr _name = \
-__ATTR(_name, 0644, show_##_name, store_##_name)
-
-#define show_uncore_data(member_name)					\
-	static ssize_t show_##member_name(struct kobject *kobj,         \
-					  struct attribute *attr,	\
-					  char *buf)			\
-	{                                                               \
-		struct uncore_data *data = to_uncore_data(kobj);	\
-		return scnprintf(buf, PAGE_SIZE, "%u\n",		\
-				 data->member_name);			\
-	}								\
-	define_one_uncore_ro(member_name)
-
-show_uncore_data(initial_min_freq_khz);
-show_uncore_data(initial_max_freq_khz);
-
 /* Common function to read MSR 0x620 and read min/max */
 static int uncore_read_ratio(struct uncore_data *data, unsigned int *min,
 			     unsigned int *max)
@@ -118,22 +103,16 @@ static int uncore_write_ratio(struct uncore_data *data, unsigned int input,
 	int ret;
 	u64 cap;
 
-	mutex_lock(&uncore_lock);
-
-	if (data->control_cpu < 0) {
-		ret = -ENXIO;
-		goto finish_write;
-	}
+	if (data->control_cpu < 0)
+		return -ENXIO;
 
 	input /= UNCORE_FREQ_KHZ_MULTIPLIER;
-	if (!input || input > 0x7F) {
-		ret = -EINVAL;
-		goto finish_write;
-	}
+	if (!input || input > 0x7F)
+		return -EINVAL;
 
 	ret = rdmsrl_on_cpu(data->control_cpu, MSR_UNCORE_RATIO_LIMIT, &cap);
 	if (ret)
-		goto finish_write;
+		return ret;
 
 	if (set_max) {
 		cap &= ~0x7F;
@@ -145,37 +124,16 @@ static int uncore_write_ratio(struct uncore_data *data, unsigned int input,
 
 	ret = wrmsrl_on_cpu(data->control_cpu, MSR_UNCORE_RATIO_LIMIT, cap);
 	if (ret)
-		goto finish_write;
+		return ret;
 
 	data->stored_uncore_data = cap;
 
-finish_write:
-	mutex_unlock(&uncore_lock);
-
-	return ret;
-}
-
-static ssize_t store_min_max_freq_khz(struct kobject *kobj,
-				      struct attribute *attr,
-				      const char *buf, ssize_t count,
-				      int min_max)
-{
-	struct uncore_data *data = to_uncore_data(kobj);
-	unsigned int input;
-
-	if (kstrtouint(buf, 10, &input))
-		return -EINVAL;
-
-	uncore_write_ratio(data, input, min_max);
-
-	return count;
+	return 0;
 }
 
-static ssize_t show_min_max_freq_khz(struct kobject *kobj,
-				     struct attribute *attr,
+static ssize_t show_min_max_freq_khz(struct uncore_data *data,
 				     char *buf, int min_max)
 {
-	struct uncore_data *data = to_uncore_data(kobj);
 	unsigned int min, max;
 	int ret;
 
@@ -191,22 +149,40 @@ static ssize_t show_min_max_freq_khz(struct kobject *kobj,
 	return sprintf(buf, "%u\n", min);
 }
 
+static ssize_t store_min_max_freq_khz(struct uncore_data *data,
+				      const char *buf, ssize_t count,
+				      int min_max)
+{
+	unsigned int input;
+
+	if (kstrtouint(buf, 10, &input))
+		return -EINVAL;
+
+	mutex_lock(&uncore_lock);
+	uncore_write_ratio(data, input, min_max);
+	mutex_unlock(&uncore_lock);
+
+	return count;
+}
+
 #define store_uncore_min_max(name, min_max)				\
-	static ssize_t store_##name(struct kobject *kobj,		\
-				    struct attribute *attr,		\
-				    const char *buf, ssize_t count)	\
-	{                                                               \
+	static ssize_t store_##name(struct device *dev,		\
+				    struct device_attribute *attr,	\
+				    const char *buf, size_t count)	\
+	{								\
+		struct uncore_data *data = container_of(attr, struct uncore_data, name##_dev_attr);\
 									\
-		return store_min_max_freq_khz(kobj, attr, buf, count,	\
-					      min_max);			\
+		return store_min_max_freq_khz(data, buf, count,	\
+					      min_max);		\
 	}
 
 #define show_uncore_min_max(name, min_max)				\
-	static ssize_t show_##name(struct kobject *kobj,		\
-				   struct attribute *attr, char *buf)	\
+	static ssize_t show_##name(struct device *dev,		\
+				   struct device_attribute *attr, char *buf)\
 	{                                                               \
+		struct uncore_data *data = container_of(attr, struct uncore_data, name##_dev_attr);\
 									\
-		return show_min_max_freq_khz(kobj, attr, buf, min_max); \
+		return show_min_max_freq_khz(data, buf, min_max);	\
 	}
 
 store_uncore_min_max(min_freq_khz, 0);
@@ -215,30 +191,64 @@ store_uncore_min_max(max_freq_khz, 1);
 show_uncore_min_max(min_freq_khz, 0);
 show_uncore_min_max(max_freq_khz, 1);
 
-define_one_uncore_rw(min_freq_khz);
-define_one_uncore_rw(max_freq_khz);
+#define show_uncore_data(member_name)					\
+	static ssize_t show_##member_name(struct device *dev,	\
+					  struct device_attribute *attr, char *buf)\
+	{                                                               \
+		struct uncore_data *data = container_of(attr, struct uncore_data,\
+							  member_name##_dev_attr);\
+									\
+		return scnprintf(buf, PAGE_SIZE, "%u\n",		\
+				 data->member_name);			\
+	}								\
 
-static struct attribute *uncore_attrs[] = {
-	&initial_min_freq_khz.attr,
-	&initial_max_freq_khz.attr,
-	&max_freq_khz.attr,
-	&min_freq_khz.attr,
-	NULL
-};
-ATTRIBUTE_GROUPS(uncore);
+show_uncore_data(initial_min_freq_khz);
+show_uncore_data(initial_max_freq_khz);
 
-static void uncore_sysfs_entry_release(struct kobject *kobj)
+#define init_attribute_rw(_name)					\
+	do {								\
+		sysfs_attr_init(&data->_name##_dev_attr.attr);	\
+		data->_name##_dev_attr.show = show_##_name;		\
+		data->_name##_dev_attr.store = store_##_name;		\
+		data->_name##_dev_attr.attr.name = #_name;		\
+		data->_name##_dev_attr.attr.mode = 0644;		\
+	} while (0)
+
+#define init_attribute_ro(_name)					\
+	do {								\
+		sysfs_attr_init(&data->_name##_dev_attr.attr);	\
+		data->_name##_dev_attr.show = show_##_name;		\
+		data->_name##_dev_attr.store = NULL;			\
+		data->_name##_dev_attr.attr.name = #_name;		\
+		data->_name##_dev_attr.attr.mode = 0444;		\
+	} while (0)
+
+static int create_attr_group(struct uncore_data *data, char *name)
 {
-	struct uncore_data *data = to_uncore_data(kobj);
+	int ret, index = 0;
+
+	init_attribute_rw(max_freq_khz);
+	init_attribute_rw(min_freq_khz);
+	init_attribute_ro(initial_min_freq_khz);
+	init_attribute_ro(initial_max_freq_khz);
+
+	data->uncore_attrs[index++] = &data->max_freq_khz_dev_attr.attr;
+	data->uncore_attrs[index++] = &data->min_freq_khz_dev_attr.attr;
+	data->uncore_attrs[index++] = &data->initial_min_freq_khz_dev_attr.attr;
+	data->uncore_attrs[index++] = &data->initial_max_freq_khz_dev_attr.attr;
+	data->uncore_attrs[index] = NULL;
+
+	data->uncore_attr_group.name = name;
+	data->uncore_attr_group.attrs = data->uncore_attrs;
+	ret = sysfs_create_group(uncore_root_kobj, &data->uncore_attr_group);
 
-	complete(&data->kobj_unregister);
+	return ret;
 }
 
-static struct kobj_type uncore_ktype = {
-	.release = uncore_sysfs_entry_release,
-	.sysfs_ops = &kobj_sysfs_ops,
-	.default_groups = uncore_groups,
-};
+static void delete_attr_group(struct uncore_data *data, char *name)
+{
+	sysfs_remove_group(uncore_root_kobj, &data->uncore_attr_group);
+}
 
 /* Caller provides protection */
 static struct uncore_data *uncore_get_instance(unsigned int cpu)
@@ -266,21 +276,17 @@ static void uncore_add_die_entry(int cpu)
 		/* control cpu changed */
 		data->control_cpu = cpu;
 	} else {
-		char str[64];
 		int ret;
 
 		memset(data, 0, sizeof(*data));
-		sprintf(str, "package_%02d_die_%02d",
+		sprintf(data->name, "package_%02d_die_%02d",
 			topology_physical_package_id(cpu),
 			topology_die_id(cpu));
 
 		uncore_read_ratio(data, &data->initial_min_freq_khz,
 				  &data->initial_max_freq_khz);
 
-		init_completion(&data->kobj_unregister);
-
-		ret = kobject_init_and_add(&data->kobj, &uncore_ktype,
-					   uncore_root_kobj, str);
+		ret = create_attr_group(data, data->name);
 		if (!ret) {
 			data->control_cpu = cpu;
 			data->valid = true;
@@ -296,8 +302,11 @@ static void uncore_remove_die_entry(int cpu)
 
 	mutex_lock(&uncore_lock);
 	data = uncore_get_instance(cpu);
-	if (data)
+	if (data) {
+		delete_attr_group(data, data->name);
 		data->control_cpu = -1;
+		data->valid = false;
+	}
 	mutex_unlock(&uncore_lock);
 }
 
@@ -433,16 +442,8 @@ module_init(intel_uncore_init)
 
 static void __exit intel_uncore_exit(void)
 {
-	int i;
-
 	unregister_pm_notifier(&uncore_pm_nb);
 	cpuhp_remove_state(uncore_hp_state);
-	for (i = 0; i < uncore_max_entries; ++i) {
-		if (uncore_instances[i].valid) {
-			kobject_put(&uncore_instances[i].kobj);
-			wait_for_completion(&uncore_instances[i].kobj_unregister);
-		}
-	}
 	kobject_put(uncore_root_kobj);
 	kfree(uncore_instances);
 }
Signature · 1 line
2.31.1
author maintainer
#3 lore raw

PATCH 3/4 platform/x86/intel/uncore-freq: Display uncore current frequency

In reply to Srinivas Pandruvada

From: Srinivas Pandruvada <[email protected]>

Add a new sysfs attribute "current_freq_khz" to display current uncore frequency. This value is read from MSR 0x621.

Root user permission is required to read uncore current frequency.

---
 .../intel/uncore-frequency/uncore-frequency.c | 71 ++++++++++++++++---
 1 file changed, 62 insertions(+), 9 deletions(-)
drivers/platform/x86/intel/uncore-frequency/uncore-frequency.c +62 -9
index 35b00608a81d..f5e980163911 100644
@@ -22,6 +22,7 @@
 #include <asm/intel-family.h>
 
 #define MSR_UNCORE_RATIO_LIMIT			0x620
+#define MSR_UNCORE_PERF_STATUS			0x621
 #define UNCORE_FREQ_KHZ_MULTIPLIER		100000
 
 /**
@@ -40,6 +41,7 @@
  * @mix_freq_khz_dev_attr: Storage for device attribute min_freq_khz
  * @initial_max_freq_khz_dev_attr: Storage for device attribute initial_max_freq_khz
  * @initial_min_freq_khz_dev_attr: Storage for device attribute initial_min_freq_khz
+ * @current_freq_khz_dev_attr: Storage for device attribute current_freq_khz
  * @uncore_attrs:	Attribute storage for group creation
  *
  * This structure is used to encapsulate all data related to uncore sysfs
@@ -60,7 +62,8 @@ struct uncore_data {
 	struct device_attribute min_freq_khz_dev_attr;
 	struct device_attribute initial_max_freq_khz_dev_attr;
 	struct device_attribute initial_min_freq_khz_dev_attr;
-	struct attribute *uncore_attrs[5];
+	struct device_attribute current_freq_khz_dev_attr;
+	struct attribute *uncore_attrs[6];
 };
 
 /* Max instances for uncore data, one for each die */
@@ -131,22 +134,32 @@ static int uncore_write_ratio(struct uncore_data *data, unsigned int input,
 	return 0;
 }
 
-static ssize_t show_min_max_freq_khz(struct uncore_data *data,
-				     char *buf, int min_max)
+static int uncore_read_freq(struct uncore_data *data, unsigned int *freq)
 {
-	unsigned int min, max;
+	u64 ratio;
+	int ret;
+
+	ret = rdmsrl_on_cpu(data->control_cpu, MSR_UNCORE_PERF_STATUS, &ratio);
+	if (ret)
+		return ret;
+
+	*freq = (ratio & 0x7F) * UNCORE_FREQ_KHZ_MULTIPLIER;
+
+	return 0;
+}
+
+static ssize_t show_perf_status_freq_khz(struct uncore_data *data, char *buf)
+{
+	unsigned int freq;
 	int ret;
 
 	mutex_lock(&uncore_lock);
-	ret = uncore_read_ratio(data, &min, &max);
+	ret = uncore_read_freq(data, &freq);
 	mutex_unlock(&uncore_lock);
 	if (ret)
 		return ret;
 
-	if (min_max)
-		return sprintf(buf, "%u\n", max);
-
-	return sprintf(buf, "%u\n", min);
+	return sprintf(buf, "%u\n", freq);
 }
 
 static ssize_t store_min_max_freq_khz(struct uncore_data *data,
@@ -165,6 +178,24 @@ static ssize_t store_min_max_freq_khz(struct uncore_data *data,
 	return count;
 }
 
+static ssize_t show_min_max_freq_khz(struct uncore_data *data,
+				     char *buf, int min_max)
+{
+	unsigned int min, max;
+	int ret;
+
+	mutex_lock(&uncore_lock);
+	ret = uncore_read_ratio(data, &min, &max);
+	mutex_unlock(&uncore_lock);
+	if (ret)
+		return ret;
+
+	if (min_max)
+		return sprintf(buf, "%u\n", max);
+
+	return sprintf(buf, "%u\n", min);
+}
+
 #define store_uncore_min_max(name, min_max)				\
 	static ssize_t store_##name(struct device *dev,		\
 				    struct device_attribute *attr,	\
@@ -185,12 +216,23 @@ static ssize_t store_min_max_freq_khz(struct uncore_data *data,
 		return show_min_max_freq_khz(data, buf, min_max);	\
 	}
 
+#define show_uncore_perf_status(name)					\
+	static ssize_t show_##name(struct device *dev,		\
+				   struct device_attribute *attr, char *buf)\
+	{                                                               \
+		struct uncore_data *data = container_of(attr, struct uncore_data, name##_dev_attr);\
+									\
+		return show_perf_status_freq_khz(data, buf); \
+	}
+
 store_uncore_min_max(min_freq_khz, 0);
 store_uncore_min_max(max_freq_khz, 1);
 
 show_uncore_min_max(min_freq_khz, 0);
 show_uncore_min_max(max_freq_khz, 1);
 
+show_uncore_perf_status(current_freq_khz);
+
 #define show_uncore_data(member_name)					\
 	static ssize_t show_##member_name(struct device *dev,	\
 					  struct device_attribute *attr, char *buf)\
@@ -223,6 +265,15 @@ show_uncore_data(initial_max_freq_khz);
 		data->_name##_dev_attr.attr.mode = 0444;		\
 	} while (0)
 
+#define init_attribute_root_ro(_name)					\
+	do {								\
+		sysfs_attr_init(&data->_name##_dev_attr.attr);	\
+		data->_name##_dev_attr.show = show_##_name;		\
+		data->_name##_dev_attr.store = NULL;			\
+		data->_name##_dev_attr.attr.name = #_name;		\
+		data->_name##_dev_attr.attr.mode = 0400;		\
+	} while (0)
+
 static int create_attr_group(struct uncore_data *data, char *name)
 {
 	int ret, index = 0;
@@ -231,11 +282,13 @@ static int create_attr_group(struct uncore_data *data, char *name)
 	init_attribute_rw(min_freq_khz);
 	init_attribute_ro(initial_min_freq_khz);
 	init_attribute_ro(initial_max_freq_khz);
+	init_attribute_root_ro(current_freq_khz);
 
 	data->uncore_attrs[index++] = &data->max_freq_khz_dev_attr.attr;
 	data->uncore_attrs[index++] = &data->min_freq_khz_dev_attr.attr;
 	data->uncore_attrs[index++] = &data->initial_min_freq_khz_dev_attr.attr;
 	data->uncore_attrs[index++] = &data->initial_max_freq_khz_dev_attr.attr;
+	data->uncore_attrs[index++] = &data->current_freq_khz_dev_attr.attr;
 	data->uncore_attrs[index] = NULL;
 
 	data->uncore_attr_group.name = name;
Signature · 1 line
2.31.1
author maintainer
#4 lore raw

PATCH 4/4 platform/x86/intel-uncore-freq: Split common and enumeration part

In reply to Srinivas Pandruvada

From: Srinivas Pandruvada <[email protected]>

Split the current driver in two parts:
- Common part: All the commom function other than enumeration function.
- Enumeration/HW specific part: The current enumeration using CPU model is left in the old module. This uses service of common driver to register sysfs objects. Also provide callbacks for MSR access related to uncore.
- Add MODULE_DEVICE_TABLE to uncore-frequency.c

No functional changes are expected.

---
 .../x86/intel/uncore-frequency/Makefile       |   2 +
 .../uncore-frequency-common.c                 | 252 +++++++++++++
 .../uncore-frequency-common.h                 |  62 ++++
 .../intel/uncore-frequency/uncore-frequency.c | 332 +++---------------
 4 files changed, 365 insertions(+), 283 deletions(-)
 create mode 100644 drivers/platform/x86/intel/uncore-frequency/uncore-frequency-common.c
 create mode 100644 drivers/platform/x86/intel/uncore-frequency/uncore-frequency-common.h
drivers/platform/x86/intel/uncore-frequency/Makefile +2 -0
index e22186a480e2..e0f7968e8285 100644
@@ -5,3 +5,5 @@
 
 obj-$(CONFIG_INTEL_UNCORE_FREQ_CONTROL)	+= intel-uncore-frequency.o
 intel-uncore-frequency-y		:= uncore-frequency.o
+obj-$(CONFIG_INTEL_UNCORE_FREQ_CONTROL)	+= intel-uncore-frequency-common.o
+intel-uncore-frequency-common-y		:= uncore-frequency-common.o
drivers/platform/x86/intel/uncore-frequency/uncore-frequency-common.c new file +252 -0

252 lines not on this page · raw message

drivers/platform/x86/intel/uncore-frequency/uncore-frequency-common.h new file +62 -0

62 lines not on this page · raw message

drivers/platform/x86/intel/uncore-frequency/uncore-frequency.c +49 -283

450 lines not on this page · raw message

Signature · 1 line
2.31.1
#5 lore raw
In reply to Srinivas Pandruvada

Hi,

Quoted 15 lines · Srinivas Pandruvada

The uncore frequency scaling is getting used by more customers to either have a deterministic performance or control power consumption. The uncore frequency scaling depends on non architecture MSRs, format of those MSR can be different on different generations of CPUs. This series prepares for easy addition of new HW interface.

There are no functional changes done except adding a new addition to read uncore frequency.

- The first patch creates a separate folder for uncore-freq.
- The second patch uses sysfs groups to create attributes.
- The third patch adds capability to read current uncore frequency.
- The fourth patch splits common and enumeration part. The enumeration part will be specific to each HW interface.

Quoted 5 lines

Srinivas Pandruvada (4):
platform/x86/intel/uncore-freq: Move to uncore-frequency folder platform/x86/intel/uncore-freq: Use sysfs API to create attributes platform/x86/intel/uncore-freq: Display uncore current frequency platform/x86/intel-uncore-freq: Split common and enumeration part

Thank you for your patch-series, I've applied the series to my review-hans branch:
https://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86.git/log/?h=review-hans

Note it will show up in my review-hans branch once I've pushed my local branch there, which might take a while.

Once I've run some tests on this branch the patches there will be added to the platform-drivers-x86/for-next branch and eventually will be included in the pdx86 pull-request to Linus for the next merge-window.

Note I've squashed a small MAINTAINERS change in to patch 1/4 so that the maintainers entry now points to the new sub-dir.

Regards,

Hans

Quoted 17 lines
 drivers/platform/x86/intel/Kconfig            |  14 +-
 drivers/platform/x86/intel/Makefile           |   4 +-
 drivers/platform/x86/intel/uncore-frequency.c | 452 ------------------
 .../x86/intel/uncore-frequency/Kconfig        |  21 +
 .../x86/intel/uncore-frequency/Makefile       |   9 +
 .../uncore-frequency-common.c                 | 252 ++++++++++
 .../uncore-frequency-common.h                 |  62 +++
 .../intel/uncore-frequency/uncore-frequency.c | 272 +++++++++++
 8 files changed, 620 insertions(+), 466 deletions(-)
 delete mode 100644 drivers/platform/x86/intel/uncore-frequency.c
 create mode 100644 drivers/platform/x86/intel/uncore-frequency/Kconfig
 create mode 100644 drivers/platform/x86/intel/uncore-frequency/Makefile
 create mode 100644 drivers/platform/x86/intel/uncore-frequency/uncore-frequency-common.c
 create mode 100644 drivers/platform/x86/intel/uncore-frequency/uncore-frequency-common.h
 create mode 100644 drivers/platform/x86/intel/uncore-frequency/uncore-frequency.c