Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E9D3BC636CD for ; Fri, 10 Feb 2023 16:10:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232803AbjBJQKL (ORCPT ); Fri, 10 Feb 2023 11:10:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34260 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232178AbjBJQKJ (ORCPT ); Fri, 10 Feb 2023 11:10:09 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D5F137359C for ; Fri, 10 Feb 2023 08:10:07 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 5EA6C61E2A for ; Fri, 10 Feb 2023 16:10:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5EC10C433D2; Fri, 10 Feb 2023 16:10:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676045406; bh=FWLH5hJ90+zRd86i34u4anxkiyVYs4VM7+qCpFJ6rXQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=AEeQAZI8Vjuwskrtje5UuG24T+Ee2sWUc2aZCnQg+a/wDlZmDumsArZAAzOYaq5i8 YxV3IvHlEyyc50LQpH353wmgV4qEg3dZGXOEKyP5TiH5gHZBtrLYkwjPzSFrEH+ALa GMcgkL0+CocoI7OpBzBtoRhlO0qIoq5mPMA/RVsOL7+W8s4/lm/yRArvlngID8irvU 0ZaG9owYmMBwCiOTusPEebbkLsfA/z/cKg3V72g+0CO3tbXWiwwfISjjhO0Bb/HrZz npNaJ2XSAXgkz+8V8QjMVUF82Es2iWaQhDoTBm7zbH6S3qzAzRJY2WbXCz/cOdXEEx UuE1jmQA4YDeQ== Date: Fri, 10 Feb 2023 17:10:03 +0100 From: Frederic Weisbecker To: Peter Zijlstra Cc: LKML , Alexey Dobriyan , Wei Li , Mirsad Goran Todorovac , Thomas Gleixner , Yu Liao , Hillf Danton , Ingo Molnar Subject: Re: [PATCH 4/6] timers/nohz: Add a comment about broken iowait counter update race Message-ID: References: <20230210140917.279062-1-frederic@kernel.org> <20230210140917.279062-5-frederic@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Feb 10, 2023 at 03:39:43PM +0100, Peter Zijlstra wrote: > On Fri, Feb 10, 2023 at 03:09:15PM +0100, Frederic Weisbecker wrote: > > The per-cpu iowait task counter is incremented locally upon sleeping. > > But since the task can be woken to (and by) another CPU, the counter may > > then be decremented remotely. This is the source of a race involving > > readers VS writer of idle/iowait sleeptime. > > > > 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. > > > > This is unfortunately hardly fixable. Just add a comment about that > > condition. > > It is far worse than that, the whole concept of per-cpu iowait is > absurd. Also see the comment near nr_iowait(). Alas I know :-(