PAPI 7.1.0.0
Loading...
Searching...
No Matches
freebsd.c File Reference
Include dependency graph for freebsd.c:

Go to the source code of this file.

Functions

long long _papi_freebsd_get_real_cycles (void)
 
int _papi_freebsd_ntv_code_to_name (unsigned int EventCode, char *ntv_name, int len)
 
static void show_counter (char *string, int id, char *name, const char *function, char *file, int line)
 
int init_mdi (void)
 
int init_presets (int cidx)
 
int _papi_freebsd_init_component (int cidx)
 
int _papi_freebsd_init_thread (hwd_context_t *ctx)
 
int _papi_freebsd_shutdown_thread (hwd_context_t *ctx)
 
int _papi_freebsd_shutdown_component (void)
 
int _papi_freebsd_init_control_state (hwd_control_state_t *ptr)
 
int _papi_freebsd_update_control_state (hwd_control_state_t *ptr, NativeInfo_t *native, int count, hwd_context_t *ctx)
 
int _papi_freebsd_start (hwd_context_t *ctx, hwd_control_state_t *ctrl)
 
int _papi_freebsd_read (hwd_context_t *ctx, hwd_control_state_t *ctrl, long long **events, int flags)
 
int _papi_freebsd_stop (hwd_context_t *ctx, hwd_control_state_t *ctrl)
 
int _papi_freebsd_reset (hwd_context_t *ctx, hwd_control_state_t *ctrl)
 
int _papi_freebsd_write (hwd_context_t *ctx, hwd_control_state_t *ctrl, long long *from)
 
void _papi_freebsd_dispatch_timer (int signal, hwd_siginfo_t *info, void *context)
 
int _papi_freebsd_stop_profiling (ThreadInfo_t *master, EventSetInfo_t *ESI)
 
int _papi_freebsd_set_overflow (EventSetInfo_t *ESI, int EventIndex, int threshold)
 
int _papi_freebsd_set_profile (EventSetInfo_t *ESI, int EventIndex, int threashold)
 
int _papi_freebsd_set_domain (hwd_control_state_t *cntrl, int domain)
 
int _papi_freebsd_ctl (hwd_context_t *ctx, int code, _papi_int_option_t *option)
 
long long _papi_freebsd_get_real_usec (void)
 
long long _papi_freebsd_get_virt_usec (void)
 
int _papi_freebsd_ntv_enum_events (unsigned int *EventCode, int modifier)
 
int _papi_freebsd_ntv_name_to_code (const char *name, unsigned int *event_code)
 
int _papi_freebsd_ntv_code_to_descr (unsigned int EventCode, char *descr, int len)
 
int _papi_freebsd_allocate_registers (EventSetInfo_t *ESI)
 
int _papi_freebsd_update_shlib_info (papi_mdi_t *mdi)
 
int _papi_freebsd_detect_hypervisor (char *virtual_vendor_name)
 
int _papi_freebsd_get_system_info (papi_mdi_t *mdi)
 
int _papi_hwi_init_os (void)
 

Variables

PAPI_os_info_t _papi_os_info
 
papi_vector_t _papi_freebsd_vector
 
static hwd_libpmc_context_t Context
 
papi_os_vector_t _papi_os_vector
 

Function Documentation

◆ _papi_freebsd_allocate_registers()

int _papi_freebsd_allocate_registers ( EventSetInfo_t ESI)

Definition at line 808 of file freebsd.c.

809{
810 char name[1024];
811 int failed, allocated_counters, i, j, ret;
812 pmc_id_t *pmcs;
813
814 SUBDBG("Entering\n");
815
816 failed = 0;
817 pmcs = (pmc_id_t*) malloc(sizeof(pmc_id_t)*ESI->NativeCount);
818 if (pmcs != NULL)
819 {
820 allocated_counters = 0;
821 /* Check if we can allocate all the counters needed */
822 for (i = 0; i < ESI->NativeCount; i++)
823 {
825 if (ret != PAPI_OK)
826 return ret;
827 if ( (ret = pmc_allocate (name, PMC_MODE_TC, 0, PMC_CPU_ANY, &pmcs[i])) < 0)
828 {
829#if defined(DEBUG)
830 fprintf (stderr, "DEBUG: %s FAILED to allocate '%s' (%#08x) [%d of %d] ERROR = %d\n", FUNC, name, ESI->NativeInfoArray[i].ni_event, i+1, ESI->NativeCount, ret);
831#endif
832 failed = 1;
833 break;
834 }
835 else
836 {
837#if defined(DEBUG)
838 fprintf (stderr, "DEBUG: %s SUCCEEDED allocating '%s' (%#08x) [%d of %d]\n", FUNC, name, ESI->NativeInfoArray[i].ni_event, i+1, ESI->NativeCount);
839#endif
840 allocated_counters++;
841 }
842 }
843 /* Free the counters */
844 for (j = 0; j < allocated_counters; j++)
845 pmc_release (pmcs[j]);
846 free (pmcs);
847 }
848 else
849 failed = 1;
850
851 return failed?PAPI_ECNFLCT:PAPI_OK;
852}
int i
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_ECNFLCT
Definition: f90papi.h:234
int _papi_freebsd_ntv_code_to_name(unsigned int EventCode, char *ntv_name, int len)
Definition: freebsd.c:763
#define FUNC
Definition: linux-pcp.c:36
#define SUBDBG(format, args...)
Definition: papi_debug.h:64
FILE * stderr
const char * name
Definition: rocs.c:225
NativeInfo_t * NativeInfoArray
Here is the call graph for this function:

◆ _papi_freebsd_ctl()

int _papi_freebsd_ctl ( hwd_context_t ctx,
int  code,
_papi_int_option_t option 
)

Definition at line 627 of file freebsd.c.

628{
629 (void)ctx;
630 SUBDBG("Entering\n");
631 switch (code)
632 {
633 case PAPI_DOMAIN:
634 case PAPI_DEFDOM:
635 /*return _papi_freebsd_set_domain(&option->domain.ESI->machdep, option->domain.domain);*/
636 return _papi_freebsd_set_domain(option->domain.ESI->ctl_state, option->domain.domain);
637 case PAPI_GRANUL:
638 case PAPI_DEFGRN:
639 return PAPI_ECMP;
640 default:
641 return PAPI_EINVAL;
642 }
643}
#define PAPI_DEFGRN
Definition: f90papi.h:26
#define PAPI_GRANUL
Definition: f90papi.h:179
#define PAPI_EINVAL
Definition: f90papi.h:115
#define PAPI_DOMAIN
Definition: f90papi.h:159
#define PAPI_ECMP
Definition: f90papi.h:214
#define PAPI_DEFDOM
Definition: f90papi.h:188
int _papi_freebsd_set_domain(hwd_control_state_t *cntrl, int domain)
Definition: freebsd.c:603
hwd_control_state_t * ctl_state
EventSetInfo_t * ESI
_papi_int_domain_t domain
Here is the call graph for this function:

◆ _papi_freebsd_detect_hypervisor()

int _papi_freebsd_detect_hypervisor ( char *  virtual_vendor_name)

Definition at line 866 of file freebsd.c.

866 {
867
868 int retval=0;
869
870#if defined(__i386__)||defined(__x86_64__)
871 retval=_x86_detect_hypervisor(virtual_vendor_name);
872#else
873 (void) virtual_vendor_name;
874#endif
875
876 return retval;
877}
int _x86_detect_hypervisor(char *vendor_name)
int retval
Definition: zero_fork.c:53
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _papi_freebsd_dispatch_timer()

void _papi_freebsd_dispatch_timer ( int  signal,
hwd_siginfo_t info,
void *  context 
)

Definition at line 551 of file freebsd.c.

552{
553 (void)signal;
554 (void)info;
555 (void)context;
556 /* Real function would call the function below with the proper args
557 * _papi_hwi_dispatch_overflow_signal(...);
558 */
559 SUBDBG("Entering\n");
560 return;
561}
__sighandler_t signal(int __sig, __sighandler_t __handler) __attribute__((__nothrow__
Here is the call graph for this function:

◆ _papi_freebsd_get_real_cycles()

long long _papi_freebsd_get_real_cycles ( void  )

Definition at line 678 of file freebsd.c.

679{
680 /* Hey, I've seen somewhere a define called __x86_64__! Should I support it? */
681#if !defined(__i386__) && !defined(__amd64__)
682 SUBDBG("Entering\n");
683 /* This will surely work, but with low precision and high overhead */
685#else
686 SUBDBG("Entering\n");
687 if (Context.use_rdtsc)
688 {
689 long long cycles;
690 __asm __volatile(".byte 0x0f, 0x31" : "=A" (cycles));
691 return cycles;
692 }
693 else
694 {
696 }
697#endif
698}
long long _papi_freebsd_get_real_usec(void)
Definition: freebsd.c:650
static hwd_libpmc_context_t Context
Definition: freebsd.c:65
papi_mdi_t _papi_hwi_system_info
Definition: papi_internal.c:56
int cpu_max_mhz
Definition: papi.h:790
PAPI_hw_info_t hw_info
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _papi_freebsd_get_real_usec()

long long _papi_freebsd_get_real_usec ( void  )

Definition at line 650 of file freebsd.c.

651{
652 /* Hey, I've seen somewhere a define called __x86_64__! Should I support it? */
653#if !defined(__i386__) && !defined(__amd64__)
654 /* This will surely work, but with low precision and high overhead */
655 struct rusage res;
656
657 SUBDBG("Entering\n");
658 if ((getrusage(RUSAGE_SELF, &res) == -1))
659 return PAPI_ESYS;
660 return (res.ru_utime.tv_sec * 1000000) + res.ru_utime.tv_usec;
661#else
662 SUBDBG("Entering\n");
663 if (Context.use_rdtsc)
664 {
666 }
667 else
668 {
669 struct rusage res;
670 if ((getrusage(RUSAGE_SELF, &res) == -1))
671 return PAPI_ESYS;
672 return (res.ru_utime.tv_sec * 1000000) + res.ru_utime.tv_usec;
673 }
674#endif
675}
#define PAPI_ESYS
Definition: f90papi.h:136
long long _papi_freebsd_get_real_cycles(void)
Definition: freebsd.c:678
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _papi_freebsd_get_system_info()

int _papi_freebsd_get_system_info ( papi_mdi_t mdi)

Definition at line 882 of file freebsd.c.

882 {
883
884 int retval;
885
887
888 /* Get virtualization info */
890
891
892 return PAPI_OK;
893
894}
int _freebsd_get_memory_info(PAPI_hw_info_t *hw_info, int id)
int _papi_freebsd_detect_hypervisor(char *virtual_vendor_name)
Definition: freebsd.c:866
int model
Definition: papi.h:783
char virtual_vendor_string[PAPI_MAX_STR_LEN]
Definition: papi.h:795
int virtualized
Definition: papi.h:794
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _papi_freebsd_get_virt_usec()

long long _papi_freebsd_get_virt_usec ( void  )

Definition at line 702 of file freebsd.c.

703{
704 struct rusage res;
705
706 SUBDBG("Entering\n");
707
708 if ((getrusage(RUSAGE_SELF, &res) == -1))
709 return PAPI_ESYS;
710 return (res.ru_utime.tv_sec * 1000000) + res.ru_utime.tv_usec;
711}

◆ _papi_freebsd_init_component()

int _papi_freebsd_init_component ( int  cidx)

Definition at line 213 of file freebsd.c.

214{
215 (void)cidx;
216
217 int retval;
218
219 SUBDBG("Entering\n");
220
221 /* Internal function, doesn't necessarily need to be a function */
223
224 return retval;
225}
int init_presets(int cidx)
Definition: freebsd.c:151
static int cidx
Here is the call graph for this function:

◆ _papi_freebsd_init_control_state()

int _papi_freebsd_init_control_state ( hwd_control_state_t ptr)

Definition at line 258 of file freebsd.c.

259{
260 /* We will default to gather counters in USER|KERNEL mode */
261 SUBDBG("Entering\n");
263 ptr->pmcs = NULL;
264 ptr->counters = NULL;
265 ptr->n_counters = 0;
266 return PAPI_OK;
267}
#define PAPI_DOM_USER
Definition: f90papi.h:174
#define PAPI_DOM_KERNEL
Definition: f90papi.h:254
char ** counters
Definition: freebsd.h:59
pmc_id_t * pmcs
Definition: freebsd.h:57

◆ _papi_freebsd_init_thread()

int _papi_freebsd_init_thread ( hwd_context_t ctx)

Definition at line 233 of file freebsd.c.

234{
235 (void)ctx;
236 SUBDBG("Entering\n");
237 return PAPI_OK;
238}

◆ _papi_freebsd_ntv_code_to_descr()

int _papi_freebsd_ntv_code_to_descr ( unsigned int  EventCode,
char *  descr,
int  len 
)

Definition at line 784 of file freebsd.c.

785{
786 SUBDBG("Entering\n");
787 int nidx;
788
789 nidx = EventCode & PAPI_NATIVE_AND_MASK;
791 return PAPI_ENOEVNT;
792 }
793
795 if (strlen(_papi_hwd_native_info[Context.CPUtype].info[nidx].description) > (size_t)len-1) {
796 return PAPI_EBUF;
797 }
798 return PAPI_OK;
799}
#define PAPI_ENOEVNT
Definition: f90papi.h:139
#define PAPI_EBUF
Definition: f90papi.h:253
papi_vector_t _papi_freebsd_vector
Definition: freebsd.c:33
Native_Event_Info_t _papi_hwd_native_info[CPU_LAST+1]
Definition: map.c:17
#define PAPI_NATIVE_AND_MASK
Native_Event_LabelDescription_t * info
Definition: map.h:47
PAPI_component_info_t cmp_info
Definition: papi_vector.h:20
char * descr

◆ _papi_freebsd_ntv_code_to_name()

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

Definition at line 763 of file freebsd.c.

765{
766 SUBDBG("Entering\n");
767
768 int nidx;
769
770 nidx = EventCode & PAPI_NATIVE_AND_MASK;
771
773 return PAPI_ENOEVNT;
774 }
775
776 strncpy (ntv_name,
778 if (strlen(_papi_hwd_native_info[Context.CPUtype].info[nidx].name) > (size_t)len-1) {
779 return PAPI_EBUF;
780 }
781 return PAPI_OK;
782}
Here is the caller graph for this function:

◆ _papi_freebsd_ntv_enum_events()

int _papi_freebsd_ntv_enum_events ( unsigned int EventCode,
int  modifier 
)

Definition at line 718 of file freebsd.c.

719{
720 int res;
721 char name[1024];
722 unsigned int nextCode = 1 + *EventCode;
723
724 SUBDBG("Entering\n");
725
726 if (modifier==PAPI_ENUM_FIRST) {
727
728 *EventCode=0;
729
730 return PAPI_OK;
731 }
732
733 if (modifier==PAPI_ENUM_EVENTS) {
734
735 res = _papi_freebsd_ntv_code_to_name(nextCode, name, sizeof(name));
736 if (res != PAPI_OK) {
737 return res;
738 } else {
739 *EventCode = nextCode;
740 }
741 return PAPI_OK;
742 }
743
744 return PAPI_ENOEVNT;
745
746}
#define PAPI_ENUM_EVENTS
Definition: f90papi.h:224
#define PAPI_ENUM_FIRST
Definition: f90papi.h:85
Here is the call graph for this function:

◆ _papi_freebsd_ntv_name_to_code()

int _papi_freebsd_ntv_name_to_code ( const char *  name,
unsigned int event_code 
)

Definition at line 748 of file freebsd.c.

748 {
749
750 SUBDBG("Entering\n");
751
752 int i;
753
755 if (strcmp (name, _papi_hwd_native_info[Context.CPUtype].info[i].name) == 0) {
756 *event_code = i;
757 return PAPI_OK;
758 }
759 }
760 return PAPI_ENOEVNT;
761}

◆ _papi_freebsd_read()

int _papi_freebsd_read ( hwd_context_t ctx,
hwd_control_state_t ctrl,
long long **  events,
int  flags 
)

Definition at line 390 of file freebsd.c.

391{
392 int i, ret;
393 (void)ctx;
394 (void)flags;
395
396 SUBDBG("Entering\n");
397
398 for (i = 0; i < ctrl->n_counters; i++)
399 if ((ret = pmc_read (ctrl->pmcs[i], &(ctrl->values[i]))) < 0)
400 {
401#if defined(DEBUG)
402 fprintf (stderr, "DEBUG: %s FAILED to read '%s' [%d of %d] ERROR = %d\n", FUNC, ctrl->counters[i], i+1, ctrl->n_counters, ret);
403#endif
404 return PAPI_ESYS;
405 }
406 *events = (long long *)ctrl->values;
407
408#if defined(DEBUG)
409 for (i = 0; i < ctrl->n_counters; i++)
410 fprintf (stderr, "DEBUG: %s counter '%s' has value %lld\n",
411 FUNC, ctrl->counters[i], (long long)ctrl->values[i]);
412#endif
413 return PAPI_OK;
414}
char events[MAX_EVENTS][BUFSIZ]
pmc_value_t * values
Definition: freebsd.h:58

◆ _papi_freebsd_reset()

int _papi_freebsd_reset ( hwd_context_t ctx,
hwd_control_state_t ctrl 
)

Definition at line 444 of file freebsd.c.

445{
446 int i, ret;
447 (void)ctx;
448
449 SUBDBG("Entering\n");
450
451 for (i = 0; i < ctrl->n_counters; i++)
452 {
453 /* Can we write on the counters? */
454 if (ctrl->caps[i] & PMC_CAP_WRITE)
455 {
456 show_counter("DEBUG: _papi_freebsd_reset is about "
457 "to stop the counter i+1",
458 ctrl->pmcs[i],ctrl->counters[i],
459 __FUNCTION__,__FILE__,__LINE__);
460
461 if ((ret = pmc_stop (ctrl->pmcs[i])) < 0)
462 {
463#if defined(DEBUG)
464 fprintf (stderr, "DEBUG: %s FAILED to stop '%s' [%d of %d] ERROR = %d\n", FUNC, ctrl->counters[i], i+1, ctrl->n_counters, ret);
465#endif
466 return PAPI_ESYS;
467 }
468
470 "DEBUG: _papi_freebsd_reset is about "
471 "to write the counter i+1\n",
472 ctrl->pmcs[i],ctrl->counters[i],
473 __FUNCTION__,__FILE__,__LINE__);
474
475 if ((ret = pmc_write (ctrl->pmcs[i], 0)) < 0)
476 {
477#if defined(DEBUG)
478 fprintf (stderr, "DEBUG: %s FAILED to write '%s' [%d of %d] ERROR = %d\n", FUNC, ctrl->counters[i], i+1, ctrl->n_counters, ret);
479#endif
480 return PAPI_ESYS;
481 }
482
483 show_counter("DEBUG: _papi_freebsd_reset is about to "
484 "start the counter %i+1",
485 ctrl->pmcs[i],ctrl->counters[i],
486 __FUNCTION__,__FILE__,__LINE__);
487
488 if ((ret = pmc_start (ctrl->pmcs[i])) < 0)
489 {
490#if defined(DEBUG)
491 fprintf (stderr, "DEBUG: %s FAILED to start '%s' [%d of %d] ERROR = %d\n", FUNC, ctrl->counters[i], i+1, ctrl->n_counters, ret);
492#endif
493 return PAPI_ESYS;
494 }
495
496 show_counter("DEBUG: _papi_freebsd_reset after "
497 "starting the counter i+1",
498 ctrl->pmcs[i],ctrl->counters[i],
499 __FUNCTION__,__FILE__,__LINE__);
500
501 }
502 else
503 return PAPI_ECMP;
504 }
505 return PAPI_OK;
506}
static void show_counter(char *string, int id, char *name, const char *function, char *file, int line)
Definition: freebsd.c:40
unsigned * caps
Definition: freebsd.h:56
Here is the call graph for this function:

