PAPI  5.3.2.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 9 of file perf_event_uncore_cbox.c.

#define MAX_PACKAGES   4

Definition at line 10 of file perf_event_uncore_cbox.c.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 12 of file perf_event_uncore_cbox.c.

12  {
13 
14  int retval,i,j;
16  long long values[EVENTS_TO_TRY][MAX_PACKAGES];
17  char event_name[BUFSIZ];
18  char uncore_base[BUFSIZ];
19  char uncore_event[BUFSIZ];
20  int uncore_cidx=-1;
21  int max_cbox=0;
22  int core_to_use=0;
23 
24  const PAPI_hw_info_t *hwinfo;
25 
26  /* Set TESTS_QUIET variable */
27  tests_quiet( argc, argv );
28 
29  /* Init the PAPI library */
31  if ( retval != PAPI_VER_CURRENT ) {
32  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
33  }
34 
35  /* Find the uncore PMU */
36  uncore_cidx=PAPI_get_component_index("perf_event_uncore");
37  if (uncore_cidx<0) {
38  test_skip(__FILE__,__LINE__,"perf_event_uncore component not found",0);
39  }
40 
41  /* Get hardware info */
42  hwinfo = PAPI_get_hardware_info();
43  if ( hwinfo == NULL ) {
44  test_fail(__FILE__,__LINE__,"PAPI_get_hardware_info()",retval);
45  }
46 
47  /* Get event to use */
48  if (hwinfo->vendor == PAPI_VENDOR_INTEL) {
49 
50  if ( hwinfo->cpuid_family == 6) {
51  switch(hwinfo->cpuid_model) {
52  case 45: /* SandyBridge EP */
53  strncpy(event_name,"UNC_C_TOR_OCCUPANCY:ALL",BUFSIZ);
54  strncpy(uncore_base,"snbep_unc_cbo",BUFSIZ);
55  break;
56  case 58: /* IvyBridge */
57  strncpy(event_name,"UNC_CBO_CACHE_LOOKUP:STATE_I:ANY_FILTER",BUFSIZ);
58  strncpy(uncore_base,"ivb_unc_cbo",BUFSIZ);
59  break;
60  default:
61  test_skip( __FILE__, __LINE__,
62  "We only support IVB and SNB-EP for now", PAPI_ENOSUPP );
63  }
64  }
65  else {
66  test_skip( __FILE__, __LINE__,
67  "We only support IVB and SNB-EP for now", PAPI_ENOSUPP );
68  }
69  }
70  else {
71  test_skip( __FILE__, __LINE__,
72  "This test only supported Intel chips", PAPI_ENOSUPP );
73 
74  }
75 
76  if (!TESTS_QUIET) {
77  printf("Trying for %d sockets\n",hwinfo->sockets);
78  printf("threads %d cores %d ncpus %d\n", hwinfo->threads,hwinfo->cores,
79  hwinfo->ncpu);
80  }
81 
82  for(i=0;i < hwinfo->sockets; i++) {
83 
84  /* perf_event provides which to use in "cpumask" */
85  /* but libpfm4 doesn't report this back to us (yet) */
86  core_to_use=i*hwinfo->threads*hwinfo->cores;
87  if (!TESTS_QUIET) {
88  printf("Using core %d for socket %d\n",core_to_use,i);
89  }
90 
91  for(j=0;j<EVENTS_TO_TRY;j++) {
92 
93  /* Create an eventset */
94  EventSet[j][i]=PAPI_NULL;
95  retval = PAPI_create_eventset(&EventSet[j][i]);
96  if (retval != PAPI_OK) {
97  test_fail(__FILE__, __LINE__, "PAPI_create_eventset",retval);
98  }
99 
100  /* Set a component for the EventSet */
101  retval = PAPI_assign_eventset_component(EventSet[j][i], uncore_cidx);
102  if (retval!=PAPI_OK) {
103  test_fail(__FILE__, __LINE__, "PAPI_assign_eventset_component",retval);
104  }
105 
106  /* we need to set to a certain cpu for uncore to work */
107 
108  PAPI_cpu_option_t cpu_opt;
109 
110  cpu_opt.eventset=EventSet[j][i];
111  cpu_opt.cpu_num=core_to_use;
112 
113  retval = PAPI_set_opt(PAPI_CPU_ATTACH,(PAPI_option_t*)&cpu_opt);
114  if (retval != PAPI_OK) {
115  test_skip( __FILE__, __LINE__,
116  "this test; trying to PAPI_CPU_ATTACH; need to run as root",
117  retval);
118  }
119 
120  /* Default Granularity should work */
121 
122  /* Default domain should work */
123 
124  /* Add our uncore event */
125  sprintf(uncore_event,"%s%d::%s",uncore_base,j,event_name);
126  retval = PAPI_add_named_event(EventSet[j][i], uncore_event);
127  if (retval != PAPI_OK) {
128  max_cbox=j;
129  break;
130  }
131  if (!TESTS_QUIET) printf("Added %s for socket %d\n",uncore_event,i);
132 
133  }
134  }
135 
136 
137  for(i=0;i < hwinfo->sockets; i++) {
138  for(j=0;j<max_cbox;j++) {
139  if (!TESTS_QUIET) printf("Starting EventSet %d\n",EventSet[j][i]);
140  /* Start PAPI */
141  retval = PAPI_start( EventSet[j][i] );
142  if ( retval != PAPI_OK ) {
143  printf("Error starting socket %d cbox %d\n",i,j);
144  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
145  }
146  }
147  }
148 
149  /* our work code */
150  do_flops( NUM_FLOPS );
151 
152  /* Stop PAPI */
153  for(i=0;i < hwinfo->sockets; i++) {
154  for(j=0;j<max_cbox;j++) {
155  retval = PAPI_stop( EventSet[j][i],&values[j][i] );
156  if ( retval != PAPI_OK ) {
157  printf("Error stopping socket %d cbox %d\n",i,j);
158  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
159  }
160  }
161  }
162 
163  /* Print Results */
164  if ( !TESTS_QUIET ) {
165  for(i=0;i < hwinfo->sockets; i++) {
166  printf("Socket %d\n",i);
167  for(j=0;j<max_cbox;j++) {
168  printf("\t%s%d::%s %lld\n",uncore_base,j,event_name,values[j][i]);
169  }
170  }
171  }
172 
173  PAPI_shutdown();
174 
175  test_pass( __FILE__, NULL, 0 );
176 
177 
178  return 0;
179 }
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:23
sprintf(splash[splash_line++],"\tIozone: Performance Test of File I/O\n")
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2232
#define NUM_FLOPS
int cores
Definition: papi.h:778
#define PAPI_CPU_ATTACH
Definition: papi.h:455
Hardware info structure.
Definition: papi.h:775
#define PAPI_NULL
Definition: fpapi.h:13
int PAPI_add_named_event(int EventSet, char *EventName)
Definition: papi.c:1816
void test_skip(char *file, int line, char *call, int retval)
Definition: test_utils.c:614
#define EVENTS_TO_TRY
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:843
#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:3371
int int argc
Definition: iozone.c:1609
unsigned int cpu_num
Definition: papi.h:819
#define MAX_PACKAGES
int TESTS_QUIET
Definition: test_utils.c:11
char ** argv
Definition: iozone.c:1610
int threads
Definition: papi.h:777
test_fail(__FILE__, __LINE__,"PAPI_library_init", retval)
int PAPI_library_init(int version)
Definition: papi.c:495
int i
Definition: fileop.c:140
#define PAPI_ENOSUPP
Definition: fpapi.h:123
void PAPI_shutdown(void)
Definition: papi.c:4357
int cpuid_model
Definition: papi.h:788
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
int PAPI_get_component_index(char *name)
Definition: papi.c:6483
int PAPI_assign_eventset_component(int EventSet, int cidx)
Definition: papi.c:1467
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1406
int cpuid_family
Definition: papi.h:787
#define PAPI_VENDOR_INTEL
Definition: papi.h:346
void do_flops(int n)
Definition: multiplex.c:23
int EventSet
int vendor
Definition: papi.h:782
int PAPI_start(int EventSet)
Definition: papi.c:2026
long j
Definition: iozone.c:19135
const PAPI_hw_info_t * PAPI_get_hardware_info(void)
Definition: papi.c:6059
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
ssize_t retval
Definition: libasync.c:338
int sockets
Definition: papi.h:779
int ncpu
Definition: papi.h:776

Here is the call graph for this function: