From owner-svn-src-head@freebsd.org Sat May 28 13:05:41 2016 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 26293B4DE25; Sat, 28 May 2016 13:05:41 +0000 (UTC) (envelope-from andrew@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::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 D2E5913C3; Sat, 28 May 2016 13:05:40 +0000 (UTC) (envelope-from andrew@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u4SD5eP9009323; Sat, 28 May 2016 13:05:40 GMT (envelope-from andrew@FreeBSD.org) Received: (from andrew@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u4SD5ew7009322; Sat, 28 May 2016 13:05:40 GMT (envelope-from andrew@FreeBSD.org) Message-Id: <201605281305.u4SD5ew7009322@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: andrew set sender to andrew@FreeBSD.org using -f From: Andrew Turner Date: Sat, 28 May 2016 13:05:40 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r300902 - head/sys/dev/hwpmc X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 28 May 2016 13:05:41 -0000 Author: andrew Date: Sat May 28 13:05:39 2016 New Revision: 300902 URL: https://svnweb.freebsd.org/changeset/base/300902 Log: Don't panic in hwpmc when stopping sampling. When hwpmc stops sampling it will set the pm_state to something other than PMC_STATE_RUNNING. This means the following sequence can happen: CPU 0: Enter the interrupt handler CPU 0: Set the thread TDP_CALLCHAIN pflag CPU 1: Stop sampling CPU 0: Call pmc_process_samples, sampling is stopped so clears ps_nsamples CPU 0: Finishes interrupt processing with the TDP_CALLCHAIN flag set CPU 0: Call pmc_capture_user_callchain to capture the user call chain CPU 0: Find all the pmc sample are free so no call chains need to be captured CPU 0: KASSERT because of this This fixes the issue by checking if any of the samples have been stopped and including this in te KASSERT. PR: 204273 Reviewed by: bz, gnn Obtained from: ABT Systems Ltd Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D6581 Modified: head/sys/dev/hwpmc/hwpmc_mod.c Modified: head/sys/dev/hwpmc/hwpmc_mod.c ============================================================================== --- head/sys/dev/hwpmc/hwpmc_mod.c Sat May 28 08:32:15 2016 (r300901) +++ head/sys/dev/hwpmc/hwpmc_mod.c Sat May 28 13:05:39 2016 (r300902) @@ -4199,6 +4199,7 @@ pmc_capture_user_callchain(int cpu, int struct pmc_samplebuffer *psb; #ifdef INVARIANTS int ncallchains; + int nfree; #endif psb = pmc_pcpu[cpu]->pc_sb[ring]; @@ -4210,6 +4211,7 @@ pmc_capture_user_callchain(int cpu, int #ifdef INVARIANTS ncallchains = 0; + nfree = 0; #endif /* @@ -4221,6 +4223,10 @@ pmc_capture_user_callchain(int cpu, int ps = psb->ps_read; ps_end = psb->ps_write; do { +#ifdef INVARIANTS + if (ps->ps_pmc->pm_state != PMC_STATE_RUNNING) + nfree++; +#endif if (ps->ps_nsamples != PMC_SAMPLE_INUSE) goto next; if (ps->ps_td != td) @@ -4256,7 +4262,7 @@ next: ps = psb->ps_samples; } while (ps != ps_end); - KASSERT(ncallchains > 0, + KASSERT(ncallchains > 0 || nfree > 0, ("[pmc,%d] cpu %d didn't find a sample to collect", __LINE__, cpu));