From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43524) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aIeFh-0001jA-Hc for qemu-devel@nongnu.org; Mon, 11 Jan 2016 10:19:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aIeFd-0001sf-0G for qemu-devel@nongnu.org; Mon, 11 Jan 2016 10:19:25 -0500 Received: from e06smtp05.uk.ibm.com ([195.75.94.101]:50113) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aIeFc-0001rn-N5 for qemu-devel@nongnu.org; Mon, 11 Jan 2016 10:19:20 -0500 Received: from localhost by e06smtp05.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 11 Jan 2016 15:19:19 -0000 Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by d06dlp01.portsmouth.uk.ibm.com (Postfix) with ESMTP id 4158F17D8042 for ; Mon, 11 Jan 2016 15:19:19 +0000 (GMT) Received: from d06av05.portsmouth.uk.ibm.com (d06av05.portsmouth.uk.ibm.com [9.149.37.229]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u0BFJIGP58720382 for ; Mon, 11 Jan 2016 15:19:18 GMT Received: from d06av05.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av05.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id u0BFJHRd018769 for ; Mon, 11 Jan 2016 08:19:17 -0700 From: Janosch Frank Date: Mon, 11 Jan 2016 16:17:45 +0100 Message-Id: <1452525484-32309-16-git-send-email-frankja@linux.vnet.ibm.com> In-Reply-To: <1452525484-32309-1-git-send-email-frankja@linux.vnet.ibm.com> References: <1452525484-32309-1-git-send-email-frankja@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH v2 15/34] scripts/kvm/kvm_stat: Cleanup of platform detection List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: pbonzini@redhat.com Cc: frankja@linux.vnet.ibm.com, qemu-devel@nongnu.org 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. Signed-off-by: Janosch Frank --- 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 93b5ea7..5b6742a 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