pmu.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. * Permission is hereby granted, free of charge, to any person obtaining a copy
  3. * of this software and associated documentation files (the "Software"), to
  4. * deal in the Software without restriction, including without limitation the
  5. * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  6. * sell copies of the Software, and to permit persons to whom the Software is
  7. * furnished to do so, subject to the following conditions:
  8. *
  9. * The above copyright notice and this permission notice shall be included in
  10. * all copies or substantial portions of the Software.
  11. *
  12. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  17. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  18. * DEALINGS IN THE SOFTWARE.
  19. *
  20. * Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved.
  21. */
  22. #ifndef __XEN_PUBLIC_PMU_H__
  23. #define __XEN_PUBLIC_PMU_H__
  24. #include "xen.h"
  25. #if defined(__i386__) || defined(__x86_64__)
  26. #include "arch-x86/pmu.h"
  27. #elif defined (__arm__) || defined (__aarch64__)
  28. #include "arch-arm.h"
  29. #else
  30. #error "Unsupported architecture"
  31. #endif
  32. #define XENPMU_VER_MAJ 0
  33. #define XENPMU_VER_MIN 1
  34. /*
  35. * ` enum neg_errnoval
  36. * ` HYPERVISOR_xenpmu_op(enum xenpmu_op cmd, struct xenpmu_params *args);
  37. *
  38. * @cmd == XENPMU_* (PMU operation)
  39. * @args == struct xenpmu_params
  40. */
  41. /* ` enum xenpmu_op { */
  42. #define XENPMU_mode_get 0 /* Also used for getting PMU version */
  43. #define XENPMU_mode_set 1
  44. #define XENPMU_feature_get 2
  45. #define XENPMU_feature_set 3
  46. #define XENPMU_init 4
  47. #define XENPMU_finish 5
  48. #define XENPMU_lvtpc_set 6
  49. #define XENPMU_flush 7 /* Write cached MSR values to HW */
  50. /* ` } */
  51. /* Parameters structure for HYPERVISOR_xenpmu_op call */
  52. struct xen_pmu_params {
  53. /* IN/OUT parameters */
  54. struct {
  55. uint32_t maj;
  56. uint32_t min;
  57. } version;
  58. uint64_t val;
  59. /* IN parameters */
  60. uint32_t vcpu;
  61. uint32_t pad;
  62. };
  63. typedef struct xen_pmu_params xen_pmu_params_t;
  64. DEFINE_XEN_GUEST_HANDLE(xen_pmu_params_t);
  65. /* PMU modes:
  66. * - XENPMU_MODE_OFF: No PMU virtualization
  67. * - XENPMU_MODE_SELF: Guests can profile themselves
  68. * - XENPMU_MODE_HV: Guests can profile themselves, dom0 profiles
  69. * itself and Xen
  70. * - XENPMU_MODE_ALL: Only dom0 has access to VPMU and it profiles
  71. * everyone: itself, the hypervisor and the guests.
  72. */
  73. #define XENPMU_MODE_OFF 0
  74. #define XENPMU_MODE_SELF (1<<0)
  75. #define XENPMU_MODE_HV (1<<1)
  76. #define XENPMU_MODE_ALL (1<<2)
  77. /*
  78. * PMU features:
  79. * - XENPMU_FEATURE_INTEL_BTS: Intel BTS support (ignored on AMD)
  80. * - XENPMU_FEATURE_IPC_ONLY: Restrict PMCs to the most minimum set possible.
  81. * Instructions, cycles, and ref cycles. Can be
  82. * used to calculate instructions-per-cycle (IPC)
  83. * (ignored on AMD).
  84. * - XENPMU_FEATURE_ARCH_ONLY: Restrict PMCs to the Intel Pre-Defined
  85. * Architectural Performance Events exposed by
  86. * cpuid and listed in the Intel developer's manual
  87. * (ignored on AMD).
  88. */
  89. #define XENPMU_FEATURE_INTEL_BTS (1<<0)
  90. #define XENPMU_FEATURE_IPC_ONLY (1<<1)
  91. #define XENPMU_FEATURE_ARCH_ONLY (1<<2)
  92. /*
  93. * Shared PMU data between hypervisor and PV(H) domains.
  94. *
  95. * The hypervisor fills out this structure during PMU interrupt and sends an
  96. * interrupt to appropriate VCPU.
  97. * Architecture-independent fields of xen_pmu_data are WO for the hypervisor
  98. * and RO for the guest but some fields in xen_pmu_arch can be writable
  99. * by both the hypervisor and the guest (see arch-$arch/pmu.h).
  100. */
  101. struct xen_pmu_data {
  102. /* Interrupted VCPU */
  103. uint32_t vcpu_id;
  104. /*
  105. * Physical processor on which the interrupt occurred. On non-privileged
  106. * guests set to vcpu_id;
  107. */
  108. uint32_t pcpu_id;
  109. /*
  110. * Domain that was interrupted. On non-privileged guests set to DOMID_SELF.
  111. * On privileged guests can be DOMID_SELF, DOMID_XEN, or, when in
  112. * XENPMU_MODE_ALL mode, domain ID of another domain.
  113. */
  114. domid_t domain_id;
  115. uint8_t pad[6];
  116. /* Architecture-specific information */
  117. struct xen_pmu_arch pmu;
  118. };
  119. #endif /* __XEN_PUBLIC_PMU_H__ */
  120. /*
  121. * Local variables:
  122. * mode: C
  123. * c-file-style: "BSD"
  124. * c-basic-offset: 4
  125. * tab-width: 4
  126. * indent-tabs-mode: nil
  127. * End:
  128. */