blob: 7e818d64bb4d7fee0e07936349dd8659a5de85cd [file] [log] [blame]
David Brazdil0f672f62019-12-10 10:32:29 +00001// SPDX-License-Identifier: GPL-2.0-only
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00002/*
3 * Kernel-based Virtual Machine driver for Linux
4 *
5 * Copyright 2016 Red Hat, Inc. and/or its affiliates.
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00006 */
7#include <linux/kvm_host.h>
8#include <linux/debugfs.h>
David Brazdil0f672f62019-12-10 10:32:29 +00009#include "lapic.h"
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000010
David Brazdil0f672f62019-12-10 10:32:29 +000011static int vcpu_get_timer_advance_ns(void *data, u64 *val)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000012{
David Brazdil0f672f62019-12-10 10:32:29 +000013 struct kvm_vcpu *vcpu = (struct kvm_vcpu *) data;
14 *val = vcpu->arch.apic->lapic_timer.timer_advance_ns;
15 return 0;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000016}
17
David Brazdil0f672f62019-12-10 10:32:29 +000018DEFINE_SIMPLE_ATTRIBUTE(vcpu_timer_advance_ns_fops, vcpu_get_timer_advance_ns, NULL, "%llu\n");
19
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000020static 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
Olivier Deprez157378f2022-04-04 15:47:50 +020046void kvm_arch_create_vcpu_debugfs(struct kvm_vcpu *vcpu, struct dentry *debugfs_dentry)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000047{
Olivier Deprez157378f2022-04-04 15:47:50 +020048 debugfs_create_file("tsc-offset", 0444, debugfs_dentry, vcpu,
David Brazdil0f672f62019-12-10 10:32:29 +000049 &vcpu_tsc_offset_fops);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000050
David Brazdil0f672f62019-12-10 10:32:29 +000051 if (lapic_in_kernel(vcpu))
52 debugfs_create_file("lapic_timer_advance_ns", 0444,
Olivier Deprez157378f2022-04-04 15:47:50 +020053 debugfs_dentry, vcpu,
David Brazdil0f672f62019-12-10 10:32:29 +000054 &vcpu_timer_advance_ns_fops);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000055
56 if (kvm_has_tsc_control) {
David Brazdil0f672f62019-12-10 10:32:29 +000057 debugfs_create_file("tsc-scaling-ratio", 0444,
Olivier Deprez157378f2022-04-04 15:47:50 +020058 debugfs_dentry, vcpu,
David Brazdil0f672f62019-12-10 10:32:29 +000059 &vcpu_tsc_scaling_fops);
60 debugfs_create_file("tsc-scaling-ratio-frac-bits", 0444,
Olivier Deprez157378f2022-04-04 15:47:50 +020061 debugfs_dentry, vcpu,
David Brazdil0f672f62019-12-10 10:32:29 +000062 &vcpu_tsc_scaling_frac_fops);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000063 }
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000064}