Received: by 2002:a05:7412:1703:b0:e2:908c:2ebd with SMTP id dm3csp415831rdb; Thu, 24 Aug 2023 09:37:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEkqPWfWFcHSt6+3XjVgiB0KiKRYVltv7JyBBfpFEjdvqwBYRM57E12gEJWCU7oAoi5loqx X-Received: by 2002:a19:c215:0:b0:4fd:bec3:776a with SMTP id l21-20020a19c215000000b004fdbec3776amr9807527lfc.61.1692895070119; Thu, 24 Aug 2023 09:37:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692895070; cv=none; d=google.com; s=arc-20160816; b=jdbHeeREgXLlOhIhfKgafIuWtsXk4kuwNjTwQVdtSqjmipIHUKt/4zwN9CrrawGdr5 UA1QsPN/Q7cYxXyhH4Q/9nmejAF8/zHW9iz7UJ+tuImC8lC3/OY0MIWvfIbwojigklYY tNhIq10KH/HwiH2j3Dl8x1gKhpANE+skBY6bW74hwgd1KjzlnTiVnskDcT/zDOLjk4oN KKGGL0ByaOh7sgeEuvOSaOW3sHFvpMI/JEjkxYkVtoEAeFVHF4h52HV5PNXD2bL0o/kj tKklhcuAFFx6/UUQpt7rF+uHqqc9SUCmKQ1kJjddeHZV5ROkQai7A555ra3XKOsF5aLS pxyA== 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=GNgJbeJmVXNTPKg4Oonx1ooSzB446v2VWz+jWfaTK54=; fh=27qK38eVr4a2QBwyFuDqBWE5l+s9EdH8asNhBpr+ytQ=; b=PLIlBNVxp2RZ5n69ANmfYa9djQ694BCXaMJZOZJlY2gIhNbPk+/+B4Qxf+Hl7/ol8J P/o72mCd3QeXbT/OBDOBDiuFFQXiG9jvCkP2bPq+kQW8zPWZQmchZeZ3hmMwnTwojjOH FM5IwRfx8zUmX/B/6WyFBfunhpZY4S+PY6xFBp4NT77ttN8IjOgARFBv8Wsn0Uia+9KN p+TYZrroBurfmmVkNODyw0MPNEq84El3ngG99yFi5qkwYbv6Vqs0+VXrhjs8z/RrAxX6 z+WajPzfvvPAK7QoqH86xr97ZKBO2aKInw6VOvemqtKYf93zH02Dm8Gl5G8SB86f9Xf9 RVBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=j9k3htV3; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b23-20020a056402139700b005255da75263si11129246edv.224.2023.08.24.09.37.25; Thu, 24 Aug 2023 09:37:50 -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=@kernel.org header.s=k20201202 header.b=j9k3htV3; 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 S242036AbjHXPnv (ORCPT + 99 others); Thu, 24 Aug 2023 11:43:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239631AbjHXPnV (ORCPT ); Thu, 24 Aug 2023 11:43:21 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D98931B0; Thu, 24 Aug 2023 08:43:18 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 5FFAD672CC; Thu, 24 Aug 2023 15:43:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C03EDC433CC; Thu, 24 Aug 2023 15:43:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1692891797; bh=oaFb5X1E3CxVVHedDJqOBhCTpJrS00UOEDxgUG4FgBs=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=j9k3htV3ynVAYCdyxXle4nNI+vJcpsNeouK3rNAxywVkuBSoGOupVo/RuXlsSLZK5 Ph7EeDMUsOALKLu7Si1qjRtPBiPoHCRGPFQeEJhrucTE/0PaV02qxU+ZN7GHyCrhOY GVZVLhZfbHU6MfFNPCTzoQoDcUP1hNzfFcoalc3Hbo+0ZKkOPPbeqkLrJAP5fanwir osA14XPWPwX4hG3vae0SxnDIh1kAB00GXS/5B8rNM9h8XuZdfISKqR3kcnwoZR3Urz WSByJG6IIxMsXWFBUHAjvhf60KEXjVIYcCXlJ+kwIyUsFJp9B7lzX5hIgILyQ1M4Tj O0/w3lFdTs/FA== Received: by mail-lj1-f178.google.com with SMTP id 38308e7fff4ca-2bb97f2c99cso107140281fa.0; Thu, 24 Aug 2023 08:43:17 -0700 (PDT) X-Gm-Message-State: AOJu0Yz5X13uFXzOdRd5yZLl6CPWYA5pgmrP5ESqHjdnQ2oFqoYkrITy lNGhe9m5Z1ezko2CxqrGpiUlYVk0vU5iiRI8VRU= X-Received: by 2002:a2e:330f:0:b0:2b8:4079:fd9d with SMTP id d15-20020a2e330f000000b002b84079fd9dmr11989361ljc.29.1692891795701; Thu, 24 Aug 2023 08:43:15 -0700 (PDT) MIME-Version: 1.0 References: <5777BD82-2C8D-4BAB-BDD3-C2C003DC57FB@joelfernandes.org> <87ttspct76.ffs@tglx> <03fe7084-0509-45fa-87ee-8f8705a221a6@paulmck-laptop> <16827b4e-9823-456d-a6be-157fbfae64c3@paulmck-laptop> <8792da20-a58e-4cc0-b3d2-231d5ade2242@paulmck-laptop> In-Reply-To: <8792da20-a58e-4cc0-b3d2-231d5ade2242@paulmck-laptop> From: Huacai Chen Date: Thu, 24 Aug 2023 23:43:04 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH V4 2/2] rcu: Update jiffies in rcu_cpu_stall_reset() To: paulmck@kernel.org Cc: Thomas Gleixner , Joel Fernandes , Z qiang , Huacai Chen , Frederic Weisbecker , Neeraj Upadhyay , Josh Triplett , Boqun Feng , Ingo Molnar , John Stultz , Stephen Boyd , Steven Rostedt , Mathieu Desnoyers , Lai Jiangshan , Sergey Senozhatsky , rcu@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Binbin Zhou Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 Hi, Paul, On Thu, Aug 24, 2023 at 9:24=E2=80=AFPM Paul E. McKenney wrote: > > On Thu, Aug 24, 2023 at 08:40:00PM +0800, Huacai Chen wrote: > > Hi, Paul, > > On Thu, Aug 24, 2023 at 7:40=E2=80=AFPM Paul E. McKenney wrote: > > > On Thu, Aug 24, 2023 at 10:50:41AM +0800, Huacai Chen wrote: > > > > Hi, Paul, > > > > On Thu, Aug 24, 2023 at 6:41=E2=80=AFAM Paul E. McKenney wrote: > > > > > On Thu, Aug 24, 2023 at 12:03:25AM +0200, Thomas Gleixner wrote: > > > > > > On Thu, Aug 17 2023 at 16:06, Huacai Chen wrote: > > > > > > > On Thu, Aug 17, 2023 at 3:27=E2=80=AFAM Joel Fernandes wrote: > > > > > > >> > If do_update_jiffies_64() cannot be used in NMI context, > > > > > > >> > > > > > > >> Can you not make the jiffies update conditional on whether i= t is > > > > > > >> called within NMI context? > > > > > > > > > > > > Which solves what? If KGDB has a breakpoint in the jiffies lock= held > > > > > > region then you still dead lock. > > > > > > > > > > > > >> I dislike that.. > > > > > > > Is this acceptable? > > > > > > > > > > > > > > void rcu_cpu_stall_reset(void) > > > > > > > { > > > > > > > unsigned long delta; > > > > > > > > > > > > > > delta =3D nsecs_to_jiffies(ktime_get_ns() - ktime_get= _coarse_ns()); > > > > > > > > > > > > > > WRITE_ONCE(rcu_state.jiffies_stall, > > > > > > > jiffies + delta + rcu_jiffies_till_stall_c= heck()); > > > > > > > } > > > > > > > > > > > > > > This can update jiffies_stall without updating jiffies (but h= as the > > > > > > > same effect). > > > > > > > > > > > > Now you traded the potential dead lock on jiffies lock for a po= tential > > > > > > live lock vs. tk_core.seq. Not really an improvement, right? > > > > > > > > > > > > The only way you can do the above is something like the incompl= ete and > > > > > > uncompiled below. NMI safe and therefore livelock proof time in= terfaces > > > > > > exist for a reason. > > > > > > > > > > Just for completeness, another approach, with its own advantages > > > > > and disadvantage, is to add something like ULONG_MAX/4 to > > > > > rcu_state.jiffies_stall, but also set a counter indicating that t= his > > > > > has been done. Then RCU's force-quiescent processing could decre= ment > > > > > that counter (if non-zero) and reset rcu_state.jiffies_stall when= it > > > > > does reach zero. > > > > > > > > > > Setting the counter to three should cover most cases, but "live b= y the > > > > > heuristic, die by the heuristic". ;-) > > > > > > > > > > It would be good to have some indication when gdb exited, but thi= ngs > > > > > like the gdb "next" command can make that "interesting" when appl= ied to > > > > > a long-running function. > > > > > > > > The original code is adding ULONG_MAX/2, so adding ULONG_MAX/4 may > > > > make no much difference? The simplest way is adding 300*HZ, but Joe= l > > > > dislikes that. > > > > > > I am not seeing the ULONG_MAX/2, so could you please point me to that > > > original code? > > > > Maybe I misunderstand something, I say the original code means code > > before commit a80be428fbc1f1f3bc9ed924 ("rcu: Do not disable GP stall > > detection in rcu_cpu_stall_reset()"). > > Yes, my suggestion would essentially revert that patch. It would > compensate by resetting rcu_state.jiffies_stall after a few calls > to rcu_gp_fqs(). > > Alternatively, we could simply provide a way for gdb users to manually > disable RCU CPU stall warnings at the beginning of their debug sessions > and to manually re-enable them when they are done. This problem is not KGDB-specific (though it is firstly found in the KGDB case), so I want to fix it in the rcu code rather than in the kgdb code. Huacai > > Thanx, Paul > > > Huacai > > > > > > The advantage of ULONG_MAX/4 over ULONG_MAX/2 is that the time_after(= ) > > > and time_before() macros have ULONG_MAX/4 slop in either direction > > > before giving you the wrong answer. You can get nearly the same resu= lt > > > using ULONG_MAX/2, but it requires a bit more care. And even on 32-b= it > > > HZ=3D1000 systems, ULONG_MAX/4 gets you more than 12 days of gdb sess= ion > > > or jiffies-update delay before you start getting false positives. > > > > > > Then things can be reset after (say) 3 calls to rcu_gp_fqs() and > > > also the current reset at the beginning of a grace period, which > > > is in record_gp_stall_check_time(). > > > > > > It would be better if RCU could get notified at both ends of the debu= g > > > session, but given gdb commands such as "next", along with Thomas's > > > point about gdb breakpoints being pretty much anywhere, this might or > > > might not be so helpful in real life. But worth looking into. > > > > > > Thanx, Paul > > > > > > > Huacai > > > > > > > > > > > > > > Thanx, Pa= ul > > > > > > > > > > > Thanks, > > > > > > > > > > > > tglx > > > > > > --- > > > > > > --- a/kernel/time/tick-sched.c > > > > > > +++ b/kernel/time/tick-sched.c > > > > > > @@ -51,6 +51,13 @@ struct tick_sched *tick_get_tick_sched(i > > > > > > */ > > > > > > static ktime_t last_jiffies_update; > > > > > > > > > > > > +unsigned long tick_estimate_stale_jiffies(void) > > > > > > +{ > > > > > > + ktime_t delta =3D ktime_get_mono_fast_ns() - READ_ONCE(la= st_jiffies_update); > > > > > > + > > > > > > + return delta < 0 ? 0 : div_s64(delta, TICK_NSEC); > > > > > > +} > > > > > > + > > > > > > /* > > > > > > * Must be called with interrupts disabled ! > > > > > > */ > > > > > > > > > > > >