From patchwork Mon Feb 20 12:41:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Weisbecker X-Patchwork-Id: 59429 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1285937wrn; Mon, 20 Feb 2023 04:45:49 -0800 (PST) X-Google-Smtp-Source: AK7set/Le22XVCGT0CG6ee5q1BV0YFmIpI7aTVIZibrU4SvVMDwcbZas70PyIcqlYCU9TYmvuVVN X-Received: by 2002:a17:903:11c4:b0:19a:aa9c:c651 with SMTP id q4-20020a17090311c400b0019aaa9cc651mr980132plh.62.1676897149444; Mon, 20 Feb 2023 04:45:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676897149; cv=none; d=google.com; s=arc-20160816; b=dtacpvVXGwI8ThuG7rVNeBuyjdX3EeMIth2bQiGn4KO2vRT59QyttDPb0mcafhmMo3 JheKVG0+VNBRNCMDL+pr4IsIa64GqXUuRtmaKNTzre6IbFmLgXsmVIGafD9JcsvcHzO1 k6AW/8nBDA3D/sFwu/tQSREeLxXYNe6/As18hfO1AZTw94sda58zcR9vvOqR9fGjvDrP xu7UqdzFoOA6Jfy0VhmTJCEwuKfePnklCSTKqGnfehncJ/bbkMSdWXdMyYyPqN64U37m ZwCdDdnE/YAvu+2C2BcJc+UeN7lBatdnA/uVw+8keFT4jOU5YQ00ngnfyKNSVRX9YvLt 807Q== 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=RrGNexfdnU/KaclcZTfqiBa7wdE7iHuZUdtypZqrJNjQt63h7xlQe/C2Oa7FJCg29P z++P/d1TfYxE1E/oAE/Ej56LYpKrT/7J3rJJQx+nqQ1LHladHox//wjCKQ9nwuF00Plw V4llZxGkFwo63KHCx55Wxk+6uBdhAG/rrcTxBvRgWgVXb8pGkkiXkturcwHBhhmRNkTD 3zvVRPqoGtj/SI7OoCePA+vtm2OoJzL/IsZRVVu9+m9mQywRqQf4H9bnIEkLFv9IlpBR NOG+CzJ5vpOp5Bb5v3/u8Jd+PAkQ5w+8Iw/m9sTQQXmQEzRK+IcZYQqSjt7Pg0RjGXBj faYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ISFWCT7G; 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 u17-20020a170902e5d100b001967580f631si10064865plf.559.2023.02.20.04.45.28; Mon, 20 Feb 2023 04:45:49 -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=ISFWCT7G; 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 S232117AbjBTMls (ORCPT + 99 others); Mon, 20 Feb 2023 07:41:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231602AbjBTMlp (ORCPT ); Mon, 20 Feb 2023 07:41:45 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23C201631E for ; Mon, 20 Feb 2023 04:41:43 -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 78BF9B80D1B for ; Mon, 20 Feb 2023 12:41:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id ECF13C433EF; Mon, 20 Feb 2023 12:41:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676896900; bh=i0suEjF1OVttZE4v7oGGN5lbF5fnEyMlbmcS3axNMpQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ISFWCT7GnY6ma8xY3Xn7Adcb1NiKLhMPN37QFqmvBPvqOHDpYv9letsbSA2cOcS+m iD7dO6J/Riu4URk86D6B42VspMhqzz453EHeB3MvDbay6hFcJW9JlFDQhee54LsZRQ W4zqo6Bs/ZUuxrw5MYyKSn4SudeviX/Be+9qb7P/aqE1M0G7mvQEg/vx2b8Ls/fX3d xDRb5MlHx0Vo/6O/CobPrGEpDF/jPF6cy6jBdDWOmtuqzeFPVYnUKxp8IhQQ7VuleW pusry7+ZnQl75NM/6Xwk7NSIuCeaWHMOntEkf49YQLG07NURUOrK0F1BLjDm6ZITrH Zd0CBr840Hrkw== From: Frederic Weisbecker To: Thomas Gleixner Cc: LKML , Frederic Weisbecker , Alexey Dobriyan , Peter Zijlstra , Wei Li , Mirsad Goran Todorovac , Yu Liao , Hillf Danton , Ingo Molnar Subject: [PATCH 1/7] timers/nohz: Restructure and reshuffle struct tick_sched Date: Mon, 20 Feb 2023 13:41:23 +0100 Message-Id: <20230220124129.519477-2-frederic@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230220124129.519477-1-frederic@kernel.org> References: <20230220124129.519477-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?1758354104931237793?= X-GMAIL-MSGID: =?utf-8?q?1758354104931237793?= 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 Mon Feb 20 12:41:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Weisbecker X-Patchwork-Id: 59427 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1285860wrn; Mon, 20 Feb 2023 04:45:42 -0800 (PST) X-Google-Smtp-Source: AK7set9KlMge2r6IXIRyeHqY4LzTUeqQ7XGPkrnC91QSnG/GASJTdCpcmnnJxeR1SgRQb7nH4ceI X-Received: by 2002:a17:90b:4c87:b0:233:d181:5b75 with SMTP id my7-20020a17090b4c8700b00233d1815b75mr3592671pjb.31.1676897141758; Mon, 20 Feb 2023 04:45:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676897141; cv=none; d=google.com; s=arc-20160816; b=ApGLloZgWQLCjJBFVOH7hiH9eb9v0nKtqeB+vIvNKHV/Obu4H6g05A+ubLdEjqp8VZ N0Z4JhvSqBHvZ0amMFKXFjBf+fTjVtbfgXq9ebuCjl+c5HdZKVAt1TMo8De6O7o82f/O G9CJn5b897fV1gPp23jJCUYoeY5XJZOKjCZJV3BtAo9K3EVMWp3fDVfL5v+oazQIhOjB cpt+HlYRQlW2V6tRDarZ0LGw5RJoKUOUoFcvgjQjNMpcX+v5t8zDX3mA/0F9dolCzcOf X29zqwxk0qCo8Pn3PA5Yi0NZ5KR0lnPk/Ta+G34EWb54RdUw59lD2BYwZAbNDZa0CVn9 cEXA== 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=MjFJlfy3WLQdIPdHz+XfwfRgoJjTBm/qeIEr+zlJ9gaJZdLOAtz9QaNwpoQUmXPawz 0/RQAyZUCT2FwZzgGP0XVX5T4Nc67ah5F1MmJH7opBRjlHQTldrKoEaGo56uRfeRz1iq 6/pKkEHLa0GwzB+qg7dGAam7jaTr8eOwFRQBlHg1dPX5NJ1NRm3Ycuv60MDPUiaXWs1u q7Sx5aX46WEvMSSQrzh7MWJmKDkm5f/ecFP7mMmlLHsaojja2gUcspBk356Xoa/AH1ts C8qflT1t1LoAtVfTMrJVPDZm4ER8qrf6EZQjcqohM21jbggNNWfuTLFVg36wov8Sno/o Xwpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UJ8Yqu4T; 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 y1-20020a17090a134100b0022be3049e52si6925197pjf.34.2023.02.20.04.45.29; Mon, 20 Feb 2023 04:45:41 -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=UJ8Yqu4T; 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 S232129AbjBTMlv (ORCPT + 99 others); Mon, 20 Feb 2023 07:41:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232112AbjBTMlr (ORCPT ); Mon, 20 Feb 2023 07:41:47 -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 5A80A1C5B0 for ; Mon, 20 Feb 2023 04:41:45 -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 F414DB80D1C for ; Mon, 20 Feb 2023 12:41:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 922B6C4339B; Mon, 20 Feb 2023 12:41:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676896902; bh=Wy5hbT4ewIbxtuRGZo3BNmMi3nK/RbjQJn9sH1g4yFs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UJ8Yqu4TY3MNStEp3/quqlin7WksyZLlHo4C3AoWniZJ/dh/ikKCGQXs/rWPS3mNr 1B2+prIa8HCPmavA6vpDDclIuRUV3Oasst3UtDObPJo/xDlGbh5AEHo6W8i6dlx9yV o71lgevA2iwWZHH88EgcBoMAvi21YdIiqzBiSKJxX/az66jrPBfbFh/gi344T764aD R8VQSIlMOW2sKS5aX7VJZmxrqyQuYEeU+XSr9MZLHAGhwEumyNe+JO0yMtwb7nhIym MIOKDje7m1Qu9VJzy2B+T2tDuwh3Rd/zYQfk0yQ1XX6UYm3l4xWqpqpd/GuKHaU3t/ L/K40Nm3tv0tQ== From: Frederic Weisbecker To: Thomas Gleixner Cc: LKML , Frederic Weisbecker , Alexey Dobriyan , Peter Zijlstra , Wei Li , Mirsad Goran Todorovac , Yu Liao , Hillf Danton , Ingo Molnar Subject: [PATCH 2/7] timers/nohz: Only ever update sleeptime from idle exit Date: Mon, 20 Feb 2023 13:41:24 +0100 Message-Id: <20230220124129.519477-3-frederic@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230220124129.519477-1-frederic@kernel.org> References: <20230220124129.519477-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?1758354097216478685?= X-GMAIL-MSGID: =?utf-8?q?1758354097216478685?= 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 Mon Feb 20 12:41:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Weisbecker X-Patchwork-Id: 59426 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1285641wrn; Mon, 20 Feb 2023 04:45:16 -0800 (PST) X-Google-Smtp-Source: AK7set+BnQVlwuMZoiorodugHjfElDAPw39DOrsQJZdKPBGzV3MWdbG9eOgnijTHNvTbimyXIRJV X-Received: by 2002:a05:6a20:7d9c:b0:bc:246c:9bdf with SMTP id v28-20020a056a207d9c00b000bc246c9bdfmr703528pzj.1.1676897116164; Mon, 20 Feb 2023 04:45:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676897116; cv=none; d=google.com; s=arc-20160816; b=nmPg9xpE894hC6u0TRnMIiM8Jdb8f32SMhH9r2RSzI8fOSAV+Mn9ZJ9ITR7S3/gHLE QwMCviqhzk67Dd+zS2Kjm8LApj3PxI4OMFTfn27tEiAW9T18ucgY9NPM77mM7mlqmGgv opYNmCr9lgViESK/fNjBQGR3BHHh8LITYmTD5RCXdkto1K3Jek+JojIcLt6y7epKCdV3 nUYqtFJOUbkIwRJjA/RV+HdbxoZqIyuCqt73svbqbUyxWjmRLIOsKiQSKozcJqfUYjz3 6+4PLgyUpXp0lMmV/R2SbJZk1Np7I3nIyjpkM7gLYXFeAkexvp7yzIGy8EvEszemILk+ 4ZTQ== 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=rSYrohAJnk2x5qIEUC94ycer4Nmu4n8y3T7VLsAItG9boT88L2LRJAzrGMVC9r+3aa dZCCTcMJajM8rXje12rXj9Fa6/sOWW4wsofDwSzT4uSuFNZyDFKTIsCMr6ZYLlh70Igk tqKtDPdatmPNN4FjN6D/dbjD+m3yMwXBK9/sR2N1ESw23h9dVecJrWZs1+7a4YfWfMk6 IK6H9DCHxme1Xr24YE8iXZSwIdogEJTe1dp9caqhr94KJaIa2DAUaRwqnWP0kl9asQ0V F8TLI7W9Zy1zt0hI0wubQXmKMAPqVnW2vgHpJrf9MvXeG4lFtdE/W5s90yNPqbik1KZn p/lQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=HhSXVcdg; 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 u185-20020a6385c2000000b00502b0909af2si7352992pgd.71.2023.02.20.04.45.03; Mon, 20 Feb 2023 04:45:16 -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=HhSXVcdg; 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 S232138AbjBTMlz (ORCPT + 99 others); Mon, 20 Feb 2023 07:41:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232122AbjBTMlt (ORCPT ); Mon, 20 Feb 2023 07:41:49 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16A921C32E for ; Mon, 20 Feb 2023 04:41:48 -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 B88ECB80D1D for ; Mon, 20 Feb 2023 12:41:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 36ABAC433D2; Mon, 20 Feb 2023 12:41:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676896905; bh=5sxyMTW09Kl3ct1nkcDaj+gcruIUS7UwkGWllRn6QWo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HhSXVcdgC6xEPlUxPKP49VgnejEr9wrqf4dGce43aXAn2W68mjRZi3Z51o58oLw0i ePRSOGz/OIswWofrZXxN5RNZi8lt7FAaefHaTsu+kZqp7MJ7knumFmhcvnI1B7jizk 2IlEOtdEArdBjsbsSbD9jhCo6PUBKB6X2iJT8Cp5TkT3BnDFydel2Vmt5C04p4+Rzj Vk9l5bbyYT0G0tLK8Oj4H889QtilvdxjzAydXpb3FLJE8MDHGxxcVlFRcRV2D5ZdgB nN03UHuOd9HOj6Y6rblB1FNd9+5h2p/qeymTk61SmAmYDpu+WCOQ7DGrgO1SJRTvJ5 8a97N3yOdP4Hg== From: Frederic Weisbecker To: Thomas Gleixner Cc: LKML , Frederic Weisbecker , Alexey Dobriyan , Peter Zijlstra , Wei Li , Mirsad Goran Todorovac , Yu Liao , Hillf Danton , Ingo Molnar Subject: [PATCH 3/7] timers/nohz: Protect idle/iowait sleep time under seqcount Date: Mon, 20 Feb 2023 13:41:25 +0100 Message-Id: <20230220124129.519477-4-frederic@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230220124129.519477-1-frederic@kernel.org> References: <20230220124129.519477-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?1758354069948601792?= X-GMAIL-MSGID: =?utf-8?q?1758354069948601792?= 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 Mon Feb 20 12:41:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Weisbecker X-Patchwork-Id: 59428 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1285910wrn; Mon, 20 Feb 2023 04:45:47 -0800 (PST) X-Google-Smtp-Source: AK7set/p2lnJNIuD0byUYXiubo91ZsKY6wF7/c2xv9zwhVmKoD4LD5iMKVnt9i0fdyrkwqYqYHRO X-Received: by 2002:a62:1c41:0:b0:5a8:46b0:8269 with SMTP id c62-20020a621c41000000b005a846b08269mr2708502pfc.31.1676897146803; Mon, 20 Feb 2023 04:45:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676897146; cv=none; d=google.com; s=arc-20160816; b=KykJU5xBj1aixa4RibqZdMCiZHDZjLjvKivTLxM5WiiIJ5oSiLMyCCDrnBX1211CXx 396tkByz6/TEgPsYpEW3FxYu79TC5USIITxxNukslYBFMm9LlFjUV1HTgMNHTWjR0iuD iUoWxkDrUfcRMkYRibQDZPTQk4IIGpgeVnxHdAByBzIg9Nz7SY09V9vgV0aRnmRZfHtF HeygCyh7lGqbGtNTTjKPiOhdNN48WEN6JdTBSYG11OcrWCgZo0F8BRBFzWMdv71spGnA /mOQkl+N2ZjUCkAQbOXPsv8ZTXQX4By2A5CEqCzdfRlFv0EAPD1AoJsdhctAWwUvYHTN ylmw== 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=wYdKh67bzZwi34NtyyLgEQsX0vUJk/W8cDlX/u8REMlzcRi3Hm/xlbn/IzdzrkTvh2 YR+8p7QFYbUbGkK/pM+Qwwfll7SboQhxGizpbEAOc30lDAdUpG74wX5xTmp8joUIAoCH RZOanKFidSkaFeXSB8rgjJ3mX7Ln1tCtftYrPSQeDsXwZyJGiXaj2xoAcvIL7K+147Kj gh2wvnGE0yYz27OaxtSZOAkS1ch679CREhyDxQpy0KBaXyTHqtHuwRUiuAGdeauikRY3 HQC1aBNb2TUk9BVF7cLY803neN1YEp21SgW7cVXWcqkO3Y6IQoFhSvw8gS0u89QdqJqh SjVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="PW/cfZUR"; 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 f17-20020a056a001ad100b005a8f32ae10fsi15288050pfv.308.2023.02.20.04.45.33; Mon, 20 Feb 2023 04:45:46 -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="PW/cfZUR"; 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 S231243AbjBTMl5 (ORCPT + 99 others); Mon, 20 Feb 2023 07:41:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232124AbjBTMlt (ORCPT ); Mon, 20 Feb 2023 07:41:49 -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 ECEC61BAF2 for ; Mon, 20 Feb 2023 04:41:48 -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 8D8B260E33 for ; Mon, 20 Feb 2023 12:41:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CC05CC4339C; Mon, 20 Feb 2023 12:41:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676896908; bh=60UVPMKRBBZlhZputsHs6D/GUWH9jHmYFrcL5ldfROQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PW/cfZURgb8rw72fj8OFpH2k/DraGTS8gVcDyP305YoNKlpHDRioW9LsBiA7vPQOp Flgz9pbIQbhsiWWlFjoLpfC8hDdVX8Bk4OuXEHhiEl6znb/tocE/D68iLJp8BwR9Vs Kil48MoAV47ng/G5qZUxpdaTvWPnppG/5QjFqegLjX+qXSzuahgwUstYDZMYjPF+O8 emFAvnmIYNw32LTP2LLKk5NIvMtDlQFDh7VwJXgi4luIeewp0Pz6GM2+c4h3I+JLyg 9mfkcXtlucp6lY+q8D7WRfxsMIGHi3ZuAZVBOJ8lzVFxm8N5nJ2LjVf5MaW0nNKyPc G2hja8GTgz2rQ== From: Frederic Weisbecker To: Thomas Gleixner Cc: LKML , Frederic Weisbecker , Alexey Dobriyan , Peter Zijlstra , Wei Li , Mirsad Goran Todorovac , Yu Liao , Hillf Danton , Ingo Molnar Subject: [PATCH 4/7] timers/nohz: Add a comment about broken iowait counter update race Date: Mon, 20 Feb 2023 13:41:26 +0100 Message-Id: <20230220124129.519477-5-frederic@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230220124129.519477-1-frederic@kernel.org> References: <20230220124129.519477-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?1758354102601523235?= X-GMAIL-MSGID: =?utf-8?q?1758354102601523235?= 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 Mon Feb 20 12:41:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Weisbecker X-Patchwork-Id: 59430 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1286497wrn; Mon, 20 Feb 2023 04:46:59 -0800 (PST) X-Google-Smtp-Source: AK7set+shyrmbkYwPsiKH6YLXSWe8e5KSh9j3PHsHGl0N6NHPM1rUCcT15qQtlN50v8MP5vcEGNK X-Received: by 2002:aa7:8ecc:0:b0:5a9:b910:6d98 with SMTP id b12-20020aa78ecc000000b005a9b9106d98mr2115728pfr.13.1676897218978; Mon, 20 Feb 2023 04:46:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676897218; cv=none; d=google.com; s=arc-20160816; b=kd+IfLR0QpjYrY4ezgRsWbVuzdvDD+yEVIfBJvzYF/Sb3DSmwH8yVzv63eJhifXxFf b2jFdmsb52//6EZUBT2uYgExKDMU2V/KeEkdtPc/CfvbaWqdsFQYnqFHymv9hANSyzci LEWtDlzeZ47Nk4iN9jkhzq5MBOp+yO7GqsYk/xmQJMeSN8Q4t22uuWYVAarO9f8jN/sA jfAQrdRH9a2sAcfIg0ZsJQnTBuNxKTwfZU/1Jau7J9alwRLHlVJbAdXJn/z5MHmoqAYa t9FMGV9+tABCDuhw+nnBN4jdFhsfWwBv+F88VvnQKpTVfK9Grw8qrl4/ShGjIZo5fbaY qdbg== 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=0Dj8g6B01fVsQhRMTZ8yn4MhzI86yy1qwQ023jyyrHbPgBFqO/x1k873z1kZQl2e+p XtI9PPCzJpzcFC3K4YIWk5U3D2RhbZtOf7eOT1KzJ36GwOlXQwFKHAW1j7/eAdtqLsy/ onB0NE7GtTykluitrrMrz3oOrIRDJnN/34JNCe4nGMN3SXAyrGphW4ioYUwlt5AXNmbC PKUxTH2cY6FjWKimH/ka9dZ4SqIEn3bP2BYSCi7qCMXfwoepTnRl+HnoxuQfkc2rbpJU JQwuqYeqR7xh+nnSouiPGNnK5YvkIiOTtf/gYxqyM81cYJjo8Nw8A+YaHNWk+etRvpd5 +yXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=a5srEQPi; 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 67-20020a621446000000b005a90fe6a3afsi13715891pfu.228.2023.02.20.04.46.45; Mon, 20 Feb 2023 04:46:58 -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=a5srEQPi; 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 S232130AbjBTMmB (ORCPT + 99 others); Mon, 20 Feb 2023 07:42:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232126AbjBTMlw (ORCPT ); Mon, 20 Feb 2023 07:41:52 -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 8F54F1C7D9 for ; Mon, 20 Feb 2023 04:41:51 -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 2FA9560DFE for ; Mon, 20 Feb 2023 12:41:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6F66DC433EF; Mon, 20 Feb 2023 12:41:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676896910; bh=/vEaMsqtOE5BkbGfNS7gZR33SAARhK8GonMdLs7ceS0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a5srEQPiwndG2qYWSkwb6rz1hH5ZVUDeQ2bFUcDI6YBO+xzbD/iIfGszglsuGKp5e MH7Ad4jfdvMpfhuoJavBuWPhogEG7Kz800j04tctQ6gZNCI6dfGJYU/TZ8PWSxkvYf 4nPImLjb7Vd0cZtcctfDUsklZIC5ei4MAj9Jza9gPa9wo6Ur+1vUyoKzANBpVz7RM8 M/8Su6Lw/ro331OCHWm3ehQckWGNT//2EWfYRLxnjHdBKYQrrP0cmoGbJcyYYdivtR cSWmBMlDUiwQYK7K42MOUibMQG2vSYBxP7pAmQcSqR2ER/thhC8yWCDZKSuMnOTJ0S 2TZS50Vr4z6LQ== From: Frederic Weisbecker To: Thomas Gleixner Cc: LKML , Frederic Weisbecker , Alexey Dobriyan , Peter Zijlstra , Wei Li , Mirsad Goran Todorovac , Yu Liao , Hillf Danton , Ingo Molnar Subject: [PATCH 5/7] timers/nohz: Remove middle-function __tick_nohz_idle_stop_tick() Date: Mon, 20 Feb 2023 13:41:27 +0100 Message-Id: <20230220124129.519477-6-frederic@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230220124129.519477-1-frederic@kernel.org> References: <20230220124129.519477-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?1758354177850072513?= X-GMAIL-MSGID: =?utf-8?q?1758354177850072513?= 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 Mon Feb 20 12:41:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Weisbecker X-Patchwork-Id: 59431 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1286782wrn; Mon, 20 Feb 2023 04:47:29 -0800 (PST) X-Google-Smtp-Source: AK7set87OZaDZHubVFUmHQQHMiZoA5fZXW99wbcCES41WPRoySRaJzmSCzFaAPjt9ugPEhAwJXsA X-Received: by 2002:a62:184d:0:b0:5a9:fcb0:e8a2 with SMTP id 74-20020a62184d000000b005a9fcb0e8a2mr362712pfy.11.1676897248751; Mon, 20 Feb 2023 04:47:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676897248; cv=none; d=google.com; s=arc-20160816; b=Qefjiy2MTdCKvWEwgVT+/xJgxibJtZtnAEKr+0PEuxudcyA7DHTUotxvxNCyJY2/sF AHzF/SQEhd6w4MqXl91p0bCVdtt3U3Zd77siffytwsP5HMx73wYTrTjIaRTdmTM1Q2jd KldMZ1FEi0rVugq6aaBYbtL4s5vtoGOiOMsMnhbsJZ36F6dao1z8/6vqTkC7/EuUWImh 3+dlqDWBkifmR3k/O+ShfJGNHSqJ7xSr4hibnhuNFX1m/x6ONMshtz9mjagQ9Ndf/094 5fdaGBHKZf4bxRcFwm6qs1kTI0TJe2JdaytXQNRKqdBEBy1mLu16c6+jrKgL1+evqzWp 8ZLQ== 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=qkjH2LXhM/KRsVP1jRoefjCvZRd2adLtcIC8iyvYNnWeeP0uFsIWOSUnPINO5wxLRx FhW7CNhCuqLiKlEMHEY7EJBOIygQdsMf9FAzy57ON5Cj/fp5Up6+i6GcCU5mNn4ljXy9 Bcz673VcxeA/pBFOhtt8Dcjc1ZpOInfr5CLt7WroDFMikzL2oVMl1d2B2E+8ts/uuH0S vkKCGFhQKTicrylMY01IrTOiovw9a6tBI04Tmcyndv4oEq4gIFSz/auchhvLA//ebOuV Ms1eb2OI9gOo2d96ZUE281sLXov3EMGcHhFh/bcl23AwvfIVKqZh/WXzGBbiVGx7E4x/ Ouhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=GlbCimPP; 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 f17-20020a056a001ad100b005a8f32ae10fsi15288050pfv.308.2023.02.20.04.47.16; Mon, 20 Feb 2023 04:47: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=GlbCimPP; 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 S232139AbjBTMmD (ORCPT + 99 others); Mon, 20 Feb 2023 07:42:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230384AbjBTMlz (ORCPT ); Mon, 20 Feb 2023 07:41:55 -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 75DC81C7D3 for ; Mon, 20 Feb 2023 04:41:54 -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 C50AC60E33 for ; Mon, 20 Feb 2023 12:41:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0F07FC4339B; Mon, 20 Feb 2023 12:41:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676896913; bh=NHv2T4M6t3YcZt1kUoyxtpuC8v5xebDYXn942sZPC1Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GlbCimPPNQGcTfH8ASY5D50pKCtOsefO9GSslEo243k1D0GgcOHNUeGfnSV4q/05g ZcPdJxzg1TykmKZzVrzfMlhIe4Y3S0/1gaYvf8pryW2Xl5iqTQs4SPVB+YBDPGWbyf aTgF+UwXTikJIuFXqmErAnV27p/Bsi0tRROhJUXrLqRw1medHSv5hg4wMbp6gfJnZ1 H7pVwOMu0GEDJ0N27cIX9P9s43SXMxsTgePsT0ewh7r5poJEO+w1l6FDrZPQgvcqb4 iqGonbZBDu2ogpOHsdkvc4T06uC2101t4DXpLt19lV69a5sOxF7kbVhPChjcJI33We bQ26nxgy6Vm+A== From: Frederic Weisbecker To: Thomas Gleixner Cc: LKML , Frederic Weisbecker , Alexey Dobriyan , Peter Zijlstra , Wei Li , Mirsad Goran Todorovac , Yu Liao , Hillf Danton , Ingo Molnar Subject: [PATCH 6/7] MAINTAINERS: Remove stale email address Date: Mon, 20 Feb 2023 13:41:28 +0100 Message-Id: <20230220124129.519477-7-frederic@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230220124129.519477-1-frederic@kernel.org> References: <20230220124129.519477-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?1758354209120709601?= X-GMAIL-MSGID: =?utf-8?q?1758354209120709601?= 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 Mon Feb 20 12:41:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Frederic Weisbecker X-Patchwork-Id: 59432 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1286933wrn; Mon, 20 Feb 2023 04:47:49 -0800 (PST) X-Google-Smtp-Source: AK7set+xz0/4xIKNHj2hm4FwzTGzm9DjBuXanRYT5PXO/zoMWbuqdPWlQSIyTqX6PUxJDaf3+Wp4 X-Received: by 2002:a17:903:40cf:b0:19b:c29:a74b with SMTP id t15-20020a17090340cf00b0019b0c29a74bmr3202416pld.34.1676897269276; Mon, 20 Feb 2023 04:47:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676897269; cv=none; d=google.com; s=arc-20160816; b=DfJH923sdCQSbDOazbKX7RFa1e5Wj5iPBDn9D65pWCnm0kv2CgzhrHIDlU4cNRdrqA A8Zi8WjSpwq7g1Hi95N50wn6OY9tDNaANXlECcG8st7a1wsQXxw92BgXKqhbTR93lNwh 8Qqt+Onjo/K28LgI0nigD90fb18uTwaYBa6r5iZaB12WVtWfP6Q5DZaFyEoQ3wELITVl Rr4rxO4fwaJrJN35WWvz0rRUqPz+LL7CqkJebVqxw08gwZ1rjSHY3VDbtmgfV5LBv5Rv SOb9fMXGsIjIs//oafHi5T4jUxPztraWSkrMA8sh4ssVA0K37oRIjWr1Lb7ythIsalJL lrmQ== 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=JyyZ736I2S5mxtxKBF1yQBkr6kil37dvzfOZRORRTYQ=; b=zk8txe7MstAaTcUWgGR5MeiCNxiJn5e9SU7+2zHPMBNRq4BUwYAKqEBBroEQV2dUS6 Oo0DtD338teitHKI+98Qo9THwWhMfYdtFzAJ0XW4TlowAgwqKTkobHAJ7s3t8b304PYO /UPdWgTuUGYi5HTKTlyD4ULlJmiJZC8RR9Z1DzcNWB0YfB+LQVXdtastZSqdsbIcZ1F9 hTu67bMURXzbP1VjnOQoHeHHgZVxWMILlWJdBkutLgP4gaWoME/SjM+hRjl6aACyuvC/ p6seOYMPVkEUTZTUhhuFlGVtQxoRcK0UBDJ0PcNOR8H9Qc7zM5TT+5AP4mPs8jhaMbq6 tqQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=L9qKAj4H; 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 q15-20020a65624f000000b004d39932df65si577737pgv.585.2023.02.20.04.47.37; Mon, 20 Feb 2023 04:47:49 -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=L9qKAj4H; 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 S231485AbjBTMmO (ORCPT + 99 others); Mon, 20 Feb 2023 07:42:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232152AbjBTMmK (ORCPT ); Mon, 20 Feb 2023 07:42:10 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26B591C338 for ; Mon, 20 Feb 2023 04:41:56 -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 6518560E33 for ; Mon, 20 Feb 2023 12:41:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A56B8C433D2; Mon, 20 Feb 2023 12:41:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676896915; bh=z6ZAk/aZqoP3M/Jdn4qB71Qde9iJsRMdQIEllZtNeXE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L9qKAj4HXTLmXuTAcL8mdBRliasDKZz5QoFZupa/ML1Vxlc1S+l6fMCyzCy1IAdEm ymVagJrjN9JFEYpyuQySH9rGKMbqt7ZSBak79l0YtAfmStxYpaY+UVCgVDtbu8UbE3 O8Lf56aWy9eJE5FlukisaR08fzlsS8OYGVRvBvHioKtJIjKzvqkagQsR8qvUYV8Z52 yHGVTeslR920YEHkubXVff9O39L6rWBgfhp9A9mlKnlz165J4HuXHz5xy0IoQDx2pI 7FzTb0xk/cMipk9Jy03FjgqdHyCNstrlFOtn8FPi47dCgclKhdluyXy253ud8GJjpt 1BRUQNQqHXfIg== From: Frederic Weisbecker To: Thomas Gleixner Cc: LKML , Frederic Weisbecker , Alexey Dobriyan , Peter Zijlstra , Wei Li , Mirsad Goran Todorovac , Yu Liao , Hillf Danton , Ingo Molnar Subject: [PATCH 7/7] selftests/proc: Remove idle time monotonicity assertions Date: Mon, 20 Feb 2023 13:41:29 +0100 Message-Id: <20230220124129.519477-8-frederic@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230220124129.519477-1-frederic@kernel.org> References: <20230220124129.519477-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?1758354231029553489?= X-GMAIL-MSGID: =?utf-8?q?1758354231029553489?= 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 selftests 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/.gitignore | 2 - tools/testing/selftests/proc/Makefile | 2 - .../testing/selftests/proc/proc-uptime-001.c | 45 ----------- .../testing/selftests/proc/proc-uptime-002.c | 79 ------------------- tools/testing/selftests/proc/proc-uptime.h | 60 -------------- 5 files changed, 188 deletions(-) delete mode 100644 tools/testing/selftests/proc/proc-uptime-001.c delete mode 100644 tools/testing/selftests/proc/proc-uptime-002.c delete mode 100644 tools/testing/selftests/proc/proc-uptime.h diff --git a/tools/testing/selftests/proc/.gitignore b/tools/testing/selftests/proc/.gitignore index a156ac5dd2c6..448db45f08dc 100644 --- a/tools/testing/selftests/proc/.gitignore +++ b/tools/testing/selftests/proc/.gitignore @@ -13,8 +13,6 @@ /proc-self-wchan /proc-subset-pid /proc-tid0 -/proc-uptime-001 -/proc-uptime-002 /read /self /setns-dcache diff --git a/tools/testing/selftests/proc/Makefile b/tools/testing/selftests/proc/Makefile index cd95369254c0..22ff9341f97c 100644 --- a/tools/testing/selftests/proc/Makefile +++ b/tools/testing/selftests/proc/Makefile @@ -16,8 +16,6 @@ TEST_GEN_PROGS += proc-self-syscall TEST_GEN_PROGS += proc-self-wchan TEST_GEN_PROGS += proc-subset-pid TEST_GEN_PROGS += proc-tid0 -TEST_GEN_PROGS += proc-uptime-001 -TEST_GEN_PROGS += proc-uptime-002 TEST_GEN_PROGS += read TEST_GEN_PROGS += self TEST_GEN_PROGS += setns-dcache diff --git a/tools/testing/selftests/proc/proc-uptime-001.c b/tools/testing/selftests/proc/proc-uptime-001.c deleted file mode 100644 index 781f7a50fc3f..000000000000 --- a/tools/testing/selftests/proc/proc-uptime-001.c +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright © 2018 Alexey Dobriyan - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * 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. -#undef NDEBUG -#include -#include -#include -#include -#include - -#include "proc-uptime.h" - -int main(void) -{ - uint64_t start, u0, u1, i0, i1; - int fd; - - fd = open("/proc/uptime", O_RDONLY); - assert(fd >= 0); - - proc_uptime(fd, &u0, &i0); - start = u0; - do { - proc_uptime(fd, &u1, &i1); - 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 deleted file mode 100644 index 7d0aa22bdc12..000000000000 --- a/tools/testing/selftests/proc/proc-uptime-002.c +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright © 2018 Alexey Dobriyan - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * 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. -#undef NDEBUG -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include "proc-uptime.h" - -static inline int sys_sched_getaffinity(pid_t pid, unsigned int len, unsigned long *m) -{ - return syscall(SYS_sched_getaffinity, pid, len, m); -} - -static inline int sys_sched_setaffinity(pid_t pid, unsigned int len, unsigned long *m) -{ - return syscall(SYS_sched_setaffinity, pid, len, m); -} - -int main(void) -{ - unsigned int len; - unsigned long *m; - unsigned int cpu; - uint64_t u0, u1, i0, i1; - int fd; - - /* find out "nr_cpu_ids" */ - m = NULL; - len = 0; - do { - len += sizeof(unsigned long); - free(m); - m = malloc(len); - } while (sys_sched_getaffinity(0, len, m) == -1 && errno == EINVAL); - - fd = open("/proc/uptime", O_RDONLY); - assert(fd >= 0); - - proc_uptime(fd, &u0, &i0); - for (cpu = 0; cpu < len * 8; cpu++) { - memset(m, 0, len); - m[cpu / (8 * sizeof(unsigned long))] |= 1UL << (cpu % (8 * sizeof(unsigned long))); - - /* CPU might not exist, ignore error */ - sys_sched_setaffinity(0, len, m); - - proc_uptime(fd, &u1, &i1); - 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 deleted file mode 100644 index dc6a42b1d6b0..000000000000 --- a/tools/testing/selftests/proc/proc-uptime.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright © 2018 Alexey Dobriyan - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ -#undef NDEBUG -#include -#include -#include -#include -#include - -#include "proc.h" - -static void proc_uptime(int fd, uint64_t *uptime, uint64_t *idle) -{ - uint64_t val1, val2; - char buf[64], *p; - ssize_t rv; - - /* save "p < end" checks */ - memset(buf, 0, sizeof(buf)); - rv = pread(fd, buf, sizeof(buf), 0); - assert(0 <= rv && rv <= sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - - p = buf; - - val1 = xstrtoull(p, &p); - assert(p[0] == '.'); - assert('0' <= p[1] && p[1] <= '9'); - assert('0' <= p[2] && p[2] <= '9'); - 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); -}