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

Go to the source code of this file.

Macros

#define EVENTS_TO_TRY   16
 
#define MAX_PACKAGES   4
 

Functions

int main (int argc, char **argv)
 

Macro Definition Documentation

#define EVENTS_TO_TRY   16

Definition at line 15 of file perf_event_uncore_cbox.c.

#define MAX_PACKAGES   4

Definition at line 16 of file perf_event_uncore_cbox.c.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 18 of file perf_event_uncore_cbox.c.

18  {
19 
20  int retval,i,j,quiet;
22  long long values[EVENTS_TO_TRY][MAX_PACKAGES];
23  char event_name[BUFSIZ];
24  char uncore_base[BUFSIZ];
25  char uncore_event[BUFSIZ];
26  int uncore_cidx=-1;
27  int max_cbox=0;
28  int core_to_use=0;
29  char *result;
30 
31  const PAPI_hw_info_t *hwinfo;
32 
33  /* Set TESTS_QUIET variable */
34  quiet = tests_quiet( argc, argv );
35 
36  /* Init the PAPI library */
38  if ( retval != PAPI_VER_CURRENT ) {
39  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
40  }
41 
42  /* Find the uncore PMU */
43  uncore_cidx=PAPI_get_component_index("perf_event_uncore");
44  if (uncore_cidx<0) {
45  if (!quiet) {
46  printf("perf_event_uncore component not found\n");
47  }
48  test_skip(__FILE__,__LINE__,"perf_event_uncore component not found",0);
49  }
50 
51  /* Get hardware info */
52  hwinfo = PAPI_get_hardware_info();
53  if ( hwinfo == NULL ) {
54  test_fail(__FILE__,__LINE__,"PAPI_get_hardware_info()",retval);
55  }
56 
57  /* Get event to use */
58  if (hwinfo->vendor == PAPI_VENDOR_INTEL) {
59  result=get_uncore_cbox_event(event_name,uncore_base,BUFSIZ);
60 
61  if (result==NULL) {
62  if (!quiet) {
63  printf("No event available\n");
64  }
65  test_skip( __FILE__, __LINE__,
66  "No event available", PAPI_ENOSUPP );
67  }
68  }
69  else {
70  if (!quiet) {
71  printf("We only support Intel for now\n");
72  }
73  test_skip( __FILE__, __LINE__,
74  "This test only supported Intel chips", PAPI_ENOSUPP );
75  }
76 
77  if (!quiet) {
78  printf("Trying for %d sockets\n",hwinfo->sockets);
79  printf("threads %d cores %d ncpus %d\n", hwinfo->threads,hwinfo->cores,
80  hwinfo->ncpu);
81  }
82 
83  for(i=0;i < hwinfo->sockets; i++) {
84 
85  /* perf_event provides which to use in "cpumask" */
86  /* but libpfm4 doesn't report this back to us (yet) */
87  core_to_use=i*hwinfo->threads*hwinfo->cores;
88  if (!quiet) {
89  printf("Using core %d for socket %d\n",core_to_use,i);
90  }
91 
92  for(j=0;j<EVENTS_TO_TRY;j++) {
93 
94  /* Create an eventset */
95  EventSet[j][i]=PAPI_NULL;
96  retval = PAPI_create_eventset(&EventSet[j][i]);
97  if (retval != PAPI_OK) {
98  test_fail(__FILE__, __LINE__, "PAPI_create_eventset",retval);
99  }
100 
101  /* Set a component for the EventSet */
102  retval = PAPI_assign_eventset_component(EventSet[j][i], uncore_cidx);
103  if (retval!=PAPI_OK) {
104  test_fail(__FILE__, __LINE__, "PAPI_assign_eventset_component",retval);
105  }
106 
107  /* we need to set to a certain cpu for uncore to work */
108 
109  PAPI_cpu_option_t cpu_opt;
110 
111  cpu_opt.eventset=EventSet[j][i];
112  cpu_opt.cpu_num=core_to_use;
113 
114  retval = PAPI_set_opt(PAPI_CPU_ATTACH,(PAPI_option_t*)&cpu_opt);
115  if (retval != PAPI_OK) {
116  if (!quiet) {
117  printf("Problem with PAPI_CPU_ATTACH\n");
118  }
119  test_skip( __FILE__, __LINE__,
120  "this test; trying to PAPI_CPU_ATTACH; need to run as root",
121  retval);
122  }
123 
124  /* Default Granularity should work */
125 
126  /* Default domain should work */
127 
128  /* Add our uncore event */
129  sprintf(uncore_event,"%s%d::%s",uncore_base,j,event_name);
130  retval = PAPI_add_named_event(EventSet[j][i], uncore_event);
131  if (retval != PAPI_OK) {
132  max_cbox=j;
133  break;
134  }
135  if (!quiet) {
136  printf("Added %s for socket %d\n",uncore_event,i);
137  }
138 
139  }
140  }
141 
142  for(i=0;i < hwinfo->sockets; i++) {
143 
144  for(j=0;j<max_cbox;j++) {
145  if (!quiet) {
146  printf("Starting EventSet %d\n",EventSet[j][i]);
147  }
148 
149  /* Start PAPI */
150  retval = PAPI_start( EventSet[j][i] );
151  if ( retval != PAPI_OK ) {
152  printf("Error starting socket %d cbox %d\n",i,j);
153  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
154  }
155  }
156  }
157 
158  /* our work code */
159  do_flops( NUM_FLOPS );
160 
161  /* Stop PAPI */
162  for(i=0;i < hwinfo->sockets; i++) {
163  for(j=0;j<max_cbox;j++) {
164  retval = PAPI_stop( EventSet[j][i],&values[j][i] );
165  if ( retval != PAPI_OK ) {
166  if (!quiet) {
167  printf("Error stopping socket %d cbox %d\n",i,j);
168  }
169  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
170  }
171  }
172  }
173 
174  /* Print Results */
175  if ( !quiet ) {
176  for(i=0;i < hwinfo->sockets; i++) {
177  printf("Socket %d\n",i);
178  for(j=0;j<max_cbox;j++) {
179  printf("\t%s%d::%s %lld\n",uncore_base,j,event_name,values[j][i]);
180  }
181  }
182  }
183 
184  PAPI_shutdown();
185 
186  test_pass( __FILE__ );
187 
188  return 0;
189 }
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:29
sprintf(splash[splash_line++],"\tIozone: Performance Test of File I/O\n")
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2314
int cores
Definition: papi.h:783
#define PAPI_CPU_ATTACH
Definition: papi.h:457
void test_pass(const char *filename)
Definition: test_utils.c:432
Hardware info structure.
Definition: papi.h:780
#define PAPI_ENOSUPP
Definition: papi.h:271
#define PAPI_NULL
Definition: papi.h:292
#define EVENTS_TO_TRY
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
#define MAX_PACKAGES
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 threads
Definition: papi.h:782
int PAPI_library_init(int version)
Definition: papi.c:500
int i
Definition: fileop.c:140
void PAPI_shutdown(void)
Definition: papi.c:4461
int quiet
Definition: rapl_overflow.c:18
int PAPI_get_component_index(const char *name)
Definition: papi.c:6610
char * get_uncore_cbox_event(char *event_name, char *uncore_base, int size)
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_VENDOR_INTEL
Definition: papi.h:348
void do_flops(int n)
Definition: multiplex.c:23
int vendor
Definition: papi.h:787
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
long j
Definition: iozone.c:19135
const PAPI_hw_info_t * PAPI_get_hardware_info(void)
Definition: papi.c:6185
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 sockets
Definition: papi.h:784
int ncpu
Definition: papi.h:781

Here is the call graph for this function: