From owner-p4-projects@FreeBSD.ORG Sun Jul 14 20:20:33 2013 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id A85CE382; Sun, 14 Jul 2013 20:20:33 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 6D647380 for ; Sun, 14 Jul 2013 20:20:33 +0000 (UTC) (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: from skunkworks.freebsd.org (skunkworks.freebsd.org [8.8.178.74]) by mx1.freebsd.org (Postfix) with ESMTP id 4EE68253 for ; Sun, 14 Jul 2013 20:20:33 +0000 (UTC) Received: from skunkworks.freebsd.org ([127.0.1.74]) by skunkworks.freebsd.org (8.14.7/8.14.7) with ESMTP id r6EKKXvi070530 for ; Sun, 14 Jul 2013 20:20:33 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: (from perforce@localhost) by skunkworks.freebsd.org (8.14.7/8.14.6/Submit) id r6EKKXE0070527 for perforce@freebsd.org; Sun, 14 Jul 2013 20:20:33 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Date: Sun, 14 Jul 2013 20:20:33 GMT Message-Id: <201307142020.r6EKKXE0070527@skunkworks.freebsd.org> X-Authentication-Warning: skunkworks.freebsd.org: perforce set sender to bb+lists.freebsd.perforce@cyrus.watson.org using -f From: Robert Watson Subject: PERFORCE change 231154 for review To: Perforce Change Reviews Precedence: bulk X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.14 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 14 Jul 2013 20:20:33 -0000 http://p4web.freebsd.org/@@231154?ac=10 Change 231154 by rwatson@rwatson_cinnamon on 2013/07/14 20:20:23 It turns out not to be the case that all struct thread's go through UMA between the last thread exiting and a new one reusing the structure -- a previously used thread may be cached with a process when the process is returned to UMA, reducing process allocation overhead but leaving the thread ctor/dtor uninvoked. To handle this, also have TESLA per-thread storage hook the process constructor and properly reset TESLA state there. Thanks to John Baldwin for help with debugging this issue. Affected files ... .. //depot/projects/ctsrd/tesla/src/sys/contrib/tesla/libtesla/tesla_class_perthread.c#7 edit Differences ... ==== //depot/projects/ctsrd/tesla/src/sys/contrib/tesla/libtesla/tesla_class_perthread.c#7 (text+ko) ==== @@ -36,7 +36,7 @@ /* * Routines for managing TESLA per-thread state, used in per-thread automata. * Kernel and userspace implementations differ quite a lot, due to very - * different guarantees for kernel per-thread storage and pthread + * different guarantees for kernel per-thread storage and perthread * thread-specific state. For example, the kernel implementation guarantees * that space will be available if the initial tesla_class allocation * succeedes, and instruments thread create and destroy to ensure this is the @@ -51,11 +51,22 @@ /* * Registration state for per-thread storage. */ -static eventhandler_tag tesla_perthread_ctor_tag; -static eventhandler_tag tesla_perthread_dtor_tag; +static eventhandler_tag tesla_perthread_thread_ctor_tag; +static eventhandler_tag tesla_perthread_thread_dtor_tag; +static eventhandler_tag tesla_perthread_process_dtor_tag; + +static void +tesla_perthread_process_dtor(__unused void *arg, struct proc *p) +{ + struct thread *td; + + td = FIRST_THREAD_IN_PROC(p); + if (td != NULL && td->td_tesla != NULL) + tesla_store_reset(td->td_tesla); +} static void -tesla_perthread_ctor(__unused void *arg, struct thread *td) +tesla_perthread_thread_ctor(__unused void *arg, struct thread *td) { struct tesla_store *store; uint32_t error; @@ -68,7 +79,7 @@ } static void -tesla_perthread_dtor(__unused void *arg, struct thread *td) +tesla_perthread_thread_dtor(__unused void *arg, struct thread *td) { struct tesla_store *store; @@ -81,10 +92,12 @@ tesla_perthread_sysinit(__unused void *arg) { - tesla_perthread_ctor_tag = EVENTHANDLER_REGISTER(thread_ctor, - tesla_perthread_ctor, NULL, EVENTHANDLER_PRI_ANY); - tesla_perthread_dtor_tag = EVENTHANDLER_REGISTER(thread_dtor, - tesla_perthread_dtor, NULL, EVENTHANDLER_PRI_ANY); + tesla_perthread_process_dtor_tag = EVENTHANDLER_REGISTER(process_dtor, + tesla_perthread_process_dtor, NULL, EVENTHANDLER_PRI_ANY); + tesla_perthread_thread_ctor_tag = EVENTHANDLER_REGISTER(thread_ctor, + tesla_perthread_thread_ctor, NULL, EVENTHANDLER_PRI_ANY); + tesla_perthread_thread_dtor_tag = EVENTHANDLER_REGISTER(thread_dtor, + tesla_perthread_thread_dtor, NULL, EVENTHANDLER_PRI_ANY); } SYSINIT(tesla_perthread, SI_SUB_TESLA, SI_ORDER_FIRST, tesla_perthread_sysinit, NULL);