PAPI 7.1.0.0
Loading...
Searching...
No Matches
attach_cpu_sys_validate.c
Go to the documentation of this file.
1/*
2 * This test attempts to attach to each CPU
3 * Then it runs some code on one CPU
4 * Then it reads the results, they should be different.
5 * It sets the granularity to SYS as this is known to be broken
6 * with some Linux/rdpmc combinations
7 */
8
9#include <stdio.h>
10#include <stdlib.h>
11
12#include "papi.h"
13#include "papi_test.h"
14
15#include "do_loops.h"
16
17#define MAX_CPUS 16
18
19int
20main( int argc, char **argv )
21{
22 int i;
23 int retval;
24 int num_cpus = 8;
25 int EventSet[MAX_CPUS];
26 const PAPI_hw_info_t *hwinfo;
27 double diff;
28
29 long long values[MAX_CPUS];
30 char event_name[PAPI_MAX_STR_LEN] = "PAPI_TOT_INS";
31 PAPI_option_t opts;
32 int quiet;
33 long long average=0;
34 int same=0;
35
36 /* Set TESTS_QUIET variable */
37 quiet=tests_quiet( argc, argv );
38
40 if ( retval != PAPI_VER_CURRENT ) {
41 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
42 }
43
44 hwinfo = PAPI_get_hardware_info( );
45 if ( hwinfo==NULL) {
46 test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", retval );
47 }
48
49 num_cpus=hwinfo->totalcpus;
50
51 if ( num_cpus < 2 ) {
52 if (!quiet) printf("Need at least 1 CPU\n");
53 test_skip( __FILE__, __LINE__, "num_cpus", 0 );
54 }
55
56 if (num_cpus > MAX_CPUS) {
58 }
59
60 for(i=0;i<num_cpus;i++) {
61
63
65 if ( retval != PAPI_OK ) {
66 test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
67 }
68
69 /* Force event set to be associated with component 0 */
70 /* (perf_events component provides all core events) */
72 if ( retval != PAPI_OK ) {
73 test_fail( __FILE__, __LINE__, "PAPI_assign_eventset_component", retval );
74 }
75
76 /* Force granularity to PAPI_GRN_SYS */
79 PAPI_set_opt( PAPI_GRANUL, &opts) ;
80 if (!quiet) {
81 printf( "Setting Eventset[%d] granularity to: "
82 "%d (%s)\n", i,opts.granularity.granularity,
84 }
85
86 /* Attach this event set to cpu i */
87 opts.cpu.eventset = EventSet[i];
88 opts.cpu.cpu_num = i;
89
91 if ( retval != PAPI_OK ) {
92 if (!quiet) printf("Can't PAPI_CPU_ATTACH: %s\n",
94 test_skip( __FILE__, __LINE__, "PAPI_set_opt", retval );
95 }
96
98 if ( retval != PAPI_OK ) {
99 if (!quiet) printf("Trouble adding event %s\n",event_name);
100 test_skip( __FILE__, __LINE__, "PAPI_add_named_event", retval );
101 }
102 }
103
104 for(i=0;i<num_cpus;i++) {
106 if ( retval != PAPI_OK ) {
107 test_fail( __FILE__, __LINE__, "PAPI_start", retval );
108 }
109 }
110
111 // do some work
113
114 for(i=0;i<num_cpus;i++) {
116 if ( retval != PAPI_OK ) {
117 test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
118 }
119 }
120
121 for(i=0;i<num_cpus;i++) {
122 if (!quiet) {
123 printf ("Event: %s: %10lld on Cpu: %d\n",
124 event_name, values[i], i);
125 }
126 }
127
128 for(i=0;i<num_cpus;i++) {
129 average+=values[i];
130 }
131 average/=num_cpus;
132 if (!quiet) {
133 printf("Average: %10lld\n",average);
134 }
135
136
137 for(i=0;i<num_cpus;i++) {
138 diff=((double)values[i]-(double)average)/(double)average;
139 if ((diff<0.01) && (diff>-0.01)) same++;
140 }
141
142 if (same) {
143 if (!quiet) {
144 printf("Error! %d events were the same\n",same);
145 }
146 test_fail( __FILE__, __LINE__, "Too similar", 0 );
147 }
148
149 PAPI_shutdown( );
150
151 test_pass( __FILE__ );
152
153 return 0;
154
155}
int i
#define MAX_CPUS
add PAPI preset or native hardware event by name to an EventSet
Assign a component index to an existing but empty EventSet.
Create a new empty PAPI EventSet.
get information about the system hardware
initialize the PAPI library.
Set PAPI library or event set options.
Finish using PAPI and free all related resources.
Start counting hardware events in an event set.
Stop counting hardware events in an event set.
Returns a string describing the PAPI error code.
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:29
#define PAPI_CPU_ATTACH
Definition: f90papi.h:19
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_NULL
Definition: f90papi.h:78
#define PAPI_GRANUL
Definition: f90papi.h:179
#define PAPI_MAX_STR_LEN
Definition: f90papi.h:77
#define PAPI_GRN_SYS
Definition: f90papi.h:43
static int EventSet
Definition: init_fini.c:8
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
static int num_cpus
Definition: linux-rapl.c:161
void do_flops(int n)
Definition: multiplex.c:23
Return codes and api definitions.
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
char * stringify_granularity(int granularity)
Definition: test_utils.c:353
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
int main()
Definition: pernode.c:20
int quiet
Definition: rapl_overflow.c:19
#define NUM_FLOPS
Definition: sdsc-mpx.c:24
unsigned int cpu_num
Definition: papi.h:818
Hardware info structure.
Definition: papi.h:774
int totalcpus
Definition: papi.h:780
A pointer to the following is passed to PAPI_set/get_opt()
Definition: papi.h:843
PAPI_granularity_option_t granularity
Definition: papi.h:847
PAPI_cpu_option_t cpu
Definition: papi.h:852
int retval
Definition: zero_fork.c:53