PAPI 7.1.0.0
Loading...
Searching...
No Matches
perf_event_uncore_attach.c File Reference
Include dependency graph for perf_event_uncore_attach.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 17 of file perf_event_uncore_attach.c.

17 {
18
19 int retval,quiet;
20 int EventSet = PAPI_NULL;
21 long long values[1];
22 char *uncore_event=NULL;
23 char event_name[BUFSIZ];
24 int uncore_cidx=-1;
25 const PAPI_component_info_t *info;
26
27 /* Set TESTS_QUIET variable */
28 quiet = tests_quiet( argc, argv );
29
30 if (!quiet) {
31 printf("Testing creating an uncore event using PAPI_set_opt() to specify CPU\n");
32 }
33
34 /* Init the PAPI library */
36 if ( retval != PAPI_VER_CURRENT ) {
37 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
38 }
39
40 /* Find the uncore PMU */
41 uncore_cidx=PAPI_get_component_index("perf_event_uncore");
42 if (uncore_cidx<0) {
43 if (!quiet) {
44 printf("perf_event_uncore component not found\n");
45 }
46 test_skip(__FILE__,__LINE__,"perf_event_uncore component not found",0);
47 }
48
49 /* Check if component disabled */
50 info=PAPI_get_component_info(uncore_cidx);
51 if (info->disabled) {
52 if (!quiet) {
53 printf("perf_event_uncore component is disabled\n");
54 }
55 test_skip(__FILE__,__LINE__,"uncore component disabled",0);
56 }
57
58 /* Get a relevant event name */
59 uncore_event=get_uncore_event(event_name, BUFSIZ);
60 if (uncore_event==NULL) {
61 if (!quiet) {
62 printf("uncore event name not available\n");
63 }
64 test_skip( __FILE__, __LINE__,
65 "PAPI does not support uncore on this processor",
67 }
68
69 /* Create an eventset */
71 if (retval != PAPI_OK) {
72 test_fail(__FILE__, __LINE__, "PAPI_create_eventset",retval);
73 }
74
75 /* Set a component for the EventSet */
77
78 /* we need to set to a certain cpu for uncore to work */
79
80 PAPI_cpu_option_t cpu_opt;
81
82 cpu_opt.eventset=EventSet;
83 cpu_opt.cpu_num=0;
84
86 if (retval != PAPI_OK) {
87 if (!quiet) {
88 printf("Could not cpu attach\n");
89 }
90 test_skip( __FILE__, __LINE__,
91 "this test; trying to PAPI_CPU_ATTACH; need to run as root",
92 retval);
93 }
94
95 /* we need to set the granularity to system-wide for uncore to work */
96
98
99 gran_opt.def_cidx=0;
100 gran_opt.eventset=EventSet;
101 gran_opt.granularity=PAPI_GRN_SYS;
102
104 if (retval != PAPI_OK) {
105 test_skip( __FILE__, __LINE__,
106 "this test; trying to set PAPI_GRN_SYS",
107 retval);
108 }
109
110 /* we need to set domain to be as inclusive as possible */
111
112 PAPI_domain_option_t domain_opt;
113
114 domain_opt.def_cidx=0;
115 domain_opt.eventset=EventSet;
116 domain_opt.domain=PAPI_DOM_ALL;
117
119 if (retval != PAPI_OK) {
120 if (!quiet) {
121 printf("could not set PAPI_DOM_ALL\n");
122 }
123 test_skip( __FILE__, __LINE__,
124 "this test; trying to set PAPI_DOM_ALL; need to run as root",
125 retval);
126 }
127
128 /* Add our uncore event */
129 retval = PAPI_add_named_event(EventSet, uncore_event);
130 if (retval != PAPI_OK) {
131 if ( !quiet ) {
132 printf("Error trying to use event %s\n", uncore_event);
133 }
134 test_fail(__FILE__, __LINE__, "adding uncore event",retval);
135 }
136
137 /* Start PAPI */
139 if ( retval != PAPI_OK ) {
140 test_fail( __FILE__, __LINE__, "PAPI_start", retval );
141 }
142
143 /* our work code */
145
146 /* Stop PAPI */
148 if ( retval != PAPI_OK ) {
149 test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
150 }
151
152 if ( !quiet ) {
153 printf("\tUsing event %s\n",uncore_event);
154 printf("\t%s: %lld\n",uncore_event,values[0]);
155 }
156
157 test_pass( __FILE__ );
158
159 return 0;
160}
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 a specific software component
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_ENOSUPP
Definition: f90papi.h:244
#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
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
char * get_uncore_event(char *event, int size)
int quiet
Definition: rapl_overflow.c:19
#define NUM_FLOPS
Definition: sdsc-mpx.c:24
unsigned int cpu_num
Definition: papi.h:818
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: