From patchwork Tue Jun 17 07:54:30 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Ellerman X-Patchwork-Id: 360427 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 1982414007D for ; Tue, 17 Jun 2014 19:49:21 +1000 (EST) Received: from localhost ([::1]:48549 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wwq10-0005Yu-Po for incoming@patchwork.ozlabs.org; Tue, 17 Jun 2014 05:49:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55083) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WwoEQ-0002Lu-SG for qemu-devel@nongnu.org; Tue, 17 Jun 2014 03:55:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WwoEH-0002Ac-IN for qemu-devel@nongnu.org; Tue, 17 Jun 2014 03:55:02 -0400 Received: from ozlabs.org ([103.22.144.67]:35407) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WwoEH-0002A6-7N for qemu-devel@nongnu.org; Tue, 17 Jun 2014 03:54:53 -0400 Received: by ozlabs.org (Postfix, from userid 1034) id E78D2140098; Tue, 17 Jun 2014 17:54:47 +1000 (EST) From: Michael Ellerman To: qemu-devel@nongnu.org Date: Tue, 17 Jun 2014 17:54:30 +1000 Message-Id: <1402991675-24905-1-git-send-email-mpe@ellerman.id.au> X-Mailer: git-send-email 1.9.1 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 1/6] kvm_stat: Only consider online cpus 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 In kvm_stat we grovel through /sys to find out how many cpus are in the system. However if a cpu is offline it will still be present in /sys, and the perf_event_open() will fail. Modify the logic to only return online cpus. We need to be careful on systems which don't support cpu hotplug, the online file will not be present at all. Signed-off-by: Michael Ellerman --- scripts/kvm/kvm_stat | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/scripts/kvm/kvm_stat b/scripts/kvm/kvm_stat index d7e97e7..2a788bc 100755 --- a/scripts/kvm/kvm_stat +++ b/scripts/kvm/kvm_stat @@ -311,18 +311,30 @@ class TracepointProvider(object): self.select(fields) def fields(self): return self._fields + + def _online_cpus(self): + l = [] + pattern = r'cpu([0-9]+)' + basedir = '/sys/devices/system/cpu' + for entry in os.listdir(basedir): + match = re.match(pattern, entry) + if not match: + continue + path = os.path.join(basedir, entry, 'online') + if os.path.exists(path) and open(path).read().strip() != '1': + continue + l.append(int(match.group(1))) + return l + def _setup(self, _fields): self._fields = _fields - cpure = r'cpu([0-9]+)' - self.cpus = [int(re.match(cpure, x).group(1)) - for x in os.listdir('/sys/devices/system/cpu') - if re.match(cpure, x)] + cpus = self._online_cpus() import resource - nfiles = len(self.cpus) * 1000 + nfiles = len(cpus) * 1000 resource.setrlimit(resource.RLIMIT_NOFILE, (nfiles, nfiles)) events = [] self.group_leaders = [] - for cpu in self.cpus: + for cpu in cpus: group = Group(cpu) for name in _fields: tracepoint = name