From owner-svn-src-stable-9@FreeBSD.ORG Thu Nov 6 01:30:16 2014 Return-Path: Delivered-To: svn-src-stable-9@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id A27E911A; Thu, 6 Nov 2014 01:30:16 +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 6A6648BA; Thu, 6 Nov 2014 01:30:16 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id sA61UGWX016724; Thu, 6 Nov 2014 01:30:16 GMT (envelope-from markj@FreeBSD.org) Received: (from markj@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id sA61UG68016723; Thu, 6 Nov 2014 01:30:16 GMT (envelope-from markj@FreeBSD.org) Message-Id: <201411060130.sA61UG68016723@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: markj set sender to markj@FreeBSD.org using -f From: Mark Johnston Date: Thu, 6 Nov 2014 01:30:16 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org Subject: svn commit: r274156 - stable/9/sys/dev/hwpmc X-SVN-Group: stable-9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-9@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for only the 9-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 06 Nov 2014 01:30:17 -0000 Author: markj Date: Thu Nov 6 01:30:15 2014 New Revision: 274156 URL: https://svnweb.freebsd.org/changeset/base/274156 Log: MFC r273236: Use pmc_destroy_pmc_descriptor() to actually free the pmc, which is consistent with pmc_destroy_owner_descriptor(). Also be sure to destroy PMCs if a process exits or execs without explicitly releasing them. Modified: stable/9/sys/dev/hwpmc/hwpmc_mod.c Directory Properties: stable/9/sys/ (props changed) stable/9/sys/dev/ (props changed) Modified: stable/9/sys/dev/hwpmc/hwpmc_mod.c ============================================================================== --- stable/9/sys/dev/hwpmc/hwpmc_mod.c Thu Nov 6 01:30:13 2014 (r274155) +++ stable/9/sys/dev/hwpmc/hwpmc_mod.c Thu Nov 6 01:30:15 2014 (r274156) @@ -191,6 +191,7 @@ static int pmc_detach_process(struct pro static int pmc_detach_one_process(struct proc *p, struct pmc *pm, int flags); static void pmc_destroy_owner_descriptor(struct pmc_owner *po); +static void pmc_destroy_pmc_descriptor(struct pmc *pm); static struct pmc_owner *pmc_find_owner_descriptor(struct proc *p); static int pmc_find_pmc(pmc_id_t pmcid, struct pmc **pm); static struct pmc *pmc_find_pmc_descriptor_in_process(struct pmc_owner *po, @@ -752,6 +753,7 @@ pmc_remove_owner(struct pmc_owner *po) ("[pmc,%d] owner %p != po %p", __LINE__, pm->pm_owner, po)); pmc_release_pmc_descriptor(pm); /* will unlink from the list */ + pmc_destroy_pmc_descriptor(pm); } KASSERT(po->po_sscount == 0, @@ -2176,9 +2178,7 @@ pmc_allocate_pmc_descriptor(void) static void pmc_destroy_pmc_descriptor(struct pmc *pm) { - (void) pm; -#ifdef DEBUG KASSERT(pm->pm_state == PMC_STATE_DELETED || pm->pm_state == PMC_STATE_FREE, ("[pmc,%d] destroying non-deleted PMC", __LINE__)); @@ -2189,7 +2189,8 @@ pmc_destroy_pmc_descriptor(struct pmc *p KASSERT(pm->pm_runcount == 0, ("[pmc,%d] pmc has non-zero run count %d", __LINE__, pm->pm_runcount)); -#endif + + free(pm, M_PMC); } static void @@ -2222,10 +2223,10 @@ pmc_wait_for_pmc_idle(struct pmc *pm) * - detaches the PMC from hardware * - unlinks all target threads that were attached to it * - removes the PMC from its owner's list - * - destroy's the PMC private mutex + * - destroys the PMC private mutex * - * Once this function completes, the given pmc pointer can be safely - * FREE'd by the caller. + * Once this function completes, the given pmc pointer can be freed by + * calling pmc_destroy_pmc_descriptor(). */ static void @@ -2375,8 +2376,6 @@ pmc_release_pmc_descriptor(struct pmc *p LIST_REMOVE(pm, pm_next); pm->pm_owner = NULL; } - - pmc_destroy_pmc_descriptor(pm); } /* @@ -3383,7 +3382,6 @@ pmc_syscall_handler(struct thread *td, v if (n == (int) md->pmd_npmc) { pmc_destroy_pmc_descriptor(pmc); - free(pmc, M_PMC); pmc = NULL; error = EINVAL; break; @@ -3419,7 +3417,6 @@ pmc_syscall_handler(struct thread *td, v (error = pcd->pcd_config_pmc(cpu, adjri, pmc)) != 0) { (void) pcd->pcd_release_pmc(cpu, adjri, pmc); pmc_destroy_pmc_descriptor(pmc); - free(pmc, M_PMC); pmc = NULL; pmc_restore_cpu_binding(&pb); error = EPERM; @@ -3447,7 +3444,7 @@ pmc_syscall_handler(struct thread *td, v if ((error = pmc_register_owner(curthread->td_proc, pmc)) != 0) { pmc_release_pmc_descriptor(pmc); - free(pmc, M_PMC); + pmc_destroy_pmc_descriptor(pmc); pmc = NULL; break; } @@ -3690,8 +3687,7 @@ pmc_syscall_handler(struct thread *td, v po = pm->pm_owner; pmc_release_pmc_descriptor(pm); pmc_maybe_remove_owner(po); - - free(pm, M_PMC); + pmc_destroy_pmc_descriptor(pm); } break;