PAPI 7.1.0.0
Loading...
Searching...
No Matches
coretemp_freebsd.c File Reference

This component is intended to access CPU On-Die Thermal Sensors in the Intel Core architecture in a FreeBSD machine using the coretemp.ko kernel module. More...

Include dependency graph for coretemp_freebsd.c:

Go to the source code of this file.

Data Structures

struct  coretemp_register_t
 
struct  coretemp_native_event_entry_t
 
struct  coretemp_reg_alloc_t
 
struct  coretemp_control_state_t
 
struct  coretemp_context_t
 

Macros

#define CORETEMP_MAX_COUNTERS   32 /* Can we tune this dynamically? */
 
#define TRUE   (1==1)
 
#define FALSE   (1!=1)
 
#define UNREFERENCED(x)   (void)x
 

Functions

int coretemp_init_thread (hwd_context_t *ctx)
 
int coretemp_init_component ()
 
int coretemp_init_control_state (hwd_control_state_t *ctrl)
 
int coretemp_ntv_enum_events (unsigned int *EventCode, int modifier)
 
int coretemp_ntv_code_to_name (unsigned int EventCode, char *name, int len)
 
int coretemp_ntv_code_to_descr (unsigned int EventCode, char *name, int len)
 
int coretemp_ntv_code_to_bits (unsigned int EventCode, hwd_register_t *bits)
 
int coretemp_update_control_state (hwd_control_state_t *ptr, NativeInfo_t *native, int count, hwd_context_t *ctx)
 
int coretemp_start (hwd_context_t *ctx, hwd_control_state_t *ctrl)
 
int coretemp_stop (hwd_context_t *ctx, hwd_control_state_t *ctrl)
 
int coretemp_read (hwd_context_t *ctx, hwd_control_state_t *ctrl, long_long **events, int flags)
 
int coretemp_write (hwd_context_t *ctx, hwd_control_state_t *ctrl, long_long events[])
 
int coretemp_reset (hwd_context_t *ctx, hwd_control_state_t *ctrl)
 
int coretemp_shutdown_component (void)
 
int coretemp_ctl (hwd_context_t *ctx, int code, _papi_int_option_t *option)
 
int coretemp_set_domain (hwd_control_state_t *cntrl, int domain)
 

Variables

static coretemp_native_event_entry_tcoretemp_native_table
 
static int CORETEMP_NUM_EVENTS = 0
 
papi_vector_t _coretemp_freebsd_vector
 

Detailed Description

Macro Definition Documentation

◆ CORETEMP_MAX_COUNTERS

#define CORETEMP_MAX_COUNTERS   32 /* Can we tune this dynamically? */

Definition at line 37 of file coretemp_freebsd.c.

◆ FALSE

#define FALSE   (1!=1)

Definition at line 39 of file coretemp_freebsd.c.

◆ TRUE

#define TRUE   (1==1)

Definition at line 38 of file coretemp_freebsd.c.

◆ UNREFERENCED

#define UNREFERENCED (   x)    (void)x

Definition at line 40 of file coretemp_freebsd.c.

Function Documentation

◆ coretemp_ctl()

int coretemp_ctl ( hwd_context_t ctx,
int  code,
_papi_int_option_t option 
)

This function sets various options in the component

Parameters
ctxunused
codevalid are PAPI_SET_DEFDOM, PAPI_SET_DOMAIN, PAPI_SETDEFGRN, PAPI_SET_GRANUL and PAPI_SET_INHERIT
optionunused

Definition at line 409 of file coretemp_freebsd.c.

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}
#define UNREFERENCED(x)
#define PAPI_OK
Definition: f90papi.h:73
#define SUBDBG(format, args...)
Definition: papi_debug.h:64
Here is the caller graph for this function:

◆ coretemp_init_component()

int coretemp_init_component ( )

Initialize hardware counters, setup the function vector table and get hardware information, this routine is called when the PAPI process is initialized (IE PAPI_library_init)

Definition at line 121 of file coretemp_freebsd.c.

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}
double tmp
int i
struct papi_vectors * _papi_hwd[]
static int CORETEMP_NUM_EVENTS
static coretemp_native_event_entry_t * coretemp_native_table
#define PAPI_ECMP
Definition: f90papi.h:214
#define PAPI_ENOMEM
Definition: f90papi.h:16
#define papi_malloc(a)
Definition: papi_memory.h:34
static int cidx
const char * name
Definition: rocs.c:225
coretemp_register_t resources
int retval
Definition: zero_fork.c:53

◆ coretemp_init_control_state()

int coretemp_init_control_state ( hwd_control_state_t ctrl)

Setup the counter control structure

Definition at line 189 of file coretemp_freebsd.c.

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}
#define FALSE
#define CORETEMP_MAX_COUNTERS
static double c[MATRIX_SIZE][MATRIX_SIZE]
Definition: libmsr_basic.c:40

◆ coretemp_init_thread()

int coretemp_init_thread ( hwd_context_t ctx)

This is called whenever a thread is initialized

Definition at line 94 of file coretemp_freebsd.c.

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}

◆ coretemp_ntv_code_to_bits()

int coretemp_ntv_code_to_bits ( unsigned int  EventCode,
hwd_register_t bits 
)

This takes an event and returns the bits that would be written out to the hardware device (this is very much tied to CPU-type support

Definition at line 270 of file coretemp_freebsd.c.

271{
272 UNREFERENCED(EventCode);
273 UNREFERENCED(bits);
274
275 return PAPI_OK;
276}

◆ coretemp_ntv_code_to_descr()

int coretemp_ntv_code_to_descr ( unsigned int  EventCode,
char *  name,
int  len 
)

Takes a native event code and passes back the event description

Parameters
EventCodeis the native event code
nameis a pointer for the description to be copied to
lenis the size of the string

Definition at line 259 of file coretemp_freebsd.c.

260{
261 int index = EventCode;
262
263 strncpy( name, coretemp_native_table[index].description, len );
264
265 return PAPI_OK;
266}

◆ coretemp_ntv_code_to_name()

int coretemp_ntv_code_to_name ( unsigned int  EventCode,
char *  name,
int  len 
)

Takes a native event code and passes back the name

Parameters
EventCodeis the native event code
nameis a pointer for the name to be copied to
lenis the size of the string

Definition at line 245 of file coretemp_freebsd.c.

246{
247 int index = EventCode;
248
249 strncpy( name, coretemp_native_table[index].name, len );
250
251 return PAPI_OK;
252}

◆ coretemp_ntv_enum_events()

int coretemp_ntv_enum_events ( unsigned int EventCode,
int  modifier 
)

Enumerate Native Events

Parameters
EventCodeis the event of interest
modifieris one of PAPI_ENUM_FIRST, PAPI_ENUM_EVENTS

Definition at line 207 of file coretemp_freebsd.c.

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}
#define PAPI_ENUM_EVENTS
Definition: f90papi.h:224
#define PAPI_ENUM_FIRST
Definition: f90papi.h:85
#define PAPI_ENOEVNT
Definition: f90papi.h:139
#define PAPI_EINVAL
Definition: f90papi.h:115

◆ coretemp_read()

int coretemp_read ( hwd_context_t ctx,
hwd_control_state_t ctrl,
long_long **  events,
int  flags 
)

Triggered by PAPI_read()

Definition at line 330 of file coretemp_freebsd.c.

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}
char events[MAX_EVENTS][BUFSIZ]

◆ coretemp_reset()

int coretemp_reset ( hwd_context_t ctx,
hwd_control_state_t ctrl 
)

Triggered by PAPI_reset

Definition at line 378 of file coretemp_freebsd.c.

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}

◆ coretemp_set_domain()

int coretemp_set_domain ( hwd_control_state_t cntrl,
int  domain 
)

This function has to set the bits needed to count different domains In particular: PAPI_DOM_USER, PAPI_DOM_KERNEL PAPI_DOM_OTHER By default return PAPI_EINVAL if none of those are specified and PAPI_OK with success PAPI_DOM_USER is only user context is counted PAPI_DOM_KERNEL is only the Kernel/OS context is counted PAPI_DOM_OTHER is Exception/transient mode (like user TLB misses) PAPI_DOM_ALL is all of the domains

Definition at line 432 of file coretemp_freebsd.c.

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}
#define PAPI_DOM_ALL
Definition: f90papi.h:261

◆ coretemp_shutdown_component()

int coretemp_shutdown_component ( void  )

Triggered by PAPI_shutdown()

Definition at line 391 of file coretemp_freebsd.c.

392{
393
394 SUBDBG( "coretemp_shutdown_component...\n");
395
396 /* Last chance to clean up */
398
399 return PAPI_OK;
400}
#define papi_free(a)
Definition: papi_memory.h:35

◆ coretemp_start()

int coretemp_start ( hwd_context_t ctx,
hwd_control_state_t ctrl 
)

Triggered by PAPI_start()

Definition at line 302 of file coretemp_freebsd.c.

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}

◆ coretemp_stop()

int coretemp_stop ( hwd_context_t ctx,
hwd_control_state_t ctrl 
)

Triggered by PAPI_stop()

Definition at line 316 of file coretemp_freebsd.c.

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}

◆ coretemp_update_control_state()

int coretemp_update_control_state ( hwd_control_state_t ptr,
NativeInfo_t native,
int  count,
hwd_context_t ctx 
)

Triggered by eventset operations like add or remove

Definition at line 279 of file coretemp_freebsd.c.

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}
static long count
#define TRUE
static int native

◆ coretemp_write()

int coretemp_write ( hwd_context_t ctx,
hwd_control_state_t ctrl,
long_long  events[] 
)

Triggered by PAPI_write(), but only if the counters are running

Definition at line 362 of file coretemp_freebsd.c.

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}

Variable Documentation

◆ _coretemp_freebsd_vector

papi_vector_t _coretemp_freebsd_vector

Vector that points to entry points for our component

Definition at line 449 of file coretemp_freebsd.c.

◆ coretemp_native_table

coretemp_native_event_entry_t* coretemp_native_table
static

This table contains the native events

Definition at line 83 of file coretemp_freebsd.c.

◆ CORETEMP_NUM_EVENTS

int CORETEMP_NUM_EVENTS = 0
static

number of events in the table

Definition at line 86 of file coretemp_freebsd.c.