PAPI  5.4.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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_t
coretemp_native_table
 
static int CORETEMP_NUM_EVENTS = 0
 
papi_vector_t _coretemp_freebsd_vector
 

Detailed Description

Macro Definition Documentation

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

Definition at line 37 of file coretemp_freebsd.c.

#define FALSE   (1!=1)

Definition at line 39 of file coretemp_freebsd.c.

#define TRUE   (1==1)

Definition at line 38 of file coretemp_freebsd.c.

#define UNREFERENCED (   x)    (void)x

Definition at line 40 of file coretemp_freebsd.c.

Function Documentation

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

399 {
400  UNREFERENCED(ctx);
401  UNREFERENCED(code);
402  UNREFERENCED(option);
403 
404  SUBDBG( "coretemp_ctl... %p %d %p\n", ctx, code, option );
405 
406  /* FIXME. This should maybe set up more state, such as which counters are active and */
407  /* counter mappings. */
408 
409  return PAPI_OK;
410 }
return PAPI_OK
Definition: linux-nvml.c:458
#define SUBDBG(format, args...)
Definition: papi_debug.h:63
#define UNREFERENCED(x)

Here is the caller graph for this function:

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

119 {
120  int ret;
121  int i;
122  int mib[4];
123  size_t len;
124  char tmp[128];
125 
126  SUBDBG("coretemp_init_component...\n");
127 
128  /* Count the number of cores (counters) that have sensors allocated */
129  i = 0;
131  sprintf (tmp, "dev.coretemp.%d.%%driver", i);
132  len = 4;
133  ret = sysctlnametomib (tmp, mib, &len);
134  while (ret != -1)
135  {
137  i++;
138  sprintf (tmp, "dev.coretemp.%d.%%driver", i);
139  len = 4;
140  ret = sysctlnametomib (tmp, mib, &len);
141  }
142 
143  if (CORETEMP_NUM_EVENTS == 0)
144  return PAPI_OK;
145 
146  /* Allocate memory for the our event table */
149  if (coretemp_native_table == NULL)
150  {
151  perror( "malloc():Could not get memory for coretemp events table" );
152  return PAPI_ENOMEM;
153  }
154 
155  /* Allocate native events internal structures */
156  for (i = 0; i < CORETEMP_NUM_EVENTS; i++)
157  {
158  /* Event name */
159  sprintf (coretemp_native_table[i].name, "CORETEMP_CPU_%d", i);
160 
161  /* Event description */
162  sprintf (coretemp_native_table[i].description, "CPU On-Die Thermal Sensor #%d", i);
163 
164  /* Event extra bits -> save MIB to faster access later */
165  sprintf (tmp, "dev.cpu.%d.temperature", i);
166  len = 4;
167  if (sysctlnametomib (tmp, coretemp_native_table[i].resources.mib, &len) == -1)
168  return PAPI_ECMP;
169 
171  }
172 
173  return PAPI_OK;
174 }
sprintf(splash[splash_line++],"\tIozone: Performance Test of File I/O\n")
#define papi_malloc(a)
Definition: papi_memory.h:34
coretemp_register_t resources
return PAPI_OK
Definition: linux-nvml.c:458
long long ret
Definition: iozone.c:1346
int i
Definition: fileop.c:140
#define SUBDBG(format, args...)
Definition: papi_debug.h:63
#define PAPI_ECMP
Definition: papi.h:254
#define PAPI_ENOMEM
Definition: papi.h:252
static int CORETEMP_NUM_EVENTS
char * name
Definition: iozone.c:23648
static coretemp_native_event_entry_t * coretemp_native_table
long long tmp
Definition: iozone.c:12031

Here is the call graph for this function:

int coretemp_init_control_state ( hwd_control_state_t ctrl)

Setup the counter control structure

Definition at line 178 of file coretemp_freebsd.c.

179 {
180  int i;
181 
182  SUBDBG("coretemp_init_control_state... %p\n", ctrl);
184 
185  for (i = 0; i < CORETEMP_MAX_COUNTERS; i++)
186  c->added[i] = FALSE;
187 
188  return PAPI_OK;
189 }
return PAPI_OK
Definition: linux-nvml.c:458
double c
Definition: multiplex.c:22
int added[CORETEMP_MAX_COUNTERS]
int i
Definition: fileop.c:140
#define FALSE
#define SUBDBG(format, args...)
Definition: papi_debug.h:63
#define CORETEMP_MAX_COUNTERS
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  SUBDBG("coretemp_init_thread %p...\n", ctx);
101 
102 #if 0
103  /* what does this do? VMW */
104 
105  len = 4;
106  if (sysctlnametomib ("dev.coretemp.0.%driver", mib, &len) == -1)
107  return PAPI_ECMP;
108 #endif
109 
110  return PAPI_OK;
111 }
return PAPI_OK
Definition: linux-nvml.c:458
#define SUBDBG(format, args...)
Definition: papi_debug.h:63
#define PAPI_ECMP
Definition: papi.h:254
#define UNREFERENCED(x)
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 259 of file coretemp_freebsd.c.

260 {
261  UNREFERENCED(EventCode);
262  UNREFERENCED(bits);
263 
264  return PAPI_OK;
265 }
return PAPI_OK
Definition: linux-nvml.c:458
#define UNREFERENCED(x)
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 248 of file coretemp_freebsd.c.

249 {
250  int index = EventCode;
251 
252  strncpy( name, coretemp_native_table[index].description, len );
253 
254  return PAPI_OK;
255 }
return PAPI_OK
Definition: linux-nvml.c:458
char * name
Definition: iozone.c:23648
static coretemp_native_event_entry_t * coretemp_native_table
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 234 of file coretemp_freebsd.c.

235 {
236  int index = EventCode;
237 
238  strncpy( name, coretemp_native_table[index].name, len );
239 
240  return PAPI_OK;
241 }
return PAPI_OK
Definition: linux-nvml.c:458
char * name
Definition: iozone.c:23648
static coretemp_native_event_entry_t * coretemp_native_table
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 196 of file coretemp_freebsd.c.

197 {
198 
199  switch ( modifier )
200  {
201  /* return EventCode of first event */
202  case PAPI_ENUM_FIRST:
203  *EventCode = 0;
204  return PAPI_OK;
205  break;
206 
207  /* return EventCode of passed-in Event */
208  case PAPI_ENUM_EVENTS:
209  {
210  int index = *EventCode;
211 
212  if ( index < CORETEMP_NUM_EVENTS - 1 )
213  {
214  *EventCode = *EventCode + 1;
215  return PAPI_OK;
216  }
217  else
218  return PAPI_ENOEVNT;
219  break;
220  }
221 
222  default:
223  return PAPI_EINVAL;
224  }
225 
226  return PAPI_EINVAL;
227 }
#define PAPI_ENOEVNT
Definition: papi.h:258
return PAPI_OK
Definition: linux-nvml.c:458
return PAPI_EINVAL
Definition: linux-nvml.c:408
static int CORETEMP_NUM_EVENTS
int coretemp_read ( hwd_context_t ctx,
hwd_control_state_t ctrl,
long_long **  events,
int  flags 
)

Triggered by PAPI_read()

Definition at line 319 of file coretemp_freebsd.c.

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

Triggered by PAPI_reset

Definition at line 367 of file coretemp_freebsd.c.

368 {
369  UNREFERENCED(ctx);
370  UNREFERENCED(ctrl);
371 
372  SUBDBG("coretemp_reset ctx=%p ctrl=%p...\n", ctx, ctrl);
373 
374  /* These sensors cannot be reseted */
375 
376  return PAPI_OK;
377 }
return PAPI_OK
Definition: linux-nvml.c:458
#define SUBDBG(format, args...)
Definition: papi_debug.h:63
#define UNREFERENCED(x)
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 421 of file coretemp_freebsd.c.

422 {
423  UNREFERENCED(cntrl);
424 
425  SUBDBG ("coretemp_set_domain... %p %d\n", cntrl, domain);
426 
427  if (PAPI_DOM_ALL & domain)
428  {
429  SUBDBG( " PAPI_DOM_ALL \n" );
430  return PAPI_OK;
431  }
432  return PAPI_EINVAL ;
433 
434 }
#define PAPI_DOM_ALL
Definition: papi.h:301
return PAPI_OK
Definition: linux-nvml.c:458
return PAPI_EINVAL
Definition: linux-nvml.c:408
#define SUBDBG(format, args...)
Definition: papi_debug.h:63
#define UNREFERENCED(x)
int coretemp_shutdown_component ( void  )

