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

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 16 of file perf_event_uncore_multiple.c.

16  {
17 
18  int retval;
19  int EventSet = PAPI_NULL;
20  int EventSet2 = PAPI_NULL;
21  long long values[1],values2[1];
22  char *uncore_event=NULL;
23  char event_name[BUFSIZ];
24  int uncore_cidx=-1;
25  const PAPI_component_info_t *info;
26 
27  /* Set TESTS_QUIET variable */
28  tests_quiet( argc, argv );
29 
30  /* Init the PAPI library */
32  if ( retval != PAPI_VER_CURRENT ) {
33  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
34  }
35 
36  /* Find the uncore PMU */
37  uncore_cidx=PAPI_get_component_index("perf_event_uncore");
38  if (uncore_cidx<0) {
39  test_skip(__FILE__,__LINE__,"perf_event_uncore component not found",0);
40  }
41 
42  /* Check if component disabled */
43  info=PAPI_get_component_info(uncore_cidx);
44  if (info->disabled) {
45  test_skip(__FILE__,__LINE__,"uncore component disabled",0);
46  }
47 
48  /* Get a relevant event name */
49  uncore_event=get_uncore_event(event_name, BUFSIZ);
50  if (uncore_event==NULL) {
51  test_skip( __FILE__, __LINE__,
52  "PAPI does not support uncore on this processor", PAPI_ENOSUPP );
53  }
54 
55  /* Create an eventset */
56  retval = PAPI_create_eventset(&EventSet);
57  if (retval != PAPI_OK) {
58  test_fail(__FILE__, __LINE__, "PAPI_create_eventset",retval);
59  }
60 
61  /* Create another eventset */
62  retval = PAPI_create_eventset(&EventSet2);
63  if (retval != PAPI_OK) {
64  test_fail(__FILE__, __LINE__, "PAPI_create_eventset",retval);
65  }
66 
67  /* Set a component for the EventSet */
68  retval = PAPI_assign_eventset_component(EventSet, uncore_cidx);
69 
70  /* we need to set to a certain cpu for uncore to work */
71 
72  PAPI_cpu_option_t cpu_opt;
73 
74  cpu_opt.eventset=EventSet;
75  cpu_opt.cpu_num=0;
76 
77  retval = PAPI_set_opt(PAPI_CPU_ATTACH,(PAPI_option_t*)&cpu_opt);
78  if (retval != PAPI_OK) {
79  test_skip( __FILE__, __LINE__,
80  "this test; trying to PAPI_CPU_ATTACH; need to run as root",
81  retval);
82  }
83 
84  /* we need to set the granularity to system-wide for uncore to work */
85 
87 
88  gran_opt.def_cidx=0;
89  gran_opt.eventset=EventSet;
90  gran_opt.granularity=PAPI_GRN_SYS;
91 
92  retval = PAPI_set_opt(PAPI_GRANUL,(PAPI_option_t*)&gran_opt);
93  if (retval != PAPI_OK) {
94  test_skip( __FILE__, __LINE__,
95  "this test; trying to set PAPI_GRN_SYS",
96  retval);
97  }
98 
99  /* we need to set domain to be as inclusive as possible */
100 
101  PAPI_domain_option_t domain_opt;
102 
103  domain_opt.def_cidx=0;
104  domain_opt.eventset=EventSet;
105  domain_opt.domain=PAPI_DOM_ALL;
106 
107  retval = PAPI_set_opt(PAPI_DOMAIN,(PAPI_option_t*)&domain_opt);
108  if (retval != PAPI_OK) {
109  test_skip( __FILE__, __LINE__,
110  "this test; trying to set PAPI_DOM_ALL; need to run as root",
111  retval);
112  }
113 
114  /* Add our uncore event */
115  retval = PAPI_add_named_event(EventSet, uncore_event);
116  if (retval != PAPI_OK) {
117  if ( !TESTS_QUIET ) {
118  fprintf(stderr,"Error trying to use event %s\n", uncore_event);
119  }
120  test_fail(__FILE__, __LINE__, "adding uncore event ",retval);
121  }
122 
123  /* Add PAPI_TOT_CYC */
124  retval = PAPI_add_named_event(EventSet2, "PAPI_TOT_CYC");
125  if (retval != PAPI_OK) {
126  if ( !TESTS_QUIET ) {
127  fprintf(stderr,"Error trying to add PAPI_TOT_CYC\n");
128  }
129  test_fail(__FILE__, __LINE__, "adding PAPI_TOT_CYC ",retval);
130  }
131 
132 
133  /* Start PAPI */
134  retval = PAPI_start( EventSet );
135  if ( retval != PAPI_OK ) {
136  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
137  }
138 
139  retval = PAPI_start( EventSet2 );
140  if ( retval != PAPI_OK ) {
141  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
142  }
143 
144  /* our work code */
145  do_flops( NUM_FLOPS );
146 
147  /* Stop PAPI */
148  retval = PAPI_stop( EventSet, values );
149  if ( retval != PAPI_OK ) {
150  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
151  }
152  retval = PAPI_stop( EventSet2, values2 );
153  if ( retval != PAPI_OK ) {
154  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
155  }
156 
157  if ( !TESTS_QUIET ) {
158  printf("Uncore and regular event test:\n");
159  printf("Using uncore event %s\n",uncore_event);
160  printf("\t%s: %lld\n",uncore_event,values[0]);
161  printf("\t%s: %lld\n","PAPI_TOT_CYC",values2[0]);
162  }
163 
164  test_pass( __FILE__, NULL, 0 );
165 
166  return 0;
167 }
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:23
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2258
#define NUM_FLOPS
const PAPI_component_info_t * PAPI_get_component_info(int cidx)
Definition: papi.c:807
#define PAPI_CPU_ATTACH
Definition: papi.h:455
int PAPI_add_named_event(int EventSet, char *EventName)
Definition: papi.c:1835
void test_skip(char *file, int line, char *call, int retval)
Definition: test_utils.c:614
#define PAPI_ENOSUPP
Definition: papi.h:269
#define PAPI_NULL
Definition: papi.h:290
int EventSet
Definition: data_range.c:25
#define PAPI_DOM_ALL
Definition: papi.h:301
return PAPI_OK
Definition: linux-nvml.c:458
tests_quiet(argc, argv)
A pointer to the following is passed to PAPI_set/get_opt()
Definition: papi.h:845
#define printf
Definition: papi_test.h:125
test_pass(__FILE__, NULL, 0)
int PAPI_set_opt(int option, PAPI_option_t *ptr)
Definition: papi.c:3409
int int argc
Definition: iozone.c:1609
unsigned int cpu_num
Definition: papi.h:821
int TESTS_QUIET
Definition: test_utils.c:11
char ** argv
Definition: iozone.c:1610
test_fail(__FILE__, __LINE__,"PAPI_library_init", retval)
int PAPI_library_init(int version)
Definition: papi.c:497
#define PAPI_GRANUL
Definition: papi.h:433
int PAPI_get_component_index(char *name)
Definition: papi.c:6536
int EventSet2
Definition: rapl_overflow.c:12
int PAPI_assign_eventset_component(int EventSet, int cidx)
Definition: papi.c:1485
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1424
#define PAPI_DOMAIN
Definition: papi.h:431
void do_flops(int n)
Definition: multiplex.c:23
char * get_uncore_event(char *event, int size)
int PAPI_start(int EventSet)
Definition: papi.c:2053
#define PAPI_GRN_SYS
Definition: papi.h:364
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
ssize_t retval
Definition: libasync.c:338
#define PAPI_VER_CURRENT
Definition: papi.h:223

Here is the call graph for this function: