Received: by 10.223.185.116 with SMTP id b49csp1101182wrg; Fri, 23 Feb 2018 11:58:49 -0800 (PST) X-Google-Smtp-Source: AH8x226Vw0R0FICf3QlOE1VDHYWErgGVMp6+rx8fq9gQLs+XOUJMn+oFLmasFpVicZ37OO+Kv8+D X-Received: by 2002:a17:902:8285:: with SMTP id y5-v6mr2784779pln.190.1519415929573; Fri, 23 Feb 2018 11:58:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519415929; cv=none; d=google.com; s=arc-20160816; b=rOy30cZHTaYiD3Ka6WV09xa2O8+WqJeWsFWgsGDQ6ymL+5Tt2TVslTAHzRSD/25J3A 8DHBUYX3J2KeHX1Kr2eaJ9ngz3CkXcC/TlHC6IY61KyP9fWfATdFXLwYgoERz245mHK9 F8liRWsUFMqA6Rq619scs8n7QscEzpamJqCqvLdoiAJbClyJCwbL9ELe4YLevGrN5uFa VptK9KmEediiM3/PPiSA+A9yZmyQYezHFSM0AjqiqTs3XaENYcGKfDLhwmQbIljro/eC 68JOoZw1bCd4xyA6uRsoabQkqT5POXR6MB0fgT/R7QMvoWxbrfuDk5AdAa6PwmGpCTBC NGCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=QyaL2ihhViyOY3E85XiptcN5hCr2pADb3pR8wPnl7vU=; b=P14gDKKHFP4o/ZvK+6p3V+d9rMkxbe6DzSphLlIyo18L9piOFDZeUg9BfLb4a49y31 9l4OYeGrOAAQh5rOM9oEEKhOu55DFlEZePSL0ASug67pK+Wix/bV3KIp3qUN9sG5u3P7 PLgNWOPDn++a11JXtPyG5N/wZYVgskTYi+0D9cuilpNg5/9FZbpimDHCQAB3pJhhzieD mMKTilAtRbNVM6nPXjV2l+qgm5xuhndulVvKHKfTf3eh1enKaSrzwSi6u0TVOcAvY/hE E2GKYAK9mVm2cb1M+c7N+z7IhxejOv8og0giBoU2DXQFe+2OVp/Z0vQEluLZcqNhbz2Q XA1w== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p8-v6si2244154pll.84.2018.02.23.11.58.35; Fri, 23 Feb 2018 11:58:49 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754936AbeBWT55 (ORCPT + 99 others); Fri, 23 Feb 2018 14:57:57 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:42528 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933546AbeBWSoV (ORCPT ); Fri, 23 Feb 2018 13:44:21 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 8818A122E; Fri, 23 Feb 2018 18:44:20 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Satheesh Rajendran , Srikar Dronamraju , "Naveen N. Rao" , Balamuruhan S , Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH 4.9 051/145] perf bench numa: Fixup discontiguous/sparse numa nodes Date: Fri, 23 Feb 2018 19:25:57 +0100 Message-Id: <20180223170731.482806680@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180223170724.669759283@linuxfoundation.org> References: <20180223170724.669759283@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Satheesh Rajendran [ Upstream commit 321a7c35c90cc834851ceda18a8ee18f1d032b92 ] 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. Signed-off-by: Satheesh Rajendran Reviewed-by: Srikar Dronamraju Acked-by: Naveen N. Rao Link: http://lkml.kernel.org/r/1edbcd353c009e109e93d78f2f46381930c340fe.1511368645.git.sathnaga@linux.vnet.ibm.com Signed-off-by: Balamuruhan S Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- tools/perf/bench/numa.c | 56 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 51 insertions(+), 5 deletions(-) --- a/tools/perf/bench/numa.c +++ b/tools/perf/bench/numa.c @@ -211,6 +211,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; @@ -239,12 +280,12 @@ static cpu_set_t bind_to_cpu(int target_ 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); @@ -644,7 +685,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; } @@ -959,6 +1000,8 @@ static void calc_convergence(double runt 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); @@ -979,8 +1022,11 @@ static void calc_convergence(double runt 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); @@ -1286,7 +1332,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",