FreeBSD/sys/dev/hwpmc/hwpmc_mod.c
/*
 * Detach a process and optionally its descendants from a PMC.
 */
Detach a process and optionally its descendants from a PMC.
Detach a process and optionally its descendants from a PMC .
static int
pmc_detach_process(struct proc *p, struct pmc *pm)
{
	struct proc *top;
	sx_assert(&pmc_sx, SX_XLOCKED);
	PMCDBG5(PRC,ATT,1, "detach pm=%p ri=%d proc=%p (%d, %s)", pm,
	    PMC_TO_ROWINDEX(pm), p, p->p_pid, p->p_comm);
	if ((pm->pm_flags & PMC_F_DESCENDANTS) == 0)
		return pmc_detach_one_process(p, pm, PMC_FLAG_REMOVE);
	sx_slock(&proctree_lock);
	top = p;
	for (;;) {
		(void) pmc_detach_one_process(p, pm, PMC_FLAG_REMOVE);
		if (!LIST_EMPTY(&p->p_children))
			p = LIST_FIRST(&p->p_children);
		else for (;;) {
			if (p == top)
				goto done;
			if (LIST_NEXT(p, p_sibling)) {
				p = LIST_NEXT(p, p_sibling);
				break;
			}
			p = p->p_pptr;
		}
	}
 done:
	sx_sunlock(&proctree_lock);
	if (LIST_EMPTY(&pm->pm_targets))
		pm->pm_flags &= ~PMC_F_ATTACH_DONE;
	return 0;
}
static int pmc_detach_process ( struct proc * p , struct pmc * pm ) { struct proc * top ; sx_assert ( & pmc_sx , SX_XLOCKED ) ; PMCDBG5 ( PRC , ATT , 1 , " " , pm , PMC_TO_ROWINDEX ( pm ) , p , p -> p_pid , p -> p_comm ) ; if ( ( pm -> pm_flags & PMC_F_DESCENDANTS ) == 0 ) return pmc_detach_one_process ( p , pm , PMC_FLAG_REMOVE ) ; sx_slock ( & proctree_lock ) ; top = p ; for ( ; ; ) { ( void ) pmc_detach_one_process ( p , pm , PMC_FLAG_REMOVE ) ; if ( ! LIST_EMPTY ( & p -> p_children ) ) p = LIST_FIRST ( & p -> p_children ) ; else for ( ; ; ) { if ( p == top ) goto done ; if ( LIST_NEXT ( p , p_sibling ) ) { p = LIST_NEXT ( p , p_sibling ) ; break ; } p = p -> p_pptr ; } } done : sx_sunlock ( & proctree_lock ) ; if ( LIST_EMPTY ( & pm -> pm_targets ) ) pm -> pm_flags &= ~ PMC_F_ATTACH_DONE ; return 0 ; }
Detach a process and optionally its descendants from a PMC.
Detach a process and optionally its descendants from a PMC .
/*
	 * Traverse all children, detaching them from this PMC.  We
	 * ignore errors since we could be detaching a PMC from a
	 * partially attached proc tree.
	 */