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

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 9 of file realtime.c.

10{
11 int retval;
12 long long elapsed_us, elapsed_cyc;
14 int quiet;
15
16 /* Set TESTS_QUIET variable */
17 quiet = tests_quiet( argc, argv );
18
20 if ( retval != PAPI_VER_CURRENT ) {
21 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
22 }
23
25 if ( hw_info == NULL ) {
26 test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 );
27 }
28
30
32
33 if (!quiet) {
34 printf( "Testing real time clock. (CPU Max %d MHz, CPU Min %d MHz)\n",
36 printf( "Sleeping for 10 seconds.\n" );
37 }
38
39 sleep( 10 );
40
42
44
45 if (!quiet) {
46 printf( "%lld us. %lld cyc.\n", elapsed_us, elapsed_cyc );
47 printf( "%f Computed MHz.\n",
48 ( float ) elapsed_cyc / ( float ) elapsed_us );
49 }
50
51/* Elapsed microseconds and elapsed cycles are not as unambiguous as they appear.
52 On Pentium III and 4, for example, cycles is a measured value, while useconds
53 is computed from cycles and mhz. MHz is read from /proc/cpuinfo (on linux).
54 Thus, any error in MHz is propagated to useconds.
55 Conversely, on ultrasparc useconds are extracted from a system call (gethrtime())
56 and cycles are computed from useconds. Also, MHz comes from a scan of system info,
57 Thus any error in gethrtime() propagates to both cycles and useconds, and cycles
58 can be further impacted by errors in reported MHz.
59 Without knowing the error bars on these system values, we can't really specify
60 error ranges for our reported values, but we *DO* know that errors for at least
61 one instance of Pentium 4 (torc17@utk) are on the order of one part per thousand.
62 Newer multicore Intel processors seem to have broken the relationship between the
63 clock rate reported in /proc/cpuinfo and the actual computed clock. To accomodate
64 this artifact, the test no longer fails, but merely reports results out of range.
65*/
66
67
68
69 if ( elapsed_us < 9000000 ) {
70 if (!quiet) printf( "NOTE: Elapsed real time less than 9 seconds (%lld us)!\n",elapsed_us );
71 test_fail(__FILE__,__LINE__,"Real time too short",1);
72 }
73
74 if ( elapsed_us > 11000000 ) {
75 if (!quiet) printf( "NOTE: Elapsed real time greater than 11 seconds! (%lld us)\n", elapsed_us );
76 test_fail(__FILE__,__LINE__,"Real time too long",1);
77 }
78
79 if ( ( float ) elapsed_cyc < 9.0 * hw_info->cpu_max_mhz * 1000000.0 )
80 if (!quiet) printf( "NOTE: Elapsed real cycles less than 9*MHz*1000000.0!\n" );
81 if ( ( float ) elapsed_cyc > 11.0 * hw_info->cpu_max_mhz * 1000000.0 )
82 if (!quiet) printf( "NOTE: Elapsed real cycles greater than 11*MHz*1000000.0!\n" );
83
84 test_pass( __FILE__ );
85
86 return 0;
87}
static const PAPI_hw_info_t * hw_info
Definition: byte_profile.c:28
get information about the system hardware
get real time counter value in clock cycles Returns the total real time passed since some arbitrary s...
get real time counter value in microseconds
initialize the PAPI library.
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
void PAPI_NORETURN test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:491
void PAPI_NORETURN test_pass(const char *filename)
Definition: test_utils.c:432
int quiet
Definition: rapl_overflow.c:19
Hardware info structure.
Definition: papi.h:774
int cpu_min_mhz
Definition: papi.h:791
int cpu_max_mhz
Definition: papi.h:790
long long elapsed_cyc
Definition: zero_fork.c:50
long long elapsed_us
Definition: zero_fork.c:50
int retval
Definition: zero_fork.c:53
Here is the call graph for this function: