From owner-svn-src-stable-10@FreeBSD.ORG Sat Oct 11 17:49:53 2014 Return-Path: Delivered-To: svn-src-stable-10@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 7481912B; Sat, 11 Oct 2014 17:49:53 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 6020822B; Sat, 11 Oct 2014 17:49:53 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id s9BHnrqO091905; Sat, 11 Oct 2014 17:49:53 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id s9BHnqag091898; Sat, 11 Oct 2014 17:49:52 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201410111749.s9BHnqag091898@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Sat, 11 Oct 2014 17:49:52 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r272946 - in stable/10/sys: conf kern sys vm X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 11 Oct 2014 17:49:53 -0000 Author: kib Date: Sat Oct 11 17:49:51 2014 New Revision: 272946 URL: https://svnweb.freebsd.org/changeset/base/272946 Log: MFC r272536: Add kernel option KSTACK_USAGE_PROF. Modified: stable/10/sys/conf/NOTES stable/10/sys/conf/options stable/10/sys/kern/kern_intr.c stable/10/sys/sys/systm.h stable/10/sys/vm/vm_glue.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/conf/NOTES ============================================================================== --- stable/10/sys/conf/NOTES Sat Oct 11 17:16:18 2014 (r272945) +++ stable/10/sys/conf/NOTES Sat Oct 11 17:49:51 2014 (r272946) @@ -2950,6 +2950,7 @@ options SC_RENDER_DEBUG # syscons rende options VFS_BIO_DEBUG # VFS buffer I/O debugging options KSTACK_MAX_PAGES=32 # Maximum pages to give the kernel stack +options KSTACK_USAGE_PROF # Adaptec Array Controller driver options options AAC_DEBUG # Debugging levels: Modified: stable/10/sys/conf/options ============================================================================== --- stable/10/sys/conf/options Sat Oct 11 17:16:18 2014 (r272945) +++ stable/10/sys/conf/options Sat Oct 11 17:49:51 2014 (r272946) @@ -132,6 +132,7 @@ GEOM_ZERO opt_geom.h KDTRACE_HOOKS opt_kdtrace.h KSTACK_MAX_PAGES KSTACK_PAGES +KSTACK_USAGE_PROF KTRACE KTRACE_REQUEST_POOL opt_ktrace.h LIBICONV Modified: stable/10/sys/kern/kern_intr.c ============================================================================== --- stable/10/sys/kern/kern_intr.c Sat Oct 11 17:16:18 2014 (r272945) +++ stable/10/sys/kern/kern_intr.c Sat Oct 11 17:49:51 2014 (r272946) @@ -28,6 +28,7 @@ __FBSDID("$FreeBSD$"); #include "opt_ddb.h" +#include "opt_kstack_usage_prof.h" #include #include @@ -1407,6 +1408,10 @@ intr_event_handle(struct intr_event *ie, td = curthread; +#ifdef KSTACK_USAGE_PROF + intr_prof_stack_use(td, frame); +#endif + /* An interrupt with no event or handlers is a stray interrupt. */ if (ie == NULL || TAILQ_EMPTY(&ie->ie_handlers)) return (EINVAL); Modified: stable/10/sys/sys/systm.h ============================================================================== --- stable/10/sys/sys/systm.h Sat Oct 11 17:16:18 2014 (r272945) +++ stable/10/sys/sys/systm.h Sat Oct 11 17:49:51 2014 (r272946) @@ -443,4 +443,6 @@ bitcount16(uint32_t x) return (x); } +void intr_prof_stack_use(struct thread *td, struct trapframe *frame); + #endif /* !_SYS_SYSTM_H_ */ Modified: stable/10/sys/vm/vm_glue.c ============================================================================== --- stable/10/sys/vm/vm_glue.c Sat Oct 11 17:16:18 2014 (r272945) +++ stable/10/sys/vm/vm_glue.c Sat Oct 11 17:49:51 2014 (r272946) @@ -62,6 +62,7 @@ __FBSDID("$FreeBSD$"); #include "opt_vm.h" #include "opt_kstack_pages.h" #include "opt_kstack_max_pages.h" +#include "opt_kstack_usage_prof.h" #include #include @@ -98,6 +99,8 @@ __FBSDID("$FreeBSD$"); #include #include +#include + #ifndef NO_SWAPPING static int swapout(struct proc *); static void swapclear(struct proc *); @@ -486,6 +489,52 @@ kstack_cache_init(void *nulll) SYSINIT(vm_kstacks, SI_SUB_KTHREAD_INIT, SI_ORDER_ANY, kstack_cache_init, NULL); +#ifdef KSTACK_USAGE_PROF +/* + * Track maximum stack used by a thread in kernel. + */ +static int max_kstack_used; + +SYSCTL_INT(_debug, OID_AUTO, max_kstack_used, CTLFLAG_RD, + &max_kstack_used, 0, + "Maxiumum stack depth used by a thread in kernel"); + +void +intr_prof_stack_use(struct thread *td, struct trapframe *frame) +{ + vm_offset_t stack_top; + vm_offset_t current; + int used, prev_used; + + /* + * Testing for interrupted kernel mode isn't strictly + * needed. It optimizes the execution, since interrupts from + * usermode will have only the trap frame on the stack. + */ + if (TRAPF_USERMODE(frame)) + return; + + stack_top = td->td_kstack + td->td_kstack_pages * PAGE_SIZE; + current = (vm_offset_t)(uintptr_t)&stack_top; + + /* + * Try to detect if interrupt is using kernel thread stack. + * Hardware could use a dedicated stack for interrupt handling. + */ + if (stack_top <= current || current < td->td_kstack) + return; + + used = stack_top - current; + for (;;) { + prev_used = max_kstack_used; + if (prev_used >= used) + break; + if (atomic_cmpset_int(&max_kstack_used, prev_used, used)) + break; + } +} +#endif /* KSTACK_USAGE_PROF */ + #ifndef NO_SWAPPING /* * Allow a thread's kernel stack to be paged out.