From patchwork Sat Oct 20 19:54:24 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin Ian King X-Patchwork-Id: 192949 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from chlorine.canonical.com (chlorine.canonical.com [91.189.94.204]) by ozlabs.org (Postfix) with ESMTP id B2AB32C008F for ; Sun, 21 Oct 2012 06:54:28 +1100 (EST) Received: from localhost ([127.0.0.1] helo=chlorine.canonical.com) by chlorine.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1TPf7r-0004Zk-J0; Sat, 20 Oct 2012 19:54:27 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by chlorine.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1TPf7p-0004ZY-7c for fwts-devel@lists.ubuntu.com; Sat, 20 Oct 2012 19:54:25 +0000 Received: from cpc3-craw6-2-0-cust180.croy.cable.virginmedia.com ([77.100.248.181] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1TPf7p-0000Ws-4a for fwts-devel@lists.ubuntu.com; Sat, 20 Oct 2012 19:54:25 +0000 From: Colin King To: fwts-devel@lists.ubuntu.com Subject: [PATCH] cpu: cpufreq: add init function to determine number of CPUs Date: Sat, 20 Oct 2012 20:54:24 +0100 Message-Id: <1350762864-5758-1-git-send-email-colin.king@canonical.com> X-Mailer: git-send-email 1.7.10.4 X-BeenThere: fwts-devel@lists.ubuntu.com X-Mailman-Version: 2.1.13 Precedence: list List-Id: Firmware Test Suite Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: fwts-devel-bounces@lists.ubuntu.com Errors-To: fwts-devel-bounces@lists.ubuntu.com From: Colin Ian King Rather than call sysconf() multiple times just evaluate the number of CPUs once and use the fwts_cpu_enumerate() helper to enumerate the number of cpus rather than sysconf(). Signed-off-by: Colin Ian King Acked-by: Alex Hung Acked-by: Keng-Yu Lin --- src/cpu/cpufreq/cpufreq.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/cpu/cpufreq/cpufreq.c b/src/cpu/cpufreq/cpufreq.c index 48e8c6d..9efe4f0 100644 --- a/src/cpu/cpufreq/cpufreq.c +++ b/src/cpu/cpufreq/cpufreq.c @@ -50,6 +50,7 @@ static int total_tests = 1; static int performed_tests = 0; static int no_cpufreq = 0; static unsigned long top_speed = 0; +static int num_cpus; #define GET_PERFORMANCE_MAX (0) #define GET_PERFORMANCE_MIN (1) @@ -284,7 +285,7 @@ static void do_cpu(fwts_framework *fw, int cpu) if (total_tests == 1) total_tests = (2+count_ints(line)) * - sysconf(_SC_NPROCESSORS_CONF) + 2; + num_cpus + 2; c = line; i = 0; @@ -667,7 +668,7 @@ static int cpufreq_test1(fwts_framework *fw) * Check for more than one CPU and more than one frequency and * then do the benchmark set 2 */ - if (sysconf(_SC_NPROCESSORS_CONF) > 1 && number_of_speeds > 1) { + if (num_cpus > 1 && number_of_speeds > 1) { do_sw_all_test(fw); performed_tests++; fwts_progress(fw, 100 * performed_tests/total_tests); @@ -684,12 +685,22 @@ static int cpufreq_test1(fwts_framework *fw) return FWTS_OK; } +static int cpufreq_init(fwts_framework *fw) +{ + if ((num_cpus = fwts_cpu_enumerate()) == FWTS_ERROR) { + fwts_log_warning(fw, "Cannot determine number of CPUS, defaulting to 1."); + num_cpus = 1; + } + return FWTS_OK; +} + static fwts_framework_minor_test cpufreq_tests[] = { { cpufreq_test1, "CPU P-State Checks." }, { NULL, NULL } }; static fwts_framework_ops cpufreq_ops = { + .init = cpufreq_init, .description = "CPU frequency scaling tests (takes ~1-2 mins).", .minor_tests = cpufreq_tests };