PAPI 7.1.0.0
Loading...
Searching...
No Matches
coretemp_freebsd.c
Go to the documentation of this file.
1/****************************/
2/* THIS IS OPEN SOURCE CODE */
3/****************************/
4
22#include <sys/types.h>
23#include <sys/resource.h>
24#include <sys/sysctl.h>
25
26#include <stdio.h>
27#include <string.h>
28#include <stdlib.h>
29#include <inttypes.h>
30
31/* Headers required by PAPI */
32#include "papi.h"
33#include "papi_internal.h"
34#include "papi_vector.h"
35#include "papi_memory.h"
36
37#define CORETEMP_MAX_COUNTERS 32 /* Can we tune this dynamically? */
38#define TRUE (1==1)
39#define FALSE (1!=1)
40#define UNREFERENCED(x) (void)x
41
42/* Structure that stores private information for each event */
43typedef struct coretemp_register
44{
45 int mib[4];
46 /* Access to registers through these MIBs + sysctl (3) call */
47
48 unsigned int selector;
52
54typedef struct coretemp_native_event_entry
55{
58 char description[PAPI_MAX_STR_LEN];
60
61/* This structure is used when doing register allocation
62 it possibly is not necessary when there are no
63 register constraints */
64typedef struct coretemp_reg_alloc
65{
68
69/* Holds control flags, usually out-of band configuration of the hardware */
70typedef struct coretemp_control_state
71{
75
76/* Holds per-thread information */
77typedef struct coretemp_context
78{
81
84
86static int CORETEMP_NUM_EVENTS = 0;
87
88
89/********************************************************************/
90/* Below are the functions required by the PAPI component interface */
91/********************************************************************/
92
95{
96 int mib[4];
97 size_t len;
98 UNREFERENCED(ctx);
99
100 ( void ) mib; /*unused */
101 ( void ) len; /*unused */
102
103 SUBDBG("coretemp_init_thread %p...\n", ctx);
104
105#if 0
106 /* what does this do? VMW */
107
108 len = 4;
109 if (sysctlnametomib ("dev.coretemp.0.%driver", mib, &len) == -1)
110 return PAPI_ECMP;
111#endif
112
113 return PAPI_OK;
114}
115
116
122{
123 int ret;
124 int i;
125 int mib[4];
126 size_t len;
127 char tmp[128];
128 int retval = PAPI_OK;
129
130 SUBDBG("coretemp_init_component...\n");
131
132 /* Count the number of cores (counters) that have sensors allocated */
133 i = 0;
135 sprintf (tmp, "dev.coretemp.%d.%%driver", i);
136 len = 4;
137 ret = sysctlnametomib (tmp, mib, &len);
138 while (ret != -1)
139 {
141 i++;
142 sprintf (tmp, "dev.coretemp.%d.%%driver", i);
143 len = 4;
144 ret = sysctlnametomib (tmp, mib, &len);
145 }
146
147 if (CORETEMP_NUM_EVENTS == 0)
148 goto fn_exit;
149
150 /* Allocate memory for the our event table */
153 if (coretemp_native_table == NULL)
154 {
155 perror( "malloc():Could not get memory for coretemp events table" );
157 goto fn_fail;
158 }
159
160 /* Allocate native events internal structures */
161 for (i = 0; i < CORETEMP_NUM_EVENTS; i++)
162 {
163 /* Event name */
164 sprintf (coretemp_native_table[i].name, "CORETEMP_CPU_%d", i);
165
166 /* Event description */
167 sprintf (coretemp_native_table[i].description, "CPU On-Die Thermal Sensor #%d", i);
168
169 /* Event extra bits -> save MIB to faster access later */
170 sprintf (tmp, "dev.cpu.%d.temperature", i);
171 len = 4;
172 if (sysctlnametomib (tmp, coretemp_native_table[i].resources.mib, &len) == -1) {
174 goto fn_fail;
175 }
176
178 }
179
180 fn_exit:
181 _papi_hwd[cidx]->cmp_info.disabled = retval;
182 return retval;
183 fn_fail:
184 goto fn_exit;
185}
186
187
190{
191 int i;
192
193 SUBDBG("coretemp_init_control_state... %p\n", ctrl);
195
196 for (i = 0; i < CORETEMP_MAX_COUNTERS; i++)
197 c->added[i] = FALSE;
198
199 return PAPI_OK;
200}
201
202
207int coretemp_ntv_enum_events (unsigned int *EventCode, int modifier)
208{
209
210 switch ( modifier )
211 {
212 /* return EventCode of first event */
213 case PAPI_ENUM_FIRST:
214 *EventCode = 0;
215 return PAPI_OK;
216 break;
217
218 /* return EventCode of passed-in Event */
219 case PAPI_ENUM_EVENTS:
220 {
221 int index = *EventCode;
222
223 if ( index < CORETEMP_NUM_EVENTS - 1 )
224 {
225 *EventCode = *EventCode + 1;
226 return PAPI_OK;
227 }
228 else
229 return PAPI_ENOEVNT;
230 break;
231 }
232
233 default:
234 return PAPI_EINVAL;
235 }
236
237 return PAPI_EINVAL;
238}
239
245int coretemp_ntv_code_to_name (unsigned int EventCode, char *name, int len)
246{
247 int index = EventCode;
248
249 strncpy( name, coretemp_native_table[index].name, len );
250
251 return PAPI_OK;
252}
253
259int coretemp_ntv_code_to_descr (unsigned int EventCode, char *name, int len)
260{
261 int index = EventCode;
262
263 strncpy( name, coretemp_native_table[index].description, len );
264
265 return PAPI_OK;
266}
267
270int coretemp_ntv_code_to_bits (unsigned int EventCode, hwd_register_t * bits)
271{
272 UNREFERENCED(EventCode);
273 UNREFERENCED(bits);
274
275 return PAPI_OK;
276}
277
280 NativeInfo_t * native, int count, hwd_context_t * ctx )
281{
282 int i, index;
284 UNREFERENCED(ctx);
285
286 SUBDBG("coretemp_update_control_state %p %p...\n", ptr, ctx);
287
288 for (i = 0; i < count; i++)
289 {
290 index = native[i].ni_event;
291 native[i].ni_position = coretemp_native_table[index].resources.selector - 1;
292 c->added[native[i].ni_position] = TRUE;
293
294 SUBDBG ("\nnative[%i].ni_position = coretemp_native_table[%i].resources.selector-1 = %i;\n",
295 i, index, native[i].ni_position );
296 }
297
298 return PAPI_OK;
299}
300
303{
304 UNREFERENCED(ctx);
305 UNREFERENCED(ctrl);
306
307 SUBDBG( "coretemp_start %p %p...\n", ctx, ctrl );
308
309 /* Nothing to be done */
310
311 return PAPI_OK;
312}
313
314
317{
318 UNREFERENCED(ctx);
319 UNREFERENCED(ctrl);
320
321 SUBDBG("coretemp_stop %p %p...\n", ctx, ctrl);
322
323 /* Nothing to be done */
324
325 return PAPI_OK;
326}
327
328
331 long_long ** events, int flags)
332{
333 int i;
335 UNREFERENCED(ctx);
336 UNREFERENCED(flags);
337
338 SUBDBG("coretemp_read... %p %d\n", ctx, flags);
339
340 for (i = 0; i < CORETEMP_MAX_COUNTERS; i++)
341 if (c->added[i])
342 {
343 int tmp;
344 size_t len = sizeof(tmp);
345
346 if (sysctl (coretemp_native_table[i].resources.mib, 4, &tmp, &len, NULL, 0) == -1)
347 c->counters[i] = 0;
348 else
349 c->counters[i] = tmp/10;
350 /* Coretemp module returns temperature in tenths of kelvin
351 Kelvin are useful to avoid negative values... but will have
352 negative temperatures ??? */
353 }
354
355 *events = c->counters;
356
357 return PAPI_OK;
358}
359
361/* otherwise, the updated state is written to ESI->hw_start */
363 long_long events[] )
364{
365 UNREFERENCED(ctx);
367 UNREFERENCED(ctrl);
368
369 SUBDBG("coretemp_write... %p %p\n", ctx, ctrl);
370
371 /* These sensor counters cannot be writtn */
372
373 return PAPI_OK;
374}
375
376
379{
380 UNREFERENCED(ctx);
381 UNREFERENCED(ctrl);
382
383 SUBDBG("coretemp_reset ctx=%p ctrl=%p...\n", ctx, ctrl);
384
385 /* These sensors cannot be reseted */
386
387 return PAPI_OK;
388}
389
392{
393
394 SUBDBG( "coretemp_shutdown_component...\n");
395
396 /* Last chance to clean up */
398
399 return PAPI_OK;
400}
401
402
403
409int coretemp_ctl (hwd_context_t * ctx, int code, _papi_int_option_t * option)
410{
411 UNREFERENCED(ctx);
412 UNREFERENCED(code);
413 UNREFERENCED(option);
414
415 SUBDBG( "coretemp_ctl... %p %d %p\n", ctx, code, option );
416
417 /* FIXME. This should maybe set up more state, such as which counters are active and */
418 /* counter mappings. */
419
420 return PAPI_OK;
421}
422
433{
434 UNREFERENCED(cntrl);
435
436 SUBDBG ("coretemp_set_domain... %p %d\n", cntrl, domain);
437
438 if (PAPI_DOM_ALL & domain)
439 {
440 SUBDBG( " PAPI_DOM_ALL \n" );
441 return PAPI_OK;
442 }
443 return PAPI_EINVAL ;
444
445}
446
447
450 .cmp_info = {
451 /* default component information (unspecified values are initialized to 0) */
452 .name = "coretemp_freebsd",
453 .short_name = "coretemp",
454 .version = "5.0",
455 .num_mpx_cntrs = CORETEMP_MAX_COUNTERS,
456 .num_cntrs = CORETEMP_MAX_COUNTERS,
457 .default_domain = PAPI_DOM_ALL,
458 .available_domains = PAPI_DOM_ALL,
459 .default_granularity = PAPI_GRN_SYS,
460 .available_granularities = PAPI_GRN_SYS,
461 .hardware_intr_sig = PAPI_INT_SIGNAL,
462
463 /* component specific cmp_info initializations */
464 .fast_real_timer = 0,
465 .fast_virtual_timer = 0,
466 .attach = 0,
467 .attach_must_ptrace = 0,
468 }
469 ,
470
471 /* sizes of framework-opaque component-private structures */
472 .size = {
473 .context = sizeof ( coretemp_context_t ),
474 .control_state = sizeof ( coretemp_control_state_t ),
475 .reg_value = sizeof ( coretemp_register_t ),
476 .reg_alloc = sizeof ( coretemp_reg_alloc_t ),
477 }
478 ,
479 /* function pointers in this component */
480 .init_thread = coretemp_init_thread,
481 .init_component = coretemp_init_component,
482 .init_control_state = coretemp_init_control_state,
483 .start = coretemp_start,
484 .stop = coretemp_stop,
485 .read = coretemp_read,
486 .write = coretemp_write,
487 .shutdown_component = coretemp_shutdown_component,
488 .ctl = coretemp_ctl,
489
490 .update_control_state = coretemp_update_control_state,
491 .set_domain = coretemp_set_domain,
492 .reset = coretemp_reset,
493
494 .ntv_enum_events = coretemp_ntv_enum_events,
495 .ntv_code_to_name = coretemp_ntv_code_to_name,
496 .ntv_code_to_descr = coretemp_ntv_code_to_descr,
497 .ntv_code_to_bits = coretemp_ntv_code_to_bits,
498};
499
double tmp
int i
static long count
struct papi_vectors * _papi_hwd[]
static int CORETEMP_NUM_EVENTS
int coretemp_reset(hwd_context_t *ctx, hwd_control_state_t *ctrl)
#define UNREFERENCED(x)
int coretemp_ntv_code_to_bits(unsigned int EventCode, hwd_register_t *bits)
int coretemp_shutdown_component(void)
int coretemp_init_thread(hwd_context_t *ctx)
int coretemp_ntv_code_to_descr(unsigned int EventCode, char *name, int len)
int coretemp_stop(hwd_context_t *ctx, hwd_control_state_t *ctrl)
int coretemp_ctl(hwd_context_t *ctx, int code, _papi_int_option_t *option)
int coretemp_init_control_state(hwd_control_state_t *ctrl)
#define TRUE
#define FALSE
int coretemp_set_domain(hwd_control_state_t *cntrl, int domain)
int coretemp_ntv_enum_events(unsigned int *EventCode, int modifier)
int coretemp_start(hwd_context_t *ctx, hwd_control_state_t *ctrl)
static coretemp_native_event_entry_t * coretemp_native_table
int coretemp_update_control_state(hwd_control_state_t *ptr, NativeInfo_t *native, int count, hwd_context_t *ctx)
int coretemp_init_component()
int coretemp_ntv_code_to_name(unsigned int EventCode, char *name, int len)
papi_vector_t _coretemp_freebsd_vector
#define CORETEMP_MAX_COUNTERS
int coretemp_write(hwd_context_t *ctx, hwd_control_state_t *ctrl, long_long events[])
int coretemp_read(hwd_context_t *ctx, hwd_control_state_t *ctrl, long_long **events, int flags)
#define PAPI_ENUM_EVENTS
Definition: f90papi.h:224
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_ENUM_FIRST
Definition: f90papi.h:85
#define PAPI_ENOEVNT
Definition: f90papi.h:139
#define PAPI_EINVAL
Definition: f90papi.h:115
#define PAPI_MAX_STR_LEN
Definition: f90papi.h:77
#define PAPI_ECMP
Definition: f90papi.h:214
#define PAPI_GRN_SYS
Definition: f90papi.h:43
#define PAPI_ENOMEM
Definition: f90papi.h:16
#define PAPI_DOM_ALL
Definition: f90papi.h:261
char events[MAX_EVENTS][BUFSIZ]
static double c[MATRIX_SIZE][MATRIX_SIZE]
Definition: libmsr_basic.c:40
#define CORETEMP_MAX_COUNTERS
Return codes and api definitions.
#define long_long
Definition: papi.h:559
#define SUBDBG(format, args...)
Definition: papi_debug.h:64
#define PAPI_INT_SIGNAL
Definition: papi_internal.h:52
#define papi_free(a)
Definition: papi_memory.h:35
#define papi_malloc(a)
Definition: papi_memory.h:34
static int native
static int cidx
const char * name
Definition: rocs.c:225
char name[PAPI_MAX_STR_LEN]
Definition: papi.h:627
coretemp_control_state_t state
coretemp_register_t resources
coretemp_register_t ra_bits
PAPI_component_info_t cmp_info
Definition: papi_vector.h:20
int retval
Definition: zero_fork.c:53