Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp987364ybp; Fri, 4 Oct 2019 08:00:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqxReGUydqwGmAumk555xv75qomHaHlqH6gHxoLdQTY0mOOQAh/g3aTXtdVTMtpcEg/JxRQ7 X-Received: by 2002:a17:906:e288:: with SMTP id gg8mr12818574ejb.24.1570201226740; Fri, 04 Oct 2019 08:00:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570201226; cv=none; d=google.com; s=arc-20160816; b=fNkQdH2aYIZoGM9T9CywECfdUZiI1On0SPeUNZ9w8iV5v26+ESg0BXXdRSpOBvkSlY XAQjXHwlTcO407Xeud9nXvMazJClchzVjw2pToeBh0B2ZjiU+WEOBn9rhEOI8GgwcP94 M11olDEQYHtXANhTuh8xozsWAO+eqFB99+5ynmmskyVCGy5/Gidsxp6xqO70Mvajr9Ju fThzG7p9nE4TlZVTk4pGqmIVrx/59FQlhm81tSNiZjLk5Kafqc/tSNpnxTGtGr277Qo0 h2c2MHLRhCzzvWUvGNJoW4dfHICxbAKmtVCy9seIulV8uoK/XlAZvm21emP4pQqPBEoR dqiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=w2obvvD0YQZHLEq7fGZQtKqybBtTNFyX7qrcoUNkcuk=; b=OkcMOSAJmz2CE3G0QdrqjIFv7AV+X1sdCoFdjefQgriuJo3Wlf9IL2cjYG+LFL62tZ cWOhsSGJJuX4ijjUBdOwFvVdoqUycmOn1GQCJ9JLJTo2v6+t4v3hHwxOTJpcvdOfiArc VElqEMqv5tYYqS4+gfKkIKl+IgwadPmn3ra2uHTl0LNj+FxXXKGsRZIS88xON/e3RoId KI9MzPrhtxhjfyLT5D4mZJjm18EJzkl/LiaeD2vk1G2pd8X5Jg7viXt3r9qQyulrKm36 3YhlSP3NaK6jLt36eruMuSoxN9dtH/wboVba5rCpS0ydObZNersio9zE37ExWychKCcW Wjdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=rHRl2+0W; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f21si3497441edb.379.2019.10.04.08.00.02; Fri, 04 Oct 2019 08:00:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=rHRl2+0W; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389479AbfJDO5u (ORCPT + 99 others); Fri, 4 Oct 2019 10:57:50 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:43404 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389378AbfJDO5t (ORCPT ); Fri, 4 Oct 2019 10:57:49 -0400 Received: by mail-pf1-f194.google.com with SMTP id a2so4042973pfo.10 for ; Fri, 04 Oct 2019 07:57:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=w2obvvD0YQZHLEq7fGZQtKqybBtTNFyX7qrcoUNkcuk=; b=rHRl2+0WeuRHpPB43fer0wtZz/voElxZMtstXIZ3hcmNuzWRZgK4eVFDJ3Q81Z2Sqb Un7WPlI4qOfGUn1c8LB+Egj32h+XnRx6kv0yULoLdwsm2mhUGZeSZ3s8B5sIR9F2lyWs vhSDEQ3ns/7NluK3dqLsKxVEYMuplU/HMAET0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=w2obvvD0YQZHLEq7fGZQtKqybBtTNFyX7qrcoUNkcuk=; b=VJAVqBIJqrid5M+AwpYh6sI4c3wSNMd+zDn+DZUUxDxCizvcRwbfkdk7sfAmET+yfW EuE14HAvX1M40v07bDCLmd3xLg/m17REAVRJP8Sw+MwWEymag7FsNVXH0ldi2Q4Jt2wj hiuj0UNdftT9qRUFZDDOpZpEDNArzlsfjnXLkfZcOhrDzjg/zNTgygWJhL087BuiPCs9 PqrugxaFheOKZlk596zBmHv5bSqvQG76IFUXiTKPXBUNF7GWAVJ1vXssXEfT1spiIAMd t8AkDbEzwuiBcTIU+VzuQvsFF1WENr9WX64ET+cE9mlqY7DS78KI6Nn+o2i90zYKXhXv evww== X-Gm-Message-State: APjAAAVUzhXqobQUzbDmIsVpoeslO5EJI64Bl/4iew17e5HPsM6vfSpd l7exGd2cfaMJg7gAn4CJPR2tWD0E5Fk= X-Received: by 2002:a63:1e16:: with SMTP id e22mr16011959pge.413.1570201068335; Fri, 04 Oct 2019 07:57:48 -0700 (PDT) Received: from joelaf.cam.corp.google.com ([2620:15c:6:12:9c46:e0da:efbf:69cc]) by smtp.gmail.com with ESMTPSA id w134sm7668359pfd.4.2019.10.04.07.57.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Oct 2019 07:57:47 -0700 (PDT) From: "Joel Fernandes (Google)" To: linux-kernel@vger.kernel.org Cc: Joel Fernandes , bristot@redhat.com, peterz@infradead.org, oleg@redhat.com, paulmck@kernel.org, rcu@vger.kernel.org, Josh Triplett , Lai Jiangshan , Mathieu Desnoyers , "Paul E. McKenney" , Steven Rostedt Subject: [PATCH] Remove GP_REPLAY state from rcu_sync Date: Fri, 4 Oct 2019 10:57:41 -0400 Message-Id: <20191004145741.118292-1-joel@joelfernandes.org> X-Mailer: git-send-email 2.23.0.581.g78d2f28ef7-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Joel Fernandes Please consider this is an RFC for discussion only. Just want to discuss why the GP_REPLAY state is needed at all. Here's the intention AFAICS: When rcu_sync_exit() has happened, the gp_state changes to GP_EXIT while we wait for a grace period before transitioning to GP_IDLE. In the meanwhile, if we receive another rcu_sync_exit(), then we want to wait for another GP to account for that. Drawing some timing diagrams, it looks like this: Legend: rse = rcu_sync_enter rsx = rcu_sync_exit i = GP_IDLE x = GP_EXIT r = GP_REPLAY e = GP_ENTER p = GP_PASSED rx = GP_REPLAY changes to GP_EXIT GP num = The GP we are one. note: A GP passes between the states: e and p x and i x and rx rx and i In a simple case, the timing and states look like: time ----------------------> GP num 1111111 2222222 GP state i e p x i CPU0 : rse rsx However we can enter the replay state like this: time ----------------------> GP num 1111111 2222222222222222222223333333 GP state i e p x r rx i CPU0 : rse rsx CPU1 : rse rsx Due to the second rse + rsx, we had to wait for another GP. I believe the rationale is, if another rsx happens, another GP has to happen. But this is not always true if you consider the following events: time ----------------------> GP num 111111 22222222222222222222222222222222233333333 GP state i e p x r rx i CPU0 : rse rsx CPU1 : rse rsx CPU2 : rse rsx Here, we had 3 grace periods that elapsed, 1 for the rcu_sync_enter(), and 2 for the rcu_sync_exit(s). However, we had 3 rcu_sync_exit()s, not 2. In other words, the rcu_sync_exit() got batched. So my point here is, rcu_sync_exit() does not really always cause a new GP to happen and we can end up having the rcu_sync_exit()s as batched and sharing the same grace period. Then what is the point of the GP_REPLAY state at all if it does not always wait for a new GP? Taking a step back, why did we intend to have to wait for a new GP if another rcu_sync_exit() comes while one is still in progress? Cc: bristot@redhat.com Cc: peterz@infradead.org Cc: oleg@redhat.com Cc: paulmck@kernel.org Cc: rcu@vger.kernel.org Signed-off-by: Joel Fernandes (Google) --- kernel/rcu/sync.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/kernel/rcu/sync.c b/kernel/rcu/sync.c index d4558ab7a07d..4f3aad67992c 100644 --- a/kernel/rcu/sync.c +++ b/kernel/rcu/sync.c @@ -10,7 +10,7 @@ #include #include -enum { GP_IDLE = 0, GP_ENTER, GP_PASSED, GP_EXIT, GP_REPLAY }; +enum { GP_IDLE = 0, GP_ENTER, GP_PASSED, GP_EXIT }; #define rss_lock gp_wait.lock @@ -85,13 +85,6 @@ static void rcu_sync_func(struct rcu_head *rhp) */ WRITE_ONCE(rsp->gp_state, GP_PASSED); wake_up_locked(&rsp->gp_wait); - } else if (rsp->gp_state == GP_REPLAY) { - /* - * A new rcu_sync_exit() has happened; requeue the callback to - * catch a later GP. - */ - WRITE_ONCE(rsp->gp_state, GP_EXIT); - rcu_sync_call(rsp); } else { /* * We're at least a GP after the last rcu_sync_exit(); eveybody @@ -167,16 +160,13 @@ void rcu_sync_enter(struct rcu_sync *rsp) */ void rcu_sync_exit(struct rcu_sync *rsp) { - WARN_ON_ONCE(READ_ONCE(rsp->gp_state) == GP_IDLE); - WARN_ON_ONCE(READ_ONCE(rsp->gp_count) == 0); + WARN_ON_ONCE(READ_ONCE(rsp->gp_state) < GP_PASSED); spin_lock_irq(&rsp->rss_lock); if (!--rsp->gp_count) { if (rsp->gp_state == GP_PASSED) { WRITE_ONCE(rsp->gp_state, GP_EXIT); rcu_sync_call(rsp); - } else if (rsp->gp_state == GP_EXIT) { - WRITE_ONCE(rsp->gp_state, GP_REPLAY); } } spin_unlock_irq(&rsp->rss_lock); -- 2.23.0.581.g78d2f28ef7-goog