Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp5435952ybc; Wed, 27 Nov 2019 04:05:45 -0800 (PST) X-Google-Smtp-Source: APXvYqxmPiwWg+iIdJjInLNEG8g9C6xAJ+Zf9a/2ypLmIA4UT/l6FHN0jruKsS5QnwnIPONpH0Nz X-Received: by 2002:a17:906:c41:: with SMTP id t1mr48091361ejf.282.1574856345569; Wed, 27 Nov 2019 04:05:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574856345; cv=none; d=google.com; s=arc-20160816; b=AW3TL/6qrhuQyt85yKaSG1dxbEJF2FOGWczerf2p/n8BVgC6P7l85t+IDufKCKdB/z d5auhcs0ljDTkUcNOk0iGSIE4l2dhomXIaO0VqJId7l7GjC9noCRMWADIFjfvFEFt/2H iNZt5+Cb2fkzKGVy7k6XgwzP29RZdpN/JE6RD1w8hNn4kN8Mtt/fYyU8BiunR2thPzwG mR1aOajlxO/qPS5vvxwBWt+jQfR8xbfMVn2GLDvf+HyQmXzkMtST6bSO1aTnLdRmwc/N eTHtUV1sIwEsGC4FM3DBtyK85ZyXkG3RGQVk+3ZGPKnvg9C0OgVOQHqgNXTpV5lgJ7od KJjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=JY/H52fF73+AHMTnZL3gJ27FmJVcDIcoFW176va4AAo=; b=KtmU8hOv/kEialOpV4L8+Xzies+3TwqSgAxsREvKt1YxG4HvUs7TAMae9FcuQGmIDD 7oYOin8diK69OrnfdDOe43AGgajGExrYbANyiHwaQI7bj+e29gDYUJopiGoGmweBnXRj diSUY89+l7Vhpjf9ytycQvxGtVdom56aK5Y5nuOs/IZjalPd6B++iD9/xDSbuXY/CwyE cCjw98DrZFf+LvL/cHszPKscP6jqze4NfKUaQCfUf5qJeTiMo8HY2UYRtcuHyZYHxkLJ Ap6P4DQnh6z0gotaSmgH8sWuiCIeZbBhnubEk9Peym4ZkYIn+OBRNsU7ndU1OKk5xOy+ l0/Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p6si9570447eds.70.2019.11.27.04.05.21; Wed, 27 Nov 2019 04:05:45 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726957AbfK0MBu (ORCPT + 99 others); Wed, 27 Nov 2019 07:01:50 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:35746 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726719AbfK0MBu (ORCPT ); Wed, 27 Nov 2019 07:01:50 -0500 Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id xARBqHYq087518; Wed, 27 Nov 2019 07:01:40 -0500 Received: from ppma01dal.us.ibm.com (83.d6.3fa9.ip4.static.sl-reverse.com [169.63.214.131]) by mx0a-001b2d01.pphosted.com with ESMTP id 2whhyfeu7s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 27 Nov 2019 07:01:40 -0500 Received: from pps.filterd (ppma01dal.us.ibm.com [127.0.0.1]) by ppma01dal.us.ibm.com (8.16.0.27/8.16.0.27) with SMTP id xARC07Qx021008; Wed, 27 Nov 2019 12:01:39 GMT Received: from b01cxnp23032.gho.pok.ibm.com (b01cxnp23032.gho.pok.ibm.com [9.57.198.27]) by ppma01dal.us.ibm.com with ESMTP id 2wevd6wfer-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 27 Nov 2019 12:01:39 +0000 Received: from b01ledav005.gho.pok.ibm.com (b01ledav005.gho.pok.ibm.com [9.57.199.110]) by b01cxnp23032.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id xARC1bwS46530910 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 27 Nov 2019 12:01:37 GMT Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CB43FAE066; Wed, 27 Nov 2019 12:01:37 +0000 (GMT) Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8BB6DAE06A; Wed, 27 Nov 2019 12:01:37 +0000 (GMT) Received: from sofia.ibm.com (unknown [9.124.35.209]) by b01ledav005.gho.pok.ibm.com (Postfix) with ESMTP; Wed, 27 Nov 2019 12:01:37 +0000 (GMT) Received: by sofia.ibm.com (Postfix, from userid 1000) id 84CFF2E2F8D; Wed, 27 Nov 2019 17:31:35 +0530 (IST) From: "Gautham R. Shenoy" To: Michael Ellerman , Vaidyanathan Srinivasan , Nathan Lynch , Kamalesh Babulal , "Naveen N. Rao" , Tyrel Datwyler Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, "Gautham R. Shenoy" Subject: [PATCH 2/3] powerpc/sysfs: Show idle_purr and idle_spurr for every CPU Date: Wed, 27 Nov 2019 17:31:11 +0530 Message-Id: <1574856072-30972-3-git-send-email-ego@linux.vnet.ibm.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1574856072-30972-1-git-send-email-ego@linux.vnet.ibm.com> References: <1574856072-30972-1-git-send-email-ego@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.95,18.0.572 definitions=2019-11-27_02:2019-11-27,2019-11-27 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 suspectscore=0 clxscore=1015 priorityscore=1501 lowpriorityscore=0 bulkscore=0 phishscore=0 impostorscore=0 mlxlogscore=999 spamscore=0 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-1910280000 definitions=main-1911270104 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Gautham R. Shenoy" On Pseries LPARs, to calculate utilization, we need to know the [S]PURR ticks when the CPUs were busy or idle. The total PURR and SPURR ticks are already exposed via the per-cpu sysfs files /sys/devices/system/cpu/cpuX/purr and /sys/devices/system/cpu/cpuX/spurr. This patch adds support for exposing the idle PURR and SPURR ticks via /sys/devices/system/cpu/cpuX/idle_purr and /sys/devices/system/cpu/cpuX/idle_spurr. Signed-off-by: Gautham R. Shenoy --- arch/powerpc/kernel/sysfs.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/arch/powerpc/kernel/sysfs.c b/arch/powerpc/kernel/sysfs.c index 80a676d..42ade55 100644 --- a/arch/powerpc/kernel/sysfs.c +++ b/arch/powerpc/kernel/sysfs.c @@ -1044,6 +1044,36 @@ static ssize_t show_physical_id(struct device *dev, } static DEVICE_ATTR(physical_id, 0444, show_physical_id, NULL); +static ssize_t idle_purr_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct cpu *cpu = container_of(dev, struct cpu, dev); + unsigned int cpuid = cpu->dev.id; + struct lppaca *cpu_lppaca_ptr = paca_ptrs[cpuid]->lppaca_ptr; + u64 idle_purr_cycles = be64_to_cpu(cpu_lppaca_ptr->wait_state_cycles); + + return sprintf(buf, "%llx\n", idle_purr_cycles); +} +static DEVICE_ATTR_RO(idle_purr); + +DECLARE_PER_CPU(u64, idle_spurr_cycles); +static ssize_t idle_spurr_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct cpu *cpu = container_of(dev, struct cpu, dev); + unsigned int cpuid = cpu->dev.id; + u64 *idle_spurr_cycles_ptr = per_cpu_ptr(&idle_spurr_cycles, cpuid); + + return sprintf(buf, "%llx\n", *idle_spurr_cycles_ptr); +} +static DEVICE_ATTR_RO(idle_spurr); + +static void create_idle_purr_spurr_sysfs_entry(struct device *cpudev) +{ + device_create_file(cpudev, &dev_attr_idle_purr); + device_create_file(cpudev, &dev_attr_idle_spurr); +} + static int __init topology_init(void) { int cpu, r; @@ -1067,6 +1097,8 @@ static int __init topology_init(void) register_cpu(c, cpu); device_create_file(&c->dev, &dev_attr_physical_id); + if (firmware_has_feature(FW_FEATURE_SPLPAR)) + create_idle_purr_spurr_sysfs_entry(&c->dev); } } r = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "powerpc/topology:online", -- 1.9.4