Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp30151676rwd; Thu, 6 Jul 2023 01:26:30 -0700 (PDT) X-Google-Smtp-Source: APBJJlHlWk0tby9ssVNlndxB3EV/+ZQPGUWOoc4xMGfiSiRMGVc3K4lG06BcG5S9m6NViq3Z+tVm X-Received: by 2002:a05:6a20:607:b0:127:159d:182a with SMTP id 7-20020a056a20060700b00127159d182amr701258pzl.27.1688631989731; Thu, 06 Jul 2023 01:26:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688631989; cv=none; d=google.com; s=arc-20160816; b=nqytcRgeg1eS8Rt/GbOosqWGkJKl4Xwv+gsuitRX5vTXRPnb1CeNGatw2kRvpg1tXt 6xByQ1EL8slvjhGHIITgLSi1S3NgDKigtLOO/Z4w1Rdfsi2E5qghjOaGJTQAZ7LlS6np 7NYZM7kqn4aTfwfu4ISlnnToFl5mb3YM7NEpNrt1zlwZR38+GRjojrO20Bbnk04e3gwH tZKggpXtqG9eZO34IEpvzSYYEtZ3eJYF+nFffB5CFxj8D+iNKx8q24UzgE9VlyMeIciq 4zjhGtNkeLD/TABqh1Ui1vVSku0XbL8kPRICy/NQYDmhP0XS/pXFl78f0BdJJKqpv34M 3Ahg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=pgG4Ij8rmZfqMBm2oqM6Ju2PS6yYhcktMwLW4JNMQGU=; fh=aJ6s+BgCzcCDsA0zhTSWQHByq97989HQKFTrb9duh9E=; b=Xy6OACEdED0xF1Oeb5HyBmVB3cSuwPmY93K3xFIItTFRoGZUEaMVi+PgKAU8gZ+nYk SliUqDvgFAjqYVfQLRX3rW1bubmoVW16DxyuLsy9gZc0JicEuhzj+D5O1Dznq9taXx8x rj1AvNEc1NnOW6GtoUTIDrlxxa4vuT5EZetqn5GsKB2eIad1IDktq7zoKNiadYWQyuP8 T5Yts9Fx3DZcs0effAcjT49fNlomVv80J+e53PyaspQfYd7rjGvbBju/qZdCXgSSwdMZ bIc4a4h9031VEHYgaJQu7Xrie3uhDXAGvysg1ZAJTp+a6J1YVP4/k/XFZFeYuQdCIqsG RthQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b="ebgLCz/p"; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ju4-20020a170903428400b001b8b37f6b46si769903plb.556.2023.07.06.01.26.15; Thu, 06 Jul 2023 01:26:29 -0700 (PDT) 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=@gmail.com header.s=20221208 header.b="ebgLCz/p"; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233817AbjGFINP (ORCPT + 99 others); Thu, 6 Jul 2023 04:13:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232731AbjGFINO (ORCPT ); Thu, 6 Jul 2023 04:13:14 -0400 Received: from mail-oi1-x22d.google.com (mail-oi1-x22d.google.com [IPv6:2607:f8b0:4864:20::22d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5464110 for ; Thu, 6 Jul 2023 01:13:13 -0700 (PDT) Received: by mail-oi1-x22d.google.com with SMTP id 5614622812f47-3a1c162cdfeso440509b6e.2 for ; Thu, 06 Jul 2023 01:13:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1688631193; x=1691223193; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=pgG4Ij8rmZfqMBm2oqM6Ju2PS6yYhcktMwLW4JNMQGU=; b=ebgLCz/pKdH6r29bkq3wNtiOBu92/5gohz0mqsiCkHyMfi9lqkaYS6l2h2dj3IY8IG uqi1S0meqlthR7q73+9Ph6hHlgauiN6eAQ7kzDWh+t9MlC8bm1LhP4UMaktOWBF5Nhp0 B6rmppTNSLgqixTmuTcHUmerHy57ZJxJj7JtHA8Rp31qItNVGXrDkXwBLezXO6QA2Ym+ c7Y0NNz4pfUqtskpVYMeY1xLimF7Vw6ukLPyzNIptcaF2r4EQKe7/n+A7fi1bfCoB7GA 2QBjmjOo2mNeLd8ez3jgLlo7e7sV+9Ru+jOwHQMZvl0b2zDagYmSbWa1RfG8C2Ite883 4pmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688631193; x=1691223193; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pgG4Ij8rmZfqMBm2oqM6Ju2PS6yYhcktMwLW4JNMQGU=; b=j3c/2f6pCvHhGBIRtu8W9SFz7HWXCWNKS/hEtJDUk4uEFc7yCkwQ/Z9ePcq7psje1D p/mco/H9Cg9aYb5HgUDs9IqDi4j0A+elMFl2kQ2/+3mcyZuHibDnLuTTpYefuBwvfTMG yz/h1jqrFppKDzoHh4cZmddBCyDU18q25jq4vFpTbPyUxL6rN5re0bzVOEiZR2LIdpsG RhnQphOHnzGbfSt5nxy6OrxTq/qzyQWCaIMunsaVvxdqnXipKbZPnnDINsRDoBWvuh/U ptf+qsDFM89ny3fz6tpjOsxCnbeyjLzjEXNJuZFt8QpS9ItfINfo69mUEwDQ7NTM5BBv 8/Rg== X-Gm-Message-State: ABy/qLald9KT5NEBHjMshdDcQI4N16pdpo36aWNKnmDimmISGjLmYIoH kIZPzc1m6/OuzNdtdlVPXwlVJ4Wc/RUQ4JXw4eaxb0bvz9Q= X-Received: by 2002:aca:2b04:0:b0:3a3:6ae3:bd9 with SMTP id i4-20020aca2b04000000b003a36ae30bd9mr923814oik.55.1688631192886; Thu, 06 Jul 2023 01:13:12 -0700 (PDT) MIME-Version: 1.0 References: <20221121035140.118651-1-zhouzhouyi@gmail.com> In-Reply-To: From: Zhouyi Zhou Date: Thu, 6 Jul 2023 16:13:01 +0800 Message-ID: Subject: Re: [PATCH linux-next][RFC]torture: avoid offline tick_do_timer_cpu To: Christophe Leroy Cc: "fweisbec@gmail.com" , "tglx@linutronix.de" , "mingo@kernel.org" , "dave@stgolabs.net" , "paulmck@kernel.org" , "josh@joshtriplett.org" , "mpe@ellerman.id.au" , "linuxppc-dev@lists.ozlabs.org" , "linux-kernel@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 On Thu, Jul 6, 2023 at 3:09=E2=80=AFPM Christophe Leroy wrote: > > > > Le 21/11/2022 =C3=A0 04:51, Zhouyi Zhou a =C3=A9crit : > > During CPU-hotplug torture (CONFIG_NO_HZ_FULL=3Dy), if we try to > > offline tick_do_timer_cpu, the operation will fail because in > > function tick_nohz_cpu_down: > > ``` > > if (tick_nohz_full_running && tick_do_timer_cpu =3D=3D cpu) > > return -EBUSY; > > ``` > > Above bug was first discovered in torture tests performed in PPC VM > > of Open Source Lab of Oregon State University, and reproducable in RISC= -V > > and X86-64 (with additional kernel commandline cpu0_hotplug). > > > > In this patch, we avoid offline tick_do_timer_cpu by distribute > > the offlining cpu among remaining cpus. > > > > Signed-off-by: Zhouyi Zhou > > --- > > include/linux/tick.h | 1 + > > kernel/time/tick-common.c | 1 + > > kernel/time/tick-internal.h | 1 - > > kernel/torture.c | 10 ++++++++++ > > 4 files changed, 12 insertions(+), 1 deletion(-) > > > > diff --git a/include/linux/tick.h b/include/linux/tick.h > > index bfd571f18cfd..23cc0b205853 100644 > > --- a/include/linux/tick.h > > +++ b/include/linux/tick.h > > @@ -14,6 +14,7 @@ > > #include > > > > #ifdef CONFIG_GENERIC_CLOCKEVENTS > > +extern int tick_do_timer_cpu __read_mostly; > > extern void __init tick_init(void); > > /* Should be core only, but ARM BL switcher requires it */ > > extern void tick_suspend_local(void); > > diff --git a/kernel/time/tick-common.c b/kernel/time/tick-common.c > > index 46789356f856..87b9b9afa320 100644 > > --- a/kernel/time/tick-common.c > > +++ b/kernel/time/tick-common.c > > @@ -48,6 +48,7 @@ ktime_t tick_next_period; > > * procedure also covers cpu hotplug. > > */ > > int tick_do_timer_cpu __read_mostly =3D TICK_DO_TIMER_BOOT; > > +EXPORT_SYMBOL_GPL(tick_do_timer_cpu); > > #ifdef CONFIG_NO_HZ_FULL > > /* > > * tick_do_timer_boot_cpu indicates the boot CPU temporarily owns > > diff --git a/kernel/time/tick-internal.h b/kernel/time/tick-internal.h > > index 649f2b48e8f0..8953dca10fdd 100644 > > --- a/kernel/time/tick-internal.h > > +++ b/kernel/time/tick-internal.h > > @@ -15,7 +15,6 @@ > > > > DECLARE_PER_CPU(struct tick_device, tick_cpu_device); > > extern ktime_t tick_next_period; > > -extern int tick_do_timer_cpu __read_mostly; > > > > extern void tick_setup_periodic(struct clock_event_device *dev, int b= roadcast); > > extern void tick_handle_periodic(struct clock_event_device *dev); > > diff --git a/kernel/torture.c b/kernel/torture.c > > index 789aeb0e1159..bccbdd33dda2 100644 > > --- a/kernel/torture.c > > +++ b/kernel/torture.c > > @@ -33,6 +33,7 @@ > > #include > > #include > > #include > > +#include > > #include > > #include > > #include > > @@ -358,7 +359,16 @@ torture_onoff(void *arg) > > schedule_timeout_interruptible(HZ / 10); > > continue; > > } > > +#ifdef CONFIG_NO_HZ_FULL > > + /* do not offline tick do timer cpu */ > > + if (tick_nohz_full_running) { > > Can you use fonction tick_nohz_full_enabled() instead and avoid the #ifde= f ? Thank Christophe for your wonderful advice, I will follow your advice next time I prepare a patch. For this false positive report, 58d766824264 ("tick/nohz: Fix cpu_is_hotpluggable() by checking with nohz subsystem") has beaten me in mainline. Thanks again Zhouyi > > > + cpu =3D (torture_random(&rand) >> 4) % maxcpu; > > + if (cpu >=3D tick_do_timer_cpu) > > + cpu =3D (cpu + 1) % (maxcpu + 1); > > + } else > > +#else > > cpu =3D (torture_random(&rand) >> 4) % (maxcpu + 1); > > +#endif > > if (!torture_offline(cpu, > > &n_offline_attempts, &n_offline_succ= esses, > > &sum_offline, &min_offline, &max_off= line))