PAPI 7.1.0.0
Loading...
Searching...
No Matches
vmware.c File Reference
Include dependency graph for vmware.c:

Go to the source code of this file.

Data Structures

struct  _vmware_native_event_entry
 
struct  _vmware_reg_alloc
 
struct  _vmware_control_state
 
struct  _vmware_context
 

Macros

#define VMWARE_MAX_COUNTERS   256
 
#define VMWARE_CPU_LIMIT_MHZ   0
 
#define VMWARE_CPU_RESERVATION_MHZ   1
 
#define VMWARE_CPU_SHARES   2
 
#define VMWARE_CPU_STOLEN_MS   3
 
#define VMWARE_CPU_USED_MS   4
 
#define VMWARE_ELAPSED_MS   5
 
#define VMWARE_MEM_ACTIVE_MB   6
 
#define VMWARE_MEM_BALLOONED_MB   7
 
#define VMWARE_MEM_LIMIT_MB   8
 
#define VMWARE_MEM_MAPPED_MB   9
 
#define VMWARE_MEM_OVERHEAD_MB   10
 
#define VMWARE_MEM_RESERVATION_MB   11
 
#define VMWARE_MEM_SHARED_MB   12
 
#define VMWARE_MEM_SHARES   13
 
#define VMWARE_MEM_SWAPPED_MB   14
 
#define VMWARE_MEM_TARGET_SIZE_MB   15
 
#define VMWARE_MEM_USED_MB   16
 
#define VMWARE_HOST_CPU_MHZ   17
 
#define VMWARE_HOST_TSC   18
 
#define VMWARE_ELAPSED_TIME   19
 
#define VMWARE_ELAPSED_APPARENT   20
 

Functions

uint64_t rdpmc (int c)
 
static int LoadFunctions (void)
 
static long long _vmware_hardware_read (struct _vmware_context *context, int starting)
 
int _vmware_init_thread (hwd_context_t *ctx)
 
int _vmware_init_component (int cidx)
 
int _vmware_init_control_state (hwd_control_state_t *ctl)
 
int _vmware_ntv_enum_events (unsigned int *EventCode, int modifier)
 
int _vmware_ntv_code_to_info (unsigned int EventCode, PAPI_event_info_t *info)
 
int _vmware_ntv_code_to_name (unsigned int EventCode, char *name, int len)
 
int _vmware_ntv_code_to_descr (unsigned int EventCode, char *name, int len)
 
int _vmware_update_control_state (hwd_control_state_t *ctl, NativeInfo_t *native, int count, hwd_context_t *ctx)
 
int _vmware_start (hwd_context_t *ctx, hwd_control_state_t *ctl)
 
int _vmware_stop (hwd_context_t *ctx, hwd_control_state_t *ctl)
 
int _vmware_read (hwd_context_t *ctx, hwd_control_state_t *ctl, long_long **events, int flags)
 
int _vmware_write (hwd_context_t *ctx, hwd_control_state_t *ctrl, long_long events[])
 
int _vmware_reset (hwd_context_t *ctx, hwd_control_state_t *ctl)
 
int _vmware_shutdown_thread (hwd_context_t *ctx)
 
int _vmware_shutdown_component (void)
 
int _vmware_ctl (hwd_context_t *ctx, int code, _papi_int_option_t *option)
 
int _vmware_set_domain (hwd_control_state_t *ctl, int domain)
 

Variables

papi_vector_t _vmware_vector
 
void(* _dl_non_dynamic_init )(void)
 
static struct _vmware_native_event_entry_vmware_native_table
 
static int num_events = 0
 
static int use_pseudo =0
 
static int use_guestlib =0
 

Macro Definition Documentation

◆ VMWARE_CPU_LIMIT_MHZ

#define VMWARE_CPU_LIMIT_MHZ   0

Definition at line 39 of file vmware.c.

◆ VMWARE_CPU_RESERVATION_MHZ

#define VMWARE_CPU_RESERVATION_MHZ   1

Definition at line 40 of file vmware.c.

◆ VMWARE_CPU_SHARES

#define VMWARE_CPU_SHARES   2

Definition at line 41 of file vmware.c.

◆ VMWARE_CPU_STOLEN_MS

#define VMWARE_CPU_STOLEN_MS   3

Definition at line 42 of file vmware.c.

◆ VMWARE_CPU_USED_MS

#define VMWARE_CPU_USED_MS   4

Definition at line 43 of file vmware.c.

◆ VMWARE_ELAPSED_APPARENT

#define VMWARE_ELAPSED_APPARENT   20

Definition at line 64 of file vmware.c.

◆ VMWARE_ELAPSED_MS

#define VMWARE_ELAPSED_MS   5

Definition at line 44 of file vmware.c.

◆ VMWARE_ELAPSED_TIME

#define VMWARE_ELAPSED_TIME   19

Definition at line 63 of file vmware.c.

◆ VMWARE_HOST_CPU_MHZ

#define VMWARE_HOST_CPU_MHZ   17

Definition at line 58 of file vmware.c.

◆ VMWARE_HOST_TSC

#define VMWARE_HOST_TSC   18

Definition at line 62 of file vmware.c.

◆ VMWARE_MAX_COUNTERS

#define VMWARE_MAX_COUNTERS   256

Definition at line 37 of file vmware.c.

◆ VMWARE_MEM_ACTIVE_MB

#define VMWARE_MEM_ACTIVE_MB   6

Definition at line 46 of file vmware.c.

◆ VMWARE_MEM_BALLOONED_MB

#define VMWARE_MEM_BALLOONED_MB   7

Definition at line 47 of file vmware.c.

◆ VMWARE_MEM_LIMIT_MB

#define VMWARE_MEM_LIMIT_MB   8

