Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 6 Apr 2000 21:01:39 -0700 (PDT)
From:      Matthew Dillon <dillon@apollo.backplane.com>
To:        Jonathan Lemon <jlemon@flugsvamp.com>
Cc:        Archie Cobbs <archie@whistle.com>, freebsd-arch@freebsd.org
Subject:   Re: RFC: kqueue API and rough code
Message-ID:  <200004070401.VAA93492@apollo.backplane.com>
References:  <200004070107.SAA97591@bubba.whistle.com> <200004070220.TAA92896@apollo.backplane.com> <20000406220454.J80578@prism.flugsvamp.com>

next in thread | previous in thread | raw e-mail | index | archive | help

    Hey! (I snap my fingers), I got it!

    There is no need to copy anything back and forth from user space to
    kernel space!

    It's simple, really.  How about this API:

	qfd = kqueue();
	kqueuectl(qfd, filter, fd, struct event *ev);
	ev = kevent(qfd, timeout);

	or (another way to do kevent):

	n = kevent(qfd, struct event **ary, int nmax, struct timeval *timeout);

    The key thing here is that the kernel creates its own internal data 
    structure which has the descriptor, filter operation, and a pointer
    to the *USER* event structure.  The kernel would not otherwise copy
    the user event structure into kernel space nor would it copy it back
    to return the event.

    Instead when an event occurs the kernel does a copyout of *ONLY* the
    kernel data update for the event structure (the 'data') field.  What it
    returns to user space in the kevent() call is not the event itself,
    but a POINTER to the event that the user originally passed it.

    If we do this then the user has the ability to extend the 
    struct event structure to contain whatever the user wants.  All the
    kernel cares about is the 'data' field.

    I would still reserve a bunch of fields for future direct kernel support
    for things like automatic function/thread dispatching, but this will
    result in a minimally sized in-kernel data structure and no copying back
    and forth (except to update the user 'data' field, which the kernel does
    in the kevent() syscall).

    The user event structure passed to the kernel (the kernel doesn't need
    to touch it at all except when populating 'data' when kevent() is 
    returning events:

	struct event {
	    long	data;
	    void	(*dispatch)(struct event *ev);
	    int		reserved[2];
	};

    The kernel internal event structure (or equivalent):

	struct kevent {
	    int		fd;
	    long	data;	/* to be copied into the uevent */
	    short	filter;
	    short	flags;
	    struct event *uevent;
	};

						-Matt





To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-arch" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200004070401.VAA93492>