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

Go to the source code of this file.

Macros

#define SLEEP_RUNS   3
 
#define REPITITIONS   2
 

Functions

static long long convert_to_ns (struct timespec *before, struct timespec *after)
 
int main (int argc, char **argv)
 

Macro Definition Documentation

◆ REPITITIONS

#define REPITITIONS   2

◆ SLEEP_RUNS

#define SLEEP_RUNS   3

Definition at line 22 of file papi_tot_cyc.c.

Function Documentation

◆ convert_to_ns()

static long long convert_to_ns ( struct timespec before,
struct timespec after 
)
static

Definition at line 25 of file papi_tot_cyc.c.

26 {
27
28 long long seconds;
29 long long ns;
30
31 seconds=after->tv_sec - before->tv_sec;
32 ns = after->tv_nsec - before->tv_nsec;
33
34 ns = (seconds*1000000000ULL)+ns;
35
36 return ns;
37}
__syscall_slong_t tv_nsec
__time_t tv_sec
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 40 of file papi_tot_cyc.c.

40 {
41
42 int quiet;
43 double mmm_ghz;
44
45 double error;
46
47 int i;
48 long long count,high=0,low=0,total=0,average=0;
49 long long nsecs;
50 long long mmm_count;
51 long long expected;
52 int retval;
53 int eventset=PAPI_NULL;
54
55 struct timespec before,after;
56
57 quiet=tests_quiet(argc,argv);
58
59 /* Init the PAPI library */
61 if ( retval != PAPI_VER_CURRENT ) {
62 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
63 }
64
65 if (!quiet) {
66 printf("\nTesting PAPI_TOT_CYC\n\n");
67 }
68
69 if (!quiet) {
70 printf("Testing a sleep of 1 second (%d times):\n",SLEEP_RUNS);
71 }
72
74 if (retval!=PAPI_OK) {
75 test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
76 }
77
78 retval=PAPI_add_named_event(eventset,"PAPI_TOT_CYC");
79 if (retval!=PAPI_OK) {
80 if (!quiet) printf("Could not add PAPI_TOT_CYC\n");
81 test_skip( __FILE__, __LINE__, "adding PAPI_TOT_CYC", retval );
82 }
83
84
85 for(i=0;i<SLEEP_RUNS;i++) {
86
87 PAPI_reset(eventset);
88 PAPI_start(eventset);
89
90 sleep(1);
91
92 retval=PAPI_stop(eventset,&count);
93 if (retval!=PAPI_OK) {
94 test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
95 }
96
97 if (count>high) high=count;
98 if ((low==0) || (count<low)) low=count;
99 total+=count;
100 }
101
102 average=total/SLEEP_RUNS;
103
104 if (!quiet) {
105 printf("\tAverage should be low, as no user cycles when sleeping\n");
106 printf("\tMeasured average: %lld\n",average);
107 }
108
109 if (average>100000) {
110 if (!quiet) printf("Average cycle count too high!\n");
111 test_fail( __FILE__, __LINE__, "idle average", retval );
112 }
113
114 /*****************************/
115 /* testing Matrix Matrix GHz */
116 /*****************************/
117
118 if (!quiet) {
119 printf("\nEstimating GHz with matrix matrix multiply\n");
120 }
121
122 // We have a problem with subsequent runs requiring fewer cycles than
123 // the first run. This may be system dependent; so we do a throw-away
124 // run here, so we end up comparing the SECOND run to the 3rd, 4th, etc.
125
126 naive_matrix_multiply(quiet); // A first run, to init system.
127
128 clock_gettime(CLOCK_REALTIME,&before);
129
130 PAPI_reset(eventset);
131 PAPI_start(eventset);
132
134
135 retval=PAPI_stop(eventset,&count);
136
137 if (retval!=PAPI_OK) {
138 test_fail( __FILE__, __LINE__, "Problem stopping!", retval );
139 }
140
141 clock_gettime(CLOCK_REALTIME,&after);
142
143 nsecs=convert_to_ns(&before,&after);
144
145 mmm_ghz=(double)count/(double)nsecs;
146
147 if (!quiet) {
148 printf("\tActual measured cycles = %lld\n",count);
149 printf("\tEstimated actual GHz = %.2lfGHz\n",mmm_ghz);
150 }
151
152 mmm_count=count;
153
154 /************************************/
155 /* Check for Linear Speedup */
156 /************************************/
157
158 if (!quiet) printf("\nTesting for a linear cycle increase\n");
159
160#define REPITITIONS 2
161
162 clock_gettime(CLOCK_REALTIME,&before);
163
164 PAPI_reset(eventset);
165 PAPI_start(eventset);
166
167 for(i=0;i<REPITITIONS;i++) {
169 }
170
171 retval=PAPI_stop(eventset,&count);
172
173 if (retval!=PAPI_OK) {
174 test_fail( __FILE__, __LINE__, "Problem stopping!", retval );
175 }
176
177 clock_gettime(CLOCK_REALTIME,&after);
178
179 nsecs=convert_to_ns(&before,&after);
180
181 expected=mmm_count*REPITITIONS;
182
183 error= 100.0 * (double)(count-expected) / (double)expected;
184
185 if (!quiet) {
186 printf("\tExpected %lld, got %lld\n",expected,count);
187 printf("\tError=%.2f%%\n",error);
188 }
189
190 if ((error>10.0) || (error<-10.0)) {
191
192 if (!quiet) printf("Error too high!\n");
193 test_fail( __FILE__, __LINE__, "Error too high", retval );
194 }
195
196 if (!quiet) printf("\n");
197
198 test_pass( __FILE__ );
199
200 return 0;
201}
int i
static long count
add PAPI preset or native hardware event by name to an EventSet
Create a new empty PAPI EventSet.
initialize the PAPI library.
Reset the hardware event counts in an event set.
Start counting hardware events in an event set.
Stop counting hardware events in an event set.
static int expected[NUM_THREADS]
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_NULL
Definition: f90papi.h:78
double naive_matrix_multiply(int quiet)
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
void PAPI_NORETURN test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:584
#define SLEEP_RUNS
Definition: papi_tot_cyc.c:22
static long long convert_to_ns(struct timespec *before, struct timespec *after)
Definition: papi_tot_cyc.c:25
#define REPITITIONS
int quiet
Definition: rapl_overflow.c:19
static int total
Definition: rapl_overflow.c:9
int retval
Definition: zero_fork.c:53
Here is the call graph for this function: