Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/tests/kernel/kqueue Add support for the EVFILT_EMPTY filter,...
details: https://anonhg.NetBSD.org/src/rev/c84f3f693781
branches: trunk
changeset: 989990:c84f3f693781
user: thorpej <thorpej%NetBSD.org@localhost>
date: Sat Oct 23 01:28:33 2021 +0000
description:
Add support for the EVFILT_EMPTY filter, which is activated when the
write buffer associated with the file descriptor is empty. This is
currently implemented only for sockets, and is intended primarily to
provide visibility to applications that all previously written data
has been acknowledged by the TCP layer on the receiver. Compatible
with the same filter in FreeBSD.
diffstat:
distrib/sets/lists/debug/mi | 3 +-
distrib/sets/lists/tests/mi | 3 +-
lib/libc/sys/kqueue.2 | 16 +++-
sys/kern/kern_event.c | 5 +-
sys/kern/uipc_socket.c | 31 ++++++-
sys/sys/event.h | 6 +-
sys/sys/socketvar.h | 13 ++-
tests/kernel/kqueue/Makefile | 5 +-
tests/kernel/kqueue/t_empty.c | 178 ++++++++++++++++++++++++++++++++++++++++++
9 files changed, 247 insertions(+), 13 deletions(-)
diffs (truncated from 422 to 300 lines):
diff -r 8d7ce6164f8c -r c84f3f693781 distrib/sets/lists/debug/mi
--- a/distrib/sets/lists/debug/mi Fri Oct 22 22:31:55 2021 +0000
+++ b/distrib/sets/lists/debug/mi Sat Oct 23 01:28:33 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.365 2021/10/13 04:57:19 thorpej Exp $
+# $NetBSD: mi,v 1.366 2021/10/23 01:28:33 thorpej Exp $
./etc/mtree/set.debug comp-sys-root
./usr/lib comp-sys-usr compatdir
./usr/lib/i18n/libBIG5_g.a comp-c-debuglib debuglib,compatfile
@@ -1760,6 +1760,7 @@
./usr/libdata/debug/usr/tests/kernel/kqueue/read/t_file2.debug tests-kernel-tests debug,atf,compattestfile
./usr/libdata/debug/usr/tests/kernel/kqueue/read/t_pipe.debug tests-kernel-tests debug,atf,compattestfile
./usr/libdata/debug/usr/tests/kernel/kqueue/read/t_ttypty.debug tests-kernel-tests debug,atf,compattestfile
+./usr/libdata/debug/usr/tests/kernel/kqueue/t_empty.debug tests-kernel-tests debug,atf,compattestfile
./usr/libdata/debug/usr/tests/kernel/kqueue/t_ioctl.debug tests-kernel-tests debug,atf,compattestfile
./usr/libdata/debug/usr/tests/kernel/kqueue/t_proc1.debug tests-kernel-tests debug,atf,compattestfile
./usr/libdata/debug/usr/tests/kernel/kqueue/t_proc2.debug tests-kernel-tests debug,atf,compattestfile
diff -r 8d7ce6164f8c -r c84f3f693781 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi Fri Oct 22 22:31:55 2021 +0000
+++ b/distrib/sets/lists/tests/mi Sat Oct 23 01:28:33 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1153 2021/10/22 22:31:55 rillig Exp $
+# $NetBSD: mi,v 1.1154 2021/10/23 01:28:34 thorpej Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@@ -2180,6 +2180,7 @@
./usr/tests/kernel/kqueue/read/t_file2 tests-kernel-tests compattestfile,atf
./usr/tests/kernel/kqueue/read/t_pipe tests-kernel-tests compattestfile,atf
./usr/tests/kernel/kqueue/read/t_ttypty tests-kernel-tests compattestfile,atf
+./usr/tests/kernel/kqueue/t_empty tests-kernel-tests compattestfile,atf
./usr/tests/kernel/kqueue/t_ioctl tests-kernel-tests compattestfile,atf
./usr/tests/kernel/kqueue/t_proc1 tests-kernel-tests compattestfile,atf
./usr/tests/kernel/kqueue/t_proc2 tests-kernel-tests compattestfile,atf
diff -r 8d7ce6164f8c -r c84f3f693781 lib/libc/sys/kqueue.2
--- a/lib/libc/sys/kqueue.2 Fri Oct 22 22:31:55 2021 +0000
+++ b/lib/libc/sys/kqueue.2 Sat Oct 23 01:28:33 2021 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: kqueue.2,v 1.56 2021/10/20 03:26:20 thorpej Exp $
+.\" $NetBSD: kqueue.2,v 1.57 2021/10/23 01:28:34 thorpej Exp $
.\"
.\" Copyright (c) 2000 Jonathan Lemon
.\" All rights reserved.
@@ -32,7 +32,7 @@
.\"
.\" $FreeBSD: src/lib/libc/sys/kqueue.2,v 1.22 2001/06/27 19:55:57 dd Exp $
.\"
-.Dd October 15, 2021
+.Dd October 22, 2021
.Dt KQUEUE 2
.Os
.Sh NAME
@@ -406,6 +406,13 @@
.Pp
For sockets, the low water mark and socket error handling is
identical to the EVFILT_READ case.
+.It Dv EVFILT_EMPTY
+Takes a descriptor as the identifier, and returns whenever
+there is no remaining data in the write buffer.
+This is currently implemented only for sockets.
+It's primary purpose is to provide visibility to an application that all
+previously written data has been acknowledged by the receiver at the TCP
+layer.
.It Dv EVFILT_AIO
This is not implemented in
.Nx .
@@ -871,3 +878,8 @@
.Dv EVFILT_VNODE
was added in
.Nx 10.0 .
+.Pp
+Support for
+.Dv EVFILT_EMPTY
+was added in
+.Nx 10.0 .
diff -r 8d7ce6164f8c -r c84f3f693781 sys/kern/kern_event.c
--- a/sys/kern/kern_event.c Fri Oct 22 22:31:55 2021 +0000
+++ b/sys/kern/kern_event.c Sat Oct 23 01:28:33 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_event.c,v 1.136 2021/10/22 04:49:24 thorpej Exp $ */
+/* $NetBSD: kern_event.c,v 1.137 2021/10/23 01:28:33 thorpej Exp $ */
/*-
* Copyright (c) 2008, 2009, 2021 The NetBSD Foundation, Inc.
@@ -63,7 +63,7 @@
#endif /* _KERNEL_OPT */
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_event.c,v 1.136 2021/10/22 04:49:24 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_event.c,v 1.137 2021/10/23 01:28:33 thorpej Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -212,6 +212,7 @@
{ "EVFILT_TIMER", EVFILT_TIMER, 0, &timer_filtops, 0 },
{ "EVFILT_FS", EVFILT_FS, 0, &fs_filtops, 0 },
{ "EVFILT_USER", EVFILT_USER, 0, &user_filtops, 0 },
+ { "EVFILT_EMPTY", EVFILT_EMPTY, 0, &file_filtops, 0 },
{ NULL, 0, 0, NULL, 0 },
};
diff -r 8d7ce6164f8c -r c84f3f693781 sys/kern/uipc_socket.c
--- a/sys/kern/uipc_socket.c Fri Oct 22 22:31:55 2021 +0000
+++ b/sys/kern/uipc_socket.c Sat Oct 23 01:28:33 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: uipc_socket.c,v 1.299 2021/10/11 01:07:36 thorpej Exp $ */
+/* $NetBSD: uipc_socket.c,v 1.300 2021/10/23 01:28:33 thorpej Exp $ */
/*
* Copyright (c) 2002, 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -71,7 +71,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uipc_socket.c,v 1.299 2021/10/11 01:07:36 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_socket.c,v 1.300 2021/10/23 01:28:33 thorpej Exp $");
#ifdef _KERNEL_OPT
#include "opt_compat_netbsd.h"
@@ -2297,6 +2297,22 @@
return rv;
}
+static int
+filt_soempty(struct knote *kn, long hint)
+{
+ struct socket *so;
+ int rv;
+
+ so = ((file_t *)kn->kn_obj)->f_socket;
+ if (hint != NOTE_SUBMIT)
+ solock(so);
+ rv = (kn->kn_data = sbused(&so->so_snd)) == 0 ||
+ (so->so_options & SO_ACCEPTCONN) != 0;
+ if (hint != NOTE_SUBMIT)
+ sounlock(so);
+ return rv;
+}
+
/*ARGSUSED*/
static int
filt_solisten(struct knote *kn, long hint)
@@ -2340,6 +2356,13 @@
.f_event = filt_sowrite,
};
+static const struct filterops soempty_filtops = {
+ .f_flags = FILTEROP_ISFD | FILTEROP_MPSAFE,
+ .f_attach = NULL,
+ .f_detach = filt_sowdetach,
+ .f_event = filt_soempty,
+};
+
int
soo_kqfilter(struct file *fp, struct knote *kn)
{
@@ -2360,6 +2383,10 @@
kn->kn_fop = &sowrite_filtops;
sb = &so->so_snd;
break;
+ case EVFILT_EMPTY:
+ kn->kn_fop = &soempty_filtops;
+ sb = &so->so_snd;
+ break;
default:
sounlock(so);
return EINVAL;
diff -r 8d7ce6164f8c -r c84f3f693781 sys/sys/event.h
--- a/sys/sys/event.h Fri Oct 22 22:31:55 2021 +0000
+++ b/sys/sys/event.h Sat Oct 23 01:28:33 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: event.h,v 1.50 2021/10/21 02:34:04 thorpej Exp $ */
+/* $NetBSD: event.h,v 1.51 2021/10/23 01:28:33 thorpej Exp $ */
/*-
* Copyright (c) 1999,2000,2001 Jonathan Lemon <jlemon%FreeBSD.org@localhost>
@@ -45,7 +45,8 @@
#define EVFILT_TIMER 6U /* arbitrary timer (in ms) */
#define EVFILT_FS 7U /* filesystem events */
#define EVFILT_USER 8U /* user events */
-#define EVFILT_SYSCOUNT 9U /* number of filters */
+#define EVFILT_EMPTY 9U
+#define EVFILT_SYSCOUNT 10U /* number of filters */
#ifdef EVFILT_NAMES
static const char *evfiltnames[] = {
@@ -58,6 +59,7 @@
"EVFILT_TIMER",
"EVFILT_FS",
"EVFILT_USER",
+ "EVFILT_EMPTY",
};
#endif
diff -r 8d7ce6164f8c -r c84f3f693781 sys/sys/socketvar.h
--- a/sys/sys/socketvar.h Fri Oct 22 22:31:55 2021 +0000
+++ b/sys/sys/socketvar.h Sat Oct 23 01:28:33 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: socketvar.h,v 1.163 2020/11/23 00:52:53 chs Exp $ */
+/* $NetBSD: socketvar.h,v 1.164 2021/10/23 01:28:33 thorpej Exp $ */
/*-
* Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -424,6 +424,17 @@
return lmin(hiwat - sb->sb_cc, sb->sb_mbmax - sb->sb_mbcnt);
}
+/*
+ * How much socket buffer space has been used?
+ */
+static __inline u_long
+sbused(const struct sockbuf *sb)
+{
+
+ KASSERT(solocked(sb->sb_so));
+ return sb->sb_cc;
+}
+
/* do we have to send all at once on a socket? */
static __inline int
sosendallatonce(const struct socket *so)
diff -r 8d7ce6164f8c -r c84f3f693781 tests/kernel/kqueue/Makefile
--- a/tests/kernel/kqueue/Makefile Fri Oct 22 22:31:55 2021 +0000
+++ b/tests/kernel/kqueue/Makefile Sat Oct 23 01:28:33 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.7 2021/10/13 04:57:19 thorpej Exp $
+# $NetBSD: Makefile,v 1.8 2021/10/23 01:28:33 thorpej Exp $
WARNS?=6
NOMAN= # defined
@@ -10,7 +10,8 @@
TESTS_SUBDIRS= read
TESTS_SUBDIRS+= write
-TESTS_C= t_ioctl
+TESTS_C= t_empty
+TESTS_C+= t_ioctl
TESTS_C+= t_proc1
TESTS_C+= t_proc2
TESTS_C+= t_proc3
diff -r 8d7ce6164f8c -r c84f3f693781 tests/kernel/kqueue/t_empty.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/kernel/kqueue/t_empty.c Sat Oct 23 01:28:33 2021 +0000
@@ -0,0 +1,178 @@
+/* $NetBSD: t_empty.c,v 1.1 2021/10/23 01:28:33 thorpej Exp $ */
+
+/*-
+ * Copyright (c) 2021 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: t_empty.c,v 1.1 2021/10/23 01:28:33 thorpej Exp $");
+
+#include <sys/event.h>
+#include <sys/socket.h>
+#include <sys/time.h>
+#include <sys/types.h>
+
+#include <netinet/in.h>
+
+#include <err.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <atf-c.h>
+
+static void
+test_empty(int readfd, int writefd, bool is_tcp)
+{
+ struct timespec ts = { 0, 0 };
+ struct kevent event;
+ int kq, error, sndbufsize;
+ char buf[1024] = { 0 };
+ ssize_t rv;
Home |
Main Index |
Thread Index |
Old Index