Received: by 10.223.164.202 with SMTP id h10csp6160975wrb; Tue, 21 Nov 2017 23:45:44 -0800 (PST) X-Google-Smtp-Source: AGs4zMYopVxPOw8Z2TcHIsZy7YDwRsmzs+AowMqhiWgbxMoGnNDOa1sngXulFmxnC3u40RP1SqOJ X-Received: by 10.84.175.3 with SMTP id s3mr20331948plb.440.1511336744666; Tue, 21 Nov 2017 23:45:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511336744; cv=none; d=google.com; s=arc-20160816; b=W3Z16HnLOp0lQpKHFPzEOVd7iKLwveCCUdnQvZYcVy1wy300vU7q21FJs7g45cZxpZ x0G7qhN1ZaILuCbx8tbKBehzwOmIi5YPdNjZw5S+IeiQUCAH+W/HTwwDaKDrQL22Ea4p iJmvBbGM5kGlG6IoozLz5nZESTXRnZC3+XBDGfZ1uDZTCPn6wQ2T+68prMD/PwSZ6a/9 pM/AV+SxfRDH/hHupMJLS/amh4ajvqWYgcVkAe5CZjT+vx9b4j36We2lCayZ8wn5L3yD XkpRrillsSjiy+5cswunPPp2rFw5BIXvjLtpXzs/fP67mHFNK/IC6l4LXXlSDOwVSZGe mTmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=4B6IAsl9YvlYLpILu3tsQ3WFyzryim2REmJTS5b5dY4=; b=E5lqD8HZ17JJKk8m+SMTn6BJK1C1dx/gbW7VKWQKzbXVqFckyqaLwW2f/7/RqdBNxH qHkpXCMb2R5+f7V5gQklUw99dl598rwdLxLkkB5XW0ThMGfKRwGzR6Qr6eMWbi3XMJx6 phmc/YeBDX2Jxmev7gy9Rx0qgFjb+/XHKSIXT7Gro7hU83EIh3BjuS17F7792vxHe/77 +dmbnFnlkFSVEhdGIASS5yPKqrLD8txK5V/zXLPos08rDEegd2ehyZzA4nBHeBHUenio dgpPLKvPl2gLrrMS3TuWi53jWPDt2skJmWxF0foRdidmMvrf9HkaPZJxLJHmiv+9XXFu E1zQ== 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 s3si12488598plp.730.2017.11.21.23.45.33; Tue, 21 Nov 2017 23:45:44 -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 S1751613AbdKVHoS (ORCPT + 76 others); Wed, 22 Nov 2017 02:44:18 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:46050 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751584AbdKVHoP (ORCPT ); Wed, 22 Nov 2017 02:44:15 -0500 Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vAM7i4Wv014574 for ; Wed, 22 Nov 2017 02:44:14 -0500 Received: from e06smtp11.uk.ibm.com (e06smtp11.uk.ibm.com [195.75.94.107]) by mx0a-001b2d01.pphosted.com with ESMTP id 2ed4jhha8v-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 22 Nov 2017 02:44:14 -0500 Received: from localhost by e06smtp11.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 22 Nov 2017 07:44:12 -0000 Received: from b06cxnps4074.portsmouth.uk.ibm.com (9.149.109.196) by e06smtp11.uk.ibm.com (192.168.101.141) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 22 Nov 2017 07:44:08 -0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vAM7i8Bg40566788; Wed, 22 Nov 2017 07:44:08 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6BEAF11C04C; Wed, 22 Nov 2017 07:38:49 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id ECFB711C04A; Wed, 22 Nov 2017 07:38:47 +0000 (GMT) Received: from satheesh-ThinkPad-T450.in.ibm.com (unknown [9.122.211.73]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 22 Nov 2017 07:38:47 +0000 (GMT) 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, naveen.n.rao@linux.vnet.ibm.com, Satheesh Rajendran Subject: [PATCH v4 1/1] perf/bench/numa: Fixup discontiguous/sparse numa nodes Date: Wed, 22 Nov 2017 13:14:02 +0530 X-Mailer: git-send-email 2.7.4 X-TM-AS-GCONF: 00 x-cbid: 17112207-0040-0000-0000-000004113D06 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17112207-0041-0000-0000-000020B408BF Message-Id: <1511336642-15389-1-git-send-email-sathnaga@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-11-22_03:,, 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-1711220106 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 Cc: Naveen N. Rao Reviewed-by: Srikar Dronamraju Signed-off-by: Satheesh Rajendran Signed-off-by: Balamuruhan S --- tools/perf/bench/numa.c | 57 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 51 insertions(+), 6 deletions(-) diff --git a/tools/perf/bench/numa.c b/tools/perf/bench/numa.c index d95fdcc..ed7db12 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,13 +1005,14 @@ 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); sum += nr; } BUG_ON(nr_min > nr_max); - BUG_ON(sum > g->p.nr_tasks); if (0 && (sum < g->p.nr_tasks)) @@ -984,8 +1026,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 +1336,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 1586076210828890162@xxx Wed Dec 06 22:42:26 +0000 2017 X-GM-THRID: 1586076210828890162 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread