Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp1902538rdb; Sat, 2 Dec 2023 14:24:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IFs4nhAq0+ZO9rxzc7CorkUPVJLIbuj4vE3r54ed1v9+Qk653xFbsNdklWBDcS3zLam9w7j X-Received: by 2002:a05:6a00:1a88:b0:6ce:2732:580 with SMTP id e8-20020a056a001a8800b006ce27320580mr2515799pfv.49.1701555877592; Sat, 02 Dec 2023 14:24:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701555877; cv=none; d=google.com; s=arc-20160816; b=rT7a/+MKquKpWOmgTdJFbTo0PRmGqAWfV9pD6nKx/LTcf5JoDms0f9aZAi8OTomBTi I+raP/n8FQTdW5DBXWapyybDL8BE9DdanbFHbCZj6Z405e2CfoaHp6HJD0xnkUmQnVnP N8kaRDytFN08HKIJGK9ZEoikpJ34tByv8ZGmiVYaFvNlcrs5FzR76ir3cWmDkIdHo35S ZWqNxlCRtcw29v15o4Z6C+tExctipxrbEpgxv6eVJe7SV9FwX/47BQVea8xP0Y4GDvDl WqqaI4COiaka6WB7rKmSuyN71X/JILkNW1zYWHEXCE/hD3Z7+4QnSfQQADFOv5JSFIKv s0Ug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=JouOYVZrp8QV/3VfEzvwkAud600ko/u80md+bt1HERk=; fh=oNZTEI/dsuHqCrxO1zrrS0d86lb00OCd9qYnwvQ9LU8=; b=Kqjx0nZ+vd952phaymEhv9ZgRhs1vhIuOX8J92Svx/YGyYaPd/VbXujHK3n8vLOHe0 3cA90fsZUJDkNKNQcQQyqguC3QXpt/+ZVxISDrrFRlc9qpiOWDxfsdMJ5QNjhiFibnKJ C4TFgHFOWzo7VgTQ4RDuGyMSQ3Mk8ACHWBL9skR/2mEPTg1QGudNa0nzjpO/N/P12tLM 8Ga/NqiDodVwQdiAZEXx9pF/rdG0CZCe7cycZ9w6KBPfk7TxjSU919tCmi+RezxTCjC9 IdNWCpFQRaU6R2dmIHnQxQH7R7bhmOiwbxZIVoWKOjcaPmRI0hgdDuGPca6UIuBkqHgT ZiyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VuoOK1Wj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id h14-20020a63e14e000000b005bdfda8e044si5423635pgk.775.2023.12.02.14.24.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 Dec 2023 14:24:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VuoOK1Wj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id E46E4803F8E1; Sat, 2 Dec 2023 14:24:34 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229531AbjLBWYW (ORCPT + 99 others); Sat, 2 Dec 2023 17:24:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53396 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229450AbjLBWYV (ORCPT ); Sat, 2 Dec 2023 17:24:21 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4B4B107 for ; Sat, 2 Dec 2023 14:24:27 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6FFBAC433C7; Sat, 2 Dec 2023 22:24:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701555867; bh=SXHC0x0+GI/myrZriQvLJwxGk27i20x6fkxa1/3/bpM=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=VuoOK1Wjn8FfBN+hGBnOMYLJZWL9lC0XOMzRyyx7NM9Jxn3/End/IN5zCy1Ji06Fs rhNsNyWn/yanHCsbBYzo1g/ccueP+EHWUYYZQa1MBCuQEAjfWshj5sX6RsondAnVu4 GgpyPJJezNvFHb8A4jDmuGAISCVzA8+Z9dMwTE565NTFzXUbSul1YI782yuZopJRT5 3dGR33R7fRg/Vqz1q2lZS60phJggbA/N/PLLmqqOEvTrAWHrSdYyjXM7NuCsJPrFEn QBtpece4r12j4uIiUlCjMTWmTWa7avqi6v3pED4kzXPGB1+1OEwwgfFprv2sjSWQDv azSkmE7JCPe7w== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id F16EFCE10DA; Sat, 2 Dec 2023 14:24:26 -0800 (PST) Date: Sat, 2 Dec 2023 14:24:26 -0800 From: "Paul E. McKenney" To: Steven Rostedt Cc: LKML , rcu@vger.kernel.org, Frederic Weisbecker , Joel Fernandes , Mathieu Desnoyers Subject: Re: [RCU] rcu_tasks_trace_qs(): trc_reader_special.b.need_qs value incorrect likely()? Message-ID: Reply-To: paulmck@kernel.org References: <20231201154932.468d088b@gandalf.local.home> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231201154932.468d088b@gandalf.local.home> X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Sat, 02 Dec 2023 14:24:35 -0800 (PST) On Fri, Dec 01, 2023 at 03:49:32PM -0500, Steven Rostedt wrote: > Paul, > > I just started running my branch tracer (that checks all branches and also > gives likely and unlikely correctness). And I found this: > > correct incorrect % Function File Line > ------- --------- - -------- ---- ---- > 0 1217713 100 rcu_softirq_qs tree.c 247 > > Which comes down to this: > > > # define rcu_tasks_trace_qs(t) \ > do { \ > int ___rttq_nesting = READ_ONCE((t)->trc_reader_nesting); \ > \ > if (likely(!READ_ONCE((t)->trc_reader_special.b.need_qs)) && \ > likely(!___rttq_nesting)) { \ > rcu_trc_cmpxchg_need_qs((t), 0, TRC_NEED_QS_CHECKED); \ > } else if (___rttq_nesting && ___rttq_nesting != INT_MIN && \ > !READ_ONCE((t)->trc_reader_special.b.blocked)) { \ > rcu_tasks_trace_qs_blkd(t); \ > } \ > } while (0) > > > I added just before the likely/unlikely to my test box and I see this: > > trace_printk("need qs? %d %d\n", READ_ONCE((t)->trc_reader_special.b.need_qs), ___rttq_nesting); \ > > -0 [005] d.h1. 2.482412: rcu_sched_clock_irq: need qs? 2 0 > -0 [002] d.h1. 2.482464: rcu_sched_clock_irq: need qs? 2 0 > -0 [000] d.h1. 2.482766: rcu_sched_clock_irq: need qs? 2 0 > -0 [001] d.h1. 2.482951: rcu_sched_clock_irq: need qs? 2 0 > -0 [007] d.h1. 2.482958: rcu_sched_clock_irq: need qs? 2 0 > -0 [005] d.h1. 2.483600: rcu_sched_clock_irq: need qs? 2 0 > -0 [002] d.h1. 2.483624: rcu_sched_clock_irq: need qs? 2 0 > -0 [000] d.h1. 2.483927: rcu_sched_clock_irq: need qs? 2 0 > -0 [007] d.h1. 2.484068: rcu_sched_clock_irq: need qs? 2 0 > -0 [001] d.h1. 2.484127: rcu_sched_clock_irq: need qs? 2 0 > -0 [002] d.h1. 2.484723: rcu_sched_clock_irq: need qs? 2 0 > -0 [005] d.h1. 2.484745: rcu_sched_clock_irq: need qs? 2 0 > -0 [000] d.h1. 2.485015: rcu_sched_clock_irq: need qs? 2 0 > -0 [007] d.h1. 2.485202: rcu_sched_clock_irq: need qs? 2 0 > -0 [001] d.h1. 2.485258: rcu_sched_clock_irq: need qs? 2 0 > -0 [002] d.h1. 2.485818: rcu_sched_clock_irq: need qs? 2 0 > -0 [005] d.h1. 2.485929: rcu_sched_clock_irq: need qs? 2 0 > -0 [000] d.h1. 2.486224: rcu_sched_clock_irq: need qs? 2 0 > -0 [007] d.h1. 2.486370: rcu_sched_clock_irq: need qs? 2 0 > -0 [001] d.h1. 2.486399: rcu_sched_clock_irq: need qs? 2 0 > -0 [002] d.h1. 2.486895: rcu_sched_clock_irq: need qs? 2 0 > -0 [005] d.h1. 2.487049: rcu_sched_clock_irq: need qs? 2 0 > -0 [000] d.h1. 2.487318: rcu_sched_clock_irq: need qs? 2 0 > -0 [007] d.h1. 2.487472: rcu_sched_clock_irq: need qs? 2 0 > -0 [001] d.h1. 2.487522: rcu_sched_clock_irq: need qs? 2 0 > -0 [002] d.h1. 2.488034: rcu_sched_clock_irq: need qs? 2 0 > -0 [005] d.h1. 2.488220: rcu_sched_clock_irq: need qs? 2 0 > > > Note, that "2" is the READ_ONCE() without the "!" to it. Thus: > > if (likely(!READ_ONCE((t)->trc_reader_special.b.need_qs)) && \ > > Is unlikely to be true. > > Was this supposed to be: > > if (!likely(READ_ONCE((t)->trc_reader_special.b.need_qs)) && \ > > Or could it be converted to: > > if (unlikely(!READ_ONCE((t)->trc_reader_special.b.need_qs)) && \ > > ? > > Note, the unlikely tracing is running on my production server v6.6.3. > > The above trace is from my test box with latest Linus's tree. Nice tool!!! My kneejerk reaction is that that condition is suboptimal. Does the (untested) patch below help things? Thanx, Paul diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h index aa87c82236dd..1df1dc9e8620 100644 --- a/include/linux/rcupdate.h +++ b/include/linux/rcupdate.h @@ -184,9 +184,9 @@ void rcu_tasks_trace_qs_blkd(struct task_struct *t); do { \ int ___rttq_nesting = READ_ONCE((t)->trc_reader_nesting); \ \ - if (likely(!READ_ONCE((t)->trc_reader_special.b.need_qs)) && \ + if (unlikely(READ_ONCE((t)->trc_reader_special.b.need_qs) == TRC_NEED_QS) && \ likely(!___rttq_nesting)) { \ - rcu_trc_cmpxchg_need_qs((t), 0, TRC_NEED_QS_CHECKED); \ + rcu_trc_cmpxchg_need_qs((t), TRC_NEED_QS, TRC_NEED_QS_CHECKED); \ } else if (___rttq_nesting && ___rttq_nesting != INT_MIN && \ !READ_ONCE((t)->trc_reader_special.b.blocked)) { \ rcu_tasks_trace_qs_blkd(t); \