PAPI  5.4.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
tests/perf_event_uncore.c File Reference
Include dependency graph for tests/perf_event_uncore.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 9 of file tests/perf_event_uncore.c.

9  {
10 
11  int retval;
12  int EventSet = PAPI_NULL;
13  long long values[1];
14  char *uncore_event=NULL;
15  char event_name[BUFSIZ];
16  int uncore_cidx=-1;
17  const PAPI_component_info_t *info;
18 
19  /* Set TESTS_QUIET variable */
20  tests_quiet( argc, argv );
21 
22  /* Init the PAPI library */
24  if ( retval != PAPI_VER_CURRENT ) {
25  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
26  }
27 
28  /* Find the uncore PMU */
29  uncore_cidx=PAPI_get_component_index("perf_event_uncore");
30  if (uncore_cidx<0) {
31  test_skip(__FILE__,__LINE__,"perf_event_uncore component not found",0);
32  }
33 
34  /* Check if component disabled */
35  info=PAPI_get_component_info(uncore_cidx);
36  if (info->disabled) {
37  test_skip(__FILE__,__LINE__,"uncore component disabled",0);
38  }
39 
40  /* Get a relevant event name */
41  uncore_event=get_uncore_event(event_name, BUFSIZ);
42  if (uncore_event==NULL) {
43  test_skip( __FILE__, __LINE__,
44  "PAPI does not support uncore on this processor", PAPI_ENOSUPP );
45  }
46 
47  /* Create an eventset */
48  retval = PAPI_create_eventset(&EventSet);
49  if (retval != PAPI_OK) {
50  test_fail(__FILE__, __LINE__, "PAPI_create_eventset",retval);
51  }
52 
53  /* Set a component for the EventSet */
54  retval = PAPI_assign_eventset_component(EventSet, uncore_cidx);
55 
56  /* we need to set to a certain cpu for uncore to work */
57 
58  PAPI_cpu_option_t cpu_opt;
59 
60  cpu_opt.eventset=EventSet;
61  cpu_opt.cpu_num=0;
62 
63  retval = PAPI_set_opt(PAPI_CPU_ATTACH,(PAPI_option_t*)&cpu_opt);
64  if (retval != PAPI_OK) {
65  test_skip( __FILE__, __LINE__,
66  "this test; trying to PAPI_CPU_ATTACH; need to run as root",
67  retval);
68  }
69 
70  /* we need to set the granularity to system-wide for uncore to work */
71 
73 
74  gran_opt.def_cidx=0;
75  gran_opt.eventset=EventSet;
76  gran_opt.granularity=PAPI_GRN_SYS;
77 
78  retval = PAPI_set_opt(PAPI_GRANUL,(PAPI_option_t*)&gran_opt);
79  if (retval != PAPI_OK) {
80  test_skip( __FILE__, __LINE__,
81  "this test; trying to set PAPI_GRN_SYS",
82  retval);
83  }
84 
85  /* we need to set domain to be as inclusive as possible */
86 
87  PAPI_domain_option_t domain_opt;
88 
89  domain_opt.def_cidx=0;
90  domain_opt.eventset=EventSet;
91  domain_opt.domain=PAPI_DOM_ALL;
92 
93  retval = PAPI_set_opt(PAPI_DOMAIN,(PAPI_option_t*)&domain_opt);
94  if (retval != PAPI_OK) {
95  test_skip( __FILE__, __LINE__,
96  "this test; trying to set PAPI_DOM_ALL; need to run as root",
97  retval);
98  }
99 
100  /* Add our uncore event */
101  retval = PAPI_add_named_event(EventSet, uncore_event);
102  if (retval != PAPI_OK) {
103  if ( !TESTS_QUIET ) {
104  fprintf(stderr,"Error trying to use event %s\n", uncore_event);
105  }
106  test_fail(__FILE__, __LINE__, "adding uncore event",retval);
107  }
108 
109 
110  /* Start PAPI */
111  retval = PAPI_start( EventSet );
112  if ( retval != PAPI_OK ) {
113  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
114  }
115 
116  /* our work code */
117  do_flops( NUM_FLOPS );
118 
119  /* Stop PAPI */
120  retval = PAPI_stop( EventSet, values );
121  if ( retval != PAPI_OK ) {
122  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
123  }
124 
125  if ( !TESTS_QUIET ) {
126  printf("Uncore test:\n");
127  printf("Using event %s\n",uncore_event);
128  printf("\t%s: %lld\n",uncore_event,values[0]);
129  }
130 
131  test_pass( __FILE__, NULL, 0 );
132 
133  return 0;
134 }
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:23
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2258
#define NUM_FLOPS
const PAPI_component_info_t * PAPI_get_component_info(int cidx)
Definition: papi.c:807
#define PAPI_CPU_ATTACH
Definition: papi.h:455
int PAPI_add_named_event(int EventSet, char *EventName)
Definition: papi.c:1835
void test_skip(char *file, int line, char *call, int retval)
Definition: test_utils.c:614
#define PAPI_ENOSUPP
Definition: papi.h:269
#define PAPI_NULL
Definition: papi.h:290
int EventSet
Definition: data_range.c:25
#define PAPI_DOM_ALL
Definition: papi.h:301
return PAPI_OK
Definition: linux-nvml.c:458
tests_quiet(argc, argv)
A pointer to the following is passed to PAPI_set/get_opt()
Definition: papi.h:845
#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:3409
int int argc
Definition: iozone.c:1609
unsigned int cpu_num
Definition: papi.h:821
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:497
#define PAPI_GRANUL
Definition: papi.h:433
int PAPI_get_component_index(char *name)
Definition: papi.c:6536
int PAPI_assign_eventset_component(int EventSet, int cidx)
Definition: papi.c:1485
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1424
#define PAPI_DOMAIN
Definition: papi.h:431
void do_flops(int n)
Definition: multiplex.c:23
char * get_uncore_event(char *event, int size)
int PAPI_start(int EventSet)
Definition: papi.c:2053
#define PAPI_GRN_SYS
Definition: papi.h:364
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:223

Here is the call graph for this function: