Commit 6dd8947d authored by Chen Wang's avatar Chen Wang Committed by guzitao
Browse files

sw64: perf: add perf kvm support for guest os

Sunway inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I5XTJN



--------------------------------

Signed-off-by: default avatarChen Wang <chenwang@wxiat.com>
Reviewed-by: default avatarHe Sheng <hesheng@wxiat.com>
Signed-off-by: default avatarGu Zitao <guzitao@wxiat.com>
parent 267e1de3
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -14,4 +14,16 @@
#ifdef CONFIG_KVM_MEMHOTPLUG
#define SW64_KVM_EXIT_MEMHOTPLUG	23
#endif

#define kvm_sw64_exception_type	\
	{0, "HOST_INTR" },	\
	{1, "IO" },		\
	{10, "HALT" },		\
	{12, "SHUTDOWN" },	\
	{13, "TIMER" },		\
	{14, "IPI" },		\
	{17, "RESTART" },	\
	{22, "FATAL_ERROR" },	\
	{23, "MEMHOTPLUG" }

#endif /* _ASM_SW64_KVM_ASM_H */
+3 −0
Original line number Diff line number Diff line
@@ -124,4 +124,7 @@ static inline void kvm_arch_vcpu_blocking(struct kvm_vcpu *vcpu) {}
static inline void kvm_arch_vcpu_unblocking(struct kvm_vcpu *vcpu) {}
static inline void kvm_arch_vcpu_block_finish(struct kvm_vcpu *vcpu) {}

int kvm_sw64_perf_init(void);
int kvm_sw64_perf_teardown(void);

#endif /* _ASM_SW64_KVM_HOST_H */
+8 −0
Original line number Diff line number Diff line
@@ -3,5 +3,13 @@
#define _ASM_SW64_PERF_EVENT_H

#include <asm/wrperfmon.h>
#include <asm/ptrace.h>

#ifdef CONFIG_PERF_EVENTS
struct pt_regs;
extern unsigned long perf_instruction_pointer(struct pt_regs *regs);
extern unsigned long perf_misc_flags(struct pt_regs *regs);
#define perf_misc_flags(regs)  perf_misc_flags(regs)
#endif

#endif /* _ASM_SW64_PERF_EVENT_H */
+32 −0
Original line number Diff line number Diff line
@@ -760,6 +760,38 @@ void perf_callchain_kernel(struct perf_callchain_entry_ctx *entry,
	walk_stackframe(NULL, regs, callchain_trace, entry);
}

/*
 * Gets the perf_instruction_pointer and perf_misc_flags for guest os.
 */
#undef is_in_guest

unsigned long perf_instruction_pointer(struct pt_regs *regs)
{
	if (perf_guest_cbs && perf_guest_cbs->is_in_guest())
		return perf_guest_cbs->get_guest_ip();

	return instruction_pointer(regs);
}

unsigned long perf_misc_flags(struct pt_regs *regs)
{
	int misc = 0;

	if (perf_guest_cbs && perf_guest_cbs->is_in_guest()) {
		if (perf_guest_cbs->is_user_mode())
			misc |= PERF_RECORD_MISC_GUEST_USER;
		else
			misc |= PERF_RECORD_MISC_GUEST_KERNEL;
	} else {
		if (user_mode(regs))
			misc |= PERF_RECORD_MISC_USER;
		else
			misc |= PERF_RECORD_MISC_KERNEL;
	}

	return misc;
}

/*
 * Init call to initialise performance events at kernel startup.
 */
+1 −1
Original line number Diff line number Diff line
@@ -8,6 +8,6 @@ KVM := ../../../virt/kvm
ccflags-y += -Ivirt/kvm -Iarch/sw_64/kvm

kvm-$(CONFIG_KVM_SW64_HOST) += $(KVM)/kvm_main.o $(KVM)/eventfd.o $(KVM)/irqchip.o $(KVM)/vfio.o
kvm-$(CONFIG_KVM_SW64_HOST) += kvm-sw64.o entry.o emulate.o mmio.o kvm_timer.o handle_exit.o
kvm-$(CONFIG_KVM_SW64_HOST) += kvm-sw64.o entry.o emulate.o mmio.o kvm_timer.o handle_exit.o perf.o

obj-$(CONFIG_KVM_SW64_HOST) += kvm.o
Loading