Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/kernel Add epoll(2) from Theodore Preduta as part of G...



details:   https://anonhg.NetBSD.org/src/rev/f428e9c9c61c
branches:  trunk
changeset: 378262:f428e9c9c61c
user:      christos <christos%NetBSD.org@localhost>
date:      Fri Jul 28 18:18:59 2023 +0000

description:
Add epoll(2) from Theodore Preduta as part of GSoC 2023

diffstat:

 distrib/sets/lists/comp/mi                  |   23 +-
 distrib/sets/lists/debug/mi                 |    3 +-
 distrib/sets/lists/tests/mi                 |    3 +-
 lib/libc/compat/sys/compat_kevent.c         |   49 +-
 lib/libc/sys/Makefile.inc                   |   24 +-
 lib/libc/sys/epoll.2                        |  388 +++++++++++++++
 lib/libc/sys/epoll.c                        |   69 ++
 lib/libc/sys/kqueue.2                       |   19 +-
 lib/libpthread/pthread_cancelstub.c         |   10 +-
 lib/librumpclient/rumpclient.c              |    8 +-
 lib/librumphijack/hijack.c                  |   14 +-
 sys/compat/common/compat_100_mod.c          |    8 +-
 sys/compat/common/compat_mod.h              |    4 +-
 sys/compat/common/files.common              |    3 +-
 sys/compat/common/kern_event_100.c          |   88 +++
 sys/compat/common/kern_select_50.c          |   18 +-
 sys/compat/linux/arch/amd64/syscalls.master |   23 +-
 sys/compat/linux/common/linux_misc.c        |  233 +++++++++-
 sys/compat/linux/common/linux_misc.h        |   11 +-
 sys/compat/sys/event.h                      |   89 +++-
 sys/kern/files.kern                         |    3 +-
 sys/kern/kern_event.c                       |    6 +-
 sys/kern/makesyscalls.sh                    |    3 +-
 sys/kern/sys_epoll.c                        |  680 ++++++++++++++++++++++++++++
 sys/kern/syscalls.conf                      |    4 +-
 sys/kern/syscalls.master                    |   24 +-
 sys/rump/Makefile.rump                      |    4 +-
 sys/rump/rump.sysmap                        |    3 +-
 sys/sys/Makefile                            |    4 +-
 sys/sys/epoll.h                             |   98 ++++
 sys/sys/event.h                             |    5 +-
 sys/sys/syscall.h                           |   22 +-
 tests/kernel/Makefile                       |    5 +-
 tests/kernel/t_epoll.c                      |  225 +++++++++
 34 files changed, 2088 insertions(+), 85 deletions(-)

diffs (truncated from 2835 to 300 lines):

diff -r 5bdc60540d08 -r f428e9c9c61c distrib/sets/lists/comp/mi
--- a/distrib/sets/lists/comp/mi        Fri Jul 28 12:03:33 2023 +0000
+++ b/distrib/sets/lists/comp/mi        Fri Jul 28 18:18:59 2023 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: mi,v 1.2437 2023/07/10 02:31:54 christos Exp $
+#      $NetBSD: mi,v 1.2438 2023/07/28 18:18:59 christos Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 ./etc/mtree/set.comp                           comp-sys-root
@@ -3328,6 +3328,7 @@
 ./usr/include/sys/elfdefinitions.h             comp-c-include
 ./usr/include/sys/endian.h                     comp-c-include
 ./usr/include/sys/envsys.h                     comp-c-include
+./usr/include/sys/epoll.h                      comp-c-include
 ./usr/include/sys/errno.h                      comp-c-include
 ./usr/include/sys/evcnt.h                      comp-c-include
 ./usr/include/sys/event.h                      comp-c-include
@@ -13211,6 +13212,16 @@
 ./usr/share/man/html2/dup.html                 comp-c-htmlman          html
 ./usr/share/man/html2/dup2.html                        comp-c-htmlman          html
 ./usr/share/man/html2/dup3.html                        comp-c-htmlman          html
