r3758 - trunk/varnish-cache/bin/varnishd

phk at projects.linpro.no phk at projects.linpro.no
Fri Feb 13 10:19:51 CET 2009


Author: phk
Date: 2009-02-13 10:19:50 +0100 (Fri, 13 Feb 2009)
New Revision: 3758

Added:
   trunk/varnish-cache/bin/varnishd/cache_waiter.h
   trunk/varnish-cache/bin/varnishd/cache_waiter_epoll.c
   trunk/varnish-cache/bin/varnishd/cache_waiter_kqueue.c
   trunk/varnish-cache/bin/varnishd/cache_waiter_poll.c
   trunk/varnish-cache/bin/varnishd/cache_waiter_ports.c
Removed:
   trunk/varnish-cache/bin/varnishd/cache_acceptor.h
   trunk/varnish-cache/bin/varnishd/cache_acceptor_epoll.c
   trunk/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c
   trunk/varnish-cache/bin/varnishd/cache_acceptor_poll.c
   trunk/varnish-cache/bin/varnishd/cache_acceptor_ports.c
Modified:
   trunk/varnish-cache/bin/varnishd/Makefile.am
   trunk/varnish-cache/bin/varnishd/cache_acceptor.c
   trunk/varnish-cache/bin/varnishd/common.h
   trunk/varnish-cache/bin/varnishd/mgt_param.c
Log:
Due to lack og foresight,the threads that keep an eye on client connections
to see if they get reused ended up being named "acceptors", which is a bad
name because we have another thread which accepts new connections.

Rename the "fake" acceptors to "waiters"



Modified: trunk/varnish-cache/bin/varnishd/Makefile.am
===================================================================
--- trunk/varnish-cache/bin/varnishd/Makefile.am	2009-02-12 22:26:44 UTC (rev 3757)
+++ trunk/varnish-cache/bin/varnishd/Makefile.am	2009-02-13 09:19:50 UTC (rev 3758)
@@ -8,10 +8,10 @@
 
 varnishd_SOURCES = \
 	cache_acceptor.c \
-	cache_acceptor_epoll.c \
-	cache_acceptor_kqueue.c \
-	cache_acceptor_poll.c \
-	cache_acceptor_ports.c \
+	cache_waiter_epoll.c \
+	cache_waiter_kqueue.c \
+	cache_waiter_poll.c \
+	cache_waiter_ports.c \
 	cache_backend.c \
 	cache_backend_cfg.c \
 	cache_backend_poll.c \
@@ -60,7 +60,7 @@
 noinst_HEADERS = \
 	acct_fields.h \
 	cache.h \
-	cache_acceptor.h \
+	cache_waiter.h \
 	cache_backend.h \
 	cache_backend_poll.h \
 	common.h \

Modified: trunk/varnish-cache/bin/varnishd/cache_acceptor.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_acceptor.c	2009-02-12 22:26:44 UTC (rev 3757)
+++ trunk/varnish-cache/bin/varnishd/cache_acceptor.c	2009-02-13 09:19:50 UTC (rev 3758)
@@ -47,23 +47,23 @@
 #include "cli_priv.h"
 #include "shmlog.h"
 #include "cache.h"
-#include "cache_acceptor.h"
+#include "cache_waiter.h"
 
-static struct acceptor * const vca_acceptors[] = {
+static struct waiter * const vca_waiters[] = {
 #if defined(HAVE_KQUEUE)
-	&acceptor_kqueue,
+	&waiter_kqueue,
 #endif
 #if defined(HAVE_EPOLL_CTL)
-	&acceptor_epoll,
+	&waiter_epoll,
 #endif
 #if defined(HAVE_PORT_CREATE)
-	&acceptor_ports,
+	&waiter_ports,
 #endif
-	&acceptor_poll,
+	&waiter_poll,
 	NULL,
 };
 
-static struct acceptor const *vca_act;
+static struct waiter const *vca_act;
 
 static pthread_t	vca_thread_acct;
 static struct timeval	tv_sndtimeo;
@@ -322,7 +322,7 @@
 	(void)priv;
 
 	if (vca_act == NULL)
-		vca_act = vca_acceptors[0];
+		vca_act = vca_waiters[0];
 
 	AN(vca_act);
 	AN(vca_act->name);
@@ -347,7 +347,7 @@
 }
 
 void
-VCA_tweak_acceptor(struct cli *cli, const char *arg)
+VCA_tweak_waiter(struct cli *cli, const char *arg)
 {
 	int i;
 
@@ -358,9 +358,9 @@
 			cli_out(cli, "%s", vca_act->name);
 
 		cli_out(cli, " (");
-		for (i = 0; vca_acceptors[i] != NULL; i++)
+		for (i = 0; vca_waiters[i] != NULL; i++)
 			cli_out(cli, "%s%s", i == 0 ? "" : ", ",
-			    vca_acceptors[i]->name);
+			    vca_waiters[i]->name);
 		cli_out(cli, ")");
 		return;
 	}
@@ -368,12 +368,12 @@
 		vca_act = NULL;
 		return;
 	}
-	for (i = 0; vca_acceptors[i]->name; i++) {
-		if (!strcmp(arg, vca_acceptors[i]->name)) {
-			vca_act = vca_acceptors[i];
+	for (i = 0; vca_waiters[i]->name; i++) {
+		if (!strcmp(arg, vca_waiters[i]->name)) {
+			vca_act = vca_waiters[i];
 			return;
 		}
 	}
-	cli_out(cli, "Unknown acceptor");
+	cli_out(cli, "Unknown waiter");
 	cli_result(cli, CLIS_PARAM);
 }

Deleted: trunk/varnish-cache/bin/varnishd/cache_acceptor.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_acceptor.h	2009-02-12 22:26:44 UTC (rev 3757)
+++ trunk/varnish-cache/bin/varnishd/cache_acceptor.h	2009-02-13 09:19:50 UTC (rev 3758)
@@ -1,60 +0,0 @@
-/*-
- * Copyright (c) 2006 Verdens Gang AS
- * Copyright (c) 2006-2008 Linpro AS
- * All rights reserved.
- *
- * Author: Poul-Henning Kamp <phk at phk.freebsd.dk>
- *
- * 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 AUTHOR 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 AUTHOR 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.
- *
- * $Id$
- */
-
-struct sess;
-
-typedef void acceptor_init_f(void);
-typedef void acceptor_pass_f(struct sess *);
-
-extern int vca_pipes[2];
-
-struct acceptor {
-	const char		*name;
-	acceptor_init_f		*init;
-	acceptor_pass_f		*pass;
-};
-
-#if defined(HAVE_EPOLL_CTL)
-extern struct acceptor acceptor_epoll;
-#endif
-
-#if defined(HAVE_KQUEUE)
-extern struct acceptor acceptor_kqueue;
-#endif
-
-extern struct acceptor acceptor_poll;
-
-#if defined(HAVE_PORT_CREATE)
-extern struct acceptor acceptor_ports;
-#endif
-
-/* vca_acceptor.c */
-void vca_handover(struct sess *sp, int bad);

Deleted: trunk/varnish-cache/bin/varnishd/cache_acceptor_epoll.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_acceptor_epoll.c	2009-02-12 22:26:44 UTC (rev 3757)
+++ trunk/varnish-cache/bin/varnishd/cache_acceptor_epoll.c	2009-02-13 09:19:50 UTC (rev 3758)
@@ -1,141 +0,0 @@
-/*-
- * Copyright (c) 2006 Verdens Gang AS
- * Copyright (c) 2006-2008 Linpro AS
- * All rights reserved.
- *
- * 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 AUTHOR 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 AUTHOR 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.
- *
- * $Id$
- *
- * XXX: We need to pass sessions back into the event engine when they are
- * reused.  Not sure what the most efficient way is for that.  For now
- * write the session pointer to a pipe which the event engine monitors.
- */
-
-#include "config.h"
-
-#if defined(HAVE_EPOLL_CTL)
-
-#include <stdio.h>
-#include <errno.h>
-#include <string.h>
-#include <stdlib.h>
-#include <unistd.h>
-
-#include <sys/epoll.h>
-
-#include "shmlog.h"
-#include "cache.h"
-#include "cache_acceptor.h"
-
-static pthread_t vca_epoll_thread;
-static int epfd = -1;
-
-static VTAILQ_HEAD(,sess) sesshead = VTAILQ_HEAD_INITIALIZER(sesshead);
-
-static void
-vca_add(int fd, void *data)
-{
-	struct epoll_event ev = { EPOLLIN | EPOLLPRI, { data } };
-	AZ(epoll_ctl(epfd, EPOLL_CTL_ADD, fd, &ev));
-}
-
-static void
-vca_del(int fd)
-{
-	struct epoll_event ev = { 0, { 0 } };
-	AZ(epoll_ctl(epfd, EPOLL_CTL_DEL, fd, &ev));
-}
-
-static void *
-vca_main(void *arg)
-{
-	struct epoll_event ev;
-	double deadline;
-	int dotimer = 0;
-	double last_timeout = 0, tmp_timeout;
-	struct sess *sp, *sp2;
-	int i;
-
-	THR_SetName("cache-epoll");
-	(void)arg;
-
-	epfd = epoll_create(16);
-	assert(epfd >= 0);
-
-	vca_add(vca_pipes[0], vca_pipes);
-
-	while (1) {
-		if ((dotimer = epoll_wait(epfd, &ev, 1, 100)) > 0) {
-			if (ev.data.ptr == vca_pipes) {
-				i = read(vca_pipes[0], &sp, sizeof sp);
-				assert(i == sizeof sp);
-				CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
-				VTAILQ_INSERT_TAIL(&sesshead, sp, list);
-				vca_add(sp->fd, sp);
-			} else {
-				CAST_OBJ_NOTNULL(sp, ev.data.ptr, SESS_MAGIC);
-				i = HTC_Rx(sp->htc);
-				if (i != 0) {
-					VTAILQ_REMOVE(&sesshead, sp, list);
-					vca_del(sp->fd);
-					vca_handover(sp, i);
-				}
-			}
-		}
-		tmp_timeout = TIM_mono();
-		if ((tmp_timeout - last_timeout) > 60) {
-			last_timeout = tmp_timeout;
-		} else {
-			if (dotimer > 0)
-				continue;
-		}
-
-		/* check for timeouts */
-		deadline = TIM_real() - params->sess_timeout;
-		VTAILQ_FOREACH_SAFE(sp, &sesshead, list, sp2) {
-			CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
-			if (sp->t_open > deadline)
-				continue;
-			VTAILQ_REMOVE(&sesshead, sp, list);
-			vca_del(sp->fd);
-			vca_close_session(sp, "timeout");
-			SES_Delete(sp);
-		}
-	}
-}
-
-/*--------------------------------------------------------------------*/
-
-static void
-vca_epoll_init(void)
-{
-
-	AZ(pthread_create(&vca_epoll_thread, NULL, vca_main, NULL));
-}
-
-struct acceptor acceptor_epoll = {
-	.name =		"epoll",
-	.init =		vca_epoll_init,
-};
-
-#endif /* defined(HAVE_EPOLL_CTL) */

Deleted: trunk/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c	2009-02-12 22:26:44 UTC (rev 3757)
+++ trunk/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c	2009-02-13 09:19:50 UTC (rev 3758)
@@ -1,225 +0,0 @@
-/*-
- * Copyright (c) 2006 Verdens Gang AS
- * Copyright (c) 2006-2008 Linpro AS
- * All rights reserved.
- *
- * Author: Poul-Henning Kamp <phk at phk.freebsd.dk>
- *
- * 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 AUTHOR 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 AUTHOR 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.
- *
- * $Id$
- *
- * XXX: We need to pass sessions back into the event engine when they are
- * reused.  Not sure what the most efficient way is for that.  For now
- * write the session pointer to a pipe which the event engine monitors.
- */
-
-#include "config.h"
-
-#if defined(HAVE_KQUEUE)
-
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <unistd.h>
-
-#include <sys/event.h>
-
-#include "shmlog.h"
-#include "cache.h"
-#include "cache_acceptor.h"
-
-
-/**********************************************************************/
-
-
-static pthread_t vca_kqueue_thread;
-static int kq = -1;
-
-
-static VTAILQ_HEAD(,sess) sesshead = VTAILQ_HEAD_INITIALIZER(sesshead);
-
-#define NKEV	100
-
-static struct kevent ki[NKEV];
-static unsigned nki;
-
-static void
-vca_kq_flush(void)
-{
-	int i;
-
-	if (nki == 0)
-		return;
-	i = kevent(kq, ki, nki, NULL, 0, NULL);
-	assert(i == 0);
-	nki = 0;
-}
-
-static void
-vca_kq_sess(struct sess *sp, short arm)
-{
-
-	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
-	assert(sp->fd >= 0);
-	DSL(0x04, SLT_Debug, sp->fd, "KQ: EV_SET sp %p arm %x", sp, arm);
-	EV_SET(&ki[nki], sp->fd, EVFILT_READ, arm, 0, 0, sp);
-	if (++nki == NKEV)
-		vca_kq_flush();
-}
-
-static void
-vca_kev(const struct kevent *kp)
-{
-	int i, j;
-	struct sess *sp;
-	struct sess *ss[NKEV];
-
-	AN(kp->udata);
-	if (kp->udata == vca_pipes) {
-		j = 0;
-		i = read(vca_pipes[0], ss, sizeof ss);
-		if (i == -1 && errno == EAGAIN)
-			return;
-		while (i >= sizeof ss[0]) {
-			CHECK_OBJ_NOTNULL(ss[j], SESS_MAGIC);
-			assert(ss[j]->fd >= 0);
-			AZ(ss[j]->obj);
-			VTAILQ_INSERT_TAIL(&sesshead, ss[j], list);
-			vca_kq_sess(ss[j], EV_ADD | EV_ONESHOT);
-			j++;
-			i -= sizeof ss[0];
-		}
-		assert(i == 0);
-		return;
-	}
-	CAST_OBJ_NOTNULL(sp, kp->udata, SESS_MAGIC);
-	DSL(0x04, SLT_Debug, sp->id, "KQ: sp %p kev data %lu flags 0x%x%s",
-	    sp, (unsigned long)kp->data, kp->flags,
-	    (kp->flags & EV_EOF) ? " EOF" : "");
-
-	assert(sp->id == kp->ident);
-	assert(sp->fd == sp->id);
-	if (kp->data > 0) {
-		i = HTC_Rx(sp->htc);
-		if (i == 0) {
-			vca_kq_sess(sp, EV_ADD | EV_ONESHOT);
-			return;	/* more needed */
-		}
-		VTAILQ_REMOVE(&sesshead, sp, list);
-		vca_handover(sp, i);
-		return;
-	} else if (kp->flags & EV_EOF) {
-		VTAILQ_REMOVE(&sesshead, sp, list);
-		vca_close_session(sp, "EOF");
-		SES_Delete(sp);
-		return;
-	} else {
-		VSL(SLT_Debug, sp->id, "KQ: sp %p kev data %lu flags 0x%x%s",
-		    sp, (unsigned long)kp->data, kp->flags,
-		    (kp->flags & EV_EOF) ? " EOF" : "");
-	}
-}
-
-/*--------------------------------------------------------------------*/
-
-static void *
-vca_kqueue_main(void *arg)
-{
-	struct kevent ke[NKEV], *kp;
-	int j, n, dotimer;
-	double deadline;
-	struct sess *sp;
-
-	THR_SetName("cache-kqueue");
-	(void)arg;
-
-	kq = kqueue();
-	assert(kq >= 0);
-
-	j = 0;
-	EV_SET(&ke[j++], 0, EVFILT_TIMER, EV_ADD, 0, 100, NULL);
-	EV_SET(&ke[j++], vca_pipes[0], EVFILT_READ, EV_ADD, 0, 0, vca_pipes);
-	AZ(kevent(kq, ke, j, NULL, 0, NULL));
-
-	nki = 0;
-	while (1) {
-		dotimer = 0;
-		n = kevent(kq, ki, nki, ke, NKEV, NULL);
-		assert(n >= 1 && n <= NKEV);
-		nki = 0;
-		for (kp = ke, j = 0; j < n; j++, kp++) {
-			if (kp->filter == EVFILT_TIMER) {
-				dotimer = 1;
-				continue;
-			}
-			assert(kp->filter == EVFILT_READ);
-			vca_kev(kp);
-		}
-		if (!dotimer)
-			continue;
-		/*
-		 * Make sure we have no pending changes for the fd's
-		 * we are about to close, in case the accept(2) in the
-		 * other thread creates new fd's betwen our close and
-		 * the kevent(2) at the top of this loop, the kernel
-		 * would not know we meant "the old fd of this number".
-		 */
-		vca_kq_flush();
-		deadline = TIM_real() - params->sess_timeout;
-		for (;;) {
-			sp = VTAILQ_FIRST(&sesshead);
-			if (sp == NULL)
-				break;
-			if (sp->t_open > deadline)
-				break;
-			VTAILQ_REMOVE(&sesshead, sp, list);
-			vca_close_session(sp, "timeout");
-			SES_Delete(sp);
-		}
-	}
-}
-
-/*--------------------------------------------------------------------*/
-
-static void
-vca_kqueue_init(void)
-{
-	int i;
-
-	i = fcntl(vca_pipes[0], F_GETFL);
-	assert(i != -1);
-	i |= O_NONBLOCK;
-	i = fcntl(vca_pipes[0], F_SETFL, i);
-	assert(i != -1);
-
-	AZ(pthread_create(&vca_kqueue_thread, NULL, vca_kqueue_main, NULL));
-}
-
-struct acceptor acceptor_kqueue = {
-	.name =		"kqueue",
-	.init =		vca_kqueue_init,
-};
-
-#endif /* defined(HAVE_KQUEUE) */

Deleted: trunk/varnish-cache/bin/varnishd/cache_acceptor_poll.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_acceptor_poll.c	2009-02-12 22:26:44 UTC (rev 3757)
+++ trunk/varnish-cache/bin/varnishd/cache_acceptor_poll.c	2009-02-13 09:19:50 UTC (rev 3758)
@@ -1,167 +0,0 @@
-/*-
- * Copyright (c) 2006 Verdens Gang AS
- * Copyright (c) 2006-2008 Linpro AS
- * All rights reserved.
- *
- * Author: Poul-Henning Kamp <phk at phk.freebsd.dk>
- *
- * 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 AUTHOR 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 AUTHOR 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.
- *
- * $Id$
- *
- */
-
-#include "config.h"
-
-#include <stdio.h>
-#include <errno.h>
-#include <string.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <poll.h>
-
-#include "shmlog.h"
-#include "cache.h"
-#include "cache_acceptor.h"
-
-static pthread_t vca_poll_thread;
-static struct pollfd *pollfd;
-static unsigned npoll, hpoll;
-
-static VTAILQ_HEAD(,sess) sesshead = VTAILQ_HEAD_INITIALIZER(sesshead);
-
-/*--------------------------------------------------------------------*/
-
-static void
-vca_pollspace(unsigned fd)
-{
-	struct pollfd *newpollfd = pollfd;
-	unsigned newnpoll;
-
-	if (fd < npoll)
-		return;
-	newnpoll = npoll;
-	while (fd >= newnpoll)
-		newnpoll = newnpoll * 2 + 1;
-	VSL(SLT_Debug, 0, "Acceptor poll space increased to %u", newnpoll);
-	newpollfd = realloc(newpollfd, newnpoll * sizeof *newpollfd);
-	XXXAN(newpollfd);	/* close offending fd */
-	memset(newpollfd + npoll, 0, (newnpoll - npoll) * sizeof *newpollfd);
-	pollfd = newpollfd;
-	while (npoll < newnpoll)
-		pollfd[npoll++].fd = -1;
-}
-
-/*--------------------------------------------------------------------*/
-
-static void
-vca_poll(int fd)
-{
-
-	assert(fd >= 0);
-	vca_pollspace((unsigned)fd);
-	if (hpoll < fd)
-		hpoll = fd;
-	pollfd[fd].fd = fd;
-	pollfd[fd].events = POLLIN;
-}
-
-static void
-vca_unpoll(int fd)
-{
-
-	assert(fd >= 0);
-	vca_pollspace((unsigned)fd);
-	pollfd[fd].fd = -1;
-	pollfd[fd].events = 0;
-	if (hpoll == fd) {
-		while (pollfd[--hpoll].fd == -1)
-			continue;
-	}
-}
-
-/*--------------------------------------------------------------------*/
-
-static void *
-vca_main(void *arg)
-{
-	unsigned v;
-	struct sess *sp, *sp2;
-	double deadline;
-	int i, fd;
-
-	THR_SetName("cache-poll");
-	(void)arg;
-
-	vca_poll(vca_pipes[0]);
-
-	while (1) {
-		v = poll(pollfd, hpoll + 1, 100);
-		if (v && pollfd[vca_pipes[0]].revents) {
-			v--;
-			i = read(vca_pipes[0], &sp, sizeof sp);
-			assert(i == sizeof sp);
-			CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
-			VTAILQ_INSERT_TAIL(&sesshead, sp, list);
-			vca_poll(sp->fd);
-		}
-		deadline = TIM_real() - params->sess_timeout;
-		VTAILQ_FOREACH_SAFE(sp, &sesshead, list, sp2) {
-			if (v == 0)
-				break;
-			CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
-			fd = sp->fd;
-			if (pollfd[fd].revents) {
-				v--;
-				i = HTC_Rx(sp->htc);
-				VTAILQ_REMOVE(&sesshead, sp, list);
-				if (i == 0) {
-					VTAILQ_INSERT_HEAD(&sesshead, sp, list);
-					continue;
-				}
-				vca_unpoll(fd);
-				vca_handover(sp, i);
-				continue;
-			}
-			if (sp->t_open > deadline)
-				continue;
-			VTAILQ_REMOVE(&sesshead, sp, list);
-			vca_unpoll(fd);
-			vca_close_session(sp, "timeout");
-			SES_Delete(sp);
-		}
-	}
-}
-
-/*--------------------------------------------------------------------*/
-
-static void
-vca_poll_init(void)
-{
-
-	AZ(pthread_create(&vca_poll_thread, NULL, vca_main, NULL));
-}
-
-struct acceptor acceptor_poll = {
-	.name =		"poll",
-	.init =		vca_poll_init,
-};

Deleted: trunk/varnish-cache/bin/varnishd/cache_acceptor_ports.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_acceptor_ports.c	2009-02-12 22:26:44 UTC (rev 3757)
+++ trunk/varnish-cache/bin/varnishd/cache_acceptor_ports.c	2009-02-13 09:19:50 UTC (rev 3758)
@@ -1,171 +0,0 @@
-/*-
- * Copyright (c) 2006 Verdens Gang AS
- * Copyright (c) 2006 Linpro AS
- * Copyright (c) 2007 OmniTI Computer Consulting, Inc.
- * Copyright (c) 2007 Theo Schlossnagle
- * All rights reserved.
- *
- * 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 AUTHOR 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 AUTHOR 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.
- *
- * $Id$
- *
- * XXX: We need to pass sessions back into the event engine when they are
- * reused.  Not sure what the most efficient way is for that.  For now
- * write the session pointer to a pipe which the event engine monitors.
- */
-
-#include "config.h"
-#if defined(HAVE_PORT_CREATE)
-
-#include <stdio.h>
-#include <errno.h>
-#include <string.h>
-#include <stdlib.h>
-#include <unistd.h>
-
-#include <port.h>
-
-#ifndef HAVE_CLOCK_GETTIME
-#include "compat/clock_gettime.h"
-#endif
-
-#include "shmlog.h"
-#include "cache.h"
-#include "cache_acceptor.h"
-
-#define MAX_EVENTS 256
-static pthread_t vca_ports_thread;
-int solaris_dport = -1;
-
-static VTAILQ_HEAD(,sess) sesshead = VTAILQ_HEAD_INITIALIZER(sesshead);
-
-static void
-vca_add(int fd, void *data)
-{
-	AZ(port_associate(solaris_dport, PORT_SOURCE_FD, fd,
-	    POLLIN | POLLERR | POLLPRI, data));
-}
-
-static void
-vca_del(int fd)
-{
-	port_dissociate(solaris_dport, PORT_SOURCE_FD, fd);
-}
-
-static void
-vca_port_ev(port_event_t *ev) {
-	struct sess *sp;
-	if(ev->portev_source == PORT_SOURCE_USER) {
-		sp = ev->portev_user;
-		CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
-		assert(sp->fd >= 0);
-		AZ(sp->obj);
-		VTAILQ_INSERT_TAIL(&sesshead, sp, list);
-		vca_add(sp->fd, sp);
-	} else {
-		int i;
-		CAST_OBJ_NOTNULL(sp, ev->portev_user, SESS_MAGIC);
-		if(ev->portev_events & POLLERR) {
-			VTAILQ_REMOVE(&sesshead, sp, list);
-			vca_close_session(sp, "EOF");
-			SES_Delete(sp);
-			return;
-		}
-		i = HTC_Rx(sp->htc);
-		if (i == 0)
-			return;
-		if (i > 0) {
-			VTAILQ_REMOVE(&sesshead, sp, list);
-			if (sp->fd != -1)
-				vca_del(sp->fd);
-			vca_handover(sp, i);
-		}
-	}
-	return;
-}
-
-static void *
-vca_main(void *arg)
-{
-	struct sess *sp;
-
-	(void)arg;
-
-	solaris_dport = port_create();
-	assert(solaris_dport >= 0);
-
-	while (1) {
-		port_event_t ev[MAX_EVENTS];
-		int nevents, ei;
-		double deadline;
-		struct timespec ts;
-		ts.tv_sec = 0L;
-		ts.tv_nsec = 50L /*ms*/  * 1000L /*us*/  * 1000L /*ns*/;
-		nevents = 1;
-		if (port_getn(solaris_dport, ev, MAX_EVENTS, &nevents, &ts)
-		     == 0) {
-			for (ei=0; ei<nevents; ei++) {
-				vca_port_ev(ev + ei);
-			}
-		}
-		/* check for timeouts */
-		deadline = TIM_real() - params->sess_timeout;
-		for (;;) {
-			sp = VTAILQ_FIRST(&sesshead);
-			if (sp == NULL)
-				break;
-			if (sp->t_open > deadline)
-				break;
-			VTAILQ_REMOVE(&sesshead, sp, list);
-			if(sp->fd != -1)
-				vca_del(sp->fd);
-			vca_close_session(sp, "timeout");
-			SES_Delete(sp);
-		}
-	}
-}
-
-static void
-vca_ports_pass(struct sess *sp)
-{
-	int r;
-	while((r = port_send(solaris_dport, 0, sp)) == -1 &&
-		errno == EAGAIN);
-	AZ(r);
-}
-
-/*--------------------------------------------------------------------*/
-
-static void
-vca_ports_init(void)
-{
-
-	AZ(pthread_create(&vca_ports_thread, NULL, vca_main, NULL));
-}
-
-struct acceptor acceptor_ports = {
-	.name =		"ports",
-	.init =		vca_ports_init,
-	.pass =		vca_ports_pass
-};
-
-#endif /* defined(HAVE_PORT_CREATE) */

Copied: trunk/varnish-cache/bin/varnishd/cache_waiter.h (from rev 3755, trunk/varnish-cache/bin/varnishd/cache_acceptor.h)
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_waiter.h	                        (rev 0)
+++ trunk/varnish-cache/bin/varnishd/cache_waiter.h	2009-02-13 09:19:50 UTC (rev 3758)
@@ -0,0 +1,60 @@
+/*-
+ * Copyright (c) 2006 Verdens Gang AS
+ * Copyright (c) 2006-2008 Linpro AS
+ * All rights reserved.
+ *
+ * Author: Poul-Henning Kamp <phk at phk.freebsd.dk>
+ *
+ * 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 AUTHOR 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 AUTHOR 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.
+ *
+ * $Id$
+ */
+
+struct sess;
+
+typedef void waiter_init_f(void);
+typedef void waiter_pass_f(struct sess *);
+
+extern int vca_pipes[2];
+
+struct waiter {
+	const char		*name;
+	waiter_init_f		*init;
+	waiter_pass_f		*pass;
+};
+
+#if defined(HAVE_EPOLL_CTL)
+extern struct waiter waiter_epoll;
+#endif
+
+#if defined(HAVE_KQUEUE)
+extern struct waiter waiter_kqueue;
+#endif
+
+extern struct waiter waiter_poll;
+
+#if defined(HAVE_PORT_CREATE)
+extern struct waiter waiter_ports;
+#endif
+
+/* vca_acceptor.c */
+void vca_handover(struct sess *sp, int bad);

Copied: trunk/varnish-cache/bin/varnishd/cache_waiter_epoll.c (from rev 3755, trunk/varnish-cache/bin/varnishd/cache_acceptor_epoll.c)
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_waiter_epoll.c	                        (rev 0)
+++ trunk/varnish-cache/bin/varnishd/cache_waiter_epoll.c	2009-02-13 09:19:50 UTC (rev 3758)
@@ -0,0 +1,141 @@
+/*-
+ * Copyright (c) 2006 Verdens Gang AS
+ * Copyright (c) 2006-2008 Linpro AS
+ * All rights reserved.
+ *
+ * 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 AUTHOR 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 AUTHOR 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.
+ *
+ * $Id$
+ *
+ * XXX: We need to pass sessions back into the event engine when they are
+ * reused.  Not sure what the most efficient way is for that.  For now
+ * write the session pointer to a pipe which the event engine monitors.
+ */
+
+#include "config.h"
+
+#if defined(HAVE_EPOLL_CTL)
+
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <sys/epoll.h>
+
+#include "shmlog.h"
+#include "cache.h"
+#include "cache_waiter.h"
+
+static pthread_t vca_epoll_thread;
+static int epfd = -1;
+
+static VTAILQ_HEAD(,sess) sesshead = VTAILQ_HEAD_INITIALIZER(sesshead);
+
+static void
+vca_add(int fd, void *data)
+{
+	struct epoll_event ev = { EPOLLIN | EPOLLPRI, { data } };
+	AZ(epoll_ctl(epfd, EPOLL_CTL_ADD, fd, &ev));
+}
+
+static void
+vca_del(int fd)
+{
+	struct epoll_event ev = { 0, { 0 } };
+	AZ(epoll_ctl(epfd, EPOLL_CTL_DEL, fd, &ev));
+}
+
+static void *
+vca_main(void *arg)
+{
+	struct epoll_event ev;
+	double deadline;
+	int dotimer = 0;
+	double last_timeout = 0, tmp_timeout;
+	struct sess *sp, *sp2;
+	int i;
+
+	THR_SetName("cache-epoll");
+	(void)arg;
+
+	epfd = epoll_create(16);
+	assert(epfd >= 0);
+
+	vca_add(vca_pipes[0], vca_pipes);
+
+	while (1) {
+		if ((dotimer = epoll_wait(epfd, &ev, 1, 100)) > 0) {
+			if (ev.data.ptr == vca_pipes) {
+				i = read(vca_pipes[0], &sp, sizeof sp);
+				assert(i == sizeof sp);
+				CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
+				VTAILQ_INSERT_TAIL(&sesshead, sp, list);
+				vca_add(sp->fd, sp);
+			} else {
+				CAST_OBJ_NOTNULL(sp, ev.data.ptr, SESS_MAGIC);
+				i = HTC_Rx(sp->htc);
+				if (i != 0) {
+					VTAILQ_REMOVE(&sesshead, sp, list);
+					vca_del(sp->fd);
+					vca_handover(sp, i);
+				}
+			}
+		}
+		tmp_timeout = TIM_mono();
+		if ((tmp_timeout - last_timeout) > 60) {
+			last_timeout = tmp_timeout;
+		} else {
+			if (dotimer > 0)
+				continue;
+		}
+
+		/* check for timeouts */
+		deadline = TIM_real() - params->sess_timeout;
+		VTAILQ_FOREACH_SAFE(sp, &sesshead, list, sp2) {
+			CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
+			if (sp->t_open > deadline)
+				continue;
+			VTAILQ_REMOVE(&sesshead, sp, list);
+			vca_del(sp->fd);
+			vca_close_session(sp, "timeout");
+			SES_Delete(sp);
+		}
+	}
+}
+
+/*--------------------------------------------------------------------*/
+
+static void
+vca_epoll_init(void)
+{
+
+	AZ(pthread_create(&vca_epoll_thread, NULL, vca_main, NULL));
+}
+
+struct waiter waiter_epoll = {
+	.name =		"epoll",
+	.init =		vca_epoll_init,
+};
+
+#endif /* defined(HAVE_EPOLL_CTL) */

Copied: trunk/varnish-cache/bin/varnishd/cache_waiter_kqueue.c (from rev 3755, trunk/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c)
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_waiter_kqueue.c	                        (rev 0)
+++ trunk/varnish-cache/bin/varnishd/cache_waiter_kqueue.c	2009-02-13 09:19:50 UTC (rev 3758)
@@ -0,0 +1,225 @@
+/*-
+ * Copyright (c) 2006 Verdens Gang AS
+ * Copyright (c) 2006-2008 Linpro AS
+ * All rights reserved.
+ *
+ * Author: Poul-Henning Kamp <phk at phk.freebsd.dk>
+ *
+ * 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 AUTHOR 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 AUTHOR 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.
+ *
+ * $Id$
+ *
+ * XXX: We need to pass sessions back into the event engine when they are
+ * reused.  Not sure what the most efficient way is for that.  For now
+ * write the session pointer to a pipe which the event engine monitors.
+ */
+
+#include "config.h"
+
+#if defined(HAVE_KQUEUE)
+
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <sys/event.h>
+
+#include "shmlog.h"
+#include "cache.h"
+#include "cache_waiter.h"
+
+
+/**********************************************************************/
+
+
+static pthread_t vca_kqueue_thread;
+static int kq = -1;
+
+
+static VTAILQ_HEAD(,sess) sesshead = VTAILQ_HEAD_INITIALIZER(sesshead);
+
+#define NKEV	100
+
+static struct kevent ki[NKEV];
+static unsigned nki;
+
+static void
+vca_kq_flush(void)
+{
+	int i;
+
+	if (nki == 0)
+		return;
+	i = kevent(kq, ki, nki, NULL, 0, NULL);
+	assert(i == 0);
+	nki = 0;
+}
+
+static void
+vca_kq_sess(struct sess *sp, short arm)
+{
+
+	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
+	assert(sp->fd >= 0);
+	DSL(0x04, SLT_Debug, sp->fd, "KQ: EV_SET sp %p arm %x", sp, arm);
+	EV_SET(&ki[nki], sp->fd, EVFILT_READ, arm, 0, 0, sp);
+	if (++nki == NKEV)
+		vca_kq_flush();
+}
+
+static void
+vca_kev(const struct kevent *kp)
+{
+	int i, j;
+	struct sess *sp;
+	struct sess *ss[NKEV];
+
+	AN(kp->udata);
+	if (kp->udata == vca_pipes) {
+		j = 0;
+		i = read(vca_pipes[0], ss, sizeof ss);
+		if (i == -1 && errno == EAGAIN)
+			return;
+		while (i >= sizeof ss[0]) {
+			CHECK_OBJ_NOTNULL(ss[j], SESS_MAGIC);
+			assert(ss[j]->fd >= 0);
+			AZ(ss[j]->obj);
+			VTAILQ_INSERT_TAIL(&sesshead, ss[j], list);
+			vca_kq_sess(ss[j], EV_ADD | EV_ONESHOT);
+			j++;
+			i -= sizeof ss[0];
+		}
+		assert(i == 0);
+		return;
+	}
+	CAST_OBJ_NOTNULL(sp, kp->udata, SESS_MAGIC);
+	DSL(0x04, SLT_Debug, sp->id, "KQ: sp %p kev data %lu flags 0x%x%s",
+	    sp, (unsigned long)kp->data, kp->flags,
+	    (kp->flags & EV_EOF) ? " EOF" : "");
+
+	assert(sp->id == kp->ident);
+	assert(sp->fd == sp->id);
+	if (kp->data > 0) {
+		i = HTC_Rx(sp->htc);
+		if (i == 0) {
+			vca_kq_sess(sp, EV_ADD | EV_ONESHOT);
+			return;	/* more needed */
+		}
+		VTAILQ_REMOVE(&sesshead, sp, list);
+		vca_handover(sp, i);
+		return;
+	} else if (kp->flags & EV_EOF) {
+		VTAILQ_REMOVE(&sesshead, sp, list);
+		vca_close_session(sp, "EOF");
+		SES_Delete(sp);
+		return;
+	} else {
+		VSL(SLT_Debug, sp->id, "KQ: sp %p kev data %lu flags 0x%x%s",
+		    sp, (unsigned long)kp->data, kp->flags,
+		    (kp->flags & EV_EOF) ? " EOF" : "");
+	}
+}
+
+/*--------------------------------------------------------------------*/
+
+static void *
+vca_kqueue_main(void *arg)
+{
+	struct kevent ke[NKEV], *kp;
+	int j, n, dotimer;
+	double deadline;
+	struct sess *sp;
+
+	THR_SetName("cache-kqueue");
+	(void)arg;
+
+	kq = kqueue();
+	assert(kq >= 0);
+
+	j = 0;
+	EV_SET(&ke[j++], 0, EVFILT_TIMER, EV_ADD, 0, 100, NULL);
+	EV_SET(&ke[j++], vca_pipes[0], EVFILT_READ, EV_ADD, 0, 0, vca_pipes);
+	AZ(kevent(kq, ke, j, NULL, 0, NULL));
+
+	nki = 0;
+	while (1) {
+		dotimer = 0;
+		n = kevent(kq, ki, nki, ke, NKEV, NULL);
+		assert(n >= 1 && n <= NKEV);
+		nki = 0;
+		for (kp = ke, j = 0; j < n; j++, kp++) {
+			if (kp->filter == EVFILT_TIMER) {
+				dotimer = 1;
+				continue;
+			}
+			assert(kp->filter == EVFILT_READ);
+			vca_kev(kp);
+		}
+		if (!dotimer)
+			continue;
+		/*
+		 * Make sure we have no pending changes for the fd's
+		 * we are about to close, in case the accept(2) in the
+		 * other thread creates new fd's betwen our close and
+		 * the kevent(2) at the top of this loop, the kernel
+		 * would not know we meant "the old fd of this number".
+		 */
+		vca_kq_flush();
+		deadline = TIM_real() - params->sess_timeout;
+		for (;;) {
+			sp = VTAILQ_FIRST(&sesshead);
+			if (sp == NULL)
+				break;
+			if (sp->t_open > deadline)
+				break;
+			VTAILQ_REMOVE(&sesshead, sp, list);
+			vca_close_session(sp, "timeout");
+			SES_Delete(sp);
+		}
+	}
+}
+
+/*--------------------------------------------------------------------*/
+
+static void
+vca_kqueue_init(void)
+{
+	int i;
+
+	i = fcntl(vca_pipes[0], F_GETFL);
+	assert(i != -1);
+	i |= O_NONBLOCK;
+	i = fcntl(vca_pipes[0], F_SETFL, i);
+	assert(i != -1);
+
+	AZ(pthread_create(&vca_kqueue_thread, NULL, vca_kqueue_main, NULL));
+}
+
+struct waiter waiter_kqueue = {
+	.name =		"kqueue",
+	.init =		vca_kqueue_init,
+};
+
+#endif /* defined(HAVE_KQUEUE) */

Copied: trunk/varnish-cache/bin/varnishd/cache_waiter_poll.c (from rev 3755, trunk/varnish-cache/bin/varnishd/cache_acceptor_poll.c)
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_waiter_poll.c	                        (rev 0)
+++ trunk/varnish-cache/bin/varnishd/cache_waiter_poll.c	2009-02-13 09:19:50 UTC (rev 3758)
@@ -0,0 +1,167 @@
+/*-
+ * Copyright (c) 2006 Verdens Gang AS
+ * Copyright (c) 2006-2008 Linpro AS
+ * All rights reserved.
+ *
+ * Author: Poul-Henning Kamp <phk at phk.freebsd.dk>
+ *
+ * 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 AUTHOR 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 AUTHOR 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.
+ *
+ * $Id$
+ *
+ */
+
+#include "config.h"
+
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <poll.h>
+
+#include "shmlog.h"
+#include "cache.h"
+#include "cache_waiter.h"
+
+static pthread_t vca_poll_thread;
+static struct pollfd *pollfd;
+static unsigned npoll, hpoll;
+
+static VTAILQ_HEAD(,sess) sesshead = VTAILQ_HEAD_INITIALIZER(sesshead);
+
+/*--------------------------------------------------------------------*/
+
+static void
+vca_pollspace(unsigned fd)
+{
+	struct pollfd *newpollfd = pollfd;
+	unsigned newnpoll;
+
+	if (fd < npoll)
+		return;
+	newnpoll = npoll;
+	while (fd >= newnpoll)
+		newnpoll = newnpoll * 2 + 1;
+	VSL(SLT_Debug, 0, "Acceptor poll space increased to %u", newnpoll);
+	newpollfd = realloc(newpollfd, newnpoll * sizeof *newpollfd);
+	XXXAN(newpollfd);	/* close offending fd */
+	memset(newpollfd + npoll, 0, (newnpoll - npoll) * sizeof *newpollfd);
+	pollfd = newpollfd;
+	while (npoll < newnpoll)
+		pollfd[npoll++].fd = -1;
+}
+
+/*--------------------------------------------------------------------*/
+
+static void
+vca_poll(int fd)
+{
+
+	assert(fd >= 0);
+	vca_pollspace((unsigned)fd);
+	if (hpoll < fd)
+		hpoll = fd;
+	pollfd[fd].fd = fd;
+	pollfd[fd].events = POLLIN;
+}
+
+static void
+vca_unpoll(int fd)
+{
+
+	assert(fd >= 0);
+	vca_pollspace((unsigned)fd);
+	pollfd[fd].fd = -1;
+	pollfd[fd].events = 0;
+	if (hpoll == fd) {
+		while (pollfd[--hpoll].fd == -1)
+			continue;
+	}
+}
+
+/*--------------------------------------------------------------------*/
+
+static void *
+vca_main(void *arg)
+{
+	unsigned v;
+	struct sess *sp, *sp2;
+	double deadline;
+	int i, fd;
+
+	THR_SetName("cache-poll");
+	(void)arg;
+
+	vca_poll(vca_pipes[0]);
+
+	while (1) {
+		v = poll(pollfd, hpoll + 1, 100);
+		if (v && pollfd[vca_pipes[0]].revents) {
+			v--;
+			i = read(vca_pipes[0], &sp, sizeof sp);
+			assert(i == sizeof sp);
+			CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
+			VTAILQ_INSERT_TAIL(&sesshead, sp, list);
+			vca_poll(sp->fd);
+		}
+		deadline = TIM_real() - params->sess_timeout;
+		VTAILQ_FOREACH_SAFE(sp, &sesshead, list, sp2) {
+			if (v == 0)
+				break;
+			CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
+			fd = sp->fd;
+			if (pollfd[fd].revents) {
+				v--;
+				i = HTC_Rx(sp->htc);
+				VTAILQ_REMOVE(&sesshead, sp, list);
+				if (i == 0) {
+					VTAILQ_INSERT_HEAD(&sesshead, sp, list);
+					continue;
+				}
+				vca_unpoll(fd);
+				vca_handover(sp, i);
+				continue;
+			}
+			if (sp->t_open > deadline)
+				continue;
+			VTAILQ_REMOVE(&sesshead, sp, list);
+			vca_unpoll(fd);
+			vca_close_session(sp, "timeout");
+			SES_Delete(sp);
+		}
+	}
+}
+
+/*--------------------------------------------------------------------*/
+
+static void
+vca_poll_init(void)
+{
+
+	AZ(pthread_create(&vca_poll_thread, NULL, vca_main, NULL));
+}
+
+struct waiter waiter_poll = {
+	.name =		"poll",
+	.init =		vca_poll_init,
+};

Copied: trunk/varnish-cache/bin/varnishd/cache_waiter_ports.c (from rev 3755, trunk/varnish-cache/bin/varnishd/cache_acceptor_ports.c)
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_waiter_ports.c	                        (rev 0)
+++ trunk/varnish-cache/bin/varnishd/cache_waiter_ports.c	2009-02-13 09:19:50 UTC (rev 3758)
@@ -0,0 +1,171 @@
+/*-
+ * Copyright (c) 2006 Verdens Gang AS
+ * Copyright (c) 2006 Linpro AS
+ * Copyright (c) 2007 OmniTI Computer Consulting, Inc.
+ * Copyright (c) 2007 Theo Schlossnagle
+ * All rights reserved.
+ *
+ * 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 AUTHOR 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 AUTHOR 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.
+ *
+ * $Id$
+ *
+ * XXX: We need to pass sessions back into the event engine when they are
+ * reused.  Not sure what the most efficient way is for that.  For now
+ * write the session pointer to a pipe which the event engine monitors.
+ */
+
+#include "config.h"
+#if defined(HAVE_PORT_CREATE)
+
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <port.h>
+
+#ifndef HAVE_CLOCK_GETTIME
+#include "compat/clock_gettime.h"
+#endif
+
+#include "shmlog.h"
+#include "cache.h"
+#include "cache_waiter.h"
+
+#define MAX_EVENTS 256
+static pthread_t vca_ports_thread;
+int solaris_dport = -1;
+
+static VTAILQ_HEAD(,sess) sesshead = VTAILQ_HEAD_INITIALIZER(sesshead);
+
+static void
+vca_add(int fd, void *data)
+{
+	AZ(port_associate(solaris_dport, PORT_SOURCE_FD, fd,
+	    POLLIN | POLLERR | POLLPRI, data));
+}
+
+static void
+vca_del(int fd)
+{
+	port_dissociate(solaris_dport, PORT_SOURCE_FD, fd);
+}
+
+static void
+vca_port_ev(port_event_t *ev) {
+	struct sess *sp;
+	if(ev->portev_source == PORT_SOURCE_USER) {
+		sp = ev->portev_user;
+		CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
+		assert(sp->fd >= 0);
+		AZ(sp->obj);
+		VTAILQ_INSERT_TAIL(&sesshead, sp, list);
+		vca_add(sp->fd, sp);
+	} else {
+		int i;
+		CAST_OBJ_NOTNULL(sp, ev->portev_user, SESS_MAGIC);
+		if(ev->portev_events & POLLERR) {
+			VTAILQ_REMOVE(&sesshead, sp, list);
+			vca_close_session(sp, "EOF");
+			SES_Delete(sp);
+			return;
+		}
+		i = HTC_Rx(sp->htc);
+		if (i == 0)
+			return;
+		if (i > 0) {
+			VTAILQ_REMOVE(&sesshead, sp, list);
+			if (sp->fd != -1)
+				vca_del(sp->fd);
+			vca_handover(sp, i);
+		}
+	}
+	return;
+}
+
+static void *
+vca_main(void *arg)
+{
+	struct sess *sp;
+
+	(void)arg;
+
+	solaris_dport = port_create();
+	assert(solaris_dport >= 0);
+
+	while (1) {
+		port_event_t ev[MAX_EVENTS];
+		int nevents, ei;
+		double deadline;
+		struct timespec ts;
+		ts.tv_sec = 0L;
+		ts.tv_nsec = 50L /*ms*/  * 1000L /*us*/  * 1000L /*ns*/;
+		nevents = 1;
+		if (port_getn(solaris_dport, ev, MAX_EVENTS, &nevents, &ts)
+		     == 0) {
+			for (ei=0; ei<nevents; ei++) {
+				vca_port_ev(ev + ei);
+			}
+		}
+		/* check for timeouts */
+		deadline = TIM_real() - params->sess_timeout;
+		for (;;) {
+			sp = VTAILQ_FIRST(&sesshead);
+			if (sp == NULL)
+				break;
+			if (sp->t_open > deadline)
+				break;
+			VTAILQ_REMOVE(&sesshead, sp, list);
+			if(sp->fd != -1)
+				vca_del(sp->fd);
+			vca_close_session(sp, "timeout");
+			SES_Delete(sp);
+		}
+	}
+}
+
+static void
+vca_ports_pass(struct sess *sp)
+{
+	int r;
+	while((r = port_send(solaris_dport, 0, sp)) == -1 &&
+		errno == EAGAIN);
+	AZ(r);
+}
+
+/*--------------------------------------------------------------------*/
+
+static void
+vca_ports_init(void)
+{
+
+	AZ(pthread_create(&vca_ports_thread, NULL, vca_main, NULL));
+}
+
+struct waiter waiter_ports = {
+	.name =		"ports",
+	.init =		vca_ports_init,
+	.pass =		vca_ports_pass
+};
+
+#endif /* defined(HAVE_PORT_CREATE) */

Modified: trunk/varnish-cache/bin/varnishd/common.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/common.h	2009-02-12 22:26:44 UTC (rev 3757)
+++ trunk/varnish-cache/bin/varnishd/common.h	2009-02-13 09:19:50 UTC (rev 3758)
@@ -33,7 +33,7 @@
 struct sockaddr;
 
 /* cache_acceptor.c */
-void VCA_tweak_acceptor(struct cli *cli, const char *arg);
+void VCA_tweak_waiter(struct cli *cli, const char *arg);
 
 /* shmlog.c */
 void VSL_Panic(int *len, char **ptr);

Modified: trunk/varnish-cache/bin/varnishd/mgt_param.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/mgt_param.c	2009-02-12 22:26:44 UTC (rev 3757)
+++ trunk/varnish-cache/bin/varnishd/mgt_param.c	2009-02-13 09:19:50 UTC (rev 3758)
@@ -413,12 +413,12 @@
 /*--------------------------------------------------------------------*/
 
 static void
-tweak_acceptor(struct cli *cli, const struct parspec *par, const char *arg)
+tweak_waiter(struct cli *cli, const struct parspec *par, const char *arg)
 {
 
 	/* XXX should have tweak_generic_string */
 	(void)par;
-	VCA_tweak_acceptor(cli, arg);
+	VCA_tweak_waiter(cli, arg);
 }
 
 /*--------------------------------------------------------------------*/
@@ -701,7 +701,7 @@
 		"completing.\n"
 		"Setting this too high results in worker threads not doing "
 		"anything for their keep, setting it too low just means that "
-		"more sessions take a detour around the acceptor.",
+		"more sessions take a detour around the waiter.",
 		EXPERIMENTAL,
 		"0", "ms" },
 	{ "cli_buffer", tweak_uint, &master.cli_buffer, 4096, UINT_MAX,
@@ -726,8 +726,8 @@
 		"SessionOpen shared memory record.\n",
 		0,
 		"off", "bool" },
-	{ "acceptor", tweak_acceptor, NULL, 0, 0,
-		"Select the acceptor kernel interface.\n",
+	{ "waiter", tweak_waiter, NULL, 0, 0,
+		"Select the waiter kernel interface.\n",
 		EXPERIMENTAL | MUST_RESTART,
 		"default", NULL },
 	{ "diag_bitmap", tweak_diag_bitmap, 0, 0, 0,



More information about the varnish-commit mailing list