Skip to content

Commit a7cbee1

Browse files
mchinthwenlingz
authored andcommitted
HV:Added support to get VM enter and exit information
profiling_vmenter_handler:Saves vm information profiling_vmexit_handler: Saves vm information and vm exit reason Tracked-On: #1409 Acked-by: Eddie Dong <eddie.dong@intel.com> Signed-off-by: Chinthapally, Manisha <manisha.chinthapally@intel.com>
1 parent fc8f9d7 commit a7cbee1

File tree

2 files changed

+80
-6
lines changed

2 files changed

+80
-6
lines changed

hypervisor/debug/profiling.c

Lines changed: 59 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -914,18 +914,71 @@ void profiling_ipi_handler(__unused void *data)
914914
*/
915915
void profiling_vmenter_handler(__unused struct vcpu *vcpu)
916916
{
917-
/* to be implemented */
917+
if (((get_cpu_var(profiling_info.sep_state).pmu_state == PMU_RUNNING) &&
918+
((sep_collection_switch &
919+
(1UL << (uint64_t)VM_SWITCH_TRACING)) > 0UL)) ||
920+
((get_cpu_var(profiling_info.soc_state) == SW_RUNNING) &&
921+
((socwatch_collection_switch &
922+
(1UL << (uint64_t)SOCWATCH_VM_SWITCH_TRACING)) > 0UL))) {
923+
924+
get_cpu_var(profiling_info.vm_info).vmenter_tsc = rdtsc();
925+
}
918926
}
919927

920928
/*
921929
* Save the VCPU info on vmexit
922930
*/
923-
void profiling_vmexit_handler(__unused struct vcpu *vcpu, __unused uint64_t exit_reason)
931+
void profiling_vmexit_handler(struct vcpu *vcpu, uint64_t exit_reason)
924932
{
925-
if (exit_reason == VMX_EXIT_REASON_EXTERNAL_INTERRUPT) {
926-
/* to be implemented */
927-
} else {
928-
/* to be implemented */
933+
per_cpu(profiling_info.sep_state, vcpu->pcpu_id).total_vmexit_count++;
934+
935+
if ((get_cpu_var(profiling_info.sep_state).pmu_state == PMU_RUNNING) ||
936+
(get_cpu_var(profiling_info.soc_state) == SW_RUNNING)) {
937+
938+
get_cpu_var(profiling_info.vm_info).vmexit_tsc = rdtsc();
939+
get_cpu_var(profiling_info.vm_info).vmexit_reason = exit_reason;
940+
if (exit_reason == VMX_EXIT_REASON_EXTERNAL_INTERRUPT) {
941+
get_cpu_var(profiling_info.vm_info).external_vector
942+
= (int32_t)(exec_vmread(VMX_EXIT_INT_INFO) & 0xFFUL);
943+
} else {
944+
get_cpu_var(profiling_info.vm_info).external_vector = -1;
945+
}
946+
get_cpu_var(profiling_info.vm_info).guest_rip
947+
= vcpu_get_rip(vcpu);
948+
949+
get_cpu_var(profiling_info.vm_info).guest_rflags
950+
= vcpu_get_rflags(vcpu);
951+
952+
get_cpu_var(profiling_info.vm_info).guest_cs
953+
= exec_vmread64(VMX_GUEST_CS_SEL);
954+
955+
get_cpu_var(profiling_info.vm_info).guest_vm_id = (int32_t)vcpu->vm->vm_id;
956+
957+
/* Generate vmswitch sample */
958+
if (((sep_collection_switch &
959+
(1UL << (uint64_t)VM_SWITCH_TRACING)) > 0UL) ||
960+
((socwatch_collection_switch &
961+
(1UL << (uint64_t)SOCWATCH_VM_SWITCH_TRACING)) > 0UL)) {
962+
get_cpu_var(profiling_info.vm_switch_trace).os_id
963+
= (int32_t)vcpu->vm->vm_id;
964+
get_cpu_var(profiling_info.vm_switch_trace).vm_enter_tsc
965+
= get_cpu_var(profiling_info.vm_info).vmenter_tsc;
966+
get_cpu_var(profiling_info.vm_switch_trace).vm_exit_tsc
967+
= get_cpu_var(profiling_info.vm_info).vmexit_tsc;
968+
get_cpu_var(profiling_info.vm_switch_trace).vm_exit_reason
969+
= exit_reason;
970+
971+
if ((sep_collection_switch &
972+
(1UL << (uint64_t)VM_SWITCH_TRACING)) > 0UL) {
973+
(void)profiling_generate_data(COLLECT_PROFILE_DATA,
974+
VM_SWITCH_TRACING);
975+
}
976+
if ((socwatch_collection_switch &
977+
(1UL << (uint64_t)SOCWATCH_VM_SWITCH_TRACING)) > 0UL) {
978+
(void)profiling_generate_data(COLLECT_POWER_DATA,
979+
SOCWATCH_VM_SWITCH_TRACING);
980+
}
981+
}
929982
}
930983
}
931984

hypervisor/include/debug/profiling_internal.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#define COLLECT_PROFILE_DATA 0
1919
#define COLLECT_POWER_DATA 1
2020

21+
#define SEP_BUF_ENTRY_SIZE 32U
2122
#define SOCWATCH_MSR_OP 100U
2223

2324
enum MSR_CMD_STATUS {
@@ -159,6 +160,16 @@ struct vmexit_msr {
159160
uint64_t msr_data;
160161
};
161162

163+
struct guest_vm_info {
164+
uint64_t vmenter_tsc;
165+
uint64_t vmexit_tsc;
166+
uint64_t vmexit_reason;
167+
uint64_t guest_rip;
168+
uint64_t guest_rflags;
169+
uint64_t guest_cs;
170+
int32_t guest_vm_id;
171+
int32_t external_vector;
172+
};
162173
struct sep_state {
163174
sep_pmu_state pmu_state;
164175

@@ -201,13 +212,23 @@ struct sep_state {
201212
uint64_t saved_debugctl_value;
202213
} __aligned(8);
203214

215+
216+
struct vm_switch_trace {
217+
uint64_t vm_enter_tsc;
218+
uint64_t vm_exit_tsc;
219+
uint64_t vm_exit_reason;
220+
int32_t os_id;
221+
}__aligned(SEP_BUF_ENTRY_SIZE);
222+
204223
/*
205224
* Wrapper containing SEP sampling/profiling related data structures
206225
*/
207226
struct profiling_info_wrapper {
208227
struct profiling_msr_ops_list *msr_node;
209228
struct sep_state sep_state;
229+
struct guest_vm_info vm_info;
210230
ipi_commands ipi_cmd;
231+
struct vm_switch_trace vm_switch_trace;
211232
socwatch_state soc_state;
212233
struct sw_msr_op_info sw_msr_op_info;
213234
} __aligned(8);

0 commit comments

Comments
 (0)