+./usr/share/man/html2/epoll.html               comp-c-htmlman          html
+./usr/share/man/html2/epoll_create.html                comp-c-htmlman          html
+./usr/share/man/html2/epoll_create1.html       comp-c-htmlman          html
+./usr/share/man/html2/epoll_ctl.html           comp-c-htmlman          html
+./usr/share/man/html2/epoll_data.html          comp-c-htmlman          html
+./usr/share/man/html2/epoll_data_t.html                comp-c-htmlman          html
+./usr/share/man/html2/epoll_event.html         comp-c-htmlman          html
+./usr/share/man/html2/epoll_pwait.html         comp-c-htmlman          html
+./usr/share/man/html2/epoll_pwait2.html                comp-c-htmlman          html
+./usr/share/man/html2/epoll_wait.html          comp-c-htmlman          html
 ./usr/share/man/html2/errno.html               comp-c-htmlman          html
 ./usr/share/man/html2/eventfd.html             comp-c-htmlman          html
 ./usr/share/man/html2/eventfd_read.html                comp-c-htmlman          html
@@ -21524,6 +21535,16 @@
 ./usr/share/man/man2/dup.2                     comp-c-man              .man
 ./usr/share/man/man2/dup2.2                    comp-c-man              .man
 ./usr/share/man/man2/dup3.2                    comp-c-man              .man
+./usr/share/man/man2/epoll.2                   comp-c-man              .man
+./usr/share/man/man2/epoll_create.2            comp-c-man              .man
+./usr/share/man/man2/epoll_create1.2           comp-c-man              .man
+./usr/share/man/man2/epoll_ctl.2               comp-c-man              .man
+./usr/share/man/man2/epoll_data.2              comp-c-man              .man
+./usr/share/man/man2/epoll_data_t.2            comp-c-man              .man
+./usr/share/man/man2/epoll_event.2             comp-c-man              .man
+./usr/share/man/man2/epoll_pwait.2             comp-c-man              .man
+./usr/share/man/man2/epoll_pwait2.2            comp-c-man              .man
+./usr/share/man/man2/epoll_wait.2              comp-c-man              .man
 ./usr/share/man/man2/errno.2                   comp-c-man              .man
 ./usr/share/man/man2/eventfd.2                 comp-c-man              .man
 ./usr/share/man/man2/eventfd_read.2            comp-c-man              .man
diff -r 5bdc60540d08 -r f428e9c9c61c distrib/sets/lists/debug/mi
--- a/distrib/sets/lists/debug/mi       Fri Jul 28 12:03:33 2023 +0000
+++ b/distrib/sets/lists/debug/mi       Fri Jul 28 18:18:59 2023 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.406 2023/07/05 22:42:46 riastradh Exp $
+# $NetBSD: mi,v 1.407 2023/07/28 18:18:59 christos 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
@@ -1790,6 +1790,7 @@
 ./usr/libdata/debug/usr/tests/kernel/posix_spawn/t_fileactions.debug   tests-obsolete  obsolete,compattestfile
 ./usr/libdata/debug/usr/tests/kernel/posix_spawn/t_spawn.debug         tests-obsolete  obsolete,compattestfile
 ./usr/libdata/debug/usr/tests/kernel/posix_spawn/t_spawnattr.debug     tests-obsolete  obsolete,compattestfile
+./usr/libdata/debug/usr/tests/kernel/t_epoll.debug                     tests-kernel-tests      debug,atf
 ./usr/libdata/debug/usr/tests/kernel/t_extattrctl.debug                        tests-kernel-tests      debug,atf,rump
 ./usr/libdata/debug/usr/tests/kernel/t_extent.debug                    tests-kernel-tests      debug,atf,compattestfile
 ./usr/libdata/debug/usr/tests/kernel/t_fcntl.debug                     tests-kernel-tests      debug,atf
diff -r 5bdc60540d08 -r f428e9c9c61c distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Fri Jul 28 12:03:33 2023 +0000
+++ b/distrib/sets/lists/tests/mi       Fri Jul 28 18:18:59 2023 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1277 2023/07/15 12:24:57 rillig Exp $
+# $NetBSD: mi,v 1.1278 2023/07/28 18:19:00 christos Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -2296,6 +2296,7 @@
 ./usr/tests/kernel/posix_spawn/t_fileactions           tests-obsolete          obsolete
 ./usr/tests/kernel/posix_spawn/t_spawn                 tests-obsolete          obsolete
 ./usr/tests/kernel/posix_spawn/t_spawnattr             tests-obsolete          obsolete
+./usr/tests/kernel/t_epoll                             tests-kernel-tests      atf
 ./usr/tests/kernel/t_extattrctl                                tests-kernel-tests      atf,rump
 ./usr/tests/kernel/t_extent                            tests-kernel-tests      compattestfile,atf
 ./usr/tests/kernel/t_fcntl                             tests-kernel-tests      atf
