File: papi_vector.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 (350 lines) | stat: -rw-r--r-- 9,967 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
/*
 * File:    papi_vector.c
 * Author:  Kevin London
 *          london@cs.utk.edu
 * Mods:    Haihang You
 *	       you@cs.utk.edu
 * Mods:    <Your name here>
 *          <Your email here>
 */

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

#include <string.h>

#ifdef _AIX

/* needed because the get_virt_usec() code uses a hardware context */
/* which is a pmapi definition on AIX.                             */
#include <pmapi.h>
#endif


void
_vectors_error(  )
{
	SUBDBG( "function is not implemented in the component!\n" );
	exit( PAPI_ECMP );
}

int
vec_int_ok_dummy(  )
{
	return PAPI_OK;
}

int
vec_int_one_dummy(  )
{
	return 1;
}

int
vec_int_dummy(  )
{
	return PAPI_ECMP;
}

void *
vec_void_star_dummy(  )
{
	return NULL;
}

void
vec_void_dummy(  )
{
	return;
}

long long
vec_long_long_dummy(  )
{
	return PAPI_ECMP;
}

long long
vec_long_long_context_dummy( hwd_context_t *ignored )
{
        (void) ignored;

	return PAPI_ECMP;
}

char *
vec_char_star_dummy(  )
{
	return NULL;
}

long
vec_long_dummy(  )
{
	return PAPI_ECMP;
}

long long vec_virt_cycles(void)
{
  return ((long long) _papi_os_vector.get_virt_usec() * 
	  _papi_hwi_system_info.hw_info.cpu_max_mhz);
}

long long vec_real_nsec_dummy(void)
{
  return ((long long) _papi_os_vector.get_real_usec() * 1000);

}

long long vec_virt_nsec_dummy(void)
{
  return ((long long) _papi_os_vector.get_virt_usec() * 1000);

}


int
_papi_hwi_innoculate_vector( papi_vector_t * v )
{
	if ( !v )
		return ( PAPI_EINVAL );

	/* component function pointers */
	if ( !v->dispatch_timer )
		v->dispatch_timer =
			( void ( * )( int, hwd_siginfo_t *, void * ) ) vec_void_dummy;
	if ( !v->get_overflow_address )
		v->get_overflow_address =
			( void *( * )( int, char *, int ) ) vec_void_star_dummy;
	if ( !v->start )
		v->start = ( int ( * )( hwd_context_t *, hwd_control_state_t * ) )
			vec_int_dummy;
	if ( !v->stop )
		v->stop = ( int ( * )( hwd_context_t *, hwd_control_state_t * ) )
			vec_int_dummy;
	if ( !v->read )
		v->read = ( int ( * )
					( hwd_context_t *, hwd_control_state_t *, long long **,
					  int ) ) vec_int_dummy;
	if ( !v->reset )
		v->reset = ( int ( * )( hwd_context_t *, hwd_control_state_t * ) )
			vec_int_dummy;
	if ( !v->write )
		v->write =
			( int ( * )( hwd_context_t *, hwd_control_state_t *, long long[] ) )
			vec_int_dummy;
	if ( !v->cleanup_eventset ) 
		v->cleanup_eventset = ( int ( * )( hwd_control_state_t * ) ) vec_int_ok_dummy;
	if ( !v->stop_profiling )
		v->stop_profiling =
			( int ( * )( ThreadInfo_t *, EventSetInfo_t * ) ) vec_int_dummy;
	if ( !v->init_component )
		v->init_component = ( int ( * )( int ) ) vec_int_ok_dummy;
	if ( !v->init_thread )
		v->init_thread = ( int ( * )( hwd_context_t * ) ) vec_int_ok_dummy;
	if ( !v->init_control_state )
		v->init_control_state =
			( int ( * )( hwd_control_state_t * ptr ) ) vec_void_dummy;
	if ( !v->update_control_state )
		v->update_control_state = ( int ( * )
									( hwd_control_state_t *, NativeInfo_t *,
									  int, hwd_context_t * ) ) vec_int_dummy;
	if ( !v->ctl )
		v->ctl = ( int ( * )( hwd_context_t *, int, _papi_int_option_t * ) )
			vec_int_dummy;
	if ( !v->set_overflow )
		v->set_overflow =
			( int ( * )( EventSetInfo_t *, int, int ) ) vec_int_dummy;
	if ( !v->set_profile )
		v->set_profile =
			( int ( * )( EventSetInfo_t *, int, int ) ) vec_int_dummy;

	if ( !v->set_domain )
		v->set_domain =
			( int ( * )( hwd_control_state_t *, int ) ) vec_int_dummy;
	if ( !v->ntv_enum_events )
		v->ntv_enum_events = ( int ( * )( unsigned int *, int ) ) vec_int_dummy;
	if ( !v->ntv_name_to_code )
		v->ntv_name_to_code =
			( int ( * )( const char *, unsigned int * ) ) vec_int_dummy;
	if ( !v->ntv_code_to_name )
		v->ntv_code_to_name =
			( int ( * )( unsigned int, char *, int ) ) vec_int_dummy;
	if ( !v->ntv_code_to_descr )
		v->ntv_code_to_descr =
			( int ( * )( unsigned int, char *, int ) ) vec_int_ok_dummy;
	if ( !v->ntv_code_to_bits )
		v->ntv_code_to_bits =
			( int ( * )( unsigned int, hwd_register_t * ) ) vec_int_dummy;
	if ( !v->ntv_code_to_info )
		v->ntv_code_to_info =
			( int ( * )( unsigned int, PAPI_event_info_t * ) ) vec_int_dummy;

	if ( !v->allocate_registers )
		v->allocate_registers =
			( int ( * )( EventSetInfo_t * ) ) vec_int_ok_dummy;

	if ( !v->shutdown_thread )
		v->shutdown_thread = ( int ( * )( hwd_context_t * ) ) vec_int_dummy;
	if ( !v->shutdown_component )
		v->shutdown_component = ( int ( * )( void ) ) vec_int_ok_dummy;
	if ( !v->user )
		v->user = ( int ( * )( int, void *, void * ) ) vec_int_dummy;
	return PAPI_OK;
}


