Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 14 Mar 2017 15:50:36 +0000 (UTC)
From:      Hans Petter Selasky <hselasky@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject:   svn commit: r315260 - stable/10/sys/kern
Message-ID:  <201703141550.v2EFoada015116@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: hselasky
Date: Tue Mar 14 15:50:36 2017
New Revision: 315260
URL: https://svnweb.freebsd.org/changeset/base/315260

Log:
  MFC r313941:
  
  Make sure the thread constructor and destructor eventhandlers are
  called for all threads belonging to a procedure. Currently the first
  thread in a procedure is kept around as an optimisation step and is
  never freed. Because the first thread in a procedure is never freed
  nor allocated, its destructor and constructor callbacks are never
  called which means per thread structures allocated by dtrace and the
  Linux emulation layers for example, might be present for threads which
  don't need these structures.
  
  This patch adds a thread construction and destruction call for the
  first thread in a procedure.
  
  Tested:			dtrace, linux emulation
  Reviewed by:		kib @
  Sponsored by:		Mellanox Technologies

Modified:
  stable/10/sys/kern/kern_proc.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/kern/kern_proc.c
==============================================================================
--- stable/10/sys/kern/kern_proc.c	Tue Mar 14 15:49:28 2017	(r315259)
+++ stable/10/sys/kern/kern_proc.c	Tue Mar 14 15:50:36 2017	(r315260)
@@ -191,11 +191,17 @@ static int
 proc_ctor(void *mem, int size, void *arg, int flags)
 {
 	struct proc *p;
+	struct thread *td;
 
 	p = (struct proc *)mem;
 	SDT_PROBE4(proc, , ctor , entry, p, size, arg, flags);
 	EVENTHANDLER_INVOKE(process_ctor, p);
 	SDT_PROBE4(proc, , ctor , return, p, size, arg, flags);
+	td = FIRST_THREAD_IN_PROC(p);
+	if (td != NULL) {
+		/* Make sure all thread constructors are executed */
+		EVENTHANDLER_INVOKE(thread_ctor, td);
+	}
 	return (0);
 }
 
@@ -220,6 +226,9 @@ proc_dtor(void *mem, int size, void *arg
 #endif
 		/* Free all OSD associated to this thread. */
 		osd_thread_exit(td);
+
+		/* Make sure all thread destructors are executed */
+		EVENTHANDLER_INVOKE(thread_dtor, td);
 	}
 	EVENTHANDLER_INVOKE(process_dtor, p);
 	if (p->p_ksi != NULL)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201703141550.v2EFoada015116>