Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp1698225pxb; Fri, 20 Nov 2020 17:02:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJypwGFql6oZMII8wQxTZ5r9BNcIjNcG4W/Cm5k/EOF8HPSmPcG1ND9B/wG5B0dLlUt1FVkq X-Received: by 2002:aa7:d891:: with SMTP id u17mr770904edq.0.1605920536299; Fri, 20 Nov 2020 17:02:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605920536; cv=none; d=google.com; s=arc-20160816; b=kkke6QAaH6nkCHmTFh1/YdPQMZtekzLr+vOiCFBeQSL2CyGbzu9vZuOaIZdwwmD3re omQKQwH8L9kOwqHnD8/3dGbym/rlm+ayFh9eTbfj13HyCiQj6yT3iNmus4v3O8141/+9 kx6P6CBZYrDIacz7lxkriKdC8AfNNZ14cUVJ+bC3daWEDJ/73yBA6gW5G1+9eXKrrqwE +LER2HUOHB2RSuf/+ok3ZUz1Bl190tHS5jQMzvGXir5ndaC/exWLxnO/B4Wzz1xI0GdM dbTkLN+az7pqvK0lGbnz6waES/T/P9ZQPdM97m4bw9eplqLhSwyqepBcapGziNZQ+eha lvYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=Y1qxKvEOGA6rsjDWtLWQWfEnR0rlfCCJaaPG29secpA=; b=RBhRfHTdZwFhkG4IES8MPNMjyTSltaPF1mGoQ/8DrjAYiwn117cHHsFFHNfnZEdtiH wKl43VWGpye6m//2Eh+D6NrKU4fjpfSGYqOCjCGwEKiOICHZhwjS/v+vypBMOV3KHvAK 1h1POTozS6l7M10YiyuKxS6hgC9v3Q/uh6iZ0NF2wc85Y1r2wS5U+2713+kkawrmI+S/ hG7X6hQj7NA2GQ6ZicBW8LIvy85mwWN5gFkleYdhyfvfHpwhqqwA5oZpoIIun6aPLLLk ZFk9q+k1/pzCKQK9zmQOv88FhnD6OQneHINYpHNBn7R4fv1m6DpB2M74WpkzJZjgr6A0 TOOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="FDPP4wu/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b6si2885619edv.126.2020.11.20.17.01.53; Fri, 20 Nov 2020 17:02:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="FDPP4wu/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1728648AbgKUA7W (ORCPT + 99 others); Fri, 20 Nov 2020 19:59:22 -0500 Received: from mail.kernel.org ([198.145.29.99]:37470 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728408AbgKUA7V (ORCPT ); Fri, 20 Nov 2020 19:59:21 -0500 Received: from paulmck-ThinkPad-P72.home (50-39-104-11.bvtn.or.frontiernet.net [50.39.104.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E952723A65; Sat, 21 Nov 2020 00:59:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1605920361; bh=77M/WPfBKgKGM1bhdEmIEogJMD8lmHt73p2vCfZoFzU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FDPP4wu/EFqI0mBcLTTyHKzcv8O+qD+hFI7EU2Ir8ThKCc3angisYr09e5rJn2kIW z6QRBmGzRQqdsJiPmYo8PJBOTiRjbZca1GPJuWXKpoSY69CI0g2ecktJxBGj47KyRK ld6dqbvaDxkT8U9AYx9OMWKMO9RQaHM7G8sd6gV0= From: paulmck@kernel.org To: rcu@vger.kernel.org Cc: linux-kernel@vger.kernel.org, kernel-team@fb.com, mingo@kernel.org, jiangshanlai@gmail.com, akpm@linux-foundation.org, mathieu.desnoyers@efficios.com, josh@joshtriplett.org, tglx@linutronix.de, peterz@infradead.org, rostedt@goodmis.org, dhowells@redhat.com, edumazet@google.com, fweisbec@gmail.com, oleg@redhat.com, joel@joelfernandes.org, kent.overstreet@gmail.com, "Paul E. McKenney" Subject: [PATCH v2 tip/core/rcu 1/6] srcu: Make Tiny SRCU use multi-bit grace-period counter Date: Fri, 20 Nov 2020 16:59:14 -0800 Message-Id: <20201121005919.17152-1-paulmck@kernel.org> X-Mailer: git-send-email 2.9.5 In-Reply-To: <@@@> References: <@@@> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Paul E. McKenney" There is a need for a polling interface for SRCU grace periods. This polling needs to distinguish between an SRCU instance being idle on the one hand or in the middle of a grace period on the other. This commit therefore converts the Tiny SRCU srcu_struct structure's srcu_idx from a defacto boolean to a free-running counter, using the bottom bit to indicate that a grace period is in progress. The second-from-bottom bit is thus used as the index returned by srcu_read_lock(). Link: https://lore.kernel.org/rcu/20201112201547.GF3365678@moria.home.lan/ Reported-by: Kent Overstreet [ paulmck: Fix __srcu_read_lock() idx computation Neeraj per Upadhyay. ] Signed-off-by: Paul E. McKenney --- include/linux/srcutiny.h | 4 ++-- kernel/rcu/srcutiny.c | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/include/linux/srcutiny.h b/include/linux/srcutiny.h index 5a5a194..d9edb67 100644 --- a/include/linux/srcutiny.h +++ b/include/linux/srcutiny.h @@ -15,7 +15,7 @@ struct srcu_struct { short srcu_lock_nesting[2]; /* srcu_read_lock() nesting depth. */ - short srcu_idx; /* Current reader array element. */ + unsigned short srcu_idx; /* Current reader array element in bit 0x2. */ u8 srcu_gp_running; /* GP workqueue running? */ u8 srcu_gp_waiting; /* GP waiting for readers? */ struct swait_queue_head srcu_wq; @@ -59,7 +59,7 @@ static inline int __srcu_read_lock(struct srcu_struct *ssp) { int idx; - idx = READ_ONCE(ssp->srcu_idx); + idx = ((READ_ONCE(ssp->srcu_idx) + 1) & 0x2) >> 1; WRITE_ONCE(ssp->srcu_lock_nesting[idx], ssp->srcu_lock_nesting[idx] + 1); return idx; } diff --git a/kernel/rcu/srcutiny.c b/kernel/rcu/srcutiny.c index 6208c1d..5598cf6 100644 --- a/kernel/rcu/srcutiny.c +++ b/kernel/rcu/srcutiny.c @@ -124,11 +124,12 @@ void srcu_drive_gp(struct work_struct *wp) ssp->srcu_cb_head = NULL; ssp->srcu_cb_tail = &ssp->srcu_cb_head; local_irq_enable(); - idx = ssp->srcu_idx; - WRITE_ONCE(ssp->srcu_idx, !ssp->srcu_idx); + idx = (ssp->srcu_idx & 0x2) / 2; + WRITE_ONCE(ssp->srcu_idx, ssp->srcu_idx + 1); WRITE_ONCE(ssp->srcu_gp_waiting, true); /* srcu_read_unlock() wakes! */ swait_event_exclusive(ssp->srcu_wq, !READ_ONCE(ssp->srcu_lock_nesting[idx])); WRITE_ONCE(ssp->srcu_gp_waiting, false); /* srcu_read_unlock() cheap. */ + WRITE_ONCE(ssp->srcu_idx, ssp->srcu_idx + 1); /* Invoke the callbacks we removed above. */ while (lh) { -- 2.9.5