From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44278) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a706o-0003I8-Bj for qemu-devel@nongnu.org; Thu, 10 Dec 2015 07:14:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a706j-0003nm-4x for qemu-devel@nongnu.org; Thu, 10 Dec 2015 07:14:06 -0500 Received: from e06smtp15.uk.ibm.com ([195.75.94.111]:58562) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a706i-0003na-RH for qemu-devel@nongnu.org; Thu, 10 Dec 2015 07:14:01 -0500 Received: from localhost by e06smtp15.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 10 Dec 2015 12:14:00 -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 704B917D8042 for ; Thu, 10 Dec 2015 12:14:28 +0000 (GMT) Received: from d06av06.portsmouth.uk.ibm.com (d06av06.portsmouth.uk.ibm.com [9.149.37.217]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id tBACDu4Z57606360 for ; Thu, 10 Dec 2015 12:13:56 GMT Received: from d06av06.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av06.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id tBACDthY025227 for ; Thu, 10 Dec 2015 05:13:55 -0700 From: Janosch Frank Date: Thu, 10 Dec 2015 13:12:45 +0100 Message-Id: <1449749584-23214-16-git-send-email-frankja@linux.vnet.ibm.com> In-Reply-To: <1449749584-23214-1-git-send-email-frankja@linux.vnet.ibm.com> References: <1449749584-23214-1-git-send-email-frankja@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH 15/34] scripts/kvm/kvm_stat: Cleanup of platform detection List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: cornelia.huck@de.ibm.com, frankja@linux.vnet.ibm.com 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