Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp444116pxk; Wed, 9 Sep 2020 09:19:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwH/2V+yYyMuLR72Wa7hBMxmtFce1Z4nj0sL56x15RdcGqTQnMKUinrSAfl5JErrBj4aHLQ X-Received: by 2002:aa7:cf0e:: with SMTP id a14mr4954868edy.81.1599668382638; Wed, 09 Sep 2020 09:19:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599668382; cv=none; d=google.com; s=arc-20160816; b=FKH+c2lvkdvQQsE/GFOMW3DbZZ2ADuzon9ZMJpDZyWyRWkSfA1LZRwx6ir7MJPnZnH D1sUVmW1b+B8ikT1eY8qeHy2URcKOUVwbgYXi+dee/KI3RTk8X6NzS02tz7aM7O96NW8 n/WN9Qnu9JF3pADQP9QslJFDWda0anyv2ZeEnHULIBjUWbSpRWtMJYwJLXtGsvITqptZ OBeRjx4xdQepM4Q628wwDZyG69gNEVy/g6RvtX8/8/4G1nE38O9fVYd8UJlfX7KOiAzn FC7aR0gPWgDdPk19pnVWySjcIxowHbNZnXMh5jB46bHwro2opW2gw+TUDCcswB79QB92 vuog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=6ULPP3Gb9cEI6JekEdlEIOYKhWs71LEp2bfdfN7zhRs=; b=bimHzeke6RyYm4k4kuMAahX8jDBjD3l7ee65pTuC/9luYW0+5cDNdIF/BZ6ZsU0LxV 5w2Bz50PahV1KKCIXAzRPd2xERIrnJHdzK/ry3fte0ceZXeStDDj0Py/chB1vZaFRef5 LEf879zKX/NsBMoVQUpsjkybzGmbz96EqF74nTAWk3ZU7nKLt90P6ZO1zBVpiXinhWPQ keBYgLzL/piO4PKxjlEMgqB7fnzIZK8QL07qH/R9H9d4qfxyYJrJjxESkXkqfVvGLLHz us4Ly77N7fcnA578oI9ZDtWV6/aJJtVNDAsoBTghSCbMdv1g1kCy6jvjuJjb2M3RsCfI dh/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2020-01-29 header.b=yTOeDS0w; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n13si1689995eju.705.2020.09.09.09.19.18; Wed, 09 Sep 2020 09:19:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2020-01-29 header.b=yTOeDS0w; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730802AbgIIQSh (ORCPT + 99 others); Wed, 9 Sep 2020 12:18:37 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:46348 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730950AbgIIQPT (ORCPT ); Wed, 9 Sep 2020 12:15:19 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 089EcaZO039982; Wed, 9 Sep 2020 14:43:32 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=corp-2020-01-29; bh=6ULPP3Gb9cEI6JekEdlEIOYKhWs71LEp2bfdfN7zhRs=; b=yTOeDS0wHSkYYU8WFkoIh5Ce9ZZOxElSYphhkwTfRfseKTRFiGQy0361GiDxIjsNLECN NB2W+blqs9WmJI80WNRon39lhU7mS+KCMm6Owh48l2DXLYAtJqLSj5+1FeBS/LBGwWhi /AgtY8a5hK3ebeqeTIvrJhQrcVWKV2m1VZHB5PZUxaJJtGMaa703FemfNLRIYrY9sZg7 HVls44NA6J8YeIvurcGQrIWlU7FIacnPJOYMsKVv097yhRQzWvYrh14R/DmKZh3gGD58 VpzDfGNJRENM+JkFXVCN8JlABBsrlglZG8i5fA0t+kcGcdiBDWwHabzjkTDAhUqVyes/ Pw== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2120.oracle.com with ESMTP id 33c2mm27me-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 09 Sep 2020 14:43:32 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 089Ef5Tp033108; Wed, 9 Sep 2020 14:41:32 GMT Received: from pps.reinject (localhost [127.0.0.1]) by aserp3020.oracle.com with ESMTP id 33cmk6prwy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 09 Sep 2020 14:41:32 +0000 Received: from aserp3020.oracle.com (aserp3020.oracle.com [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 089EfUC8034192; Wed, 9 Sep 2020 14:41:32 GMT Received: from localhost.localdomain (dhcp-10-65-175-55.vpn.oracle.com [10.65.175.55]) by aserp3020.oracle.com with ESMTP id 33cmk6pru6-3; Wed, 09 Sep 2020 14:41:31 +0000 From: Tom Hromatka To: tom.hromatka@oracle.com, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, fweisbec@gmail.com, tglx@linutronix.de, mingo@kernel.org, adobriyan@gmail.com Subject: [RESEND PATCH 2/2] /proc/stat: Simplify iowait and idle calculations when cpu is offline Date: Wed, 9 Sep 2020 08:41:22 -0600 Message-Id: <20200909144122.77210-3-tom.hromatka@oracle.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20200909144122.77210-1-tom.hromatka@oracle.com> References: <20200909144122.77210-1-tom.hromatka@oracle.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9738 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 priorityscore=1501 phishscore=0 adultscore=0 bulkscore=0 clxscore=1015 mlxlogscore=999 malwarescore=0 suspectscore=0 lowpriorityscore=0 spamscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009090132 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org A customer reported that when a cpu goes offline, the iowait and idle times reported in /proc/stat will sometimes spike. This is being caused by a different data source being used for these values when a cpu is offline. Prior to this patch: put the system under heavy load so that there is little idle time user nice system idle iowait cpu 109515 17 32111 220686 607 take cpu1 offline user nice system idle iowait cpu 113742 17 32721 220724 612 bring cpu1 back online user nice system idle iowait cpu 118332 17 33430 220687 607 To prevent this, let's use the same data source whether a cpu is online or not. With this patch: put the system under heavy load so that there is little idle time user nice system idle iowait cpu 14096 16 4646 157687 426 take cpu1 offline user nice system idle iowait cpu 21614 16 7179 157687 426 bring cpu1 back online user nice system idle iowait cpu 27362 16 9555 157688 426 Signed-off-by: Tom Hromatka --- fs/proc/stat.c | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/fs/proc/stat.c b/fs/proc/stat.c index 46b3293015fe..35b92539e711 100644 --- a/fs/proc/stat.c +++ b/fs/proc/stat.c @@ -47,32 +47,20 @@ static u64 get_iowait_time(struct kernel_cpustat *kcs, int cpu) static u64 get_idle_time(struct kernel_cpustat *kcs, int cpu) { - u64 idle, idle_usecs = -1ULL; + u64 idle, idle_usecs; - if (cpu_online(cpu)) - idle_usecs = get_cpu_idle_time_us(cpu, NULL); - - if (idle_usecs == -1ULL) - /* !NO_HZ or cpu offline so we can rely on cpustat.idle */ - idle = kcs->cpustat[CPUTIME_IDLE]; - else - idle = idle_usecs * NSEC_PER_USEC; + idle_usecs = get_cpu_idle_time_us(cpu, NULL); + idle = idle_usecs * NSEC_PER_USEC; return idle; } static u64 get_iowait_time(struct kernel_cpustat *kcs, int cpu) { - u64 iowait, iowait_usecs = -1ULL; - - if (cpu_online(cpu)) - iowait_usecs = get_cpu_iowait_time_us(cpu, NULL); + u64 iowait, iowait_usecs; - if (iowait_usecs == -1ULL) - /* !NO_HZ or cpu offline so we can rely on cpustat.iowait */ - iowait = kcs->cpustat[CPUTIME_IOWAIT]; - else - iowait = iowait_usecs * NSEC_PER_USEC; + iowait_usecs = get_cpu_iowait_time_us(cpu, NULL); + iowait = iowait_usecs * NSEC_PER_USEC; return iowait; } -- 2.25.4