diff options
| author | cl <cl@NetBSD.org> | 2004-03-14 01:19:41 +0000 |
|---|---|---|
| committer | cl <cl@NetBSD.org> | 2004-03-14 01:19:41 +0000 |
| commit | f2f106648cb994804efdc8a9f457a642815d8272 (patch) | |
| tree | 10126518767faefa83c91ddc96be71ebe9be015c /lib/libpthread/pthread_debug.c | |
| parent | ea5ec0212d715373eb56dbdeb218b9504e1139f2 (diff) | |
add libpthread part of concurrency support for SA on MP systems
- enable concurrency according to environment variable PTHREAD_CONCURRENCY
- add idle VP wakeup if there are additional jobs and idle VPs
- make reidlequeue per VP
- enable spinning for locks
- fix race condition in alarm processing
- fix race condition in mutex locking
- make debugging output line buffered and add VP prefix to debug lines
Diffstat (limited to 'lib/libpthread/pthread_debug.c')
| -rw-r--r-- | lib/libpthread/pthread_debug.c | 76 |
1 files changed, 62 insertions, 14 deletions
diff --git a/lib/libpthread/pthread_debug.c b/lib/libpthread/pthread_debug.c index a17dff32bc4..e01a9d7e9f2 100644 --- a/lib/libpthread/pthread_debug.c +++ b/lib/libpthread/pthread_debug.c @@ -1,4 +1,4 @@ -/* $NetBSD: pthread_debug.c,v 1.7 2004/01/02 14:13:16 cl Exp $ */ +/* $NetBSD: pthread_debug.c,v 1.8 2004/03/14 01:19:41 cl Exp $ */ /*- * Copyright (c) 2001 The NetBSD Foundation, Inc. @@ -37,7 +37,7 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: pthread_debug.c,v 1.7 2004/01/02 14:13:16 cl Exp $"); +__RCSID("$NetBSD: pthread_debug.c,v 1.8 2004/03/14 01:19:41 cl Exp $"); #include <err.h> #include <errno.h> @@ -59,15 +59,23 @@ int pthread__dbg; #ifdef PTHREAD__DEBUG int pthread__debug_counters[PTHREADD_NCOUNTERS]; -int pthread__debug_newline; -static struct pthread_msgbuf* debugbuf; +static struct pthread_msgbuf *debugbuf; +#define MAXLINELEN 1000 +struct linebuf { + char buf[MAXLINELEN]; + int len; +}; +static struct linebuf *linebuf; static void pthread__debug_printcounters(void); static const char *pthread__counternames[] = PTHREADD_INITCOUNTERNAMES; -void pthread__debug_init(void) +extern int pthread__maxconcurrency, pthread__started; + +void pthread__debug_init(int ncpu) { time_t t; + int i; if (getenv("PTHREAD_DEBUGCOUNTERS") != NULL) atexit(pthread__debug_printcounters); @@ -75,10 +83,15 @@ void pthread__debug_init(void) if (getenv("PTHREAD_DEBUGLOG") != NULL) { t = time(NULL); debugbuf = pthread__debuglog_init(0); + linebuf = (struct linebuf *) + malloc(ncpu * sizeof(struct linebuf)); + if (linebuf == NULL) + err(1, "Couldn't allocate linebuf"); + for (i = 0; i < ncpu; i++) + linebuf[i].len = 0; + DPRINTF(("Started debugging %s (pid %d) at %s\n", getprogname(), getpid(), ctime(&t))); - - pthread__debug_newline = 1; } } @@ -139,25 +152,44 @@ pthread__debuglog_init(int force) void pthread__debuglog_printf(const char *fmt, ...) { - char tmpbuf[200+6]; + char *tmpbuf; size_t len, cplen, r, w, s; long diff1, diff2; + int vpid; va_list ap; if (debugbuf == NULL) return; + if (pthread__maxconcurrency > 1) { + vpid = pthread_self()->pt_vpid; + } else + vpid = 0; + + tmpbuf = linebuf[vpid].buf; + len = linebuf[vpid].len; + +#if defined(PTHREAD_PID_DEBUG) || defined(PTHREAD_VP_DEBUG) + if (len == 0) { #ifdef PTHREAD_PID_DEBUG - if (pthread__debug_newline == 1) - len = sprintf(tmpbuf, "%05d ", getpid()); - else + len += sprintf(tmpbuf, "[%05d]", getpid()); +#endif +#ifdef PTHREAD_VP_DEBUG + if (pthread__maxconcurrency > 1) + len += sprintf(tmpbuf + len, "[%d]", vpid); +#endif + } #endif - len = 0; + va_start(ap, fmt); - len += vsnprintf(tmpbuf, 200, fmt, ap); + len += vsnprintf(tmpbuf + len, (unsigned int)(MAXLINELEN - len), + fmt, ap); va_end(ap); - pthread__debug_newline = (tmpbuf[len - 1] == '\n') ? 1 : 0; + linebuf[vpid].len = len; + + if (tmpbuf[len - 1] != '\n') + return; r = debugbuf->msg_bufr; w = debugbuf->msg_bufw; @@ -190,6 +222,22 @@ pthread__debuglog_printf(const char *fmt, ...) debugbuf->msg_bufr = (w + 1) % s; } + linebuf[vpid].len = 0; +} + +int +pthread__debuglog_newline(void) +{ + int vpid; + + if (debugbuf == NULL) + return 1; + if (pthread__maxconcurrency > 1) + vpid = pthread_self()->pt_vpid; + else + vpid = 0; + + return (linebuf[vpid].len == 0); } #endif |
