PAPI  5.3.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 395 of file coretemp_freebsd.c.

396 {
397  UNREFERENCED(ctx);
398  UNREFERENCED(code);
399  UNREFERENCED(option);
400 
401  SUBDBG( "coretemp_ctl... %p %d %p\n", ctx, code, option );
402 
403  /* FIXME. This should maybe set up more state, such as which counters are active and */
404  /* counter mappings. */
405 
406  return PAPI_OK;
407 }
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  /* Allocate memory for the our event table */
146  if (coretemp_native_table == NULL)
147  {
148  perror( "malloc():Could not get memory for coretemp events table" );
149  return PAPI_ENOMEM;
150  }
151 
152  /* Allocate native events internal structures */
153  for (i = 0; i < CORETEMP_NUM_EVENTS; i++)
154  {
155  /* Event name */
156  sprintf (coretemp_native_table[i].name, "CORETEMP_CPU_%d", i);
157 
158  /* Event description */
159  sprintf (coretemp_native_table[i].description, "CPU On-Die Thermal Sensor #%d", i);
160 
161  /* Event extra bits -> save MIB to faster access later */
162  sprintf (tmp, "dev.cpu.%d.temperature", i);
163  len = 4;
164  if (sysctlnametomib (tmp, coretemp_native_table[i].resources.mib, &len) == -1)
165  return PAPI_ECMP;
166 
168  }
169 
170  return PAPI_OK;
171 }
sprintf(splash[splash_line++],"\tIozone: Performance Test of File I/O\n")
#define PAPI_ENOMEM
Definition: fpapi.h:107
#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 PAPI_ECMP
Definition: fpapi.h:109
#define SUBDBG(format, args...)
Definition: papi_debug.h:63
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 175 of file coretemp_freebsd.c.

176 {
177  int i;
178 
179  SUBDBG("coretemp_init_control_state... %p\n", ctrl);
181 
182  for (i = 0; i < CORETEMP_MAX_COUNTERS; i++)
183  c->added[i] = FALSE;
184 
185  return PAPI_OK;
186 }
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 PAPI_ECMP
Definition: fpapi.h:109
#define SUBDBG(format, args...)
Definition: papi_debug.h:63
#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 256 of file coretemp_freebsd.c.

257 {
258  UNREFERENCED(EventCode);
259  UNREFERENCED(bits);
260 
261  return PAPI_OK;
262 }
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 245 of file coretemp_freebsd.c.

246 {
247  int index = EventCode;
248 
249  strncpy( name, coretemp_native_table[index].description, len );
250 
251  return PAPI_OK;
252 }
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 231 of file coretemp_freebsd.c.

232 {
233  int index = EventCode;
234 
235  strncpy( name, coretemp_native_table[index].name, len );
236 
237  return PAPI_OK;
238 }
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 193 of file coretemp_freebsd.c.

194 {
195 
196  switch ( modifier )
197  {
198  /* return EventCode of first event */
199  case PAPI_ENUM_FIRST:
200  *EventCode = 0;
201  return PAPI_OK;
202  break;
203 
204  /* return EventCode of passed-in Event */
205  case PAPI_ENUM_EVENTS:
206  {
207  int index = *EventCode;
208 
209  if ( index < CORETEMP_NUM_EVENTS - 1 )
210  {
211  *EventCode = *EventCode + 1;
212  return PAPI_OK;
213  }
214  else
215  return PAPI_ENOEVNT;
216  break;
217  }
218 
219  default:
220  return PAPI_EINVAL;
221  }
222 
223  return PAPI_EINVAL;
224 }
#define PAPI_ENOEVNT
Definition: fpapi.h:112
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 316 of file coretemp_freebsd.c.

318 {
319  int i;
321  UNREFERENCED(ctx);
323 
324  SUBDBG("coretemp_read... %p %d\n", ctx, flags);
325 
326  for (i = 0; i < CORETEMP_MAX_COUNTERS; i++)
327  if (c->added[i])
328  {
329  int tmp;
330  size_t len = sizeof(tmp);
331 
332  if (sysctl (coretemp_native_table[i].resources.mib, 4, &tmp, &len, NULL, 0) == -1)
333  c->counters[i] = 0;
334  else
335  c->counters[i] = tmp/10;
336  /* Coretemp module returns temperature in tenths of kelvin
337  Kelvin are useful to avoid negative values... but will have
338  negative temperatures ??? */
339  }
340 
341  *events = c->counters;
342 
343  return PAPI_OK;
344 }
long long flags
Definition: iozone.c:12330
return PAPI_OK
Definition: linux-nvml.c:458
double c
Definition: multiplex.c:22
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
char events[MAX_EVENTS][BUFSIZ]
#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 364 of file coretemp_freebsd.c.

365 {
366  UNREFERENCED(ctx);
367  UNREFERENCED(ctrl);
368 
369  SUBDBG("coretemp_reset ctx=%p ctrl=%p...\n", ctx, ctrl);
370 
371  /* These sensors cannot be reseted */
372 
373  return PAPI_OK;
374 }
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 418 of file coretemp_freebsd.c.

419 {
420  int found = 0;
421  UNREFERENCED(cntrl);
422 
423  SUBDBG ("coretemp_set_domain... %p %d\n", cntrl, domain);
424 
425  if (PAPI_DOM_USER & domain)
426  {
427  SUBDBG( " PAPI_DOM_USER \n" );
428  found = 1;
429  }
430  if (PAPI_DOM_KERNEL & domain)
431  {
432  SUBDBG( " PAPI_DOM_KERNEL \n" );
433  found = 1;
434  }
435  if (PAPI_DOM_OTHER & domain)
436  {
437  SUBDBG( " PAPI_DOM_OTHER \n" );
438  found = 1;
439  }
440  if (PAPI_DOM_ALL & domain)
441  {
442  SUBDBG( " PAPI_DOM_ALL \n" );
443  found = 1;
444  }
445  if (!found)
446  return PAPI_EINVAL ;
447 
448  return PAPI_OK;
449 }
#define PAPI_DOM_ALL
Definition: fpapi.h:25
return PAPI_OK
Definition: linux-nvml.c:458
#define PAPI_DOM_OTHER
Definition: fpapi.h:23
#define PAPI_DOM_KERNEL
Definition: fpapi.h:22
return PAPI_EINVAL
Definition: linux-nvml.c:408
long long found
Definition: libasync.c:735
#define SUBDBG(format, args...)
Definition: papi_debug.h:63
#define PAPI_DOM_USER
Definition: fpapi.h:21
#define UNREFERENCED(x)
int coretemp_shutdown_component ( void  )

Triggered by PAPI_shutdown()

Definition at line 377 of file coretemp_freebsd.c.

378 {
379 
380  SUBDBG( "coretemp_shutdown_component... %p\n", ctx );
381 
382  /* Last chance to clean up */
384 
385  return PAPI_OK;
386 }
#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 288 of file coretemp_freebsd.c.

289 {
290  UNREFERENCED(ctx);
291  UNREFERENCED(ctrl);
292 
293  SUBDBG( "coretemp_start %p %p...\n", ctx, ctrl );
294 
295  /* Nothing to be done */
296 
297  return PAPI_OK;
298 }
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 302 of file coretemp_freebsd.c.

303 {
304  UNREFERENCED(ctx);
305  UNREFERENCED(ctrl);
306 
307  SUBDBG("coretemp_stop %p %p...\n", ctx, ctrl);
308 
309  /* Nothing to be done */
310 
311  return PAPI_OK;
312 }
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 265 of file coretemp_freebsd.c.

267 {
268  int i, index;
270  UNREFERENCED(ctx);
271 
272  SUBDBG("coretemp_update_control_state %p %p...\n", ptr, ctx);
273 
274  for (i = 0; i < count; i++)
275  {
276  index = native[i].ni_event;
278  c->added[native[i].ni_position] = TRUE;
279 
280  SUBDBG ("\nnative[%i].ni_position = coretemp_native_table[%i].resources.selector-1 = %i;\n",
281  i, index, native[i].ni_position );
282  }
283 
284  return PAPI_OK;
285 }
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 348 of file coretemp_freebsd.c.

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

Variable Documentation

papi_vector_t _coretemp_freebsd_vector

Vector that points to entry points for our component

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