Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp1745943rbb; Mon, 26 Feb 2024 22:41:21 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUTyZ5LmsvlDeymAxiD7ZNnj6UUhqFy2zDCRfb4qzzdA3jnRnsbhzyVVeRmSlFpbs+qYXEoonej/c70cc7tU3XBrcH+KLD4SnBq4pYuMQ== X-Google-Smtp-Source: AGHT+IHwhkKm05AdQxLK45AyyVs5GEUaTD3XMAYnuAZeV6qxonwNKg4sLJ6HuBQjlmYKfGqucab6 X-Received: by 2002:a05:620a:2a08:b0:787:1fba:5848 with SMTP id o8-20020a05620a2a0800b007871fba5848mr1553937qkp.74.1709016080946; Mon, 26 Feb 2024 22:41:20 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709016080; cv=pass; d=google.com; s=arc-20160816; b=UIP4lq/yc/glF7a4IZJ77E5NF/1Zl+atVxULh9izu5bBLynQ1XTVomk58U2b1mcMwt hcyl470NhLSwmUw7aMiBRsJ9cxfbJXluI3JDjnxptSfti/X+Hk+n/0U82psqrcjhKVuP KQuLZkJOkuKmhsC9sbPav5bweQK42On2pPyZBAd6YrOlPyvyuen5uNkWVQmPVQfoynkD 0tuSf58PZPQ4qXGAy9JDdNpm0PKA0maDfiVWwpLpTDg30RtAeFNstg9hMF3mSWsyAx2L ptjOkAs42WkncCYvraoznt/dswNVBY58F1l/49vXshb6O5F/hzjmU12lFZ/9n4MlZ+Qx 4DBQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :dkim-signature; bh=dx2RNt3R8rZc7pTxB1fOzWWdwOyApPRS74B6TRm04bY=; fh=edweYs19FcKXyo9JVPEQeVth3BDbOVPff5B3LmkQBtA=; b=LuqzuvILJYudDUVnPnEibzk1xhSB0ir4f/81s63cqO/VTc7B/imjV3SKF4C8vgrcZZ s6EMZinqe9ZdEwO0N3Qib6m8+KcxYee6XvxFfIKXcIZfX155dQ4uEgC7gQH+lgJUoCpJ C8IkaHP9h7FUIEvEZVw9GqKK4+IzIqkxHHWzUn+D1LuMNUcEJnYBXrjnF9deTm7WS/je BRrjCnIfxkkq9HUb263DC0hHzoH2K3y5ZqWVC4LFpgZQdW8l7ta6wJ/Yf1975k0lIi0Q kzcE/Rkfw1DISrax30Ns5rNIqm0kVFZgp+39INA6CLsi0pWUpJbMJligmwq86r7J/yHv QCeg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=MvQGAyOC; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-82752-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-82752-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id e27-20020a05620a209b00b00787236a4ba6si6779718qka.387.2024.02.26.22.41.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 22:41:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-82752-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=MvQGAyOC; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-82752-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-82752-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 2DE8B1C21402 for ; Tue, 27 Feb 2024 06:40:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4DEC653389; Tue, 27 Feb 2024 06:40:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MvQGAyOC" Received: from mail-pg1-f181.google.com (mail-pg1-f181.google.com [209.85.215.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0BB0D41C6A; Tue, 27 Feb 2024 06:40:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709016009; cv=none; b=pqeUR+Ok+qnU3jR2bjMl98fKs2Qo/5Du2o/zzb46WM2PaT0tr0plgD9H5YKfkTEKewnXTN78t20M+RM2uUhJa4rcWVNdMuWP7flnvxX6H71X0IQmAeO3TC7e0QGPriUq9+gHs9Db9cK19+fe/Ue4v+dVqZnZ37N86nMwBdjhFMw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709016009; c=relaxed/simple; bh=mjGBzkk8NtbmFG0WlX04o018Vs4aUWGPZ3MgTwyCc3s=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=E5ZbW2bmtvMkOEBshdvt0fMjvsGvcowHxWR+T+Jfg8IYef8Yr07poBbgtzzHtbaB2YZDgyaLUoSms7xPwiceCBzkZRHsL51/Bx27IRaTtQ8cfBtrvDtYj3zuMU0Qq6SVNjboAWrRfX3lzPBQJIFKtzLaMqk0DOXeifMawzwNPtM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=MvQGAyOC; arc=none smtp.client-ip=209.85.215.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pg1-f181.google.com with SMTP id 41be03b00d2f7-5cddc5455aeso3738233a12.1; Mon, 26 Feb 2024 22:40:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709016007; x=1709620807; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=dx2RNt3R8rZc7pTxB1fOzWWdwOyApPRS74B6TRm04bY=; b=MvQGAyOC0Cl6qaV6CWJ0rP7AkgDl8QrkZ+vNQzdm8mlGtyGMltXOuE88ZoLr7BZyPQ xetS7Iar2HONNQapWjMgRyoNfyax4EPt1X+AKeS+k90N/SX6acAQaVTNHak3NORxcqqY jdw+nDASBgHHLgvkJ7QtuSKf0XX/Z3UxuUkPIXHmmcfaYPklNlmHNXyHbGixmZyqWGfw tVo2icKckWxUa/Q2YTfhQPNBSD+oA3gU5gUk9n0L7eA5N1KiJT8nZstJdW4yEml27UNe A9kBBU9QwZz94rf2hQ3KUFk78OVpI7cp4RvsQBrgRRi4vuB8D05y7vPDMSzSMBGGgNvn ySLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709016007; x=1709620807; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=dx2RNt3R8rZc7pTxB1fOzWWdwOyApPRS74B6TRm04bY=; b=ib7H7jNxiJnS5urpEM6il7mG/yTQiHmPkZQn3aiQcZimYsZAXSAAw6SYDjgQWMPjZk ycgM6JxOnzND4em5T/qCvn79hikYgkWz7IsOnCwW3vnJ8FiyD8F3XcGBeWm8iaWlQXcU tk7wR7/c3OtLrrXb19uz0jqPvWSTrZt4BuvFlsD8mqoer0TIG7nm4OHr6rHkDtcnvF4T lJkZT8ZWK6USWrJF56A9yIeeQ/iy85O3eVtZkw4dCqy78TbJYJn7xBNorVvcOWMkIP/1 d2604fdjBAFgGj+h4laMC18tyaCEDxWAR+0D+zagpz+SsZxhZWoJA1CEpmJMn4mvAzln xIDQ== X-Forwarded-Encrypted: i=1; AJvYcCVVgkkHAOY/cKChK+Ln4yC1ci3nq7WEh06ihzgaHkmYJ7FUTIj03+e0mDx06QRKDYQHyPrk4qcsTpHgAhAaSBHfyQqzyB0je8z0Y2fhacqgiH5CZSvQdEodneuOCTR7upG9 X-Gm-Message-State: AOJu0YzLPJ4ZoKLYWyifwKHiIIFQcnU14ZutbhKKddkQuxcREK1PSCaQ 9qswbVPyVLNMzs3504he8ZWORzgkLAG/ohL1Vfed/PypVSKkOlN3C2wHw090LpuucnOZtQbibUN 70uZu76l8BWw9cR6C7fNNS43Y0NQ= X-Received: by 2002:a05:6a21:9103:b0:19e:bc8f:d0ca with SMTP id tn3-20020a056a21910300b0019ebc8fd0camr1212398pzb.58.1709016007197; Mon, 26 Feb 2024 22:40:07 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240220183115.74124-1-urezki@gmail.com> <20240220183115.74124-3-urezki@gmail.com> In-Reply-To: From: Z qiang Date: Tue, 27 Feb 2024 14:39:55 +0800 Message-ID: Subject: Re: [PATCH v5 2/4] rcu: Reduce synchronize_rcu() latency To: Frederic Weisbecker Cc: "Uladzislau Rezki (Sony)" , "Paul E . McKenney" , RCU , Neeraj upadhyay , Boqun Feng , Hillf Danton , Joel Fernandes , LKML , Oleksiy Avramchenko Content-Type: text/plain; charset="UTF-8" > > On Tue, Feb 20, 2024 at 07:31:13PM +0100, Uladzislau Rezki (Sony) wrote: > > +static void rcu_sr_normal_gp_cleanup_work(struct work_struct *work) > > +{ > > + struct llist_node *done, *rcu, *next, *head; > > + > > + /* > > + * This work execution can potentially execute > > + * while a new done tail is being updated by > > + * grace period kthread in rcu_sr_normal_gp_cleanup(). > > + * So, read and updates of done tail need to > > + * follow acq-rel semantics. > > + * > > + * Given that wq semantics guarantees that a single work > > + * cannot execute concurrently by multiple kworkers, > > + * the done tail list manipulations are protected here. > > + */ > > + done = smp_load_acquire(&rcu_state.srs_done_tail); > > + if (!done) > > + return; > > + > > + WARN_ON_ONCE(!rcu_sr_is_wait_head(done)); > > + head = done->next; > > + done->next = NULL; > > Can the following race happen? > > CPU 0 CPU 1 > ----- ----- > > // wait_tail == HEAD1 > rcu_sr_normal_gp_cleanup() { > // has passed SR_MAX_USERS_WAKE_FROM_GP > wait_tail->next = next; > // done_tail = HEAD1 > smp_store_release(&rcu_state.srs_done_tail, wait_tail); > queue_work() { > test_and_set_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(work) > __queue_work() > } > } > > set_work_pool_and_clear_pending() > rcu_sr_normal_gp_cleanup_work() { > // new GP, wait_tail == HEAD2 > rcu_sr_normal_gp_cleanup() { > // executes all completion, but stop at HEAD1 > wait_tail->next = HEAD1; > // done_tail = HEAD2 > smp_store_release(&rcu_state.srs_done_tail, wait_tail); > queue_work() { > test_and_set_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(work) > __queue_work() > } > } > // done = HEAD2 > done = smp_load_acquire(&rcu_state.srs_done_tail); > // head = HEAD1 > head = done->next; > done->next = NULL; > llist_for_each_safe() { > // completes all callbacks, release HEAD1 > } > } > // Process second queue > set_work_pool_and_clear_pending() > rcu_sr_normal_gp_cleanup_work() { > // done = HEAD2 > done = smp_load_acquire(&rcu_state.srs_done_tail); > > // new GP, wait_tail == HEAD3 > rcu_sr_normal_gp_cleanup() { > // Finds HEAD2 with ->next == NULL at the end > rcu_sr_put_wait_head(HEAD2) It seems that we should move rcu_sr_put_wait_head() from rcu_sr_normal_gp_cleanup() to rcu_sr_normal_gp_cleanup_work(), if find wait_head->next == NULL, invoke rcu_sr_put_wait_head() to release wait_head. Thanks Zqiang > ... > > // A few more GPs later > rcu_sr_normal_gp_init() { > HEAD2 = rcu_sr_get_wait_head(); > llist_add(HEAD2, &rcu_state.srs_next); > // head == rcu_state.srs_next > head = done->next; > done->next = NULL; > llist_for_each_safe() { > // EXECUTE CALLBACKS TOO EARLY!!! > } > } >