Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5636181imu; Mon, 26 Nov 2018 03:19:31 -0800 (PST) X-Google-Smtp-Source: AFSGD/WCHVOu7J8dw67dLdgtz+GLjhm0tv21ztOd5Jly1FnbIfXX6JgAkGgDApNVF/Ws9qzweBY8 X-Received: by 2002:a63:3287:: with SMTP id y129mr24452216pgy.337.1543231171149; Mon, 26 Nov 2018 03:19:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543231171; cv=none; d=google.com; s=arc-20160816; b=ZGMbOWY6sYeNCha34I85ROuFhT2q9AemVVdBIHFuP/QSiyf//SCvt/zz6OMDHqhz1X aoAvrcNwUt4/Fgz/M5V8h85kj6vkDpE8wGxc1YpugeVG9+lPxyw85lHZ1C0B9sDYUse8 DKNriCsS1qE6Zbj2MjLvyc9dtgnThsnyO3thPkM8wFmAxzYTaE6yzIl2hZTf1tMFlvR5 aJVNXDYo4FB+MXssC8rQlTxSzLRUiS2iCHXOe8hRjOgfGdQBZcmpHAaTWvT0EFMz64e7 aznsJEd2K1DdGnhSccDGb0emVuWIJXf9nxhnPKdaxC1zx5wi+/LMu2fdOJeSe69vCjDc wLYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=nrx2zj5XZTgXey3WQToQTL5uMst3Ews4O0ejteop7js=; b=NtkKze1l/8rdd4ib/qVisSLGfVTPCXz5Pzktk/JZR5PjQPfaD8Gn3s3BQkqZh0AHlq aUpZ1qg7YHwxzUGuFlkqRHaFL4w5oLx2UhsZqbNgTU9kGyIYzKImmSUGLrfFveU4UwSc 1kk7/sLviqMe/JvfGAyWT4/8hINpaHDv+joBCQliTuMqq3zGnXnIfroQ2BNEGpviKhqv fkVmJBlxBn/MW4ag6p5rqycAf8XAcJLTM4E7irckx68zkTo8FSFIV7JBVwkHpW+pd6Yc luThCi6KTq/BnCBpsFtu0j8TdaQWwW7TtEcbRhOnHPWtX6nxb+dc1igt7rRXpVcO6g8E rRmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Eie1m18x; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w1si22491pgi.66.2018.11.26.03.19.15; Mon, 26 Nov 2018 03:19:31 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Eie1m18x; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729862AbeKZVyR (ORCPT + 99 others); Mon, 26 Nov 2018 16:54:17 -0500 Received: from mail.kernel.org ([198.145.29.99]:36294 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728039AbeKZVyQ (ORCPT ); Mon, 26 Nov 2018 16:54:16 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9467A2146F; Mon, 26 Nov 2018 11:00:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543230031; bh=AuEH9jgbSHviJll6nfowz/VV4SG9qTHrvgMP4YPjGIQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Eie1m18xyL+yfk3fshaQkUedU9M2gtxyjh5tFL2hvCX0hwF4JW/6a4A1k00vq+x2F aoIsuSBc4/sKShlNzn7LsPJlBcDM+nZBrzNNnaFmWPnLArPEpnFeAf6TAKNNcWenOT rUiZ7jZhw/WwAzhHZwcej/d/v0x56g+0abpm8Dkc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Adrian Hunter , Alexander Shishkin , Andi Kleen , Andy Lutomirski , Dave Hansen , "H. Peter Anvin" , Jiri Olsa , Joerg Roedel , Peter Zijlstra , Thomas Gleixner , x86@kernel.org, Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH 4.14 45/62] perf machine: Add nr_cpus_avail() Date: Mon, 26 Nov 2018 11:51:26 +0100 Message-Id: <20181126105054.194629176@linuxfoundation.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181126105050.592727680@linuxfoundation.org> References: <20181126105050.592727680@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ commit 9cecca325ea879c84fcd31a5e609a514c1a1dbd1 upstream. Add a function to return the number of the machine's available CPUs. Signed-off-by: Adrian Hunter Cc: Alexander Shishkin Cc: Andi Kleen Cc: Andy Lutomirski Cc: Dave Hansen Cc: H. Peter Anvin Cc: Jiri Olsa Cc: Joerg Roedel Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: x86@kernel.org Link: http://lkml.kernel.org/r/1526986485-6562-5-git-send-email-adrian.hunter@intel.com Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- tools/perf/util/env.c | 13 +++++++++++++ tools/perf/util/env.h | 1 + tools/perf/util/machine.c | 5 +++++ tools/perf/util/machine.h | 1 + 4 files changed, 20 insertions(+) diff --git a/tools/perf/util/env.c b/tools/perf/util/env.c index 49f58921a968..b492cb974aa0 100644 --- a/tools/perf/util/env.c +++ b/tools/perf/util/env.c @@ -101,11 +101,24 @@ static int perf_env__read_arch(struct perf_env *env) return env->arch ? 0 : -ENOMEM; } +static int perf_env__read_nr_cpus_avail(struct perf_env *env) +{ + if (env->nr_cpus_avail == 0) + env->nr_cpus_avail = cpu__max_present_cpu(); + + return env->nr_cpus_avail ? 0 : -ENOENT; +} + const char *perf_env__raw_arch(struct perf_env *env) { return env && !perf_env__read_arch(env) ? env->arch : "unknown"; } +int perf_env__nr_cpus_avail(struct perf_env *env) +{ + return env && !perf_env__read_nr_cpus_avail(env) ? env->nr_cpus_avail : 0; +} + void cpu_cache_level__free(struct cpu_cache_level *cache) { free(cache->type); diff --git a/tools/perf/util/env.h b/tools/perf/util/env.h index bd3869913907..9aace8452751 100644 --- a/tools/perf/util/env.h +++ b/tools/perf/util/env.h @@ -67,5 +67,6 @@ int perf_env__read_cpu_topology_map(struct perf_env *env); void cpu_cache_level__free(struct cpu_cache_level *cache); const char *perf_env__raw_arch(struct perf_env *env); +int perf_env__nr_cpus_avail(struct perf_env *env); #endif /* __PERF_ENV_H */ diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index af18c3d55642..78aa1c5f19ca 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -2247,6 +2247,11 @@ bool machine__is(struct machine *machine, const char *arch) return machine && !strcmp(perf_env__raw_arch(machine->env), arch); } +int machine__nr_cpus_avail(struct machine *machine) +{ + return machine ? perf_env__nr_cpus_avail(machine->env) : 0; +} + int machine__get_kernel_start(struct machine *machine) { struct map *map = machine__kernel_map(machine); diff --git a/tools/perf/util/machine.h b/tools/perf/util/machine.h index fbc5133fb27c..245743d9ce63 100644 --- a/tools/perf/util/machine.h +++ b/tools/perf/util/machine.h @@ -170,6 +170,7 @@ static inline bool machine__is_host(struct machine *machine) } bool machine__is(struct machine *machine, const char *arch); +int machine__nr_cpus_avail(struct machine *machine); struct thread *__machine__findnew_thread(struct machine *machine, pid_t pid, pid_t tid); struct thread *machine__findnew_thread(struct machine *machine, pid_t pid, pid_t tid); -- 2.17.1