KVM: debugfs: Reuse binary stats descriptors

To remove code duplication, use the binary stats descriptors in the
implementation of the debugfs interface for statistics. This unifies
the definition of statistics for the binary and debugfs interfaces.

Signed-off-by: Jing Zhang <jingzhangos@google.com>
Message-Id: <20210618222709.1858088-8-jingzhangos@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
Jing Zhang
2021-06-23 17:28:46 -04:00
committed by Paolo Bonzini
parent 0b45d58738
commit bc9e9e672d
8 changed files with 78 additions and 313 deletions

View File

@@ -1264,14 +1264,8 @@ enum kvm_stat_kind {
struct kvm_stat_data {
struct kvm *kvm;
struct kvm_stats_debugfs_item *dbgfs_item;
};
struct kvm_stats_debugfs_item {
const char *name;
int offset;
const struct _kvm_stats_desc *desc;
enum kvm_stat_kind kind;
int mode;
};
struct _kvm_stats_desc {
@@ -1279,14 +1273,6 @@ struct _kvm_stats_desc {
char name[KVM_STATS_NAME_SIZE];
};
#define KVM_DBGFS_GET_MODE(dbgfs_item) \
((dbgfs_item)->mode ? (dbgfs_item)->mode : 0644)
#define VM_STAT(n, x, ...) \
{ n, offsetof(struct kvm, stat.x), KVM_STAT_VM, ## __VA_ARGS__ }
#define VCPU_STAT(n, x, ...) \
{ n, offsetof(struct kvm_vcpu, stat.x), KVM_STAT_VCPU, ## __VA_ARGS__ }
#define STATS_DESC_COMMON(type, unit, base, exp) \
.flags = type | unit | base | \
BUILD_BUG_ON_ZERO(type & ~KVM_STATS_TYPE_MASK) | \
@@ -1367,7 +1353,6 @@ struct _kvm_stats_desc {
STATS_DESC_TIME_NSEC(VCPU_GENERIC, halt_poll_success_ns), \
STATS_DESC_TIME_NSEC(VCPU_GENERIC, halt_poll_fail_ns)
extern struct kvm_stats_debugfs_item debugfs_entries[];
extern struct dentry *kvm_debugfs_dir;
ssize_t kvm_stats_read(char *id, const struct kvm_stats_header *header,
const struct _kvm_stats_desc *desc,