Re: kevent(2) EVFILT_USER support
On Thu, Nov 02, 2017 at 01:50:01PM +, Stuart Henderson wrote: > On 2017/11/02 14:29, Paul Irofti wrote: > > Here is a backport from FreeBSD to support EVFILT_USER events. > > I can't comment on whether or not this should be added, but if it is, some > ports > will pick it up and need bumps: > > devel/libinotify > devel/libivykis > net/ntp > sysutils/syslog-ng > telephony/asterisk > www/nginx So I guess some ports do use it. I greped for patches removing the functionality, but I guess that's hidden behind ifdefs and autoconf layers so no need for patching. Thanks Stuart!
Re: kevent(2) EVFILT_USER support
On 2017/11/02 14:29, Paul Irofti wrote: > Here is a backport from FreeBSD to support EVFILT_USER events. I can't comment on whether or not this should be added, but if it is, some ports will pick it up and need bumps: devel/libinotify devel/libivykis net/ntp sysutils/syslog-ng telephony/asterisk www/nginx
Re: kevent(2) EVFILT_USER support
> Date: Thu, 2 Nov 2017 14:29:30 +0200 > From: Paul Irofti> > Hi, > > Here is a backport from FreeBSD to support EVFILT_USER events. > > %--- > EVFILT_USEREstablishes a user event identified by ident which is >not associated with any kernel mechanism but is trig- >gered by user level code. The lower 24 bits of the >fflags may be used for user defined flags and manipu- >lated using the following: > >NOTE_FFNOP Ignore the input fflags. > >NOTE_FFAND Bitwise AND fflags. > >NOTE_FFOR Bitwise OR fflags. > >NOTE_FFCOPY Copy fflags. > >NOTE_FFCTRLMASK Control mask for fflags. > >NOTE_FFLAGSMASK User defined flag mask for >fflags. > >A user event is triggered for output with the follow- >ing: > >NOTE_TRIGGERCause the event to be triggered. > >On return, fflags contains the users defined flags in >the lower 24 bits. > %--- > > I can split the diff in two if needed: first add the touch > functionality and then the EVFILT_USER support on top. > > Thoughts? I think you need a very good motivation for introducing such functionality in OpenBSD. > Index: sys/event.h > === > RCS file: /cvs/src/sys/sys/event.h,v > retrieving revision 1.26 > diff -u -p -u -p -r1.26 event.h > --- sys/event.h 26 Jun 2017 09:32:32 - 1.26 > +++ sys/event.h 2 Nov 2017 11:58:11 - > @@ -38,8 +38,9 @@ > #define EVFILT_PROC (-5)/* attached to struct process */ > #define EVFILT_SIGNAL(-6)/* attached to struct process */ > #define EVFILT_TIMER (-7)/* timers */ > +#define EVFILT_USER (-8)/* User events */ > > -#define EVFILT_SYSCOUNT 7 > +#define EVFILT_SYSCOUNT 8 > > #define EV_SET(kevp_, a, b, c, d, e, f) do { \ > struct kevent *kevp = (kevp_); \ > @@ -80,6 +81,25 @@ struct kevent { > #define EV_ERROR 0x4000 /* error, data contains errno */ > > /* > + * data/hint flags/masks for EVFILT_USER, shared with userspace > + * > + * On input, the top two bits of fflags specifies how the lower twenty four > + * bits should be applied to the stored value of fflags. > + * > + * On output, the top two bits will always be set to NOTE_FFNOP and the > + * remaining twenty four bits will contain the stored fflags value. > + */ > +#define NOTE_FFNOP 0x /* ignore input fflags */ > +#define NOTE_FFAND 0x4000 /* AND fflags */ > +#define NOTE_FFOR0x8000 /* OR fflags */ > +#define NOTE_FFCOPY 0xc000 /* copy fflags */ > +#define NOTE_FFCTRLMASK 0xc000 /* masks for operations > */ > +#define NOTE_FFLAGSMASK 0x00ff > + > +#define NOTE_TRIGGER 0x0100 /* Cause the event to be > +triggered for output. */ > + > +/* > * hint flag for in-kernel use - must not equal any existing note > */ > #ifdef _KERNEL > @@ -142,11 +162,22 @@ SLIST_HEAD(klist, knote); > */ > #define NOTE_SIGNAL 0x0800 > > +/* > + * Hint values for the optional f_touch event filter. If f_touch is not set > + * to NULL and f_isfd is zero the f_touch filter will be called with the type > + * argument set to EVENT_REGISTER during a kevent() system call. It is also > + * called under the same conditions with the type argument set to > EVENT_PROCESS > + * when the event has been triggered. > + */ > +#define EVENT_REGISTER 1 > +#define EVENT_PROCESS2 > + > struct filterops { > int f_isfd; /* true if ident == filedescriptor */ > int (*f_attach)(struct knote *kn); > void(*f_detach)(struct knote *kn); > int (*f_event)(struct knote *kn, long hint); > + void(*f_touch)(struct knote *kn, struct kevent *kev, long type); > }; > > struct knote { > @@ -164,6 +195,7 @@ struct knote { > } kn_ptr; > const structfilterops *kn_fop; > void*kn_hook; > + int kn_hookid; > #define KN_ACTIVE0x01/* event has been triggered */ > #define KN_QUEUED0x02/* event is on queue */ > #define KN_DISABLED 0x04/* event is disabled */ > Index: kern/kern_event.c > === > RCS file: /cvs/src/sys/kern/kern_event.c,v > retrieving revision 1.81 > diff -u -p -u -p -r1.81
Re: kevent(2) EVFILT_USER support
> Reducing kqueue(2) differences is IMHO good since it makes easier to > port 3rd party software. However you forgot to mention why you want > this. Which ports make use of that? None at the moment. I am currently porting libudev from FreeBSD that makes use of it. > Do FreeBSD has regression test for this new functionality? Or can you > add one to our test suite? They do and I can add it to our regress suite. https://github.com/freebsd/freebsd/blob/master/tests/sys/kqueue/libkqueue/user.c > I also have a tricky pending kqueue(2) for MP work, so we need to > coordinate ourself. Sure.
Re: kevent(2) EVFILT_USER support
On 02/11/17(Thu) 14:29, Paul Irofti wrote: > Hi, > > Here is a backport from FreeBSD to support EVFILT_USER events. > [...] > I can split the diff in two if needed: first add the touch > functionality and then the EVFILT_USER support on top. > > Thoughts? Reducing kqueue(2) differences is IMHO good since it makes easier to port 3rd party software. However you forgot to mention why you want this. Which ports make use of that? Do FreeBSD has regression test for this new functionality? Or can you add one to our test suite? I also have a tricky pending kqueue(2) for MP work, so we need to coordinate ourself. > Index: sys/event.h > === > RCS file: /cvs/src/sys/sys/event.h,v > retrieving revision 1.26 > diff -u -p -u -p -r1.26 event.h > --- sys/event.h 26 Jun 2017 09:32:32 - 1.26 > +++ sys/event.h 2 Nov 2017 11:58:11 - > @@ -38,8 +38,9 @@ > #define EVFILT_PROC (-5)/* attached to struct process */ > #define EVFILT_SIGNAL(-6)/* attached to struct process */ > #define EVFILT_TIMER (-7)/* timers */ > +#define EVFILT_USER (-8)/* User events */ > > -#define EVFILT_SYSCOUNT 7 > +#define EVFILT_SYSCOUNT 8 > > #define EV_SET(kevp_, a, b, c, d, e, f) do { \ > struct kevent *kevp = (kevp_); \ > @@ -80,6 +81,25 @@ struct kevent { > #define EV_ERROR 0x4000 /* error, data contains errno */ > > /* > + * data/hint flags/masks for EVFILT_USER, shared with userspace > + * > + * On input, the top two bits of fflags specifies how the lower twenty four > + * bits should be applied to the stored value of fflags. > + * > + * On output, the top two bits will always be set to NOTE_FFNOP and the > + * remaining twenty four bits will contain the stored fflags value. > + */ > +#define NOTE_FFNOP 0x /* ignore input fflags */ > +#define NOTE_FFAND 0x4000 /* AND fflags */ > +#define NOTE_FFOR0x8000 /* OR fflags */ > +#define NOTE_FFCOPY 0xc000 /* copy fflags */ > +#define NOTE_FFCTRLMASK 0xc000 /* masks for operations > */ > +#define NOTE_FFLAGSMASK 0x00ff > + > +#define NOTE_TRIGGER 0x0100 /* Cause the event to be > +triggered for output. */ > + > +/* > * hint flag for in-kernel use - must not equal any existing note > */ > #ifdef _KERNEL > @@ -142,11 +162,22 @@ SLIST_HEAD(klist, knote); > */ > #define NOTE_SIGNAL 0x0800 > > +/* > + * Hint values for the optional f_touch event filter. If f_touch is not set > + * to NULL and f_isfd is zero the f_touch filter will be called with the type > + * argument set to EVENT_REGISTER during a kevent() system call. It is also > + * called under the same conditions with the type argument set to > EVENT_PROCESS > + * when the event has been triggered. > + */ > +#define EVENT_REGISTER 1 > +#define EVENT_PROCESS2 > + > struct filterops { > int f_isfd; /* true if ident == filedescriptor */ > int (*f_attach)(struct knote *kn); > void(*f_detach)(struct knote *kn); > int (*f_event)(struct knote *kn, long hint); > + void(*f_touch)(struct knote *kn, struct kevent *kev, long type); > }; > > struct knote { > @@ -164,6 +195,7 @@ struct knote { > } kn_ptr; > const structfilterops *kn_fop; > void*kn_hook; > + int kn_hookid; > #define KN_ACTIVE0x01/* event has been triggered */ > #define KN_QUEUED0x02/* event is on queue */ > #define KN_DISABLED 0x04/* event is disabled */ > Index: kern/kern_event.c > === > RCS file: /cvs/src/sys/kern/kern_event.c,v > retrieving revision 1.81 > diff -u -p -u -p -r1.81 kern_event.c > --- kern/kern_event.c 11 Oct 2017 08:06:56 - 1.81 > +++ kern/kern_event.c 2 Nov 2017 11:58:11 - > @@ -2,6 +2,7 @@ > > /*- > * Copyright (c) 1999,2000,2001 Jonathan Lemon> + * Copyright (c) 2009 Apple, Inc. > * All rights reserved. > * > * Redistribution and use in source and binary forms, with or without > @@ -98,6 +99,11 @@ intfilt_timerattach(struct knote *kn); > void filt_timerdetach(struct knote *kn); > int filt_timer(struct knote *kn, long hint); > void filt_seltruedetach(struct knote *kn); > +int filt_userattach(struct knote *kn); > +void filt_userdetach(struct knote *kn); > +int filt_user(struct knote *kn, long hint); > +void filt_usertouch(struct knote *kn, struct kevent *kev, long type); > + > > struct filterops kqread_filtops = > { 1, NULL, filt_kqdetach, filt_kqueue }; > @@ -107,6 +113,9 @@ struct filterops file_filtops = > { 1,
kevent(2) EVFILT_USER support
Hi, Here is a backport from FreeBSD to support EVFILT_USER events. %--- EVFILT_USER Establishes a user event identified by ident which is not associated with any kernel mechanism but is trig- gered by user level code. The lower 24 bits of the fflags may be used for user defined flags and manipu- lated using the following: NOTE_FFNOP Ignore the input fflags. NOTE_FFAND Bitwise AND fflags. NOTE_FFOR Bitwise OR fflags. NOTE_FFCOPY Copy fflags. NOTE_FFCTRLMASK Control mask for fflags. NOTE_FFLAGSMASK User defined flag mask for fflags. A user event is triggered for output with the follow- ing: NOTE_TRIGGERCause the event to be triggered. On return, fflags contains the users defined flags in the lower 24 bits. %--- I can split the diff in two if needed: first add the touch functionality and then the EVFILT_USER support on top. Thoughts? Index: sys/event.h === RCS file: /cvs/src/sys/sys/event.h,v retrieving revision 1.26 diff -u -p -u -p -r1.26 event.h --- sys/event.h 26 Jun 2017 09:32:32 - 1.26 +++ sys/event.h 2 Nov 2017 11:58:11 - @@ -38,8 +38,9 @@ #define EVFILT_PROC(-5)/* attached to struct process */ #define EVFILT_SIGNAL (-6)/* attached to struct process */ #define EVFILT_TIMER (-7)/* timers */ +#define EVFILT_USER(-8)/* User events */ -#define EVFILT_SYSCOUNT7 +#define EVFILT_SYSCOUNT8 #define EV_SET(kevp_, a, b, c, d, e, f) do { \ struct kevent *kevp = (kevp_); \ @@ -80,6 +81,25 @@ struct kevent { #define EV_ERROR 0x4000 /* error, data contains errno */ /* + * data/hint flags/masks for EVFILT_USER, shared with userspace + * + * On input, the top two bits of fflags specifies how the lower twenty four + * bits should be applied to the stored value of fflags. + * + * On output, the top two bits will always be set to NOTE_FFNOP and the + * remaining twenty four bits will contain the stored fflags value. + */ +#define NOTE_FFNOP 0x /* ignore input fflags */ +#define NOTE_FFAND 0x4000 /* AND fflags */ +#define NOTE_FFOR 0x8000 /* OR fflags */ +#define NOTE_FFCOPY0xc000 /* copy fflags */ +#define NOTE_FFCTRLMASK0xc000 /* masks for operations */ +#define NOTE_FFLAGSMASK0x00ff + +#define NOTE_TRIGGER 0x0100 /* Cause the event to be + triggered for output. */ + +/* * hint flag for in-kernel use - must not equal any existing note */ #ifdef _KERNEL @@ -142,11 +162,22 @@ SLIST_HEAD(klist, knote); */ #define NOTE_SIGNAL0x0800 +/* + * Hint values for the optional f_touch event filter. If f_touch is not set + * to NULL and f_isfd is zero the f_touch filter will be called with the type + * argument set to EVENT_REGISTER during a kevent() system call. It is also + * called under the same conditions with the type argument set to EVENT_PROCESS + * when the event has been triggered. + */ +#define EVENT_REGISTER 1 +#define EVENT_PROCESS 2 + struct filterops { int f_isfd; /* true if ident == filedescriptor */ int (*f_attach)(struct knote *kn); void(*f_detach)(struct knote *kn); int (*f_event)(struct knote *kn, long hint); + void(*f_touch)(struct knote *kn, struct kevent *kev, long type); }; struct knote { @@ -164,6 +195,7 @@ struct knote { } kn_ptr; const structfilterops *kn_fop; void*kn_hook; + int kn_hookid; #define KN_ACTIVE 0x01/* event has been triggered */ #define KN_QUEUED 0x02/* event is on queue */ #define KN_DISABLED0x04/* event is disabled */ Index: kern/kern_event.c === RCS file: /cvs/src/sys/kern/kern_event.c,v retrieving revision 1.81 diff -u -p -u -p -r1.81 kern_event.c --- kern/kern_event.c 11 Oct 2017 08:06:56 - 1.81 +++ kern/kern_event.c 2 Nov 2017 11:58:11 - @@ -2,6 +2,7 @@ /*- * Copyright (c) 1999,2000,2001 Jonathan Lemon+ * Copyright (c) 2009 Apple, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or