David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Kernel-based Virtual Machine driver for Linux |
| 4 | * |
| 5 | * Copyright 2016 Red Hat, Inc. and/or its affiliates. |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 6 | */ |
| 7 | #include <linux/kvm_host.h> |
| 8 | #include <linux/debugfs.h> |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 9 | #include "lapic.h" |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 10 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 11 | static int vcpu_get_timer_advance_ns(void *data, u64 *val) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 12 | { |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 13 | struct kvm_vcpu *vcpu = (struct kvm_vcpu *) data; |
| 14 | *val = vcpu->arch.apic->lapic_timer.timer_advance_ns; |
| 15 | return 0; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 16 | } |
| 17 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 18 | DEFINE_SIMPLE_ATTRIBUTE(vcpu_timer_advance_ns_fops, vcpu_get_timer_advance_ns, NULL, "%llu\n"); |
| 19 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [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 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 46 | void kvm_arch_create_vcpu_debugfs(struct kvm_vcpu *vcpu, struct dentry *debugfs_dentry) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 47 | { |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 48 | debugfs_create_file("tsc-offset", 0444, debugfs_dentry, vcpu, |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 49 | &vcpu_tsc_offset_fops); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 50 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 51 | if (lapic_in_kernel(vcpu)) |
| 52 | debugfs_create_file("lapic_timer_advance_ns", 0444, |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 53 | debugfs_dentry, vcpu, |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 54 | &vcpu_timer_advance_ns_fops); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 55 | |
| 56 | if (kvm_has_tsc_control) { |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 57 | debugfs_create_file("tsc-scaling-ratio", 0444, |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 58 | debugfs_dentry, vcpu, |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 59 | &vcpu_tsc_scaling_fops); |
| 60 | debugfs_create_file("tsc-scaling-ratio-frac-bits", 0444, |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 61 | debugfs_dentry, vcpu, |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 62 | &vcpu_tsc_scaling_frac_fops); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 63 | } |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 64 | } |