int
_papi_hwi_innoculate_os_vector( papi_os_vector_t * v )
{
	if ( !v )
		return ( PAPI_EINVAL );

	if ( !v->get_real_cycles )
		v->get_real_cycles = vec_long_long_dummy;
	if ( !v->get_real_usec )
		v->get_real_usec = vec_long_long_dummy;
	if ( !v->get_real_nsec )
		v->get_real_nsec = vec_real_nsec_dummy;
	if ( !v->get_virt_cycles )
		v->get_virt_cycles = vec_virt_cycles;
	if ( !v->get_virt_usec )
		v->get_virt_usec = vec_long_long_dummy;
	if ( !v->get_virt_nsec )
		v->get_virt_nsec = vec_virt_nsec_dummy;

	if ( !v->update_shlib_info )
		v->update_shlib_info = ( int ( * )( papi_mdi_t * ) ) vec_int_dummy;
	if ( !v->get_system_info )
		v->get_system_info = ( int ( * )(  ) ) vec_int_dummy;

	if ( !v->get_memory_info )
		v->get_memory_info =
			( int ( * )( PAPI_hw_info_t *, int ) ) vec_int_dummy;

	if ( !v->get_dmem_info )
		v->get_dmem_info = ( int ( * )( PAPI_dmem_info_t * ) ) vec_int_dummy;

	return PAPI_OK;
}

/* not used?  debug only? */
#if 0
static void *
vector_find_dummy( void *func, char **buf )
{
	void *ptr = NULL;

	if ( vec_int_ok_dummy == ( int ( * )(  ) ) func ) {
		ptr = ( void * ) vec_int_ok_dummy;
		if ( buf != NULL )
			*buf = papi_strdup( "vec_int_ok_dummy" );
	} else if ( vec_int_one_dummy == ( int ( * )(  ) ) func ) {
		ptr = ( void * ) vec_int_one_dummy;
		if ( buf != NULL )
			*buf = papi_strdup( "vec_int_one_dummy" );
	} else if ( vec_int_dummy == ( int ( * )(  ) ) func ) {
		ptr = ( void * ) vec_int_dummy;
		if ( buf != NULL )
			*buf = papi_strdup( "vec_int_dummy" );
	} else if ( vec_void_dummy == ( void ( * )(  ) ) func ) {
		ptr = ( void * ) vec_void_dummy;
		if ( buf != NULL )
			*buf = papi_strdup( "vec_void_dummy" );
	} else if ( vec_void_star_dummy == ( void *( * )(  ) ) func ) {
		ptr = ( void * ) vec_void_star_dummy;
		if ( buf != NULL )
			*buf = papi_strdup( "vec_void_star_dummy" );
	} else if ( vec_long_long_dummy == ( long long ( * )(  ) ) func ) {
		ptr = ( void * ) vec_long_long_dummy;
		if ( buf != NULL )
			*buf = papi_strdup( "vec_long_long_dummy" );
	} else if ( vec_char_star_dummy == ( char *( * )(  ) ) func ) {
		ptr = ( void * ) vec_char_star_dummy;
		*buf = papi_strdup( "vec_char_star_dummy" );
	} else if ( vec_long_dummy == ( long ( * )(  ) ) func ) {
		ptr = ( void * ) vec_long_dummy;
		if ( buf != NULL )
			*buf = papi_strdup( "vec_long_dummy" );
	} else {
		ptr = NULL;
	}
	return ( ptr );
}


static void
vector_print_routine( void *func, char *fname, int pfunc )
{
	void *ptr = NULL;
	char *buf = NULL;

	ptr = vector_find_dummy( func, &buf );
	if ( ptr ) {
		printf( "DUMMY: %s is mapped to %s.\n",
				fname, buf );
		papi_free( buf );
	} else if ( ( !ptr && pfunc ) )
		printf( "function: %s is mapped to %p.\n",
				fname, func );
}

static void
vector_print_table( papi_vector_t * v, int print_func )
{

	if ( !v )
		return;

	vector_print_routine( ( void * ) v->dispatch_timer,
						  "_papi_hwd_dispatch_timer", print_func );
	vector_print_routine( ( void * ) v->get_overflow_address,
						  "_papi_hwd_get_overflow_address", print_func );
	vector_print_routine( ( void * ) v->start, "_papi_hwd_start", print_func );
	vector_print_routine( ( void * ) v->stop, "_papi_hwd_stop", print_func );
	vector_print_routine( ( void * ) v->read, "_papi_hwd_read", print_func );
	vector_print_routine( ( void * ) v->reset, "_papi_hwd_reset", print_func );
	vector_print_routine( ( void * ) v->write, "_papi_hwd_write", print_func );
	vector_print_routine( ( void * ) v->cleanup_eventset, 
						  "_papi_hwd_cleanup_eventset", print_func );

	vector_print_routine( ( void * ) v->stop_profiling,
						  "_papi_hwd_stop_profiling", print_func );
	vector_print_routine( ( void * ) v->init_component,
						  "_papi_hwd_init_component", print_func );
	vector_print_routine( ( void * ) v->init_thread, "_papi_hwd_init_thread", print_func );
	vector_print_routine( ( void * ) v->init_control_state,
						  "_papi_hwd_init_control_state", print_func );
	vector_print_routine( ( void * ) v->ctl, "_papi_hwd_ctl", print_func );
	vector_print_routine( ( void * ) v->set_overflow, "_papi_hwd_set_overflow",
						  print_func );
	vector_print_routine( ( void * ) v->set_profile, "_papi_hwd_set_profile",
						  print_func );
	vector_print_routine( ( void * ) v->set_domain, "_papi_hwd_set_domain",
						  print_func );
	vector_print_routine( ( void * ) v->ntv_enum_events,
						  "_papi_hwd_ntv_enum_events", print_func );
	vector_print_routine( ( void * ) v->ntv_name_to_code,
						  "_papi_hwd_ntv_name_to_code", print_func );
	vector_print_routine( ( void * ) v->ntv_code_to_name,
						  "_papi_hwd_ntv_code_to_name", print_func );
	vector_print_routine( ( void * ) v->ntv_code_to_descr,
						  "_papi_hwd_ntv_code_to_descr", print_func );
	vector_print_routine( ( void * ) v->ntv_code_to_bits,
						  "_papi_hwd_ntv_code_to_bits", print_func );
	vector_print_routine( ( void * ) v->ntv_code_to_info,
						  "_papi_hwd_ntv_code_to_info", print_func );

	vector_print_routine( ( void * ) v->allocate_registers,
						  "_papi_hwd_allocate_registers", print_func );

	vector_print_routine( ( void * ) v->shutdown_thread, "_papi_hwd_shutdown_thread",
						  print_func );
	vector_print_routine( ( void * ) v->shutdown_component,
						  "_papi_hwd_shutdown_component", print_func );
	vector_print_routine( ( void * ) v->user, "_papi_hwd_user", print_func );
}

#endif