Commit 744f4020 authored by chenjiajun's avatar chenjiajun Committed by liangtian
Browse files

kvm: debugfs: aarch64 export cpu time related items to debugfs

virt inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I919BF


CVE: NA

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

This patch export cpu time related items to vcpu_stat.
Contain:
	steal, st_max, utime, stime, gtime

The definitions of these items are:
steal: cpu time VCPU waits for PCPU while it is servicing another VCPU
st_max: max scheduling delay
utime: cpu time in userspace
stime: cpu time in sys
gtime: cpu time in guest

Through these items, user can get many cpu usage info of vcpu, such as:
CPU Usage of Guest =  gtime_delta / delta_cputime
CPU Usage of Hyp = (utime_delta - gtime_delta + stime_delta) / delta_cputime
CPU Usage of Steal = steal_delta / delta_cputime
Max Scheduling Delay = st_max

Signed-off-by: default avatarliangpeng <liangpeng10@huawei.com>
Signed-off-by: default avatarchenjiajun <chenjiajun8@huawei.com>
Signed-off-by: default avatarliangtian <liangtian13@huawei.com>
parent fe9b4f40
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -934,6 +934,11 @@ struct kvm_vcpu_stat {
	u64 smc_exit_stat;
	u64 sve_exit_stat;
	u64 debug_exit_stat;
	u64 steal;
	u64 st_max;
	u64 utime;
	u64 stime;
	u64 gtime;
};

unsigned long kvm_arm_num_regs(struct kvm_vcpu *vcpu);
+31 −0
Original line number Diff line number Diff line
@@ -449,6 +449,22 @@ void kvm_arch_vcpu_unblocking(struct kvm_vcpu *vcpu)

}

#ifdef CONFIG_ARCH_VCPU_STAT
void kvm_arch_vcpu_stat_reset(struct kvm_vcpu_stat *vcpu_stat)
{
	vcpu_stat->st_max = 0;
}

static void update_steal_time(struct kvm_vcpu *vcpu)
{
	u64 delta;

	delta = current->sched_info.run_delay - vcpu->stat.steal;
	vcpu->stat.steal = current->sched_info.run_delay;
	vcpu->stat.st_max = max(vcpu->stat.st_max, delta);
}
#endif

void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
{
	struct kvm_s2_mmu *mmu;
@@ -487,6 +503,9 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
	else
		vcpu_set_wfx_traps(vcpu);

#ifdef CONFIG_ARCH_VCPU_STAT
	update_steal_time(vcpu);
#endif
	if (vcpu_has_ptrauth(vcpu))
		vcpu_ptrauth_disable(vcpu);
	kvm_arch_vcpu_load_debug_state_flags(vcpu);
@@ -863,6 +882,15 @@ static bool vcpu_mode_is_bad_32bit(struct kvm_vcpu *vcpu)
	return !kvm_supports_32bit_el0();
}

#ifdef CONFIG_ARCH_VCPU_STAT
static void update_vcpu_stat_time(struct kvm_vcpu_stat *vcpu_stat)
{
	vcpu_stat->utime = current->utime;
	vcpu_stat->stime = current->stime;
	vcpu_stat->gtime = current->gtime;
}
#endif

/**
 * kvm_vcpu_exit_request - returns true if the VCPU should *not* enter the guest
 * @vcpu:	The VCPU pointer
@@ -1107,6 +1135,9 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
		}

		ret = handle_exit(vcpu, ret);
#ifdef CONFIG_ARCH_VCPU_STAT
		update_vcpu_stat_time(&vcpu->stat);
#endif
	}

	/* Tell userspace about in-kernel device output levels */
+5 −0
Original line number Diff line number Diff line
@@ -55,6 +55,11 @@ struct dfx_kvm_stats_debugfs_item dfx_debugfs_entries[] = {
	DFX_STAT("smc_exit_stat", smc_exit_stat),
	DFX_STAT("sve_exit_stat", sve_exit_stat),
	DFX_STAT("debug_exit_stat", debug_exit_stat),
	DFX_STAT("steal", steal),
	DFX_STAT("st_max", st_max),
	DFX_STAT("utime", utime),
	DFX_STAT("stime", stime),
	DFX_STAT("gtime", gtime),
	{ NULL }
};
#endif
+4 −0
Original line number Diff line number Diff line
@@ -2321,6 +2321,10 @@ static inline int kvm_arch_vcpu_run_pid_change(struct kvm_vcpu *vcpu)
}
#endif /* CONFIG_HAVE_KVM_VCPU_RUN_PID_CHANGE */

#ifdef CONFIG_ARCH_VCPU_STAT
void kvm_arch_vcpu_stat_reset(struct kvm_vcpu_stat *vcpu_stat);
#endif

typedef int (*kvm_vm_thread_fn_t)(struct kvm *kvm, uintptr_t data);

int kvm_vm_create_worker_thread(struct kvm *kvm, kvm_vm_thread_fn_t thread_fn,
+1 −0
Original line number Diff line number Diff line
@@ -5914,6 +5914,7 @@ static int __dfx_vcpu_stats_get(struct seq_file *p, void *v)
				break;
			memcpy(vcpu_stats + index, &vcpu->stat,
			       sizeof(struct kvm_vcpu_stat));
			kvm_arch_vcpu_stat_reset(&vcpu->stat);
			++index;
		}
	}