From patchwork Fri May 18 13:03:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Pen X-Patchwork-Id: 10410719 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 720F06031B for ; Fri, 18 May 2018 13:08:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 568F528535 for ; Fri, 18 May 2018 13:08:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 49412285A4; Fri, 18 May 2018 13:08:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E918A28984 for ; Fri, 18 May 2018 13:08:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752244AbeERNHl (ORCPT ); Fri, 18 May 2018 09:07:41 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:38788 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752473AbeERNF2 (ORCPT ); Fri, 18 May 2018 09:05:28 -0400 Received: by mail-wm0-f65.google.com with SMTP id m129-v6so15006126wmb.3 for ; Fri, 18 May 2018 06:05:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=profitbricks-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=UD9ycGB1AdB2iWHLig1MDOmhC2Bw6On0cibjUFZbKyA=; b=T6rxnJIaNwgW73X63hmBUi9cRwZ+lsyXtokyhzUOL6xzzEZzecGR/K8h/gKEyT7r6v 1h0xdPOl+Z2cBQWVHDQf7jMh40SxOIoVeWkGY4EuHh+x8cnyooXXpI0Gr6hPI8bq5tj7 oCZI+dZsV0kIh0eWsy430UvRlZk6v//27pFYUwAARbpsY8U23u2ZxGOboUxgui0a2OfB OrAxcI6mGhqfNhpHo1GNmvL0M4X+CFIIghx0Wr1srA89t9nJKvIWYqYAKLnyB987Z3Ik ctLdWeY+qIBlqJ7waIpB9b+Xz3v/H0DP+hHO7vjh6DveRfhR4IbpWtI2YwdvqA+Cj5TK aG0w== 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:in-reply-to :references; bh=UD9ycGB1AdB2iWHLig1MDOmhC2Bw6On0cibjUFZbKyA=; b=IVK0OBLvIYDtIIiaMcqpCwWsj5jBjuoDik/OGcbpWdOkjRw6nHDJnCPjqhwDVuCUPb OHC+LrwuhFOR5WebKE5mr0qAX9NzTz1fwryZMOdZJKkOdFpAtV16vMpRx5CCtiiqgC/H 8sq66Dzoz8V3uY4L8bP0VL3jG4ifRf6NPdaG4hQZW1ltIbperhe7FhGTaPQwGQjZKspN ngnOfyVcRpo1jzSJ/TLsGC74i0XGvX1OYn7vRptGPl0ap+Rmzei//yJ4L7PWesNEH7hB jxTi7etLiwb7fAPK6gZbyJqm/v4wo27nMpXF4C0R8WE8JYz6DnkbB7yjN/M4T6X8y0W+ XGqg== X-Gm-Message-State: ALKqPweeVU4HB0tWiW7e5Mz94C8si/m3ytypcsKbqQvCvGZKt6v5/MJ4 2XL9m4cS4Rl/6f6ucT1PMbmkK3Ho X-Google-Smtp-Source: AB8JxZpGViDMXI2BBNMBz9f3Q3uG5PCp2Vv6nY7KrEy6b0E0aA8adpwJdrWHv01u43YKt9Zjg10TDQ== X-Received: by 2002:a1c:7f0a:: with SMTP id a10-v6mr4931805wmd.97.1526648727114; Fri, 18 May 2018 06:05:27 -0700 (PDT) Received: from pb.pb.local ([62.217.45.26]) by smtp.gmail.com with ESMTPSA id m35-v6sm7639980wrm.51.2018.05.18.06.05.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 May 2018 06:05:26 -0700 (PDT) From: Roman Pen To: linux-block@vger.kernel.org, linux-rdma@vger.kernel.org Cc: Jens Axboe , Christoph Hellwig , Sagi Grimberg , Bart Van Assche , Or Gerlitz , Doug Ledford , Swapnil Ingle , Danil Kipnis , Jack Wang , Roman Pen , "Paul E . McKenney" , linux-kernel@vger.kernel.org Subject: [PATCH v2 01/26] rculist: introduce list_next_or_null_rr_rcu() Date: Fri, 18 May 2018 15:03:48 +0200 Message-Id: <20180518130413.16997-2-roman.penyaev@profitbricks.com> X-Mailer: git-send-email 2.13.1 In-Reply-To: <20180518130413.16997-1-roman.penyaev@profitbricks.com> References: <20180518130413.16997-1-roman.penyaev@profitbricks.com> Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Function is going to be used in transport over RDMA module in subsequent patches. Function returns next element in round-robin fashion, i.e. head will be skipped. NULL will be returned if list is observed as empty. Signed-off-by: Roman Pen Cc: Paul E. McKenney Cc: linux-kernel@vger.kernel.org --- include/linux/rculist.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/include/linux/rculist.h b/include/linux/rculist.h index 127f534fec94..b0840d5ab25a 100644 --- a/include/linux/rculist.h +++ b/include/linux/rculist.h @@ -339,6 +339,25 @@ static inline void list_splice_tail_init_rcu(struct list_head *list, }) /** + * list_next_or_null_rr_rcu - get next list element in round-robin fashion. + * @head: the head for the list. + * @ptr: the list head to take the next element from. + * @type: the type of the struct this is embedded in. + * @memb: the name of the list_head within the struct. + * + * Next element returned in round-robin fashion, i.e. head will be skipped, + * but if list is observed as empty, NULL will be returned. + * + * This primitive may safely run concurrently with the _rcu list-mutation + * primitives such as list_add_rcu() as long as it's guarded by rcu_read_lock(). + */ +#define list_next_or_null_rr_rcu(head, ptr, type, memb) \ +({ \ + list_next_or_null_rcu(head, ptr, type, memb) ?: \ + list_next_or_null_rcu(head, READ_ONCE((ptr)->next), type, memb); \ +}) + +/** * list_for_each_entry_rcu - iterate over rcu list of given type * @pos: the type * to use as a loop cursor. * @head: the head for your list.