]>
Commit | Line | Data |
---|---|---|
20c8ccb1 | 1 | // SPDX-License-Identifier: GPL-2.0-only |
235539b4 LC |
2 | /* |
3 | * Kernel-based Virtual Machine driver for Linux | |
4 | * | |
5 | * Copyright 2016 Red Hat, Inc. and/or its affiliates. | |
235539b4 LC |
6 | */ |
7 | #include <linux/kvm_host.h> | |
4f5758fc | 8 | #include <linux/debugfs.h> |
16ba3ab4 | 9 | #include "lapic.h" |
235539b4 LC |
10 | |
11 | bool kvm_arch_has_vcpu_debugfs(void) | |
12 | { | |
4f5758fc | 13 | return true; |
235539b4 LC |
14 | } |
15 | ||
16ba3ab4 WL |
16 | static int vcpu_get_timer_advance_ns(void *data, u64 *val) |
17 | { | |
18 | struct kvm_vcpu *vcpu = (struct kvm_vcpu *) data; | |
19 | *val = vcpu->arch.apic->lapic_timer.timer_advance_ns; | |
20 | return 0; | |
21 | } | |
22 | ||
23 | DEFINE_SIMPLE_ATTRIBUTE(vcpu_timer_advance_ns_fops, vcpu_get_timer_advance_ns, NULL, "%llu\n"); | |
24 | ||
4f5758fc LC |
25 | static int vcpu_get_tsc_offset(void *data, u64 *val) |
26 | { | |
27 | struct kvm_vcpu *vcpu = (struct kvm_vcpu *) data; | |
28 | *val = vcpu->arch.tsc_offset; | |
29 | return 0; | |
30 | } | |
31 | ||
32 | DEFINE_SIMPLE_ATTRIBUTE(vcpu_tsc_offset_fops, vcpu_get_tsc_offset, NULL, "%lld\n"); | |
33 | ||
34 | static int vcpu_get_tsc_scaling_ratio(void *data, u64 *val) | |
35 | { | |
36 | struct kvm_vcpu *vcpu = (struct kvm_vcpu *) data; | |
37 | *val = vcpu->arch.tsc_scaling_ratio; | |
38 | return 0; | |
39 | } | |
40 | ||
41 | DEFINE_SIMPLE_ATTRIBUTE(vcpu_tsc_scaling_fops, vcpu_get_tsc_scaling_ratio, NULL, "%llu\n"); | |
42 | ||
43 | static int vcpu_get_tsc_scaling_frac_bits(void *data, u64 *val) | |
44 | { | |
45 | *val = kvm_tsc_scaling_ratio_frac_bits; | |
46 | return 0; | |
47 | } | |
48 | ||
49 | DEFINE_SIMPLE_ATTRIBUTE(vcpu_tsc_scaling_frac_fops, vcpu_get_tsc_scaling_frac_bits, NULL, "%llu\n"); | |
50 | ||
235539b4 LC |
51 | int kvm_arch_create_vcpu_debugfs(struct kvm_vcpu *vcpu) |
52 | { | |
4f5758fc LC |
53 | struct dentry *ret; |
54 | ||
55 | ret = debugfs_create_file("tsc-offset", 0444, | |
56 | vcpu->debugfs_dentry, | |
57 | vcpu, &vcpu_tsc_offset_fops); | |
58 | if (!ret) | |
59 | return -ENOMEM; | |
60 | ||
16ba3ab4 WL |
61 | if (lapic_in_kernel(vcpu)) { |
62 | ret = debugfs_create_file("lapic_timer_advance_ns", 0444, | |
63 | vcpu->debugfs_dentry, | |
64 | vcpu, &vcpu_timer_advance_ns_fops); | |
65 | if (!ret) | |
66 | return -ENOMEM; | |
67 | } | |
68 | ||
4f5758fc LC |
69 | if (kvm_has_tsc_control) { |
70 | ret = debugfs_create_file("tsc-scaling-ratio", 0444, | |
71 | vcpu->debugfs_dentry, | |
72 | vcpu, &vcpu_tsc_scaling_fops); | |
73 | if (!ret) | |
74 | return -ENOMEM; | |
75 | ret = debugfs_create_file("tsc-scaling-ratio-frac-bits", 0444, | |
76 | vcpu->debugfs_dentry, | |
77 | vcpu, &vcpu_tsc_scaling_frac_fops); | |
78 | if (!ret) | |
79 | return -ENOMEM; | |
80 | ||
81 | } | |
82 | ||
235539b4 LC |
83 | return 0; |
84 | } |