blob: 7e818d64bb4d7fee0e07936349dd8659a5de85cd [file] [log] [blame]
Thomas Gleixner20c8ccb2019-06-04 10:11:32 +02001// SPDX-License-Identifier: GPL-2.0-only
Luiz Capitulino235539b2016-09-07 14:47:23 -04002/*
3 * Kernel-based Virtual Machine driver for Linux
4 *
5 * Copyright 2016 Red Hat, Inc. and/or its affiliates.
Luiz Capitulino235539b2016-09-07 14:47:23 -04006 */
7#include <linux/kvm_host.h>
Luiz Capitulino4f5758f2016-09-16 10:27:36 -04008#include <linux/debugfs.h>
Wanpeng Li16ba3ab2019-05-20 16:18:07 +08009#include "lapic.h"
Luiz Capitulino235539b2016-09-07 14:47:23 -040010
Wanpeng Li16ba3ab2019-05-20 16:18:07 +080011static int vcpu_get_timer_advance_ns(void *data, u64 *val)
12{
13 struct kvm_vcpu *vcpu = (struct kvm_vcpu *) data;
14 *val = vcpu->arch.apic->lapic_timer.timer_advance_ns;
15 return 0;
16}
17
18DEFINE_SIMPLE_ATTRIBUTE(vcpu_timer_advance_ns_fops, vcpu_get_timer_advance_ns, NULL, "%llu\n");
19
Luiz Capitulino4f5758f2016-09-16 10:27:36 -040020static int vcpu_get_tsc_offset(void *data, u64 *val)
21{
22 struct kvm_vcpu *vcpu = (struct kvm_vcpu *) data;
23 *val = vcpu->arch.tsc_offset;
24 return 0;
25}
26
27DEFINE_SIMPLE_ATTRIBUTE(vcpu_tsc_offset_fops, vcpu_get_tsc_offset, NULL, "%lld\n");
28
29static int vcpu_get_tsc_scaling_ratio(void *data, u64 *val)
30{
31 struct kvm_vcpu *vcpu = (struct kvm_vcpu *) data;
32 *val = vcpu->arch.tsc_scaling_ratio;
33 return 0;
34}
35
36DEFINE_SIMPLE_ATTRIBUTE(vcpu_tsc_scaling_fops, vcpu_get_tsc_scaling_ratio, NULL, "%llu\n");
37
38static int vcpu_get_tsc_scaling_frac_bits(void *data, u64 *val)
39{
40 *val = kvm_tsc_scaling_ratio_frac_bits;
41 return 0;
42}
43
44DEFINE_SIMPLE_ATTRIBUTE(vcpu_tsc_scaling_frac_fops, vcpu_get_tsc_scaling_frac_bits, NULL, "%llu\n");
45
Paolo Bonzinid56f5132020-06-04 15:16:52 +020046void kvm_arch_create_vcpu_debugfs(struct kvm_vcpu *vcpu, struct dentry *debugfs_dentry)
Luiz Capitulino235539b2016-09-07 14:47:23 -040047{
Paolo Bonzinid56f5132020-06-04 15:16:52 +020048 debugfs_create_file("tsc-offset", 0444, debugfs_dentry, vcpu,
Greg KH3e7093d2019-07-31 20:56:20 +020049 &vcpu_tsc_offset_fops);
Luiz Capitulino4f5758f2016-09-16 10:27:36 -040050
Greg KH3e7093d2019-07-31 20:56:20 +020051 if (lapic_in_kernel(vcpu))
52 debugfs_create_file("lapic_timer_advance_ns", 0444,
Paolo Bonzinid56f5132020-06-04 15:16:52 +020053 debugfs_dentry, vcpu,
Greg KH3e7093d2019-07-31 20:56:20 +020054 &vcpu_timer_advance_ns_fops);
Wanpeng Li16ba3ab2019-05-20 16:18:07 +080055
Luiz Capitulino4f5758f2016-09-16 10:27:36 -040056 if (kvm_has_tsc_control) {
Greg KH3e7093d2019-07-31 20:56:20 +020057 debugfs_create_file("tsc-scaling-ratio", 0444,
Paolo Bonzinid56f5132020-06-04 15:16:52 +020058 debugfs_dentry, vcpu,
Greg KH3e7093d2019-07-31 20:56:20 +020059 &vcpu_tsc_scaling_fops);
60 debugfs_create_file("tsc-scaling-ratio-frac-bits", 0444,
Paolo Bonzinid56f5132020-06-04 15:16:52 +020061 debugfs_dentry, vcpu,
Greg KH3e7093d2019-07-31 20:56:20 +020062 &vcpu_tsc_scaling_frac_fops);
Luiz Capitulino4f5758f2016-09-16 10:27:36 -040063 }
Luiz Capitulino235539b2016-09-07 14:47:23 -040064}