Remove the leftovers of the old poll/select mechanism. This includes the fields si_seltid and si_flags in struct selinfo. They should now always be zero because nothing calls selrecord().
selwakeup() becomes a wrapper for KNOTE(). I do not want to change it further in this patch. This code can be subtle, as shown by the socket selwakeup() experiment in May. ;) The selwakeup() call in bpf_wakeup_cb() can be removed as the kqueue event filter ignores it. The patch makes kern.nselcoll sysctl constant. However, is there any actual need to keep this sysctl? vmstat(1) is the only user of KERN_NSELCOLL in base. Debian code search does not reveal uses that would affect ports. Index: bin/ps/ps.1 =================================================================== RCS file: src/bin/ps/ps.1,v retrieving revision 1.125 diff -u -p -r1.125 ps.1 --- bin/ps/ps.1 31 Mar 2022 17:27:14 -0000 1.125 +++ bin/ps/ps.1 2 Jul 2022 13:51:19 -0000 @@ -222,7 +222,6 @@ P_PROFPEND 0x2 this thread needs P_ALRMPEND 0x4 this thread needs SIGVTALRM P_SIGSUSPEND 0x8 need to restore before-suspend mask P_CANTSLEEP 0x10 this thread is not permitted to sleep -P_SELECT 0x40 selecting; wakeup/waiting danger P_SINTR 0x80 sleep is interruptible P_SYSTEM 0x200 system process: no sigs, stats, or swapping Index: sys/dev/wscons/wsdisplay.c =================================================================== RCS file: src/sys/dev/wscons/wsdisplay.c,v retrieving revision 1.146 diff -u -p -r1.146 wsdisplay.c --- sys/dev/wscons/wsdisplay.c 2 Jul 2022 08:50:42 -0000 1.146 +++ sys/dev/wscons/wsdisplay.c 2 Jul 2022 13:51:45 -0000 @@ -1441,7 +1441,7 @@ wsdisplaystart(struct tty *tp) splx(s); return; } - if (tp->t_outq.c_cc == 0 && tp->t_wsel.si_seltid == 0) + if (tp->t_outq.c_cc == 0) goto low; if ((scr = sc->sc_scr[WSDISPLAYSCREEN(tp->t_dev)]) == NULL) { Index: sys/kern/kern_sysctl.c =================================================================== RCS file: src/sys/kern/kern_sysctl.c,v retrieving revision 1.402 diff -u -p -r1.402 kern_sysctl.c --- sys/kern/kern_sysctl.c 21 Mar 2022 09:12:34 -0000 1.402 +++ sys/kern/kern_sysctl.c 2 Jul 2022 13:51:45 -0000 @@ -120,7 +120,7 @@ extern struct forkstat forkstat; extern struct nchstats nchstats; -extern int nselcoll, fscale; +extern int fscale; extern fixpt_t ccpu; extern long numvnodes; extern int allowdt; @@ -298,7 +298,7 @@ const struct sysctl_bounded_args kern_va {KERN_NFILES, &numfiles, SYSCTL_INT_READONLY}, {KERN_TTYCOUNT, &tty_count, SYSCTL_INT_READONLY}, {KERN_ARGMAX, &arg_max, SYSCTL_INT_READONLY}, - {KERN_NSELCOLL, &nselcoll, SYSCTL_INT_READONLY}, + {KERN_NSELCOLL, &int_zero, SYSCTL_INT_READONLY}, {KERN_POSIX1, &posix_version, SYSCTL_INT_READONLY}, {KERN_NGROUPS, &ngroups_max, SYSCTL_INT_READONLY}, {KERN_JOB_CONTROL, &int_one, SYSCTL_INT_READONLY}, Index: sys/kern/sys_generic.c =================================================================== RCS file: src/sys/kern/sys_generic.c,v retrieving revision 1.147 diff -u -p -r1.147 sys_generic.c --- sys/kern/sys_generic.c 8 Feb 2022 08:56:41 -0000 1.147 +++ sys/kern/sys_generic.c 2 Jul 2022 13:51:45 -0000 @@ -89,7 +89,6 @@ int dopselect(struct proc *, int, fd_set struct timespec *, const sigset_t *, register_t *); int doppoll(struct proc *, struct pollfd *, u_int, struct timespec *, const sigset_t *, register_t *); -void doselwakeup(struct selinfo *); int iovec_copyin(const struct iovec *uiov, struct iovec **iovp, struct iovec *aiov, @@ -522,8 +521,6 @@ out: return (error); } -int selwait, nselcoll; - /* * Select system call. */ @@ -840,41 +837,6 @@ pselcollect(struct proc *p, struct keven return (0); } -int -seltrue(dev_t dev, int events, struct proc *p) -{ - - return (events & (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM)); -} - -int -selfalse(dev_t dev, int events, struct proc *p) -{ - - return (0); -} - -/* - * Record a select request. - */ -void -selrecord(struct proc *selector, struct selinfo *sip) -{ - struct proc *p; - pid_t mytid; - - KERNEL_ASSERT_LOCKED(); - - mytid = selector->p_tid; - if (sip->si_seltid == mytid) - return; - if (sip->si_seltid && (p = tfind(sip->si_seltid)) && - p->p_wchan == (caddr_t)&selwait) - sip->si_flags |= SI_COLL; - else - sip->si_seltid = mytid; -} - /* * Do a wakeup when a selectable event occurs. */ @@ -883,34 +845,9 @@ selwakeup(struct selinfo *sip) { KERNEL_LOCK(); KNOTE(&sip->si_note, NOTE_SUBMIT); - doselwakeup(sip); KERNEL_UNLOCK(); } -void -doselwakeup(struct selinfo *sip) -{ - struct proc *p; - - KERNEL_ASSERT_LOCKED(); - - if (sip->si_seltid == 0) - return; - if (sip->si_flags & SI_COLL) { - nselcoll++; - sip->si_flags &= ~SI_COLL; - wakeup(&selwait); - } - p = tfind(sip->si_seltid); - sip->si_seltid = 0; - if (p != NULL) { - if (wakeup_proc(p, &selwait)) { - /* nothing else to do */ - } else if (p->p_flag & P_SELECT) - atomic_clearbits_int(&p->p_flag, P_SELECT); - } -} - /* * Only copyout the revents field. */ Index: sys/net/bpf.c =================================================================== RCS file: src/sys/net/bpf.c,v retrieving revision 1.217 diff -u -p -r1.217 bpf.c --- sys/net/bpf.c 2 Jul 2022 08:50:42 -0000 1.217 +++ sys/net/bpf.c 2 Jul 2022 13:51:45 -0000 @@ -588,11 +588,11 @@ bpf_wakeup(struct bpf_d *d) KNOTE(&d->bd_sel.si_note, 0); /* - * As long as pgsigio() and selwakeup() need to be protected + * As long as pgsigio() needs to be protected * by the KERNEL_LOCK() we have to delay the wakeup to * another context to keep the hot path KERNEL_LOCK()-free. */ - if ((d->bd_async && d->bd_sig) || d->bd_sel.si_seltid != 0) { + if (d->bd_async && d->bd_sig) { bpf_get(d); if (!task_add(systq, &d->bd_wake_task)) bpf_put(d); @@ -607,9 +607,6 @@ bpf_wakeup_cb(void *xd) if (d->bd_async && d->bd_sig) pgsigio(&d->bd_sigio, d->bd_sig, 0); - mtx_enter(&d->bd_mtx); - selwakeup(&d->bd_sel); - mtx_leave(&d->bd_mtx); bpf_put(d); } @@ -1192,9 +1189,6 @@ filt_bpfread(struct knote *kn, long hint { struct bpf_d *d = kn->kn_hook; - if (hint == NOTE_SUBMIT) /* ignore activation from selwakeup */ - return (0); - MUTEX_ASSERT_LOCKED(&d->bd_mtx); kn->kn_data = d->bd_hlen; Index: sys/sys/proc.h =================================================================== RCS file: src/sys/sys/proc.h,v retrieving revision 1.332 diff -u -p -r1.332 proc.h --- sys/sys/proc.h 29 Jun 2022 12:17:31 -0000 1.332 +++ sys/sys/proc.h 2 Jul 2022 13:51:45 -0000 @@ -409,7 +409,6 @@ struct proc { #define P_ALRMPEND 0x00000004 /* SIGVTALRM needs to be posted */ #define P_SIGSUSPEND 0x00000008 /* Need to restore before-suspend mask*/ #define P_CANTSLEEP 0x00000010 /* insomniac thread */ -#define P_SELECT 0x00000040 /* Selecting; wakeup/waiting danger. */ #define P_SINTR 0x00000080 /* Sleep is interruptible. */ #define P_SYSTEM 0x00000200 /* No sigs, stats or swapping. */ #define P_TIMEOUT 0x00000400 /* Timing out during sleep. */ @@ -424,7 +423,7 @@ struct proc { #define P_BITS \ ("\20" "\01INKTR" "\02PROFPEND" "\03ALRMPEND" "\04SIGSUSPEND" \ - "\05CANTSLEEP" "\07SELECT" "\010SINTR" "\012SYSTEM" "\013TIMEOUT" \ + "\05CANTSLEEP" "\010SINTR" "\012SYSTEM" "\013TIMEOUT" \ "\016WEXIT" "\020OWEUPC" "\024SUSPSINGLE" "\027XX" \ "\030CONTINUED" "\033THREAD" "\034SUSPSIG" "\035SOFTDEP" "\037CPUPEG") Index: sys/sys/selinfo.h =================================================================== RCS file: src/sys/sys/selinfo.h,v retrieving revision 1.5 diff -u -p -r1.5 selinfo.h --- sys/sys/selinfo.h 18 Jul 2017 19:20:26 -0000 1.5 +++ sys/sys/selinfo.h 2 Jul 2022 13:51:45 -0000 @@ -42,15 +42,9 @@ */ struct selinfo { struct klist si_note; /* kernel note list */ - pid_t si_seltid; /* thread to be notified */ - short si_flags; /* see below */ }; -#define SI_COLL 0x0001 /* collision occurred */ #ifdef _KERNEL -struct proc; - -void selrecord(struct proc *selector, struct selinfo *); void selwakeup(struct selinfo *); #endif Index: sys/sys/systm.h =================================================================== RCS file: src/sys/sys/systm.h,v retrieving revision 1.155 diff -u -p -r1.155 systm.h --- sys/sys/systm.h 9 Dec 2021 00:26:10 -0000 1.155 +++ sys/sys/systm.h 2 Jul 2022 13:51:45 -0000 @@ -91,7 +91,6 @@ extern int ncpusfound; /* number of CPU extern int nblkdev; /* number of entries in bdevsw */ extern int nchrdev; /* number of entries in cdevsw */ -extern int selwait; /* select timeout address */ extern int maxmem; /* max memory per process */ extern int physmem; /* physical memory */ @@ -151,8 +150,6 @@ int enoioctl(void); int enxio(void); int eopnotsupp(void *); -int seltrue(dev_t dev, int which, struct proc *); -int selfalse(dev_t dev, int which, struct proc *); void *hashinit(int, int, int, u_long *); void hashfree(void *, int, int); int sys_nosys(struct proc *, void *, register_t *);