From patchwork Wed Feb 22 14:46:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Weisbecker X-Patchwork-Id: 60562 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp618014wrd; Wed, 22 Feb 2023 06:51:52 -0800 (PST) X-Google-Smtp-Source: AK7set8YnblpSoR0QEqvZLp1qVE/HeU2iNXPv9WpcxQw+OLw6TnJc0e4RrBgs5ULmx4e1ik/dA9f X-Received: by 2002:a05:6402:1157:b0:4ad:7c41:d0f4 with SMTP id g23-20020a056402115700b004ad7c41d0f4mr7594366edw.4.1677077512347; Wed, 22 Feb 2023 06:51:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677077512; cv=none; d=google.com; s=arc-20160816; b=IBZ7EYBlW97lKgt32xmuFnSlNxpym4MyJNePHMYAB4POVAxPZ21kEH2l6EyW1oaFGC dOBkp5lrcYI234mFlvLfPUrTioj6wshsZjePsK27dCCbOX7PkudyWan2kWC4jDiz1vNl gG+mJeNWnWhJAfNA+YlpqF/VjskFywkym3JL6CAms4MDj+oECKZb1+ZLEtDXYt3Hmgk6 3y7vmNe5JBgoK6KDBqzzF6DCkMqdLDk0pDn1ezdJo1yaI5AO702NMSTo55mfoaXbk8uq GqH0r5N6ZxuLxAAvinXyMtUaBIqr4Rn04TXOOW7FP4E/B7OTBH7FoDUBGSad/YP3ei2w niyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=AmMujhepPCnVmhISMOLGbh98uquvIrQ+3htR61BoVSI=; b=HALc/v15PHKV6BWo2i+PVI1pydeR7JCnQSEcKbsQTquQQ/5rcOiIV4cke4xCHCRnHZ iux2BtXORlfDmiuhFil/jhDR9IWfujvJiew9Bm/Nsn5QtPX4dRwFiFaefatnCLownRmj QBupbavEnEKdxd3ymp0X3XB0qAPP32wV4VrqXQlMX92WB9HXzfn6TjaFc+Y35COLvxdZ IKfSwvzdK4MC6tMnBATDzgprBdO9FfZfDcMEotcb+bBZbtALQTODUqa7h0B4peTwOXKA Qk9T25+YoEmjubd6f6XMoByrtcMYFlCKv1HiBDTrBc9SwtpmiCvl3+rHD5VXoD7vMi2r UmIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Z5Oy+8JB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l11-20020aa7c3cb000000b004acccbad706si8567140edr.194.2023.02.22.06.51.27; Wed, 22 Feb 2023 06:51:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Z5Oy+8JB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232274AbjBVOro (ORCPT + 99 others); Wed, 22 Feb 2023 09:47:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232216AbjBVOre (ORCPT ); Wed, 22 Feb 2023 09:47:34 -0500 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D17A938E80 for ; Wed, 22 Feb 2023 06:47:16 -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 sin.source.kernel.org (Postfix) with ESMTPS id D07D8CE1DDE for ; Wed, 22 Feb 2023 14:47:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DA38CC433D2; Wed, 22 Feb 2023 14:46:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1677077219; bh=i0suEjF1OVttZE4v7oGGN5lbF5fnEyMlbmcS3axNMpQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Z5Oy+8JBnQ3KrQ1WgxmB3G+kQ2Y6XPmfVa9zlkxOvp3QAq/WCcKocc7sjnmbc8B3k +khwBCnBJdm3akmYQFadw/1DzXGAwLiQtC/qoljoKBPsFOfe8/ND0ia7HReSer0+k4 Gsn/HLGMxQI0/k7aqeLmW1f2RTrTbwa7ORJ3QM6TL4sskFilRwRdYyo7EhdYH6MYmS puc7pu/xTxbTrPQQsfSW3aBx+ug28InqceUeXhHH4InCIa0HcdN6zdvPxFc40wlM8H 0H4MMEew3ljsRgT1V22HOodaHm8KCkWJip4gvKy5tMbYyaNeKNiBCkQTzRa2vTfIip LsDHF+CUO6qOg== From: Frederic Weisbecker To: Thomas Gleixner Cc: LKML , Frederic Weisbecker , Alexey Dobriyan , Wei Li , Peter Zijlstra , Mirsad Goran Todorovac , Yu Liao , Hillf Danton , Ingo Molnar Subject: [PATCH 1/8] timers/nohz: Restructure and reshuffle struct tick_sched Date: Wed, 22 Feb 2023 15:46:42 +0100 Message-Id: <20230222144649.624380-2-frederic@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230222144649.624380-1-frederic@kernel.org> References: <20230222144649.624380-1-frederic@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758543229960177907?= X-GMAIL-MSGID: =?utf-8?q?1758543229960177907?= Restructure and group fields by access in order to optimize cache layout. While at it, also add missing kernel doc for two fields: @last_jiffies and @idle_expires. Reported-by: Thomas Gleixner Acked-by: Peter Zijlstra (Intel) Cc: Hillf Danton Cc: Yu Liao Cc: Ingo Molnar Cc: Wei Li Cc: Alexey Dobriyan Cc: Mirsad Goran Todorovac Signed-off-by: Frederic Weisbecker --- kernel/time/tick-sched.h | 66 +++++++++++++++++++++++++--------------- 1 file changed, 41 insertions(+), 25 deletions(-) diff --git a/kernel/time/tick-sched.h b/kernel/time/tick-sched.h index 504649513399..c6663254d17d 100644 --- a/kernel/time/tick-sched.h +++ b/kernel/time/tick-sched.h @@ -22,65 +22,81 @@ enum tick_nohz_mode { /** * struct tick_sched - sched tick emulation and no idle tick control/stats - * @sched_timer: hrtimer to schedule the periodic tick in high - * resolution mode - * @check_clocks: Notification mechanism about clocksource changes - * @nohz_mode: Mode - one state of tick_nohz_mode + * * @inidle: Indicator that the CPU is in the tick idle mode * @tick_stopped: Indicator that the idle tick has been stopped * @idle_active: Indicator that the CPU is actively in the tick idle mode; * it is reset during irq handling phases. - * @do_timer_lst: CPU was the last one doing do_timer before going idle + * @do_timer_last: CPU was the last one doing do_timer before going idle * @got_idle_tick: Tick timer function has run with @inidle set + * @stalled_jiffies: Number of stalled jiffies detected across ticks + * @last_tick_jiffies: Value of jiffies seen on last tick + * @sched_timer: hrtimer to schedule the periodic tick in high + * resolution mode * @last_tick: Store the last tick expiry time when the tick * timer is modified for nohz sleeps. This is necessary * to resume the tick timer operation in the timeline * when the CPU returns from nohz sleep. * @next_tick: Next tick to be fired when in dynticks mode. * @idle_jiffies: jiffies at the entry to idle for idle time accounting + * @idle_waketime: Time when the idle was interrupted + * @idle_entrytime: Time when the idle call was entered + * @nohz_mode: Mode - one state of tick_nohz_mode + * @last_jiffies: Base jiffies snapshot when next event was last computed + * @timer_expires_base: Base time clock monotonic for @timer_expires + * @timer_expires: Anticipated timer expiration time (in case sched tick is stopped) + * @next_timer: Expiry time of next expiring timer for debugging purpose only + * @idle_expires: Next tick in idle, for debugging purpose only * @idle_calls: Total number of idle calls * @idle_sleeps: Number of idle calls, where the sched tick was stopped - * @idle_entrytime: Time when the idle call was entered - * @idle_waketime: Time when the idle was interrupted * @idle_exittime: Time when the idle state was left * @idle_sleeptime: Sum of the time slept in idle with sched tick stopped * @iowait_sleeptime: Sum of the time slept in idle with sched tick stopped, with IO outstanding - * @timer_expires: Anticipated timer expiration time (in case sched tick is stopped) - * @timer_expires_base: Base time clock monotonic for @timer_expires - * @next_timer: Expiry time of next expiring timer for debugging purpose only * @tick_dep_mask: Tick dependency mask - is set, if someone needs the tick - * @last_tick_jiffies: Value of jiffies seen on last tick - * @stalled_jiffies: Number of stalled jiffies detected across ticks + * @check_clocks: Notification mechanism about clocksource changes */ struct tick_sched { - struct hrtimer sched_timer; - unsigned long check_clocks; - enum tick_nohz_mode nohz_mode; - + /* Common flags */ unsigned int inidle : 1; unsigned int tick_stopped : 1; unsigned int idle_active : 1; unsigned int do_timer_last : 1; unsigned int got_idle_tick : 1; + /* Tick handling: jiffies stall check */ + unsigned int stalled_jiffies; + unsigned long last_tick_jiffies; + + /* Tick handling */ + struct hrtimer sched_timer; ktime_t last_tick; ktime_t next_tick; unsigned long idle_jiffies; - unsigned long idle_calls; - unsigned long idle_sleeps; - ktime_t idle_entrytime; ktime_t idle_waketime; - ktime_t idle_exittime; - ktime_t idle_sleeptime; - ktime_t iowait_sleeptime; + + /* Idle entry */ + ktime_t idle_entrytime; + + /* Tick stop */ + enum tick_nohz_mode nohz_mode; unsigned long last_jiffies; - u64 timer_expires; u64 timer_expires_base; + u64 timer_expires; u64 next_timer; ktime_t idle_expires; + unsigned long idle_calls; + unsigned long idle_sleeps; + + /* Idle exit */ + ktime_t idle_exittime; + ktime_t idle_sleeptime; + ktime_t iowait_sleeptime; + + /* Full dynticks handling */ atomic_t tick_dep_mask; - unsigned long last_tick_jiffies; - unsigned int stalled_jiffies; + + /* Clocksource changes */ + unsigned long check_clocks; }; extern struct tick_sched *tick_get_tick_sched(int cpu); From patchwork Wed Feb 22 14:46:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Weisbecker X-Patchwork-Id: 60565 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp618718wrd; Wed, 22 Feb 2023 06:53:28 -0800 (PST) X-Google-Smtp-Source: AK7set85Rgd9pU+pU9E2spMCmFfmkTAc8k7aDfZGY9ZMtICrw1mUjExTLowLHhOsNGn2XodRrLMw X-Received: by 2002:a05:6402:785:b0:4af:62ad:a36 with SMTP id d5-20020a056402078500b004af62ad0a36mr2095375edy.27.1677077608380; Wed, 22 Feb 2023 06:53:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677077608; cv=none; d=google.com; s=arc-20160816; b=yb6a/oZWPyVRNdGihK+p5i3N2sZcBWdxD0bLoJViJPwXtrDVn3bX8WxxoXQgpQsGRu BcVDHDVusKj0PGh4d+OH0Cpwcwach7TXQOaGkdEYcAZNubV2y8YVahjOy10DsDLLoGTv pFdOM2XH8GC9pVgUMtz9llWHLqSAMGBZ5SmCPdrNXbtNJz/f70ufpDTFnPZxZUBIX1Yi Lx8CQNm0LWJ9yzSwdaT6Z0ZKjaN8GR3Z6iicUrylvUGIY0RfIvKFJHpOBYdlur+znSWb 5jfZ8Kddu0BPRd/y0eLuU+G2ZG0nxqNNJ5R+53D3iliU1yCjoA0OtByBMcic/BJ4fUpY LaTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=egoUl+UrCX7i4gPVYmA9o3lWb9zRaE4swrZUPBYXKnY=; b=Fn1utU5kXhwPStE9KbuJlli6Xyl05f+U0cJ+BKcSENzbXKEfizsPoFcgrb4ultgRYq VM41W3psNyc448DX9t98K5uFFfnHnMgzBKBnfPt83v/h/Y7kvQbU16LnSLeudX9Hdzq0 v0tG9E5Mrou+8C4IVYgmqCn/cpf20RlpWTFQbs2zV6QtPttkl8cAGBRkcrK2lQXARTz6 QhUlAIqjTJNFdtAxvAnyU2uBJFj3rZjndU0ZwesxlMNhdmt2KcZiz5N7XYyoiNuhZ1zu OH8CYRmb01aDVU3t5y8qVcAI7EW7JyU56DAw3Gf5FNot81+lKr+N1cW80l2uKeNYV8qh +vZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FDmOTfUD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y17-20020a056402135100b004a2758d0cc5si4504515edw.226.2023.02.22.06.53.04; Wed, 22 Feb 2023 06:53:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FDmOTfUD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232253AbjBVOrg (ORCPT + 99 others); Wed, 22 Feb 2023 09:47:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59486 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232169AbjBVOrZ (ORCPT ); Wed, 22 Feb 2023 09:47:25 -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 BF94E3BDAF for ; Wed, 22 Feb 2023 06:47:02 -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 3544661464 for ; Wed, 22 Feb 2023 14:47:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 819ADC4339B; Wed, 22 Feb 2023 14:46:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1677077221; bh=Wy5hbT4ewIbxtuRGZo3BNmMi3nK/RbjQJn9sH1g4yFs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FDmOTfUDDAvB318Tim6Svmwl4prd0CvCrO2yMhterj811AW25jGCizagfRmMU3PuO TtwrV6OOwv0mDAN5hY6twOv0xbamI50e31QG5hOBllfU0tfy1WiuNPI1PFNylJku9E QN4/p1q4Mkdo26fnClKlfGr9+zZk2dvpCo1jxbOYzQ+c677jHx0+V9SrSnUeintpfl JfyivG+S4iGlZNMP70TqKR+DSDUdc7Wbb+gTYayl3WGKBFkf2IXoLn4WuTbr4EivDM MdnybAwi2AGGOFmy382kl+pG1nF6aGuLLq2BGD/GXMWKOpgw5S3CvPPD7yfdLzqFb8 UabOOMYAYTN6w== From: Frederic Weisbecker To: Thomas Gleixner Cc: LKML , Frederic Weisbecker , Alexey Dobriyan , Wei Li , Peter Zijlstra , Mirsad Goran Todorovac , Yu Liao , Hillf Danton , Ingo Molnar Subject: [PATCH 2/8] timers/nohz: Only ever update sleeptime from idle exit Date: Wed, 22 Feb 2023 15:46:43 +0100 Message-Id: <20230222144649.624380-3-frederic@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230222144649.624380-1-frederic@kernel.org> References: <20230222144649.624380-1-frederic@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758543330286671622?= X-GMAIL-MSGID: =?utf-8?q?1758543330286671622?= The idle and io sleeptime statistics appearing in /proc/stat can be currently updated from two sites: locally on idle exit and remotely by cpufreq. However there is no synchronization mechanism protecting concurrent updates. It is therefore possible to account the sleeptime twice, among all the possible broken scenarios. To prevent from breaking the sleeptime accounting source, restrict the sleeptime updates to the local idle exit site. If there is a delta to add since the last update, IO/Idle sleep time readers will now only compute the delta without actually writing it back to the internal idle statistic fields. This fixes a writer VS writer race. Note there are still two known reader VS writer races to handle. A subsequent patch will fix one. Reported-by: Yu Liao Acked-by: Peter Zijlstra (Intel) Cc: Hillf Danton Cc: Yu Liao Cc: Ingo Molnar Cc: Thomas Gleixner Cc: Wei Li Cc: Alexey Dobriyan Cc: Mirsad Goran Todorovac Signed-off-by: Frederic Weisbecker --- kernel/time/tick-sched.c | 103 ++++++++++++++++----------------------- 1 file changed, 41 insertions(+), 62 deletions(-) diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c index b0e3c9205946..9058b9eb8bc1 100644 --- a/kernel/time/tick-sched.c +++ b/kernel/time/tick-sched.c @@ -637,31 +637,21 @@ static void tick_nohz_update_jiffies(ktime_t now) touch_softlockup_watchdog_sched(); } -/* - * Updates the per-CPU time idle statistics counters - */ -static void -update_ts_time_stats(int cpu, struct tick_sched *ts, ktime_t now, u64 *last_update_time) -{ - ktime_t delta; - - if (ts->idle_active) { - delta = ktime_sub(now, ts->idle_entrytime); - if (nr_iowait_cpu(cpu) > 0) - ts->iowait_sleeptime = ktime_add(ts->iowait_sleeptime, delta); - else - ts->idle_sleeptime = ktime_add(ts->idle_sleeptime, delta); - ts->idle_entrytime = now; - } - - if (last_update_time) - *last_update_time = ktime_to_us(now); - -} - static void tick_nohz_stop_idle(struct tick_sched *ts, ktime_t now) { - update_ts_time_stats(smp_processor_id(), ts, now, NULL); + ktime_t delta; + + if (WARN_ON_ONCE(!ts->idle_active)) + return; + + delta = ktime_sub(now, ts->idle_entrytime); + + if (nr_iowait_cpu(smp_processor_id()) > 0) + ts->iowait_sleeptime = ktime_add(ts->iowait_sleeptime, delta); + else + ts->idle_sleeptime = ktime_add(ts->idle_sleeptime, delta); + + ts->idle_entrytime = now; ts->idle_active = 0; sched_clock_idle_wakeup_event(); @@ -674,6 +664,30 @@ static void tick_nohz_start_idle(struct tick_sched *ts) sched_clock_idle_sleep_event(); } +static u64 get_cpu_sleep_time_us(struct tick_sched *ts, ktime_t *sleeptime, + bool compute_delta, u64 *last_update_time) +{ + ktime_t now, idle; + + if (!tick_nohz_active) + return -1; + + now = ktime_get(); + if (last_update_time) + *last_update_time = ktime_to_us(now); + + if (ts->idle_active && compute_delta) { + ktime_t delta = ktime_sub(now, ts->idle_entrytime); + + idle = ktime_add(*sleeptime, delta); + } else { + idle = *sleeptime; + } + + return ktime_to_us(idle); + +} + /** * get_cpu_idle_time_us - get the total idle time of a CPU * @cpu: CPU number to query @@ -691,27 +705,9 @@ static void tick_nohz_start_idle(struct tick_sched *ts) u64 get_cpu_idle_time_us(int cpu, u64 *last_update_time) { struct tick_sched *ts = &per_cpu(tick_cpu_sched, cpu); - ktime_t now, idle; - - if (!tick_nohz_active) - return -1; - - now = ktime_get(); - if (last_update_time) { - update_ts_time_stats(cpu, ts, now, last_update_time); - idle = ts->idle_sleeptime; - } else { - if (ts->idle_active && !nr_iowait_cpu(cpu)) { - ktime_t delta = ktime_sub(now, ts->idle_entrytime); - - idle = ktime_add(ts->idle_sleeptime, delta); - } else { - idle = ts->idle_sleeptime; - } - } - - return ktime_to_us(idle); + return get_cpu_sleep_time_us(ts, &ts->idle_sleeptime, + !nr_iowait_cpu(cpu), last_update_time); } EXPORT_SYMBOL_GPL(get_cpu_idle_time_us); @@ -732,26 +728,9 @@ EXPORT_SYMBOL_GPL(get_cpu_idle_time_us); u64 get_cpu_iowait_time_us(int cpu, u64 *last_update_time) { struct tick_sched *ts = &per_cpu(tick_cpu_sched, cpu); - ktime_t now, iowait; - if (!tick_nohz_active) - return -1; - - now = ktime_get(); - if (last_update_time) { - update_ts_time_stats(cpu, ts, now, last_update_time); - iowait = ts->iowait_sleeptime; - } else { - if (ts->idle_active && nr_iowait_cpu(cpu) > 0) { - ktime_t delta = ktime_sub(now, ts->idle_entrytime); - - iowait = ktime_add(ts->iowait_sleeptime, delta); - } else { - iowait = ts->iowait_sleeptime; - } - } - - return ktime_to_us(iowait); + return get_cpu_sleep_time_us(ts, &ts->iowait_sleeptime, + nr_iowait_cpu(cpu), last_update_time); } EXPORT_SYMBOL_GPL(get_cpu_iowait_time_us); From patchwork Wed Feb 22 14:46:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Weisbecker X-Patchwork-Id: 60563 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp618113wrd; Wed, 22 Feb 2023 06:52:05 -0800 (PST) X-Google-Smtp-Source: AK7set/QgpftJlzyuEisElYRbrMwyk0TTAtdIv2Fl1nWHfdQcZVlLH7hKqAuOF6bWat6gSblQDrf X-Received: by 2002:a05:6402:202:b0:4ad:7c6c:537d with SMTP id t2-20020a056402020200b004ad7c6c537dmr7966971edv.33.1677077525650; Wed, 22 Feb 2023 06:52:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677077525; cv=none; d=google.com; s=arc-20160816; b=Q1Wntn6liGF8JFSNTtcRsIRmkZfBZIl5xkI+Ea29oubZpYzk4Mr5LCx+bcUYowObaI /LdVe32pl8PJLsMe+gbiVagImto+3bzTRZGCiVX9grjquoYQJ1d8Aqi/5mxQ3WcN9/vy Don/sPOhSOdv9VhrbDOs7FLXO2AfjnEYQRoKpewsdFmFV9bKqoKU2f+5ydz5oNNAywYG dJvhuC2Gh/XMK9PoJT/zztjNZ8zhEk48EOTDPhSea1Cv735jfzjIfwv3QsOAHJHmwpE+ QtzsBm6GdzoSR4FXQhs+HHLMMbAeD4zpI1LWHIfBMVrI8Hbed5hLqGE8lRYzhN04yb88 A7qg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=j8S8KwqGSfvA+BWFE3awZzpfdbRcW5+HPxYAuXJJeCs=; b=cA8pkc1THubBDNIi+u4btbIzlZS+sEzqlKurmK4aFJ6IQArsJgIblu5CHDTCKa+nSa pBHa0mcZ2dOLSQ2CXtndU1j2Cec678MXoEAbKhGZ9QMePamO8DsMYRVVtTsfIcNuHK5G grmvChSgEZp6u7vWS8kGPf2uozLFi8dOtuIOlJiiiCR6l6ztqRi/dTJSqXM33PG/W282 aM0681pNasJj0g5IaOREAetChw3iLVlmEBrRGFsO5pT2ODyhOYM6KLksm5dNHlX0sr1u x8G/+q1egXLkHIOvYN7ORtnWevJhAA4P1kN0/8kKqqHyyNZnedIiT04SNeUeN9HVnh36 JQPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Sc66U+Je; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m21-20020aa7c495000000b004acb24be0d2si8721134edq.315.2023.02.22.06.51.42; Wed, 22 Feb 2023 06:52:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Sc66U+Je; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231174AbjBVOrq (ORCPT + 99 others); Wed, 22 Feb 2023 09:47:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232196AbjBVOrf (ORCPT ); Wed, 22 Feb 2023 09:47:35 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3AD222A2F for ; Wed, 22 Feb 2023 06:47:19 -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 DD4DD61486 for ; Wed, 22 Feb 2023 14:47:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2C18EC433D2; Wed, 22 Feb 2023 14:47:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1677077224; bh=5sxyMTW09Kl3ct1nkcDaj+gcruIUS7UwkGWllRn6QWo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Sc66U+JeBvcIan2oTweypNsCy2L8Q2/rPUz6v+bXrFziNS6zAxmMtjoUctKljuRW5 59q297z8DODDV+4UtOB4+eFCzY4DcJO7esf/AF4bPFIy9gxqqrFX64DtVFKz2Hi73L n+uuZcaGU40P4h0HRfuKyBmN4WO6ylbAmBn6d6vwVZ2dGLjgwYfpnbr3phSDVbTIf9 P9JJM92Z7sgM9Mk7/fOrst3iDJtN+i2ImK7gpXdihpHHdy1YIovXunR3SkSKR/odZn pYDPMZqntFhTXNPrx41WL2rAOI+OlnhnEeGnjI9vbbChhMDztY2XoZwqdkBbG8/cX2 XTv0y2jKriNaQ== From: Frederic Weisbecker To: Thomas Gleixner Cc: LKML , Frederic Weisbecker , Alexey Dobriyan , Wei Li , Peter Zijlstra , Mirsad Goran Todorovac , Yu Liao , Hillf Danton , Ingo Molnar Subject: [PATCH 3/8] timers/nohz: Protect idle/iowait sleep time under seqcount Date: Wed, 22 Feb 2023 15:46:44 +0100 Message-Id: <20230222144649.624380-4-frederic@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230222144649.624380-1-frederic@kernel.org> References: <20230222144649.624380-1-frederic@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758543243476744223?= X-GMAIL-MSGID: =?utf-8?q?1758543243476744223?= Reading idle/io sleep time (eg: from /proc/stat) can race with idle exit updates because the state machine handling the stats is not atomic and requires a coherent read batch. As a result reading the sleep time may report irrelevant or backward values. Fix this with protecting the simple state machine within a seqcount. This is expected to be cheap enough not to add measurable performance impact on the idle path. Note this only fixes reader VS writer condition partitially. A race remains that involves remote updates of the CPU iowait task counter. It can hardly be fixed. Reported-by: Yu Liao Acked-by: Peter Zijlstra (Intel) Cc: Hillf Danton Cc: Yu Liao Cc: Ingo Molnar Cc: Thomas Gleixner Cc: Wei Li Cc: Alexey Dobriyan Cc: Mirsad Goran Todorovac Signed-off-by: Frederic Weisbecker --- kernel/time/tick-sched.c | 22 ++++++++++++++++------ kernel/time/tick-sched.h | 1 + 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c index 9058b9eb8bc1..90d9b7b29875 100644 --- a/kernel/time/tick-sched.c +++ b/kernel/time/tick-sched.c @@ -646,6 +646,7 @@ static void tick_nohz_stop_idle(struct tick_sched *ts, ktime_t now) delta = ktime_sub(now, ts->idle_entrytime); + write_seqcount_begin(&ts->idle_sleeptime_seq); if (nr_iowait_cpu(smp_processor_id()) > 0) ts->iowait_sleeptime = ktime_add(ts->iowait_sleeptime, delta); else @@ -653,14 +654,18 @@ static void tick_nohz_stop_idle(struct tick_sched *ts, ktime_t now) ts->idle_entrytime = now; ts->idle_active = 0; + write_seqcount_end(&ts->idle_sleeptime_seq); sched_clock_idle_wakeup_event(); } static void tick_nohz_start_idle(struct tick_sched *ts) { + write_seqcount_begin(&ts->idle_sleeptime_seq); ts->idle_entrytime = ktime_get(); ts->idle_active = 1; + write_seqcount_end(&ts->idle_sleeptime_seq); + sched_clock_idle_sleep_event(); } @@ -668,6 +673,7 @@ static u64 get_cpu_sleep_time_us(struct tick_sched *ts, ktime_t *sleeptime, bool compute_delta, u64 *last_update_time) { ktime_t now, idle; + unsigned int seq; if (!tick_nohz_active) return -1; @@ -676,13 +682,17 @@ static u64 get_cpu_sleep_time_us(struct tick_sched *ts, ktime_t *sleeptime, if (last_update_time) *last_update_time = ktime_to_us(now); - if (ts->idle_active && compute_delta) { - ktime_t delta = ktime_sub(now, ts->idle_entrytime); + do { + seq = read_seqcount_begin(&ts->idle_sleeptime_seq); - idle = ktime_add(*sleeptime, delta); - } else { - idle = *sleeptime; - } + if (ts->idle_active && compute_delta) { + ktime_t delta = ktime_sub(now, ts->idle_entrytime); + + idle = ktime_add(*sleeptime, delta); + } else { + idle = *sleeptime; + } + } while (read_seqcount_retry(&ts->idle_sleeptime_seq, seq)); return ktime_to_us(idle); diff --git a/kernel/time/tick-sched.h b/kernel/time/tick-sched.h index c6663254d17d..5ed5a9d41d5a 100644 --- a/kernel/time/tick-sched.h +++ b/kernel/time/tick-sched.h @@ -75,6 +75,7 @@ struct tick_sched { ktime_t idle_waketime; /* Idle entry */ + seqcount_t idle_sleeptime_seq; ktime_t idle_entrytime; /* Tick stop */ From patchwork Wed Feb 22 14:46:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Weisbecker X-Patchwork-Id: 60564 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp618180wrd; Wed, 22 Feb 2023 06:52:14 -0800 (PST) X-Google-Smtp-Source: AK7set8sXuV5H+LIKpSMQS1LYaBX8yMHG8vouc8RdkSVG4YVsPlt58cHF+7xYuN1/R7LWYaXEzwq X-Received: by 2002:a17:906:8586:b0:8b2:7567:9c30 with SMTP id v6-20020a170906858600b008b275679c30mr21463404ejx.59.1677077534088; Wed, 22 Feb 2023 06:52:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677077534; cv=none; d=google.com; s=arc-20160816; b=DkpJYXzaGgF9MxlhzSdh/6BNeYEfA2kexyzSdBAbHuG66G/VN9pQs76WbPS2f+Ia7i y6fv6i1fC63j8JlhsD4SkpXAVZ2H4oiam8UtXTMoIH4/EVWD4jGJXIVbLKDH0xgTYh9E WQL2Q8kyLjI9LNyUl1wlU9DNGMjHx8trDnXqJH2e8nNK/81aFpRvi4eP5I1BxgY0XFzY 0T3t0Nwoc5yz7GlPHqq+EEltuLJ7Fr2RezHZ5Z2cCXM0w+VkNI3gSwk3b3hEn83co3ZI Jqygz3J/CnJF6NrBOGk/GR6RHUUUJvAUoNxHY5n9PUL8F646uArciC7Z+sPH1fDXSZlQ khKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=NrB7afxi3d5+PqIM9nM6wjQbxSOb/RrygeHypAOKagQ=; b=HQxMxj1mUS6voWy7QIJfgm11nY/9eVMfoa0szfG2GrIed/UvHE+GbeIwCLQP8Sx3lW kr8/hNQAgEAybjZ2KgexgS5Df7xrqlZ9V1LflqkpsgQxUq+pTuAAPiVhepWAVfJ4sHPg Q0y5mhpICSKp+tn6IwDPeJjgFLdzvYX6fH9Hk7aBDnpoPpasSQOle8ensKVYcpml7gFy yKQmvWRqXnq2D31FCszGBd6wDluGZFa8MqOsGe45iyG8SSFreRu3xEOD7cLAnHub3iRZ 3X/hn3DZzN6cAaT8hL4mxhbzimZQ3zl/SYg+q34KW6U7j43Pdyh0YeNhdZDQbQvmNc8X s2gw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=freejV55; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id wc23-20020a170907125700b008d2f41325e4si9201237ejb.420.2023.02.22.06.51.48; Wed, 22 Feb 2023 06:52:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=freejV55; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232284AbjBVOrt (ORCPT + 99 others); Wed, 22 Feb 2023 09:47:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232239AbjBVOrf (ORCPT ); Wed, 22 Feb 2023 09:47:35 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A43C63B215 for ; Wed, 22 Feb 2023 06:47:20 -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 85E1C6148E for ; Wed, 22 Feb 2023 14:47:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C9F62C4339E; Wed, 22 Feb 2023 14:47:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1677077227; bh=60UVPMKRBBZlhZputsHs6D/GUWH9jHmYFrcL5ldfROQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=freejV5546gLOuur9fYo+33buf40+Z96Mnn9j+UC1Jxp8s5/spdnEbt5zWmtjnFOc QXWQeq1FBg88cz9a7m5Gy36Ckj9xyFCDnW4KgPvsM7XrwYmAjJ1a7+Jsz1LPdA5FdL vH1yWwgm168Z5/4gQlURHesskOnAf4YQ3LQzCQ7F4B/yEKWx9uvjxJ5hMnNE+5xiqB jVMtIzfw+iF9GWl+VU1vnLRyMsgCU3nCDtNcEsoAbNycgCVZSVELl2HPGL7I8nvY/c fPG7t6B3IQLqPDmbHcRJ5RW1slecVqquDxO1pqOc1kSlvbmr2RZWPZQz+zETA6z6NN czPhb1KyzQPPg== From: Frederic Weisbecker To: Thomas Gleixner Cc: LKML , Frederic Weisbecker , Alexey Dobriyan , Wei Li , Peter Zijlstra , Mirsad Goran Todorovac , Yu Liao , Hillf Danton , Ingo Molnar Subject: [PATCH 4/8] timers/nohz: Add a comment about broken iowait counter update race Date: Wed, 22 Feb 2023 15:46:45 +0100 Message-Id: <20230222144649.624380-5-frederic@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230222144649.624380-1-frederic@kernel.org> References: <20230222144649.624380-1-frederic@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758543252374747903?= X-GMAIL-MSGID: =?utf-8?q?1758543252374747903?= 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. Acked-by: Peter Zijlstra (Intel) Cc: Hillf Danton Cc: Yu Liao Cc: Ingo Molnar Cc: Thomas Gleixner Cc: Wei Li Cc: Alexey Dobriyan Cc: Mirsad Goran Todorovac Signed-off-by: Frederic Weisbecker --- kernel/time/tick-sched.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c index 90d9b7b29875..edd6e9f26d16 100644 --- a/kernel/time/tick-sched.c +++ b/kernel/time/tick-sched.c @@ -705,7 +705,10 @@ static u64 get_cpu_sleep_time_us(struct tick_sched *ts, ktime_t *sleeptime, * counters if NULL. * * 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. @@ -728,7 +731,10 @@ EXPORT_SYMBOL_GPL(get_cpu_idle_time_us); * counters if NULL. * * Return the cumulative iowait 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. From patchwork Wed Feb 22 14:46:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Weisbecker X-Patchwork-Id: 60567 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp619045wrd; Wed, 22 Feb 2023 06:54:14 -0800 (PST) X-Google-Smtp-Source: AK7set8tkcAvxtqSVek+kjocQ05/5xQKOVdU9+dCHt7HCmbzA7pcEuPq8lFt+rn89Pg4cVPD42dM X-Received: by 2002:a17:906:58cf:b0:88b:5798:2613 with SMTP id e15-20020a17090658cf00b0088b57982613mr20987596ejs.20.1677077654341; Wed, 22 Feb 2023 06:54:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677077654; cv=none; d=google.com; s=arc-20160816; b=qzFfmKSC97x2imFLZTPMYKc8YB93/XJoKC2u1AR/Rg5gjS60NKpNAh2v7FUgE28BYz faYaviH9nGLr3iNwj4rZ8QW+Fge42X9FV8ISeJ7rlSByo94JMsbdcKJX9UUqFkM7R4Ft m+JFV1MkPfDjlKuUMSHIL72pfMCFaxLOtI6PWnbf9Z6iiBv/bt/iL3n1itJgluGc5Qh2 ZVzP7VWk/V+L4Q9lKNNqJfcQdyctGFPoB7aMXesIAsOdxnZ6BB5Loyhzd65IExC8MFox qFx1N+DVkycFd4Ieb7OARSZ3lD7fSQ46sBnyuxsJrkMaMnl3oiq9VMNH3FYtov9XC4Yg RZPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=hFbVBQX5traxN3KDS5Y0JH03AX0vM76qT+/IKvGQRtA=; b=TxHjeYCQTL6ZDXsHSzADX4Ds8sLrSRHxibqOdh1as6Iiy0RECwG4C0X5Up4yujLDVl +CROtoRDTchGy+hhh3Wpf9xz3iWAr8ZcDqo1OX2BQb/jO2bcULYJtGPPuPh8h4O73/Kv tVjZ13YB/0qrrFMXtDybIFmZE/bDs6vtDb3Ff5k4/5BEnX7WYAxq5Q8ePHangpgfJzB0 ZS2zRkbfk2ezijds7/yXdk5hbHnco3qdBC0nfXveh34oyA8h+sTPQGBLvhU+ajbn1sZs v4nIOUpMhpT0MFqsr1xXQ19BCsCOWlmWuQBc2oBgX9w6IDnyGdmbvus/SJskb6uRfDLn PCCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bxgURqkQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n21-20020a17090673d500b008b176cc834bsi23937982ejl.939.2023.02.22.06.53.47; Wed, 22 Feb 2023 06:54:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bxgURqkQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231926AbjBVOsD (ORCPT + 99 others); Wed, 22 Feb 2023 09:48:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231945AbjBVOrl (ORCPT ); Wed, 22 Feb 2023 09:47:41 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B27E83BD92 for ; Wed, 22 Feb 2023 06:47:22 -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 2AC9961490 for ; Wed, 22 Feb 2023 14:47:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7259DC4339C; Wed, 22 Feb 2023 14:47:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1677077229; bh=/vEaMsqtOE5BkbGfNS7gZR33SAARhK8GonMdLs7ceS0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bxgURqkQdkUvU9rwsmMvbmQ+NaQ/3H72lC8HzB9tC2wpkHwyjDOJmuPdDA1QjJPZc ogLlOR/no2HPH3zJD3aCVLLkDtZGFcVcdYy3rS+o/Wycq5KwssYIZzyNWKxkp1H6q9 NkyVSxYNBDpvaF40BBjqj5zFfaXJ8/z8ZOZzR1CxsQYcJ5XZTK4y24u5KxQDf50lCL kDi3Gwhx4ntKzy9+AD6K1OFMLGEuLBvX+7TTIZGgQfV4g8ZvgFst7pjGLuKIlvyId/ yPEDf+4C+EpTeiEcGylwcfTsEZ6g5/adZYZmDBsruqLJErd2w/8NBc3kvNQOlAKIXZ LNxnamwUqx4Hg== From: Frederic Weisbecker To: Thomas Gleixner Cc: LKML , Frederic Weisbecker , Alexey Dobriyan , Wei Li , Peter Zijlstra , Mirsad Goran Todorovac , Yu Liao , Hillf Danton , Ingo Molnar Subject: [PATCH 5/8] timers/nohz: Remove middle-function __tick_nohz_idle_stop_tick() Date: Wed, 22 Feb 2023 15:46:46 +0100 Message-Id: <20230222144649.624380-6-frederic@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230222144649.624380-1-frederic@kernel.org> References: <20230222144649.624380-1-frederic@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758543378351152817?= X-GMAIL-MSGID: =?utf-8?q?1758543378351152817?= There is no need for the __tick_nohz_idle_stop_tick() function between tick_nohz_idle_stop_tick() and its implementation. Remove that unnecessary step. Acked-by: Peter Zijlstra (Intel) Cc: Hillf Danton Cc: Yu Liao Cc: Ingo Molnar Cc: Thomas Gleixner Cc: Wei Li Cc: Alexey Dobriyan Cc: Mirsad Goran Todorovac Signed-off-by: Frederic Weisbecker --- kernel/time/tick-sched.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c index edd6e9f26d16..3b53b894ca98 100644 --- a/kernel/time/tick-sched.c +++ b/kernel/time/tick-sched.c @@ -1079,10 +1079,16 @@ static bool can_stop_idle_tick(int cpu, struct tick_sched *ts) return true; } -static void __tick_nohz_idle_stop_tick(struct tick_sched *ts) +/** + * tick_nohz_idle_stop_tick - stop the idle tick from the idle task + * + * When the next event is more than a tick into the future, stop the idle tick + */ +void tick_nohz_idle_stop_tick(void) { + struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched); + int cpu = smp_processor_id(); ktime_t expires; - int cpu = smp_processor_id(); /* * If tick_nohz_get_sleep_length() ran tick_nohz_next_event(), the @@ -1114,16 +1120,6 @@ static void __tick_nohz_idle_stop_tick(struct tick_sched *ts) } } -/** - * tick_nohz_idle_stop_tick - stop the idle tick from the idle task - * - * When the next event is more than a tick into the future, stop the idle tick - */ -void tick_nohz_idle_stop_tick(void) -{ - __tick_nohz_idle_stop_tick(this_cpu_ptr(&tick_cpu_sched)); -} - void tick_nohz_idle_retain_tick(void) { tick_nohz_retain_tick(this_cpu_ptr(&tick_cpu_sched)); From patchwork Wed Feb 22 14:46:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Weisbecker X-Patchwork-Id: 60566 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp619030wrd; Wed, 22 Feb 2023 06:54:12 -0800 (PST) X-Google-Smtp-Source: AK7set80TpeeXdwV2O5AztPvp+rCXTxMaUcH4pRC0kYIEXCPexpTxHwRaVr0mvUx7ct0GbjTx0jo X-Received: by 2002:a17:906:3c6:b0:878:78bc:975c with SMTP id c6-20020a17090603c600b0087878bc975cmr16940040eja.36.1677077652324; Wed, 22 Feb 2023 06:54:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677077652; cv=none; d=google.com; s=arc-20160816; b=FOW27r9hudb/+jt7sU9jBjJA1wWCuHcT6FL43mU064XJSSrypjEP+wMJiGPbypLYtq daZGp/jg1u54sNxspja+iyp7c2kZBouFVIyWwJ79DnLA9fnTfZjZLK/2vW0N3c24OzwG esRu7hPHQ/BevhtgAE1CdnBjsrzaBePKkUOM5gJ7yXhaRlKxCWdttpdxXaPzuVt0DMho AkROhrK6kIkBd3k3Mb+taeFjtjohymX/AY05W9FzYkL1D5llmcNO61HTroR8mxLmaibl ELP8tG0oOcJuxrHBQ9EoZkmOxRphKdUNiW3VSBMDqiDOhJviaNV163XgJxrp/6u6smn4 PKZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=g3DcKUCCv/U3jYeWTX+nrQQz8TJ39df1PilTyrpb6JI=; b=c0HSaby4I0SO74fkYGlcuberVAqDyGVZG1JatTG4GOeclS/XFgPYxV635tAaChCelI lPgPV7EEH+8OT3Zf59ZddPfCFQ9LEDa6xol6PoHHBm2PcXEbmCAjeEUKymOyCYiA1URO ob2bsRGGSGGz8z9kFaMHo3q3X0wReePe0e+o8q7RpgQRkqp8b90qQevXRPNPgTtHg0y6 XnxigjdOJCLs7SbmW3WRM/3D4VK++vLAiKytzn9pgYWzKg2PboNX43NnrHL6BOKPb7Fh LMhd2lAJqR6bfa+S/Ie9sA6gy+B/A9h6EAjabVr/9csRL8aAnES4wO4aqNYXCT8ru/0w v8Qg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VMn+Xg+Q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e30-20020a170906749e00b008cadb41bef9si15023750ejl.852.2023.02.22.06.53.49; Wed, 22 Feb 2023 06:54:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VMn+Xg+Q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232282AbjBVOsI (ORCPT + 99 others); Wed, 22 Feb 2023 09:48:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232280AbjBVOro (ORCPT ); Wed, 22 Feb 2023 09:47:44 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 45D3F3B3FC for ; Wed, 22 Feb 2023 06:47:24 -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 ams.source.kernel.org (Postfix) with ESMTPS id BDBC2B81230 for ; Wed, 22 Feb 2023 14:47:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1BD26C4339E; Wed, 22 Feb 2023 14:47:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1677077232; bh=NHv2T4M6t3YcZt1kUoyxtpuC8v5xebDYXn942sZPC1Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VMn+Xg+QFyaDpYO0E6BpyUqeqGmDlgBBMKYEMIqvgN/H98zMYGaPN4Uq0rFnoCsBu tR6bonMsi9+qmL4BdwaYawwEBsOZObdXewrMkBug1CI7+uriwqKPXTyZzs48vIJdfu fAU55CEta+BA6FOXhOW5JOm7VCWcFs526FnrqzrR6OwoLEsd0F4SftzsnequpojC7S wDFZHiPuITun5zbc247ZGd8fIqkQrUBhmrxaCb3kMIFRagIeZkTEj464yA7byI5+m0 9bRHeIJDLkrCyxhO2vZ9AbiBXKw0jESwdJHJxQCJW6GwX4WL3WR9zm8qMx83qoE3yE ot9hFyqNsXFZw== From: Frederic Weisbecker To: Thomas Gleixner Cc: LKML , Frederic Weisbecker , Alexey Dobriyan , Wei Li , Peter Zijlstra , Mirsad Goran Todorovac , Yu Liao , Hillf Danton , Ingo Molnar Subject: [PATCH 6/8] MAINTAINERS: Remove stale email address Date: Wed, 22 Feb 2023 15:46:47 +0100 Message-Id: <20230222144649.624380-7-frederic@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230222144649.624380-1-frederic@kernel.org> References: <20230222144649.624380-1-frederic@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758543376410080669?= X-GMAIL-MSGID: =?utf-8?q?1758543376410080669?= Acked-by: Peter Zijlstra (Intel) Cc: Hillf Danton Cc: Yu Liao Cc: Ingo Molnar Cc: Thomas Gleixner Cc: Wei Li Cc: Alexey Dobriyan Cc: Mirsad Goran Todorovac Signed-off-by: Frederic Weisbecker --- MAINTAINERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MAINTAINERS b/MAINTAINERS index fb1471cb5ed3..300ca61fa0bc 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -14794,7 +14794,7 @@ F: include/uapi/linux/nitro_enclaves.h F: samples/nitro_enclaves/ NOHZ, DYNTICKS SUPPORT -M: Frederic Weisbecker +M: Frederic Weisbecker M: Thomas Gleixner M: Ingo Molnar L: linux-kernel@vger.kernel.org From patchwork Wed Feb 22 14:46:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Weisbecker X-Patchwork-Id: 60569 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp619354wrd; Wed, 22 Feb 2023 06:54:53 -0800 (PST) X-Google-Smtp-Source: AK7set/vRzLMyK+vpeJjnzPesi/dbHl8hWKo1RmSIYX/bbVh7lwLMauBCYnnBhRcocN1MHEGxPIK X-Received: by 2002:a17:907:6025:b0:878:683c:f0d1 with SMTP id fs37-20020a170907602500b00878683cf0d1mr13187688ejc.38.1677077693375; Wed, 22 Feb 2023 06:54:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677077693; cv=none; d=google.com; s=arc-20160816; b=q4OhJBdUFx/098ZopPzMV7Foq0VD4+ZwL1WVSx5pWXCXgXKRFKsbqHEn8CNiZQc2Sc pmGSQALV1RrFK7wXnK5TJlLKK0mfeSbeanKOVkv7FMOj1OhvGj2SqfdAoWxElCYtATH/ XC8o3HF0yzS5MvYVMDkmmfWwgiq5o1E6ZRM4NMMzlynQNuWXTKbPDIT+feloPgbIdpYK Tb4pbttClV9SoAI3fI1GVeiLxDFw9zZ3HBWybHfxrG1GQpTyNngkiH+oGsBxWJ4ricPJ 3hHoR0egy6pOa37bTdfhnFiaarxQ/RROgQewDhIYlEhi/R7OKww2YBMoYrpNoSr5xoby n8bQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=2oncR+7k+yEKHbll4dHTPRpUcymMI3j5R/s+c+wVKUg=; b=fuz+TzuB2al9WlecAl5pXqk176bb+88dR+MpCZqO9FMVpm+2R7Q21vVGMFzNN0Z2ly ve5MpeDDOuzudbfL31e0YtSQK7gRw6yDUoPhOF3FZ4eHjQ7V20xq+nSbDrJ/ioMqzGLL pLDQf7p56+/dd2pb3cyHlOR6749jkTWUkRNvhATxPJXS7NaV0iDK/T/H58KJ8GEyNorb b0oaXZz6sUoe279P1AeVF7QBEBPLM5O2+eKQBeT4wJ6StT1RwjsulmFpcTqiZiuhqXwl 4SyRRcNRV7GvchH5x/Kuvx7bF/L9HNejF+Wtr0JBZInucFOFSAoWONQ7vvC4/tWFL72V lt+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Ucf5hOIw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ms31-20020a170907621f00b008c7abe01745si11358750ejc.492.2023.02.22.06.54.30; Wed, 22 Feb 2023 06:54:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Ucf5hOIw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231955AbjBVOsK (ORCPT + 99 others); Wed, 22 Feb 2023 09:48:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231821AbjBVOrp (ORCPT ); Wed, 22 Feb 2023 09:47:45 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6BCEB3C781 for ; Wed, 22 Feb 2023 06:47:25 -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 6CD4D612FC for ; Wed, 22 Feb 2023 14:47:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B842CC4339C; Wed, 22 Feb 2023 14:47:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1677077234; bh=Y8JxDtLzBbykmpbzPSKug0UQ8gYai1KJkaFJDQJ6g9M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ucf5hOIwqMVgXUZUJPSIqcTzk8UXkIhjg9lURzfKGg5BVAYGcrekCEyCjTKRHul9b sSWYME9oC2gyhBP8dnf2Fpdp0FuFx0ndMd1bMLNcR7f/l9pDuWktgLnxtHGPIaCAcd YgqyfxLG2Befj3Y2d8/wNrjyPc2/Hceb7s3qxUS3k5HrLwFAY+FAaxL/ws5IXWLu6W 41x55tBJoa3nL1XAEkDTEIZMXro3VFn5WVxpdMV+FY7opHdqcZD49XMpSCgBMqOeWX 0aKZZeIjeL33wBFumEr9uGShDHC/+oTQ1ZX1vujlLNHxvUyRf2biOOi14C/RtOP8eF +eydlKhZeJBrg== From: Frederic Weisbecker To: Thomas Gleixner Cc: LKML , Frederic Weisbecker , Alexey Dobriyan , Wei Li , Peter Zijlstra , Mirsad Goran Todorovac , Yu Liao , Hillf Danton , Ingo Molnar Subject: [PATCH 7/8] selftests/proc: Remove idle time monotonicity assertions Date: Wed, 22 Feb 2023 15:46:48 +0100 Message-Id: <20230222144649.624380-8-frederic@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230222144649.624380-1-frederic@kernel.org> References: <20230222144649.624380-1-frederic@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758543419355749345?= X-GMAIL-MSGID: =?utf-8?q?1758543419355749345?= Due to broken iowait task counting design (cf: comments above get_cpu_idle_time_us() and nr_iowait()), it is not possible to provide the guarantee that /proc/stat or /proc/uptime display monotonic idle time values. Remove the assertions that verify the related wrong assumption so that testers and maintainers don't spend more time on that. Reported-by: Yu Liao Reported-by: Thomas Gleixner Cc: Hillf Danton Cc: Ingo Molnar Cc: Wei Li Cc: Alexey Dobriyan Cc: Mirsad Goran Todorovac Cc: Peter Zijlstra Signed-off-by: Frederic Weisbecker --- tools/testing/selftests/proc/proc-uptime-001.c | 12 ++++++------ tools/testing/selftests/proc/proc-uptime-002.c | 13 ++++++------- tools/testing/selftests/proc/proc-uptime.h | 16 ++-------------- 3 files changed, 14 insertions(+), 27 deletions(-) diff --git a/tools/testing/selftests/proc/proc-uptime-001.c b/tools/testing/selftests/proc/proc-uptime-001.c index 781f7a50fc3f..35bddd9dd60b 100644 --- a/tools/testing/selftests/proc/proc-uptime-001.c +++ b/tools/testing/selftests/proc/proc-uptime-001.c @@ -13,7 +13,9 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -// Test that values in /proc/uptime increment monotonically. +// Test that boottime value in /proc/uptime increments monotonically. +// We don't test idle time monotonicity due to broken iowait task +// counting, cf: comment above get_cpu_idle_time_us() #undef NDEBUG #include #include @@ -25,20 +27,18 @@ int main(void) { - uint64_t start, u0, u1, i0, i1; + uint64_t start, u0, u1; int fd; fd = open("/proc/uptime", O_RDONLY); assert(fd >= 0); - proc_uptime(fd, &u0, &i0); + u0 = proc_uptime(fd); start = u0; do { - proc_uptime(fd, &u1, &i1); + u1 = proc_uptime(fd); assert(u1 >= u0); - assert(i1 >= i0); u0 = u1; - i0 = i1; } while (u1 - start < 100); return 0; diff --git a/tools/testing/selftests/proc/proc-uptime-002.c b/tools/testing/selftests/proc/proc-uptime-002.c index 7d0aa22bdc12..7ad79d5eaa84 100644 --- a/tools/testing/selftests/proc/proc-uptime-002.c +++ b/tools/testing/selftests/proc/proc-uptime-002.c @@ -13,8 +13,9 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -// Test that values in /proc/uptime increment monotonically -// while shifting across CPUs. +// Test that boottime value in /proc/uptime increments monotonically +// while shifting across CPUs. We don't test idle time monotonicity +// due to broken iowait task counting, cf: comment above get_cpu_idle_time_us() #undef NDEBUG #include #include @@ -45,7 +46,7 @@ int main(void) unsigned int len; unsigned long *m; unsigned int cpu; - uint64_t u0, u1, i0, i1; + uint64_t u0, u1; int fd; /* find out "nr_cpu_ids" */ @@ -60,7 +61,7 @@ int main(void) fd = open("/proc/uptime", O_RDONLY); assert(fd >= 0); - proc_uptime(fd, &u0, &i0); + u0 = proc_uptime(fd); for (cpu = 0; cpu < len * 8; cpu++) { memset(m, 0, len); m[cpu / (8 * sizeof(unsigned long))] |= 1UL << (cpu % (8 * sizeof(unsigned long))); @@ -68,11 +69,9 @@ int main(void) /* CPU might not exist, ignore error */ sys_sched_setaffinity(0, len, m); - proc_uptime(fd, &u1, &i1); + u1 = proc_uptime(fd); assert(u1 >= u0); - assert(i1 >= i0); u0 = u1; - i0 = i1; } return 0; diff --git a/tools/testing/selftests/proc/proc-uptime.h b/tools/testing/selftests/proc/proc-uptime.h index dc6a42b1d6b0..ca55abeb0ccc 100644 --- a/tools/testing/selftests/proc/proc-uptime.h +++ b/tools/testing/selftests/proc/proc-uptime.h @@ -22,7 +22,7 @@ #include "proc.h" -static void proc_uptime(int fd, uint64_t *uptime, uint64_t *idle) +static uint64_t proc_uptime(int fd) { uint64_t val1, val2; char buf[64], *p; @@ -43,18 +43,6 @@ static void proc_uptime(int fd, uint64_t *uptime, uint64_t *idle) assert(p[3] == ' '); val2 = (p[1] - '0') * 10 + p[2] - '0'; - *uptime = val1 * 100 + val2; - p += 4; - - val1 = xstrtoull(p, &p); - assert(p[0] == '.'); - assert('0' <= p[1] && p[1] <= '9'); - assert('0' <= p[2] && p[2] <= '9'); - assert(p[3] == '\n'); - - val2 = (p[1] - '0') * 10 + p[2] - '0'; - *idle = val1 * 100 + val2; - - assert(p + 4 == buf + rv); + return val1 * 100 + val2; } From patchwork Wed Feb 22 14:46:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Weisbecker X-Patchwork-Id: 60568 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp619085wrd; Wed, 22 Feb 2023 06:54:20 -0800 (PST) X-Google-Smtp-Source: AK7set+sZicC9YhDcGXSupO6m1HGo5DNqgiLoADJ+xR4Rw7PNxo4K7VNCGaH2Y2pvG4gY2bOeqk3 X-Received: by 2002:a17:906:489:b0:879:ab3:93d1 with SMTP id f9-20020a170906048900b008790ab393d1mr16618088eja.4.1677077660004; Wed, 22 Feb 2023 06:54:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677077659; cv=none; d=google.com; s=arc-20160816; b=wDDyHuX3UyEVTivIgtMvFq/XolXYl7xD15hcxOADfiLtJSuFbRoaLGdQESfXm3Zbxn czUXbHi4kz3OxH25wQbgBdTVLsjA2Aztm9rbuNCGSgIFzLqeiCYAxVOdvHrfRKjlwo/7 D0tYwlayTIrByxWMcEFe81kElzF3sQwSnEE/NXzI6XAPLlbUZO7mA5+XHqwcxqnNgEIh KRg+2eSbgTBiOWY60tsEEMS4BZQEu7wD47MCOnAKoDNedxQ5I2aNQYef3CFtDXF/TZRz OqKsB6HIYj+PHz94tohx0isFVrP70fiucMHQSTrJY7OfzLuu1W40z5Pipl8Hkw7V889l SfHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=D2JmexIW+UHfXP2WtCzOlQ001Sk+aLFj/Twgy2DczE0=; b=HT6VAt5XjwQaUPeRM9SsvKBWpsA52lceJNhn4aI2Qg7eLR3IV6edjIIHPnyLCv8AZa z76bKJAUB/q2fWyzC2hoHUCBefBIpn4j/kLWkqjEDTPeChg/Z5sDSsLU1cD2uNGjQ7+C 0irsHh2ZUeBSfe+fSsm82LB5HTODpDOV+1/bcmSXkg1vt3OAimnR3BHImGF0E1jjBvVA VzBc7MYuAygkeA+4hFaZGKlO4QN77OUJ/kpzSuwFHQWFM8Ebz9Mk05hU+8EcXlsgFOSU IvvJu52MKweJpEZ6YvCFtUfLz5x3NfiIMY3H2UVb2vRY3cw+fs1DhNpfDoNx7XeTEhiK qlbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="O/SXFOf0"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gj19-20020a170907741300b008b84c44d603si14773349ejc.388.2023.02.22.06.53.45; Wed, 22 Feb 2023 06:54:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="O/SXFOf0"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232302AbjBVOr7 (ORCPT + 99 others); Wed, 22 Feb 2023 09:47:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59326 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232201AbjBVOrh (ORCPT ); Wed, 22 Feb 2023 09:47:37 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8249F38EB6 for ; Wed, 22 Feb 2023 06:47:21 -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 ams.source.kernel.org (Postfix) with ESMTPS id BC6C2B815C9 for ; Wed, 22 Feb 2023 14:47:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 60642C4339E; Wed, 22 Feb 2023 14:47:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1677077237; bh=3ds3/cTbh0yU84XZ4nwDnOjFVf7ivtfK68suy9ql4Kw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=O/SXFOf0UVWM/2lQuF9pRCQJD7/Qjp1ltLC72UF7I04QPqLkTNXiYIUbh83lE8D6P qI/1/V3Rz/i9ea+1Q7TIPhxLJC0epNbZysQD2oisZBi73sQYcCq8mBgRma8Mv4S8KI 79IkEWklYyfvR/pp5se81yl7XOoFJZ50LTqpYdgtEHNd4klwuarw0kxpeDfNnr3zmJ LqBU2SnACBrx2yZ5SKNg3m9UjybeHnfUTlc8GatJcYbBnJE3YsVNSgvPMSJLS7FHg/ M9dIgk/6Kf7kqCTGT7u45sBjDL//mMflCmQpOjNH+k/XnbdQf2cyCbbY1Jg6OGcI9E FF1NHlqN4bxfw== From: Frederic Weisbecker To: Thomas Gleixner Cc: LKML , Frederic Weisbecker , Alexey Dobriyan , Wei Li , Peter Zijlstra , Mirsad Goran Todorovac , Yu Liao , Hillf Danton , Ingo Molnar Subject: [PATCH 8/8] selftests/proc: Assert clock_gettime(CLOCK_BOOTTIME) VS /proc/uptime monotonicity Date: Wed, 22 Feb 2023 15:46:49 +0100 Message-Id: <20230222144649.624380-9-frederic@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230222144649.624380-1-frederic@kernel.org> References: <20230222144649.624380-1-frederic@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758543384300603834?= X-GMAIL-MSGID: =?utf-8?q?1758543384300603834?= The first field of /proc/uptime relies on the CLOCK_BOOTTIME clock which can also be fetched from clock_gettime() API. Improve the test coverage while verifying the monotonicity of CLOCK_BOOTTIME accross both interfaces. Suggested-by: Thomas Gleixner Cc: Yu Liao Cc: Hillf Danton Cc: Ingo Molnar Cc: Wei Li Cc: Alexey Dobriyan Cc: Mirsad Goran Todorovac Cc: Peter Zijlstra Signed-off-by: Frederic Weisbecker --- .../testing/selftests/proc/proc-uptime-001.c | 21 ++++++++++++++---- .../testing/selftests/proc/proc-uptime-002.c | 22 +++++++++++++++---- tools/testing/selftests/proc/proc-uptime.h | 12 ++++++++++ 3 files changed, 47 insertions(+), 8 deletions(-) diff --git a/tools/testing/selftests/proc/proc-uptime-001.c b/tools/testing/selftests/proc/proc-uptime-001.c index 35bddd9dd60b..f335eec5067e 100644 --- a/tools/testing/selftests/proc/proc-uptime-001.c +++ b/tools/testing/selftests/proc/proc-uptime-001.c @@ -13,9 +13,9 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -// Test that boottime value in /proc/uptime increments monotonically. -// We don't test idle time monotonicity due to broken iowait task -// counting, cf: comment above get_cpu_idle_time_us() +// Test that boottime value in /proc/uptime and CLOCK_BOOTTIME increment +// monotonically. We don't test idle time monotonicity due to broken iowait +// task counting, cf: comment above get_cpu_idle_time_us() #undef NDEBUG #include #include @@ -27,7 +27,7 @@ int main(void) { - uint64_t start, u0, u1; + uint64_t start, u0, u1, c0, c1; int fd; fd = open("/proc/uptime", O_RDONLY); @@ -35,10 +35,23 @@ int main(void) u0 = proc_uptime(fd); start = u0; + c0 = clock_boottime(); + do { u1 = proc_uptime(fd); + c1 = clock_boottime(); + + /* Is /proc/uptime monotonic ? */ assert(u1 >= u0); + + /* Is CLOCK_BOOTTIME monotonic ? */ + assert(c1 >= c0); + + /* Is CLOCK_BOOTTIME VS /proc/uptime monotonic ? */ + assert(c0 >= u0); + u0 = u1; + c0 = c1; } while (u1 - start < 100); return 0; diff --git a/tools/testing/selftests/proc/proc-uptime-002.c b/tools/testing/selftests/proc/proc-uptime-002.c index 7ad79d5eaa84..ae453daa96c1 100644 --- a/tools/testing/selftests/proc/proc-uptime-002.c +++ b/tools/testing/selftests/proc/proc-uptime-002.c @@ -13,9 +13,10 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -// Test that boottime value in /proc/uptime increments monotonically -// while shifting across CPUs. We don't test idle time monotonicity -// due to broken iowait task counting, cf: comment above get_cpu_idle_time_us() +// Test that boottime value in /proc/uptime and CLOCK_BOOTTIME increment +// monotonically while shifting across CPUs. We don't test idle time +// monotonicity due to broken iowait task counting, cf: comment above +// get_cpu_idle_time_us() #undef NDEBUG #include #include @@ -43,10 +44,10 @@ static inline int sys_sched_setaffinity(pid_t pid, unsigned int len, unsigned lo int main(void) { + uint64_t u0, u1, c0, c1; unsigned int len; unsigned long *m; unsigned int cpu; - uint64_t u0, u1; int fd; /* find out "nr_cpu_ids" */ @@ -62,6 +63,8 @@ int main(void) assert(fd >= 0); u0 = proc_uptime(fd); + c0 = clock_boottime(); + for (cpu = 0; cpu < len * 8; cpu++) { memset(m, 0, len); m[cpu / (8 * sizeof(unsigned long))] |= 1UL << (cpu % (8 * sizeof(unsigned long))); @@ -70,8 +73,19 @@ int main(void) sys_sched_setaffinity(0, len, m); u1 = proc_uptime(fd); + c1 = clock_boottime(); + + /* Is /proc/uptime monotonic ? */ assert(u1 >= u0); + + /* Is CLOCK_BOOTTIME monotonic ? */ + assert(c1 >= c0); + + /* Is CLOCK_BOOTTIME VS /proc/uptime monotonic ? */ + assert(c0 >= u0); + u0 = u1; + c0 = c1; } return 0; diff --git a/tools/testing/selftests/proc/proc-uptime.h b/tools/testing/selftests/proc/proc-uptime.h index ca55abeb0ccc..730cce4a3d73 100644 --- a/tools/testing/selftests/proc/proc-uptime.h +++ b/tools/testing/selftests/proc/proc-uptime.h @@ -19,9 +19,21 @@ #include #include #include +#include #include "proc.h" +static uint64_t clock_boottime(void) +{ + struct timespec ts; + int err; + + err = clock_gettime(CLOCK_BOOTTIME, &ts); + assert(err >= 0); + + return (ts.tv_sec * 100) + (ts.tv_nsec / 10000000); +} + static uint64_t proc_uptime(int fd) { uint64_t val1, val2;