aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/ABI/testing/sysfs-devices-system-cpu69
-rw-r--r--drivers/cpufreq/powernv-cpufreq.c74
2 files changed, 141 insertions, 2 deletions
diff --git a/Documentation/ABI/testing/sysfs-devices-system-cpu b/Documentation/ABI/testing/sysfs-devices-system-cpu
index b683e8ee69ec..16501334b99f 100644
--- a/Documentation/ABI/testing/sysfs-devices-system-cpu
+++ b/Documentation/ABI/testing/sysfs-devices-system-cpu
@@ -271,3 +271,72 @@ Description: Parameters for the CPU cache attributes
271 - WriteBack: data is written only to the cache line and 271 - WriteBack: data is written only to the cache line and
272 the modified cache line is written to main 272 the modified cache line is written to main
273 memory only when it is replaced 273 memory only when it is replaced
274
275What: /sys/devices/system/cpu/cpuX/cpufreq/throttle_stats
276 /sys/devices/system/cpu/cpuX/cpufreq/throttle_stats/turbo_stat
277 /sys/devices/system/cpu/cpuX/cpufreq/throttle_stats/sub_turbo_stat
278 /sys/devices/system/cpu/cpuX/cpufreq/throttle_stats/unthrottle
279 /sys/devices/system/cpu/cpuX/cpufreq/throttle_stats/powercap
280 /sys/devices/system/cpu/cpuX/cpufreq/throttle_stats/overtemp
281 /sys/devices/system/cpu/cpuX/cpufreq/throttle_stats/supply_fault
282 /sys/devices/system/cpu/cpuX/cpufreq/throttle_stats/overcurrent
283 /sys/devices/system/cpu/cpuX/cpufreq/throttle_stats/occ_reset
284Date: March 2016
285Contact: Linux kernel mailing list <linux-kernel@vger.kernel.org>
286 Linux for PowerPC mailing list <linuxppc-dev@ozlabs.org>
287Description: POWERNV CPUFreq driver's frequency throttle stats directory and
288 attributes
289
290 'cpuX/cpufreq/throttle_stats' directory contains the CPU frequency
291 throttle stat attributes for the chip. The throttle stats of a cpu
292 is common across all the cpus belonging to a chip. Below are the
293 throttle attributes exported in the 'throttle_stats' directory:
294
295 - turbo_stat : This file gives the total number of times the max
296 frequency is throttled to lower frequency in turbo (at and above
297 nominal frequency) range of frequencies.
298
299 - sub_turbo_stat : This file gives the total number of times the
300 max frequency is throttled to lower frequency in sub-turbo(below
301 nominal frequency) range of frequencies.
302
303 - unthrottle : This file gives the total number of times the max
304 frequency is unthrottled after being throttled.
305
306 - powercap : This file gives the total number of times the max
307 frequency is throttled due to 'Power Capping'.
308
309 - overtemp : This file gives the total number of times the max
310 frequency is throttled due to 'CPU Over Temperature'.
311
312 - supply_fault : This file gives the total number of times the
313 max frequency is throttled due to 'Power Supply Failure'.
314
315 - overcurrent : This file gives the total number of times the
316 max frequency is throttled due to 'Overcurrent'.
317
318 - occ_reset : This file gives the total number of times the max
319 frequency is throttled due to 'OCC Reset'.
320
321 The sysfs attributes representing different throttle reasons like
322 powercap, overtemp, supply_fault, overcurrent and occ_reset map to
323 the reasons provided by OCC firmware for throttling the frequency.
324
325What: /sys/devices/system/cpu/cpufreq/policyX/throttle_stats
326 /sys/devices/system/cpu/cpufreq/policyX/throttle_stats/turbo_stat
327 /sys/devices/system/cpu/cpufreq/policyX/throttle_stats/sub_turbo_stat
328 /sys/devices/system/cpu/cpufreq/policyX/throttle_stats/unthrottle
329 /sys/devices/system/cpu/cpufreq/policyX/throttle_stats/powercap
330 /sys/devices/system/cpu/cpufreq/policyX/throttle_stats/overtemp
331 /sys/devices/system/cpu/cpufreq/policyX/throttle_stats/supply_fault
332 /sys/devices/system/cpu/cpufreq/policyX/throttle_stats/overcurrent
333 /sys/devices/system/cpu/cpufreq/policyX/throttle_stats/occ_reset
334Date: March 2016
335Contact: Linux kernel mailing list <linux-kernel@vger.kernel.org>
336 Linux for PowerPC mailing list <linuxppc-dev@ozlabs.org>
337Description: POWERNV CPUFreq driver's frequency throttle stats directory and
338 attributes
339
340 'policyX/throttle_stats' directory and all the attributes are same as
341 the /sys/devices/system/cpu/cpuX/cpufreq/throttle_stats directory and
342 attributes which give the frequency throttle information of the chip.
diff --git a/drivers/cpufreq/powernv-cpufreq.c b/drivers/cpufreq/powernv-cpufreq.c
index a00bcc2cef09..39ac78c94be0 100644
--- a/drivers/cpufreq/powernv-cpufreq.c
+++ b/drivers/cpufreq/powernv-cpufreq.c
@@ -54,6 +54,16 @@ static const char * const throttle_reason[] = {
54 "OCC Reset" 54 "OCC Reset"
55}; 55};
56 56
57enum throttle_reason_type {
58 NO_THROTTLE = 0,
59 POWERCAP,
60 CPU_OVERTEMP,
61 POWER_SUPPLY_FAILURE,
62 OVERCURRENT,
63 OCC_RESET_THROTTLE,
64 OCC_MAX_REASON
65};
66
57static struct chip { 67static struct chip {
58 unsigned int id; 68 unsigned int id;
59 bool throttled; 69 bool throttled;
@@ -61,6 +71,9 @@ static struct chip {
61 u8 throttle_reason; 71 u8 throttle_reason;
62 cpumask_t mask; 72 cpumask_t mask;
63 struct work_struct throttle; 73 struct work_struct throttle;
74 int throttle_turbo;
75 int throttle_sub_turbo;
76 int reason[OCC_MAX_REASON];
64} *chips; 77} *chips;
65 78
66static int nr_chips; 79static int nr_chips;
@@ -196,6 +209,42 @@ static struct freq_attr *powernv_cpu_freq_attr[] = {
196 NULL, 209 NULL,
197}; 210};
198 211
212#define throttle_attr(name, member) \
213static ssize_t name##_show(struct cpufreq_policy *policy, char *buf) \
214{ \
215 struct chip *chip = per_cpu(chip_info, policy->cpu); \
216 \
217 return sprintf(buf, "%u\n", chip->member); \
218} \
219 \
220static struct freq_attr throttle_attr_##name = __ATTR_RO(name) \
221
222throttle_attr(unthrottle, reason[NO_THROTTLE]);
223throttle_attr(powercap, reason[POWERCAP]);
224throttle_attr(overtemp, reason[CPU_OVERTEMP]);
225throttle_attr(supply_fault, reason[POWER_SUPPLY_FAILURE]);
226throttle_attr(overcurrent, reason[OVERCURRENT]);
227throttle_attr(occ_reset, reason[OCC_RESET_THROTTLE]);
228throttle_attr(turbo_stat, throttle_turbo);
229throttle_attr(sub_turbo_stat, throttle_sub_turbo);
230
231static struct attribute *throttle_attrs[] = {
232 &throttle_attr_unthrottle.attr,
233 &throttle_attr_powercap.attr,
234 &throttle_attr_overtemp.attr,
235 &throttle_attr_supply_fault.attr,
236 &throttle_attr_overcurrent.attr,
237 &throttle_attr_occ_reset.attr,
238 &throttle_attr_turbo_stat.attr,
239 &throttle_attr_sub_turbo_stat.attr,
240 NULL,
241};
242
243static const struct attribute_group throttle_attr_grp = {
244 .name = "throttle_stats",
245 .attrs = throttle_attrs,
246};
247
199/* Helper routines */ 248/* Helper routines */
200 249
201/* Access helpers to power mgt SPR */ 250/* Access helpers to power mgt SPR */
@@ -338,10 +387,14 @@ static void powernv_cpufreq_throttle_check(void *data)
338 if (chip->throttled) 387 if (chip->throttled)
339 goto next; 388 goto next;
340 chip->throttled = true; 389 chip->throttled = true;
341 if (pmsr_pmax < powernv_pstate_info.nominal) 390 if (pmsr_pmax < powernv_pstate_info.nominal) {
342 pr_warn_once("CPU %d on Chip %u has Pmax reduced below nominal frequency (%d < %d)\n", 391 pr_warn_once("CPU %d on Chip %u has Pmax reduced below nominal frequency (%d < %d)\n",
343 cpu, chip->id, pmsr_pmax, 392 cpu, chip->id, pmsr_pmax,
344 powernv_pstate_info.nominal); 393 powernv_pstate_info.nominal);
394 chip->throttle_sub_turbo++;
395 } else {
396 chip->throttle_turbo++;
397 }
345 trace_powernv_throttle(chip->id, 398 trace_powernv_throttle(chip->id,
346 throttle_reason[chip->throttle_reason], 399 throttle_reason[chip->throttle_reason],
347 pmsr_pmax); 400 pmsr_pmax);
@@ -408,6 +461,21 @@ static int powernv_cpufreq_cpu_init(struct cpufreq_policy *policy)
408 for (i = 0; i < threads_per_core; i++) 461 for (i = 0; i < threads_per_core; i++)
409 cpumask_set_cpu(base + i, policy->cpus); 462 cpumask_set_cpu(base + i, policy->cpus);
410 463
464 if (!policy->driver_data) {
465 int ret;
466
467 ret = sysfs_create_group(&policy->kobj, &throttle_attr_grp);
468 if (ret) {
469 pr_info("Failed to create throttle stats directory for cpu %d\n",
470 policy->cpu);
471 return ret;
472 }
473 /*
474 * policy->driver_data is used as a flag for one-time
475 * creation of throttle sysfs files.
476 */
477 policy->driver_data = policy;
478 }
411 return cpufreq_table_validate_and_show(policy, powernv_freqs); 479 return cpufreq_table_validate_and_show(policy, powernv_freqs);
412} 480}
413 481
@@ -514,8 +582,10 @@ static int powernv_cpufreq_occ_msg(struct notifier_block *nb,
514 break; 582 break;
515 583
516 if (omsg.throttle_status >= 0 && 584 if (omsg.throttle_status >= 0 &&
517 omsg.throttle_status <= OCC_MAX_THROTTLE_STATUS) 585 omsg.throttle_status <= OCC_MAX_THROTTLE_STATUS) {
518 chips[i].throttle_reason = omsg.throttle_status; 586 chips[i].throttle_reason = omsg.throttle_status;
587 chips[i].reason[omsg.throttle_status]++;
588 }
519 589
520 if (!omsg.throttle_status) 590 if (!omsg.throttle_status)
521 chips[i].restore = true; 591 chips[i].restore = true;