FreeBSD/sys/dev/hwpmc/hwpmc_mod.c
/*
 * Detach a process from a PMC.  If there are no other PMCs tracking
 * this process, remove the process structure from its hash table.  If
 * 'flags' contains PMC_FLAG_REMOVE, then free the process structure.
 */
Detach a process from a PMC.  If there are no other PMCs tracking
this process, remove the process structure from its hash table.  If
'flags' contains PMC_FLAG_REMOVE, then free the process structure.
Detach a process from a PMC . If there are no other PMCs tracking this process remove the process structure from its hash table . If ' flags ' contains PMC_FLAG_REMOVE then free the process structure .
static int
pmc_detach_one_process(struct proc *p, struct pmc *pm, int flags)
{
	int ri;
	struct pmc_process *pp;
	sx_assert(&pmc_sx, SX_XLOCKED);
	KASSERT(pm != NULL,
	    ("[pmc,%d] null pm pointer", __LINE__));
	ri = PMC_TO_ROWINDEX(pm);
	PMCDBG6(PRC,ATT,2, "detach-one pm=%p ri=%d proc=%p (%d, %s) flags=0x%x",
	    pm, ri, p, p->p_pid, p->p_comm, flags);
	if ((pp = pmc_find_process_descriptor(p, 0)) == NULL)
		return ESRCH;
	if (pp->pp_pmcs[ri].pp_pmc != pm)
		return EINVAL;
	pmc_unlink_target_process(pm, pp);
	if (pm->pm_owner->po_flags & PMC_PO_OWNS_LOGFILE)
		pmclog_process_pmcdetach(pm, p->p_pid);
	KASSERT(pp->pp_refcnt >= 0 && pp->pp_refcnt <= (int) md->pmd_npmc,
	    ("[pmc,%d] Illegal refcnt %d for process struct %p",
		__LINE__, pp->pp_refcnt, pp));
	if (pp->pp_refcnt != 0)	
		return 0;
	pmc_remove_process_descriptor(pp);
	if (flags & PMC_FLAG_REMOVE)
		free(pp, M_PMC);
	PROC_LOCK(p);
	p->p_flag &= ~P_HWPMC;
	PROC_UNLOCK(p);
	return 0;
}
static int pmc_detach_one_process ( struct proc * p , struct pmc * pm , int flags ) { int ri ; struct pmc_process * pp ; sx_assert ( & pmc_sx , SX_XLOCKED ) ; KASSERT ( pm != NULL , ( " " , __LINE__ ) ) ; ri = PMC_TO_ROWINDEX ( pm ) ; PMCDBG6 ( PRC , ATT , 2 , " " , pm , ri , p , p -> p_pid , p -> p_comm , flags ) ; if ( ( pp = pmc_find_process_descriptor ( p , 0 ) ) == NULL ) return ESRCH ; if ( pp -> pp_pmcs [ ri ] . pp_pmc != pm ) return EINVAL ; pmc_unlink_target_process ( pm , pp ) ; if ( pm -> pm_owner -> po_flags & PMC_PO_OWNS_LOGFILE ) pmclog_process_pmcdetach ( pm , p -> p_pid ) ; KASSERT ( pp -> pp_refcnt >= 0 && pp -> pp_refcnt <= ( int ) md -> pmd_npmc , ( " " , __LINE__ , pp -> pp_refcnt , pp ) ) ; if ( pp -> pp_refcnt != 0 ) return 0 ; pmc_remove_process_descriptor ( pp ) ; if ( flags & PMC_FLAG_REMOVE ) free ( pp , M_PMC ) ; PROC_LOCK ( p ) ; p -> p_flag &= ~ P_HWPMC ; PROC_UNLOCK ( p ) ; return 0 ; }
Detach a process from a PMC.
Detach a process from a PMC .
/* Issue a detach entry if a log file is configured */ /*
	 * If there are no PMCs targeting this process, we remove its
	 * descriptor from the target hash table and unset the P_HWPMC
	 * flag in the struct proc.
	 */ /* still a target of some PMC */