PAPI  5.7.0.0
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 401 of file coretemp_freebsd.c.

402 {
403  UNREFERENCED(ctx);
404  UNREFERENCED(code);
405  UNREFERENCED(option);
406 
407  SUBDBG( "coretemp_ctl... %p %d %p\n", ctx, code, option );
408 
409  /* FIXME. This should maybe set up more state, such as which counters are active and */
410  /* counter mappings. */
411 
412  return PAPI_OK;
413 }
#define PAPI_OK
Definition: fpapi.h:105
#define SUBDBG(format, args...)
Definition: papi_debug.h:63
#define UNREFERENCED(x)
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 
129  SUBDBG("coretemp_init_component...\n");
130 
131  /* Count the number of cores (counters) that have sensors allocated */
132  i = 0;
134  sprintf (tmp, "dev.coretemp.%d.%%driver", i);
135  len = 4;
136  ret = sysctlnametomib (tmp, mib, &len);
137  while (ret != -1)
138  {
140  i++;
141  sprintf (tmp, "dev.coretemp.%d.%%driver", i);
142  len = 4;
143  ret = sysctlnametomib (tmp, mib, &len);
144  }
145 
146  if (CORETEMP_NUM_EVENTS == 0)
147  return PAPI_OK;
148 
149  /* Allocate memory for the our event table */
152  if (coretemp_native_table == NULL)
153  {
154  perror( "malloc():Could not get memory for coretemp events table" );
155  return PAPI_ENOMEM;
156  }
157 
158  /* Allocate native events internal structures */
159  for (i = 0; i < CORETEMP_NUM_EVENTS; i++)
160  {
161  /* Event name */
162  sprintf (coretemp_native_table[i].name, "CORETEMP_CPU_%d", i);
163 
164  /* Event description */
165  sprintf (coretemp_native_table[i].description, "CPU On-Die Thermal Sensor #%d", i);
166 
167  /* Event extra bits -> save MIB to faster access later */
168  sprintf (tmp, "dev.cpu.%d.temperature", i);
169  len = 4;
170  if (sysctlnametomib (tmp, coretemp_native_table[i].resources.mib, &len) == -1)
171  return PAPI_ECMP;
172 
174  }
175 
176  return PAPI_OK;
177 }
#define PAPI_OK
Definition: fpapi.h:105
#define PAPI_ENOMEM
Definition: fpapi.h:107
static const char * name
Definition: fork_overflow.c:31
#define papi_malloc(a)
Definition: papi_memory.h:34
coretemp_register_t resources
double tmp
#define PAPI_ECMP
Definition: fpapi.h:109
#define SUBDBG(format, args...)
Definition: papi_debug.h:63
long long ret
Definition: iozone.c:1346
static int CORETEMP_NUM_EVENTS
static coretemp_native_event_entry_t * coretemp_native_table
int i
Definition: fileop.c:140

◆ coretemp_init_control_state()

int coretemp_init_control_state ( hwd_control_state_t ctrl)

Setup the counter control structure

Definition at line 181 of file coretemp_freebsd.c.

182 {
183  int i;
184 
185  SUBDBG("coretemp_init_control_state... %p\n", ctrl);
187 
188  for (i = 0; i < CORETEMP_MAX_COUNTERS; i++)
189  c->added[i] = FALSE;
190 
191  return PAPI_OK;
192 }
#define PAPI_OK
Definition: fpapi.h:105
double c
Definition: multiplex.c:22
#define FALSE
#define SUBDBG(format, args...)
Definition: papi_debug.h:63
#define CORETEMP_MAX_COUNTERS
int i
Definition: fileop.c:140

◆ 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 }
#define PAPI_OK
Definition: fpapi.h:105
#define PAPI_ECMP
Definition: fpapi.h:109
#define SUBDBG(format, args...)
Definition: papi_debug.h:63
#define UNREFERENCED(x)

◆ 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 262 of file coretemp_freebsd.c.

263 {
264  UNREFERENCED(EventCode);
265  UNREFERENCED(bits);
266 
267  return PAPI_OK;
268 }
#define PAPI_OK
Definition: fpapi.h:105
#define UNREFERENCED(x)

