Received: by 2002:ab2:620c:0:b0:1ef:ffd0:ce49 with SMTP id o12csp610700lqt; Mon, 18 Mar 2024 19:33:24 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVLHEpII233Kuer490bZUXJeUcPnlGwhEPWtJvXa9zn42dgj5yOQYWb1lyH6QM8KgsWZTWS+qDhMUr/877ifrT7zC1QZNRb9v9ih+ttiw== X-Google-Smtp-Source: AGHT+IHX+CrHH8q8hC0dvimBMemyCURT/3XlUDnffln1Ou6kgrgUDs0v2mr3ZkDuoZdFJapP7iCx X-Received: by 2002:a05:6808:384b:b0:3c3:86bc:2633 with SMTP id ej11-20020a056808384b00b003c386bc2633mr7458331oib.53.1710815604481; Mon, 18 Mar 2024 19:33:24 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710815604; cv=pass; d=google.com; s=arc-20160816; b=BjFSd0cAZkSbVf9ZERLQsm5SddmEJ/KkZ6aP+HVxNv4j/EuBSGeV1fYkoTseB2MFp5 gCWVuCVVRGTy1SZxIHpIDUdavyNbn8bWaFnox9I6lSBhMp9uut9Tl5hvtvSe1oIMLFct nXMar3Wi332cqRBcf1foYYWq67gbf+L+lLCbmmQgvp/iQP0nbzBvLsDdpx9sqmZafGLM ky3gbF2u2ELsFG7azAOMz/hYuFbRIvbbBgA2vnJxabJPdZRnHVLlME6NvIN8dOmeQxEH fXZ7LIEnqp0EtjNW1cA4dChin1gmnyWTREwVSW5WTkQEY0lVe3aB8PyGv8PaaxpG5no0 7Ayw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=1/ugjgSVKg/BMvJ6AYVxFTNZ2b8E1qURDrbsQiUbZk8=; fh=7EThEPfLQ2eL1Zv0oiZoBth9S1IzW4obi2VPn+KRCYo=; b=O7hZt3uPiR5RnWOo1UIX1oj8F+5awvdsz1XaKHidN7DnAYFrb8cg+3EgMYyptE4gPF azQ6Yrha1xXDAyFPafXUVM1JjzOyENS6K0ngOvOGcabFc3NPeAtX6mv3g2v8c4ZLM1Gt zKFuhAW+/aYwy75Llu7bYK7TzTejT4LMNfqeMyzB8N/ftapRInl/Shw/90sCrmsVAdMU KC3+0lh6LY+XQ9I6LreMoQZN85y1Cpz5Ic8sPoSRC4Qbt8A9+UNprPgoC3NUdNkd5a1o gqm/np0L3nIhgeUX7digVhrl3nsHbahLMNyBTPVIeG+7y1KDI8rk7iinmH2Lg1sN3w/o Tz/Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@cloudflare.com header.s=google09082023 header.b=DdMzqcEA; arc=pass (i=1 spf=pass spfdomain=cloudflare.com dkim=pass dkdomain=cloudflare.com dmarc=pass fromdomain=cloudflare.com); spf=pass (google.com: domain of linux-kernel+bounces-106925-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-106925-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cloudflare.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id h7-20020aa79f47000000b006e6a174e49esi10048569pfr.227.2024.03.18.19.33.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Mar 2024 19:33:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-106925-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@cloudflare.com header.s=google09082023 header.b=DdMzqcEA; arc=pass (i=1 spf=pass spfdomain=cloudflare.com dkim=pass dkdomain=cloudflare.com dmarc=pass fromdomain=cloudflare.com); spf=pass (google.com: domain of linux-kernel+bounces-106925-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-106925-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cloudflare.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 06CDE282BCA for ; Tue, 19 Mar 2024 02:33:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0D9DA7B3EB; Tue, 19 Mar 2024 02:33:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=cloudflare.com header.i=@cloudflare.com header.b="DdMzqcEA" Received: from mail-ed1-f45.google.com (mail-ed1-f45.google.com [209.85.208.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 822547B3C1 for ; Tue, 19 Mar 2024 02:33:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710815583; cv=none; b=NAgZ2gjIeEsWm8RtFTWhzqdbJqPYrPKXXcHnn5F1eVsw4hDzutHuEp68E41lFO75SQKY8qJIUSrz7WHwiP8DT/8sjNiJIFzzpCPY3VKiLTRwoGsuZ4s/tHshFGs58a8hoIxEH2F20zBpYAklWJFOMbQWunfbmnz3yRRnWZ3mN60= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710815583; c=relaxed/simple; bh=ZvlzHmiqM0PBn3qAhl+WMIP+un56FpRYKp1adoqUp70=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=Se6WQgdTuw+4wsiIuWLq/SucwJ9jlGwDBKlxWQvex/wgIirTzTW4b1Fq0SXnZLHi+GVTiySWdX9Z1JK4uEYWD3tkqoY+Hp0YwbhG0A0MWy7R0bOsai43G1e/9N/5ydTted9mA+WDq2hIYjTXyLBN1+tODJyiXa8mlcNSnh/Osxs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=cloudflare.com; spf=pass smtp.mailfrom=cloudflare.com; dkim=pass (2048-bit key) header.d=cloudflare.com header.i=@cloudflare.com header.b=DdMzqcEA; arc=none smtp.client-ip=209.85.208.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=cloudflare.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cloudflare.com Received: by mail-ed1-f45.google.com with SMTP id 4fb4d7f45d1cf-5658082d2c4so6378861a12.1 for ; Mon, 18 Mar 2024 19:33:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudflare.com; s=google09082023; t=1710815579; x=1711420379; darn=vger.kernel.org; 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=1/ugjgSVKg/BMvJ6AYVxFTNZ2b8E1qURDrbsQiUbZk8=; b=DdMzqcEAOW1rMXNBlPg7KR8wQBFyTu++Lrrhnzgy81v5I3E9jnIcwh6OTtCWrcHkLr 7+2BHbjbopQ2OhsOKFFfDTJYUs+UF37vRpavRU3Mno7L2KH8XSKl+TWw6pYVcMcBil1+ h8rGy/s9FNnTPcPef2pe//FIgxCKG3ueawVlVqFrNXr14HVQGgT/nU9zBGR8XQEDnXok F/aQal8f29cTMdmEQpyvcTZUWp4Oz/ZSSgINiDhCF9Y13PJK+lKescMGdNu0S6dWlLIr YokECc0hm45gPe9Jm9M1EskJbVaA5vHaMCNOMLHZXncszy6J0H5EB2p6uRnDMKWg9sdI DpAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710815579; x=1711420379; 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=1/ugjgSVKg/BMvJ6AYVxFTNZ2b8E1qURDrbsQiUbZk8=; b=WDh+53A9asLBzrSOgUb3zmNWLnvaNdA/fDJBPtkhV/9XKwhBLrdU0cvepllk4K2CUy HrHL3TU8MEzG7WXgE5Ze+lv/grsN3Pc9MfDOKu5gFJC/hOykMO8hwwVi4hSzCPaaBQZM BAvWo4NzUGBw6ejaaNtnZqs3hIOYnclXjR85T+cy/hcxm+4fcY6zS2oJn0bizVAjNg0X M+5GzsHGFcHdcCIzK+Cc9kjImJphC6GO+ZQkFNwYPR356eSI2LswQudJWMxOuTEMluV4 4s/QE6jKu68U46FgDuh9U6TX6s2Nxh24wKgXbue98osxzDHgquqOWmT6uySULIcaQdb5 0Jdg== X-Forwarded-Encrypted: i=1; AJvYcCWnLUoBUMH9hb9n3t/xgn849gLFUY0T8oOGG/g6cNlWWjU/P4fuwTpZfA2fc6848lICtGCaG3Tc6ZjVGyx5IRPcVUabjxZNZjCW+S/2 X-Gm-Message-State: AOJu0YzlxYcIlrsp+Oop0I0W81zXBuRg5o9s1o38LUPbHmrd6liyNxQI TJJwigCBh08XmXs6JL3kF0bkNVA/mq1hQRQIGo7t/DO1qrU0FOWa5qQp8ZM/d24Tk0rsBkZ3kcg 8PK7I4emCHeJ+skjnfuWoe6EZe6+24JUtNN6G7/QxZLh75xfYV0U= X-Received: by 2002:a05:6402:1f03:b0:568:b4c8:9af with SMTP id b3-20020a0564021f0300b00568b4c809afmr7871934edb.17.1710815578912; Mon, 18 Mar 2024 19:32:58 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <491d3af6c7d66dfb3b60b2f210f38e843dfe6ed2.1710525524.git.yan@cloudflare.com> <790ce7e7-a8fd-4d28-aaf3-1b991a898be2@paulmck-laptop> In-Reply-To: From: Yan Zhai Date: Mon, 18 Mar 2024 21:32:47 -0500 Message-ID: Subject: Re: [PATCH v4 net 1/3] rcu: add a helper to report consolidated flavor QS To: Mark Rutland Cc: "Paul E. McKenney" , netdev@vger.kernel.org, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jiri Pirko , Simon Horman , Daniel Borkmann , Lorenzo Bianconi , Coco Li , Wei Wang , Alexander Duyck , Hannes Frederic Sowa , linux-kernel@vger.kernel.org, rcu@vger.kernel.org, bpf@vger.kernel.org, kernel-team@cloudflare.com, Joel Fernandes , Toke Hoiland-Jorgensen , Alexei Starovoitov , Steven Rostedt , Jesper Dangaard Brouer Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Mar 18, 2024 at 5:59=E2=80=AFAM Mark Rutland = wrote: > > On Fri, Mar 15, 2024 at 10:40:56PM -0700, Paul E. McKenney wrote: > > On Fri, Mar 15, 2024 at 12:55:03PM -0700, Yan Zhai wrote: > > > There are several scenario in network processing that can run > > > extensively under heavy traffic. In such situation, RCU synchronizati= on > > > might not observe desired quiescent states for indefinitely long peri= od. > > > Create a helper to safely raise the desired RCU quiescent states for > > > such scenario. > > > > > > Currently the frequency is locked at HZ/10, i.e. 100ms, which is > > > sufficient to address existing problems around RCU tasks. It's unclea= r > > > yet if there is any future scenario for it to be further tuned down. > > > > I suggest something like the following for the commit log: > > > > -----------------------------------------------------------------------= - > > > > When under heavy load, network processing can run CPU-bound for many te= ns > > of seconds. Even in preemptible kernels, this can block RCU Tasks grac= e > > periods, which can cause trace-event removal to take more than a minute= , > > which is unacceptably long. > > > > This commit therefore creates a new helper function that passes > > through both RCU and RCU-Tasks quiescent states every 100 milliseconds. > > This hard-coded value suffices for current workloads. > > FWIW, this sounds good to me. > > > > > -----------------------------------------------------------------------= - > > > > > Suggested-by: Paul E. McKenney > > > Reviewed-by: Jesper Dangaard Brouer > > > Signed-off-by: Yan Zhai > > > --- > > > v3->v4: comment fixup > > > > > > --- > > > include/linux/rcupdate.h | 24 ++++++++++++++++++++++++ > > > 1 file changed, 24 insertions(+) > > > > > > diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h > > > index 0746b1b0b663..da224706323e 100644 > > > --- a/include/linux/rcupdate.h > > > +++ b/include/linux/rcupdate.h > > > @@ -247,6 +247,30 @@ do { \ > > > cond_resched(); \ > > > } while (0) > > > > > > +/** > > > + * rcu_softirq_qs_periodic - Periodically report consolidated quiesc= ent states > > > + * @old_ts: last jiffies when QS was reported. Might be modified in = the macro. > > > + * > > > + * This helper is for network processing in non-RT kernels, where th= ere could > > > + * be busy polling threads that block RCU synchronization indefinite= ly. In > > > + * such context, simply calling cond_resched is insufficient, so giv= e it a > > > + * stronger push to eliminate all potential blockage of all RCU type= s. > > > + * > > > + * NOTE: unless absolutely sure, this helper should in general be ca= lled > > > + * outside of bh lock section to avoid reporting a surprising QS to = updaters, > > > + * who could be expecting RCU read critical section to end at local_= bh_enable(). > > > + */ > > > > How about something like this for the kernel-doc comment? > > > > /** > > * rcu_softirq_qs_periodic - Report RCU and RCU-Tasks quiescent states > > * @old_ts: jiffies at start of processing. > > * > > * This helper is for long-running softirq handlers, such as those > > * in networking. The caller should initialize the variable passed in > > * as @old_ts at the beginning of the softirq handler. When invoked > > * frequently, this macro will invoke rcu_softirq_qs() every 100 > > * milliseconds thereafter, which will provide both RCU and RCU-Tasks > > * quiescent states. Note that this macro modifies its old_ts argument= . > > * > > * Note that although cond_resched() provides RCU quiescent states, > > * it does not provide RCU-Tasks quiescent states. > > * > > * Because regions of code that have disabled softirq act as RCU > > * read-side critical sections, this macro should be invoked with softi= rq > > * (and preemption) enabled. > > * > > * This macro has no effect in CONFIG_PREEMPT_RT kernels. > > */ > > Considering the note about cond_resched(), does does cond_resched() actua= lly > provide an RCU quiescent state for fully-preemptible kernels? IIUC for th= ose > cond_resched() expands to: > > __might_resched(); > klp_sched_try_switch() > > ... and AFAICT neither reports an RCU quiescent state. > > So maybe it's worth dropping the note? > > Seperately, what's the rationale for not doing this on PREEMPT_RT? Does t= hat > avoid the problem through other means, or are people just not running eff= ected > workloads on that? > It's a bit anti-intuition but yes the RT kernel avoids the problem. This is because "schedule()" reports task RCU QS actually, and on RT kernel cond_resched() call won't call "__cond_resched()" or "__schedule(PREEMPT)" as you already pointed out, which would clear need-resched flag. This then allows "schedule()" to be called on hard IRQ exit time by time. Yan > Mark. > > > > > Thanx, Paul > > > > > +#define rcu_softirq_qs_periodic(old_ts) \ > > > +do { \ > > > + if (!IS_ENABLED(CONFIG_PREEMPT_RT) && \ > > > + time_after(jiffies, (old_ts) + HZ / 10)) { \ > > > + preempt_disable(); \ > > > + rcu_softirq_qs(); \ > > > + preempt_enable(); \ > > > + (old_ts) =3D jiffies; \ > > > + } \ > > > +} while (0) > > > + > > > /* > > > * Infrastructure to implement the synchronize_() primitives in > > > * TREE_RCU and rcu_barrier_() primitives in TINY_RCU. > > > -- > > > 2.30.2 > > > > > >