aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Rostedt (Google) <rostedt@goodmis.org>2022-05-21 20:39:33 -0400
committerSteven Rostedt (Google) <rostedt@goodmis.org>2022-05-21 21:02:52 -0400
commite7574f26990b47b104aa3866e047eea3067c5f43 (patch)
treeeb27d5c89b6442d6103c2479e5372dfb3ff2a22a
parent80fd938528e9bf463ca86c6f36e9c80f6cc7ffaf (diff)
downloadtrace-cmd-e7574f26990b47b104aa3866e047eea3067c5f43.tar.gz
trace-cmd kvm timesync: Check for one valid VM
Currently if there are no valid VMs the kvm supported check can return true. Check for at least one valid VM, and that echa VM has one valid VCPU. Also comment the code as it is very confusing to why the scaling checks return true or false. Link: https://lore.kernel.org/linux-trace-devel/20220522003935.196466-3-rostedt@goodmis.org Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
-rw-r--r--lib/trace-cmd/trace-timesync-kvm.c46
1 files changed, 36 insertions, 10 deletions
diff --git a/lib/trace-cmd/trace-timesync-kvm.c b/lib/trace-cmd/trace-timesync-kvm.c
index a645fa2c..671eafaf 100644
--- a/lib/trace-cmd/trace-timesync-kvm.c
+++ b/lib/trace-cmd/trace-timesync-kvm.c
@@ -73,6 +73,11 @@ static int read_ll_from_file(char *file, long long *res)
return 0;
}
+/*
+ * Returns true if both scaling and fraction exist or both do
+ * not exist. false if one exists without the other or if there
+ * is a memory error.
+ */
static bool kvm_scaling_check_vm_cpu(char *vname, char *cpu)
{
bool has_scaling = false;
@@ -101,46 +106,66 @@ static bool kvm_scaling_check_vm_cpu(char *vname, char *cpu)
return true;
}
+/*
+ * Returns true if a VCPU exists with a tsc-offset file and that
+ * the scaling files for ratio and fraction both exist or both
+ * do not exist. False if there is no VM with a tsc-offset or
+ * there is only one of the two scaling files, or there's a
+ * memory issue.
+ */
static bool kvm_scaling_check_vm(char *name)
{
struct dirent *entry;
char *vdir;
DIR *dir;
+ bool valid = false;
if (asprintf(&vdir, "%s/%s", KVM_DEBUG_FS, name) < 0)
- return true;
+ return false;
dir = opendir(vdir);
if (!dir) {
free(vdir);
- return true;
+ return false;
}
while ((entry = readdir(dir))) {
- if (entry->d_type == DT_DIR && !strncmp(entry->d_name, "vcpu", 4) &&
- !kvm_scaling_check_vm_cpu(vdir, entry->d_name))
- break;
+ if (entry->d_type == DT_DIR && !strncmp(entry->d_name, "vcpu", 4)) {
+ if (!kvm_scaling_check_vm_cpu(vdir, entry->d_name))
+ break;
+ valid = true;
+ }
}
closedir(dir);
free(vdir);
- return entry == NULL;
+ return valid && entry == NULL;
}
+
+/*
+ * Returns true if all VMs have a tsc-offset file and that
+ * the scaling files for ratio and fraction both exist or both
+ * do not exist. False if a VM with a tsc-offset or there is only
+ * one of the two scaling files, or no VM exists or there's a memory issue.
+ */
static bool kvm_scaling_check(void)
{
struct dirent *entry;
DIR *dir;
+ bool valid = false;
dir = opendir(KVM_DEBUG_FS);
if (!dir)
return true;
while ((entry = readdir(dir))) {
- if (entry->d_type == DT_DIR && isdigit(entry->d_name[0]) &&
- !kvm_scaling_check_vm(entry->d_name))
- break;
+ if (entry->d_type == DT_DIR && isdigit(entry->d_name[0])) {
+ if (!kvm_scaling_check_vm(entry->d_name))
+ break;
+ valid = true;
+ }
}
closedir(dir);
- return entry == NULL;
+ return valid && entry == NULL;
}
static bool kvm_support_check(bool guest)
@@ -148,6 +173,7 @@ static bool kvm_support_check(bool guest)
struct stat st;
int ret;
+ /* The kvm files are only in the host so we can ignore guests */
if (guest)
return true;