Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp4507141rdb; Fri, 15 Sep 2023 04:36:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHXIqHcCNTG9Is8WAmfj4jwT7Md+gHguiM6THhQiN5NcThX7ZxQ++BHZJhtE40FU/epoXMJ X-Received: by 2002:a05:6358:91a6:b0:141:3a1:1877 with SMTP id j38-20020a05635891a600b0014103a11877mr1719944rwa.14.1694777803540; Fri, 15 Sep 2023 04:36:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694777803; cv=none; d=google.com; s=arc-20160816; b=S/e1P1XKs954PDUaUr7TfiTedASElaYfQnR/IM1axFA7hl5SglnQz2nzrRHlrT0OJ7 nD+w9re8cULtEG3ZLXD3KCHfKSx7FCeyGAhzexqYhuXye9Cvmuh/qkDQGqUE49Fe7QKm Ls/LIt3c8s+SmSFQBEKNV6XUrgEsfgipGuDh8T/+K+ap/85ES6aTrn5sqEbWopuoMJ1a IMSuBvjz6jU5A9KCUtMjprDs/wTbW7CXYHHV2bzy6dgtE1tK5CKOLPo7imi16tTCS0Qx Zpp23OJEwn6saBpRJL20GAiuWcLiNt/MZCPRMQpvSsvjbdMXn8phn7Dq5YCUR4RWmqbY 3F7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:references:in-reply-to:subject :cc:to:from:mime-version:content-transfer-encoding:dkim-signature :dkim-signature; bh=lRhO5Usk0tWo8ZTx91/qTeniCJK8iZhQwKtez0oWKNI=; fh=cX8hcLzHSbgevn4g7kKEfpGxSGhfYnzQMjDoTjch0j0=; b=Qj+dBGfU3dGSWmJ/t8fQrWTnPj7XsruOl/FS2U4PrAysO0Jlb6XCTaXp2hDweXoH/t I/d+Q/t7vXm1isdx12iBC+znIb5WMOBNWPN0znsE//U6sbG4ac5uSsmU+iXWhowO32Cn f7kEE785dlDtfhq1qIQZvef9K1leQ/ApK1Iiolt6M+ixODBSc/eFaSdKwMz8y54GI8eU FMRetfiVi35vVb09Ar/E6qPIQfSsmxpEts4I7yLrOkzx3PaAulRAaVoygW5DIIAebYIS siKGeFSUzT9MerhbDyT2958pF+uYrnPevx86FbQLNuggALpSvvaqaIsfQalT10z2AL1x UDeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=IEvMveqR; dkim=neutral (no key) header.i=@suse.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id h62-20020a638341000000b00573fcfcb5eesi3031212pge.726.2023.09.15.04.36.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 04:36:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=IEvMveqR; dkim=neutral (no key) header.i=@suse.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 57C1F838F06A; Thu, 14 Sep 2023 19:24:19 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231584AbjIOCYP (ORCPT + 99 others); Thu, 14 Sep 2023 22:24:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230512AbjIOCYO (ORCPT ); Thu, 14 Sep 2023 22:24:14 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5131C2130; Thu, 14 Sep 2023 19:24:10 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 889D82183F; Fri, 15 Sep 2023 02:24:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1694744643; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lRhO5Usk0tWo8ZTx91/qTeniCJK8iZhQwKtez0oWKNI=; b=IEvMveqRwkUSLtnNpuEc/3mI3EuLIDvJkQkS6zRouGGAPbmuTakqQTLTeAGdRIVQ+BCjln RaSxF4GJE47uB6ZBgOnNlTrKfKRywkCawzjEvATxUSUFHDyGQeR9vvPB320LVSXQfiHyhV 1KkljTisSXHWaBAfNnhmkTxLGCalNVs= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1694744643; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lRhO5Usk0tWo8ZTx91/qTeniCJK8iZhQwKtez0oWKNI=; b=hENIJPQHFR8kj/UMR6GFExr5ladvIWq3xMzpEmaHQAAyO5zfAjp0Dizjh/mLDXGRcPz99M 6khArsxN8tpdKcBw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id BB9EB1358A; Fri, 15 Sep 2023 02:24:00 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id eHqfG0DAA2W5HgAAMHmgww (envelope-from ); Fri, 15 Sep 2023 02:24:00 +0000 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit MIME-Version: 1.0 From: "NeilBrown" To: "Andrew Morton" , "Chuck Lever" Cc: "Linux NFS Mailing List" , "Liam Howlett" , "Kees Cook" , "Greg Kroah-Hartman" , "David Gow" , "linux-kernel@vger.kernel.org" Subject: [PATCH 11/17 SQUASH and replace commit message] lib: add light-weight queuing mechanism. In-reply-to: <20230911183025.5f808a70a62df79a3a1e349e@linux-foundation.org> References: <169444233785.4327.4365499966926096681.stgit@bazille.1015granger.net>, <169444318342.4327.18355944158180782708.stgit@bazille.1015granger.net>, <20230911111333.4d1a872330e924a00acb905b@linux-foundation.org>, <4D5C2693-40E9-467D-9F2F-59D92CBE9D3B@oracle.com>, <20230911140439.b273bf9e120881f038da0de7@linux-foundation.org>, <169447439989.19905.9386812394578844629@noble.neil.brown.name>, <20230911183025.5f808a70a62df79a3a1e349e@linux-foundation.org> Date: Fri, 15 Sep 2023 12:22:36 +1000 Message-id: <169474455669.8274.9157028681960361538@noble.neil.brown.name> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Thu, 14 Sep 2023 19:24:19 -0700 (PDT) X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email lwq is a FIFO single-linked queue that only requires a spinlock for dequeueing, which happens in process context. Enqueueing is atomic with no spinlock and can happen in any context. This is particularly useful when work items are queued from BH or IRQ context, and when they are handled one at a time by dedicated threads. Avoiding any locking when enqueueing means there is no need to disable BH or interrupts, which is generally best avoided (particularly when there are any RT tasks on the machine). This solution is superior to using "list_head" links because we need half as many pointers in the data structures, and because list_head lists would need locking to add items to the queue. This solution is superior to a bespoke solution as all locking and container_of casting is integrated, so the interface is simple. Despite the similar name, this solution meets a distinctly different need to kfifo. kfifo provides a fixed sized circular buffer to which data can be added at one end and removed at the other, and does not provide any locking. lwq does not have any size limit and works with data structures (objects?) rather than data (bytes). A unit test for basic functionality, which runs at boot time, is included. Signed-off-by: NeilBrown --- include/linux/lwq.h | 4 ++++ lib/lwq.c | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/include/linux/lwq.h b/include/linux/lwq.h index 52b9c81b493a..c4148fe1cf72 100644 --- a/include/linux/lwq.h +++ b/include/linux/lwq.h @@ -7,6 +7,10 @@ * * Entries can be enqueued from any context with no locking. * Entries can be dequeued from process context with integrated locking. + * + * This is particularly suitable when work items are queued in + * BH or IRQ context, and where work items are handled one at a time + * by dedicated threads. */ #include #include diff --git a/lib/lwq.c b/lib/lwq.c index 7fe6c7125357..eb8324225309 100644 --- a/lib/lwq.c +++ b/lib/lwq.c @@ -8,6 +8,10 @@ * Entries are dequeued using a spinlock to protect against * multiple access. The llist is staged in reverse order, and refreshed * from the llist when it exhausts. + * + * This is particularly suitable when work items are queued in + * BH or IRQ context, and where work items are handled one at a time + * by dedicated threads. */ #include #include -- 2.42.0