From patchwork Wed Apr 22 03:30:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Honnappa Nagarahalli X-Patchwork-Id: 185652 Delivered-To: patch@linaro.org Received: by 2002:a92:3d9a:0:0:0:0:0 with SMTP id k26csp251842ilf; Tue, 21 Apr 2020 20:30:44 -0700 (PDT) X-Google-Smtp-Source: APiQypIejCd3qnAkUf3tMHx68MDv8SzYhQmzvfDV2/w6MXT0R+TFQPzSwh0KuMy+4++k14NaipYV X-Received: by 2002:a05:6402:1757:: with SMTP id v23mr22378093edx.335.1587526244573; Tue, 21 Apr 2020 20:30:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587526244; cv=none; d=google.com; s=arc-20160816; b=fuLXSUOl7Rm4yT/0JwjShyR9mHBvLsPCG6W5e839AlWqiHBh1XfRxCRkiEZjVVNWJt 6BRqZH1p8Hs+m7VkYxPFxAIPyVr1XbC8X1lRmACeoF8U7/bB3JZh06iXlvKOM81tk1Gd LwV+d2lHOtfSc6vaFWNkwqwak7IMF59k7Nr0fhHV1CRRYaGxvAkiAiaNEDPkmKNn8FaS sbk0zthCrJOcBH2bDm2Yhe7hDVpeHNHUEUUCSlyIEd9W3e/X7sx4gpH0c3+aomxsJvI2 F0cKYYZljSFmdWu9q1YdiVp4IsxgTubSPpsqCKeVA0elsCYvjx+7dmUIypAp4bDDWWBo JDaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:cc:to:from; bh=YL9ZdZGE1Du239JZwls0MEYmphnyWITfOPaomcgGl9Y=; b=IEXOCzdwB+n2kDISRG35/N5oOtCsWyzqbuhJno4MW8FnL/3oc5A6NIkimZVEo0BhnZ xyIABvXDva++rIY9gNs/hMP9MdVqNhghgzjs5KF58aDerKK+bBiGk0g50sN5QkjFKrAs FPoFGAofdion3Vib/+oZ8YMGj28BsRxP1WdRqlM8Vio9lBbuDu8NuHwj1deq2fW3YZRL T626NA1cfy0uE3pcFDRDzpDc5T2ss9ckC7cpwDX72LW5jBNXjG/jhP+cgkCyW1S/MRF0 ZOzxt99J5MSgXve7jpPnnX2ipTkLvYgdDDnS83fjUupRUXCfxM9bw1HqyWq4RuoLq2x6 N2aA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org Return-Path: Received: from dpdk.org (dpdk.org. [92.243.14.124]) by mx.google.com with ESMTP id oh24si2818530ejb.531.2020.04.21.20.30.44; Tue, 21 Apr 2020 20:30:44 -0700 (PDT) Received-SPF: pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) client-ip=92.243.14.124; Authentication-Results: mx.google.com; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 2CFF01C2EF; Wed, 22 Apr 2020 05:30:38 +0200 (CEST) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by dpdk.org (Postfix) with ESMTP id 461F01C1DF for ; Wed, 22 Apr 2020 05:30:35 +0200 (CEST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 9B4181045; Tue, 21 Apr 2020 20:30:34 -0700 (PDT) Received: from qc2400f-1.austin.arm.com (qc2400f-1.austin.arm.com [10.118.14.48]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8933A3F6CF; Tue, 21 Apr 2020 20:30:34 -0700 (PDT) From: Honnappa Nagarahalli To: konstantin.ananyev@intel.com, stephen@networkplumber.org, vladimir.medvedkin@intel.com, dev@dpdk.org Cc: honnappa.nagarahalli@arm.com, david.marchand@redhat.com, ruifeng.wang@arm.com, dharmik.thakkar@arm.com, nd@arm.com Date: Tue, 21 Apr 2020 22:30:05 -0500 Message-Id: <20200422033006.1124-4-honnappa.nagarahalli@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200422033006.1124-1-honnappa.nagarahalli@arm.com> References: <20191001062917.35578-1-honnappa.nagarahalli@arm.com> <20200422033006.1124-1-honnappa.nagarahalli@arm.com> Subject: [dpdk-dev] [PATCH v5 3/4] doc/rcu: add RCU integration design details X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Ruifeng Wang Add a section to describe a design to integrate QSBR RCU library with other libraries in DPDK. Signed-off-by: Honnappa Nagarahalli Signed-off-by: Ruifeng Wang Reviewed-by: Gavin Hu Reviewed-by: Ruifeng Wang --- doc/guides/prog_guide/rcu_lib.rst | 59 +++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) -- 2.17.1 diff --git a/doc/guides/prog_guide/rcu_lib.rst b/doc/guides/prog_guide/rcu_lib.rst index 9b0bf138f..60468f143 100644 --- a/doc/guides/prog_guide/rcu_lib.rst +++ b/doc/guides/prog_guide/rcu_lib.rst @@ -190,3 +190,62 @@ However, when ``CONFIG_RTE_LIBRTE_RCU_DEBUG`` is enabled, these APIs aid in debugging issues. One can mark the access to shared data structures on the reader side using these APIs. The ``rte_rcu_qsbr_quiescent()`` will check if all the locks are unlocked. + +Resource reclamation framework for DPDK +--------------------------------------- + +Lock-free algorithms place additional burden of resource reclamation on +the application. When a writer deletes an entry from a data structure, the writer: + +#. Has to start the grace period +#. Has to store a reference to the deleted resources in a FIFO +#. Should check if the readers have completed a grace period and free the resources. + +There are several APIs provided to help with this process. The writer +can create a FIFO to store the references to deleted resources using ``rte_rcu_qsbr_dq_create()``. +The resources can be enqueued to this FIFO using ``rte_rcu_qsbr_dq_enqueue()``. +If the FIFO is full, ``rte_rcu_qsbr_dq_enqueue`` will reclaim the resources before enqueuing. It will also reclaim resources on regular basis to keep the FIFO from growing too large. If the writer runs out of resources, the writer can call ``rte_rcu_qsbr_dq_reclaim`` API to reclaim resources. ``rte_rcu_qsbr_dq_delete`` is provided to reclaim any remaining resources and free the FIFO while shutting down. + +However, if this resource reclamation process were to be integrated in lock-free data structure libraries, it +hides this complexity from the application and makes it easier for the application to adopt lock-free algorithms. The following paragraphs discuss how the reclamation process can be integrated in DPDK libraries. + +In any DPDK application, the resource reclamation process using QSBR can be split into 4 parts: + +#. Initialization +#. Quiescent State Reporting +#. Reclaiming Resources +#. Shutdown + +The design proposed here assigns different parts of this process to client libraries and applications. The term 'client library' refers to lock-free data structure libraries such at rte_hash, rte_lpm etc. in DPDK or similar libraries outside of DPDK. The term 'application' refers to the packet processing application that makes use of DPDK such as L3 Forwarding example application, OVS, VPP etc.. + +The application has to handle 'Initialization' and 'Quiescent State Reporting'. So, + +* the application has to create the RCU variable and register the reader threads to report their quiescent state. +* the application has to register the same RCU variable with the client library. +* reader threads in the application have to report the quiescent state. This allows for the application to control the length of the critical section/how frequently the application wants to report the quiescent state. + +The client library will handle 'Reclaiming Resources' part of the process. The +client libraries will make use of the writer thread context to execute the memory +reclamation algorithm. So, + +* client library should provide an API to register a RCU variable that it will use. It should call ``rte_rcu_qsbr_dq_create()`` to create the FIFO to store the references to deleted entries. +* client library should use ``rte_rcu_qsbr_dq_enqueue`` to enqueue the deleted resources on the FIFO and start the grace period. +* if the library runs out of resources while adding entries, it should call ``rte_rcu_qsbr_dq_reclaim`` to reclaim the resources and try the resource allocation again. + +The 'Shutdown' process needs to be shared between the application and the +client library. + +* the application should make sure that the reader threads are not using the shared data structure, unregister the reader threads from the QSBR variable before calling the client library's shutdown function. + +* client library should call ``rte_rcu_qsbr_dq_delete`` to reclaim any remaining resources and free the FIFO. + +Integrating the resource reclamation with client libraries removes the burden from +the application and makes it easy to use lock-free algorithms. + +This design has several advantages over currently known methods. + +#. Application does not need a dedicated thread to reclaim resources. Memory + reclamation happens as part of the writer thread with little impact on + performance. +#. The client library has better control over the resources. For ex: the client + library can attempt to reclaim when it has run out of resources.