PAPI  5.6.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
tests/perf_event_uncore.c
Go to the documentation of this file.
1 /*
2  * This file tests uncore events on perf_event kernels
3  *
4  * In this test we use the :cpu=0 way of attaching to the CPU
5  * rather than the legacy PAPI way.
6  */
7 
8 #include <stdio.h>
9 
10 #include "papi.h"
11 #include "papi_test.h"
12 
13 #include "do_loops.h"
14 
15 #include "perf_event_uncore_lib.h"
16 
17 int main( int argc, char **argv ) {
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 the :cpu=0 way of attaching an uncore event to a core\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",
66  PAPI_ENOSUPP );
67  }
68 
69  sprintf(uncore_event,"%s:cpu=0",uncore_event);
70 
71  /* Create an eventset */
72  retval = PAPI_create_eventset(&EventSet);
73  if (retval != PAPI_OK) {
74  test_fail(__FILE__, __LINE__, "PAPI_create_eventset",retval);
75  }
76 
77  /* Add our uncore event */
78  retval = PAPI_add_named_event(EventSet, uncore_event);
79  if (retval != PAPI_OK) {
80  if ( !quiet ) {
81  printf("Error trying to use event %s\n", uncore_event);
82  }
83  test_fail(__FILE__, __LINE__, "adding uncore event",retval);
84  }
85 
86  /* Start PAPI */
87  retval = PAPI_start( EventSet );
88  if ( retval != PAPI_OK ) {
89  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
90  }
91 
92  /* our work code */
94 
95  /* Stop PAPI */
96  retval = PAPI_stop( EventSet, values );
97  if ( retval != PAPI_OK ) {
98  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
99  }
100 
101  if ( !quiet ) {
102  printf("\tUsing event %s\n",uncore_event);
103  printf("\t%s: %lld\n",uncore_event,values[0]);
104  }
105 
106  test_pass( __FILE__ );
107 
108  return 0;
109 }
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:29
sprintf(splash[splash_line++],"\tIozone: Performance Test of File I/O\n")
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2314
const PAPI_component_info_t * PAPI_get_component_info(int cidx)
Definition: papi.c:796
void test_pass(const char *filename)
Definition: test_utils.c:432
#define PAPI_ENOSUPP
Definition: papi.h:271
#define PAPI_NULL
Definition: papi.h:292
int EventSet
return PAPI_OK
Definition: linux-nvml.c:497
#define NUM_FLOPS
Definition: sdsc-mpx.c:24
int int argc
Definition: iozone.c:1609
Return codes and api definitions.
void test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:559
int PAPI_add_named_event(int EventSet, const char *EventName)
Definition: papi.c:1876
char ** argv
Definition: iozone.c:1610
int PAPI_library_init(int version)
Definition: papi.c:500
int quiet
Definition: rapl_overflow.c:18
int PAPI_get_component_index(const char *name)
Definition: papi.c:6610
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1464
void do_flops(int n)
Definition: multiplex.c:23
char * get_uncore_event(char *event, int size)
printf("\tTry: -i 0 -i 1 \n\n")
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
void test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:468
int PAPI_start(int EventSet)
Definition: papi.c:2096
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:225
int main(int argc, char **argv)
List all appio events codes and names.