Triggered by PAPI_shutdown()

Definition at line 380 of file coretemp_freebsd.c.

381 {
382 
383  SUBDBG( "coretemp_shutdown_component... %p\n");
384 
385  /* Last chance to clean up */
387 
388  return PAPI_OK;
389 }
#define papi_free(a)
Definition: papi_memory.h:35
return PAPI_OK
Definition: linux-nvml.c:458
#define SUBDBG(format, args...)
Definition: papi_debug.h:63
static coretemp_native_event_entry_t * coretemp_native_table
int coretemp_start ( hwd_context_t ctx,
hwd_control_state_t ctrl 
)

Triggered by PAPI_start()

Definition at line 291 of file coretemp_freebsd.c.

292 {
293  UNREFERENCED(ctx);
294  UNREFERENCED(ctrl);
295 
296  SUBDBG( "coretemp_start %p %p...\n", ctx, ctrl );
297 
298  /* Nothing to be done */
299 
300  return PAPI_OK;
301 }
return PAPI_OK
Definition: linux-nvml.c:458
#define SUBDBG(format, args...)
Definition: papi_debug.h:63
#define UNREFERENCED(x)
int coretemp_stop ( hwd_context_t ctx,
hwd_control_state_t ctrl 
)

Triggered by PAPI_stop()

Definition at line 305 of file coretemp_freebsd.c.

306 {
307  UNREFERENCED(ctx);
308  UNREFERENCED(ctrl);
309 
310  SUBDBG("coretemp_stop %p %p...\n", ctx, ctrl);
311 
312  /* Nothing to be done */
313 
314  return PAPI_OK;
315 }
return PAPI_OK
Definition: linux-nvml.c:458
#define SUBDBG(format, args...)
Definition: papi_debug.h:63
#define UNREFERENCED(x)
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 268 of file coretemp_freebsd.c.

270 {
271  int i, index;
273  UNREFERENCED(ctx);
274 
275  SUBDBG("coretemp_update_control_state %p %p...\n", ptr, ctx);
276 
277  for (i = 0; i < count; i++)
278  {
279  index = native[i].ni_event;
281  c->added[native[i].ni_position] = TRUE;
282 
283  SUBDBG ("\nnative[%i].ni_position = coretemp_native_table[%i].resources.selector-1 = %i;\n",
284  i, index, native[i].ni_position );
285  }
286 
287  return PAPI_OK;
288 }
coretemp_register_t resources
return PAPI_OK
Definition: linux-nvml.c:458
int count
Definition: iozone.c:22422
double c
Definition: multiplex.c:22
int added[CORETEMP_MAX_COUNTERS]
int i
Definition: fileop.c:140
#define SUBDBG(format, args...)
Definition: papi_debug.h:63
#define TRUE
static coretemp_native_event_entry_t * coretemp_native_table
#define UNREFERENCED(x)
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 351 of file coretemp_freebsd.c.

353 {
354  UNREFERENCED(ctx);
356  UNREFERENCED(ctrl);
357 
358  SUBDBG("coretemp_write... %p %p\n", ctx, ctrl);
359 
360  /* These sensor counters cannot be writtn */
361 
362  return PAPI_OK;
363 }
return PAPI_OK
Definition: linux-nvml.c:458
char events[MAX_EVENTS][BUFSIZ]
#define SUBDBG(format, args...)
Definition: papi_debug.h:63
#define UNREFERENCED(x)

Variable Documentation

papi_vector_t _coretemp_freebsd_vector

Vector that points to entry points for our component

Definition at line 438 of file coretemp_freebsd.c.

coretemp_native_event_entry_t* coretemp_native_table
static

This table contains the native events

Definition at line 83 of file coretemp_freebsd.c.

int CORETEMP_NUM_EVENTS = 0
static

number of events in the table

Definition at line 86 of file coretemp_freebsd.c.