Received: by 2002:ab2:6991:0:b0:1f7:f6c3:9cb1 with SMTP id v17csp1047012lqo; Thu, 9 May 2024 03:14:56 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWsEJhO9UvNMIJEhXHQ8h/BlTxIi3BBlVLKE07Fb3TsJjWfYKXbMtF1F/voFxwFwhee/Mo6sEdoLuhl2krQuUA4d4/ej9vDpZE8iL+LLQ== X-Google-Smtp-Source: AGHT+IEnMTncVzeoY4aZXOZ/0RxNthz7eg7GWhV6g1Jhn8jeKDMeyYq0l405Z52dAf62TGuzGlP7 X-Received: by 2002:a05:6402:50d3:b0:572:5122:4845 with SMTP id 4fb4d7f45d1cf-57332685c61mr2394700a12.4.1715249696412; Thu, 09 May 2024 03:14:56 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715249696; cv=pass; d=google.com; s=arc-20160816; b=zaTrO9d44iPFGWQkoN/bvoAPEYkvOlT/HNBv2VeYM39M1G4125K3E9VzsWtIltl0EN Z8F0eB7FvVzg+ezvo4xzJxyZlztVcs1vf4Qa1XzVf1dWye5useMx/xQR2XdioMl6nWzV AYnREAWw5r+GbCW7KrcHgz7O3q2++W759dLOVV8EJjGAy2UYU8I1C649gW0q7IWC+lP5 RNwhLXV7yQalw68F1DE9LrgaDemf6zdj9eUKQKizVlrbYtfMCRhCqII9NlSvvCf7CPDo IMFVZ/64hh6qoNNXwqc6MJN3k6hviOajSlyhl6OKAY7Xh1y0MBc89e3bewP4hVBzjcbj 7MSg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:content-disposition:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature; bh=Y94ZLI6kJ1Hvts2f4+dyM/gxRfim2F0PWqoiLQCgXSQ=; fh=zIP3mt+Zz3jtMlglHBVqLZDsIh251DIjyLpqMd8bxA0=; b=qF1wBzhbeFmKli6MdI4Hx6T1KrRPLwvjhThn27xL+afq5IMY5wwFIVM+ggEkkFKwxM lKP8JT68Eck9rWTG94Im+Yy2uTN39Fx4VZGqbT+Ll75kM3kzJ4f250srhbIgoQOv6MM2 EXwZSSaw1ZVibySwluj+tp8u0Lr5AJxcuNxdtbaC6qzPos7ckgLo8PS1k6Wa6983pUrQ vUYa34PA/WKhx0D1DD70lPmHN6G/el+q75to9s5TD427gTE3TpaidVFVdUqE4Ki3Skku +o9u0ql2cipuipTARqY1NNXAzlR9aWPs966isa9GScR9IaTMOvD4b0Q0nd8Yi2q6QHZl Y3sQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=dCWOQPbD; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-174395-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-174395-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-5733c32c81bsi668577a12.453.2024.05.09.03.14.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 May 2024 03:14:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-174395-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=dCWOQPbD; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-174395-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-174395-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.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 am.mirrors.kernel.org (Postfix) with ESMTPS id F18AB1F2201F for ; Thu, 9 May 2024 10:14:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3EDFC14B949; Thu, 9 May 2024 10:14:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="dCWOQPbD" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4AA4F14B088 for ; Thu, 9 May 2024 10:14:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715249683; cv=none; b=Fq0HrGWKHEYtN5EmHYTZfRnAAHAIRnUif0DpyOsHJSSJUl0YULnvFbtJ03HvBadw2W8XPW07C3HLSir31XEViAU4oQ2ul7Cpgcno5i4hfMH8ibCM3BqzicblodQ21K38Q2GOGLxWjX3Zy7EZffM3vKREuheI0yZgscqnPUb3Yhc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715249683; c=relaxed/simple; bh=KgdfPRGU/BUygq/vRrZlzXD4Zb3wjlPGMOETvS32BqA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type:Content-Disposition; b=dl1JLGMKpupLxdsOnTNZsepds8FOzoAfPyqmzEydYjliK6ltqaFMcmcQdmWXEnqAm/Nromvp1y33HMoB5gOkiFU25ycT+JQuyMTCHc503YUmIZ3NQirhPZhy68wYSZ5/Dj/LZ5mF9c+hJauj/NhuUWsKwhFy1YRxi8JBnyxVXbE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=dCWOQPbD; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1715249680; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Y94ZLI6kJ1Hvts2f4+dyM/gxRfim2F0PWqoiLQCgXSQ=; b=dCWOQPbDrB3kg0KcWy/pRTvnQc5Gn2SC1mluIw6swvpIZsNgePcbX+nryd6uzvguHhw8aq BRfcSFY31c29Zy/45Tfg8YTVmDIUOAzcjgf02OARIBnnBBQaYBbrqj+d3uwelfvRVsYq4F 8VW8DaU+zB42U+cqMUMAGyV50kUUha0= Received: from mail-pf1-f200.google.com (mail-pf1-f200.google.com [209.85.210.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-523-n_47Rit0Miq8jAnrN0y2uQ-1; Thu, 09 May 2024 06:14:38 -0400 X-MC-Unique: n_47Rit0Miq8jAnrN0y2uQ-1 Received: by mail-pf1-f200.google.com with SMTP id d2e1a72fcca58-6f46bf70fd3so403451b3a.3 for ; Thu, 09 May 2024 03:14:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715249678; x=1715854478; h=content-transfer-encoding:content-disposition:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Y94ZLI6kJ1Hvts2f4+dyM/gxRfim2F0PWqoiLQCgXSQ=; b=Rb3i92K7CJzS/dlGN0ZNmu28tNQc2zrpax0Gs5QFUHxu9wegexuKRQ/++vIj+H2zou nCDHyOU061Aj4Naz5GYiZtWyUDBpMex9VdCIEkaPmev3MG7rxu0RHJ/yKbKpkkaOgF+o jMu91oZWqwwvQl+SWillLbwRwPI/WnjZ6zxcwW4gR9tGVxpCi3R/blp4cdXyu9LVdzK5 9dYYxP4CRHNjurmfaqPrFfuAf4h2ZUJu3ntofwOr3XH7RafBfNvfk4vaBPPI22WZTuOQ e9E3Oq2fTMjnOHM4G+S0+GtxKk6bcpbqQPm66Tz72yPecKs/kf0jWtEMrBL3o4pBoCje bt1w== X-Forwarded-Encrypted: i=1; AJvYcCVIYvfIz5iB26/1CsbymiR5Vn2uyuvxmRzcvSH8WpoDer/Xq7glRuz9ncNKh2ABXB5OFcgFGlpasb3w42KtFu8DD/le7jfO4sVcL9Z4 X-Gm-Message-State: AOJu0YxxJSNFwKAf1uIaUjQ3wOdmMCGAFANgBMv9wux9K9BLQgbd7CTI Q6+z+JVlJW5I16Xgh9A/Dyq0xPZ4dCwMwsPGG2RDjZ6HqUwqXNMSUEE3y9LWQHENf8MnykKxjFN EiMENvCosgwJo9yI9B8QOZugCn/TMsTeGUZMMu+ra2ErHezPiBhfdSnWA4Px8ng== X-Received: by 2002:a05:6a00:740c:b0:6f4:5531:7ce4 with SMTP id d2e1a72fcca58-6f49c2a67camr5575810b3a.33.1715249677639; Thu, 09 May 2024 03:14:37 -0700 (PDT) X-Received: by 2002:a05:6a00:740c:b0:6f4:5531:7ce4 with SMTP id d2e1a72fcca58-6f49c2a67camr5575785b3a.33.1715249677123; Thu, 09 May 2024 03:14:37 -0700 (PDT) Received: from localhost.localdomain ([2804:1b3:a800:8d87:eac1:dae4:8dd4:fe50]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-6f4d2a66616sm968113b3a.22.2024.05.09.03.14.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 May 2024 03:14:36 -0700 (PDT) From: Leonardo Bras To: Leonardo Bras Cc: "Paul E. McKenney" , Sean Christopherson , Paolo Bonzini , Frederic Weisbecker , Neeraj Upadhyay , Joel Fernandes , Josh Triplett , Boqun Feng , Steven Rostedt , Mathieu Desnoyers , Lai Jiangshan , Zqiang , Marcelo Tosatti , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, rcu@vger.kernel.org Subject: Re: [RFC PATCH v1 0/2] Avoid rcu_core() if CPU just left guest vcpu Date: Thu, 9 May 2024 07:14:18 -0300 Message-ID: X-Mailer: git-send-email 2.45.0 In-Reply-To: References: <0e239143-65ed-445a-9782-e905527ea572@paulmck-laptop> <5fd66909-1250-4a91-aa71-93cb36ed4ad5@paulmck-laptop> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: 8bit On Thu, May 09, 2024 at 05:16:57AM -0300, Leonardo Bras wrote: > On Wed, May 08, 2024 at 08:32:40PM -0700, Paul E. McKenney wrote: > > On Wed, May 08, 2024 at 07:01:29AM -0700, Sean Christopherson wrote: > > > On Wed, May 08, 2024, Leonardo Bras wrote: > > > > Something just hit me, and maybe I need to propose something more generic. > > > > > > Yes. This is what I was trying to get across with my complaints about keying off > > > of the last VM-Exit time. It's effectively a broad stroke "this task will likely > > > be quiescent soon" and so the core concept/functionality belongs in common code, > > > not KVM. > > > > OK, we could do something like the following wholly within RCU, namely > > to make rcu_pending() refrain from invoking rcu_core() until the grace > > period is at least the specified age, defaulting to zero (and to the > > current behavior). > > > > Perhaps something like the patch shown below. > > That's exactly what I was thinking :) > > > > > Thoughts? > > Some suggestions below: > > > > > Thanx, Paul > > > > ------------------------------------------------------------------------ > > > > commit abc7cd2facdebf85aa075c567321589862f88542 > > Author: Paul E. McKenney > > Date: Wed May 8 20:11:58 2024 -0700 > > > > rcu: Add rcutree.nocb_patience_delay to reduce nohz_full OS jitter > > > > If a CPU is running either a userspace application or a guest OS in > > nohz_full mode, it is possible for a system call to occur just as an > > RCU grace period is starting. If that CPU also has the scheduling-clock > > tick enabled for any reason (such as a second runnable task), and if the > > system was booted with rcutree.use_softirq=0, then RCU can add insult to > > injury by awakening that CPU's rcuc kthread, resulting in yet another > > task and yet more OS jitter due to switching to that task, running it, > > and switching back. > > > > In addition, in the common case where that system call is not of > > excessively long duration, awakening the rcuc task is pointless. > > This pointlessness is due to the fact that the CPU will enter an extended > > quiescent state upon returning to the userspace application or guest OS. > > In this case, the rcuc kthread cannot do anything that the main RCU > > grace-period kthread cannot do on its behalf, at least if it is given > > a few additional milliseconds (for example, given the time duration > > specified by rcutree.jiffies_till_first_fqs, give or take scheduling > > delays). > > > > This commit therefore adds a rcutree.nocb_patience_delay kernel boot > > parameter that specifies the grace period age (in milliseconds) > > before which RCU will refrain from awakening the rcuc kthread. > > Preliminary experiementation suggests a value of 1000, that is, > > one second. Increasing rcutree.nocb_patience_delay will increase > > grace-period latency and in turn increase memory footprint, so systems > > with constrained memory might choose a smaller value. Systems with > > less-aggressive OS-jitter requirements might choose the default value > > of zero, which keeps the traditional immediate-wakeup behavior, thus > > avoiding increases in grace-period latency. > > > > Link: https://lore.kernel.org/all/20240328171949.743211-1-leobras@redhat.com/ > > > > Reported-by: Leonardo Bras > > Suggested-by: Leonardo Bras > > Suggested-by: Sean Christopherson > > Signed-off-by: Paul E. McKenney > > > > diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt > > index 0a3b0fd1910e6..42383986e692b 100644 > > --- a/Documentation/admin-guide/kernel-parameters.txt > > +++ b/Documentation/admin-guide/kernel-parameters.txt > > @@ -4981,6 +4981,13 @@ > > the ->nocb_bypass queue. The definition of "too > > many" is supplied by this kernel boot parameter. > > > > + rcutree.nocb_patience_delay= [KNL] > > + On callback-offloaded (rcu_nocbs) CPUs, avoid > > + disturbing RCU unless the grace period has > > + reached the specified age in milliseconds. > > + Defaults to zero. Large values will be capped > > + at five seconds. > > + > > rcutree.qhimark= [KNL] > > Set threshold of queued RCU callbacks beyond which > > batch limiting is disabled. > > diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c > > index 7560e204198bb..6e4b8b43855a0 100644 > > --- a/kernel/rcu/tree.c > > +++ b/kernel/rcu/tree.c > > @@ -176,6 +176,8 @@ static int gp_init_delay; > > module_param(gp_init_delay, int, 0444); > > static int gp_cleanup_delay; > > module_param(gp_cleanup_delay, int, 0444); > > +static int nocb_patience_delay; > > +module_param(nocb_patience_delay, int, 0444); > > > > // Add delay to rcu_read_unlock() for strict grace periods. > > static int rcu_unlock_delay; > > @@ -4334,6 +4336,8 @@ EXPORT_SYMBOL_GPL(cond_synchronize_rcu_full); > > static int rcu_pending(int user) > > { > > bool gp_in_progress; > > + unsigned long j = jiffies; > > I think this is probably taken care by the compiler, but just in case I would move the > j = jiffies; > closer to it's use, in order to avoid reading 'jiffies' if rcu_pending > exits before the nohz_full testing. > > > > + unsigned int patience = msecs_to_jiffies(nocb_patience_delay); > > What do you think on processsing the new parameter in boot, and saving it > in terms of jiffies already? > > It would make it unnecessary to convert ms -> jiffies every time we run > rcu_pending. > > (OOO will probably remove the extra division, but may cause less impact in > some arch) > > > struct rcu_data *rdp = this_cpu_ptr(&rcu_data); > > struct rcu_node *rnp = rdp->mynode; > > > > @@ -4347,11 +4351,13 @@ static int rcu_pending(int user) > > return 1; > > > > /* Is this a nohz_full CPU in userspace or idle? (Ignore RCU if so.) */ > > - if ((user || rcu_is_cpu_rrupt_from_idle()) && rcu_nohz_full_cpu()) > > + gp_in_progress = rcu_gp_in_progress(); > > + if ((user || rcu_is_cpu_rrupt_from_idle() || > > + (gp_in_progress && time_before(j + patience, rcu_state.gp_start))) && > > I think you meant: > time_before(j, rcu_state.gp_start + patience) > > or else this always fails, as we can never have now to happen before a > previously started gp, right? > > Also, as per rcu_nohz_full_cpu() we probably need it to be read with > READ_ONCE(): > > time_before(j, READ_ONCE(rcu_state.gp_start) + patience) > > > + rcu_nohz_full_cpu()) > > return 0; > > > > /* Is the RCU core waiting for a quiescent state from this CPU? */ > > - gp_in_progress = rcu_gp_in_progress(); > > if (rdp->core_needs_qs && !rdp->cpu_no_qs.b.norm && gp_in_progress) > > return 1; > > > > diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h > > index 340bbefe5f652..174333d0e9507 100644 > > --- a/kernel/rcu/tree_plugin.h > > +++ b/kernel/rcu/tree_plugin.h > > @@ -93,6 +93,15 @@ static void __init rcu_bootup_announce_oddness(void) > > pr_info("\tRCU debug GP init slowdown %d jiffies.\n", gp_init_delay); > > if (gp_cleanup_delay) > > pr_info("\tRCU debug GP cleanup slowdown %d jiffies.\n", gp_cleanup_delay); > > + if (nocb_patience_delay < 0) { > > + pr_info("\tRCU NOCB CPU patience negative (%d), resetting to zero.\n", nocb_patience_delay); > > + nocb_patience_delay = 0; > > + } else if (nocb_patience_delay > 5 * MSEC_PER_SEC) { > > + pr_info("\tRCU NOCB CPU patience too large (%d), resetting to %ld.\n", nocb_patience_delay, 5 * MSEC_PER_SEC); > > + nocb_patience_delay = 5 * MSEC_PER_SEC; > > + } else if (nocb_patience_delay) { > > Here you suggest that we don't print if 'nocb_patience_delay == 0', > as it's the default behavior, right? > > I think printing on 0 could be useful to check if the feature exists, even > though we are zeroing it, but this will probably add unnecessary verbosity. > > > + pr_info("\tRCU NOCB CPU patience set to %d milliseconds.\n", nocb_patience_delay); > > + } > > Here I suppose something like this can take care of not needing to convert > ms -> jiffies every rcu_pending(): > > + nocb_patience_delay = msecs_to_jiffies(nocb_patience_delay); > Uh, there is more to it, actually. We need to make sure the user understands that we are rounding-down the value to multiple of a jiffy period, so it's not a surprise if the delay value is not exactly the same as the passed on kernel cmdline. So something like bellow diff should be ok, as this behavior is explained in the docs, and pr_info() will print the effective value. What do you think? Thanks! Leo diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 0a3b0fd1910e..9a50be9fd9eb 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -4974,20 +4974,28 @@ otherwise be caused by callback floods through use of the ->nocb_bypass list. However, in the common non-flooded case, RCU queues directly to the main ->cblist in order to avoid the extra overhead of the ->nocb_bypass list and its lock. But if there are too many callbacks queued during a single jiffy, RCU pre-queues the callbacks into the ->nocb_bypass queue. The definition of "too many" is supplied by this kernel boot parameter. + rcutree.nocb_patience_delay= [KNL] + On callback-offloaded (rcu_nocbs) CPUs, avoid + disturbing RCU unless the grace period has + reached the specified age in milliseconds. + Defaults to zero. Large values will be capped + at five seconds. Values rounded-down to a multiple + of a jiffy period. + rcutree.qhimark= [KNL] Set threshold of queued RCU callbacks beyond which batch limiting is disabled. rcutree.qlowmark= [KNL] Set threshold of queued RCU callbacks below which batch limiting is re-enabled. rcutree.qovld= [KNL] Set threshold of queued RCU callbacks beyond which diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h index fcf2b4aa3441..62ede401420f 100644 --- a/kernel/rcu/tree.h +++ b/kernel/rcu/tree.h @@ -512,20 +512,21 @@ do { \ local_irq_save(flags); \ if (rcu_segcblist_is_offloaded(&(rdp)->cblist)) \ raw_spin_lock(&(rdp)->nocb_lock); \ } while (0) #else /* #ifdef CONFIG_RCU_NOCB_CPU */ #define rcu_nocb_lock_irqsave(rdp, flags) local_irq_save(flags) #endif /* #else #ifdef CONFIG_RCU_NOCB_CPU */ static void rcu_bind_gp_kthread(void); static bool rcu_nohz_full_cpu(void); +static bool rcu_on_patience_delay(void); /* Forward declarations for tree_stall.h */ static void record_gp_stall_check_time(void); static void rcu_iw_handler(struct irq_work *iwp); static void check_cpu_stall(struct rcu_data *rdp); static void rcu_check_gp_start_stall(struct rcu_node *rnp, struct rcu_data *rdp, const unsigned long gpssdelay); /* Forward declarations for tree_exp.h. */ static void sync_rcu_do_polled_gp(struct work_struct *wp); diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h index 340bbefe5f65..639243b0410f 100644 --- a/kernel/rcu/tree_plugin.h +++ b/kernel/rcu/tree_plugin.h @@ -5,20 +5,21 @@ * or preemptible semantics. * * Copyright Red Hat, 2009 * Copyright IBM Corporation, 2009 * * Author: Ingo Molnar * Paul E. McKenney */ #include "../locking/rtmutex_common.h" +#include static bool rcu_rdp_is_offloaded(struct rcu_data *rdp) { /* * In order to read the offloaded state of an rdp in a safe * and stable way and prevent from its value to be changed * under us, we must either hold the barrier mutex, the cpu * hotplug lock (read or write) or the nocb lock. Local * non-preemptible reads are also safe. NOCB kthreads and * timers have their own means of synchronization against the @@ -86,20 +87,33 @@ static void __init rcu_bootup_announce_oddness(void) if (rcu_kick_kthreads) pr_info("\tKick kthreads if too-long grace period.\n"); if (IS_ENABLED(CONFIG_DEBUG_OBJECTS_RCU_HEAD)) pr_info("\tRCU callback double-/use-after-free debug is enabled.\n"); if (gp_preinit_delay) pr_info("\tRCU debug GP pre-init slowdown %d jiffies.\n", gp_preinit_delay); if (gp_init_delay) pr_info("\tRCU debug GP init slowdown %d jiffies.\n", gp_init_delay); if (gp_cleanup_delay) pr_info("\tRCU debug GP cleanup slowdown %d jiffies.\n", gp_cleanup_delay); + if (nocb_patience_delay < 0) { + pr_info("\tRCU NOCB CPU patience negative (%d), resetting to zero.\n", + nocb_patience_delay); + nocb_patience_delay = 0; + } else if (nocb_patience_delay > 5 * MSEC_PER_SEC) { + pr_info("\tRCU NOCB CPU patience too large (%d), resetting to %ld.\n", + nocb_patience_delay, 5 * MSEC_PER_SEC); + nocb_patience_delay = msecs_to_jiffies(5 * MSEC_PER_SEC); + } else if (nocb_patience_delay) { + nocb_patience_delay = msecs_to_jiffies(nocb_patience_delay); + pr_info("\tRCU NOCB CPU patience set to %d milliseconds.\n", + jiffies_to_msecs(nocb_patience_delay); + } if (!use_softirq) pr_info("\tRCU_SOFTIRQ processing moved to rcuc kthreads.\n"); if (IS_ENABLED(CONFIG_RCU_EQS_DEBUG)) pr_info("\tRCU debug extended QS entry/exit.\n"); rcupdate_announce_bootup_oddness(); } #ifdef CONFIG_PREEMPT_RCU static void rcu_report_exp_rnp(struct rcu_node *rnp, bool wake); @@ -1260,10 +1274,29 @@ static bool rcu_nohz_full_cpu(void) /* * Bind the RCU grace-period kthreads to the housekeeping CPU. */ static void rcu_bind_gp_kthread(void) { if (!tick_nohz_full_enabled()) return; housekeeping_affine(current, HK_TYPE_RCU); } + +/* + * Is this CPU a NO_HZ_FULL CPU that should ignore RCU if the time since the + * start of current grace period is smaller than nocb_patience_delay ? + * + * This code relies on the fact that all NO_HZ_FULL CPUs are also + * RCU_NOCB_CPU CPUs. + */ +static bool rcu_on_patience_delay(void) +{ +#ifdef CONFIG_NO_HZ_FULL + if (!nocb_patience_delay) + return false; + + if (time_before(jiffies, READ_ONCE(rcu_state.gp_start) + nocb_patience_delay)) + return true; +#endif /* #ifdef CONFIG_NO_HZ_FULL */ + return false; +} diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c index 7560e204198b..7a2d94370ab4 100644 --- a/kernel/rcu/tree.c +++ b/kernel/rcu/tree.c @@ -169,20 +169,22 @@ static int kthread_prio = IS_ENABLED(CONFIG_RCU_BOOST) ? 1 : 0; module_param(kthread_prio, int, 0444); /* Delay in jiffies for grace-period initialization delays, debug only. */ static int gp_preinit_delay; module_param(gp_preinit_delay, int, 0444); static int gp_init_delay; module_param(gp_init_delay, int, 0444); static int gp_cleanup_delay; module_param(gp_cleanup_delay, int, 0444); +static int nocb_patience_delay; +module_param(nocb_patience_delay, int, 0444); // Add delay to rcu_read_unlock() for strict grace periods. static int rcu_unlock_delay; #ifdef CONFIG_RCU_STRICT_GRACE_PERIOD module_param(rcu_unlock_delay, int, 0444); #endif /* * This rcu parameter is runtime-read-only. It reflects * a minimum allowed number of objects which can be cached @@ -4340,25 +4342,27 @@ static int rcu_pending(int user) lockdep_assert_irqs_disabled(); /* Check for CPU stalls, if enabled. */ check_cpu_stall(rdp); /* Does this CPU need a deferred NOCB wakeup? */ if (rcu_nocb_need_deferred_wakeup(rdp, RCU_NOCB_WAKE)) return 1; /* Is this a nohz_full CPU in userspace or idle? (Ignore RCU if so.) */ - if ((user || rcu_is_cpu_rrupt_from_idle()) && rcu_nohz_full_cpu()) + gp_in_progress = rcu_gp_in_progress(); + if ((user || rcu_is_cpu_rrupt_from_idle() || + (gp_in_progress && rcu_on_patience_delay())) && + rcu_nohz_full_cpu()) return 0; /* Is the RCU core waiting for a quiescent state from this CPU? */ - gp_in_progress = rcu_gp_in_progress(); if (rdp->core_needs_qs && !rdp->cpu_no_qs.b.norm && gp_in_progress) return 1; /* Does this CPU have callbacks ready to invoke? */ if (!rcu_rdp_is_offloaded(rdp) && rcu_segcblist_ready_cbs(&rdp->cblist)) return 1; /* Has RCU gone idle with this CPU needing another grace period? */ if (!gp_in_progress && rcu_segcblist_is_enabled(&rdp->cblist) &&