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