PAPI 7.1.0.0
Loading...
Searching...
No Matches
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

◆ main()

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 */
95 if (retval != PAPI_OK) {
96 test_fail(__FILE__, __LINE__, "PAPI_create_eventset",retval);
97 }
98
99 /* Set a component for the EventSet */
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
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
119
120 gran_opt.def_cidx=0;
121 gran_opt.eventset=EventSet;
122 gran_opt.granularity=PAPI_GRN_SYS;
123
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
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 */
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 */
158 if ( retval != PAPI_OK ) {
159 test_fail( __FILE__, __LINE__, "PAPI_start", retval );
160 }
161
162 /* our work code */
164
165 /* Stop PAPI */
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}
add PAPI preset or native hardware event by name to an EventSet
Assign a component index to an existing but empty EventSet.
Create a new empty PAPI EventSet.
returns the component index for the named component
get information about the system hardware
initialize the PAPI library.
Set PAPI library or event set options.
Start counting hardware events in an event set.
Stop counting hardware events in an event set.
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:29
#define PAPI_CPU_ATTACH
Definition: f90papi.h:19
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_NULL
Definition: f90papi.h:78
#define PAPI_GRANUL
Definition: f90papi.h:179
#define PAPI_VENDOR_AMD
Definition: f90papi.h:230
#define PAPI_DOMAIN
Definition: f90papi.h:159
#define PAPI_GRN_SYS
Definition: f90papi.h:43
#define PAPI_DOM_ALL
Definition: f90papi.h:261
static int EventSet
Definition: init_fini.c:8
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
void do_flops(int n)
Definition: multiplex.c:23
FILE * stderr
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
void PAPI_NORETURN test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:491
void PAPI_NORETURN test_pass(const char *filename)
Definition: test_utils.c:432
void PAPI_NORETURN test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:584
int quiet
Definition: rapl_overflow.c:19
#define NUM_FLOPS
Definition: sdsc-mpx.c:24
unsigned int cpu_num
Definition: papi.h:818
Hardware info structure.
Definition: papi.h:774
int cpuid_family
Definition: papi.h:786
int vendor
Definition: papi.h:781
A pointer to the following is passed to PAPI_set/get_opt()
Definition: papi.h:843
int retval
Definition: zero_fork.c:53
Here is the call graph for this function: