Subject: Re: After newlock2 merge: Different pthread behavior for userland
To: None <current-users@netbsd.org>
From: Takahiro Kambe <taca@back-street.net>
List: current-users
Date: 03/24/2007 02:16:16
In message <200703231053.58668.sverre@viewmark.com>
	on Fri, 23 Mar 2007 10:53:58 -0600,
	Sverre Froyen <sverre@viewmark.com> wrote:
> load averages:  0.07,  0.05,  0.04                       up 0 days,  1:34   
> 10:31:17
> 59 processes:  58 sleeping, 1 on processor
> CPU states:  0.0% user,  0.0% nice,  0.0% system,  0.0% interrupt,  100% idle
> Memory: 136M Act, 4188K Wired, 10M Exec, 104M File, 303M Free
> Swap: 1000M Total, 1000M Free
>  
>   PID USERNAME PRI NICE   SIZE   RES STATE      TIME   WCPU    CPU COMMAND
>    16 root      18    0     0K   12M syncer     0:05  0.00%  0.00% [ioflush]
>  2175 sverre    28    0   240K 1160K CPU        0:00  0.00%  0.00% top
>   417 www       29    0  4176K 1556K tstile     0:00  0.00%  0.00% httpd
>  1229 www       29    0  4176K 1068K tstile     0:00  0.00%  0.00% httpd
>  1367 www       28    0  4176K 1556K tstile     0:00  0.00%  0.00% httpd
>  1908 www       28    0  4176K 1068K tstile     0:00  0.00%  0.00% httpd
>  1440 root      28    0   244K  920K tstile     0:00  0.00%  0.00% cron
This "tstile" situation could be happen with a simple program,
with kernel of 19th Mar. at least.

This is contained in configure script of libevent.

-- 
Takahiro Kambe <taca@back-street.net>

#include <sys/types.h>
#include <sys/time.h>
#include <sys/event.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>

int
main(int argc, char **argv)
{
	int kq;
	int n;
	int fd[2];
	struct kevent ev;
	struct timespec ts;
	char buf[8000];

	if (pipe(fd) == -1)
		exit(1);
	if (fcntl(fd[1], F_SETFL, O_NONBLOCK) == -1)
		exit(1);

	while ((n = write(fd[1], buf, sizeof(buf))) == sizeof(buf))
		;

        if ((kq = kqueue()) == -1)
		exit(1);

	ev.ident = fd[1];
	ev.filter = EVFILT_WRITE;
	ev.flags = EV_ADD | EV_ENABLE;
	n = kevent(kq, &ev, 1, NULL, 0, NULL);
	if (n == -1)
		exit(1);

	read(fd[0], buf, sizeof(buf));

	ts.tv_sec = 0;
	ts.tv_nsec = 0;
	n = kevent(kq, NULL, 0, &ev, 1, &ts);
	if (n == -1 || n == 0)
		exit(1);

	exit(0);
}