Linux Audio

Check our new training course

Loading...
v4.17
 
 1/*
 2 * Kernel-based Virtual Machine driver for Linux
 3 *
 4 * Copyright 2016 Red Hat, Inc. and/or its affiliates.
 5 *
 6 * This work is licensed under the terms of the GNU GPL, version 2.  See
 7 * the COPYING file in the top-level directory.
 8 *
 9 */
10#include <linux/kvm_host.h>
11#include <linux/debugfs.h>
 
12
13bool kvm_arch_has_vcpu_debugfs(void)
14{
15	return true;
 
 
16}
17
 
 
18static int vcpu_get_tsc_offset(void *data, u64 *val)
19{
20	struct kvm_vcpu *vcpu = (struct kvm_vcpu *) data;
21	*val = vcpu->arch.tsc_offset;
22	return 0;
23}
24
25DEFINE_SIMPLE_ATTRIBUTE(vcpu_tsc_offset_fops, vcpu_get_tsc_offset, NULL, "%lld\n");
26
27static int vcpu_get_tsc_scaling_ratio(void *data, u64 *val)
28{
29	struct kvm_vcpu *vcpu = (struct kvm_vcpu *) data;
30	*val = vcpu->arch.tsc_scaling_ratio;
31	return 0;
32}
33
34DEFINE_SIMPLE_ATTRIBUTE(vcpu_tsc_scaling_fops, vcpu_get_tsc_scaling_ratio, NULL, "%llu\n");
35
36static int vcpu_get_tsc_scaling_frac_bits(void *data, u64 *val)
37{
38	*val = kvm_tsc_scaling_ratio_frac_bits;
39	return 0;
40}
41
42DEFINE_SIMPLE_ATTRIBUTE(vcpu_tsc_scaling_frac_fops, vcpu_get_tsc_scaling_frac_bits, NULL, "%llu\n");
43
44int kvm_arch_create_vcpu_debugfs(struct kvm_vcpu *vcpu)
45{
46	struct dentry *ret;
 
47
48	ret = debugfs_create_file("tsc-offset", 0444,
49							vcpu->debugfs_dentry,
50							vcpu, &vcpu_tsc_offset_fops);
51	if (!ret)
52		return -ENOMEM;
53
54	if (kvm_has_tsc_control) {
55		ret = debugfs_create_file("tsc-scaling-ratio", 0444,
56							vcpu->debugfs_dentry,
57							vcpu, &vcpu_tsc_scaling_fops);
58		if (!ret)
59			return -ENOMEM;
60		ret = debugfs_create_file("tsc-scaling-ratio-frac-bits", 0444,
61							vcpu->debugfs_dentry,
62							vcpu, &vcpu_tsc_scaling_frac_fops);
63		if (!ret)
64			return -ENOMEM;
65
66	}
67
68	return 0;
69}
v5.4
 1// SPDX-License-Identifier: GPL-2.0-only
 2/*
 3 * Kernel-based Virtual Machine driver for Linux
 4 *
 5 * Copyright 2016 Red Hat, Inc. and/or its affiliates.
 
 
 
 
 6 */
 7#include <linux/kvm_host.h>
 8#include <linux/debugfs.h>
 9#include "lapic.h"
10
11static 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
20static 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
46void kvm_arch_create_vcpu_debugfs(struct kvm_vcpu *vcpu)
47{
48	debugfs_create_file("tsc-offset", 0444, vcpu->debugfs_dentry, vcpu,
49			    &vcpu_tsc_offset_fops);
50
51	if (lapic_in_kernel(vcpu))
52		debugfs_create_file("lapic_timer_advance_ns", 0444,
53				    vcpu->debugfs_dentry, vcpu,
54				    &vcpu_timer_advance_ns_fops);
 
55
56	if (kvm_has_tsc_control) {
57		debugfs_create_file("tsc-scaling-ratio", 0444,
58				    vcpu->debugfs_dentry, vcpu,
59				    &vcpu_tsc_scaling_fops);
60		debugfs_create_file("tsc-scaling-ratio-frac-bits", 0444,
61				    vcpu->debugfs_dentry, vcpu,
62				    &vcpu_tsc_scaling_frac_fops);
 
 
 
 
 
63	}
 
 
64}