PAPI  5.6.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
perf_event_uncore_multiple.c
Go to the documentation of this file.
1 /*
2  * This file tests measuring uncore and non-uncore events at the same time
3  *
4  * Despite perf_event supporting this, PAPI had to do this with
5  * separate event sets on separate components.
6  *
7  * PAPI does not allow two eventsets to be running simultaneously
8  * on the same component, nor does it allow events in the same
9  * event set to have different domains/granularities.
10  */
11 
12 #include <stdio.h>
13 
14 #include "papi.h"
15 #include "papi_test.h"
16 
17 #include "do_loops.h"
18 
19 #include "perf_event_uncore_lib.h"
20 
21 int main( int argc, char **argv ) {
22 
23  int retval,quiet;
24  int EventSet = PAPI_NULL;
25  int EventSet2 = PAPI_NULL;
26  long long values[1],values2[1];
27  char *uncore_event=NULL;
28  char event_name[BUFSIZ];
29  int uncore_cidx=-1;
30  const PAPI_component_info_t *info;
31 
32  /* Set TESTS_QUIET variable */
33  quiet = tests_quiet( argc, argv );
34 
35  /* Init the PAPI library */
37  if ( retval != PAPI_VER_CURRENT ) {
38  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
39  }
40 
41  /* Find the uncore PMU */
42  uncore_cidx=PAPI_get_component_index("perf_event_uncore");
43  if (uncore_cidx<0) {
44  if (!quiet) {
45  printf("perf_event_uncore component not found\n");
46  }
47  test_skip(__FILE__,__LINE__,"perf_event_uncore component not found",0);
48  }
49 
50  /* Check if component disabled */
51  info=PAPI_get_component_info(uncore_cidx);
52  if (info->disabled) {
53  if (!quiet) {
54  printf("perf_event_uncore component disabled\n");
55  }
56  test_skip(__FILE__,__LINE__,"uncore component disabled",0);
57  }
58 
59  /* Get a relevant event name */
60  uncore_event=get_uncore_event(event_name, BUFSIZ);
61  if (uncore_event==NULL) {
62  if (!quiet) {
63  printf("Could not find an uncore event for this processor\n");
64  }
65  test_skip( __FILE__, __LINE__,
66  "PAPI does not support uncore on this processor",
67  PAPI_ENOSUPP );
68  }
69 
70  /* Create an eventset */
71  retval = PAPI_create_eventset(&EventSet);
72  if (retval != PAPI_OK) {
73  test_fail(__FILE__, __LINE__, "PAPI_create_eventset",retval);
74  }
75 
76  /* Create another eventset */
77  retval = PAPI_create_eventset(&EventSet2);
78  if (retval != PAPI_OK) {
79  test_fail(__FILE__, __LINE__, "PAPI_create_eventset",retval);
80  }
81 
82  /* Set a component for the EventSet */
83  retval = PAPI_assign_eventset_component(EventSet, uncore_cidx);
84 
85  /* we need to set to a certain cpu for uncore to work */
86 
87  PAPI_cpu_option_t cpu_opt;
88 
89  cpu_opt.eventset=EventSet;
90  cpu_opt.cpu_num=0;
91 
92  retval = PAPI_set_opt(PAPI_CPU_ATTACH,(PAPI_option_t*)&cpu_opt);
93  if (retval != PAPI_OK) {
94  if (!quiet) {
95  printf("Could not PAPI_CPU_ATTACH\n");
96  }
97  test_skip( __FILE__, __LINE__,
98  "this test; trying to PAPI_CPU_ATTACH; need to run as root",
99  retval);
100  }
101 
102  /* we need to set the granularity to system-wide for uncore to work */
103 
104  PAPI_granularity_option_t gran_opt;
105 
106  gran_opt.def_cidx=0;
107  gran_opt.eventset=EventSet;
108  gran_opt.granularity=PAPI_GRN_SYS;
109 
110  retval = PAPI_set_opt(PAPI_GRANUL,(PAPI_option_t*)&gran_opt);
111  if (retval != PAPI_OK) {
112  if (!quiet) {
113  printf("Could not set PAPI_GRN_SYS\n");
114  }
115  test_skip( __FILE__, __LINE__,
116  "this test; trying to set PAPI_GRN_SYS",
117  retval);
118  }
119 
120  /* we need to set domain to be as inclusive as possible */
121 
122  PAPI_domain_option_t domain_opt;
123 
124  domain_opt.def_cidx=0;
125  domain_opt.eventset=EventSet;
126  domain_opt.domain=PAPI_DOM_ALL;
127 
128  retval = PAPI_set_opt(PAPI_DOMAIN,(PAPI_option_t*)&domain_opt);
129  if (retval != PAPI_OK) {
130  if (!quiet) {
131  printf("Could not set PAPI_DOM_ALL\n");
132  }
133  test_skip( __FILE__, __LINE__,
134  "this test; trying to set PAPI_DOM_ALL; need to run as root",
135  retval);
136  }
137 
138  /* Add our uncore event */
139  retval = PAPI_add_named_event(EventSet, uncore_event);
140  if (retval != PAPI_OK) {
141  if ( !quiet ) {
142  printf("Error trying to use event %s\n", uncore_event);
143  }
144  test_fail(__FILE__, __LINE__, "adding uncore event ",retval);
145  }
146 
147  /* Add PAPI_TOT_CYC */
148  retval = PAPI_add_named_event(EventSet2, "PAPI_TOT_CYC");
149  if (retval != PAPI_OK) {
150  if ( !quiet ) {
151  printf("Error trying to add PAPI_TOT_CYC\n");
152  }
153  test_fail(__FILE__, __LINE__, "adding PAPI_TOT_CYC ",retval);
154  }
155 
156 
157  /* Start PAPI */
158  retval = PAPI_start( EventSet );
159  if ( retval != PAPI_OK ) {
160  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
161  }
162 
163  retval = PAPI_start( EventSet2 );
164  if ( retval != PAPI_OK ) {
165  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
166  }
167 
168  /* our work code */
169  do_flops( NUM_FLOPS );
170 
171  /* Stop PAPI */
172  retval = PAPI_stop( EventSet, values );
173  if ( retval != PAPI_OK ) {
174  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
175  }
176 
177  retval = PAPI_stop( EventSet2, values2 );
178  if ( retval != PAPI_OK ) {
179  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
180  }
181 
182  if ( !quiet ) {
183  printf("Uncore and regular event test:\n");
184  printf("Using uncore event %s\n",uncore_event);
185  printf("\t%s: %lld\n",uncore_event,values[0]);
186  printf("\t%s: %lld\n","PAPI_TOT_CYC",values2[0]);
187  }
188 
189  test_pass( __FILE__ );
190 
191  return 0;
192 }
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:29
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2314
const PAPI_component_info_t * PAPI_get_component_info(int cidx)
Definition: papi.c:796
#define PAPI_CPU_ATTACH
Definition: papi.h:457
void test_pass(const char *filename)
Definition: test_utils.c:432
#define PAPI_ENOSUPP
Definition: papi.h:271
#define PAPI_NULL
Definition: papi.h:292
#define PAPI_DOM_ALL
Definition: papi.h:303
int EventSet
return PAPI_OK
Definition: linux-nvml.c:497
A pointer to the following is passed to PAPI_set/get_opt()
Definition: papi.h:848
#define NUM_FLOPS
Definition: sdsc-mpx.c:24
int PAPI_set_opt(int option, PAPI_option_t *ptr)
Definition: papi.c:3465
int int argc
Definition: iozone.c:1609
unsigned int cpu_num
Definition: papi.h:824
Return codes and api definitions.
void test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:559
int PAPI_add_named_event(int EventSet, const char *EventName)
Definition: papi.c:1876
char ** argv
Definition: iozone.c:1610
int PAPI_library_init(int version)
Definition: papi.c:500
int quiet
Definition: rapl_overflow.c:18
int PAPI_get_component_index(const char *name)
Definition: papi.c:6610
#define PAPI_GRANUL
Definition: papi.h:435
int EventSet2
Definition: rapl_overflow.c:16
int PAPI_assign_eventset_component(int EventSet, int cidx)
Definition: papi.c:1526
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1464
#define PAPI_DOMAIN
Definition: papi.h:433
void do_flops(int n)
Definition: multiplex.c:23
char * get_uncore_event(char *event, int size)
printf("\tTry: -i 0 -i 1 \n\n")
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
void test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:468
int PAPI_start(int EventSet)
Definition: papi.c:2096
#define PAPI_GRN_SYS
Definition: papi.h:366
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:225
int main(int argc, char **argv)
List all appio events codes and names.