PAPI 7.1.0.0
Loading...
Searching...
No Matches
attach_cpu.c
Go to the documentation of this file.
1/*
2 * This test case creates an event set and attaches it to a cpu. This causes only activity
3 * on that cpu to get counted. The test case then starts the event set does a little work and
4 * then stops the event set. It then prints out the event, count and cpu number which was used
5 * during the test case.
6 *
7 * Since this test case does not try to force its own execution to the cpu which it is using to
8 * count events, it is fairly normal to get zero counts printed at the end of the test. But every
9 * now and then it will count the cpu where the test case is running and then the counts will be non-zero.
10 *
11 * The test case allows the user to specify which cpu should be counted by providing an argument to the
12 * test case (ie: ./attach_cpu 3). Sometimes by trying different cpu numbers with the test case, you
13 * can find the cpu used to run the test (because counts will look like cycle counts).
14 *
15 */
16
17#include <stdio.h>
18#include <stdlib.h>
19
20#include "papi.h"
21#include "papi_test.h"
22
23#include "do_loops.h"
24
25int
26main( int argc, char **argv )
27{
28 int num_tests=1;
29 int num_events=1;
30 int retval;
31 int cpu_num = 1;
32 int EventSet1 = PAPI_NULL;
33 long long **values;
34 char event_name[PAPI_MAX_STR_LEN] = "PAPI_TOT_CYC";
35 PAPI_option_t opts;
36 int quiet;
37
38 /* Set TESTS_QUIET variable */
39 quiet=tests_quiet( argc, argv );
40
41 // user can provide cpu number on which to count events as arg 1
42 if (argc > 1) {
43 retval = atoi(argv[1]);
44 if (retval >= 0) {
45 cpu_num = retval;
46 }
47 }
48
50 if ( retval != PAPI_VER_CURRENT )
51 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
52
54 if ( retval != PAPI_OK )
55 test_fail( __FILE__, __LINE__, "PAPI_attach", retval );
56
57 // Force event set to be associated with component 0 (perf_events component provides all core events)
59 if ( retval != PAPI_OK )
60 test_fail( __FILE__, __LINE__, "PAPI_assign_eventset_component", retval );
61
62 // Attach this event set to cpu 1
63 opts.cpu.eventset = EventSet1;
64 opts.cpu.cpu_num = cpu_num;
65
67 if ( retval != PAPI_OK ) {
68 if (!quiet) printf("Can't PAPI_CPU_ATTACH: %s\n",
70 test_skip( __FILE__, __LINE__, "PAPI_set_opt", retval );
71 }
72
74 if ( retval != PAPI_OK ) {
75 if (!quiet) printf("Trouble adding event %s\n",event_name);
76 test_skip( __FILE__, __LINE__, "PAPI_add_named_event", retval );
77 }
78
79 // get space for counter values (this needs to do this call because it malloc's space that test_pass and friends free)
81
83 if ( retval != PAPI_OK ) {
84 test_fail( __FILE__, __LINE__, "PAPI_start", retval );
85 }
86
87 // do some work
89
91 if ( retval != PAPI_OK )
92 test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
93
94 if (!quiet) printf ("Event: %s: %8lld on Cpu: %d\n", event_name, values[0][0], cpu_num);
95
97
98 test_pass( __FILE__ );
99
100 return 0;
101
102}
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.
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.
Returns a string describing the PAPI error code.
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_MAX_STR_LEN
Definition: f90papi.h:77
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
static int num_events
void do_flops(int n)
Definition: multiplex.c:23
Return codes and api definitions.
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
long long ** allocate_test_space(int num_tests, int num_events)
Definition: test_utils.c:46
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 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
A pointer to the following is passed to PAPI_set/get_opt()
Definition: papi.h:843
PAPI_cpu_option_t cpu
Definition: papi.h:852
int EventSet1
Definition: zero_fork.c:47
int num_tests
Definition: zero_fork.c:53
int retval
Definition: zero_fork.c:53