Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp753403ybz; Wed, 15 Apr 2020 18:12:41 -0700 (PDT) X-Google-Smtp-Source: APiQypJqdF3XFA+zDZaCAPfRO+RUyWwPE+daTU2Qi2w7JGu4kR6QzHfMwbqA95wEj5OKZzk9krlz X-Received: by 2002:a50:f699:: with SMTP id d25mr27548846edn.244.1586999561363; Wed, 15 Apr 2020 18:12:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586999561; cv=none; d=google.com; s=arc-20160816; b=Tm3W08I1lYCwcU35w4oBhyijuveNOqEb9dn8OAdaTnsxWDbA4WCQ5GiSCprPHDw5L+ Svk/QPl6t6S2YEWA5lMkqWjbJUuKjl2+BwzkLwv9K0m3e5w7iRkyu26LmOJXKMF1ANQk jFGxS2YvLPakDaYOPFfyeGZnJue7otiYgV1blyepftyy+v/x1+8C5P0ONVL40U+oa00/ Skc1dxJ+koDrAfRKkl1g3mco0X6PO4YNLY4IGSIinCqXOdUi4dSobW6NWhGxAsvovc0Z r62ZHbYX0AGTRH6CXzIU6BO2kOrdGMa1qiTJ9vApmb/2dNQWV67aaHXpvhUbuewmhljo QQrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=zg3ob5dFIHsdWUyPt1RU43xeZYyJjlIPkOiX/f8YR84=; b=o4ZvfmElUj1dLI72E7zj0+h8orK4hetle9C/Zl3RtB9HOTniCfJxuSDAq7rKxFfMeD oekdeC2SE4Cgb3j+F+PE9R7Ytcy6Hx++H1rzS0cDMvHijfW4RzoeZC5NRiBOnTupuzKH sU1SSZk4cVLguGP8eF8Bio+IA3FMD8PKZzYO8VitIBviUP6fJQ22gkqoswwKu3IXMT+g 50fXgJ4PSthIOsaZzxGm1o4E7LT1fYjAI+6/JGzcv/IcKXCLK/56QKjojl4emvgeEXq8 vxin+R0EeBehrhjTBoeLfjolKOkhOm7+ReI0J2qhbQO+qrUfpHXZsfpGzv3k7pm7z9Pq 0oIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ogbq48oE; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id nm2si7619628ejb.243.2020.04.15.18.12.16; Wed, 15 Apr 2020 18:12:41 -0700 (PDT) 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=@gmail.com header.s=20161025 header.b=ogbq48oE; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732045AbgDOW1O (ORCPT + 99 others); Wed, 15 Apr 2020 18:27:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1727993AbgDOW1H (ORCPT ); Wed, 15 Apr 2020 18:27:07 -0400 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D283C061A0C; Wed, 15 Apr 2020 15:27:07 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id z6so2067572wml.2; Wed, 15 Apr 2020 15:27:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=zg3ob5dFIHsdWUyPt1RU43xeZYyJjlIPkOiX/f8YR84=; b=ogbq48oEXKMvuX6Wqc6V76/Y7aYtAhaE3UxZLBIRfJWjqKTFOGiMRkVg03+/9opHA0 Nq6JVFRzLkJTSiWD4gAsFBQEX7eFyrNMHD7B3XftHASOHKXdIzeVyv4D7j69sC1bLwIe aPFXb+CYlnhKrsIqHb2AXECHd6qlZ4mH4rZ4cEhZQ9ZnNOHzycXeSdFC0KuJMtcuhINR UO5jtzUV+dpWuVz/6KV/c6mIHKpGO8vTqMFIxRaN5d9gy+mtTGct+2KDKgvJQCCs3Fvy QpYmYrE3jVGqaF+PyeEh8uOYzopcs35jPRrF1Ac2l3N3RQDta9L8/ERN881JxIBhXm0X OBhw== 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; bh=zg3ob5dFIHsdWUyPt1RU43xeZYyJjlIPkOiX/f8YR84=; b=scLId3iEV3u4iyy+5md9kBsHOJ168jni7pinyGawwapuGY7VQd1qehZ6J60gshiRxP faWnpUndNbTLQV6c1MgglQwU/JpuavQjAa1YgbJ0yNlIF0um+UH+AMBkNUVyOR2ukL9N sLasdSeelGafspvuRHnNEgsH4PvslZ0mikxadN2A3csW1+qlgMyiNgnB6sTPROijglkE 9XA8DprLrv9Pw3qjcBlzsrvdd7qDX2A1OCyDISRhBNUn5dy+sMpDUt1gSA9Au9ju525i p12JOYkcX709CEfpf5NBnXQD0i3T/uYLh2qOEnjrVfnjfqrtGytnBj+pTzQuwYfx40Ln 8RUQ== X-Gm-Message-State: AGi0PuZ8ddYhVP8nHyBafBbSUZMFy26owqzRU4XahPfz7xQ1GNq8eh7m VQ8IBzAYumBzD+zdxUxWiQ8= X-Received: by 2002:a1c:1d4b:: with SMTP id d72mr1421501wmd.19.1586989626211; Wed, 15 Apr 2020 15:27:06 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id b4sm20105151wrv.42.2020.04.15.15.27.05 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 15 Apr 2020 15:27:05 -0700 (PDT) From: Wei Yang To: paulmck@kernel.org, josh@joshtriplett.org Cc: rcu@vger.kernel.org, linux-kernel@vger.kernel.org, Wei Yang Subject: [PATCH] rcu: init and destroy rcu_synchronize when necessary Date: Wed, 15 Apr 2020 22:26:55 +0000 Message-Id: <20200415222655.9006-1-richard.weiyang@gmail.com> X-Mailer: git-send-email 2.11.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We would skip the rcu_synchronize if it is a duplicate call back function. This is not necessary to init and destroy for them. Signed-off-by: Wei Yang --- kernel/rcu/update.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c index 6c4b862f57d6..91e44b527aad 100644 --- a/kernel/rcu/update.c +++ b/kernel/rcu/update.c @@ -353,13 +353,14 @@ void __wait_rcu_gp(bool checktiny, int n, call_rcu_func_t *crcu_array, might_sleep(); continue; } - init_rcu_head_on_stack(&rs_array[i].head); - init_completion(&rs_array[i].completion); for (j = 0; j < i; j++) if (crcu_array[j] == crcu_array[i]) break; - if (j == i) + if (j == i) { + init_rcu_head_on_stack(&rs_array[i].head); + init_completion(&rs_array[i].completion); (crcu_array[i])(&rs_array[i].head, wakeme_after_rcu); + } } /* Wait for all callbacks to be invoked. */ @@ -370,9 +371,10 @@ void __wait_rcu_gp(bool checktiny, int n, call_rcu_func_t *crcu_array, for (j = 0; j < i; j++) if (crcu_array[j] == crcu_array[i]) break; - if (j == i) + if (j == i) { wait_for_completion(&rs_array[i].completion); - destroy_rcu_head_on_stack(&rs_array[i].head); + destroy_rcu_head_on_stack(&rs_array[i].head); + } } } EXPORT_SYMBOL_GPL(__wait_rcu_gp); -- 2.23.0