Definition at line 48 of file vmware.c.

◆ VMWARE_MEM_MAPPED_MB

#define VMWARE_MEM_MAPPED_MB   9

Definition at line 49 of file vmware.c.

◆ VMWARE_MEM_OVERHEAD_MB

#define VMWARE_MEM_OVERHEAD_MB   10

Definition at line 50 of file vmware.c.

◆ VMWARE_MEM_RESERVATION_MB

#define VMWARE_MEM_RESERVATION_MB   11

Definition at line 51 of file vmware.c.

◆ VMWARE_MEM_SHARED_MB

#define VMWARE_MEM_SHARED_MB   12

Definition at line 52 of file vmware.c.

◆ VMWARE_MEM_SHARES

#define VMWARE_MEM_SHARES   13

Definition at line 53 of file vmware.c.

◆ VMWARE_MEM_SWAPPED_MB

#define VMWARE_MEM_SWAPPED_MB   14

Definition at line 54 of file vmware.c.

◆ VMWARE_MEM_TARGET_SIZE_MB

#define VMWARE_MEM_TARGET_SIZE_MB   15

Definition at line 55 of file vmware.c.

◆ VMWARE_MEM_USED_MB

#define VMWARE_MEM_USED_MB   16

Definition at line 56 of file vmware.c.

Function Documentation

◆ _vmware_ctl()

int _vmware_ctl ( hwd_context_t ctx,
int  code,
_papi_int_option_t option 
)

This function sets various options in the component

Parameters
ctx
codevalid are PAPI_SET_DEFDOM, PAPI_SET_DOMAIN, PAPI_SETDEFGRN, PAPI_SET_GRANUL and PAPI_SET_INHERIT
option

Definition at line 1190 of file vmware.c.

1191{
1192
1193 (void) ctx;
1194 (void) code;
1195 (void) option;
1196
1197 SUBDBG( "_vmware_ctl..." );
1198
1199 return PAPI_OK;
1200}
#define PAPI_OK
Definition: f90papi.h:73
#define SUBDBG(format, args...)
Definition: papi_debug.h:64

◆ _vmware_hardware_read()

static long long _vmware_hardware_read ( struct _vmware_context context,
int  starting 
)
static

Code that reads event values. You might replace this with code that accesses hardware or reads values from the operatings system.

Definition at line 302 of file vmware.c.

