Bug 128922 - threads hang with xorg running
Summary: threads hang with xorg running
Status: Open
Alias: None
Product: Base System
Classification: Unclassified
Component: threads (show other bugs)
Version: Unspecified
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-threads (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-11-16 19:20 UTC by Peter
Modified: 2018-01-03 05:16 UTC (History)
0 users

See Also:


Attachments
file.txt (803 bytes, text/plain)
2008-11-16 19:20 UTC, Peter
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Peter 2008-11-16 19:20:01 UTC
 The following program runs perfectly on FreeBSD 6.3 amd64 (with xorg running
and without xorg running).

 But on FreeBSD 7.0 amd64 and 7.1 beta amd64 (only with xorg running) 
after a few seconds of working the thread "period_thread" hangs printing 
only one time a second and even less. Moreover, the whole system becomes slow 
though "top" does not show a heavy load.
 Tried on Intel E6600 and on Intel E1200 with the same result.
 Tried with GENERIC kernel "out of the box" and with my kernel configurations with the same result.
 Tried with 4BSD and ULE schedulers with the same result.


#include <stdlib.h>
#include <stdio.h>

#include <pthread.h>
#include <unistd.h>


void* thread(void* q)
{
	const size_t SIZE = 500;
	volatile double vec[SIZE];
	
	size_t cnt;
	for(cnt = 0; cnt < 1000000; ++cnt)
	{
		size_t i;
		for(i = 0; i < SIZE; ++i)
		{
			vec[i] = 0;
		}
		for(i = 0; i < SIZE; ++i)
		{
			vec[i] += i;
			vec[i] -= i;
		}
	}

}

void* period_thread(void* q)
{
	int i;
	for(i = 0;;++i)
	{
		printf("period thread %i\n", i);
		usleep( 50 * 1000 );
	}
}

int main( int argc, char** argv )
{

	pthread_t hs;
	pthread_create(&hs, NULL, period_thread, NULL);

	for(;;)
	{
		const size_t SIZE = 5;
		pthread_t h[SIZE];
	
		size_t i;
		for(i = 0; i < SIZE; ++i)
		{
			pthread_create( &h[i], NULL, thread, NULL);
		}

		for(i = 0; i < SIZE; ++i)
		{
			pthread_join(h[i], NULL);
		}
	}
}

Fix: Patch attached with submission follows:
How-To-Repeat: Run the program on FreeBSD 7.0 amd64 or 7.1 beta amd64 in xterm, konsole, etc 
(xorg running).
Comment 1 Peter 2008-11-18 11:02:17 UTC
Some additional information:

The example works fine on FreeBSD 6.3:
   when linked with libpthread (-lpthread)
  or
   when linked with libthr  (-lthr)

The example works fine on FreeBSD 7.0 and 7.1:
    when linked with libkse  (-lkse)

The example does not work and threads hang as I described earlier:
    when linked with lthr (-lthr or -lpthread that is the same on FreeBSD
7).

Therefore it seems to me that there is some problem in the new version
of the library "libthr" included in FreeBSD 7.0 and 7.1.
Comment 2 Peter 2008-12-10 18:20:24 UTC
Some additional information

FreeBSD 7.1 RC-1 amd64   and    FreeBSD 7.1 RC-1 i386:
The problem exists in both systems if the program links with pthread;
no problem exists if the program links with kse.
Comment 3 David Xu freebsd_committer 2009-09-25 01:31:10 UTC
Try to set scheduler's preemption threshold to large priority value,
the default one is too low for cpu-bound application, and can starve
other threads under heavy cpu load. for example:
sysctl kern.sched.preempt_thresh=220

On 7.x and 8.0 kernel, I always set a large value for my Desktop PC.

Regards,
David Xu
Comment 4 Eitan Adler freebsd_committer freebsd_triage 2017-12-31 07:59:51 UTC
For bugs matching the following criteria:

Status: In Progress Changed: (is less than) 2014-06-01

Reset to default assignee and clear in-progress tags.

Mail being skipped