Received: by 10.223.185.116 with SMTP id b49csp1072106wrg; Fri, 23 Feb 2018 11:24:35 -0800 (PST) X-Google-Smtp-Source: AH8x225EfVWFp7OKLi10yEN5oiHrcZNMoPos3piD7aQgd4cmjuBbHpOVcIqKFmxdtMEm7ydKB5qG X-Received: by 2002:a17:902:c81:: with SMTP id 1-v6mr2646990plt.205.1519413875214; Fri, 23 Feb 2018 11:24:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519413875; cv=none; d=google.com; s=arc-20160816; b=UPZqccHMmKqIDNiuL0QRCSSnMiiJzHynb+1UBJ+jy5IvQ8L6fBaYF1GGilh70+M0CU gOrXwLUFjAmdXKXzw88A6FdvrSMqFDq4ah+FE7e3CDKC7qkRtFUTc6QEzGyuwttSjF+Y jOTNVMmB0lmkAshJLEjGve33YfWYP1DeOm2nToXccWYR685nzqBwfnn45SwfOyNsyror fzFQJElI+CVxadSGjM7Pe7c37j+ZOHFvyjt+FF4ggG92WDqMq+gTaTOGlrHMyGMMG+3o ZKcJA+8QLlVOqdkA65yK8UJuTDl4e0C7piHihMSh6OR5A3SHlKEdKZAi6buw1XrrDPK7 +lMw== 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=O3NJgNM/nJOJnxErQDSJtALblpeQdVKcLEAstKv9eNE=; b=kJ4ucRXCDwkHlMGdnkEp5Y9izai/dpDy4ETlk8HmwgJVFZuuFE+UE9U9X4/UfF4kaA lRh0VLisQIBeYGH7bk69XozffltDO1Z2aC+EyLQuQZ5GSivIuqzBIxQWp0sr77X1NqV6 N1fwh22npBvD0dpbtuzBbXeRE2bUT11+ARUPkvRgwV786JnNcUfJkvoNmGg2/KRfI2JD xIeze+OA7Rah5jZFNOKYTwKBCe8jbUMDbnLioYIj8fi8UwolxXSMy7ewBw04vZ+JbBiO uBy+NAVhTtH6lLci6tP3lSlNAccLVE4jLcxw3ryOUJ48BCw60D6/zqRX8gGOZiThGbDm MSqw== 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 t3-v6si2165861plm.224.2018.02.23.11.24.21; Fri, 23 Feb 2018 11:24:35 -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 S935403AbeBWSx1 (ORCPT + 99 others); Fri, 23 Feb 2018 13:53:27 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:47330 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935345AbeBWSxY (ORCPT ); Fri, 23 Feb 2018 13:53:24 -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 CB490FCE; Fri, 23 Feb 2018 18:53:23 +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.14 074/159] perf bench numa: Fixup discontiguous/sparse numa nodes Date: Fri, 23 Feb 2018 19:26:22 +0100 Message-Id: <20180223170752.562694504@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180223170743.086611315@linuxfoundation.org> References: <20180223170743.086611315@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.14-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 @@ -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_ 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 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); @@ -984,8 +1027,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); @@ -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",