303{
304
305 int i;
306
307 if (use_pseudo) {
308 context->values[VMWARE_HOST_TSC]=rdpmc(0x10000);
309 context->values[VMWARE_ELAPSED_TIME]=rdpmc(0x10001);
310 context->values[VMWARE_ELAPSED_APPARENT]=rdpmc(0x10002);
311 }
312
313
314#ifdef VMGUESTLIB
315 static VMSessionId sessionId = 0;
316 VMSessionId tmpSession;
317 uint32_t temp32;
318 uint64_t temp64;
319 VMGuestLibError glError;
320
321 if (use_guestlib) {
322
323 glError = GuestLib_UpdateInfo(context->glHandle);
324 if (glError != VMGUESTLIB_ERROR_SUCCESS) {
325 fprintf(stderr,"UpdateInfo failed: %s\n",
326 GuestLib_GetErrorText(glError));
327 return PAPI_ECMP;
328 }
329
330 /* Retrieve and check the session ID */
331 glError = GuestLib_GetSessionId(context->glHandle, &tmpSession);
332 if (glError != VMGUESTLIB_ERROR_SUCCESS) {
333 fprintf(stderr, "Failed to get session ID: %s\n",
334 GuestLib_GetErrorText(glError));
335 return PAPI_ECMP;
336 }
337
338 if (tmpSession == 0) {
339 fprintf(stderr, "Error: Got zero sessionId from GuestLib\n");
340 return PAPI_ECMP;
341 }
342
343 if (sessionId == 0) {
344 sessionId = tmpSession;
345 } else if (tmpSession != sessionId) {
346 sessionId = tmpSession;
347 }
348
349 glError = GuestLib_GetCpuLimitMHz(context->glHandle,&temp32);
350 context->values[VMWARE_CPU_LIMIT_MHZ]=temp32;
351 if (glError != VMGUESTLIB_ERROR_SUCCESS) {
352 fprintf(stderr,"Failed to get CPU limit: %s\n",
353 GuestLib_GetErrorText(glError));
354 return PAPI_ECMP;
355 }
356
357 glError = GuestLib_GetCpuReservationMHz(context->glHandle,&temp32);
358 context->values[VMWARE_CPU_RESERVATION_MHZ]=temp32;
359 if (glError != VMGUESTLIB_ERROR_SUCCESS) {
360 fprintf(stderr,"Failed to get CPU reservation: %s\n",
361 GuestLib_GetErrorText(glError));
362 return PAPI_ECMP;
363 }
364
365 glError = GuestLib_GetCpuShares(context->glHandle,&temp32);
366 context->values[VMWARE_CPU_SHARES]=temp32;
367 if (glError != VMGUESTLIB_ERROR_SUCCESS) {
368 fprintf(stderr,"Failed to get cpu shares: %s\n",
369 GuestLib_GetErrorText(glError));
370 return PAPI_ECMP;
371 }
372
373 glError = GuestLib_GetCpuStolenMs(context->glHandle,&temp64);
374 context->values[VMWARE_CPU_STOLEN_MS]=temp64;
375 if (glError != VMGUESTLIB_ERROR_SUCCESS) {
376 if (glError == VMGUESTLIB_ERROR_UNSUPPORTED_VERSION) {
377 context->values[VMWARE_CPU_STOLEN_MS]=0;
378 fprintf(stderr, "Skipping CPU stolen, not supported...\n");
379 } else {
380 fprintf(stderr, "Failed to get CPU stolen: %s\n",
381 GuestLib_GetErrorText(glError));
382 return PAPI_ECMP;
383 }
384 }
385
386 glError = GuestLib_GetCpuUsedMs(context->glHandle,&temp64);
387 context->values[VMWARE_CPU_USED_MS]=temp64;
388 if (glError != VMGUESTLIB_ERROR_SUCCESS) {
389 fprintf(stderr, "Failed to get used ms: %s\n",
390 GuestLib_GetErrorText(glError));
391 return PAPI_ECMP;
392 }
393
394 glError = GuestLib_GetElapsedMs(context->glHandle, &temp64);
395 context->values[VMWARE_ELAPSED_MS]=temp64;
396 if (glError != VMGUESTLIB_ERROR_SUCCESS) {
397 fprintf(stderr, "Failed to get elapsed ms: %s\n",
398 GuestLib_GetErrorText(glError));
399 return PAPI_ECMP;
400 }
401
402 glError = GuestLib_GetMemActiveMB(context->glHandle, &temp32);
403 context->values[VMWARE_MEM_ACTIVE_MB]=temp32;
404 if (glError != VMGUESTLIB_ERROR_SUCCESS) {
405 fprintf(stderr, "Failed to get active mem: %s\n",
406 GuestLib_GetErrorText(glError));
407 return PAPI_ECMP;
408 }
409
410 glError = GuestLib_GetMemBalloonedMB(context->glHandle, &temp32);
411 context->values[VMWARE_MEM_BALLOONED_MB]=temp32;
412 if (glError != VMGUESTLIB_ERROR_SUCCESS) {
413 fprintf(stderr, "Failed to get ballooned mem: %s\n",
414 GuestLib_GetErrorText(glError));
415 return PAPI_ECMP;
416 }
417
418 glError = GuestLib_GetMemLimitMB(context->glHandle, &temp32);
419 context->values[VMWARE_MEM_LIMIT_MB]=temp32;
420 if (glError != VMGUESTLIB_ERROR_SUCCESS) {
421 fprintf(stderr,"Failed to get mem limit: %s\n",
422 GuestLib_GetErrorText(glError));
423 return PAPI_ECMP;
424 }
425
426 glError = GuestLib_GetMemMappedMB(context->glHandle, &temp32);
427 context->values[VMWARE_MEM_MAPPED_MB]=temp32;
428 if (glError != VMGUESTLIB_ERROR_SUCCESS) {
429 fprintf(stderr, "Failed to get mapped mem: %s\n",
430 GuestLib_GetErrorText(glError));
431 return PAPI_ECMP;
432 }
433
434 glError = GuestLib_GetMemOverheadMB(context->glHandle, &temp32);
435 context->values[VMWARE_MEM_OVERHEAD_MB]=temp32;
436 if (glError != VMGUESTLIB_ERROR_SUCCESS) {
437 fprintf(stderr, "Failed to get overhead mem: %s\n",
438 GuestLib_GetErrorText(glError));
439 return PAPI_ECMP;
440 }
441
442 glError = GuestLib_GetMemReservationMB(context->glHandle, &temp32);
443 context->values[VMWARE_MEM_RESERVATION_MB]=temp32;
444 if (glError != VMGUESTLIB_ERROR_SUCCESS) {
445 fprintf(stderr, "Failed to get mem reservation: %s\n",
446 GuestLib_GetErrorText(glError));
447 return PAPI_ECMP;
448 }
449
450 glError = GuestLib_GetMemSharedMB(context->glHandle, &temp32);
451 context->values[VMWARE_MEM_SHARED_MB]=temp32;
452 if (glError != VMGUESTLIB_ERROR_SUCCESS) {
453 fprintf(stderr, "Failed to get swapped mem: %s\n",
454 GuestLib_GetErrorText(glError));
455 return PAPI_ECMP;
456 }
457
458 glError = GuestLib_GetMemShares(context->glHandle, &temp32);
459 context->values[VMWARE_MEM_SHARES]=temp32;
460 if (glError != VMGUESTLIB_ERROR_SUCCESS) {
461 if (glError == VMGUESTLIB_ERROR_NOT_AVAILABLE) {
462 context->values[VMWARE_MEM_SHARES]=0;
463 fprintf(stderr, "Skipping mem shares, not supported...\n");
464 } else {
465 fprintf(stderr, "Failed to get mem shares: %s\n",
466 GuestLib_GetErrorText(glError));
467 return PAPI_ECMP;
468 }
469 }
470
471 glError = GuestLib_GetMemSwappedMB(context->glHandle, &temp32);
472 context->values[VMWARE_MEM_SWAPPED_MB]=temp32;
473 if (glError != VMGUESTLIB_ERROR_SUCCESS) {
474 fprintf(stderr, "Failed to get swapped mem: %s\n",
475 GuestLib_GetErrorText(glError));
476 return PAPI_ECMP;
477 }
478
479 glError = GuestLib_GetMemTargetSizeMB(context->glHandle, &temp64);
480 context->values[VMWARE_MEM_TARGET_SIZE_MB]=temp64;
481 if (glError != VMGUESTLIB_ERROR_SUCCESS) {
482 if (glError == VMGUESTLIB_ERROR_UNSUPPORTED_VERSION) {
484 fprintf(stderr, "Skipping target mem size, not supported...\n");
485 } else {
486 fprintf(stderr, "Failed to get target mem size: %s\n",
487 GuestLib_GetErrorText(glError));
488 return PAPI_ECMP;
489 }
490 }
491
492 glError = GuestLib_GetMemUsedMB(context->glHandle, &temp32);
493 context->values[VMWARE_MEM_USED_MB]=temp32;
494 if (glError != VMGUESTLIB_ERROR_SUCCESS) {
495 fprintf(stderr, "Failed to get swapped mem: %s\n",
496 GuestLib_GetErrorText(glError));
497 return PAPI_ECMP;
498 }
499
500 glError = GuestLib_GetHostProcessorSpeed(context->glHandle, &temp32);
501 context->values[VMWARE_HOST_CPU_MHZ]=temp32;
502 if (glError != VMGUESTLIB_ERROR_SUCCESS) {
503 fprintf(stderr, "Failed to get host proc speed: %s\n",
504 GuestLib_GetErrorText(glError));
505 return PAPI_ECMP;
506 }
507 }
508
509#endif
510
511 if (starting) {
512
513 for(i=0;i<VMWARE_MAX_COUNTERS;i++) {
514 context->start_values[i]=context->values[i];
515 }
516
517 }
518
519 return PAPI_OK;
520}
int i
#define PAPI_ECMP
Definition: f90papi.h:214
FILE * stderr
long long start_values[VMWARE_MAX_COUNTERS]
Definition: vmware.c:173
long long values[VMWARE_MAX_COUNTERS]
Definition: vmware.c:172
#define VMWARE_CPU_USED_MS
Definition: vmware.c:43
#define VMWARE_MEM_MAPPED_MB
Definition: vmware.c:49
#define VMWARE_MEM_SHARED_MB
Definition: vmware.c:52
#define VMWARE_HOST_TSC
Definition: vmware.c:62
#define VMWARE_CPU_RESERVATION_MHZ
Definition: vmware.c:40
#define VMWARE_ELAPSED_MS
Definition: vmware.c:44
#define VMWARE_MEM_OVERHEAD_MB
Definition: vmware.c:50
#define VMWARE_ELAPSED_TIME
Definition: vmware.c:63
#define VMWARE_MAX_COUNTERS
Definition: vmware.c:37
static int use_guestlib
Definition: vmware.c:292
uint64_t rdpmc(int c)
Definition: vmware.c:93
#define VMWARE_MEM_LIMIT_MB
Definition: vmware.c:48
#define VMWARE_MEM_ACTIVE_MB
Definition: vmware.c:46
#define VMWARE_MEM_SWAPPED_MB
Definition: vmware.c:54
#define VMWARE_CPU_LIMIT_MHZ
Definition: vmware.c:39
static int use_pseudo
Definition: vmware.c:291
#define VMWARE_CPU_STOLEN_MS
Definition: vmware.c:42
#define VMWARE_MEM_USED_MB
Definition: vmware.c:56
#define VMWARE_ELAPSED_APPARENT
Definition: vmware.c:64
#define VMWARE_MEM_BALLOONED_MB
Definition: vmware.c:47
#define VMWARE_HOST_CPU_MHZ
Definition: vmware.c:58
#define VMWARE_MEM_SHARES
Definition: vmware.c:53
#define VMWARE_MEM_TARGET_SIZE_MB
Definition: vmware.c:55
#define VMWARE_CPU_SHARES
Definition: vmware.c:41
#define VMWARE_MEM_RESERVATION_MB
Definition: vmware.c:51
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _vmware_init_component()