diff -r 5bdc60540d08 -r f428e9c9c61c lib/libc/compat/sys/compat_kevent.c
--- a/lib/libc/compat/sys/compat_kevent.c       Fri Jul 28 12:03:33 2023 +0000
+++ b/lib/libc/compat/sys/compat_kevent.c       Fri Jul 28 18:18:59 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: compat_kevent.c,v 1.2 2009/01/11 02:46:26 christos Exp $ */
+/*     $NetBSD: compat_kevent.c,v 1.3 2023/07/28 18:19:00 christos Exp $ */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 #include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: compat_kevent.c,v 1.2 2009/01/11 02:46:26 christos Exp $");
+__RCSID("$NetBSD: compat_kevent.c,v 1.3 2023/07/28 18:19:00 christos Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include "namespace.h"
@@ -46,13 +46,16 @@
 #include <compat/sys/time.h>
 #include <sys/event.h>
 #include <compat/sys/event.h>
+#include <stdlib.h>
 
 __warn_references(kevent,
     "warning: reference to compatibility kevent(); include <sys/event.h> to generate correct reference")
+__warn_references(kevent,
+    "warning: reference to compatibility __kevent50(); use kevent()")
 
 int
-kevent(int kq, const struct kevent *changelist, size_t nchanges,
-    struct kevent *eventlist, size_t nevents, const struct timespec50 *ts50)
+kevent(int kq, const struct kevent100 *changelist, size_t nchanges,
+    struct kevent100 *eventlist, size_t nevents, const struct timespec50 *ts50)
 {
        struct timespec ts, *tsp;
 
@@ -60,5 +63,41 @@ kevent(int kq, const struct kevent *chan
                timespec50_to_timespec(ts50, tsp = &ts);
        else
                tsp = NULL;
-       return __kevent50(kq, changelist, nchanges, eventlist, nevents, tsp);
+        return __kevent50(kq, changelist, nchanges, eventlist, nevents, tsp);
 }
+
+int
+__kevent50(int kq, const struct kevent100 *changelist100, size_t nchanges,
+    struct kevent100 *eventlist100, size_t nevents, const struct timespec *tsp)
+{
+       int retval;
+       struct kevent *changelist;
+       struct kevent *eventlist;
+
+       changelist = malloc(sizeof(*changelist) * nchanges);
+       if (changelist == NULL) {
+               return -1;
+       }
+
+       eventlist = malloc(sizeof(*eventlist) * nevents);
+        if (eventlist == NULL) {
+               retval = -1;
+               goto leave0;
+       }
+
+       for (size_t i = 0; i < nchanges; i++)
+               kevent100_to_kevent(changelist100 + i, changelist + i);
+
+       retval = __kevent100(kq, changelist, nchanges, eventlist, nevents, tsp);
+       if (retval == -1)
+               goto leave1;
+
+       for (int i = 0; i < retval; i++)
+               kevent_to_kevent100(eventlist + i, eventlist100 + i);
+
+leave1:
+       free(eventlist);
+leave0:
+       free(changelist);
+       return retval;
+}
diff -r 5bdc60540d08 -r f428e9c9c61c lib/libc/sys/Makefile.inc
--- a/lib/libc/sys/Makefile.inc Fri Jul 28 12:03:33 2023 +0000
+++ b/lib/libc/sys/Makefile.inc Fri Jul 28 18:18:59 2023 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile.inc,v 1.251 2023/07/10 02:31:54 christos Exp $
+#      $NetBSD: Makefile.inc,v 1.252 2023/07/28 18:19:00 christos Exp $
 #      @(#)Makefile.inc        8.3 (Berkeley) 10/24/94
 
 # sys sources
@@ -7,10 +7,10 @@
 # other sources shared with the kernel, used in syscalls
 SRCS+= cpuset.c
 # glue to offer userland wrappers for some syscalls
-SRCS+= accept4.c clock_getcpuclockid.c eventfd_read.c eventfd_write.c \
-       posix_fadvise.c posix_madvise.c ppoll.c sched.c sigqueue.c \
-       sigtimedwait.c sigwait.c sigwaitinfo.c statvfs.c swapon.c semctl.c \
-       vadvise.c
+SRCS+= accept4.c clock_getcpuclockid.c epoll.c eventfd_read.c \
+       eventfd_write.c posix_fadvise.c posix_madvise.c ppoll.c sched.c \
+       sigqueue.c sigtimedwait.c sigwait.c sigwaitinfo.c statvfs.c swapon.c \
+       semctl.c vadvise.c
 
 .if ${RUMPRUN} != "yes"
 # modules with non-default implementations on at least one architecture:
@@ -103,6 +103,7 @@ ASM=\
                clock_getcpuclockid2.S \
                __clock_getres50.S __clock_gettime50.S \
        dup.S dup2.S dup3.S \
+       epoll_create1.S epoll_ctl.S epoll_pwait2.S \
        eventfd.S \
        extattrctl.S \
                extattr_delete_fd.S extattr_delete_file.S \
@@ -180,7 +181,7 @@ ASM_MD=     _lwp_getprivate.S mremap.S
 WEAKASM= accept.S __aio_suspend50.S clock_nanosleep.S close.S connect.S \
        execve.S \
        fcntl.S fdatasync.S fsync.S \
-       fsync_range.S __kevent50.S \
+       fsync_range.S __kevent100.S \
        kill.S mq_receive.S mq_send.S __mq_timedreceive50.S __mq_timedsend50.S \
        msgrcv.S msgsnd.S __msync13.S  __nanosleep50.S open.S openat.S \
        paccept.S poll.S \
@@ -260,7 +261,7 @@ LintSysPseudoNoerr.c: ${LIBCDIR}/sys/mak
 MAN+=  accept.2 access.2 acct.2 adjtime.2 bind.2 brk.2 chdir.2 \
        chflags.2 chmod.2 chown.2 chroot.2 clock_getcpuclockid2.2 \
        clock_settime.2 clone.2 close.2 \
-       connect.2 dup.2 eventfd.2 execve.2 _exit.2 extattr_get_file.2 \
+       connect.2 dup.2 epoll.2 eventfd.2 execve.2 _exit.2 extattr_get_file.2 \
        fcntl.2 fdatasync.2 fdiscard.2 fhopen.2 \
        flock.2 fork.2 fsync.2 getcontext.2 getdents.2 \
        getfh.2 getvfsstat.2 getgid.2 getgroups.2 \
@@ -308,6 +309,15 @@ MLINKS+=chown.2 fchown.2 chown.2 lchown.
 MLINKS+=chroot.2 fchroot.2
 MLINKS+=clock_settime.2 clock_gettime.2
 MLINKS+=clock_settime.2 clock_getres.2
+MLINKS+=epoll.2 epoll_event.2 \
+       epoll.2 epoll_data.2 \
+       epoll.2 epoll_data_t.2 \
+       epoll.2 epoll_create.2 \
+       epoll.2 epoll_create1.2 \
+       epoll.2 epoll_ctl.2 \
+       epoll.2 epoll_wait.2 \
+       epoll.2 epoll_pwait.2 \
+       epoll.2 epoll_pwait2.2
 MLINKS+=eventfd.2 eventfd_read.2 \
        eventfd.2 eventfd_write.2
 MLINKS+=extattr_get_file.2 extattr_set_file.2 \
diff -r 5bdc60540d08 -r f428e9c9c61c lib/libc/sys/epoll.2
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libc/sys/epoll.2      Fri Jul 28 18:18:59 2023 +0000
@@ -0,0 +1,388 @@
+.\"    $NetBSD: epoll.2,v 1.1 2023/07/28 18:19:00 christos Exp $
+.\"
+.\" Copyright (c) 2023 The NetBSD Foundation, Inc.
+.\" All rights reserved.
+.\"
+.\" This code is derived from software contributed to The NetBSD Foundation
+.\" by Theodore Preduta.
+.\"
+.\" 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.
+.\"
+.Dd July 19, 2023
+.Dt EPOLL 2
+.Os
+.Sh NAME
+.Nm epoll ,
+.Nm epoll_event ,
+.Nm epoll_data ,
+.Nm epoll_data_t ,
+.Nm epoll_create ,
+.Nm epoll_create1 ,
+.Nm epoll_ctl ,
+.Nm epoll_wait ,
+.Nm epoll_pwait ,
+.Nm epoll_pwait2
+.Nd event notification mechanism
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In sys/epoll.h
+.Bd -literal
+union epoll_data {
+       void            *ptr;
+       int             fd;
+       uint32_t        u32;
+       uint64_t        u64;
+};
+
+typedef union epoll_data       epoll_data_t;
+
+struct epoll_event {
+       uint32_t        events;
+       epoll_data_t    data;
+};
+.Ed
+.Pp
+.Ft int



Home | Main Index | Thread Index | Old Index