From patchwork Wed Aug 22 08:43:12 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoshihiro YUNOMAE X-Patchwork-Id: 179263 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 578DF2C008D for ; Wed, 22 Aug 2012 18:43:52 +1000 (EST) Received: from localhost ([::1]:44719 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T46XW-0001NR-BX for incoming@patchwork.ozlabs.org; Wed, 22 Aug 2012 04:43:50 -0400 Received: from eggs.gnu.org ([208.118.235.92]:36303) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T46XD-00015K-Bb for qemu-devel@nongnu.org; Wed, 22 Aug 2012 04:43:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T46X9-0003fM-I6 for qemu-devel@nongnu.org; Wed, 22 Aug 2012 04:43:31 -0400 Received: from mail9.hitachi.co.jp ([133.145.228.44]:36036) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T46X9-0003eq-2w for qemu-devel@nongnu.org; Wed, 22 Aug 2012 04:43:27 -0400 Received: from mlsv7.hitachi.co.jp (unknown [133.144.234.166]) by mail9.hitachi.co.jp (Postfix) with ESMTP id 1ADB137C8F; Wed, 22 Aug 2012 17:43:25 +0900 (JST) Received: from mfilter04.hitachi.co.jp by mlsv7.hitachi.co.jp (8.13.1/8.13.1) id q7M8hPCY014883; Wed, 22 Aug 2012 17:43:25 +0900 Received: from vshuts3.hitachi.co.jp (vshuts3.hitachi.co.jp [10.201.6.72]) by mfilter04.hitachi.co.jp (Switch-3.3.4/Switch-3.3.4) with ESMTP id q7M8hNXa026102; Wed, 22 Aug 2012 17:43:24 +0900 X-AuditID: b753bd60-991dcba000000c4c-83-50349bab67ef Received: from hsdlmain.sdl.hitachi.co.jp (unknown [133.144.14.194]) by vshuts3.hitachi.co.jp (Symantec Mail Security) with ESMTP id 4092D7742E2; Wed, 22 Aug 2012 17:43:23 +0900 (JST) Received: from hsdlvgate2.sdl.hitachi.co.jp by hsdlmain.sdl.hitachi.co.jp (8.13.8/3.7W11021512) id q7M8hNsG024502; Wed, 22 Aug 2012 17:43:23 +0900 X-AuditID: b753bd60-991dcba000000c4c-83-50349bab67ef Received: from sdl99w.sdl.hitachi.co.jp (sdl99w.sdl.hitachi.co.jp [133.144.14.250]) by hsdlvgate2.sdl.hitachi.co.jp (Symantec Mail Security) with ESMTP id C47D6236561; Wed, 22 Aug 2012 17:43:22 +0900 (JST) Received: from maild.sdl.hitachi.co.jp (sdl99d.sdl.hitachi.co.jp [133.144.14.199]) by sdl99w.sdl.hitachi.co.jp (Postfix) with ESMTP id 05B4C53C158; Wed, 22 Aug 2012 17:43:24 +0900 (JST) Received: from ltc189.sdl.hitachi.co.jp (unknown [10.232.28.60]) by maild.sdl.hitachi.co.jp (Postfix) with ESMTP id BE1F7495BB7; Wed, 22 Aug 2012 17:43:22 +0900 (JST) From: Yoshihiro YUNOMAE To: Steven Rostedt Date: Wed, 22 Aug 2012 17:43:12 +0900 Message-ID: <20120822084312.17293.47596.stgit@ltc189.sdl.hitachi.co.jp> In-Reply-To: <20120822084251.17293.69086.stgit@ltc189.sdl.hitachi.co.jp> References: <20120822084251.17293.69086.stgit@ltc189.sdl.hitachi.co.jp> User-Agent: StGIT/0.14.3 MIME-Version: 1.0 X-Brightmail-Tracker: AAAAAA== X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4-2.6 X-Received-From: 133.145.228.44 Cc: Herbert Xu , Arnd Bergmann , qemu-devel@nongnu.org, Frederic Weisbecker , Yoshihiro YUNOMAE , Rusty Russell , linux-kernel@vger.kernel.org, Borislav Petkov , virtualization@lists.linux-foundation.org, Masami Hiramatsu , "Franch Ch. Eigler" , Ingo Molnar , Mathieu Desnoyers , Anthony Liguori , Greg Kroah-Hartman , Amit Shah , yrl.pp-manager.tt@hitachi.com Subject: [Qemu-devel] [PATCH 2/5] trace-cmd: Use tracing directory to count 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 From: Masami Hiramatsu Count debugfs/tracing/per_cpu/cpu* to determine the number of CPUs. Signed-off-by: Masami Hiramatsu Signed-off-by: Yoshihiro YUNOMAE --- trace-record.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 files changed, 41 insertions(+), 0 deletions(-) diff --git a/trace-record.c b/trace-record.c index 9dc18a9..ed18951 100644 --- a/trace-record.c +++ b/trace-record.c @@ -1179,6 +1179,41 @@ static void expand_event_list(void) } } +static int count_tracingdir_cpus(void) +{ + char *tracing_dir = NULL; + char *percpu_dir = NULL; + struct dirent **namelist; + int count = 0, n; + + /* Count cpus in per_cpu directory */ + tracing_dir = tracecmd_find_tracing_dir(); + if (!tracing_dir) + return 0; + percpu_dir = malloc_or_die(strlen(tracing_dir) + 9); + if (!percpu_dir) + goto err; + + sprintf(percpu_dir, "%s/per_cpu", tracing_dir); + + n = scandir(percpu_dir, &namelist, NULL, alphasort); + if (n > 0) { + while (n--) { + if (strncmp("cpu", namelist[n]->d_name, 3) == 0) + count++; + free(namelist[n]); + } + free(namelist); + } + + if (percpu_dir) + free(percpu_dir); +err: + if (tracing_dir) + free(tracing_dir); + return count; +} + static int count_cpus(void) { FILE *fp; @@ -1189,6 +1224,12 @@ static int count_cpus(void) size_t n; int r; + cpus = count_tracingdir_cpus(); + if (cpus > 0) + return cpus; + + warning("failed to use tracing_dir to determine number of CPUS"); + cpus = sysconf(_SC_NPROCESSORS_CONF); if (cpus > 0) return cpus;