-.\" $OpenBSD: knote.9,v 1.9 2014/01/21 03:15:46 schwarze Exp $
+.\" $OpenBSD: knote.9,v 1.10 2023/02/10 14:34:16 visa Exp $
.\" $NetBSD: knote.9,v 1.9 2003/04/16 13:35:29 wiz Exp $
.\"
.\" Copyright (c) 2001, 2002, 2003 The NetBSD Foundation, Inc.
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd $Mdocdate: January 21 2014 $
+.Dd $Mdocdate: February 10 2023 $
.Dt KNOTE 9
.Os
.Sh NAME
.Nm knote ,
-.Nm KNOTE
+.Nm knote_locked
.Nd raise kernel event
.Sh SYNOPSIS
.In sys/param.h
.In sys/event.h
.Ft void
.Fn knote "struct klist *list" "long hint"
-.Fn KNOTE "struct klist *list" "long hint"
+.Ft void
+.Fn knote_locked "struct klist *list" "long hint"
.Sh DESCRIPTION
The
.Fn knote
-function provides a hook into the kqueue kernel event notification
+and
+.Fn knote_locked
+functions provide a hook into the kqueue kernel event notification
mechanism to allow sections of the kernel to raise a kernel event
in the form of a
.Sq knote ,
.Fa hint
(which is passed to the appropriate filter routine).
.Fn knote
-then walks the
+then locks and walks the
.Fa list
making calls to the filter routine for each knote.
As each knote contains a reference to the data structure that it is
call to the filter occurs in order to provide an opportunity for the
filter to record the activity.
.Pp
+.Fn knote_locked
+is like
+.Fn knote
+but assumes that the
+.Fa list
+is already locked.
+.Pp
.Fn knote
+and
+.Fn knote_locked
must not be called from interrupt contexts running at an interrupt
priority level higher than
.Fn splsched .
-.Pp
-.Fn KNOTE
-is a macro that calls
-.Fn knote list hint
-if
-.Fa list
-is not empty.
.\" .Sh ERRORS
.Sh SEE ALSO
.Xr kqueue 2
.Sh HISTORY
The
.Fn knote
-and
-.Fn KNOTE
functions first appeared in
.Fx 4.1 ,
and then in
-/* $OpenBSD: apm.c,v 1.21 2023/01/22 13:14:21 kettenis Exp $ */
+/* $OpenBSD: apm.c,v 1.22 2023/02/10 14:34:16 visa Exp $ */
/*-
* Copyright (c) 2001 Alexander Guy. All rights reserved.
return 1;
apm_evindex++;
- KNOTE(&sc->sc_note, APM_EVENT_COMPOSE(event, apm_evindex));
+ knote_locked(&sc->sc_note, APM_EVENT_COMPOSE(event, apm_evindex));
return 0;
}
-/* $OpenBSD: apm.c,v 1.129 2023/01/30 10:49:04 jsg Exp $ */
+/* $OpenBSD: apm.c,v 1.130 2023/02/10 14:34:16 visa Exp $ */
/*-
* Copyright (c) 1998-2001 Michael Shalayeff. All rights reserved.
}
apm_evindex++;
- KNOTE(&sc->sc_note, APM_EVENT_COMPOSE(type, apm_evindex));
+ knote_locked(&sc->sc_note, APM_EVENT_COMPOSE(type, apm_evindex));
return (0);
}
-/* $OpenBSD: apm.c,v 1.41 2022/11/19 16:23:48 cheloha Exp $ */
+/* $OpenBSD: apm.c,v 1.42 2023/02/10 14:34:16 visa Exp $ */
/*-
* Copyright (c) 2001 Alexander Guy. All rights reserved.
return (1);
apm_evindex++;
- KNOTE(&sc->sc_note, APM_EVENT_COMPOSE(event, apm_evindex));
+ knote_locked(&sc->sc_note, APM_EVENT_COMPOSE(event, apm_evindex));
return (0);
}
-/* $OpenBSD: acpi.c,v 1.418 2022/09/13 17:14:54 kettenis Exp $ */
+/* $OpenBSD: acpi.c,v 1.419 2023/02/10 14:34:16 visa Exp $ */
/*
* Copyright (c) 2005 Thorsten Lockert <tholo@sigmasoft.com>
* Copyright (c) 2005 Jordan Hargrave <jordan@openbsd.org>
return (1);
acpi_evindex++;
- KNOTE(&sc->sc_note, APM_EVENT_COMPOSE(type, acpi_evindex));
+ knote_locked(&sc->sc_note, APM_EVENT_COMPOSE(type, acpi_evindex));
return (0);
}
-/* $OpenBSD: audio.c,v 1.205 2022/11/08 17:53:01 kn Exp $ */
+/* $OpenBSD: audio.c,v 1.206 2023/02/10 14:34:16 visa Exp $ */
/*
* Copyright (c) 2015 Alexandre Ratchov <alex@caoua.org>
*
wakeup(&sc->mix_blocking);
sc->mix_blocking = 0;
}
- KNOTE(&sc->mix_klist, 0);
+ knote_locked(&sc->mix_klist, 0);
}
void
wakeup(&buf->blocking);
buf->blocking = 0;
}
- KNOTE(&buf->klist, 0);
+ knote_locked(&buf->klist, 0);
}
int
case WSDISPLAYIO_PARAM_BRIGHTNESS:
bd->props.brightness = dp->curval;
backlight_update_status(bd);
- KNOTE(&adev->ddev.note, NOTE_CHANGE);
+ knote_locked(&adev->ddev.note, NOTE_CHANGE);
return 0;
}
break;
} else if (property == connector->backlight_property) {
connector->backlight_device->props.brightness = value;
backlight_schedule_update_status(connector->backlight_device);
- KNOTE(&connector->dev->note, NOTE_CHANGE);
+ knote_locked(&connector->dev->note, NOTE_CHANGE);
ret = 0;
#endif
} else if (connector->funcs->set_property)
-/* $OpenBSD: drm_linux.c,v 1.95 2023/01/01 01:34:34 jsg Exp $ */
+/* $OpenBSD: drm_linux.c,v 1.96 2023/02/10 14:34:16 visa Exp $ */
/*
* Copyright (c) 2013 Jonathan Gray <jsg@openbsd.org>
* Copyright (c) 2015, 2016 Mark Kettenis <kettenis@openbsd.org>
void
drm_sysfs_hotplug_event(struct drm_device *dev)
{
- KNOTE(&dev->note, NOTE_CHANGE);
+ knote_locked(&dev->note, NOTE_CHANGE);
}
void
drm_sysfs_connector_hotplug_event(struct drm_connector *connector)
{
- KNOTE(&connector->dev->note, NOTE_CHANGE);
+ knote_locked(&connector->dev->note, NOTE_CHANGE);
}
void
struct drm_connector *connector = obj_to_connector(obj);
connector->backlight_device->props.brightness = prop_value;
backlight_schedule_update_status(connector->backlight_device);
- KNOTE(&connector->dev->note, NOTE_CHANGE);
+ knote_locked(&connector->dev->note, NOTE_CHANGE);
ret = 0;
#endif
} else {
case WSDISPLAYIO_PARAM_BRIGHTNESS:
bd->props.brightness = dp->curval;
backlight_update_status(bd);
- KNOTE(&dev_priv->drm.note, NOTE_CHANGE);
+ knote_locked(&dev_priv->drm.note, NOTE_CHANGE);
return 0;
}
break;
-/* $OpenBSD: kern_event.c,v 1.194 2022/11/09 22:25:36 claudio Exp $ */
+/* $OpenBSD: kern_event.c,v 1.195 2023/02/10 14:34:17 visa Exp $ */
/*-
* Copyright (c) 1999,2000,2001 Jonathan Lemon <jlemon@FreeBSD.org>
{
struct kqueue *kq = arg;
- mtx_enter(&kqueue_klist_lock);
- KNOTE(&kq->kq_klist, 0);
- mtx_leave(&kqueue_klist_lock);
+ knote(&kq->kq_klist, 0);
}
void
*/
void
knote(struct klist *list, long hint)
+{
+ int ls;
+
+ ls = klist_lock(list);
+ knote_locked(list, hint);
+ klist_unlock(list, ls);
+}
+
+void
+knote_locked(struct klist *list, long hint)
{
struct knote *kn, *kn0;
struct kqueue *kq;
{
KERNEL_ASSERT_LOCKED();
- KNOTE(&pr->ps_klist, NOTE_EXIT);
+ knote_locked(&pr->ps_klist, NOTE_EXIT);
/* remove other knotes hanging off the process */
klist_invalidate(&pr->ps_klist);
-/* $OpenBSD: kern_exec.c,v 1.243 2023/01/13 23:02:43 kettenis Exp $ */
+/* $OpenBSD: kern_exec.c,v 1.244 2023/02/10 14:34:17 visa Exp $ */
/* $NetBSD: kern_exec.c,v 1.75 1996/02/09 18:59:28 christos Exp $ */
/*-
/*
* notify others that we exec'd
*/
- KNOTE(&pr->ps_klist, NOTE_EXEC);
+ knote_locked(&pr->ps_klist, NOTE_EXEC);
/* map the process's timekeep page, needs to be before exec_elf_fixup */
if (exec_timekeep_map(pr))
-/* $OpenBSD: kern_fork.c,v 1.245 2023/01/07 05:24:58 guenther Exp $ */
+/* $OpenBSD: kern_fork.c,v 1.246 2023/02/10 14:34:17 visa Exp $ */
/* $NetBSD: kern_fork.c,v 1.29 1996/02/09 18:59:34 christos Exp $ */
/*
/*
* Notify any interested parties about the new process.
*/
- KNOTE(&curpr->ps_klist, NOTE_FORK | pr->ps_pid);
+ knote_locked(&curpr->ps_klist, NOTE_FORK | pr->ps_pid);
/*
* Update stats now that we know the fork was successful.
-/* $OpenBSD: kern_sig.c,v 1.304 2023/01/31 15:18:56 deraadt Exp $ */
+/* $OpenBSD: kern_sig.c,v 1.305 2023/02/10 14:34:17 visa Exp $ */
/* $NetBSD: kern_sig.c,v 1.54 1996/04/22 01:38:32 christos Exp $ */
/*
}
if (type != SPROPAGATED)
- KNOTE(&pr->ps_klist, NOTE_SIGNAL | signum);
+ knote_locked(&pr->ps_klist, NOTE_SIGNAL | signum);
prop = sigprop[signum];
-/* $OpenBSD: sys_generic.c,v 1.151 2022/12/27 20:13:03 patrick Exp $ */
+/* $OpenBSD: sys_generic.c,v 1.152 2023/02/10 14:34:17 visa Exp $ */
/* $NetBSD: sys_generic.c,v 1.24 1996/03/29 00:25:32 cgd Exp $ */
/*
selwakeup(struct selinfo *sip)
{
KERNEL_LOCK();
- KNOTE(&sip->si_note, NOTE_SUBMIT);
+ knote_locked(&sip->si_note, NOTE_SUBMIT);
KERNEL_UNLOCK();
}
-/* $OpenBSD: sys_pipe.c,v 1.143 2022/12/05 23:18:37 deraadt Exp $ */
+/* $OpenBSD: sys_pipe.c,v 1.144 2023/02/10 14:34:17 visa Exp $ */
/*
* Copyright (c) 1996 John S. Dyson
{
rw_assert_wrlock(cpipe->pipe_lock);
- KNOTE(&cpipe->pipe_klist, 0);
+ knote_locked(&cpipe->pipe_klist, 0);
if (cpipe->pipe_state & PIPE_ASYNC)
pgsigio(&cpipe->pipe_sigio, SIGIO, 0);
-/* $OpenBSD: uipc_socket.c,v 1.300 2023/02/02 09:35:07 mvs Exp $ */
+/* $OpenBSD: uipc_socket.c,v 1.301 2023/02/10 14:34:17 visa Exp $ */
/* $NetBSD: uipc_socket.c,v 1.21 1996/02/04 02:17:52 christos Exp $ */
/*
sohasoutofband(struct socket *so)
{
pgsigio(&so->so_sigio, SIGURG, 0);
- KNOTE(&so->so_rcv.sb_klist, 0);
+ knote_locked(&so->so_rcv.sb_klist, 0);
}
int
-/* $OpenBSD: uipc_socket2.c,v 1.135 2023/02/02 09:35:07 mvs Exp $ */
+/* $OpenBSD: uipc_socket2.c,v 1.136 2023/02/10 14:34:17 visa Exp $ */
/* $NetBSD: uipc_socket2.c,v 1.11 1996/02/04 02:17:55 christos Exp $ */
/*
}
if (sb->sb_flags & SB_ASYNC)
pgsigio(&so->so_sigio, SIGIO, 0);
- KNOTE(&sb->sb_klist, 0);
+ knote_locked(&sb->sb_klist, 0);
}
/*
-/* $OpenBSD: uipc_syscalls.c,v 1.211 2023/01/27 21:01:59 mvs Exp $ */
+/* $OpenBSD: uipc_syscalls.c,v 1.212 2023/02/10 14:34:17 visa Exp $ */
/* $NetBSD: uipc_syscalls.c,v 1.19 1996/02/09 19:00:48 christos Exp $ */
/*
: (flags & SOCK_NONBLOCK ? FNONBLOCK : 0);
/* connection has been removed from the listen queue */
- KNOTE(&head->so_rcv.sb_klist, 0);
+ knote_locked(&head->so_rcv.sb_klist, 0);
if (persocket)
sounlock(head);
-/* $OpenBSD: bpf.c,v 1.219 2022/07/09 12:48:21 visa Exp $ */
+/* $OpenBSD: bpf.c,v 1.220 2023/02/10 14:34:17 visa Exp $ */
/* $NetBSD: bpf.c,v 1.33 1997/02/21 23:59:35 thorpej Exp $ */
/*
if (d->bd_nreaders)
wakeup(d);
- KNOTE(&d->bd_klist, 0);
+ knote_locked(&d->bd_klist, 0);
/*
* As long as pgsigio() needs to be protected
-/* $OpenBSD: if_pppx.c,v 1.125 2023/01/30 03:31:59 visa Exp $ */
+/* $OpenBSD: if_pppx.c,v 1.126 2023/02/10 14:34:17 visa Exp $ */
/*
* Copyright (c) 2010 Claudio Jeker <claudio@openbsd.org>
wakeup((caddr_t)pxi->pxi_dev);
pxi->pxi_dev->pxd_waiting = 0;
}
- mtx_enter(&pxi->pxi_dev->pxd_mtx);
- KNOTE(&pxi->pxi_dev->pxd_rklist, 0);
- mtx_leave(&pxi->pxi_dev->pxd_mtx);
+ knote(&pxi->pxi_dev->pxd_rklist, 0);
}
}
if (!mq_empty(&sc->sc_mq)) {
wakeup(sc);
- mtx_enter(&sc->sc_mtx);
- KNOTE(&sc->sc_rklist, 0);
- mtx_leave(&sc->sc_mtx);
+ knote(&sc->sc_rklist, 0);
}
}
-/* $OpenBSD: event.h,v 1.68 2023/02/02 09:35:07 mvs Exp $ */
+/* $OpenBSD: event.h,v 1.69 2023/02/10 14:34:17 visa Exp $ */
/*-
* Copyright (c) 1999,2000,2001 Jonathan Lemon <jlemon@FreeBSD.org>
*/
#define NOTE_SUBMIT 0x01000000 /* initial knote submission */
-#define KNOTE(list, hint) do { \
- struct klist *__list = (list); \
- if (!klist_empty(__list)) \
- knote(__list, hint); \
- } while (0)
-
#define KN_HASHSIZE 64 /* XXX should be tunable */
/*
extern void kqpoll_done(unsigned int);
extern void kqpoll_exit(void);
extern void knote(struct klist *list, long hint);
+extern void knote_locked(struct klist *list, long hint);
extern void knote_fdclose(struct proc *p, int fd);
extern void knote_processexit(struct process *);
extern void knote_assign(const struct kevent *, struct knote *);
-/* $OpenBSD: vnode.h,v 1.167 2022/08/12 14:30:53 visa Exp $ */
+/* $OpenBSD: vnode.h,v 1.168 2023/02/10 14:34:17 visa Exp $ */
/* $NetBSD: vnode.h,v 1.38 1996/02/29 20:59:05 cgd Exp $ */
/*
#define VATTR_NULL(vap) vattr_null(vap)
#define NULLVP ((struct vnode *)NULL)
#define VN_KNOTE(vp, b) \
- KNOTE(&vp->v_selectinfo.si_note, (b))
+ knote_locked(&vp->v_selectinfo.si_note, (b))
/*
* Global vnode data.