PAPI 7.1.0.0
Loading...
Searching...
No Matches
perf_event_uncore_cbox.c
Go to the documentation of this file.
1/*
2 * This file tests cbox uncore events on Intel Processors
3 */
4
5#include <stdio.h>
6#include <string.h>
7
8#include "papi.h"
9#include "papi_test.h"
10
11#include "do_loops.h"
12
14
15#define EVENTS_TO_TRY 16
16#define MAX_PACKAGES 4
17
18int main( int argc, char **argv ) {
19
20 int retval,i,j,quiet;
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 */
97 if (retval != PAPI_OK) {
98 test_fail(__FILE__, __LINE__, "PAPI_create_eventset",retval);
99 }
100
101 /* Set a component for the EventSet */
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
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 retval = snprintf(uncore_event, BUFSIZ, "%s%d::%s",uncore_base,j,event_name);
130 if( retval >= BUFSIZ ){
131 fprintf(stderr,"Event full name \"%s%d::%s\" has been truncated to \"%s\"\n",uncore_base,j,event_name, uncore_event);
132 }
133 retval = PAPI_add_named_event(EventSet[j][i], uncore_event);
134 if (retval != PAPI_OK) {
135 max_cbox=j;
136 break;
137 }
138 if (!quiet) {
139 printf("Added %s for socket %d\n",uncore_event,i);
140 }
141
142 }
143 }
144
145 for(i=0;i < hwinfo->sockets; i++) {
146
147 for(j=0;j<max_cbox;j++) {
148 if (!quiet) {
149 printf("Starting EventSet %d\n",EventSet[j][i]);
150 }
151
152 /* Start PAPI */
153 retval = PAPI_start( EventSet[j][i] );
154 if ( retval != PAPI_OK ) {
155 printf("Error starting socket %d cbox %d\n",i,j);
156 test_fail( __FILE__, __LINE__, "PAPI_start", retval );
157 }
158 }
159 }
160
161 /* our work code */
163
164 /* Stop PAPI */
165 for(i=0;i < hwinfo->sockets; i++) {
166 for(j=0;j<max_cbox;j++) {
167 retval = PAPI_stop( EventSet[j][i],&values[j][i] );
168 if ( retval != PAPI_OK ) {
169 if (!quiet) {
170 printf("Error stopping socket %d cbox %d\n",i,j);
171 }
172 test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
173 }
174 }
175 }
176
177 /* Print Results */
178 if ( !quiet ) {
179 for(i=0;i < hwinfo->sockets; i++) {
180 printf("Socket %d\n",i);
181 for(j=0;j<max_cbox;j++) {
182 printf("\t%s%d::%s %lld\n",uncore_base,j,event_name,values[j][i]);
183 }
184 }
185 }
186
188
189 test_pass( __FILE__ );
190
191 return 0;
192}
volatile int result
int i
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.
Finish using PAPI and free all related resources.
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_VENDOR_INTEL
Definition: f90papi.h:275
#define PAPI_ENOSUPP
Definition: f90papi.h:244
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
Return codes and api definitions.
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
#define EVENTS_TO_TRY
#define MAX_PACKAGES
char * get_uncore_cbox_event(char *event_name, char *uncore_base, int size)
int main()
Definition: pernode.c:20
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 sockets
Definition: papi.h:778
int vendor
Definition: papi.h:781
int ncpu
Definition: papi.h:775
int cores
Definition: papi.h:777
int threads
Definition: papi.h:776
A pointer to the following is passed to PAPI_set/get_opt()
Definition: papi.h:843
int retval
Definition: zero_fork.c:53