FreeBSD/sys/dev/hwpmc/hwpmc_mod.c
/*
 * Add an association between a target process and a PMC.
 */
Add an association between a target process and a PMC.
Add an association between a target process and a PMC .
static void
pmc_link_target_process(struct pmc *pm, struct pmc_process *pp)
{
	int ri;
	struct pmc_target *pt;
	sx_assert(&pmc_sx, SX_XLOCKED);
	KASSERT(pm != NULL && pp != NULL,
	    ("[pmc,%d] Null pm %p or pp %p", __LINE__, pm, pp));
	KASSERT(PMC_IS_VIRTUAL_MODE(PMC_TO_MODE(pm)),
	    ("[pmc,%d] Attaching a non-process-virtual pmc=%p to pid=%d",
		__LINE__, pm, pp->pp_proc->p_pid));
	KASSERT(pp->pp_refcnt >= 0 && pp->pp_refcnt <= ((int) md->pmd_npmc - 1),
	    ("[pmc,%d] Illegal reference count %d for process record %p",
		__LINE__, pp->pp_refcnt, (void *) pp));
	ri = PMC_TO_ROWINDEX(pm);
	PMCDBG3(PRC,TLK,1, "link-target pmc=%p ri=%d pmc-process=%p",
	    pm, ri, pp);
#ifdef	HWPMC_DEBUG
	LIST_FOREACH(pt, &pm->pm_targets, pt_next)
	    if (pt->pt_process == pp)
		    KASSERT(0, ("[pmc,%d] pp %p already in pmc %p targets",
				__LINE__, pp, pm));
#endif
	pt = malloc(sizeof(struct pmc_target), M_PMC, M_WAITOK|M_ZERO);
	pt->pt_process = pp;
	LIST_INSERT_HEAD(&pm->pm_targets, pt, pt_next);
	atomic_store_rel_ptr((uintptr_t *)&pp->pp_pmcs[ri].pp_pmc,
	    (uintptr_t)pm);
	if (pm->pm_owner->po_owner == pp->pp_proc)
		pm->pm_flags |= PMC_F_ATTACHED_TO_OWNER;
	pp->pp_pmcs[ri].pp_pmcval = PMC_TO_MODE(pm) == PMC_MODE_TS ?
	    pm->pm_sc.pm_reloadcount : 0;
	pp->pp_refcnt++;
}
static void pmc_link_target_process ( struct pmc * pm , struct pmc_process * pp ) { int ri ; struct pmc_target * pt ; sx_assert ( & pmc_sx , SX_XLOCKED ) ; KASSERT ( pm != NULL && pp != NULL , ( " " , __LINE__ , pm , pp ) ) ; KASSERT ( PMC_IS_VIRTUAL_MODE ( PMC_TO_MODE ( pm ) ) , ( " " , __LINE__ , pm , pp -> pp_proc -> p_pid ) ) ; KASSERT ( pp -> pp_refcnt >= 0 && pp -> pp_refcnt <= ( ( int ) md -> pmd_npmc - 1 ) , ( " " , __LINE__ , pp -> pp_refcnt , ( void * ) pp ) ) ; ri = PMC_TO_ROWINDEX ( pm ) ; PMCDBG3 ( PRC , TLK , 1 , " " , pm , ri , pp ) ; #ifdef HWPMC_DEBUG LIST_FOREACH ( pt , & pm -> pm_targets , pt_next ) if ( pt -> pt_process == pp ) KASSERT ( 0 , ( " " , __LINE__ , pp , pm ) ) ; #endif pt = malloc ( sizeof ( struct pmc_target ) , M_PMC , M_WAITOK | M_ZERO ) ; pt -> pt_process = pp ; LIST_INSERT_HEAD ( & pm -> pm_targets , pt , pt_next ) ; atomic_store_rel_ptr ( ( uintptr_t * ) & pp -> pp_pmcs [ ri ] . pp_pmc , ( uintptr_t ) pm ) ; if ( pm -> pm_owner -> po_owner == pp -> pp_proc ) pm -> pm_flags |= PMC_F_ATTACHED_TO_OWNER ; pp -> pp_pmcs [ ri ] . pp_pmcval = PMC_TO_MODE ( pm ) == PMC_MODE_TS ? pm -> pm_sc . pm_reloadcount : 0 ; pp -> pp_refcnt ++ ; }
Add an association between a target process and a PMC.
Add an association between a target process and a PMC .
/*
	 * Initialize the per-process values at this row index.
	 */