Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753328AbdHUJ2G (ORCPT ); Mon, 21 Aug 2017 05:28:06 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:45506 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752482AbdHUJ2E (ORCPT ); Mon, 21 Aug 2017 05:28:04 -0400 From: sathnaga@linux.vnet.ibm.com To: acme@kernel.org, mingo@kernel.org, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Cc: srikar@linux.vnet.ibm.com, bala24@linux.vnet.ibm.com, Satheesh Rajendran Subject: [PATCH v2 1/2] perf/bench/numa: Add functions to detect sparse numa nodes Date: Mon, 21 Aug 2017 14:57:48 +0530 X-Mailer: git-send-email 2.7.4 In-Reply-To: References: X-TM-AS-MML: disable x-cbid: 17082109-1617-0000-0000-000001FC4094 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17082109-1618-0000-0000-000048482AA6 Message-Id: <2a54db2b5e75b15c6f214899bdc7b4a6a1568af0.1502971981.git.sathnaga@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-08-21_07:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1707230000 definitions=main-1708210153 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1766 Lines: 65 From: Satheesh Rajendran Added functions 1) to get a count of all nodes that are exposed to userspace. These nodes could be memoryless cpu nodes or cpuless memory nodes, 2) to check given node is present and 3) to check given node has cpus This information can be used to handle sparse/discontiguous nodes. Reviewed-by: Arnaldo Carvalho de Melo Reviewed-by: Srikar Dronamraju Signed-off-by: Satheesh Rajendran Signed-off-by: Balamuruhan S --- tools/perf/bench/numa.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tools/perf/bench/numa.c b/tools/perf/bench/numa.c index 469d65b..300faba1 100644 --- a/tools/perf/bench/numa.c +++ b/tools/perf/bench/numa.c @@ -215,6 +215,41 @@ static const char * const numa_usage[] = { NULL }; +// To get number of numa nodes present. +static int nr_numa_nodes(void) +{ + int i, nr_nodes = 0; + + for (i = 0; i < g->p.nr_nodes; i++) { + if (numa_bitmask_isbitset(numa_nodes_ptr, i)) + nr_nodes++; + } + return nr_nodes; +} + +// To check if given numa node is present. +static int is_node_present(int node) +{ + return numa_bitmask_isbitset(numa_nodes_ptr, node); +} + +// To check given numa node has cpus. +static bool node_has_cpus(int node) +{ + struct bitmask *cpu = numa_allocate_cpumask(); + unsigned int i; + + if (cpu == NULL) + return false; // lets fall back to nocpus safely + if (numa_node_to_cpus(node, cpu) == 0) { + for (i = 0; i < cpu->size; i++) { + if (numa_bitmask_isbitset(cpu, i)) + return true; + } + } + return false; +} + static cpu_set_t bind_to_cpu(int target_cpu) { cpu_set_t orig_mask, mask; -- 2.7.4