OSDN Git Service

powernv-cpufreq: Fix pstate_to_idx() to handle non-continguous pstates
authorGautham R. Shenoy <ego@linux.vnet.ibm.com>
Wed, 13 Dec 2017 06:57:40 +0000 (12:27 +0530)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Fri, 5 Jan 2018 12:11:24 +0000 (13:11 +0100)
commit332f0a01f0dd669dcd208e4e9666d80dffd62e7b
treee7c0648f8515fb7863991c07a163eb6d2c5c4c02
parentee1f4a7dafa997816ff3de96155c6f3edc21c1e6
powernv-cpufreq: Fix pstate_to_idx() to handle non-continguous pstates

The code in powernv-cpufreq, makes the following two assumptions which
are not guaranteed by the device-tree bindings:

    1) Pstate ids are continguous: This is used in pstate_to_idx() to
       obtain the reverse map from a pstate to it's corresponding
       entry into the cpufreq frequency table.

    2) Every Pstate should always lie between the max and the min
       pstates that are explicitly reported in the device tree: This
       is used to determine whether a pstate reported by the PMSR is
       out of bounds.

Both these assumptions are unwarranted and can change on future
platforms.

In this patch, we maintain the reverse map from a pstate to it's index
in the cpufreq frequency table and use this in pstate_to_idx(). This
does away with the assumptions (1) mentioned above, and will work with
non continguous pstate ids. If no entry exists for a particular
pstate, then such a pstate is treated as being out of bounds. This
gets rid of assumption (2).

On all the existing platforms, where the pstates are 8-bit long
values, the new implementation of pstate_to_idx() takes constant time.

Signed-off-by: Gautham R. Shenoy <ego@linux.vnet.ibm.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/cpufreq/powernv-cpufreq.c