From patchwork Tue Jun 17 07:54:32 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Ellerman X-Patchwork-Id: 360424 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 5191E140098 for ; Tue, 17 Jun 2014 19:47:47 +1000 (EST) Received: from localhost ([::1]:48526 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WwpzU-0002fV-Vw for incoming@patchwork.ozlabs.org; Tue, 17 Jun 2014 05:47:45 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55081) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WwoEQ-0002Lt-MA for qemu-devel@nongnu.org; Tue, 17 Jun 2014 03:55:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WwoEG-0002AS-JK for qemu-devel@nongnu.org; Tue, 17 Jun 2014 03:55:02 -0400 Received: from ozlabs.org ([103.22.144.67]:51976) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WwoEG-000294-84 for qemu-devel@nongnu.org; Tue, 17 Jun 2014 03:54:52 -0400 Received: by ozlabs.org (Postfix, from userid 1034) id 0573614009C; Tue, 17 Jun 2014 17:54:48 +1000 (EST) From: Michael Ellerman To: qemu-devel@nongnu.org Date: Tue, 17 Jun 2014 17:54:32 +1000 Message-Id: <1402991675-24905-3-git-send-email-mpe@ellerman.id.au> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1402991675-24905-1-git-send-email-mpe@ellerman.id.au> References: <1402991675-24905-1-git-send-email-mpe@ellerman.id.au> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 103.22.144.67 X-Mailman-Approved-At: Tue, 17 Jun 2014 05:47:18 -0400 Cc: kvm@vger.kernel.org, aik@ozlabs.ru, jan.kiszka@siemens.com, agraf@suse.de, jfrei@linux.vnet.ibm.com, alfs@linux.vnet.ibm.com, pbonzini@redhat.com Subject: [Qemu-devel] [PATCH 3/6] kvm_stat: Rework platform detection X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org The current platform detection is a little bit messy. We look for lines in /proc/cpuinfo starting with 'flags' OR 'vendor-id', and scan both for values we know will only occur in one or the other. We also keep scanning once we've found a value, which could be a feature, but isn't in this case. We'd also like to add another platform, powerpc, which will just make it worse. So clean it up in preparation. Signed-off-by: Michael Ellerman --- scripts/kvm/kvm_stat | 44 +++++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/scripts/kvm/kvm_stat b/scripts/kvm/kvm_stat index fe2eae3..98c81a8 100755 --- a/scripts/kvm/kvm_stat +++ b/scripts/kvm/kvm_stat @@ -169,27 +169,41 @@ generic_exit_reasons = { 23: 'EPR', } -vendor_exit_reasons = { +x86_exit_reasons = { 'vmx': vmx_exit_reasons, 'svm': svm_exit_reasons, - 'IBM/S390': generic_exit_reasons, } -syscall_numbers = { - 'IBM/S390': 331, -} - -sc_perf_evt_open = 298 - +sc_perf_evt_open = None exit_reasons = None -for line in file('/proc/cpuinfo').readlines(): - if line.startswith('flags') or line.startswith('vendor_id'): - for flag in line.split(): - if flag in vendor_exit_reasons: - exit_reasons = vendor_exit_reasons[flag] - if flag in syscall_numbers: - sc_perf_evt_open = syscall_numbers[flag] +def x86_init(flag): + globals().update({ + 'sc_perf_evt_open' : 298, + 'exit_reasons' : x86_exit_reasons[flag], + }) + +def s390_init(): + globals().update({ + 'sc_perf_evt_open' : 331, + 'exit_reasons' : generic_exit_reasons, + }) + +def detect_platform(): + 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 + +detect_platform() + filters = { 'kvm_exit': ('exit_reason', exit_reasons) }