FreeBSD/sys/dev/hwpmc/hwpmc_amd.c
/*
 * processor dependent cleanup prior to the KLD
 * being unloaded
 */
processor dependent cleanup prior to the KLD
being unloaded
processor dependent cleanup prior to the KLD being unloaded
static int
amd_pcpu_fini(struct pmc_mdep *md, int cpu)
{
	int classindex, first_ri, i;
	uint32_t evsel;
	struct pmc_cpu *pc;
	struct amd_cpu *pac;
	KASSERT(cpu >= 0 && cpu < pmc_cpu_max(),
	    ("[amd,%d] insane cpu number (%d)", __LINE__, cpu));
	PMCDBG1(MDP,INI,1,"amd-cleanup cpu=%d", cpu);
	for (i = 0; i < 4; i++) { 
		evsel = rdmsr(AMD_PMC_EVSEL_0 + i);
		evsel &= ~AMD_PMC_ENABLE;
		wrmsr(AMD_PMC_EVSEL_0 + i, evsel);
	}
	if ((pac = amd_pcpu[cpu]) == NULL)
		return (0);
	amd_pcpu[cpu] = NULL;
#ifdef	HWPMC_DEBUG
	for (i = 0; i < AMD_NPMCS; i++) {
		KASSERT(pac->pc_amdpmcs[i].phw_pmc == NULL,
		    ("[amd,%d] CPU%d/PMC%d in use", __LINE__, cpu, i));
		KASSERT(AMD_PMC_IS_STOPPED(AMD_PMC_EVSEL_0 + i),
		    ("[amd,%d] CPU%d/PMC%d not stopped", __LINE__, cpu, i));
	}
#endif
	pc = pmc_pcpu[cpu];
	KASSERT(pc != NULL, ("[amd,%d] NULL per-cpu state", __LINE__));
#if	defined(__amd64__)
	classindex = PMC_MDEP_CLASS_INDEX_K8;
#elif	defined(__i386__)
	classindex = md->pmd_cputype == PMC_CPU_AMD_K8 ? PMC_MDEP_CLASS_INDEX_K8 :
	    PMC_MDEP_CLASS_INDEX_K7;
#endif
	first_ri = md->pmd_classdep[classindex].pcd_ri;
	for (i = 0; i < AMD_NPMCS; i++) {
		pc->pc_hwpmcs[i + first_ri] = NULL;
	}
	free(pac, M_PMC);
	return (0);
}
static int amd_pcpu_fini ( struct pmc_mdep * md , int cpu ) { int classindex , first_ri , i ; uint32_t evsel ; struct pmc_cpu * pc ; struct amd_cpu * pac ; KASSERT ( cpu >= 0 && cpu < pmc_cpu_max ( ) , ( " " , __LINE__ , cpu ) ) ; PMCDBG1 ( MDP , INI , 1 , " " , cpu ) ; for ( i = 0 ; i < 4 ; i ++ ) { evsel = rdmsr ( AMD_PMC_EVSEL_0 + i ) ; evsel &= ~ AMD_PMC_ENABLE ; wrmsr ( AMD_PMC_EVSEL_0 + i , evsel ) ; } if ( ( pac = amd_pcpu [ cpu ] ) == NULL ) return ( 0 ) ; amd_pcpu [ cpu ] = NULL ; #ifdef HWPMC_DEBUG for ( i = 0 ; i < AMD_NPMCS ; i ++ ) { KASSERT ( pac -> pc_amdpmcs [ i ] . phw_pmc == NULL , ( " " , __LINE__ , cpu , i ) ) ; KASSERT ( AMD_PMC_IS_STOPPED ( AMD_PMC_EVSEL_0 + i ) , ( " " , __LINE__ , cpu , i ) ) ; } #endif pc = pmc_pcpu [ cpu ] ; KASSERT ( pc != NULL , ( " " , __LINE__ ) ) ; #if defined ( __amd64__ ) classindex = PMC_MDEP_CLASS_INDEX_K8 ; #elif defined ( __i386__ ) classindex = md -> pmd_cputype == PMC_CPU_AMD_K8 ? PMC_MDEP_CLASS_INDEX_K8 : PMC_MDEP_CLASS_INDEX_K7 ; #endif first_ri = md -> pmd_classdep [ classindex ] . pcd_ri ; for ( i = 0 ; i < AMD_NPMCS ; i ++ ) { pc -> pc_hwpmcs [ i + first_ri ] = NULL ; } free ( pac , M_PMC ) ; return ( 0 ) ; }
processor dependent cleanup prior to the KLD
 being unloaded
processor dependent cleanup prior to the KLD being unloaded
/*
	 * First, turn off all PMCs on this CPU.
	 */ /* XXX this loop is now not needed */ /*
	 * Next, free up allocated space.
	 */ /*
	 * Reset pointers in the MI 'per-cpu' state.
	 */