Received: by 10.223.185.116 with SMTP id b49csp1135481wrg; Fri, 23 Feb 2018 12:33:35 -0800 (PST) X-Google-Smtp-Source: AH8x2263hXBvtdO8odJjhxwuJPX0SBPhpAg2Wt9qfouGx8vvabOKAcJgZLqeRzREOh3aHKrHo+Y2 X-Received: by 10.99.99.132 with SMTP id x126mr2304275pgb.86.1519418015768; Fri, 23 Feb 2018 12:33:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519418015; cv=none; d=google.com; s=arc-20160816; b=L1HXq0p7r0sL1fwWLadfGSy5qrdCFkhn4xywEzRVRVxqaZyPhi1+tr5PpL5S9Zfg6l UQ2iRWgUNCPOMeqMu8za3NftKwVrv98ipAFk/qwD1cTFCK6lpwALH0k+d3nzN1S6Qjrb WIJdC1sD7p2DJpW3qLaqoe6VdhzhaaEkk5KKsQ5jRokyy8Gb/AMwapKoXK3x4LBO2057 2FQvsAHwr1dcmk1PmQUuNaZ2RaYL7H8jtC7AcSICnu0ghb+JjEhkuTHiv4rQC/Zmdmj3 GIEB4IcgLEWL6H99zi0yENAOtQaZbkdkZ3vWn6aPOr7FlAJPB/PYPxh+cUHh4NadB+9I 2I9A== 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=zBJCaw1nUTM3uMhYLjo4iGphpSQ+v3yBpHca+Y0gwY8=; b=N+Rx40/6YIk3BnczjgMK6h3X8vl4Wbeprujze1OYbfhC3YswFo/3MHffu5ZinT8DPa d1R0A7IliKYVxC6Dd8eI4t1nphw7wBZznegYP++IrIwVtSppZoQIkCUs5qocpm1BtPAC jkvzunI/czhsL2f5jLnuQmkMkDZEm5ggLeLIGASv1aYxOfz/yrrTXzNsbTcCys4o9iuY V6wHCy1W3v4tXfA4fcvgyCXyNfUty4GNLsrXFlyapn/v/OOQr61UUnVE5FUhbTXgF2xC GXoOLOL+qqMwqDcjSVswBc54bN0y9CHUvj85TuPyYs5KJiSfvwb5OnbSn3FoKc+WUIke yx0Q== 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 h13si1914870pgn.782.2018.02.23.12.33.20; Fri, 23 Feb 2018 12:33: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 S1753870AbeBWSfi (ORCPT + 99 others); Fri, 23 Feb 2018 13:35:38 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:37354 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753838AbeBWSff (ORCPT ); Fri, 23 Feb 2018 13:35:35 -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 046D111D8; Fri, 23 Feb 2018 18:35:34 +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.4 036/193] perf bench numa: Fixup discontiguous/sparse numa nodes Date: Fri, 23 Feb 2018 19:24:29 +0100 Message-Id: <20180223170331.756199134@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180223170325.997716448@linuxfoundation.org> References: <20180223170325.997716448@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.4-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 @@ -208,6 +208,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; @@ -236,12 +277,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); @@ -641,7 +682,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; } @@ -956,6 +997,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); @@ -976,8 +1019,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); @@ -1283,7 +1329,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",