◆ 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 251 of file coretemp_freebsd.c.

252 {
253  int index = EventCode;
254 
255  strncpy( name, coretemp_native_table[index].description, len );
256 
257  return PAPI_OK;
258 }
#define PAPI_OK
Definition: fpapi.h:105
static const char * name
Definition: fork_overflow.c:31
static coretemp_native_event_entry_t * coretemp_native_table

◆ 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 237 of file coretemp_freebsd.c.

238 {
239  int index = EventCode;
240 
241  strncpy( name, coretemp_native_table[index].name, len );
242 
243  return PAPI_OK;
244 }
#define PAPI_OK
Definition: fpapi.h:105
static const char * name
Definition: fork_overflow.c:31
static coretemp_native_event_entry_t * coretemp_native_table

◆ 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 199 of file coretemp_freebsd.c.

200 {
201 
202  switch ( modifier )
203  {
204  /* return EventCode of first event */
205  case PAPI_ENUM_FIRST:
206  *EventCode = 0;
207  return PAPI_OK;
208  break;
209 
210  /* return EventCode of passed-in Event */
211  case PAPI_ENUM_EVENTS:
212  {
213  int index = *EventCode;
214 
215  if ( index < CORETEMP_NUM_EVENTS - 1 )
216  {
217  *EventCode = *EventCode + 1;
218  return PAPI_OK;
219  }
220  else
221  return PAPI_ENOEVNT;
222  break;
223  }
224 
225  default:
226  return PAPI_EINVAL;
227  }
228 
229  return PAPI_EINVAL;
230 }
#define PAPI_OK
Definition: fpapi.h:105
#define PAPI_EINVAL
Definition: fpapi.h:106
static int CORETEMP_NUM_EVENTS
#define PAPI_ENOEVNT
Definition: fpapi.h:112

◆ 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 322 of file coretemp_freebsd.c.

324 {
325  int i;
327  UNREFERENCED(ctx);
328  UNREFERENCED(flags);
329 
330  SUBDBG("coretemp_read... %p %d\n", ctx, flags);
331 
332  for (i = 0; i < CORETEMP_MAX_COUNTERS; i++)
333  if (c->added[i])
334  {
335  int tmp;
336  size_t len = sizeof(tmp);
337 
338  if (sysctl (coretemp_native_table[i].resources.mib, 4, &tmp, &len, NULL, 0) == -1)
339  c->counters[i] = 0;
340  else
341  c->counters[i] = tmp/10;
342  /* Coretemp module returns temperature in tenths of kelvin
343  Kelvin are useful to avoid negative values... but will have
344  negative temperatures ??? */
345  }
346 
347  *events = c->counters;
348 
349  return PAPI_OK;
350 }
#define PAPI_OK
Definition: fpapi.h:105
double c
Definition: multiplex.c:22
double tmp
char events[MAX_EVENTS][BUFSIZ]
#define SUBDBG(format, args...)
Definition: papi_debug.h:63
#define CORETEMP_MAX_COUNTERS
static coretemp_native_event_entry_t * coretemp_native_table
#define UNREFERENCED(x)
int i
Definition: fileop.c:140

◆ coretemp_reset()

int coretemp_reset ( hwd_context_t ctx,
hwd_control_state_t ctrl 
)

Triggered by PAPI_reset

Definition at line 370 of file coretemp_freebsd.c.

371 {
372  UNREFERENCED(ctx);
373  UNREFERENCED(ctrl);
374 
375  SUBDBG("coretemp_reset ctx=%p ctrl=%p...\n", ctx, ctrl);
376 
377  /* These sensors cannot be reseted */
378 
379  return PAPI_OK;
380 }
#define PAPI_OK
Definition: fpapi.h:105
#define SUBDBG(format, args...)
Definition: papi_debug.h:63
#define UNREFERENCED(x)

◆ 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 424 of file coretemp_freebsd.c.

425 {
426  UNREFERENCED(cntrl);
427 
428  SUBDBG ("coretemp_set_domain... %p %d\n", cntrl, domain);
429 
430  if (PAPI_DOM_ALL & domain)
431  {
432  SUBDBG( " PAPI_DOM_ALL \n" );
433  return PAPI_OK;
434  }
435  return PAPI_EINVAL ;
436 
437 }
#define PAPI_OK
Definition: fpapi.h:105
#define PAPI_EINVAL
Definition: fpapi.h:106
#define SUBDBG(format, args...)
Definition: papi_debug.h:63
#define PAPI_DOM_ALL
Definition: fpapi.h:25
#define UNREFERENCED(x)

◆ coretemp_shutdown_component()

int coretemp_shutdown_component ( void  )

Triggered by PAPI_shutdown()

Definition at line 383 of file coretemp_freebsd.c.

384 {
385 
386  SUBDBG( "coretemp_shutdown_component...\n");
387 
388  /* Last chance to clean up */
390 
391  return PAPI_OK;
392 }
#define PAPI_OK
Definition: fpapi.h:105
#define papi_free(a)
Definition: papi_memory.h:35
#define SUBDBG(format, args...)
Definition: papi_debug.h:63
static coretemp_native_event_entry_t * coretemp_native_table

◆ coretemp_start()

int coretemp_start ( hwd_context_t ctx,
hwd_control_state_t ctrl 
)

Triggered by PAPI_start()

Definition at line 294 of file coretemp_freebsd.c.

295 {
296  UNREFERENCED(ctx);
297  UNREFERENCED(ctrl);
298 
299  SUBDBG( "coretemp_start %p %p...\n", ctx, ctrl );
300 
301  /* Nothing to be done */
302 
303  return PAPI_OK;
304 }
#define PAPI_OK
Definition: fpapi.h:105
#define SUBDBG(format, args...)
Definition: papi_debug.h:63
#define UNREFERENCED(x)

◆ coretemp_stop()

int coretemp_stop ( hwd_context_t ctx,
hwd_control_state_t ctrl 
)

Triggered by PAPI_stop()

Definition at line 308 of file coretemp_freebsd.c.

309 {
310  UNREFERENCED(ctx);
311  UNREFERENCED(ctrl);
312 
313  SUBDBG("coretemp_stop %p %p...\n", ctx, ctrl);
314 
315  /* Nothing to be done */
316 
317  return PAPI_OK;
318 }
#define PAPI_OK
Definition: fpapi.h:105
#define SUBDBG(format, args...)
Definition: papi_debug.h:63
#define UNREFERENCED(x)

◆ 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 271 of file coretemp_freebsd.c.

273 {
274  int i, index;
276  UNREFERENCED(ctx);
277 
278  SUBDBG("coretemp_update_control_state %p %p...\n", ptr, ctx);
279 
280  for (i = 0; i < count; i++)
281  {
282  index = native[i].ni_event;
283  native[i].ni_position = coretemp_native_table[index].resources.selector - 1;
284  c->added[native[i].ni_position] = TRUE;
285 
286  SUBDBG ("\nnative[%i].ni_position = coretemp_native_table[%i].resources.selector-1 = %i;\n",
287  i, index, native[i].ni_position );
288  }
289 
290  return PAPI_OK;
291 }
#define PAPI_OK
Definition: fpapi.h:105
coretemp_register_t resources
double c
Definition: multiplex.c:22
static int native
#define SUBDBG(format, args...)
Definition: papi_debug.h:63
#define TRUE
static coretemp_native_event_entry_t * coretemp_native_table
static long count
#define UNREFERENCED(x)
int i
Definition: fileop.c:140

◆ 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 354 of file coretemp_freebsd.c.

356 {
357  UNREFERENCED(ctx);
359  UNREFERENCED(ctrl);
360 
361  SUBDBG("coretemp_write... %p %p\n", ctx, ctrl);
362 
363  /* These sensor counters cannot be writtn */
364 
365  return PAPI_OK;
366 }
#define PAPI_OK
Definition: fpapi.h:105
char events[MAX_EVENTS][BUFSIZ]
#define SUBDBG(format, args...)
Definition: papi_debug.h:63
#define UNREFERENCED(x)

Variable Documentation

◆ _coretemp_freebsd_vector

papi_vector_t _coretemp_freebsd_vector

Vector that points to entry points for our component

Definition at line 441 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.