From nobody Mon Sep 02 09:12:40 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Wy31j1sKMz5MqZQ; Mon, 02 Sep 2024 09:12:41 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Wy31j0Ctsz4CS3; Mon, 2 Sep 2024 09:12:41 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1725268361; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Vq6xW3F9wBub8udzyCx/ufr05U81bazozwnAYYK8KFo=; b=ksh7Ta1gvK6nFlcGjOhFpq9GAxsCCIWRU4ECRIQpuVW4xWlz3tPR+O8wekqtfPf08xZ3hl WE5+5VYRTH1Fcw3FD1VdlePMSBR528wz5nR9B+19adAmNxLqsBtNxbwrrQmwhCDm/vFJrs UAyqwLqMwtpDFt5py8rPlMustHw2fBUnKjxlexaZVi901lyHyOnEIBNj6QbNE624MUJLhk biMHR+2TqZ/I7wJMjQBFUnPkg0PeZQFw7J2QDLmUDnjsF34aVytntnaYzOZ7RE2U6nf5BN XhKKPmxTItqZ4m5nn06bNuoH8NwqN6vyIg2yXVtILcbzcb1ZQCWrnKQ/s7j/Pg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1725268361; a=rsa-sha256; cv=none; b=lfb4+FijMOjT45rqg60WVBtvPelK6TmoL75cyKm6oL02Xh0L4qfebAtH48SW+g/2p1n2Wr PHxJJ4cAq4Pm83/q2U6qeWSEViFXgFbiJEGeI4cBujATxLp1URicSR2MYYnNZ4Ia2Sqf7K GNsB5EHYs0pBAewS1NvVsjzP2089gSoVfvsfbIzV8z7yeSwGTBPCMjxL9lvGHav/o8UyzZ dl+gMK/fuw8frrkFgZDmErDL7NYRJBSlqH1exdT2MuA8jb8ib/f1iOgFDkGRCkZBJ8jmgC mSJ/Y+3y/SNU8BdxxMiaWYK3kXamUjF6hLRingEqFzzQB6jwm/LuEcf1Wyf35g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1725268361; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Vq6xW3F9wBub8udzyCx/ufr05U81bazozwnAYYK8KFo=; b=BjwVN8Vi3YYX7cAlVbKMkkDpAsrotnvjb6YCoqQ5PO89WxLXQJJ1O4oXXMsCeXgp8BMMH3 ljvvVSl4S0t13554LaXO22BIcGMlrVdeKCo0ociepp88ambPk+DlxWJWX+ivDbNZj7z7TP IVav6qJQfGcwh0hen4W9gucE4ZzpPS1ea3ZY78JfV76rq9AfyuWlY+mr7em2IvRACqLbC3 sublELTTGO0MFZVWzde4uk4waAaqjhw9xv7RXQYaoK8lidDJJZTIvewI+vx7W5MtjHzzE9 vEw2U1VSZ2fMBwz27n6ZaZd8b6d5dlkDuewVXCwfozefSGuumwmMhS7Xt2naWg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Wy31h6yDqz160j; Mon, 2 Sep 2024 09:12:40 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 4829Cebm049707; Mon, 2 Sep 2024 09:12:40 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4829Ce9t049704; Mon, 2 Sep 2024 09:12:40 GMT (envelope-from git) Date: Mon, 2 Sep 2024 09:12:40 GMT Message-Id: <202409020912.4829Ce9t049704@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Andrew Turner Subject: git: 292b2f9c5d14 - stable/13 - buf_ring: Make buf_ring.h amenable to userspace compilation List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: andrew X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 292b2f9c5d141fbc4a9f7ef2df3e3950a467e69f Auto-Submitted: auto-generated The branch stable/13 has been updated by andrew: URL: https://cgit.FreeBSD.org/src/commit/?id=292b2f9c5d141fbc4a9f7ef2df3e3950a467e69f commit 292b2f9c5d141fbc4a9f7ef2df3e3950a467e69f Author: Mark Johnston AuthorDate: 2024-07-11 18:55:11 +0000 Commit: Andrew Turner CommitDate: 2024-09-02 09:11:57 +0000 buf_ring: Make buf_ring.h amenable to userspace compilation This will be useful for adding test cases. Reviewed by: andrew MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D45869 (cherry picked from commit a161269b2451140a45de2d0cae0dad84f9e7b439) --- sys/sys/buf_ring.h | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/sys/sys/buf_ring.h b/sys/sys/buf_ring.h index 21e221220331..0645f97aa77c 100644 --- a/sys/sys/buf_ring.h +++ b/sys/sys/buf_ring.h @@ -30,11 +30,18 @@ #ifndef _SYS_BUF_RING_H_ #define _SYS_BUF_RING_H_ +#include +#include +#include #include #ifdef DEBUG_BUFRING +#ifdef _KERNEL #include #include +#else +#error "DEBUG_BUFRING is only supported in kernel" +#endif #endif struct buf_ring { @@ -361,8 +368,36 @@ buf_ring_count(struct buf_ring *br) & br->br_prod_mask); } +#ifdef _KERNEL struct buf_ring *buf_ring_alloc(int count, struct malloc_type *type, int flags, struct mtx *); void buf_ring_free(struct buf_ring *br, struct malloc_type *type); +#else -#endif +#include + +static inline struct buf_ring * +buf_ring_alloc(int count) +{ + struct buf_ring *br; + + KASSERT(powerof2(count), ("buf ring must be size power of 2")); + + br = calloc(1, sizeof(struct buf_ring) + count * sizeof(void *)); + if (br == NULL) + return (NULL); + br->br_prod_size = br->br_cons_size = count; + br->br_prod_mask = br->br_cons_mask = count - 1; + br->br_prod_head = br->br_cons_head = 0; + br->br_prod_tail = br->br_cons_tail = 0; + return (br); +} + +static inline void +buf_ring_free(struct buf_ring *br) +{ + free(br); +} + +#endif /* !_KERNEL */ +#endif /* _SYS_BUF_RING_H_ */