<commit_before>/****************************/
/* THIS IS OPEN SOURCE CODE */
/****************************/

/* 
* File:    freebsd.c
* CVS:     $Id$
* Author:  <NAME>
*          <EMAIL>
*/

#include <sys/types.h>
#include <sys/resource.h>
#include <sys/sysctl.h>
#include <sys/utsname.h>

#include "papi.h"
#include "papi_internal.h"
#include "papi_vector.h"

#include SUBSTRATE
#include "map.h"

#if defined(DEBUG)
# define SHOW_WHERE_I_AM  { fprintf (stderr, "DEBUG: I am at function %s (file: %s, line: %d)\n", __FUNCTION__, __FILE__, __LINE__); }
#else
# define SHOW_WHERE_I_AM
#endif

#if defined(DEBUG)
# define SHOW_COUNTER(id,name) \
	{ \
		pmc_value_t tmp_value; \
		int ret = pmc_read (id, &tmp_value); \
		if (ret < 0) \
			fprintf (stderr, "DEBUG: Unable to read counter %s (ID: %08x) on routine %s (file: %s, line: %d)\n", name, id, __FUNCTION__, __FILE__, __LINE__); \
		else \
			fprintf (stderr, "DEBUG: Read counter %s (ID: %08x) - value %llu on routine %s (file: %s, line: %d)\n", name, id, (long long unsigned int)tmp_value, __FUNCTION__, __FILE__, __LINE__); \
	}
#else
# define SHOW_COUNTER(id,name)
#endif

static hwd_libpmc_context_t Context;

extern int _papi_freebsd_get_dmem_info(PAPI_dmem_info_t*);

extern papi_vector_t _papi_freebsd_vector;

int _papi_freebsd_set_domain(hwd_control_state_t *cntrl, int domain);

long long _papi_freebsd_get_real_cycles(void);
long long _papi_freebsd_get_real_usec();

int _papi_freebsd_ntv_code_to_name(unsigned int EventCode, char *ntv_name, int len);

int init_mdi(void);
int init_presets(void);


/*
 * Substrate setup and shutdown
 */

/* Initialize hardware counters, setup the function vector table
 * and get hardware information, this routine is called when the 
 * PAPI process is initialized (IE PAPI_library_init)
 */
int _papi_freebsd_init_substrate(int cidx)
{
   (void)cidx;

   SHOW_WHERE_I_AM;

#ifdef DEBUG 
   /* This prints out which functions are mapped to dummy routines
    * and this should be taken out once the substrate is completed.
    * The 0 argument will print out only dummy routines, change
    * it to a 1 to print out all routines.
    */
#endif

   /* Internal function, doesn't necessarily need to be a function */
   init_mdi();

   /* Internal function, doesn't necessarily need to be a function */
   init_presets();

   return PAPI_OK;
}

int init_presets(void)
{
	const struct pmc_cpuinfo *info;

	SHOW_WHERE_I_AM;

	if (pmc_cpuinfo (&info) != 0)
		return PAPI_ESYS;

	init_freebsd_libpmc_mappings();

	if (strcmp(pmc_name_of_cputype(info->pm_cputype), "INTEL_P6") == 0)
		Context.CPUsubstrate = CPU_P6;
	else if (strcmp(pmc_name_of_cputype(info->pm_cputype), "INTEL_PII") == 0)
		Context.CPUsubstrate = CPU_P6_2;
	else if (strcmp(pmc_name_of_cputype(info->pm_cputype), "INTEL_PIII") == 0)
		Context.CPUsubstrate = CPU_P6_3;
	else if (strcmp(pmc_name_of_cputype(info->pm_cputype), "INTEL_CL") == 0)
		Context.CPUsubstrate = CPU_P6_C;
	else if (strcmp(pmc_name_of_cputype(info->pm_cputype), "INTEL_PM") == 0)
		Context.CPUsubstrate = CPU_P6_M;
	else if (strcmp(pmc_name_of_cputype(info->pm_cputype), "AMD_K7") == 0)
		Context.CPUsubstrate = CPU_K7;
	else if (strcmp(pmc_name_of_cputype(info->pm_cputype), "AMD_K8") == 0)
		Context.CPUsubstrate = CPU_K8;
	else if (strcmp(pmc_name_of_cputype(info->pm_cputype), "INTEL_PIV") == 0)
		Context.CPUsubstrate = CPU_P4;
	else if (strcmp(pmc_name_of_cputype(info->pm_cputype), "INTEL_ATOM") == 0)
		Context.CPUsubstrate = CPU_ATOM;
	else if (strcmp(pmc_name_of_cputype(info->pm_cputype), "INTEL_CORE") == 0)
		Context.CPUsubstrate = CPU_CORE;
	else if (strcmp(pmc_name_of_cputype(info->pm_cputype), "INTEL_CORE2") == 0)
		Context.CPUsubstrate = CPU_CORE2;
	else if (strcmp(pmc_name_of_cputype(info->pm_cputype), "INTEL_CORE2EXTREME") == 0)
		Context.CPUsubstrate = CPU_CORE2EXTREME;
	else if (strcmp(pmc_name_of_cputype(info->pm_cputype), "INTEL_COREI7") == 0)
		Context.CPUsubstrate = CPU_COREI7;
	else
		/* Unknown processor! */
		Context.CPUsubstrate = CPU_UNKNOWN;


	_papi_freebsd_vector.cmp_info.num_native_events = freebsd_substrate_number_of_events (Context.CPUsubstrate);
	_papi_freebsd_vector.cmp_info.attach = 0;
<commit_msg>Enable new Westmere events on FreeBSD<commit_after>/****************************/
/* THIS IS OPEN SOURCE CODE */
/****************************/

/* 
* File:    freebsd.c
* CVS:     $Id$
* Author:  <NAME>
*          <EMAIL>
*/

#include <sys/types.h>
#include <sys/resource.h>
#include <sys/sysctl.h>
#include <sys/utsname.h>

#include "papi.h"
#include "papi_internal.h"
#include "papi_vector.h"

#include SUBSTRATE
#include "map.h"

#if defined(DEBUG)
# define SHOW_WHERE_I_AM  { fprintf (stderr, "DEBUG: I am at function %s (file: %s, line: %d)\n", __FUNCTION__, __FILE__, __LINE__); }
#else
# define SHOW_WHERE_I_AM
#endif

#if defined(DEBUG)
# define SHOW_COUNTER(id,name) \
	{ \
		pmc_value_t tmp_value; \
		int ret = pmc_read (id, &tmp_value); \
		if (ret < 0) \
			fprintf (stderr, "DEBUG: Unable to read counter %s (ID: %08x) on routine %s (file: %s, line: %d)\n", name, id, __FUNCTION__, __FILE__, __LINE__); \
		else \
			fprintf (stderr, "DEBUG: Read counter %s (ID: %08x) - value %llu on routine %s (file: %s, line: %d)\n", name, id, (long long unsigned int)tmp_value, __FUNCTION__, __FILE__, __LINE__); \
	}
#else
# define SHOW_COUNTER(id,name)
#endif

static hwd_libpmc_context_t Context;

extern int _papi_freebsd_get_dmem_info(PAPI_dmem_info_t*);

extern papi_vector_t _papi_freebsd_vector;

int _papi_freebsd_set_domain(hwd_control_state_t *cntrl, int domain);

long long _papi_freebsd_get_real_cycles(void);
long long _papi_freebsd_get_real_usec();

int _papi_freebsd_ntv_code_to_name(unsigned int EventCode, char *ntv_name, int len);

int init_mdi(void);
int init_presets(void);


/*
 * Substrate setup and shutdown
 */

/* Initialize hardware counters, setup the function vector table
 * and get hardware information, this routine is called when the 
 * PAPI process is initialized (IE PAPI_library_init)
 */
int _papi_freebsd_init_substrate(int cidx)
{
   (void)cidx;

   SHOW_WHERE_I_AM;

#ifdef DEBUG 
   /* This prints out which functions are mapped to dummy routines
    * and this should be taken out once the substrate is completed.
    * The 0 argument will print out only dummy routines, change
    * it to a 1 to print out all routines.
    */
#endif

   /* Internal function, doesn't necessarily need to be a function */
   init_mdi();

   /* Internal function, doesn't necessarily need to be a function */
   init_presets();

   return PAPI_OK;
}

int init_presets(void)
{
	const struct pmc_cpuinfo *info;

	SHOW_WHERE_I_AM;

	if (pmc_cpuinfo (&info) != 0)
		return PAPI_ESYS;

	init_freebsd_libpmc_mappings();

	if (strcmp(pmc_name_of_cputype(info->pm_cputype), "INTEL_P6") == 0)
		Context.CPUsubstrate = CPU_P6;
	else if (strcmp(pmc_name_of_cputype(info->pm_cputype), "INTEL_PII") == 0)
		Context.CPUsubstrate = CPU_P6_2;
	else if (strcmp(pmc_name_of_cputype(info->pm_cputype), "INTEL_PIII") == 0)
		Context.CPUsubstrate = CPU_P6_3;
	else if (strcmp(pmc_name_of_cputype(info->pm_cputype), "INTEL_CL") == 0)
		Context.CPUsubstrate = CPU_P6_C;
	else if (strcmp(pmc_name_of_cputype(info->pm_cputype), "INTEL_PM") == 0)
		Context.CPUsubstrate = CPU_P6_M;
	else if (strcmp(pmc_name_of_cputype(info->pm_cputype), "AMD_K7") == 0)
		Context.CPUsubstrate = CPU_K7;
	else if (strcmp(pmc_name_of_cputype(info->pm_cputype), "AMD_K8") == 0)
		Context.CPUsubstrate = CPU_K8;
	else if (strcmp(pmc_name_of_cputype(info->pm_cputype), "INTEL_PIV") == 0)
		Context.CPUsubstrate = CPU_P4;
	else if (strcmp(pmc_name_of_cputype(info->pm_cputype), "INTEL_ATOM") == 0)
		Context.CPUsubstrate = CPU_ATOM;
	else if (strcmp(pmc_name_of_cputype(info->pm_cputype), "INTEL_CORE") == 0)
		Context.CPUsubstrate = CPU_CORE;
	else if (strcmp(pmc_name_of_cputype(info->pm_cputype), "INTEL_CORE2") == 0)
		Context.CPUsubstrate = CPU_CORE2;
	else if (strcmp(pmc_name_of_cputype(info->pm_cputype), "INTEL_CORE2EXTREME") == 0)
		Context.CPUsubstrate = CPU_CORE2EXTREME;
	else if (strcmp(pmc_name_of_cputype(info->pm_cputype), "INTEL_COREI7") == 0)
		Context.CPUsubstrate = CPU_COREI7;
	else if (strcmp(pmc_name_of_cputype(info->pm_cputype), "INTEL_WESTMERE") == 0)
		Context.CPUsubstrate = CPU_COREWESTMERE;
	else
		/* Unknown processor! */
		Context.CPUsubstrate = CPU_UNKNOWN;


	_papi_freebsd_vector.cmp_info.num_native_events = freebsd_substrate_number_of_events (Context.CPUsubstrate);
	_papi_freebsd_vector.cmp_info.attach = 0;

{'fraction_non_alphanumeric': 0.13511925743155917, 'fraction_numerical': 0.009752085536364705, 'mean_word_length': 5.123741007194244, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 42, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6291687', 'n_tokens_mistral': 3518, 'n_tokens_neox': 3370, 'n_words': 742}