qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 15/34] scripts/kvm/kvm_stat: Cleanup of platform det


From: Janosch Frank
Subject: [Qemu-devel] [PATCH 15/34] scripts/kvm/kvm_stat: Cleanup of platform detection
Date: Thu, 10 Dec 2015 13:12:45 +0100

s390 machines can also be detected via uname -m, i.e. python's
os.uname, no need for more complicated checks.

Calling uname once and saving its value for multiple checks is
perfectly sufficient. We don't expect the machine's architecture to
change when the script is running anyway.

On multi-cpu systems x86_init currently will get called multiple
times, returning makes sure we don't waste cicles on that.
---
 scripts/kvm/kvm_stat | 31 ++++++++++++++-----------------
 1 file changed, 14 insertions(+), 17 deletions(-)

diff --git a/scripts/kvm/kvm_stat b/scripts/kvm/kvm_stat
index b8c2a8f..4cb18e1 100755
--- a/scripts/kvm/kvm_stat
+++ b/scripts/kvm/kvm_stat
@@ -254,24 +254,21 @@ def aarch64_init():
     EXIT_REASONS = AARCH64_EXIT_REASONS
 
 def detect_platform():
-    if os.uname()[4].startswith('ppc'):
-        ppc_init()
-        return
-    elif os.uname()[4].startswith('aarch64'):
-        aarch64_init()
-        return
+    machine = os.uname()[4]
 
-    for line in file('/proc/cpuinfo').readlines():
-        if line.startswith('flags'):
-            for flag in line.split():
-                if flag in X86_EXIT_REASONS:
-                    x86_init(flag)
-                    return
-        elif line.startswith('vendor_id'):
-            for flag in line.split():
-                if flag == 'IBM/S390':
-                    s390_init()
-                    return
+    if machine.startswith('ppc'):
+        ppc_init()
+    elif machine.startswith('aarch64'):
+        aarch64_init()
+    elif machine.startswith('s390'):
+        s390_init()
+    else:
+        for line in file('/proc/cpuinfo').readlines():
+            if line.startswith('flags'):
+                for flag in line.split():
+                    if flag in X86_EXIT_REASONS:
+                        x86_init(flag)
+                        return
 
 
 def walkdir(path):
-- 
2.3.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]