From nobody Mon Jul 22 00:55:34 2024 X-Original-To: dev-commits-src-branches@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 4WS1zW1zGgz5QwlK; Mon, 22 Jul 2024 00:55:35 +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 4WS1zV6t08z4hvQ; Mon, 22 Jul 2024 00:55:34 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1721609735; 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=5JTqRmrJQ0c5BJ5l2U7N3yrYDqpkLK5CFPh1uGd3Wk8=; b=bEYFIS4EHTym3aU5Fz8hXvzLJyWVI0uHpu/zP9vo7m1vKJ+uo+JuC2ulpA8vyJk8lGczc/ nCj6KWbLH7Ez19d0KMl169KSusIO0bjPECvtWUxC7NJk3SYhiL5RHdV/JbvrpvBZhaZ2Mi 3r4nZGEtKQ7LJ9F8378oTdwKBPmLelUUoipXn065412OEonL8+HX+RpraVzgC5hO2TE/iJ aVHn+ehKM31/y6hTSx6gV8w2xs1QgFfup1CCikS0l97WVAZ0DaMUpMRgrsQWb8pZTah7L7 O0OLBaiRV/N/WwUZZF+Nr5UtVdPB5eBDsBGSS//rYipj28aJWd2h2Ew0Tqh3Ug== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1721609735; a=rsa-sha256; cv=none; b=O6B/cjIBx3Jlk97K6E4OWNkNfLqpxpkDt/2s8VjbNvCkYkdEOQetdVF/7YKiLHiiIXdDb4 fElgdNoJ0RjPi3y5LrTh3oiSjiFCbwbXL3prcS00AnpJ7uuqgBlhvbv0fv7PGxlulVmdiR MW3aNs20aWbFLtFLPirz6Wq/itzHYdP/qtlTbrZkWDQpy7XXnm6Oh6v7OBWJ0q2bDVJlPW CSgPJAlf6AkXPXQlDMH1tfRm2gRiukERKpx2bXhrQOetNVQVhowdWG9GALGrribkm42lK8 L8bohI79baOMlEcggFwubpTudfHS5yr+N11Duj7MTrwMXPD6fPNd8HNeuI0D1w== 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=1721609735; 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=5JTqRmrJQ0c5BJ5l2U7N3yrYDqpkLK5CFPh1uGd3Wk8=; b=iHVaQk6dnT+D60/zYxUGSWLz1cqnhHOQc8+b6hdetgSYgMsumtWBaMeKvvv4JwekaxD09f yPdTw1jnkozONuwMVJ0P2mfl/v/JFojm8fAyXuwl6peXrbnbijL4M8cJfzNG60N70/rYde cFdlRJpJHU8iNcu+xlNk72R5b40me1brsh0OGz8Zn3aFKdAJ/bX7Fofcx6sbb4J8jswuxT UvLb5qOTnYZm5JWBrcd+epI46UZwltlb67gMbOkYmjDoyfGUk+A939831eCcVCDskyQCGR 1U2hZkfs5sQ4pX5dzytwCVkxowVLn159ul2F601lrZTasfp+HuloWV0Ff3wA3w== 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 4WS1zV6VGkzNb7; Mon, 22 Jul 2024 00:55:34 +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 46M0tYRd007201; Mon, 22 Jul 2024 00:55:34 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 46M0tYVO007198; Mon, 22 Jul 2024 00:55:34 GMT (envelope-from git) Date: Mon, 22 Jul 2024 00:55:34 GMT Message-Id: <202407220055.46M0tYVO007198@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 7d521f0a61ff - stable/14 - buf_ring: Make buf_ring.h amenable to userspace compilation List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 7d521f0a61ff8be5778979d97e71760fe8559e14 Auto-Submitted: auto-generated The branch stable/14 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=7d521f0a61ff8be5778979d97e71760fe8559e14 commit 7d521f0a61ff8be5778979d97e71760fe8559e14 Author: Mark Johnston AuthorDate: 2024-07-11 18:55:11 +0000 Commit: Mark Johnston CommitDate: 2024-07-22 00:55:27 +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 32c9f5b15f22..cb18175c3a75 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_ */