File: papi_libpfm4_events.c

package info (click to toggle)
papi 5.7.0+dfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 9,856 kB
  • sloc: ansic: 93,265; fortran: 3,338; xml: 2,460; makefile: 815; sh: 290
file content (157 lines) | stat: -rw-r--r-- 4,094 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
* File:    papi_libpfm4_events.c
* Author:  Vince Weaver vincent.weaver @ maine.edu
*          based heavily on existing papi_libpfm3_events.c
*/

#include <string.h>

#include "papi.h"
#include "papi_internal.h"
#include "papi_vector.h"

#include "papi_libpfm4_events.h"

#include "perfmon/pfmlib.h"
#include "perfmon/pfmlib_perf_event.h"

/**********************************************************/
/* Local scope globals                                    */
/**********************************************************/

static int libpfm4_users=0;

/***********************************************************/
/* Exported functions                                      */
/***********************************************************/

/** @class  _papi_libpfm4_error
 *  @brief  convert libpfm error codes to PAPI error codes
 *
 *  @param[in] pfm_error
 *             -- a libpfm4 error code
 *
 *  @returns returns a PAPI error code
 *
 */

int
_papi_libpfm4_error( int pfm_error ) {

  switch ( pfm_error ) {
  case PFM_SUCCESS:      return PAPI_OK;       /* success */
  case PFM_ERR_NOTSUPP:  return PAPI_ENOSUPP;  /* function not supported */
  case PFM_ERR_INVAL:    return PAPI_EINVAL;   /* invalid parameters */
  case PFM_ERR_NOINIT:   return PAPI_ENOINIT;  /* library not initialized */
  case PFM_ERR_NOTFOUND: return PAPI_ENOEVNT;  /* event not found */
  case PFM_ERR_FEATCOMB: return PAPI_ECOMBO;   /* invalid combination of features */
  case PFM_ERR_UMASK:    return PAPI_EATTR;    /* invalid or missing unit mask */
  case PFM_ERR_NOMEM:    return PAPI_ENOMEM;   /* out of memory */
  case PFM_ERR_ATTR:     return PAPI_EATTR;    /* invalid event attribute */
  case PFM_ERR_ATTR_VAL: return PAPI_EATTR;    /* invalid event attribute value */
  case PFM_ERR_ATTR_SET: return PAPI_EATTR;    /* attribute value already set */
  case PFM_ERR_TOOMANY:  return PAPI_ECOUNT;   /* too many parameters */
  case PFM_ERR_TOOSMALL: return PAPI_ECOUNT;   /* parameter is too small */
  default:
	PAPIWARN("Unknown libpfm error code %d, returning PAPI_EINVAL",pfm_error);
	return PAPI_EINVAL;
  }
}

/** @class  _papi_libpfm4_shutdown
 *  @brief  Shutdown any initialization done by the libpfm4 code
 *
 *  @param[in] component
 *        -- component doing the shutdown
 *
 *  @retval PAPI_OK       Success
 *
 */

int
_papi_libpfm4_shutdown(papi_vector_t *my_vector) {

	/* clean out and free the native events structure */
	_papi_hwi_lock( NAMELIB_LOCK );

	libpfm4_users--;

	/* Only free if we're the last user */

	if (!libpfm4_users) {
		pfm_terminate();
	}

	_papi_hwi_unlock( NAMELIB_LOCK );

	strcpy(my_vector->cmp_info.support_version,"");

	return PAPI_OK;
}

/** @class  _papi_libpfm4_init
 *  @brief  Initialize the libpfm4 code
 *
 *  @param[in] my_vector
 *        -- vector of the component doing the initialization
 *
 *  @retval PAPI_OK       Success
 *  @retval PAPI_ECMP     There was an error initializing
 *
 */

int
_papi_libpfm4_init(papi_vector_t *my_vector) {

	int version;
	pfm_err_t retval = PFM_SUCCESS;

	_papi_hwi_lock( NAMELIB_LOCK );

	if (!libpfm4_users) {
		retval = pfm_initialize();
		if ( retval == PFM_SUCCESS ) {
			libpfm4_users++;
		}
		else {
			strncpy(my_vector->cmp_info.disabled_reason,
				pfm_strerror(retval),PAPI_MAX_STR_LEN);
			_papi_hwi_unlock( NAMELIB_LOCK );
			return PAPI_ESBSTR;
		}
	}
	else {
		libpfm4_users++;
	}

	_papi_hwi_unlock( NAMELIB_LOCK );

	/* get the libpfm4 version */

	version=pfm_get_version( );
	if (version >= 0) {

		/* Complain if the compiled-against version */
		/* doesn't match current version            */

		if ( PFM_MAJ_VERSION( version ) !=
			PFM_MAJ_VERSION( LIBPFM_VERSION ) ) {

			PAPIWARN( "Version mismatch of libpfm: "
				"compiled %#x vs. installed %#x\n",
				PFM_MAJ_VERSION( LIBPFM_VERSION ),
				PFM_MAJ_VERSION( version ) );

		}

		/* Set the version */
		sprintf( my_vector->cmp_info.support_version, "%d.%d",
			PFM_MAJ_VERSION( version ),
			PFM_MIN_VERSION( version ) );

	} else {
		PAPIWARN( "pfm_get_version(): %s", pfm_strerror( retval ) );
	}

	return PAPI_OK;
}