int _vmware_init_component ( int  cidx)

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 560 of file vmware.c.

561{
562 int retval = PAPI_OK;
563 (void) cidx;
564
565 int result;
566
567 SUBDBG( "_vmware_init_component..." );
568
569 /* Initialize and try to load the VMware library */
570 /* Try to load the library. */
572
573 if (result!=PAPI_OK) {
575 "GuestLibTest: Failed to load shared library",
578 goto fn_fail;
579 }
580
581 /* we know in advance how many events we want */
582 /* for actual hardware this might have to be determined dynamically */
583
584 /* Allocate memory for the our event table */
586 calloc( VMWARE_MAX_COUNTERS, sizeof ( struct _vmware_native_event_entry ));
587 if ( _vmware_native_table == NULL ) {
589 goto fn_fail;
590 }
591
592
593#ifdef VMGUESTLIB
594
595 /* Detect if GuestLib works */
596 {
597
598 VMGuestLibError glError;
599 VMGuestLibHandle glHandle;
600
601 use_guestlib=0;
602
603 /* try to open */
604 glError = GuestLib_OpenHandle(&glHandle);
605 if (glError != VMGUESTLIB_ERROR_SUCCESS) {
606 fprintf(stderr,"OpenHandle failed: %s\n",
607 GuestLib_GetErrorText(glError));
608 }
609 else {
610 /* open worked, try to update */
611 glError = GuestLib_UpdateInfo(glHandle);
612 if (glError != VMGUESTLIB_ERROR_SUCCESS) {
613 fprintf(stderr,"UpdateInfo failed: %s\n",
614 GuestLib_GetErrorText(glError));
615 }
616 else {
617 /* update worked, things work! */
618 use_guestlib=1;
619 }
620 /* shut things down */
621 glError = GuestLib_CloseHandle(glHandle);
622 }
623
624 }
625
626
627
628 if (use_guestlib) {
629
630 /* fill in the event table parameters */
632 "CPU_LIMIT" );
634 "Retrieves the upper limit of processor use in MHz "
635 "available to the virtual machine.",
637 strcpy( _vmware_native_table[num_events].units,"MHz");
641 num_events++;
642
644 "CPU_RESERVATION" );
646 "Retrieves the minimum processing power in MHz "
647 "reserved for the virtual machine.",
649 strcpy( _vmware_native_table[num_events].units,"MHz");
653 num_events++;
654
656 "CPU_SHARES" );
658 "Retrieves the number of CPU shares allocated "
659 "to the virtual machine.",
661 strcpy( _vmware_native_table[num_events].units,"shares");
665 num_events++;
666
668 "CPU_STOLEN" );
670 "Retrieves the number of milliseconds that the "
671 "virtual machine was in a ready state (able to "
672 "transition to a run state), but was not scheduled to run.",
678 num_events++;
679
681 "CPU_USED" );
683 "Retrieves the number of milliseconds during which "
684 "the virtual machine has used the CPU. This value "
685 "includes the time used by the guest operating system "
686 "and the time used by virtualization code for tasks for "
687 "this virtual machine. You can combine this value with "
688 "the elapsed time (VMWARE_ELAPSED) to estimate the "
689 "effective virtual machine CPU speed. This value is a "
690 "subset of elapsedMs.",
696 num_events++;
697
699 "ELAPSED" );
701 "Retrieves the number of milliseconds that have passed "
702 "in the virtual machine since it last started running on "
703 "the server. The count of elapsed time restarts each time "
704 "the virtual machine is powered on, resumed, or migrated "
705 "using VMotion. This value counts milliseconds, regardless "
706 "of whether the virtual machine is using processing power "
707 "during that time. You can combine this value with the CPU "
708 "time used by the virtual machine (VMWARE_CPU_USED) to "
709 "estimate the effective virtual machine xCPU speed. "
710 "cpuUsedMS is a subset of this value.",
716 num_events++;
717
719 "MEM_ACTIVE" );
721 "Retrieves the amount of memory the virtual machine is "
722 "actively using in MB - Its estimated working set size.",
728 num_events++;
729
731 "MEM_BALLOONED" );
733 "Retrieves the amount of memory that has been reclaimed "
734 "from this virtual machine by the vSphere memory balloon "
735 "driver (also referred to as the 'vmemctl' driver) in MB.",
741 num_events++;
742
744 "MEM_LIMIT" );
746 "Retrieves the upper limit of memory that is available "
747 "to the virtual machine in MB.",
753 num_events++;
754
756 "MEM_MAPPED" );
758 "Retrieves the amount of memory that is allocated to "
759 "the virtual machine in MB. Memory that is ballooned, "
760 "swapped, or has never been accessed is excluded.",
766 num_events++;
767
769 "MEM_OVERHEAD" );
771 "Retrieves the amount of 'overhead' memory associated "
772 "with this virtual machine that is currently consumed "
773 "on the host system in MB. Overhead memory is additional "
774 "memory that is reserved for data structures required by "
775 "the virtualization layer.",
781 num_events++;
782
784 "MEM_RESERVATION" );
786 "Retrieves the minimum amount of memory that is "
787 "reserved for the virtual machine in MB.",
793 num_events++;
794
796 "MEM_SHARED" );
798 "Retrieves the amount of physical memory associated "
799 "with this virtual machine that is copy-on-write (COW) "
800 "shared on the host in MB.",
806 num_events++;
807
809 "MEM_SHARES" );
811 "Retrieves the number of memory shares allocated to "
812 "the virtual machine.",
814 strcpy( _vmware_native_table[num_events].units,"shares");
818 num_events++;
819
821 "MEM_SWAPPED" );
823 "Retrieves the amount of memory that has been reclaimed "
824 "from this virtual machine by transparently swapping "
825 "guest memory to disk in MB.",
831 num_events++;
832
834 "MEM_TARGET_SIZE" );
836 "Retrieves the size of the target memory allocation "
837 "for this virtual machine in MB.",
843 num_events++;
844
846 "MEM_USED" );
848 "Retrieves the estimated amount of physical host memory "
849 "currently consumed for this virtual machine's "
850 "physical memory.",
856 num_events++;
857
859 "HOST_CPU" );
861 "Retrieves the speed of the ESX system's physical "
862 "CPU in MHz.",
864 strcpy( _vmware_native_table[num_events].units,"MHz");
868 num_events++;
869 }
870
871#endif
872
873 /* For VMWare Pseudo Performance Counters */
874 if ( getenv( "PAPI_VMWARE_PSEUDOPERFORMANCE" ) ) {
875
876 use_pseudo=1;
877
879 "HOST_TSC" );
881 "Physical host TSC",
883 strcpy( _vmware_native_table[num_events].units,"cycles");
887 num_events++;
888
890 "ELAPSED_TIME" );
892 "Elapsed real time in ns.",
898 num_events++;
899
901 "ELAPSED_APPARENT" );
903 "Elapsed apparent time in ns.",
909 num_events++;
910 }
911
912 if (num_events==0) {
914 "VMware SDK not installed, and PAPI_VMWARE_PSEUDOPERFORMANCE not set",
917 goto fn_fail;
918 }
919
921
922 fn_exit:
923 _papi_hwd[cidx]->cmp_info.disabled = retval;
924 return retval;
925 fn_fail:
926 goto fn_exit;
927}
volatile int result
struct papi_vectors * _papi_hwd[]
#define PAPI_MAX_STR_LEN
Definition: f90papi.h:77
#define PAPI_ENOMEM
Definition: f90papi.h:16
#define PAPI_HUGE_STR_LEN
Definition: f90papi.h:120
static int cidx
char units[MAX_EVENTS][BUFSIZ]
Definition: powercap_plot.c:15
const char * name
Definition: rocs.c:225
char disabled_reason[PAPI_HUGE_STR_LEN]
Definition: papi.h:634
Definition: vmware.c:80
int which_counter
Definition: vmware.c:84
char description[PAPI_HUGE_STR_LEN]
Definition: vmware.c:82
int report_difference
Definition: vmware.c:85
PAPI_component_info_t cmp_info
Definition: papi_vector.h:20
static int LoadFunctions(void)
Definition: vmware.c:203
static int num_events
Definition: vmware.c:290
static struct _vmware_native_event_entry * _vmware_native_table
Definition: vmware.c:288
papi_vector_t _vmware_vector
Definition: vmware.c:67
int retval
Definition: zero_fork.c:53
Here is the call graph for this function:

◆ _vmware_init_control_state()

int _vmware_init_control_state ( hwd_control_state_t ctl)

Setup the counter control structure

Definition at line 931 of file vmware.c.

932{
933 (void) ctl;
934
935 return PAPI_OK;
936}

◆ _vmware_init_thread()

int _vmware_init_thread ( hwd_context_t ctx)

This is called whenever a thread is initialized

Definition at line 528 of file vmware.c.

529{
530 (void) ctx;
531
532
533#ifdef VMGUESTLIB
534
535 struct _vmware_context *context;
536 VMGuestLibError glError;
537
538 context=(struct _vmware_context *)ctx;
539
540 if (use_guestlib) {
541 glError = GuestLib_OpenHandle(&(context->glHandle));
542 if (glError != VMGUESTLIB_ERROR_SUCCESS) {
543 fprintf(stderr,"OpenHandle failed: %s\n",
544 GuestLib_GetErrorText(glError));
545 return PAPI_ECMP;
546 }
547 }
548
549#endif
550
551 return PAPI_OK;
552}

◆ _vmware_ntv_code_to_descr()

int _vmware_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 1014 of file vmware.c.

1015{
1016 int index = EventCode;
1017
1018 if ( index >= 0 && index < num_events ) {
1019 strncpy( name, _vmware_native_table[index].description, len );
1020 }
1021 return PAPI_OK;
1022}

◆ _vmware_ntv_code_to_info()

int _vmware_ntv_code_to_info ( unsigned int  EventCode,
PAPI_event_info_t info 
)

Definition at line 972 of file vmware.c.

973{
974
975 int index = EventCode;
976
977 if ( ( index < 0) || (index >= num_events )) return PAPI_ENOEVNT;
978
979 strncpy( info->symbol, _vmware_native_table[index].name,
980 sizeof(info->symbol));
981
982 strncpy( info->long_descr, _vmware_native_table[index].description,
983 sizeof(info->symbol));
984
985 strncpy( info->units, _vmware_native_table[index].units,
986 sizeof(info->units));
987
988 return PAPI_OK;
989}
#define PAPI_ENOEVNT
Definition: f90papi.h:139
char units[PAPI_MIN_STR_LEN]
Definition: papi.h:969
char symbol[PAPI_HUGE_STR_LEN]
Definition: papi.h:960
char long_descr[PAPI_HUGE_STR_LEN]
Definition: papi.h:963
char units[PAPI_MIN_STR_LEN]
Definition: vmware.c:83
char name[PAPI_MAX_STR_LEN]
Definition: vmware.c:81

◆ _vmware_ntv_code_to_name()

int _vmware_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 998 of file vmware.c.

999{
1000 int index = EventCode;
1001
1002 if ( index >= 0 && index < num_events ) {
1003 strncpy( name, _vmware_native_table[index].name, len );
1004 }
1005 return PAPI_OK;
1006}

◆ _vmware_ntv_enum_events()

int _vmware_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 943 of file vmware.c.

944{
945
946 switch ( modifier ) {
947 /* return EventCode of first event */
948 case PAPI_ENUM_FIRST:
949 if (num_events==0) return PAPI_ENOEVNT;
950 *EventCode = 0;
951 return PAPI_OK;
952 break;
953 /* return EventCode of passed-in Event */
954 case PAPI_ENUM_EVENTS:{
955 int index = *EventCode;
956
957 if ( index < num_events - 1 ) {
958 *EventCode = *EventCode + 1;
959 return PAPI_OK;
960 } else {
961 return PAPI_ENOEVNT;
962 }
963 break;
964 }
965 default:
966 return PAPI_EINVAL;
967 }
968 return PAPI_EINVAL;
969}
#define PAPI_ENUM_EVENTS
Definition: f90papi.h:224
#define PAPI_ENUM_FIRST
Definition: f90papi.h:85
#define PAPI_EINVAL
Definition: f90papi.h:115

◆ _vmware_read()

int _vmware_read ( hwd_context_t ctx,
hwd_control_state_t ctl,
long_long **  events,
int  flags 
)

Triggered by PAPI_read()

Definition at line 1080 of file vmware.c.

1083{
1084
1085 struct _vmware_context *context;
1086 struct _vmware_control_state *control;
1087
1088 (void) flags;
1089 int i;
1090
1091 context=(struct _vmware_context *)ctx;
1092 control=(struct _vmware_control_state *)ctl;
1093
1094 _vmware_hardware_read( context, 0 );
1095
1096 for (i=0; i<control->num_events; i++) {
1097
1100 report_difference) {
1101 control->value[i]=context->values[control->which_counter[i]]-
1102 context->start_values[control->which_counter[i]];
1103 } else {
1104 control->value[i]=context->values[control->which_counter[i]];
1105 }
1106 // printf("%d %d %lld-%lld=%lld\n",i,control->which_counter[i],
1107 // context->values[control->which_counter[i]],
1108 // context->start_values[control->which_counter[i]],
1109 // control->value[i]);
1110
1111 }
1112
1113 *events = control->value;
1114
1115 return PAPI_OK;
1116}
char events[MAX_EVENTS][BUFSIZ]
int which_counter[VMWARE_MAX_COUNTERS]
Definition: vmware.c:166
long long value[VMWARE_MAX_COUNTERS]
Definition: vmware.c:165
static long long _vmware_hardware_read(struct _vmware_context *context, int starting)
Definition: vmware.c:302
Here is the call graph for this function:

◆ _vmware_reset()

int _vmware_reset ( hwd_context_t ctx,
hwd_control_state_t ctl 
)

Triggered by PAPI_reset

Definition at line 1135 of file vmware.c.

1136{
1137 (void) ctx;
1138 (void) ctl;
1139
1140 return PAPI_OK;
1141}

◆ _vmware_set_domain()

int _vmware_set_domain ( hwd_control_state_t ctl,
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 1212 of file vmware.c.

1213{
1214 (void) ctl;
1215
1216 int found = 0;
1217 SUBDBG( "_vmware_set_domain..." );
1218 if ( PAPI_DOM_USER & domain ) {
1219 SUBDBG( " PAPI_DOM_USER " );
1220 found = 1;
1221 }
1222 if ( PAPI_DOM_KERNEL & domain ) {
1223 SUBDBG( " PAPI_DOM_KERNEL " );
1224 found = 1;
1225 }
1226 if ( PAPI_DOM_OTHER & domain ) {
1227 SUBDBG( " PAPI_DOM_OTHER " );
1228 found = 1;
1229 }
1230 if ( PAPI_DOM_ALL & domain ) {
1231 SUBDBG( " PAPI_DOM_ALL " );
1232 found = 1;
1233 }
1234 if ( !found ) {
1235 return ( PAPI_EINVAL );
1236 }
1237 return PAPI_OK;
1238}
#define PAPI_DOM_USER
Definition: f90papi.h:174
#define PAPI_DOM_OTHER
Definition: f90papi.h:21
#define PAPI_DOM_KERNEL
Definition: f90papi.h:254
#define PAPI_DOM_ALL
Definition: f90papi.h:261

◆ _vmware_shutdown_component()

int _vmware_shutdown_component ( void  )

Triggered by PAPI_shutdown()

Definition at line 1170 of file vmware.c.

1171{
1172
1173#ifdef VMGUESTLIB
1174 if (dlclose(dlHandle)) {
1175 fprintf(stderr, "dlclose failed\n");
1176 return EXIT_FAILURE;
1177 }
1178#endif
1179
1180 return PAPI_OK;
1181}

◆ _vmware_shutdown_thread()

int _vmware_shutdown_thread ( hwd_context_t ctx)

Shutting down a context

Definition at line 1145 of file vmware.c.

1146{
1147 (void) ctx;
1148
1149#ifdef VMGUESTLIB
1150 VMGuestLibError glError;
1151 struct _vmware_context *context;
1152
1153 context=(struct _vmware_context *)ctx;
1154
1155 if (use_guestlib) {
1156 glError = GuestLib_CloseHandle(context->glHandle);
1157 if (glError != VMGUESTLIB_ERROR_SUCCESS) {
1158 fprintf(stderr, "Failed to CloseHandle: %s\n",
1159 GuestLib_GetErrorText(glError));
1160 return PAPI_ECMP;
1161 }
1162 }
1163#endif
1164
1165 return PAPI_OK;
1166}

◆ _vmware_start()

int _vmware_start ( hwd_context_t ctx,
hwd_control_state_t ctl 
)

Triggered by PAPI_start()

Definition at line 1051 of file vmware.c.

1052{
1053 struct _vmware_context *context;
1054 (void) ctl;
1055
1056 context=(struct _vmware_context *)ctx;
1057
1058 _vmware_hardware_read( context, 1 );
1059
1060 return PAPI_OK;
1061}
Here is the call graph for this function:

◆ _vmware_stop()

int _vmware_stop ( hwd_context_t ctx,
hwd_control_state_t ctl 
)

Triggered by PAPI_stop()

Definition at line 1065 of file vmware.c.

1066{
1067
1068 struct _vmware_context *context;
1069 (void) ctl;
1070
1071 context=(struct _vmware_context *)ctx;
1072
1073 _vmware_hardware_read( context, 0 );
1074
1075 return PAPI_OK;
1076}
Here is the call graph for this function:

◆ _vmware_update_control_state()

int _vmware_update_control_state ( hwd_control_state_t ctl,
NativeInfo_t native,
int  count,
hwd_context_t ctx 
)

Triggered by eventset operations like add or remove

Definition at line 1026 of file vmware.c.

1030{
1031 (void) ctx;
1032
1033 struct _vmware_control_state *control;
1034
1035 int i, index;
1036
1037 control=(struct _vmware_control_state *)ctl;
1038
1039 for ( i = 0; i < count; i++ ) {
1040 index = native[i].ni_event;
1042 native[i].ni_position = i;
1043 }
1044 control->num_events=count;
1045
1046 return PAPI_OK;
1047}
static long count
static int native

◆ _vmware_write()

int _vmware_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 1121 of file vmware.c.

1122{
1123 (void) ctx;
1124 (void) ctrl;
1125 (void) events;
1126 SUBDBG( "_vmware_write... %p %p", ctx, ctrl );
1127 /* FIXME... this should actually carry out the write, though */
1128 /* this is non-trivial as which counter being written has to be */
1129 /* determined somehow. */
1130 return PAPI_OK;
1131}

◆ LoadFunctions()

static int LoadFunctions ( void  )
static

Definition at line 203 of file vmware.c.

204{
205
206#ifdef VMGUESTLIB
207 /*
208 * First, try to load the shared library.
209 */
210
211 /* Attempt to guess if we were statically linked to libc, if so bail */
212 if ( _dl_non_dynamic_init != NULL ) {
213 strncpy(_vmware_vector.cmp_info.disabled_reason, "The VMware component does not support statically linking of libc.", PAPI_MAX_STR_LEN);
214 return PAPI_ENOSUPP;
215 }
216
217 char const *dlErrStr;
218 char filename[BUFSIZ];
219
220 sprintf(filename,"%s","libvmGuestLib.so");
221 dlHandle = dlopen(filename, RTLD_NOW);
222 if (!dlHandle) {
223 dlErrStr = dlerror();
224 fprintf(stderr, "dlopen of %s failed: \'%s\'\n", filename,
225 dlErrStr);
226
227 sprintf(filename,"%s/lib/lib64/libvmGuestLib.so",VMWARE_INCDIR);
228 dlHandle = dlopen(filename, RTLD_NOW);
229 if (!dlHandle) {
230 dlErrStr = dlerror();
231 fprintf(stderr, "dlopen of %s failed: \'%s\'\n", filename,
232 dlErrStr);
233
234 sprintf(filename,"%s/lib/lib32/libvmGuestLib.so",VMWARE_INCDIR);
235 dlHandle = dlopen(filename, RTLD_NOW);
236 if (!dlHandle) {
237 dlErrStr = dlerror();
238 fprintf(stderr, "dlopen of %s failed: \'%s\'\n", filename,
239 dlErrStr);
240 return PAPI_ECMP;
241 }
242 }
243 }
244
245 /* Load all the individual library functions. */
246 LOAD_ONE_FUNC(GuestLib_GetErrorText);
247 LOAD_ONE_FUNC(GuestLib_OpenHandle);
248 LOAD_ONE_FUNC(GuestLib_CloseHandle);
249 LOAD_ONE_FUNC(GuestLib_UpdateInfo);
250 LOAD_ONE_FUNC(GuestLib_GetSessionId);
251 LOAD_ONE_FUNC(GuestLib_GetCpuReservationMHz);
252 LOAD_ONE_FUNC(GuestLib_GetCpuLimitMHz);
253 LOAD_ONE_FUNC(GuestLib_GetCpuShares);
254 LOAD_ONE_FUNC(GuestLib_GetCpuUsedMs);
255 LOAD_ONE_FUNC(GuestLib_GetHostProcessorSpeed);
256 LOAD_ONE_FUNC(GuestLib_GetMemReservationMB);
257 LOAD_ONE_FUNC(GuestLib_GetMemLimitMB);
258 LOAD_ONE_FUNC(GuestLib_GetMemShares);
259 LOAD_ONE_FUNC(GuestLib_GetMemMappedMB);
260 LOAD_ONE_FUNC(GuestLib_GetMemActiveMB);
261 LOAD_ONE_FUNC(GuestLib_GetMemOverheadMB);
262 LOAD_ONE_FUNC(GuestLib_GetMemBalloonedMB);
263 LOAD_ONE_FUNC(GuestLib_GetMemSwappedMB);
264 LOAD_ONE_FUNC(GuestLib_GetMemSharedMB);
265 LOAD_ONE_FUNC(GuestLib_GetMemSharedSavedMB);
266 LOAD_ONE_FUNC(GuestLib_GetMemUsedMB);
267 LOAD_ONE_FUNC(GuestLib_GetElapsedMs);
268 LOAD_ONE_FUNC(GuestLib_GetResourcePoolPath);
269 LOAD_ONE_FUNC(GuestLib_GetCpuStolenMs);
270 LOAD_ONE_FUNC(GuestLib_GetMemTargetSizeMB);
271 LOAD_ONE_FUNC(GuestLib_GetHostNumCpuCores);
272 LOAD_ONE_FUNC(GuestLib_GetHostCpuUsedMs);
273 LOAD_ONE_FUNC(GuestLib_GetHostMemSwappedMB);
274 LOAD_ONE_FUNC(GuestLib_GetHostMemSharedMB);
275 LOAD_ONE_FUNC(GuestLib_GetHostMemUsedMB);
276 LOAD_ONE_FUNC(GuestLib_GetHostMemPhysMB);
277 LOAD_ONE_FUNC(GuestLib_GetHostMemPhysFreeMB);
278 LOAD_ONE_FUNC(GuestLib_GetHostMemKernOvhdMB);
279 LOAD_ONE_FUNC(GuestLib_GetHostMemMappedMB);
280 LOAD_ONE_FUNC(GuestLib_GetHostMemUnmappedMB);
281#endif
282 return PAPI_OK;
283}
#define PAPI_ENOSUPP
Definition: f90papi.h:244
void(* _dl_non_dynamic_init)(void)
Definition: vmware.c:70
Here is the caller graph for this function:

◆ rdpmc()

uint64_t rdpmc ( int  c)
inline

Definition at line 93 of file vmware.c.

94{
95 uint32_t low, high;
96 __asm__ __volatile__("rdpmc" : "=a" (low), "=d" (high) : "c" (c));
97 return (uint64_t)high << 32 | (uint64_t)low;
98}
static double c[MATRIX_SIZE][MATRIX_SIZE]
Definition: libmsr_basic.c:40
Here is the caller graph for this function:

Variable Documentation

◆ _dl_non_dynamic_init

void(* _dl_non_dynamic_init) (void) ( void  )

Structure that stores private information for each event

< Signifies which counter slot is being used

< Indexed from 1 as 0 has a special meaning

Definition at line 70 of file vmware.c.

73 {
74 unsigned int selector;
77};

◆ _vmware_native_table

struct _vmware_native_event_entry* _vmware_native_table
static

This table contains the native events

Definition at line 288 of file vmware.c.

◆ _vmware_vector

papi_vector_t _vmware_vector

Vector that points to entry points for our component

Definition at line 67 of file vmware.c.

◆ num_events

int num_events = 0
static

number of events in the table

Definition at line 290 of file vmware.c.

◆ use_guestlib

int use_guestlib =0
static

Definition at line 292 of file vmware.c.

◆ use_pseudo

int use_pseudo =0
static

Definition at line 291 of file vmware.c.