PAPI  5.3.2.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
perf_event_amd_northbridge.c
Go to the documentation of this file.
1 /*
2  * This file tests uncore events on AMD fam15h Northbridge machines
3  * The Linux perf_event developers introduced fam15h Northbridge
4  * support in Linux 3.9 with an interfae similar to fam10h
5  * where the events were part of the core CPU
6  * They broke the ABI with Linux 3.10 and made fam15h NB a separate
7  * PMU, like the Intel uncore support.
8  */
9 
10 #include "papi_test.h"
11 int main( int argc, char **argv ) {
12 
13  int retval;
14  int EventSet = PAPI_NULL;
15  long long values[1];
16  char event_name[BUFSIZ];
17  int uncore_cidx=-1;
18  const PAPI_hw_info_t *hwinfo;
19  char kernel[]="3.9";
20 
21  /* Set TESTS_QUIET variable */
22  tests_quiet( argc, argv );
23 
24  /* Init the PAPI library */
26  if ( retval != PAPI_VER_CURRENT ) {
27  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
28  }
29 
30  /* Check for AMD machine */
31  hwinfo = PAPI_get_hardware_info();
32  if ( hwinfo == NULL ) {
33  test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 0 );
34  }
35 
36  if (hwinfo->vendor != PAPI_VENDOR_AMD) {
37  test_skip(__FILE__,__LINE__,"Test only for AMD processor",0);
38  }
39 
40  if ( hwinfo->cpuid_family != 21) {
41  test_skip(__FILE__,__LINE__,"Test only for fam15h AMD processor",0);
42  }
43 
44  if (!strcmp(kernel,"3.9")) {
45 
46  /* For kernel 3.9 use regular CPU component */
47 
48  /* Find the uncore PMU */
49  uncore_cidx=PAPI_get_component_index("perf_event");
50  if (uncore_cidx<0) {
51  test_skip(__FILE__,__LINE__,"perf_event component not found",0);
52  }
53 
54  /* Get a relevant event name */
55  strncpy(event_name,"DRAM_ACCESSES:ALL", BUFSIZ);
56 
57  }
58  else {
59 
60  /* 3.10 and later */
61 
62  /* Find the uncore PMU */
63  uncore_cidx=PAPI_get_component_index("perf_event_uncore");
64  if (uncore_cidx<0) {
65  test_skip(__FILE__,__LINE__,"perf_event_uncore component not found",0);
66  }
67 
68  /* Get a relevant event name */
69  /* This might chanve once libpfm4 gets new fam15h NB support */
70  strncpy(event_name,"DRAM_ACCESSES:ALL", BUFSIZ);
71  }
72 
73  /* Create an eventset */
74  retval = PAPI_create_eventset(&EventSet);
75  if (retval != PAPI_OK) {
76  test_fail(__FILE__, __LINE__, "PAPI_create_eventset",retval);
77  }
78 
79  /* Set a component for the EventSet */
80  retval = PAPI_assign_eventset_component(EventSet, uncore_cidx);
81 
82  /* we need to set to a certain cpu for uncore to work */
83 
84  PAPI_cpu_option_t cpu_opt;
85 
86  cpu_opt.eventset=EventSet;
87  cpu_opt.cpu_num=0;
88 
89  retval = PAPI_set_opt(PAPI_CPU_ATTACH,(PAPI_option_t*)&cpu_opt);
90  if (retval != PAPI_OK) {
91  test_skip( __FILE__, __LINE__,
92  "this test; trying to PAPI_CPU_ATTACH; need to run as root",
93  retval);
94  }
95 
96  /* we need to set the granularity to system-wide for uncore to work */
97 
99 
100  gran_opt.def_cidx=0;
101  gran_opt.eventset=EventSet;
102  gran_opt.granularity=PAPI_GRN_SYS;
103 
104  retval = PAPI_set_opt(PAPI_GRANUL,(PAPI_option_t*)&gran_opt);
105  if (retval != PAPI_OK) {
106  test_skip( __FILE__, __LINE__,
107  "this test; trying to set PAPI_GRN_SYS",
108  retval);
109  }
110 
111  /* we need to set domain to be as inclusive as possible */
112 
113  PAPI_domain_option_t domain_opt;
114 
115  domain_opt.def_cidx=0;
116  domain_opt.eventset=EventSet;
117  domain_opt.domain=PAPI_DOM_ALL;
118 
119  retval = PAPI_set_opt(PAPI_DOMAIN,(PAPI_option_t*)&domain_opt);
120  if (retval != PAPI_OK) {
121  test_skip( __FILE__, __LINE__,
122  "this test; trying to set PAPI_DOM_ALL; need to run as root",
123  retval);
124  }
125 
126  /* Add our uncore event */
127  retval = PAPI_add_named_event(EventSet, event_name);
128  if (retval != PAPI_OK) {
129  if ( !TESTS_QUIET ) {
130  fprintf(stderr,"Error trying to use event %s\n", event_name);
131  }
132  test_fail(__FILE__, __LINE__, "adding uncore event",retval);
133  }
134 
135 
136  /* Start PAPI */
137  retval = PAPI_start( EventSet );
138  if ( retval != PAPI_OK ) {
139  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
140  }
141 
142  /* our work code */
143  do_flops( NUM_FLOPS );
144 
145  /* Stop PAPI */
146  retval = PAPI_stop( EventSet, values );
147  if ( retval != PAPI_OK ) {
148  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
149  }
150 
151  if ( !TESTS_QUIET ) {
152  printf("AMD fam15h Northbridge test:\n");
153  printf("Using event %s\n",event_name);
154  printf("\t%s: %lld\n",event_name,values[0]);
155  }
156 
157  test_pass( __FILE__, NULL, 0 );
158 
159  return 0;
160 }
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:23
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2232
#define NUM_FLOPS
#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
#define PAPI_DOM_ALL
Definition: fpapi.h:25
void test_skip(char *file, int line, char *call, int retval)
Definition: test_utils.c:614
return PAPI_OK
Definition: linux-nvml.c:458
tests_quiet(argc, argv)
#define PAPI_GRN_SYS
Definition: fpapi.h:71
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
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:495
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
#define PAPI_DOMAIN
Definition: fpapi.h:50
int PAPI_get_component_index(char *name)
Definition: papi.c:6483
#define PAPI_GRANUL
Definition: fpapi.h:52
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
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
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 main(int argc, char **argv)
List all appio events codes and names.
#define PAPI_VENDOR_AMD
Definition: papi.h:347