PAPI  5.3.2.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
perfctr.c File Reference
Include dependency graph for perfctr.c:

Go to the source code of this file.

Macros

#define FOPEN_ERROR   "fopen(%s) returned NULL"
 
#define PERFCTR_CPU_NAME   perfctr_cpu_name
 
#define PERFCTR_CPU_NRCTRS   perfctr_cpu_nrctrs
 
#define OVERFLOW_MASK   si->si_pmc_ovf_mask
 
#define GEN_OVERFLOW   0
 

Functions

static int xlate_cpu_type_to_vendor (unsigned perfctr_cpu_type)
 
int _perfctr_init_component (int cidx)
 
static int attach (hwd_control_state_t *ctl, unsigned long tid)
 
static int detach (hwd_control_state_t *ctl)
 
static int round_requested_ns (int ns)
 
int _perfctr_ctl (hwd_context_t *ctx, int code, _papi_int_option_t *option)
 
void _perfctr_dispatch_timer (int signal, siginfo_t *si, void *context)
 
int _perfctr_init_thread (hwd_context_t *ctx)
 
int _perfctr_shutdown_thread (hwd_context_t *ctx)
 

Variables

papi_vector_t _perfctr_vector
 
long long tb_scale_factor = ( long long ) 1
 

Macro Definition Documentation

#define FOPEN_ERROR   "fopen(%s) returned NULL"

Definition at line 43 of file perfctr.c.

#define GEN_OVERFLOW   0
#define OVERFLOW_MASK   si->si_pmc_ovf_mask
#define PERFCTR_CPU_NAME   perfctr_cpu_name

Definition at line 49 of file perfctr.c.

#define PERFCTR_CPU_NRCTRS   perfctr_cpu_nrctrs

Definition at line 50 of file perfctr.c.

Function Documentation

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

Definition at line 289 of file perfctr.c.

290 {
291  ( void ) ctx; /*unused */
292  switch ( code ) {
293  case PAPI_DOMAIN:
294  case PAPI_DEFDOM:
295 #if defined(PPC64)
296  return ( _perfctr_vector.
297  set_domain( option->domain.ESI, option->domain.domain ) );
298 #else
299  return ( _perfctr_vector.
300  set_domain( option->domain.ESI->ctl_state,
301  option->domain.domain ) );
302 #endif
303  case PAPI_GRANUL:
304  case PAPI_DEFGRN:
305  return PAPI_ECMP;
306  case PAPI_ATTACH:
307  return ( attach( option->attach.ESI->ctl_state, option->attach.tid ) );
308  case PAPI_DETACH:
309  return ( detach( option->attach.ESI->ctl_state ) );
310  case PAPI_DEF_ITIMER:
311  {
312  /* flags are currently ignored, eventually the flags will be able
313  to specify whether or not we use POSIX itimers (clock_gettimer) */
314  if ( ( option->itimer.itimer_num == ITIMER_REAL ) &&
315  ( option->itimer.itimer_sig != SIGALRM ) )
316  return PAPI_EINVAL;
317  if ( ( option->itimer.itimer_num == ITIMER_VIRTUAL ) &&
318  ( option->itimer.itimer_sig != SIGVTALRM ) )
319  return PAPI_EINVAL;
320  if ( ( option->itimer.itimer_num == ITIMER_PROF ) &&
321  ( option->itimer.itimer_sig != SIGPROF ) )
322  return PAPI_EINVAL;
323  if ( option->itimer.ns > 0 )
324  option->itimer.ns = round_requested_ns( option->itimer.ns );
325  /* At this point, we assume the user knows what he or
326  she is doing, they maybe doing something arch specific */
327  return PAPI_OK;
328  }
329  case PAPI_DEF_MPX_NS:
330  {
331  option->multiplex.ns =
332  ( unsigned long ) round_requested_ns( ( int ) option->multiplex.
333  ns );
334  return ( PAPI_OK );
335  }
336  case PAPI_DEF_ITIMER_NS:
337  {
338  option->itimer.ns = round_requested_ns( option->itimer.ns );
339  return ( PAPI_OK );
340  }
341  default:
342  return ( PAPI_ENOSUPP );
343  }
344 }
static int round_requested_ns(int ns)
Definition: perfctr.c:278
EventSetInfo_t * ESI
#define PAPI_DEF_ITIMER_NS
Definition: papi.h:453
int ns
Definition: iozone.c:20358
return PAPI_OK
Definition: linux-nvml.c:458
void
Definition: iozone.c:18627
return PAPI_EINVAL
Definition: linux-nvml.c:408
_papi_int_itimer_t itimer
_papi_int_attach_t attach
unsigned long tid
#define PAPI_ENOSUPP
Definition: fpapi.h:123
static int set_domain(hwd_control_state_t *cntrl, unsigned int domain)
#define PAPI_ECMP
Definition: fpapi.h:109
#define PAPI_DEFDOM
Definition: fpapi.h:49
papi_vector_t _perfctr_vector
Definition: perfctr-x86.c:1163
long long
Definition: iozone.c:19827
EventSetInfo_t * ESI
#define PAPI_DOMAIN
Definition: fpapi.h:50
#define PAPI_ATTACH
Definition: fpapi.h:62
#define PAPI_DEFGRN
Definition: fpapi.h:51
#define PAPI_GRANUL
Definition: fpapi.h:52
_papi_int_multiplex_t multiplex
#define PAPI_DEF_MPX_NS
Definition: fpapi.h:53
#define PAPI_DETACH
Definition: fpapi.h:66
#define PAPI_DEF_ITIMER
Definition: papi.h:452
_papi_int_domain_t domain
static int attach(hwd_control_state_t *ctl, unsigned long tid)
Definition: perfctr.c:242
hwd_control_state_t * ctl_state
static int detach(hwd_control_state_t *ctl)
Definition: perfctr.c:271

Here is the call graph for this function:

void _perfctr_dispatch_timer ( int  signal,
siginfo_t *  si,
void context 
)

Definition at line 347 of file perfctr.c.

348 {
349  ( void ) signal; /*unused */
351  ThreadInfo_t *master = NULL;
352  int isHardware = 0;
353  caddr_t address;
355  hwd_context_t *our_context;
356 
357  ctx.si = si;
358  ctx.ucontext = ( ucontext_t * ) context;
359 
360 #define OVERFLOW_MASK si->si_pmc_ovf_mask
361 #define GEN_OVERFLOW 0
362 
363  address = ( caddr_t ) GET_OVERFLOW_ADDRESS( ( ctx ) );
364  _papi_hwi_dispatch_overflow_signal( ( void * ) &ctx, address, &isHardware,
365  OVERFLOW_MASK, GEN_OVERFLOW, &master,
367 
368  /* We are done, resume interrupting counters */
369  if ( isHardware ) {
370  our_context=(hwd_context_t *) master->context[cidx];
371  errno = vperfctr_iresume( our_context->perfctr );
372  if ( errno < 0 ) {
373  PAPIERROR( "vperfctr_iresume errno %d", errno );
374  }
375  }
376 }
int errno
void
Definition: iozone.c:18627
PAPI_component_info_t cmp_info
Definition: papi_vector.h:20
#define OVERFLOW_MASK
static int cidx
Definition: event_info.c:40
hwd_ucontext_t * ucontext
hwd_context_t ** context
Definition: threads.h:28
papi_vector_t _perfctr_vector
Definition: perfctr-x86.c:1163
void PAPIERROR(char *format,...)
hwd_siginfo_t * si
int _papi_hwi_dispatch_overflow_signal(void *papiContext, caddr_t address, int *isHardware, long long overflow_bit, int genOverflowBit, ThreadInfo_t **t, int cidx)
Definition: extras.c:214
#define GET_OVERFLOW_ADDRESS(ctx)
Definition: aix-context.h:12
signal(SIGINT, signal_handler)
#define GEN_OVERFLOW

Here is the call graph for this function:

int _perfctr_init_component ( int  cidx)

Definition at line 107 of file perfctr.c.

108 {
109  int retval;
110  struct perfctr_info info;
111  char abiv[PAPI_MIN_STR_LEN];
112 
113 #if defined(PERFCTR26)
114  int fd;
115 #else
116  struct vperfctr *dev;
117 #endif
118 
119 #if defined(PERFCTR26)
120  /* Get info from the kernel */
121  /* Use lower level calls per Mikael to get the perfctr info
122  without actually creating a new kernel-side state.
123  Also, close the fd immediately after retrieving the info.
124  This is much lighter weight and doesn't reserve the counter
125  resources. Also compatible with perfctr 2.6.14.
126  */
127  fd = _vperfctr_open( 0 );
128  if ( fd < 0 ) {
131  return PAPI_ESYS;
132  }
133  retval = perfctr_info( fd, &info );
134  close( fd );
135  if ( retval < 0 ) {
138  return PAPI_ESYS;
139  }
140 
141  /* copy tsc multiplier to local variable */
142  /* this field appears in perfctr 2.6 and higher */
143  tb_scale_factor = ( long long ) info.tsc_to_cpu_mult;
144 #else
145  /* Opened once for all threads. */
146  if ( ( dev = vperfctr_open( ) ) == NULL ) {
149  return PAPI_ESYS;
150  }
151  SUBDBG( "_perfctr_init_component vperfctr_open = %p\n", dev );
152 
153  /* Get info from the kernel */
154  retval = vperfctr_info( dev, &info );
155  if ( retval < 0 ) {
158  return ( PAPI_ESYS );
159  }
160  vperfctr_close( dev );
161 #endif
162 
163  /* Fill in what we can of the papi_system_info. */
165  if ( retval != PAPI_OK )
166  return ( retval );
167 
168  /* Setup memory info */
170  ( int ) info.cpu_type );
171  if ( retval )
172  return ( retval );
173 
174  strcpy( _perfctr_vector.cmp_info.name,"perfctr.c" );
175  strcpy( _perfctr_vector.cmp_info.version, "$Revision$" );
176  sprintf( abiv, "0x%08X", info.abi_version );
178  strcpy( _perfctr_vector.cmp_info.kernel_version, info.driver_version );
182  if ( info.cpu_features & PERFCTR_FEATURE_RDPMC )
184  else
191 #if !defined(PPC64)
192  /* AMD and Intel ia386 processors all support unit mask bits */
194 #endif
195 #if defined(PPC64)
198 #else
200 #endif
203  if ( info.cpu_features & PERFCTR_FEATURE_PCINT )
205  else
207  SUBDBG( "Hardware/OS %s support counter generated interrupts\n",
208  _perfctr_vector.cmp_info.hardware_intr ? "does" : "does not" );
209 
211  PERFCTR_CPU_NAME( &info ) );
212  _papi_hwi_system_info.hw_info.model = ( int ) info.cpu_type;
213 #if defined(PPC64)
215  if ( strlen( _papi_hwi_system_info.hw_info.vendor_string ) == 0 )
217 #else
219  xlate_cpu_type_to_vendor( info.cpu_type );
220 #endif
221 
222  /* Setup presets last. Some platforms depend on earlier info */
223 #if !defined(PPC64)
224 // retval = setup_p3_vector_table(vtable);
225  if ( !retval )
226  retval = _papi_libpfm_init(&_perfctr_vector, cidx );
227 #else
228  /* Setup native and preset events */
229 // retval = ppc64_setup_vector_table(vtable);
230  if ( !retval )
232  if ( !retval )
233  retval = setup_ppc64_presets( info.cpu_type, cidx );
234 #endif
235  if ( retval )
236  return ( retval );
237 
238  return ( PAPI_OK );
239 }
char name[PAPI_MAX_STR_LEN]
Definition: papi.h:625
sprintf(splash[splash_line++],"\tIozone: Performance Test of File I/O\n")
int _papi_libpfm_init(papi_vector_t *my_vector, int cidx)
int available_granularities
Definition: papi.h:642
int close(int fd)
Definition: appio.c:175
#define PERFCTR_CPU_NRCTRS
Definition: perfctr.c:50
unsigned int attach
Definition: papi.h:657
#define PAPI_MAX_STR_LEN
Definition: fpapi.h:43
#define PAPI_MIN_STR_LEN
Definition: fpapi.h:41
int default_granularity
Definition: papi.h:641
static int xlate_cpu_type_to_vendor(unsigned perfctr_cpu_type)
Definition: perfctr.c:55
int fd
Definition: iozone.c:1291
return PAPI_OK
Definition: linux-nvml.c:458
long long tb_scale_factor
Definition: perfctr.c:104
#define PAPI_DOM_KERNEL
Definition: fpapi.h:22
PAPI_component_info_t cmp_info
Definition: papi_vector.h:20
unsigned int cntr_umasks
Definition: papi.h:663
char kernel_version[PAPI_MIN_STR_LEN]
Definition: papi.h:631
#define VOPEN_ERROR
Definition: perfctr-x86.h:62
char disabled_reason[PAPI_MAX_STR_LEN]
Definition: papi.h:632
papi_os_vector_t _papi_os_vector
Definition: aix.c:1288
unsigned int fast_real_timer
Definition: papi.h:655
unsigned int fast_virtual_timer
Definition: papi.h:656
#define PAPI_VENDOR_IBM
Definition: papi.h:348
#define PAPI_DOM_SUPERVISOR
Definition: fpapi.h:24
unsigned int attach_must_ptrace
Definition: papi.h:658
static int cidx
Definition: event_info.c:40
unsigned int fast_counter_read
Definition: papi.h:654
#define SUBDBG(format, args...)
Definition: papi_debug.h:63
papi_vector_t _perfctr_vector
Definition: perfctr-x86.c:1163
long long
Definition: iozone.c:19827
#define PAPI_ESYS
Definition: fpapi.h:108
unsigned int hardware_intr
Definition: papi.h:647
char vendor_string[PAPI_MAX_STR_LEN]
Definition: papi.h:783
papi_mdi_t _papi_hwi_system_info
Definition: papi_internal.c:57
strcpy(filename, default_filename)
PAPI_hw_info_t hw_info
int(* get_system_info)(papi_mdi_t *mdi)
Definition: papi_vector.h:68
int vendor
Definition: papi.h:782
int model
Definition: papi.h:784
int
Definition: iozone.c:18528
char version[PAPI_MIN_STR_LEN]
Definition: papi.h:629
int perfctr_ppc64_setup_native_table()
Definition: ppc64_events.c:73
char support_version[PAPI_MIN_STR_LEN]
Definition: papi.h:630
char model_string[PAPI_MAX_STR_LEN]
Definition: papi.h:785
int setup_ppc64_presets(int cputype)
#define VINFO_ERROR
Definition: perfctr-x86.h:64
#define PAPI_DOM_USER
Definition: fpapi.h:21
#define PERFCTR_CPU_NAME
Definition: perfctr.c:49
ssize_t retval
Definition: libasync.c:338
int(* get_memory_info)(PAPI_hw_info_t *, int)
Definition: papi_vector.h:69
#define PAPI_GRN_THR
Definition: fpapi.h:67
if(gettimeofday(&tp,(struct timezone *) NULL)==-1) perror("gettimeofday")

Here is the call graph for this function:

int _perfctr_init_thread ( hwd_context_t ctx)

Definition at line 380 of file perfctr.c.

381 {
382  struct vperfctr_control tmp;
383  int error;
384 
385  /* Initialize our thread/process pointer. */
386  if ( ( ctx->perfctr = vperfctr_open( ) ) == NULL ) {
387 #ifdef VPERFCTR_OPEN_CREAT_EXCL
388  /* New versions of perfctr have this, which allows us to
389  get a previously created context, i.e. one created after
390  a fork and now we're inside a new process that has been exec'd */
391  if ( errno ) {
392  if ( ( ctx->perfctr = vperfctr_open_mode( 0 ) ) == NULL ) {
393  return PAPI_ESYS;
394  }
395  } else {
396  return PAPI_ESYS;
397  }
398 #else
399  return PAPI_ESYS;
400 #endif
401  }
402  SUBDBG( "_papi_hwd_init vperfctr_open() = %p\n", ctx->perfctr );
403 
404  /* Initialize the per thread/process virtualized TSC */
405  memset( &tmp, 0x0, sizeof ( tmp ) );
406  tmp.cpu_control.tsc_on = 1;
407 
408 #ifdef VPERFCTR_CONTROL_CLOEXEC
409  tmp.flags = VPERFCTR_CONTROL_CLOEXEC;
410  SUBDBG( "close on exec\t\t\t%u\n", tmp.flags );
411 #endif
412 
413  /* Start the per thread/process virtualized TSC */
414  error = vperfctr_control( ctx->perfctr, &tmp );
415  if ( error < 0 ) {
416  SUBDBG( "starting virtualized TSC; vperfctr_control returns %d\n",
417  error );
418  return PAPI_ESYS;
419  }
420 
421  return PAPI_OK;
422 }
memset(eventId, 0, size)
int errno
return PAPI_OK
Definition: linux-nvml.c:458
#define SUBDBG(format, args...)
Definition: papi_debug.h:63
#define PAPI_ESYS
Definition: fpapi.h:108
long long tmp
Definition: iozone.c:12031

Here is the call graph for this function:

int _perfctr_shutdown_thread ( hwd_context_t ctx)

Definition at line 428 of file perfctr.c.

429 {
430 #ifdef DEBUG
431  int retval = vperfctr_unlink( ctx->perfctr );
432  SUBDBG( "_papi_hwd_shutdown vperfctr_unlink(%p) = %d\n", ctx->perfctr,
433  retval );
434 #else
435  vperfctr_unlink( ctx->perfctr );
436 #endif
437  vperfctr_close( ctx->perfctr );
438  SUBDBG( "_perfctr_shutdown vperfctr_close(%p)\n", ctx->perfctr );
439  memset( ctx, 0x0, sizeof ( hwd_context_t ) );
440  return ( PAPI_OK );
441 }
memset(eventId, 0, size)
return PAPI_OK
Definition: linux-nvml.c:458
#define SUBDBG(format, args...)
Definition: papi_debug.h:63
ssize_t retval
Definition: libasync.c:338

Here is the call graph for this function:

static int attach ( hwd_control_state_t ctl,
unsigned long  tid 
)
static

Definition at line 242 of file perfctr.c.

243 {
244  struct vperfctr_control tmp;
245 
246 #ifdef VPERFCTR_CONTROL_CLOEXEC
247  tmp.flags = VPERFCTR_CONTROL_CLOEXEC;
248 #endif
249 
250  ctl->rvperfctr = rvperfctr_open( ( int ) tid );
251  if ( ctl->rvperfctr == NULL ) {
253  return ( PAPI_ESYS );
254  }
255  SUBDBG( "_papi_hwd_ctl rvperfctr_open() = %p\n", ctl->rvperfctr );
256 
257  /* Initialize the per thread/process virtualized TSC */
258  memset( &tmp, 0x0, sizeof ( tmp ) );
259  tmp.cpu_control.tsc_on = 1;
260 
261  /* Start the per thread/process virtualized TSC */
262  if ( rvperfctr_control( ctl->rvperfctr, &tmp ) < 0 ) {
264  return ( PAPI_ESYS );
265  }
266 
267  return ( PAPI_OK );
268 } /* end attach() */
memset(eventId, 0, size)
return PAPI_OK
Definition: linux-nvml.c:458
#define VOPEN_ERROR
Definition: perfctr-x86.h:62
void *long long tid
Definition: iozone.c:18586
#define SUBDBG(format, args...)
Definition: papi_debug.h:63
void PAPIERROR(char *format,...)
#define PAPI_ESYS
Definition: fpapi.h:108
#define RCNTRL_ERROR
Definition: perfctr-x86.h:66
long long tmp
Definition: iozone.c:12031

Here is the call graph for this function:

Here is the caller graph for this function:

static int detach ( hwd_control_state_t ctl)
static

Definition at line 271 of file perfctr.c.

272 {
273  rvperfctr_close( ctl->rvperfctr );
274  return ( PAPI_OK );
275 } /* end detach() */
return PAPI_OK
Definition: linux-nvml.c:458

Here is the caller graph for this function:

static int round_requested_ns ( int  ns)
inlinestatic

Definition at line 278 of file perfctr.c.

279 {
280  if ( ns < _papi_os_info.itimer_res_ns ) {
282  } else {
283  int leftover_ns = ns % _papi_os_info.itimer_res_ns;
284  return ns + leftover_ns;
285  }
286 }
int ns
Definition: iozone.c:20358
PAPI_os_info_t _papi_os_info
Definition: aix.c:1210

Here is the caller graph for this function:

static int xlate_cpu_type_to_vendor ( unsigned  perfctr_cpu_type)
inlinestatic

Definition at line 55 of file perfctr.c.

56 {
57  switch ( perfctr_cpu_type ) {
58  case PERFCTR_X86_INTEL_P5:
59  case PERFCTR_X86_INTEL_P5MMX:
60  case PERFCTR_X86_INTEL_P6:
61  case PERFCTR_X86_INTEL_PII:
62  case PERFCTR_X86_INTEL_PIII:
63  case PERFCTR_X86_INTEL_P4:
64  case PERFCTR_X86_INTEL_P4M2:
65 #ifdef PERFCTR_X86_INTEL_P4M3
66  case PERFCTR_X86_INTEL_P4M3:
67 #endif
68 #ifdef PERFCTR_X86_INTEL_PENTM
69  case PERFCTR_X86_INTEL_PENTM:
70 #endif
71 #ifdef PERFCTR_X86_INTEL_CORE
72  case PERFCTR_X86_INTEL_CORE:
73 #endif
74 #ifdef PERFCTR_X86_INTEL_CORE2
75  case PERFCTR_X86_INTEL_CORE2:
76 #endif
77 #ifdef PERFCTR_X86_INTEL_ATOM /* family 6 model 28 */
78  case PERFCTR_X86_INTEL_ATOM:
79 #endif
80 #ifdef PERFCTR_X86_INTEL_NHLM /* family 6 model 26 */
81  case PERFCTR_X86_INTEL_NHLM:
82 #endif
83 #ifdef PERFCTR_X86_INTEL_WSTMR
84  case PERFCTR_X86_INTEL_WSTMR:
85 #endif
86  return ( PAPI_VENDOR_INTEL );
87 #ifdef PERFCTR_X86_AMD_K8
88  case PERFCTR_X86_AMD_K8:
89 #endif
90 #ifdef PERFCTR_X86_AMD_K8C
91  case PERFCTR_X86_AMD_K8C:
92 #endif
93 #ifdef PERFCTR_X86_AMD_FAM10 /* this is defined in perfctr 2.6.29 */
94  case PERFCTR_X86_AMD_FAM10:
95 #endif
96  case PERFCTR_X86_AMD_K7:
97  return ( PAPI_VENDOR_AMD );
98  default:
99  return ( PAPI_VENDOR_UNKNOWN );
100  }
101 }
#define PAPI_VENDOR_INTEL
Definition: papi.h:346
#define PAPI_VENDOR_AMD
Definition: papi.h:347
#define PAPI_VENDOR_UNKNOWN
Definition: papi.h:345

Here is the caller graph for this function:

Variable Documentation

papi_vector_t _perfctr_vector
long long tb_scale_factor = ( long long ) 1

Definition at line 104 of file perfctr.c.