FreeBSD/lib/libpmc/libpmc.c
/*
 * Return a list of events known to a given PMC class.  'cl' is the
 * PMC class identifier, 'eventnames' is the returned list of 'const
 * char *' pointers pointing to the names of the events. 'nevents' is
 * the number of event name pointers returned.
 *
 * The space for 'eventnames' is allocated using malloc(3).  The caller
 * is responsible for freeing this space when done.
 */
Return a list of events known to a given PMC class.

The space for 'eventnames' is allocated using malloc(3).  The caller
is responsible for freeing this space when done.
Return a list of events known to a given PMC class . The space for ' eventnames ' is allocated using malloc ( 3 ) . The caller is responsible for freeing this space when done .
int
pmc_event_names_of_class(enum pmc_class cl, const char ***eventnames,
    int *nevents)
{
	int count;
	const char **names;
	const struct pmc_event_descr *ev;
	switch (cl)
	{
	case PMC_CLASS_IAF:
		ev = iaf_event_table;
		count = PMC_EVENT_TABLE_SIZE(iaf);
		break;
	case PMC_CLASS_IAP:
		switch (cpu_info.pm_cputype) {
		default:
		case PMC_CPU_INTEL_ATOM:
			ev = atom_event_table;
			count = PMC_EVENT_TABLE_SIZE(atom);
			break;
		case PMC_CPU_INTEL_ATOM_SILVERMONT:
			ev = atom_silvermont_event_table;
			count = PMC_EVENT_TABLE_SIZE(atom_silvermont);
			break;
		case PMC_CPU_INTEL_CORE:
			ev = core_event_table;
			count = PMC_EVENT_TABLE_SIZE(core);
			break;
		case PMC_CPU_INTEL_CORE2:
		case PMC_CPU_INTEL_CORE2EXTREME:
			ev = core2_event_table;
			count = PMC_EVENT_TABLE_SIZE(core2);
			break;
		case PMC_CPU_INTEL_COREI7:
			ev = corei7_event_table;
			count = PMC_EVENT_TABLE_SIZE(corei7);
			break;
		case PMC_CPU_INTEL_NEHALEM_EX:
			ev = nehalem_ex_event_table;
			count = PMC_EVENT_TABLE_SIZE(nehalem_ex);
			break;
		case PMC_CPU_INTEL_HASWELL:
			ev = haswell_event_table;
			count = PMC_EVENT_TABLE_SIZE(haswell);
			break;
		case PMC_CPU_INTEL_HASWELL_XEON:
			ev = haswell_xeon_event_table;
			count = PMC_EVENT_TABLE_SIZE(haswell_xeon);
			break;
		case PMC_CPU_INTEL_BROADWELL:
			ev = broadwell_event_table;
			count = PMC_EVENT_TABLE_SIZE(broadwell);
			break;
		case PMC_CPU_INTEL_BROADWELL_XEON:
			ev = broadwell_xeon_event_table;
			count = PMC_EVENT_TABLE_SIZE(broadwell_xeon);
			break;
		case PMC_CPU_INTEL_SKYLAKE:
			ev = skylake_event_table;
			count = PMC_EVENT_TABLE_SIZE(skylake);
			break;
		case PMC_CPU_INTEL_IVYBRIDGE:
			ev = ivybridge_event_table;
			count = PMC_EVENT_TABLE_SIZE(ivybridge);
			break;
		case PMC_CPU_INTEL_IVYBRIDGE_XEON:
			ev = ivybridge_xeon_event_table;
			count = PMC_EVENT_TABLE_SIZE(ivybridge_xeon);
			break;
		case PMC_CPU_INTEL_SANDYBRIDGE:
			ev = sandybridge_event_table;
			count = PMC_EVENT_TABLE_SIZE(sandybridge);
			break;
		case PMC_CPU_INTEL_SANDYBRIDGE_XEON:
			ev = sandybridge_xeon_event_table;
			count = PMC_EVENT_TABLE_SIZE(sandybridge_xeon);
			break;
		case PMC_CPU_INTEL_WESTMERE:
			ev = westmere_event_table;
			count = PMC_EVENT_TABLE_SIZE(westmere);
			break;
		case PMC_CPU_INTEL_WESTMERE_EX:
			ev = westmere_ex_event_table;
			count = PMC_EVENT_TABLE_SIZE(westmere_ex);
			break;
		}
		break;
	case PMC_CLASS_UCF:
		ev = ucf_event_table;
		count = PMC_EVENT_TABLE_SIZE(ucf);
		break;
	case PMC_CLASS_UCP:
		switch (cpu_info.pm_cputype) {
		default:
		case PMC_CPU_INTEL_COREI7:
			ev = corei7uc_event_table;
			count = PMC_EVENT_TABLE_SIZE(corei7uc);
			break;
		case PMC_CPU_INTEL_HASWELL:
			ev = haswelluc_event_table;
			count = PMC_EVENT_TABLE_SIZE(haswelluc);
			break;
		case PMC_CPU_INTEL_BROADWELL:
			ev = broadwelluc_event_table;
			count = PMC_EVENT_TABLE_SIZE(broadwelluc);
			break;
		case PMC_CPU_INTEL_SANDYBRIDGE:
			ev = sandybridgeuc_event_table;
			count = PMC_EVENT_TABLE_SIZE(sandybridgeuc);
			break;
		case PMC_CPU_INTEL_WESTMERE:
			ev = westmereuc_event_table;
			count = PMC_EVENT_TABLE_SIZE(westmereuc);
			break;
		}
		break;
	case PMC_CLASS_TSC:
		ev = tsc_event_table;
		count = PMC_EVENT_TABLE_SIZE(tsc);
		break;
	case PMC_CLASS_K7:
		ev = k7_event_table;
		count = PMC_EVENT_TABLE_SIZE(k7);
		break;
	case PMC_CLASS_K8:
		ev = k8_event_table;
		count = PMC_EVENT_TABLE_SIZE(k8);
		break;
	case PMC_CLASS_P4:
		ev = p4_event_table;
		count = PMC_EVENT_TABLE_SIZE(p4);
		break;
	case PMC_CLASS_P5:
		ev = p5_event_table;
		count = PMC_EVENT_TABLE_SIZE(p5);
		break;
	case PMC_CLASS_P6:
		ev = p6_event_table;
		count = PMC_EVENT_TABLE_SIZE(p6);
		break;
	case PMC_CLASS_XSCALE:
		ev = xscale_event_table;
		count = PMC_EVENT_TABLE_SIZE(xscale);
		break;
	case PMC_CLASS_ARMV7:
		switch (cpu_info.pm_cputype) {
		default:
		case PMC_CPU_ARMV7_CORTEX_A8:
			ev = cortex_a8_event_table;
			count = PMC_EVENT_TABLE_SIZE(cortex_a8);
			break;
		case PMC_CPU_ARMV7_CORTEX_A9:
			ev = cortex_a9_event_table;
			count = PMC_EVENT_TABLE_SIZE(cortex_a9);
			break;
		}
		break;
	case PMC_CLASS_ARMV8:
		switch (cpu_info.pm_cputype) {
		default:
		case PMC_CPU_ARMV8_CORTEX_A53:
			ev = cortex_a53_event_table;
			count = PMC_EVENT_TABLE_SIZE(cortex_a53);
			break;
		case PMC_CPU_ARMV8_CORTEX_A57:
			ev = cortex_a57_event_table;
			count = PMC_EVENT_TABLE_SIZE(cortex_a57);
			break;
		}
		break;
	case PMC_CLASS_MIPS24K:
		ev = mips24k_event_table;
		count = PMC_EVENT_TABLE_SIZE(mips24k);
		break;
	case PMC_CLASS_MIPS74K:
		ev = mips74k_event_table;
		count = PMC_EVENT_TABLE_SIZE(mips74k);
		break;
	case PMC_CLASS_OCTEON:
		ev = octeon_event_table;
		count = PMC_EVENT_TABLE_SIZE(octeon);
		break;
	case PMC_CLASS_PPC7450:
		ev = ppc7450_event_table;
		count = PMC_EVENT_TABLE_SIZE(ppc7450);
		break;
	case PMC_CLASS_PPC970:
		ev = ppc970_event_table;
		count = PMC_EVENT_TABLE_SIZE(ppc970);
		break;
	case PMC_CLASS_E500:
		ev = e500_event_table;
		count = PMC_EVENT_TABLE_SIZE(e500);
		break;
	case PMC_CLASS_SOFT:
		ev = soft_event_table;
		count = soft_event_info.pm_nevent;
		break;
	default:
		errno = EINVAL;
		return (-1);
	}
	if ((names = malloc(count * sizeof(const char *))) == NULL)
		return (-1);
	*eventnames = names;
	*nevents = count;
	for (;count--; ev++, names++)
		*names = ev->pm_ev_name;
	return (0);
}
int pmc_event_names_of_class ( enum pmc_class cl , const char * * * eventnames , int * nevents ) { int count ; const char * * names ; const struct pmc_event_descr * ev ; switch ( cl ) { case PMC_CLASS_IAF : ev = iaf_event_table ; count = PMC_EVENT_TABLE_SIZE ( iaf ) ; break ; case PMC_CLASS_IAP : switch ( cpu_info . pm_cputype ) { default : case PMC_CPU_INTEL_ATOM : ev = atom_event_table ; count = PMC_EVENT_TABLE_SIZE ( atom ) ; break ; case PMC_CPU_INTEL_ATOM_SILVERMONT : ev = atom_silvermont_event_table ; count = PMC_EVENT_TABLE_SIZE ( atom_silvermont ) ; break ; case PMC_CPU_INTEL_CORE : ev = core_event_table ; count = PMC_EVENT_TABLE_SIZE ( core ) ; break ; case PMC_CPU_INTEL_CORE2 : case PMC_CPU_INTEL_CORE2EXTREME : ev = core2_event_table ; count = PMC_EVENT_TABLE_SIZE ( core2 ) ; break ; case PMC_CPU_INTEL_COREI7 : ev = corei7_event_table ; count = PMC_EVENT_TABLE_SIZE ( corei7 ) ; break ; case PMC_CPU_INTEL_NEHALEM_EX : ev = nehalem_ex_event_table ; count = PMC_EVENT_TABLE_SIZE ( nehalem_ex ) ; break ; case PMC_CPU_INTEL_HASWELL : ev = haswell_event_table ; count = PMC_EVENT_TABLE_SIZE ( haswell ) ; break ; case PMC_CPU_INTEL_HASWELL_XEON : ev = haswell_xeon_event_table ; count = PMC_EVENT_TABLE_SIZE ( haswell_xeon ) ; break ; case PMC_CPU_INTEL_BROADWELL : ev = broadwell_event_table ; count = PMC_EVENT_TABLE_SIZE ( broadwell ) ; break ; case PMC_CPU_INTEL_BROADWELL_XEON : ev = broadwell_xeon_event_table ; count = PMC_EVENT_TABLE_SIZE ( broadwell_xeon ) ; break ; case PMC_CPU_INTEL_SKYLAKE : ev = skylake_event_table ; count = PMC_EVENT_TABLE_SIZE ( skylake ) ; break ; case PMC_CPU_INTEL_IVYBRIDGE : ev = ivybridge_event_table ; count = PMC_EVENT_TABLE_SIZE ( ivybridge ) ; break ; case PMC_CPU_INTEL_IVYBRIDGE_XEON : ev = ivybridge_xeon_event_table ; count = PMC_EVENT_TABLE_SIZE ( ivybridge_xeon ) ; break ; case PMC_CPU_INTEL_SANDYBRIDGE : ev = sandybridge_event_table ; count = PMC_EVENT_TABLE_SIZE ( sandybridge ) ; break ; case PMC_CPU_INTEL_SANDYBRIDGE_XEON : ev = sandybridge_xeon_event_table ; count = PMC_EVENT_TABLE_SIZE ( sandybridge_xeon ) ; break ; case PMC_CPU_INTEL_WESTMERE : ev = westmere_event_table ; count = PMC_EVENT_TABLE_SIZE ( westmere ) ; break ; case PMC_CPU_INTEL_WESTMERE_EX : ev = westmere_ex_event_table ; count = PMC_EVENT_TABLE_SIZE ( westmere_ex ) ; break ; } break ; case PMC_CLASS_UCF : ev = ucf_event_table ; count = PMC_EVENT_TABLE_SIZE ( ucf ) ; break ; case PMC_CLASS_UCP : switch ( cpu_info . pm_cputype ) { default : case PMC_CPU_INTEL_COREI7 : ev = corei7uc_event_table ; count = PMC_EVENT_TABLE_SIZE ( corei7uc ) ; break ; case PMC_CPU_INTEL_HASWELL : ev = haswelluc_event_table ; count = PMC_EVENT_TABLE_SIZE ( haswelluc ) ; break ; case PMC_CPU_INTEL_BROADWELL : ev = broadwelluc_event_table ; count = PMC_EVENT_TABLE_SIZE ( broadwelluc ) ; break ; case PMC_CPU_INTEL_SANDYBRIDGE : ev = sandybridgeuc_event_table ; count = PMC_EVENT_TABLE_SIZE ( sandybridgeuc ) ; break ; case PMC_CPU_INTEL_WESTMERE : ev = westmereuc_event_table ; count = PMC_EVENT_TABLE_SIZE ( westmereuc ) ; break ; } break ; case PMC_CLASS_TSC : ev = tsc_event_table ; count = PMC_EVENT_TABLE_SIZE ( tsc ) ; break ; case PMC_CLASS_K7 : ev = k7_event_table ; count = PMC_EVENT_TABLE_SIZE ( k7 ) ; break ; case PMC_CLASS_K8 : ev = k8_event_table ; count = PMC_EVENT_TABLE_SIZE ( k8 ) ; break ; case PMC_CLASS_P4 : ev = p4_event_table ; count = PMC_EVENT_TABLE_SIZE ( p4 ) ; break ; case PMC_CLASS_P5 : ev = p5_event_table ; count = PMC_EVENT_TABLE_SIZE ( p5 ) ; break ; case PMC_CLASS_P6 : ev = p6_event_table ; count = PMC_EVENT_TABLE_SIZE ( p6 ) ; break ; case PMC_CLASS_XSCALE : ev = xscale_event_table ; count = PMC_EVENT_TABLE_SIZE ( xscale ) ; break ; case PMC_CLASS_ARMV7 : switch ( cpu_info . pm_cputype ) { default : case PMC_CPU_ARMV7_CORTEX_A8 : ev = cortex_a8_event_table ; count = PMC_EVENT_TABLE_SIZE ( cortex_a8 ) ; break ; case PMC_CPU_ARMV7_CORTEX_A9 : ev = cortex_a9_event_table ; count = PMC_EVENT_TABLE_SIZE ( cortex_a9 ) ; break ; } break ; case PMC_CLASS_ARMV8 : switch ( cpu_info . pm_cputype ) { default : case PMC_CPU_ARMV8_CORTEX_A53 : ev = cortex_a53_event_table ; count = PMC_EVENT_TABLE_SIZE ( cortex_a53 ) ; break ; case PMC_CPU_ARMV8_CORTEX_A57 : ev = cortex_a57_event_table ; count = PMC_EVENT_TABLE_SIZE ( cortex_a57 ) ; break ; } break ; case PMC_CLASS_MIPS24K : ev = mips24k_event_table ; count = PMC_EVENT_TABLE_SIZE ( mips24k ) ; break ; case PMC_CLASS_MIPS74K : ev = mips74k_event_table ; count = PMC_EVENT_TABLE_SIZE ( mips74k ) ; break ; case PMC_CLASS_OCTEON : ev = octeon_event_table ; count = PMC_EVENT_TABLE_SIZE ( octeon ) ; break ; case PMC_CLASS_PPC7450 : ev = ppc7450_event_table ; count = PMC_EVENT_TABLE_SIZE ( ppc7450 ) ; break ; case PMC_CLASS_PPC970 : ev = ppc970_event_table ; count = PMC_EVENT_TABLE_SIZE ( ppc970 ) ; break ; case PMC_CLASS_E500 : ev = e500_event_table ; count = PMC_EVENT_TABLE_SIZE ( e500 ) ; break ; case PMC_CLASS_SOFT : ev = soft_event_table ; count = soft_event_info . pm_nevent ; break ; default : errno = EINVAL ; return ( -1 ) ; } if ( ( names = malloc ( count * sizeof ( const char * ) ) ) == NULL ) return ( -1 ) ; * eventnames = names ; * nevents = count ; for ( ; count -- ; ev ++ , names ++ ) * names = ev -> pm_ev_name ; return ( 0 ) ; }
Return a list of events known to a given PMC class.
Return a list of events known to a given PMC class .
/*
		 * Return the most appropriate set of event name
		 * spellings for the current CPU.
		 */ /*
		 * Return the most appropriate set of event name
		 * spellings for the current CPU.
		 */