From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3177C284B4F for ; Tue, 25 Nov 2025 09:37:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.31.5 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764063481; cv=none; b=U2SrApLdQeI45D/9r5D8ppqdJucLwRSZKLpqMaoI5oECFa3obUt8BsiWGW3Jj60ENyDf3Hl8na+9LlVhTRCwz432VfJGpJpCiNKGZh7nZ/7dir06mBVQEdv5FiHq2URKpPgBsOPP9dXQcdfEZ17RpWguL14+TmlePsNIzllqXRw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764063481; c=relaxed/simple; bh=0nE07o5DTR0D1Hm+Ee4rob9reM5+GgEne7Z56priezc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=fAAkVrl7vbpij2Z21M0OKzGqclSBnxa/2iYBZaCEouy0Uf+OrFluEgzInpBd9BwI9K2/kM1LMYM/nbVgtGW8EKzYakJwU09q9eH/zv/ZI1tdoo12FKkfK4jyZe8pR077JILyI+xLJsv9+52QsGfWGFoAGOm1ZJUh68moF9E245Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=cMJ1/Qqy; arc=none smtp.client-ip=220.197.31.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="cMJ1/Qqy" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-Id:MIME-Version: Content-Type; bh=0JHn+kPpvX4T+T3LlFaAp1rcfcXNY7HyaVAN00ems5A=; b=cMJ1/QqyVbYSEOHtcfaspYAF3bhsh70sl9XxG7DVV9i7obbJFhuhBNDLZKWppw G3dAcMQtxV9mxG0ebxQ5vsyVaPB9Vbul7CO/CBr23uIyL95QOg0a1OG9iZgqPp04 LvP9sCmSBHgWeJTwyq8FtzF4hnFfVusa7MWvO8ShHquJg= Received: from zhaoxin-MS-7E12.. (unknown []) by gzga-smtp-mtada-g0-2 (Coremail) with SMTP id _____wDnRwqteCVpLAy6CA--.236S2; Tue, 25 Nov 2025 17:36:46 +0800 (CST) From: Xin Zhao To: frederic@kernel.org Cc: adobriyan@gmail.com, hdanton@sina.com, liaoyu15@huawei.com, linux-kernel@vger.kernel.org, liwei391@huawei.com, mingo@kernel.org, mirsad.todorovac@alu.unizg.hr, peterz@infradead.org, tglx@linutronix.de Subject: Re: [PATCH 4/8] timers/nohz: Add a comment about broken iowait counter update race Date: Tue, 25 Nov 2025 17:36:44 +0800 Message-Id: <20251125093644.1786359-1-jackzxcui1989@163.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230222144649.624380-5-frederic@kernel.org> References: <20230222144649.624380-5-frederic@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=y Content-Transfer-Encoding: 8bit X-CM-TRANSID:_____wDnRwqteCVpLAy6CA--.236S2 X-Coremail-Antispam: 1Uf129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7v73 VFW2AGmfu7bjvjm3AaLaJ3UbIYCTnIWIevJa73UjIFyTuYvjxUo18BUUUUU X-CM-SenderInfo: pmdfy650fxxiqzyzqiywtou0bp/1tbibgIQCmkkfTNJEgACss On Wed, 22 Feb 2023 15:46:45 +0100 Frederic Weisbecker wrote: > The following scenario shows an example where a /proc/stat reader > observes a pending sleep time as IO whereas that pending sleep time > later eventually gets accounted as non-IO. > > CPU 0 CPU 1 CPU 2 > ----- ----- ------ > //io_schedule() TASK A > current->in_iowait = 1 > rq(0)->nr_iowait++ > //switch to idle > // READ /proc/stat > // See nr_iowait_cpu(0) == 1 > return ts->iowait_sleeptime + > ktime_sub(ktime_get(), ts->idle_entrytime) > > //try_to_wake_up(TASK A) > rq(0)->nr_iowait-- > //idle exit > // See nr_iowait_cpu(0) == 0 > ts->idle_sleeptime += ktime_sub(ktime_get(), ts->idle_entrytime) > > As a result subsequent reads on /proc/stat may expose backward progress. ... > * > * Return the cumulative idle time (since boot) for a given > - * CPU, in microseconds. > + * CPU, in microseconds. Note this is partially broken due to > + * the counter of iowait tasks that can be remotely updated without > + * any synchronization. Therefore it is possible to observe backward > + * values within two consecutive reads. > * > * This time is measured via accounting rather than sampling, > * and is as accurate as ktime_get() is. Dear Frederic, I indeed encountered the situation in our project where both the iowait and idle statistics decreased during the updates. We encountered this scenario while testing the standby wake-up. I looked at the illustration you provided above and could understand well how the iowait statistics could decrease, but I just can't figure out why the idle statistics would also decrease. I believe that the iowait statistics for the rq only increase when the prev task is scheduled out, so the increase should only occur on the local CPU. The remote CPU only decreases the rq's iowait statistics when waking up. I haven’t found any situation where a remote CPU could cause an increase in the rq's iowait statistics. Therefore, I understand that there shouldn't be a decrease in the idle statistics between two updates. I truly cannot comprehend what could have caused this. Could you provide some hints? It would be even better if it relates to another illustration like above. Thank you very much! Xin Zhao