Received: by 10.223.164.202 with SMTP id h10csp389689wrb; Wed, 22 Nov 2017 08:45:23 -0800 (PST) X-Google-Smtp-Source: AGs4zMbzsjTpLUxEPq3Nj83d/18OsxoJHAlhq/y/k3BPeh58yAu5zTWct14dzp4M8wgs0XeQoJ3w X-Received: by 10.84.233.72 with SMTP id k8mr4676753plt.420.1511369123431; Wed, 22 Nov 2017 08:45:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511369123; cv=none; d=google.com; s=arc-20160816; b=kC7zqf3jJqasty2MhHLdW4jNWeSGnaScSJnSkjJEcCTKWC77FZxJW66XrF9+zLCTZq 5MsGRiBMS7JOfEBTWjo1AC2RVQcMaHlt/oFR7BtiZ7bUeazcsVoQKn4iUBsz4s6FbBKu kH1NBP/VUb2sQBs9kj7oP84U82+n5FAkdC5dcW7TnF5VFQmISiyYXXaHKQdVxvNUdcRL RDOMBAA/usxzFWessVHW4/DPFnESyQWtrcHa54HkwhWjpbcpkEq5HpWkJ+rk4B8c/Lay FaeW3FsaKYVUi5mROMkjJLslObl1LDQYmYBhmunO4nOVVhZkd3d3pNwnd7n2Gs6CqjyY QEkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:references:in-reply-to:date :subject:cc:to:from:arc-authentication-results; bh=yZmS3RQoFZtjoZdn/kT+an6rjdP05BX/b1xSNlIrDBw=; b=S0NIjt8cPnJfsiKByG0uY+WbuBbANJajTcqLXIwMT/1q1Yf9YrOb4JWJaTp84cebMH 61Eih1b82iQ1cz3Vo7it49QN6rz3DC/1BGlDYAkwkhFc/LonztRSRZrqGiAoaK0odCuP BKczXGukLgwJS+y6UZleepxjBACg4JQv5q/HFHdlisrvTrULjDH/oS4Wm/GFrh75Dcna 2d49mYDOrybx1JkgLxMLPY0lkKoZEWX4Ez5/3t47ZxhHJ+c1kBaLEBSAYsglHIa6dBuZ DkoT1eIlYDEBwGfIz34p7X73Zfix2/o9sKtR2bvHVI8ZHDZ9kjMZqqYHjOjXKBg8sNB6 brRA== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a13si13833986pgq.440.2017.11.22.08.45.11; Wed, 22 Nov 2017 08:45:23 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751976AbdKVQoN (ORCPT + 77 others); Wed, 22 Nov 2017 11:44:13 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:33784 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751472AbdKVQoL (ORCPT ); Wed, 22 Nov 2017 11:44:11 -0500 Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vAMGi6Ns022988 for ; Wed, 22 Nov 2017 11:44:10 -0500 Received: from e06smtp12.uk.ibm.com (e06smtp12.uk.ibm.com [195.75.94.108]) by mx0b-001b2d01.pphosted.com with ESMTP id 2edcbm2cbt-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 22 Nov 2017 11:44:10 -0500 Received: from localhost by e06smtp12.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 22 Nov 2017 16:44:08 -0000 Received: from b06cxnps4075.portsmouth.uk.ibm.com (9.149.109.197) by e06smtp12.uk.ibm.com (192.168.101.142) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 22 Nov 2017 16:44:05 -0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vAMGi4Kr22151304; Wed, 22 Nov 2017 16:44:04 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9D85E4C046; Wed, 22 Nov 2017 16:39:08 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E551E4C044; Wed, 22 Nov 2017 16:39:05 +0000 (GMT) Received: from satheesh-ThinkPad-T450.in.ibm.com (unknown [9.77.198.0]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 22 Nov 2017 16:39:05 +0000 (GMT) From: sathnaga@linux.vnet.ibm.com To: acme@kernel.org, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, mingo@kernel.org Cc: bala24@linux.vnet.ibm.com, srikar@linux.vnet.ibm.com, naveen.n.rao@linux.vnet.ibm.com, Satheesh Rajendran Subject: [PATCH v5 1/1] perf/bench/numa: Fixup discontiguous/sparse numa nodes Date: Wed, 22 Nov 2017 22:13:53 +0530 X-Mailer: git-send-email 2.7.4 In-Reply-To: References: X-TM-AS-GCONF: 00 x-cbid: 17112216-0008-0000-0000-000004AE77BA X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17112216-0009-0000-0000-00001E41428F Message-Id: <1edbcd353c009e109e93d78f2f46381930c340fe.1511368645.git.sathnaga@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-11-22_05:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1711220223 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Satheesh Rajendran Certain systems are designed to have sparse/discontiguous nodes. On such systems, perf bench numa hangs, shows wrong number of nodes and shows values for non-existent nodes. Handle this by only taking nodes that are exposed by kernel to userspace. Cc: Arnaldo Carvalho de Melo Acked-by: Naveen N. Rao Reviewed-by: Srikar Dronamraju Signed-off-by: Satheesh Rajendran Signed-off-by: Balamuruhan S --- tools/perf/bench/numa.c | 56 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 51 insertions(+), 5 deletions(-) diff --git a/tools/perf/bench/numa.c b/tools/perf/bench/numa.c index d95fdcc..944070e 100644 --- a/tools/perf/bench/numa.c +++ b/tools/perf/bench/numa.c @@ -216,6 +216,47 @@ 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 && !numa_node_to_cpus(node, cpu)) { + for (i = 0; i < cpu->size; i++) { + if (numa_bitmask_isbitset(cpu, i)) + return true; + } + } + + return false; /* lets fall back to nocpus safely */ +} + static cpu_set_t bind_to_cpu(int target_cpu) { cpu_set_t orig_mask, mask; @@ -244,12 +285,12 @@ static cpu_set_t bind_to_cpu(int target_cpu) static cpu_set_t bind_to_node(int target_node) { - int cpus_per_node = g->p.nr_cpus/g->p.nr_nodes; + int cpus_per_node = g->p.nr_cpus / nr_numa_nodes(); cpu_set_t orig_mask, mask; int cpu; int ret; - BUG_ON(cpus_per_node*g->p.nr_nodes != g->p.nr_cpus); + BUG_ON(cpus_per_node * nr_numa_nodes() != g->p.nr_cpus); BUG_ON(!cpus_per_node); ret = sched_getaffinity(0, sizeof(orig_mask), &orig_mask); @@ -649,7 +690,7 @@ static int parse_setup_node_list(void) int i; for (i = 0; i < mul; i++) { - if (t >= g->p.nr_tasks) { + if (t >= g->p.nr_tasks || !node_has_cpus(bind_node)) { printf("\n# NOTE: ignoring bind NODEs starting at NODE#%d\n", bind_node); goto out; } @@ -964,6 +1005,8 @@ static void calc_convergence(double runtime_ns_max, double *convergence) sum = 0; for (node = 0; node < g->p.nr_nodes; node++) { + if (!is_node_present(node)) + continue; nr = nodes[node]; nr_min = min(nr, nr_min); nr_max = max(nr, nr_max); @@ -984,8 +1027,11 @@ static void calc_convergence(double runtime_ns_max, double *convergence) process_groups = 0; for (node = 0; node < g->p.nr_nodes; node++) { - int processes = count_node_processes(node); + int processes; + if (!is_node_present(node)) + continue; + processes = count_node_processes(node); nr = nodes[node]; tprintf(" %2d/%-2d", nr, processes); @@ -1291,7 +1337,7 @@ static void print_summary(void) printf("\n ###\n"); printf(" # %d %s will execute (on %d nodes, %d CPUs):\n", - g->p.nr_tasks, g->p.nr_tasks == 1 ? "task" : "tasks", g->p.nr_nodes, g->p.nr_cpus); + g->p.nr_tasks, g->p.nr_tasks == 1 ? "task" : "tasks", nr_numa_nodes(), g->p.nr_cpus); printf(" # %5dx %5ldMB global shared mem operations\n", g->p.nr_loops, g->p.bytes_global/1024/1024); printf(" # %5dx %5ldMB process shared mem operations\n", -- 2.7.4 From 1585896654821411708@xxx Mon Dec 04 23:08:28 +0000 2017 X-GM-THRID: 1585873057096339557 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread