public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Frank Mayhar <fmayhar@google.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: bugme-daemon@bugzilla.kernel.org, linux-kernel@vger.kernel.org,
	Ingo Molnar <mingo@elte.hu>, Thomas Gleixner <tglx@linutronix.de>,
	Roland McGrath <roland@redhat.com>,
	Jakub Jelinek <jakub@redhat.com>
Subject: Re: [Bugme-new] [Bug 9906] New: Weird hang with NPTL and SIGPROF.
Date: Wed, 06 Feb 2008 16:58:13 -0800	[thread overview]
Message-ID: <1202345893.8525.33.camel@peace.smo.corp.google.com> (raw)
In-Reply-To: <20080206165045.89b809cc.akpm@linux-foundation.org>

[-- Attachment #1: Type: text/plain, Size: 395 bytes --]

On Wed, 2008-02-06 at 16:50 -0800, Andrew Morton wrote:
> It's probably better to handle this one via email, so please send that
> testcase vie reply-to-all to this email, thanks.

Testcase attached.

Build with
        gcc -D_GNU_SOURCE -c hangc-2.c -o hangc-2.o
        gcc -lpthread -o hangc-2 hangc-2.o

Run with
        hangc-2 4500 4500

-- 
Frank Mayhar <fmayhar@google.com>
Google, Inc.

[-- Attachment #2: hangc-2.c --]
[-- Type: text/x-csrc, Size: 2664 bytes --]


#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/time.h>
#include <unistd.h>
#include <ucontext.h>
#include <string.h>
#include <errno.h>

static void *
LinuxThreadTestRoutine(
	void *pid)
{
	pid_t *pid_ptr = (pid_t *) (pid);

	*pid_ptr = getpid();
	return NULL;
}

int
id_runningNPTL(void)
{
	int cc;
	pthread_t thread;
	pid_t child_pid;

	cc = pthread_create(&thread, NULL, &LinuxThreadTestRoutine, &child_pid);
	if (cc != 0) {
		perror("pthread_create");
		exit(1);
	}
	cc = pthread_join(thread, NULL);
	if (cc != 0) {
		perror("pthread_join");
		exit(1);
	}
	int is_linux_threads = (child_pid != getpid());

	return !is_linux_threads;
}



char const *
id_threads_package_string(void)
{
	return id_runningNPTL()? "NPTL" : "LinuxThreads";
}


typedef struct shared_args_t {
	unsigned n;
	pthread_barrier_t barrier;
} shared_args_t;

shared_args_t g_args;

void prof_handler(int sig, siginfo_t *foo, void *signal_ucontext)
{
	static int stk = 0;
	int saved_errno = errno;

	stk = 0;
	errno = saved_errno;
}

void *
nop1_inner(
	void *varg)
{
	int cc;
	cc = pthread_barrier_wait(&g_args.barrier);
	if ((cc != 0) && (cc != PTHREAD_BARRIER_SERIAL_THREAD)) {
		perror("pthread_barrier_wait");
		exit(1);
	}
	return NULL;
}

#define MAXTHREADS  (1024 * 1024)
pthread_t threads[MAXTHREADS];

int
main(
	int argc,
	char **argv)
{
	pthread_attr_t attr;
	unsigned nthreads;
	unsigned nops;
	unsigned i;
	int cc;
	struct sigaction sa;
	struct itimerval timer;

	sa.sa_sigaction = prof_handler;
	sa.sa_flags = SA_RESTART | SA_SIGINFO;
	sigemptyset(&sa.sa_mask);
	sigaction(SIGPROF, &sa, NULL);

	timer.it_interval.tv_sec = 0;
	timer.it_interval.tv_usec = 1000000 / 100;
	timer.it_value = timer.it_interval;
	setitimer(ITIMER_PROF, &timer, 0);
	cc = pthread_attr_init(&attr);
	if (cc != 0) {
		perror("pthread_attr_init");
		exit(1);
	}
	cc = pthread_attr_setstacksize(&attr, 16 * 1024);
	if (cc != 0) {
		perror("pthread_attr_setstacksize");
		exit(1);
	}
	if (argc != 3) {
		fputs("Usage: hangc THREADS BARRIER-OPS-PER-THREAD\n", stderr);
		exit(1);
	}

	nthreads = strtoul(argv[1], NULL, 0);
	if (nthreads > MAXTHREADS) {
		perror("internal error: static allocation too small for THREADS arg");
		exit(1);
	}
	nops = strtoul(argv[2], NULL, 0);

	cc = pthread_barrier_init(&g_args.barrier, NULL, nthreads + 1);
	if (cc != 0) {
		perror("pthread_barrier_init");
		exit(1);
	}

	g_args.n = nops;

	for (i = 0; i < nthreads; ++i) {
		cc = pthread_create(&threads[i], &attr, nop1_inner, NULL);
		if (cc != 0) {
			perror("pthread_create");
			exit(1);
		}
	}

	printf("threads: %s\n", id_threads_package_string());
	exit(0);
}

  reply	other threads:[~2008-02-07  1:01 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <bug-9906-10286@http.bugzilla.kernel.org/>
2008-02-07  0:50 ` [Bugme-new] [Bug 9906] New: Weird hang with NPTL and SIGPROF Andrew Morton
2008-02-07  0:58   ` Frank Mayhar [this message]
2008-02-07  2:57     ` Parag Warudkar
2008-02-07 15:22       ` Alejandro Riveira Fernández
2008-02-07 15:53         ` Parag Warudkar
2008-02-07 15:56           ` Parag Warudkar
2008-02-07 15:54             ` Alejandro Riveira Fernández
2008-02-07 16:01               ` Parag Warudkar
2008-02-07 16:53                 ` Parag Warudkar
2008-02-29 19:55                   ` Frank Mayhar
2008-03-04  7:00                     ` Roland McGrath
2008-03-04 19:52                       ` Frank Mayhar
2008-03-05  4:08                         ` Roland McGrath
2008-03-06 19:04                           ` Frank Mayhar
2008-03-11  7:50                             ` posix-cpu-timers revamp Roland McGrath
2008-03-11 21:05                               ` Frank Mayhar
2008-03-11 21:35                                 ` Roland McGrath
2008-03-14  0:37                                   ` Frank Mayhar
2008-03-21  7:18                                     ` Roland McGrath
2008-03-21 17:57                                       ` Frank Mayhar
2008-03-22 21:58                                         ` Roland McGrath
2008-03-24 17:34                                           ` Frank Mayhar
2008-03-24 22:43                                             ` Frank Mayhar
2008-03-31  5:44                                             ` Roland McGrath
2008-03-31 20:24                                               ` Frank Mayhar
2008-04-02  2:07                                                 ` Roland McGrath
2008-04-02 16:34                                                   ` Frank Mayhar
2008-04-02 17:42                                                   ` Frank Mayhar
2008-04-02 19:48                                                     ` Roland McGrath
2008-04-02 20:34                                                       ` Frank Mayhar
2008-04-02 21:42                                                         ` Frank Mayhar
2008-04-04  0:53                                                           ` Frank Mayhar
2008-04-04 23:17                                                         ` Roland McGrath
2008-04-06  5:26                                                           ` Frank Mayhar
2008-04-07 20:08                                                             ` Roland McGrath
2008-04-07 21:31                                                               ` Frank Mayhar
2008-04-07 22:02                                                                 ` Roland McGrath
2008-04-08 21:27                                                               ` Frank Mayhar
2008-04-08 21:52                                                                 ` Frank Mayhar
2008-04-08 22:49                                                                 ` Roland McGrath
2008-04-09 16:29                                                                   ` Frank Mayhar
2008-04-02 18:42                                                   ` Frank Mayhar
2008-03-28  0:52                                           ` [PATCH 2.6.25-rc6] Fix itimer/many thread hang Frank Mayhar
2008-03-28 10:28                                             ` Ingo Molnar
2008-03-28 22:46                                             ` [PATCH 2.6.25-rc7 resubmit] " Frank Mayhar
2008-04-01 18:45                                               ` Andrew Morton
2008-04-01 21:46                                                 ` Frank Mayhar
2008-03-21 20:40                                       ` posix-cpu-timers revamp Frank Mayhar
2008-03-07 23:26                           ` [Bugme-new] [Bug 9906] New: Weird hang with NPTL and SIGPROF Frank Mayhar
2008-03-08  0:01                             ` Frank Mayhar
2008-02-07 17:36           ` Frank Mayhar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1202345893.8525.33.camel@peace.smo.corp.google.com \
    --to=fmayhar@google.com \
    --cc=akpm@linux-foundation.org \
    --cc=bugme-daemon@bugzilla.kernel.org \
    --cc=jakub@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=roland@redhat.com \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox