From d9619b4709496273d3b1f73ea72ead643c744374 Mon Sep 17 00:00:00 2001 From: Octav Zlatior Date: Wed, 27 May 2015 18:02:27 +0200 Subject: cpufreq: adds custom sampling-rate support in dt This allows the setting of a sampling-rate property for a cpu in the device-tree; if set, this will override the defaut sampling rate calculation Signed-off-by: Octav Zlatior Signed-off-by: Christoph Muellner --- Documentation/devicetree/bindings/cpufreq/cpufreq-dt.txt | 6 ++++++ drivers/cpufreq/cpufreq-dt.c | 5 +++++ drivers/cpufreq/cpufreq_governor.c | 7 ++++++- include/linux/cpufreq.h | 3 +++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/cpufreq/cpufreq-dt.txt b/Documentation/devicetree/bindings/cpufreq/cpufreq-dt.txt index e41c98ffbccb..eb492a9a0e1f 100644 --- a/Documentation/devicetree/bindings/cpufreq/cpufreq-dt.txt +++ b/Documentation/devicetree/bindings/cpufreq/cpufreq-dt.txt @@ -21,6 +21,11 @@ Optional properties: - cooling-min-level: - cooling-max-level: Please refer to Documentation/devicetree/bindings/thermal/thermal.txt. +- sampling-rate: Override the default sample rate (calculated from transition + latency, please refer to Documentation/cpu-freq/governors.txt) with a + user-specified value (in microseconds); if the value is zero, the default + (calculated) value will be used; if the value is a non-zero integer smaller + than sampling_rate_min, sampling_rate_min will be used Examples: @@ -39,6 +44,7 @@ cpus { 198000 850000 >; clock-latency = <61036>; /* two CLK32 periods */ + sampling-rate = <160000>; /* 160 milliseconds */ #cooling-cells = <2>; cooling-min-level = <0>; cooling-max-level = <2>; diff --git a/drivers/cpufreq/cpufreq-dt.c b/drivers/cpufreq/cpufreq-dt.c index bab67db54b7e..88812437e8af 100644 --- a/drivers/cpufreq/cpufreq-dt.c +++ b/drivers/cpufreq/cpufreq-dt.c @@ -193,6 +193,7 @@ static int cpufreq_init(struct cpufreq_policy *policy) struct clk *cpu_clk; unsigned long min_uV = ~0, max_uV = 0; unsigned int transition_latency; + unsigned int sampling_rate = 0; int ret; ret = allocate_resources(policy->cpu, &cpu_dev, &cpu_reg, &cpu_clk); @@ -230,6 +231,9 @@ static int cpufreq_init(struct cpufreq_policy *policy) of_property_read_u32(np, "voltage-tolerance", &priv->voltage_tolerance); + if (of_property_read_u32(np, "sampling-rate", &sampling_rate)) + sampling_rate = 0; + if (of_property_read_u32(np, "clock-latency", &transition_latency)) transition_latency = CPUFREQ_ETERNAL; @@ -292,6 +296,7 @@ static int cpufreq_init(struct cpufreq_policy *policy) } policy->cpuinfo.transition_latency = transition_latency; + policy->cpuinfo.sampling_rate = sampling_rate; pd = cpufreq_get_driver_data(); if (!pd || !pd->independent_clocks) diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c index 1b44496b2d2b..53d06df86310 100644 --- a/drivers/cpufreq/cpufreq_governor.c +++ b/drivers/cpufreq/cpufreq_governor.c @@ -303,11 +303,16 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy, if (latency == 0) latency = 1; + sampling_rate = policy->cpuinfo.sampling_rate; + + if (sampling_rate == 0) + sampling_rate = latency * LATENCY_MULTIPLIER; + /* Bring kernel and HW constraints together */ dbs_data->min_sampling_rate = max(dbs_data->min_sampling_rate, MIN_LATENCY_MULTIPLIER * latency); set_sampling_rate(dbs_data, max(dbs_data->min_sampling_rate, - latency * LATENCY_MULTIPLIER)); + sampling_rate)); if ((cdata->governor == GOV_CONSERVATIVE) && (!policy->governor->initialized)) { diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h index 2ee4888c1f47..61f05a1ba139 100644 --- a/include/linux/cpufreq.h +++ b/include/linux/cpufreq.h @@ -49,6 +49,9 @@ struct cpufreq_cpuinfo { /* in 10^(-9) s = nanoseconds */ unsigned int transition_latency; + + /* in 10^(-9) s = nanoseconds */ + unsigned int sampling_rate; }; struct cpufreq_real_policy { -- cgit v1.2.3