debugfs.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. bool kvm_arch_has_vcpu_debugfs(void)
  13. {
  14. return true;
  15. }
  16. static int vcpu_get_tsc_offset(void *data, u64 *val)
  17. {
  18. struct kvm_vcpu *vcpu = (struct kvm_vcpu *) data;
  19. *val = vcpu->arch.tsc_offset;
  20. return 0;
  21. }
  22. DEFINE_SIMPLE_ATTRIBUTE(vcpu_tsc_offset_fops, vcpu_get_tsc_offset, NULL, "%lld\n");
  23. static int vcpu_get_tsc_scaling_ratio(void *data, u64 *val)
  24. {
  25. struct kvm_vcpu *vcpu = (struct kvm_vcpu *) data;
  26. *val = vcpu->arch.tsc_scaling_ratio;
  27. return 0;
  28. }
  29. DEFINE_SIMPLE_ATTRIBUTE(vcpu_tsc_scaling_fops, vcpu_get_tsc_scaling_ratio, NULL, "%llu\n");
  30. static int vcpu_get_tsc_scaling_frac_bits(void *data, u64 *val)
  31. {
  32. *val = kvm_tsc_scaling_ratio_frac_bits;
  33. return 0;
  34. }
  35. DEFINE_SIMPLE_ATTRIBUTE(vcpu_tsc_scaling_frac_fops, vcpu_get_tsc_scaling_frac_bits, NULL, "%llu\n");
  36. int kvm_arch_create_vcpu_debugfs(struct kvm_vcpu *vcpu)
  37. {
  38. struct dentry *ret;
  39. ret = debugfs_create_file("tsc-offset", 0444,
  40. vcpu->debugfs_dentry,
  41. vcpu, &vcpu_tsc_offset_fops);
  42. if (!ret)
  43. return -ENOMEM;
  44. if (kvm_has_tsc_control) {
  45. ret = debugfs_create_file("tsc-scaling-ratio", 0444,
  46. vcpu->debugfs_dentry,
  47. vcpu, &vcpu_tsc_scaling_fops);
  48. if (!ret)
  49. return -ENOMEM;
  50. ret = debugfs_create_file("tsc-scaling-ratio-frac-bits", 0444,
  51. vcpu->debugfs_dentry,
  52. vcpu, &vcpu_tsc_scaling_frac_fops);
  53. if (!ret)
  54. return -ENOMEM;
  55. }
  56. return 0;
  57. }