NetBSD-Bugs archive

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

Re: PR/53998 CVS commit: src/sys



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

From: =?UTF-8?Q?BERTRAND_Jo=c3=abl?= <joel.bertrand%systella.fr@localhost>
To: Christos Zoulas <christos%zoulas.com@localhost>,
        "gnats-bugs%netbsd.org@localhost" <gnats-bugs%NetBSD.org@localhost>
Cc: kern-bug-people%netbsd.org@localhost, gnats-admin%netbsd.org@localhost, netbsd-bugs%netbsd.org@localhost
Subject: Re: PR/53998 CVS commit: src/sys
Date: Sun, 10 Mar 2019 11:09:24 +0100

 This is a multi-part message in MIME format.
 --------------C8161B390C4FAED3061F6A9A
 Content-Type: text/plain; charset=UTF-8
 Content-Transfer-Encoding: 8bit
 
 Christos Zoulas a écrit :
 > This is not a bug. Nobody is waiting for those processes (they all end up zombies), so eventually you run out.
 
 	Certainly. I haven't put waitpid() to simplify my stress test. When
 test program aborts, there are some child processes in run state (not in
 zombie state) and they take a lot of CPU time. gdb shows that these
 processes stall in /usr/libexec/ld.elf_so without any other information
 (no debugging symbols found).
 
 	That's being said, in my complete program, I wait for child process
 with waitpid(), line 4138 of src/instructions_s1.c :
 
         while(waitpid(pid, &status, 0) == -1)
         {
             if (errno != EINTR)
             {
                 (*s_etat_processus).erreur_systeme = d_es_processus;
                 return;
             }
         }
 
 	If you run attached program, you will obtain following output :
 
 < 454 >
 < 456 >
 < 452 >
 < 450 >
 < 453 >
 Free slot : 0 (457 threads)
 Free slot : 1 (458 threads)
 Free slot : 2 (459 threads)
 Free slot : 3 (460 threads)
 Free slot : 4 (461 threads)
 Free slot : 5 (462 threads)
 Free slot : 6 (463 threads)
 Free slot : 7 (464 threads)
 < 458 >
 < 460 >
 < 459 >
 < 457 >
 < 464 >
 < 461 >
 < 463 >
 < 462 >
 Free slot : 0 (465 threads)
 Free slot : 1 (466 threads)
 Free slot : 2 (467 threads)
 Free slot : 3 (468 threads)
 Free slot : 4 (469 threads)
 Free slot : 5 (470 threads)
 Free slot : 6 (471 threads)
 dead lock detected   <-------------- ?
 Free slot : 7 (472 threads)
 < 466 >
 < 467 >
 < 469 >
 
 	After some times :
 
 < 20301 >
 Free slot : 2 (20302 threads)
 < 20302 >
 Free slot : 5 (20303 threads)
 < 20303 >
 Free slot : 0 (20304 threads)
 Free slot : 6 (20305 threads)
 < 20304 >
 < 20305 >
 Free slot : 4 (20306 threads)
 < 20306 >
 Free slot : 2 (20307 threads)
 < 20307 >
 Free slot : 5 (20308 threads)
 < 20308 >
 Free slot : 0 (20309 threads)
 Free slot : 6 (20310 threads)
 < 20310 >
 < 20309 >
 Free slot : 4 (20311 threads)
 < 20311 >
 Free slot : 2 (20312 threads)
 < 20312 >
 Free slot : 5 (20313 threads)
 < 20313 >
 Free slot : 0 (20314 threads)
 Free slot : 6 (20315 threads)
 < 20314 >
 < 20315 >
 Free slot : 4 (20316 threads)
 < 20316 >
 Free slot : 2 (20317 threads)
 < 20317 >
 Free slot : 5 (20318 threads)
 < 20318 >
 Free slot : 0 (20319 threads)
 Free slot : 6 (20320 threads) <- only 5 active processes
 < 20320 >
 < 20319 >
 ....
 Free slot : 0 (31041 threads)
 < 31041 >
 Free slot : 2 (31042 threads)
 Free slot : 5 (31043 threads)
 Free slot : 6 (31044 threads) <- only 4
 < 31043 >
 < 31042 >
 < 31044 >
 Free slot : 0 (31045 threads)
 < 31045 >
 Free slot : 2 (31046 threads)
 Free slot : 5 (31047 threads)
 Free slot : 6 (31048 threads)
 < 31047 >
 < 31048 >
 < 31046 >
 Free slot : 0 (31049 threads)
 < 31049 >
 Free slot : 2 (31050 threads)
 Free slot : 5 (31051 threads)
 Free slot : 6 (31052 threads)
 < 31052 >
 < 31051 >
 < 31050 >
 Free slot : 0 (31053 threads)
 < 31053 >
 Free slot : 2 (31054 threads)
 Free slot : 5 (31055 threads)
 Free slot : 6 (31056 threads)
 < 31055 >
 < 31054 >
 < 31056 >
 Free slot : 0 (31057 threads)
 < 31057 >
 Free slot : 2 (31058 threads)
 Free slot : 5 (31059 threads)
 ...
 Free slot : 2 (214116 threads)
 Free slot : 5 (214117 threads)
 < 214116 >
 < 214117 >
 Free slot : 2 (214118 threads)
 Free slot : 5 (214119 threads)
 < 214118 >
 < 214119 >
 Free slot : 2 (214120 threads)
 Free slot : 5 (214121 threads)
 < 214120 >
 < 214121 >
 Free slot : 2 (214122 threads)
 Free slot : 5 (214123 threads)
 < 214122 >
 < 214123 >
 Free slot : 2 (214124 threads) <- only 2
 
 	Some childs seem to be blocked :
 
 schwarz# ps auwx | grep semaphore | grep -v grep
 root      4544  0.0  0.0 79096   404 ttyp0  I+    9:08AM 0:00.00
 ./semaphore
 root      5678  0.0  0.0 79096   400 ttyp0  I+    8:59AM 0:00.00
 ./semaphore
 root      6754  0.0  0.0 79096   400 ttyp0  I+    9:01AM 0:00.00
 ./semaphore
 root      7623  0.0  0.0 79096  1564 ttyp0  Sl+   8:58AM 2:33.14
 ./semaphore
 root     10765  0.0  0.0 79096   392 ttyp0  I+    8:59AM 0:00.00
 ./semaphore
 root     24954  0.0  0.0 79096   396 ttyp0  I+   10:20AM 0:00.00
 ./semaphore
 root     26642  0.0  0.0 79096   396 ttyp0  I+   10:25AM 0:00.00
 ./semaphore
 schwarz#  gdb -p 5678
 GNU gdb (GDB) 7.12
 Copyright (C) 2016 Free Software Foundation, Inc.
 License GPLv3+: GNU GPL version 3 or later
 <http://gnu.org/licenses/gpl.html>
 This is free software: you are free to change and redistribute it.
 There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
 and "show warranty" for details.
 This GDB was configured as "x86_64--netbsd".
 Type "show configuration" for configuration details.
 For bug reporting instructions, please see:
 <http://www.gnu.org/software/gdb/bugs/>.
 Find the GDB manual and other documentation resources online at:
 <http://www.gnu.org/software/gdb/documentation/>.
 For help, type "help".
 Type "apropos word" to search for commands related to "word".
 Attaching to process 5678
 Reading symbols from /root/./semaphore...done.
 Reading symbols from /usr/lib/libpthread.so.1...(no debugging symbols
 found)...done.
 Reading symbols from /usr/lib/libc.so.12...(no debugging symbols
 found)...done.
 Reading symbols from /usr/libexec/ld.elf_so...(no debugging symbols
 found)...done.
 [Switching to LWP 1]
 0x00007f7e5c00ae3a in ___lwp_park60 () from /usr/libexec/ld.elf_so
 (gdb) bt
 #0  0x00007f7e5c00ae3a in ___lwp_park60 () from /usr/libexec/ld.elf_so
 #1  0x00007f7e5c001db8 in _rtld_shared_enter () from /usr/libexec/ld.elf_so
 #2  0x00007f7e5c000b17 in _rtld_bind () from /usr/libexec/ld.elf_so
 #3  0x00007f7e5c0007cd in _rtld_bind_start () from /usr/libexec/ld.elf_so
 #4  0x0000000000000246 in ?? ()
 #5  0x0000798a4243eb0a in _lwp_ctl () from /usr/lib/libc.so.12
 #6  0x0000000000400000 in ?? ()
 #7  0x00000000000000a8 in ?? ()
 #8  0x0000000000000018 in ?? ()
 #9  0x0000000000000000 in ?? ()
 (gdb)
 
 	It is possible I have misunderstood something in process and thread
 management...
 
 	Best regards,
 
 	JB
 
 --------------C8161B390C4FAED3061F6A9A
 Content-Type: text/x-csrc;
  name="semaphore.c"
 Content-Transfer-Encoding: 7bit
 Content-Disposition: attachment;
  filename="semaphore.c"
 
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <stdbool.h>
 #include <semaphore.h>
 #include <pthread.h>
 #include <string.h>
 #include <sys/wait.h>
 
 #define NUMBER_OF_THREADS	8
 
 typedef struct
 {
 	pthread_t		tid;
 	volatile bool	active;
 	long long		i;
 	sem_t			s;
 } thread_arg_t;
 
 thread_arg_t targ[NUMBER_OF_THREADS];
 
 void *
 thread(void *arg)
 {
 	char			**arguments;
 
 	int				status;
 	pid_t			pid;
 	thread_arg_t	*ta = arg;
 
 	if (sem_init(&(ta->s), 0, 0) != 0)
 	{
 		perror("sem_init()");
 		_exit(EXIT_FAILURE);
 	}
 
 	pid = fork();
 
 	if (pid < 0)
 	{
 		perror("fork()");
 		_exit(EXIT_FAILURE);
 	}
 	else if (pid == 0)
 	{
 		// Child
 
 		if ((arguments = malloc(3 * sizeof(char *))) == NULL)
 		{
 			perror("malloc()");
 			_exit(EXIT_FAILURE);
 		}
 
 		if ((arguments[0] = malloc(5 * sizeof(char *))) == NULL)
 		{
 			perror("malloc(0)");
 			_exit(EXIT_FAILURE);
 		}
 
 		if ((arguments[1] = malloc(40 * sizeof(char *))) == NULL)
 		{
 			perror("malloc(1)");
 			_exit(EXIT_FAILURE);
 		}
 
 		strcpy(arguments[0], "echo");
 		sprintf(arguments[1], "< %lld >", ta->i);
 		arguments[2] = NULL;
 
 		execvp(arguments[0], arguments);
 		perror("execvp()");
 		_exit(EXIT_FAILURE);
 	}
 
 	if (waitpid(pid, &status, 0) == -1)
 	{
 		perror("waitpid()");
 		_exit(EXIT_FAILURE);
 	}
 
 	usleep(100000);
 
 	if (sem_destroy(&(ta->s)) != 0)
 	{
 		perror("sem_destroy()");
 		_exit(EXIT_FAILURE);
 	}
 
 	ta->active = false;
 	pthread_exit(NULL);
 }
 
 int
 main()
 {
 	int			i;
 	long long	nt;
 
 	for(nt = 0;;)
 	{
 		for(i = 0; i < NUMBER_OF_THREADS; i++)
 		{
 			if (targ[i].active == false)
 			{
 				break;
 			}
 		}
 
 		if (i < NUMBER_OF_THREADS)
 		{
 			printf("Free slot : %d (%lld threads)\n", i, ++nt);
 			targ[i].active = true;
 			targ[i].i = nt;
 
 			if (pthread_create(&(targ[i].tid), NULL, thread, &(targ[i])) != 0)
 			{
 				perror("pthread_create()");
 				exit(EXIT_FAILURE);
 			}
 
 			if (pthread_detach(targ[i].tid) != 0)
 			{
 				perror("pthread_detach()");
 				exit(EXIT_FAILURE);
 			}
 		}
 		else
 		{
 			usleep(1000);
 		}
 	}
 
 	exit(EXIT_SUCCESS);
 }
 
 --------------C8161B390C4FAED3061F6A9A--
 


Home | Main Index | Thread Index | Old Index