Thomas Gleixner | 20c8ccb | 2019-06-04 10:11:32 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Luiz Capitulino | 235539b | 2016-09-07 14:47:23 -0400 | [diff] [blame] | 2 | /* |
| 3 | * Kernel-based Virtual Machine driver for Linux |
| 4 | * |
| 5 | * Copyright 2016 Red Hat, Inc. and/or its affiliates. |
Luiz Capitulino | 235539b | 2016-09-07 14:47:23 -0400 | [diff] [blame] | 6 | */ |
| 7 | #include <linux/kvm_host.h> |
Luiz Capitulino | 4f5758f | 2016-09-16 10:27:36 -0400 | [diff] [blame] | 8 | #include <linux/debugfs.h> |
Wanpeng Li | 16ba3ab | 2019-05-20 16:18:07 +0800 | [diff] [blame] | 9 | #include "lapic.h" |
Luiz Capitulino | 235539b | 2016-09-07 14:47:23 -0400 | [diff] [blame] | 10 | |
Wanpeng Li | 16ba3ab | 2019-05-20 16:18:07 +0800 | [diff] [blame] | 11 | static 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 | |
| 18 | DEFINE_SIMPLE_ATTRIBUTE(vcpu_timer_advance_ns_fops, vcpu_get_timer_advance_ns, NULL, "%llu\n"); |
| 19 | |
Luiz Capitulino | 4f5758f | 2016-09-16 10:27:36 -0400 | [diff] [blame] | 20 | static 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 | |
| 27 | DEFINE_SIMPLE_ATTRIBUTE(vcpu_tsc_offset_fops, vcpu_get_tsc_offset, NULL, "%lld\n"); |
| 28 | |
| 29 | static 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 | |
| 36 | DEFINE_SIMPLE_ATTRIBUTE(vcpu_tsc_scaling_fops, vcpu_get_tsc_scaling_ratio, NULL, "%llu\n"); |
| 37 | |
| 38 | static 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 | |
| 44 | DEFINE_SIMPLE_ATTRIBUTE(vcpu_tsc_scaling_frac_fops, vcpu_get_tsc_scaling_frac_bits, NULL, "%llu\n"); |
| 45 | |
Paolo Bonzini | d56f513 | 2020-06-04 15:16:52 +0200 | [diff] [blame] | 46 | void kvm_arch_create_vcpu_debugfs(struct kvm_vcpu *vcpu, struct dentry *debugfs_dentry) |
Luiz Capitulino | 235539b | 2016-09-07 14:47:23 -0400 | [diff] [blame] | 47 | { |
Paolo Bonzini | d56f513 | 2020-06-04 15:16:52 +0200 | [diff] [blame] | 48 | debugfs_create_file("tsc-offset", 0444, debugfs_dentry, vcpu, |
Greg KH | 3e7093d | 2019-07-31 20:56:20 +0200 | [diff] [blame] | 49 | &vcpu_tsc_offset_fops); |
Luiz Capitulino | 4f5758f | 2016-09-16 10:27:36 -0400 | [diff] [blame] | 50 | |
Greg KH | 3e7093d | 2019-07-31 20:56:20 +0200 | [diff] [blame] | 51 | if (lapic_in_kernel(vcpu)) |
| 52 | debugfs_create_file("lapic_timer_advance_ns", 0444, |
Paolo Bonzini | d56f513 | 2020-06-04 15:16:52 +0200 | [diff] [blame] | 53 | debugfs_dentry, vcpu, |
Greg KH | 3e7093d | 2019-07-31 20:56:20 +0200 | [diff] [blame] | 54 | &vcpu_timer_advance_ns_fops); |
Wanpeng Li | 16ba3ab | 2019-05-20 16:18:07 +0800 | [diff] [blame] | 55 | |
Luiz Capitulino | 4f5758f | 2016-09-16 10:27:36 -0400 | [diff] [blame] | 56 | if (kvm_has_tsc_control) { |
Greg KH | 3e7093d | 2019-07-31 20:56:20 +0200 | [diff] [blame] | 57 | debugfs_create_file("tsc-scaling-ratio", 0444, |
Paolo Bonzini | d56f513 | 2020-06-04 15:16:52 +0200 | [diff] [blame] | 58 | debugfs_dentry, vcpu, |
Greg KH | 3e7093d | 2019-07-31 20:56:20 +0200 | [diff] [blame] | 59 | &vcpu_tsc_scaling_fops); |
| 60 | debugfs_create_file("tsc-scaling-ratio-frac-bits", 0444, |
Paolo Bonzini | d56f513 | 2020-06-04 15:16:52 +0200 | [diff] [blame] | 61 | debugfs_dentry, vcpu, |
Greg KH | 3e7093d | 2019-07-31 20:56:20 +0200 | [diff] [blame] | 62 | &vcpu_tsc_scaling_frac_fops); |
Luiz Capitulino | 4f5758f | 2016-09-16 10:27:36 -0400 | [diff] [blame] | 63 | } |
Luiz Capitulino | 235539b | 2016-09-07 14:47:23 -0400 | [diff] [blame] | 64 | } |