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

Defines

#define CORETEMP_MAX_COUNTERS   32
#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

Author:
Joachim Protze joachim.protze@zih.tu-dresden.de
Vince Weaver vweaver1@eecs.utk.edu
Harald Servat harald.servat@gmail.com

Definition in file coretemp_freebsd.c.


Define Documentation

#define CORETEMP_MAX_COUNTERS   32

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:
ctx unused
code valid are PAPI_SET_DEFDOM, PAPI_SET_DOMAIN, PAPI_SETDEFGRN, PAPI_SET_GRANUL and PAPI_SET_INHERIT
option unused

Definition at line 398 of file coretemp_freebsd.c.

00399 {
00400     UNREFERENCED(ctx);
00401     UNREFERENCED(code);
00402     UNREFERENCED(option);
00403 
00404     SUBDBG( "coretemp_ctl... %p %d %p\n", ctx, code, option );
00405 
00406     /* FIXME.  This should maybe set up more state, such as which counters are active and */
00407     /*         counter mappings. */
00408 
00409     return PAPI_OK;
00410 }

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.

00119 {
00120     int ret;
00121     int i;
00122     int mib[4];
00123     size_t len;
00124     char tmp[128];
00125 
00126     SUBDBG("coretemp_init_component...\n");
00127 
00128     /* Count the number of cores (counters) that have sensors allocated */
00129     i = 0;
00130     CORETEMP_NUM_EVENTS = 0;
00131     sprintf (tmp, "dev.coretemp.%d.%%driver", i);
00132     len = 4;
00133     ret = sysctlnametomib (tmp, mib, &len);
00134     while (ret != -1)
00135     {
00136         CORETEMP_NUM_EVENTS++;
00137         i++;
00138         sprintf (tmp, "dev.coretemp.%d.%%driver", i);
00139         len = 4;
00140         ret = sysctlnametomib (tmp, mib, &len);
00141     }
00142 
00143     if (CORETEMP_NUM_EVENTS == 0)
00144         return PAPI_OK;
00145 
00146     /* Allocate memory for the our event table */
00147     coretemp_native_table = (coretemp_native_event_entry_t *)
00148         papi_malloc (sizeof (coretemp_native_event_entry_t) * CORETEMP_NUM_EVENTS);
00149     if (coretemp_native_table == NULL)
00150     {
00151         perror( "malloc():Could not get memory for coretemp events table" );
00152         return PAPI_ENOMEM;
00153     }
00154 
00155     /* Allocate native events internal structures */
00156     for (i = 0; i < CORETEMP_NUM_EVENTS; i++)
00157     {
00158         /* Event name */
00159         sprintf (coretemp_native_table[i].name, "CORETEMP_CPU_%d", i);
00160 
00161         /* Event description */
00162         sprintf (coretemp_native_table[i].description, "CPU On-Die Thermal Sensor #%d", i);
00163 
00164         /* Event extra bits -> save MIB to faster access later */
00165         sprintf (tmp, "dev.cpu.%d.temperature", i);
00166         len = 4;
00167         if (sysctlnametomib (tmp, coretemp_native_table[i].resources.mib, &len) == -1)
00168             return PAPI_ECMP;
00169 
00170         coretemp_native_table[i].resources.selector = i+1;
00171     }
00172 
00173     return PAPI_OK;
00174 }

int coretemp_init_control_state ( hwd_control_state_t ctrl  ) 

Setup the counter control structure

Definition at line 178 of file coretemp_freebsd.c.

00179 {
00180     int i;
00181 
00182     SUBDBG("coretemp_init_control_state... %p\n", ctrl);
00183     coretemp_control_state_t *c = (coretemp_control_state_t *) ctrl;
00184 
00185     for (i = 0; i < CORETEMP_MAX_COUNTERS; i++)
00186         c->added[i] = FALSE;
00187 
00188     return PAPI_OK;
00189 }

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.

00095 {
00096     int mib[4];
00097     size_t len;
00098     UNREFERENCED(ctx);
00099 
00100     SUBDBG("coretemp_init_thread %p...\n", ctx);
00101 
00102 #if 0
00103     /* what does this do?  VMW */
00104 
00105     len = 4;
00106     if (sysctlnametomib ("dev.coretemp.0.%driver", mib, &len) == -1)
00107         return PAPI_ECMP;
00108 #endif
00109 
00110     return PAPI_OK;
00111 }

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.

00260 {
00261     UNREFERENCED(EventCode);
00262     UNREFERENCED(bits);
00263 
00264     return PAPI_OK;
00265 }

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:
EventCode is the native event code
name is a pointer for the description to be copied to
len is the size of the string

Definition at line 248 of file coretemp_freebsd.c.

00249 {
00250     int index = EventCode;
00251 
00252     strncpy( name, coretemp_native_table[index].description, len );
00253 
00254     return PAPI_OK;
00255 }

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

Takes a native event code and passes back the name

Parameters:
EventCode is the native event code
name is a pointer for the name to be copied to
len is the size of the string

Definition at line 234 of file coretemp_freebsd.c.

00235 {
00236     int index = EventCode;
00237 
00238     strncpy( name, coretemp_native_table[index].name, len );
00239 
00240     return PAPI_OK;
00241 }

int coretemp_ntv_enum_events ( unsigned int *  EventCode,
int  modifier 
)

Enumerate Native Events

Parameters:
EventCode is the event of interest
modifier is one of PAPI_ENUM_FIRST, PAPI_ENUM_EVENTS

Definition at line 196 of file coretemp_freebsd.c.

00197 {
00198 
00199     switch ( modifier )
00200     {
00201         /* return EventCode of first event */
00202         case PAPI_ENUM_FIRST:
00203         *EventCode = 0;
00204         return PAPI_OK;
00205         break;
00206 
00207         /* return EventCode of passed-in Event */
00208         case PAPI_ENUM_EVENTS:
00209         {
00210             int index = *EventCode;
00211 
00212             if ( index < CORETEMP_NUM_EVENTS - 1 )
00213             {
00214                 *EventCode = *EventCode + 1;
00215                 return PAPI_OK;
00216             }
00217             else
00218                 return PAPI_ENOEVNT;
00219             break;
00220         }
00221 
00222         default:
00223             return PAPI_EINVAL;
00224     }
00225 
00226     return PAPI_EINVAL;
00227 }

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.

00321 {
00322     int i;
00323     coretemp_control_state_t *c = (coretemp_control_state_t *) ctrl;
00324     UNREFERENCED(ctx);
00325     UNREFERENCED(flags);
00326 
00327     SUBDBG("coretemp_read... %p %d\n", ctx, flags);
00328 
00329     for (i = 0; i < CORETEMP_MAX_COUNTERS; i++)
00330         if (c->added[i])
00331         {
00332             int tmp;
00333             size_t len = sizeof(tmp);
00334 
00335             if (sysctl (coretemp_native_table[i].resources.mib, 4, &tmp, &len, NULL, 0) == -1)
00336                 c->counters[i] = 0;
00337             else
00338                 c->counters[i] = tmp/10;
00339                 /* Coretemp module returns temperature in tenths of kelvin 
00340                    Kelvin are useful to avoid negative values... but will have
00341                    negative temperatures ??? */
00342         }
00343 
00344     *events = c->counters;
00345 
00346     return PAPI_OK;
00347 }

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.

00368 {
00369     UNREFERENCED(ctx);
00370     UNREFERENCED(ctrl);
00371 
00372     SUBDBG("coretemp_reset ctx=%p ctrl=%p...\n", ctx, ctrl);
00373 
00374     /* These sensors cannot be reseted */
00375 
00376     return PAPI_OK;
00377 }

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.

00422 {
00423     UNREFERENCED(cntrl);
00424 
00425     SUBDBG ("coretemp_set_domain... %p %d\n", cntrl, domain);
00426 
00427     if (PAPI_DOM_ALL & domain)
00428     {
00429         SUBDBG( " PAPI_DOM_ALL \n" );
00430         return PAPI_OK;
00431     }
00432     return PAPI_EINVAL ;
00433 
00434 }

int coretemp_shutdown_component ( void   ) 

Triggered by PAPI_shutdown()

Definition at line 380 of file coretemp_freebsd.c.

00381 {
00382 
00383     SUBDBG( "coretemp_shutdown_component... %p\n");
00384 
00385     /* Last chance to clean up */
00386     papi_free (coretemp_native_table);
00387 
00388     return PAPI_OK;
00389 }

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.

00292 {
00293     UNREFERENCED(ctx);
00294     UNREFERENCED(ctrl);
00295 
00296     SUBDBG( "coretemp_start %p %p...\n", ctx, ctrl );
00297 
00298     /* Nothing to be done */
00299 
00300     return PAPI_OK;
00301 }

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.

00306 {
00307     UNREFERENCED(ctx);
00308     UNREFERENCED(ctrl);
00309 
00310     SUBDBG("coretemp_stop %p %p...\n", ctx, ctrl);
00311 
00312     /* Nothing to be done */
00313 
00314     return PAPI_OK;
00315 }

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.

00270 {
00271     int i, index;
00272     coretemp_control_state_t *c = (coretemp_control_state_t *) ptr;
00273     UNREFERENCED(ctx);
00274 
00275     SUBDBG("coretemp_update_control_state %p %p...\n", ptr, ctx);
00276 
00277     for (i = 0; i < count; i++)
00278     {
00279         index = native[i].ni_event;
00280         native[i].ni_position = coretemp_native_table[index].resources.selector - 1;
00281         c->added[native[i].ni_position] = TRUE;
00282 
00283         SUBDBG ("\nnative[%i].ni_position = coretemp_native_table[%i].resources.selector-1 = %i;\n",
00284           i, index, native[i].ni_position );
00285     }
00286 
00287     return PAPI_OK;
00288 }

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.

00353 {
00354     UNREFERENCED(ctx);
00355     UNREFERENCED(events);
00356     UNREFERENCED(ctrl);
00357 
00358     SUBDBG("coretemp_write... %p %p\n", ctx, ctrl);
00359 
00360     /* These sensor counters cannot be writtn */
00361 
00362     return PAPI_OK;
00363 }


Variable Documentation

Vector that points to entry points for our component

Definition at line 438 of file coretemp_freebsd.c.

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.


Generated on 8 Sep 2016 for PAPI by  doxygen 1.6.1