aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2018-06-05 12:38:39 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2018-06-05 12:38:39 -0400
commit3c89adb0d11117f64d5b501730be7fb2bf53a479 (patch)
treec259aec20deed6c0a0773cfda3a11f58ec9a077d
parent11e7c21880617b8383ad8ad059ae9a07e5abe68e (diff)
parenta24e16b1310ce7f474aa0caca0e66f0f174c022f (diff)
Merge tag 'pm-4.18-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm
Pull power management updates from Rafael Wysocki: "These include a significant update of the generic power domains (genpd) and Operating Performance Points (OPP) frameworks, mostly related to the introduction of power domain performance levels, cpufreq updates (new driver for Qualcomm Kryo processors, updates of the existing drivers, some core fixes, schedutil governor improvements), PCI power management fixes, ACPI workaround for EC-based wakeup events handling on resume from suspend-to-idle, and major updates of the turbostat and pm-graph utilities. Specifics: - Introduce power domain performance levels into the the generic power domains (genpd) and Operating Performance Points (OPP) frameworks (Viresh Kumar, Rajendra Nayak, Dan Carpenter). - Fix two issues in the runtime PM framework related to the initialization and removal of devices using device links (Ulf Hansson). - Clean up the initialization of drivers for devices in PM domains (Ulf Hansson, Geert Uytterhoeven). - Fix a cpufreq core issue related to the policy sysfs interface causing CPU online to fail for CPUs sharing one cpufreq policy in some situations (Tao Wang). - Make it possible to use platform-specific suspend/resume hooks in the cpufreq-dt driver and make the Armada 37xx DVFS use that feature (Viresh Kumar, Miquel Raynal). - Optimize policy transition notifications in cpufreq (Viresh Kumar). - Improve the iowait boost mechanism in the schedutil cpufreq governor (Patrick Bellasi). - Improve the handling of deferred frequency updates in the schedutil cpufreq governor (Joel Fernandes, Dietmar Eggemann, Rafael Wysocki, Viresh Kumar). - Add a new cpufreq driver for Qualcomm Kryo (Ilia Lin). - Fix and clean up some cpufreq drivers (Colin Ian King, Dmitry Osipenko, Doug Smythies, Luc Van Oostenryck, Simon Horman, Viresh Kumar). - Fix the handling of PCI devices with the DPM_SMART_SUSPEND flag set and update stale comments in the PCI core PM code (Rafael Wysocki). - Work around an issue related to the handling of EC-based wakeup events in the ACPI PM core during resume from suspend-to-idle if the EC has been put into the low-power mode (Rafael Wysocki). - Improve the handling of wakeup source objects in the PM core (Doug Berger, Mahendran Ganesh, Rafael Wysocki). - Update the driver core to prevent deferred probe from breaking suspend/resume ordering (Feng Kan). - Clean up the PM core somewhat (Bjorn Helgaas, Ulf Hansson, Rafael Wysocki). - Make the core suspend/resume code and cpufreq support the RT patch (Sebastian Andrzej Siewior, Thomas Gleixner). - Consolidate the PM QoS handling in cpuidle governors (Rafael Wysocki). - Fix a possible crash in the hibernation core (Tetsuo Handa). - Update the rockchip-io Adaptive Voltage Scaling (AVS) driver (David Wu). - Update the turbostat utility (fixes, cleanups, new CPU IDs, new command line options, built-in "Low Power Idle" counters support, new POLL and POLL% columns) and add an entry for it to MAINTAINERS (Len Brown, Artem Bityutskiy, Chen Yu, Laura Abbott, Matt Turner, Prarit Bhargava, Srinivas Pandruvada). - Update the pm-graph to version 5.1 (Todd Brandt). - Update the intel_pstate_tracer utility (Doug Smythies)" * tag 'pm-4.18-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm: (128 commits) tools/power turbostat: update version number tools/power turbostat: Add Node in output tools/power turbostat: add node information into turbostat calculations tools/power turbostat: remove num_ from cpu_topology struct tools/power turbostat: rename num_cores_per_pkg to num_cores_per_node tools/power turbostat: track thread ID in cpu_topology tools/power turbostat: Calculate additional node information for a package tools/power turbostat: Fix node and siblings lookup data tools/power turbostat: set max_num_cpus equal to the cpumask length tools/power turbostat: if --num_iterations, print for specific number of iterations tools/power turbostat: Add Cannon Lake support tools/power turbostat: delete duplicate #defines x86: msr-index.h: Correct SNB_C1/C3_AUTO_UNDEMOTE defines tools/power turbostat: Correct SNB_C1/C3_AUTO_UNDEMOTE defines tools/power turbostat: add POLL and POLL% column tools/power turbostat: Fix --hide Pk%pc10 tools/power turbostat: Build-in "Low Power Idle" counters support tools/power turbostat: Don't make man pages executable tools/power turbostat: remove blank lines tools/power turbostat: a small C-states dump readability immprovement ...
-rw-r--r--Documentation/devicetree/bindings/opp/kryo-cpufreq.txt680
-rw-r--r--Documentation/devicetree/bindings/opp/opp.txt7
-rw-r--r--Documentation/devicetree/bindings/power/power_domain.txt6
-rw-r--r--Documentation/devicetree/bindings/power/rockchip-io-domain.txt15
-rw-r--r--MAINTAINERS16
-rw-r--r--arch/x86/include/asm/msr-index.h4
-rw-r--r--drivers/acpi/acpica/evgpe.c6
-rw-r--r--drivers/acpi/acpica/evxfgpe.c22
-rw-r--r--drivers/acpi/device_pm.c9
-rw-r--r--drivers/acpi/ec.c6
-rw-r--r--drivers/acpi/internal.h1
-rw-r--r--drivers/acpi/sleep.c7
-rw-r--r--drivers/amba/bus.c4
-rw-r--r--drivers/base/base.h3
-rw-r--r--drivers/base/core.c20
-rw-r--r--drivers/base/dd.c7
-rw-r--r--drivers/base/platform.c17
-rw-r--r--drivers/base/power/common.c10
-rw-r--r--drivers/base/power/domain.c212
-rw-r--r--drivers/base/power/main.c37
-rw-r--r--drivers/base/power/power.h30
-rw-r--r--drivers/base/power/runtime.c29
-rw-r--r--drivers/base/power/wakeup.c96
-rw-r--r--drivers/cpufreq/Kconfig.arm13
-rw-r--r--drivers/cpufreq/Makefile1
-rw-r--r--drivers/cpufreq/armada-37xx-cpufreq.c100
-rw-r--r--drivers/cpufreq/cpufreq-dt-platdev.c5
-rw-r--r--drivers/cpufreq/cpufreq-dt.c10
-rw-r--r--drivers/cpufreq/cpufreq-dt.h5
-rw-r--r--drivers/cpufreq/cpufreq.c78
-rw-r--r--drivers/cpufreq/cpufreq_governor.c2
-rw-r--r--drivers/cpufreq/intel_pstate.c46
-rw-r--r--drivers/cpufreq/qcom-cpufreq-kryo.c212
-rw-r--r--drivers/cpufreq/s3c2440-cpufreq.c2
-rw-r--r--drivers/cpufreq/speedstep-lib.c2
-rw-r--r--drivers/cpufreq/tegra20-cpufreq.c200
-rw-r--r--drivers/cpuidle/governor.c17
-rw-r--r--drivers/cpuidle/governors/ladder.c10
-rw-r--r--drivers/cpuidle/governors/menu.c10
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_acp.c2
-rw-r--r--drivers/i2c/i2c-core-base.c2
-rw-r--r--drivers/mmc/core/sdio_bus.c2
-rw-r--r--drivers/opp/core.c267
-rw-r--r--drivers/opp/debugfs.c15
-rw-r--r--drivers/opp/of.c184
-rw-r--r--drivers/opp/opp.h6
-rw-r--r--drivers/pci/pci-driver.c5
-rw-r--r--drivers/pci/pci.c6
-rw-r--r--drivers/power/avs/rockchip-io-domain.c68
-rw-r--r--drivers/soc/tegra/pmc.c20
-rw-r--r--drivers/soundwire/bus_type.c15
-rw-r--r--drivers/spi/spi.c11
-rw-r--r--include/acpi/acpixf.h1
-rw-r--r--include/linux/acpi.h2
-rw-r--r--include/linux/cpufreq.h2
-rw-r--r--include/linux/cpuidle.h1
-rw-r--r--include/linux/kernel.h1
-rw-r--r--include/linux/notifier.h34
-rw-r--r--include/linux/pm_domain.h79
-rw-r--r--include/linux/pm_opp.h27
-rw-r--r--include/linux/pm_runtime.h6
-rw-r--r--include/linux/srcutiny.h6
-rw-r--r--include/linux/srcutree.h6
-rw-r--r--kernel/power/hibernate.c7
-rw-r--r--kernel/power/qos.c1
-rw-r--r--kernel/power/suspend.c27
-rw-r--r--kernel/power/user.c5
-rw-r--r--kernel/power/wakelock.c1
-rw-r--r--kernel/sched/cpufreq_schedutil.c262
-rw-r--r--kernel/time/tick-common.c2
-rwxr-xr-xtools/power/pm-graph/bootgraph.py2
-rw-r--r--tools/power/pm-graph/sleepgraph.84
-rwxr-xr-xtools/power/pm-graph/sleepgraph.py399
-rwxr-xr-xtools/power/x86/intel_pstate_tracer/intel_pstate_tracer.py54
-rw-r--r--tools/power/x86/turbostat/Makefile2
-rw-r--r--tools/power/x86/turbostat/turbostat.826
-rw-r--r--tools/power/x86/turbostat/turbostat.c908
-rw-r--r--tools/power/x86/x86_energy_perf_policy/Makefile2
78 files changed, 3235 insertions, 1192 deletions
diff --git a/Documentation/devicetree/bindings/opp/kryo-cpufreq.txt b/Documentation/devicetree/bindings/opp/kryo-cpufreq.txt
new file mode 100644
index 000000000000..c2127b96805a
--- /dev/null
+++ b/Documentation/devicetree/bindings/opp/kryo-cpufreq.txt
@@ -0,0 +1,680 @@
1Qualcomm Technologies, Inc. KRYO CPUFreq and OPP bindings
2===================================
3
4In Certain Qualcomm Technologies, Inc. SoCs like apq8096 and msm8996
5that have KRYO processors, the CPU ferequencies subset and voltage value
6of each OPP varies based on the silicon variant in use.
7Qualcomm Technologies, Inc. Process Voltage Scaling Tables
8defines the voltage and frequency value based on the msm-id in SMEM
9and speedbin blown in the efuse combination.
10The qcom-cpufreq-kryo driver reads the msm-id and efuse value from the SoC
11to provide the OPP framework with required information (existing HW bitmap).
12This is used to determine the voltage and frequency value for each OPP of
13operating-points-v2 table when it is parsed by the OPP framework.
14
15Required properties:
16--------------------
17In 'cpus' nodes:
18- operating-points-v2: Phandle to the operating-points-v2 table to use.
19
20In 'operating-points-v2' table:
21- compatible: Should be
22 - 'operating-points-v2-kryo-cpu' for apq8096 and msm8996.
23- nvmem-cells: A phandle pointing to a nvmem-cells node representing the
24 efuse registers that has information about the
25 speedbin that is used to select the right frequency/voltage
26 value pair.
27 Please refer the for nvmem-cells
28 bindings Documentation/devicetree/bindings/nvmem/nvmem.txt
29 and also examples below.
30
31In every OPP node:
32- opp-supported-hw: A single 32 bit bitmap value, representing compatible HW.
33 Bitmap:
34 0: MSM8996 V3, speedbin 0
35 1: MSM8996 V3, speedbin 1
36 2: MSM8996 V3, speedbin 2
37 3: unused
38 4: MSM8996 SG, speedbin 0
39 5: MSM8996 SG, speedbin 1
40 6: MSM8996 SG, speedbin 2
41 7-31: unused
42
43Example 1:
44---------
45
46 cpus {
47 #address-cells = <2>;
48 #size-cells = <0>;
49
50 CPU0: cpu@0 {
51 device_type = "cpu";
52 compatible = "qcom,kryo";
53 reg = <0x0 0x0>;
54 enable-method = "psci";
55 clocks = <&kryocc 0>;
56 cpu-supply = <&pm8994_s11_saw>;
57 operating-points-v2 = <&cluster0_opp>;
58 #cooling-cells = <2>;
59 next-level-cache = <&L2_0>;
60 L2_0: l2-cache {
61 compatible = "cache";
62 cache-level = <2>;
63 };
64 };
65
66 CPU1: cpu@1 {
67 device_type = "cpu";
68 compatible = "qcom,kryo";
69 reg = <0x0 0x1>;
70 enable-method = "psci";
71 clocks = <&kryocc 0>;
72 cpu-supply = <&pm8994_s11_saw>;
73 operating-points-v2 = <&cluster0_opp>;
74 #cooling-cells = <2>;
75 next-level-cache = <&L2_0>;
76 };
77
78 CPU2: cpu@100 {
79 device_type = "cpu";
80 compatible = "qcom,kryo";
81 reg = <0x0 0x100>;
82 enable-method = "psci";
83 clocks = <&kryocc 1>;
84 cpu-supply = <&pm8994_s11_saw>;
85 operating-points-v2 = <&cluster1_opp>;
86 #cooling-cells = <2>;
87 next-level-cache = <&L2_1>;
88 L2_1: l2-cache {
89 compatible = "cache";
90 cache-level = <2>;
91 };
92 };
93
94 CPU3: cpu@101 {
95 device_type = "cpu";
96 compatible = "qcom,kryo";
97 reg = <0x0 0x101>;
98 enable-method = "psci";
99 clocks = <&kryocc 1>;
100 cpu-supply = <&pm8994_s11_saw>;
101 operating-points-v2 = <&cluster1_opp>;
102 #cooling-cells = <2>;
103 next-level-cache = <&L2_1>;
104 };
105
106 cpu-map {
107 cluster0 {
108 core0 {
109 cpu = <&CPU0>;
110 };
111
112 core1 {
113 cpu = <&CPU1>;
114 };
115 };
116
117 cluster1 {
118 core0 {
119 cpu = <&CPU2>;
120 };
121
122 core1 {
123 cpu = <&CPU3>;
124 };
125 };
126 };
127 };
128
129 cluster0_opp: opp_table0 {
130 compatible = "operating-points-v2-kryo-cpu";
131 nvmem-cells = <&speedbin_efuse>;
132 opp-shared;
133
134 opp-307200000 {
135 opp-hz = /bits/ 64 <307200000>;
136 opp-microvolt = <905000 905000 1140000>;
137 opp-supported-hw = <0x77>;
138 clock-latency-ns = <200000>;
139 };
140 opp-384000000 {
141 opp-hz = /bits/ 64 <384000000>;
142 opp-microvolt = <905000 905000 1140000>;
143 opp-supported-hw = <0x70>;
144 clock-latency-ns = <200000>;
145 };
146 opp-422400000 {
147 opp-hz = /bits/ 64 <422400000>;
148 opp-microvolt = <905000 905000 1140000>;
149 opp-supported-hw = <0x7>;
150 clock-latency-ns = <200000>;
151 };
152 opp-460800000 {
153 opp-hz = /bits/ 64 <460800000>;
154 opp-microvolt = <905000 905000 1140000>;
155 opp-supported-hw = <0x70>;
156 clock-latency-ns = <200000>;
157 };
158 opp-480000000 {
159 opp-hz = /bits/ 64 <480000000>;
160 opp-microvolt = <905000 905000 1140000>;
161 opp-supported-hw = <0x7>;
162 clock-latency-ns = <200000>;
163 };
164 opp-537600000 {
165 opp-hz = /bits/ 64 <537600000>;
166 opp-microvolt = <905000 905000 1140000>;
167 opp-supported-hw = <0x70>;
168 clock-latency-ns = <200000>;
169 };
170 opp-556800000 {
171 opp-hz = /bits/ 64 <556800000>;
172 opp-microvolt = <905000 905000 1140000>;
173 opp-supported-hw = <0x7>;
174 clock-latency-ns = <200000>;
175 };
176 opp-614400000 {
177 opp-hz = /bits/ 64 <614400000>;
178 opp-microvolt = <905000 905000 1140000>;
179 opp-supported-hw = <0x70>;
180 clock-latency-ns = <200000>;
181 };
182 opp-652800000 {
183 opp-hz = /bits/ 64 <652800000>;
184 opp-microvolt = <905000 905000 1140000>;
185 opp-supported-hw = <0x7>;
186 clock-latency-ns = <200000>;
187 };
188 opp-691200000 {
189 opp-hz = /bits/ 64 <691200000>;
190 opp-microvolt = <905000 905000 1140000>;
191 opp-supported-hw = <0x70>;
192 clock-latency-ns = <200000>;
193 };
194 opp-729600000 {
195 opp-hz = /bits/ 64 <729600000>;
196 opp-microvolt = <905000 905000 1140000>;
197 opp-supported-hw = <0x7>;
198 clock-latency-ns = <200000>;
199 };
200 opp-768000000 {
201 opp-hz = /bits/ 64 <768000000>;
202 opp-microvolt = <905000 905000 1140000>;
203 opp-supported-hw = <0x70>;
204 clock-latency-ns = <200000>;
205 };
206 opp-844800000 {
207 opp-hz = /bits/ 64 <844800000>;
208 opp-microvolt = <905000 905000 1140000>;
209 opp-supported-hw = <0x77>;
210 clock-latency-ns = <200000>;
211 };
212 opp-902400000 {
213 opp-hz = /bits/ 64 <902400000>;
214 opp-microvolt = <905000 905000 1140000>;
215 opp-supported-hw = <0x70>;
216 clock-latency-ns = <200000>;
217 };
218 opp-960000000 {
219 opp-hz = /bits/ 64 <960000000>;
220 opp-microvolt = <905000 905000 1140000>;
221 opp-supported-hw = <0x7>;
222 clock-latency-ns = <200000>;
223 };
224 opp-979200000 {
225 opp-hz = /bits/ 64 <979200000>;
226 opp-microvolt = <905000 905000 1140000>;
227 opp-supported-hw = <0x70>;
228 clock-latency-ns = <200000>;
229 };
230 opp-1036800000 {
231 opp-hz = /bits/ 64 <1036800000>;
232 opp-microvolt = <905000 905000 1140000>;
233 opp-supported-hw = <0x7>;
234 clock-latency-ns = <200000>;
235 };
236 opp-1056000000 {
237 opp-hz = /bits/ 64 <1056000000>;
238 opp-microvolt = <905000 905000 1140000>;
239 opp-supported-hw = <0x70>;
240 clock-latency-ns = <200000>;
241 };
242 opp-1113600000 {
243 opp-hz = /bits/ 64 <1113600000>;
244 opp-microvolt = <905000 905000 1140000>;
245 opp-supported-hw = <0x7>;
246 clock-latency-ns = <200000>;
247 };
248 opp-1132800000 {
249 opp-hz = /bits/ 64 <1132800000>;
250 opp-microvolt = <905000 905000 1140000>;
251 opp-supported-hw = <0x70>;
252 clock-latency-ns = <200000>;
253 };
254 opp-1190400000 {
255 opp-hz = /bits/ 64 <1190400000>;
256 opp-microvolt = <905000 905000 1140000>;
257 opp-supported-hw = <0x7>;
258 clock-latency-ns = <200000>;
259 };
260 opp-1209600000 {
261 opp-hz = /bits/ 64 <1209600000>;
262 opp-microvolt = <905000 905000 1140000>;
263 opp-supported-hw = <0x70>;
264 clock-latency-ns = <200000>;
265 };
266 opp-1228800000 {
267 opp-hz = /bits/ 64 <1228800000>;
268 opp-microvolt = <905000 905000 1140000>;
269 opp-supported-hw = <0x7>;
270 clock-latency-ns = <200000>;
271 };
272 opp-1286400000 {
273 opp-hz = /bits/ 64 <1286400000>;
274 opp-microvolt = <1140000 905000 1140000>;
275 opp-supported-hw = <0x70>;
276 clock-latency-ns = <200000>;
277 };
278 opp-1324800000 {
279 opp-hz = /bits/ 64 <1324800000>;
280 opp-microvolt = <1140000 905000 1140000>;
281 opp-supported-hw = <0x5>;
282 clock-latency-ns = <200000>;
283 };
284 opp-1363200000 {
285 opp-hz = /bits/ 64 <1363200000>;
286 opp-microvolt = <1140000 905000 1140000>;
287 opp-supported-hw = <0x72>;
288 clock-latency-ns = <200000>;
289 };
290 opp-1401600000 {
291 opp-hz = /bits/ 64 <1401600000>;
292 opp-microvolt = <1140000 905000 1140000>;
293 opp-supported-hw = <0x5>;
294 clock-latency-ns = <200000>;
295 };
296 opp-1440000000 {
297 opp-hz = /bits/ 64 <1440000000>;
298 opp-microvolt = <1140000 905000 1140000>;
299 opp-supported-hw = <0x70>;
300 clock-latency-ns = <200000>;
301 };
302 opp-1478400000 {
303 opp-hz = /bits/ 64 <1478400000>;
304 opp-microvolt = <1140000 905000 1140000>;
305 opp-supported-hw = <0x1>;
306 clock-latency-ns = <200000>;
307 };
308 opp-1497600000 {
309 opp-hz = /bits/ 64 <1497600000>;
310 opp-microvolt = <1140000 905000 1140000>;
311 opp-supported-hw = <0x4>;
312 clock-latency-ns = <200000>;
313 };
314 opp-1516800000 {
315 opp-hz = /bits/ 64 <1516800000>;
316 opp-microvolt = <1140000 905000 1140000>;
317 opp-supported-hw = <0x70>;
318 clock-latency-ns = <200000>;
319 };
320 opp-1593600000 {
321 opp-hz = /bits/ 64 <1593600000>;
322 opp-microvolt = <1140000 905000 1140000>;
323 opp-supported-hw = <0x71>;
324 clock-latency-ns = <200000>;
325 };
326 opp-1996800000 {
327 opp-hz = /bits/ 64 <1996800000>;
328 opp-microvolt = <1140000 905000 1140000>;
329 opp-supported-hw = <0x20>;
330 clock-latency-ns = <200000>;
331 };
332 opp-2188800000 {
333 opp-hz = /bits/ 64 <2188800000>;
334 opp-microvolt = <1140000 905000 1140000>;
335 opp-supported-hw = <0x10>;
336 clock-latency-ns = <200000>;
337 };
338 };
339
340 cluster1_opp: opp_table1 {
341 compatible = "operating-points-v2-kryo-cpu";
342 nvmem-cells = <&speedbin_efuse>;
343 opp-shared;
344
345 opp-307200000 {
346 opp-hz = /bits/ 64 <307200000>;
347 opp-microvolt = <905000 905000 1140000>;
348 opp-supported-hw = <0x77>;
349 clock-latency-ns = <200000>;
350 };
351 opp-384000000 {
352 opp-hz = /bits/ 64 <384000000>;
353 opp-microvolt = <905000 905000 1140000>;
354 opp-supported-hw = <0x70>;
355 clock-latency-ns = <200000>;
356 };
357 opp-403200000 {
358 opp-hz = /bits/ 64 <403200000>;
359 opp-microvolt = <905000 905000 1140000>;
360 opp-supported-hw = <0x7>;
361 clock-latency-ns = <200000>;
362 };
363 opp-460800000 {
364 opp-hz = /bits/ 64 <460800000>;
365 opp-microvolt = <905000 905000 1140000>;
366 opp-supported-hw = <0x70>;
367 clock-latency-ns = <200000>;
368 };
369 opp-480000000 {
370 opp-hz = /bits/ 64 <480000000>;
371 opp-microvolt = <905000 905000 1140000>;
372 opp-supported-hw = <0x7>;
373 clock-latency-ns = <200000>;
374 };
375 opp-537600000 {
376 opp-hz = /bits/ 64 <537600000>;
377 opp-microvolt = <905000 905000 1140000>;
378 opp-supported-hw = <0x70>;
379 clock-latency-ns = <200000>;
380 };
381 opp-556800000 {
382 opp-hz = /bits/ 64 <556800000>;
383 opp-microvolt = <905000 905000 1140000>;
384 opp-supported-hw = <0x7>;
385 clock-latency-ns = <200000>;
386 };
387 opp-614400000 {
388 opp-hz = /bits/ 64 <614400000>;
389 opp-microvolt = <905000 905000 1140000>;
390 opp-supported-hw = <0x70>;
391 clock-latency-ns = <200000>;
392 };
393 opp-652800000 {
394 opp-hz = /bits/ 64 <652800000>;
395 opp-microvolt = <905000 905000 1140000>;
396 opp-supported-hw = <0x7>;
397 clock-latency-ns = <200000>;
398 };
399 opp-691200000 {
400 opp-hz = /bits/ 64 <691200000>;
401 opp-microvolt = <905000 905000 1140000>;
402 opp-supported-hw = <0x70>;
403 clock-latency-ns = <200000>;
404 };
405 opp-729600000 {
406 opp-hz = /bits/ 64 <729600000>;
407 opp-microvolt = <905000 905000 1140000>;
408 opp-supported-hw = <0x7>;
409 clock-latency-ns = <200000>;
410 };
411 opp-748800000 {
412 opp-hz = /bits/ 64 <748800000>;
413 opp-microvolt = <905000 905000 1140000>;
414 opp-supported-hw = <0x70>;
415 clock-latency-ns = <200000>;
416 };
417 opp-806400000 {
418 opp-hz = /bits/ 64 <806400000>;
419 opp-microvolt = <905000 905000 1140000>;
420 opp-supported-hw = <0x7>;
421 clock-latency-ns = <200000>;
422 };
423 opp-825600000 {
424 opp-hz = /bits/ 64 <825600000>;
425 opp-microvolt = <905000 905000 1140000>;
426 opp-supported-hw = <0x70>;
427 clock-latency-ns = <200000>;
428 };
429 opp-883200000 {
430 opp-hz = /bits/ 64 <883200000>;
431 opp-microvolt = <905000 905000 1140000>;
432 opp-supported-hw = <0x7>;
433 clock-latency-ns = <200000>;
434 };
435 opp-902400000 {
436 opp-hz = /bits/ 64 <902400000>;
437 opp-microvolt = <905000 905000 1140000>;
438 opp-supported-hw = <0x70>;
439 clock-latency-ns = <200000>;
440 };
441 opp-940800000 {
442 opp-hz = /bits/ 64 <940800000>;
443 opp-microvolt = <905000 905000 1140000>;
444 opp-supported-hw = <0x7>;
445 clock-latency-ns = <200000>;
446 };
447 opp-979200000 {
448 opp-hz = /bits/ 64 <979200000>;
449 opp-microvolt = <905000 905000 1140000>;
450 opp-supported-hw = <0x70>;
451 clock-latency-ns = <200000>;
452 };
453 opp-1036800000 {
454 opp-hz = /bits/ 64 <1036800000>;
455 opp-microvolt = <905000 905000 1140000>;
456 opp-supported-hw = <0x7>;
457 clock-latency-ns = <200000>;
458 };
459 opp-1056000000 {
460 opp-hz = /bits/ 64 <1056000000>;
461 opp-microvolt = <905000 905000 1140000>;
462 opp-supported-hw = <0x70>;
463 clock-latency-ns = <200000>;
464 };
465 opp-1113600000 {
466 opp-hz = /bits/ 64 <1113600000>;
467 opp-microvolt = <905000 905000 1140000>;
468 opp-supported-hw = <0x7>;
469 clock-latency-ns = <200000>;
470 };
471 opp-1132800000 {
472 opp-hz = /bits/ 64 <1132800000>;
473 opp-microvolt = <905000 905000 1140000>;
474 opp-supported-hw = <0x70>;
475 clock-latency-ns = <200000>;
476 };
477 opp-1190400000 {
478 opp-hz = /bits/ 64 <1190400000>;
479 opp-microvolt = <905000 905000 1140000>;
480 opp-supported-hw = <0x7>;
481 clock-latency-ns = <200000>;
482 };
483 opp-1209600000 {
484 opp-hz = /bits/ 64 <1209600000>;
485 opp-microvolt = <905000 905000 1140000>;
486 opp-supported-hw = <0x70>;
487 clock-latency-ns = <200000>;
488 };
489 opp-1248000000 {
490 opp-hz = /bits/ 64 <1248000000>;
491 opp-microvolt = <905000 905000 1140000>;
492 opp-supported-hw = <0x7>;
493 clock-latency-ns = <200000>;
494 };
495 opp-1286400000 {
496 opp-hz = /bits/ 64 <1286400000>;
497 opp-microvolt = <905000 905000 1140000>;
498 opp-supported-hw = <0x70>;
499 clock-latency-ns = <200000>;
500 };
501 opp-1324800000 {
502 opp-hz = /bits/ 64 <1324800000>;
503 opp-microvolt = <1140000 905000 1140000>;
504 opp-supported-hw = <0x7>;
505 clock-latency-ns = <200000>;
506 };
507 opp-1363200000 {
508 opp-hz = /bits/ 64 <1363200000>;
509 opp-microvolt = <1140000 905000 1140000>;
510 opp-supported-hw = <0x70>;
511 clock-latency-ns = <200000>;
512 };
513 opp-1401600000 {
514 opp-hz = /bits/ 64 <1401600000>;
515 opp-microvolt = <1140000 905000 1140000>;
516 opp-supported-hw = <0x7>;
517 clock-latency-ns = <200000>;
518 };
519 opp-1440000000 {
520 opp-hz = /bits/ 64 <1440000000>;
521 opp-microvolt = <1140000 905000 1140000>;
522 opp-supported-hw = <0x70>;
523 clock-latency-ns = <200000>;
524 };
525 opp-1478400000 {
526 opp-hz = /bits/ 64 <1478400000>;
527 opp-microvolt = <1140000 905000 1140000>;
528 opp-supported-hw = <0x7>;
529 clock-latency-ns = <200000>;
530 };
531 opp-1516800000 {
532 opp-hz = /bits/ 64 <1516800000>;
533 opp-microvolt = <1140000 905000 1140000>;
534 opp-supported-hw = <0x70>;
535 clock-latency-ns = <200000>;
536 };
537 opp-1555200000 {
538 opp-hz = /bits/ 64 <1555200000>;
539 opp-microvolt = <1140000 905000 1140000>;
540 opp-supported-hw = <0x7>;
541 clock-latency-ns = <200000>;
542 };
543 opp-1593600000 {
544 opp-hz = /bits/ 64 <1593600000>;
545 opp-microvolt = <1140000 905000 1140000>;
546 opp-supported-hw = <0x70>;
547 clock-latency-ns = <200000>;
548 };
549 opp-1632000000 {
550 opp-hz = /bits/ 64 <1632000000>;
551 opp-microvolt = <1140000 905000 1140000>;
552 opp-supported-hw = <0x7>;
553 clock-latency-ns = <200000>;
554 };
555 opp-1670400000 {
556 opp-hz = /bits/ 64 <1670400000>;
557 opp-microvolt = <1140000 905000 1140000>;
558 opp-supported-hw = <0x70>;
559 clock-latency-ns = <200000>;
560 };
561 opp-1708800000 {
562 opp-hz = /bits/ 64 <1708800000>;
563 opp-microvolt = <1140000 905000 1140000>;
564 opp-supported-hw = <0x7>;
565 clock-latency-ns = <200000>;
566 };
567 opp-1747200000 {
568 opp-hz = /bits/ 64 <1747200000>;
569 opp-microvolt = <1140000 905000 1140000>;
570 opp-supported-hw = <0x70>;
571 clock-latency-ns = <200000>;
572 };
573 opp-1785600000 {
574 opp-hz = /bits/ 64 <1785600000>;
575 opp-microvolt = <1140000 905000 1140000>;
576 opp-supported-hw = <0x7>;
577 clock-latency-ns = <200000>;
578 };
579 opp-1804800000 {
580 opp-hz = /bits/ 64 <1804800000>;
581 opp-microvolt = <1140000 905000 1140000>;
582 opp-supported-hw = <0x6>;
583 clock-latency-ns = <200000>;
584 };
585 opp-1824000000 {
586 opp-hz = /bits/ 64 <1824000000>;
587 opp-microvolt = <1140000 905000 1140000>;
588 opp-supported-hw = <0x71>;
589 clock-latency-ns = <200000>;
590 };
591 opp-1900800000 {
592 opp-hz = /bits/ 64 <1900800000>;
593 opp-microvolt = <1140000 905000 1140000>;
594 opp-supported-hw = <0x74>;
595 clock-latency-ns = <200000>;
596 };
597 opp-1920000000 {
598 opp-hz = /bits/ 64 <1920000000>;
599 opp-microvolt = <1140000 905000 1140000>;
600 opp-supported-hw = <0x1>;
601 clock-latency-ns = <200000>;
602 };
603 opp-1977600000 {
604 opp-hz = /bits/ 64 <1977600000>;
605 opp-microvolt = <1140000 905000 1140000>;
606 opp-supported-hw = <0x30>;
607 clock-latency-ns = <200000>;
608 };
609 opp-1996800000 {
610 opp-hz = /bits/ 64 <1996800000>;
611 opp-microvolt = <1140000 905000 1140000>;
612 opp-supported-hw = <0x1>;
613 clock-latency-ns = <200000>;
614 };
615 opp-2054400000 {
616 opp-hz = /bits/ 64 <2054400000>;
617 opp-microvolt = <1140000 905000 1140000>;
618 opp-supported-hw = <0x30>;
619 clock-latency-ns = <200000>;
620 };
621 opp-2073600000 {
622 opp-hz = /bits/ 64 <2073600000>;
623 opp-microvolt = <1140000 905000 1140000>;
624 opp-supported-hw = <0x1>;
625 clock-latency-ns = <200000>;
626 };
627 opp-2150400000 {
628 opp-hz = /bits/ 64 <2150400000>;
629 opp-microvolt = <1140000 905000 1140000>;
630 opp-supported-hw = <0x31>;
631 clock-latency-ns = <200000>;
632 };
633 opp-2246400000 {
634 opp-hz = /bits/ 64 <2246400000>;
635 opp-microvolt = <1140000 905000 1140000>;
636 opp-supported-hw = <0x10>;
637 clock-latency-ns = <200000>;
638 };
639 opp-2342400000 {
640 opp-hz = /bits/ 64 <2342400000>;
641 opp-microvolt = <1140000 905000 1140000>;
642 opp-supported-hw = <0x10>;
643 clock-latency-ns = <200000>;
644 };
645 };
646
647....
648
649reserved-memory {
650 #address-cells = <2>;
651 #size-cells = <2>;
652 ranges;
653....
654 smem_mem: smem-mem@86000000 {
655 reg = <0x0 0x86000000 0x0 0x200000>;
656 no-map;
657 };
658....
659};
660
661smem {
662 compatible = "qcom,smem";
663 memory-region = <&smem_mem>;
664 hwlocks = <&tcsr_mutex 3>;
665};
666
667soc {
668....
669 qfprom: qfprom@74000 {
670 compatible = "qcom,qfprom";
671 reg = <0x00074000 0x8ff>;
672 #address-cells = <1>;
673 #size-cells = <1>;
674 ....
675 speedbin_efuse: speedbin@133 {
676 reg = <0x133 0x1>;
677 bits = <5 3>;
678 };
679 };
680};
diff --git a/Documentation/devicetree/bindings/opp/opp.txt b/Documentation/devicetree/bindings/opp/opp.txt
index 4e4f30288c8b..c396c4c0af92 100644
--- a/Documentation/devicetree/bindings/opp/opp.txt
+++ b/Documentation/devicetree/bindings/opp/opp.txt
@@ -82,7 +82,10 @@ This defines voltage-current-frequency combinations along with other related
82properties. 82properties.
83 83
84Required properties: 84Required properties:
85- opp-hz: Frequency in Hz, expressed as a 64-bit big-endian integer. 85- opp-hz: Frequency in Hz, expressed as a 64-bit big-endian integer. This is a
86 required property for all device nodes but devices like power domains. The
87 power domain nodes must have another (implementation dependent) property which
88 uniquely identifies the OPP nodes.
86 89
87Optional properties: 90Optional properties:
88- opp-microvolt: voltage in micro Volts. 91- opp-microvolt: voltage in micro Volts.
@@ -159,7 +162,7 @@ Optional properties:
159 162
160- status: Marks the node enabled/disabled. 163- status: Marks the node enabled/disabled.
161 164
162- required-opp: This contains phandle to an OPP node in another device's OPP 165- required-opps: This contains phandle to an OPP node in another device's OPP
163 table. It may contain an array of phandles, where each phandle points to an 166 table. It may contain an array of phandles, where each phandle points to an
164 OPP of a different device. It should not contain multiple phandles to the OPP 167 OPP of a different device. It should not contain multiple phandles to the OPP
165 nodes in the same OPP table. This specifies the minimum required OPP of the 168 nodes in the same OPP table. This specifies the minimum required OPP of the
diff --git a/Documentation/devicetree/bindings/power/power_domain.txt b/Documentation/devicetree/bindings/power/power_domain.txt
index f3355313c020..4733f76cbe48 100644
--- a/Documentation/devicetree/bindings/power/power_domain.txt
+++ b/Documentation/devicetree/bindings/power/power_domain.txt
@@ -127,7 +127,7 @@ inside a PM domain with index 0 of a power controller represented by a node
127with the label "power". 127with the label "power".
128 128
129Optional properties: 129Optional properties:
130- required-opp: This contains phandle to an OPP node in another device's OPP 130- required-opps: This contains phandle to an OPP node in another device's OPP
131 table. It may contain an array of phandles, where each phandle points to an 131 table. It may contain an array of phandles, where each phandle points to an
132 OPP of a different device. It should not contain multiple phandles to the OPP 132 OPP of a different device. It should not contain multiple phandles to the OPP
133 nodes in the same OPP table. This specifies the minimum required OPP of the 133 nodes in the same OPP table. This specifies the minimum required OPP of the
@@ -175,14 +175,14 @@ Example:
175 compatible = "foo,i-leak-current"; 175 compatible = "foo,i-leak-current";
176 reg = <0x12350000 0x1000>; 176 reg = <0x12350000 0x1000>;
177 power-domains = <&power 0>; 177 power-domains = <&power 0>;
178 required-opp = <&domain0_opp_0>; 178 required-opps = <&domain0_opp_0>;
179 }; 179 };
180 180
181 leaky-device1@12350000 { 181 leaky-device1@12350000 {
182 compatible = "foo,i-leak-current"; 182 compatible = "foo,i-leak-current";
183 reg = <0x12350000 0x1000>; 183 reg = <0x12350000 0x1000>;
184 power-domains = <&power 1>; 184 power-domains = <&power 1>;
185 required-opp = <&domain1_opp_1>; 185 required-opps = <&domain1_opp_1>;
186 }; 186 };
187 187
188[1]. Documentation/devicetree/bindings/power/domain-idle-state.txt 188[1]. Documentation/devicetree/bindings/power/domain-idle-state.txt
diff --git a/Documentation/devicetree/bindings/power/rockchip-io-domain.txt b/Documentation/devicetree/bindings/power/rockchip-io-domain.txt
index 4a4766e9c254..e66fd4eab71c 100644
--- a/Documentation/devicetree/bindings/power/rockchip-io-domain.txt
+++ b/Documentation/devicetree/bindings/power/rockchip-io-domain.txt
@@ -31,6 +31,8 @@ SoC is on the same page.
31 31
32Required properties: 32Required properties:
33- compatible: should be one of: 33- compatible: should be one of:
34 - "rockchip,px30-io-voltage-domain" for px30
35 - "rockchip,px30-pmu-io-voltage-domain" for px30 pmu-domains
34 - "rockchip,rk3188-io-voltage-domain" for rk3188 36 - "rockchip,rk3188-io-voltage-domain" for rk3188
35 - "rockchip,rk3228-io-voltage-domain" for rk3228 37 - "rockchip,rk3228-io-voltage-domain" for rk3228
36 - "rockchip,rk3288-io-voltage-domain" for rk3288 38 - "rockchip,rk3288-io-voltage-domain" for rk3288
@@ -51,6 +53,19 @@ a phandle the relevant regulator. All specified supplies must be able
51to report their voltage. The IO Voltage Domain for any non-specified 53to report their voltage. The IO Voltage Domain for any non-specified
52supplies will be not be touched. 54supplies will be not be touched.
53 55
56Possible supplies for PX30:
57- vccio6-supply: The supply connected to VCCIO6.
58- vccio1-supply: The supply connected to VCCIO1.
59- vccio2-supply: The supply connected to VCCIO2.
60- vccio3-supply: The supply connected to VCCIO3.
61- vccio4-supply: The supply connected to VCCIO4.
62- vccio5-supply: The supply connected to VCCIO5.
63- vccio-oscgpi-supply: The supply connected to VCCIO_OSCGPI.
64
65Possible supplies for PX30 pmu-domains:
66- pmuio1-supply: The supply connected to PMUIO1.
67- pmuio2-supply: The supply connected to PMUIO2.
68
54Possible supplies for rk3188: 69Possible supplies for rk3188:
55- ap0-supply: The supply connected to AP0_VCC. 70- ap0-supply: The supply connected to AP0_VCC.
56- ap1-supply: The supply connected to AP1_VCC. 71- ap1-supply: The supply connected to AP1_VCC.
diff --git a/MAINTAINERS b/MAINTAINERS
index c3e2e7076a95..a2254aced8fa 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -11663,6 +11663,13 @@ F: Documentation/devicetree/bindings/media/qcom,camss.txt
11663F: Documentation/media/v4l-drivers/qcom_camss.rst 11663F: Documentation/media/v4l-drivers/qcom_camss.rst
11664F: drivers/media/platform/qcom/camss-8x16/ 11664F: drivers/media/platform/qcom/camss-8x16/
11665 11665
11666QUALCOMM CPUFREQ DRIVER MSM8996/APQ8096
11667M: Ilia Lin <ilia.lin@gmail.com>
11668L: linux-pm@vger.kernel.org
11669S: Maintained
11670F: Documentation/devicetree/bindings/opp/kryo-cpufreq.txt
11671F: drivers/cpufreq/qcom-cpufreq-kryo.c
11672
11666QUALCOMM EMAC GIGABIT ETHERNET DRIVER 11673QUALCOMM EMAC GIGABIT ETHERNET DRIVER
11667M: Timur Tabi <timur@codeaurora.org> 11674M: Timur Tabi <timur@codeaurora.org>
11668L: netdev@vger.kernel.org 11675L: netdev@vger.kernel.org
@@ -14380,6 +14387,15 @@ S: Maintained
14380F: drivers/tc/ 14387F: drivers/tc/
14381F: include/linux/tc.h 14388F: include/linux/tc.h
14382 14389
14390TURBOSTAT UTILITY
14391M: "Len Brown" <lenb@kernel.org>
14392L: linux-pm@vger.kernel.org
14393B: https://bugzilla.kernel.org
14394Q: https://patchwork.kernel.org/project/linux-pm/list/
14395T: git git://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux.git turbostat
14396S: Supported
14397F: tools/power/x86/turbostat/
14398
14383TW5864 VIDEO4LINUX DRIVER 14399TW5864 VIDEO4LINUX DRIVER
14384M: Bluecherry Maintainers <maintainers@bluecherrydvr.com> 14400M: Bluecherry Maintainers <maintainers@bluecherrydvr.com>
14385M: Anton Sviridenko <anton@corp.bluecherry.net> 14401M: Anton Sviridenko <anton@corp.bluecherry.net>
diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-index.h
index fda2114197b3..68b2c3150de1 100644
--- a/arch/x86/include/asm/msr-index.h
+++ b/arch/x86/include/asm/msr-index.h
@@ -62,8 +62,8 @@
62#define NHM_C3_AUTO_DEMOTE (1UL << 25) 62#define NHM_C3_AUTO_DEMOTE (1UL << 25)
63#define NHM_C1_AUTO_DEMOTE (1UL << 26) 63#define NHM_C1_AUTO_DEMOTE (1UL << 26)
64#define ATM_LNC_C6_AUTO_DEMOTE (1UL << 25) 64#define ATM_LNC_C6_AUTO_DEMOTE (1UL << 25)
65#define SNB_C1_AUTO_UNDEMOTE (1UL << 27) 65#define SNB_C3_AUTO_UNDEMOTE (1UL << 27)
66#define SNB_C3_AUTO_UNDEMOTE (1UL << 28) 66#define SNB_C1_AUTO_UNDEMOTE (1UL << 28)
67 67
68#define MSR_MTRRcap 0x000000fe 68#define MSR_MTRRcap 0x000000fe
69 69
diff --git a/drivers/acpi/acpica/evgpe.c b/drivers/acpi/acpica/evgpe.c
index abbd59063906..e10fec99a182 100644
--- a/drivers/acpi/acpica/evgpe.c
+++ b/drivers/acpi/acpica/evgpe.c
@@ -634,6 +634,12 @@ acpi_ev_detect_gpe(struct acpi_namespace_node *gpe_device,
634 634
635 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock); 635 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
636 636
637 if (!gpe_event_info) {
638 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
639 if (!gpe_event_info)
640 goto error_exit;
641 }
642
637 /* Get the info block for the entire GPE register */ 643 /* Get the info block for the entire GPE register */
638 644
639 gpe_register_info = gpe_event_info->register_info; 645 gpe_register_info = gpe_event_info->register_info;
diff --git a/drivers/acpi/acpica/evxfgpe.c b/drivers/acpi/acpica/evxfgpe.c
index c80e3bdf4805..b2d5f66cc1b0 100644
--- a/drivers/acpi/acpica/evxfgpe.c
+++ b/drivers/acpi/acpica/evxfgpe.c
@@ -639,6 +639,28 @@ ACPI_EXPORT_SYMBOL(acpi_get_gpe_status)
639 639
640/******************************************************************************* 640/*******************************************************************************
641 * 641 *
642 * FUNCTION: acpi_gispatch_gpe
643 *
644 * PARAMETERS: gpe_device - Parent GPE Device. NULL for GPE0/GPE1
645 * gpe_number - GPE level within the GPE block
646 *
647 * RETURN: None
648 *
649 * DESCRIPTION: Detect and dispatch a General Purpose Event to either a function
650 * (e.g. EC) or method (e.g. _Lxx/_Exx) handler.
651 *
652 ******************************************************************************/
653void acpi_dispatch_gpe(acpi_handle gpe_device, u32 gpe_number)
654{
655 ACPI_FUNCTION_TRACE(acpi_dispatch_gpe);
656
657 acpi_ev_detect_gpe(gpe_device, NULL, gpe_number);
658}
659
660ACPI_EXPORT_SYMBOL(acpi_dispatch_gpe)
661
662/*******************************************************************************
663 *
642 * FUNCTION: acpi_finish_gpe 664 * FUNCTION: acpi_finish_gpe
643 * 665 *
644 * PARAMETERS: gpe_device - Namespace node for the GPE Block 666 * PARAMETERS: gpe_device - Namespace node for the GPE Block
diff --git a/drivers/acpi/device_pm.c b/drivers/acpi/device_pm.c
index 3d96e4da2d98..a7c2673ffd36 100644
--- a/drivers/acpi/device_pm.c
+++ b/drivers/acpi/device_pm.c
@@ -1257,10 +1257,7 @@ int acpi_dev_pm_attach(struct device *dev, bool power_on)
1257 struct acpi_device *adev = ACPI_COMPANION(dev); 1257 struct acpi_device *adev = ACPI_COMPANION(dev);
1258 1258
1259 if (!adev) 1259 if (!adev)
1260 return -ENODEV; 1260 return 0;
1261
1262 if (dev->pm_domain)
1263 return -EEXIST;
1264 1261
1265 /* 1262 /*
1266 * Only attach the power domain to the first device if the 1263 * Only attach the power domain to the first device if the
@@ -1268,7 +1265,7 @@ int acpi_dev_pm_attach(struct device *dev, bool power_on)
1268 * management twice. 1265 * management twice.
1269 */ 1266 */
1270 if (!acpi_device_is_first_physical_node(adev, dev)) 1267 if (!acpi_device_is_first_physical_node(adev, dev))
1271 return -EBUSY; 1268 return 0;
1272 1269
1273 acpi_add_pm_notifier(adev, dev, acpi_pm_notify_work_func); 1270 acpi_add_pm_notifier(adev, dev, acpi_pm_notify_work_func);
1274 dev_pm_domain_set(dev, &acpi_general_pm_domain); 1271 dev_pm_domain_set(dev, &acpi_general_pm_domain);
@@ -1278,7 +1275,7 @@ int acpi_dev_pm_attach(struct device *dev, bool power_on)
1278 } 1275 }
1279 1276
1280 dev->pm_domain->detach = acpi_dev_pm_detach; 1277 dev->pm_domain->detach = acpi_dev_pm_detach;
1281 return 0; 1278 return 1;
1282} 1279}
1283EXPORT_SYMBOL_GPL(acpi_dev_pm_attach); 1280EXPORT_SYMBOL_GPL(acpi_dev_pm_attach);
1284#endif /* CONFIG_PM */ 1281#endif /* CONFIG_PM */
diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c
index 30a572956557..bb94cf0731fe 100644
--- a/drivers/acpi/ec.c
+++ b/drivers/acpi/ec.c
@@ -1034,6 +1034,12 @@ void acpi_ec_unblock_transactions(void)
1034 acpi_ec_start(first_ec, true); 1034 acpi_ec_start(first_ec, true);
1035} 1035}
1036 1036
1037void acpi_ec_dispatch_gpe(void)
1038{
1039 if (first_ec)
1040 acpi_dispatch_gpe(NULL, first_ec->gpe);
1041}
1042
1037/* -------------------------------------------------------------------------- 1043/* --------------------------------------------------------------------------
1038 Event Management 1044 Event Management
1039 -------------------------------------------------------------------------- */ 1045 -------------------------------------------------------------------------- */
diff --git a/drivers/acpi/internal.h b/drivers/acpi/internal.h
index 1d0a501bc7f0..530a3f675490 100644
--- a/drivers/acpi/internal.h
+++ b/drivers/acpi/internal.h
@@ -188,6 +188,7 @@ int acpi_ec_ecdt_probe(void);
188int acpi_ec_dsdt_probe(void); 188int acpi_ec_dsdt_probe(void);
189void acpi_ec_block_transactions(void); 189void acpi_ec_block_transactions(void);
190void acpi_ec_unblock_transactions(void); 190void acpi_ec_unblock_transactions(void);
191void acpi_ec_dispatch_gpe(void);
191int acpi_ec_add_query_handler(struct acpi_ec *ec, u8 query_bit, 192int acpi_ec_add_query_handler(struct acpi_ec *ec, u8 query_bit,
192 acpi_handle handle, acpi_ec_query_func func, 193 acpi_handle handle, acpi_ec_query_func func,
193 void *data); 194 void *data);
diff --git a/drivers/acpi/sleep.c b/drivers/acpi/sleep.c
index 974e58457697..5d0486f1cfcd 100644
--- a/drivers/acpi/sleep.c
+++ b/drivers/acpi/sleep.c
@@ -989,6 +989,13 @@ static void acpi_s2idle_wake(void)
989 !irqd_is_wakeup_armed(irq_get_irq_data(acpi_sci_irq))) { 989 !irqd_is_wakeup_armed(irq_get_irq_data(acpi_sci_irq))) {
990 pm_system_cancel_wakeup(); 990 pm_system_cancel_wakeup();
991 s2idle_wakeup = true; 991 s2idle_wakeup = true;
992 /*
993 * On some platforms with the LPS0 _DSM device noirq resume
994 * takes too much time for EC wakeup events to survive, so look
995 * for them now.
996 */
997 if (lps0_device_handle)
998 acpi_ec_dispatch_gpe();
992 } 999 }
993} 1000}
994 1001
diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
index 3b0118786b43..0cf51d57e4ae 100644
--- a/drivers/amba/bus.c
+++ b/drivers/amba/bus.c
@@ -251,7 +251,7 @@ static int amba_probe(struct device *dev)
251 break; 251 break;
252 252
253 ret = dev_pm_domain_attach(dev, true); 253 ret = dev_pm_domain_attach(dev, true);
254 if (ret == -EPROBE_DEFER) 254 if (ret)
255 break; 255 break;
256 256
257 ret = amba_get_enable_pclk(pcdev); 257 ret = amba_get_enable_pclk(pcdev);
@@ -378,7 +378,7 @@ static int amba_device_try_add(struct amba_device *dev, struct resource *parent)
378 } 378 }
379 379
380 ret = dev_pm_domain_attach(&dev->dev, true); 380 ret = dev_pm_domain_attach(&dev->dev, true);
381 if (ret == -EPROBE_DEFER) { 381 if (ret) {
382 iounmap(tmp); 382 iounmap(tmp);
383 goto err_release; 383 goto err_release;
384 } 384 }
diff --git a/drivers/base/base.h b/drivers/base/base.h
index d800de650fa5..a75c3025fb78 100644
--- a/drivers/base/base.h
+++ b/drivers/base/base.h
@@ -161,3 +161,6 @@ extern void device_links_driver_cleanup(struct device *dev);
161extern void device_links_no_driver(struct device *dev); 161extern void device_links_no_driver(struct device *dev);
162extern bool device_links_busy(struct device *dev); 162extern bool device_links_busy(struct device *dev);
163extern void device_links_unbind_consumers(struct device *dev); 163extern void device_links_unbind_consumers(struct device *dev);
164
165/* device pm support */
166void device_pm_move_to_tail(struct device *dev);
diff --git a/drivers/base/core.c b/drivers/base/core.c
index b610816eb887..ad7b50897bcc 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -145,6 +145,26 @@ static int device_reorder_to_tail(struct device *dev, void *not_used)
145} 145}
146 146
147/** 147/**
148 * device_pm_move_to_tail - Move set of devices to the end of device lists
149 * @dev: Device to move
150 *
151 * This is a device_reorder_to_tail() wrapper taking the requisite locks.
152 *
153 * It moves the @dev along with all of its children and all of its consumers
154 * to the ends of the device_kset and dpm_list, recursively.
155 */
156void device_pm_move_to_tail(struct device *dev)
157{
158 int idx;
159
160 idx = device_links_read_lock();
161 device_pm_lock();
162 device_reorder_to_tail(dev, NULL);
163 device_pm_unlock();
164 device_links_read_unlock(idx);
165}
166
167/**
148 * device_link_add - Create a link between two devices. 168 * device_link_add - Create a link between two devices.
149 * @consumer: Consumer end of the link. 169 * @consumer: Consumer end of the link.
150 * @supplier: Supplier end of the link. 170 * @supplier: Supplier end of the link.
diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index c9f54089429b..a41c91bfac0e 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -122,9 +122,7 @@ static void deferred_probe_work_func(struct work_struct *work)
122 * the list is a good order for suspend but deferred 122 * the list is a good order for suspend but deferred
123 * probe makes that very unsafe. 123 * probe makes that very unsafe.
124 */ 124 */
125 device_pm_lock(); 125 device_pm_move_to_tail(dev);
126 device_pm_move_last(dev);
127 device_pm_unlock();
128 126
129 dev_dbg(dev, "Retrying from deferred list\n"); 127 dev_dbg(dev, "Retrying from deferred list\n");
130 if (initcall_debug && !initcalls_done) 128 if (initcall_debug && !initcalls_done)
@@ -582,7 +580,7 @@ int driver_probe_device(struct device_driver *drv, struct device *dev)
582 pr_debug("bus: '%s': %s: matched device %s with driver %s\n", 580 pr_debug("bus: '%s': %s: matched device %s with driver %s\n",
583 drv->bus->name, __func__, dev_name(dev), drv->name); 581 drv->bus->name, __func__, dev_name(dev), drv->name);
584 582
585 pm_runtime_get_suppliers(dev); 583 pm_runtime_resume_suppliers(dev);
586 if (dev->parent) 584 if (dev->parent)
587 pm_runtime_get_sync(dev->parent); 585 pm_runtime_get_sync(dev->parent);
588 586
@@ -593,7 +591,6 @@ int driver_probe_device(struct device_driver *drv, struct device *dev)
593 if (dev->parent) 591 if (dev->parent)
594 pm_runtime_put(dev->parent); 592 pm_runtime_put(dev->parent);
595 593
596 pm_runtime_put_suppliers(dev);
597 return ret; 594 return ret;
598} 595}
599 596
diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index c0ff1e73a634..dff82a3c2caa 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -572,17 +572,16 @@ static int platform_drv_probe(struct device *_dev)
572 return ret; 572 return ret;
573 573
574 ret = dev_pm_domain_attach(_dev, true); 574 ret = dev_pm_domain_attach(_dev, true);
575 if (ret != -EPROBE_DEFER) { 575 if (ret)
576 if (drv->probe) { 576 goto out;
577 ret = drv->probe(dev); 577
578 if (ret) 578 if (drv->probe) {
579 dev_pm_domain_detach(_dev, true); 579 ret = drv->probe(dev);
580 } else { 580 if (ret)
581 /* don't fail if just dev_pm_domain_attach failed */ 581 dev_pm_domain_detach(_dev, true);
582 ret = 0;
583 }
584 } 582 }
585 583
584out:
586 if (drv->prevent_deferred_probe && ret == -EPROBE_DEFER) { 585 if (drv->prevent_deferred_probe && ret == -EPROBE_DEFER) {
587 dev_warn(_dev, "probe deferral not supported\n"); 586 dev_warn(_dev, "probe deferral not supported\n");
588 ret = -ENXIO; 587 ret = -ENXIO;
diff --git a/drivers/base/power/common.c b/drivers/base/power/common.c
index f6a9ad52cbbf..7ae62b6355b8 100644
--- a/drivers/base/power/common.c
+++ b/drivers/base/power/common.c
@@ -98,17 +98,21 @@ EXPORT_SYMBOL_GPL(dev_pm_put_subsys_data);
98 * Callers must ensure proper synchronization of this function with power 98 * Callers must ensure proper synchronization of this function with power
99 * management callbacks. 99 * management callbacks.
100 * 100 *
101 * Returns 0 on successfully attached PM domain or negative error code. 101 * Returns 0 on successfully attached PM domain, or when it is found that the
102 * device doesn't need a PM domain, else a negative error code.
102 */ 103 */
103int dev_pm_domain_attach(struct device *dev, bool power_on) 104int dev_pm_domain_attach(struct device *dev, bool power_on)
104{ 105{
105 int ret; 106 int ret;
106 107
108 if (dev->pm_domain)
109 return 0;
110
107 ret = acpi_dev_pm_attach(dev, power_on); 111 ret = acpi_dev_pm_attach(dev, power_on);
108 if (ret) 112 if (!ret)
109 ret = genpd_dev_pm_attach(dev); 113 ret = genpd_dev_pm_attach(dev);
110 114
111 return ret; 115 return ret < 0 ? ret : 0;
112} 116}
113EXPORT_SYMBOL_GPL(dev_pm_domain_attach); 117EXPORT_SYMBOL_GPL(dev_pm_domain_attach);
114 118
diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
index 1ea0e2502e8e..6f403d6fccb2 100644
--- a/drivers/base/power/domain.c
+++ b/drivers/base/power/domain.c
@@ -10,6 +10,7 @@
10#include <linux/kernel.h> 10#include <linux/kernel.h>
11#include <linux/io.h> 11#include <linux/io.h>
12#include <linux/platform_device.h> 12#include <linux/platform_device.h>
13#include <linux/pm_opp.h>
13#include <linux/pm_runtime.h> 14#include <linux/pm_runtime.h>
14#include <linux/pm_domain.h> 15#include <linux/pm_domain.h>
15#include <linux/pm_qos.h> 16#include <linux/pm_qos.h>
@@ -1315,7 +1316,6 @@ EXPORT_SYMBOL_GPL(pm_genpd_syscore_poweron);
1315#endif /* CONFIG_PM_SLEEP */ 1316#endif /* CONFIG_PM_SLEEP */
1316 1317
1317static struct generic_pm_domain_data *genpd_alloc_dev_data(struct device *dev, 1318static struct generic_pm_domain_data *genpd_alloc_dev_data(struct device *dev,
1318 struct generic_pm_domain *genpd,
1319 struct gpd_timing_data *td) 1319 struct gpd_timing_data *td)
1320{ 1320{
1321 struct generic_pm_domain_data *gpd_data; 1321 struct generic_pm_domain_data *gpd_data;
@@ -1377,24 +1377,19 @@ static int genpd_add_device(struct generic_pm_domain *genpd, struct device *dev,
1377 struct gpd_timing_data *td) 1377 struct gpd_timing_data *td)
1378{ 1378{
1379 struct generic_pm_domain_data *gpd_data; 1379 struct generic_pm_domain_data *gpd_data;
1380 int ret = 0; 1380 int ret;
1381 1381
1382 dev_dbg(dev, "%s()\n", __func__); 1382 dev_dbg(dev, "%s()\n", __func__);
1383 1383
1384 if (IS_ERR_OR_NULL(genpd) || IS_ERR_OR_NULL(dev)) 1384 if (IS_ERR_OR_NULL(genpd) || IS_ERR_OR_NULL(dev))
1385 return -EINVAL; 1385 return -EINVAL;
1386 1386
1387 gpd_data = genpd_alloc_dev_data(dev, genpd, td); 1387 gpd_data = genpd_alloc_dev_data(dev, td);
1388 if (IS_ERR(gpd_data)) 1388 if (IS_ERR(gpd_data))
1389 return PTR_ERR(gpd_data); 1389 return PTR_ERR(gpd_data);
1390 1390
1391 genpd_lock(genpd); 1391 genpd_lock(genpd);
1392 1392
1393 if (genpd->prepared_count > 0) {
1394 ret = -EAGAIN;
1395 goto out;
1396 }
1397
1398 ret = genpd->attach_dev ? genpd->attach_dev(genpd, dev) : 0; 1393 ret = genpd->attach_dev ? genpd->attach_dev(genpd, dev) : 0;
1399 if (ret) 1394 if (ret)
1400 goto out; 1395 goto out;
@@ -1418,23 +1413,21 @@ static int genpd_add_device(struct generic_pm_domain *genpd, struct device *dev,
1418} 1413}
1419 1414
1420/** 1415/**
1421 * __pm_genpd_add_device - Add a device to an I/O PM domain. 1416 * pm_genpd_add_device - Add a device to an I/O PM domain.
1422 * @genpd: PM domain to add the device to. 1417 * @genpd: PM domain to add the device to.
1423 * @dev: Device to be added. 1418 * @dev: Device to be added.
1424 * @td: Set of PM QoS timing parameters to attach to the device.
1425 */ 1419 */
1426int __pm_genpd_add_device(struct generic_pm_domain *genpd, struct device *dev, 1420int pm_genpd_add_device(struct generic_pm_domain *genpd, struct device *dev)
1427 struct gpd_timing_data *td)
1428{ 1421{
1429 int ret; 1422 int ret;
1430 1423
1431 mutex_lock(&gpd_list_lock); 1424 mutex_lock(&gpd_list_lock);
1432 ret = genpd_add_device(genpd, dev, td); 1425 ret = genpd_add_device(genpd, dev, NULL);
1433 mutex_unlock(&gpd_list_lock); 1426 mutex_unlock(&gpd_list_lock);
1434 1427
1435 return ret; 1428 return ret;
1436} 1429}
1437EXPORT_SYMBOL_GPL(__pm_genpd_add_device); 1430EXPORT_SYMBOL_GPL(pm_genpd_add_device);
1438 1431
1439static int genpd_remove_device(struct generic_pm_domain *genpd, 1432static int genpd_remove_device(struct generic_pm_domain *genpd,
1440 struct device *dev) 1433 struct device *dev)
@@ -1481,13 +1474,13 @@ static int genpd_remove_device(struct generic_pm_domain *genpd,
1481 1474
1482/** 1475/**
1483 * pm_genpd_remove_device - Remove a device from an I/O PM domain. 1476 * pm_genpd_remove_device - Remove a device from an I/O PM domain.
1484 * @genpd: PM domain to remove the device from.
1485 * @dev: Device to be removed. 1477 * @dev: Device to be removed.
1486 */ 1478 */
1487int pm_genpd_remove_device(struct generic_pm_domain *genpd, 1479int pm_genpd_remove_device(struct device *dev)
1488 struct device *dev)
1489{ 1480{
1490 if (!genpd || genpd != genpd_lookup_dev(dev)) 1481 struct generic_pm_domain *genpd = genpd_lookup_dev(dev);
1482
1483 if (!genpd)
1491 return -EINVAL; 1484 return -EINVAL;
1492 1485
1493 return genpd_remove_device(genpd, dev); 1486 return genpd_remove_device(genpd, dev);
@@ -1696,6 +1689,9 @@ int pm_genpd_init(struct generic_pm_domain *genpd,
1696 return ret; 1689 return ret;
1697 } 1690 }
1698 1691
1692 device_initialize(&genpd->dev);
1693 dev_set_name(&genpd->dev, "%s", genpd->name);
1694
1699 mutex_lock(&gpd_list_lock); 1695 mutex_lock(&gpd_list_lock);
1700 list_add(&genpd->gpd_list_node, &gpd_list); 1696 list_add(&genpd->gpd_list_node, &gpd_list);
1701 mutex_unlock(&gpd_list_lock); 1697 mutex_unlock(&gpd_list_lock);
@@ -1892,14 +1888,33 @@ int of_genpd_add_provider_simple(struct device_node *np,
1892 1888
1893 mutex_lock(&gpd_list_lock); 1889 mutex_lock(&gpd_list_lock);
1894 1890
1895 if (genpd_present(genpd)) { 1891 if (!genpd_present(genpd))
1896 ret = genpd_add_provider(np, genpd_xlate_simple, genpd); 1892 goto unlock;
1897 if (!ret) { 1893
1898 genpd->provider = &np->fwnode; 1894 genpd->dev.of_node = np;
1899 genpd->has_provider = true; 1895
1896 /* Parse genpd OPP table */
1897 if (genpd->set_performance_state) {
1898 ret = dev_pm_opp_of_add_table(&genpd->dev);
1899 if (ret) {
1900 dev_err(&genpd->dev, "Failed to add OPP table: %d\n",
1901 ret);
1902 goto unlock;
1900 } 1903 }
1901 } 1904 }
1902 1905
1906 ret = genpd_add_provider(np, genpd_xlate_simple, genpd);
1907 if (ret) {
1908 if (genpd->set_performance_state)
1909 dev_pm_opp_of_remove_table(&genpd->dev);
1910
1911 goto unlock;
1912 }
1913
1914 genpd->provider = &np->fwnode;
1915 genpd->has_provider = true;
1916
1917unlock:
1903 mutex_unlock(&gpd_list_lock); 1918 mutex_unlock(&gpd_list_lock);
1904 1919
1905 return ret; 1920 return ret;
@@ -1914,6 +1929,7 @@ EXPORT_SYMBOL_GPL(of_genpd_add_provider_simple);
1914int of_genpd_add_provider_onecell(struct device_node *np, 1929int of_genpd_add_provider_onecell(struct device_node *np,
1915 struct genpd_onecell_data *data) 1930 struct genpd_onecell_data *data)
1916{ 1931{
1932 struct generic_pm_domain *genpd;
1917 unsigned int i; 1933 unsigned int i;
1918 int ret = -EINVAL; 1934 int ret = -EINVAL;
1919 1935
@@ -1926,13 +1942,27 @@ int of_genpd_add_provider_onecell(struct device_node *np,
1926 data->xlate = genpd_xlate_onecell; 1942 data->xlate = genpd_xlate_onecell;
1927 1943
1928 for (i = 0; i < data->num_domains; i++) { 1944 for (i = 0; i < data->num_domains; i++) {
1929 if (!data->domains[i]) 1945 genpd = data->domains[i];
1946
1947 if (!genpd)
1930 continue; 1948 continue;
1931 if (!genpd_present(data->domains[i])) 1949 if (!genpd_present(genpd))
1932 goto error; 1950 goto error;
1933 1951
1934 data->domains[i]->provider = &np->fwnode; 1952 genpd->dev.of_node = np;
1935 data->domains[i]->has_provider = true; 1953
1954 /* Parse genpd OPP table */
1955 if (genpd->set_performance_state) {
1956 ret = dev_pm_opp_of_add_table_indexed(&genpd->dev, i);
1957 if (ret) {
1958 dev_err(&genpd->dev, "Failed to add OPP table for index %d: %d\n",
1959 i, ret);
1960 goto error;
1961 }
1962 }
1963
1964 genpd->provider = &np->fwnode;
1965 genpd->has_provider = true;
1936 } 1966 }
1937 1967
1938 ret = genpd_add_provider(np, data->xlate, data); 1968 ret = genpd_add_provider(np, data->xlate, data);
@@ -1945,10 +1975,16 @@ int of_genpd_add_provider_onecell(struct device_node *np,
1945 1975
1946error: 1976error:
1947 while (i--) { 1977 while (i--) {
1948 if (!data->domains[i]) 1978 genpd = data->domains[i];
1979
1980 if (!genpd)
1949 continue; 1981 continue;
1950 data->domains[i]->provider = NULL; 1982
1951 data->domains[i]->has_provider = false; 1983 genpd->provider = NULL;
1984 genpd->has_provider = false;
1985
1986 if (genpd->set_performance_state)
1987 dev_pm_opp_of_remove_table(&genpd->dev);
1952 } 1988 }
1953 1989
1954 mutex_unlock(&gpd_list_lock); 1990 mutex_unlock(&gpd_list_lock);
@@ -1975,10 +2011,17 @@ void of_genpd_del_provider(struct device_node *np)
1975 * provider, set the 'has_provider' to false 2011 * provider, set the 'has_provider' to false
1976 * so that the PM domain can be safely removed. 2012 * so that the PM domain can be safely removed.
1977 */ 2013 */
1978 list_for_each_entry(gpd, &gpd_list, gpd_list_node) 2014 list_for_each_entry(gpd, &gpd_list, gpd_list_node) {
1979 if (gpd->provider == &np->fwnode) 2015 if (gpd->provider == &np->fwnode) {
1980 gpd->has_provider = false; 2016 gpd->has_provider = false;
1981 2017
2018 if (!gpd->set_performance_state)
2019 continue;
2020
2021 dev_pm_opp_of_remove_table(&gpd->dev);
2022 }
2023 }
2024
1982 list_del(&cp->link); 2025 list_del(&cp->link);
1983 of_node_put(cp->node); 2026 of_node_put(cp->node);
1984 kfree(cp); 2027 kfree(cp);
@@ -2185,31 +2228,25 @@ static void genpd_dev_pm_sync(struct device *dev)
2185 * Parse device's OF node to find a PM domain specifier. If such is found, 2228 * Parse device's OF node to find a PM domain specifier. If such is found,
2186 * attaches the device to retrieved pm_domain ops. 2229 * attaches the device to retrieved pm_domain ops.
2187 * 2230 *
2188 * Both generic and legacy Samsung-specific DT bindings are supported to keep 2231 * Returns 1 on successfully attached PM domain, 0 when the device don't need a
2189 * backwards compatibility with existing DTBs. 2232 * PM domain or a negative error code in case of failures. Note that if a
2190 * 2233 * power-domain exists for the device, but it cannot be found or turned on,
2191 * Returns 0 on successfully attached PM domain or negative error code. Note 2234 * then return -EPROBE_DEFER to ensure that the device is not probed and to
2192 * that if a power-domain exists for the device, but it cannot be found or 2235 * re-try again later.
2193 * turned on, then return -EPROBE_DEFER to ensure that the device is not
2194 * probed and to re-try again later.
2195 */ 2236 */
2196int genpd_dev_pm_attach(struct device *dev) 2237int genpd_dev_pm_attach(struct device *dev)
2197{ 2238{
2198 struct of_phandle_args pd_args; 2239 struct of_phandle_args pd_args;
2199 struct generic_pm_domain *pd; 2240 struct generic_pm_domain *pd;
2200 unsigned int i;
2201 int ret; 2241 int ret;
2202 2242
2203 if (!dev->of_node) 2243 if (!dev->of_node)
2204 return -ENODEV; 2244 return 0;
2205
2206 if (dev->pm_domain)
2207 return -EEXIST;
2208 2245
2209 ret = of_parse_phandle_with_args(dev->of_node, "power-domains", 2246 ret = of_parse_phandle_with_args(dev->of_node, "power-domains",
2210 "#power-domain-cells", 0, &pd_args); 2247 "#power-domain-cells", 0, &pd_args);
2211 if (ret < 0) 2248 if (ret < 0)
2212 return ret; 2249 return 0;
2213 2250
2214 mutex_lock(&gpd_list_lock); 2251 mutex_lock(&gpd_list_lock);
2215 pd = genpd_get_from_provider(&pd_args); 2252 pd = genpd_get_from_provider(&pd_args);
@@ -2223,21 +2260,14 @@ int genpd_dev_pm_attach(struct device *dev)
2223 2260
2224 dev_dbg(dev, "adding to PM domain %s\n", pd->name); 2261 dev_dbg(dev, "adding to PM domain %s\n", pd->name);
2225 2262
2226 for (i = 1; i < GENPD_RETRY_MAX_MS; i <<= 1) { 2263 ret = genpd_add_device(pd, dev, NULL);
2227 ret = genpd_add_device(pd, dev, NULL);
2228 if (ret != -EAGAIN)
2229 break;
2230
2231 mdelay(i);
2232 cond_resched();
2233 }
2234 mutex_unlock(&gpd_list_lock); 2264 mutex_unlock(&gpd_list_lock);
2235 2265
2236 if (ret < 0) { 2266 if (ret < 0) {
2237 if (ret != -EPROBE_DEFER) 2267 if (ret != -EPROBE_DEFER)
2238 dev_err(dev, "failed to add to PM domain %s: %d", 2268 dev_err(dev, "failed to add to PM domain %s: %d",
2239 pd->name, ret); 2269 pd->name, ret);
2240 goto out; 2270 return ret;
2241 } 2271 }
2242 2272
2243 dev->pm_domain->detach = genpd_dev_pm_detach; 2273 dev->pm_domain->detach = genpd_dev_pm_detach;
@@ -2246,8 +2276,11 @@ int genpd_dev_pm_attach(struct device *dev)
2246 genpd_lock(pd); 2276 genpd_lock(pd);
2247 ret = genpd_power_on(pd, 0); 2277 ret = genpd_power_on(pd, 0);
2248 genpd_unlock(pd); 2278 genpd_unlock(pd);
2249out: 2279
2250 return ret ? -EPROBE_DEFER : 0; 2280 if (ret)
2281 genpd_remove_device(pd, dev);
2282
2283 return ret ? -EPROBE_DEFER : 1;
2251} 2284}
2252EXPORT_SYMBOL_GPL(genpd_dev_pm_attach); 2285EXPORT_SYMBOL_GPL(genpd_dev_pm_attach);
2253 2286
@@ -2361,6 +2394,55 @@ int of_genpd_parse_idle_states(struct device_node *dn,
2361} 2394}
2362EXPORT_SYMBOL_GPL(of_genpd_parse_idle_states); 2395EXPORT_SYMBOL_GPL(of_genpd_parse_idle_states);
2363 2396
2397/**
2398 * of_genpd_opp_to_performance_state- Gets performance state of device's
2399 * power domain corresponding to a DT node's "required-opps" property.
2400 *
2401 * @dev: Device for which the performance-state needs to be found.
2402 * @opp_node: DT node where the "required-opps" property is present. This can be
2403 * the device node itself (if it doesn't have an OPP table) or a node
2404 * within the OPP table of a device (if device has an OPP table).
2405 * @state: Pointer to return performance state.
2406 *
2407 * Returns performance state corresponding to the "required-opps" property of
2408 * a DT node. This calls platform specific genpd->opp_to_performance_state()
2409 * callback to translate power domain OPP to performance state.
2410 *
2411 * Returns performance state on success and 0 on failure.
2412 */
2413unsigned int of_genpd_opp_to_performance_state(struct device *dev,
2414 struct device_node *opp_node)
2415{
2416 struct generic_pm_domain *genpd;
2417 struct dev_pm_opp *opp;
2418 int state = 0;
2419
2420 genpd = dev_to_genpd(dev);
2421 if (IS_ERR(genpd))
2422 return 0;
2423
2424 if (unlikely(!genpd->set_performance_state))
2425 return 0;
2426
2427 genpd_lock(genpd);
2428
2429 opp = of_dev_pm_opp_find_required_opp(&genpd->dev, opp_node);
2430 if (IS_ERR(opp)) {
2431 dev_err(dev, "Failed to find required OPP: %ld\n",
2432 PTR_ERR(opp));
2433 goto unlock;
2434 }
2435
2436 state = genpd->opp_to_performance_state(genpd, opp);
2437 dev_pm_opp_put(opp);
2438
2439unlock:
2440 genpd_unlock(genpd);
2441
2442 return state;
2443}
2444EXPORT_SYMBOL_GPL(of_genpd_opp_to_performance_state);
2445
2364#endif /* CONFIG_PM_GENERIC_DOMAINS_OF */ 2446#endif /* CONFIG_PM_GENERIC_DOMAINS_OF */
2365 2447
2366 2448
@@ -2628,6 +2710,19 @@ static int genpd_devices_show(struct seq_file *s, void *data)
2628 return ret; 2710 return ret;
2629} 2711}
2630 2712
2713static int genpd_perf_state_show(struct seq_file *s, void *data)
2714{
2715 struct generic_pm_domain *genpd = s->private;
2716
2717 if (genpd_lock_interruptible(genpd))
2718 return -ERESTARTSYS;
2719
2720 seq_printf(s, "%u\n", genpd->performance_state);
2721
2722 genpd_unlock(genpd);
2723 return 0;
2724}
2725
2631#define define_genpd_open_function(name) \ 2726#define define_genpd_open_function(name) \
2632static int genpd_##name##_open(struct inode *inode, struct file *file) \ 2727static int genpd_##name##_open(struct inode *inode, struct file *file) \
2633{ \ 2728{ \
@@ -2641,6 +2736,7 @@ define_genpd_open_function(idle_states);
2641define_genpd_open_function(active_time); 2736define_genpd_open_function(active_time);
2642define_genpd_open_function(total_idle_time); 2737define_genpd_open_function(total_idle_time);
2643define_genpd_open_function(devices); 2738define_genpd_open_function(devices);
2739define_genpd_open_function(perf_state);
2644 2740
2645#define define_genpd_debugfs_fops(name) \ 2741#define define_genpd_debugfs_fops(name) \
2646static const struct file_operations genpd_##name##_fops = { \ 2742static const struct file_operations genpd_##name##_fops = { \
@@ -2657,6 +2753,7 @@ define_genpd_debugfs_fops(idle_states);
2657define_genpd_debugfs_fops(active_time); 2753define_genpd_debugfs_fops(active_time);
2658define_genpd_debugfs_fops(total_idle_time); 2754define_genpd_debugfs_fops(total_idle_time);
2659define_genpd_debugfs_fops(devices); 2755define_genpd_debugfs_fops(devices);
2756define_genpd_debugfs_fops(perf_state);
2660 2757
2661static int __init genpd_debug_init(void) 2758static int __init genpd_debug_init(void)
2662{ 2759{
@@ -2690,6 +2787,9 @@ static int __init genpd_debug_init(void)
2690 d, genpd, &genpd_total_idle_time_fops); 2787 d, genpd, &genpd_total_idle_time_fops);
2691 debugfs_create_file("devices", 0444, 2788 debugfs_create_file("devices", 0444,
2692 d, genpd, &genpd_devices_fops); 2789 d, genpd, &genpd_devices_fops);
2790 if (genpd->set_performance_state)
2791 debugfs_create_file("perf_state", 0444,
2792 d, genpd, &genpd_perf_state_fops);
2693 } 2793 }
2694 2794
2695 return 0; 2795 return 0;
diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
index e5e067091572..3f68e2919dc5 100644
--- a/drivers/base/power/main.c
+++ b/drivers/base/power/main.c
@@ -192,34 +192,31 @@ void device_pm_move_last(struct device *dev)
192 list_move_tail(&dev->power.entry, &dpm_list); 192 list_move_tail(&dev->power.entry, &dpm_list);
193} 193}
194 194
195static ktime_t initcall_debug_start(struct device *dev) 195static ktime_t initcall_debug_start(struct device *dev, void *cb)
196{ 196{
197 ktime_t calltime = 0; 197 if (!pm_print_times_enabled)
198 198 return 0;
199 if (pm_print_times_enabled) {
200 pr_info("calling %s+ @ %i, parent: %s\n",
201 dev_name(dev), task_pid_nr(current),
202 dev->parent ? dev_name(dev->parent) : "none");
203 calltime = ktime_get();
204 }
205 199
206 return calltime; 200 dev_info(dev, "calling %pF @ %i, parent: %s\n", cb,
201 task_pid_nr(current),
202 dev->parent ? dev_name(dev->parent) : "none");
203 return ktime_get();
207} 204}
208 205
209static void initcall_debug_report(struct device *dev, ktime_t calltime, 206static void initcall_debug_report(struct device *dev, ktime_t calltime,
210 int error, pm_message_t state, 207 void *cb, int error)
211 const char *info)
212{ 208{
213 ktime_t rettime; 209 ktime_t rettime;
214 s64 nsecs; 210 s64 nsecs;
215 211
212 if (!pm_print_times_enabled)
213 return;
214
216 rettime = ktime_get(); 215 rettime = ktime_get();
217 nsecs = (s64) ktime_to_ns(ktime_sub(rettime, calltime)); 216 nsecs = (s64) ktime_to_ns(ktime_sub(rettime, calltime));
218 217
219 if (pm_print_times_enabled) { 218 dev_info(dev, "%pF returned %d after %Ld usecs\n", cb, error,
220 pr_info("call %s+ returned %d after %Ld usecs\n", dev_name(dev), 219 (unsigned long long)nsecs >> 10);
221 error, (unsigned long long)nsecs >> 10);
222 }
223} 220}
224 221
225/** 222/**
@@ -446,7 +443,7 @@ static int dpm_run_callback(pm_callback_t cb, struct device *dev,
446 if (!cb) 443 if (!cb)
447 return 0; 444 return 0;
448 445
449 calltime = initcall_debug_start(dev); 446 calltime = initcall_debug_start(dev, cb);
450 447
451 pm_dev_dbg(dev, state, info); 448 pm_dev_dbg(dev, state, info);
452 trace_device_pm_callback_start(dev, info, state.event); 449 trace_device_pm_callback_start(dev, info, state.event);
@@ -454,7 +451,7 @@ static int dpm_run_callback(pm_callback_t cb, struct device *dev,
454 trace_device_pm_callback_end(dev, error); 451 trace_device_pm_callback_end(dev, error);
455 suspend_report_result(cb, error); 452 suspend_report_result(cb, error);
456 453
457 initcall_debug_report(dev, calltime, error, state, info); 454 initcall_debug_report(dev, calltime, cb, error);
458 455
459 return error; 456 return error;
460} 457}
@@ -1664,14 +1661,14 @@ static int legacy_suspend(struct device *dev, pm_message_t state,
1664 int error; 1661 int error;
1665 ktime_t calltime; 1662 ktime_t calltime;
1666 1663
1667 calltime = initcall_debug_start(dev); 1664 calltime = initcall_debug_start(dev, cb);
1668 1665
1669 trace_device_pm_callback_start(dev, info, state.event); 1666 trace_device_pm_callback_start(dev, info, state.event);
1670 error = cb(dev, state); 1667 error = cb(dev, state);
1671 trace_device_pm_callback_end(dev, error); 1668 trace_device_pm_callback_end(dev, error);
1672 suspend_report_result(cb, error); 1669 suspend_report_result(cb, error);
1673 1670
1674 initcall_debug_report(dev, calltime, error, state, info); 1671 initcall_debug_report(dev, calltime, cb, error);
1675 1672
1676 return error; 1673 return error;
1677} 1674}
diff --git a/drivers/base/power/power.h b/drivers/base/power/power.h
index 86e67e70b509..c511def48b48 100644
--- a/drivers/base/power/power.h
+++ b/drivers/base/power/power.h
@@ -56,14 +56,6 @@ static inline void device_wakeup_detach_irq(struct device *dev)
56{ 56{
57} 57}
58 58
59static inline void device_wakeup_arm_wake_irqs(void)
60{
61}
62
63static inline void device_wakeup_disarm_wake_irqs(void)
64{
65}
66
67#endif /* CONFIG_PM_SLEEP */ 59#endif /* CONFIG_PM_SLEEP */
68 60
69/* 61/*
@@ -95,28 +87,6 @@ static inline void pm_runtime_remove(struct device *dev) {}
95 87
96static inline int dpm_sysfs_add(struct device *dev) { return 0; } 88static inline int dpm_sysfs_add(struct device *dev) { return 0; }
97static inline void dpm_sysfs_remove(struct device *dev) {} 89static inline void dpm_sysfs_remove(struct device *dev) {}
98static inline void rpm_sysfs_remove(struct device *dev) {}
99static inline int wakeup_sysfs_add(struct device *dev) { return 0; }
100static inline void wakeup_sysfs_remove(struct device *dev) {}
101static inline int pm_qos_sysfs_add(struct device *dev) { return 0; }
102static inline void pm_qos_sysfs_remove(struct device *dev) {}
103
104static inline void dev_pm_arm_wake_irq(struct wake_irq *wirq)
105{
106}
107
108static inline void dev_pm_disarm_wake_irq(struct wake_irq *wirq)
109{
110}
111
112static inline void dev_pm_enable_wake_irq_check(struct device *dev,
113 bool can_change_status)
114{
115}
116
117static inline void dev_pm_disable_wake_irq_check(struct device *dev)
118{
119}
120 90
121#endif 91#endif
122 92
diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
index 8bef3cb2424d..c6030f100c08 100644
--- a/drivers/base/power/runtime.c
+++ b/drivers/base/power/runtime.c
@@ -1563,37 +1563,16 @@ void pm_runtime_clean_up_links(struct device *dev)
1563} 1563}
1564 1564
1565/** 1565/**
1566 * pm_runtime_get_suppliers - Resume and reference-count supplier devices. 1566 * pm_runtime_resume_suppliers - Resume supplier devices.
1567 * @dev: Consumer device. 1567 * @dev: Consumer device.
1568 */ 1568 */
1569void pm_runtime_get_suppliers(struct device *dev) 1569void pm_runtime_resume_suppliers(struct device *dev)
1570{ 1570{
1571 struct device_link *link;
1572 int idx;
1573
1574 idx = device_links_read_lock();
1575
1576 list_for_each_entry_rcu(link, &dev->links.suppliers, c_node)
1577 if (link->flags & DL_FLAG_PM_RUNTIME)
1578 pm_runtime_get_sync(link->supplier);
1579
1580 device_links_read_unlock(idx);
1581}
1582
1583/**
1584 * pm_runtime_put_suppliers - Drop references to supplier devices.
1585 * @dev: Consumer device.
1586 */
1587void pm_runtime_put_suppliers(struct device *dev)
1588{
1589 struct device_link *link;
1590 int idx; 1571 int idx;
1591 1572
1592 idx = device_links_read_lock(); 1573 idx = device_links_read_lock();
1593 1574
1594 list_for_each_entry_rcu(link, &dev->links.suppliers, c_node) 1575 rpm_get_suppliers(dev);
1595 if (link->flags & DL_FLAG_PM_RUNTIME)
1596 pm_runtime_put(link->supplier);
1597 1576
1598 device_links_read_unlock(idx); 1577 device_links_read_unlock(idx);
1599} 1578}
@@ -1607,6 +1586,8 @@ void pm_runtime_new_link(struct device *dev)
1607 1586
1608void pm_runtime_drop_link(struct device *dev) 1587void pm_runtime_drop_link(struct device *dev)
1609{ 1588{
1589 rpm_put_suppliers(dev);
1590
1610 spin_lock_irq(&dev->power.lock); 1591 spin_lock_irq(&dev->power.lock);
1611 WARN_ON(dev->power.links_count == 0); 1592 WARN_ON(dev->power.links_count == 0);
1612 dev->power.links_count--; 1593 dev->power.links_count--;
diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
index ea01621ed769..5fa1898755a3 100644
--- a/drivers/base/power/wakeup.c
+++ b/drivers/base/power/wakeup.c
@@ -57,7 +57,7 @@ static void split_counters(unsigned int *cnt, unsigned int *inpr)
57/* A preserved old value of the events counter. */ 57/* A preserved old value of the events counter. */
58static unsigned int saved_count; 58static unsigned int saved_count;
59 59
60static DEFINE_SPINLOCK(events_lock); 60static DEFINE_RAW_SPINLOCK(events_lock);
61 61
62static void pm_wakeup_timer_fn(struct timer_list *t); 62static void pm_wakeup_timer_fn(struct timer_list *t);
63 63
@@ -183,11 +183,10 @@ void wakeup_source_add(struct wakeup_source *ws)
183 spin_lock_init(&ws->lock); 183 spin_lock_init(&ws->lock);
184 timer_setup(&ws->timer, pm_wakeup_timer_fn, 0); 184 timer_setup(&ws->timer, pm_wakeup_timer_fn, 0);
185 ws->active = false; 185 ws->active = false;
186 ws->last_time = ktime_get();
187 186
188 spin_lock_irqsave(&events_lock, flags); 187 raw_spin_lock_irqsave(&events_lock, flags);
189 list_add_rcu(&ws->entry, &wakeup_sources); 188 list_add_rcu(&ws->entry, &wakeup_sources);
190 spin_unlock_irqrestore(&events_lock, flags); 189 raw_spin_unlock_irqrestore(&events_lock, flags);
191} 190}
192EXPORT_SYMBOL_GPL(wakeup_source_add); 191EXPORT_SYMBOL_GPL(wakeup_source_add);
193 192
@@ -202,9 +201,9 @@ void wakeup_source_remove(struct wakeup_source *ws)
202 if (WARN_ON(!ws)) 201 if (WARN_ON(!ws))
203 return; 202 return;
204 203
205 spin_lock_irqsave(&events_lock, flags); 204 raw_spin_lock_irqsave(&events_lock, flags);
206 list_del_rcu(&ws->entry); 205 list_del_rcu(&ws->entry);
207 spin_unlock_irqrestore(&events_lock, flags); 206 raw_spin_unlock_irqrestore(&events_lock, flags);
208 synchronize_srcu(&wakeup_srcu); 207 synchronize_srcu(&wakeup_srcu);
209} 208}
210EXPORT_SYMBOL_GPL(wakeup_source_remove); 209EXPORT_SYMBOL_GPL(wakeup_source_remove);
@@ -843,7 +842,7 @@ bool pm_wakeup_pending(void)
843 unsigned long flags; 842 unsigned long flags;
844 bool ret = false; 843 bool ret = false;
845 844
846 spin_lock_irqsave(&events_lock, flags); 845 raw_spin_lock_irqsave(&events_lock, flags);
847 if (events_check_enabled) { 846 if (events_check_enabled) {
848 unsigned int cnt, inpr; 847 unsigned int cnt, inpr;
849 848
@@ -851,10 +850,10 @@ bool pm_wakeup_pending(void)
851 ret = (cnt != saved_count || inpr > 0); 850 ret = (cnt != saved_count || inpr > 0);
852 events_check_enabled = !ret; 851 events_check_enabled = !ret;
853 } 852 }
854 spin_unlock_irqrestore(&events_lock, flags); 853 raw_spin_unlock_irqrestore(&events_lock, flags);
855 854
856 if (ret) { 855 if (ret) {
857 pr_info("PM: Wakeup pending, aborting suspend\n"); 856 pr_debug("PM: Wakeup pending, aborting suspend\n");
858 pm_print_active_wakeup_sources(); 857 pm_print_active_wakeup_sources();
859 } 858 }
860 859
@@ -940,13 +939,13 @@ bool pm_save_wakeup_count(unsigned int count)
940 unsigned long flags; 939 unsigned long flags;
941 940
942 events_check_enabled = false; 941 events_check_enabled = false;
943 spin_lock_irqsave(&events_lock, flags); 942 raw_spin_lock_irqsave(&events_lock, flags);
944 split_counters(&cnt, &inpr); 943 split_counters(&cnt, &inpr);
945 if (cnt == count && inpr == 0) { 944 if (cnt == count && inpr == 0) {
946 saved_count = count; 945 saved_count = count;
947 events_check_enabled = true; 946 events_check_enabled = true;
948 } 947 }
949 spin_unlock_irqrestore(&events_lock, flags); 948 raw_spin_unlock_irqrestore(&events_lock, flags);
950 return events_check_enabled; 949 return events_check_enabled;
951} 950}
952 951
@@ -1029,32 +1028,75 @@ static int print_wakeup_source_stats(struct seq_file *m,
1029 return 0; 1028 return 0;
1030} 1029}
1031 1030
1032/** 1031static void *wakeup_sources_stats_seq_start(struct seq_file *m,
1033 * wakeup_sources_stats_show - Print wakeup sources statistics information. 1032 loff_t *pos)
1034 * @m: seq_file to print the statistics into.
1035 */
1036static int wakeup_sources_stats_show(struct seq_file *m, void *unused)
1037{ 1033{
1038 struct wakeup_source *ws; 1034 struct wakeup_source *ws;
1039 int srcuidx; 1035 loff_t n = *pos;
1036 int *srcuidx = m->private;
1040 1037
1041 seq_puts(m, "name\t\tactive_count\tevent_count\twakeup_count\t" 1038 if (n == 0) {
1042 "expire_count\tactive_since\ttotal_time\tmax_time\t" 1039 seq_puts(m, "name\t\tactive_count\tevent_count\twakeup_count\t"
1043 "last_change\tprevent_suspend_time\n"); 1040 "expire_count\tactive_since\ttotal_time\tmax_time\t"
1041 "last_change\tprevent_suspend_time\n");
1042 }
1044 1043
1045 srcuidx = srcu_read_lock(&wakeup_srcu); 1044 *srcuidx = srcu_read_lock(&wakeup_srcu);
1046 list_for_each_entry_rcu(ws, &wakeup_sources, entry) 1045 list_for_each_entry_rcu(ws, &wakeup_sources, entry) {
1047 print_wakeup_source_stats(m, ws); 1046 if (n-- <= 0)
1048 srcu_read_unlock(&wakeup_srcu, srcuidx); 1047 return ws;
1048 }
1049
1050 return NULL;
1051}
1052
1053static void *wakeup_sources_stats_seq_next(struct seq_file *m,
1054 void *v, loff_t *pos)
1055{
1056 struct wakeup_source *ws = v;
1057 struct wakeup_source *next_ws = NULL;
1049 1058
1050 print_wakeup_source_stats(m, &deleted_ws); 1059 ++(*pos);
1060
1061 list_for_each_entry_continue_rcu(ws, &wakeup_sources, entry) {
1062 next_ws = ws;
1063 break;
1064 }
1065
1066 return next_ws;
1067}
1068
1069static void wakeup_sources_stats_seq_stop(struct seq_file *m, void *v)
1070{
1071 int *srcuidx = m->private;
1072
1073 srcu_read_unlock(&wakeup_srcu, *srcuidx);
1074}
1075
1076/**
1077 * wakeup_sources_stats_seq_show - Print wakeup sources statistics information.
1078 * @m: seq_file to print the statistics into.
1079 * @v: wakeup_source of each iteration
1080 */
1081static int wakeup_sources_stats_seq_show(struct seq_file *m, void *v)
1082{
1083 struct wakeup_source *ws = v;
1084
1085 print_wakeup_source_stats(m, ws);
1051 1086
1052 return 0; 1087 return 0;
1053} 1088}
1054 1089
1090static const struct seq_operations wakeup_sources_stats_seq_ops = {
1091 .start = wakeup_sources_stats_seq_start,
1092 .next = wakeup_sources_stats_seq_next,
1093 .stop = wakeup_sources_stats_seq_stop,
1094 .show = wakeup_sources_stats_seq_show,
1095};
1096
1055static int wakeup_sources_stats_open(struct inode *inode, struct file *file) 1097static int wakeup_sources_stats_open(struct inode *inode, struct file *file)
1056{ 1098{
1057 return single_open(file, wakeup_sources_stats_show, NULL); 1099 return seq_open_private(file, &wakeup_sources_stats_seq_ops, sizeof(int));
1058} 1100}
1059 1101
1060static const struct file_operations wakeup_sources_stats_fops = { 1102static const struct file_operations wakeup_sources_stats_fops = {
@@ -1062,7 +1104,7 @@ static const struct file_operations wakeup_sources_stats_fops = {
1062 .open = wakeup_sources_stats_open, 1104 .open = wakeup_sources_stats_open,
1063 .read = seq_read, 1105 .read = seq_read,
1064 .llseek = seq_lseek, 1106 .llseek = seq_lseek,
1065 .release = single_release, 1107 .release = seq_release_private,
1066}; 1108};
1067 1109
1068static int __init wakeup_sources_debugfs_init(void) 1110static int __init wakeup_sources_debugfs_init(void)
diff --git a/drivers/cpufreq/Kconfig.arm b/drivers/cpufreq/Kconfig.arm
index 96b35b8b3606..c7ce928fbf1f 100644
--- a/drivers/cpufreq/Kconfig.arm
+++ b/drivers/cpufreq/Kconfig.arm
@@ -124,6 +124,17 @@ config ARM_OMAP2PLUS_CPUFREQ
124 depends on ARCH_OMAP2PLUS 124 depends on ARCH_OMAP2PLUS
125 default ARCH_OMAP2PLUS 125 default ARCH_OMAP2PLUS
126 126
127config ARM_QCOM_CPUFREQ_KRYO
128 bool "Qualcomm Kryo based CPUFreq"
129 depends on ARM64
130 depends on QCOM_QFPROM
131 depends on QCOM_SMEM
132 select PM_OPP
133 help
134 This adds the CPUFreq driver for Qualcomm Kryo SoC based boards.
135
136 If in doubt, say N.
137
127config ARM_S3C_CPUFREQ 138config ARM_S3C_CPUFREQ
128 bool 139 bool
129 help 140 help
@@ -264,7 +275,7 @@ config ARM_TANGO_CPUFREQ
264 default y 275 default y
265 276
266config ARM_TEGRA20_CPUFREQ 277config ARM_TEGRA20_CPUFREQ
267 bool "Tegra20 CPUFreq support" 278 tristate "Tegra20 CPUFreq support"
268 depends on ARCH_TEGRA 279 depends on ARCH_TEGRA
269 default y 280 default y
270 help 281 help
diff --git a/drivers/cpufreq/Makefile b/drivers/cpufreq/Makefile
index 8d24ade3bd02..fb4a2ecac43b 100644
--- a/drivers/cpufreq/Makefile
+++ b/drivers/cpufreq/Makefile
@@ -65,6 +65,7 @@ obj-$(CONFIG_MACH_MVEBU_V7) += mvebu-cpufreq.o
65obj-$(CONFIG_ARM_OMAP2PLUS_CPUFREQ) += omap-cpufreq.o 65obj-$(CONFIG_ARM_OMAP2PLUS_CPUFREQ) += omap-cpufreq.o
66obj-$(CONFIG_ARM_PXA2xx_CPUFREQ) += pxa2xx-cpufreq.o 66obj-$(CONFIG_ARM_PXA2xx_CPUFREQ) += pxa2xx-cpufreq.o
67obj-$(CONFIG_PXA3xx) += pxa3xx-cpufreq.o 67obj-$(CONFIG_PXA3xx) += pxa3xx-cpufreq.o
68obj-$(CONFIG_ARM_QCOM_CPUFREQ_KRYO) += qcom-cpufreq-kryo.o
68obj-$(CONFIG_ARM_S3C2410_CPUFREQ) += s3c2410-cpufreq.o 69obj-$(CONFIG_ARM_S3C2410_CPUFREQ) += s3c2410-cpufreq.o
69obj-$(CONFIG_ARM_S3C2412_CPUFREQ) += s3c2412-cpufreq.o 70obj-$(CONFIG_ARM_S3C2412_CPUFREQ) += s3c2412-cpufreq.o
70obj-$(CONFIG_ARM_S3C2416_CPUFREQ) += s3c2416-cpufreq.o 71obj-$(CONFIG_ARM_S3C2416_CPUFREQ) += s3c2416-cpufreq.o
diff --git a/drivers/cpufreq/armada-37xx-cpufreq.c b/drivers/cpufreq/armada-37xx-cpufreq.c
index 72a2975499db..739da90ff3f6 100644
--- a/drivers/cpufreq/armada-37xx-cpufreq.c
+++ b/drivers/cpufreq/armada-37xx-cpufreq.c
@@ -23,6 +23,8 @@
23#include <linux/regmap.h> 23#include <linux/regmap.h>
24#include <linux/slab.h> 24#include <linux/slab.h>
25 25
26#include "cpufreq-dt.h"
27
26/* Power management in North Bridge register set */ 28/* Power management in North Bridge register set */
27#define ARMADA_37XX_NB_L0L1 0x18 29#define ARMADA_37XX_NB_L0L1 0x18
28#define ARMADA_37XX_NB_L2L3 0x1C 30#define ARMADA_37XX_NB_L2L3 0x1C
@@ -56,6 +58,16 @@
56 */ 58 */
57#define LOAD_LEVEL_NR 4 59#define LOAD_LEVEL_NR 4
58 60
61struct armada37xx_cpufreq_state {
62 struct regmap *regmap;
63 u32 nb_l0l1;
64 u32 nb_l2l3;
65 u32 nb_dyn_mod;
66 u32 nb_cpu_load;
67};
68
69static struct armada37xx_cpufreq_state *armada37xx_cpufreq_state;
70
59struct armada_37xx_dvfs { 71struct armada_37xx_dvfs {
60 u32 cpu_freq_max; 72 u32 cpu_freq_max;
61 u8 divider[LOAD_LEVEL_NR]; 73 u8 divider[LOAD_LEVEL_NR];
@@ -136,7 +148,7 @@ static void __init armada37xx_cpufreq_dvfs_setup(struct regmap *base,
136 clk_set_parent(clk, parent); 148 clk_set_parent(clk, parent);
137} 149}
138 150
139static void __init armada37xx_cpufreq_disable_dvfs(struct regmap *base) 151static void armada37xx_cpufreq_disable_dvfs(struct regmap *base)
140{ 152{
141 unsigned int reg = ARMADA_37XX_NB_DYN_MOD, 153 unsigned int reg = ARMADA_37XX_NB_DYN_MOD,
142 mask = ARMADA_37XX_NB_DFS_EN; 154 mask = ARMADA_37XX_NB_DFS_EN;
@@ -162,10 +174,47 @@ static void __init armada37xx_cpufreq_enable_dvfs(struct regmap *base)
162 regmap_update_bits(base, reg, mask, mask); 174 regmap_update_bits(base, reg, mask, mask);
163} 175}
164 176
177static int armada37xx_cpufreq_suspend(struct cpufreq_policy *policy)
178{
179 struct armada37xx_cpufreq_state *state = armada37xx_cpufreq_state;
180
181 regmap_read(state->regmap, ARMADA_37XX_NB_L0L1, &state->nb_l0l1);
182 regmap_read(state->regmap, ARMADA_37XX_NB_L2L3, &state->nb_l2l3);
183 regmap_read(state->regmap, ARMADA_37XX_NB_CPU_LOAD,
184 &state->nb_cpu_load);
185 regmap_read(state->regmap, ARMADA_37XX_NB_DYN_MOD, &state->nb_dyn_mod);
186
187 return 0;
188}
189
190static int armada37xx_cpufreq_resume(struct cpufreq_policy *policy)
191{
192 struct armada37xx_cpufreq_state *state = armada37xx_cpufreq_state;
193
194 /* Ensure DVFS is disabled otherwise the following registers are RO */
195 armada37xx_cpufreq_disable_dvfs(state->regmap);
196
197 regmap_write(state->regmap, ARMADA_37XX_NB_L0L1, state->nb_l0l1);
198 regmap_write(state->regmap, ARMADA_37XX_NB_L2L3, state->nb_l2l3);
199 regmap_write(state->regmap, ARMADA_37XX_NB_CPU_LOAD,
200 state->nb_cpu_load);
201
202 /*
203 * NB_DYN_MOD register is the one that actually enable back DVFS if it
204 * was enabled before the suspend operation. This must be done last
205 * otherwise other registers are not writable.
206 */
207 regmap_write(state->regmap, ARMADA_37XX_NB_DYN_MOD, state->nb_dyn_mod);
208
209 return 0;
210}
211
165static int __init armada37xx_cpufreq_driver_init(void) 212static int __init armada37xx_cpufreq_driver_init(void)
166{ 213{
214 struct cpufreq_dt_platform_data pdata;
167 struct armada_37xx_dvfs *dvfs; 215 struct armada_37xx_dvfs *dvfs;
168 struct platform_device *pdev; 216 struct platform_device *pdev;
217 unsigned long freq;
169 unsigned int cur_frequency; 218 unsigned int cur_frequency;
170 struct regmap *nb_pm_base; 219 struct regmap *nb_pm_base;
171 struct device *cpu_dev; 220 struct device *cpu_dev;
@@ -207,33 +256,58 @@ static int __init armada37xx_cpufreq_driver_init(void)
207 } 256 }
208 257
209 dvfs = armada_37xx_cpu_freq_info_get(cur_frequency); 258 dvfs = armada_37xx_cpu_freq_info_get(cur_frequency);
210 if (!dvfs) 259 if (!dvfs) {
260 clk_put(clk);
211 return -EINVAL; 261 return -EINVAL;
262 }
263
264 armada37xx_cpufreq_state = kmalloc(sizeof(*armada37xx_cpufreq_state),
265 GFP_KERNEL);
266 if (!armada37xx_cpufreq_state) {
267 clk_put(clk);
268 return -ENOMEM;
269 }
270
271 armada37xx_cpufreq_state->regmap = nb_pm_base;
212 272
213 armada37xx_cpufreq_dvfs_setup(nb_pm_base, clk, dvfs->divider); 273 armada37xx_cpufreq_dvfs_setup(nb_pm_base, clk, dvfs->divider);
214 clk_put(clk); 274 clk_put(clk);
215 275
216 for (load_lvl = ARMADA_37XX_DVFS_LOAD_0; load_lvl < LOAD_LEVEL_NR; 276 for (load_lvl = ARMADA_37XX_DVFS_LOAD_0; load_lvl < LOAD_LEVEL_NR;
217 load_lvl++) { 277 load_lvl++) {
218 unsigned long freq = cur_frequency / dvfs->divider[load_lvl]; 278 freq = cur_frequency / dvfs->divider[load_lvl];
219 279
220 ret = dev_pm_opp_add(cpu_dev, freq, 0); 280 ret = dev_pm_opp_add(cpu_dev, freq, 0);
221 if (ret) { 281 if (ret)
222 /* clean-up the already added opp before leaving */ 282 goto remove_opp;
223 while (load_lvl-- > ARMADA_37XX_DVFS_LOAD_0) {
224 freq = cur_frequency / dvfs->divider[load_lvl];
225 dev_pm_opp_remove(cpu_dev, freq);
226 }
227 return ret;
228 }
229 } 283 }
230 284
231 /* Now that everything is setup, enable the DVFS at hardware level */ 285 /* Now that everything is setup, enable the DVFS at hardware level */
232 armada37xx_cpufreq_enable_dvfs(nb_pm_base); 286 armada37xx_cpufreq_enable_dvfs(nb_pm_base);
233 287
234 pdev = platform_device_register_simple("cpufreq-dt", -1, NULL, 0); 288 pdata.suspend = armada37xx_cpufreq_suspend;
289 pdata.resume = armada37xx_cpufreq_resume;
290
291 pdev = platform_device_register_data(NULL, "cpufreq-dt", -1, &pdata,
292 sizeof(pdata));
293 ret = PTR_ERR_OR_ZERO(pdev);
294 if (ret)
295 goto disable_dvfs;
296
297 return 0;
298
299disable_dvfs:
300 armada37xx_cpufreq_disable_dvfs(nb_pm_base);
301remove_opp:
302 /* clean-up the already added opp before leaving */
303 while (load_lvl-- > ARMADA_37XX_DVFS_LOAD_0) {
304 freq = cur_frequency / dvfs->divider[load_lvl];
305 dev_pm_opp_remove(cpu_dev, freq);
306 }
307
308 kfree(armada37xx_cpufreq_state);
235 309
236 return PTR_ERR_OR_ZERO(pdev); 310 return ret;
237} 311}
238/* late_initcall, to guarantee the driver is loaded after A37xx clock driver */ 312/* late_initcall, to guarantee the driver is loaded after A37xx clock driver */
239late_initcall(armada37xx_cpufreq_driver_init); 313late_initcall(armada37xx_cpufreq_driver_init);
diff --git a/drivers/cpufreq/cpufreq-dt-platdev.c b/drivers/cpufreq/cpufreq-dt-platdev.c
index 3b585e4bfac5..fe14c57de6ca 100644
--- a/drivers/cpufreq/cpufreq-dt-platdev.c
+++ b/drivers/cpufreq/cpufreq-dt-platdev.c
@@ -66,8 +66,6 @@ static const struct of_device_id whitelist[] __initconst = {
66 { .compatible = "renesas,r8a7792", }, 66 { .compatible = "renesas,r8a7792", },
67 { .compatible = "renesas,r8a7793", }, 67 { .compatible = "renesas,r8a7793", },
68 { .compatible = "renesas,r8a7794", }, 68 { .compatible = "renesas,r8a7794", },
69 { .compatible = "renesas,r8a7795", },
70 { .compatible = "renesas,r8a7796", },
71 { .compatible = "renesas,sh73a0", }, 69 { .compatible = "renesas,sh73a0", },
72 70
73 { .compatible = "rockchip,rk2928", }, 71 { .compatible = "rockchip,rk2928", },
@@ -118,6 +116,9 @@ static const struct of_device_id blacklist[] __initconst = {
118 116
119 { .compatible = "nvidia,tegra124", }, 117 { .compatible = "nvidia,tegra124", },
120 118
119 { .compatible = "qcom,apq8096", },
120 { .compatible = "qcom,msm8996", },
121
121 { .compatible = "st,stih407", }, 122 { .compatible = "st,stih407", },
122 { .compatible = "st,stih410", }, 123 { .compatible = "st,stih410", },
123 124
diff --git a/drivers/cpufreq/cpufreq-dt.c b/drivers/cpufreq/cpufreq-dt.c
index 190ea0dccb79..0a9ebf00be46 100644
--- a/drivers/cpufreq/cpufreq-dt.c
+++ b/drivers/cpufreq/cpufreq-dt.c
@@ -346,8 +346,14 @@ static int dt_cpufreq_probe(struct platform_device *pdev)
346 if (ret) 346 if (ret)
347 return ret; 347 return ret;
348 348
349 if (data && data->have_governor_per_policy) 349 if (data) {
350 dt_cpufreq_driver.flags |= CPUFREQ_HAVE_GOVERNOR_PER_POLICY; 350 if (data->have_governor_per_policy)
351 dt_cpufreq_driver.flags |= CPUFREQ_HAVE_GOVERNOR_PER_POLICY;
352
353 dt_cpufreq_driver.resume = data->resume;
354 if (data->suspend)
355 dt_cpufreq_driver.suspend = data->suspend;
356 }
351 357
352 ret = cpufreq_register_driver(&dt_cpufreq_driver); 358 ret = cpufreq_register_driver(&dt_cpufreq_driver);
353 if (ret) 359 if (ret)
diff --git a/drivers/cpufreq/cpufreq-dt.h b/drivers/cpufreq/cpufreq-dt.h
index 54d774e46c43..d5aeea13433e 100644
--- a/drivers/cpufreq/cpufreq-dt.h
+++ b/drivers/cpufreq/cpufreq-dt.h
@@ -12,8 +12,13 @@
12 12
13#include <linux/types.h> 13#include <linux/types.h>
14 14
15struct cpufreq_policy;
16
15struct cpufreq_dt_platform_data { 17struct cpufreq_dt_platform_data {
16 bool have_governor_per_policy; 18 bool have_governor_per_policy;
19
20 int (*suspend)(struct cpufreq_policy *policy);
21 int (*resume)(struct cpufreq_policy *policy);
17}; 22};
18 23
19#endif /* __CPUFREQ_DT_H__ */ 24#endif /* __CPUFREQ_DT_H__ */
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 075d18f6ba7a..b0dfd3222013 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -89,16 +89,7 @@ static void cpufreq_governor_limits(struct cpufreq_policy *policy);
89 * The mutex locks both lists. 89 * The mutex locks both lists.
90 */ 90 */
91static BLOCKING_NOTIFIER_HEAD(cpufreq_policy_notifier_list); 91static BLOCKING_NOTIFIER_HEAD(cpufreq_policy_notifier_list);
92static struct srcu_notifier_head cpufreq_transition_notifier_list; 92SRCU_NOTIFIER_HEAD_STATIC(cpufreq_transition_notifier_list);
93
94static bool init_cpufreq_transition_notifier_list_called;
95static int __init init_cpufreq_transition_notifier_list(void)
96{
97 srcu_init_notifier_head(&cpufreq_transition_notifier_list);
98 init_cpufreq_transition_notifier_list_called = true;
99 return 0;
100}
101pure_initcall(init_cpufreq_transition_notifier_list);
102 93
103static int off __read_mostly; 94static int off __read_mostly;
104static int cpufreq_disabled(void) 95static int cpufreq_disabled(void)
@@ -300,8 +291,19 @@ static void adjust_jiffies(unsigned long val, struct cpufreq_freqs *ci)
300#endif 291#endif
301} 292}
302 293
303static void __cpufreq_notify_transition(struct cpufreq_policy *policy, 294/**
304 struct cpufreq_freqs *freqs, unsigned int state) 295 * cpufreq_notify_transition - Notify frequency transition and adjust_jiffies.
296 * @policy: cpufreq policy to enable fast frequency switching for.
297 * @freqs: contain details of the frequency update.
298 * @state: set to CPUFREQ_PRECHANGE or CPUFREQ_POSTCHANGE.
299 *
300 * This function calls the transition notifiers and the "adjust_jiffies"
301 * function. It is called twice on all CPU frequency changes that have
302 * external effects.
303 */
304static void cpufreq_notify_transition(struct cpufreq_policy *policy,
305 struct cpufreq_freqs *freqs,
306 unsigned int state)
305{ 307{
306 BUG_ON(irqs_disabled()); 308 BUG_ON(irqs_disabled());
307 309
@@ -313,54 +315,44 @@ static void __cpufreq_notify_transition(struct cpufreq_policy *policy,
313 state, freqs->new); 315 state, freqs->new);
314 316
315 switch (state) { 317 switch (state) {
316
317 case CPUFREQ_PRECHANGE: 318 case CPUFREQ_PRECHANGE:
318 /* detect if the driver reported a value as "old frequency" 319 /*
320 * Detect if the driver reported a value as "old frequency"
319 * which is not equal to what the cpufreq core thinks is 321 * which is not equal to what the cpufreq core thinks is
320 * "old frequency". 322 * "old frequency".
321 */ 323 */
322 if (!(cpufreq_driver->flags & CPUFREQ_CONST_LOOPS)) { 324 if (!(cpufreq_driver->flags & CPUFREQ_CONST_LOOPS)) {
323 if ((policy) && (policy->cpu == freqs->cpu) && 325 if (policy->cur && (policy->cur != freqs->old)) {
324 (policy->cur) && (policy->cur != freqs->old)) {
325 pr_debug("Warning: CPU frequency is %u, cpufreq assumed %u kHz\n", 326 pr_debug("Warning: CPU frequency is %u, cpufreq assumed %u kHz\n",
326 freqs->old, policy->cur); 327 freqs->old, policy->cur);
327 freqs->old = policy->cur; 328 freqs->old = policy->cur;
328 } 329 }
329 } 330 }
330 srcu_notifier_call_chain(&cpufreq_transition_notifier_list, 331
331 CPUFREQ_PRECHANGE, freqs); 332 for_each_cpu(freqs->cpu, policy->cpus) {
333 srcu_notifier_call_chain(&cpufreq_transition_notifier_list,
334 CPUFREQ_PRECHANGE, freqs);
335 }
336
332 adjust_jiffies(CPUFREQ_PRECHANGE, freqs); 337 adjust_jiffies(CPUFREQ_PRECHANGE, freqs);
333 break; 338 break;
334 339
335 case CPUFREQ_POSTCHANGE: 340 case CPUFREQ_POSTCHANGE:
336 adjust_jiffies(CPUFREQ_POSTCHANGE, freqs); 341 adjust_jiffies(CPUFREQ_POSTCHANGE, freqs);
337 pr_debug("FREQ: %lu - CPU: %lu\n", 342 pr_debug("FREQ: %u - CPUs: %*pbl\n", freqs->new,
338 (unsigned long)freqs->new, (unsigned long)freqs->cpu); 343 cpumask_pr_args(policy->cpus));
339 trace_cpu_frequency(freqs->new, freqs->cpu); 344
345 for_each_cpu(freqs->cpu, policy->cpus) {
346 trace_cpu_frequency(freqs->new, freqs->cpu);
347 srcu_notifier_call_chain(&cpufreq_transition_notifier_list,
348 CPUFREQ_POSTCHANGE, freqs);
349 }
350
340 cpufreq_stats_record_transition(policy, freqs->new); 351 cpufreq_stats_record_transition(policy, freqs->new);
341 srcu_notifier_call_chain(&cpufreq_transition_notifier_list, 352 policy->cur = freqs->new;
342 CPUFREQ_POSTCHANGE, freqs);
343 if (likely(policy) && likely(policy->cpu == freqs->cpu))
344 policy->cur = freqs->new;
345 break;
346 } 353 }
347} 354}
348 355
349/**
350 * cpufreq_notify_transition - call notifier chain and adjust_jiffies
351 * on frequency transition.
352 *
353 * This function calls the transition notifiers and the "adjust_jiffies"
354 * function. It is called twice on all CPU frequency changes that have
355 * external effects.
356 */
357static void cpufreq_notify_transition(struct cpufreq_policy *policy,
358 struct cpufreq_freqs *freqs, unsigned int state)
359{
360 for_each_cpu(freqs->cpu, policy->cpus)
361 __cpufreq_notify_transition(policy, freqs, state);
362}
363
364/* Do post notifications when there are chances that transition has failed */ 356/* Do post notifications when there are chances that transition has failed */
365static void cpufreq_notify_post_transition(struct cpufreq_policy *policy, 357static void cpufreq_notify_post_transition(struct cpufreq_policy *policy,
366 struct cpufreq_freqs *freqs, int transition_failed) 358 struct cpufreq_freqs *freqs, int transition_failed)
@@ -696,6 +688,8 @@ static ssize_t store_##file_name \
696 struct cpufreq_policy new_policy; \ 688 struct cpufreq_policy new_policy; \
697 \ 689 \
698 memcpy(&new_policy, policy, sizeof(*policy)); \ 690 memcpy(&new_policy, policy, sizeof(*policy)); \
691 new_policy.min = policy->user_policy.min; \
692 new_policy.max = policy->user_policy.max; \
699 \ 693 \
700 ret = sscanf(buf, "%u", &new_policy.object); \ 694 ret = sscanf(buf, "%u", &new_policy.object); \
701 if (ret != 1) \ 695 if (ret != 1) \
@@ -1764,8 +1758,6 @@ int cpufreq_register_notifier(struct notifier_block *nb, unsigned int list)
1764 if (cpufreq_disabled()) 1758 if (cpufreq_disabled())
1765 return -EINVAL; 1759 return -EINVAL;
1766 1760
1767 WARN_ON(!init_cpufreq_transition_notifier_list_called);
1768
1769 switch (list) { 1761 switch (list) {
1770 case CPUFREQ_TRANSITION_NOTIFIER: 1762 case CPUFREQ_TRANSITION_NOTIFIER:
1771 mutex_lock(&cpufreq_fast_switch_lock); 1763 mutex_lock(&cpufreq_fast_switch_lock);
diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
index ca38229b045a..871bf9cf55cf 100644
--- a/drivers/cpufreq/cpufreq_governor.c
+++ b/drivers/cpufreq/cpufreq_governor.c
@@ -278,7 +278,7 @@ static void dbs_update_util_handler(struct update_util_data *data, u64 time,
278 struct policy_dbs_info *policy_dbs = cdbs->policy_dbs; 278 struct policy_dbs_info *policy_dbs = cdbs->policy_dbs;
279 u64 delta_ns, lst; 279 u64 delta_ns, lst;
280 280
281 if (!cpufreq_can_do_remote_dvfs(policy_dbs->policy)) 281 if (!cpufreq_this_cpu_can_update(policy_dbs->policy))
282 return; 282 return;
283 283
284 /* 284 /*
diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
index 17e566afbb41..08960a55eb27 100644
--- a/drivers/cpufreq/intel_pstate.c
+++ b/drivers/cpufreq/intel_pstate.c
@@ -1939,13 +1939,51 @@ static int intel_cpufreq_verify_policy(struct cpufreq_policy *policy)
1939 return 0; 1939 return 0;
1940} 1940}
1941 1941
1942/* Use of trace in passive mode:
1943 *
1944 * In passive mode the trace core_busy field (also known as the
1945 * performance field, and lablelled as such on the graphs; also known as
1946 * core_avg_perf) is not needed and so is re-assigned to indicate if the
1947 * driver call was via the normal or fast switch path. Various graphs
1948 * output from the intel_pstate_tracer.py utility that include core_busy
1949 * (or performance or core_avg_perf) have a fixed y-axis from 0 to 100%,
1950 * so we use 10 to indicate the the normal path through the driver, and
1951 * 90 to indicate the fast switch path through the driver.
1952 * The scaled_busy field is not used, and is set to 0.
1953 */
1954
1955#define INTEL_PSTATE_TRACE_TARGET 10
1956#define INTEL_PSTATE_TRACE_FAST_SWITCH 90
1957
1958static void intel_cpufreq_trace(struct cpudata *cpu, unsigned int trace_type, int old_pstate)
1959{
1960 struct sample *sample;
1961
1962 if (!trace_pstate_sample_enabled())
1963 return;
1964
1965 if (!intel_pstate_sample(cpu, ktime_get()))
1966 return;
1967
1968 sample = &cpu->sample;
1969 trace_pstate_sample(trace_type,
1970 0,
1971 old_pstate,
1972 cpu->pstate.current_pstate,
1973 sample->mperf,
1974 sample->aperf,
1975 sample->tsc,
1976 get_avg_frequency(cpu),
1977 fp_toint(cpu->iowait_boost * 100));
1978}
1979
1942static int intel_cpufreq_target(struct cpufreq_policy *policy, 1980static int intel_cpufreq_target(struct cpufreq_policy *policy,
1943 unsigned int target_freq, 1981 unsigned int target_freq,
1944 unsigned int relation) 1982 unsigned int relation)
1945{ 1983{
1946 struct cpudata *cpu = all_cpu_data[policy->cpu]; 1984 struct cpudata *cpu = all_cpu_data[policy->cpu];
1947 struct cpufreq_freqs freqs; 1985 struct cpufreq_freqs freqs;
1948 int target_pstate; 1986 int target_pstate, old_pstate;
1949 1987
1950 update_turbo_state(); 1988 update_turbo_state();
1951 1989
@@ -1965,12 +2003,14 @@ static int intel_cpufreq_target(struct cpufreq_policy *policy,
1965 break; 2003 break;
1966 } 2004 }
1967 target_pstate = intel_pstate_prepare_request(cpu, target_pstate); 2005 target_pstate = intel_pstate_prepare_request(cpu, target_pstate);
2006 old_pstate = cpu->pstate.current_pstate;
1968 if (target_pstate != cpu->pstate.current_pstate) { 2007 if (target_pstate != cpu->pstate.current_pstate) {
1969 cpu->pstate.current_pstate = target_pstate; 2008 cpu->pstate.current_pstate = target_pstate;
1970 wrmsrl_on_cpu(policy->cpu, MSR_IA32_PERF_CTL, 2009 wrmsrl_on_cpu(policy->cpu, MSR_IA32_PERF_CTL,
1971 pstate_funcs.get_val(cpu, target_pstate)); 2010 pstate_funcs.get_val(cpu, target_pstate));
1972 } 2011 }
1973 freqs.new = target_pstate * cpu->pstate.scaling; 2012 freqs.new = target_pstate * cpu->pstate.scaling;
2013 intel_cpufreq_trace(cpu, INTEL_PSTATE_TRACE_TARGET, old_pstate);
1974 cpufreq_freq_transition_end(policy, &freqs, false); 2014 cpufreq_freq_transition_end(policy, &freqs, false);
1975 2015
1976 return 0; 2016 return 0;
@@ -1980,13 +2020,15 @@ static unsigned int intel_cpufreq_fast_switch(struct cpufreq_policy *policy,
1980 unsigned int target_freq) 2020 unsigned int target_freq)
1981{ 2021{
1982 struct cpudata *cpu = all_cpu_data[policy->cpu]; 2022 struct cpudata *cpu = all_cpu_data[policy->cpu];
1983 int target_pstate; 2023 int target_pstate, old_pstate;
1984 2024
1985 update_turbo_state(); 2025 update_turbo_state();
1986 2026
1987 target_pstate = DIV_ROUND_UP(target_freq, cpu->pstate.scaling); 2027 target_pstate = DIV_ROUND_UP(target_freq, cpu->pstate.scaling);
1988 target_pstate = intel_pstate_prepare_request(cpu, target_pstate); 2028 target_pstate = intel_pstate_prepare_request(cpu, target_pstate);
2029 old_pstate = cpu->pstate.current_pstate;
1989 intel_pstate_update_pstate(cpu, target_pstate); 2030 intel_pstate_update_pstate(cpu, target_pstate);
2031 intel_cpufreq_trace(cpu, INTEL_PSTATE_TRACE_FAST_SWITCH, old_pstate);
1990 return target_pstate * cpu->pstate.scaling; 2032 return target_pstate * cpu->pstate.scaling;
1991} 2033}
1992 2034
diff --git a/drivers/cpufreq/qcom-cpufreq-kryo.c b/drivers/cpufreq/qcom-cpufreq-kryo.c
new file mode 100644
index 000000000000..d049fe4b80c4
--- /dev/null
+++ b/drivers/cpufreq/qcom-cpufreq-kryo.c
@@ -0,0 +1,212 @@
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (c) 2018, The Linux Foundation. All rights reserved.
4 */
5
6/*
7 * In Certain QCOM SoCs like apq8096 and msm8996 that have KRYO processors,
8 * the CPU frequency subset and voltage value of each OPP varies
9 * based on the silicon variant in use. Qualcomm Process Voltage Scaling Tables
10 * defines the voltage and frequency value based on the msm-id in SMEM
11 * and speedbin blown in the efuse combination.
12 * The qcom-cpufreq-kryo driver reads the msm-id and efuse value from the SoC
13 * to provide the OPP framework with required information.
14 * This is used to determine the voltage and frequency value for each OPP of
15 * operating-points-v2 table when it is parsed by the OPP framework.
16 */
17
18#include <linux/cpu.h>
19#include <linux/err.h>
20#include <linux/init.h>
21#include <linux/kernel.h>
22#include <linux/module.h>
23#include <linux/nvmem-consumer.h>
24#include <linux/of.h>
25#include <linux/platform_device.h>
26#include <linux/pm_opp.h>
27#include <linux/slab.h>
28#include <linux/soc/qcom/smem.h>
29
30#define MSM_ID_SMEM 137
31
32enum _msm_id {
33 MSM8996V3 = 0xF6ul,
34 APQ8096V3 = 0x123ul,
35 MSM8996SG = 0x131ul,
36 APQ8096SG = 0x138ul,
37};
38
39enum _msm8996_version {
40 MSM8996_V3,
41 MSM8996_SG,
42 NUM_OF_MSM8996_VERSIONS,
43};
44
45static enum _msm8996_version __init qcom_cpufreq_kryo_get_msm_id(void)
46{
47 size_t len;
48 u32 *msm_id;
49 enum _msm8996_version version;
50
51 msm_id = qcom_smem_get(QCOM_SMEM_HOST_ANY, MSM_ID_SMEM, &len);
52 if (IS_ERR(msm_id))
53 return NUM_OF_MSM8996_VERSIONS;
54
55 /* The first 4 bytes are format, next to them is the actual msm-id */
56 msm_id++;
57
58 switch ((enum _msm_id)*msm_id) {
59 case MSM8996V3:
60 case APQ8096V3:
61 version = MSM8996_V3;
62 break;
63 case MSM8996SG:
64 case APQ8096SG:
65 version = MSM8996_SG;
66 break;
67 default:
68 version = NUM_OF_MSM8996_VERSIONS;
69 }
70
71 return version;
72}
73
74static int qcom_cpufreq_kryo_probe(struct platform_device *pdev)
75{
76 struct opp_table *opp_tables[NR_CPUS] = {0};
77 struct platform_device *cpufreq_dt_pdev;
78 enum _msm8996_version msm8996_version;
79 struct nvmem_cell *speedbin_nvmem;
80 struct device_node *np;
81 struct device *cpu_dev;
82 unsigned cpu;
83 u8 *speedbin;
84 u32 versions;
85 size_t len;
86 int ret;
87
88 cpu_dev = get_cpu_device(0);
89 if (NULL == cpu_dev)
90 ret = -ENODEV;
91
92 msm8996_version = qcom_cpufreq_kryo_get_msm_id();
93 if (NUM_OF_MSM8996_VERSIONS == msm8996_version) {
94 dev_err(cpu_dev, "Not Snapdragon 820/821!");
95 return -ENODEV;
96 }
97
98 np = dev_pm_opp_of_get_opp_desc_node(cpu_dev);
99 if (IS_ERR(np))
100 return PTR_ERR(np);
101
102 ret = of_device_is_compatible(np, "operating-points-v2-kryo-cpu");
103 if (!ret) {
104 of_node_put(np);
105 return -ENOENT;
106 }
107
108 speedbin_nvmem = of_nvmem_cell_get(np, NULL);
109 of_node_put(np);
110 if (IS_ERR(speedbin_nvmem)) {
111 dev_err(cpu_dev, "Could not get nvmem cell: %ld\n",
112 PTR_ERR(speedbin_nvmem));
113 return PTR_ERR(speedbin_nvmem);
114 }
115
116 speedbin = nvmem_cell_read(speedbin_nvmem, &len);
117 nvmem_cell_put(speedbin_nvmem);
118
119 switch (msm8996_version) {
120 case MSM8996_V3:
121 versions = 1 << (unsigned int)(*speedbin);
122 break;
123 case MSM8996_SG:
124 versions = 1 << ((unsigned int)(*speedbin) + 4);
125 break;
126 default:
127 BUG();
128 break;
129 }
130
131 for_each_possible_cpu(cpu) {
132 cpu_dev = get_cpu_device(cpu);
133 if (NULL == cpu_dev) {
134 ret = -ENODEV;
135 goto free_opp;
136 }
137
138 opp_tables[cpu] = dev_pm_opp_set_supported_hw(cpu_dev,
139 &versions, 1);
140 if (IS_ERR(opp_tables[cpu])) {
141 ret = PTR_ERR(opp_tables[cpu]);
142 dev_err(cpu_dev, "Failed to set supported hardware\n");
143 goto free_opp;
144 }
145 }
146
147 cpufreq_dt_pdev = platform_device_register_simple("cpufreq-dt", -1,
148 NULL, 0);
149 if (!IS_ERR(cpufreq_dt_pdev))
150 return 0;
151
152 ret = PTR_ERR(cpufreq_dt_pdev);
153 dev_err(cpu_dev, "Failed to register platform device\n");
154
155free_opp:
156 for_each_possible_cpu(cpu) {
157 if (IS_ERR_OR_NULL(opp_tables[cpu]))
158 break;
159 dev_pm_opp_put_supported_hw(opp_tables[cpu]);
160 }
161
162 return ret;
163}
164
165static struct platform_driver qcom_cpufreq_kryo_driver = {
166 .probe = qcom_cpufreq_kryo_probe,
167 .driver = {
168 .name = "qcom-cpufreq-kryo",
169 },
170};
171
172static const struct of_device_id qcom_cpufreq_kryo_match_list[] __initconst = {
173 { .compatible = "qcom,apq8096", },
174 { .compatible = "qcom,msm8996", },
175};
176
177/*
178 * Since the driver depends on smem and nvmem drivers, which may
179 * return EPROBE_DEFER, all the real activity is done in the probe,
180 * which may be defered as well. The init here is only registering
181 * the driver and the platform device.
182 */
183static int __init qcom_cpufreq_kryo_init(void)
184{
185 struct device_node *np = of_find_node_by_path("/");
186 const struct of_device_id *match;
187 int ret;
188
189 if (!np)
190 return -ENODEV;
191
192 match = of_match_node(qcom_cpufreq_kryo_match_list, np);
193 of_node_put(np);
194 if (!match)
195 return -ENODEV;
196
197 ret = platform_driver_register(&qcom_cpufreq_kryo_driver);
198 if (unlikely(ret < 0))
199 return ret;
200
201 ret = PTR_ERR_OR_ZERO(platform_device_register_simple(
202 "qcom-cpufreq-kryo", -1, NULL, 0));
203 if (0 == ret)
204 return 0;
205
206 platform_driver_unregister(&qcom_cpufreq_kryo_driver);
207 return ret;
208}
209module_init(qcom_cpufreq_kryo_init);
210
211MODULE_DESCRIPTION("Qualcomm Technologies, Inc. Kryo CPUfreq driver");
212MODULE_LICENSE("GPL v2");
diff --git a/drivers/cpufreq/s3c2440-cpufreq.c b/drivers/cpufreq/s3c2440-cpufreq.c
index d0d75b65ddd6..d2f67b7a20dd 100644
--- a/drivers/cpufreq/s3c2440-cpufreq.c
+++ b/drivers/cpufreq/s3c2440-cpufreq.c
@@ -143,7 +143,7 @@ static void s3c2440_cpufreq_setdivs(struct s3c_cpufreq_config *cfg)
143{ 143{
144 unsigned long clkdiv, camdiv; 144 unsigned long clkdiv, camdiv;
145 145
146 s3c_freq_dbg("%s: divsiors: h=%d, p=%d\n", __func__, 146 s3c_freq_dbg("%s: divisors: h=%d, p=%d\n", __func__,
147 cfg->divs.h_divisor, cfg->divs.p_divisor); 147 cfg->divs.h_divisor, cfg->divs.p_divisor);
148 148
149 clkdiv = __raw_readl(S3C2410_CLKDIVN); 149 clkdiv = __raw_readl(S3C2410_CLKDIVN);
diff --git a/drivers/cpufreq/speedstep-lib.c b/drivers/cpufreq/speedstep-lib.c
index e3a9962ee410..cabb6f48eb77 100644
--- a/drivers/cpufreq/speedstep-lib.c
+++ b/drivers/cpufreq/speedstep-lib.c
@@ -252,7 +252,7 @@ EXPORT_SYMBOL_GPL(speedstep_get_frequency);
252 *********************************************************************/ 252 *********************************************************************/
253 253
254/* Keep in sync with the x86_cpu_id tables in the different modules */ 254/* Keep in sync with the x86_cpu_id tables in the different modules */
255unsigned int speedstep_detect_processor(void) 255enum speedstep_processor speedstep_detect_processor(void)
256{ 256{
257 struct cpuinfo_x86 *c = &cpu_data(0); 257 struct cpuinfo_x86 *c = &cpu_data(0);
258 u32 ebx, msr_lo, msr_hi; 258 u32 ebx, msr_lo, msr_hi;
diff --git a/drivers/cpufreq/tegra20-cpufreq.c b/drivers/cpufreq/tegra20-cpufreq.c
index 2bd62845e9d5..05f57dcd5215 100644
--- a/drivers/cpufreq/tegra20-cpufreq.c
+++ b/drivers/cpufreq/tegra20-cpufreq.c
@@ -16,16 +16,13 @@
16 * 16 *
17 */ 17 */
18 18
19#include <linux/kernel.h> 19#include <linux/clk.h>
20#include <linux/module.h>
21#include <linux/types.h>
22#include <linux/sched.h>
23#include <linux/cpufreq.h> 20#include <linux/cpufreq.h>
24#include <linux/delay.h>
25#include <linux/init.h>
26#include <linux/err.h> 21#include <linux/err.h>
27#include <linux/clk.h> 22#include <linux/init.h>
28#include <linux/io.h> 23#include <linux/module.h>
24#include <linux/platform_device.h>
25#include <linux/types.h>
29 26
30static struct cpufreq_frequency_table freq_table[] = { 27static struct cpufreq_frequency_table freq_table[] = {
31 { .frequency = 216000 }, 28 { .frequency = 216000 },
@@ -39,25 +36,27 @@ static struct cpufreq_frequency_table freq_table[] = {
39 { .frequency = CPUFREQ_TABLE_END }, 36 { .frequency = CPUFREQ_TABLE_END },
40}; 37};
41 38
42#define NUM_CPUS 2 39struct tegra20_cpufreq {
43 40 struct device *dev;
44static struct clk *cpu_clk; 41 struct cpufreq_driver driver;
45static struct clk *pll_x_clk; 42 struct clk *cpu_clk;
46static struct clk *pll_p_clk; 43 struct clk *pll_x_clk;
47static struct clk *emc_clk; 44 struct clk *pll_p_clk;
48static bool pll_x_prepared; 45 bool pll_x_prepared;
46};
49 47
50static unsigned int tegra_get_intermediate(struct cpufreq_policy *policy, 48static unsigned int tegra_get_intermediate(struct cpufreq_policy *policy,
51 unsigned int index) 49 unsigned int index)
52{ 50{
53 unsigned int ifreq = clk_get_rate(pll_p_clk) / 1000; 51 struct tegra20_cpufreq *cpufreq = cpufreq_get_driver_data();
52 unsigned int ifreq = clk_get_rate(cpufreq->pll_p_clk) / 1000;
54 53
55 /* 54 /*
56 * Don't switch to intermediate freq if: 55 * Don't switch to intermediate freq if:
57 * - we are already at it, i.e. policy->cur == ifreq 56 * - we are already at it, i.e. policy->cur == ifreq
58 * - index corresponds to ifreq 57 * - index corresponds to ifreq
59 */ 58 */
60 if ((freq_table[index].frequency == ifreq) || (policy->cur == ifreq)) 59 if (freq_table[index].frequency == ifreq || policy->cur == ifreq)
61 return 0; 60 return 0;
62 61
63 return ifreq; 62 return ifreq;
@@ -66,6 +65,7 @@ static unsigned int tegra_get_intermediate(struct cpufreq_policy *policy,
66static int tegra_target_intermediate(struct cpufreq_policy *policy, 65static int tegra_target_intermediate(struct cpufreq_policy *policy,
67 unsigned int index) 66 unsigned int index)
68{ 67{
68 struct tegra20_cpufreq *cpufreq = cpufreq_get_driver_data();
69 int ret; 69 int ret;
70 70
71 /* 71 /*
@@ -78,47 +78,37 @@ static int tegra_target_intermediate(struct cpufreq_policy *policy,
78 * Also, we wouldn't be using pll_x anymore and must not take extra 78 * Also, we wouldn't be using pll_x anymore and must not take extra
79 * reference to it, as it can be disabled now to save some power. 79 * reference to it, as it can be disabled now to save some power.
80 */ 80 */
81 clk_prepare_enable(pll_x_clk); 81 clk_prepare_enable(cpufreq->pll_x_clk);
82 82
83 ret = clk_set_parent(cpu_clk, pll_p_clk); 83 ret = clk_set_parent(cpufreq->cpu_clk, cpufreq->pll_p_clk);
84 if (ret) 84 if (ret)
85 clk_disable_unprepare(pll_x_clk); 85 clk_disable_unprepare(cpufreq->pll_x_clk);
86 else 86 else
87 pll_x_prepared = true; 87 cpufreq->pll_x_prepared = true;
88 88
89 return ret; 89 return ret;
90} 90}
91 91
92static int tegra_target(struct cpufreq_policy *policy, unsigned int index) 92static int tegra_target(struct cpufreq_policy *policy, unsigned int index)
93{ 93{
94 struct tegra20_cpufreq *cpufreq = cpufreq_get_driver_data();
94 unsigned long rate = freq_table[index].frequency; 95 unsigned long rate = freq_table[index].frequency;
95 unsigned int ifreq = clk_get_rate(pll_p_clk) / 1000; 96 unsigned int ifreq = clk_get_rate(cpufreq->pll_p_clk) / 1000;
96 int ret = 0; 97 int ret;
97
98 /*
99 * Vote on memory bus frequency based on cpu frequency
100 * This sets the minimum frequency, display or avp may request higher
101 */
102 if (rate >= 816000)
103 clk_set_rate(emc_clk, 600000000); /* cpu 816 MHz, emc max */
104 else if (rate >= 456000)
105 clk_set_rate(emc_clk, 300000000); /* cpu 456 MHz, emc 150Mhz */
106 else
107 clk_set_rate(emc_clk, 100000000); /* emc 50Mhz */
108 98
109 /* 99 /*
110 * target freq == pll_p, don't need to take extra reference to pll_x_clk 100 * target freq == pll_p, don't need to take extra reference to pll_x_clk
111 * as it isn't used anymore. 101 * as it isn't used anymore.
112 */ 102 */
113 if (rate == ifreq) 103 if (rate == ifreq)
114 return clk_set_parent(cpu_clk, pll_p_clk); 104 return clk_set_parent(cpufreq->cpu_clk, cpufreq->pll_p_clk);
115 105
116 ret = clk_set_rate(pll_x_clk, rate * 1000); 106 ret = clk_set_rate(cpufreq->pll_x_clk, rate * 1000);
117 /* Restore to earlier frequency on error, i.e. pll_x */ 107 /* Restore to earlier frequency on error, i.e. pll_x */
118 if (ret) 108 if (ret)
119 pr_err("Failed to change pll_x to %lu\n", rate); 109 dev_err(cpufreq->dev, "Failed to change pll_x to %lu\n", rate);
120 110
121 ret = clk_set_parent(cpu_clk, pll_x_clk); 111 ret = clk_set_parent(cpufreq->cpu_clk, cpufreq->pll_x_clk);
122 /* This shouldn't fail while changing or restoring */ 112 /* This shouldn't fail while changing or restoring */
123 WARN_ON(ret); 113 WARN_ON(ret);
124 114
@@ -126,9 +116,9 @@ static int tegra_target(struct cpufreq_policy *policy, unsigned int index)
126 * Drop count to pll_x clock only if we switched to intermediate freq 116 * Drop count to pll_x clock only if we switched to intermediate freq
127 * earlier while transitioning to a target frequency. 117 * earlier while transitioning to a target frequency.
128 */ 118 */
129 if (pll_x_prepared) { 119 if (cpufreq->pll_x_prepared) {
130 clk_disable_unprepare(pll_x_clk); 120 clk_disable_unprepare(cpufreq->pll_x_clk);
131 pll_x_prepared = false; 121 cpufreq->pll_x_prepared = false;
132 } 122 }
133 123
134 return ret; 124 return ret;
@@ -136,81 +126,111 @@ static int tegra_target(struct cpufreq_policy *policy, unsigned int index)
136 126
137static int tegra_cpu_init(struct cpufreq_policy *policy) 127static int tegra_cpu_init(struct cpufreq_policy *policy)
138{ 128{
129 struct tegra20_cpufreq *cpufreq = cpufreq_get_driver_data();
139 int ret; 130 int ret;
140 131
141 if (policy->cpu >= NUM_CPUS) 132 clk_prepare_enable(cpufreq->cpu_clk);
142 return -EINVAL;
143
144 clk_prepare_enable(emc_clk);
145 clk_prepare_enable(cpu_clk);
146 133
147 /* FIXME: what's the actual transition time? */ 134 /* FIXME: what's the actual transition time? */
148 ret = cpufreq_generic_init(policy, freq_table, 300 * 1000); 135 ret = cpufreq_generic_init(policy, freq_table, 300 * 1000);
149 if (ret) { 136 if (ret) {
150 clk_disable_unprepare(cpu_clk); 137 clk_disable_unprepare(cpufreq->cpu_clk);
151 clk_disable_unprepare(emc_clk);
152 return ret; 138 return ret;
153 } 139 }
154 140
155 policy->clk = cpu_clk; 141 policy->clk = cpufreq->cpu_clk;
156 policy->suspend_freq = freq_table[0].frequency; 142 policy->suspend_freq = freq_table[0].frequency;
157 return 0; 143 return 0;
158} 144}
159 145
160static int tegra_cpu_exit(struct cpufreq_policy *policy) 146static int tegra_cpu_exit(struct cpufreq_policy *policy)
161{ 147{
162 clk_disable_unprepare(cpu_clk); 148 struct tegra20_cpufreq *cpufreq = cpufreq_get_driver_data();
163 clk_disable_unprepare(emc_clk); 149
150 clk_disable_unprepare(cpufreq->cpu_clk);
164 return 0; 151 return 0;
165} 152}
166 153
167static struct cpufreq_driver tegra_cpufreq_driver = { 154static int tegra20_cpufreq_probe(struct platform_device *pdev)
168 .flags = CPUFREQ_NEED_INITIAL_FREQ_CHECK,
169 .verify = cpufreq_generic_frequency_table_verify,
170 .get_intermediate = tegra_get_intermediate,
171 .target_intermediate = tegra_target_intermediate,
172 .target_index = tegra_target,
173 .get = cpufreq_generic_get,
174 .init = tegra_cpu_init,
175 .exit = tegra_cpu_exit,
176 .name = "tegra",
177 .attr = cpufreq_generic_attr,
178 .suspend = cpufreq_generic_suspend,
179};
180
181static int __init tegra_cpufreq_init(void)
182{ 155{
183 cpu_clk = clk_get_sys(NULL, "cclk"); 156 struct tegra20_cpufreq *cpufreq;
184 if (IS_ERR(cpu_clk)) 157 int err;
185 return PTR_ERR(cpu_clk); 158
186 159 cpufreq = devm_kzalloc(&pdev->dev, sizeof(*cpufreq), GFP_KERNEL);
187 pll_x_clk = clk_get_sys(NULL, "pll_x"); 160 if (!cpufreq)
188 if (IS_ERR(pll_x_clk)) 161 return -ENOMEM;
189 return PTR_ERR(pll_x_clk); 162
190 163 cpufreq->cpu_clk = clk_get_sys(NULL, "cclk");
191 pll_p_clk = clk_get_sys(NULL, "pll_p"); 164 if (IS_ERR(cpufreq->cpu_clk))
192 if (IS_ERR(pll_p_clk)) 165 return PTR_ERR(cpufreq->cpu_clk);
193 return PTR_ERR(pll_p_clk); 166
194 167 cpufreq->pll_x_clk = clk_get_sys(NULL, "pll_x");
195 emc_clk = clk_get_sys("cpu", "emc"); 168 if (IS_ERR(cpufreq->pll_x_clk)) {
196 if (IS_ERR(emc_clk)) { 169 err = PTR_ERR(cpufreq->pll_x_clk);
197 clk_put(cpu_clk); 170 goto put_cpu;
198 return PTR_ERR(emc_clk); 171 }
172
173 cpufreq->pll_p_clk = clk_get_sys(NULL, "pll_p");
174 if (IS_ERR(cpufreq->pll_p_clk)) {
175 err = PTR_ERR(cpufreq->pll_p_clk);
176 goto put_pll_x;
199 } 177 }
200 178
201 return cpufreq_register_driver(&tegra_cpufreq_driver); 179 cpufreq->dev = &pdev->dev;
180 cpufreq->driver.get = cpufreq_generic_get;
181 cpufreq->driver.attr = cpufreq_generic_attr;
182 cpufreq->driver.init = tegra_cpu_init;
183 cpufreq->driver.exit = tegra_cpu_exit;
184 cpufreq->driver.flags = CPUFREQ_NEED_INITIAL_FREQ_CHECK;
185 cpufreq->driver.verify = cpufreq_generic_frequency_table_verify;
186 cpufreq->driver.suspend = cpufreq_generic_suspend;
187 cpufreq->driver.driver_data = cpufreq;
188 cpufreq->driver.target_index = tegra_target;
189 cpufreq->driver.get_intermediate = tegra_get_intermediate;
190 cpufreq->driver.target_intermediate = tegra_target_intermediate;
191 snprintf(cpufreq->driver.name, CPUFREQ_NAME_LEN, "tegra");
192
193 err = cpufreq_register_driver(&cpufreq->driver);
194 if (err)
195 goto put_pll_p;
196
197 platform_set_drvdata(pdev, cpufreq);
198
199 return 0;
200
201put_pll_p:
202 clk_put(cpufreq->pll_p_clk);
203put_pll_x:
204 clk_put(cpufreq->pll_x_clk);
205put_cpu:
206 clk_put(cpufreq->cpu_clk);
207
208 return err;
202} 209}
203 210
204static void __exit tegra_cpufreq_exit(void) 211static int tegra20_cpufreq_remove(struct platform_device *pdev)
205{ 212{
206 cpufreq_unregister_driver(&tegra_cpufreq_driver); 213 struct tegra20_cpufreq *cpufreq = platform_get_drvdata(pdev);
207 clk_put(emc_clk); 214
208 clk_put(cpu_clk); 215 cpufreq_unregister_driver(&cpufreq->driver);
216
217 clk_put(cpufreq->pll_p_clk);
218 clk_put(cpufreq->pll_x_clk);
219 clk_put(cpufreq->cpu_clk);
220
221 return 0;
209} 222}
210 223
224static struct platform_driver tegra20_cpufreq_driver = {
225 .probe = tegra20_cpufreq_probe,
226 .remove = tegra20_cpufreq_remove,
227 .driver = {
228 .name = "tegra20-cpufreq",
229 },
230};
231module_platform_driver(tegra20_cpufreq_driver);
211 232
233MODULE_ALIAS("platform:tegra20-cpufreq");
212MODULE_AUTHOR("Colin Cross <ccross@android.com>"); 234MODULE_AUTHOR("Colin Cross <ccross@android.com>");
213MODULE_DESCRIPTION("cpufreq driver for Nvidia Tegra2"); 235MODULE_DESCRIPTION("NVIDIA Tegra20 cpufreq driver");
214MODULE_LICENSE("GPL"); 236MODULE_LICENSE("GPL");
215module_init(tegra_cpufreq_init);
216module_exit(tegra_cpufreq_exit);
diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
index 5d359aff3cc5..9fed1b829292 100644
--- a/drivers/cpuidle/governor.c
+++ b/drivers/cpuidle/governor.c
@@ -8,8 +8,10 @@
8 * This code is licenced under the GPL. 8 * This code is licenced under the GPL.
9 */ 9 */
10 10
11#include <linux/mutex.h> 11#include <linux/cpu.h>
12#include <linux/cpuidle.h> 12#include <linux/cpuidle.h>
13#include <linux/mutex.h>
14#include <linux/pm_qos.h>
13 15
14#include "cpuidle.h" 16#include "cpuidle.h"
15 17
@@ -93,3 +95,16 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
93 95
94 return ret; 96 return ret;
95} 97}
98
99/**
100 * cpuidle_governor_latency_req - Compute a latency constraint for CPU
101 * @cpu: Target CPU
102 */
103int cpuidle_governor_latency_req(unsigned int cpu)
104{
105 int global_req = pm_qos_request(PM_QOS_CPU_DMA_LATENCY);
106 struct device *device = get_cpu_device(cpu);
107 int device_req = dev_pm_qos_raw_read_value(device);
108
109 return device_req < global_req ? device_req : global_req;
110}
diff --git a/drivers/cpuidle/governors/ladder.c b/drivers/cpuidle/governors/ladder.c
index b24883f85c99..704880a6612a 100644
--- a/drivers/cpuidle/governors/ladder.c
+++ b/drivers/cpuidle/governors/ladder.c
@@ -14,10 +14,8 @@
14 14
15#include <linux/kernel.h> 15#include <linux/kernel.h>
16#include <linux/cpuidle.h> 16#include <linux/cpuidle.h>
17#include <linux/pm_qos.h>
18#include <linux/jiffies.h> 17#include <linux/jiffies.h>
19#include <linux/tick.h> 18#include <linux/tick.h>
20#include <linux/cpu.h>
21 19
22#include <asm/io.h> 20#include <asm/io.h>
23#include <linux/uaccess.h> 21#include <linux/uaccess.h>
@@ -69,16 +67,10 @@ static int ladder_select_state(struct cpuidle_driver *drv,
69 struct cpuidle_device *dev, bool *dummy) 67 struct cpuidle_device *dev, bool *dummy)
70{ 68{
71 struct ladder_device *ldev = this_cpu_ptr(&ladder_devices); 69 struct ladder_device *ldev = this_cpu_ptr(&ladder_devices);
72 struct device *device = get_cpu_device(dev->cpu);
73 struct ladder_device_state *last_state; 70 struct ladder_device_state *last_state;
74 int last_residency, last_idx = ldev->last_state_idx; 71 int last_residency, last_idx = ldev->last_state_idx;
75 int first_idx = drv->states[0].flags & CPUIDLE_FLAG_POLLING ? 1 : 0; 72 int first_idx = drv->states[0].flags & CPUIDLE_FLAG_POLLING ? 1 : 0;
76 int latency_req = pm_qos_request(PM_QOS_CPU_DMA_LATENCY); 73 int latency_req = cpuidle_governor_latency_req(dev->cpu);
77 int resume_latency = dev_pm_qos_raw_read_value(device);
78
79 if (resume_latency < latency_req &&
80 resume_latency != PM_QOS_RESUME_LATENCY_NO_CONSTRAINT)
81 latency_req = resume_latency;
82 74
83 /* Special case when user has set very strict latency requirement */ 75 /* Special case when user has set very strict latency requirement */
84 if (unlikely(latency_req == 0)) { 76 if (unlikely(latency_req == 0)) {
diff --git a/drivers/cpuidle/governors/menu.c b/drivers/cpuidle/governors/menu.c
index 1bfe03ceb236..1aef60d160eb 100644
--- a/drivers/cpuidle/governors/menu.c
+++ b/drivers/cpuidle/governors/menu.c
@@ -12,7 +12,6 @@
12 12
13#include <linux/kernel.h> 13#include <linux/kernel.h>
14#include <linux/cpuidle.h> 14#include <linux/cpuidle.h>
15#include <linux/pm_qos.h>
16#include <linux/time.h> 15#include <linux/time.h>
17#include <linux/ktime.h> 16#include <linux/ktime.h>
18#include <linux/hrtimer.h> 17#include <linux/hrtimer.h>
@@ -21,7 +20,6 @@
21#include <linux/sched/loadavg.h> 20#include <linux/sched/loadavg.h>
22#include <linux/sched/stat.h> 21#include <linux/sched/stat.h>
23#include <linux/math64.h> 22#include <linux/math64.h>
24#include <linux/cpu.h>
25 23
26/* 24/*
27 * Please note when changing the tuning values: 25 * Please note when changing the tuning values:
@@ -286,15 +284,13 @@ static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev,
286 bool *stop_tick) 284 bool *stop_tick)
287{ 285{
288 struct menu_device *data = this_cpu_ptr(&menu_devices); 286 struct menu_device *data = this_cpu_ptr(&menu_devices);
289 struct device *device = get_cpu_device(dev->cpu); 287 int latency_req = cpuidle_governor_latency_req(dev->cpu);
290 int latency_req = pm_qos_request(PM_QOS_CPU_DMA_LATENCY);
291 int i; 288 int i;
292 int first_idx; 289 int first_idx;
293 int idx; 290 int idx;
294 unsigned int interactivity_req; 291 unsigned int interactivity_req;
295 unsigned int expected_interval; 292 unsigned int expected_interval;
296 unsigned long nr_iowaiters, cpu_load; 293 unsigned long nr_iowaiters, cpu_load;
297 int resume_latency = dev_pm_qos_raw_read_value(device);
298 ktime_t delta_next; 294 ktime_t delta_next;
299 295
300 if (data->needs_update) { 296 if (data->needs_update) {
@@ -302,10 +298,6 @@ static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev,
302 data->needs_update = 0; 298 data->needs_update = 0;
303 } 299 }
304 300
305 if (resume_latency < latency_req &&
306 resume_latency != PM_QOS_RESUME_LATENCY_NO_CONSTRAINT)
307 latency_req = resume_latency;
308
309 /* Special case when user has set very strict latency requirement */ 301 /* Special case when user has set very strict latency requirement */
310 if (unlikely(latency_req == 0)) { 302 if (unlikely(latency_req == 0)) {
311 *stop_tick = false; 303 *stop_tick = false;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_acp.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_acp.c
index a29362f9ef41..12558044acd4 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_acp.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_acp.c
@@ -513,7 +513,7 @@ static int acp_hw_fini(void *handle)
513 if (adev->acp.acp_genpd) { 513 if (adev->acp.acp_genpd) {
514 for (i = 0; i < ACP_DEVS ; i++) { 514 for (i = 0; i < ACP_DEVS ; i++) {
515 dev = get_mfd_cell_dev(adev->acp.acp_cell[i].name, i); 515 dev = get_mfd_cell_dev(adev->acp.acp_cell[i].name, i);
516 ret = pm_genpd_remove_device(&adev->acp.acp_genpd->gpd, dev); 516 ret = pm_genpd_remove_device(dev);
517 /* If removal fails, dont giveup and try rest */ 517 /* If removal fails, dont giveup and try rest */
518 if (ret) 518 if (ret)
519 dev_err(dev, "remove dev from genpd failed\n"); 519 dev_err(dev, "remove dev from genpd failed\n");
diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index 1ba40bb2b966..a17f46a95f73 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -363,7 +363,7 @@ static int i2c_device_probe(struct device *dev)
363 goto err_clear_wakeup_irq; 363 goto err_clear_wakeup_irq;
364 364
365 status = dev_pm_domain_attach(&client->dev, true); 365 status = dev_pm_domain_attach(&client->dev, true);
366 if (status == -EPROBE_DEFER) 366 if (status)
367 goto err_clear_wakeup_irq; 367 goto err_clear_wakeup_irq;
368 368
369 /* 369 /*
diff --git a/drivers/mmc/core/sdio_bus.c b/drivers/mmc/core/sdio_bus.c
index 2b32b88949ba..b6d8203e46eb 100644
--- a/drivers/mmc/core/sdio_bus.c
+++ b/drivers/mmc/core/sdio_bus.c
@@ -139,7 +139,7 @@ static int sdio_bus_probe(struct device *dev)
139 return -ENODEV; 139 return -ENODEV;
140 140
141 ret = dev_pm_domain_attach(dev, false); 141 ret = dev_pm_domain_attach(dev, false);
142 if (ret == -EPROBE_DEFER) 142 if (ret)
143 return ret; 143 return ret;
144 144
145 /* Unbound SDIO functions are always suspended. 145 /* Unbound SDIO functions are always suspended.
diff --git a/drivers/opp/core.c b/drivers/opp/core.c
index 92fa94a6dcc1..ab2f3fead6b1 100644
--- a/drivers/opp/core.c
+++ b/drivers/opp/core.c
@@ -33,8 +33,6 @@ LIST_HEAD(opp_tables);
33/* Lock to allow exclusive modification to the device and opp lists */ 33/* Lock to allow exclusive modification to the device and opp lists */
34DEFINE_MUTEX(opp_table_lock); 34DEFINE_MUTEX(opp_table_lock);
35 35
36static void dev_pm_opp_get(struct dev_pm_opp *opp);
37
38static struct opp_device *_find_opp_dev(const struct device *dev, 36static struct opp_device *_find_opp_dev(const struct device *dev,
39 struct opp_table *opp_table) 37 struct opp_table *opp_table)
40{ 38{
@@ -281,6 +279,23 @@ unsigned long dev_pm_opp_get_suspend_opp_freq(struct device *dev)
281} 279}
282EXPORT_SYMBOL_GPL(dev_pm_opp_get_suspend_opp_freq); 280EXPORT_SYMBOL_GPL(dev_pm_opp_get_suspend_opp_freq);
283 281
282int _get_opp_count(struct opp_table *opp_table)
283{
284 struct dev_pm_opp *opp;
285 int count = 0;
286
287 mutex_lock(&opp_table->lock);
288
289 list_for_each_entry(opp, &opp_table->opp_list, node) {
290 if (opp->available)
291 count++;
292 }
293
294 mutex_unlock(&opp_table->lock);
295
296 return count;
297}
298
284/** 299/**
285 * dev_pm_opp_get_opp_count() - Get number of opps available in the opp table 300 * dev_pm_opp_get_opp_count() - Get number of opps available in the opp table
286 * @dev: device for which we do this operation 301 * @dev: device for which we do this operation
@@ -291,25 +306,17 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_get_suspend_opp_freq);
291int dev_pm_opp_get_opp_count(struct device *dev) 306int dev_pm_opp_get_opp_count(struct device *dev)
292{ 307{
293 struct opp_table *opp_table; 308 struct opp_table *opp_table;
294 struct dev_pm_opp *temp_opp; 309 int count;
295 int count = 0;
296 310
297 opp_table = _find_opp_table(dev); 311 opp_table = _find_opp_table(dev);
298 if (IS_ERR(opp_table)) { 312 if (IS_ERR(opp_table)) {
299 count = PTR_ERR(opp_table); 313 count = PTR_ERR(opp_table);
300 dev_dbg(dev, "%s: OPP table not found (%d)\n", 314 dev_dbg(dev, "%s: OPP table not found (%d)\n",
301 __func__, count); 315 __func__, count);
302 return count; 316 return 0;
303 }
304
305 mutex_lock(&opp_table->lock);
306
307 list_for_each_entry(temp_opp, &opp_table->opp_list, node) {
308 if (temp_opp->available)
309 count++;
310 } 317 }
311 318
312 mutex_unlock(&opp_table->lock); 319 count = _get_opp_count(opp_table);
313 dev_pm_opp_put_opp_table(opp_table); 320 dev_pm_opp_put_opp_table(opp_table);
314 321
315 return count; 322 return count;
@@ -892,7 +899,7 @@ static void _opp_kref_release(struct kref *kref)
892 dev_pm_opp_put_opp_table(opp_table); 899 dev_pm_opp_put_opp_table(opp_table);
893} 900}
894 901
895static void dev_pm_opp_get(struct dev_pm_opp *opp) 902void dev_pm_opp_get(struct dev_pm_opp *opp)
896{ 903{
897 kref_get(&opp->kref); 904 kref_get(&opp->kref);
898} 905}
@@ -985,22 +992,11 @@ static bool _opp_supported_by_regulators(struct dev_pm_opp *opp,
985 return true; 992 return true;
986} 993}
987 994
988/* 995static int _opp_is_duplicate(struct device *dev, struct dev_pm_opp *new_opp,
989 * Returns: 996 struct opp_table *opp_table,
990 * 0: On success. And appropriate error message for duplicate OPPs. 997 struct list_head **head)
991 * -EBUSY: For OPP with same freq/volt and is available. The callers of
992 * _opp_add() must return 0 if they receive -EBUSY from it. This is to make
993 * sure we don't print error messages unnecessarily if different parts of
994 * kernel try to initialize the OPP table.
995 * -EEXIST: For OPP with same freq but different volt or is unavailable. This
996 * should be considered an error by the callers of _opp_add().
997 */
998int _opp_add(struct device *dev, struct dev_pm_opp *new_opp,
999 struct opp_table *opp_table)
1000{ 998{
1001 struct dev_pm_opp *opp; 999 struct dev_pm_opp *opp;
1002 struct list_head *head;
1003 int ret;
1004 1000
1005 /* 1001 /*
1006 * Insert new OPP in order of increasing frequency and discard if 1002 * Insert new OPP in order of increasing frequency and discard if
@@ -1010,17 +1006,14 @@ int _opp_add(struct device *dev, struct dev_pm_opp *new_opp,
1010 * loop, don't replace it with head otherwise it will become an infinite 1006 * loop, don't replace it with head otherwise it will become an infinite
1011 * loop. 1007 * loop.
1012 */ 1008 */
1013 mutex_lock(&opp_table->lock);
1014 head = &opp_table->opp_list;
1015
1016 list_for_each_entry(opp, &opp_table->opp_list, node) { 1009 list_for_each_entry(opp, &opp_table->opp_list, node) {
1017 if (new_opp->rate > opp->rate) { 1010 if (new_opp->rate > opp->rate) {
1018 head = &opp->node; 1011 *head = &opp->node;
1019 continue; 1012 continue;
1020 } 1013 }
1021 1014
1022 if (new_opp->rate < opp->rate) 1015 if (new_opp->rate < opp->rate)
1023 break; 1016 return 0;
1024 1017
1025 /* Duplicate OPPs */ 1018 /* Duplicate OPPs */
1026 dev_warn(dev, "%s: duplicate OPPs detected. Existing: freq: %lu, volt: %lu, enabled: %d. New: freq: %lu, volt: %lu, enabled: %d\n", 1019 dev_warn(dev, "%s: duplicate OPPs detected. Existing: freq: %lu, volt: %lu, enabled: %d. New: freq: %lu, volt: %lu, enabled: %d\n",
@@ -1029,15 +1022,39 @@ int _opp_add(struct device *dev, struct dev_pm_opp *new_opp,
1029 new_opp->supplies[0].u_volt, new_opp->available); 1022 new_opp->supplies[0].u_volt, new_opp->available);
1030 1023
1031 /* Should we compare voltages for all regulators here ? */ 1024 /* Should we compare voltages for all regulators here ? */
1032 ret = opp->available && 1025 return opp->available &&
1033 new_opp->supplies[0].u_volt == opp->supplies[0].u_volt ? -EBUSY : -EEXIST; 1026 new_opp->supplies[0].u_volt == opp->supplies[0].u_volt ? -EBUSY : -EEXIST;
1034
1035 mutex_unlock(&opp_table->lock);
1036 return ret;
1037 } 1027 }
1038 1028
1039 if (opp_table->get_pstate) 1029 return 0;
1040 new_opp->pstate = opp_table->get_pstate(dev, new_opp->rate); 1030}
1031
1032/*
1033 * Returns:
1034 * 0: On success. And appropriate error message for duplicate OPPs.
1035 * -EBUSY: For OPP with same freq/volt and is available. The callers of
1036 * _opp_add() must return 0 if they receive -EBUSY from it. This is to make
1037 * sure we don't print error messages unnecessarily if different parts of
1038 * kernel try to initialize the OPP table.
1039 * -EEXIST: For OPP with same freq but different volt or is unavailable. This
1040 * should be considered an error by the callers of _opp_add().
1041 */
1042int _opp_add(struct device *dev, struct dev_pm_opp *new_opp,
1043 struct opp_table *opp_table, bool rate_not_available)
1044{
1045 struct list_head *head;
1046 int ret;
1047
1048 mutex_lock(&opp_table->lock);
1049 head = &opp_table->opp_list;
1050
1051 if (likely(!rate_not_available)) {
1052 ret = _opp_is_duplicate(dev, new_opp, opp_table, &head);
1053 if (ret) {
1054 mutex_unlock(&opp_table->lock);
1055 return ret;
1056 }
1057 }
1041 1058
1042 list_add(&new_opp->node, head); 1059 list_add(&new_opp->node, head);
1043 mutex_unlock(&opp_table->lock); 1060 mutex_unlock(&opp_table->lock);
@@ -1104,7 +1121,7 @@ int _opp_add_v1(struct opp_table *opp_table, struct device *dev,
1104 new_opp->available = true; 1121 new_opp->available = true;
1105 new_opp->dynamic = dynamic; 1122 new_opp->dynamic = dynamic;
1106 1123
1107 ret = _opp_add(dev, new_opp, opp_table); 1124 ret = _opp_add(dev, new_opp, opp_table, false);
1108 if (ret) { 1125 if (ret) {
1109 /* Don't return error for duplicate OPPs */ 1126 /* Don't return error for duplicate OPPs */
1110 if (ret == -EBUSY) 1127 if (ret == -EBUSY)
@@ -1140,7 +1157,6 @@ struct opp_table *dev_pm_opp_set_supported_hw(struct device *dev,
1140 const u32 *versions, unsigned int count) 1157 const u32 *versions, unsigned int count)
1141{ 1158{
1142 struct opp_table *opp_table; 1159 struct opp_table *opp_table;
1143 int ret;
1144 1160
1145 opp_table = dev_pm_opp_get_opp_table(dev); 1161 opp_table = dev_pm_opp_get_opp_table(dev);
1146 if (!opp_table) 1162 if (!opp_table)
@@ -1149,29 +1165,20 @@ struct opp_table *dev_pm_opp_set_supported_hw(struct device *dev,
1149 /* Make sure there are no concurrent readers while updating opp_table */ 1165 /* Make sure there are no concurrent readers while updating opp_table */
1150 WARN_ON(!list_empty(&opp_table->opp_list)); 1166 WARN_ON(!list_empty(&opp_table->opp_list));
1151 1167
1152 /* Do we already have a version hierarchy associated with opp_table? */ 1168 /* Another CPU that shares the OPP table has set the property ? */
1153 if (opp_table->supported_hw) { 1169 if (opp_table->supported_hw)
1154 dev_err(dev, "%s: Already have supported hardware list\n", 1170 return opp_table;
1155 __func__);
1156 ret = -EBUSY;
1157 goto err;
1158 }
1159 1171
1160 opp_table->supported_hw = kmemdup(versions, count * sizeof(*versions), 1172 opp_table->supported_hw = kmemdup(versions, count * sizeof(*versions),
1161 GFP_KERNEL); 1173 GFP_KERNEL);
1162 if (!opp_table->supported_hw) { 1174 if (!opp_table->supported_hw) {
1163 ret = -ENOMEM; 1175 dev_pm_opp_put_opp_table(opp_table);
1164 goto err; 1176 return ERR_PTR(-ENOMEM);
1165 } 1177 }
1166 1178
1167 opp_table->supported_hw_count = count; 1179 opp_table->supported_hw_count = count;
1168 1180
1169 return opp_table; 1181 return opp_table;
1170
1171err:
1172 dev_pm_opp_put_opp_table(opp_table);
1173
1174 return ERR_PTR(ret);
1175} 1182}
1176EXPORT_SYMBOL_GPL(dev_pm_opp_set_supported_hw); 1183EXPORT_SYMBOL_GPL(dev_pm_opp_set_supported_hw);
1177 1184
@@ -1188,12 +1195,6 @@ void dev_pm_opp_put_supported_hw(struct opp_table *opp_table)
1188 /* Make sure there are no concurrent readers while updating opp_table */ 1195 /* Make sure there are no concurrent readers while updating opp_table */
1189 WARN_ON(!list_empty(&opp_table->opp_list)); 1196 WARN_ON(!list_empty(&opp_table->opp_list));
1190 1197
1191 if (!opp_table->supported_hw) {
1192 pr_err("%s: Doesn't have supported hardware list\n",
1193 __func__);
1194 return;
1195 }
1196
1197 kfree(opp_table->supported_hw); 1198 kfree(opp_table->supported_hw);
1198 opp_table->supported_hw = NULL; 1199 opp_table->supported_hw = NULL;
1199 opp_table->supported_hw_count = 0; 1200 opp_table->supported_hw_count = 0;
@@ -1215,7 +1216,6 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_put_supported_hw);
1215struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, const char *name) 1216struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, const char *name)
1216{ 1217{
1217 struct opp_table *opp_table; 1218 struct opp_table *opp_table;
1218 int ret;
1219 1219
1220 opp_table = dev_pm_opp_get_opp_table(dev); 1220 opp_table = dev_pm_opp_get_opp_table(dev);
1221 if (!opp_table) 1221 if (!opp_table)
@@ -1224,26 +1224,17 @@ struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, const char *name)
1224 /* Make sure there are no concurrent readers while updating opp_table */ 1224 /* Make sure there are no concurrent readers while updating opp_table */
1225 WARN_ON(!list_empty(&opp_table->opp_list)); 1225 WARN_ON(!list_empty(&opp_table->opp_list));
1226 1226
1227 /* Do we already have a prop-name associated with opp_table? */ 1227 /* Another CPU that shares the OPP table has set the property ? */
1228 if (opp_table->prop_name) { 1228 if (opp_table->prop_name)
1229 dev_err(dev, "%s: Already have prop-name %s\n", __func__, 1229 return opp_table;
1230 opp_table->prop_name);
1231 ret = -EBUSY;
1232 goto err;
1233 }
1234 1230
1235 opp_table->prop_name = kstrdup(name, GFP_KERNEL); 1231 opp_table->prop_name = kstrdup(name, GFP_KERNEL);
1236 if (!opp_table->prop_name) { 1232 if (!opp_table->prop_name) {
1237 ret = -ENOMEM; 1233 dev_pm_opp_put_opp_table(opp_table);
1238 goto err; 1234 return ERR_PTR(-ENOMEM);
1239 } 1235 }
1240 1236
1241 return opp_table; 1237 return opp_table;
1242
1243err:
1244 dev_pm_opp_put_opp_table(opp_table);
1245
1246 return ERR_PTR(ret);
1247} 1238}
1248EXPORT_SYMBOL_GPL(dev_pm_opp_set_prop_name); 1239EXPORT_SYMBOL_GPL(dev_pm_opp_set_prop_name);
1249 1240
@@ -1260,11 +1251,6 @@ void dev_pm_opp_put_prop_name(struct opp_table *opp_table)
1260 /* Make sure there are no concurrent readers while updating opp_table */ 1251 /* Make sure there are no concurrent readers while updating opp_table */
1261 WARN_ON(!list_empty(&opp_table->opp_list)); 1252 WARN_ON(!list_empty(&opp_table->opp_list));
1262 1253
1263 if (!opp_table->prop_name) {
1264 pr_err("%s: Doesn't have a prop-name\n", __func__);
1265 return;
1266 }
1267
1268 kfree(opp_table->prop_name); 1254 kfree(opp_table->prop_name);
1269 opp_table->prop_name = NULL; 1255 opp_table->prop_name = NULL;
1270 1256
@@ -1334,11 +1320,9 @@ struct opp_table *dev_pm_opp_set_regulators(struct device *dev,
1334 goto err; 1320 goto err;
1335 } 1321 }
1336 1322
1337 /* Already have regulators set */ 1323 /* Another CPU that shares the OPP table has set the regulators ? */
1338 if (opp_table->regulators) { 1324 if (opp_table->regulators)
1339 ret = -EBUSY; 1325 return opp_table;
1340 goto err;
1341 }
1342 1326
1343 opp_table->regulators = kmalloc_array(count, 1327 opp_table->regulators = kmalloc_array(count,
1344 sizeof(*opp_table->regulators), 1328 sizeof(*opp_table->regulators),
@@ -1392,10 +1376,8 @@ void dev_pm_opp_put_regulators(struct opp_table *opp_table)
1392{ 1376{
1393 int i; 1377 int i;
1394 1378
1395 if (!opp_table->regulators) { 1379 if (!opp_table->regulators)
1396 pr_err("%s: Doesn't have regulators set\n", __func__); 1380 goto put_opp_table;
1397 return;
1398 }
1399 1381
1400 /* Make sure there are no concurrent readers while updating opp_table */ 1382 /* Make sure there are no concurrent readers while updating opp_table */
1401 WARN_ON(!list_empty(&opp_table->opp_list)); 1383 WARN_ON(!list_empty(&opp_table->opp_list));
@@ -1409,6 +1391,7 @@ void dev_pm_opp_put_regulators(struct opp_table *opp_table)
1409 opp_table->regulators = NULL; 1391 opp_table->regulators = NULL;
1410 opp_table->regulator_count = 0; 1392 opp_table->regulator_count = 0;
1411 1393
1394put_opp_table:
1412 dev_pm_opp_put_opp_table(opp_table); 1395 dev_pm_opp_put_opp_table(opp_table);
1413} 1396}
1414EXPORT_SYMBOL_GPL(dev_pm_opp_put_regulators); 1397EXPORT_SYMBOL_GPL(dev_pm_opp_put_regulators);
@@ -1494,7 +1477,6 @@ struct opp_table *dev_pm_opp_register_set_opp_helper(struct device *dev,
1494 int (*set_opp)(struct dev_pm_set_opp_data *data)) 1477 int (*set_opp)(struct dev_pm_set_opp_data *data))
1495{ 1478{
1496 struct opp_table *opp_table; 1479 struct opp_table *opp_table;
1497 int ret;
1498 1480
1499 if (!set_opp) 1481 if (!set_opp)
1500 return ERR_PTR(-EINVAL); 1482 return ERR_PTR(-EINVAL);
@@ -1505,24 +1487,15 @@ struct opp_table *dev_pm_opp_register_set_opp_helper(struct device *dev,
1505 1487
1506 /* This should be called before OPPs are initialized */ 1488 /* This should be called before OPPs are initialized */
1507 if (WARN_ON(!list_empty(&opp_table->opp_list))) { 1489 if (WARN_ON(!list_empty(&opp_table->opp_list))) {
1508 ret = -EBUSY; 1490 dev_pm_opp_put_opp_table(opp_table);
1509 goto err; 1491 return ERR_PTR(-EBUSY);
1510 }
1511
1512 /* Already have custom set_opp helper */
1513 if (WARN_ON(opp_table->set_opp)) {
1514 ret = -EBUSY;
1515 goto err;
1516 } 1492 }
1517 1493
1518 opp_table->set_opp = set_opp; 1494 /* Another CPU that shares the OPP table has set the helper ? */
1495 if (!opp_table->set_opp)
1496 opp_table->set_opp = set_opp;
1519 1497
1520 return opp_table; 1498 return opp_table;
1521
1522err:
1523 dev_pm_opp_put_opp_table(opp_table);
1524
1525 return ERR_PTR(ret);
1526} 1499}
1527EXPORT_SYMBOL_GPL(dev_pm_opp_register_set_opp_helper); 1500EXPORT_SYMBOL_GPL(dev_pm_opp_register_set_opp_helper);
1528 1501
@@ -1535,97 +1508,15 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_register_set_opp_helper);
1535 */ 1508 */
1536void dev_pm_opp_unregister_set_opp_helper(struct opp_table *opp_table) 1509void dev_pm_opp_unregister_set_opp_helper(struct opp_table *opp_table)
1537{ 1510{
1538 if (!opp_table->set_opp) {
1539 pr_err("%s: Doesn't have custom set_opp helper set\n",
1540 __func__);
1541 return;
1542 }
1543
1544 /* Make sure there are no concurrent readers while updating opp_table */ 1511 /* Make sure there are no concurrent readers while updating opp_table */
1545 WARN_ON(!list_empty(&opp_table->opp_list)); 1512 WARN_ON(!list_empty(&opp_table->opp_list));
1546 1513
1547 opp_table->set_opp = NULL; 1514 opp_table->set_opp = NULL;
1548
1549 dev_pm_opp_put_opp_table(opp_table); 1515 dev_pm_opp_put_opp_table(opp_table);
1550} 1516}
1551EXPORT_SYMBOL_GPL(dev_pm_opp_unregister_set_opp_helper); 1517EXPORT_SYMBOL_GPL(dev_pm_opp_unregister_set_opp_helper);
1552 1518
1553/** 1519/**
1554 * dev_pm_opp_register_get_pstate_helper() - Register get_pstate() helper.
1555 * @dev: Device for which the helper is getting registered.
1556 * @get_pstate: Helper.
1557 *
1558 * TODO: Remove this callback after the same information is available via Device
1559 * Tree.
1560 *
1561 * This allows a platform to initialize the performance states of individual
1562 * OPPs for its devices, until we get similar information directly from DT.
1563 *
1564 * This must be called before the OPPs are initialized for the device.
1565 */
1566struct opp_table *dev_pm_opp_register_get_pstate_helper(struct device *dev,
1567 int (*get_pstate)(struct device *dev, unsigned long rate))
1568{
1569 struct opp_table *opp_table;
1570 int ret;
1571
1572 if (!get_pstate)
1573 return ERR_PTR(-EINVAL);
1574
1575 opp_table = dev_pm_opp_get_opp_table(dev);
1576 if (!opp_table)
1577 return ERR_PTR(-ENOMEM);
1578
1579 /* This should be called before OPPs are initialized */
1580 if (WARN_ON(!list_empty(&opp_table->opp_list))) {
1581 ret = -EBUSY;
1582 goto err;
1583 }
1584
1585 /* Already have genpd_performance_state set */
1586 if (WARN_ON(opp_table->genpd_performance_state)) {
1587 ret = -EBUSY;
1588 goto err;
1589 }
1590
1591 opp_table->genpd_performance_state = true;
1592 opp_table->get_pstate = get_pstate;
1593
1594 return opp_table;
1595
1596err:
1597 dev_pm_opp_put_opp_table(opp_table);
1598
1599 return ERR_PTR(ret);
1600}
1601EXPORT_SYMBOL_GPL(dev_pm_opp_register_get_pstate_helper);
1602
1603/**
1604 * dev_pm_opp_unregister_get_pstate_helper() - Releases resources blocked for
1605 * get_pstate() helper
1606 * @opp_table: OPP table returned from dev_pm_opp_register_get_pstate_helper().
1607 *
1608 * Release resources blocked for platform specific get_pstate() helper.
1609 */
1610void dev_pm_opp_unregister_get_pstate_helper(struct opp_table *opp_table)
1611{
1612 if (!opp_table->genpd_performance_state) {
1613 pr_err("%s: Doesn't have performance states set\n",
1614 __func__);
1615 return;
1616 }
1617
1618 /* Make sure there are no concurrent readers while updating opp_table */
1619 WARN_ON(!list_empty(&opp_table->opp_list));
1620
1621 opp_table->genpd_performance_state = false;
1622 opp_table->get_pstate = NULL;
1623
1624 dev_pm_opp_put_opp_table(opp_table);
1625}
1626EXPORT_SYMBOL_GPL(dev_pm_opp_unregister_get_pstate_helper);
1627
1628/**
1629 * dev_pm_opp_add() - Add an OPP table from a table definitions 1520 * dev_pm_opp_add() - Add an OPP table from a table definitions
1630 * @dev: device for which we do this operation 1521 * @dev: device for which we do this operation
1631 * @freq: Frequency in Hz for this OPP 1522 * @freq: Frequency in Hz for this OPP
diff --git a/drivers/opp/debugfs.c b/drivers/opp/debugfs.c
index b03c03576a62..e6828e5f81b0 100644
--- a/drivers/opp/debugfs.c
+++ b/drivers/opp/debugfs.c
@@ -77,10 +77,21 @@ int opp_debug_create_one(struct dev_pm_opp *opp, struct opp_table *opp_table)
77{ 77{
78 struct dentry *pdentry = opp_table->dentry; 78 struct dentry *pdentry = opp_table->dentry;
79 struct dentry *d; 79 struct dentry *d;
80 unsigned long id;
80 char name[25]; /* 20 chars for 64 bit value + 5 (opp:\0) */ 81 char name[25]; /* 20 chars for 64 bit value + 5 (opp:\0) */
81 82
82 /* Rate is unique to each OPP, use it to give opp-name */ 83 /*
83 snprintf(name, sizeof(name), "opp:%lu", opp->rate); 84 * Get directory name for OPP.
85 *
86 * - Normally rate is unique to each OPP, use it to get unique opp-name.
87 * - For some devices rate isn't available, use index instead.
88 */
89 if (likely(opp->rate))
90 id = opp->rate;
91 else
92 id = _get_opp_count(opp_table);
93
94 snprintf(name, sizeof(name), "opp:%lu", id);
84 95
85 /* Create per-opp directory */ 96 /* Create per-opp directory */
86 d = debugfs_create_dir(name, pdentry); 97 d = debugfs_create_dir(name, pdentry);
diff --git a/drivers/opp/of.c b/drivers/opp/of.c
index cb716aa2f44b..7af0ddec936b 100644
--- a/drivers/opp/of.c
+++ b/drivers/opp/of.c
@@ -17,6 +17,7 @@
17#include <linux/errno.h> 17#include <linux/errno.h>
18#include <linux/device.h> 18#include <linux/device.h>
19#include <linux/of_device.h> 19#include <linux/of_device.h>
20#include <linux/pm_domain.h>
20#include <linux/slab.h> 21#include <linux/slab.h>
21#include <linux/export.h> 22#include <linux/export.h>
22 23
@@ -250,20 +251,17 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_of_remove_table);
250 251
251/* Returns opp descriptor node for a device node, caller must 252/* Returns opp descriptor node for a device node, caller must
252 * do of_node_put() */ 253 * do of_node_put() */
253static struct device_node *_opp_of_get_opp_desc_node(struct device_node *np) 254static struct device_node *_opp_of_get_opp_desc_node(struct device_node *np,
255 int index)
254{ 256{
255 /* 257 /* "operating-points-v2" can be an array for power domain providers */
256 * There should be only ONE phandle present in "operating-points-v2" 258 return of_parse_phandle(np, "operating-points-v2", index);
257 * property.
258 */
259
260 return of_parse_phandle(np, "operating-points-v2", 0);
261} 259}
262 260
263/* Returns opp descriptor node for a device, caller must do of_node_put() */ 261/* Returns opp descriptor node for a device, caller must do of_node_put() */
264struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev) 262struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev)
265{ 263{
266 return _opp_of_get_opp_desc_node(dev->of_node); 264 return _opp_of_get_opp_desc_node(dev->of_node, 0);
267} 265}
268EXPORT_SYMBOL_GPL(dev_pm_opp_of_get_opp_desc_node); 266EXPORT_SYMBOL_GPL(dev_pm_opp_of_get_opp_desc_node);
269 267
@@ -289,9 +287,10 @@ static int _opp_add_static_v2(struct opp_table *opp_table, struct device *dev,
289 struct device_node *np) 287 struct device_node *np)
290{ 288{
291 struct dev_pm_opp *new_opp; 289 struct dev_pm_opp *new_opp;
292 u64 rate; 290 u64 rate = 0;
293 u32 val; 291 u32 val;
294 int ret; 292 int ret;
293 bool rate_not_available = false;
295 294
296 new_opp = _opp_allocate(opp_table); 295 new_opp = _opp_allocate(opp_table);
297 if (!new_opp) 296 if (!new_opp)
@@ -299,8 +298,21 @@ static int _opp_add_static_v2(struct opp_table *opp_table, struct device *dev,
299 298
300 ret = of_property_read_u64(np, "opp-hz", &rate); 299 ret = of_property_read_u64(np, "opp-hz", &rate);
301 if (ret < 0) { 300 if (ret < 0) {
302 dev_err(dev, "%s: opp-hz not found\n", __func__); 301 /* "opp-hz" is optional for devices like power domains. */
303 goto free_opp; 302 if (!of_find_property(dev->of_node, "#power-domain-cells",
303 NULL)) {
304 dev_err(dev, "%s: opp-hz not found\n", __func__);
305 goto free_opp;
306 }
307
308 rate_not_available = true;
309 } else {
310 /*
311 * Rate is defined as an unsigned long in clk API, and so
312 * casting explicitly to its type. Must be fixed once rate is 64
313 * bit guaranteed in clk API.
314 */
315 new_opp->rate = (unsigned long)rate;
304 } 316 }
305 317
306 /* Check if the OPP supports hardware's hierarchy of versions or not */ 318 /* Check if the OPP supports hardware's hierarchy of versions or not */
@@ -309,12 +321,6 @@ static int _opp_add_static_v2(struct opp_table *opp_table, struct device *dev,
309 goto free_opp; 321 goto free_opp;
310 } 322 }
311 323
312 /*
313 * Rate is defined as an unsigned long in clk API, and so casting
314 * explicitly to its type. Must be fixed once rate is 64 bit
315 * guaranteed in clk API.
316 */
317 new_opp->rate = (unsigned long)rate;
318 new_opp->turbo = of_property_read_bool(np, "turbo-mode"); 324 new_opp->turbo = of_property_read_bool(np, "turbo-mode");
319 325
320 new_opp->np = np; 326 new_opp->np = np;
@@ -324,11 +330,13 @@ static int _opp_add_static_v2(struct opp_table *opp_table, struct device *dev,
324 if (!of_property_read_u32(np, "clock-latency-ns", &val)) 330 if (!of_property_read_u32(np, "clock-latency-ns", &val))
325 new_opp->clock_latency_ns = val; 331 new_opp->clock_latency_ns = val;
326 332
333 new_opp->pstate = of_genpd_opp_to_performance_state(dev, np);
334
327 ret = opp_parse_supplies(new_opp, dev, opp_table); 335 ret = opp_parse_supplies(new_opp, dev, opp_table);
328 if (ret) 336 if (ret)
329 goto free_opp; 337 goto free_opp;
330 338
331 ret = _opp_add(dev, new_opp, opp_table); 339 ret = _opp_add(dev, new_opp, opp_table, rate_not_available);
332 if (ret) { 340 if (ret) {
333 /* Don't return error for duplicate OPPs */ 341 /* Don't return error for duplicate OPPs */
334 if (ret == -EBUSY) 342 if (ret == -EBUSY)
@@ -374,7 +382,8 @@ static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np)
374{ 382{
375 struct device_node *np; 383 struct device_node *np;
376 struct opp_table *opp_table; 384 struct opp_table *opp_table;
377 int ret = 0, count = 0; 385 int ret = 0, count = 0, pstate_count = 0;
386 struct dev_pm_opp *opp;
378 387
379 opp_table = _managed_opp(opp_np); 388 opp_table = _managed_opp(opp_np);
380 if (opp_table) { 389 if (opp_table) {
@@ -408,6 +417,20 @@ static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np)
408 goto put_opp_table; 417 goto put_opp_table;
409 } 418 }
410 419
420 list_for_each_entry(opp, &opp_table->opp_list, node)
421 pstate_count += !!opp->pstate;
422
423 /* Either all or none of the nodes shall have performance state set */
424 if (pstate_count && pstate_count != count) {
425 dev_err(dev, "Not all nodes have performance state set (%d: %d)\n",
426 count, pstate_count);
427 ret = -ENOENT;
428 goto put_opp_table;
429 }
430
431 if (pstate_count)
432 opp_table->genpd_performance_state = true;
433
411 opp_table->np = opp_np; 434 opp_table->np = opp_np;
412 if (of_property_read_bool(opp_np, "opp-shared")) 435 if (of_property_read_bool(opp_np, "opp-shared"))
413 opp_table->shared_opp = OPP_TABLE_ACCESS_SHARED; 436 opp_table->shared_opp = OPP_TABLE_ACCESS_SHARED;
@@ -509,6 +532,54 @@ int dev_pm_opp_of_add_table(struct device *dev)
509} 532}
510EXPORT_SYMBOL_GPL(dev_pm_opp_of_add_table); 533EXPORT_SYMBOL_GPL(dev_pm_opp_of_add_table);
511 534
535/**
536 * dev_pm_opp_of_add_table_indexed() - Initialize indexed opp table from device tree
537 * @dev: device pointer used to lookup OPP table.
538 * @index: Index number.
539 *
540 * Register the initial OPP table with the OPP library for given device only
541 * using the "operating-points-v2" property.
542 *
543 * Return:
544 * 0 On success OR
545 * Duplicate OPPs (both freq and volt are same) and opp->available
546 * -EEXIST Freq are same and volt are different OR
547 * Duplicate OPPs (both freq and volt are same) and !opp->available
548 * -ENOMEM Memory allocation failure
549 * -ENODEV when 'operating-points' property is not found or is invalid data
550 * in device node.
551 * -ENODATA when empty 'operating-points' property is found
552 * -EINVAL when invalid entries are found in opp-v2 table
553 */
554int dev_pm_opp_of_add_table_indexed(struct device *dev, int index)
555{
556 struct device_node *opp_np;
557 int ret, count;
558
559again:
560 opp_np = _opp_of_get_opp_desc_node(dev->of_node, index);
561 if (!opp_np) {
562 /*
563 * If only one phandle is present, then the same OPP table
564 * applies for all index requests.
565 */
566 count = of_count_phandle_with_args(dev->of_node,
567 "operating-points-v2", NULL);
568 if (count == 1 && index) {
569 index = 0;
570 goto again;
571 }
572
573 return -ENODEV;
574 }
575
576 ret = _of_add_opp_table_v2(dev, opp_np);
577 of_node_put(opp_np);
578
579 return ret;
580}
581EXPORT_SYMBOL_GPL(dev_pm_opp_of_add_table_indexed);
582
512/* CPU device specific helpers */ 583/* CPU device specific helpers */
513 584
514/** 585/**
@@ -613,7 +684,7 @@ int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev,
613 } 684 }
614 685
615 /* Get OPP descriptor node */ 686 /* Get OPP descriptor node */
616 tmp_np = _opp_of_get_opp_desc_node(cpu_np); 687 tmp_np = _opp_of_get_opp_desc_node(cpu_np, 0);
617 of_node_put(cpu_np); 688 of_node_put(cpu_np);
618 if (!tmp_np) { 689 if (!tmp_np) {
619 pr_err("%pOF: Couldn't find opp node\n", cpu_np); 690 pr_err("%pOF: Couldn't find opp node\n", cpu_np);
@@ -633,3 +704,76 @@ put_cpu_node:
633 return ret; 704 return ret;
634} 705}
635EXPORT_SYMBOL_GPL(dev_pm_opp_of_get_sharing_cpus); 706EXPORT_SYMBOL_GPL(dev_pm_opp_of_get_sharing_cpus);
707
708/**
709 * of_dev_pm_opp_find_required_opp() - Search for required OPP.
710 * @dev: The device whose OPP node is referenced by the 'np' DT node.
711 * @np: Node that contains the "required-opps" property.
712 *
713 * Returns the OPP of the device 'dev', whose phandle is present in the "np"
714 * node. Although the "required-opps" property supports having multiple
715 * phandles, this helper routine only parses the very first phandle in the list.
716 *
717 * Return: Matching opp, else returns ERR_PTR in case of error and should be
718 * handled using IS_ERR.
719 *
720 * The callers are required to call dev_pm_opp_put() for the returned OPP after
721 * use.
722 */
723struct dev_pm_opp *of_dev_pm_opp_find_required_opp(struct device *dev,
724 struct device_node *np)
725{
726 struct dev_pm_opp *temp_opp, *opp = ERR_PTR(-ENODEV);
727 struct device_node *required_np;
728 struct opp_table *opp_table;
729
730 opp_table = _find_opp_table(dev);
731 if (IS_ERR(opp_table))
732 return ERR_CAST(opp_table);
733
734 required_np = of_parse_phandle(np, "required-opps", 0);
735 if (unlikely(!required_np)) {
736 dev_err(dev, "Unable to parse required-opps\n");
737 goto put_opp_table;
738 }
739
740 mutex_lock(&opp_table->lock);
741
742 list_for_each_entry(temp_opp, &opp_table->opp_list, node) {
743 if (temp_opp->available && temp_opp->np == required_np) {
744 opp = temp_opp;
745
746 /* Increment the reference count of OPP */
747 dev_pm_opp_get(opp);
748 break;
749 }
750 }
751
752 mutex_unlock(&opp_table->lock);
753
754 of_node_put(required_np);
755put_opp_table:
756 dev_pm_opp_put_opp_table(opp_table);
757
758 return opp;
759}
760EXPORT_SYMBOL_GPL(of_dev_pm_opp_find_required_opp);
761
762/**
763 * dev_pm_opp_get_of_node() - Gets the DT node corresponding to an opp
764 * @opp: opp for which DT node has to be returned for
765 *
766 * Return: DT node corresponding to the opp, else 0 on success.
767 *
768 * The caller needs to put the node with of_node_put() after using it.
769 */
770struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp)
771{
772 if (IS_ERR_OR_NULL(opp)) {
773 pr_err("%s: Invalid parameters\n", __func__);
774 return NULL;
775 }
776
777 return of_node_get(opp->np);
778}
779EXPORT_SYMBOL_GPL(dev_pm_opp_get_of_node);
diff --git a/drivers/opp/opp.h b/drivers/opp/opp.h
index 4d00061648a3..7c540fd063b2 100644
--- a/drivers/opp/opp.h
+++ b/drivers/opp/opp.h
@@ -140,7 +140,6 @@ enum opp_table_access {
140 * @genpd_performance_state: Device's power domain support performance state. 140 * @genpd_performance_state: Device's power domain support performance state.
141 * @set_opp: Platform specific set_opp callback 141 * @set_opp: Platform specific set_opp callback
142 * @set_opp_data: Data to be passed to set_opp callback 142 * @set_opp_data: Data to be passed to set_opp callback
143 * @get_pstate: Platform specific get_pstate callback
144 * @dentry: debugfs dentry pointer of the real device directory (not links). 143 * @dentry: debugfs dentry pointer of the real device directory (not links).
145 * @dentry_name: Name of the real dentry. 144 * @dentry_name: Name of the real dentry.
146 * 145 *
@@ -178,7 +177,6 @@ struct opp_table {
178 177
179 int (*set_opp)(struct dev_pm_set_opp_data *data); 178 int (*set_opp)(struct dev_pm_set_opp_data *data);
180 struct dev_pm_set_opp_data *set_opp_data; 179 struct dev_pm_set_opp_data *set_opp_data;
181 int (*get_pstate)(struct device *dev, unsigned long rate);
182 180
183#ifdef CONFIG_DEBUG_FS 181#ifdef CONFIG_DEBUG_FS
184 struct dentry *dentry; 182 struct dentry *dentry;
@@ -187,14 +185,16 @@ struct opp_table {
187}; 185};
188 186
189/* Routines internal to opp core */ 187/* Routines internal to opp core */
188void dev_pm_opp_get(struct dev_pm_opp *opp);
190void _get_opp_table_kref(struct opp_table *opp_table); 189void _get_opp_table_kref(struct opp_table *opp_table);
190int _get_opp_count(struct opp_table *opp_table);
191struct opp_table *_find_opp_table(struct device *dev); 191struct opp_table *_find_opp_table(struct device *dev);
192struct opp_device *_add_opp_dev(const struct device *dev, struct opp_table *opp_table); 192struct opp_device *_add_opp_dev(const struct device *dev, struct opp_table *opp_table);
193void _dev_pm_opp_remove_table(struct opp_table *opp_table, struct device *dev, bool remove_all); 193void _dev_pm_opp_remove_table(struct opp_table *opp_table, struct device *dev, bool remove_all);
194void _dev_pm_opp_find_and_remove_table(struct device *dev, bool remove_all); 194void _dev_pm_opp_find_and_remove_table(struct device *dev, bool remove_all);
195struct dev_pm_opp *_opp_allocate(struct opp_table *opp_table); 195struct dev_pm_opp *_opp_allocate(struct opp_table *opp_table);
196void _opp_free(struct dev_pm_opp *opp); 196void _opp_free(struct dev_pm_opp *opp);
197int _opp_add(struct device *dev, struct dev_pm_opp *new_opp, struct opp_table *opp_table); 197int _opp_add(struct device *dev, struct dev_pm_opp *new_opp, struct opp_table *opp_table, bool rate_not_available);
198int _opp_add_v1(struct opp_table *opp_table, struct device *dev, unsigned long freq, long u_volt, bool dynamic); 198int _opp_add_v1(struct opp_table *opp_table, struct device *dev, unsigned long freq, long u_volt, bool dynamic);
199void _dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask, bool of); 199void _dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask, bool of);
200struct opp_table *_add_opp_table(struct device *dev); 200struct opp_table *_add_opp_table(struct device *dev);
diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
index f8269a725667..18ba62c76480 100644
--- a/drivers/pci/pci-driver.c
+++ b/drivers/pci/pci-driver.c
@@ -755,10 +755,11 @@ static int pci_pm_suspend(struct device *dev)
755 * better to resume the device from runtime suspend here. 755 * better to resume the device from runtime suspend here.
756 */ 756 */
757 if (!dev_pm_test_driver_flags(dev, DPM_FLAG_SMART_SUSPEND) || 757 if (!dev_pm_test_driver_flags(dev, DPM_FLAG_SMART_SUSPEND) ||
758 !pci_dev_keep_suspended(pci_dev)) 758 !pci_dev_keep_suspended(pci_dev)) {
759 pm_runtime_resume(dev); 759 pm_runtime_resume(dev);
760 pci_dev->state_saved = false;
761 }
760 762
761 pci_dev->state_saved = false;
762 if (pm->suspend) { 763 if (pm->suspend) {
763 pci_power_t prev = pci_dev->current_state; 764 pci_power_t prev = pci_dev->current_state;
764 int error; 765 int error;
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index dbfe7c4f3776..e90cf5c32e14 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -2025,8 +2025,7 @@ static pci_power_t pci_target_state(struct pci_dev *dev, bool wakeup)
2025 2025
2026 if (platform_pci_power_manageable(dev)) { 2026 if (platform_pci_power_manageable(dev)) {
2027 /* 2027 /*
2028 * Call the platform to choose the target state of the device 2028 * Call the platform to find the target state for the device.
2029 * and enable wake-up from this state if supported.
2030 */ 2029 */
2031 pci_power_t state = platform_pci_choose_state(dev); 2030 pci_power_t state = platform_pci_choose_state(dev);
2032 2031
@@ -2059,8 +2058,7 @@ static pci_power_t pci_target_state(struct pci_dev *dev, bool wakeup)
2059 if (wakeup) { 2058 if (wakeup) {
2060 /* 2059 /*
2061 * Find the deepest state from which the device can generate 2060 * Find the deepest state from which the device can generate
2062 * wake-up events, make it the target state and enable device 2061 * PME#.
2063 * to generate PME#.
2064 */ 2062 */
2065 if (dev->pme_support) { 2063 if (dev->pme_support) {
2066 while (target_state 2064 while (target_state
diff --git a/drivers/power/avs/rockchip-io-domain.c b/drivers/power/avs/rockchip-io-domain.c
index ed2b109ae8fc..d6a5e6bf5f12 100644
--- a/drivers/power/avs/rockchip-io-domain.c
+++ b/drivers/power/avs/rockchip-io-domain.c
@@ -39,6 +39,10 @@
39#define MAX_VOLTAGE_1_8 1980000 39#define MAX_VOLTAGE_1_8 1980000
40#define MAX_VOLTAGE_3_3 3600000 40#define MAX_VOLTAGE_3_3 3600000
41 41
42#define PX30_IO_VSEL 0x180
43#define PX30_IO_VSEL_VCCIO6_SRC BIT(0)
44#define PX30_IO_VSEL_VCCIO6_SUPPLY_NUM 1
45
42#define RK3288_SOC_CON2 0x24c 46#define RK3288_SOC_CON2 0x24c
43#define RK3288_SOC_CON2_FLASH0 BIT(7) 47#define RK3288_SOC_CON2_FLASH0 BIT(7)
44#define RK3288_SOC_FLASH_SUPPLY_NUM 2 48#define RK3288_SOC_FLASH_SUPPLY_NUM 2
@@ -151,6 +155,25 @@ static int rockchip_iodomain_notify(struct notifier_block *nb,
151 return NOTIFY_OK; 155 return NOTIFY_OK;
152} 156}
153 157
158static void px30_iodomain_init(struct rockchip_iodomain *iod)
159{
160 int ret;
161 u32 val;
162
163 /* if no VCCIO0 supply we should leave things alone */
164 if (!iod->supplies[PX30_IO_VSEL_VCCIO6_SUPPLY_NUM].reg)
165 return;
166
167 /*
168 * set vccio0 iodomain to also use this framework
169 * instead of a special gpio.
170 */
171 val = PX30_IO_VSEL_VCCIO6_SRC | (PX30_IO_VSEL_VCCIO6_SRC << 16);
172 ret = regmap_write(iod->grf, PX30_IO_VSEL, val);
173 if (ret < 0)
174 dev_warn(iod->dev, "couldn't update vccio0 ctrl\n");
175}
176
154static void rk3288_iodomain_init(struct rockchip_iodomain *iod) 177static void rk3288_iodomain_init(struct rockchip_iodomain *iod)
155{ 178{
156 int ret; 179 int ret;
@@ -227,6 +250,43 @@ static void rk3399_pmu_iodomain_init(struct rockchip_iodomain *iod)
227 dev_warn(iod->dev, "couldn't update pmu io iodomain ctrl\n"); 250 dev_warn(iod->dev, "couldn't update pmu io iodomain ctrl\n");
228} 251}
229 252
253static const struct rockchip_iodomain_soc_data soc_data_px30 = {
254 .grf_offset = 0x180,
255 .supply_names = {
256 NULL,
257 "vccio6",
258 "vccio1",
259 "vccio2",
260 "vccio3",
261 "vccio4",
262 "vccio5",
263 "vccio-oscgpi",
264 },
265 .init = px30_iodomain_init,
266};
267
268static const struct rockchip_iodomain_soc_data soc_data_px30_pmu = {
269 .grf_offset = 0x100,
270 .supply_names = {
271 NULL,
272 NULL,
273 NULL,
274 NULL,
275 NULL,
276 NULL,
277 NULL,
278 NULL,
279 NULL,
280 NULL,
281 NULL,
282 NULL,
283 NULL,
284 NULL,
285 "pmuio1",
286 "pmuio2",
287 },
288};
289
230/* 290/*
231 * On the rk3188 the io-domains are handled by a shared register with the 291 * On the rk3188 the io-domains are handled by a shared register with the
232 * lower 8 bits being still being continuing drive-strength settings. 292 * lower 8 bits being still being continuing drive-strength settings.
@@ -381,6 +441,14 @@ static const struct rockchip_iodomain_soc_data soc_data_rv1108_pmu = {
381 441
382static const struct of_device_id rockchip_iodomain_match[] = { 442static const struct of_device_id rockchip_iodomain_match[] = {
383 { 443 {
444 .compatible = "rockchip,px30-io-voltage-domain",
445 .data = (void *)&soc_data_px30
446 },
447 {
448 .compatible = "rockchip,px30-pmu-io-voltage-domain",
449 .data = (void *)&soc_data_px30_pmu
450 },
451 {
384 .compatible = "rockchip,rk3188-io-voltage-domain", 452 .compatible = "rockchip,rk3188-io-voltage-domain",
385 .data = &soc_data_rk3188 453 .data = &soc_data_rk3188
386 }, 454 },
diff --git a/drivers/soc/tegra/pmc.c b/drivers/soc/tegra/pmc.c
index d9fcdb592b39..3e3d12ce4587 100644
--- a/drivers/soc/tegra/pmc.c
+++ b/drivers/soc/tegra/pmc.c
@@ -559,22 +559,28 @@ EXPORT_SYMBOL(tegra_powergate_remove_clamping);
559int tegra_powergate_sequence_power_up(unsigned int id, struct clk *clk, 559int tegra_powergate_sequence_power_up(unsigned int id, struct clk *clk,
560 struct reset_control *rst) 560 struct reset_control *rst)
561{ 561{
562 struct tegra_powergate pg; 562 struct tegra_powergate *pg;
563 int err; 563 int err;
564 564
565 if (!tegra_powergate_is_available(id)) 565 if (!tegra_powergate_is_available(id))
566 return -EINVAL; 566 return -EINVAL;
567 567
568 pg.id = id; 568 pg = kzalloc(sizeof(*pg), GFP_KERNEL);
569 pg.clks = &clk; 569 if (!pg)
570 pg.num_clks = 1; 570 return -ENOMEM;
571 pg.reset = rst;
572 pg.pmc = pmc;
573 571
574 err = tegra_powergate_power_up(&pg, false); 572 pg->id = id;
573 pg->clks = &clk;
574 pg->num_clks = 1;
575 pg->reset = rst;
576 pg->pmc = pmc;
577
578 err = tegra_powergate_power_up(pg, false);
575 if (err) 579 if (err)
576 pr_err("failed to turn on partition %d: %d\n", id, err); 580 pr_err("failed to turn on partition %d: %d\n", id, err);
577 581
582 kfree(pg);
583
578 return err; 584 return err;
579} 585}
580EXPORT_SYMBOL(tegra_powergate_sequence_power_up); 586EXPORT_SYMBOL(tegra_powergate_sequence_power_up);
diff --git a/drivers/soundwire/bus_type.c b/drivers/soundwire/bus_type.c
index d5f3a70c06b0..283b2832728e 100644
--- a/drivers/soundwire/bus_type.c
+++ b/drivers/soundwire/bus_type.c
@@ -83,17 +83,16 @@ static int sdw_drv_probe(struct device *dev)
83 * attach to power domain but don't turn on (last arg) 83 * attach to power domain but don't turn on (last arg)
84 */ 84 */
85 ret = dev_pm_domain_attach(dev, false); 85 ret = dev_pm_domain_attach(dev, false);
86 if (ret != -EPROBE_DEFER) {
87 ret = drv->probe(slave, id);
88 if (ret) {
89 dev_err(dev, "Probe of %s failed: %d\n", drv->name, ret);
90 dev_pm_domain_detach(dev, false);
91 }
92 }
93
94 if (ret) 86 if (ret)
95 return ret; 87 return ret;
96 88
89 ret = drv->probe(slave, id);
90 if (ret) {
91 dev_err(dev, "Probe of %s failed: %d\n", drv->name, ret);
92 dev_pm_domain_detach(dev, false);
93 return ret;
94 }
95
97 /* device is probed so let's read the properties now */ 96 /* device is probed so let's read the properties now */
98 if (slave->ops && slave->ops->read_prop) 97 if (slave->ops && slave->ops->read_prop)
99 slave->ops->read_prop(slave); 98 slave->ops->read_prop(slave);
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 20b5b2754830..efc624f9e490 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -359,11 +359,12 @@ static int spi_drv_probe(struct device *dev)
359 } 359 }
360 360
361 ret = dev_pm_domain_attach(dev, true); 361 ret = dev_pm_domain_attach(dev, true);
362 if (ret != -EPROBE_DEFER) { 362 if (ret)
363 ret = sdrv->probe(spi); 363 return ret;
364 if (ret) 364
365 dev_pm_domain_detach(dev, true); 365 ret = sdrv->probe(spi);
366 } 366 if (ret)
367 dev_pm_domain_detach(dev, true);
367 368
368 return ret; 369 return ret;
369} 370}
diff --git a/include/acpi/acpixf.h b/include/acpi/acpixf.h
index da0215ea9f44..c01d790c17c2 100644
--- a/include/acpi/acpixf.h
+++ b/include/acpi/acpixf.h
@@ -753,6 +753,7 @@ ACPI_HW_DEPENDENT_RETURN_STATUS(acpi_status
753 u32 gpe_number, 753 u32 gpe_number,
754 acpi_event_status 754 acpi_event_status
755 *event_status)) 755 *event_status))
756ACPI_HW_DEPENDENT_RETURN_VOID(void acpi_dispatch_gpe(acpi_handle gpe_device, u32 gpe_number))
756ACPI_HW_DEPENDENT_RETURN_STATUS(acpi_status acpi_disable_all_gpes(void)) 757ACPI_HW_DEPENDENT_RETURN_STATUS(acpi_status acpi_disable_all_gpes(void))
757ACPI_HW_DEPENDENT_RETURN_STATUS(acpi_status acpi_enable_all_runtime_gpes(void)) 758ACPI_HW_DEPENDENT_RETURN_STATUS(acpi_status acpi_enable_all_runtime_gpes(void))
758ACPI_HW_DEPENDENT_RETURN_STATUS(acpi_status acpi_enable_all_wakeup_gpes(void)) 759ACPI_HW_DEPENDENT_RETURN_STATUS(acpi_status acpi_enable_all_wakeup_gpes(void))
diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index 15bfb15c2fa5..c01675b3d93f 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -899,7 +899,7 @@ static inline int acpi_subsys_runtime_suspend(struct device *dev) { return 0; }
899static inline int acpi_subsys_runtime_resume(struct device *dev) { return 0; } 899static inline int acpi_subsys_runtime_resume(struct device *dev) { return 0; }
900static inline int acpi_dev_pm_attach(struct device *dev, bool power_on) 900static inline int acpi_dev_pm_attach(struct device *dev, bool power_on)
901{ 901{
902 return -ENODEV; 902 return 0;
903} 903}
904#endif 904#endif
905 905
diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
index 87f48dd932eb..882a9b9e34bc 100644
--- a/include/linux/cpufreq.h
+++ b/include/linux/cpufreq.h
@@ -571,7 +571,7 @@ struct governor_attr {
571 size_t count); 571 size_t count);
572}; 572};
573 573
574static inline bool cpufreq_can_do_remote_dvfs(struct cpufreq_policy *policy) 574static inline bool cpufreq_this_cpu_can_update(struct cpufreq_policy *policy)
575{ 575{
576 /* 576 /*
577 * Allow remote callbacks if: 577 * Allow remote callbacks if:
diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
index 1eefabf1621f..4325d6fdde9b 100644
--- a/include/linux/cpuidle.h
+++ b/include/linux/cpuidle.h
@@ -258,6 +258,7 @@ struct cpuidle_governor {
258 258
259#ifdef CONFIG_CPU_IDLE 259#ifdef CONFIG_CPU_IDLE
260extern int cpuidle_register_governor(struct cpuidle_governor *gov); 260extern int cpuidle_register_governor(struct cpuidle_governor *gov);
261extern int cpuidle_governor_latency_req(unsigned int cpu);
261#else 262#else
262static inline int cpuidle_register_governor(struct cpuidle_governor *gov) 263static inline int cpuidle_register_governor(struct cpuidle_governor *gov)
263{return 0;} 264{return 0;}
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 6a1eb0b0aad9..7aed92624531 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -542,6 +542,7 @@ extern enum system_states {
542 SYSTEM_HALT, 542 SYSTEM_HALT,
543 SYSTEM_POWER_OFF, 543 SYSTEM_POWER_OFF,
544 SYSTEM_RESTART, 544 SYSTEM_RESTART,
545 SYSTEM_SUSPEND,
545} system_state; 546} system_state;
546 547
547/* This cannot be an enum because some may be used in assembly source. */ 548/* This cannot be an enum because some may be used in assembly source. */
diff --git a/include/linux/notifier.h b/include/linux/notifier.h
index 6d731110e0db..f35c7bf76143 100644
--- a/include/linux/notifier.h
+++ b/include/linux/notifier.h
@@ -43,9 +43,7 @@
43 * in srcu_notifier_call_chain(): no cache bounces and no memory barriers. 43 * in srcu_notifier_call_chain(): no cache bounces and no memory barriers.
44 * As compensation, srcu_notifier_chain_unregister() is rather expensive. 44 * As compensation, srcu_notifier_chain_unregister() is rather expensive.
45 * SRCU notifier chains should be used when the chain will be called very 45 * SRCU notifier chains should be used when the chain will be called very
46 * often but notifier_blocks will seldom be removed. Also, SRCU notifier 46 * often but notifier_blocks will seldom be removed.
47 * chains are slightly more difficult to use because they require special
48 * runtime initialization.
49 */ 47 */
50 48
51struct notifier_block; 49struct notifier_block;
@@ -91,7 +89,7 @@ struct srcu_notifier_head {
91 (name)->head = NULL; \ 89 (name)->head = NULL; \
92 } while (0) 90 } while (0)
93 91
94/* srcu_notifier_heads must be initialized and cleaned up dynamically */ 92/* srcu_notifier_heads must be cleaned up dynamically */
95extern void srcu_init_notifier_head(struct srcu_notifier_head *nh); 93extern void srcu_init_notifier_head(struct srcu_notifier_head *nh);
96#define srcu_cleanup_notifier_head(name) \ 94#define srcu_cleanup_notifier_head(name) \
97 cleanup_srcu_struct(&(name)->srcu); 95 cleanup_srcu_struct(&(name)->srcu);
@@ -104,7 +102,13 @@ extern void srcu_init_notifier_head(struct srcu_notifier_head *nh);
104 .head = NULL } 102 .head = NULL }
105#define RAW_NOTIFIER_INIT(name) { \ 103#define RAW_NOTIFIER_INIT(name) { \
106 .head = NULL } 104 .head = NULL }
107/* srcu_notifier_heads cannot be initialized statically */ 105
106#define SRCU_NOTIFIER_INIT(name, pcpu) \
107 { \
108 .mutex = __MUTEX_INITIALIZER(name.mutex), \
109 .head = NULL, \
110 .srcu = __SRCU_STRUCT_INIT(name.srcu, pcpu), \
111 }
108 112
109#define ATOMIC_NOTIFIER_HEAD(name) \ 113#define ATOMIC_NOTIFIER_HEAD(name) \
110 struct atomic_notifier_head name = \ 114 struct atomic_notifier_head name = \
@@ -116,6 +120,26 @@ extern void srcu_init_notifier_head(struct srcu_notifier_head *nh);
116 struct raw_notifier_head name = \ 120 struct raw_notifier_head name = \
117 RAW_NOTIFIER_INIT(name) 121 RAW_NOTIFIER_INIT(name)
118 122
123#ifdef CONFIG_TREE_SRCU
124#define _SRCU_NOTIFIER_HEAD(name, mod) \
125 static DEFINE_PER_CPU(struct srcu_data, \
126 name##_head_srcu_data); \
127 mod struct srcu_notifier_head name = \
128 SRCU_NOTIFIER_INIT(name, name##_head_srcu_data)
129
130#else
131#define _SRCU_NOTIFIER_HEAD(name, mod) \
132 mod struct srcu_notifier_head name = \
133 SRCU_NOTIFIER_INIT(name, name)
134
135#endif
136
137#define SRCU_NOTIFIER_HEAD(name) \
138 _SRCU_NOTIFIER_HEAD(name, /* not static */)
139
140#define SRCU_NOTIFIER_HEAD_STATIC(name) \
141 _SRCU_NOTIFIER_HEAD(name, static)
142
119#ifdef __KERNEL__ 143#ifdef __KERNEL__
120 144
121extern int atomic_notifier_chain_register(struct atomic_notifier_head *nh, 145extern int atomic_notifier_chain_register(struct atomic_notifier_head *nh,
diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
index 04dbef9847d3..42e0d649e653 100644
--- a/include/linux/pm_domain.h
+++ b/include/linux/pm_domain.h
@@ -47,8 +47,10 @@ struct genpd_power_state {
47}; 47};
48 48
49struct genpd_lock_ops; 49struct genpd_lock_ops;
50struct dev_pm_opp;
50 51
51struct generic_pm_domain { 52struct generic_pm_domain {
53 struct device dev;
52 struct dev_pm_domain domain; /* PM domain operations */ 54 struct dev_pm_domain domain; /* PM domain operations */
53 struct list_head gpd_list_node; /* Node in the global PM domains list */ 55 struct list_head gpd_list_node; /* Node in the global PM domains list */
54 struct list_head master_links; /* Links with PM domain as a master */ 56 struct list_head master_links; /* Links with PM domain as a master */
@@ -67,6 +69,8 @@ struct generic_pm_domain {
67 unsigned int performance_state; /* Aggregated max performance state */ 69 unsigned int performance_state; /* Aggregated max performance state */
68 int (*power_off)(struct generic_pm_domain *domain); 70 int (*power_off)(struct generic_pm_domain *domain);
69 int (*power_on)(struct generic_pm_domain *domain); 71 int (*power_on)(struct generic_pm_domain *domain);
72 unsigned int (*opp_to_performance_state)(struct generic_pm_domain *genpd,
73 struct dev_pm_opp *opp);
70 int (*set_performance_state)(struct generic_pm_domain *genpd, 74 int (*set_performance_state)(struct generic_pm_domain *genpd,
71 unsigned int state); 75 unsigned int state);
72 struct gpd_dev_ops dev_ops; 76 struct gpd_dev_ops dev_ops;
@@ -139,21 +143,16 @@ static inline struct generic_pm_domain_data *dev_gpd_data(struct device *dev)
139 return to_gpd_data(dev->power.subsys_data->domain_data); 143 return to_gpd_data(dev->power.subsys_data->domain_data);
140} 144}
141 145
142extern int __pm_genpd_add_device(struct generic_pm_domain *genpd, 146int pm_genpd_add_device(struct generic_pm_domain *genpd, struct device *dev);
143 struct device *dev, 147int pm_genpd_remove_device(struct device *dev);
144 struct gpd_timing_data *td); 148int pm_genpd_add_subdomain(struct generic_pm_domain *genpd,
145 149 struct generic_pm_domain *new_subdomain);
146extern int pm_genpd_remove_device(struct generic_pm_domain *genpd, 150int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd,
147 struct device *dev); 151 struct generic_pm_domain *target);
148extern int pm_genpd_add_subdomain(struct generic_pm_domain *genpd, 152int pm_genpd_init(struct generic_pm_domain *genpd,
149 struct generic_pm_domain *new_subdomain); 153 struct dev_power_governor *gov, bool is_off);
150extern int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd, 154int pm_genpd_remove(struct generic_pm_domain *genpd);
151 struct generic_pm_domain *target); 155int dev_pm_genpd_set_performance_state(struct device *dev, unsigned int state);
152extern int pm_genpd_init(struct generic_pm_domain *genpd,
153 struct dev_power_governor *gov, bool is_off);
154extern int pm_genpd_remove(struct generic_pm_domain *genpd);
155extern int dev_pm_genpd_set_performance_state(struct device *dev,
156 unsigned int state);
157 156
158extern struct dev_power_governor simple_qos_governor; 157extern struct dev_power_governor simple_qos_governor;
159extern struct dev_power_governor pm_domain_always_on_gov; 158extern struct dev_power_governor pm_domain_always_on_gov;
@@ -163,14 +162,12 @@ static inline struct generic_pm_domain_data *dev_gpd_data(struct device *dev)
163{ 162{
164 return ERR_PTR(-ENOSYS); 163 return ERR_PTR(-ENOSYS);
165} 164}
166static inline int __pm_genpd_add_device(struct generic_pm_domain *genpd, 165static inline int pm_genpd_add_device(struct generic_pm_domain *genpd,
167 struct device *dev, 166 struct device *dev)
168 struct gpd_timing_data *td)
169{ 167{
170 return -ENOSYS; 168 return -ENOSYS;
171} 169}
172static inline int pm_genpd_remove_device(struct generic_pm_domain *genpd, 170static inline int pm_genpd_remove_device(struct device *dev)
173 struct device *dev)
174{ 171{
175 return -ENOSYS; 172 return -ENOSYS;
176} 173}
@@ -204,15 +201,9 @@ static inline int dev_pm_genpd_set_performance_state(struct device *dev,
204#define pm_domain_always_on_gov (*(struct dev_power_governor *)(NULL)) 201#define pm_domain_always_on_gov (*(struct dev_power_governor *)(NULL))
205#endif 202#endif
206 203
207static inline int pm_genpd_add_device(struct generic_pm_domain *genpd,
208 struct device *dev)
209{
210 return __pm_genpd_add_device(genpd, dev, NULL);
211}
212
213#ifdef CONFIG_PM_GENERIC_DOMAINS_SLEEP 204#ifdef CONFIG_PM_GENERIC_DOMAINS_SLEEP
214extern void pm_genpd_syscore_poweroff(struct device *dev); 205void pm_genpd_syscore_poweroff(struct device *dev);
215extern void pm_genpd_syscore_poweron(struct device *dev); 206void pm_genpd_syscore_poweron(struct device *dev);
216#else 207#else
217static inline void pm_genpd_syscore_poweroff(struct device *dev) {} 208static inline void pm_genpd_syscore_poweroff(struct device *dev) {}
218static inline void pm_genpd_syscore_poweron(struct device *dev) {} 209static inline void pm_genpd_syscore_poweron(struct device *dev) {}
@@ -236,13 +227,14 @@ int of_genpd_add_provider_simple(struct device_node *np,
236int of_genpd_add_provider_onecell(struct device_node *np, 227int of_genpd_add_provider_onecell(struct device_node *np,
237 struct genpd_onecell_data *data); 228 struct genpd_onecell_data *data);
238void of_genpd_del_provider(struct device_node *np); 229void of_genpd_del_provider(struct device_node *np);
239extern int of_genpd_add_device(struct of_phandle_args *args, 230int of_genpd_add_device(struct of_phandle_args *args, struct device *dev);
240 struct device *dev); 231int of_genpd_add_subdomain(struct of_phandle_args *parent,
241extern int of_genpd_add_subdomain(struct of_phandle_args *parent, 232 struct of_phandle_args *new_subdomain);
242 struct of_phandle_args *new_subdomain); 233struct generic_pm_domain *of_genpd_remove_last(struct device_node *np);
243extern struct generic_pm_domain *of_genpd_remove_last(struct device_node *np); 234int of_genpd_parse_idle_states(struct device_node *dn,
244extern int of_genpd_parse_idle_states(struct device_node *dn, 235 struct genpd_power_state **states, int *n);
245 struct genpd_power_state **states, int *n); 236unsigned int of_genpd_opp_to_performance_state(struct device *dev,
237 struct device_node *opp_node);
246 238
247int genpd_dev_pm_attach(struct device *dev); 239int genpd_dev_pm_attach(struct device *dev);
248#else /* !CONFIG_PM_GENERIC_DOMAINS_OF */ 240#else /* !CONFIG_PM_GENERIC_DOMAINS_OF */
@@ -278,11 +270,18 @@ static inline int of_genpd_parse_idle_states(struct device_node *dn,
278 return -ENODEV; 270 return -ENODEV;
279} 271}
280 272
281static inline int genpd_dev_pm_attach(struct device *dev) 273static inline unsigned int
274of_genpd_opp_to_performance_state(struct device *dev,
275 struct device_node *opp_node)
282{ 276{
283 return -ENODEV; 277 return -ENODEV;
284} 278}
285 279
280static inline int genpd_dev_pm_attach(struct device *dev)
281{
282 return 0;
283}
284
286static inline 285static inline
287struct generic_pm_domain *of_genpd_remove_last(struct device_node *np) 286struct generic_pm_domain *of_genpd_remove_last(struct device_node *np)
288{ 287{
@@ -291,13 +290,13 @@ struct generic_pm_domain *of_genpd_remove_last(struct device_node *np)
291#endif /* CONFIG_PM_GENERIC_DOMAINS_OF */ 290#endif /* CONFIG_PM_GENERIC_DOMAINS_OF */
292 291
293#ifdef CONFIG_PM 292#ifdef CONFIG_PM
294extern int dev_pm_domain_attach(struct device *dev, bool power_on); 293int dev_pm_domain_attach(struct device *dev, bool power_on);
295extern void dev_pm_domain_detach(struct device *dev, bool power_off); 294void dev_pm_domain_detach(struct device *dev, bool power_off);
296extern void dev_pm_domain_set(struct device *dev, struct dev_pm_domain *pd); 295void dev_pm_domain_set(struct device *dev, struct dev_pm_domain *pd);
297#else 296#else
298static inline int dev_pm_domain_attach(struct device *dev, bool power_on) 297static inline int dev_pm_domain_attach(struct device *dev, bool power_on)
299{ 298{
300 return -ENODEV; 299 return 0;
301} 300}
302static inline void dev_pm_domain_detach(struct device *dev, bool power_off) {} 301static inline void dev_pm_domain_detach(struct device *dev, bool power_off) {}
303static inline void dev_pm_domain_set(struct device *dev, 302static inline void dev_pm_domain_set(struct device *dev,
diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h
index 6c2d2e88f066..099b31960dec 100644
--- a/include/linux/pm_opp.h
+++ b/include/linux/pm_opp.h
@@ -125,8 +125,6 @@ struct opp_table *dev_pm_opp_set_clkname(struct device *dev, const char * name);
125void dev_pm_opp_put_clkname(struct opp_table *opp_table); 125void dev_pm_opp_put_clkname(struct opp_table *opp_table);
126struct opp_table *dev_pm_opp_register_set_opp_helper(struct device *dev, int (*set_opp)(struct dev_pm_set_opp_data *data)); 126struct opp_table *dev_pm_opp_register_set_opp_helper(struct device *dev, int (*set_opp)(struct dev_pm_set_opp_data *data));
127void dev_pm_opp_unregister_set_opp_helper(struct opp_table *opp_table); 127void dev_pm_opp_unregister_set_opp_helper(struct opp_table *opp_table);
128struct opp_table *dev_pm_opp_register_get_pstate_helper(struct device *dev, int (*get_pstate)(struct device *dev, unsigned long rate));
129void dev_pm_opp_unregister_get_pstate_helper(struct opp_table *opp_table);
130int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq); 128int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq);
131int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, const struct cpumask *cpumask); 129int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, const struct cpumask *cpumask);
132int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask); 130int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask);
@@ -247,14 +245,6 @@ static inline struct opp_table *dev_pm_opp_register_set_opp_helper(struct device
247 245
248static inline void dev_pm_opp_unregister_set_opp_helper(struct opp_table *opp_table) {} 246static inline void dev_pm_opp_unregister_set_opp_helper(struct opp_table *opp_table) {}
249 247
250static inline struct opp_table *dev_pm_opp_register_get_pstate_helper(struct device *dev,
251 int (*get_pstate)(struct device *dev, unsigned long rate))
252{
253 return ERR_PTR(-ENOTSUPP);
254}
255
256static inline void dev_pm_opp_unregister_get_pstate_helper(struct opp_table *opp_table) {}
257
258static inline struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, const char *name) 248static inline struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, const char *name)
259{ 249{
260 return ERR_PTR(-ENOTSUPP); 250 return ERR_PTR(-ENOTSUPP);
@@ -303,17 +293,25 @@ static inline void dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask
303 293
304#if defined(CONFIG_PM_OPP) && defined(CONFIG_OF) 294#if defined(CONFIG_PM_OPP) && defined(CONFIG_OF)
305int dev_pm_opp_of_add_table(struct device *dev); 295int dev_pm_opp_of_add_table(struct device *dev);
296int dev_pm_opp_of_add_table_indexed(struct device *dev, int index);
306void dev_pm_opp_of_remove_table(struct device *dev); 297void dev_pm_opp_of_remove_table(struct device *dev);
307int dev_pm_opp_of_cpumask_add_table(const struct cpumask *cpumask); 298int dev_pm_opp_of_cpumask_add_table(const struct cpumask *cpumask);
308void dev_pm_opp_of_cpumask_remove_table(const struct cpumask *cpumask); 299void dev_pm_opp_of_cpumask_remove_table(const struct cpumask *cpumask);
309int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask); 300int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask);
310struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev); 301struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev);
302struct dev_pm_opp *of_dev_pm_opp_find_required_opp(struct device *dev, struct device_node *np);
303struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp);
311#else 304#else
312static inline int dev_pm_opp_of_add_table(struct device *dev) 305static inline int dev_pm_opp_of_add_table(struct device *dev)
313{ 306{
314 return -ENOTSUPP; 307 return -ENOTSUPP;
315} 308}
316 309
310static inline int dev_pm_opp_of_add_table_indexed(struct device *dev, int index)
311{
312 return -ENOTSUPP;
313}
314
317static inline void dev_pm_opp_of_remove_table(struct device *dev) 315static inline void dev_pm_opp_of_remove_table(struct device *dev)
318{ 316{
319} 317}
@@ -336,6 +334,15 @@ static inline struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device
336{ 334{
337 return NULL; 335 return NULL;
338} 336}
337
338static inline struct dev_pm_opp *of_dev_pm_opp_find_required_opp(struct device *dev, struct device_node *np)
339{
340 return NULL;
341}
342static inline struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp)
343{
344 return NULL;
345}
339#endif 346#endif
340 347
341#endif /* __LINUX_OPP_H__ */ 348#endif /* __LINUX_OPP_H__ */
diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
index f0fc4700b6ff..db5dbbf7a48d 100644
--- a/include/linux/pm_runtime.h
+++ b/include/linux/pm_runtime.h
@@ -56,8 +56,7 @@ extern void pm_runtime_update_max_time_suspended(struct device *dev,
56 s64 delta_ns); 56 s64 delta_ns);
57extern void pm_runtime_set_memalloc_noio(struct device *dev, bool enable); 57extern void pm_runtime_set_memalloc_noio(struct device *dev, bool enable);
58extern void pm_runtime_clean_up_links(struct device *dev); 58extern void pm_runtime_clean_up_links(struct device *dev);
59extern void pm_runtime_get_suppliers(struct device *dev); 59extern void pm_runtime_resume_suppliers(struct device *dev);
60extern void pm_runtime_put_suppliers(struct device *dev);
61extern void pm_runtime_new_link(struct device *dev); 60extern void pm_runtime_new_link(struct device *dev);
62extern void pm_runtime_drop_link(struct device *dev); 61extern void pm_runtime_drop_link(struct device *dev);
63 62
@@ -173,8 +172,7 @@ static inline unsigned long pm_runtime_autosuspend_expiration(
173static inline void pm_runtime_set_memalloc_noio(struct device *dev, 172static inline void pm_runtime_set_memalloc_noio(struct device *dev,
174 bool enable){} 173 bool enable){}
175static inline void pm_runtime_clean_up_links(struct device *dev) {} 174static inline void pm_runtime_clean_up_links(struct device *dev) {}
176static inline void pm_runtime_get_suppliers(struct device *dev) {} 175static inline void pm_runtime_resume_suppliers(struct device *dev) {}
177static inline void pm_runtime_put_suppliers(struct device *dev) {}
178static inline void pm_runtime_new_link(struct device *dev) {} 176static inline void pm_runtime_new_link(struct device *dev) {}
179static inline void pm_runtime_drop_link(struct device *dev) {} 177static inline void pm_runtime_drop_link(struct device *dev) {}
180 178
diff --git a/include/linux/srcutiny.h b/include/linux/srcutiny.h
index 261471f407a5..f41d2fb09f87 100644
--- a/include/linux/srcutiny.h
+++ b/include/linux/srcutiny.h
@@ -43,7 +43,7 @@ struct srcu_struct {
43 43
44void srcu_drive_gp(struct work_struct *wp); 44void srcu_drive_gp(struct work_struct *wp);
45 45
46#define __SRCU_STRUCT_INIT(name) \ 46#define __SRCU_STRUCT_INIT(name, __ignored) \
47{ \ 47{ \
48 .srcu_wq = __SWAIT_QUEUE_HEAD_INITIALIZER(name.srcu_wq), \ 48 .srcu_wq = __SWAIT_QUEUE_HEAD_INITIALIZER(name.srcu_wq), \
49 .srcu_cb_tail = &name.srcu_cb_head, \ 49 .srcu_cb_tail = &name.srcu_cb_head, \
@@ -56,9 +56,9 @@ void srcu_drive_gp(struct work_struct *wp);
56 * Tree SRCU, which needs some per-CPU data. 56 * Tree SRCU, which needs some per-CPU data.
57 */ 57 */
58#define DEFINE_SRCU(name) \ 58#define DEFINE_SRCU(name) \
59 struct srcu_struct name = __SRCU_STRUCT_INIT(name) 59 struct srcu_struct name = __SRCU_STRUCT_INIT(name, name)
60#define DEFINE_STATIC_SRCU(name) \ 60#define DEFINE_STATIC_SRCU(name) \
61 static struct srcu_struct name = __SRCU_STRUCT_INIT(name) 61 static struct srcu_struct name = __SRCU_STRUCT_INIT(name, name)
62 62
63void synchronize_srcu(struct srcu_struct *sp); 63void synchronize_srcu(struct srcu_struct *sp);
64 64
diff --git a/include/linux/srcutree.h b/include/linux/srcutree.h
index 4eda108abee0..745d4ca4dd50 100644
--- a/include/linux/srcutree.h
+++ b/include/linux/srcutree.h
@@ -104,9 +104,9 @@ struct srcu_struct {
104#define SRCU_STATE_SCAN1 1 104#define SRCU_STATE_SCAN1 1
105#define SRCU_STATE_SCAN2 2 105#define SRCU_STATE_SCAN2 2
106 106
107#define __SRCU_STRUCT_INIT(name) \ 107#define __SRCU_STRUCT_INIT(name, pcpu_name) \
108 { \ 108 { \
109 .sda = &name##_srcu_data, \ 109 .sda = &pcpu_name, \
110 .lock = __SPIN_LOCK_UNLOCKED(name.lock), \ 110 .lock = __SPIN_LOCK_UNLOCKED(name.lock), \
111 .srcu_gp_seq_needed = 0 - 1, \ 111 .srcu_gp_seq_needed = 0 - 1, \
112 __SRCU_DEP_MAP_INIT(name) \ 112 __SRCU_DEP_MAP_INIT(name) \
@@ -133,7 +133,7 @@ struct srcu_struct {
133 */ 133 */
134#define __DEFINE_SRCU(name, is_static) \ 134#define __DEFINE_SRCU(name, is_static) \
135 static DEFINE_PER_CPU(struct srcu_data, name##_srcu_data);\ 135 static DEFINE_PER_CPU(struct srcu_data, name##_srcu_data);\
136 is_static struct srcu_struct name = __SRCU_STRUCT_INIT(name) 136 is_static struct srcu_struct name = __SRCU_STRUCT_INIT(name, name##_srcu_data)
137#define DEFINE_SRCU(name) __DEFINE_SRCU(name, /* not static */) 137#define DEFINE_SRCU(name) __DEFINE_SRCU(name, /* not static */)
138#define DEFINE_STATIC_SRCU(name) __DEFINE_SRCU(name, static) 138#define DEFINE_STATIC_SRCU(name) __DEFINE_SRCU(name, static)
139 139
diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
index 5454cc639a8d..9c85c7822383 100644
--- a/kernel/power/hibernate.c
+++ b/kernel/power/hibernate.c
@@ -287,6 +287,8 @@ static int create_image(int platform_mode)
287 287
288 local_irq_disable(); 288 local_irq_disable();
289 289
290 system_state = SYSTEM_SUSPEND;
291
290 error = syscore_suspend(); 292 error = syscore_suspend();
291 if (error) { 293 if (error) {
292 pr_err("Some system devices failed to power down, aborting hibernation\n"); 294 pr_err("Some system devices failed to power down, aborting hibernation\n");
@@ -317,6 +319,7 @@ static int create_image(int platform_mode)
317 syscore_resume(); 319 syscore_resume();
318 320
319 Enable_irqs: 321 Enable_irqs:
322 system_state = SYSTEM_RUNNING;
320 local_irq_enable(); 323 local_irq_enable();
321 324
322 Enable_cpus: 325 Enable_cpus:
@@ -445,6 +448,7 @@ static int resume_target_kernel(bool platform_mode)
445 goto Enable_cpus; 448 goto Enable_cpus;
446 449
447 local_irq_disable(); 450 local_irq_disable();
451 system_state = SYSTEM_SUSPEND;
448 452
449 error = syscore_suspend(); 453 error = syscore_suspend();
450 if (error) 454 if (error)
@@ -478,6 +482,7 @@ static int resume_target_kernel(bool platform_mode)
478 syscore_resume(); 482 syscore_resume();
479 483
480 Enable_irqs: 484 Enable_irqs:
485 system_state = SYSTEM_RUNNING;
481 local_irq_enable(); 486 local_irq_enable();
482 487
483 Enable_cpus: 488 Enable_cpus:
@@ -563,6 +568,7 @@ int hibernation_platform_enter(void)
563 goto Enable_cpus; 568 goto Enable_cpus;
564 569
565 local_irq_disable(); 570 local_irq_disable();
571 system_state = SYSTEM_SUSPEND;
566 syscore_suspend(); 572 syscore_suspend();
567 if (pm_wakeup_pending()) { 573 if (pm_wakeup_pending()) {
568 error = -EAGAIN; 574 error = -EAGAIN;
@@ -575,6 +581,7 @@ int hibernation_platform_enter(void)
575 581
576 Power_up: 582 Power_up:
577 syscore_resume(); 583 syscore_resume();
584 system_state = SYSTEM_RUNNING;
578 local_irq_enable(); 585 local_irq_enable();
579 586
580 Enable_cpus: 587 Enable_cpus:
diff --git a/kernel/power/qos.c b/kernel/power/qos.c
index fa39092b7aea..86d72ffb811b 100644
--- a/kernel/power/qos.c
+++ b/kernel/power/qos.c
@@ -184,7 +184,6 @@ static inline void pm_qos_set_value(struct pm_qos_constraints *c, s32 value)
184 c->target_value = value; 184 c->target_value = value;
185} 185}
186 186
187static inline int pm_qos_get_value(struct pm_qos_constraints *c);
188static int pm_qos_dbg_show_requests(struct seq_file *s, void *unused) 187static int pm_qos_dbg_show_requests(struct seq_file *s, void *unused)
189{ 188{
190 struct pm_qos_object *qos = (struct pm_qos_object *)s->private; 189 struct pm_qos_object *qos = (struct pm_qos_object *)s->private;
diff --git a/kernel/power/suspend.c b/kernel/power/suspend.c
index 4c10be0f4843..87331565e505 100644
--- a/kernel/power/suspend.c
+++ b/kernel/power/suspend.c
@@ -27,6 +27,7 @@
27#include <linux/export.h> 27#include <linux/export.h>
28#include <linux/suspend.h> 28#include <linux/suspend.h>
29#include <linux/syscore_ops.h> 29#include <linux/syscore_ops.h>
30#include <linux/swait.h>
30#include <linux/ftrace.h> 31#include <linux/ftrace.h>
31#include <trace/events/power.h> 32#include <trace/events/power.h>
32#include <linux/compiler.h> 33#include <linux/compiler.h>
@@ -57,10 +58,10 @@ EXPORT_SYMBOL_GPL(pm_suspend_global_flags);
57 58
58static const struct platform_suspend_ops *suspend_ops; 59static const struct platform_suspend_ops *suspend_ops;
59static const struct platform_s2idle_ops *s2idle_ops; 60static const struct platform_s2idle_ops *s2idle_ops;
60static DECLARE_WAIT_QUEUE_HEAD(s2idle_wait_head); 61static DECLARE_SWAIT_QUEUE_HEAD(s2idle_wait_head);
61 62
62enum s2idle_states __read_mostly s2idle_state; 63enum s2idle_states __read_mostly s2idle_state;
63static DEFINE_SPINLOCK(s2idle_lock); 64static DEFINE_RAW_SPINLOCK(s2idle_lock);
64 65
65void s2idle_set_ops(const struct platform_s2idle_ops *ops) 66void s2idle_set_ops(const struct platform_s2idle_ops *ops)
66{ 67{
@@ -78,12 +79,12 @@ static void s2idle_enter(void)
78{ 79{
79 trace_suspend_resume(TPS("machine_suspend"), PM_SUSPEND_TO_IDLE, true); 80 trace_suspend_resume(TPS("machine_suspend"), PM_SUSPEND_TO_IDLE, true);
80 81
81 spin_lock_irq(&s2idle_lock); 82 raw_spin_lock_irq(&s2idle_lock);
82 if (pm_wakeup_pending()) 83 if (pm_wakeup_pending())
83 goto out; 84 goto out;
84 85
85 s2idle_state = S2IDLE_STATE_ENTER; 86 s2idle_state = S2IDLE_STATE_ENTER;
86 spin_unlock_irq(&s2idle_lock); 87 raw_spin_unlock_irq(&s2idle_lock);
87 88
88 get_online_cpus(); 89 get_online_cpus();
89 cpuidle_resume(); 90 cpuidle_resume();
@@ -91,17 +92,17 @@ static void s2idle_enter(void)
91 /* Push all the CPUs into the idle loop. */ 92 /* Push all the CPUs into the idle loop. */
92 wake_up_all_idle_cpus(); 93 wake_up_all_idle_cpus();
93 /* Make the current CPU wait so it can enter the idle loop too. */ 94 /* Make the current CPU wait so it can enter the idle loop too. */
94 wait_event(s2idle_wait_head, 95 swait_event(s2idle_wait_head,
95 s2idle_state == S2IDLE_STATE_WAKE); 96 s2idle_state == S2IDLE_STATE_WAKE);
96 97
97 cpuidle_pause(); 98 cpuidle_pause();
98 put_online_cpus(); 99 put_online_cpus();
99 100
100 spin_lock_irq(&s2idle_lock); 101 raw_spin_lock_irq(&s2idle_lock);
101 102
102 out: 103 out:
103 s2idle_state = S2IDLE_STATE_NONE; 104 s2idle_state = S2IDLE_STATE_NONE;
104 spin_unlock_irq(&s2idle_lock); 105 raw_spin_unlock_irq(&s2idle_lock);
105 106
106 trace_suspend_resume(TPS("machine_suspend"), PM_SUSPEND_TO_IDLE, false); 107 trace_suspend_resume(TPS("machine_suspend"), PM_SUSPEND_TO_IDLE, false);
107} 108}
@@ -156,12 +157,12 @@ void s2idle_wake(void)
156{ 157{
157 unsigned long flags; 158 unsigned long flags;
158 159
159 spin_lock_irqsave(&s2idle_lock, flags); 160 raw_spin_lock_irqsave(&s2idle_lock, flags);
160 if (s2idle_state > S2IDLE_STATE_NONE) { 161 if (s2idle_state > S2IDLE_STATE_NONE) {
161 s2idle_state = S2IDLE_STATE_WAKE; 162 s2idle_state = S2IDLE_STATE_WAKE;
162 wake_up(&s2idle_wait_head); 163 swake_up(&s2idle_wait_head);
163 } 164 }
164 spin_unlock_irqrestore(&s2idle_lock, flags); 165 raw_spin_unlock_irqrestore(&s2idle_lock, flags);
165} 166}
166EXPORT_SYMBOL_GPL(s2idle_wake); 167EXPORT_SYMBOL_GPL(s2idle_wake);
167 168
@@ -428,6 +429,8 @@ static int suspend_enter(suspend_state_t state, bool *wakeup)
428 arch_suspend_disable_irqs(); 429 arch_suspend_disable_irqs();
429 BUG_ON(!irqs_disabled()); 430 BUG_ON(!irqs_disabled());
430 431
432 system_state = SYSTEM_SUSPEND;
433
431 error = syscore_suspend(); 434 error = syscore_suspend();
432 if (!error) { 435 if (!error) {
433 *wakeup = pm_wakeup_pending(); 436 *wakeup = pm_wakeup_pending();
@@ -443,6 +446,8 @@ static int suspend_enter(suspend_state_t state, bool *wakeup)
443 syscore_resume(); 446 syscore_resume();
444 } 447 }
445 448
449 system_state = SYSTEM_RUNNING;
450
446 arch_suspend_enable_irqs(); 451 arch_suspend_enable_irqs();
447 BUG_ON(irqs_disabled()); 452 BUG_ON(irqs_disabled());
448 453
diff --git a/kernel/power/user.c b/kernel/power/user.c
index 75c959de4b29..abd225550271 100644
--- a/kernel/power/user.c
+++ b/kernel/power/user.c
@@ -186,6 +186,11 @@ static ssize_t snapshot_write(struct file *filp, const char __user *buf,
186 res = PAGE_SIZE - pg_offp; 186 res = PAGE_SIZE - pg_offp;
187 } 187 }
188 188
189 if (!data_of(data->handle)) {
190 res = -EINVAL;
191 goto unlock;
192 }
193
189 res = simple_write_to_buffer(data_of(data->handle), res, &pg_offp, 194 res = simple_write_to_buffer(data_of(data->handle), res, &pg_offp,
190 buf, count); 195 buf, count);
191 if (res > 0) 196 if (res > 0)
diff --git a/kernel/power/wakelock.c b/kernel/power/wakelock.c
index dfba59be190b..4210152e56f0 100644
--- a/kernel/power/wakelock.c
+++ b/kernel/power/wakelock.c
@@ -188,6 +188,7 @@ static struct wakelock *wakelock_lookup_add(const char *name, size_t len,
188 return ERR_PTR(-ENOMEM); 188 return ERR_PTR(-ENOMEM);
189 } 189 }
190 wl->ws.name = wl->name; 190 wl->ws.name = wl->name;
191 wl->ws.last_time = ktime_get();
191 wakeup_source_add(&wl->ws); 192 wakeup_source_add(&wl->ws);
192 rb_link_node(&wl->node, parent, node); 193 rb_link_node(&wl->node, parent, node);
193 rb_insert_color(&wl->node, &wakelocks_tree); 194 rb_insert_color(&wl->node, &wakelocks_tree);
diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c
index 28592b62b1d5..3cde46483f0a 100644
--- a/kernel/sched/cpufreq_schedutil.c
+++ b/kernel/sched/cpufreq_schedutil.c
@@ -51,7 +51,7 @@ struct sugov_cpu {
51 bool iowait_boost_pending; 51 bool iowait_boost_pending;
52 unsigned int iowait_boost; 52 unsigned int iowait_boost;
53 unsigned int iowait_boost_max; 53 unsigned int iowait_boost_max;
54 u64 last_update; 54 u64 last_update;
55 55
56 /* The fields below are only needed when sharing a policy: */ 56 /* The fields below are only needed when sharing a policy: */
57 unsigned long util_cfs; 57 unsigned long util_cfs;
@@ -89,46 +89,52 @@ static bool sugov_should_update_freq(struct sugov_policy *sg_policy, u64 time)
89 * schedule the kthread. 89 * schedule the kthread.
90 */ 90 */
91 if (sg_policy->policy->fast_switch_enabled && 91 if (sg_policy->policy->fast_switch_enabled &&
92 !cpufreq_can_do_remote_dvfs(sg_policy->policy)) 92 !cpufreq_this_cpu_can_update(sg_policy->policy))
93 return false; 93 return false;
94 94
95 if (sg_policy->work_in_progress) 95 if (unlikely(sg_policy->need_freq_update))
96 return false;
97
98 if (unlikely(sg_policy->need_freq_update)) {
99 sg_policy->need_freq_update = false;
100 /*
101 * This happens when limits change, so forget the previous
102 * next_freq value and force an update.
103 */
104 sg_policy->next_freq = UINT_MAX;
105 return true; 96 return true;
106 }
107 97
108 delta_ns = time - sg_policy->last_freq_update_time; 98 delta_ns = time - sg_policy->last_freq_update_time;
109 99
110 return delta_ns >= sg_policy->freq_update_delay_ns; 100 return delta_ns >= sg_policy->freq_update_delay_ns;
111} 101}
112 102
113static void sugov_update_commit(struct sugov_policy *sg_policy, u64 time, 103static bool sugov_update_next_freq(struct sugov_policy *sg_policy, u64 time,
114 unsigned int next_freq) 104 unsigned int next_freq)
115{ 105{
116 struct cpufreq_policy *policy = sg_policy->policy;
117
118 if (sg_policy->next_freq == next_freq) 106 if (sg_policy->next_freq == next_freq)
119 return; 107 return false;
120 108
121 sg_policy->next_freq = next_freq; 109 sg_policy->next_freq = next_freq;
122 sg_policy->last_freq_update_time = time; 110 sg_policy->last_freq_update_time = time;
123 111
124 if (policy->fast_switch_enabled) { 112 return true;
125 next_freq = cpufreq_driver_fast_switch(policy, next_freq); 113}
126 if (!next_freq)
127 return;
128 114
129 policy->cur = next_freq; 115static void sugov_fast_switch(struct sugov_policy *sg_policy, u64 time,
130 trace_cpu_frequency(next_freq, smp_processor_id()); 116 unsigned int next_freq)
131 } else { 117{
118 struct cpufreq_policy *policy = sg_policy->policy;
119
120 if (!sugov_update_next_freq(sg_policy, time, next_freq))
121 return;
122
123 next_freq = cpufreq_driver_fast_switch(policy, next_freq);
124 if (!next_freq)
125 return;
126
127 policy->cur = next_freq;
128 trace_cpu_frequency(next_freq, smp_processor_id());
129}
130
131static void sugov_deferred_update(struct sugov_policy *sg_policy, u64 time,
132 unsigned int next_freq)
133{
134 if (!sugov_update_next_freq(sg_policy, time, next_freq))
135 return;
136
137 if (!sg_policy->work_in_progress) {
132 sg_policy->work_in_progress = true; 138 sg_policy->work_in_progress = true;
133 irq_work_queue(&sg_policy->irq_work); 139 irq_work_queue(&sg_policy->irq_work);
134 } 140 }
@@ -165,8 +171,10 @@ static unsigned int get_next_freq(struct sugov_policy *sg_policy,
165 171
166 freq = (freq + (freq >> 2)) * util / max; 172 freq = (freq + (freq >> 2)) * util / max;
167 173
168 if (freq == sg_policy->cached_raw_freq && sg_policy->next_freq != UINT_MAX) 174 if (freq == sg_policy->cached_raw_freq && !sg_policy->need_freq_update)
169 return sg_policy->next_freq; 175 return sg_policy->next_freq;
176
177 sg_policy->need_freq_update = false;
170 sg_policy->cached_raw_freq = freq; 178 sg_policy->cached_raw_freq = freq;
171 return cpufreq_driver_resolve_freq(policy, freq); 179 return cpufreq_driver_resolve_freq(policy, freq);
172} 180}
@@ -200,43 +208,120 @@ static unsigned long sugov_aggregate_util(struct sugov_cpu *sg_cpu)
200 return min(sg_cpu->max, (sg_cpu->util_dl + sg_cpu->util_cfs)); 208 return min(sg_cpu->max, (sg_cpu->util_dl + sg_cpu->util_cfs));
201} 209}
202 210
203static void sugov_set_iowait_boost(struct sugov_cpu *sg_cpu, u64 time, unsigned int flags) 211/**
212 * sugov_iowait_reset() - Reset the IO boost status of a CPU.
213 * @sg_cpu: the sugov data for the CPU to boost
214 * @time: the update time from the caller
215 * @set_iowait_boost: true if an IO boost has been requested
216 *
217 * The IO wait boost of a task is disabled after a tick since the last update
218 * of a CPU. If a new IO wait boost is requested after more then a tick, then
219 * we enable the boost starting from the minimum frequency, which improves
220 * energy efficiency by ignoring sporadic wakeups from IO.
221 */
222static bool sugov_iowait_reset(struct sugov_cpu *sg_cpu, u64 time,
223 bool set_iowait_boost)
204{ 224{
205 if (flags & SCHED_CPUFREQ_IOWAIT) { 225 s64 delta_ns = time - sg_cpu->last_update;
206 if (sg_cpu->iowait_boost_pending)
207 return;
208 226
209 sg_cpu->iowait_boost_pending = true; 227 /* Reset boost only if a tick has elapsed since last request */
228 if (delta_ns <= TICK_NSEC)
229 return false;
210 230
211 if (sg_cpu->iowait_boost) { 231 sg_cpu->iowait_boost = set_iowait_boost
212 sg_cpu->iowait_boost <<= 1; 232 ? sg_cpu->sg_policy->policy->min : 0;
213 if (sg_cpu->iowait_boost > sg_cpu->iowait_boost_max) 233 sg_cpu->iowait_boost_pending = set_iowait_boost;
214 sg_cpu->iowait_boost = sg_cpu->iowait_boost_max;
215 } else {
216 sg_cpu->iowait_boost = sg_cpu->sg_policy->policy->min;
217 }
218 } else if (sg_cpu->iowait_boost) {
219 s64 delta_ns = time - sg_cpu->last_update;
220 234
221 /* Clear iowait_boost if the CPU apprears to have been idle. */ 235 return true;
222 if (delta_ns > TICK_NSEC) { 236}
223 sg_cpu->iowait_boost = 0; 237
224 sg_cpu->iowait_boost_pending = false; 238/**
225 } 239 * sugov_iowait_boost() - Updates the IO boost status of a CPU.
240 * @sg_cpu: the sugov data for the CPU to boost
241 * @time: the update time from the caller
242 * @flags: SCHED_CPUFREQ_IOWAIT if the task is waking up after an IO wait
243 *
244 * Each time a task wakes up after an IO operation, the CPU utilization can be
245 * boosted to a certain utilization which doubles at each "frequent and
246 * successive" wakeup from IO, ranging from the utilization of the minimum
247 * OPP to the utilization of the maximum OPP.
248 * To keep doubling, an IO boost has to be requested at least once per tick,
249 * otherwise we restart from the utilization of the minimum OPP.
250 */
251static void sugov_iowait_boost(struct sugov_cpu *sg_cpu, u64 time,
252 unsigned int flags)
253{
254 bool set_iowait_boost = flags & SCHED_CPUFREQ_IOWAIT;
255
256 /* Reset boost if the CPU appears to have been idle enough */
257 if (sg_cpu->iowait_boost &&
258 sugov_iowait_reset(sg_cpu, time, set_iowait_boost))
259 return;
260
261 /* Boost only tasks waking up after IO */
262 if (!set_iowait_boost)
263 return;
264
265 /* Ensure boost doubles only one time at each request */
266 if (sg_cpu->iowait_boost_pending)
267 return;
268 sg_cpu->iowait_boost_pending = true;
269
270 /* Double the boost at each request */
271 if (sg_cpu->iowait_boost) {
272 sg_cpu->iowait_boost <<= 1;
273 if (sg_cpu->iowait_boost > sg_cpu->iowait_boost_max)
274 sg_cpu->iowait_boost = sg_cpu->iowait_boost_max;
275 return;
226 } 276 }
277
278 /* First wakeup after IO: start with minimum boost */
279 sg_cpu->iowait_boost = sg_cpu->sg_policy->policy->min;
227} 280}
228 281
229static void sugov_iowait_boost(struct sugov_cpu *sg_cpu, unsigned long *util, 282/**
230 unsigned long *max) 283 * sugov_iowait_apply() - Apply the IO boost to a CPU.
284 * @sg_cpu: the sugov data for the cpu to boost
285 * @time: the update time from the caller
286 * @util: the utilization to (eventually) boost
287 * @max: the maximum value the utilization can be boosted to
288 *
289 * A CPU running a task which woken up after an IO operation can have its
290 * utilization boosted to speed up the completion of those IO operations.
291 * The IO boost value is increased each time a task wakes up from IO, in
292 * sugov_iowait_apply(), and it's instead decreased by this function,
293 * each time an increase has not been requested (!iowait_boost_pending).
294 *
295 * A CPU which also appears to have been idle for at least one tick has also
296 * its IO boost utilization reset.
297 *
298 * This mechanism is designed to boost high frequently IO waiting tasks, while
299 * being more conservative on tasks which does sporadic IO operations.
300 */
301static void sugov_iowait_apply(struct sugov_cpu *sg_cpu, u64 time,
302 unsigned long *util, unsigned long *max)
231{ 303{
232 unsigned int boost_util, boost_max; 304 unsigned int boost_util, boost_max;
233 305
306 /* No boost currently required */
234 if (!sg_cpu->iowait_boost) 307 if (!sg_cpu->iowait_boost)
235 return; 308 return;
236 309
310 /* Reset boost if the CPU appears to have been idle enough */
311 if (sugov_iowait_reset(sg_cpu, time, false))
312 return;
313
314 /*
315 * An IO waiting task has just woken up:
316 * allow to further double the boost value
317 */
237 if (sg_cpu->iowait_boost_pending) { 318 if (sg_cpu->iowait_boost_pending) {
238 sg_cpu->iowait_boost_pending = false; 319 sg_cpu->iowait_boost_pending = false;
239 } else { 320 } else {
321 /*
322 * Otherwise: reduce the boost value and disable it when we
323 * reach the minimum.
324 */
240 sg_cpu->iowait_boost >>= 1; 325 sg_cpu->iowait_boost >>= 1;
241 if (sg_cpu->iowait_boost < sg_cpu->sg_policy->policy->min) { 326 if (sg_cpu->iowait_boost < sg_cpu->sg_policy->policy->min) {
242 sg_cpu->iowait_boost = 0; 327 sg_cpu->iowait_boost = 0;
@@ -244,9 +329,12 @@ static void sugov_iowait_boost(struct sugov_cpu *sg_cpu, unsigned long *util,
244 } 329 }
245 } 330 }
246 331
332 /*
333 * Apply the current boost value: a CPU is boosted only if its current
334 * utilization is smaller then the current IO boost level.
335 */
247 boost_util = sg_cpu->iowait_boost; 336 boost_util = sg_cpu->iowait_boost;
248 boost_max = sg_cpu->iowait_boost_max; 337 boost_max = sg_cpu->iowait_boost_max;
249
250 if (*util * boost_max < *max * boost_util) { 338 if (*util * boost_max < *max * boost_util) {
251 *util = boost_util; 339 *util = boost_util;
252 *max = boost_max; 340 *max = boost_max;
@@ -285,7 +373,7 @@ static void sugov_update_single(struct update_util_data *hook, u64 time,
285 unsigned int next_f; 373 unsigned int next_f;
286 bool busy; 374 bool busy;
287 375
288 sugov_set_iowait_boost(sg_cpu, time, flags); 376 sugov_iowait_boost(sg_cpu, time, flags);
289 sg_cpu->last_update = time; 377 sg_cpu->last_update = time;
290 378
291 ignore_dl_rate_limit(sg_cpu, sg_policy); 379 ignore_dl_rate_limit(sg_cpu, sg_policy);
@@ -298,21 +386,31 @@ static void sugov_update_single(struct update_util_data *hook, u64 time,
298 sugov_get_util(sg_cpu); 386 sugov_get_util(sg_cpu);
299 max = sg_cpu->max; 387 max = sg_cpu->max;
300 util = sugov_aggregate_util(sg_cpu); 388 util = sugov_aggregate_util(sg_cpu);
301 sugov_iowait_boost(sg_cpu, &util, &max); 389 sugov_iowait_apply(sg_cpu, time, &util, &max);
302 next_f = get_next_freq(sg_policy, util, max); 390 next_f = get_next_freq(sg_policy, util, max);
303 /* 391 /*
304 * Do not reduce the frequency if the CPU has not been idle 392 * Do not reduce the frequency if the CPU has not been idle
305 * recently, as the reduction is likely to be premature then. 393 * recently, as the reduction is likely to be premature then.
306 */ 394 */
307 if (busy && next_f < sg_policy->next_freq && 395 if (busy && next_f < sg_policy->next_freq) {
308 sg_policy->next_freq != UINT_MAX) {
309 next_f = sg_policy->next_freq; 396 next_f = sg_policy->next_freq;
310 397
311 /* Reset cached freq as next_freq has changed */ 398 /* Reset cached freq as next_freq has changed */
312 sg_policy->cached_raw_freq = 0; 399 sg_policy->cached_raw_freq = 0;
313 } 400 }
314 401
315 sugov_update_commit(sg_policy, time, next_f); 402 /*
403 * This code runs under rq->lock for the target CPU, so it won't run
404 * concurrently on two different CPUs for the same target and it is not
405 * necessary to acquire the lock in the fast switch case.
406 */
407 if (sg_policy->policy->fast_switch_enabled) {
408 sugov_fast_switch(sg_policy, time, next_f);
409 } else {
410 raw_spin_lock(&sg_policy->update_lock);
411 sugov_deferred_update(sg_policy, time, next_f);
412 raw_spin_unlock(&sg_policy->update_lock);
413 }
316} 414}
317 415
318static unsigned int sugov_next_freq_shared(struct sugov_cpu *sg_cpu, u64 time) 416static unsigned int sugov_next_freq_shared(struct sugov_cpu *sg_cpu, u64 time)
@@ -325,28 +423,12 @@ static unsigned int sugov_next_freq_shared(struct sugov_cpu *sg_cpu, u64 time)
325 for_each_cpu(j, policy->cpus) { 423 for_each_cpu(j, policy->cpus) {
326 struct sugov_cpu *j_sg_cpu = &per_cpu(sugov_cpu, j); 424 struct sugov_cpu *j_sg_cpu = &per_cpu(sugov_cpu, j);
327 unsigned long j_util, j_max; 425 unsigned long j_util, j_max;
328 s64 delta_ns;
329 426
330 sugov_get_util(j_sg_cpu); 427 sugov_get_util(j_sg_cpu);
331
332 /*
333 * If the CFS CPU utilization was last updated before the
334 * previous frequency update and the time elapsed between the
335 * last update of the CPU utilization and the last frequency
336 * update is long enough, reset iowait_boost and util_cfs, as
337 * they are now probably stale. However, still consider the
338 * CPU contribution if it has some DEADLINE utilization
339 * (util_dl).
340 */
341 delta_ns = time - j_sg_cpu->last_update;
342 if (delta_ns > TICK_NSEC) {
343 j_sg_cpu->iowait_boost = 0;
344 j_sg_cpu->iowait_boost_pending = false;
345 }
346
347 j_max = j_sg_cpu->max; 428 j_max = j_sg_cpu->max;
348 j_util = sugov_aggregate_util(j_sg_cpu); 429 j_util = sugov_aggregate_util(j_sg_cpu);
349 sugov_iowait_boost(j_sg_cpu, &j_util, &j_max); 430 sugov_iowait_apply(j_sg_cpu, time, &j_util, &j_max);
431
350 if (j_util * max > j_max * util) { 432 if (j_util * max > j_max * util) {
351 util = j_util; 433 util = j_util;
352 max = j_max; 434 max = j_max;
@@ -365,14 +447,18 @@ sugov_update_shared(struct update_util_data *hook, u64 time, unsigned int flags)
365 447
366 raw_spin_lock(&sg_policy->update_lock); 448 raw_spin_lock(&sg_policy->update_lock);
367 449
368 sugov_set_iowait_boost(sg_cpu, time, flags); 450 sugov_iowait_boost(sg_cpu, time, flags);
369 sg_cpu->last_update = time; 451 sg_cpu->last_update = time;
370 452
371 ignore_dl_rate_limit(sg_cpu, sg_policy); 453 ignore_dl_rate_limit(sg_cpu, sg_policy);
372 454
373 if (sugov_should_update_freq(sg_policy, time)) { 455 if (sugov_should_update_freq(sg_policy, time)) {
374 next_f = sugov_next_freq_shared(sg_cpu, time); 456 next_f = sugov_next_freq_shared(sg_cpu, time);
375 sugov_update_commit(sg_policy, time, next_f); 457
458 if (sg_policy->policy->fast_switch_enabled)
459 sugov_fast_switch(sg_policy, time, next_f);
460 else
461 sugov_deferred_update(sg_policy, time, next_f);
376 } 462 }
377 463
378 raw_spin_unlock(&sg_policy->update_lock); 464 raw_spin_unlock(&sg_policy->update_lock);
@@ -381,13 +467,27 @@ sugov_update_shared(struct update_util_data *hook, u64 time, unsigned int flags)
381static void sugov_work(struct kthread_work *work) 467static void sugov_work(struct kthread_work *work)
382{ 468{
383 struct sugov_policy *sg_policy = container_of(work, struct sugov_policy, work); 469 struct sugov_policy *sg_policy = container_of(work, struct sugov_policy, work);
470 unsigned int freq;
471 unsigned long flags;
472
473 /*
474 * Hold sg_policy->update_lock shortly to handle the case where:
475 * incase sg_policy->next_freq is read here, and then updated by
476 * sugov_deferred_update() just before work_in_progress is set to false
477 * here, we may miss queueing the new update.
478 *
479 * Note: If a work was queued after the update_lock is released,
480 * sugov_work() will just be called again by kthread_work code; and the
481 * request will be proceed before the sugov thread sleeps.
482 */
483 raw_spin_lock_irqsave(&sg_policy->update_lock, flags);
484 freq = sg_policy->next_freq;
485 sg_policy->work_in_progress = false;
486 raw_spin_unlock_irqrestore(&sg_policy->update_lock, flags);
384 487
385 mutex_lock(&sg_policy->work_lock); 488 mutex_lock(&sg_policy->work_lock);
386 __cpufreq_driver_target(sg_policy->policy, sg_policy->next_freq, 489 __cpufreq_driver_target(sg_policy->policy, freq, CPUFREQ_RELATION_L);
387 CPUFREQ_RELATION_L);
388 mutex_unlock(&sg_policy->work_lock); 490 mutex_unlock(&sg_policy->work_lock);
389
390 sg_policy->work_in_progress = false;
391} 491}
392 492
393static void sugov_irq_work(struct irq_work *irq_work) 493static void sugov_irq_work(struct irq_work *irq_work)
@@ -510,11 +610,7 @@ static int sugov_kthread_create(struct sugov_policy *sg_policy)
510 } 610 }
511 611
512 sg_policy->thread = thread; 612 sg_policy->thread = thread;
513 613 kthread_bind_mask(thread, policy->related_cpus);
514 /* Kthread is bound to all CPUs by default */
515 if (!policy->dvfs_possible_from_any_cpu)
516 kthread_bind_mask(thread, policy->related_cpus);
517
518 init_irq_work(&sg_policy->irq_work, sugov_irq_work); 614 init_irq_work(&sg_policy->irq_work, sugov_irq_work);
519 mutex_init(&sg_policy->work_lock); 615 mutex_init(&sg_policy->work_lock);
520 616
@@ -657,7 +753,7 @@ static int sugov_start(struct cpufreq_policy *policy)
657 753
658 sg_policy->freq_update_delay_ns = sg_policy->tunables->rate_limit_us * NSEC_PER_USEC; 754 sg_policy->freq_update_delay_ns = sg_policy->tunables->rate_limit_us * NSEC_PER_USEC;
659 sg_policy->last_freq_update_time = 0; 755 sg_policy->last_freq_update_time = 0;
660 sg_policy->next_freq = UINT_MAX; 756 sg_policy->next_freq = 0;
661 sg_policy->work_in_progress = false; 757 sg_policy->work_in_progress = false;
662 sg_policy->need_freq_update = false; 758 sg_policy->need_freq_update = false;
663 sg_policy->cached_raw_freq = 0; 759 sg_policy->cached_raw_freq = 0;
diff --git a/kernel/time/tick-common.c b/kernel/time/tick-common.c
index 78e598334007..b7005dd21ec1 100644
--- a/kernel/time/tick-common.c
+++ b/kernel/time/tick-common.c
@@ -491,6 +491,7 @@ void tick_freeze(void)
491 if (tick_freeze_depth == num_online_cpus()) { 491 if (tick_freeze_depth == num_online_cpus()) {
492 trace_suspend_resume(TPS("timekeeping_freeze"), 492 trace_suspend_resume(TPS("timekeeping_freeze"),
493 smp_processor_id(), true); 493 smp_processor_id(), true);
494 system_state = SYSTEM_SUSPEND;
494 timekeeping_suspend(); 495 timekeeping_suspend();
495 } else { 496 } else {
496 tick_suspend_local(); 497 tick_suspend_local();
@@ -514,6 +515,7 @@ void tick_unfreeze(void)
514 515
515 if (tick_freeze_depth == num_online_cpus()) { 516 if (tick_freeze_depth == num_online_cpus()) {
516 timekeeping_resume(); 517 timekeeping_resume();
518 system_state = SYSTEM_RUNNING;
517 trace_suspend_resume(TPS("timekeeping_freeze"), 519 trace_suspend_resume(TPS("timekeeping_freeze"),
518 smp_processor_id(), false); 520 smp_processor_id(), false);
519 } else { 521 } else {
diff --git a/tools/power/pm-graph/bootgraph.py b/tools/power/pm-graph/bootgraph.py
index abb4c38f029b..8ee626c0f6a5 100755
--- a/tools/power/pm-graph/bootgraph.py
+++ b/tools/power/pm-graph/bootgraph.py
@@ -1,4 +1,4 @@
1#!/usr/bin/python 1#!/usr/bin/python2
2# 2#
3# Tool for analyzing boot timing 3# Tool for analyzing boot timing
4# Copyright (c) 2013, Intel Corporation. 4# Copyright (c) 2013, Intel Corporation.
diff --git a/tools/power/pm-graph/sleepgraph.8 b/tools/power/pm-graph/sleepgraph.8
index 18baaf6300c9..070be2cf7f74 100644
--- a/tools/power/pm-graph/sleepgraph.8
+++ b/tools/power/pm-graph/sleepgraph.8
@@ -168,6 +168,7 @@ Create a summary page of all tests in \fIindir\fR. Creates summary.html
168in the current folder. The output page is a table of tests with 168in the current folder. The output page is a table of tests with
169suspend and resume values sorted by suspend mode, host, and kernel. 169suspend and resume values sorted by suspend mode, host, and kernel.
170Includes test averages by mode and links to the test html files. 170Includes test averages by mode and links to the test html files.
171Use -genhtml to include tests with missing html.
171.TP 172.TP
172\fB-modes\fR 173\fB-modes\fR
173List available suspend modes. 174List available suspend modes.
@@ -179,6 +180,9 @@ with any options you intend to use to see if they will work.
179\fB-fpdt\fR 180\fB-fpdt\fR
180Print out the contents of the ACPI Firmware Performance Data Table. 181Print out the contents of the ACPI Firmware Performance Data Table.
181.TP 182.TP
183\fB-battery\fR
184Print out battery status and current charge.
185.TP
182\fB-sysinfo\fR 186\fB-sysinfo\fR
183Print out system info extracted from BIOS. Reads /dev/mem directly instead of going through dmidecode. 187Print out system info extracted from BIOS. Reads /dev/mem directly instead of going through dmidecode.
184.TP 188.TP
diff --git a/tools/power/pm-graph/sleepgraph.py b/tools/power/pm-graph/sleepgraph.py
index 266409fb27ae..0c760478f7d7 100755
--- a/tools/power/pm-graph/sleepgraph.py
+++ b/tools/power/pm-graph/sleepgraph.py
@@ -1,4 +1,4 @@
1#!/usr/bin/python 1#!/usr/bin/python2
2# 2#
3# Tool for analyzing suspend/resume timing 3# Tool for analyzing suspend/resume timing
4# Copyright (c) 2013, Intel Corporation. 4# Copyright (c) 2013, Intel Corporation.
@@ -69,7 +69,7 @@ from subprocess import call, Popen, PIPE
69# store system values and test parameters 69# store system values and test parameters
70class SystemValues: 70class SystemValues:
71 title = 'SleepGraph' 71 title = 'SleepGraph'
72 version = '5.0' 72 version = '5.1'
73 ansi = False 73 ansi = False
74 rs = 0 74 rs = 0
75 display = 0 75 display = 0
@@ -240,7 +240,7 @@ class SystemValues:
240 kprobes = dict() 240 kprobes = dict()
241 timeformat = '%.3f' 241 timeformat = '%.3f'
242 cmdline = '%s %s' % \ 242 cmdline = '%s %s' % \
243 (os.path.basename(sys.argv[0]), string.join(sys.argv[1:], ' ')) 243 (os.path.basename(sys.argv[0]), ' '.join(sys.argv[1:]))
244 def __init__(self): 244 def __init__(self):
245 self.archargs = 'args_'+platform.machine() 245 self.archargs = 'args_'+platform.machine()
246 self.hostname = platform.node() 246 self.hostname = platform.node()
@@ -917,12 +917,18 @@ class Data:
917 self.devicegroups.append([phase]) 917 self.devicegroups.append([phase])
918 self.errorinfo = {'suspend':[],'resume':[]} 918 self.errorinfo = {'suspend':[],'resume':[]}
919 def extractErrorInfo(self): 919 def extractErrorInfo(self):
920 elist = {
921 'HWERROR' : '.*\[ *Hardware Error *\].*',
922 'FWBUG' : '.*\[ *Firmware Bug *\].*',
923 'BUG' : '.*BUG.*',
924 'ERROR' : '.*ERROR.*',
925 'WARNING' : '.*WARNING.*',
926 'IRQ' : '.*genirq: .*',
927 'TASKFAIL': '.*Freezing of tasks failed.*',
928 }
920 lf = sysvals.openlog(sysvals.dmesgfile, 'r') 929 lf = sysvals.openlog(sysvals.dmesgfile, 'r')
921 i = 0 930 i = 0
922 list = [] 931 list = []
923 # sl = start line, et = error time, el = error line
924 type = 'ERROR'
925 sl = et = el = -1
926 for line in lf: 932 for line in lf:
927 i += 1 933 i += 1
928 m = re.match('[ \t]*(\[ *)(?P<ktime>[0-9\.]*)(\]) (?P<msg>.*)', line) 934 m = re.match('[ \t]*(\[ *)(?P<ktime>[0-9\.]*)(\]) (?P<msg>.*)', line)
@@ -931,43 +937,13 @@ class Data:
931 t = float(m.group('ktime')) 937 t = float(m.group('ktime'))
932 if t < self.start or t > self.end: 938 if t < self.start or t > self.end:
933 continue 939 continue
934 if t < self.tSuspended: 940 dir = 'suspend' if t < self.tSuspended else 'resume'
935 dir = 'suspend'
936 else:
937 dir = 'resume'
938 msg = m.group('msg') 941 msg = m.group('msg')
939 if re.match('-*\[ *cut here *\]-*', msg): 942 for err in elist:
940 type = 'WARNING' 943 if re.match(elist[err], msg):
941 sl = i 944 list.append((err, dir, t, i, i))
942 elif re.match('genirq: .*', msg):
943 type = 'IRQ'
944 sl = i
945 elif re.match('BUG: .*', msg) or re.match('kernel BUG .*', msg):
946 type = 'BUG'
947 sl = i
948 elif re.match('-*\[ *end trace .*\]-*', msg) or \
949 re.match('R13: .*', msg):
950 if et >= 0 and sl >= 0:
951 list.append((type, dir, et, sl, i))
952 self.kerror = True
953 sl = et = el = -1
954 type = 'ERROR'
955 elif 'Call Trace:' in msg:
956 if el >= 0 and et >= 0:
957 list.append((type, dir, et, el, el))
958 self.kerror = True 945 self.kerror = True
959 et, el = t, i 946 break
960 if sl < 0 or type == 'BUG':
961 slval = i
962 if sl >= 0:
963 slval = sl
964 list.append((type, dir, et, slval, i))
965 self.kerror = True
966 sl = et = el = -1
967 type = 'ERROR'
968 if el >= 0 and et >= 0:
969 list.append((type, dir, et, el, el))
970 self.kerror = True
971 for e in list: 947 for e in list:
972 type, dir, t, idx1, idx2 = e 948 type, dir, t, idx1, idx2 = e
973 sysvals.vprint('kernel %s found in %s at %f' % (type, dir, t)) 949 sysvals.vprint('kernel %s found in %s at %f' % (type, dir, t))
@@ -2331,12 +2307,14 @@ class TestProps:
2331 sv.suspendmode = data.stamp['mode'] 2307 sv.suspendmode = data.stamp['mode']
2332 if sv.suspendmode == 'command' and sv.ftracefile != '': 2308 if sv.suspendmode == 'command' and sv.ftracefile != '':
2333 modes = ['on', 'freeze', 'standby', 'mem', 'disk'] 2309 modes = ['on', 'freeze', 'standby', 'mem', 'disk']
2334 out = Popen(['grep', 'machine_suspend', sv.ftracefile], 2310 fp = sysvals.openlog(sv.ftracefile, 'r')
2335 stderr=PIPE, stdout=PIPE).stdout.read() 2311 for line in fp:
2336 m = re.match('.* machine_suspend\[(?P<mode>.*)\]', out) 2312 m = re.match('.* machine_suspend\[(?P<mode>.*)\]', line)
2337 if m and m.group('mode') in ['1', '2', '3', '4']: 2313 if m and m.group('mode') in ['1', '2', '3', '4']:
2338 sv.suspendmode = modes[int(m.group('mode'))] 2314 sv.suspendmode = modes[int(m.group('mode'))]
2339 data.stamp['mode'] = sv.suspendmode 2315 data.stamp['mode'] = sv.suspendmode
2316 break
2317 fp.close()
2340 m = re.match(self.cmdlinefmt, self.cmdline) 2318 m = re.match(self.cmdlinefmt, self.cmdline)
2341 if m: 2319 if m:
2342 sv.cmdline = m.group('cmd') 2320 sv.cmdline = m.group('cmd')
@@ -2413,7 +2391,7 @@ class ProcessMonitor:
2413# markers, and/or kprobes required for primary parsing. 2391# markers, and/or kprobes required for primary parsing.
2414def doesTraceLogHaveTraceEvents(): 2392def doesTraceLogHaveTraceEvents():
2415 kpcheck = ['_cal: (', '_cpu_down()'] 2393 kpcheck = ['_cal: (', '_cpu_down()']
2416 techeck = sysvals.traceevents[:] 2394 techeck = ['suspend_resume']
2417 tmcheck = ['SUSPEND START', 'RESUME COMPLETE'] 2395 tmcheck = ['SUSPEND START', 'RESUME COMPLETE']
2418 sysvals.usekprobes = False 2396 sysvals.usekprobes = False
2419 fp = sysvals.openlog(sysvals.ftracefile, 'r') 2397 fp = sysvals.openlog(sysvals.ftracefile, 'r')
@@ -2808,7 +2786,7 @@ def parseTraceLog(live=False):
2808 # -- phase changes -- 2786 # -- phase changes --
2809 # start of kernel suspend 2787 # start of kernel suspend
2810 if(re.match('suspend_enter\[.*', t.name)): 2788 if(re.match('suspend_enter\[.*', t.name)):
2811 if(isbegin): 2789 if(isbegin and data.start == data.tKernSus):
2812 data.dmesg[phase]['start'] = t.time 2790 data.dmesg[phase]['start'] = t.time
2813 data.tKernSus = t.time 2791 data.tKernSus = t.time
2814 continue 2792 continue
@@ -3072,13 +3050,20 @@ def parseTraceLog(live=False):
3072 sysvals.vprint('Callgraph found for task %d: %.3fms, %s' % (cg.pid, (cg.end - cg.start)*1000, name)) 3050 sysvals.vprint('Callgraph found for task %d: %.3fms, %s' % (cg.pid, (cg.end - cg.start)*1000, name))
3073 cg.newActionFromFunction(data) 3051 cg.newActionFromFunction(data)
3074 if sysvals.suspendmode == 'command': 3052 if sysvals.suspendmode == 'command':
3075 return testdata 3053 return (testdata, '')
3076 3054
3077 # fill in any missing phases 3055 # fill in any missing phases
3056 error = []
3078 for data in testdata: 3057 for data in testdata:
3058 tn = '' if len(testdata) == 1 else ('%d' % (data.testnumber + 1))
3059 terr = ''
3079 lp = data.phases[0] 3060 lp = data.phases[0]
3080 for p in data.phases: 3061 for p in data.phases:
3081 if(data.dmesg[p]['start'] < 0 and data.dmesg[p]['end'] < 0): 3062 if(data.dmesg[p]['start'] < 0 and data.dmesg[p]['end'] < 0):
3063 if not terr:
3064 print 'TEST%s FAILED: %s failed in %s phase' % (tn, sysvals.suspendmode, lp)
3065 terr = '%s%s failed in %s phase' % (sysvals.suspendmode, tn, lp)
3066 error.append(terr)
3082 sysvals.vprint('WARNING: phase "%s" is missing!' % p) 3067 sysvals.vprint('WARNING: phase "%s" is missing!' % p)
3083 if(data.dmesg[p]['start'] < 0): 3068 if(data.dmesg[p]['start'] < 0):
3084 data.dmesg[p]['start'] = data.dmesg[lp]['end'] 3069 data.dmesg[p]['start'] = data.dmesg[lp]['end']
@@ -3106,7 +3091,7 @@ def parseTraceLog(live=False):
3106 for j in range(i + 1, tc): 3091 for j in range(i + 1, tc):
3107 testdata[j].mergeOverlapDevices(devlist) 3092 testdata[j].mergeOverlapDevices(devlist)
3108 testdata[0].stitchTouchingThreads(testdata[1:]) 3093 testdata[0].stitchTouchingThreads(testdata[1:])
3109 return testdata 3094 return (testdata, ', '.join(error))
3110 3095
3111# Function: loadKernelLog 3096# Function: loadKernelLog
3112# Description: 3097# Description:
@@ -3173,7 +3158,7 @@ def loadKernelLog():
3173 if data: 3158 if data:
3174 testruns.append(data) 3159 testruns.append(data)
3175 if len(testruns) < 1: 3160 if len(testruns) < 1:
3176 doError(' dmesg log has no suspend/resume data: %s' \ 3161 print('ERROR: dmesg log has no suspend/resume data: %s' \
3177 % sysvals.dmesgfile) 3162 % sysvals.dmesgfile)
3178 3163
3179 # fix lines with same timestamp/function with the call and return swapped 3164 # fix lines with same timestamp/function with the call and return swapped
@@ -3521,68 +3506,144 @@ def createHTMLSummarySimple(testruns, htmlfile, folder):
3521 .summary {border:1px solid;}\n\ 3506 .summary {border:1px solid;}\n\
3522 th {border: 1px solid black;background:#222;color:white;}\n\ 3507 th {border: 1px solid black;background:#222;color:white;}\n\
3523 td {font: 16px "Times New Roman";text-align: center;}\n\ 3508 td {font: 16px "Times New Roman";text-align: center;}\n\
3524 tr.alt td {background:#ddd;}\n\ 3509 tr.head td {border: 1px solid black;background:#aaa;}\n\
3525 tr.avg td {background:#aaa;}\n\ 3510 tr.alt {background-color:#ddd;}\n\
3511 tr.notice {color:red;}\n\
3512 .minval {background-color:#BBFFBB;}\n\
3513 .medval {background-color:#BBBBFF;}\n\
3514 .maxval {background-color:#FFBBBB;}\n\
3515 .head a {color:#000;text-decoration: none;}\n\
3526 </style>\n</head>\n<body>\n' 3516 </style>\n</head>\n<body>\n'
3527 3517
3518 # extract the test data into list
3519 list = dict()
3520 tAvg, tMin, tMax, tMed = [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [[], []]
3521 iMin, iMed, iMax = [0, 0], [0, 0], [0, 0]
3522 num = 0
3523 lastmode = ''
3524 cnt = {'pass':0, 'fail':0, 'hang':0}
3525 for data in sorted(testruns, key=lambda v:(v['mode'], v['host'], v['kernel'], v['time'])):
3526 mode = data['mode']
3527 if mode not in list:
3528 list[mode] = {'data': [], 'avg': [0,0], 'min': [0,0], 'max': [0,0], 'med': [0,0]}
3529 if lastmode and lastmode != mode and num > 0:
3530 for i in range(2):
3531 s = sorted(tMed[i])
3532 list[lastmode]['med'][i] = s[int(len(s)/2)]
3533 iMed[i] = tMed[i].index(list[lastmode]['med'][i])
3534 list[lastmode]['avg'] = [tAvg[0] / num, tAvg[1] / num]
3535 list[lastmode]['min'] = tMin
3536 list[lastmode]['max'] = tMax
3537 list[lastmode]['idx'] = (iMin, iMed, iMax)
3538 tAvg, tMin, tMax, tMed = [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [[], []]
3539 iMin, iMed, iMax = [0, 0], [0, 0], [0, 0]
3540 num = 0
3541 tVal = [float(data['suspend']), float(data['resume'])]
3542 list[mode]['data'].append([data['host'], data['kernel'],
3543 data['time'], tVal[0], tVal[1], data['url'], data['result'],
3544 data['issues']])
3545 idx = len(list[mode]['data']) - 1
3546 if data['result'] == 'pass':
3547 cnt['pass'] += 1
3548 for i in range(2):
3549 tMed[i].append(tVal[i])
3550 tAvg[i] += tVal[i]
3551 if tMin[i] == 0 or tVal[i] < tMin[i]:
3552 iMin[i] = idx
3553 tMin[i] = tVal[i]
3554 if tMax[i] == 0 or tVal[i] > tMax[i]:
3555 iMax[i] = idx
3556 tMax[i] = tVal[i]
3557 num += 1
3558 elif data['result'] == 'hang':
3559 cnt['hang'] += 1
3560 elif data['result'] == 'fail':
3561 cnt['fail'] += 1
3562 lastmode = mode
3563 if lastmode and num > 0:
3564 for i in range(2):
3565 s = sorted(tMed[i])
3566 list[lastmode]['med'][i] = s[int(len(s)/2)]
3567 iMed[i] = tMed[i].index(list[lastmode]['med'][i])
3568 list[lastmode]['avg'] = [tAvg[0] / num, tAvg[1] / num]
3569 list[lastmode]['min'] = tMin
3570 list[lastmode]['max'] = tMax
3571 list[lastmode]['idx'] = (iMin, iMed, iMax)
3572
3528 # group test header 3573 # group test header
3529 html += '<div class="stamp">%s (%d tests)</div>\n' % (folder, len(testruns)) 3574 desc = []
3575 for ilk in sorted(cnt, reverse=True):
3576 if cnt[ilk] > 0:
3577 desc.append('%d %s' % (cnt[ilk], ilk))
3578 html += '<div class="stamp">%s (%d tests: %s)</div>\n' % (folder, len(testruns), ', '.join(desc))
3530 th = '\t<th>{0}</th>\n' 3579 th = '\t<th>{0}</th>\n'
3531 td = '\t<td>{0}</td>\n' 3580 td = '\t<td>{0}</td>\n'
3581 tdh = '\t<td{1}>{0}</td>\n'
3532 tdlink = '\t<td><a href="{0}">html</a></td>\n' 3582 tdlink = '\t<td><a href="{0}">html</a></td>\n'
3533 3583
3534 # table header 3584 # table header
3535 html += '<table class="summary">\n<tr>\n' + th.format('#') +\ 3585 html += '<table class="summary">\n<tr>\n' + th.format('#') +\
3536 th.format('Mode') + th.format('Host') + th.format('Kernel') +\ 3586 th.format('Mode') + th.format('Host') + th.format('Kernel') +\
3537 th.format('Test Time') + th.format('Suspend') + th.format('Resume') +\ 3587 th.format('Test Time') + th.format('Result') + th.format('Issues') +\
3538 th.format('Detail') + '</tr>\n' 3588 th.format('Suspend') + th.format('Resume') + th.format('Detail') + '</tr>\n'
3539 3589
3540 # test data, 1 row per test 3590 # export list into html
3541 avg = '<tr class="avg"><td></td><td></td><td></td><td></td>'+\ 3591 head = '<tr class="head"><td>{0}</td><td>{1}</td>'+\
3542 '<td>Average of {0} {1} tests</td><td>{2}</td><td>{3}</td><td></td></tr>\n' 3592 '<td colspan=8 class="sus">Suspend Avg={2} '+\
3543 sTimeAvg = rTimeAvg = 0.0 3593 '<span class=minval><a href="#s{10}min">Min={3}</a></span> '+\
3544 mode = '' 3594 '<span class=medval><a href="#s{10}med">Med={4}</a></span> '+\
3545 num = 0 3595 '<span class=maxval><a href="#s{10}max">Max={5}</a></span> '+\
3546 for data in sorted(testruns, key=lambda v:(v['mode'], v['host'], v['kernel'], v['time'])): 3596 'Resume Avg={6} '+\
3547 if mode != data['mode']: 3597 '<span class=minval><a href="#r{10}min">Min={7}</a></span> '+\
3548 # test average line 3598 '<span class=medval><a href="#r{10}med">Med={8}</a></span> '+\
3549 if(num > 0): 3599 '<span class=maxval><a href="#r{10}max">Max={9}</a></span></td>'+\
3550 sTimeAvg /= (num - 1) 3600 '</tr>\n'
3551 rTimeAvg /= (num - 1) 3601 headnone = '<tr class="head"><td>{0}</td><td>{1}</td><td colspan=8></td></tr>\n'
3552 html += avg.format('%d' % (num - 1), mode, 3602 for mode in list:
3553 '%3.3f ms' % sTimeAvg, '%3.3f ms' % rTimeAvg) 3603 # header line for each suspend mode
3554 sTimeAvg = rTimeAvg = 0.0 3604 num = 0
3555 mode = data['mode'] 3605 tAvg, tMin, tMax, tMed = list[mode]['avg'], list[mode]['min'],\
3556 num = 1 3606 list[mode]['max'], list[mode]['med']
3557 # alternate row color 3607 count = len(list[mode]['data'])
3558 if num % 2 == 1: 3608 if 'idx' in list[mode]:
3559 html += '<tr class="alt">\n' 3609 iMin, iMed, iMax = list[mode]['idx']
3610 html += head.format('%d' % count, mode.upper(),
3611 '%.3f' % tAvg[0], '%.3f' % tMin[0], '%.3f' % tMed[0], '%.3f' % tMax[0],
3612 '%.3f' % tAvg[1], '%.3f' % tMin[1], '%.3f' % tMed[1], '%.3f' % tMax[1],
3613 mode.lower()
3614 )
3560 else: 3615 else:
3561 html += '<tr>\n' 3616 iMin = iMed = iMax = [-1, -1, -1]
3562 html += td.format("%d" % num) 3617 html += headnone.format('%d' % count, mode.upper())
3563 num += 1 3618 for d in list[mode]['data']:
3564 # basic info 3619 # row classes - alternate row color
3565 for item in ['mode', 'host', 'kernel', 'time']: 3620 rcls = ['alt'] if num % 2 == 1 else []
3566 val = "unknown" 3621 if d[6] != 'pass':
3567 if(item in data): 3622 rcls.append('notice')
3568 val = data[item] 3623 html += '<tr class="'+(' '.join(rcls))+'">\n' if len(rcls) > 0 else '<tr>\n'
3569 html += td.format(val) 3624 # figure out if the line has sus or res highlighted
3570 # suspend time 3625 idx = list[mode]['data'].index(d)
3571 sTime = float(data['suspend']) 3626 tHigh = ['', '']
3572 sTimeAvg += sTime 3627 for i in range(2):
3573 html += td.format('%.3f ms' % sTime) 3628 tag = 's%s' % mode if i == 0 else 'r%s' % mode
3574 # resume time 3629 if idx == iMin[i]:
3575 rTime = float(data['resume']) 3630 tHigh[i] = ' id="%smin" class=minval title="Minimum"' % tag
3576 rTimeAvg += rTime 3631 elif idx == iMax[i]:
3577 html += td.format('%.3f ms' % rTime) 3632 tHigh[i] = ' id="%smax" class=maxval title="Maximum"' % tag
3578 # link to the output html 3633 elif idx == iMed[i]:
3579 html += tdlink.format(data['url']) + '</tr>\n' 3634 tHigh[i] = ' id="%smed" class=medval title="Median"' % tag
3580 # last test average line 3635 html += td.format("%d" % (list[mode]['data'].index(d) + 1)) # row
3581 if(num > 0): 3636 html += td.format(mode) # mode
3582 sTimeAvg /= (num - 1) 3637 html += td.format(d[0]) # host
3583 rTimeAvg /= (num - 1) 3638 html += td.format(d[1]) # kernel
3584 html += avg.format('%d' % (num - 1), mode, 3639 html += td.format(d[2]) # time
3585 '%3.3f ms' % sTimeAvg, '%3.3f ms' % rTimeAvg) 3640 html += td.format(d[6]) # result
3641 html += td.format(d[7]) # issues
3642 html += tdh.format('%.3f ms' % d[3], tHigh[0]) if d[3] else td.format('') # suspend
3643 html += tdh.format('%.3f ms' % d[4], tHigh[1]) if d[4] else td.format('') # resume
3644 html += tdlink.format(d[5]) if d[5] else td.format('') # url
3645 html += '</tr>\n'
3646 num += 1
3586 3647
3587 # flush the data to file 3648 # flush the data to file
3588 hf = open(htmlfile, 'w') 3649 hf = open(htmlfile, 'w')
@@ -3607,7 +3668,7 @@ def ordinal(value):
3607# testruns: array of Data objects from parseKernelLog or parseTraceLog 3668# testruns: array of Data objects from parseKernelLog or parseTraceLog
3608# Output: 3669# Output:
3609# True if the html file was created, false if it failed 3670# True if the html file was created, false if it failed
3610def createHTML(testruns): 3671def createHTML(testruns, testfail):
3611 if len(testruns) < 1: 3672 if len(testruns) < 1:
3612 print('ERROR: Not enough test data to build a timeline') 3673 print('ERROR: Not enough test data to build a timeline')
3613 return 3674 return
@@ -3641,6 +3702,7 @@ def createHTML(testruns):
3641 '<td class="purple">{4}Firmware Resume: {2} ms</td>'\ 3702 '<td class="purple">{4}Firmware Resume: {2} ms</td>'\
3642 '<td class="yellow" title="time from firmware mode to return from kernel enter_state({5}) [kernel time only]">{4}Kernel Resume: {3} ms</td>'\ 3703 '<td class="yellow" title="time from firmware mode to return from kernel enter_state({5}) [kernel time only]">{4}Kernel Resume: {3} ms</td>'\
3643 '</tr>\n</table>\n' 3704 '</tr>\n</table>\n'
3705 html_fail = '<table class="testfail"><tr><td>{0}</td></tr></table>\n'
3644 3706
3645 # html format variables 3707 # html format variables
3646 scaleH = 20 3708 scaleH = 20
@@ -3708,6 +3770,9 @@ def createHTML(testruns):
3708 resume_time, testdesc, stitle, rtitle) 3770 resume_time, testdesc, stitle, rtitle)
3709 devtl.html += thtml 3771 devtl.html += thtml
3710 3772
3773 if testfail:
3774 devtl.html += html_fail.format(testfail)
3775
3711 # time scale for potentially multiple datasets 3776 # time scale for potentially multiple datasets
3712 t0 = testruns[0].start 3777 t0 = testruns[0].start
3713 tMax = testruns[-1].end 3778 tMax = testruns[-1].end
@@ -4006,6 +4071,7 @@ def addCSS(hf, sv, testcount=1, kerror=False, extra=''):
4006 .blue {background:rgba(169,208,245,0.4);}\n\ 4071 .blue {background:rgba(169,208,245,0.4);}\n\
4007 .time1 {font:22px Arial;border:1px solid;}\n\ 4072 .time1 {font:22px Arial;border:1px solid;}\n\
4008 .time2 {font:15px Arial;border-bottom:1px solid;border-left:1px solid;border-right:1px solid;}\n\ 4073 .time2 {font:15px Arial;border-bottom:1px solid;border-left:1px solid;border-right:1px solid;}\n\
4074 .testfail {font:bold 22px Arial;color:red;border:1px dashed;}\n\
4009 td {text-align:center;}\n\ 4075 td {text-align:center;}\n\
4010 r {color:#500000;font:15px Tahoma;}\n\ 4076 r {color:#500000;font:15px Tahoma;}\n\
4011 n {color:#505050;font:15px Tahoma;}\n\ 4077 n {color:#505050;font:15px Tahoma;}\n\
@@ -4927,6 +4993,25 @@ def dmidecode(mempath, fatal=False):
4927 count += 1 4993 count += 1
4928 return out 4994 return out
4929 4995
4996def getBattery():
4997 p = '/sys/class/power_supply'
4998 bat = dict()
4999 for d in os.listdir(p):
5000 type = sysvals.getVal(os.path.join(p, d, 'type')).strip().lower()
5001 if type != 'battery':
5002 continue
5003 for v in ['status', 'energy_now', 'capacity_now']:
5004 bat[v] = sysvals.getVal(os.path.join(p, d, v)).strip().lower()
5005 break
5006 ac = True
5007 if 'status' in bat and 'discharging' in bat['status']:
5008 ac = False
5009 charge = 0
5010 for v in ['energy_now', 'capacity_now']:
5011 if v in bat and bat[v]:
5012 charge = int(bat[v])
5013 return (ac, charge)
5014
4930# Function: getFPDT 5015# Function: getFPDT
4931# Description: 5016# Description:
4932# Read the acpi bios tables and pull out FPDT, the firmware data 5017# Read the acpi bios tables and pull out FPDT, the firmware data
@@ -5202,8 +5287,9 @@ def getArgFloat(name, args, min, max, main=True):
5202 5287
5203def processData(live=False): 5288def processData(live=False):
5204 print('PROCESSING DATA') 5289 print('PROCESSING DATA')
5290 error = ''
5205 if(sysvals.usetraceevents): 5291 if(sysvals.usetraceevents):
5206 testruns = parseTraceLog(live) 5292 testruns, error = parseTraceLog(live)
5207 if sysvals.dmesgfile: 5293 if sysvals.dmesgfile:
5208 for data in testruns: 5294 for data in testruns:
5209 data.extractErrorInfo() 5295 data.extractErrorInfo()
@@ -5220,15 +5306,18 @@ def processData(live=False):
5220 for data in testruns: 5306 for data in testruns:
5221 data.debugPrint() 5307 data.debugPrint()
5222 sys.exit() 5308 sys.exit()
5223 5309 if len(testruns) < 1:
5310 return (testruns, {'error': 'timeline generation failed'})
5224 sysvals.vprint('Creating the html timeline (%s)...' % sysvals.htmlfile) 5311 sysvals.vprint('Creating the html timeline (%s)...' % sysvals.htmlfile)
5225 createHTML(testruns) 5312 createHTML(testruns, error)
5226 print('DONE') 5313 print('DONE')
5227 data = testruns[0] 5314 data = testruns[0]
5228 stamp = data.stamp 5315 stamp = data.stamp
5229 stamp['suspend'], stamp['resume'] = data.getTimeValues() 5316 stamp['suspend'], stamp['resume'] = data.getTimeValues()
5230 if data.fwValid: 5317 if data.fwValid:
5231 stamp['fwsuspend'], stamp['fwresume'] = data.fwSuspend, data.fwResume 5318 stamp['fwsuspend'], stamp['fwresume'] = data.fwSuspend, data.fwResume
5319 if error:
5320 stamp['error'] = error
5232 return (testruns, stamp) 5321 return (testruns, stamp)
5233 5322
5234# Function: rerunTest 5323# Function: rerunTest
@@ -5268,58 +5357,88 @@ def runTest(n=0):
5268 sysvals.sudouser(sysvals.testdir) 5357 sysvals.sudouser(sysvals.testdir)
5269 sysvals.outputResult(stamp, n) 5358 sysvals.outputResult(stamp, n)
5270 5359
5271def find_in_html(html, strs, div=False): 5360def find_in_html(html, start, end, firstonly=True):
5272 for str in strs: 5361 n, out = 0, []
5273 l = len(str) 5362 while n < len(html):
5274 i = html.find(str) 5363 m = re.search(start, html[n:])
5275 if i >= 0: 5364 if not m:
5276 break 5365 break
5277 if i < 0: 5366 i = m.end()
5278 return '' 5367 m = re.search(end, html[n+i:])
5279 if not div: 5368 if not m:
5280 return re.search(r'[-+]?\d*\.\d+|\d+', html[i+l:i+l+50]).group() 5369 break
5281 n = html[i+l:].find('</div>') 5370 j = m.start()
5282 if n < 0: 5371 str = html[n+i:n+i+j]
5372 if end == 'ms':
5373 num = re.search(r'[-+]?\d*\.\d+|\d+', str)
5374 str = num.group() if num else 'NaN'
5375 if firstonly:
5376 return str
5377 out.append(str)
5378 n += i+j
5379 if firstonly:
5283 return '' 5380 return ''
5284 return html[i+l:i+l+n] 5381 return out
5285 5382
5286# Function: runSummary 5383# Function: runSummary
5287# Description: 5384# Description:
5288# create a summary of tests in a sub-directory 5385# create a summary of tests in a sub-directory
5289def runSummary(subdir, local=True): 5386def runSummary(subdir, local=True, genhtml=False):
5290 inpath = os.path.abspath(subdir) 5387 inpath = os.path.abspath(subdir)
5291 outpath = inpath 5388 outpath = inpath
5292 if local: 5389 if local:
5293 outpath = os.path.abspath('.') 5390 outpath = os.path.abspath('.')
5294 print('Generating a summary of folder "%s"' % inpath) 5391 print('Generating a summary of folder "%s"' % inpath)
5392 if genhtml:
5393 for dirname, dirnames, filenames in os.walk(subdir):
5394 sysvals.dmesgfile = sysvals.ftracefile = sysvals.htmlfile = ''
5395 for filename in filenames:
5396 if(re.match('.*_dmesg.txt', filename)):
5397 sysvals.dmesgfile = os.path.join(dirname, filename)
5398 elif(re.match('.*_ftrace.txt', filename)):
5399 sysvals.ftracefile = os.path.join(dirname, filename)
5400 sysvals.setOutputFile()
5401 if sysvals.ftracefile and sysvals.htmlfile and \
5402 not os.path.exists(sysvals.htmlfile):
5403 print('FTRACE: %s' % sysvals.ftracefile)
5404 if sysvals.dmesgfile:
5405 print('DMESG : %s' % sysvals.dmesgfile)
5406 rerunTest()
5295 testruns = [] 5407 testruns = []
5296 for dirname, dirnames, filenames in os.walk(subdir): 5408 for dirname, dirnames, filenames in os.walk(subdir):
5297 for filename in filenames: 5409 for filename in filenames:
5298 if(not re.match('.*.html', filename)): 5410 if(not re.match('.*.html', filename)):
5299 continue 5411 continue
5300 file = os.path.join(dirname, filename) 5412 file = os.path.join(dirname, filename)
5301 html = open(file, 'r').read(10000) 5413 html = open(file, 'r').read()
5302 suspend = find_in_html(html, 5414 suspend = find_in_html(html, 'Kernel Suspend', 'ms')
5303 ['Kernel Suspend: ', 'Kernel Suspend Time: ']) 5415 resume = find_in_html(html, 'Kernel Resume', 'ms')
5304 resume = find_in_html(html, 5416 line = find_in_html(html, '<div class="stamp">', '</div>')
5305 ['Kernel Resume: ', 'Kernel Resume Time: '])
5306 line = find_in_html(html, ['<div class="stamp">'], True)
5307 stmp = line.split() 5417 stmp = line.split()
5308 if not suspend or not resume or len(stmp) < 4: 5418 if not suspend or not resume or len(stmp) != 8:
5309 continue 5419 continue
5420 try:
5421 dt = datetime.strptime(' '.join(stmp[3:]), '%B %d %Y, %I:%M:%S %p')
5422 except:
5423 continue
5424 tstr = dt.strftime('%Y/%m/%d %H:%M:%S')
5425 error = find_in_html(html, '<table class="testfail"><tr><td>', '</td>')
5426 result = 'fail' if error else 'pass'
5427 ilist = []
5428 e = find_in_html(html, 'class="err"[\w=":;\.%\- ]*>', '&rarr;</div>', False)
5429 for i in list(set(e)):
5430 ilist.append('%sx%d' % (i, e.count(i)) if e.count(i) > 1 else i)
5310 data = { 5431 data = {
5432 'mode': stmp[2],
5311 'host': stmp[0], 5433 'host': stmp[0],
5312 'kernel': stmp[1], 5434 'kernel': stmp[1],
5313 'mode': stmp[2], 5435 'time': tstr,
5314 'time': string.join(stmp[3:], ' '), 5436 'result': result,
5437 'issues': ','.join(ilist),
5315 'suspend': suspend, 5438 'suspend': suspend,
5316 'resume': resume, 5439 'resume': resume,
5317 'url': os.path.relpath(file, outpath), 5440 'url': os.path.relpath(file, outpath),
5318 } 5441 }
5319 if len(stmp) == 7:
5320 data['kernel'] = 'unknown'
5321 data['mode'] = stmp[1]
5322 data['time'] = string.join(stmp[2:], ' ')
5323 testruns.append(data) 5442 testruns.append(data)
5324 outfile = os.path.join(outpath, 'summary.html') 5443 outfile = os.path.join(outpath, 'summary.html')
5325 print('Summary file: %s' % outfile) 5444 print('Summary file: %s' % outfile)
@@ -5609,11 +5728,12 @@ def printHelp():
5609 print(' -modes List available suspend modes') 5728 print(' -modes List available suspend modes')
5610 print(' -status Test to see if the system is enabled to run this tool') 5729 print(' -status Test to see if the system is enabled to run this tool')
5611 print(' -fpdt Print out the contents of the ACPI Firmware Performance Data Table') 5730 print(' -fpdt Print out the contents of the ACPI Firmware Performance Data Table')
5731 print(' -battery Print out battery info (if available)')
5612 print(' -sysinfo Print out system info extracted from BIOS') 5732 print(' -sysinfo Print out system info extracted from BIOS')
5613 print(' -devinfo Print out the pm settings of all devices which support runtime suspend') 5733 print(' -devinfo Print out the pm settings of all devices which support runtime suspend')
5614 print(' -flist Print the list of functions currently being captured in ftrace') 5734 print(' -flist Print the list of functions currently being captured in ftrace')
5615 print(' -flistall Print all functions capable of being captured in ftrace') 5735 print(' -flistall Print all functions capable of being captured in ftrace')
5616 print(' -summary directory Create a summary of all test in this dir') 5736 print(' -summary dir Create a summary of tests in this dir [-genhtml builds missing html]')
5617 print(' [redo]') 5737 print(' [redo]')
5618 print(' -ftrace ftracefile Create HTML output using ftrace input (used with -dmesg)') 5738 print(' -ftrace ftracefile Create HTML output using ftrace input (used with -dmesg)')
5619 print(' -dmesg dmesgfile Create HTML output using dmesg (used with -ftrace)') 5739 print(' -dmesg dmesgfile Create HTML output using dmesg (used with -ftrace)')
@@ -5623,8 +5743,9 @@ def printHelp():
5623# ----------------- MAIN -------------------- 5743# ----------------- MAIN --------------------
5624# exec start (skipped if script is loaded as library) 5744# exec start (skipped if script is loaded as library)
5625if __name__ == '__main__': 5745if __name__ == '__main__':
5746 genhtml = False
5626 cmd = '' 5747 cmd = ''
5627 simplecmds = ['-sysinfo', '-modes', '-fpdt', '-flist', '-flistall', '-devinfo', '-status'] 5748 simplecmds = ['-sysinfo', '-modes', '-fpdt', '-flist', '-flistall', '-devinfo', '-status', '-battery']
5628 if '-f' in sys.argv: 5749 if '-f' in sys.argv:
5629 sysvals.cgskip = sysvals.configFile('cgskip.txt') 5750 sysvals.cgskip = sysvals.configFile('cgskip.txt')
5630 # loop through the command line arguments 5751 # loop through the command line arguments
@@ -5660,6 +5781,8 @@ if __name__ == '__main__':
5660 sysvals.skiphtml = True 5781 sysvals.skiphtml = True
5661 elif(arg == '-cgdump'): 5782 elif(arg == '-cgdump'):
5662 sysvals.cgdump = True 5783 sysvals.cgdump = True
5784 elif(arg == '-genhtml'):
5785 genhtml = True
5663 elif(arg == '-addlogs'): 5786 elif(arg == '-addlogs'):
5664 sysvals.dmesglog = sysvals.ftracelog = True 5787 sysvals.dmesglog = sysvals.ftracelog = True
5665 elif(arg == '-verbose'): 5788 elif(arg == '-verbose'):
@@ -5856,6 +5979,8 @@ if __name__ == '__main__':
5856 statusCheck(True) 5979 statusCheck(True)
5857 elif(cmd == 'fpdt'): 5980 elif(cmd == 'fpdt'):
5858 getFPDT(True) 5981 getFPDT(True)
5982 elif(cmd == 'battery'):
5983 print 'AC Connect: %s\nCharge: %d' % getBattery()
5859 elif(cmd == 'sysinfo'): 5984 elif(cmd == 'sysinfo'):
5860 sysvals.printSystemInfo(True) 5985 sysvals.printSystemInfo(True)
5861 elif(cmd == 'devinfo'): 5986 elif(cmd == 'devinfo'):
@@ -5867,7 +5992,7 @@ if __name__ == '__main__':
5867 elif(cmd == 'flistall'): 5992 elif(cmd == 'flistall'):
5868 sysvals.getFtraceFilterFunctions(False) 5993 sysvals.getFtraceFilterFunctions(False)
5869 elif(cmd == 'summary'): 5994 elif(cmd == 'summary'):
5870 runSummary(sysvals.outdir, True) 5995 runSummary(sysvals.outdir, True, genhtml)
5871 sys.exit() 5996 sys.exit()
5872 5997
5873 # if instructed, re-analyze existing data files 5998 # if instructed, re-analyze existing data files
@@ -5920,7 +6045,7 @@ if __name__ == '__main__':
5920 print('TEST (%d/%d) COMPLETE' % (i+1, sysvals.multitest['count'])) 6045 print('TEST (%d/%d) COMPLETE' % (i+1, sysvals.multitest['count']))
5921 sysvals.logmsg = '' 6046 sysvals.logmsg = ''
5922 if not sysvals.skiphtml: 6047 if not sysvals.skiphtml:
5923 runSummary(sysvals.outdir, False) 6048 runSummary(sysvals.outdir, False, False)
5924 sysvals.sudouser(sysvals.outdir) 6049 sysvals.sudouser(sysvals.outdir)
5925 else: 6050 else:
5926 if sysvals.outdir: 6051 if sysvals.outdir:
diff --git a/tools/power/x86/intel_pstate_tracer/intel_pstate_tracer.py b/tools/power/x86/intel_pstate_tracer/intel_pstate_tracer.py
index 29f50d4cfea0..84e2b648e622 100755
--- a/tools/power/x86/intel_pstate_tracer/intel_pstate_tracer.py
+++ b/tools/power/x86/intel_pstate_tracer/intel_pstate_tracer.py
@@ -28,6 +28,7 @@ import subprocess
28import os 28import os
29import time 29import time
30import re 30import re
31import signal
31import sys 32import sys
32import getopt 33import getopt
33import Gnuplot 34import Gnuplot
@@ -78,11 +79,12 @@ def print_help():
78 print(' Or') 79 print(' Or')
79 print(' ./intel_pstate_tracer.py [--cpu cpus] ---trace_file <trace_file> --name <test_name>') 80 print(' ./intel_pstate_tracer.py [--cpu cpus] ---trace_file <trace_file> --name <test_name>')
80 print(' To generate trace file, parse and plot, use (sudo required):') 81 print(' To generate trace file, parse and plot, use (sudo required):')
81 print(' sudo ./intel_pstate_tracer.py [-c cpus] -i <interval> -n <test_name>') 82 print(' sudo ./intel_pstate_tracer.py [-c cpus] -i <interval> -n <test_name> -m <kbytes>')
82 print(' Or') 83 print(' Or')
83 print(' sudo ./intel_pstate_tracer.py [--cpu cpus] --interval <interval> --name <test_name>') 84 print(' sudo ./intel_pstate_tracer.py [--cpu cpus] --interval <interval> --name <test_name> --memory <kbytes>')
84 print(' Optional argument:') 85 print(' Optional argument:')
85 print(' cpus: comma separated list of CPUs') 86 print(' cpus: comma separated list of CPUs')
87 print(' kbytes: Kilo bytes of memory per CPU to allocate to the trace buffer. Default: 10240')
86 print(' Output:') 88 print(' Output:')
87 print(' If not already present, creates a "results/test_name" folder in the current working directory with:') 89 print(' If not already present, creates a "results/test_name" folder in the current working directory with:')
88 print(' cpu.csv - comma seperated values file with trace contents and some additional calculations.') 90 print(' cpu.csv - comma seperated values file with trace contents and some additional calculations.')
@@ -379,7 +381,7 @@ def clear_trace_file():
379 f_handle.close() 381 f_handle.close()
380 except: 382 except:
381 print('IO error clearing trace file ') 383 print('IO error clearing trace file ')
382 quit() 384 sys.exit(2)
383 385
384def enable_trace(): 386def enable_trace():
385 """ Enable trace """ 387 """ Enable trace """
@@ -389,7 +391,7 @@ def enable_trace():
389 , 'w').write("1") 391 , 'w').write("1")
390 except: 392 except:
391 print('IO error enabling trace ') 393 print('IO error enabling trace ')
392 quit() 394 sys.exit(2)
393 395
394def disable_trace(): 396def disable_trace():
395 """ Disable trace """ 397 """ Disable trace """
@@ -399,17 +401,17 @@ def disable_trace():
399 , 'w').write("0") 401 , 'w').write("0")
400 except: 402 except:
401 print('IO error disabling trace ') 403 print('IO error disabling trace ')
402 quit() 404 sys.exit(2)
403 405
404def set_trace_buffer_size(): 406def set_trace_buffer_size():
405 """ Set trace buffer size """ 407 """ Set trace buffer size """
406 408
407 try: 409 try:
408 open('/sys/kernel/debug/tracing/buffer_size_kb' 410 with open('/sys/kernel/debug/tracing/buffer_size_kb', 'w') as fp:
409 , 'w').write("10240") 411 fp.write(memory)
410 except: 412 except:
411 print('IO error setting trace buffer size ') 413 print('IO error setting trace buffer size ')
412 quit() 414 sys.exit(2)
413 415
414def free_trace_buffer(): 416def free_trace_buffer():
415 """ Free the trace buffer memory """ 417 """ Free the trace buffer memory """
@@ -418,8 +420,8 @@ def free_trace_buffer():
418 open('/sys/kernel/debug/tracing/buffer_size_kb' 420 open('/sys/kernel/debug/tracing/buffer_size_kb'
419 , 'w').write("1") 421 , 'w').write("1")
420 except: 422 except:
421 print('IO error setting trace buffer size ') 423 print('IO error freeing trace buffer ')
422 quit() 424 sys.exit(2)
423 425
424def read_trace_data(filename): 426def read_trace_data(filename):
425 """ Read and parse trace data """ 427 """ Read and parse trace data """
@@ -431,7 +433,7 @@ def read_trace_data(filename):
431 data = open(filename, 'r').read() 433 data = open(filename, 'r').read()
432 except: 434 except:
433 print('Error opening ', filename) 435 print('Error opening ', filename)
434 quit() 436 sys.exit(2)
435 437
436 for line in data.splitlines(): 438 for line in data.splitlines():
437 search_obj = \ 439 search_obj = \
@@ -489,10 +491,22 @@ def read_trace_data(filename):
489# Now seperate the main overall csv file into per CPU csv files. 491# Now seperate the main overall csv file into per CPU csv files.
490 split_csv() 492 split_csv()
491 493
494def signal_handler(signal, frame):
495 print(' SIGINT: Forcing cleanup before exit.')
496 if interval:
497 disable_trace()
498 clear_trace_file()
499 # Free the memory
500 free_trace_buffer()
501 sys.exit(0)
502
503signal.signal(signal.SIGINT, signal_handler)
504
492interval = "" 505interval = ""
493filename = "" 506filename = ""
494cpu_list = "" 507cpu_list = ""
495testname = "" 508testname = ""
509memory = "10240"
496graph_data_present = False; 510graph_data_present = False;
497 511
498valid1 = False 512valid1 = False
@@ -501,7 +515,7 @@ valid2 = False
501cpu_mask = zeros((MAX_CPUS,), dtype=int) 515cpu_mask = zeros((MAX_CPUS,), dtype=int)
502 516
503try: 517try:
504 opts, args = getopt.getopt(sys.argv[1:],"ht:i:c:n:",["help","trace_file=","interval=","cpu=","name="]) 518 opts, args = getopt.getopt(sys.argv[1:],"ht:i:c:n:m:",["help","trace_file=","interval=","cpu=","name=","memory="])
505except getopt.GetoptError: 519except getopt.GetoptError:
506 print_help() 520 print_help()
507 sys.exit(2) 521 sys.exit(2)
@@ -521,6 +535,8 @@ for opt, arg in opts:
521 elif opt in ("-n", "--name"): 535 elif opt in ("-n", "--name"):
522 valid2 = True 536 valid2 = True
523 testname = arg 537 testname = arg
538 elif opt in ("-m", "--memory"):
539 memory = arg
524 540
525if not (valid1 and valid2): 541if not (valid1 and valid2):
526 print_help() 542 print_help()
@@ -569,6 +585,11 @@ current_max_cpu = 0
569 585
570read_trace_data(filename) 586read_trace_data(filename)
571 587
588clear_trace_file()
589# Free the memory
590if interval:
591 free_trace_buffer()
592
572if graph_data_present == False: 593if graph_data_present == False:
573 print('No valid data to plot') 594 print('No valid data to plot')
574 sys.exit(2) 595 sys.exit(2)
@@ -593,9 +614,4 @@ for root, dirs, files in os.walk('.'):
593 for f in files: 614 for f in files:
594 fix_ownership(f) 615 fix_ownership(f)
595 616
596clear_trace_file()
597# Free the memory
598if interval:
599 free_trace_buffer()
600
601os.chdir('../../') 617os.chdir('../../')
diff --git a/tools/power/x86/turbostat/Makefile b/tools/power/x86/turbostat/Makefile
index a9bc914a8fe8..2ab25aa38263 100644
--- a/tools/power/x86/turbostat/Makefile
+++ b/tools/power/x86/turbostat/Makefile
@@ -25,4 +25,4 @@ install : turbostat
25 install -d $(DESTDIR)$(PREFIX)/bin 25 install -d $(DESTDIR)$(PREFIX)/bin
26 install $(BUILD_OUTPUT)/turbostat $(DESTDIR)$(PREFIX)/bin/turbostat 26 install $(BUILD_OUTPUT)/turbostat $(DESTDIR)$(PREFIX)/bin/turbostat
27 install -d $(DESTDIR)$(PREFIX)/share/man/man8 27 install -d $(DESTDIR)$(PREFIX)/share/man/man8
28 install turbostat.8 $(DESTDIR)$(PREFIX)/share/man/man8 28 install -m 644 turbostat.8 $(DESTDIR)$(PREFIX)/share/man/man8
diff --git a/tools/power/x86/turbostat/turbostat.8 b/tools/power/x86/turbostat/turbostat.8
index ccf2a69365cc..ca9ef7017624 100644
--- a/tools/power/x86/turbostat/turbostat.8
+++ b/tools/power/x86/turbostat/turbostat.8
@@ -54,9 +54,12 @@ name as necessary to disambiguate it from others is necessary. Note that option
54.PP 54.PP
55\fB--cpu cpu-set\fP limit output to system summary plus the specified cpu-set. If cpu-set is the string "core", then the system summary plus the first CPU in each core are printed -- eg. subsequent HT siblings are not printed. Or if cpu-set is the string "package", then the system summary plus the first CPU in each package is printed. Otherwise, the system summary plus the specified set of CPUs are printed. The cpu-set is ordered from low to high, comma delimited with ".." and "-" permitted to denote a range. eg. 1,2,8,14..17,21-44 55\fB--cpu cpu-set\fP limit output to system summary plus the specified cpu-set. If cpu-set is the string "core", then the system summary plus the first CPU in each core are printed -- eg. subsequent HT siblings are not printed. Or if cpu-set is the string "package", then the system summary plus the first CPU in each package is printed. Otherwise, the system summary plus the specified set of CPUs are printed. The cpu-set is ordered from low to high, comma delimited with ".." and "-" permitted to denote a range. eg. 1,2,8,14..17,21-44
56.PP 56.PP
57\fB--hide column\fP do not show the specified columns. May be invoked multiple times, or with a comma-separated list of column names. Use "--hide sysfs" to hide the sysfs statistics columns as a group. 57\fB--hide column\fP do not show the specified built-in columns. May be invoked multiple times, or with a comma-separated list of column names. Use "--hide sysfs" to hide the sysfs statistics columns as a group.
58.PP 58.PP
59\fB--show column\fP show only the specified columns. May be invoked multiple times, or with a comma-separated list of column names. Use "--show sysfs" to show the sysfs statistics columns as a group. 59\fB--enable column\fP show the specified built-in columns, which are otherwise disabled, by default. Currently the only built-in counters disabled by default are "usec" and "Time_Of_Day_Seconds".
60The column name "all" can be used to enable all disabled-by-default built-in counters.
61.PP
62\fB--show column\fP show only the specified built-in columns. May be invoked multiple times, or with a comma-separated list of column names. Use "--show sysfs" to show the sysfs statistics columns as a group.
60.PP 63.PP
61\fB--Dump\fP displays the raw counter values. 64\fB--Dump\fP displays the raw counter values.
62.PP 65.PP
@@ -64,6 +67,8 @@ name as necessary to disambiguate it from others is necessary. Note that option
64.PP 67.PP
65\fB--interval seconds\fP overrides the default 5.0 second measurement interval. 68\fB--interval seconds\fP overrides the default 5.0 second measurement interval.
66.PP 69.PP
70\fB--num_iterations num\fP number of the measurement iterations.
71.PP
67\fB--out output_file\fP turbostat output is written to the specified output_file. 72\fB--out output_file\fP turbostat output is written to the specified output_file.
68The file is truncated if it already exists, and it is created if it does not exist. 73The file is truncated if it already exists, and it is created if it does not exist.
69.PP 74.PP
@@ -86,6 +91,8 @@ displays the statistics gathered since it was forked.
86The system configuration dump (if --quiet is not used) is followed by statistics. The first row of the statistics labels the content of each column (below). The second row of statistics is the system summary line. The system summary line has a '-' in the columns for the Package, Core, and CPU. The contents of the system summary line depends on the type of column. Columns that count items (eg. IRQ) show the sum across all CPUs in the system. Columns that show a percentage show the average across all CPUs in the system. Columns that dump raw MSR values simply show 0 in the summary. After the system summary row, each row describes a specific Package/Core/CPU. Note that if the --cpu parameter is used to limit which specific CPUs are displayed, turbostat will still collect statistics for all CPUs in the system and will still show the system summary for all CPUs in the system. 91The system configuration dump (if --quiet is not used) is followed by statistics. The first row of the statistics labels the content of each column (below). The second row of statistics is the system summary line. The system summary line has a '-' in the columns for the Package, Core, and CPU. The contents of the system summary line depends on the type of column. Columns that count items (eg. IRQ) show the sum across all CPUs in the system. Columns that show a percentage show the average across all CPUs in the system. Columns that dump raw MSR values simply show 0 in the summary. After the system summary row, each row describes a specific Package/Core/CPU. Note that if the --cpu parameter is used to limit which specific CPUs are displayed, turbostat will still collect statistics for all CPUs in the system and will still show the system summary for all CPUs in the system.
87.SH COLUMN DESCRIPTIONS 92.SH COLUMN DESCRIPTIONS
88.nf 93.nf
94\fBusec\fP For each CPU, the number of microseconds elapsed during counter collection, including thread migration -- if any. This counter is disabled by default, and is enabled with "--enable usec", or --debug. On the summary row, usec refers to the total elapsed time to collect the counters on all cpus.
95\fBTime_Of_Day_Seconds\fP For each CPU, the gettimeofday(2) value (seconds.subsec since Epoch) when the counters ending the measurement interval were collected. This column is disabled by default, and can be enabled with "--enable Time_Of_Day_Seconds" or "--debug". On the summary row, Time_Of_Day_Seconds refers to the timestamp following collection of counters on the last CPU.
89\fBCore\fP processor core number. Note that multiple CPUs per core indicate support for Intel(R) Hyper-Threading Technology (HT). 96\fBCore\fP processor core number. Note that multiple CPUs per core indicate support for Intel(R) Hyper-Threading Technology (HT).
90\fBCPU\fP Linux CPU (logical processor) number. Yes, it is okay that on many systems the CPUs are not listed in numerical order -- for efficiency reasons, turbostat runs in topology order, so HT siblings appear together. 97\fBCPU\fP Linux CPU (logical processor) number. Yes, it is okay that on many systems the CPUs are not listed in numerical order -- for efficiency reasons, turbostat runs in topology order, so HT siblings appear together.
91\fBPackage\fP processor package number -- not present on systems with a single processor package. 98\fBPackage\fP processor package number -- not present on systems with a single processor package.
@@ -262,6 +269,21 @@ CPU PRF_CTRL
262 269
263.fi 270.fi
264 271
272.SH INPUT
273
274For interval-mode, turbostat will immediately end the current interval
275when it sees a newline on standard input.
276turbostat will then start the next interval.
277Control-C will be send a SIGINT to turbostat,
278which will immediately abort the program with no further processing.
279.SH SIGNALS
280
281SIGINT will interrupt interval-mode.
282The end-of-interval data will be collected and displayed before turbostat exits.
283
284SIGUSR1 will end current interval,
285end-of-interval data will be collected and displayed before turbostat
286starts a new interval.
265.SH NOTES 287.SH NOTES
266 288
267.B "turbostat " 289.B "turbostat "
diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c
index bd9c6b31a504..d6cff3070ebd 100644
--- a/tools/power/x86/turbostat/turbostat.c
+++ b/tools/power/x86/turbostat/turbostat.c
@@ -29,6 +29,7 @@
29#include <sys/types.h> 29#include <sys/types.h>
30#include <sys/wait.h> 30#include <sys/wait.h>
31#include <sys/stat.h> 31#include <sys/stat.h>
32#include <sys/select.h>
32#include <sys/resource.h> 33#include <sys/resource.h>
33#include <fcntl.h> 34#include <fcntl.h>
34#include <signal.h> 35#include <signal.h>
@@ -47,9 +48,13 @@
47char *proc_stat = "/proc/stat"; 48char *proc_stat = "/proc/stat";
48FILE *outf; 49FILE *outf;
49int *fd_percpu; 50int *fd_percpu;
51struct timeval interval_tv = {5, 0};
50struct timespec interval_ts = {5, 0}; 52struct timespec interval_ts = {5, 0};
53struct timespec one_msec = {0, 1000000};
54unsigned int num_iterations;
51unsigned int debug; 55unsigned int debug;
52unsigned int quiet; 56unsigned int quiet;
57unsigned int shown;
53unsigned int sums_need_wide_columns; 58unsigned int sums_need_wide_columns;
54unsigned int rapl_joules; 59unsigned int rapl_joules;
55unsigned int summary_only; 60unsigned int summary_only;
@@ -58,6 +63,7 @@ unsigned int dump_only;
58unsigned int do_snb_cstates; 63unsigned int do_snb_cstates;
59unsigned int do_knl_cstates; 64unsigned int do_knl_cstates;
60unsigned int do_slm_cstates; 65unsigned int do_slm_cstates;
66unsigned int do_cnl_cstates;
61unsigned int use_c1_residency_msr; 67unsigned int use_c1_residency_msr;
62unsigned int has_aperf; 68unsigned int has_aperf;
63unsigned int has_epb; 69unsigned int has_epb;
@@ -80,6 +86,8 @@ unsigned int do_rapl;
80unsigned int do_dts; 86unsigned int do_dts;
81unsigned int do_ptm; 87unsigned int do_ptm;
82unsigned long long gfx_cur_rc6_ms; 88unsigned long long gfx_cur_rc6_ms;
89unsigned long long cpuidle_cur_cpu_lpi_us;
90unsigned long long cpuidle_cur_sys_lpi_us;
83unsigned int gfx_cur_mhz; 91unsigned int gfx_cur_mhz;
84unsigned int tcc_activation_temp; 92unsigned int tcc_activation_temp;
85unsigned int tcc_activation_temp_override; 93unsigned int tcc_activation_temp_override;
@@ -87,6 +95,7 @@ double rapl_power_units, rapl_time_units;
87double rapl_dram_energy_units, rapl_energy_units; 95double rapl_dram_energy_units, rapl_energy_units;
88double rapl_joule_counter_range; 96double rapl_joule_counter_range;
89unsigned int do_core_perf_limit_reasons; 97unsigned int do_core_perf_limit_reasons;
98unsigned int has_automatic_cstate_conversion;
90unsigned int do_gfx_perf_limit_reasons; 99unsigned int do_gfx_perf_limit_reasons;
91unsigned int do_ring_perf_limit_reasons; 100unsigned int do_ring_perf_limit_reasons;
92unsigned int crystal_hz; 101unsigned int crystal_hz;
@@ -147,7 +156,9 @@ char *progname;
147#define CPU_SUBSET_MAXCPUS 1024 /* need to use before probe... */ 156#define CPU_SUBSET_MAXCPUS 1024 /* need to use before probe... */
148cpu_set_t *cpu_present_set, *cpu_affinity_set, *cpu_subset; 157cpu_set_t *cpu_present_set, *cpu_affinity_set, *cpu_subset;
149size_t cpu_present_setsize, cpu_affinity_setsize, cpu_subset_size; 158size_t cpu_present_setsize, cpu_affinity_setsize, cpu_subset_size;
150#define MAX_ADDED_COUNTERS 16 159#define MAX_ADDED_COUNTERS 8
160#define MAX_ADDED_THREAD_COUNTERS 24
161#define BITMASK_SIZE 32
151 162
152struct thread_data { 163struct thread_data {
153 struct timeval tv_begin; 164 struct timeval tv_begin;
@@ -162,7 +173,7 @@ struct thread_data {
162 unsigned int flags; 173 unsigned int flags;
163#define CPU_IS_FIRST_THREAD_IN_CORE 0x2 174#define CPU_IS_FIRST_THREAD_IN_CORE 0x2
164#define CPU_IS_FIRST_CORE_IN_PACKAGE 0x4 175#define CPU_IS_FIRST_CORE_IN_PACKAGE 0x4
165 unsigned long long counter[MAX_ADDED_COUNTERS]; 176 unsigned long long counter[MAX_ADDED_THREAD_COUNTERS];
166} *thread_even, *thread_odd; 177} *thread_even, *thread_odd;
167 178
168struct core_data { 179struct core_data {
@@ -183,6 +194,8 @@ struct pkg_data {
183 unsigned long long pc8; 194 unsigned long long pc8;
184 unsigned long long pc9; 195 unsigned long long pc9;
185 unsigned long long pc10; 196 unsigned long long pc10;
197 unsigned long long cpu_lpi;
198 unsigned long long sys_lpi;
186 unsigned long long pkg_wtd_core_c0; 199 unsigned long long pkg_wtd_core_c0;
187 unsigned long long pkg_any_core_c0; 200 unsigned long long pkg_any_core_c0;
188 unsigned long long pkg_any_gfxe_c0; 201 unsigned long long pkg_any_gfxe_c0;
@@ -203,12 +216,21 @@ struct pkg_data {
203#define ODD_COUNTERS thread_odd, core_odd, package_odd 216#define ODD_COUNTERS thread_odd, core_odd, package_odd
204#define EVEN_COUNTERS thread_even, core_even, package_even 217#define EVEN_COUNTERS thread_even, core_even, package_even
205 218
206#define GET_THREAD(thread_base, thread_no, core_no, pkg_no) \ 219#define GET_THREAD(thread_base, thread_no, core_no, node_no, pkg_no) \
207 (thread_base + (pkg_no) * topo.num_cores_per_pkg * \ 220 ((thread_base) + \
208 topo.num_threads_per_core + \ 221 ((pkg_no) * \
209 (core_no) * topo.num_threads_per_core + (thread_no)) 222 topo.nodes_per_pkg * topo.cores_per_node * topo.threads_per_core) + \
210#define GET_CORE(core_base, core_no, pkg_no) \ 223 ((node_no) * topo.cores_per_node * topo.threads_per_core) + \
211 (core_base + (pkg_no) * topo.num_cores_per_pkg + (core_no)) 224 ((core_no) * topo.threads_per_core) + \
225 (thread_no))
226
227#define GET_CORE(core_base, core_no, node_no, pkg_no) \
228 ((core_base) + \
229 ((pkg_no) * topo.nodes_per_pkg * topo.cores_per_node) + \
230 ((node_no) * topo.cores_per_node) + \
231 (core_no))
232
233
212#define GET_PKG(pkg_base, pkg_no) (pkg_base + pkg_no) 234#define GET_PKG(pkg_base, pkg_no) (pkg_base + pkg_no)
213 235
214enum counter_scope {SCOPE_CPU, SCOPE_CORE, SCOPE_PACKAGE}; 236enum counter_scope {SCOPE_CPU, SCOPE_CORE, SCOPE_PACKAGE};
@@ -244,14 +266,25 @@ struct system_summary {
244 struct pkg_data packages; 266 struct pkg_data packages;
245} average; 267} average;
246 268
269struct cpu_topology {
270 int physical_package_id;
271 int logical_cpu_id;
272 int physical_node_id;
273 int logical_node_id; /* 0-based count within the package */
274 int physical_core_id;
275 int thread_id;
276 cpu_set_t *put_ids; /* Processing Unit/Thread IDs */
277} *cpus;
247 278
248struct topo_params { 279struct topo_params {
249 int num_packages; 280 int num_packages;
250 int num_cpus; 281 int num_cpus;
251 int num_cores; 282 int num_cores;
252 int max_cpu_num; 283 int max_cpu_num;
253 int num_cores_per_pkg; 284 int max_node_num;
254 int num_threads_per_core; 285 int nodes_per_pkg;
286 int cores_per_node;
287 int threads_per_core;
255} topo; 288} topo;
256 289
257struct timeval tv_even, tv_odd, tv_delta; 290struct timeval tv_even, tv_odd, tv_delta;
@@ -273,27 +306,33 @@ int cpu_is_not_present(int cpu)
273int for_all_cpus(int (func)(struct thread_data *, struct core_data *, struct pkg_data *), 306int for_all_cpus(int (func)(struct thread_data *, struct core_data *, struct pkg_data *),
274 struct thread_data *thread_base, struct core_data *core_base, struct pkg_data *pkg_base) 307 struct thread_data *thread_base, struct core_data *core_base, struct pkg_data *pkg_base)
275{ 308{
276 int retval, pkg_no, core_no, thread_no; 309 int retval, pkg_no, core_no, thread_no, node_no;
277 310
278 for (pkg_no = 0; pkg_no < topo.num_packages; ++pkg_no) { 311 for (pkg_no = 0; pkg_no < topo.num_packages; ++pkg_no) {
279 for (core_no = 0; core_no < topo.num_cores_per_pkg; ++core_no) { 312 for (core_no = 0; core_no < topo.cores_per_node; ++core_no) {
280 for (thread_no = 0; thread_no < 313 for (node_no = 0; node_no < topo.nodes_per_pkg;
281 topo.num_threads_per_core; ++thread_no) { 314 node_no++) {
282 struct thread_data *t; 315 for (thread_no = 0; thread_no <
283 struct core_data *c; 316 topo.threads_per_core; ++thread_no) {
284 struct pkg_data *p; 317 struct thread_data *t;
285 318 struct core_data *c;
286 t = GET_THREAD(thread_base, thread_no, core_no, pkg_no); 319 struct pkg_data *p;
287 320
288 if (cpu_is_not_present(t->cpu_id)) 321 t = GET_THREAD(thread_base, thread_no,
289 continue; 322 core_no, node_no,
290 323 pkg_no);
291 c = GET_CORE(core_base, core_no, pkg_no); 324
292 p = GET_PKG(pkg_base, pkg_no); 325 if (cpu_is_not_present(t->cpu_id))
293 326 continue;
294 retval = func(t, c, p); 327
295 if (retval) 328 c = GET_CORE(core_base, core_no,
296 return retval; 329 node_no, pkg_no);
330 p = GET_PKG(pkg_base, pkg_no);
331
332 retval = func(t, c, p);
333 if (retval)
334 return retval;
335 }
297 } 336 }
298 } 337 }
299 } 338 }
@@ -346,6 +385,8 @@ int get_msr(int cpu, off_t offset, unsigned long long *msr)
346 * Thus, strings that are proper sub-sets must follow their more specific peers. 385 * Thus, strings that are proper sub-sets must follow their more specific peers.
347 */ 386 */
348struct msr_counter bic[] = { 387struct msr_counter bic[] = {
388 { 0x0, "usec" },
389 { 0x0, "Time_Of_Day_Seconds" },
349 { 0x0, "Package" }, 390 { 0x0, "Package" },
350 { 0x0, "Avg_MHz" }, 391 { 0x0, "Avg_MHz" },
351 { 0x0, "Bzy_MHz" }, 392 { 0x0, "Bzy_MHz" },
@@ -369,7 +410,9 @@ struct msr_counter bic[] = {
369 { 0x0, "Pkg%pc7" }, 410 { 0x0, "Pkg%pc7" },
370 { 0x0, "Pkg%pc8" }, 411 { 0x0, "Pkg%pc8" },
371 { 0x0, "Pkg%pc9" }, 412 { 0x0, "Pkg%pc9" },
372 { 0x0, "Pkg%pc10" }, 413 { 0x0, "Pk%pc10" },
414 { 0x0, "CPU%LPI" },
415 { 0x0, "SYS%LPI" },
373 { 0x0, "PkgWatt" }, 416 { 0x0, "PkgWatt" },
374 { 0x0, "CorWatt" }, 417 { 0x0, "CorWatt" },
375 { 0x0, "GFXWatt" }, 418 { 0x0, "GFXWatt" },
@@ -389,62 +432,72 @@ struct msr_counter bic[] = {
389 { 0x0, "Any%C0" }, 432 { 0x0, "Any%C0" },
390 { 0x0, "GFX%C0" }, 433 { 0x0, "GFX%C0" },
391 { 0x0, "CPUGFX%" }, 434 { 0x0, "CPUGFX%" },
435 { 0x0, "Node%" },
392}; 436};
393 437
394 438
395 439
396#define MAX_BIC (sizeof(bic) / sizeof(struct msr_counter)) 440#define MAX_BIC (sizeof(bic) / sizeof(struct msr_counter))
397#define BIC_Package (1ULL << 0) 441#define BIC_USEC (1ULL << 0)
398#define BIC_Avg_MHz (1ULL << 1) 442#define BIC_TOD (1ULL << 1)
399#define BIC_Bzy_MHz (1ULL << 2) 443#define BIC_Package (1ULL << 2)
400#define BIC_TSC_MHz (1ULL << 3) 444#define BIC_Avg_MHz (1ULL << 3)
401#define BIC_IRQ (1ULL << 4) 445#define BIC_Bzy_MHz (1ULL << 4)
402#define BIC_SMI (1ULL << 5) 446#define BIC_TSC_MHz (1ULL << 5)
403#define BIC_Busy (1ULL << 6) 447#define BIC_IRQ (1ULL << 6)
404#define BIC_CPU_c1 (1ULL << 7) 448#define BIC_SMI (1ULL << 7)
405#define BIC_CPU_c3 (1ULL << 8) 449#define BIC_Busy (1ULL << 8)
406#define BIC_CPU_c6 (1ULL << 9) 450#define BIC_CPU_c1 (1ULL << 9)
407#define BIC_CPU_c7 (1ULL << 10) 451#define BIC_CPU_c3 (1ULL << 10)
408#define BIC_ThreadC (1ULL << 11) 452#define BIC_CPU_c6 (1ULL << 11)
409#define BIC_CoreTmp (1ULL << 12) 453#define BIC_CPU_c7 (1ULL << 12)
410#define BIC_CoreCnt (1ULL << 13) 454#define BIC_ThreadC (1ULL << 13)
411#define BIC_PkgTmp (1ULL << 14) 455#define BIC_CoreTmp (1ULL << 14)
412#define BIC_GFX_rc6 (1ULL << 15) 456#define BIC_CoreCnt (1ULL << 15)
413#define BIC_GFXMHz (1ULL << 16) 457#define BIC_PkgTmp (1ULL << 16)
414#define BIC_Pkgpc2 (1ULL << 17) 458#define BIC_GFX_rc6 (1ULL << 17)
415#define BIC_Pkgpc3 (1ULL << 18) 459#define BIC_GFXMHz (1ULL << 18)
416#define BIC_Pkgpc6 (1ULL << 19) 460#define BIC_Pkgpc2 (1ULL << 19)
417#define BIC_Pkgpc7 (1ULL << 20) 461#define BIC_Pkgpc3 (1ULL << 20)
418#define BIC_Pkgpc8 (1ULL << 21) 462#define BIC_Pkgpc6 (1ULL << 21)
419#define BIC_Pkgpc9 (1ULL << 22) 463#define BIC_Pkgpc7 (1ULL << 22)
420#define BIC_Pkgpc10 (1ULL << 23) 464#define BIC_Pkgpc8 (1ULL << 23)
421#define BIC_PkgWatt (1ULL << 24) 465#define BIC_Pkgpc9 (1ULL << 24)
422#define BIC_CorWatt (1ULL << 25) 466#define BIC_Pkgpc10 (1ULL << 25)
423#define BIC_GFXWatt (1ULL << 26) 467#define BIC_CPU_LPI (1ULL << 26)
424#define BIC_PkgCnt (1ULL << 27) 468#define BIC_SYS_LPI (1ULL << 27)
425#define BIC_RAMWatt (1ULL << 28) 469#define BIC_PkgWatt (1ULL << 26)
426#define BIC_PKG__ (1ULL << 29) 470#define BIC_CorWatt (1ULL << 27)
427#define BIC_RAM__ (1ULL << 30) 471#define BIC_GFXWatt (1ULL << 28)
428#define BIC_Pkg_J (1ULL << 31) 472#define BIC_PkgCnt (1ULL << 29)
429#define BIC_Cor_J (1ULL << 32) 473#define BIC_RAMWatt (1ULL << 30)
430#define BIC_GFX_J (1ULL << 33) 474#define BIC_PKG__ (1ULL << 31)
431#define BIC_RAM_J (1ULL << 34) 475#define BIC_RAM__ (1ULL << 32)
432#define BIC_Core (1ULL << 35) 476#define BIC_Pkg_J (1ULL << 33)
433#define BIC_CPU (1ULL << 36) 477#define BIC_Cor_J (1ULL << 34)
434#define BIC_Mod_c6 (1ULL << 37) 478#define BIC_GFX_J (1ULL << 35)
435#define BIC_sysfs (1ULL << 38) 479#define BIC_RAM_J (1ULL << 36)
436#define BIC_Totl_c0 (1ULL << 39) 480#define BIC_Core (1ULL << 37)
437#define BIC_Any_c0 (1ULL << 40) 481#define BIC_CPU (1ULL << 38)
438#define BIC_GFX_c0 (1ULL << 41) 482#define BIC_Mod_c6 (1ULL << 39)
439#define BIC_CPUGFX (1ULL << 42) 483#define BIC_sysfs (1ULL << 40)
440 484#define BIC_Totl_c0 (1ULL << 41)
441unsigned long long bic_enabled = 0xFFFFFFFFFFFFFFFFULL; 485#define BIC_Any_c0 (1ULL << 42)
442unsigned long long bic_present = BIC_sysfs; 486#define BIC_GFX_c0 (1ULL << 43)
487#define BIC_CPUGFX (1ULL << 44)
488#define BIC_Node (1ULL << 45)
489
490#define BIC_DISABLED_BY_DEFAULT (BIC_USEC | BIC_TOD)
491
492unsigned long long bic_enabled = (0xFFFFFFFFFFFFFFFFULL & ~BIC_DISABLED_BY_DEFAULT);
493unsigned long long bic_present = BIC_USEC | BIC_TOD | BIC_sysfs;
443 494
444#define DO_BIC(COUNTER_NAME) (bic_enabled & bic_present & COUNTER_NAME) 495#define DO_BIC(COUNTER_NAME) (bic_enabled & bic_present & COUNTER_NAME)
496#define ENABLE_BIC(COUNTER_NAME) (bic_enabled |= COUNTER_NAME)
445#define BIC_PRESENT(COUNTER_BIT) (bic_present |= COUNTER_BIT) 497#define BIC_PRESENT(COUNTER_BIT) (bic_present |= COUNTER_BIT)
446#define BIC_NOT_PRESENT(COUNTER_BIT) (bic_present &= ~COUNTER_BIT) 498#define BIC_NOT_PRESENT(COUNTER_BIT) (bic_present &= ~COUNTER_BIT)
447 499
500
448#define MAX_DEFERRED 16 501#define MAX_DEFERRED 16
449char *deferred_skip_names[MAX_DEFERRED]; 502char *deferred_skip_names[MAX_DEFERRED];
450int deferred_skip_index; 503int deferred_skip_index;
@@ -469,9 +522,10 @@ void help(void)
469 "--cpu cpu-set limit output to summary plus cpu-set:\n" 522 "--cpu cpu-set limit output to summary plus cpu-set:\n"
470 " {core | package | j,k,l..m,n-p }\n" 523 " {core | package | j,k,l..m,n-p }\n"
471 "--quiet skip decoding system configuration header\n" 524 "--quiet skip decoding system configuration header\n"
472 "--interval sec Override default 5-second measurement interval\n" 525 "--interval sec.subsec Override default 5-second measurement interval\n"
473 "--help print this help message\n" 526 "--help print this help message\n"
474 "--list list column headers only\n" 527 "--list list column headers only\n"
528 "--num_iterations num number of the measurement iterations\n"
475 "--out file create or truncate \"file\" for all output\n" 529 "--out file create or truncate \"file\" for all output\n"
476 "--version print version information\n" 530 "--version print version information\n"
477 "\n" 531 "\n"
@@ -496,6 +550,9 @@ unsigned long long bic_lookup(char *name_list, enum show_hide_mode mode)
496 if (comma) 550 if (comma)
497 *comma = '\0'; 551 *comma = '\0';
498 552
553 if (!strcmp(name_list, "all"))
554 return ~0;
555
499 for (i = 0; i < MAX_BIC; ++i) { 556 for (i = 0; i < MAX_BIC; ++i) {
500 if (!strcmp(name_list, bic[i].name)) { 557 if (!strcmp(name_list, bic[i].name)) {
501 retval |= (1ULL << i); 558 retval |= (1ULL << i);
@@ -532,10 +589,14 @@ void print_header(char *delim)
532 struct msr_counter *mp; 589 struct msr_counter *mp;
533 int printed = 0; 590 int printed = 0;
534 591
535 if (debug) 592 if (DO_BIC(BIC_USEC))
536 outp += sprintf(outp, "usec %s", delim); 593 outp += sprintf(outp, "%susec", (printed++ ? delim : ""));
594 if (DO_BIC(BIC_TOD))
595 outp += sprintf(outp, "%sTime_Of_Day_Seconds", (printed++ ? delim : ""));
537 if (DO_BIC(BIC_Package)) 596 if (DO_BIC(BIC_Package))
538 outp += sprintf(outp, "%sPackage", (printed++ ? delim : "")); 597 outp += sprintf(outp, "%sPackage", (printed++ ? delim : ""));
598 if (DO_BIC(BIC_Node))
599 outp += sprintf(outp, "%sNode", (printed++ ? delim : ""));
539 if (DO_BIC(BIC_Core)) 600 if (DO_BIC(BIC_Core))
540 outp += sprintf(outp, "%sCore", (printed++ ? delim : "")); 601 outp += sprintf(outp, "%sCore", (printed++ ? delim : ""));
541 if (DO_BIC(BIC_CPU)) 602 if (DO_BIC(BIC_CPU))
@@ -576,7 +637,7 @@ void print_header(char *delim)
576 637
577 if (DO_BIC(BIC_CPU_c1)) 638 if (DO_BIC(BIC_CPU_c1))
578 outp += sprintf(outp, "%sCPU%%c1", (printed++ ? delim : "")); 639 outp += sprintf(outp, "%sCPU%%c1", (printed++ ? delim : ""));
579 if (DO_BIC(BIC_CPU_c3) && !do_slm_cstates && !do_knl_cstates) 640 if (DO_BIC(BIC_CPU_c3) && !do_slm_cstates && !do_knl_cstates && !do_cnl_cstates)
580 outp += sprintf(outp, "%sCPU%%c3", (printed++ ? delim : "")); 641 outp += sprintf(outp, "%sCPU%%c3", (printed++ ? delim : ""));
581 if (DO_BIC(BIC_CPU_c6)) 642 if (DO_BIC(BIC_CPU_c6))
582 outp += sprintf(outp, "%sCPU%%c6", (printed++ ? delim : "")); 643 outp += sprintf(outp, "%sCPU%%c6", (printed++ ? delim : ""));
@@ -635,6 +696,10 @@ void print_header(char *delim)
635 outp += sprintf(outp, "%sPkg%%pc9", (printed++ ? delim : "")); 696 outp += sprintf(outp, "%sPkg%%pc9", (printed++ ? delim : ""));
636 if (DO_BIC(BIC_Pkgpc10)) 697 if (DO_BIC(BIC_Pkgpc10))
637 outp += sprintf(outp, "%sPk%%pc10", (printed++ ? delim : "")); 698 outp += sprintf(outp, "%sPk%%pc10", (printed++ ? delim : ""));
699 if (DO_BIC(BIC_CPU_LPI))
700 outp += sprintf(outp, "%sCPU%%LPI", (printed++ ? delim : ""));
701 if (DO_BIC(BIC_SYS_LPI))
702 outp += sprintf(outp, "%sSYS%%LPI", (printed++ ? delim : ""));
638 703
639 if (do_rapl && !rapl_joules) { 704 if (do_rapl && !rapl_joules) {
640 if (DO_BIC(BIC_PkgWatt)) 705 if (DO_BIC(BIC_PkgWatt))
@@ -739,6 +804,9 @@ int dump_counters(struct thread_data *t, struct core_data *c,
739 outp += sprintf(outp, "pc8: %016llX\n", p->pc8); 804 outp += sprintf(outp, "pc8: %016llX\n", p->pc8);
740 outp += sprintf(outp, "pc9: %016llX\n", p->pc9); 805 outp += sprintf(outp, "pc9: %016llX\n", p->pc9);
741 outp += sprintf(outp, "pc10: %016llX\n", p->pc10); 806 outp += sprintf(outp, "pc10: %016llX\n", p->pc10);
807 outp += sprintf(outp, "pc10: %016llX\n", p->pc10);
808 outp += sprintf(outp, "cpu_lpi: %016llX\n", p->cpu_lpi);
809 outp += sprintf(outp, "sys_lpi: %016llX\n", p->sys_lpi);
742 outp += sprintf(outp, "Joules PKG: %0X\n", p->energy_pkg); 810 outp += sprintf(outp, "Joules PKG: %0X\n", p->energy_pkg);
743 outp += sprintf(outp, "Joules COR: %0X\n", p->energy_cores); 811 outp += sprintf(outp, "Joules COR: %0X\n", p->energy_cores);
744 outp += sprintf(outp, "Joules GFX: %0X\n", p->energy_gfx); 812 outp += sprintf(outp, "Joules GFX: %0X\n", p->energy_gfx);
@@ -786,7 +854,7 @@ int format_counters(struct thread_data *t, struct core_data *c,
786 (cpu_subset && !CPU_ISSET_S(t->cpu_id, cpu_subset_size, cpu_subset))) 854 (cpu_subset && !CPU_ISSET_S(t->cpu_id, cpu_subset_size, cpu_subset)))
787 return 0; 855 return 0;
788 856
789 if (debug) { 857 if (DO_BIC(BIC_USEC)) {
790 /* on each row, print how many usec each timestamp took to gather */ 858 /* on each row, print how many usec each timestamp took to gather */
791 struct timeval tv; 859 struct timeval tv;
792 860
@@ -794,6 +862,10 @@ int format_counters(struct thread_data *t, struct core_data *c,
794 outp += sprintf(outp, "%5ld\t", tv.tv_sec * 1000000 + tv.tv_usec); 862 outp += sprintf(outp, "%5ld\t", tv.tv_sec * 1000000 + tv.tv_usec);
795 } 863 }
796 864
865 /* Time_Of_Day_Seconds: on each row, print sec.usec last timestamp taken */
866 if (DO_BIC(BIC_TOD))
867 outp += sprintf(outp, "%10ld.%06ld\t", t->tv_end.tv_sec, t->tv_end.tv_usec);
868
797 interval_float = tv_delta.tv_sec + tv_delta.tv_usec/1000000.0; 869 interval_float = tv_delta.tv_sec + tv_delta.tv_usec/1000000.0;
798 870
799 tsc = t->tsc * tsc_tweak; 871 tsc = t->tsc * tsc_tweak;
@@ -802,6 +874,8 @@ int format_counters(struct thread_data *t, struct core_data *c,
802 if (t == &average.threads) { 874 if (t == &average.threads) {
803 if (DO_BIC(BIC_Package)) 875 if (DO_BIC(BIC_Package))
804 outp += sprintf(outp, "%s-", (printed++ ? delim : "")); 876 outp += sprintf(outp, "%s-", (printed++ ? delim : ""));
877 if (DO_BIC(BIC_Node))
878 outp += sprintf(outp, "%s-", (printed++ ? delim : ""));
805 if (DO_BIC(BIC_Core)) 879 if (DO_BIC(BIC_Core))
806 outp += sprintf(outp, "%s-", (printed++ ? delim : "")); 880 outp += sprintf(outp, "%s-", (printed++ ? delim : ""));
807 if (DO_BIC(BIC_CPU)) 881 if (DO_BIC(BIC_CPU))
@@ -813,6 +887,15 @@ int format_counters(struct thread_data *t, struct core_data *c,
813 else 887 else
814 outp += sprintf(outp, "%s-", (printed++ ? delim : "")); 888 outp += sprintf(outp, "%s-", (printed++ ? delim : ""));
815 } 889 }
890 if (DO_BIC(BIC_Node)) {
891 if (t)
892 outp += sprintf(outp, "%s%d",
893 (printed++ ? delim : ""),
894 cpus[t->cpu_id].physical_node_id);
895 else
896 outp += sprintf(outp, "%s-",
897 (printed++ ? delim : ""));
898 }
816 if (DO_BIC(BIC_Core)) { 899 if (DO_BIC(BIC_Core)) {
817 if (c) 900 if (c)
818 outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), c->core_id); 901 outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), c->core_id);
@@ -882,7 +965,7 @@ int format_counters(struct thread_data *t, struct core_data *c,
882 if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE)) 965 if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE))
883 goto done; 966 goto done;
884 967
885 if (DO_BIC(BIC_CPU_c3) && !do_slm_cstates && !do_knl_cstates) 968 if (DO_BIC(BIC_CPU_c3) && !do_slm_cstates && !do_knl_cstates && !do_cnl_cstates)
886 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * c->c3/tsc); 969 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * c->c3/tsc);
887 if (DO_BIC(BIC_CPU_c6)) 970 if (DO_BIC(BIC_CPU_c6))
888 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * c->c6/tsc); 971 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * c->c6/tsc);
@@ -959,6 +1042,11 @@ int format_counters(struct thread_data *t, struct core_data *c,
959 if (DO_BIC(BIC_Pkgpc10)) 1042 if (DO_BIC(BIC_Pkgpc10))
960 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pc10/tsc); 1043 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pc10/tsc);
961 1044
1045 if (DO_BIC(BIC_CPU_LPI))
1046 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->cpu_lpi / 1000000.0 / interval_float);
1047 if (DO_BIC(BIC_SYS_LPI))
1048 outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->sys_lpi / 1000000.0 / interval_float);
1049
962 /* 1050 /*
963 * If measurement interval exceeds minimum RAPL Joule Counter range, 1051 * If measurement interval exceeds minimum RAPL Joule Counter range,
964 * indicate that results are suspect by printing "**" in fraction place. 1052 * indicate that results are suspect by printing "**" in fraction place.
@@ -1006,7 +1094,8 @@ int format_counters(struct thread_data *t, struct core_data *c,
1006 } 1094 }
1007 1095
1008done: 1096done:
1009 outp += sprintf(outp, "\n"); 1097 if (*(outp - 1) != '\n')
1098 outp += sprintf(outp, "\n");
1010 1099
1011 return 0; 1100 return 0;
1012} 1101}
@@ -1083,6 +1172,8 @@ delta_package(struct pkg_data *new, struct pkg_data *old)
1083 old->pc8 = new->pc8 - old->pc8; 1172 old->pc8 = new->pc8 - old->pc8;
1084 old->pc9 = new->pc9 - old->pc9; 1173 old->pc9 = new->pc9 - old->pc9;
1085 old->pc10 = new->pc10 - old->pc10; 1174 old->pc10 = new->pc10 - old->pc10;
1175 old->cpu_lpi = new->cpu_lpi - old->cpu_lpi;
1176 old->sys_lpi = new->sys_lpi - old->sys_lpi;
1086 old->pkg_temp_c = new->pkg_temp_c; 1177 old->pkg_temp_c = new->pkg_temp_c;
1087 1178
1088 /* flag an error when rc6 counter resets/wraps */ 1179 /* flag an error when rc6 counter resets/wraps */
@@ -1140,6 +1231,15 @@ delta_thread(struct thread_data *new, struct thread_data *old,
1140 int i; 1231 int i;
1141 struct msr_counter *mp; 1232 struct msr_counter *mp;
1142 1233
1234 /*
1235 * the timestamps from start of measurement interval are in "old"
1236 * the timestamp from end of measurement interval are in "new"
1237 * over-write old w/ new so we can print end of interval values
1238 */
1239
1240 old->tv_begin = new->tv_begin;
1241 old->tv_end = new->tv_end;
1242
1143 old->tsc = new->tsc - old->tsc; 1243 old->tsc = new->tsc - old->tsc;
1144 1244
1145 /* check for TSC < 1 Mcycles over interval */ 1245 /* check for TSC < 1 Mcycles over interval */
@@ -1228,6 +1328,11 @@ void clear_counters(struct thread_data *t, struct core_data *c, struct pkg_data
1228 int i; 1328 int i;
1229 struct msr_counter *mp; 1329 struct msr_counter *mp;
1230 1330
1331 t->tv_begin.tv_sec = 0;
1332 t->tv_begin.tv_usec = 0;
1333 t->tv_end.tv_sec = 0;
1334 t->tv_end.tv_usec = 0;
1335
1231 t->tsc = 0; 1336 t->tsc = 0;
1232 t->aperf = 0; 1337 t->aperf = 0;
1233 t->mperf = 0; 1338 t->mperf = 0;
@@ -1260,6 +1365,8 @@ void clear_counters(struct thread_data *t, struct core_data *c, struct pkg_data
1260 p->pc8 = 0; 1365 p->pc8 = 0;
1261 p->pc9 = 0; 1366 p->pc9 = 0;
1262 p->pc10 = 0; 1367 p->pc10 = 0;
1368 p->cpu_lpi = 0;
1369 p->sys_lpi = 0;
1263 1370
1264 p->energy_pkg = 0; 1371 p->energy_pkg = 0;
1265 p->energy_dram = 0; 1372 p->energy_dram = 0;
@@ -1286,6 +1393,13 @@ int sum_counters(struct thread_data *t, struct core_data *c,
1286 int i; 1393 int i;
1287 struct msr_counter *mp; 1394 struct msr_counter *mp;
1288 1395
1396 /* remember first tv_begin */
1397 if (average.threads.tv_begin.tv_sec == 0)
1398 average.threads.tv_begin = t->tv_begin;
1399
1400 /* remember last tv_end */
1401 average.threads.tv_end = t->tv_end;
1402
1289 average.threads.tsc += t->tsc; 1403 average.threads.tsc += t->tsc;
1290 average.threads.aperf += t->aperf; 1404 average.threads.aperf += t->aperf;
1291 average.threads.mperf += t->mperf; 1405 average.threads.mperf += t->mperf;
@@ -1341,6 +1455,9 @@ int sum_counters(struct thread_data *t, struct core_data *c,
1341 average.packages.pc9 += p->pc9; 1455 average.packages.pc9 += p->pc9;
1342 average.packages.pc10 += p->pc10; 1456 average.packages.pc10 += p->pc10;
1343 1457
1458 average.packages.cpu_lpi = p->cpu_lpi;
1459 average.packages.sys_lpi = p->sys_lpi;
1460
1344 average.packages.energy_pkg += p->energy_pkg; 1461 average.packages.energy_pkg += p->energy_pkg;
1345 average.packages.energy_dram += p->energy_dram; 1462 average.packages.energy_dram += p->energy_dram;
1346 average.packages.energy_cores += p->energy_cores; 1463 average.packages.energy_cores += p->energy_cores;
@@ -1487,7 +1604,7 @@ int get_mp(int cpu, struct msr_counter *mp, unsigned long long *counterp)
1487 if (get_msr(cpu, mp->msr_num, counterp)) 1604 if (get_msr(cpu, mp->msr_num, counterp))
1488 return -1; 1605 return -1;
1489 } else { 1606 } else {
1490 char path[128]; 1607 char path[128 + PATH_BYTES];
1491 1608
1492 if (mp->flags & SYSFS_PERCPU) { 1609 if (mp->flags & SYSFS_PERCPU) {
1493 sprintf(path, "/sys/devices/system/cpu/cpu%d/%s", 1610 sprintf(path, "/sys/devices/system/cpu/cpu%d/%s",
@@ -1603,7 +1720,7 @@ retry:
1603 if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE)) 1720 if (!(t->flags & CPU_IS_FIRST_THREAD_IN_CORE))
1604 goto done; 1721 goto done;
1605 1722
1606 if (DO_BIC(BIC_CPU_c3) && !do_slm_cstates && !do_knl_cstates) { 1723 if (DO_BIC(BIC_CPU_c3) && !do_slm_cstates && !do_knl_cstates && !do_cnl_cstates) {
1607 if (get_msr(cpu, MSR_CORE_C3_RESIDENCY, &c->c3)) 1724 if (get_msr(cpu, MSR_CORE_C3_RESIDENCY, &c->c3))
1608 return -6; 1725 return -6;
1609 } 1726 }
@@ -1684,6 +1801,11 @@ retry:
1684 if (get_msr(cpu, MSR_PKG_C10_RESIDENCY, &p->pc10)) 1801 if (get_msr(cpu, MSR_PKG_C10_RESIDENCY, &p->pc10))
1685 return -13; 1802 return -13;
1686 1803
1804 if (DO_BIC(BIC_CPU_LPI))
1805 p->cpu_lpi = cpuidle_cur_cpu_lpi_us;
1806 if (DO_BIC(BIC_SYS_LPI))
1807 p->sys_lpi = cpuidle_cur_sys_lpi_us;
1808
1687 if (do_rapl & RAPL_PKG) { 1809 if (do_rapl & RAPL_PKG) {
1688 if (get_msr(cpu, MSR_PKG_ENERGY_STATUS, &msr)) 1810 if (get_msr(cpu, MSR_PKG_ENERGY_STATUS, &msr))
1689 return -13; 1811 return -13;
@@ -1769,7 +1891,7 @@ int slv_pkg_cstate_limits[16] = {PCL__0, PCL__1, PCLRSV, PCLRSV, PCL__4, PCLRSV,
1769int amt_pkg_cstate_limits[16] = {PCLUNL, PCL__1, PCL__2, PCLRSV, PCLRSV, PCLRSV, PCL__6, PCL__7, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV}; 1891int amt_pkg_cstate_limits[16] = {PCLUNL, PCL__1, PCL__2, PCLRSV, PCLRSV, PCLRSV, PCL__6, PCL__7, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV};
1770int phi_pkg_cstate_limits[16] = {PCL__0, PCL__2, PCL_6N, PCL_6R, PCLRSV, PCLRSV, PCLRSV, PCLUNL, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV}; 1892int phi_pkg_cstate_limits[16] = {PCL__0, PCL__2, PCL_6N, PCL_6R, PCLRSV, PCLRSV, PCLRSV, PCLUNL, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV};
1771int bxt_pkg_cstate_limits[16] = {PCL__0, PCL__2, PCLUNL, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV}; 1893int bxt_pkg_cstate_limits[16] = {PCL__0, PCL__2, PCLUNL, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV};
1772int skx_pkg_cstate_limits[16] = {PCL__0, PCL__2, PCL_6N, PCL_6R, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLUNL, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV}; 1894int skx_pkg_cstate_limits[16] = {PCL__0, PCL__2, PCL_6N, PCL_6R, PCLRSV, PCLRSV, PCLRSV, PCLUNL, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV, PCLRSV};
1773 1895
1774 1896
1775static void 1897static void
@@ -2071,12 +2193,9 @@ dump_nhm_cst_cfg(void)
2071 2193
2072 get_msr(base_cpu, MSR_PKG_CST_CONFIG_CONTROL, &msr); 2194 get_msr(base_cpu, MSR_PKG_CST_CONFIG_CONTROL, &msr);
2073 2195
2074#define SNB_C1_AUTO_UNDEMOTE (1UL << 27)
2075#define SNB_C3_AUTO_UNDEMOTE (1UL << 28)
2076
2077 fprintf(outf, "cpu%d: MSR_PKG_CST_CONFIG_CONTROL: 0x%08llx", base_cpu, msr); 2196 fprintf(outf, "cpu%d: MSR_PKG_CST_CONFIG_CONTROL: 0x%08llx", base_cpu, msr);
2078 2197
2079 fprintf(outf, " (%s%s%s%s%slocked: pkg-cstate-limit=%d: %s)\n", 2198 fprintf(outf, " (%s%s%s%s%slocked, pkg-cstate-limit=%d (%s)",
2080 (msr & SNB_C3_AUTO_UNDEMOTE) ? "UNdemote-C3, " : "", 2199 (msr & SNB_C3_AUTO_UNDEMOTE) ? "UNdemote-C3, " : "",
2081 (msr & SNB_C1_AUTO_UNDEMOTE) ? "UNdemote-C1, " : "", 2200 (msr & SNB_C1_AUTO_UNDEMOTE) ? "UNdemote-C1, " : "",
2082 (msr & NHM_C3_AUTO_DEMOTE) ? "demote-C3, " : "", 2201 (msr & NHM_C3_AUTO_DEMOTE) ? "demote-C3, " : "",
@@ -2084,6 +2203,15 @@ dump_nhm_cst_cfg(void)
2084 (msr & (1 << 15)) ? "" : "UN", 2203 (msr & (1 << 15)) ? "" : "UN",
2085 (unsigned int)msr & 0xF, 2204 (unsigned int)msr & 0xF,
2086 pkg_cstate_limit_strings[pkg_cstate_limit]); 2205 pkg_cstate_limit_strings[pkg_cstate_limit]);
2206
2207#define AUTOMATIC_CSTATE_CONVERSION (1UL << 16)
2208 if (has_automatic_cstate_conversion) {
2209 fprintf(outf, ", automatic c-state conversion=%s",
2210 (msr & AUTOMATIC_CSTATE_CONVERSION) ? "on" : "off");
2211 }
2212
2213 fprintf(outf, ")\n");
2214
2087 return; 2215 return;
2088} 2216}
2089 2217
@@ -2184,6 +2312,8 @@ void free_fd_percpu(void)
2184 2312
2185void free_all_buffers(void) 2313void free_all_buffers(void)
2186{ 2314{
2315 int i;
2316
2187 CPU_FREE(cpu_present_set); 2317 CPU_FREE(cpu_present_set);
2188 cpu_present_set = NULL; 2318 cpu_present_set = NULL;
2189 cpu_present_setsize = 0; 2319 cpu_present_setsize = 0;
@@ -2216,6 +2346,12 @@ void free_all_buffers(void)
2216 2346
2217 free(irq_column_2_cpu); 2347 free(irq_column_2_cpu);
2218 free(irqs_per_cpu); 2348 free(irqs_per_cpu);
2349
2350 for (i = 0; i <= topo.max_cpu_num; ++i) {
2351 if (cpus[i].put_ids)
2352 CPU_FREE(cpus[i].put_ids);
2353 }
2354 free(cpus);
2219} 2355}
2220 2356
2221 2357
@@ -2240,44 +2376,6 @@ int parse_int_file(const char *fmt, ...)
2240} 2376}
2241 2377
2242/* 2378/*
2243 * get_cpu_position_in_core(cpu)
2244 * return the position of the CPU among its HT siblings in the core
2245 * return -1 if the sibling is not in list
2246 */
2247int get_cpu_position_in_core(int cpu)
2248{
2249 char path[64];
2250 FILE *filep;
2251 int this_cpu;
2252 char character;
2253 int i;
2254
2255 sprintf(path,
2256 "/sys/devices/system/cpu/cpu%d/topology/thread_siblings_list",
2257 cpu);
2258 filep = fopen(path, "r");
2259 if (filep == NULL) {
2260 perror(path);
2261 exit(1);
2262 }
2263
2264 for (i = 0; i < topo.num_threads_per_core; i++) {
2265 fscanf(filep, "%d", &this_cpu);
2266 if (this_cpu == cpu) {
2267 fclose(filep);
2268 return i;
2269 }
2270
2271 /* Account for no separator after last thread*/
2272 if (i != (topo.num_threads_per_core - 1))
2273 fscanf(filep, "%c", &character);
2274 }
2275
2276 fclose(filep);
2277 return -1;
2278}
2279
2280/*
2281 * cpu_is_first_core_in_package(cpu) 2379 * cpu_is_first_core_in_package(cpu)
2282 * return 1 if given CPU is 1st core in package 2380 * return 1 if given CPU is 1st core in package
2283 */ 2381 */
@@ -2296,35 +2394,115 @@ int get_core_id(int cpu)
2296 return parse_int_file("/sys/devices/system/cpu/cpu%d/topology/core_id", cpu); 2394 return parse_int_file("/sys/devices/system/cpu/cpu%d/topology/core_id", cpu);
2297} 2395}
2298 2396
2299int get_num_ht_siblings(int cpu) 2397void set_node_data(void)
2300{ 2398{
2301 char path[80]; 2399 char path[80];
2302 FILE *filep; 2400 FILE *filep;
2303 int sib1; 2401 int pkg, node, cpu;
2304 int matches = 0;
2305 char character;
2306 char str[100];
2307 char *ch;
2308 2402
2309 sprintf(path, "/sys/devices/system/cpu/cpu%d/topology/thread_siblings_list", cpu); 2403 struct pkg_node_info {
2310 filep = fopen_or_die(path, "r"); 2404 int count;
2405 int min;
2406 } *pni;
2311 2407
2312 /* 2408 pni = calloc(topo.num_packages, sizeof(struct pkg_node_info));
2313 * file format: 2409 if (!pni)
2314 * A ',' separated or '-' separated set of numbers 2410 err(1, "calloc pkg_node_count");
2315 * (eg 1-2 or 1,3,4,5) 2411
2316 */ 2412 for (pkg = 0; pkg < topo.num_packages; pkg++)
2317 fscanf(filep, "%d%c\n", &sib1, &character); 2413 pni[pkg].min = topo.num_cpus;
2318 fseek(filep, 0, SEEK_SET); 2414
2319 fgets(str, 100, filep); 2415 for (node = 0; node <= topo.max_node_num; node++) {
2320 ch = strchr(str, character); 2416 /* find the "first" cpu in the node */
2321 while (ch != NULL) { 2417 sprintf(path, "/sys/bus/node/devices/node%d/cpulist", node);
2322 matches++; 2418 filep = fopen(path, "r");
2323 ch = strchr(ch+1, character); 2419 if (!filep)
2420 continue;
2421 fscanf(filep, "%d", &cpu);
2422 fclose(filep);
2423
2424 pkg = cpus[cpu].physical_package_id;
2425 pni[pkg].count++;
2426
2427 if (node < pni[pkg].min)
2428 pni[pkg].min = node;
2324 } 2429 }
2325 2430
2431 for (pkg = 0; pkg < topo.num_packages; pkg++)
2432 if (pni[pkg].count > topo.nodes_per_pkg)
2433 topo.nodes_per_pkg = pni[0].count;
2434
2435 for (cpu = 0; cpu < topo.num_cpus; cpu++) {
2436 pkg = cpus[cpu].physical_package_id;
2437 node = cpus[cpu].physical_node_id;
2438 cpus[cpu].logical_node_id = node - pni[pkg].min;
2439 }
2440 free(pni);
2441
2442}
2443
2444int get_physical_node_id(struct cpu_topology *thiscpu)
2445{
2446 char path[80];
2447 FILE *filep;
2448 int i;
2449 int cpu = thiscpu->logical_cpu_id;
2450
2451 for (i = 0; i <= topo.max_cpu_num; i++) {
2452 sprintf(path, "/sys/devices/system/cpu/cpu%d/node%i/cpulist",
2453 cpu, i);
2454 filep = fopen(path, "r");
2455 if (!filep)
2456 continue;
2457 fclose(filep);
2458 return i;
2459 }
2460 return -1;
2461}
2462
2463int get_thread_siblings(struct cpu_topology *thiscpu)
2464{
2465 char path[80], character;
2466 FILE *filep;
2467 unsigned long map;
2468 int so, shift, sib_core;
2469 int cpu = thiscpu->logical_cpu_id;
2470 int offset = topo.max_cpu_num + 1;
2471 size_t size;
2472 int thread_id = 0;
2473
2474 thiscpu->put_ids = CPU_ALLOC((topo.max_cpu_num + 1));
2475 if (thiscpu->thread_id < 0)
2476 thiscpu->thread_id = thread_id++;
2477 if (!thiscpu->put_ids)
2478 return -1;
2479
2480 size = CPU_ALLOC_SIZE((topo.max_cpu_num + 1));
2481 CPU_ZERO_S(size, thiscpu->put_ids);
2482
2483 sprintf(path,
2484 "/sys/devices/system/cpu/cpu%d/topology/thread_siblings", cpu);
2485 filep = fopen_or_die(path, "r");
2486 do {
2487 offset -= BITMASK_SIZE;
2488 fscanf(filep, "%lx%c", &map, &character);
2489 for (shift = 0; shift < BITMASK_SIZE; shift++) {
2490 if ((map >> shift) & 0x1) {
2491 so = shift + offset;
2492 sib_core = get_core_id(so);
2493 if (sib_core == thiscpu->physical_core_id) {
2494 CPU_SET_S(so, size, thiscpu->put_ids);
2495 if ((so != cpu) &&
2496 (cpus[so].thread_id < 0))
2497 cpus[so].thread_id =
2498 thread_id++;
2499 }
2500 }
2501 }
2502 } while (!strncmp(&character, ",", 1));
2326 fclose(filep); 2503 fclose(filep);
2327 return matches+1; 2504
2505 return CPU_COUNT_S(size, thiscpu->put_ids);
2328} 2506}
2329 2507
2330/* 2508/*
@@ -2339,32 +2517,42 @@ int for_all_cpus_2(int (func)(struct thread_data *, struct core_data *,
2339 struct thread_data *thread_base2, struct core_data *core_base2, 2517 struct thread_data *thread_base2, struct core_data *core_base2,
2340 struct pkg_data *pkg_base2) 2518 struct pkg_data *pkg_base2)
2341{ 2519{
2342 int retval, pkg_no, core_no, thread_no; 2520 int retval, pkg_no, node_no, core_no, thread_no;
2343 2521
2344 for (pkg_no = 0; pkg_no < topo.num_packages; ++pkg_no) { 2522 for (pkg_no = 0; pkg_no < topo.num_packages; ++pkg_no) {
2345 for (core_no = 0; core_no < topo.num_cores_per_pkg; ++core_no) { 2523 for (node_no = 0; node_no < topo.nodes_per_pkg; ++node_no) {
2346 for (thread_no = 0; thread_no < 2524 for (core_no = 0; core_no < topo.cores_per_node;
2347 topo.num_threads_per_core; ++thread_no) { 2525 ++core_no) {
2348 struct thread_data *t, *t2; 2526 for (thread_no = 0; thread_no <
2349 struct core_data *c, *c2; 2527 topo.threads_per_core; ++thread_no) {
2350 struct pkg_data *p, *p2; 2528 struct thread_data *t, *t2;
2351 2529 struct core_data *c, *c2;
2352 t = GET_THREAD(thread_base, thread_no, core_no, pkg_no); 2530 struct pkg_data *p, *p2;
2353 2531
2354 if (cpu_is_not_present(t->cpu_id)) 2532 t = GET_THREAD(thread_base, thread_no,
2355 continue; 2533 core_no, node_no,
2356 2534 pkg_no);
2357 t2 = GET_THREAD(thread_base2, thread_no, core_no, pkg_no); 2535
2358 2536 if (cpu_is_not_present(t->cpu_id))
2359 c = GET_CORE(core_base, core_no, pkg_no); 2537 continue;
2360 c2 = GET_CORE(core_base2, core_no, pkg_no); 2538
2361 2539 t2 = GET_THREAD(thread_base2, thread_no,
2362 p = GET_PKG(pkg_base, pkg_no); 2540 core_no, node_no,
2363 p2 = GET_PKG(pkg_base2, pkg_no); 2541 pkg_no);
2364 2542
2365 retval = func(t, c, p, t2, c2, p2); 2543 c = GET_CORE(core_base, core_no,
2366 if (retval) 2544 node_no, pkg_no);
2367 return retval; 2545 c2 = GET_CORE(core_base2, core_no,
2546 node_no,
2547 pkg_no);
2548
2549 p = GET_PKG(pkg_base, pkg_no);
2550 p2 = GET_PKG(pkg_base2, pkg_no);
2551
2552 retval = func(t, c, p, t2, c2, p2);
2553 if (retval)
2554 return retval;
2555 }
2368 } 2556 }
2369 } 2557 }
2370 } 2558 }
@@ -2409,6 +2597,20 @@ void re_initialize(void)
2409 printf("turbostat: re-initialized with num_cpus %d\n", topo.num_cpus); 2597 printf("turbostat: re-initialized with num_cpus %d\n", topo.num_cpus);
2410} 2598}
2411 2599
2600void set_max_cpu_num(void)
2601{
2602 FILE *filep;
2603 unsigned long dummy;
2604
2605 topo.max_cpu_num = 0;
2606 filep = fopen_or_die(
2607 "/sys/devices/system/cpu/cpu0/topology/thread_siblings",
2608 "r");
2609 while (fscanf(filep, "%lx,", &dummy) == 1)
2610 topo.max_cpu_num += BITMASK_SIZE;
2611 fclose(filep);
2612 topo.max_cpu_num--; /* 0 based */
2613}
2412 2614
2413/* 2615/*
2414 * count_cpus() 2616 * count_cpus()
@@ -2416,10 +2618,7 @@ void re_initialize(void)
2416 */ 2618 */
2417int count_cpus(int cpu) 2619int count_cpus(int cpu)
2418{ 2620{
2419 if (topo.max_cpu_num < cpu) 2621 topo.num_cpus++;
2420 topo.max_cpu_num = cpu;
2421
2422 topo.num_cpus += 1;
2423 return 0; 2622 return 0;
2424} 2623}
2425int mark_cpu_present(int cpu) 2624int mark_cpu_present(int cpu)
@@ -2428,6 +2627,12 @@ int mark_cpu_present(int cpu)
2428 return 0; 2627 return 0;
2429} 2628}
2430 2629
2630int init_thread_id(int cpu)
2631{
2632 cpus[cpu].thread_id = -1;
2633 return 0;
2634}
2635
2431/* 2636/*
2432 * snapshot_proc_interrupts() 2637 * snapshot_proc_interrupts()
2433 * 2638 *
@@ -2542,6 +2747,52 @@ int snapshot_gfx_mhz(void)
2542} 2747}
2543 2748
2544/* 2749/*
2750 * snapshot_cpu_lpi()
2751 *
2752 * record snapshot of
2753 * /sys/devices/system/cpu/cpuidle/low_power_idle_cpu_residency_us
2754 *
2755 * return 1 if config change requires a restart, else return 0
2756 */
2757int snapshot_cpu_lpi_us(void)
2758{
2759 FILE *fp;
2760 int retval;
2761
2762 fp = fopen_or_die("/sys/devices/system/cpu/cpuidle/low_power_idle_cpu_residency_us", "r");
2763
2764 retval = fscanf(fp, "%lld", &cpuidle_cur_cpu_lpi_us);
2765 if (retval != 1)
2766 err(1, "CPU LPI");
2767
2768 fclose(fp);
2769
2770 return 0;
2771}
2772/*
2773 * snapshot_sys_lpi()
2774 *
2775 * record snapshot of
2776 * /sys/devices/system/cpu/cpuidle/low_power_idle_system_residency_us
2777 *
2778 * return 1 if config change requires a restart, else return 0
2779 */
2780int snapshot_sys_lpi_us(void)
2781{
2782 FILE *fp;
2783 int retval;
2784
2785 fp = fopen_or_die("/sys/devices/system/cpu/cpuidle/low_power_idle_system_residency_us", "r");
2786
2787 retval = fscanf(fp, "%lld", &cpuidle_cur_sys_lpi_us);
2788 if (retval != 1)
2789 err(1, "SYS LPI");
2790
2791 fclose(fp);
2792
2793 return 0;
2794}
2795/*
2545 * snapshot /proc and /sys files 2796 * snapshot /proc and /sys files
2546 * 2797 *
2547 * return 1 if configuration restart needed, else return 0 2798 * return 1 if configuration restart needed, else return 0
@@ -2558,13 +2809,83 @@ int snapshot_proc_sysfs_files(void)
2558 if (DO_BIC(BIC_GFXMHz)) 2809 if (DO_BIC(BIC_GFXMHz))
2559 snapshot_gfx_mhz(); 2810 snapshot_gfx_mhz();
2560 2811
2812 if (DO_BIC(BIC_CPU_LPI))
2813 snapshot_cpu_lpi_us();
2814
2815 if (DO_BIC(BIC_SYS_LPI))
2816 snapshot_sys_lpi_us();
2817
2561 return 0; 2818 return 0;
2562} 2819}
2563 2820
2821int exit_requested;
2822
2823static void signal_handler (int signal)
2824{
2825 switch (signal) {
2826 case SIGINT:
2827 exit_requested = 1;
2828 if (debug)
2829 fprintf(stderr, " SIGINT\n");
2830 break;
2831 case SIGUSR1:
2832 if (debug > 1)
2833 fprintf(stderr, "SIGUSR1\n");
2834 break;
2835 }
2836 /* make sure this manually-invoked interval is at least 1ms long */
2837 nanosleep(&one_msec, NULL);
2838}
2839
2840void setup_signal_handler(void)
2841{
2842 struct sigaction sa;
2843
2844 memset(&sa, 0, sizeof(sa));
2845
2846 sa.sa_handler = &signal_handler;
2847
2848 if (sigaction(SIGINT, &sa, NULL) < 0)
2849 err(1, "sigaction SIGINT");
2850 if (sigaction(SIGUSR1, &sa, NULL) < 0)
2851 err(1, "sigaction SIGUSR1");
2852}
2853
2854void do_sleep(void)
2855{
2856 struct timeval select_timeout;
2857 fd_set readfds;
2858 int retval;
2859
2860 FD_ZERO(&readfds);
2861 FD_SET(0, &readfds);
2862
2863 if (!isatty(fileno(stdin))) {
2864 nanosleep(&interval_ts, NULL);
2865 return;
2866 }
2867
2868 select_timeout = interval_tv;
2869 retval = select(1, &readfds, NULL, NULL, &select_timeout);
2870
2871 if (retval == 1) {
2872 switch (getc(stdin)) {
2873 case 'q':
2874 exit_requested = 1;
2875 break;
2876 }
2877 /* make sure this manually-invoked interval is at least 1ms long */
2878 nanosleep(&one_msec, NULL);
2879 }
2880}
2881
2564void turbostat_loop() 2882void turbostat_loop()
2565{ 2883{
2566 int retval; 2884 int retval;
2567 int restarted = 0; 2885 int restarted = 0;
2886 int done_iters = 0;
2887
2888 setup_signal_handler();
2568 2889
2569restart: 2890restart:
2570 restarted++; 2891 restarted++;
@@ -2581,6 +2902,7 @@ restart:
2581 goto restart; 2902 goto restart;
2582 } 2903 }
2583 restarted = 0; 2904 restarted = 0;
2905 done_iters = 0;
2584 gettimeofday(&tv_even, (struct timezone *)NULL); 2906 gettimeofday(&tv_even, (struct timezone *)NULL);
2585 2907
2586 while (1) { 2908 while (1) {
@@ -2588,7 +2910,7 @@ restart:
2588 re_initialize(); 2910 re_initialize();
2589 goto restart; 2911 goto restart;
2590 } 2912 }
2591 nanosleep(&interval_ts, NULL); 2913 do_sleep();
2592 if (snapshot_proc_sysfs_files()) 2914 if (snapshot_proc_sysfs_files())
2593 goto restart; 2915 goto restart;
2594 retval = for_all_cpus(get_counters, ODD_COUNTERS); 2916 retval = for_all_cpus(get_counters, ODD_COUNTERS);
@@ -2607,7 +2929,11 @@ restart:
2607 compute_average(EVEN_COUNTERS); 2929 compute_average(EVEN_COUNTERS);
2608 format_all_counters(EVEN_COUNTERS); 2930 format_all_counters(EVEN_COUNTERS);
2609 flush_output_stdout(); 2931 flush_output_stdout();
2610 nanosleep(&interval_ts, NULL); 2932 if (exit_requested)
2933 break;
2934 if (num_iterations && ++done_iters >= num_iterations)
2935 break;
2936 do_sleep();
2611 if (snapshot_proc_sysfs_files()) 2937 if (snapshot_proc_sysfs_files())
2612 goto restart; 2938 goto restart;
2613 retval = for_all_cpus(get_counters, EVEN_COUNTERS); 2939 retval = for_all_cpus(get_counters, EVEN_COUNTERS);
@@ -2626,6 +2952,10 @@ restart:
2626 compute_average(ODD_COUNTERS); 2952 compute_average(ODD_COUNTERS);
2627 format_all_counters(ODD_COUNTERS); 2953 format_all_counters(ODD_COUNTERS);
2628 flush_output_stdout(); 2954 flush_output_stdout();
2955 if (exit_requested)
2956 break;
2957 if (num_iterations && ++done_iters >= num_iterations)
2958 break;
2629 } 2959 }
2630} 2960}
2631 2961
@@ -2740,6 +3070,7 @@ int probe_nhm_msrs(unsigned int family, unsigned int model)
2740 case INTEL_FAM6_SKYLAKE_DESKTOP: /* SKL */ 3070 case INTEL_FAM6_SKYLAKE_DESKTOP: /* SKL */
2741 case INTEL_FAM6_KABYLAKE_MOBILE: /* KBL */ 3071 case INTEL_FAM6_KABYLAKE_MOBILE: /* KBL */
2742 case INTEL_FAM6_KABYLAKE_DESKTOP: /* KBL */ 3072 case INTEL_FAM6_KABYLAKE_DESKTOP: /* KBL */
3073 case INTEL_FAM6_CANNONLAKE_MOBILE: /* CNL */
2743 pkg_cstate_limits = hsw_pkg_cstate_limits; 3074 pkg_cstate_limits = hsw_pkg_cstate_limits;
2744 has_misc_feature_control = 1; 3075 has_misc_feature_control = 1;
2745 break; 3076 break;
@@ -2945,6 +3276,7 @@ int has_config_tdp(unsigned int family, unsigned int model)
2945 case INTEL_FAM6_SKYLAKE_DESKTOP: /* SKL */ 3276 case INTEL_FAM6_SKYLAKE_DESKTOP: /* SKL */
2946 case INTEL_FAM6_KABYLAKE_MOBILE: /* KBL */ 3277 case INTEL_FAM6_KABYLAKE_MOBILE: /* KBL */
2947 case INTEL_FAM6_KABYLAKE_DESKTOP: /* KBL */ 3278 case INTEL_FAM6_KABYLAKE_DESKTOP: /* KBL */
3279 case INTEL_FAM6_CANNONLAKE_MOBILE: /* CNL */
2948 case INTEL_FAM6_SKYLAKE_X: /* SKX */ 3280 case INTEL_FAM6_SKYLAKE_X: /* SKX */
2949 3281
2950 case INTEL_FAM6_XEON_PHI_KNL: /* Knights Landing */ 3282 case INTEL_FAM6_XEON_PHI_KNL: /* Knights Landing */
@@ -3399,6 +3731,7 @@ void rapl_probe(unsigned int family, unsigned int model)
3399 case INTEL_FAM6_SKYLAKE_DESKTOP: /* SKL */ 3731 case INTEL_FAM6_SKYLAKE_DESKTOP: /* SKL */
3400 case INTEL_FAM6_KABYLAKE_MOBILE: /* KBL */ 3732 case INTEL_FAM6_KABYLAKE_MOBILE: /* KBL */
3401 case INTEL_FAM6_KABYLAKE_DESKTOP: /* KBL */ 3733 case INTEL_FAM6_KABYLAKE_DESKTOP: /* KBL */
3734 case INTEL_FAM6_CANNONLAKE_MOBILE: /* CNL */
3402 do_rapl = RAPL_PKG | RAPL_CORES | RAPL_CORE_POLICY | RAPL_DRAM | RAPL_DRAM_PERF_STATUS | RAPL_PKG_PERF_STATUS | RAPL_GFX | RAPL_PKG_POWER_INFO; 3735 do_rapl = RAPL_PKG | RAPL_CORES | RAPL_CORE_POLICY | RAPL_DRAM | RAPL_DRAM_PERF_STATUS | RAPL_PKG_PERF_STATUS | RAPL_GFX | RAPL_PKG_POWER_INFO;
3403 BIC_PRESENT(BIC_PKG__); 3736 BIC_PRESENT(BIC_PKG__);
3404 BIC_PRESENT(BIC_RAM__); 3737 BIC_PRESENT(BIC_RAM__);
@@ -3523,6 +3856,12 @@ void perf_limit_reasons_probe(unsigned int family, unsigned int model)
3523 } 3856 }
3524} 3857}
3525 3858
3859void automatic_cstate_conversion_probe(unsigned int family, unsigned int model)
3860{
3861 if (is_skx(family, model) || is_bdx(family, model))
3862 has_automatic_cstate_conversion = 1;
3863}
3864
3526int print_thermal(struct thread_data *t, struct core_data *c, struct pkg_data *p) 3865int print_thermal(struct thread_data *t, struct core_data *c, struct pkg_data *p)
3527{ 3866{
3528 unsigned long long msr; 3867 unsigned long long msr;
@@ -3728,6 +4067,7 @@ int has_snb_msrs(unsigned int family, unsigned int model)
3728 case INTEL_FAM6_SKYLAKE_DESKTOP: /* SKL */ 4067 case INTEL_FAM6_SKYLAKE_DESKTOP: /* SKL */
3729 case INTEL_FAM6_KABYLAKE_MOBILE: /* KBL */ 4068 case INTEL_FAM6_KABYLAKE_MOBILE: /* KBL */
3730 case INTEL_FAM6_KABYLAKE_DESKTOP: /* KBL */ 4069 case INTEL_FAM6_KABYLAKE_DESKTOP: /* KBL */
4070 case INTEL_FAM6_CANNONLAKE_MOBILE: /* CNL */
3731 case INTEL_FAM6_SKYLAKE_X: /* SKX */ 4071 case INTEL_FAM6_SKYLAKE_X: /* SKX */
3732 case INTEL_FAM6_ATOM_GOLDMONT: /* BXT */ 4072 case INTEL_FAM6_ATOM_GOLDMONT: /* BXT */
3733 case INTEL_FAM6_ATOM_GEMINI_LAKE: 4073 case INTEL_FAM6_ATOM_GEMINI_LAKE:
@@ -3761,6 +4101,7 @@ int has_hsw_msrs(unsigned int family, unsigned int model)
3761 case INTEL_FAM6_SKYLAKE_DESKTOP: /* SKL */ 4101 case INTEL_FAM6_SKYLAKE_DESKTOP: /* SKL */
3762 case INTEL_FAM6_KABYLAKE_MOBILE: /* KBL */ 4102 case INTEL_FAM6_KABYLAKE_MOBILE: /* KBL */
3763 case INTEL_FAM6_KABYLAKE_DESKTOP: /* KBL */ 4103 case INTEL_FAM6_KABYLAKE_DESKTOP: /* KBL */
4104 case INTEL_FAM6_CANNONLAKE_MOBILE: /* CNL */
3764 case INTEL_FAM6_ATOM_GOLDMONT: /* BXT */ 4105 case INTEL_FAM6_ATOM_GOLDMONT: /* BXT */
3765 case INTEL_FAM6_ATOM_GEMINI_LAKE: 4106 case INTEL_FAM6_ATOM_GEMINI_LAKE:
3766 return 1; 4107 return 1;
@@ -3786,6 +4127,7 @@ int has_skl_msrs(unsigned int family, unsigned int model)
3786 case INTEL_FAM6_SKYLAKE_DESKTOP: /* SKL */ 4127 case INTEL_FAM6_SKYLAKE_DESKTOP: /* SKL */
3787 case INTEL_FAM6_KABYLAKE_MOBILE: /* KBL */ 4128 case INTEL_FAM6_KABYLAKE_MOBILE: /* KBL */
3788 case INTEL_FAM6_KABYLAKE_DESKTOP: /* KBL */ 4129 case INTEL_FAM6_KABYLAKE_DESKTOP: /* KBL */
4130 case INTEL_FAM6_CANNONLAKE_MOBILE: /* CNL */
3789 return 1; 4131 return 1;
3790 } 4132 }
3791 return 0; 4133 return 0;
@@ -3815,6 +4157,19 @@ int is_knl(unsigned int family, unsigned int model)
3815 return 0; 4157 return 0;
3816} 4158}
3817 4159
4160int is_cnl(unsigned int family, unsigned int model)
4161{
4162 if (!genuine_intel)
4163 return 0;
4164
4165 switch (model) {
4166 case INTEL_FAM6_CANNONLAKE_MOBILE: /* CNL */
4167 return 1;
4168 }
4169
4170 return 0;
4171}
4172
3818unsigned int get_aperf_mperf_multiplier(unsigned int family, unsigned int model) 4173unsigned int get_aperf_mperf_multiplier(unsigned int family, unsigned int model)
3819{ 4174{
3820 if (is_knl(family, model)) 4175 if (is_knl(family, model))
@@ -3947,7 +4302,7 @@ void decode_misc_enable_msr(void)
3947 base_cpu, msr, 4302 base_cpu, msr,
3948 msr & MSR_IA32_MISC_ENABLE_TM1 ? "" : "No-", 4303 msr & MSR_IA32_MISC_ENABLE_TM1 ? "" : "No-",
3949 msr & MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP ? "" : "No-", 4304 msr & MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP ? "" : "No-",
3950 msr & MSR_IA32_MISC_ENABLE_MWAIT ? "No-" : "", 4305 msr & MSR_IA32_MISC_ENABLE_MWAIT ? "" : "No-",
3951 msr & MSR_IA32_MISC_ENABLE_PREFETCH_DISABLE ? "No-" : "", 4306 msr & MSR_IA32_MISC_ENABLE_PREFETCH_DISABLE ? "No-" : "",
3952 msr & MSR_IA32_MISC_ENABLE_TURBO_DISABLE ? "No-" : ""); 4307 msr & MSR_IA32_MISC_ENABLE_TURBO_DISABLE ? "No-" : "");
3953} 4308}
@@ -4152,7 +4507,6 @@ void process_cpuid()
4152 case INTEL_FAM6_KABYLAKE_DESKTOP: /* KBL */ 4507 case INTEL_FAM6_KABYLAKE_DESKTOP: /* KBL */
4153 crystal_hz = 24000000; /* 24.0 MHz */ 4508 crystal_hz = 24000000; /* 24.0 MHz */
4154 break; 4509 break;
4155 case INTEL_FAM6_SKYLAKE_X: /* SKX */
4156 case INTEL_FAM6_ATOM_DENVERTON: /* DNV */ 4510 case INTEL_FAM6_ATOM_DENVERTON: /* DNV */
4157 crystal_hz = 25000000; /* 25.0 MHz */ 4511 crystal_hz = 25000000; /* 25.0 MHz */
4158 break; 4512 break;
@@ -4253,6 +4607,7 @@ void process_cpuid()
4253 } 4607 }
4254 do_slm_cstates = is_slm(family, model); 4608 do_slm_cstates = is_slm(family, model);
4255 do_knl_cstates = is_knl(family, model); 4609 do_knl_cstates = is_knl(family, model);
4610 do_cnl_cstates = is_cnl(family, model);
4256 4611
4257 if (!quiet) 4612 if (!quiet)
4258 decode_misc_pwr_mgmt_msr(); 4613 decode_misc_pwr_mgmt_msr();
@@ -4262,6 +4617,7 @@ void process_cpuid()
4262 4617
4263 rapl_probe(family, model); 4618 rapl_probe(family, model);
4264 perf_limit_reasons_probe(family, model); 4619 perf_limit_reasons_probe(family, model);
4620 automatic_cstate_conversion_probe(family, model);
4265 4621
4266 if (!quiet) 4622 if (!quiet)
4267 dump_cstate_pstate_config_info(family, model); 4623 dump_cstate_pstate_config_info(family, model);
@@ -4280,6 +4636,16 @@ void process_cpuid()
4280 if (!access("/sys/class/graphics/fb0/device/drm/card0/gt_cur_freq_mhz", R_OK)) 4636 if (!access("/sys/class/graphics/fb0/device/drm/card0/gt_cur_freq_mhz", R_OK))
4281 BIC_PRESENT(BIC_GFXMHz); 4637 BIC_PRESENT(BIC_GFXMHz);
4282 4638
4639 if (!access("/sys/devices/system/cpu/cpuidle/low_power_idle_cpu_residency_us", R_OK))
4640 BIC_PRESENT(BIC_CPU_LPI);
4641 else
4642 BIC_NOT_PRESENT(BIC_CPU_LPI);
4643
4644 if (!access("/sys/devices/system/cpu/cpuidle/low_power_idle_system_residency_us", R_OK))
4645 BIC_PRESENT(BIC_SYS_LPI);
4646 else
4647 BIC_NOT_PRESENT(BIC_SYS_LPI);
4648
4283 if (!quiet) 4649 if (!quiet)
4284 decode_misc_feature_control(); 4650 decode_misc_feature_control();
4285 4651
@@ -4310,14 +4676,10 @@ void topology_probe()
4310 int max_core_id = 0; 4676 int max_core_id = 0;
4311 int max_package_id = 0; 4677 int max_package_id = 0;
4312 int max_siblings = 0; 4678 int max_siblings = 0;
4313 struct cpu_topology {
4314 int core_id;
4315 int physical_package_id;
4316 } *cpus;
4317 4679
4318 /* Initialize num_cpus, max_cpu_num */ 4680 /* Initialize num_cpus, max_cpu_num */
4681 set_max_cpu_num();
4319 topo.num_cpus = 0; 4682 topo.num_cpus = 0;
4320 topo.max_cpu_num = 0;
4321 for_all_proc_cpus(count_cpus); 4683 for_all_proc_cpus(count_cpus);
4322 if (!summary_only && topo.num_cpus > 1) 4684 if (!summary_only && topo.num_cpus > 1)
4323 BIC_PRESENT(BIC_CPU); 4685 BIC_PRESENT(BIC_CPU);
@@ -4357,6 +4719,7 @@ void topology_probe()
4357 cpu_affinity_setsize = CPU_ALLOC_SIZE((topo.max_cpu_num + 1)); 4719 cpu_affinity_setsize = CPU_ALLOC_SIZE((topo.max_cpu_num + 1));
4358 CPU_ZERO_S(cpu_affinity_setsize, cpu_affinity_set); 4720 CPU_ZERO_S(cpu_affinity_setsize, cpu_affinity_set);
4359 4721
4722 for_all_proc_cpus(init_thread_id);
4360 4723
4361 /* 4724 /*
4362 * For online cpus 4725 * For online cpus
@@ -4370,26 +4733,45 @@ void topology_probe()
4370 fprintf(outf, "cpu%d NOT PRESENT\n", i); 4733 fprintf(outf, "cpu%d NOT PRESENT\n", i);
4371 continue; 4734 continue;
4372 } 4735 }
4373 cpus[i].core_id = get_core_id(i);
4374 if (cpus[i].core_id > max_core_id)
4375 max_core_id = cpus[i].core_id;
4376 4736
4737 cpus[i].logical_cpu_id = i;
4738
4739 /* get package information */
4377 cpus[i].physical_package_id = get_physical_package_id(i); 4740 cpus[i].physical_package_id = get_physical_package_id(i);
4378 if (cpus[i].physical_package_id > max_package_id) 4741 if (cpus[i].physical_package_id > max_package_id)
4379 max_package_id = cpus[i].physical_package_id; 4742 max_package_id = cpus[i].physical_package_id;
4380 4743
4381 siblings = get_num_ht_siblings(i); 4744 /* get numa node information */
4745 cpus[i].physical_node_id = get_physical_node_id(&cpus[i]);
4746 if (cpus[i].physical_node_id > topo.max_node_num)
4747 topo.max_node_num = cpus[i].physical_node_id;
4748
4749 /* get core information */
4750 cpus[i].physical_core_id = get_core_id(i);
4751 if (cpus[i].physical_core_id > max_core_id)
4752 max_core_id = cpus[i].physical_core_id;
4753
4754 /* get thread information */
4755 siblings = get_thread_siblings(&cpus[i]);
4382 if (siblings > max_siblings) 4756 if (siblings > max_siblings)
4383 max_siblings = siblings; 4757 max_siblings = siblings;
4758 if (cpus[i].thread_id != -1)
4759 topo.num_cores++;
4760
4384 if (debug > 1) 4761 if (debug > 1)
4385 fprintf(outf, "cpu %d pkg %d core %d\n", 4762 fprintf(outf,
4386 i, cpus[i].physical_package_id, cpus[i].core_id); 4763 "cpu %d pkg %d node %d core %d thread %d\n",
4764 i, cpus[i].physical_package_id,
4765 cpus[i].physical_node_id,
4766 cpus[i].physical_core_id,
4767 cpus[i].thread_id);
4387 } 4768 }
4388 topo.num_cores_per_pkg = max_core_id + 1; 4769
4770 topo.cores_per_node = max_core_id + 1;
4389 if (debug > 1) 4771 if (debug > 1)
4390 fprintf(outf, "max_core_id %d, sizing for %d cores per package\n", 4772 fprintf(outf, "max_core_id %d, sizing for %d cores per package\n",
4391 max_core_id, topo.num_cores_per_pkg); 4773 max_core_id, topo.cores_per_node);
4392 if (!summary_only && topo.num_cores_per_pkg > 1) 4774 if (!summary_only && topo.cores_per_node > 1)
4393 BIC_PRESENT(BIC_Core); 4775 BIC_PRESENT(BIC_Core);
4394 4776
4395 topo.num_packages = max_package_id + 1; 4777 topo.num_packages = max_package_id + 1;
@@ -4399,33 +4781,38 @@ void topology_probe()
4399 if (!summary_only && topo.num_packages > 1) 4781 if (!summary_only && topo.num_packages > 1)
4400 BIC_PRESENT(BIC_Package); 4782 BIC_PRESENT(BIC_Package);
4401 4783
4402 topo.num_threads_per_core = max_siblings; 4784 set_node_data();
4403 if (debug > 1) 4785 if (debug > 1)
4404 fprintf(outf, "max_siblings %d\n", max_siblings); 4786 fprintf(outf, "nodes_per_pkg %d\n", topo.nodes_per_pkg);
4787 if (!summary_only && topo.nodes_per_pkg > 1)
4788 BIC_PRESENT(BIC_Node);
4405 4789
4406 free(cpus); 4790 topo.threads_per_core = max_siblings;
4791 if (debug > 1)
4792 fprintf(outf, "max_siblings %d\n", max_siblings);
4407} 4793}
4408 4794
4409void 4795void
4410allocate_counters(struct thread_data **t, struct core_data **c, struct pkg_data **p) 4796allocate_counters(struct thread_data **t, struct core_data **c,
4797 struct pkg_data **p)
4411{ 4798{
4412 int i; 4799 int i;
4800 int num_cores = topo.cores_per_node * topo.nodes_per_pkg *
4801 topo.num_packages;
4802 int num_threads = topo.threads_per_core * num_cores;
4413 4803
4414 *t = calloc(topo.num_threads_per_core * topo.num_cores_per_pkg * 4804 *t = calloc(num_threads, sizeof(struct thread_data));
4415 topo.num_packages, sizeof(struct thread_data));
4416 if (*t == NULL) 4805 if (*t == NULL)
4417 goto error; 4806 goto error;
4418 4807
4419 for (i = 0; i < topo.num_threads_per_core * 4808 for (i = 0; i < num_threads; i++)
4420 topo.num_cores_per_pkg * topo.num_packages; i++)
4421 (*t)[i].cpu_id = -1; 4809 (*t)[i].cpu_id = -1;
4422 4810
4423 *c = calloc(topo.num_cores_per_pkg * topo.num_packages, 4811 *c = calloc(num_cores, sizeof(struct core_data));
4424 sizeof(struct core_data));
4425 if (*c == NULL) 4812 if (*c == NULL)
4426 goto error; 4813 goto error;
4427 4814
4428 for (i = 0; i < topo.num_cores_per_pkg * topo.num_packages; i++) 4815 for (i = 0; i < num_cores; i++)
4429 (*c)[i].core_id = -1; 4816 (*c)[i].core_id = -1;
4430 4817
4431 *p = calloc(topo.num_packages, sizeof(struct pkg_data)); 4818 *p = calloc(topo.num_packages, sizeof(struct pkg_data));
@@ -4442,47 +4829,39 @@ error:
4442/* 4829/*
4443 * init_counter() 4830 * init_counter()
4444 * 4831 *
4445 * set cpu_id, core_num, pkg_num
4446 * set FIRST_THREAD_IN_CORE and FIRST_CORE_IN_PACKAGE 4832 * set FIRST_THREAD_IN_CORE and FIRST_CORE_IN_PACKAGE
4447 *
4448 * increment topo.num_cores when 1st core in pkg seen
4449 */ 4833 */
4450void init_counter(struct thread_data *thread_base, struct core_data *core_base, 4834void init_counter(struct thread_data *thread_base, struct core_data *core_base,
4451 struct pkg_data *pkg_base, int thread_num, int core_num, 4835 struct pkg_data *pkg_base, int cpu_id)
4452 int pkg_num, int cpu_id)
4453{ 4836{
4837 int pkg_id = cpus[cpu_id].physical_package_id;
4838 int node_id = cpus[cpu_id].logical_node_id;
4839 int core_id = cpus[cpu_id].physical_core_id;
4840 int thread_id = cpus[cpu_id].thread_id;
4454 struct thread_data *t; 4841 struct thread_data *t;
4455 struct core_data *c; 4842 struct core_data *c;
4456 struct pkg_data *p; 4843 struct pkg_data *p;
4457 4844
4458 t = GET_THREAD(thread_base, thread_num, core_num, pkg_num); 4845 t = GET_THREAD(thread_base, thread_id, core_id, node_id, pkg_id);
4459 c = GET_CORE(core_base, core_num, pkg_num); 4846 c = GET_CORE(core_base, core_id, node_id, pkg_id);
4460 p = GET_PKG(pkg_base, pkg_num); 4847 p = GET_PKG(pkg_base, pkg_id);
4461 4848
4462 t->cpu_id = cpu_id; 4849 t->cpu_id = cpu_id;
4463 if (thread_num == 0) { 4850 if (thread_id == 0) {
4464 t->flags |= CPU_IS_FIRST_THREAD_IN_CORE; 4851 t->flags |= CPU_IS_FIRST_THREAD_IN_CORE;
4465 if (cpu_is_first_core_in_package(cpu_id)) 4852 if (cpu_is_first_core_in_package(cpu_id))
4466 t->flags |= CPU_IS_FIRST_CORE_IN_PACKAGE; 4853 t->flags |= CPU_IS_FIRST_CORE_IN_PACKAGE;
4467 } 4854 }
4468 4855
4469 c->core_id = core_num; 4856 c->core_id = core_id;
4470 p->package_id = pkg_num; 4857 p->package_id = pkg_id;
4471} 4858}
4472 4859
4473 4860
4474int initialize_counters(int cpu_id) 4861int initialize_counters(int cpu_id)
4475{ 4862{
4476 int my_thread_id, my_core_id, my_package_id; 4863 init_counter(EVEN_COUNTERS, cpu_id);
4477 4864 init_counter(ODD_COUNTERS, cpu_id);
4478 my_package_id = get_physical_package_id(cpu_id);
4479 my_core_id = get_core_id(cpu_id);
4480 my_thread_id = get_cpu_position_in_core(cpu_id);
4481 if (!my_thread_id)
4482 topo.num_cores++;
4483
4484 init_counter(EVEN_COUNTERS, my_thread_id, my_core_id, my_package_id, cpu_id);
4485 init_counter(ODD_COUNTERS, my_thread_id, my_core_id, my_package_id, cpu_id);
4486 return 0; 4865 return 0;
4487} 4866}
4488 4867
@@ -4630,7 +5009,7 @@ int get_and_dump_counters(void)
4630} 5009}
4631 5010
4632void print_version() { 5011void print_version() {
4633 fprintf(outf, "turbostat version 17.06.23" 5012 fprintf(outf, "turbostat version 18.06.01"
4634 " - Len Brown <lenb@kernel.org>\n"); 5013 " - Len Brown <lenb@kernel.org>\n");
4635} 5014}
4636 5015
@@ -4661,7 +5040,7 @@ int add_counter(unsigned int msr_num, char *path, char *name,
4661 msrp->next = sys.tp; 5040 msrp->next = sys.tp;
4662 sys.tp = msrp; 5041 sys.tp = msrp;
4663 sys.added_thread_counters++; 5042 sys.added_thread_counters++;
4664 if (sys.added_thread_counters > MAX_ADDED_COUNTERS) { 5043 if (sys.added_thread_counters > MAX_ADDED_THREAD_COUNTERS) {
4665 fprintf(stderr, "exceeded max %d added thread counters\n", 5044 fprintf(stderr, "exceeded max %d added thread counters\n",
4666 MAX_ADDED_COUNTERS); 5045 MAX_ADDED_COUNTERS);
4667 exit(-1); 5046 exit(-1);
@@ -4820,7 +5199,7 @@ void probe_sysfs(void)
4820 if (!DO_BIC(BIC_sysfs)) 5199 if (!DO_BIC(BIC_sysfs))
4821 return; 5200 return;
4822 5201
4823 for (state = 10; state > 0; --state) { 5202 for (state = 10; state >= 0; --state) {
4824 5203
4825 sprintf(path, "/sys/devices/system/cpu/cpu%d/cpuidle/state%d/name", 5204 sprintf(path, "/sys/devices/system/cpu/cpu%d/cpuidle/state%d/name",
4826 base_cpu, state); 5205 base_cpu, state);
@@ -4847,7 +5226,7 @@ void probe_sysfs(void)
4847 FORMAT_PERCENT, SYSFS_PERCPU); 5226 FORMAT_PERCENT, SYSFS_PERCPU);
4848 } 5227 }
4849 5228
4850 for (state = 10; state > 0; --state) { 5229 for (state = 10; state >= 0; --state) {
4851 5230
4852 sprintf(path, "/sys/devices/system/cpu/cpu%d/cpuidle/state%d/name", 5231 sprintf(path, "/sys/devices/system/cpu/cpu%d/cpuidle/state%d/name",
4853 base_cpu, state); 5232 base_cpu, state);
@@ -4960,34 +5339,6 @@ error:
4960 exit(-1); 5339 exit(-1);
4961} 5340}
4962 5341
4963int shown;
4964/*
4965 * parse_show_hide() - process cmdline to set default counter action
4966 */
4967void parse_show_hide(char *optarg, enum show_hide_mode new_mode)
4968{
4969 /*
4970 * --show: show only those specified
4971 * The 1st invocation will clear and replace the enabled mask
4972 * subsequent invocations can add to it.
4973 */
4974 if (new_mode == SHOW_LIST) {
4975 if (shown == 0)
4976 bic_enabled = bic_lookup(optarg, new_mode);
4977 else
4978 bic_enabled |= bic_lookup(optarg, new_mode);
4979 shown = 1;
4980
4981 return;
4982 }
4983
4984 /*
4985 * --hide: do not show those specified
4986 * multiple invocations simply clear more bits in enabled mask
4987 */
4988 bic_enabled &= ~bic_lookup(optarg, new_mode);
4989
4990}
4991 5342
4992void cmdline(int argc, char **argv) 5343void cmdline(int argc, char **argv)
4993{ 5344{
@@ -4998,7 +5349,9 @@ void cmdline(int argc, char **argv)
4998 {"cpu", required_argument, 0, 'c'}, 5349 {"cpu", required_argument, 0, 'c'},
4999 {"Dump", no_argument, 0, 'D'}, 5350 {"Dump", no_argument, 0, 'D'},
5000 {"debug", no_argument, 0, 'd'}, /* internal, not documented */ 5351 {"debug", no_argument, 0, 'd'}, /* internal, not documented */
5352 {"enable", required_argument, 0, 'e'},
5001 {"interval", required_argument, 0, 'i'}, 5353 {"interval", required_argument, 0, 'i'},
5354 {"num_iterations", required_argument, 0, 'n'},
5002 {"help", no_argument, 0, 'h'}, 5355 {"help", no_argument, 0, 'h'},
5003 {"hide", required_argument, 0, 'H'}, // meh, -h taken by --help 5356 {"hide", required_argument, 0, 'H'}, // meh, -h taken by --help
5004 {"Joules", no_argument, 0, 'J'}, 5357 {"Joules", no_argument, 0, 'J'},
@@ -5014,7 +5367,7 @@ void cmdline(int argc, char **argv)
5014 5367
5015 progname = argv[0]; 5368 progname = argv[0];
5016 5369
5017 while ((opt = getopt_long_only(argc, argv, "+C:c:Ddhi:JM:m:o:qST:v", 5370 while ((opt = getopt_long_only(argc, argv, "+C:c:Dde:hi:Jn:o:qST:v",
5018 long_options, &option_index)) != -1) { 5371 long_options, &option_index)) != -1) {
5019 switch (opt) { 5372 switch (opt) {
5020 case 'a': 5373 case 'a':
@@ -5026,11 +5379,20 @@ void cmdline(int argc, char **argv)
5026 case 'D': 5379 case 'D':
5027 dump_only++; 5380 dump_only++;
5028 break; 5381 break;
5382 case 'e':
5383 /* --enable specified counter */
5384 bic_enabled |= bic_lookup(optarg, SHOW_LIST);
5385 break;
5029 case 'd': 5386 case 'd':
5030 debug++; 5387 debug++;
5388 ENABLE_BIC(BIC_DISABLED_BY_DEFAULT);
5031 break; 5389 break;
5032 case 'H': 5390 case 'H':
5033 parse_show_hide(optarg, HIDE_LIST); 5391 /*
5392 * --hide: do not show those specified
5393 * multiple invocations simply clear more bits in enabled mask
5394 */
5395 bic_enabled &= ~bic_lookup(optarg, HIDE_LIST);
5034 break; 5396 break;
5035 case 'h': 5397 case 'h':
5036 default: 5398 default:
@@ -5046,7 +5408,8 @@ void cmdline(int argc, char **argv)
5046 exit(2); 5408 exit(2);
5047 } 5409 }
5048 5410
5049 interval_ts.tv_sec = interval; 5411 interval_tv.tv_sec = interval_ts.tv_sec = interval;
5412 interval_tv.tv_usec = (interval - interval_tv.tv_sec) * 1000000;
5050 interval_ts.tv_nsec = (interval - interval_ts.tv_sec) * 1000000000; 5413 interval_ts.tv_nsec = (interval - interval_ts.tv_sec) * 1000000000;
5051 } 5414 }
5052 break; 5415 break;
@@ -5054,6 +5417,7 @@ void cmdline(int argc, char **argv)
5054 rapl_joules++; 5417 rapl_joules++;
5055 break; 5418 break;
5056 case 'l': 5419 case 'l':
5420 ENABLE_BIC(BIC_DISABLED_BY_DEFAULT);
5057 list_header_only++; 5421 list_header_only++;
5058 quiet++; 5422 quiet++;
5059 break; 5423 break;
@@ -5063,8 +5427,26 @@ void cmdline(int argc, char **argv)
5063 case 'q': 5427 case 'q':
5064 quiet = 1; 5428 quiet = 1;
5065 break; 5429 break;
5430 case 'n':
5431 num_iterations = strtod(optarg, NULL);
5432
5433 if (num_iterations <= 0) {
5434 fprintf(outf, "iterations %d should be positive number\n",
5435 num_iterations);
5436 exit(2);
5437 }
5438 break;
5066 case 's': 5439 case 's':
5067 parse_show_hide(optarg, SHOW_LIST); 5440 /*
5441 * --show: show only those specified
5442 * The 1st invocation will clear and replace the enabled mask
5443 * subsequent invocations can add to it.
5444 */
5445 if (shown == 0)
5446 bic_enabled = bic_lookup(optarg, SHOW_LIST);
5447 else
5448 bic_enabled |= bic_lookup(optarg, SHOW_LIST);
5449 shown = 1;
5068 break; 5450 break;
5069 case 'S': 5451 case 'S':
5070 summary_only++; 5452 summary_only++;
diff --git a/tools/power/x86/x86_energy_perf_policy/Makefile b/tools/power/x86/x86_energy_perf_policy/Makefile
index 2447b1bbaacf..f4534fb8b951 100644
--- a/tools/power/x86/x86_energy_perf_policy/Makefile
+++ b/tools/power/x86/x86_energy_perf_policy/Makefile
@@ -24,5 +24,5 @@ install : x86_energy_perf_policy
24 install -d $(DESTDIR)$(PREFIX)/bin 24 install -d $(DESTDIR)$(PREFIX)/bin
25 install $(BUILD_OUTPUT)/x86_energy_perf_policy $(DESTDIR)$(PREFIX)/bin/x86_energy_perf_policy 25 install $(BUILD_OUTPUT)/x86_energy_perf_policy $(DESTDIR)$(PREFIX)/bin/x86_energy_perf_policy
26 install -d $(DESTDIR)$(PREFIX)/share/man/man8 26 install -d $(DESTDIR)$(PREFIX)/share/man/man8
27 install x86_energy_perf_policy.8 $(DESTDIR)$(PREFIX)/share/man/man8 27 install -m 644 x86_energy_perf_policy.8 $(DESTDIR)$(PREFIX)/share/man/man8
28 28