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: 4364781 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id B5B989F36A for ; Tue, 17 Jun 2014 07:55:00 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id ED3C420279 for ; Tue, 17 Jun 2014 07:54:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5800F20256 for ; Tue, 17 Jun 2014 07:54:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932265AbaFQHyv (ORCPT ); Tue, 17 Jun 2014 03:54:51 -0400 Received: from ozlabs.org ([103.22.144.67]:36726 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932187AbaFQHyu (ORCPT ); Tue, 17 Jun 2014 03:54:50 -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 Cc: , alfs@linux.vnet.ibm.com, jfrei@linux.vnet.ibm.com, agraf@suse.de, jan.kiszka@siemens.com, pbonzini@redhat.com, aik@ozlabs.ru Subject: [PATCH 3/6] kvm_stat: Rework platform detection 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> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-7.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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) }