12#include <sys/resource.h>
13#include <sys/sysctl.h>
14#include <sys/utsname.h>
41 const char *function,
char *
file,
int line) {
44 pmc_value_t tmp_value;
45 int ret = pmc_read (
id, &tmp_value);
47 fprintf(
stderr,
"%s\n",
string);
49 fprintf (
stderr,
"DEBUG: Unable to read counter %s (ID: %08x) "
50 "on routine %s (file: %s, line: %d)\n",
53 fprintf (
stderr,
"DEBUG: Read counter %s (ID: %08x) - "
54 "value %llu on routine %s (file: %s, line: %d)\n",
55 name,
id, (
long long unsigned int)tmp_value,
56 function,
file, line);
59 (void)
string; (void)
name;
60 (void)
id; (void)function; (void)
file; (void)line;
78 const struct pmc_cpuinfo *info;
86 if (pmc_cpuinfo (&info) != 0)
98#if !defined(__i386__) && !defined(__amd64__)
106 Context.
use_rdtsc = sysctlnametomib (
"dev.cpufreq.0.%driver", mib, &len) == -1;
110 if (sysctlnametomib (
"hw.clockrate", mib, &len) == -1)
112 len =
sizeof(hw_clockrate);
113 if (sysctl (mib, 2, &hw_clockrate, &len, NULL, 0) == -1)
117 if (sysctlnametomib (
"hw.model", mib, &len) == -1)
120 if (sysctl (mib, 2, &hw_model, &len, NULL, 0) == -1)
137 if ( strstr(pmc_name_of_cputype(info->pm_cputype),
"INTEL"))
139 else if ( strstr(pmc_name_of_cputype(info->pm_cputype),
"AMD"))
142 fprintf(
stderr,
"We didn't actually find a supported vendor...\n\n\n");
153 const struct pmc_cpuinfo *info;
157 if (pmc_cpuinfo (&info) != 0)
162 if (strcmp(pmc_name_of_cputype(info->pm_cputype),
"INTEL_P6") == 0)
165 else if (strcmp(pmc_name_of_cputype(info->pm_cputype),
"INTEL_PII") == 0)
167 else if (strcmp(pmc_name_of_cputype(info->pm_cputype),
"INTEL_PIII") == 0)
169 else if (strcmp(pmc_name_of_cputype(info->pm_cputype),
"INTEL_CL") == 0)
171 else if (strcmp(pmc_name_of_cputype(info->pm_cputype),
"INTEL_PM") == 0)
173 else if (strcmp(pmc_name_of_cputype(info->pm_cputype),
"AMD_K7") == 0)
175 else if (strcmp(pmc_name_of_cputype(info->pm_cputype),
"AMD_K8") == 0)
177 else if (strcmp(pmc_name_of_cputype(info->pm_cputype),
"INTEL_PIV") == 0)
179 else if (strcmp(pmc_name_of_cputype(info->pm_cputype),
"INTEL_ATOM") == 0)
181 else if (strcmp(pmc_name_of_cputype(info->pm_cputype),
"INTEL_CORE") == 0)
183 else if (strcmp(pmc_name_of_cputype(info->pm_cputype),
"INTEL_CORE2") == 0)
185 else if (strcmp(pmc_name_of_cputype(info->pm_cputype),
"INTEL_CORE2EXTREME") == 0)
187 else if (strcmp(pmc_name_of_cputype(info->pm_cputype),
"INTEL_COREI7") == 0)
189 else if (strcmp(pmc_name_of_cputype(info->pm_cputype),
"INTEL_WESTMERE") == 0)
290 if (ptr->
pmcs != NULL)
294 if (ptr->
caps != NULL)
298 ptr->
pmcs = (pmc_id_t*) malloc (
sizeof(pmc_id_t)*
count);
299 ptr->
caps = (uint32_t*) malloc (
sizeof(uint32_t)*
count);
300 ptr->
values = (pmc_value_t*) malloc (
sizeof(pmc_value_t)*
count);
326 ptr->
counters[
i] = malloc ((strlen(
name)+strlen(
",usr")+1)*
sizeof(
char));
334 ptr->
counters[
i] = malloc ((strlen(
name)+strlen(
",os")+1)*
sizeof(
char));
361 if ((ret = pmc_allocate (ctrl->
counters[
i], PMC_MODE_TC, 0, PMC_CPU_ANY, &(ctrl->
pmcs[
i]))) < 0)
369 if ((ret = pmc_capabilities (ctrl->
pmcs[
i],&(ctrl->
caps[
i]))) < 0)
379 if ((ret = pmc_start (ctrl->
pmcs[
i])) < 0)
399 if ((ret = pmc_read (ctrl->
pmcs[
i], &(ctrl->
values[
i]))) < 0)
410 fprintf (
stderr,
"DEBUG: %s counter '%s' has value %lld\n",
425 if ((ret = pmc_stop (ctrl->
pmcs[
i])) < 0)
432 if ((ret = pmc_release (ctrl->
pmcs[
i])) < 0)
454 if (ctrl->
caps[
i] & PMC_CAP_WRITE)
457 "to stop the counter i+1",
459 __FUNCTION__,__FILE__,__LINE__);
461 if ((ret = pmc_stop (ctrl->
pmcs[
i])) < 0)
470 "DEBUG: _papi_freebsd_reset is about "
471 "to write the counter i+1\n",
473 __FUNCTION__,__FILE__,__LINE__);
475 if ((ret = pmc_write (ctrl->
pmcs[
i], 0)) < 0)
484 "start the counter %i+1",
486 __FUNCTION__,__FILE__,__LINE__);
488 if ((ret = pmc_start (ctrl->
pmcs[
i])) < 0)
497 "starting the counter i+1",
499 __FUNCTION__,__FILE__,__LINE__);
518 if (ctrl->
caps[
i] & PMC_CAP_WRITE)
520 if ((ret = pmc_stop (ctrl->
pmcs[
i])) < 0)
527 if ((ret = pmc_write (ctrl->
pmcs[
i], from[
i])) < 0)
534 if ((ret = pmc_start (ctrl->
pmcs[
i])) < 0)
653#if !defined(__i386__) && !defined(__amd64__)
658 if ((getrusage(RUSAGE_SELF, &res) == -1))
660 return (res.ru_utime.tv_sec * 1000000) + res.ru_utime.tv_usec;
670 if ((getrusage(RUSAGE_SELF, &res) == -1))
672 return (res.ru_utime.tv_sec * 1000000) + res.ru_utime.tv_usec;
681#if !defined(__i386__) && !defined(__amd64__)
690 __asm __volatile(
".byte 0x0f, 0x31" :
"=A" (cycles));
708 if ((getrusage(RUSAGE_SELF, &res) == -1))
710 return (res.ru_utime.tv_sec * 1000000) + res.ru_utime.tv_usec;
722 unsigned int nextCode = 1 + *EventCode;
739 *EventCode = nextCode;
811 int failed, allocated_counters,
i, j, ret;
817 pmcs = (pmc_id_t*) malloc(
sizeof(pmc_id_t)*ESI->
NativeCount);
820 allocated_counters = 0;
827 if ( (ret = pmc_allocate (
name, PMC_MODE_TC, 0, PMC_CPU_ANY, &pmcs[
i])) < 0)
840 allocated_counters++;
844 for (j = 0; j < allocated_counters; j++)
845 pmc_release (pmcs[j]);
870#if defined(__i386__)||defined(__x86_64__)
873 (void) virtual_vendor_name;
899 struct utsname uname_buffer;
904 uname(&uname_buffer);
924 .description =
"FreeBSD CPU counters",
931 .kernel_multiplex = 1,
933 .num_mpx_cntrs = HWPMC_NUM_COUNTERS,
937 .fast_real_timer = 1,
938 .fast_virtual_timer = 0,
940 .attach_must_ptrace = 0,
#define PAPI_VENDOR_INTEL
int _freebsd_get_memory_info(PAPI_hw_info_t *hw_info, int id)
int _papi_freebsd_get_dmem_info(PAPI_dmem_info_t *d)
int _papi_freebsd_ntv_code_to_descr(unsigned int EventCode, char *descr, int len)
int _papi_freebsd_ntv_code_to_name(unsigned int EventCode, char *ntv_name, int len)
int _papi_freebsd_get_system_info(papi_mdi_t *mdi)
void _papi_freebsd_dispatch_timer(int signal, hwd_siginfo_t *info, void *context)
int _papi_freebsd_shutdown_component(void)
int _papi_freebsd_set_profile(EventSetInfo_t *ESI, int EventIndex, int threashold)
int _papi_freebsd_write(hwd_context_t *ctx, hwd_control_state_t *ctrl, long long *from)
int _papi_freebsd_read(hwd_context_t *ctx, hwd_control_state_t *ctrl, long long **events, int flags)
int _papi_freebsd_allocate_registers(EventSetInfo_t *ESI)
int _papi_freebsd_update_shlib_info(papi_mdi_t *mdi)
int _papi_freebsd_ctl(hwd_context_t *ctx, int code, _papi_int_option_t *option)
int _papi_freebsd_init_thread(hwd_context_t *ctx)
int _papi_freebsd_update_control_state(hwd_control_state_t *ptr, NativeInfo_t *native, int count, hwd_context_t *ctx)
static void show_counter(char *string, int id, char *name, const char *function, char *file, int line)
int _papi_hwi_init_os(void)
int _papi_freebsd_shutdown_thread(hwd_context_t *ctx)
int _papi_freebsd_detect_hypervisor(char *virtual_vendor_name)
long long _papi_freebsd_get_real_usec(void)
papi_vector_t _papi_freebsd_vector
PAPI_os_info_t _papi_os_info
long long _papi_freebsd_get_virt_usec(void)
int _papi_freebsd_set_overflow(EventSetInfo_t *ESI, int EventIndex, int threshold)
int _papi_freebsd_set_domain(hwd_control_state_t *cntrl, int domain)
int _papi_freebsd_stop_profiling(ThreadInfo_t *master, EventSetInfo_t *ESI)
static hwd_libpmc_context_t Context
int _papi_freebsd_init_component(int cidx)
int _papi_freebsd_ntv_name_to_code(const char *name, unsigned int *event_code)
long long _papi_freebsd_get_real_cycles(void)
int _papi_freebsd_reset(hwd_context_t *ctx, hwd_control_state_t *ctrl)
int _papi_freebsd_ntv_enum_events(unsigned int *EventCode, int modifier)
int _papi_freebsd_stop(hwd_context_t *ctx, hwd_control_state_t *ctrl)
papi_os_vector_t _papi_os_vector
int _papi_freebsd_start(hwd_context_t *ctx, hwd_control_state_t *ctrl)
int init_presets(int cidx)
int _papi_freebsd_init_control_state(hwd_control_state_t *ptr)
char events[MAX_EVENTS][BUFSIZ]
void init_freebsd_libpmc_mappings(void)
Native_Event_Info_t _papi_hwd_native_info[CPU_LAST+1]
int freebsd_number_of_events(int processortype)
#define PAPI_NATIVE_AND_MASK
Return codes and api definitions.
#define SUBDBG(format, args...)
__sighandler_t signal(int __sig, __sighandler_t __handler) __attribute__((__nothrow__
#define PAPI_INT_MPX_SIGNAL
#define PAPI_INT_MPX_DEF_US
int _papi_load_preset_table(char *pmu_str, int pmu_type, int cidx)
papi_mdi_t _papi_hwi_system_info
hwd_control_state_t * ctl_state
NativeInfo_t * NativeInfoArray
Native_Event_LabelDescription_t * info
char name[PAPI_MAX_STR_LEN]
char vendor_string[PAPI_MAX_STR_LEN]
char virtual_vendor_string[PAPI_MAX_STR_LEN]
char model_string[PAPI_MAX_STR_LEN]
char version[PAPI_MAX_STR_LEN]
char name[PAPI_MAX_STR_LEN]
int(* get_dmem_info)(PAPI_dmem_info_t *)
PAPI_component_info_t cmp_info
_papi_int_domain_t domain
int _x86_detect_hypervisor(char *vendor_name)