NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: kern/56414: cmake hang on kqueue (condvar waiter list issue) ?



The following reply was made to PR kern/56414; it has been noted by GNATS.

From: Taylor R Campbell <riastradh%NetBSD.org@localhost>
To: gnats-bugs%NetBSD.org@localhost
Cc: Manuel.Bouyer%lip6.fr@localhost, joerg%bec.de@localhost, wiz%NetBSD.org@localhost, mlelstv%NetBSD.org@localhost
Subject: Re: kern/56414: cmake hang on kqueue (condvar waiter list issue) ?
Date: Sat, 9 Apr 2022 20:35:10 +0000

 This is a multi-part message in MIME format.
 --=_kfI//mdIC0kx2NGNjppVUyLgYbxCgVBW
 
 Does this still manifest on HEAD?  Do you have a machine running a
 current kernel where you've seen the cmake hang?  Can you run this
 program on it and see if it fails?
 
 Adjust N to be the (even) number of CPUs you have.  It'll check for
 progress every second and raise SIGABRT if not -- you can run it under
 gdb to catch the SIGABRT or examine the core dump later if you like.
 
 Took about an hour to wedge the first time on my 12-core/24-thread
 Sandy Bridge system (but that's running netbsd-9 and everything
 changed with pthread_cond.c in HEAD so it's not as useful as I hoped).
 
 --=_kfI//mdIC0kx2NGNjppVUyLgYbxCgVBW
 Content-Type: text/plain; charset="ISO-8859-1"; name="nbcv"
 Content-Transfer-Encoding: quoted-printable
 Content-Disposition: attachment; filename="nbcv.c"
 
 #include <sys/param.h>
 
 #include <err.h>
 #include <pthread.h>
 #include <sched.h>
 #include <signal.h>
 #include <stdio.h>
 #include <unistd.h>
 
 enum { N =3D 12 };
 
 pthread_mutex_t mutex[N];
 pthread_cond_t cond[N];
 pthread_t sleeper[N/2];
 pthread_t waker[N/2];
 struct {
 	volatile unsigned v;
 } __aligned(COHERENCY_UNIT) ticker[N/2];
 
 static void
 lock(unsigned i)
 {
 	int error;
 
 	error =3D pthread_mutex_lock(&mutex[i]);
 	if (error)
 		errc(1, error, "pthread_mutex_lock");
 }
 
 static void
 unlock(unsigned i)
 {
 	int error;
 
 	error =3D pthread_mutex_unlock(&mutex[i]);
 	if (error)
 		errc(1, error, "pthread_mutex_unlock");
 }
 
 static void
 wait(unsigned i)
 {
 	int error;
 
 	error =3D pthread_cond_wait(&cond[i], &mutex[i]);
 	if (error)
 		errc(1, error, "pthread_cond_wait");
 }
 
 static void
 wake_one(unsigned i)
 {
 	int error;
 
 	error =3D pthread_cond_signal(&cond[i]);
 	if (error)
 		errc(1, error, "pthread_cond_signal");
 }
 
 static void __unused
 wake_all(unsigned i)
 {
 	int error;
 
 	error =3D pthread_cond_broadcast(&cond[i]);
 	if (error)
 		errc(1, error, "pthread_cond_broadcast");
 }
 
 static void *
 start_sleeper(void *cookie)
 {
 	unsigned t =3D (unsigned)(uintptr_t)cookie;
 	unsigned i;
 
 	for (i =3D 0;; i++, i %=3D N) {
 		lock(i);
 		wait(i);
 		unlock(i);
 		ticker[t].v++;
 	}
 	__unreachable();
 }
 
 static void *
 start_waker(void *cookie)
 {
 	unsigned i;
 
 	(void)cookie;
 
 	for (i =3D 0;; i++, i %=3D N) {
 		lock(i);
 		wake_one(i);
 		unlock(i);
 	}
 	__unreachable();
 }
 
 int
 main(void)
 {
 	uint64_t c =3D 0;
 	unsigned tickercache[N/2] =3D {0};
 	unsigned i, tmp;
 	int error;
 
 	for (i =3D 0; i < N; i++) {
 		error =3D pthread_mutex_init(&mutex[i], NULL);
 		if (error)
 			errc(1, error, "pthread_mutex_init");
 		error =3D pthread_cond_init(&cond[i], NULL);
 		if (error)
 			errc(1, error, "pthread_cond_init");
 	}
 
 	for (i =3D 0; i < N/2; i++) {
 		error =3D pthread_create(&sleeper[i], NULL, &start_sleeper,
 		    (void *)(uintptr_t)i);
 		if (error)
 			errc(1, error ,"pthread_create sleeper");
 		error =3D pthread_create(&waker[i], NULL, &start_waker,
 		    NULL);
 		if (error)
 			errc(1, error ,"pthread_create waker");
 	}
 
 	setlinebuf(stdout);
 	for (;;) {
 		sleep(1);
 		c =3D 0;
 		for (i =3D 0; i < N/2; i++) {
 			if ((tmp =3D ticker[i].v) !=3D tickercache[i]) {
 				c +=3D (tmp - tickercache[i]);
 				tickercache[i] =3D tmp;
 			} else {
 				printf("thread %u wedged\n", i);
 				raise(SIGABRT);
 			}
 		}
 		printf("%"PRIu64" wakeups\n", c);
 	}
 	return 0;
 }
 
 --=_kfI//mdIC0kx2NGNjppVUyLgYbxCgVBW--
 


Home | Main Index | Thread Index | Old Index