PAPI 7.1.0.0
Loading...
Searching...
No Matches
linux-timer.c File Reference
Include dependency graph for linux-timer.c:

Go to the source code of this file.

Functions

int mmtimer_setup (void)
 
long long _linux_get_real_cycles (void)
 
long long _linux_get_real_usec_gettime (void)
 
long long _linux_get_real_usec_gettimeofday (void)
 
long long _linux_get_real_usec_cycles (void)
 
long long _linux_get_virt_usec_rusage (void)
 
long long _linux_get_virt_usec_times (void)
 
long long _linux_get_virt_usec_gettime (void)
 
long long _linux_get_virt_usec_pttimer (void)
 
long long _linux_get_real_nsec_gettime (void)
 
long long _linux_get_virt_nsec_gettime (void)
 

Function Documentation

◆ _linux_get_real_cycles()

long long _linux_get_real_cycles ( void  )

Definition at line 312 of file linux-timer.c.

313{
314 long long retval;
315#if defined(HAVE_GETTIMEOFDAY)||defined(__arm__)||defined(__mips__)
316
317 /* Crude estimate, not accurate in prescence of DVFS */
318
321#else
322 retval = get_cycles( );
323#endif
324 return retval;
325}
papi_os_vector_t _papi_os_vector
Definition: aix.c:1288
#define get_cycles
Definition: linux-bgq.c:48
papi_mdi_t _papi_hwi_system_info
Definition: papi_internal.c:56
long long int long long
Definition: sde_internal.h:85
int cpu_max_mhz
Definition: papi.h:790
PAPI_hw_info_t hw_info
long long(* get_real_usec)(void)
Definition: papi_vector.h:63
int retval
Definition: zero_fork.c:53

◆ _linux_get_real_nsec_gettime()

long long _linux_get_real_nsec_gettime ( void  )

Definition at line 533 of file linux-timer.c.

534{
535
536 long long retval;
537
538 struct timespec foo;
539#ifdef HAVE_CLOCK_GETTIME_REALTIME_HR
540 syscall( __NR_clock_gettime, CLOCK_REALTIME_HR, &foo );
541#else
542 syscall( __NR_clock_gettime, CLOCK_REALTIME, &foo );
543#endif
544 retval = ( long long ) foo.tv_sec * ( long long ) 1000000000;
545 retval += ( long long ) ( foo.tv_nsec );
546
547 return retval;
548}

◆ _linux_get_real_usec_cycles()

long long _linux_get_real_usec_cycles ( void  )

Definition at line 377 of file linux-timer.c.

378{
379
380 long long retval;
381
382 /* Not accurate in the prescence of DVFS */
383
384 retval = get_cycles( ) /
386
387 return retval;
388}

◆ _linux_get_real_usec_gettime()

long long _linux_get_real_usec_gettime ( void  )

Definition at line 340 of file linux-timer.c.

341{
342
343 long long retval;
344
345 struct timespec foo;
346#ifdef HAVE_CLOCK_GETTIME_REALTIME_HR
347 syscall( __NR_clock_gettime, CLOCK_REALTIME_HR, &foo );
348#else
349 syscall( __NR_clock_gettime, CLOCK_REALTIME, &foo );
350#endif
351 retval = ( long long ) foo.tv_sec * ( long long ) 1000000;
352 retval += ( long long ) ( foo.tv_nsec / 1000 );
353
354 return retval;
355}

◆ _linux_get_real_usec_gettimeofday()

long long _linux_get_real_usec_gettimeofday ( void  )

Definition at line 362 of file linux-timer.c.

363{
364
365 long long retval;
366
367 struct timeval buffer;
368 gettimeofday( &buffer, NULL );
369 retval = ( long long ) buffer.tv_sec * ( long long ) 1000000;
370 retval += ( long long ) ( buffer.tv_usec );
371
372 return retval;
373}

◆ _linux_get_virt_nsec_gettime()

long long _linux_get_virt_nsec_gettime ( void  )

Definition at line 556 of file linux-timer.c.

557{
558
559 long long retval;
560
561 struct timespec foo;
562
563 syscall( __NR_clock_gettime, CLOCK_THREAD_CPUTIME_ID, &foo );
564 retval = ( long long ) foo.tv_sec * ( long long ) 1000000000;
565 retval += ( long long ) foo.tv_nsec ;
566
567 return retval;
568}

◆ _linux_get_virt_usec_gettime()

long long _linux_get_virt_usec_gettime ( void  )

Definition at line 443 of file linux-timer.c.

444{
445
446 long long retval;
447
448 struct timespec foo;
449
450 syscall( __NR_clock_gettime, CLOCK_THREAD_CPUTIME_ID, &foo );
451 retval = ( long long ) foo.tv_sec * ( long long ) 1000000;
452 retval += ( long long ) foo.tv_nsec / 1000;
453
454 return retval;
455}

◆ _linux_get_virt_usec_pttimer()

long long _linux_get_virt_usec_pttimer ( void  )

Definition at line 462 of file linux-timer.c.

463{
464
465 long long retval;
466 char buf[LINE_MAX];
467 long long utime, stime;
468 int rv, cnt = 0, i = 0;
469 int stat_fd;
470
471
472again:
473 sprintf( buf, "/proc/%d/task/%d/stat", getpid( ), mygettid( ) );
474 stat_fd = open( buf, O_RDONLY );
475 if ( stat_fd == -1 ) {
476 PAPIERROR( "open(%s)", buf );
477 return PAPI_ESYS;
478 }
479
480 rv = read( stat_fd, buf, LINE_MAX * sizeof ( char ) );
481 if ( rv == -1 ) {
482 if ( errno == EBADF ) {
483 close(stat_fd);
484 goto again;
485 }
486 PAPIERROR( "read()" );
487 close(stat_fd);
488 return PAPI_ESYS;
489 }
490 lseek( stat_fd, 0, SEEK_SET );
491
492 if (rv == LINE_MAX) rv--;
493 buf[rv] = '\0';
494 SUBDBG( "Thread stat file is:%s\n", buf );
495 while ( ( cnt != 13 ) && ( i < rv ) ) {
496 if ( buf[i] == ' ' ) {
497 cnt++;
498 }
499 i++;
500 }
501
502 if ( cnt != 13 ) {
503 PAPIERROR( "utime and stime not in thread stat file?" );
504 close(stat_fd);
505 return PAPI_ESYS;
506 }
507
508 if ( sscanf( buf + i, "%llu %llu", &utime, &stime ) != 2 ) {
509 close(stat_fd);
510 PAPIERROR("Unable to scan two items from thread stat file at 13th space?");
511 return PAPI_ESYS;
512 }
513
514 retval = ( utime + stime ) * ( long long ) 1000000 /_papi_os_info.clock_ticks;
515
516 close(stat_fd);
517
518 return retval;
519}
int i
PAPI_os_info_t _papi_os_info
Definition: aix.c:1210
int open(const char *pathname, int flags, mode_t mode)
Definition: appio.c:188
off_t lseek(int fd, off_t offset, int whence)
Definition: appio.c:214
int close(int fd)
Definition: appio.c:179
int errno
ssize_t read(int fd, void *buf, size_t count)
Definition: appio.c:229
static pid_t mygettid(void)
Definition: darwin-common.h:11
volatile int buf[CACHE_FLUSH_BUFFER_SIZE_INTS]
Definition: do_loops.c:12
#define PAPI_ESYS
Definition: f90papi.h:136
#define SUBDBG(format, args...)
Definition: papi_debug.h:64
void PAPIERROR(char *format,...)
Here is the call graph for this function:

◆ _linux_get_virt_usec_rusage()

long long _linux_get_virt_usec_rusage ( void  )

Definition at line 397 of file linux-timer.c.

398{
399
400 long long retval;
401
402 struct rusage buffer;
403
404 getrusage( RUSAGE_SELF, &buffer );
405 SUBDBG( "user %d system %d\n", ( int ) buffer.ru_utime.tv_sec,
406 ( int ) buffer.ru_stime.tv_sec );
407 retval = ( long long ) ( buffer.ru_utime.tv_sec + buffer.ru_stime.tv_sec )
408 * ( long long ) 1000000;
409 retval += (long long) ( buffer.ru_utime.tv_usec + buffer.ru_stime.tv_usec );
410
411 return retval;
412}

◆ _linux_get_virt_usec_times()

long long _linux_get_virt_usec_times ( void  )

Definition at line 419 of file linux-timer.c.

420{
421
422 long long retval;
423
424 struct tms buffer;
425
426 times( &buffer );
427
428 SUBDBG( "user %d system %d\n", ( int ) buffer.tms_utime,
429 ( int ) buffer.tms_stime );
430 retval = ( long long ) ( ( buffer.tms_utime + buffer.tms_stime ) *
431 1000000 / sysconf( _SC_CLK_TCK ));
432
433 /* NOT CLOCKS_PER_SEC as in the headers! */
434
435 return retval;
436}

◆ mmtimer_setup()

int mmtimer_setup ( void  )

Definition at line 130 of file linux-timer.c.

130 {
131
132#if defined(__powerpc__)
133multiplier = ((uint64_t)_papi_hwi_system_info.hw_info.cpu_max_mhz * 1000000ULL) / (__ppc_get_timebase_freq()/(uint64_t)1000);
134#endif
135return PAPI_OK; }
#define PAPI_OK
Definition: f90papi.h:73
Here is the caller graph for this function: