PAPI  5.3.2.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
linux-host_micpower.c
Go to the documentation of this file.
1 
12 /* From intel examples, see $(mic_dir)/sysmgt/sdk/Examples/Usage */
13 #define MAX_DEVICES (32)
14 #define EVENTS_PER_DEVICE 10
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <unistd.h>
18 #include <dlfcn.h>
19 
20 #include "MicAccessTypes.h"
21 #include "MicBasicTypes.h"
22 #include "MicAccessErrorTypes.h"
23 #include "MicAccessApi.h"
24 #include "MicPowerManagerAPI.h"
25 
26 #include "papi.h"
27 #include "papi_internal.h"
28 #include "papi_vector.h"
29 #include "papi_memory.h"
30 
32 
33 /* This is a guess, refine this later */
34 #define UPDATEFREQ 500000
35 
37 
38 typedef struct host_micpower_register {
40  unsigned int selector;
42 
43 typedef struct host_micpower_reg_alloc {
46 
48 typedef struct host_micpower_native_event_entry {
51  char description[PAPI_MAX_STR_LEN];
52  char units[3];
54 
56 typedef struct host_micpower_control_state {
59  long long counts[MAX_DEVICES*EVENTS_PER_DEVICE];
60  long long lastupdate[MAX_DEVICES];
62 
64 typedef struct host_micpower_context {
67 
68 /* Global state info */
69 static MicDeviceOnSystem adapters[MAX_DEVICES];
70 static HANDLE handles[MAX_DEVICES];
71 static long long lastupdate[MAX_DEVICES];
72 static HANDLE accessHandle = NULL;
73 static U32 nAdapters = MAX_DEVICES;
74 
75 static void* mic_access = NULL;
76 static void* scif_access = NULL;
77 
78 #undef MICACCESS_API
79 #define MICACCESS_API __attribute__((weak))
80 const char *MicGetErrorString(U32);
81 U32 MICACCESS_API MicCloseAdapter(HANDLE);
82 U32 MICACCESS_API MicInitAPI(HANDLE *, ETarget, MicDeviceOnSystem *, U32 *);
83 U32 MICACCESS_API MicCloseAPI(HANDLE *);
84 U32 MICACCESS_API MicInitAdapter(HANDLE *, MicDeviceOnSystem *);
85 U32 MICACCESS_API MicGetPowerUsage(HANDLE, MicPwrUsage *);
86 
87 const char *(*MicGetErrorStringPtr)(U32);
88 U32 (*MicCloseAdapterPtr)(HANDLE);
89 U32 (*MicInitAPIPtr)(HANDLE *, ETarget, MicDeviceOnSystem *, U32 *);
90 U32 (*MicCloseAPIPtr)(HANDLE *);
91 U32 (*MicInitAdapterPtr)(HANDLE *, MicDeviceOnSystem *);
92 U32 (*MicGetPowerUsagePtr)(HANDLE, MicPwrUsage *);
94 
95 struct powers {
96  int total0;
97  int total1;
98  int inst;
99  int imax;
100  int pcie;
101  int c2x3;
102  int c2x4;
103  int vccp;
104  int vddg;
105  int vddq;
106 };
107 
108 typedef union {
109  struct powers power;
110  int array[EVENTS_PER_DEVICE];
111 } power_t;
112 
114 
115 static int
117 {
118  /* Attempt to guess if we were statically linked to libc, if so bail */
119  if ( _dl_non_dynamic_init != NULL ) {
120  strncpy(_host_micpower_vector.cmp_info.disabled_reason, "The host_micpower component does not support statically linking of libc.", PAPI_MAX_STR_LEN);
121  return PAPI_ENOSUPP;
122  }
123 
124  /* Need to link in the cuda libraries, if not found disable the component */
125  scif_access = dlopen("libscif.so", RTLD_NOW | RTLD_GLOBAL);
126  if (NULL == scif_access)
127  {
128  snprintf(_host_micpower_vector.cmp_info.disabled_reason, PAPI_MAX_STR_LEN, "Problem loading the SCIF library: %s\n", dlerror());
129  _host_micpower_vector.cmp_info.disabled = 1;
130  return ( PAPI_ENOSUPP );
131  }
132 
133  mic_access = dlopen("libMicAccessSDK.so", RTLD_NOW | RTLD_GLOBAL);
134  if (NULL == mic_access)
135  {
136  snprintf(_host_micpower_vector.cmp_info.disabled_reason, PAPI_MAX_STR_LEN, "Problem loading libMicAccessSDK.so: %s\n", dlerror());
137  _host_micpower_vector.cmp_info.disabled = 1;
138  return ( PAPI_ENOSUPP );
139  }
140 
141  MicGetErrorStringPtr = dlsym(mic_access, "MicGetErrorString");
142  if (dlerror() != NULL)
143  {
144  strncpy(_host_micpower_vector.cmp_info.disabled_reason, "MicAccessSDK function MicGetErrorString not found.",PAPI_MAX_STR_LEN);
145  _host_micpower_vector.cmp_info.disabled = 1;
146  return ( PAPI_ENOSUPP );
147  }
148  MicCloseAdapterPtr = dlsym(mic_access, "MicCloseAdapter");
149  if (dlerror() != NULL)
150  {
151  strncpy(_host_micpower_vector.cmp_info.disabled_reason, "MicAccessSDK function MicCloseAdapter not found.",PAPI_MAX_STR_LEN);
152  _host_micpower_vector.cmp_info.disabled = 1;
153  return ( PAPI_ENOSUPP );
154  }
155  MicInitAPIPtr = dlsym(mic_access, "MicInitAPI");
156  if (dlerror() != NULL)
157  {
158  strncpy(_host_micpower_vector.cmp_info.disabled_reason, "MicAccessSDK function MicInitAPI not found.",PAPI_MAX_STR_LEN);
159  _host_micpower_vector.cmp_info.disabled = 1;
160  return ( PAPI_ENOSUPP );
161  }
162  MicCloseAPIPtr = dlsym(mic_access, "MicCloseAPI");
163  if (dlerror() != NULL)
164  {
165  strncpy(_host_micpower_vector.cmp_info.disabled_reason, "MicAccessSDK function MicCloseAPI not found.",PAPI_MAX_STR_LEN);
166  _host_micpower_vector.cmp_info.disabled = 1;
167  return ( PAPI_ENOSUPP );
168  }
169  MicInitAdapterPtr = dlsym(mic_access, "MicInitAdapter");
170  if (dlerror() != NULL)
171  {
172  strncpy(_host_micpower_vector.cmp_info.disabled_reason, "MicAccessSDK function MicInitAdapter not found.",PAPI_MAX_STR_LEN);
173  _host_micpower_vector.cmp_info.disabled = 1;
174  return ( PAPI_ENOSUPP );
175  }
176 
177  MicGetPowerUsagePtr = dlsym(mic_access, "MicGetPowerUsage");
178  if (dlerror() != NULL)
179  {
180  strncpy(_host_micpower_vector.cmp_info.disabled_reason, "MicAccessSDK function MicGetPowerUsage not found.",PAPI_MAX_STR_LEN);
181  _host_micpower_vector.cmp_info.disabled = 1;
182  return ( PAPI_ENOSUPP );
183  }
184 
185  return 0;
186 }
187 
188 
189 /* ###############################################
190  * Component Interface code
191  * ############################################### */
192 
193 
194 int
196 {
197  U32 ret = MIC_ACCESS_API_ERROR_UNKNOWN;
198  U32 adapterNum = 0;
199  U32 throwaway = 1;
200 
201  _host_micpower_vector.cmp_info.CmpIdx = cidx;
202 
203  if ( loadFunctionPtrs() ) {
204  goto disable_me;
205  }
206 
207  memset( lastupdate, 0x0, sizeof(lastupdate));
208  memset( cached_values, 0x0, sizeof(struct powers)*MAX_DEVICES );
209  ret = MicInitAPIPtr( &accessHandle, eTARGET_SCIF_DRIVER, adapters, &nAdapters );
210  if ( MIC_ACCESS_API_SUCCESS != ret ) {
211  snprintf( _host_micpower_vector.cmp_info.disabled_reason, PAPI_MAX_STR_LEN, "Failed to init: %s", MicGetErrorStringPtr(ret));
212  MicCloseAPIPtr(&accessHandle);
213  goto disable_me;
214  }
215  /* Sanity check on array size */
216  if ( nAdapters >= MAX_DEVICES ) {
217  snprintf(_host_micpower_vector.cmp_info.disabled_reason, PAPI_MAX_STR_LEN, "Too many MIC cards [%d] found, bailing.", nAdapters);
218  MicCloseAPIPtr(&accessHandle);
219  goto disable_me;
220  }
221 
222 /* XXX: This code initializes a token for each adapter, in testing this appeared to be required/
223  * One has to call MicInitAdapter() before calling into that adapter's entries */
224  for (adapterNum=0; adapterNum < nAdapters; adapterNum++) {
225  ret = MicInitAPIPtr( &handles[adapterNum], eTARGET_SCIF_DRIVER, adapters, &throwaway );
226  throwaway = 1;
227  if (MIC_ACCESS_API_SUCCESS != ret) {
228  fprintf(stderr, "%d:MicInitAPI carps: %s\n", __LINE__, MicGetErrorStringPtr(ret));
229  nAdapters = adapterNum;
230  for (adapterNum=0; adapterNum < nAdapters; adapterNum++)
231  MicCloseAdapterPtr( handles[adapterNum] );
232  MicCloseAPIPtr( &accessHandle );
233  snprintf(_host_micpower_vector.cmp_info.disabled_reason, PAPI_MAX_STR_LEN,
234  "Failed to initialize card %d's interface.", nAdapters);
235  goto disable_me;
236  }
237  ret = MicInitAdapterPtr(&handles[adapterNum], &adapters[adapterNum]);
238  if (MIC_ACCESS_API_SUCCESS != ret) {
239  fprintf(stderr, "%d:MicInitAdapter carps: %s\n", __LINE__, MicGetErrorStringPtr(ret));
240  nAdapters = adapterNum;
241  for (adapterNum=0; adapterNum < nAdapters; adapterNum++)
242  MicCloseAdapterPtr( handles[adapterNum] );
243  MicCloseAPIPtr( &accessHandle );
244  snprintf(_host_micpower_vector.cmp_info.disabled_reason, PAPI_MAX_STR_LEN,
245  "Failed to initialize card %d's interface.", nAdapters);
246  goto disable_me;
247  }
248  }
249 
251  if ( NULL == native_events_table ) {
252  return PAPI_ENOMEM;
253  }
254  for (adapterNum=0; adapterNum < nAdapters; adapterNum++) {
255  snprintf(native_events_table[adapterNum*EVENTS_PER_DEVICE].name, PAPI_MAX_STR_LEN, "mic%d:tot0", adapterNum);
256  snprintf(native_events_table[adapterNum*EVENTS_PER_DEVICE].description, PAPI_MAX_STR_LEN, "Total power utilization, Averaged over Time Window 0 (uWatts)");
257  native_events_table[adapterNum*EVENTS_PER_DEVICE].resources.selector = adapterNum*EVENTS_PER_DEVICE + 1;
258  snprintf(native_events_table[adapterNum*EVENTS_PER_DEVICE].units, PAPI_MIN_STR_LEN, "uW");
259 
260  snprintf(native_events_table[adapterNum*EVENTS_PER_DEVICE + 1].name, PAPI_MAX_STR_LEN, "mic%d:tot1", adapterNum);
261  snprintf(native_events_table[adapterNum*EVENTS_PER_DEVICE + 1].description, PAPI_MAX_STR_LEN, "Total power utilization, Averaged over Time Window 1 (uWatts)");
262  native_events_table[adapterNum*EVENTS_PER_DEVICE + 1].resources.selector = adapterNum*EVENTS_PER_DEVICE + 2;
263  snprintf(native_events_table[adapterNum*EVENTS_PER_DEVICE + 1].units, PAPI_MIN_STR_LEN, "uW");
264 
265  snprintf(native_events_table[adapterNum*EVENTS_PER_DEVICE + 2].name, PAPI_MAX_STR_LEN, "mic%d:pcie", adapterNum);
266  snprintf(native_events_table[adapterNum*EVENTS_PER_DEVICE + 2].description, PAPI_MAX_STR_LEN, "PCI-E connector power (uWatts)");
267  native_events_table[adapterNum*EVENTS_PER_DEVICE + 2].resources.selector = adapterNum*EVENTS_PER_DEVICE + 3;
268  snprintf(native_events_table[adapterNum*EVENTS_PER_DEVICE + 2].units, PAPI_MIN_STR_LEN, "uW");
269 
270  snprintf(native_events_table[adapterNum*EVENTS_PER_DEVICE + 3].name, PAPI_MAX_STR_LEN, "mic%d:inst", adapterNum);
271  snprintf(native_events_table[adapterNum*EVENTS_PER_DEVICE + 3].description, PAPI_MAX_STR_LEN, "Instantaneous power (uWatts)");
272  native_events_table[adapterNum*EVENTS_PER_DEVICE + 3].resources.selector = adapterNum*EVENTS_PER_DEVICE + 4;
273  snprintf(native_events_table[adapterNum*EVENTS_PER_DEVICE + 3].units, PAPI_MIN_STR_LEN, "uW");
274 
275  snprintf(native_events_table[adapterNum*EVENTS_PER_DEVICE + 4].name, PAPI_MAX_STR_LEN, "mic%d:imax", adapterNum);
276  snprintf(native_events_table[adapterNum*EVENTS_PER_DEVICE + 4].description, PAPI_MAX_STR_LEN, "Max instantaneous power (uWatts)");
277  native_events_table[adapterNum*EVENTS_PER_DEVICE + 4].resources.selector = adapterNum*EVENTS_PER_DEVICE + 5;
278  snprintf(native_events_table[adapterNum*EVENTS_PER_DEVICE + 4].units, PAPI_MIN_STR_LEN, "uW");
279 
280  snprintf(native_events_table[adapterNum*EVENTS_PER_DEVICE + 5].name, PAPI_MAX_STR_LEN, "mic%d:c2x3", adapterNum);
281  snprintf(native_events_table[adapterNum*EVENTS_PER_DEVICE + 5].description, PAPI_MAX_STR_LEN, "2x3 connector power (uWatts)");
282  native_events_table[adapterNum*EVENTS_PER_DEVICE + 5].resources.selector = adapterNum*EVENTS_PER_DEVICE + 6;
283  snprintf(native_events_table[adapterNum*EVENTS_PER_DEVICE + 5].units, PAPI_MIN_STR_LEN, "uW");
284 
285  snprintf(native_events_table[adapterNum*EVENTS_PER_DEVICE + 6].name, PAPI_MAX_STR_LEN, "mic%d:c2x4", adapterNum);
286  snprintf(native_events_table[adapterNum*EVENTS_PER_DEVICE + 6].description, PAPI_MAX_STR_LEN, "2x4 connector power (uWatts)");
287  native_events_table[adapterNum*EVENTS_PER_DEVICE + 6].resources.selector = adapterNum*EVENTS_PER_DEVICE + 7;
288  snprintf(native_events_table[adapterNum*EVENTS_PER_DEVICE + 6].units, PAPI_MIN_STR_LEN, "uW");
289 
290  snprintf(native_events_table[adapterNum*EVENTS_PER_DEVICE + 7].name, PAPI_MAX_STR_LEN, "mic%d:vccp", adapterNum);
291  snprintf(native_events_table[adapterNum*EVENTS_PER_DEVICE + 7].description, PAPI_MAX_STR_LEN, "Core rail (uVolts)");
292  native_events_table[adapterNum*EVENTS_PER_DEVICE + 7].resources.selector = adapterNum*EVENTS_PER_DEVICE + 8;
293  snprintf(native_events_table[adapterNum*EVENTS_PER_DEVICE + 7].units, PAPI_MIN_STR_LEN, "uV");
294 
295  snprintf(native_events_table[adapterNum*EVENTS_PER_DEVICE + 8].name, PAPI_MAX_STR_LEN, "mic%d:vddg", adapterNum);
296  snprintf(native_events_table[adapterNum*EVENTS_PER_DEVICE + 8].description, PAPI_MAX_STR_LEN, "Uncore rail (uVolts)");
297  native_events_table[adapterNum*EVENTS_PER_DEVICE + 8].resources.selector = adapterNum*EVENTS_PER_DEVICE + 9;
298  snprintf(native_events_table[adapterNum*EVENTS_PER_DEVICE + 8].units, PAPI_MIN_STR_LEN, "uV");
299 
300  snprintf(native_events_table[adapterNum*EVENTS_PER_DEVICE + 9].name, PAPI_MAX_STR_LEN, "mic%d:vddq", adapterNum);
301  snprintf(native_events_table[adapterNum*EVENTS_PER_DEVICE + 9].description, PAPI_MAX_STR_LEN, "Memory subsystem rail (uVolts)");
302  native_events_table[adapterNum*EVENTS_PER_DEVICE + 9].resources.selector = adapterNum*EVENTS_PER_DEVICE + 10;
303  snprintf(native_events_table[adapterNum*EVENTS_PER_DEVICE + 9].units, PAPI_MIN_STR_LEN, "uV");
304  }
305 
306  _host_micpower_vector.cmp_info.num_cntrs = EVENTS_PER_DEVICE*nAdapters;
307  _host_micpower_vector.cmp_info.num_mpx_cntrs = EVENTS_PER_DEVICE*nAdapters;
308 
309  _host_micpower_vector.cmp_info.num_native_events = EVENTS_PER_DEVICE*nAdapters;
310 
311  return PAPI_OK;
312 
313 disable_me:
314  _host_micpower_vector.cmp_info.num_cntrs = 0;
315  _host_micpower_vector.cmp_info.num_mpx_cntrs = 0;
316  _host_micpower_vector.cmp_info.num_native_events = 0;
317  _host_micpower_vector.cmp_info.disabled = 1;
318 
319  nAdapters = 0;
320  return PAPI_ENOSUPP;
321 }
322 
324  (void)ctx;
325  return PAPI_OK;
326 }
327 
328 int
330  U32 i = 0;
331  for( i=0; i<nAdapters; i++) {
332  MicCloseAdapterPtr( handles[i] );
333  }
334 
335  papi_free(native_events_table);
336  return PAPI_OK;
337 }
338 
339 int
341  (void) ctx;
342  return PAPI_OK;
343 }
344 
347  memset( state, 0, sizeof(host_micpower_control_state_t));
348 
349  return PAPI_OK;
350 }
351 
353  NativeInfo_t *info,
354  int count,
355  hwd_context_t* ctx ) {
356 
357  (void) ctx;
358  int i, index;
359 
361 
362  for (i=0; i<MAX_DEVICES*EVENTS_PER_DEVICE; i++)
363  state->resident[i] = 0;
364 
365  for (i=0; i < count; i++) {
366  index = info[i].ni_event&PAPI_NATIVE_AND_MASK;
367  info[i].ni_position=native_events_table[index].resources.selector-1;
368  state->resident[index] = 1;
369  }
370  state->num_events = count;
371 
372  return PAPI_OK;
373 }
374 
375 int
377 {
378  (void) ctx;
379  (void) ctl;
380  return PAPI_OK;
381 }
382 
383 static int
384 read_power( struct powers *pwr, int which_one )
385 {
386  MicPwrUsage power;
387  U32 ret = MIC_ACCESS_API_ERROR_UNKNOWN;
388 
389  if ( which_one < 0 || which_one > (int)nAdapters )
390  return PAPI_ENOEVNT;
391 
392 
393  ret = MicGetPowerUsagePtr(handles[which_one], &power);
394  if (MIC_ACCESS_API_SUCCESS != ret) {
395  fprintf(stderr,"Oops MicGetPowerUsage failed: %s\n",
396  MicGetErrorStringPtr(ret));
397  return PAPI_ECMP;
398  }
399 
400  pwr->total0 = power.total0.prr;
401  pwr->total1 = power.total1.prr;
402  pwr->inst = power.inst.prr;
403  pwr->imax = power.imax.prr;
404  pwr->pcie = power.pcie.prr;
405  pwr->c2x3 = power.c2x3.prr;
406  pwr->c2x4 = power.c2x4.prr;
407  pwr->vccp = power.vccp.pwr;
408  pwr->vddg = power.vddg.pwr;
409  pwr->vddq = power.vddq.pwr;
410 
411  return PAPI_OK;
412 }
413 
414 int
416  long long **events, int flags)
417 {
418  (void)flags;
419  (void)events;
420  (void)ctx;
421  unsigned int i,j;
422  int needs_update = 0;
424  long long now = PAPI_get_real_usec();
425 
426  for( i=0; i<nAdapters; i++) {
427  needs_update = 0;
428  for (j=0; j<EVENTS_PER_DEVICE; j++) {
429  if ( control->resident[EVENTS_PER_DEVICE*i+j]) {
430  needs_update = 1;
431  break;
432  }
433  }
434 
435  if ( needs_update ) {
436  /* Do the global update */
437  if ( now >= lastupdate[i] + UPDATEFREQ) {
438  read_power( &cached_values[i].power, i );
439  lastupdate[i] = now;
440  }
441  /* update from cached values */
442  if ( control->lastupdate[i] < lastupdate[i]) {
443  control->lastupdate[i] = lastupdate[i];
444  }
445  for (j=0; j<EVENTS_PER_DEVICE; j++) {
446  if ( control->resident[EVENTS_PER_DEVICE*i+j] ) {
447  control->counts[EVENTS_PER_DEVICE*i+j] = (long long)cached_values[i].array[j];
448  }
449  }
450  }
451  }
452 
453  *events = control->counts;
454  return PAPI_OK;
455 }
456 
457 int
459 {
460  (void)ctx;
461  int needs_update = 0;
462  unsigned int i,j;
464  long long now = PAPI_get_real_usec();
465 
466  for( i=0; i<nAdapters; i++) {
467  needs_update = 0;
468  for (j=0; j<EVENTS_PER_DEVICE; j++) {
469  if ( control->resident[EVENTS_PER_DEVICE*i+j]) {
470  needs_update = 1;
471  break;
472  }
473  }
474 
475  if ( needs_update ) {
476  /* Do the global update */
477  if ( now >= lastupdate[i] + UPDATEFREQ) {
478  read_power( &cached_values[i].power, i );
479  lastupdate[i] = now;
480  }
481  /* update from cached values */
482  if ( control->lastupdate[i] < lastupdate[i]) {
483  control->lastupdate[i] = lastupdate[i];
484  }
485  for (j=0; j<EVENTS_PER_DEVICE; j++) {
486  if ( control->resident[EVENTS_PER_DEVICE*i+j] ) {
487  control->counts[EVENTS_PER_DEVICE*i+j] = (long long)cached_values[i].array[j];
488  }
489  }
490  }
491  }
492  return PAPI_OK;
493 
494 }
495 
496 int _host_micpower_ntv_enum_events( unsigned int *EventCode, int modifier )
497 {
498  int index;
499  switch (modifier) {
500  case PAPI_ENUM_FIRST:
501  if (0 == _host_micpower_vector.cmp_info.num_cntrs)
502  return PAPI_ENOEVNT;
503  *EventCode = 0;
504  return PAPI_OK;
505  case PAPI_ENUM_EVENTS:
506  index = *EventCode;
507  if ( index < _host_micpower_vector.cmp_info.num_cntrs - 1) {
508  *EventCode = *EventCode + 1;
509  return PAPI_OK;
510  } else {
511  return PAPI_ENOEVNT;
512  }
513  break;
514  default:
515  return PAPI_EINVAL;
516  }
517  return PAPI_EINVAL;
518 }
519 
520 int
521 _host_micpower_ntv_code_to_name( unsigned int EventCode, char *name, int len )
522 {
523  unsigned int code = EventCode & PAPI_NATIVE_AND_MASK;
524  if ( code < _host_micpower_vector.cmp_info.num_cntrs ) {
525  strncpy( name, native_events_table[code].name, len);
526  return PAPI_OK;
527  }
528 
529  return PAPI_ENOEVNT;
530 }
531 
532 int
533 _host_micpower_ntv_code_to_descr( unsigned int EventCode, char *name, int len )
534 {
535  unsigned int code = EventCode & PAPI_NATIVE_AND_MASK;
536  if ( code < _host_micpower_vector.cmp_info.num_cntrs ) {
537  strncpy( name, native_events_table[code].description, len );
538  return PAPI_OK;
539  }
540 
541  return PAPI_ENOEVNT;
542 }
543 
544 int
545 _host_micpower_ntv_code_to_info( unsigned int EventCode, PAPI_event_info_t *info)
546 {
547  unsigned int code = EventCode & PAPI_NATIVE_AND_MASK;
548  if ( code >= _host_micpower_vector.cmp_info.num_cntrs)
549  return PAPI_ENOEVNT;
550  strncpy( info->symbol, native_events_table[code].name, sizeof(info->symbol) );
551  strncpy( info->long_descr, native_events_table[code].description, sizeof(info->long_descr) );
552  strncpy( info->units, native_events_table[code].units, sizeof(info->units) );
553  return PAPI_OK;
554 }
555 
556 int
558 {
559  (void)ctx;
560  (void)code;
561  (void)option;
562  return PAPI_OK;
563 }
564 
565 int
567 {
568  (void)ctl;
569  if ( PAPI_DOM_ALL != domain )
570  return PAPI_EINVAL;
571  return PAPI_OK;
572 }
573 
574 papi_vector_t _host_micpower_vector = {
575  .cmp_info = {
576  .name = "host_micpower",
577  .short_name = "host_micpower",
578  .description = "A host-side component to read power usage on MIC guest cards.",
579  .version = "0.1",
580  .support_version = "n/a",
581  .kernel_version = "n/a",
582  .num_cntrs = 0,
583  .num_mpx_cntrs = 0,
584  .default_domain = PAPI_DOM_ALL,
585  .available_domains = PAPI_DOM_ALL,
586  .default_granularity = PAPI_GRN_SYS,
587  .available_granularities = PAPI_GRN_SYS,
588  .hardware_intr_sig = PAPI_INT_SIGNAL,
589  },
590 
591  .size = {
592  .context = sizeof(host_micpower_context_t),
593  .control_state = sizeof(host_micpower_control_state_t),
594  .reg_value = sizeof(host_micpower_register_t),
595  .reg_alloc = sizeof(host_micpower_reg_alloc_t),
596  },
597 
598  .start = _host_micpower_start,
599  .stop = _host_micpower_start,
600  .read = _host_micpower_read,
601  .reset = NULL,
602  .write = NULL,
603  .init_component = _host_micpower_init_component,
604  .init_thread = _host_micpower_init_thread,
605  .init_control_state = _host_micpower_init_control_state,
606  .update_control_state = _host_micpower_update_control_state,
607  .ctl = _host_micpower_ctl,
608  .shutdown_thread = _host_micpower_shutdown_thread,
609  .shutdown_component = _host_micpower_shutdown_component,
610  .set_domain = _host_micpower_set_domain,
611 
612  .ntv_enum_events = _host_micpower_ntv_enum_events,
613  .ntv_code_to_name = _host_micpower_ntv_code_to_name,
614  .ntv_code_to_descr = _host_micpower_ntv_code_to_descr,
615  .ntv_code_to_info = _host_micpower_ntv_code_to_info,
616 
617 };
int _host_micpower_ntv_code_to_descr(unsigned int EventCode, char *name, int len)
char name[PAPI_MAX_STR_LEN]
Definition: papi.h:625
static HANDLE handles[MAX_DEVICES]
memset(eventId, 0, size)
int _host_micpower_stop(hwd_context_t *ctx, hwd_control_state_t *ctl)
papi_vector_t _host_micpower_vector
#define PAPI_ENOMEM
Definition: fpapi.h:107
int _host_micpower_ctl(hwd_context_t *ctx, int code, _papi_int_option_t *option)
long long flags
Definition: iozone.c:12330
#define papi_free(a)
Definition: papi_memory.h:35
#define PAPI_MAX_STR_LEN
Definition: fpapi.h:43
#define PAPI_DOM_ALL
Definition: fpapi.h:25
#define papi_malloc(a)
Definition: papi_memory.h:34
#define PAPI_MIN_STR_LEN
Definition: fpapi.h:41
char name[PAPI_MAX_STR_LEN]
const char *(* MicGetErrorStringPtr)(U32)
#define PAPI_ENOEVNT
Definition: fpapi.h:112
int resident[MAX_DEVICES *EVENTS_PER_DEVICE]
char long_descr[PAPI_HUGE_STR_LEN]
Definition: papi.h:964
#define MAX_DEVICES
This component wraps the MicAccessAPI to provide hostside power information for attached Intel Xeon P...
int _host_micpower_set_domain(hwd_control_state_t *ctl, int domain)
const char * MicGetErrorString(U32)
host_micpower_register_t resources
char symbol[PAPI_HUGE_STR_LEN]
Definition: papi.h:961
for(i=0;i<=max_y;i++)
Definition: iozone.c:11615
long long lastupdate[MAX_DEVICES]
return PAPI_OK
Definition: linux-nvml.c:458
int count
Definition: iozone.c:22422
#define PAPI_GRN_SYS
Definition: fpapi.h:71
void
Definition: iozone.c:18627
host_micpower_register_t
return PAPI_EINVAL
Definition: linux-nvml.c:408
PAPI_component_info_t cmp_info
Definition: papi_vector.h:20
int _host_micpower_ntv_enum_events(unsigned int *EventCode, int modifier)
U32 MICACCESS_API MicInitAdapter(HANDLE *, MicDeviceOnSystem *)
Return codes and api definitions.
long long ret
Definition: iozone.c:1346
U32(* MicInitAdapterPtr)(HANDLE *, MicDeviceOnSystem *)
char disabled_reason[PAPI_MAX_STR_LEN]
Definition: papi.h:632
static power_t cached_values[MAX_DEVICES]
static MicDeviceOnSystem adapters[MAX_DEVICES]
static host_micpower_native_event_entry_t * native_events_table
void(* _dl_non_dynamic_init)(void)
Definition: linux-cuda.c:41
host_micpower_control_state_t state
int i
Definition: fileop.c:140
#define PAPI_ENOSUPP
Definition: fpapi.h:123
U32 MICACCESS_API MicGetPowerUsage(HANDLE, MicPwrUsage *)
#define EVENTS_PER_DEVICE
#define MICACCESS_API
static int cidx
Definition: event_info.c:40
#define PAPI_ECMP
Definition: fpapi.h:109
int _host_micpower_ntv_code_to_info(unsigned int EventCode, PAPI_event_info_t *info)
int _host_micpower_start(hwd_context_t *ctx, hwd_control_state_t *ctl)
U32(* MicGetPowerUsagePtr)(HANDLE, MicPwrUsage *)
__attribute__((constructor))
Definition: init_fini.c:12
static U32 nAdapters
host_micpower_register_t ra_bits
long long
Definition: iozone.c:19827
U32(* MicCloseAPIPtr)(HANDLE *)
static long long lastupdate[MAX_DEVICES]
char events[MAX_EVENTS][BUFSIZ]
static void * scif_access
int _host_micpower_update_control_state(hwd_control_state_t *ctl, NativeInfo_t *info, int count, hwd_context_t *ctx)
#define PAPI_INT_SIGNAL
Definition: papi_internal.h:53
U32 MICACCESS_API MicInitAPI(HANDLE *, ETarget, MicDeviceOnSystem *, U32 *)
U32(* MicInitAPIPtr)(HANDLE *, ETarget, MicDeviceOnSystem *, U32 *)
static HANDLE accessHandle
static int read_power(struct powers *pwr, int which_one)
static int loadFunctionPtrs()
int _host_micpower_init_component(int cidx)
long long PAPI_get_real_usec(void)
Definition: papi.c:6138
#define UPDATEFREQ
char * name
Definition: iozone.c:23648
int _host_micpower_ntv_code_to_name(unsigned int EventCode, char *name, int len)
child_idents[x-1] state
Definition: iozone.c:21341
long long counts[MAX_DEVICES *EVENTS_PER_DEVICE]
#define PAPI_NATIVE_AND_MASK
U32 MICACCESS_API MicCloseAdapter(HANDLE)
int _host_micpower_shutdown_component(void)
int _host_micpower_read(hwd_context_t *ctx, hwd_control_state_t *ctl, long long **events, int flags)
U32(* MicCloseAdapterPtr)(HANDLE)
char units[3]
long j
Definition: iozone.c:19135
char description[PAPI_MAX_STR_LEN]
int _host_micpower_init_control_state(hwd_control_state_t *ctl)
static void * mic_access
char units[PAPI_MIN_STR_LEN]
Definition: papi.h:970
int _host_micpower_shutdown_thread(hwd_context_t *ctx)
U32 MICACCESS_API MicCloseAPI(HANDLE *)
int _host_micpower_init_thread(hwd_context_t *ctx)