PAPI  5.6.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
perf_event_amd_northbridge.c File Reference
Include dependency graph for perf_event_amd_northbridge.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 20 of file perf_event_amd_northbridge.c.

20  {
21 
22  int retval;
23  int EventSet = PAPI_NULL;
24  long long values[1];
25  char event_name[BUFSIZ];
26  int uncore_cidx=-1;
27  const PAPI_hw_info_t *hwinfo;
28  int quiet;
29  struct utsname uname_info;
30 
31  /* Set TESTS_QUIET variable */
32  quiet = tests_quiet( argc, argv );
33 
34  uname(&uname_info);
35  if (!quiet) printf("Found Linux %s\n",uname_info.release);
36 
37  /* Init the PAPI library */
39  if ( retval != PAPI_VER_CURRENT ) {
40  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
41  }
42 
43  /* Check for AMD machine */
44  hwinfo = PAPI_get_hardware_info();
45  if ( hwinfo == NULL ) {
46  test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 0 );
47  }
48 
49  if (hwinfo->vendor != PAPI_VENDOR_AMD) {
50  if (!quiet) printf("Test only for AMD machines\n");
51  test_skip(__FILE__,__LINE__,"Test only for AMD processor",0);
52  }
53 
54  if ( hwinfo->cpuid_family != 21) {
55  if (!quiet) printf("Test only for fam15h AMD machines\n");
56  test_skip(__FILE__,__LINE__,"Test only for fam15h AMD processor",0);
57  }
58 
59  if (!strcmp(uname_info.release,"3.9")) {
60 
61  if (!quiet) printf("Detected 3.9 kernel, using perf_event\n");
62 
63  /* For kernel 3.9 use regular CPU component */
64 
65  /* Find the uncore PMU */
66  uncore_cidx=PAPI_get_component_index("perf_event");
67  if (uncore_cidx<0) {
68  test_skip(__FILE__,__LINE__,"perf_event component not found",0);
69  }
70 
71  /* Get a relevant event name */
72  strncpy(event_name,"DRAM_ACCESSES:ALL", BUFSIZ);
73  }
74  else {
75 
76  /* 3.10 and later */
77 
78  if (!quiet) {
79  printf("Detected > 3.9 kernel, using perf_event_uncore\n");
80  }
81 
82  /* Find the uncore PMU */
83  uncore_cidx=PAPI_get_component_index("perf_event_uncore");
84  if (uncore_cidx<0) {
85  test_skip(__FILE__,__LINE__,"perf_event_uncore component not found",0);
86  }
87 
88  /* Get a relevant event name */
89  /* This might change once libpfm4 gets new fam15h NB support */
90  strncpy(event_name,"DRAM_ACCESSES:ALL", BUFSIZ);
91  }
92 
93  /* Create an eventset */
94  retval = PAPI_create_eventset(&EventSet);
95  if (retval != PAPI_OK) {
96  test_fail(__FILE__, __LINE__, "PAPI_create_eventset",retval);
97  }
98 
99  /* Set a component for the EventSet */
100  retval = PAPI_assign_eventset_component(EventSet, uncore_cidx);
101 
102  /* we need to set to a certain cpu for uncore to work */
103 
104  PAPI_cpu_option_t cpu_opt;
105 
106  cpu_opt.eventset=EventSet;
107  cpu_opt.cpu_num=0;
108 
109  retval = PAPI_set_opt(PAPI_CPU_ATTACH,(PAPI_option_t*)&cpu_opt);
110  if (retval != PAPI_OK) {
111  test_skip( __FILE__, __LINE__,
112  "this test; trying to PAPI_CPU_ATTACH; need to run as root",
113  retval);
114  }
115 
116  /* we need to set the granularity to system-wide for uncore to work */
117 
118  PAPI_granularity_option_t gran_opt;
119 
120  gran_opt.def_cidx=0;
121  gran_opt.eventset=EventSet;
122  gran_opt.granularity=PAPI_GRN_SYS;
123 
124  retval = PAPI_set_opt(PAPI_GRANUL,(PAPI_option_t*)&gran_opt);
125  if (retval != PAPI_OK) {
126  test_skip( __FILE__, __LINE__,
127  "this test; trying to set PAPI_GRN_SYS",
128  retval);
129  }
130 
131  /* we need to set domain to be as inclusive as possible */
132 
133  PAPI_domain_option_t domain_opt;
134 
135  domain_opt.def_cidx=0;
136  domain_opt.eventset=EventSet;
137  domain_opt.domain=PAPI_DOM_ALL;
138 
139  retval = PAPI_set_opt(PAPI_DOMAIN,(PAPI_option_t*)&domain_opt);
140  if (retval != PAPI_OK) {
141  test_skip( __FILE__, __LINE__,
142  "this test; trying to set PAPI_DOM_ALL; need to run as root",
143  retval);
144  }
145 
146  /* Add our uncore event */
147  retval = PAPI_add_named_event(EventSet, event_name);
148  if (retval != PAPI_OK) {
149  if ( !quiet ) {
150  fprintf(stderr,"Error trying to use event %s\n", event_name);
151  }
152  test_fail(__FILE__, __LINE__, "adding uncore event",retval);
153  }
154 
155 
156  /* Start PAPI */
157  retval = PAPI_start( EventSet );
158  if ( retval != PAPI_OK ) {
159  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
160  }
161 
162  /* our work code */
163  do_flops( NUM_FLOPS );
164 
165  /* Stop PAPI */
166  retval = PAPI_stop( EventSet, values );
167  if ( retval != PAPI_OK ) {
168  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
169  }
170 
171  if ( !quiet ) {
172  printf("AMD fam15h Northbridge test:\n");
173  printf("Using event %s\n",event_name);
174  printf("\t%s: %lld\n",event_name,values[0]);
175  }
176 
177  test_pass( __FILE__ );
178 
179  return 0;
180 }
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
#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_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
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 PAPI_assign_eventset_component(int EventSet, int cidx)
Definition: papi.c:1526
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1464
int cpuid_family
Definition: papi.h:792
#define PAPI_DOMAIN
Definition: papi.h:433
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
#define PAPI_GRN_SYS
Definition: papi.h:366
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
#define PAPI_VENDOR_AMD
Definition: papi.h:349

Here is the call graph for this function: