PAPI  5.4.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
darwin-common.c File Reference
Include dependency graph for darwin-common.c:

Go to the source code of this file.

Macros

#define _PATH_SYS_SYSTEM   "/sys/devices/system"
 
#define _PATH_SYS_CPU0   _PATH_SYS_SYSTEM "/cpu/cpu0"
 

Functions

static int _darwin_init_locks (void)
 
int _darwin_detect_hypervisor (char *virtual_vendor_name)
 
static char * search_cpu_info (FILE *f, char *search_str, char *line)
 
int _darwin_get_cpu_info (PAPI_hw_info_t *hwinfo, int *cpuinfo_mhz)
 
int _darwin_get_system_info (papi_mdi_t *mdi)
 
int _papi_hwi_init_os (void)
 
static long long get_cycles (void)
 
long long _darwin_get_real_cycles (void)
 
long long _darwin_get_real_usec_gettimeofday (void)
 
long long _darwin_get_virt_usec_times (void)
 

Variables

PAPI_os_info_t _papi_os_info
 
volatile unsigned int _papi_hwd_lock_data [PAPI_MAX_LOCK]
 
static char pathbuf [PATH_MAX] = "/"
 
papi_os_vector_t _papi_os_vector
 

Macro Definition Documentation

#define _PATH_SYS_CPU0   _PATH_SYS_SYSTEM "/cpu/cpu0"

Definition at line 68 of file darwin-common.c.

#define _PATH_SYS_SYSTEM   "/sys/devices/system"

Definition at line 67 of file darwin-common.c.

Function Documentation

int _darwin_detect_hypervisor ( char *  virtual_vendor_name)

Definition at line 53 of file darwin-common.c.

53  {
54 
55  int retval=0;
56 
57 #if defined(__i386__)||defined(__x86_64__)
58  retval=_x86_detect_hypervisor(virtual_vendor_name);
59 #else
60  (void) virtual_vendor_name;
61 #endif
62 
63  return retval;
64 }
void
Definition: iozone.c:18627
int _x86_detect_hypervisor(char *vendor_name)
ssize_t retval
Definition: libasync.c:338

Here is the call graph for this function:

Here is the caller graph for this function:

int _darwin_get_cpu_info ( PAPI_hw_info_t hwinfo,
int cpuinfo_mhz 
)

Definition at line 94 of file darwin-common.c.

95 {
96 
97  int mib[4];
98  size_t len;
99  char buffer[BUFSIZ];
100  long long ll;
101 
102  /* "sysctl -a" shows lots of info we can get on OSX */
103 
104  /**********/
105  /* Vendor */
106  /**********/
107  len = 3;
108  sysctlnametomib("machdep.cpu.vendor", mib, &len);
109 
110  len = BUFSIZ;
111  if (sysctl(mib, 3, &buffer, &len, NULL, 0) == -1) {
112  return PAPI_ESYS;
113  }
114  strncpy( hwinfo->vendor_string,buffer,len);
115 
116  hwinfo->vendor = PAPI_VENDOR_INTEL;
117 
118 
119  /**************/
120  /* Model Name */
121  /**************/
122  len = 3;
123  sysctlnametomib("machdep.cpu.brand_string", mib, &len);
124 
125  len = BUFSIZ;
126  if (sysctl(mib, 3, &buffer, &len, NULL, 0) == -1) {
127  return PAPI_ESYS;
128  }
129  strncpy( hwinfo->model_string,buffer,len);
130 
131  /************/
132  /* Revision */
133  /************/
134  len = 3;
135  sysctlnametomib("machdep.cpu.stepping", mib, &len);
136 
137  len = BUFSIZ;
138  if (sysctl(mib, 3, &buffer, &len, NULL, 0) == -1) {
139  return PAPI_ESYS;
140  }
141 
142  hwinfo->cpuid_stepping=buffer[0];
143  hwinfo->revision=(float)(hwinfo->cpuid_stepping);
144 
145  /**********/
146  /* Family */
147  /**********/
148  len = 3;
149  sysctlnametomib("machdep.cpu.family", mib, &len);
150 
151  len = BUFSIZ;
152  if (sysctl(mib, 3, &buffer, &len, NULL, 0) == -1) {
153  return PAPI_ESYS;
154  }
155 
156  hwinfo->cpuid_family=buffer[0];
157 
158  /**********/
159  /* Model */
160  /**********/
161  len = 3;
162  sysctlnametomib("machdep.cpu.model", mib, &len);
163 
164  len = BUFSIZ;
165  if (sysctl(mib, 3, &buffer, &len, NULL, 0) == -1) {
166  return PAPI_ESYS;
167  }
168 
169  hwinfo->cpuid_model=buffer[0];
170  hwinfo->model=hwinfo->cpuid_model;
171 
172  /*************/
173  /* Frequency */
174  /*************/
175  len = 2;
176  sysctlnametomib("hw.cpufrequency_max", mib, &len);
177 
178  len = 8;
179  if (sysctl(mib, 2, &ll, &len, NULL, 0) == -1) {
180  return PAPI_ESYS;
181  }
182 
183  hwinfo->cpu_max_mhz=(int)(ll/(1000*1000));
184 
185  len = 2;
186  sysctlnametomib("hw.cpufrequency_min", mib, &len);
187 
188  len = 8;
189  if (sysctl(mib, 2, &ll, &len, NULL, 0) == -1) {
190  return PAPI_ESYS;
191  }
192 
193  hwinfo->cpu_min_mhz=(int)(ll/(1000*1000));
194 
195  /**********/
196  /* ncpu */
197  /**********/
198  len = 2;
199  sysctlnametomib("hw.ncpu", mib, &len);
200 
201  len = BUFSIZ;
202  if (sysctl(mib, 2, &buffer, &len, NULL, 0) == -1) {
203  return PAPI_ESYS;
204  }
205 
206  hwinfo->totalcpus=buffer[0];
207 
208 
209  return PAPI_OK;
210 }
int cpu_min_mhz
Definition: papi.h:794
return PAPI_OK
Definition: linux-nvml.c:458
int cpuid_stepping
Definition: papi.h:791
float revision
Definition: papi.h:788
#define PAPI_ESYS
Definition: papi.h:253
int cpuid_model
Definition: papi.h:790
int cpuid_family
Definition: papi.h:789
char vendor_string[PAPI_MAX_STR_LEN]
Definition: papi.h:785
#define PAPI_VENDOR_INTEL
Definition: papi.h:346
char * buffer
Definition: iozone.c:1366
int vendor
Definition: papi.h:784
int model
Definition: papi.h:786
int cpu_max_mhz
Definition: papi.h:793
int
Definition: iozone.c:18528
int totalcpus
Definition: papi.h:783
char model_string[PAPI_MAX_STR_LEN]
Definition: papi.h:787

Here is the caller graph for this function:

long long _darwin_get_real_cycles ( void  )

Definition at line 363 of file darwin-common.c.

364 {
365  long long retval;
366 
367  retval = get_cycles( );
368 
369  return retval;
370 }
static long long get_cycles(void)
ssize_t retval
Definition: libasync.c:338

Here is the call graph for this function:

long long _darwin_get_real_usec_gettimeofday ( void  )

Definition at line 374 of file darwin-common.c.

375 {
376 
377  long long retval;
378 
379  struct timeval buffer;
380  gettimeofday( &buffer, NULL );
381  retval = ( long long ) buffer.tv_sec * ( long long ) 1000000;
382  retval += ( long long ) ( buffer.tv_usec );
383 
384  return retval;
385 }
long long
Definition: iozone.c:19827
char * buffer
Definition: iozone.c:1366
ssize_t retval
Definition: libasync.c:338
int _darwin_get_system_info ( papi_mdi_t mdi)

Definition at line 214 of file darwin-common.c.

214  {
215 
216  int retval;
217 
218  char maxargs[PAPI_HUGE_STR_LEN];
219  pid_t pid;
220 
221  int cpuinfo_mhz,sys_min_khz,sys_max_khz;
222 
223  /* Software info */
224 
225  /* Path and args */
226 
227  pid = getpid( );
228  if ( pid < 0 ) {
229  PAPIERROR( "getpid() returned < 0" );
230  return PAPI_ESYS;
231  }
232  mdi->pid = pid;
233 
234 #if 0
235  sprintf( maxargs, "/proc/%d/exe", ( int ) pid );
236  if ( readlink( maxargs, mdi->exe_info.fullname, PAPI_HUGE_STR_LEN ) < 0 ) {
237  PAPIERROR( "readlink(%s) returned < 0", maxargs );
238  return PAPI_ESYS;
239  }
240 
241  /* Careful, basename can modify it's argument */
242 
243  strcpy( maxargs, mdi->exe_info.fullname );
244  strcpy( mdi->exe_info.address_info.name, basename( maxargs ) );
245 
246  SUBDBG( "Executable is %s\n", mdi->exe_info.address_info.name );
247  SUBDBG( "Full Executable is %s\n", mdi->exe_info.fullname );
248 
249  /* Executable regions, may require reading /proc/pid/maps file */
250 
251  retval = _darwin_update_shlib_info( mdi );
252  SUBDBG( "Text: Start %p, End %p, length %d\n",
255  ( int ) ( mdi->exe_info.address_info.text_end -
257  SUBDBG( "Data: Start %p, End %p, length %d\n",
260  ( int ) ( mdi->exe_info.address_info.data_end -
262  SUBDBG( "Bss: Start %p, End %p, length %d\n",
265  ( int ) ( mdi->exe_info.address_info.bss_end -
267 #endif
268  /* PAPI_preload_option information */
269 
270  strcpy( mdi->preload_info.lib_preload_env, "LD_PRELOAD" );
271  mdi->preload_info.lib_preload_sep = ' ';
272  strcpy( mdi->preload_info.lib_dir_env, "LD_LIBRARY_PATH" );
273  mdi->preload_info.lib_dir_sep = ':';
274 
275  /* Hardware info */
276 
277  retval = _darwin_get_cpu_info( &mdi->hw_info, &cpuinfo_mhz );
278  if ( retval ) {
279  return retval;
280  }
281 
282  /* Set Up Memory */
283 
284  retval = _darwin_get_memory_info( &mdi->hw_info, mdi->hw_info.model );
285  if ( retval )
286  return retval;
287 
288  SUBDBG( "Found %d %s(%d) %s(%d) CPUs at %d Mhz.\n",
289  mdi->hw_info.totalcpus,
290  mdi->hw_info.vendor_string,
291  mdi->hw_info.vendor,
292  mdi->hw_info.model_string,
293  mdi->hw_info.model,
294  mdi->hw_info.cpu_max_mhz);
295 
296  /* Get virtualization info */
298 
299  return PAPI_OK;
300 }
char name[PAPI_HUGE_STR_LEN]
Definition: papi.h:693
sprintf(splash[splash_line++],"\tIozone: Performance Test of File I/O\n")
int _darwin_detect_hypervisor(char *virtual_vendor_name)
Definition: darwin-common.c:53
caddr_t text_end
Definition: papi.h:695
return PAPI_OK
Definition: linux-nvml.c:458
caddr_t bss_start
Definition: papi.h:698
PAPI_preload_info_t preload_info
PAPI_exe_info_t exe_info
#define PAPI_HUGE_STR_LEN
Definition: papi.h:465
int _darwin_update_shlib_info(papi_mdi_t *mdi)
Definition: darwin-memory.c:76
char lib_preload_env[PAPI_MAX_STR_LEN]
Definition: papi.h:618
static int pid
char virtual_vendor_string[PAPI_MAX_STR_LEN]
Definition: papi.h:798
char lib_preload_sep
Definition: papi.h:619
caddr_t text_start
Definition: papi.h:694
PAPI_address_map_t address_info
Definition: papi.h:706
#define PAPI_ESYS
Definition: papi.h:253
int _darwin_get_cpu_info(PAPI_hw_info_t *hwinfo, int *cpuinfo_mhz)
Definition: darwin-common.c:94
#define SUBDBG(format, args...)
Definition: papi_debug.h:63
void PAPIERROR(char *format,...)
char vendor_string[PAPI_MAX_STR_LEN]
Definition: papi.h:785
strcpy(filename, default_filename)
PAPI_hw_info_t hw_info
caddr_t data_start
Definition: papi.h:696
int vendor
Definition: papi.h:784
int model
Definition: papi.h:786
int cpu_max_mhz
Definition: papi.h:793
caddr_t bss_end
Definition: papi.h:699
caddr_t data_end
Definition: papi.h:697
int totalcpus
Definition: papi.h:783
char model_string[PAPI_MAX_STR_LEN]
Definition: papi.h:787
char fullname[PAPI_HUGE_STR_LEN]
Definition: papi.h:705
int virtualized
Definition: papi.h:797
int _darwin_get_memory_info(PAPI_hw_info_t *hwinfo, int cpu_type)
Definition: darwin-memory.c:65
ssize_t retval
Definition: libasync.c:338
char lib_dir_sep
Definition: papi.h:621
char lib_dir_env[PAPI_MAX_STR_LEN]
Definition: papi.h:620

Here is the call graph for this function:

Here is the caller graph for this function:

long long _darwin_get_virt_usec_times ( void  )

Definition at line 389 of file darwin-common.c.

390 {
391 
392  long long retval;
393 
394  struct tms buffer;
395 
396  times( &buffer );
397 
398  SUBDBG( "user %d system %d\n", ( int ) buffer.tms_utime,
399  ( int ) buffer.tms_stime );
400  retval = ( long long ) ( ( buffer.tms_utime + buffer.tms_stime ) *
401  1000000 / sysconf( _SC_CLK_TCK ));
402 
403  /* NOT CLOCKS_PER_SEC as in the headers! */
404 
405  return retval;
406 }
#define SUBDBG(format, args...)
Definition: papi_debug.h:63
long long
Definition: iozone.c:19827
char * buffer
Definition: iozone.c:1366
ssize_t retval
Definition: libasync.c:338
static int _darwin_init_locks ( void  )
static

Definition at line 36 of file darwin-common.c.

36  {
37 
38  int i;
39 
40  for ( i = 0; i < PAPI_MAX_LOCK; i++ ) {
41 #if defined(USE_PTHREAD_MUTEXES)
42  pthread_mutex_init(&_papi_hwd_lock_data[i],NULL);
43 #else
45 #endif
46  }
47 
48  return PAPI_OK;
49 }
return PAPI_OK
Definition: linux-nvml.c:458
#define PAPI_MAX_LOCK
Definition: papi_lock.h:18
int i
Definition: fileop.c:140
volatile unsigned int _papi_hwd_lock_data[PAPI_MAX_LOCK]
Definition: darwin-common.c:32
#define MUTEX_OPEN
Definition: perfctr-ppc64.h:75

Here is the caller graph for this function:

int _papi_hwi_init_os ( void  )

Definition at line 303 of file darwin-common.c.

303  {
304 
305  int major=0,minor=0,sub=0;
306  char *ptr;
307  struct utsname uname_buffer;
308 
309  /* Initialize the locks */
311 
312  /* Get the kernel info */
313  uname(&uname_buffer);
314 
315  SUBDBG("Native kernel version %s\n",uname_buffer.release);
316 
317  strncpy(_papi_os_info.name,uname_buffer.sysname,PAPI_MAX_STR_LEN);
318 
319  strncpy(_papi_os_info.version,uname_buffer.release,PAPI_MAX_STR_LEN);
320 
321  ptr=strtok(_papi_os_info.version,".");
322  if (ptr!=NULL) major=atoi(ptr);
323 
324  ptr=strtok(NULL,".");
325  if (ptr!=NULL) minor=atoi(ptr);
326 
327  ptr=strtok(NULL,".");
328  if (ptr!=NULL) sub=atoi(ptr);
329 
330  // _papi_os_info.os_version=LINUX_VERSION(major,minor,sub);
331 
336  _papi_os_info.clock_ticks = sysconf( _SC_CLK_TCK );
337 
338  /* Get Darwin-specific system info */
340 
341  return PAPI_OK;
342 }
int atoi()
#define PAPI_INT_MPX_DEF_US
Definition: papi_internal.h:65
return PAPI_OK
Definition: linux-nvml.c:458
char name[PAPI_MAX_STR_LEN]
static int _darwin_init_locks(void)
Definition: darwin-common.c:36
int _darwin_get_system_info(papi_mdi_t *mdi)
PAPI_os_info_t _papi_os_info
Definition: aix.c:1210
#define SUBDBG(format, args...)
Definition: papi_debug.h:63
#define PAPI_INT_ITIMER
Definition: papi_internal.h:54
char version[PAPI_MAX_STR_LEN]
#define PAPI_INT_MPX_SIGNAL
Definition: papi_internal.h:52
papi_mdi_t _papi_hwi_system_info
Definition: papi_internal.c:57
#define PAPI_MAX_STR_LEN
Definition: papi.h:463
char * ptr
Definition: iozone.c:23586

Here is the call graph for this function:

static long long get_cycles ( void  )
inlinestatic

Definition at line 346 of file darwin-common.c.

347 {
348  long long ret = 0;
349 #ifdef __x86_64__
350  do {
351  unsigned int a, d;
352  asm volatile ( "rdtsc":"=a" ( a ), "=d"( d ) );
353  ( ret ) = ( ( long long ) a ) | ( ( ( long long ) d ) << 32 );
354  }
355  while ( 0 );
356 #else
357  __asm__ __volatile__( "rdtsc":"=A"( ret ): );
358 #endif
359  return ret;
360 }
static double a[MATRIX_SIZE][MATRIX_SIZE]
Definition: rapl_basic.c:37
long long ret
Definition: iozone.c:1346

Here is the caller graph for this function:

static char* search_cpu_info ( FILE *  f,
char *  search_str,
char *  line 
)
static

Definition at line 74 of file darwin-common.c.

75 {
76  /* This function courtesy of Rudolph Berrendorf! */
77  /* See the home page for the German version of PAPI. */
78  char *s;
79 
80  while ( fgets( line, 256, f ) != NULL ) {
81  if ( strstr( line, search_str ) != NULL ) {
82  /* ignore all characters in line up to : */
83  for ( s = line; *s && ( *s != ':' ); ++s );
84  if ( *s )
85  return s;
86  }
87  }
88  return NULL;
89 }
double f(double a)
Definition: cpi.c:23
s
Definition: iozone.c:20289

Variable Documentation

volatile unsigned int _papi_hwd_lock_data[PAPI_MAX_LOCK]

Definition at line 32 of file darwin-common.c.

PAPI_os_info_t _papi_os_info

Definition at line 25 of file darwin-common.c.

papi_os_vector_t _papi_os_vector
Initial value:
= {
.get_memory_info = _darwin_get_memory_info,
.get_dmem_info = _darwin_get_dmem_info,
.get_real_cycles = _darwin_get_real_cycles,
.update_shlib_info = _darwin_update_shlib_info,
.get_system_info = _darwin_get_system_info,
.get_virt_usec = _darwin_get_virt_usec_times,
}
long long _darwin_get_real_usec_gettimeofday(void)
long long _darwin_get_real_cycles(void)
long long _darwin_get_virt_usec_times(void)
int _darwin_update_shlib_info(papi_mdi_t *mdi)
Definition: darwin-memory.c:76
int _darwin_get_system_info(papi_mdi_t *mdi)
int _darwin_get_memory_info(PAPI_hw_info_t *hwinfo, int cpu_type)
Definition: darwin-memory.c:65
int _darwin_get_dmem_info(PAPI_dmem_info_t *d)
Definition: darwin-memory.c:13

Definition at line 412 of file darwin-common.c.

char pathbuf[PATH_MAX] = "/"
static

Definition at line 70 of file darwin-common.c.