[Intel-gfx] [PATCH 8/9] OPTIONAL: cpufreq/intel_pstate: Expose LP controller parameters via debugfs.

Francisco Jerez currojerez at riseup.net
Wed Mar 28 06:38:44 UTC 2018


This is not required for the controller to work but has proven very
useful for debugging and testing of alternative heuristic parameters,
which may offer a better trade-off between energy efficiency and
latency -- The default parameters are rather aggressively
latency-minimizing in order to keep up with the big-core controller
and avoid regressions in latency-sensitive applications, however a
more energy-efficient trade-off may be preferable in practice.  E.g.:

{
   .sample_interval_ms = 10,
   .setpoint_pml = 700,
   .p_base_avg_hz = 3,
   .io_active_threshold_pml = 950,
   .io_active_avg_hz = 10
}

A warning is printed out which should taint the kernel for the
non-standard calibration of the heuristic to be obvious in bug
reports.

Signed-off-by: Francisco Jerez <currojerez at riseup.net>
---
 drivers/cpufreq/intel_pstate.c | 90 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 90 insertions(+)

diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
index d0e212387755..7b1666c34273 100644
--- a/drivers/cpufreq/intel_pstate.c
+++ b/drivers/cpufreq/intel_pstate.c
@@ -862,6 +862,92 @@ static void intel_pstate_update_policies(void)
 		cpufreq_update_policy(cpu);
 }
 
+/************************** debugfs begin ************************/
+static void intel_pstate_lp_reset(struct cpudata *cpu);
+
+static int lp_param_set(void *data, u64 val)
+{
+	unsigned int cpu;
+
+	*(u32 *)data = val;
+	for_each_possible_cpu(cpu) {
+		if (all_cpu_data[cpu])
+			intel_pstate_lp_reset(all_cpu_data[cpu]);
+	}
+
+	WARN_ONCE(1, "Unsupported P-state LP parameter update via debugging interface");
+
+	return 0;
+}
+
+static int lp_param_get(void *data, u64 *val)
+{
+	*val = *(u32 *)data;
+	return 0;
+}
+DEFINE_SIMPLE_ATTRIBUTE(fops_lp_param, lp_param_get, lp_param_set, "%llu\n");
+
+static struct dentry *debugfs_parent;
+
+struct lp_param {
+	char *name;
+	void *value;
+	struct dentry *dentry;
+};
+
+static struct lp_param lp_files[] = {
+	{"lp_sample_interval_ms", &lp_params.sample_interval_ms, },
+	{"lp_setpoint_pml", &lp_params.setpoint_pml, },
+	{"lp_p_base_avg_hz", &lp_params.p_base_avg_hz, },
+	{"lp_io_active_threshold_pml", &lp_params.io_active_threshold_pml, },
+	{"lp_io_active_avg_hz", &lp_params.io_active_avg_hz, },
+	{NULL, NULL, }
+};
+
+static void intel_pstate_update_util_lp(struct update_util_data *data,
+					u64 time, unsigned int flags);
+
+static void intel_pstate_debug_expose_params(void)
+{
+	int i;
+
+	if (hwp_active ||
+	    pstate_funcs.update_util != intel_pstate_update_util_lp)
+		return;
+
+	debugfs_parent = debugfs_create_dir("pstate_snb", NULL);
+	if (IS_ERR_OR_NULL(debugfs_parent))
+		return;
+
+	for (i = 0; lp_files[i].name; i++) {
+		struct dentry *dentry;
+
+		dentry = debugfs_create_file(lp_files[i].name, 0660,
+					     debugfs_parent, lp_files[i].value,
+					     &fops_lp_param);
+		if (!IS_ERR(dentry))
+			lp_files[i].dentry = dentry;
+	}
+}
+
+static void intel_pstate_debug_hide_params(void)
+{
+	int i;
+
+	if (IS_ERR_OR_NULL(debugfs_parent))
+		return;
+
+	for (i = 0; lp_files[i].name; i++) {
+		debugfs_remove(lp_files[i].dentry);
+		lp_files[i].dentry = NULL;
+	}
+
+	debugfs_remove(debugfs_parent);
+	debugfs_parent = NULL;
+}
+
+/************************** debugfs end ************************/
+
 /************************** sysfs begin ************************/
 #define show_one(file_name, object)					\
 	static ssize_t show_##file_name					\
@@ -2423,6 +2509,8 @@ static int intel_pstate_register_driver(struct cpufreq_driver *driver)
 
 	global.min_perf_pct = min_perf_pct_min();
 
+	intel_pstate_debug_expose_params();
+
 	return 0;
 }
 
@@ -2431,6 +2519,8 @@ static int intel_pstate_unregister_driver(void)
 	if (hwp_active)
 		return -EBUSY;
 
+	intel_pstate_debug_hide_params();
+
 	cpufreq_unregister_driver(intel_pstate_driver);
 	intel_pstate_driver_cleanup();
 
-- 
2.16.1



More information about the Intel-gfx mailing list