From patchwork Tue Feb 2 19:41:42 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shilpasri G Bhat X-Patchwork-Id: 8195091 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 38FE89F3CD for ; Tue, 2 Feb 2016 19:43:40 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D4A9A202BE for ; Tue, 2 Feb 2016 19:43:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3C63520253 for ; Tue, 2 Feb 2016 19:43:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757630AbcBBTnQ (ORCPT ); Tue, 2 Feb 2016 14:43:16 -0500 Received: from e23smtp01.au.ibm.com ([202.81.31.143]:57992 "EHLO e23smtp01.au.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757622AbcBBTnN (ORCPT ); Tue, 2 Feb 2016 14:43:13 -0500 Received: from localhost by e23smtp01.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 3 Feb 2016 05:43:11 +1000 Received: from d23dlp03.au.ibm.com (202.81.31.214) by e23smtp01.au.ibm.com (202.81.31.207) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 3 Feb 2016 05:43:09 +1000 X-IBM-Helo: d23dlp03.au.ibm.com X-IBM-MailFrom: shilpa.bhat@linux.vnet.ibm.com X-IBM-RcptTo: linux-api@vger.kernel.org; linux-kernel@vger.kernel.org; linux-pm@vger.kernel.org Received: from d23relay07.au.ibm.com (d23relay07.au.ibm.com [9.190.26.37]) by d23dlp03.au.ibm.com (Postfix) with ESMTP id C4D023578052; Wed, 3 Feb 2016 06:43:08 +1100 (EST) Received: from d23av03.au.ibm.com (d23av03.au.ibm.com [9.190.234.97]) by d23relay07.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u12Jh2Fx47710396; Wed, 3 Feb 2016 06:43:10 +1100 Received: from d23av03.au.ibm.com (localhost [127.0.0.1]) by d23av03.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id u12JgZAt024059; Wed, 3 Feb 2016 06:42:36 +1100 Received: from localhost.in.ibm.com ([9.79.187.230]) by d23av03.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id u12Jg1RO022740; Wed, 3 Feb 2016 06:42:32 +1100 From: Shilpasri G Bhat To: linuxppc-dev@ozlabs.org, linux-kernel@vger.kernel.org Cc: rjw@rjwysocki.net, viresh.kumar@linaro.org, linux-pm@vger.kernel.org, pc@us.ibm.com, anton@samba.org, ego@linux.vnet.ibm.com, shreyas@linux.vnet.ibm.com, bsingharora@gmail.com, mpe@ellerman.id.au, Shilpasri G Bhat , linux-api@vger.kernel.org Subject: [PATCH v8 6/6] cpufreq: powernv: Add sysfs attributes to show throttle stats Date: Wed, 3 Feb 2016 01:11:42 +0530 Message-Id: <1454442102-1229-7-git-send-email-shilpa.bhat@linux.vnet.ibm.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1454442102-1229-1-git-send-email-shilpa.bhat@linux.vnet.ibm.com> References: <1454442102-1229-1-git-send-email-shilpa.bhat@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16020219-1618-0000-0000-000003A194EE Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Create sysfs attributes to export throttle information in /sys/devices/system/cpu/cpufreq/chipX. The newly added sysfs files are as follows: 1)/sys/devices/system/cpu/cpufreq/chipX/throttle_table This table gives the detailed information on number of times Pmax is limited to different frequencies due to different throttle reasons. This table contains all frequencies in rows and all throttle reasons in columns. Each cell represents the throttle count the Pmax was limited to the frequency in its row and due to the reason in its column. The 'Unthrottle' column here gives the count of unthrottling back to Pmax after the frequency was throttled. # cat /sys/devices/system/cpu/cpufreq/chip0/throttle_table Frequency Unthrottle PowerCap OverTemp ... 4322000 0 0 0 4289000 0 0 0 4256000 0 0 0 4222000 0 0 0 4189000 0 0 0 4156000 3 0 3 4123000 4 0 4 ... 2)/sys/devices/system/cpu/cpufreq/chipX/throttle_stat This gives the total number of events of max frequency throttling to lower frequencies in the turbo range of frequencies and the sub-turbo(at and below nominal) range of frequencies. # cat /sys/devices/system/cpu/cpufreq/chip0/throttle_stat turbo 7 sub-turbo 0 3)/sys/devices/system/cpu/cpufreq/chipX/chip-mask This gives the list of cpus present in the chip. # cat /sys/devices/system/cpu/cpufreq/chip0/chip_mask 0-31 Signed-off-by: Shilpasri G Bhat Cc: linux-api@vger.kernel.org --- Changes from v7: - Replace throttle_frequencies and throttle_reasons/ sysfs attributes with a 2d table 'throttle_table' which lists the all frequencies in rows and throttle reasons in columns. - Add 'chip_mask' attribute to show the list of cpus in the chip. - Replace the kobject pointer with the variable in struct chip. - Add 'pstate' member to struct chip to store last throttled pstate index. - Fixes in the error-out-paths 'free_*' in init_chip_info() to avoid freeing unallocated pointers. - Explicitly call 'sysfs_remove_group()' while cleaning up before kobject_put() - Replacements with snprintf(), __ATTR_RO() and container_of() - Modified commit message and Documentation. Changes from v6: - Rename struct chip members 'throt_{nominal/turbo}' to throttle_* - Rename sysfs throttle_reason attribute 'throttle_reset' to 'unthrottle_count' - Add sysfs attribute details in Documentation/ABI/testing/sysfs-devices-system-cpu - Add helper routine get_chip_index_from_kobj() for throttle sysfs attribute show() to get chip index from kobject. - Add the chip id in the pr_warn_once No changes from v5. Changes from v4: - Taken care of Gautham's comments to use inline get_chip_index() Changes from v3: - Seperate the patch to contain only the throttle sysfs attribute changes. - Add helper inline function get_chip_index() Changes from v2: - Fixed kbuild test warning. drivers/cpufreq/powernv-cpufreq.c:609:2: warning: ignoring return value of 'kstrtoint', declared with attribute warn_unused_result [-Wunused-result] Changes from v1: - Added a kobject to struct chip - Grouped the throttle reasons under a separate attribute_group and exported each reason as individual file. - Moved the sysfs files from /sys/devices/system/node/nodeN to /sys/devices/system/cpu/cpufreq/chipN - As suggested by Paul Clarke replaced 'Nominal' with 'sub-turbo'. Documentation/ABI/testing/sysfs-devices-system-cpu | 66 +++++++ drivers/cpufreq/powernv-cpufreq.c | 197 +++++++++++++++++++-- 2 files changed, 253 insertions(+), 10 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-devices-system-cpu b/Documentation/ABI/testing/sysfs-devices-system-cpu index b683e8e..84ff57a 100644 --- a/Documentation/ABI/testing/sysfs-devices-system-cpu +++ b/Documentation/ABI/testing/sysfs-devices-system-cpu @@ -271,3 +271,69 @@ Description: Parameters for the CPU cache attributes - WriteBack: data is written only to the cache line and the modified cache line is written to main memory only when it is replaced + +What: /sys/devices/system/cpu/cpufreq/chipX/ +Date: Feb 2016 +Contact: Linux kernel mailing list + Linux for PowerPC mailing list +Description: POWERNV CPUFreq driver's frequency throttle stats directory for + the chip + + This directory contains the CPU frequency throttle attributes + for the chip. It is named using the hardware chip-id in the + format of 'chip'. This directory contains the below + set of attributes: + - throttle_table + - throttle_stats + - chip_mask + +What: /sys/devices/system/cpu/cpufreq/chipX/throttle_table +Date: Feb 2016 +Contact: Linux kernel mailing list + Linux for PowerPC mailing list +Description: POWERNV CPUFreq driver's frequency throttle stats table for the + chip + + This table gives the detailed information on number of times + Pmax is limited to different frequencies due to different + throttle reasons. This table contains all frequencies in rows + and all throttle reasons in columns. Each cell represents the + throttle count the Pmax was limited to the frequency in its row + and due to the reason in its column. The 'Unthrottle' column + here gives the count of unthrottling back to Pmax after the + frequency was throttled. + # cat /sys/devices/system/cpu/cpufreq/chip0/throttle_table + Frequency Unthrottle PowerCap OverTemp ... + 4322000 0 0 0 + 4289000 0 0 0 + 4256000 0 0 0 + 4222000 0 0 0 + 4189000 0 0 0 + 4156000 3 0 3 + 4123000 0 0 0 + ... + +What: /sys/devices/system/cpu/cpufreq/chipX/throttle_stats +Date: Feb 2016 +Contact: Linux kernel mailing list + Linux for PowerPC mailing list +Description: POWERNV CPUFreq driver's overall frequency throttle stats for + the chip + + This attribute gives the total number of events of max + frequency throttling to any lower frequency in the turbo (above + nominal) and the sub-turbo (at and below nominal) range of + frequencies. + # cat /sys/devices/system/cpu/cpufreq/chip0/throttle_stat + turbo 7 + sub-turbo 0 + +What: /sys/devices/system/cpu/cpufreq/chipX/chip_mask +Date: Feb 2016 +Contact: Linux kernel mailing list + Linux for PowerPC mailing list +Description: POWERNV CPUFreq driver's attribute to show cpu mask of the chip + + This attribute gives the list of cpus present in the chip. + # cat /sys/devices/system/cpu/cpufreq/chip0/chip_mask + 0-31 diff --git a/drivers/cpufreq/powernv-cpufreq.c b/drivers/cpufreq/powernv-cpufreq.c index 1bbc10a..0f55e7a 100644 --- a/drivers/cpufreq/powernv-cpufreq.c +++ b/drivers/cpufreq/powernv-cpufreq.c @@ -60,8 +60,13 @@ static struct chip { bool throttled; bool restore; u8 throttle_reason; + s8 pstate; cpumask_t mask; struct work_struct throttle; + int throttle_turbo; + int throttle_nominal; + int *reason[OCC_MAX_THROTTLE_STATUS + 1]; + struct kobject kobj; } *chips; static int nr_chips; @@ -196,6 +201,111 @@ static struct freq_attr *powernv_cpu_freq_attr[] = { NULL, }; +static inline int get_chip_index(unsigned int id) +{ + int i; + + for (i = 0; i < nr_chips; i++) + if (chips[i].id == id) + return i; + + return -EINVAL; +} + +static inline int get_chip_index_from_kobj(struct kobject *kobj) +{ + int ret; + struct chip *chip; + + chip = container_of(kobj, struct chip, kobj); + + ret = get_chip_index(chip->id); + if (ret < 0) + pr_warn_once("%s Matching chip-id not found %d\n", __func__, + chip->id); + return ret; +} + +static const char * const column_str[] = { + "Frequency", + "Unthrottle", + "PowerCap", + "OverTemp", + "PowerFault", + "OverCurrent", + "OCCReset" +}; + +static ssize_t throttle_table_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + int id, count = 0, i, j; + + id = get_chip_index_from_kobj(kobj); + if (id < 0) + return id; + + for (i = 0; i < ARRAY_SIZE(column_str); i++) + count += sprintf(&buf[count], "%s\t", column_str[i]); + count += sprintf(&buf[count], "\n"); + + for (i = 0; i < powernv_pstate_info.nr_pstates; i++) { + count += sprintf(&buf[count], "%d\t\t", + powernv_freqs[i].frequency); + for (j = 0; j <= OCC_MAX_THROTTLE_STATUS; j++) + count += sprintf(&buf[count], "%d\t\t", + chips[id].reason[j][i]); + count += sprintf(&buf[count], "\n"); + } + + return count; +} + +static struct kobj_attribute attr_throttle_table = __ATTR_RO(throttle_table); + +static ssize_t throttle_stat_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + int id, count = 0; + + id = get_chip_index_from_kobj(kobj); + if (id < 0) + return id; + + count += sprintf(&buf[count], "turbo %d\n", chips[id].throttle_turbo); + count += sprintf(&buf[count], "sub-turbo %d\n", + chips[id].throttle_nominal); + + return count; +} + +static struct kobj_attribute attr_throttle_stat = __ATTR_RO(throttle_stat); + +static ssize_t chip_mask_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + int id; + + id = get_chip_index_from_kobj(kobj); + if (id < 0) + return id; + + return cpumap_print_to_pagebuf(true, buf, &chips[id].mask); +} + +static struct kobj_attribute attr_chip_mask = __ATTR_RO(chip_mask); + +static struct attribute *throttle_stat_attrs[] = { + &attr_throttle_stat.attr, + &attr_throttle_table.attr, + &attr_chip_mask.attr, + NULL +}; + +static const struct attribute_group throttle_stat_group = { + .attrs = throttle_stat_attrs, +}; + /* Helper routines */ /* Access helpers to power mgt SPR */ @@ -327,13 +437,16 @@ static void powernv_cpufreq_throttle_check(void *data) unsigned int cpu = smp_processor_id(); unsigned int chip_id = core_to_chip_map[cpu_core_index_of_thread(cpu)]; unsigned long pmsr; - int pmsr_pmax, i; + int pmsr_pmax, i, index; pmsr = get_pmspr(SPRN_PMSR); - for (i = 0; i < nr_chips; i++) - if (chips[i].id == chip_id) - break; + i = get_chip_index(chip_id); + if (unlikely(i < 0)) { + pr_warn_once("%s Matching chip-id not found %d\n", __func__, + chip_id); + return; + } /* Check for Pmax Capping */ pmsr_pmax = (s8)PMSR_MAX(pmsr); @@ -341,15 +454,27 @@ static void powernv_cpufreq_throttle_check(void *data) if (chips[i].throttled) goto next; chips[i].throttled = true; - if (pmsr_pmax < powernv_pstate_info.nominal) + if (pmsr_pmax < powernv_pstate_info.nominal) { pr_warn_once("CPU %d on Chip %u has Pmax reduced below nominal frequency (%d < %d)\n", cpu, chips[i].id, pmsr_pmax, powernv_pstate_info.nominal); + chips[i].throttle_nominal++; + } else { + chips[i].throttle_turbo++; + } + + index = powernv_pstate_info.max - pmsr_pmax; + if (index >= 0 && index < powernv_pstate_info.nr_pstates) { + chips[i].reason[chips[i].throttle_reason][index]++; + chips[i].pstate = index; + } + trace_powernv_throttle(chips[i].id, throttle_reason[chips[i].throttle_reason], pmsr_pmax); } else if (chips[i].throttled) { chips[i].throttled = false; + chips[i].reason[chips[i].throttle_reason][chips[i].pstate]++; trace_powernv_throttle(chips[i].id, throttle_reason[chips[i].throttle_reason], pmsr_pmax); @@ -512,9 +637,12 @@ static int powernv_cpufreq_occ_msg(struct notifier_block *nb, return 0; } - for (i = 0; i < nr_chips; i++) - if (chips[i].id == omsg.chip) - break; + i = get_chip_index(omsg.chip); + if (i < 0) { + pr_warn_once("%s Matching chip-id not found %d\n", + __func__, (int)omsg.chip); + return i; + } if (omsg.throttle_status >= 0 && omsg.throttle_status <= OCC_MAX_THROTTLE_STATUS) @@ -556,10 +684,10 @@ static struct cpufreq_driver powernv_cpufreq_driver = { static int init_chip_info(void) { unsigned int chip[256]; - unsigned int cpu, i; + unsigned int cpu; unsigned int prev_chip_id = UINT_MAX; cpumask_t cpu_mask; - int ret = -ENOMEM; + int i, j, ret = -ENOMEM; core_to_chip_map = kcalloc(cpu_nr_cores(), sizeof(unsigned int), GFP_KERNEL); @@ -583,12 +711,51 @@ static int init_chip_info(void) goto free_chip_map; for (i = 0; i < nr_chips; i++) { + char name[10]; + chips[i].id = chip[i]; cpumask_copy(&chips[i].mask, cpumask_of_node(chip[i])); INIT_WORK(&chips[i].throttle, powernv_cpufreq_work_fn); + + for (j = 0; j <= OCC_MAX_THROTTLE_STATUS; j++) { + chips[i].reason[j] = + kcalloc(powernv_pstate_info.nr_pstates, + sizeof(int), GFP_KERNEL); + if (!chips[i].reason[j]) { + ret = -ENOMEM; + goto free_chip; + } + } + + snprintf(name, sizeof(name), "chip%d", chips[i].id); + ret = kobject_init_and_add(&chips[i].kobj, + get_ktype(cpufreq_global_kobject), + cpufreq_global_kobject, name); + if (ret) + goto free_chip; + + ret = sysfs_create_group(&chips[i].kobj, &throttle_stat_group); + if (ret) { + pr_info("Chip %d failed to create throttle sysfs group\n", + chips[i].id); + goto free_kobject; + } } return 0; + +free_kobject: + kobject_put(&chips[i].kobj); +free_chip: + while (--j >= 0) + kfree(chips[i].reason[j]); + while (--i >= 0) { + sysfs_remove_group(&chips[i].kobj, &throttle_stat_group); + kobject_put(&chips[i].kobj); + for (j = 0; j <= OCC_MAX_THROTTLE_STATUS; j++) + kfree(chips[i].reason[j]); + } + kfree(chips); free_chip_map: kfree(core_to_chip_map); out: @@ -623,9 +790,19 @@ module_init(powernv_cpufreq_init); static void __exit powernv_cpufreq_exit(void) { + int i, j; + unregister_reboot_notifier(&powernv_cpufreq_reboot_nb); opal_message_notifier_unregister(OPAL_MSG_OCC, &powernv_cpufreq_opal_nb); + + for (i = 0; i < nr_chips; i++) { + sysfs_remove_group(&chips[i].kobj, &throttle_stat_group); + kobject_put(&chips[i].kobj); + for (j = 0; j <= OCC_MAX_THROTTLE_STATUS; j++) + kfree(chips[i].reason[j]); + } + kfree(chips); kfree(core_to_chip_map); cpufreq_unregister_driver(&powernv_cpufreq_driver);