PERFORCE change 129919 for review
Peter Wemm
peter at FreeBSD.org
Sat Dec 1 15:59:31 PST 2007
http://perforce.freebsd.org/chv.cgi?CH=129919
Change 129919 by peter at peter_daintree on 2007/12/01 23:58:58
I'd like to change thread_stash() calls to thread_free(), but I'm not
yet certain if the context allows that.
Affected files ...
.. //depot/projects/bike_sched/sys/kern/kern_thread.c#8 edit
Differences ...
==== //depot/projects/bike_sched/sys/kern/kern_thread.c#8 (text+ko) ====
@@ -66,10 +66,19 @@
SYSCTL_INT(_kern_threads, OID_AUTO, max_threads_hits, CTLFLAG_RD,
&max_threads_hits, 0, "");
+/*
+ * I'm unsure if this is safe to remove. thread_free might not be able
+ * to be called from the contexts that thread_stash is.
+ */
+#define ZOMBIES 1
+#ifdef ZOMBIES
TAILQ_HEAD(, thread) zombie_threads = TAILQ_HEAD_INITIALIZER(zombie_threads);
static struct mtx zombie_lock;
MTX_SYSINIT(zombie_lock, &zombie_lock, "zombie lock", MTX_SPIN);
+static void thread_zombie(struct thread *);
+#endif
+
struct mtx tid_lock;
static struct unrhdr *tid_unrhdr;
@@ -220,7 +229,36 @@
16 - 1, 0);
}
+#ifdef ZOMBIES
/*
+ * Place an unused thread on the zombie list.
+ * Use the slpq as that must be unused by now.
+ */
+void
+thread_zombie(struct thread *td)
+{
+ mtx_lock_spin(&zombie_lock);
+ TAILQ_INSERT_HEAD(&zombie_threads, td, td_slpq);
+ mtx_unlock_spin(&zombie_lock);
+}
+#endif
+
+/*
+ * Release a thread that has exited after cpu_throw().
+ */
+void
+thread_stash(struct thread *td)
+{
+ atomic_subtract_rel_int(&td->td_proc->p_exitthreads, 1);
+#ifdef ZOMBIES
+ thread_zombie(td);
+#else
+ thread_free(td); /* unsafe here? */
+#endif
+}
+
+#ifdef ZOMBIES
+/*
* Reap zombie kse resource.
*/
void
@@ -247,6 +285,7 @@
}
}
}
+#endif
/*
* Allocate a thread.
@@ -256,7 +295,9 @@
{
struct thread *td;
+#ifdef ZOMBIES
thread_reap(); /* check if any zombies to get */
+#endif
td = (struct thread *)uma_zalloc(thread_zone, M_WAITOK);
KASSERT(td->td_kstack == 0, ("thread_alloc got thread with kstack"));
@@ -423,7 +464,9 @@
sched_relinquish(curthread);
cpu_thread_clean(td);
crfree(td->td_ucred);
+#ifdef ZOMBIES
thread_reap(); /* check for zombie threads etc. */
+#endif
}
/*
More information about the p4-projects
mailing list