Re: Debugging FreeBSD user threads with gdb
On Fri, 7 May 1999, Matthew Dillon wrote: > :> :--- uthread_create.c 1999/03/23 05:07:55 1.12 > :> :+++ uthread_create.c 1999/05/06 15:27:33 > :> :@@ -42,6 +42,8 @@ > :> : #include "pthread_private.h" > :> : #include "libc_private.h" > :> : > :> :+static int next_tid = 1; > :> :+ > :> : int > :> : pthread_create(pthread_t * thread, const pthread_attr_t * attr, > :> : void *(*start_routine) (void *), void *arg) > :> :@@ -87,6 +89,7 @@ > :> : } else { > :> : /* Initialise the thread structure: */ > :> : memset(new_thread, 0, sizeof(struct pthread)); > :> :+ new_thread->tid = next_tid++; > :> : > :> :Doug Rabson Mail: d...@nlsystems.com > :> :Nonlinear Systems Ltd.Phone: +44 181 442 9037 > :> > :> Hmmm. tid is only an int and some programs which create and destroy > :> threads a lot are almost certainly going to overflow it. 4 billion > :> is not hard to reach. This can result in duplicate tid's. > : > :Didn't think of that. It gets a bit ugly inside gdb since gdb needs a > :single int to encode the pid and thread id. I'm currently allowing 20 > :bits for the pid and 11 for the tid. Any ideas? > : > :-- > :Doug Rabson Mail: d...@nlsystems.com > :Nonlinear Systems Ltd. Phone: +44 181 442 9037 > > Hmmm. 11 bits is only 2048 threads. You are going to have problems > no matter what. > > You could have a pool of tid structures. A simple freelist. Pseudo > code below. This would fix the unique-tid problem but it would not fix > the 2048 thread limit with gdb. I can probably increase the field size of the tid up to about 14 bits (we only have pids going up to 10 I think). I would rather not do this amount of work inside uthread; perhaps it would be better to make the uthread store a 64bit unique number and then compress it down to a 14 bit tid inside gdb by keeping a hash table or something similar. Its going to be pretty hard to debug a program with 16k active threads so I think this limit should be ok. -- Doug Rabson Mail: d...@nlsystems.com Nonlinear Systems Ltd. Phone: +44 181 442 9037 To Unsubscribe: send mail to majord...@freebsd.org with "unsubscribe freebsd-current" in the body of the message
Re: Debugging FreeBSD user threads with gdb
:> :--- uthread_create.c1999/03/23 05:07:55 1.12 :> :+++ uthread_create.c1999/05/06 15:27:33 :> :@@ -42,6 +42,8 @@ :> : #include "pthread_private.h" :> : #include "libc_private.h" :> : :> :+static int next_tid = 1; :> :+ :> : int :> : pthread_create(pthread_t * thread, const pthread_attr_t * attr, :> : void *(*start_routine) (void *), void *arg) :> :@@ -87,6 +89,7 @@ :> :} else { :> :/* Initialise the thread structure: */ :> :memset(new_thread, 0, sizeof(struct pthread)); :> :+ new_thread->tid = next_tid++; :> : :> :Doug Rabson Mail: d...@nlsystems.com :> :Nonlinear Systems Ltd. Phone: +44 181 442 9037 :> :> Hmmm. tid is only an int and some programs which create and destroy :> threads a lot are almost certainly going to overflow it. 4 billion :> is not hard to reach. This can result in duplicate tid's. : :Didn't think of that. It gets a bit ugly inside gdb since gdb needs a :single int to encode the pid and thread id. I'm currently allowing 20 :bits for the pid and 11 for the tid. Any ideas? : :-- :Doug RabsonMail: d...@nlsystems.com :Nonlinear Systems Ltd. Phone: +44 181 442 9037 Hmmm. 11 bits is only 2048 threads. You are going to have problems no matter what. You could have a pool of tid structures. A simple freelist. Pseudo code below. This would fix the unique-tid problem but it would not fix the 2048 thread limit with gdb. #define TIDINCR 32 struct tid { struct tid *t_next; int t_tid; }; int maxtid = 1; struct tid *tidpool; struct tid * alloctid(void) { struct tid *tid; while ((tid = tidpool) == NULL) { int i; tidpool = malloc(sizeof(struct tid) * TIDINCR); if (tidpool == NULL) { ... memory allocation failed ... } for (i = 0; i < TIDINCR; ++i) { tidpool[i].t_tid = maxtid + i; tidpool[i].t_next = &tidpool[i+1]; } tidpool[i-1].t_next = NULL; maxtid += TIDINCR; } tidpool = tid->t_next; return(tid); } freetid(struct tid *tid) { tid->t_next = tidpool; tidpool = tid; } -Matt Matthew Dillon To Unsubscribe: send mail to majord...@freebsd.org with "unsubscribe freebsd-current" in the body of the message
Re: Debugging FreeBSD user threads with gdb
On Fri, 7 May 1999, Matthew Dillon wrote: > :--- uthread_create.c 1999/03/23 05:07:55 1.12 > :+++ uthread_create.c 1999/05/06 15:27:33 > :@@ -42,6 +42,8 @@ > : #include "pthread_private.h" > : #include "libc_private.h" > : > :+static int next_tid = 1; > :+ > : int > : pthread_create(pthread_t * thread, const pthread_attr_t * attr, > :void *(*start_routine) (void *), void *arg) > :@@ -87,6 +89,7 @@ > : } else { > : /* Initialise the thread structure: */ > : memset(new_thread, 0, sizeof(struct pthread)); > :+new_thread->tid = next_tid++; > : > :Doug Rabson Mail: d...@nlsystems.com > :Nonlinear Systems Ltd. Phone: +44 181 442 9037 > > Hmmm. tid is only an int and some programs which create and destroy > threads a lot are almost certainly going to overflow it. 4 billion > is not hard to reach. This can result in duplicate tid's. Didn't think of that. It gets a bit ugly inside gdb since gdb needs a single int to encode the pid and thread id. I'm currently allowing 20 bits for the pid and 11 for the tid. Any ideas? -- Doug Rabson Mail: d...@nlsystems.com Nonlinear Systems Ltd. Phone: +44 181 442 9037 To Unsubscribe: send mail to majord...@freebsd.org with "unsubscribe freebsd-current" in the body of the message
Re: Debugging FreeBSD user threads with gdb
Matthew Dillon once wrote: > Hmmm. tid is only an int and some programs which create and destroy > threads a lot are almost certainly going to overflow it. 4 billion > is not hard to reach. This can result in duplicate tid's. Unsigned will double that. Not enough either? -mi To Unsubscribe: send mail to majord...@freebsd.org with "unsubscribe freebsd-current" in the body of the message
Re: Debugging FreeBSD user threads with gdb
:--- uthread_create.c 1999/03/23 05:07:55 1.12 :+++ uthread_create.c 1999/05/06 15:27:33 :@@ -42,6 +42,8 @@ : #include "pthread_private.h" : #include "libc_private.h" : :+static int next_tid = 1; :+ : int : pthread_create(pthread_t * thread, const pthread_attr_t * attr, : void *(*start_routine) (void *), void *arg) :@@ -87,6 +89,7 @@ : } else { : /* Initialise the thread structure: */ : memset(new_thread, 0, sizeof(struct pthread)); :+ new_thread->tid = next_tid++; : :Doug RabsonMail: d...@nlsystems.com :Nonlinear Systems Ltd. Phone: +44 181 442 9037 Hmmm. tid is only an int and some programs which create and destroy threads a lot are almost certainly going to overflow it. 4 billion is not hard to reach. This can result in duplicate tid's. -Matt Matthew Dillon To Unsubscribe: send mail to majord...@freebsd.org with "unsubscribe freebsd-current" in the body of the message