◆ _papi_freebsd_set_domain()

int _papi_freebsd_set_domain ( hwd_control_state_t cntrl,
int  domain 
)

Definition at line 603 of file freebsd.c.

604{
605 int found = 0;
606
607 SUBDBG("Entering\n");
608 /* libpmc supports USER/KERNEL mode only when counters are native */
610 {
611 if (domain & (PAPI_DOM_USER|PAPI_DOM_KERNEL))
612 {
613 cntrl->hwc_domain = domain & (PAPI_DOM_USER|PAPI_DOM_KERNEL);
614 found = 1;
615 }
616 return found?PAPI_OK:PAPI_EINVAL;
617 }
618 else
619 return PAPI_ECMP;
620}
@ CPU_UNKNOWN
Definition: map.h:20
Here is the caller graph for this function:

◆ _papi_freebsd_set_overflow()

int _papi_freebsd_set_overflow ( EventSetInfo_t ESI,
int  EventIndex,
int  threshold 
)

Definition at line 571 of file freebsd.c.

572{
573 (void)ESI;
574 (void)EventIndex;
575 (void)threshold;
576 SUBDBG("Entering\n");
577 return PAPI_OK;
578}
static int threshold

◆ _papi_freebsd_set_profile()

int _papi_freebsd_set_profile ( EventSetInfo_t ESI,
int  EventIndex,
int  threashold 
)

Definition at line 580 of file freebsd.c.

581{
582 (void)ESI;
583 (void)EventIndex;
584 (void)threashold;
585 SUBDBG("Entering\n");
586 return PAPI_OK;
587}

◆ _papi_freebsd_shutdown_component()

int _papi_freebsd_shutdown_component ( void  )

Definition at line 247 of file freebsd.c.

248{
249 SUBDBG("Entering\n");
250 return PAPI_OK;
251}

◆ _papi_freebsd_shutdown_thread()

int _papi_freebsd_shutdown_thread ( hwd_context_t ctx)

Definition at line 240 of file freebsd.c.

241{
242 (void)ctx;
243 SUBDBG("Entering\n");
244 return PAPI_OK;
245}

◆ _papi_freebsd_start()

int _papi_freebsd_start ( hwd_context_t ctx,
hwd_control_state_t ctrl 
)

Definition at line 352 of file freebsd.c.

353{
354 int i, ret;
355 (void)ctx;
356
357 SUBDBG("Entering\n");
358
359 for (i = 0; i < ctrl->n_counters; i++)
360 {
361 if ((ret = pmc_allocate (ctrl->counters[i], PMC_MODE_TC, 0, PMC_CPU_ANY, &(ctrl->pmcs[i]))) < 0)
362 {
363#if defined(DEBUG)
364 /* This shouldn't happen, it's tested previously on _papi_freebsd_allocate_registers */
365 fprintf (stderr, "DEBUG: %s FAILED to allocate '%s' [%d of %d] ERROR = %d\n", FUNC, ctrl->counters[i], i+1, ctrl->n_counters, ret);
366#endif
367 return PAPI_ESYS;
368 }
369 if ((ret = pmc_capabilities (ctrl->pmcs[i],&(ctrl->caps[i]))) < 0)
370 {
371#if defined(DEBUG)
372 fprintf (stderr, "DEBUG: %s FAILED to get capabilites for '%s' [%d of %d] ERROR = %d\n", FUNC, ctrl->counters[i], i+1, ctrl->n_counters, ret);
373#endif
374 ctrl->caps[i] = 0;
375 }
376#if defined(DEBUG)
377 fprintf (stderr, "DEBUG: %s got counter '%s' is %swrittable! [%d of %d]\n", FUNC, ctrl->counters[i], (ctrl->caps[i]&PMC_CAP_WRITE)?"":"NOT", i+1, ctrl->n_counters);
378#endif
379 if ((ret = pmc_start (ctrl->pmcs[i])) < 0)
380 {
381#if defined(DEBUG)
382 fprintf (stderr, "DEBUG: %s FAILED to start '%s' [%d of %d] ERROR = %d\n", FUNC, ctrl->counters[i], i+1, ctrl->n_counters, ret);
383#endif
384 return PAPI_ESYS;
385 }
386 }
387 return PAPI_OK;
388}

◆ _papi_freebsd_stop()

int _papi_freebsd_stop ( hwd_context_t ctx,
hwd_control_state_t ctrl 
)

Definition at line 416 of file freebsd.c.

417{
418 int i, ret;
419 (void)ctx;
420
421 SUBDBG("Entering\n");
422
423 for (i = 0; i < ctrl->n_counters; i++)
424 {
425 if ((ret = pmc_stop (ctrl->pmcs[i])) < 0)
426 {
427#if defined(DEBUG)
428 fprintf (stderr, "DEBUG: %s FAILED to stop '%s' [%d of %d] ERROR = %d\n", FUNC, ctrl->counters[i], i+1, ctrl->n_counters, ret);
429#endif
430 return PAPI_ESYS;
431 }
432 if ((ret = pmc_release (ctrl->pmcs[i])) < 0)
433 {
434#if defined(DEBUG)
435 /* This shouldn't happen, it's tested previously on _papi_freebsd_allocate_registers */
436 fprintf (stderr, "DEBUG: %s FAILED to release '%s' [%d of %d] ERROR = %d\n", FUNC, ctrl->counters[i], i+1, ctrl->n_counters, ret);
437#endif
438 return PAPI_ESYS;
439 }
440 }
441 return PAPI_OK;
442}

◆ _papi_freebsd_stop_profiling()

int _papi_freebsd_stop_profiling ( ThreadInfo_t master,
EventSetInfo_t ESI 
)

Definition at line 563 of file freebsd.c.

564{
565 (void)master;
566 (void)ESI;
567 SUBDBG("Entering\n");
568 return PAPI_OK;
569}

◆ _papi_freebsd_update_control_state()

int _papi_freebsd_update_control_state ( hwd_control_state_t ptr,
NativeInfo_t native,
int  count,
hwd_context_t ctx 
)

Definition at line 269 of file freebsd.c.

270{
271 char name[1024];
272 int i;
273 int res;
274 (void)ctx;
275
276 SUBDBG("Entering\n");
277
278 /* We're going to store which counters are being used in this EventSet.
279 As this ptr structure can be reused within many PAPI_add_event calls,
280 and domain can change we will reconstruct the table of counters
281 (ptr->counters) everytime where here.
282 */
283 if (ptr->counters != NULL && ptr->n_counters > 0)
284 {
285 for (i = 0; i < ptr->n_counters; i++)
286 if (ptr->counters[i] != NULL)
287 free (ptr->counters[i]);
288 free (ptr->counters);
289 }
290 if (ptr->pmcs != NULL)
291 free (ptr->pmcs);
292 if (ptr->values != NULL)
293 free (ptr->values);
294 if (ptr->caps != NULL)
295 free (ptr->caps);
296
297 ptr->n_counters = count;
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);
301 ptr->counters = (char **) malloc (sizeof(char*)*count);
302 for (i = 0; i < count; i++)
303 ptr->counters[i] = NULL;
304
305 for (i = 0; i < count; i++)
306 {
307 res = _papi_freebsd_ntv_code_to_name (native[i].ni_event, name, sizeof(name));
308 if (res != PAPI_OK)
309 return res;
310
311 native[i].ni_position = i;
312
313 /* Domains can be applied to canonical events in libpmc (not "generic") */
315 {
317 {
318 /* PMC defaults domain to OS & User. So simply copy the name of the counter */
319 ptr->counters[i] = strdup (name);
320 if (ptr->counters[i] == NULL)
321 return PAPI_ESYS;
322 }
323 else if (ptr->hwc_domain == PAPI_DOM_USER)
324 {
325 /* This is user-domain case. Just add unitmask=usr */
326 ptr->counters[i] = malloc ((strlen(name)+strlen(",usr")+1)*sizeof(char));
327 if (ptr->counters[i] == NULL)
328 return PAPI_ESYS;
329 sprintf (ptr->counters[i], "%s,usr", name);
330 }
331 else /* if (ptr->hwc_domain == PAPI_DOM_KERNEL) */
332 {
333 /* This is the last case. Just add unitmask=os */
334 ptr->counters[i] = malloc ((strlen(name)+strlen(",os")+1)*sizeof(char));
335 if (ptr->counters[i] == NULL)
336 return PAPI_ESYS;
337 sprintf (ptr->counters[i], "%s,os", name);
338 }
339 }
340 else
341 {
342 /* PMC defaults domain to OS & User. So simply copy the name of the counter */
343 ptr->counters[i] = strdup (name);
344 if (ptr->counters[i] == NULL)
345 return PAPI_ESYS;
346 }
347 }
348
349 return PAPI_OK;
350}
static long count
static int native
Here is the call graph for this function:

◆ _papi_freebsd_update_shlib_info()

int _papi_freebsd_update_shlib_info ( papi_mdi_t mdi)

Definition at line 857 of file freebsd.c.

857 {
858 SUBDBG("Entering\n");
859 (void)mdi;
860 return PAPI_OK;
861}

◆ _papi_freebsd_write()

int _papi_freebsd_write ( hwd_context_t ctx,
hwd_control_state_t ctrl,
long long from 
)

Definition at line 508 of file freebsd.c.

509{
510 int i, ret;
511 (void)ctx;
512
513 SUBDBG("Entering\n");
514
515 for (i = 0; i < ctrl->n_counters; i++)
516 {
517 /* Can we write on the counters? */
518 if (ctrl->caps[i] & PMC_CAP_WRITE)
519 {
520 if ((ret = pmc_stop (ctrl->pmcs[i])) < 0)
521 {
522#if defined(DEBUG)
523 fprintf (stderr, "DEBUG: %s FAILED to stop '%s' [%d of %d] ERROR = %d\n", FUNC, ctrl->counters[i], i+1, ctrl->n_counters, ret);
524#endif
525 return PAPI_ESYS;
526 }
527 if ((ret = pmc_write (ctrl->pmcs[i], from[i])) < 0)
528 {
529#if defined(DEBUG)
530 fprintf (stderr, "DEBUG: %s FAILED to write '%s' [%d of %d] ERROR = %d\n", FUNC, ctrl->counters[i], i+1, ctrl->n_counters, ret);
531#endif
532 return PAPI_ESYS;
533 }
534 if ((ret = pmc_start (ctrl->pmcs[i])) < 0)
535 {
536#if defined(DEBUG)
537 fprintf (stderr, "DEBUG: %s FAILED to stop '%s' [%d of %d] ERROR = %d\n", FUNC, ctrl->counters[i], i+1, ctrl->n_counters, ret);
538#endif
539 return PAPI_ESYS;
540 }
541 }
542 else
543 return PAPI_ECMP;
544 }
545 return PAPI_OK;
546}

◆ _papi_hwi_init_os()

int _papi_hwi_init_os ( void  )

Definition at line 897 of file freebsd.c.

897 {
898
899 struct utsname uname_buffer;
900
901 /* Internal function, doesn't necessarily need to be a function */
902 init_mdi();
903
904 uname(&uname_buffer);
905
906 strncpy(_papi_os_info.name,uname_buffer.sysname,PAPI_MAX_STR_LEN);
907
908 strncpy(_papi_os_info.version,uname_buffer.release,PAPI_MAX_STR_LEN);
909
912 _papi_os_info.itimer_ns = PAPI_INT_MPX_DEF_US * 1000; /* Not actually supported */
914
916
917 return PAPI_OK;
918}
#define PAPI_MAX_STR_LEN
Definition: f90papi.h:77
int _papi_freebsd_get_system_info(papi_mdi_t *mdi)
Definition: freebsd.c:882
int init_mdi(void)
Definition: freebsd.c:76
PAPI_os_info_t _papi_os_info
Definition: freebsd.c:30
#define PAPI_INT_MPX_SIGNAL
Definition: papi_internal.h:51
#define PAPI_INT_MPX_DEF_US
Definition: papi_internal.h:64
#define PAPI_INT_ITIMER
Definition: papi_internal.h:53
char version[PAPI_MAX_STR_LEN]
char name[PAPI_MAX_STR_LEN]
Here is the call graph for this function:

◆ init_mdi()

int init_mdi ( void  )

Definition at line 76 of file freebsd.c.

77{
78 const struct pmc_cpuinfo *info;
79
80 SUBDBG("Entering\n");
81
82 /* Initialize PMC library */
83 if (pmc_init() < 0)
84 return PAPI_ESYS;
85
86 if (pmc_cpuinfo (&info) != 0)
87 return PAPI_ESYS;
88
89 if (info != NULL)
90 {
91 /* Get CPU clock rate from HW.CLOCKRATE sysctl value, and
92 MODEL from HW.MODEL */
93 int mib[5];
94 size_t len;
95 int hw_clockrate;
96 char hw_model[PAPI_MAX_STR_LEN];
97
98#if !defined(__i386__) && !defined(__amd64__)
100#else
101 /* Ok, I386s/AMD64s can use RDTSC. But be careful, if the cpufreq
102 module is loaded, then CPU frequency can vary and this method
103 does not work properly! We'll use use_rdtsc to know if this
104 method is available */
105 len = 5;
106 Context.use_rdtsc = sysctlnametomib ("dev.cpufreq.0.%driver", mib, &len) == -1;
107#endif
108
109 len = 3;
110 if (sysctlnametomib ("hw.clockrate", mib, &len) == -1)
111 return PAPI_ESYS;
112 len = sizeof(hw_clockrate);
113 if (sysctl (mib, 2, &hw_clockrate, &len, NULL, 0) == -1)
114 return PAPI_ESYS;
115
116 len = 3;
117 if (sysctlnametomib ("hw.model", mib, &len) == -1)
118 return PAPI_ESYS;
119 len = PAPI_MAX_STR_LEN;
120 if (sysctl (mib, 2, &hw_model, &len, NULL, 0) == -1)
121 return PAPI_ESYS;
122
123 /*strcpy (_papi_hwi_system_info.hw_info.vendor_string, pmc_name_of_cputype(info->pm_cputype));*/
124 sprintf (_papi_hwi_system_info.hw_info.vendor_string, "%s (TSC:%c)", pmc_name_of_cputype(info->pm_cputype), Context.use_rdtsc?'Y':'N');
125 strcpy (_papi_hwi_system_info.hw_info.model_string, hw_model);
126 _papi_hwi_system_info.hw_info.mhz = (float) hw_clockrate;
129 _papi_hwi_system_info.hw_info.ncpu = info->pm_ncpu;
132 /* Right now, PMC states that TSC is an additional counter. However
133 it's only available as a system-wide counter and this requires
134 root access */
135 _papi_freebsd_vector.cmp_info.num_cntrs = info->pm_npmc - 1;
136
137 if ( strstr(pmc_name_of_cputype(info->pm_cputype), "INTEL"))
139 else if ( strstr(pmc_name_of_cputype(info->pm_cputype), "AMD"))
141 else
142 fprintf(stderr,"We didn't actually find a supported vendor...\n\n\n");
143 }
144 else
145 return PAPI_ESYS;
146
147 return 1;
148}
#define FALSE
#define PAPI_VENDOR_INTEL
Definition: f90papi.h:275
#define PAPI_VENDOR_AMD
Definition: f90papi.h:230
if(file==NULL) goto out
char vendor_string[PAPI_MAX_STR_LEN]
Definition: papi.h:782
float mhz
Definition: papi.h:801
int nnodes
Definition: papi.h:779
int totalcpus
Definition: papi.h:780
int vendor
Definition: papi.h:781
int cpu_min_mhz
Definition: papi.h:791
int ncpu
Definition: papi.h:775
char model_string[PAPI_MAX_STR_LEN]
Definition: papi.h:784
Here is the call graph for this function:
Here is the caller graph for this function:

◆ init_presets()

int init_presets ( int  cidx)

Definition at line 151 of file freebsd.c.

152{
153 const struct pmc_cpuinfo *info;
154
155 SUBDBG("Entering\n");
156
157 if (pmc_cpuinfo (&info) != 0)
158 return PAPI_ESYS;
159
161
162 if (strcmp(pmc_name_of_cputype(info->pm_cputype), "INTEL_P6") == 0)
164
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)
191 else
192 /* Unknown processor! */
194
195
198
199 _papi_load_preset_table((char *)pmc_name_of_cputype(info->pm_cputype),
200 0,cidx);
201
202 return 0;
203}
void init_freebsd_libpmc_mappings(void)
Definition: map.c:19
int freebsd_number_of_events(int processortype)
Definition: map.c:40
@ CPU_K7
Definition: map.h:27
@ CPU_P6
Definition: map.h:21
@ CPU_P6_2
Definition: map.h:23
@ CPU_COREWESTMERE
Definition: map.h:34
@ CPU_P6_3
Definition: map.h:24
@ CPU_P6_M
Definition: map.h:25
@ CPU_CORE
Definition: map.h:30
@ CPU_CORE2
Definition: map.h:31
@ CPU_P6_C
Definition: map.h:22
@ CPU_ATOM
Definition: map.h:29
@ CPU_K8
Definition: map.h:28
@ CPU_CORE2EXTREME
Definition: map.h:32
@ CPU_P4
Definition: map.h:26
@ CPU_COREI7
Definition: map.h:33
int _papi_load_preset_table(char *pmu_str, int pmu_type, int cidx)
Definition: papi_preset.c:771
unsigned int attach
Definition: papi.h:658
Here is the call graph for this function:
Here is the caller graph for this function:

◆ show_counter()

static void show_counter ( char *  string,
int  id,
char *  name,
const char *  function,
char *  file,
int  line 
)
static

Definition at line 40 of file freebsd.c.

41 {
42
43#if defined(DEBUG)
44 pmc_value_t tmp_value;
45 int ret = pmc_read (id, &tmp_value);
46
47 fprintf(stderr,"%s\n",string);
48 if (ret < 0) {
49 fprintf (stderr, "DEBUG: Unable to read counter %s (ID: %08x) "
50 "on routine %s (file: %s, line: %d)\n",
51 name, id, function,file,line);
52 } else {
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);
57 }
58#else
59 (void) string; (void)name;
60 (void)id; (void)function; (void)file; (void)line;
61#endif
62}
const char FILE * file
Definition: pscanf.h:13
Here is the caller graph for this function:

Variable Documentation

◆ _papi_freebsd_vector

papi_vector_t _papi_freebsd_vector

Definition at line 33 of file freebsd.c.

◆ _papi_os_info

PAPI_os_info_t _papi_os_info

Definition at line 30 of file freebsd.c.

◆ _papi_os_vector

papi_os_vector_t _papi_os_vector
Initial value:
= {
.get_dmem_info = _papi_freebsd_get_dmem_info,
.get_real_cycles = _papi_freebsd_get_real_cycles,
.get_real_usec = _papi_freebsd_get_real_usec,
.get_virt_usec = _papi_freebsd_get_virt_usec,
.update_shlib_info = _papi_freebsd_update_shlib_info,
.get_system_info = _papi_freebsd_get_system_info,
}
int _papi_freebsd_get_dmem_info(PAPI_dmem_info_t *d)
int _papi_freebsd_update_shlib_info(papi_mdi_t *mdi)
Definition: freebsd.c:857
long long _papi_freebsd_get_virt_usec(void)
Definition: freebsd.c:702

Definition at line 976 of file freebsd.c.

◆ Context

hwd_libpmc_context_t Context
static

Definition at line 65 of file freebsd.c.